Add Mac OS sync tool

GitOrigin-RevId: 2f0f21e037dd7c00fffd0827e80438a5de1968d7
This commit is contained in:
Dietrich Epp 2021-03-04 13:56:07 -05:00
commit fa2f0d12a0
2 changed files with 150 additions and 0 deletions

76
Makefile Normal file
View File

@ -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}

74
sync.c Normal file
View File

@ -0,0 +1,74 @@
#include <Files.h>
#include <MacMemory.h>
#include <stdio.h>
#include <string.h>
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;
}