clean up tar.tal
This commit is contained in:
parent
b9c2a4501f
commit
f8c728d331
66
tar.tal
66
tar.tal
|
@ -2,12 +2,18 @@
|
||||||
( )
|
( )
|
||||||
( by d_m )
|
( by d_m )
|
||||||
( )
|
( )
|
||||||
( currently only supports listing the contents of tar files )
|
|
||||||
( )
|
|
||||||
( see https://en.wikipedia.org/wiki/Tar_(computing)#UStar_format )
|
( see https://en.wikipedia.org/wiki/Tar_(computing)#UStar_format )
|
||||||
|
( )
|
||||||
|
( TODO: )
|
||||||
|
( - support creating archives )
|
||||||
|
( - arg validation should depend on mode )
|
||||||
|
( - validate checksums )
|
||||||
|
( - better error messages on unsupported files, e.g. symlinks )
|
||||||
|
( - better usage message )
|
||||||
|
( - support using "-" for stdin/stdout? )
|
||||||
|
|
||||||
( File1 is used to read the tar file )
|
( File1 is used to read/write the tar file )
|
||||||
( TODO File2 is used to write files and directories )
|
( File2 is used to read/write files and directories )
|
||||||
|a0 @File1 [ &vec $2 &ok $2 &stat $2 &del $1 &append $1 &name $2 &len $2 &r $2 &w $2 ]
|
|a0 @File1 [ &vec $2 &ok $2 &stat $2 &del $1 &append $1 &name $2 &len $2 &r $2 &w $2 ]
|
||||||
|b0 @File2 [ &vec $2 &ok $2 &stat $2 &del $1 &append $1 &name $2 &len $2 &r $2 &w $2 ]
|
|b0 @File2 [ &vec $2 &ok $2 &stat $2 &del $1 &append $1 &name $2 &len $2 &r $2 &w $2 ]
|
||||||
|
|
||||||
|
@ -132,7 +138,7 @@
|
||||||
@sanitize-path ( s* -> s1* )
|
@sanitize-path ( s* -> s1* )
|
||||||
LDAk LIT "/ NEQ JMP INC2 JMP2r
|
LDAk LIT "/ NEQ JMP INC2 JMP2r
|
||||||
|
|
||||||
@extra-xyz ( n* -> extra* )
|
@remainder-512 ( n* -> extra* )
|
||||||
#01ff AND2 #0200 SWP2 SUB2 ORAk ?{ POP2 #0000 } JMP2r
|
#01ff AND2 #0200 SWP2 SUB2 ORAk ?{ POP2 #0000 } JMP2r
|
||||||
|
|
||||||
@expand-file ( type^ -> )
|
@expand-file ( type^ -> )
|
||||||
|
@ -141,7 +147,7 @@
|
||||||
DUP2 #0064 lprint #0a18 DEO
|
DUP2 #0064 lprint #0a18 DEO
|
||||||
.File2/name DEO2
|
.File2/name DEO2
|
||||||
;header/size load-octal11 STH2k write
|
;header/size load-octal11 STH2k write
|
||||||
STH2r extra-xyz skip-lo !expand-entries
|
STH2r remainder-512 skip-lo !expand-entries
|
||||||
|
|
||||||
@expand-dir ( type^ -> )
|
@expand-dir ( type^ -> )
|
||||||
POP
|
POP
|
||||||
|
@ -149,53 +155,9 @@
|
||||||
DUP2 #0064 lprint #0a18 DEO
|
DUP2 #0064 lprint #0a18 DEO
|
||||||
.File2/name DEO2
|
.File2/name DEO2
|
||||||
#0004 .File2/len DEO2
|
#0004 .File2/len DEO2
|
||||||
;tmp .File2/w DEO2
|
#0001 .File2/w DEO2
|
||||||
!expand-entries
|
!expand-entries
|
||||||
|
|
||||||
@tmp "tmp 0a 00
|
|
||||||
|
|
||||||
( TODO write data from memory into the tar file )
|
|
||||||
@z-write-memory ( filename* size* data* -> )
|
|
||||||
STH2 STH2k z-write-file-header ( [data* size*] )
|
|
||||||
STH2r STH2r z-write-file-body JMP2r ( )
|
|
||||||
.File1/len
|
|
||||||
|
|
||||||
( TODO write out the file header )
|
|
||||||
@z-write-file-header ( filename* size* -> )
|
|
||||||
SWP2 ;header/filename copy JMP2r
|
|
||||||
z-write-size-2
|
|
||||||
( TODO: compute checksum )
|
|
||||||
LIT "0 ;header/type STA
|
|
||||||
#00 ;header/linkname STA
|
|
||||||
JMP2r
|
|
||||||
|
|
||||||
( TODO write file body into archive )
|
|
||||||
@z-write-file-body ( size* data* -> )
|
|
||||||
SWP2 .File1/len DEO2 .File1/w DEO2 JMP2r
|
|
||||||
|
|
||||||
( TODO write file size, limited to 64k )
|
|
||||||
@z-write-size-2 ( size* -> )
|
|
||||||
;header/size STH2 ( size* [start*] )
|
|
||||||
LIT2r 000a ADD2r ( size* [start* last*] )
|
|
||||||
&loop ( size* [start* pos*] )
|
|
||||||
LTH2kr STHr ?&done ( size* [start* pos*] )
|
|
||||||
DUP2 #0007 AND2 ( size* size%8* [start* pos*] )
|
|
||||||
NIP LIT "0 ADD ( size* octal^ [start* pos*] )
|
|
||||||
STH2kr STA ( size* [start* pos*] )
|
|
||||||
#03 SFT2 ( size/8* [start* pos*] )
|
|
||||||
LIT2 0001 SUB2 !&loop ( size/8* [start* pos-1*] )
|
|
||||||
&done ( zero* [start* pos*] )
|
|
||||||
POP2 POP2r POP2r JMP2r ( )
|
|
||||||
|
|
||||||
( TODO: copy string from src to dst )
|
|
||||||
( TODO: need a length param too )
|
|
||||||
@copy ( src* dst* -> )
|
|
||||||
STH2
|
|
||||||
&loop
|
|
||||||
LDAk DUP STH2kr STA2 ?&ok
|
|
||||||
POP2 POP2r JMP2r
|
|
||||||
&ok INC2 INC2r !&loop
|
|
||||||
|
|
||||||
( writes `n` bytes from File1 to File2 )
|
( writes `n` bytes from File1 to File2 )
|
||||||
( uses a 32k internal buffer )
|
( uses a 32k internal buffer )
|
||||||
@write ( carry^ hi* lo* -> )
|
@write ( carry^ hi* lo* -> )
|
||||||
|
@ -407,7 +369,7 @@
|
||||||
JMP2r
|
JMP2r
|
||||||
|
|
||||||
( some handy string constants )
|
( some handy string constants )
|
||||||
@usage "usage: 20 "uxncli 20 "tar.rom 20 "c|t|x 20 "FILENAME 0a 00
|
@usage "usage: 20 "uxncli 20 "tar.rom 20 "t|x 20 "FILENAME 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
|
||||||
|
|
Loading…
Reference in New Issue