From f8a6589f34490db14c8870d9a5c1610a02072e63 Mon Sep 17 00:00:00 2001 From: Dave Schmenk Date: Sat, 31 Dec 2022 22:41:28 -0800 Subject: [PATCH] Place common routine into matchfiles --- src/inc/matchfiles.plh | 1 + src/libsrc/apple/matchfiles.pla | 14 ++++++++++++++ src/makefile | 6 +++--- src/utilsrc/apple/cat.pla | 34 +++------------------------------ src/utilsrc/apple/copy.pla | 13 +------------ src/utilsrc/apple/del.pla | 18 +++-------------- src/utilsrc/apple/type.pla | 30 ++++++++++++++--------------- 7 files changed, 40 insertions(+), 76 deletions(-) diff --git a/src/inc/matchfiles.plh b/src/inc/matchfiles.plh index 9c571d4..f60b27c 100644 --- a/src/inc/matchfiles.plh +++ b/src/inc/matchfiles.plh @@ -2,4 +2,5 @@ import matchfiles predef matchName(src, exp)#1 predef matchList(pathptr, exp)#2 predef isWildName(exp)#1 + predef fileFromPath(filestr, pathstr)#0 end diff --git a/src/libsrc/apple/matchfiles.pla b/src/libsrc/apple/matchfiles.pla index cc5842e..11da710 100644 --- a/src/libsrc/apple/matchfiles.pla +++ b/src/libsrc/apple/matchfiles.pla @@ -113,4 +113,18 @@ export def isWildName(exp)#1 fin return FALSE end +// +// Utility routine to separate filename from path +// +export def fileFromPath(filestr, pathstr)#0 + byte i + + for i = ^pathstr downto 1 + if pathstr->[i] == '/' + break + fin + next + ^filestr = ^pathstr - i + memcpy(filestr + 1, pathstr + 1 + i, ^filestr) +end done diff --git a/src/makefile b/src/makefile index bff11a6..ce2e034 100755 --- a/src/makefile +++ b/src/makefile @@ -485,11 +485,11 @@ $(MON): utilsrc/apple/mon.pla $(PLASM) ./$(PLASM) -AMOW < utilsrc/apple/mon.pla > utilsrc/apple/mon.a acme --setpc 4094 -o $(MON) utilsrc/apple/mon.a -$(COPY): utilsrc/apple/copy.pla $(PLASM) +$(COPY): utilsrc/apple/copy.pla $(MATCHFILES) $(PLASM) ./$(PLASM) -AMOW < utilsrc/apple/copy.pla > utilsrc/apple/copy.a acme --setpc 4094 -o $(COPY) utilsrc/apple/copy.a -$(DEL): utilsrc/apple/del.pla $(PLASM) +$(DEL): utilsrc/apple/del.pla $(MATCHFILES) $(PLASM) ./$(PLASM) -AMOW < utilsrc/apple/del.pla > utilsrc/apple/del.a acme --setpc 4094 -o $(DEL) utilsrc/apple/del.a @@ -497,7 +497,7 @@ $(REN): utilsrc/apple/ren.pla $(PLASM) ./$(PLASM) -AMOW < utilsrc/apple/ren.pla > utilsrc/apple/ren.a acme --setpc 4094 -o $(REN) utilsrc/apple/ren.a -$(CAT): utilsrc/apple/cat.pla $(PLASM) +$(CAT): utilsrc/apple/cat.pla $(MATCHFILES) $(PLASM) ./$(PLASM) -AMOW < utilsrc/apple/cat.pla > utilsrc/apple/cat.a acme --setpc 4094 -o $(CAT) utilsrc/apple/cat.a diff --git a/src/utilsrc/apple/cat.pla b/src/utilsrc/apple/cat.pla index e7f131e..87d4d7d 100644 --- a/src/utilsrc/apple/cat.pla +++ b/src/utilsrc/apple/cat.pla @@ -12,23 +12,6 @@ char[64] path, wildname res[t_fileinfo] fileinfo res[t_fileentry] fileentry // -// Convert byte to two hex chars -// -def putb(b)#0 - char h - - h = ((b >> 4) & $0F) + '0' - if h > '9' - h = h + 7 - fin - putc(h) - h = (b & $0F) + '0' - if h > '9' - h = h + 7 - fin - putc(h) -end -// // Copy string with upper case conversion // def struprcpy(dst, src)#0 @@ -46,23 +29,12 @@ def struprcpy(dst, src)#0 fin ^dst = ^src end -def filefrompath(filestr, pathstr)#0 - byte i - - for i = ^pathstr downto 1 - if pathstr->[i] == '/' - break - fin - next - ^filestr = ^pathstr - i - memcpy(filestr + 1, pathstr + 1 + i, ^filestr) -end // // Print out a directory entry // def printentry(entryptr)#0 char type, pad, eofstr[12] - + puts(entryptr) when entryptr->entry_type is $0F // Is it a directory? @@ -88,12 +60,12 @@ def printentry(entryptr)#0 for pad = eofstr to 9 putc(' ') next - puts(@eofstr) + puts(@eofstr) putln end def printentries(pathstr, entries, num)#0 byte page - + puts(pathstr); putln puts("=NAME==========TYPE===AUX====LENGTH=\n") page = 20 diff --git a/src/utilsrc/apple/copy.pla b/src/utilsrc/apple/copy.pla index 04d23a5..ea16d30 100644 --- a/src/utilsrc/apple/copy.pla +++ b/src/utilsrc/apple/copy.pla @@ -67,17 +67,6 @@ def pathdiff(path1, path2)#1 next return FALSE end -def filefrompath(filestr, pathstr)#0 - byte i - - for i = ^pathstr downto 1 - if pathstr->[i] == '/' - break - fin - next - ^filestr = ^pathstr - i - memcpy(filestr + 1, pathstr + 1 + i, ^filestr) -end // // Check destination path // @@ -115,7 +104,7 @@ def copyfiles(srcfile, dstfile)#0 strcpy(@srcpath, srcfile) wildname = 0 if fileio:getfileinfo(@srcpath, @srcfileinfo) <> FILE_ERR_OK or (srcfileinfo.storage_type & $0D <> $0D) - filefrompath(@wildname, @srcpath) + fileFromPath(@wildname, @srcpath) srcpath = srcpath - wildname fin entrylist, entrycnt = matchList(@srcpath, @wildname) diff --git a/src/utilsrc/apple/del.pla b/src/utilsrc/apple/del.pla index 3129ed4..3fa3108 100644 --- a/src/utilsrc/apple/del.pla +++ b/src/utilsrc/apple/del.pla @@ -25,17 +25,6 @@ def struprcpy(dst, src)#0 fin ^dst = ^src end -def filefrompath(filestr, pathstr)#0 - byte i - - for i = ^pathstr downto 1 - if pathstr->[i] == '/' - break - fin - next - ^filestr = ^pathstr - i - memcpy(filestr + 1, pathstr + 1 + i, ^filestr) -end // // Check filename // @@ -81,9 +70,8 @@ def delfiles(delfile)#0 strcpy(@delpath, delfile) wildname = 0 - //if fileio:getfileinfo(@delpath, @fileinfo) <> FILE_ERR_OK or fileinfo.file_type <> $0F if delpath[delpath] <> '/' - filefrompath(@wildname, @delpath) + fileFromPath(@wildname, @delpath) delpath = delpath - wildname fin // @@ -115,7 +103,7 @@ def delfiles(delfile)#0 fileio:destroy(@delfilepath) fin entry = entry + t_fileentry - entrycnt-- + entrycnt-- loop elsif not wildname puts("Not found: "); puts(@delpath); puts("/"); puts(@wildname); putln @@ -156,7 +144,7 @@ if not except(exit) strcpy(@path,fileptr) strcat(@path, "/") delfiles(@path) - fin + fin delfiles(fileptr) fileptr = fileptr + ^fileptr + 1 filecnt-- diff --git a/src/utilsrc/apple/type.pla b/src/utilsrc/apple/type.pla index 799f9f7..eca4438 100644 --- a/src/utilsrc/apple/type.pla +++ b/src/utilsrc/apple/type.pla @@ -8,23 +8,23 @@ var arg, type, aux // // Convert byte to two hex chars // -def putb(b)#0 - char h - - h = ((b >> 4) & $0F) + '0' - if h > '9' - h = h + 7 - fin - putc(h) - h = (b & $0F) + '0' - if h > '9' - h = h + 7 - fin - putc(h) -end +//def putb(b)#0 +// char h +// +// h = ((b >> 4) & $0F) + '0' +// if h > '9' +// h = h + 7 +// fin +// putc(h) +// h = (b & $0F) + '0' +// if h > '9' +// h = h + 7 +// fin +// putc(h) +//end def htoi(hexptr) var val, i, n - + val = 0 for i = 1 to ^hexptr n = toupper(^(hexptr + i)) - '0'