From fa2f0d12a00660184f5534211aa70eb0379a8f4f Mon Sep 17 00:00:00 2001 From: Dietrich Epp Date: Thu, 4 Mar 2021 13:56:07 -0500 Subject: [PATCH] Add Mac OS sync tool GitOrigin-RevId: 2f0f21e037dd7c00fffd0827e80438a5de1968d7 --- Makefile | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ sync.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 150 insertions(+) create mode 100644 Makefile create mode 100644 sync.c diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f9210fc --- /dev/null +++ b/Makefile @@ -0,0 +1,76 @@ +Sym-PPC = -sym Full +Sym-68K = -sym Full + +COptions = -proto strict +COptions-PPC = {COptions} {Sym-PPC} +COptions-68K = {COptions} {Sym-68K} + +### Source Files ### + +SrcFiles = ∂ + sync.c + +### Object Files ### + +ObjFiles-PPC = ∂ + sync.c.x + +ObjFiles-68K = ∂ + sync.c.o + +### Libraries ### + +LibFiles-PPC = ∂ + "{SharedLibraries}InterfaceLib" ∂ + "{SharedLibraries}StdCLib" ∂ + "{PPCLibraries}StdCRuntime.o" ∂ + "{PPCLibraries}PPCCRuntime.o" ∂ + "{PPCLibraries}PPCToolLibs.o" + +LibFiles-68K = ∂ + "{Libraries}Stubs.o" ∂ + "{CLibraries}StdCLib.o" ∂ + "{Libraries}MacRuntime.o" ∂ + "{Libraries}IntEnv.o" ∂ + "{Libraries}ToolLibs.o" ∂ + "{Libraries}Interface.o" + +### Default Rules ### + +.c.x ƒ .c + {PPCC} {depDir}{default}.c -o {targDir}{default}.c.x {COptions-PPC} + +.c.o ƒ .c + {C} {depDir}{default}.c -o {targDir}{default}.c.o {COptions-68K} + +### Build Rules ### + +SyncFiles ƒƒ {ObjFiles-PPC} {LibFiles-PPC} + PPCLink ∂ + -o {Targ} ∂ + {ObjFiles-PPC} ∂ + {LibFiles-PPC} ∂ + {Sym-PPC} ∂ + -mf -d ∂ + -t 'MPST' ∂ + -c 'MPS ' + +SyncFiles ƒƒ {ObjFiles-68K} {LibFiles-68K} + Link ∂ + -o {Targ} ∂ + {ObjFiles-68K} ∂ + {LibFiles-68K} ∂ + {Sym-68K} ∂ + -mf -d ∂ + -t 'MPST' ∂ + -c 'MPS ' + +### Build this target to generate "include file" dependencies. ### + +Dependencies ƒ $OutOfDate + MakeDepend ∂ + -append {MAKEFILE} ∂ + -ignore "{CIncludes}" ∂ + -objext .x ∂ + -objext .o ∂ + {SrcFiles} diff --git a/sync.c b/sync.c new file mode 100644 index 0000000..33ae4d6 --- /dev/null +++ b/sync.c @@ -0,0 +1,74 @@ +#include +#include + +#include +#include + +static int c2pstr(Str255 ostr, const char *istr) { + size_t n = strlen(istr); + if (n > 255) { + fprintf(stderr, "## Error: path too long: %s\n", istr); + return 1; + } + ostr[0] = n; + memcpy(ostr + 1, istr, n); + memset(ostr + 1 + n, 0, 255 - n); + return 0; +} + +static int list_dir(const char *dirpath) { + unsigned char path[257]; + WDPBRec wd; + CInfoPBRec ci; + OSErr err; + int i, result = 0; + + if (c2pstr(path, dirpath)) { + return 1; + } + memset(&wd, 0, sizeof(wd)); + wd.ioNamePtr = path; + err = PBOpenWDSync(&wd); + if (err != 0) { + fprintf(stderr, "## Error: could not open directory '%s' (err = %d)\n", dirpath, err); + return 1; + } + printf("Path: %s\n", dirpath); + printf(" VREF: %d\n", wd.ioVRefNum); + + for (i = 1; i < 10; i++) { + memset(&ci, 0, sizeof(ci)); + ci.dirInfo.ioNamePtr = path; + ci.dirInfo.ioVRefNum = wd.ioVRefNum; + ci.dirInfo.ioFDirIndex = i; + err = PBGetCatInfoSync(&ci); + if (err != 0) { + printf(" err\n"); + if (err != fnfErr) { + result = 1; + fprintf(stderr, "## Error: could not list directory '%s' (err = %d)\n", dirpath, err); + } + continue; + } + path[path[0] + 1] = '\0'; + printf(" File: '%s'\n", path + 1); + } + + err = PBCloseWDSync(&wd); + if (err != 0) { + fprintf(stderr, "## Error: could not close directory '%s' (err = %d)\n", dirpath, err); + return 1; + } + return result; +} + +int main(int argc, char **argv, char **envp) { + int i; + (void)envp; + for (i = 1; i < argc; i++) { + if (list_dir(argv[i])) { + return 1; + } + } + return 0; +}