home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / mbug / mbug028.arc / SQUEEZE.DOC < prev    next >
Text File  |  1979-12-31  |  23KB  |  522 lines

  1. USAGE AND RECOMPILATION DOCUMENTATION FOR:         7/18/81
  2.      SQ.COM    1.3  File squeezer
  3.      USQ.COM   1.4  File unsqueezer
  4.      FLS.COM   1.1  Ambiguous file name expander
  5.  
  6. DISTRIBUTION RIGHTS:
  7. I   allow  unrestricted  non-profit  distribution  of   this 
  8. software  and  invite  users groups  to  spread  it  around. 
  9. However,  any distribution for profit requires my permission 
  10. in  advance.  This applies only to the above listed programs 
  11. and their program source and documentation files.  I do sell  
  12. other software.
  13.  
  14. PURPOSE:
  15. The file squeezer,  SQ, compresses files into a more compact 
  16. form.  This provides:
  17.      1.   Faster transmission by modem.
  18.      2.   Fewer diskettes to distribute a program  package. 
  19.           (Include USQ.COM and instructions, both unsqueezed.)
  20.      3.   Fewer diskettes for archival storage.
  21.  
  22. Any file can be squeezed,  but program source files and text 
  23. files  benefit the most,  typically shrinking by 35%.  Files 
  24. containing only a limited character set,  such as dictionary 
  25. files,  may shrink as much as 48%.  Squeezed files look like 
  26. gibbersh and must be unsqueezed before they can be used.
  27.  
  28. The  unsqueezer,  USQ,  expands  squeezed files  into  exact 
  29. duplicates  of the original or provides a quick,  unsqueezed 
  30. display  of  the  tops  of  (or  all  of)  squeezed   files. 
  31. Unsqueezing requires only a single pass.
  32.  
  33. Both SQ and USQ accept batches of work specified by lists of 
  34. file  names  (with  drives  if  needed)  and   miscellaneous 
  35. options. They accept these parameters in any of three ways:
  36.  
  37.      1. On the CP/M command line.
  38.      2. From the console keyboard.
  39.      3. From a file.
  40.  
  41. The  FLS program can be used (on the same command line!)  to 
  42. expand parameter lists containing wild-card (ambiguous) file 
  43. names into lists with the specific file names required by SQ 
  44. and USQ.
  45.  
  46. This  combination of programs allows you to issue  a  single 
  47. command which will produce many squeezed or unsqueezed files 
  48. from and to various diskettes. For example, to unsqueeze all 
  49. squeezed  ASM files on drive B and send the results to drive 
  50. C  and also unsqueeze all squeezed TXT files on drive A  and 
  51. send the results to drive D:
  52.      A>fls c: b:*.aqm d: *.tqt |usq
  53. For detailed instructions see USAGE.
  54. This  DOES  run under plain old vanilla CP/M!  Many  of  the 
  55. smarts  are buried in the COM files in the form  of  library 
  56. routines  provided  with the BDS C package  (available  from 
  57. Lifeboat).
  58.  
  59. The  above example simulates a "pipe" (indicated by the "|") 
  60. by sending the "console" output of the fls.com program to  a 
  61. temporary  file  and  then running the sq.com  program  with 
  62. options  which  cause  it to read its  parameters  from  its 
  63. "console" input, which is really redirected to come from the 
  64. temporary file.
  65.  
  66. THEORY:
  67. The  data  in the file is treated at the byte  level  rather 
  68. then  the word level,  and can contain absolutely  anything. 
  69. The compression is in two stages: first repeated byte values 
  70. are  compressed  and  then a  Huffman  code  is  dynamically 
  71. generated  to match the properties of each particular  file. 
  72. This requires two passes over the source data.
  73.  
  74. The  decoding  table is included in the  squeezed  file,  so 
  75. squeezing  short  files can actually  lengthen  them.  Fixed 
  76. decoding  tables  are not used because  English and  various 
  77. computer  languages vary greatly as to upper and lower  case 
  78. proportions  and  use of special  characters.  Much  of  the 
  79. savings  comes  from  not  assigning codes  to  unused  byte 
  80. values.
  81.  
  82. More detailed comments are included in the source files.
  83.  
  84. USAGE TUTORIAL:
  85. As usual, you have to learn how to tell the programs what to 
  86. do  (i.e.,  what parameters to type after the program name). 
  87. First I will introduce the various possibilities by example. 
  88. Then I will summarize the rules.
  89.  
  90. In  the simplest case either SQ or USQ can simply  be  given 
  91. one or more file names (with or without drive names):
  92.      A>sq xyz.asm
  93.      A>sq thisfile.doc b:thatfile.doc
  94. will   create  squeezed  files  xyz.aqm,   thisfile.dqc  and 
  95. thatfile.dqc,  all  on the current drive,  A.  The  original 
  96. files are not disturbed. Note that the names of the squeezed 
  97. files are generated by rules - you don't specify them.
  98.  
  99. Likewise,
  100.      A>usq xyz.aqm
  101. will  create file xyz.asm on the A  drive,  overwriting  the 
  102. original.  (The  original name is recreated from information 
  103. stored in the squeezed version.) The squeezed version is not 
  104. disturbed.
  105.  
  106. Each file name is processed in order,  and you can list  all 
  107. the files you can fit in a command.  The file names given to 
  108. SQ and USQ must be specific. You will learn below how to use 
  109. the FLS program to expand patterns like *.asm (all files  of 
  110. type  asm) into a list of specific names and feed them  into 
  111. SQ or USQ.
  112.  
  113. The above examples let the destination drive default to  the 
  114. current logged drive, which was shown in the prompt to be A. 
  115. You can change the destination drive as often as you like in 
  116. the parameter list. For example,
  117.      A>sq x.asm b: y.asm z.asm c: d:s.asm
  118. will create x.aqm on the current drive,  A,  y.aqm and z.aqm 
  119. on the B drive and s.aqm on the C drive. Note that the first 
  120. three originals are on drive A and the last one is on  drive 
  121. D.  Remember  that each parameter is processed in order,  so 
  122. you must change the destination drive before you specify the 
  123. files to be created on that drive.
  124.  
  125. Eventually you will have diskettes with many squeezed  files 
  126. on  them and you will wonder what is in which file.  If they 
  127. weren't  squeezed you would use the TYPE command to look  at 
  128. the  comments at the beginning of the  files.  But  squeezed 
  129. files  just  make  a mess on your CRT screen when  you  TYPE 
  130. them,  so  I have provided the required feature as a preview 
  131. option to the USQ program.
  132.      A>usq -10 x.bas b:y.asm
  133. will  not take the time to create unsqueezed files.  Instead 
  134. it  will  unsqueeze  the first 10 lines  of  each  file  and 
  135. display  them  on your console.  The display from each  file 
  136. consists of the file names, the data and a formfeed (FF).
  137. Also,
  138.      A>usq - c:xyz.mac
  139. will  unsqueeze  and display the first 65,535 lines  of  any 
  140. files listed. That's the biggest number you can give it, and 
  141. is intended to display the whole file.
  142.  
  143. This   preview  option  also  ensures  that  the   data   is 
  144. displayable.  The  parity bit is stripped off (some Wordstar 
  145. files  use  it for format control) and any  unusual  control 
  146. characters  are  converted to periods.  You'll see  some  of 
  147. these  at  the end of the files as the CP/M end of  file  is 
  148. treated  as  data  and  the  remainder  of  the  sector   is 
  149. displayed.
  150.  
  151. You are now familiar with all of the operational  parameters 
  152. of SQ and USQ.  But so far you have always typed them on the 
  153. command line which caused the program to be run. For reasons 
  154. which  will become apparent later,  I have also provided  an 
  155. interactive  mode.   If  there  are  no  parameters  (except 
  156. directed  i/o  parameters,  described later) on the  command 
  157. line,  SQ  and USQ will prompt with an asterisk  and  accept 
  158. parameters from the console keyboard. Each parameter must be 
  159. followed  by  RETURN and will be processed  immediately.  An 
  160. empty  command (just RETURN) will cause the program to  exit 
  161. back  to  CP/M.  Try it - it will help you  understand  what 
  162. follows.
  163.  
  164. Now lets get into directed i/o, which will be new to most of 
  165. you,  but will save you so much work you will wonder how you 
  166. ever got along without it.
  167.  
  168. Perhaps you frequently squeeze or unsqueeze the same list of 
  169. files  and you would like to type the list once and be  done 
  170. with it. Use an editor (or FLS, described below) to create a 
  171. file  with  one  parameter per line.  For  example  call  it 
  172. commands.lst.
  173.  
  174. Then,
  175. A>sq <commands.lst
  176. will  cause the command list file to be read as if you  were 
  177. typing it! You will see it on the console.
  178.  
  179. That was redirected console input.  Now assume that you have 
  180. a very long list of files to squeeze or unsqueeze and  while 
  181. you  are  taking a nap the progress comments and maybe  some 
  182. error  comments  scroll  off  the  screen.  Redirecting  the 
  183. console   output   will  let  you  capture   the   progress 
  184. information  in a file so you can check it later.  The error 
  185. comments will have the screen to themselves.
  186.  
  187. For example,
  188. A>sq <commands.lst >out
  189. will send the progress comments to the file "out", which you 
  190. can TYPE later.  The routine display of the program name and 
  191. version, etc., will still go to the console.
  192.  
  193. A more practical example is to send that information to  the 
  194. console and to the file.
  195. A>sq <commands.lst +out
  196. will do that.
  197.  
  198. Redirected  input  and output are independent - you  can  do 
  199. either, both or neither.
  200.  
  201. There is one more form of redirection called a "pipe". It is 
  202. by far the most important to you.  Recall that I promised to 
  203. tell  you how to use ambiguous file names such as *.asm (all 
  204. files  of  type asm on the current default drive)  or  *.?q? 
  205. (all files having a "q" as the second letter of their type). 
  206. That last example just happens to mean "all squeezed files", 
  207. assuming  you don't have any other files with such  a  silly 
  208. name (I hope).
  209.  
  210. I  have  provided  a program called FLS  which  is  intended 
  211. primarily for use in pipes. Here is an example:
  212. A>fls c: x.asm y*.asm >temp.$$$
  213. will  simply  pass the first two parameters through  to  the 
  214. console output,  which is being redirected to a file  called 
  215. temp.$$$.  But  the third parameter will be replaced by  all 
  216. the  files  on the current drive which are of type  asm  and 
  217. have names beginning with y.
  218.  
  219. FLS  is  smart  enough to know that a letter followed  by  a 
  220. colon and nothing else is a destination drive name  intended 
  221. for  SQ or USQ.  It will also treat any parameter  beginning 
  222. with  a  - (minus sign) as an option to be  passed  through. 
  223. Anything  else  is considered a file name or pattern and  is 
  224. checked against the directory of the appropriate drive.
  225.  
  226. Therefore you could use:
  227. A>fls b: c:*.aqm *.aqm -10 stuff.dqc >temp.$$$
  228. A>usq <temp.$$$
  229. A>era temp.$$$
  230. to unsqueeze all files of type aqm on drives C and A and put 
  231. the unsqueezed files on drive B,  and then preview the first 
  232. 10 lines of file stuff.dqc.
  233.  
  234. Here  is where the pipe comes in.  The above three  commands 
  235. can be abbreviated as:
  236. A>fls b: c:*.aqm *.aqm -10 stuff.dqc |usq
  237.  
  238. That  little  "|" is the pipe option and it causes  the  FLS 
  239. output to be redirected to a temporary file and when that is 
  240. done  it  actually  runs USQ for you with the  proper  input 
  241. redirection and then erases the temporary file.
  242.  
  243. If  that  isn't  enough,  you  can still  use  the  +  or  > 
  244. redirection  option  at the end of that line to capture  the 
  245. console output from USQ.
  246. A>fls b: c:*.aqm *.aqm -10 stuff.dqc |usq >out
  247.  
  248. If you plan your comments carefully you can produce a single 
  249. file containing an abstract of an entire library of squeezed 
  250. files in one step!
  251. A>fls -25 *.?q? |usq >abstract
  252.  
  253. One  final point.  Anywhere you specify a file name you  can 
  254. specify a drive in front of it.  That applies to redirection 
  255. and well as files to be squeezed and unsqueezed.  If a  name 
  256. begins  with a - (minus sign) it will look like an option to 
  257. FLS unless you put a drive name in front of it (b:-sq.077).
  258.  
  259. USAGE SUMMARY:
  260. The previous section gradually presented the various options 
  261. by example. This section gives a condensed and more abstract 
  262. description  and is intended for reference.  If you couldn't 
  263. see  the forest for the trees,  maybe this will give  you  a 
  264. better view.
  265.  
  266. The parameter handling of these programs is straightforward. 
  267. Parameters  fall into two classes:  directed i/o options and 
  268. operational parameters . Note that parameters read from files 
  269. or  from the console are not forced to upper case,  but  the 
  270. internal  file  handling routines all treat  lower  case  as 
  271. upper case.
  272.  
  273. When  a  file to be written already exists,  it  is  quietly 
  274. overwritten.
  275.  
  276.  
  277.  
  278. Directed I/O parameters:
  279. The  first  action  taken by these programs  is  to  process 
  280. directed  i/o parameters from the CP/M command  line.  These 
  281. parameters are optional and take the forms:
  282.  
  283.      <file     read console input from file
  284.      >file     send most console output to file
  285.      +file     send most console output to file and console
  286.      |pgm ...  send most console output to a temporary file
  287.                then run PGM.COM and take console input
  288.                from the temporary file. "..." represent the
  289.                parameters for PGM. This is called "piping".
  290.  
  291. Only  one input and one output redirection can apply to each 
  292. program. After the program has arranged for any directed i/o 
  293. parameters to be obeyed they are deleted from the  parameter 
  294. list seen by the rest of the program.
  295.  
  296. Operational parameters:
  297. The   program  then  checks  if  there  are  any   remaining 
  298. parameters from the CP/M command line.  If there  are,  they 
  299. are obeyed. If and only if there are no remaining parameters 
  300. on  the  command line,  the program prompts for them at  the 
  301. console.  If  console input has been directed to a file  one 
  302. parameter  is  read and obeyed from each line of  the  file. 
  303. Otherwise,  the  user  follows each typed parameter  with  a 
  304. RETURN and an empty command exits the program.
  305.  
  306. Each  operational parameter is obeyed without looking  ahead 
  307. to  other  parameters,  so options should precede  the  file 
  308. names to which they apply.
  309.  
  310. SQ operational parameters are a list of the following types:
  311.      drive:         set the current destination drive
  312.      filename       file to be squeezed
  313.      drive:filename  "   "    "    "
  314.  
  315. SQ does not change the files being squeezed. New, squeezed 
  316. files are created on the destination drive (defaults to  the 
  317. current drive) with names derived from the original name but 
  318. with  the second letter of the file type (extention) changed 
  319. to Q.  When there is no type, QQQ is used. The original name 
  320. is saved in the squeezed file.
  321.  
  322. USQ  operational  parameters  are a list  of  the  following 
  323. types:
  324.      drive:         set the current destination drive
  325.      filename       file to be squeezed
  326.      drive:filename  "   "    "    "
  327.      -count         Preview (display on the console) the first
  328.                     "count"  lines  of  each   file,   where 
  329.                     "count" is a number from 1 to 65535.
  330.  
  331. If  the  -count  option IS NOT in effect  then  USQ  creates 
  332. unsqueezed  versions of the listed files on the  destination 
  333. drive,  which  defaults to the current  logged  drive.  Each 
  334. unsqueezed  file is CRC checked against the CRC value of the 
  335. original file, which is part of the squeezed file.
  336.  
  337. The  -count  option is for  previewing  squeezed  files.  It 
  338. allows  you  to  skim  through a group  of  squeezed  files, 
  339. peeking  at  the first "count" lines in each.  The  >  or  + 
  340. output  redirection  option could be used  to  capture  this 
  341. information  in a file,  along with the corresponding  file 
  342. names, thus forming an abstract of the files on a disk.
  343.  
  344. When  the  -count option is used the CRC check is  cancelled 
  345. and  the  output is forced into printable form by  stripping 
  346. the  parity bit and changing most unprintable characters  to 
  347. periods.  The exceptions are CR,  LF, TAB and FF. The output 
  348. from  each file is terminated by an FF.  PIP can be used  to 
  349. strip FFs and provide formatted printing if desired. "Count" 
  350. defaults to the maximum value,  65,535,  in case you want to 
  351. look at a whole file.
  352.  
  353. FLS operational parameters:  FLS is a "filter",  which means 
  354. it  accepts input from the console input or command line and 
  355. transforms the input according to a set of rules to  produce 
  356. console  output.  That's fine for getting familiar with FLS, 
  357. but to make it useful you "pipe" its output to the input  of 
  358. SQ or USQ.
  359.  
  360. Any FLS parameter which is of the form:
  361.      drive:
  362. or   -anything
  363. is  copied  to console output unchanged.
  364.  
  365. Any  other  FLS operational parameter is treated as  a  file 
  366. name and is checked against the directory of the appropriate 
  367. drive. If it contains * or ? it is replaced by a list of all 
  368. the files which fit the pattern.  If nothing is found in the 
  369. directory  an error comment is sent to the console,  even if 
  370. normal console output has been redirected to a file.
  371.  
  372. IMPORTANT:  when  using  a pipe from FLS or any other  input 
  373. redirection to get the file list,  etc.,  on which USQ or SQ 
  374. are  to operate you must NOT put any parameters  other  than 
  375. redirection  following  the program name.  They must be  all 
  376. together in the input parameter list. Example:
  377.  
  378. A>fls -10  b:*.cq |usq +saveout
  379. is  the  proper way to preview the top (first 10  lines)  of 
  380. each  squeezed  .C file on the B drive.  The -10  is  passed 
  381. through  FLS  to USQ.  The results will be displayed on  the 
  382. console  and  saved in file "saveout" on the  A  drive.  The 
  383. saveout  file lets you confirm the list of  processed  files 
  384. even  if  the display scrolls off the screen  while  running 
  385. unattended.
  386.  
  387. In summary, i/o redirection parameters (those prefixed by +, 
  388. <,  >,  or |) always follow the command to which they apply, 
  389. but  operational parameters  (destination  drive,  -options) 
  390. must be with the file name list.
  391.  
  392. EXAMPLES:
  393. 1. Unsqueeze all squeezed files on the current drive and put 
  394. the resulting unsqueezed files on the same drive.
  395.      A>fls *.?q? |usq
  396.  
  397. 2.  Look  at  the first 10 lines of every squeezed  file  on 
  398. drive B.
  399.     A>fls -10 b:*.?Q? |usq
  400. note  that since the file names for USQ came from  FLS,  the 
  401. count option had to come from there too.
  402.  
  403. 4.  Squeeze all .ASM files on the B and C drives and put the 
  404. squeezed files on the D drive.
  405.      A>fls d: b:*.asm c:*.asm |sq
  406. Note that if d:  had not been first the squeezed files would 
  407. have gone to the A drive.
  408.  
  409. 5.  Squeeze file xyz.c on the A drive and put the results on 
  410. the A drive.
  411.      A>sq xyz.c
  412.  
  413. 6.  Build  a  parameter list of all ASM files on drive C  in 
  414. file XX.PAR and view it on the console.
  415.      A>fls c:*.asm +xx.par
  416.  
  417. 7. Use the above list to squeeze the files to the A drive.
  418.      A>sq <xx.par
  419.  
  420. 8. As above, but results to the B drive.
  421.      A>b:
  422.      B>a:sq <a:xx.par
  423.  
  424. 9.  Squeeze  all ASM and C files on the A drive and put  the 
  425. results on the B drive. Capture the progress comments in the 
  426. file "out" without displaying them.
  427.      A>fls b: *.asm *.c |sq >out
  428.  
  429. 10.  Preview  the first 24 lines of each squeezed  ASM  file 
  430. THEN unsqueeze them (unless stopped via cntl-C).
  431.      A>fls -24 *.aqm a: *.aqm |usq
  432. Note  that  specification  of a  destination  drive  cancels 
  433. previewing.
  434.  
  435. RECOMPILATION:
  436. These programs are written in C and the instructions are for 
  437. the BDS C compiler. The libraries must have been adapted for 
  438. directed i/o as described in DIO2.C.
  439.  
  440. The  procedures below indicate the various C language source 
  441. files  (file  type .C) required to  recompile.  Those  files 
  442. contain  #include statements which cause header files  (file 
  443. type  .H) to be read and compiled.  The BDSCIO.H header file 
  444. contains information about your system,  including how  much 
  445. space  to reserve for file buffers.  You should use your own 
  446. version of this file.
  447.  
  448. The source files DIO2.C, SQDIO.C and USQDIO.C are identical! 
  449. If you only get one,  just use PIP to create the rest.  They 
  450. are separate only to provide separate CRL files,  which  are 
  451. needed  because of the different external variable  options. 
  452. Note  that  they  do  not  include  all  the  header  files, 
  453. therefore  the  other  source  files must  include  the  dio 
  454. related headers first.
  455.  
  456. DIO.C is supplied with BDS C.  The above three files  differ 
  457. from  the official version only by a change to the  dioflush 
  458. function to ensure TEMPIN.$$$ is deleted before another file 
  459. is renamed to that name.  (CP/M is stupid enough to make two 
  460. files of the same name!).
  461.  
  462. The procedure for building the SQ.COM and USQ.COM files from 
  463. their  source files follows.  Note that I have  renamed  the 
  464. first  phase  of the BDS C compiler to CC.COM.  Also I  will 
  465. assume  the BDS C package is on drive D and the SQ  and  USQ 
  466. related files are on B along with BDSCIO.H and DIO.H.
  467.  
  468. Each  CC command produces a CRL file with specific addresses 
  469. for  external variables.  If you recompile a file  with  the 
  470. same  value in the -e option you don't have to recompile the 
  471. other  files,  just  do the desired CC and then  repeat  the 
  472. entire CLINK.
  473.  
  474. CLINK's -s option prints statistics. Top of memory means the 
  475. current TPA. Stack space is what's left over. These programs 
  476. require  stack  space for local  variables,  including  some 
  477. healthy i/o buffers.  Also some functions are recursive.  If 
  478. SQ doesn't have several K of stack space it will probably go 
  479. crazy and do almost anything.
  480.  
  481. For SQ (note not all use -o):
  482. D>cc b:sq.c -o -e3200
  483. D>cc b:sqdio.c -e3200
  484. D>cc b:tr1.c -o -e3200
  485. D>cc b:tr2.c -o -e3200
  486. D>cc b:io.c -o -e3200
  487. D>clink b:sq sqdio tr2 tr1 io -s
  488.  
  489. The linker will display some statistics. Check that the last 
  490. code  address is less than the start address of the external 
  491. variables (3200 in this example).  If not,  repeat the above 
  492. with a higher address in the -e options.
  493.  
  494. For USQ (note: -e2800 may be enough. Note not all use -o):
  495. D>cc b:usq.c -o -e2900
  496. D>cc b:usqdio.c -e2900
  497. D>cc b:utr.c -o -e2900
  498. D>clink b:usq usqdio utr -s
  499.  
  500. Check the addresses as described above.
  501.  
  502. For FLS:
  503. D>cc b:fls.c
  504. D>cc b:dio2.c
  505. D>clink b:fls dio2
  506.  
  507. IN CASE OF TROUBLE:
  508. I  welcome  suggestions  and  bug  reports,   but  you  must 
  509. understand that some of the ideas I get would involve almost 
  510. as much program development as the original package.  I have 
  511. what I want and (I hope) what most users want,  so I am  not 
  512. motivated  to  spend  many more  months  creating  something 
  513. entirely  different  which  just  happens  to  involve  data 
  514. compression. The data compression routines are probably less 
  515. than  half of this package,  and are designed to operate  on 
  516. large blocks of data, such as files.
  517.  
  518.         Dick Greenlaw
  519.                 251 Colony Ct.
  520.                 Gahanna, Ohio 43230
  521.                 614-475-0172 weekends and evenings
  522.