> ZipCrunch 9 Crunch contents of a zip file, keeping all metadata : .A$=OS_GetEnv:in$=cl("",0):out$=cl("",0) ]in$="-?" in$="" out$="":"Syntax: ZipCrunch ":exit(-220*(in$="")) : ( winrar a -afzip outfile.zip infile 4zip$="C:\Apps\Disk&File\WinRAR\WinRAR a -afzip " : ! ctrl% 31:X%=ctrl%:Y%=X%256 X info% 29,name% 255,extra% 255,misc% 3,A% -1:max%=-A%-2000: mem% max%:wr%=2:rd%=4 :in%=(in$):in%=0:"File '"in$"' not found":exit(214) Eout%=(out$):out%=0:Close_All:"Can't open '"out$"'":exit(192)  file !info%<>&04034B50 Close_All out%=(out$) zipcat Close_All exit(0)  : file B 0 local file header signature 4 bytes "PK",&03,&04 4 4 version needed to extract 2 bytes 4 6 general purpose bit flag 2 bytes 4 8 compression method 2 bytes 4 10 last modification time 2 bytes 4 12 last modification date 2 bytes 4 14 crc-32 4 bytes 4 18 compressed size 4 bytes 4 22 uncompressed size 4 bytes 4 26 filename length 2 bytes 4 28 extra field length 2 bytes ; 30 filename (variable size) ; 30+fsz extra field (variable size) ; 30+fsz+esz data (variable size) : =!info%=0:f_gbpb(rd%,in%,info%,30,0):!info%<>&04034B50: `cty%=info%!8 &FFFF:crc%=info%!14:cfz%=info%!18:fsz%=info%!26 &FFFF:esz%=info%!28 &FFFF 0f_gbpb(rd%,in%,name%, fsz%,0):name%?fsz%=13 "f_gbpb(rd%,in%,extra%,esz%,0) ."Type:";cty%;" Size=&";h0(cfz%,8);" "; L:tmp1$=@tmp$+h0(,6)+".tmp":in1%=(tmp1$):in1%:#in1%:in1%=0:tmp1$="" tmp1$<>"" L:tmp2$=@tmp$+h0(,6)+".zip":in1%=(tmp2$):in1%:#in1%:in1%=0:tmp2$="" tmp2$<>"" Lname%?(fsz%-1)="/":"CopyDir "; cty%=0:"Crunch "; "Copying "; $name%; out1%=(tmp1$) &f_trans(in%,out1%,cfz%,mem%,max%) #out1%:out1%=0 name%?(fsz%-1)<>"/"  cty%=0 zip$+tmp2$+" "+tmp1$ in1%=(tmp2$) ##in1%=8:cty%=#in1%+256*#in1% #in1%=14 +f_gbpb(rd%,in1%,misc%,4,0):crc%=!misc% +f_gbpb(rd%,in1%,misc%,4,0):ext%=!misc% @#in1%=26:len%=#in1%+256*#in1%:len%=len%+#in1%+256*#in1% #in1%=30+len%  &in1%=(tmp1$):ext%=#in1%:tmp2$=""   &in1%=(tmp1$):ext%=#in1%:tmp2$=""  =info%?8=cty%:info%?9=cty%256:info%!14=crc%:info%!18=ext% f_gbpb(wr%,out%,info%,30,0) "f_gbpb(wr%,out%,name%,fsz%,0) #f_gbpb(wr%,out%,extra%,esz%,0) &f_trans(in1%,out%,ext%,mem%,max%) #in1%:in1%=0 tmp2$<>"":"Delete "+tmp2$ tmp1$<>"":"Delete "+tmp1$   : zipcat B 0 central file header signature 4 bytes (0x02014b50) 4 4 version made by 2 bytes 4 6 version needed to extract 2 bytes @ 8 general purpose bit flag 2 bytes ----+ @ 10 compression method 2 bytes | @ 12 last mod file time 2 bytes | @ 14 last mod file date 2 bytes As | @ 16 crc-32 4 bytes in | @ 20 compressed size 4 bytes local| @ 24 uncompressed size 4 bytes header| @ 28 filename length 2 bytes | @ 30 extra field length 2 bytes ----+ 4 32 file comment length 2 bytes 4 34 disk number start 2 bytes 4 36 internal file attributes 2 bytes 4 38 external file attributes 4 bytes 4 42 relative offset of local header 4 bytes ; 46 filename (variable size) ; 46+fsz extra field (variable size) ; 36+fsz+esz file comment (variable size) : !cp%=#out%:ep%=cp%:fp%=0:n%=0 :#out%=fp%:lp%=fp% f_gbpb(rd%,out%,info%,30,0) 9fsz%=info%!26 &FFFF:f_gbpb(rd%,out%,name%, fsz%,0) 9esz%=info%!28 &FFFF:f_gbpb(rd%,out%,extra%,esz%,0) !fp%=fp%+30+info%!18+fsz%+esz% $name%?fsz%=13:$name%;(10);13; #out%=ep% 0!misc%=&02014B50:f_gbpb(wr%,out%,misc%,4,0) +!info%=0:f_gbpb(wr%,out%,info%+2,28,0) /!info%=0:info%!4=0:info%!6=&20:info%!10=lp% f_gbpb(wr%,out%,info%,14,0) "f_gbpb(wr%,out%,name%,fsz%,0) #f_gbpb(wr%,out%,extra%,esz%,0) n%=n%+1:ep%=ep%+46+fsz%+esz% fp%>=cp% : B 0 end of central dir signature 4 bytes (0x06054b50) 4 4 number of this disk 2 bytes ( 6 number of the disk with the 4 start of the central directory 2 bytes ' 8 total number of entries in 4 the central dir on this disk 2 bytes ' 10 total number of entries in 4 the central dir 2 bytes 4 12 size of the central directory 4 bytes ' 16 offset of start of central & directory with respect to 4 the starting disk number 4 bytes 4 20 zipfile comment length 2 bytes ; 22 zipfile comment (variable size) : ^!info%=&06054B50:info%!4=0:info%!8=n%:info%!10=n%:info%!12=ep%-cp%:info%!16=cp%:info%!20=0 f_gbpb(wr%,out%,info%,22,0)  : :  Support functions  ================= : 1f_trans(src%,dst%,cnt%,buf%,max%):cnt%=0: num%  "num%=max%:num%>cnt%:num%=cnt% !f_gbpb(rd%,src%,buf%,num%,0) !f_gbpb(wr%,dst%,buf%,num%,0) cnt%=cnt%-num% cnt%<1   /f_gbpb(A%,chn%,addr%,num%,ptr%):num%<1: @?X%=chn%:X%!1=addr%:X%!5=num%:X%!9=ptr%:(os%32)=0:&FFD1: A%=1A%=3:#?X%=X%!9 7:A%=1A%=2:#?X%,?X%!1 A%=3A%=4:?(X%!1)=#?X% 6X%!1=X%!1+1:X%!5=X%!5-1:(#?X% A%>2) X%!5<1:  ,ݤfs:(os%32)=0:A%,Y%,E%:=(&FFDA)&FF =29  Close_All:*EXEC in%:A%=in%:in%=0:#A% out%:A%=out%:out%=0:#A%   #ݤh0(A%,N%)="0000000"+~A%,N%)  exit(A%):(os%32):Ș A%    # > BLib.ProgEnv 1.04 09Jan2007 : # Program Environment Functions # ============================= : ? Return command line tail, sets run$ to execution filename ; Works with BASIC on I/O,T6502,Arc,TZ80BBC,PC,Win,TARM ; Needs: 270 free bytes above end of heap for temp. w/s ? --------------------------------------------------------- @ݤOS_GetEnv:A$,A%,X%,Y%:X%=1:os%=((&FFF4)&FF00)256:X%-1 Jos%=32:>&FFFF:ș"GetModuleFileName",0,X%,255:A$=$$X%:run$=A$:=@cmd$ os%=32:A$=$&100 {A$=0:>&7FFF:run$=$&8100:ș"OS_GetEnv"A$,,A%:ș"OS_WriteEnv","",A%:A$=A$,1+A$+" "," ",1+A$," "))):A$=0:A$=run$ 2A$=0:?(P-3):A$=$&600 A$=0:A$=$(-&300) 7A%=A$+" "," "):run$=A$,A%-1):run$<>"":=A$,A%+1) bY%=X%256:A%=9:?X%=0:X%!1=X%+16:X%!16=0:&FFD1:A%=X%+16:!A%?A%+A%?2<>8:A%?(A%+1)=13:=$(A%+1) ="" : . Run a program, passing it a command line = If program is *Command, called with OSCLI, else CHAINed = ------------------------------------------------------- &os(A$):A$=42:A$ A$<>"":A$  : ( Exit program, setting return value ( ---------------------------------- @exit(A%):"FX1,"+A%:quit$=quit$:A$=quit$:quit$="":os(A$) os%=32:Ș A% os%<6: *Quit  : # > BLib.CmdLine 1.10 27Jul2009 # v1.10 Parses "quoted" options :  Command Line Parsing  ~~~~~~~~~~~~~~~~~~~~ : F FNcl() - parse command line for switches, options and parameters F ---------------------------------------------------------------- ( FNcl("",0) - return next parameter < FNcl(switch$,0) - return TRUE/FALSE if switch$ present = FNcl(option$,1) - return option string if present or "" : cݤcl(l$,n%):l$="":A$=s(A$):A$=34:A%=A$+" "" ",""" ",2):l$=A$,2,A%-2):A$=s(A$,A%+1)):=l$ "":A%=A$,l$):A%:A$=s(A$,A%-1)+A$,A$," ",A%)+1)):= n%=0:l$<>"":= %A%=" ",l$=32)+A$,l$):A%=0:="" 'A$=A$,A%-1)+s(A$,A$," ",A%)+1)) Cl$=32:l$=A$,A%):A$=A$,A%-1):=l$,1-(l$=34),l$+2*(l$=34)) PA$,A%,1)<>34:l$=A$,A%,A$+" "," ",A%)-A%):A$=A$,A%-1)+A$,A%+l$+1):=l$ Jl$=A$,A%+1,A$+""" ",""" ",A%+1)-A%-1):A$=A$,A%-1)+A$,A%+l$+3):=l$ /ݤs(A$):A$,1)=" ":A$=A$,2):A$,1)<>" " +A$,1)=" ":A$=A$,A$-1):A$,1)<>" " =A$