diff --git a/src/inc/fileio.plh b/src/inc/fileio.plh index 9b88405..ba7ee72 100644 --- a/src/inc/fileio.plh +++ b/src/inc/fileio.plh @@ -45,6 +45,7 @@ import fileio word write word create word destroy + word rename word newline word online word readblock diff --git a/src/libsrc/apple/fileio.pla b/src/libsrc/apple/fileio.pla index f006ff5..d074c6a 100644 --- a/src/libsrc/apple/fileio.pla +++ b/src/libsrc/apple/fileio.pla @@ -34,20 +34,21 @@ struc t_fileio word write word create word destroy + word rename word newline word online word readblock word writeblock end predef a2getpfx(path), a23setpfx(path), a2getfileinfo(path, fileinfo), a23geteof(refnum), a2iobufs(iobufs), a2open(path), a2close(refnum) -predef a23read(refnum, buf, len), a2write(refnum, buf, len), a2create(path, type, aux), a23destroy(path) +predef a23read(refnum, buf, len), a2write(refnum, buf, len), a2create(path, type, aux), a23destroy(path), a23rename(path, newpath) predef a2newline(refnum, emask, nlchar), a2online(unit, buf), a2readblock(unit, buf, block), a2writeblock(unit, buf, block) // // Exported function table. // word fileio[] word = @a2getpfx, @a23setpfx, @a2getfileinfo, @a23geteof, @a2iobufs, @a2open, @a2close -word = @a23read, @a2write, @a2create, @a23destroy +word = @a23read, @a2write, @a2create, @a23destroy, @a23rename word = @a2newline, @a2online, @a2readblock, @a2writeblock // // SOS/ProDOS error code @@ -293,6 +294,7 @@ def a3create(path, type, aux) return perr end def a1destroy(path) + perr = $01 return perr end def a23destroy(path) @@ -303,6 +305,19 @@ def a23destroy(path) perr = syscall($C1, @params) return perr end +def a1rename(oldpath, newpath) + perr = $01 + return perr +end +def a23rename(path, newpath) + byte params[5] + + params.0 = 2 + params:1 = path + params:3 = newpath + perr = syscall($C2, @params) + return perr +end def a1newline(refnum, emask, nlchar) return perr end @@ -434,6 +449,7 @@ when MACHID & MACHID_MODEL fileio:write = @a1write fileio:create = @a1create fileio:destroy = @a1destroy + fileio:rename = @a1rename fileio:newline = @a1newline fileio:online = @a1online fileio:readblock = @a13readblock diff --git a/src/libsrc/cat.pla b/src/libsrc/cat.pla new file mode 100644 index 0000000..fd10654 --- /dev/null +++ b/src/libsrc/cat.pla @@ -0,0 +1,93 @@ +include "inc/cmdsys.plh" +include "inc/args.plh" +include "inc/fileio.plh" + +var arg, refnum, dirbuf +var page, firstblk, entrylen, entriesblk, i, entry, filecnt + +char[64] path +res[t_fileinfo] fileinfo +// +// Print out a directory entry +// +def printentry()#0 + byte type, len + + type = ^entry + len = type & $0F + ^entry = len + puts(entry) + type = ' ' + when entry->$10 + is $0F // Is it a directory? + type = '/' + break + is $FF // SYSTEM file + type = '-' + break + is $FE // REL file + type = '+' + wend + putc(type) + for len = 16 - len downto 0 + putc(' ') + next + putc('$'); puth(entry->$10) + putln +end +// +// Check arguments and file types +// +arg = argNext(argFirst) +if ^arg + strcpy(@path, arg) +else + fileio:getpfx(@path) +fin +refnum = fileio:open(@path) +if refnum + page = 0 + filecnt = 0 + firstblk = 1 + dirbuf = heapallocalign(512, 8, 0) + repeat + if fileio:read(refnum, dirbuf, 512) == 512 + // + // Skip block pointers + // + entry = dirbuf + 4 + if firstblk + // + // Pull out revelant details from the first block + // + entrylen = dirbuf->$23 + entriesblk = dirbuf->$24 + filecnt = dirbuf=>$25 + entry = entry + entrylen + fin + for i = firstblk to entriesblk + // + // Print directory entry details + // + if ^entry + printentry() + filecnt-- + fin + entry = entry + entrylen + // + // Pause display every screenfull + // + page++ + if page == 23 + getc + page = 0 + fin + next + firstblk = 0 + fin + until filecnt == 0 + fileio:close(0) +else + puts("Unable to open: "); puts(@path); putln +fin +done diff --git a/src/libsrc/copy.pla b/src/libsrc/copy.pla new file mode 100644 index 0000000..881faa9 --- /dev/null +++ b/src/libsrc/copy.pla @@ -0,0 +1,146 @@ +include "inc/cmdsys.plh" +include "inc/args.plh" +include "inc/fileio.plh" + +const MAXBUFSIZE = 16384 +var arg, srcref, dstref, copybuff, copysize, copyxfer +char[64] srcfilename, dstfilename +res[t_fileinfo] srcfileinfo, dstfileinfo +// +// Handy string functions +// +def filefrompath(filestr, pathstr)#0 + byte i + + for i = ^pathstr + 1 downto 1 + if pathstr->[i] == '/' + break + fin + next + ^filestr = ^pathstr - i + memcpy(filestr + 1, pathstr + 1 + i, ^filestr) +end +// +// Check destination filename +// +def checkdst + char[17] basefile + // + // Check if destination exists + // + if fileio:getfileinfo(@dstfilename, @dstfileinfo) == FILE_ERR_OK + // + // Check if copying into a directory + // + if dstfileinfo.file_type == $0F + if dstfilename[dstfilename] <> '/' + // + // Add path seperator + // + dstfilename++ + dstfilename[dstfilename] = '/' + fin + filefrompath(@basefile, @srcfilename) + strcat(@dstfilename, @basefile) + if fileio:getfileinfo(@dstfilename, @dstfileinfo) == FILE_ERR_OK + // + // Check if *that* is a directory + // + if dstfileinfo.file_type == $0F + puts("Destination is a directory filename\n") + return FALSE + fin + else + return TRUE + fin + fin + // + // Remove existing file + // + fileio:destroy(@dstfilename) + fin + return TRUE +end +// +// Check arguments and file types +// +arg = argNext(argFirst) +if ^arg + strcpy(@srcfilename, arg) + fileio:iobufalloc(2) // Reserve two I/O buffers + if fileio:getfileinfo(@srcfilename, @srcfileinfo) == FILE_ERR_OK + // + // Check that source isn't a directory - can't handle that yet + // + if srcfileinfo.file_type == $0F + puts("Can't copy directories (yet)\n") + return + fin + else + // + // File not found + // + puts("File not found: "); puts(@srcfilename); putln + return + fin + srcref = fileio:open(@srcfilename) + if srcref + arg = argNext(arg) + if ^arg + strcpy(@dstfilename, arg) + if checkdst() + // + // Create the destination file and open for writing + // + if fileio:create(@dstfilename, srcfileinfo.file_type, srcfileinfo:aux_type) == FILE_ERR_OK + dstref = fileio:open(@dstfilename) + if dstref + // + // Let the copying begin + // + copysize = MAXBUFSIZE + while isult(heapavail, copysize + 512) + copysize = copysize / 2 + loop + copybuff = heapalloc(copysize) + if copybuff + // + // Round buffer to page boundary for faster transfers + // + copybuff = (copybuff + $FF) & $FF00 + copyxfer = fileio:read(srcref, copybuff, copysize) + while copyxfer + if fileio:write(dstref, copybuff, copyxfer) <> copyxfer + puts("Error writing: "); puts(@dstfilename); putln + break + fin + copyxfer = fileio:read(srcref, copybuff, copysize) + loop + else + puts("No memory available!\n") + fin + else + puts("Unable to open: "); puts(@dstfilename); putln + fin + else + puts("Unable to create: "); puts(@dstfilename); putln + fin + fin + fileio:close(0) + return + fin + else + // + // Unable to open source + // + puts("Unable to open: "); puts(@srcfilename); putln + return + fin + // + // Close all files + // + fileio:close(0) + return +fin +puts("Usage: +COPY SRCFILE DEST\n") +done diff --git a/src/libsrc/del.pla b/src/libsrc/del.pla new file mode 100644 index 0000000..83a07f9 --- /dev/null +++ b/src/libsrc/del.pla @@ -0,0 +1,62 @@ +include "inc/cmdsys.plh" +include "inc/args.plh" +include "inc/fileio.plh" + +char[64] filename +var arg + +// +// Check filename +// +def checkfile + var refnum, dirbuf + res[t_fileinfo] fileinfo + + // + // Check if file exists + // + if fileio:getfileinfo(@filename, @fileinfo) == FILE_ERR_OK + // + // Check if deleting a directory + // + if fileinfo.file_type == $0F + refnum = fileio:open(@filename) + if refnum + // + // Check for files inside directory + // + dirbuf = heapalloc(512) + if fileio:read(refnum, dirbuf, 512) == 512 + fileio:close(refnum) + if dirbuf=>$25 // File count in directory + puts("Directory not empty: "); puts(@filename); putln + return FALSE + fin + fin + fin + fin + return TRUE + fin + puts("File not found: "); puts(@filename); putln + return FALSE +end +// +// Check arguments and file types +// +arg = argNext(argFirst) +if ^arg + strcpy(@filename, arg) + if checkfile() + // + // Remove existing file + // + fileio:destroy(@filename) + fin + // + // Close all files + // + fileio:close(0) + return +fin +puts("Usage: +DEL FILE\n") +done diff --git a/src/libsrc/newdir.pla b/src/libsrc/newdir.pla new file mode 100644 index 0000000..79226b8 --- /dev/null +++ b/src/libsrc/newdir.pla @@ -0,0 +1,24 @@ +include "inc/cmdsys.plh" +include "inc/args.plh" +include "inc/fileio.plh" + +var arg +char[64] filename +res[t_fileinfo] fileinfo +// +// Check arguments and file types +// +arg = argNext(argFirst) +if ^arg + strcpy(@filename, arg) + if fileio:getfileinfo(@filename, @fileinfo) == FILE_ERR_OK + puts("File exists: "); puts(@filename); putln + else + if fileio:create(@filename, $0F, $0000) <> FILE_ERR_OK + puts("Unable to create directory: "); puts(@filename); putln + fin + fin + return +fin +puts("Usage: +NEWDIR PATH\n") +done diff --git a/src/libsrc/ren.pla b/src/libsrc/ren.pla new file mode 100644 index 0000000..f2f5f36 --- /dev/null +++ b/src/libsrc/ren.pla @@ -0,0 +1,34 @@ +include "inc/cmdsys.plh" +include "inc/args.plh" +include "inc/fileio.plh" + +var arg +char[64] oldfilename, newfilename +res[t_fileinfo] fileinfo +// +// Check arguments and file types +// +arg = argNext(argFirst) +if ^arg + strcpy(@oldfilename, arg) + if fileio:getfileinfo(@oldfilename, @fileinfo) <> FILE_ERR_OK + // + // File not found + // + puts("File not found: "); puts(@oldfilename); putln + return + fin + arg = argNext(arg) + if ^arg + strcpy(@newfilename, arg) + // + // Rename file + // + if fileio:rename(@oldfilename, @newfilename) <> FILE_ERR_OK + puts("Unable to rename: "); puts(@oldfilename); puts(" --> "); puts(@newfilename); putln + fin + return + fin +fin +puts("Usage: +REN OLDNAME NEWNAME\n") +done diff --git a/src/libsrc/type.pla b/src/libsrc/type.pla new file mode 100644 index 0000000..10ac895 --- /dev/null +++ b/src/libsrc/type.pla @@ -0,0 +1,83 @@ +include "inc/cmdsys.plh" +include "inc/args.plh" +include "inc/fileio.plh" + +char[64] filename +var arg +// +// Convert byte to two hex chars +// +def btoh(cptr, b)#0 + byte h + + h = ((b >> 4) & $0F) + '0' + if h > '9' + h = h + 7 + fin + ^cptr = h + cptr++ + h = (b & $0F) + '0' + if h > '9' + h = h + 7 + fin + ^cptr = h +end +// +// Check filename +// +def checkfile + var refnum, dirbuf + res[t_fileinfo] fileinfo + + // + // Check if file exists + // + if fileio:getfileinfo(@filename, @fileinfo) == FILE_ERR_OK + // + // Check if deleting a directory + // + if fileinfo.file_type == $0F + refnum = fileio:open(@filename) + if refnum + // + // Check for files inside directory + // + dirbuf = heapalloc(512) + if fileio:read(refnum, dirbuf, 512) == 512 + fileio:close(refnum) + if dirbuf=>$25 // File count in directory + puts("Directory not empty: "); puts(@filename); putln + return FALSE + fin + fin + fin + fin + return TRUE + fin + puts("File not found: "); puts(@filename); putln + return FALSE +end +// +// Check arguments and file types +// +arg = argNext(argFirst) +if ^arg + strcpy(@filename, arg) + // + // Check if file exists + // + if fileio:getfileinfo(@filename, @fileinfo) == FILE_ERR_OK + // + // Check if re-typing a directory + // + if fileinfo.file_type <> $0F + fin + fin + // + // Close all files + // + fileio:close(0) + return +fin +puts("Usage: +TYPE FILE [HEXTYPE [HEXAUX]]\n") +done diff --git a/src/makefile b/src/makefile index e8d27d9..efe8a7f 100755 --- a/src/makefile +++ b/src/makefile @@ -18,6 +18,11 @@ JIT16 = rel/apple/JIT16\#FE1000 JITUNE = rel/apple/JITUNE\#FE1000 SOS = rel/apple/SOS\#FE1000 ROD = rel/apple/ROD\#FE1000 +COPY = rel/COPY\#FE1000 +DEL = rel/DEL\#FE1000 +REN = rel/REN\#FE1000 +CAT = rel/CAT\#FE1000 +NEWDIR = rel/NEWDIR\#FE1000 SIEVE = rel/SIEVE\#FE1000 PRIMEGAP = rel/PRIMEGAP\#FE1000 ARGS = rel/ARGS\#FE1000 @@ -90,7 +95,7 @@ TXTTYPE = .TXT #SYSTYPE = \#FF2000 #TXTTYPE = \#040000 -apple: $(PLVMZP_APL) $(PLASM) $(PLVM) $(PLVM01) $(PLVM02) $(PLVMJIT) $(PLVM802) $(PLVM03) $(CMD) $(CMDJIT) $(JIT) $(JIT16) $(JITUNE) $(SOSCMD) $(PLASMAPLASM) $(CODEOPT) $(ARGS) $(MEMMGR) $(MEMTEST) $(FIBER) $(FIBERTEST) $(LONGJMP) $(ED) $(MON) $(SOS) $(ROD) $(SIEVE) $(PRIMEGAP) $(MOUSE) $(UTHERNET2) $(UTHERNET) $(ETHERIP) $(INET) $(DHCP) $(HTTPD) $(TFTPD) $(ROGUE) $(ROGUEMAP) $(ROGUECOMBAT) $(GRAFIX) $(GFXDEMO) $(LINESPANS) $(GRLIB) $(DGRLIB) $(GRTEST) $(DGRTEST) $(HGRTEST) $(FILEIO_APL) $(CONIO_APL) $(JOYBUZZ) $(PORTIO) $(SPIPORT) $(SDFAT) $(FATCAT) $(FATGET) $(FATPUT) $(FATWDSK) $(FATRDSK) $(SANE) $(FPSTR) $(FPU) $(SANITY) $(LZ4) $(LZ4CAT) $(RPNCALC) $(SNDSEQ) $(PLAYSEQ) +apple: $(PLVMZP_APL) $(PLASM) $(PLVM) $(PLVM01) $(PLVM02) $(PLVMJIT) $(PLVM802) $(PLVM03) $(CMD) $(CMDJIT) $(JIT) $(JIT16) $(JITUNE) $(SOSCMD) $(PLASMAPLASM) $(CODEOPT) $(ARGS) $(MEMMGR) $(MEMTEST) $(FIBER) $(FIBERTEST) $(LONGJMP) $(ED) $(MON) $(COPY) $(DEL) $(REN) $(CAT) $(NEWDIR) $(SOS) $(ROD) $(SIEVE) $(PRIMEGAP) $(MOUSE) $(UTHERNET2) $(UTHERNET) $(ETHERIP) $(INET) $(DHCP) $(HTTPD) $(TFTPD) $(ROGUE) $(ROGUEMAP) $(ROGUECOMBAT) $(GRAFIX) $(GFXDEMO) $(LINESPANS) $(GRLIB) $(DGRLIB) $(GRTEST) $(DGRTEST) $(HGRTEST) $(FILEIO_APL) $(CONIO_APL) $(JOYBUZZ) $(PORTIO) $(SPIPORT) $(SDFAT) $(FATCAT) $(FATGET) $(FATPUT) $(FATWDSK) $(FATRDSK) $(SANE) $(FPSTR) $(FPU) $(SANITY) $(LZ4) $(LZ4CAT) $(RPNCALC) $(SNDSEQ) $(PLAYSEQ) -rm vmsrc/plvmzp.inc @@ -409,6 +414,26 @@ $(MON): samplesrc/mon.pla $(PLVM02) $(PLASM) ./$(PLASM) -AMOW < samplesrc/mon.pla > samplesrc/mon.a acme --setpc 4094 -o $(MON) samplesrc/mon.a +$(COPY): libsrc/copy.pla $(PLVM03) $(PLASM) + ./$(PLASM) -AMOW < libsrc/copy.pla > libsrc/copy.a + acme --setpc 4094 -o $(COPY) libsrc/copy.a + +$(DEL): libsrc/del.pla $(PLVM03) $(PLASM) + ./$(PLASM) -AMOW < libsrc/del.pla > libsrc/del.a + acme --setpc 4094 -o $(DEL) libsrc/del.a + +$(REN): libsrc/ren.pla $(PLVM03) $(PLASM) + ./$(PLASM) -AMOW < libsrc/ren.pla > libsrc/ren.a + acme --setpc 4094 -o $(REN) libsrc/ren.a + +$(CAT): libsrc/cat.pla $(PLVM03) $(PLASM) + ./$(PLASM) -AMOW < libsrc/cat.pla > libsrc/cat.a + acme --setpc 4094 -o $(CAT) libsrc/cat.a + +$(NEWDIR): libsrc/newdir.pla $(PLVM03) $(PLASM) + ./$(PLASM) -AMOW < libsrc/newdir.pla > libsrc/newdir.a + acme --setpc 4094 -o $(NEWDIR) libsrc/newdir.a + $(SOS): libsrc/apple/sos.pla $(PLVM03) $(PLASM) ./$(PLASM) -AMOW < libsrc/apple/sos.pla > libsrc/apple/sos.a acme --setpc 4094 -o $(SOS) libsrc/apple/sos.a diff --git a/src/mkrel b/src/mkrel index f82a996..57cc74b 100755 --- a/src/mkrel +++ b/src/mkrel @@ -12,6 +12,11 @@ cp rel/apple/CONIO#FE1000 prodos/sys/CONIO.REL cp rel/apple/LINESPANS#FE1000 prodos/sys/LINESPANS.REL cp rel/apple/GRLIB#FE1000 prodos/sys/GRLIB.REL cp rel/apple/DGRLIB#FE1000 prodos/sys/DGRLIB.REL +cp rel/COPY#FE1000 prodos/sys/COPY.REL +cp rel/DEL#FE1000 prodos/sys/DEL.REL +cp rel/REN#FE1000 prodos/sys/REN.REL +cp rel/CAT#FE1000 prodos/sys/CAT.REL +cp rel/NEWDIR#FE1000 prodos/sys/NEWDIR.REL cp rel/ARGS#FE1000 prodos/sys/ARGS.REL cp rel/ED#FE1000 prodos/sys/ED.REL cp rel/FIBER#FE1000 prodos/sys/FIBER.REL diff --git a/src/tftprel b/src/tftprel index 3fbd73f..2d20b6e 100755 --- a/src/tftprel +++ b/src/tftprel @@ -1,6 +1,7 @@ #!/bin/bash ./tftpsys $1 $2 +./tftputil $1 $2 ./tftpsane $1 $2 ./tftpbld $1 $2 ./tftpdemos $1 $2 diff --git a/src/tftpsys b/src/tftpsys index 2b1f5d8..4cffe31 100755 --- a/src/tftpsys +++ b/src/tftpsys @@ -13,14 +13,11 @@ echo "SYS/JITUNE"; atftp $1 --put -l rel/apple/JITUNE#FE1000 -r $2/SYS/JITUNE # Core libraries echo "SYS/ARGS"; atftp $1 --put -l rel/ARGS#FE1000 -r $2/SYS/ARGS#FE1000 echo "SYS/DHCP"; atftp $1 --put -l rel/DHCP#FE1000 -r $2/SYS/DHCP#FE1000 -echo "SYS/ED"; atftp $1 --put -l rel/ED#FE1000 -r $2/SYS/ED#FE1000 -echo "SYS/TFTPD"; atftp $1 --put -l rel/TFTPD#FE1000 -r $2/SYS/TFTPD#FE1000 echo "SYS/ETHERIP"; atftp $1 --put -l rel/ETHERIP#FE1000 -r $2/SYS/ETHERIP#FE1000 echo "SYS/MOUSE"; atftp $1 --put -l rel/apple/MOUSE#FE1000 -r $2/SYS/MOUSE#FE1000 echo "SYS/FIBER"; atftp $1 --put -l rel/FIBER#FE1000 -r $2/SYS/FIBER#FE1000 echo "SYS/INET"; atftp $1 --put -l rel/INET#FE1000 -r $2/SYS/INET#FE1000 echo "SYS/LONGJUMP"; atftp $1 --put -l rel/LONGJMP#FE1000 -r $2/SYS/LONGJMP#FE1000 -echo "SYS/LZ4"; atftp $1 --put -l rel/LZ4#FE1000 -r $2/SYS/LZ4#FE1000 echo "SYS/MEMMGR"; atftp $1 --put -l rel/MEMMGR#FE1000 -r $2/SYS/MEMMGR#FE1000 echo "SYS/CONIO"; atftp $1 --put -l rel/apple/CONIO#FE1000 -r $2/SYS/CONIO#FE1000 echo "SYS/LINESPANS"; atftp $1 --put -l rel/apple/LINESPANS#FE1000 -r $2/SYS/LINESPANS#FE1000 @@ -29,8 +26,6 @@ echo "SYS/DGRLIB"; atftp $1 --put -l rel/apple/DGRLIB#FE1000 -r $2/SYS/DGRLIB# echo "SYS/FILEIO"; atftp $1 --put -l rel/apple/FILEIO#FE1000 -r $2/SYS/FILEIO#FE1000 echo "SYS/JOYBUZZ"; atftp $1 --put -l rel/apple/JOYBUZZ#FE1000 -r $2/SYS/JOYBUZZ#FE1000 echo "SYS/SNDSEQ"; atftp $1 --put -l rel/apple/SNDSEQ#FE1000 -r $2/SYS/SNDSEQ#FE1000 -echo "SYS/MON"; atftp $1 --put -l rel/apple/MON#FE1000 -r $2/SYS/MON#FE1000 -echo "SYS/SOS"; atftp $1 --put -l rel/apple/SOS#FE1000 -r $2/SYS/SOS#FE1000 echo "SYS/PORTIO"; atftp $1 --put -l rel/apple/PORTIO#FE1000 -r $2/SYS/PORTIO#FE1000 echo "SYS/UTHERNET2";atftp $1 --put -l rel/apple/UTHERNET2#FE1000 -r $2/SYS/UTHERNET2#FE1000 echo "SYS/UTHERNET"; atftp $1 --put -l rel/apple/UTHERNET#FE1000 -r $2/SYS/UTHERNET#FE1000