' prefix$ = " whether extracted shortages measurements thoughts exported imported facility sounds fixed lateral stores opens until patrols explorers personal externals interactions internals scales experiences adapters ships surplus classify targets active finds deleted integrated units beginnings minimums overviews regions loads fields ranges respectively forget products surely profiled passed around shared represents determines wasted significantly calling digital usually combinations receives kinds backgrounds wells doubles really pages always records edited loops anything accounts positions focu
' PRINT LEN (prefix$)
'
' long prefix with 4132 bytes
'
prefix$ = "once storage true reason close final words much were exceptions continue modify depends incorrect smaller rather elastic inserted validated books goods synchronized governmental typically thus thinks frames consistency furthermore shells essentials notify manipulated whether extracted shortages measurements thoughts exported imported facility sounds fixed lateral stores opens until patrols explorers personal externals interactions internals scales experiences adapters ships surplus classify targets active finds deleted integrated units beginnings minimums overviews regions loads fields ranges respectively forget products surely profiled passed around shared represents determines wasted significantly calling digital usually combinations receives kinds backgrounds wells doubles really pages always records edited loops anything accounts positions focuses results arguments various converts path eventually knowledge accumulates worlds insiders left increases searchers bytes obtains executes symbols earlier rectangles checks dialogs reality templates actually disable wants helpful collections techniques cases immediately apparatus providers indicates viewers effects downstream threesome rotates patents sensations monitors visible itself invents tests during customs contextual statements children individuals levels sizes keyboards pictures technology means mighty pixels steps enhanced indentical certainly calculated interfaces many longer appearances shows partners sequences headers spaces working seconds groups iterates namesake sends contents given couldn't probably mental aspects such items panels still completed two boxed themselves foundation details below blocks connected promptly universal locations features remotes differences updated basics encoded graphics separates wouldn't quality chapters layers beings binary cannot numbers something directly outlines generally likely toggles bothers locals justice attributes status removes screens brains everywhere sincerely lengthy operations makers videos containers allowances previously printers "
prefix$ = prefix$ + "lines mostly summary points designers those while scripts accessed drivers utility managers above surroundings dismay exchanged disks corresponds thanks written handles resources errors describes doesn't inputs been perceptions commons questions orders within hastle seen assigns fundamentals automation limited creates throughout they newly textures expressed values formats similar people chooses performs needs includes runs understands existing addresses however necessary correctly lists ones components languages button must related methods originals requires anyone transforms subjects already pleased property granted based notes implements concepts points reserved times extensions directory what clicks comments hardware generic created several instructions library parameters theirs types buildings switches perceptions appropriately devices characters because multiples references installed routines mains options performances entity into copyrights introductions declares singles visuals enters arithmetic additional important where returns before bits sets releases distributed same starts associated modules buffers automatics outputs sections between either each simpler more lines first compress supports after problems colors contacts understands machines compatible selects develops creates compilers variables calls then sources currents settings buttons changes instances purposes changes demonstrates consciousness another names modes users provides builds also documentation defines can values memory used software includes configures strings algorithms only drawings descriptions running codes without defaults therefore images processes supports particulars standards computers coordinates objects when others structures about numbers have these different services data implements controls not contains examples displays commands should specifics are systems using initial which you from available will follows programs functions with messages versions samples files directory for that information this and applications windows the "
' PRINT LEN (prefix$)
'
' alternatively load the prefix string from a disk file
'
' zfile = OPEN ("zapwords.txt", $$RD)
' IF (zfile <= 0) THEN RETURN
' zlength = LOF (zfile)
' IF (zlength < 3840) THEN RETURN
' prefix$ = NULL$ (zlength)
' READ [zfile], prefix$
' CLOSE (zfile)
'
' PRINT "LEN (prefix$) = "; LEN (prefix$)
END FUNCTION
'
'
' ##########################
' ##### GetString () #####
' ##########################
'
FUNCTION GetString (addr, count, string$)
'
string$ = ""
IF (count <= 0) THEN RETURN
string$ = NULL$(count)
'
FOR d = 0 TO count-1
string${d} = UBYTEAT(addr)
INC addr
NEXT d
END FUNCTION
'
'
' ############################
' ##### CommandLine () #####
' ############################
'
' command line syntax
'
' zap [-i|-e] inputfilename outputfilename"
'
' -i switch means "Implode() aka compress the input file"
' -e switch means "Explode() aka decompress the input file"
' if no switch given, figure out implode vs explode from file header
'
' CommandLine() gets the command line arguments, gets the data
' from the input file into UBYTE array i[], determines direction
' of operation (implode vs explode), and returns these results.
'
' if input file is a compressed file with a "zap" signature,
' version is the algorithm version taken from the input file.
'
'
FUNCTION CommandLine (UBYTE i[], ofile, ilength, direction, version)
'
DIM i[] ' return no data unless read in
ofile$ = "" ' return no ofile$ unless found
version = 0 ' return no version unless found
direction = 0 ' return no direction unless found
'
XstGetCommandLineArguments (@argc, @argv$[]) ' get command line
'
' get [-switch], inputfilename, outputfilename from command line
'
IF (argc > 1) THEN
FOR i = 1 TO argc-1 ' for all command line arguments
arg$ = TRIM$(argv$[i]) ' get next argument
IF arg$ THEN ' if not empty
char = arg${0} ' get 1st byte
IF (char = '-') THEN ' command line switch?
next = arg${1} ' get switch character
SELECT CASE next ' which switch?
CASE 'i' : direction = 'i' ' implode = compress
CASE 'e' : direction = 'e' ' explode = decompress
END SELECT
ELSE ' not a switch argument
IFZ ifile$ THEN ' if 1st filename not yet given
ifile$ = arg$ ' get 1st filename aka source file
ELSE
IFZ ofile$ THEN ' if 2nd filename not yet given
ofile$ = arg$ ' get 2nd filename aka result file
END IF
END IF
END IF
END IF
NEXT i
END IF
'
' see if we have valid input file and output filename : read input file
'
IF ifile$ THEN ' need input filename
IF ofile$ THEN ' and output filename
ifile = OPEN (ifile$, $$RD)
IF (ifile <= 0) THEN RETURN ' can't open input filename
ilength = LOF (ifile) ' input filename length
IF (ilength <= 0) THEN ' bogus file
CLOSE (ifile)
RETURN (1)
END IF
upper = ilength-1
DIM i[upper]
READ [ifile], i[] ' read input file into i[]
CLOSE (ifile)
IF (upper >= 8) THEN ' zap file head is 8+ bytes
IF (i[0] = 'z') THEN
IF (i[1] = 'a') THEN
IF (i[2] = 'p') THEN ' "zap" begins compressed files
IFZ direction THEN ' if direction is not specified
direction = 'e' ' explode already compressed files
END IF
END IF
END IF
END IF
END IF
END IF
END IF
'
IF (direction = 'e') THEN ' Explode() this "zap" file
version = i[3] ' get zap.x version number
ELSE ' no "zap" header, so compress
version = $$Version ' algorithm version number
direction = 'i' ' say Implode()
END IF
'
IF i[] THEN ' if we have input data
IF ofile$ THEN ' if we have output filename
ofile = OPEN (ofile$, $$WRNEW) ' open output file
IF (ofile > 0) THEN ' if output file opened okay
RETURN ($$FALSE) ' then return arguments - no error
END IF
END IF
END IF
'
' an error occured, clear out arguments and return error = $$TRUE
'
DIM i[] ' no input data
version = 0 ' invalid version
direction = 0 ' invalid direction
IF (ofile > 0) THEN ' output file open?
CLOSE (ofile) ' close output file
ofile = 0 ' clear argument
END IF
RETURN ($$TRUE) ' error = $$TRUE
END FUNCTION
'
'
' ########################
' ##### Implode () #####
' ########################
'
FUNCTION Implode (addr, bytes, count, version, UBYTE o[])
SHARED words$
UBYTE i[]
'
DIM o[]
count = 0
length = bytes
IF (length <= 0) THEN RETURN ($$TRUE) ' error
'
IFZ words$ THEN GetPrefix (@words$) ' get prefix data
zlength = LEN(words$)
'
DIM i[zlength+bytes-1]
FOR i = 0 TO zlength-1
i[i] = words${i} ' put prefix data in i[]
NEXT i
'
at = addr
FOR z = zlength TO zlength+bytes-1
i[z] = UBYTEAT (at) ' append input data to prefix
INC at
NEXT z
'
upper = bytes - 1 '
count = 0 ' result count starts at zero
addra = addr ' address of first byte to compress
addrz = addra + upper ' address of last byte to compress
addra = &i[] + zlength '
addrz = addra + upper '
'
output = 0 ' output data offset
outhalf = 0 '
input = addra ' address to get bytes from input data
DIM o[upper+upper+255] ' let result be up to twice as many bytes
'
o[0] = 'z' ' signature = "zap"
o[1] = 'a' '
o[2] = 'p' '
o[3] = version ' algorithm version # byte
output = 8 ' leave room for length, etc
'
' compress input bytes to create o[]
'
' XstGetSystemTime (@msa)
'
DO WHILE (input <= addrz) ' compress all input bytes