home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / CPM / UTILS / SQUSQ / CRUNCH.INF < prev    next >
Text File  |  2000-06-30  |  11KB  |  192 lines

  1.  
  2.                                CRUNCH.TXT
  3.  
  4. Background on CRUNCH, from author Steven Greenberg's documentation.
  5.  
  6. ---------
  7.  
  8.      In order to make a practical stand alone "cruncher" that was easy
  9. to use, especially for those already familiar with squeezers, some
  10. header information had to be included in the resulting "crunched" file
  11. (eg. the filename of the original file, etc.).  I have defined a header
  12. based on the time tested squeezed file format, with some necessary
  13. changes and a few additions.  The additions are mostly to insure that
  14. files crunched now will always be un-crunchable with future versions of
  15. the uncruncher, no matter what possible enhancements are made.  Those
  16. familiar with the MS-DOS ARC.xxx program have probably seen this idea in
  17. action.  More on this later.
  18.  
  19.      Another slight problem with LZWCOM and LZWUNC had to do with the
  20. question of termination.  When the input file was exhausted during
  21. compression, it was unlikely the output file was on a sector boundary.
  22. No matter what the rest of the final output sector was padded with
  23. ("1A"'s were used), the uncruncher would try to uncrunch those bytes
  24. (since all data is conceivably valid).  This resulted in occasional
  25. extra sectors of garbage following an otherwise properly decoded file.
  26. While this did not usually cause a problem, it was certainly not
  27. desirable.
  28.  
  29.      I have chosen to handle the termination problem the same way it
  30. was handled with squeezed files; by dedicating a unique code to
  31. represent EOF (End Of Field).  By only allowing 4095 instead of 4096
  32. different codes (not a major shortcoming), code 000 can become a
  33. dedicated EOF.  As soon as it is encountered on the input file, the
  34. decoding process is known to be complete.  For those who are interested,
  35. the exact code put out by CRUNCH can be duplicated by the "C" program
  36. LZWCOM if table entry zero "artificially" flagged as "used" (before
  37. initializing the table).  That insures that the code will never come up,
  38. except when manually inserted at the end of file.
  39.  
  40.      The other functional difference from LZWCOM involves repeat byte
  41. coding.  CRUNCH converts the "physical input stream" into a "logical
  42. input stream", which is then handed to the cruncher.  The conversion
  43. takes 3 or more contiguous occurrences of the same byte and encodes them
  44. as <byte> "90H" <count> where "count" is the number of "additional"
  45. occurrences of <byte> (ie total occurrences -1).  90H itself is encoded
  46. as "90H", "00".  This scheme is identical to that used in standard
  47. squeezing.
  48.  
  49.      Crunching requires only one pass through the input file, while
  50. squeezing requires two.  While this is one of its significant
  51. advantages, it does complicate the problem of including a checksum, if
  52. one is desired, in the header of the result file (since the value is
  53. not known until everything is done).  A bad solution is to close the
  54. finished output file, re-open it, insert the checksum, and close it
  55. again.  A good solution is to put the checksum at the end of the output
  56. file right after the EOF.  And that's where it is.  With all this in
  57. mind, herein follows a specification for the format of a crunched file.
  58.  
  59.              ---------------------------------------------
  60.  
  61.      ID FIELD: Bytes 0 and 1 are always 076H and 0FEH, respectively.
  62. This identifies the file as "crunched".
  63.  
  64.      FILENAME: The filename field starts at byte 2.  It is a field of
  65. variable length, terminated by a zero byte.  The field contains the
  66. filename as ASCII characters, including an ASCII "." immediately
  67. preceding the filename's extension.  Less than eight characters may
  68. precede the "."; there is no necessity to pad the filename with blanks.
  69. Additional characters after the third extension character but before the
  70. zero byte specifically are allowed and will be ignored by the current
  71. uncruncher.  This allows an area of unlimited size for date stamping, or
  72. other miscellaneous information which a future cruncher or application
  73. program might want to insert, for use or display by some uncrunching
  74. program.  By skipping over these bytes now, future incompatibilities are
  75. eliminated.
  76.  
  77.      Following the zero byte are the following 4 bytes, in order:
  78.  
  79.      REFERENCE REVISION LEVEL: 1 byte }
  80.      SIGNIFICANT REVISION LEVEL: 1 byte } described later
  81.      ERROR DETECTION TYPE: 1 byte }
  82.      SPARE: 1 byte }
  83.  
  84.      CRUNCHED OUTPUT: After the SPARE byte, the actual crunched output
  85. finally begins.  The crunched output is a series of 12-bit codes in
  86. "natural" order.  (Every other 12-bit code starts on a byte boundary
  87. and includes the 4 ms bits of the next byte.  The "odd" codes start in
  88. the middle of a byte and include the whole following byte as the
  89. remaining 8 ls bits).  A 12-bit code of 000 is an EOF, as explained
  90. above.  If the EOF code itself ends in the middle of a byte, an
  91. additional 4 bits of zero are padded on to get back on a byte boundary
  92. for the checksum.
  93.  
  94.      CHECKSUM: The next two bytes are the 16-bit checksum, least
  95. significant byte first.  The checksum is the modula 2^16 sum of all the
  96. bytes as input from the physical input stream, prior to repeat byte
  97. encoding (or, in the case of uncrunching, as output to the physical
  98. output stream, after repeat byte decoding).
  99.  
  100.      REMAINDER OF THE SECTOR: The remaining bytes in the sector
  101. following the checksum are irrelevant.  CRUNCH fills them with "1A"'s.
  102.  
  103.              ---------------------------------------------
  104.  
  105.      These are the four bytes not fully described above:
  106.  
  107.      "Reference Revision Level": The program/revision level of the
  108. program that performed the crunch operation.  This byte is put in for
  109. general reference only.  The current value is "20" (hex).
  110.  
  111.      "Significant Revision Level": If the value of this byte in a
  112. crunched data file exceeds the value contained within the uncrunching
  113. program, the message "File requires newer revision of program" will be
  114. displayed.  If changes or enhancements are ever made to CRUNCH which
  115. are significant enough to actually output an incompatible file, the
  116. information in this byte will allow a new revision of UNCR to be
  117. compatible with all existing data files, old or new.  The error message
  118. gets displayed only if someone tries to uncrunch a new file with an old
  119. uncruncher which doesn't know about the "future" format yet.  Current
  120. value is "23" (hex).
  121.  
  122.      "Error Detection Type":  If this value is non-zero, the current
  123. uncruncher will not examine the checksum or give an error associated
  124. with it.  This will permit a CRC type (or no error checking) value to be
  125. used if circumstances warrant it.  The current UNCR program is always
  126. checking for "illegal" codes, which are ones which have not been defined
  127. by previous codes.  If any are encountered, the message "Invalid
  128. Crunched File" is displayed.  This inherent self-checking probably
  129. precludes the necessity of more advanced error checking.
  130.  
  131.      "Spare": The SPARE byte is a spare byte.
  132.  
  133.      Notes from CRUNCH 2.3.
  134.  
  135.      CRUNCH 1.x maintained a table representing up to 4096 strings of
  136. varying lengths using the so called LZW algorithm, which has been
  137. described in the earlier documentation.  These strings were entered
  138. into a table in a manner where the strings content was used to
  139. determine the physical location (hashing), and that location was used
  140. as the output code.  Hash "collisions" were resolved by maintaining
  141. another 12 bits of data per entry which was a "link", or pointer to
  142. another entry.
  143.  
  144.      In contrast, CRUNCH 2.x uses an "open-addressing, double hashing"
  145. method similar to that employed in the UNIX COMPRESS.  This method
  146. involves a table of length 5003, where only 4096 entries are ever made,
  147. insuring the table never gets much more than about 80% full.  When a
  148. hash collision occurs, a secondary hash function is used to check a
  149. series of additional entries until an empty entry is encountered.  This
  150. method creates a table filled with many criss-crossed "virtual" chains,
  151. without the use of a "link" entry in the table.
  152.  
  153.      One reason this is important is that [without using any additional
  154. memory] the 1 1/2 bytes which were previously allocated as a link can
  155. now become the [output] code number.  This enables us to assign code
  156. numbers, which are kept right alongside the entry itself, independently
  157. of the entry's physical location.  This allows the codes to be assigned
  158. in order, permitting the use of 9-bit representations until there are
  159. 512 codes in the table, after which 10 bit representations are output,
  160. etc.
  161.  
  162.      The variable bit length method has three ramifications.  It is
  163. particularly helpful when encoding very short files, where the table
  164. never even fills up.  It also provides a fixed additional savings (not
  165. insubstantial) even when the table does fill up.  Thirdly, it reduces
  166. the overhead associated with an "adaptive reset" to the point where it
  167. becomes a very viable alternative.  "Adaptive reset" simply means
  168. throwing out the whole table and starting over.  This can be quite
  169. advantageous when used properly.  CRUNCH v2.x employs this provision,
  170. which was not incorporated in the V1.x algorithm.
  171.  
  172.      "Code reassignment" is an advancement the author of CRUNCH, Steven
  173. Greenberg, has introduced with the release of CRUNCH v2.0 based on
  174. original work.  It is not used in COMPRESS, any MS-DOS ARC program, or
  175. any other data compression utility currently available.  There are many
  176. ways one might go about this (and at least as many possible pitfalls).
  177. The algorithm selected seemed to represent a good tradeoff between
  178. speed, memory used, and improved performance, while maintaining
  179. "soundness of algorithm" (ie it works).
  180.  
  181.      Briefly, it works as follows: Once the table fills up, the code
  182. reassignment process begins.  (At this same time, the possibility of
  183. adaptive reset is also enabled).  Whenever a new code would otherwise
  184. be made (if the table weren't full), the entries along the hash chain
  185. which would normally contain the entry are scanned.  The first, if any,
  186. of those entries which was made but never subsequently referenced is
  187. bumped in favor of the new entry.  The uncruncher, which would not
  188. normally need to perform any hash type function, has an auxiliary
  189. physical to logical translation table, where it simulates the hashing
  190. going on in the cruncher.  In this fashion it is able to exactly
  191. reproduce the reassignments made my the cruncher, which is essential.
  192.