start adding support for creating archives

This commit is contained in:
Erik Osheim 2025-02-12 10:56:40 -05:00
parent 8171300a7c
commit 7640bce419
1 changed files with 25 additions and 14 deletions

39
tar.tal
View File

@ -27,24 +27,33 @@
@panic ( -> $exit ) @panic ( -> $exit )
#010e DEO #010f DEO BRK #010e DEO #010f DEO BRK
@print-usage ( -> )
;usage1 print ;usage2 !print
( handle all provided command-line arguments ) ( handle all provided command-line arguments )
@arg-callback ( -> ) @arg-callback ( -> )
;arg/count LDA ;arg/count LDA
DUP #00 EQU ?&missing-mode DUP #00 GTH ?{ POP ;missing-mode !handle-error }
DUP #01 EQU ?&missing-file DUP #01 GTH ?{ POP ;missing-filename !handle-error }
#02 GTH ?&toomany !run !run
&missing-mode ;missing-mode !&error
&missing-file ;missing-filename !&error @error-toomany ( -> BRK )
&toomany ;too-many-arguments ;too-many-arguments !handle-error
&error print ;usage print #01 !exit
@error-noinput ( -> BRK )
;no-input-arguments !handle-error
@handle-error ( ;msg -> BRK )
print print-usage #01 !exit
( run the program ) ( run the program )
@run ( -> BRK ) @run ( -> BRK )
#01 arg/read .File1/name DEO2 #01 arg/read .File1/name DEO2
#00 arg/read LDA #00 arg/read LDA
DUP LIT "c NEQ ?{ POP create-archive #00 !exit }
DUP LIT "t NEQ ?{ POP list-entries #00 !exit } DUP LIT "t NEQ ?{ POP list-entries #00 !exit }
DUP LIT "x NEQ ?{ POP expand-entries #00 !exit } DUP LIT "x NEQ ?{ POP expand-entries #00 !exit }
POP ;invalid-mode print ;usage print #00 !exit POP ;invalid-mode print print-usage #00 !exit
( exit normally ) ( exit normally )
@exit ( code^ -> BRK ) @exit ( code^ -> BRK )
@ -124,10 +133,9 @@
ADD2r INC2 GTH2k ?&loop ( limit* pos+1* [sum+n*] ) ADD2r INC2 GTH2k ?&loop ( limit* pos+1* [sum+n*] )
POP2 POP2 STH2r JMP2r ( sum* ) POP2 POP2 STH2r JMP2r ( sum* )
( list all the entries in the tar archive ) ( list all the entries in the tar archive )
@list-entries ( -> ) @list-entries ( -> )
;arg/count LDA #02 GTH ?error-toomany
read-header ?{ JMP2r } read-header ?{ JMP2r }
;header/filename LDA ?&non-null ;header/filename LDA ?&non-null
#800f DEO BRK #800f DEO BRK
@ -177,6 +185,7 @@
( expand a .tar archive in the current working directory ) ( expand a .tar archive in the current working directory )
@expand-entries ( -> ) @expand-entries ( -> )
;arg/count LDA #02 GTH ?error-toomany
read-header ?{ JMP2r } read-header ?{ JMP2r }
;header/filename LDA ?&non-null ;header/filename LDA ?&non-null
#800f DEO BRK #800f DEO BRK
@ -216,9 +225,9 @@
print-filename print-filename
;header/size load-octal11 round-up-to-512 skip !expand-entries ;header/size load-octal11 round-up-to-512 skip !expand-entries
( src and dst should be paths ) @create-archive ( -> )
@compress-entries ( src* dst* -> ) ;arg/count LDA #03 LTH ?error-noinput
POP2 POP2 JMP2r JMP2r
( writes `n` bytes from File1 to File2 ) ( writes `n` bytes from File1 to File2 )
( uses a 32k internal buffer ) ( uses a 32k internal buffer )
@ -406,10 +415,12 @@
JMP2r JMP2r
( some handy string constants ) ( some handy string constants )
@usage "usage: 20 "uxncli 20 "tar.rom 20 "t|x 20 "FILENAME 0a 00 @usage1 "usage: 20 "uxncli 20 "tar.rom 20 "t|x 20 "TARFILE 0a 00
@usage2 20 20 20 20 20 20 20 "uxncli 20 "tar.rom 20 "c 20 "TARFILE 20 "FILE1 20 "... 0a 00
@missing-mode "error: 20 "missing 20 "mode 0a 00 @missing-mode "error: 20 "missing 20 "mode 0a 00
@missing-filename "error: 20 "missing 20 "filename 0a 00 @missing-filename "error: 20 "missing 20 "filename 0a 00
@too-many-arguments "error: 20 "too 20 "many 20 "arguments 0a 00 @too-many-arguments "error: 20 "too 20 "many 20 "arguments 0a 00
@no-input-arguments "error: 20 "no 20 "input 20 "files 0a 00
@invalid-mode "error: 20 "invalid 20 "mode 0a 00 @invalid-mode "error: 20 "invalid 20 "mode 0a 00
@read-error "error 20 "reading 20 "data 0a 00 @read-error "error 20 "reading 20 "data 0a 00
@write-error "error 20 "writing 20 "data 0a 00 @write-error "error 20 "writing 20 "data 0a 00