home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume31 / freeze / patch05 < prev    next >
Encoding:
Text File  |  1992-08-21  |  28.6 KB  |  1,121 lines

  1. Newsgroups: comp.sources.misc
  2. From: leo@ipmce.su (Leonid A. Broukhis)
  3. Subject:  v31i089:  freeze - Freeze/melt compression program 2.3, Patch05
  4. Message-ID: <1992Aug18.215658.29273@sparky.imd.sterling.com>
  5. X-Md4-Signature: d64313176f1e0ff48b0941206b3eb8e6
  6. Date: Tue, 18 Aug 1992 21:56:58 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: leo@ipmce.su (Leonid A. Broukhis)
  10. Posting-number: Volume 31, Issue 89
  11. Archive-name: freeze/patch05
  12. Environment: ISC, Xenix, SunOS, MS-DOS
  13. Patch-To: freeze: Volume 25, Issue 12-13
  14.  
  15. Main enhancements:
  16.  - compression speed (without reducing compression rate)
  17.    was significantly increased;
  18.  - other small contributed patches.
  19.  
  20. *** distribution/README    Thu Jul 16 15:20:51 1992
  21. --- README    Mon Aug 17 17:02:12 1992
  22. ***************
  23. *** 12,29 ****
  24.       o M_XENIX & !M_I386     Makes arrays < 65536 bytes each
  25.       o BSD                   Allow long filenames ( > 14 characters) &
  26.                   Call setlinebuf(stderr)
  27. !     o INT_SIG               signal is int (*)() unstead of void
  28.       o MSDOS                 Turns off some UNIX-dependencies
  29. !                 and MSDOS' ones - vice versa
  30. !                 !!! It's important !!!
  31. !                 If your MSDOS' C compiler does support
  32. !                 inline functions, define DO_INLINE.
  33. !                 This will cause the main loop to be
  34. !                 replaced with a call of memcmp, which
  35. !                 will be represented as 'repz cmpsb'.
  36.       o FAST                  Forces the Get_Next_Match routine
  37.                   to be inline. This gives additional
  38. !                 percents of speedup.
  39.       o __TURBOC__            For compiling under TURBO C
  40.       o __i386__              When compiling under GNU C causes
  41.                   some fixed register allocations,
  42. --- 12,31 ----
  43.       o M_XENIX & !M_I386     Makes arrays < 65536 bytes each
  44.       o BSD                   Allow long filenames ( > 14 characters) &
  45.                   Call setlinebuf(stderr)
  46. !     o SIGTYPE               The type that is returned by signal
  47. !                 handlers.  Defaults to void.
  48.       o MSDOS                 Turns off some UNIX-dependencies
  49. !                 and MSDOS' ones - vice versa.
  50. !     o FASTHASH              Uses another hash function which gives
  51. !                 some speedup, thus reducing the compression
  52. !                 rate (!)
  53.       o FAST                  Forces the Get_Next_Match routine
  54.                   to be inline. This gives additional
  55. !                 percents of speedup on some machines
  56. !                 using some compilers (depends on
  57. !                 the number of registers, register
  58. !                 allocation strategy and subroutine call
  59. !                 overhead).
  60.       o __TURBOC__            For compiling under TURBO C
  61.       o __i386__              When compiling under GNU C causes
  62.                   some fixed register allocations,
  63. ***************
  64. *** 38,46 ****
  65.                   4.3).
  66.   
  67.   Please! If your computer supports the string operations, try to write
  68. ! "asm" instructions (GNU style) which realize the right-to-left memory
  69. ! comparison (s1, s2, length) in minimum number of clock cycles.
  70. ! If a noticeable (5% or more) speedup is gained, please send me a message.
  71.   
  72.   Other preprocessor symbols (DEBUG, GATHER_STAT) are for internal use
  73.   only.
  74. --- 40,49 ----
  75.                   4.3).
  76.   
  77.   Please! If your computer supports the string operations, try to write
  78. ! "asm" instructions (GNU style) which realize the memory comparison
  79. ! "(s1, s2, maxlength) --> matched length" in the minimum number of clock
  80. ! cycles.  If a noticeable (5% or more) speedup is gained, please send
  81. ! me a message.
  82.   
  83.   Other preprocessor symbols (DEBUG, GATHER_STAT) are for internal use
  84.   only.
  85. ***************
  86. *** 126,131 ****
  87. --- 129,136 ----
  88.   gif =   0 0 0 0 2 60 0 0        # This is NOT! optimal data
  89.                   # for GIF files
  90.   doc=0 0 1 2 7 16 36 0           # The sample was gcc.lp
  91. + greedy2=0 1 1 2 5 8 11 34       #
  92.   # End of file
  93.   ---------- cut here -----------
  94.   
  95. ***************
  96. *** 144,150 ****
  97.   ------------------- BUGS ----------------------------
  98.   
  99.   Please send descriptions of found bugs, incompatibilities, etc.  to
  100. ! leo@s514.ipmce.su.  MS-DOS version will not be supported in future
  101.   versions !!  (If they will be :-) )
  102.   
  103.   ------------ SPEED & COMPRESSION RATE ---------------
  104. --- 149,155 ----
  105.   ------------------- BUGS ----------------------------
  106.   
  107.   Please send descriptions of found bugs, incompatibilities, etc.  to
  108. ! leo@ipmce.su.  MS-DOS version might not be supported in future
  109.   versions !!  (If they will be :-) )
  110.   
  111.   ------------ SPEED & COMPRESSION RATE ---------------
  112. *** distribution/encode.c    Thu Jul 16 15:20:58 1992
  113. --- encode.c    Thu Jul 30 13:19:42 1992
  114. ***************
  115. *** 6,13 ****
  116.   /* for future versions ?... */
  117.   
  118.   #define LENGTH_OFFSET   256
  119. ! #define EncodeLiteral(l)        EncodeChar(l)
  120. ! #define EncodeLength(l)         EncodeChar(l + LENGTH_OFFSET)
  121.   
  122.   /*
  123.    * Freezes stdin to stdout
  124. --- 6,13 ----
  125.   /* for future versions ?... */
  126.   
  127.   #define LENGTH_OFFSET   256
  128. ! #define EncodeLiteral(l)        EncodeChar((int)l)
  129. ! #define EncodeLength(l)         EncodeChar((int)l + LENGTH_OFFSET)
  130.   
  131.   /*
  132.    * Freezes stdin to stdout
  133. ***************
  134. *** 15,23 ****
  135.   
  136.   void freeze ()
  137.   {
  138. !     register us_t i, len, r, s;
  139. !     register short c;
  140. !     int greedy_threshold = CHAIN_THRESHOLD / (3 * greedy + 3);
  141.       putchar(MAGIC1);
  142.       putchar(MAGIC2_2);
  143.   
  144. --- 15,21 ----
  145.   
  146.   void freeze ()
  147.   {
  148. !     register int i, len, r, s, c;
  149.       putchar(MAGIC1);
  150.       putchar(MAGIC2_2);
  151.   
  152. ***************
  153. *** 65,78 ****
  154.                   fprintf(stderr, "'%s'\n",
  155.                       pr_char(text_buf[r]));
  156.   #endif /* DEBUG */
  157. !         } else if (match_length >= greedy_threshold) {
  158.   /* GREEDY parsing (compression rate 1.5% worse, but 40% faster) */
  159.   
  160. !             EncodeLength((us_t) (match_length - THRESHOLD));
  161. !             EncodePosition((us_t)match_position);
  162.   
  163.           } else {
  164. !             register us_t orig_length, orig_position, oldchar;
  165.   
  166.   /* This fragment (delayed coding, non-greedy) is due to ideas of
  167.       Jan Mark Wams' <jms@cs.vu.nl> COMIC:
  168. --- 63,77 ----
  169.                   fprintf(stderr, "'%s'\n",
  170.                       pr_char(text_buf[r]));
  171.   #endif /* DEBUG */
  172. !         } else if (greedy) {
  173.   /* GREEDY parsing (compression rate 1.5% worse, but 40% faster) */
  174.   
  175. !             EncodeLength(match_length - THRESHOLD);
  176. !             EncodePosition(match_position);
  177.   
  178.           } else {
  179. !             register int orig_length, orig_position;
  180. !             register us_t oldchar;
  181.   
  182.   /* This fragment (delayed coding, non-greedy) is due to ideas of
  183.       Jan Mark Wams' <jms@cs.vu.nl> COMIC:
  184. ***************
  185. *** 88,96 ****
  186.               if (match_length > len) match_length = len;
  187.   
  188.               if (orig_length >= match_length) {
  189. !                 EncodeLength((us_t)
  190. !                     (orig_length - THRESHOLD));
  191. !                 EncodePosition((us_t)orig_position);
  192.   #ifdef DEBUG
  193.                   match_position = orig_position;
  194.   #endif  /* DEBUG */
  195. --- 87,94 ----
  196.               if (match_length > len) match_length = len;
  197.   
  198.               if (orig_length >= match_length) {
  199. !                 EncodeLength(orig_length - THRESHOLD);
  200. !                 EncodePosition(orig_position);
  201.   #ifdef DEBUG
  202.                   match_position = orig_position;
  203.   #endif  /* DEBUG */
  204. ***************
  205. *** 106,113 ****
  206.                   EncodeLength(match_length - THRESHOLD);
  207.                   EncodePosition(match_position);
  208.               }
  209. ! #ifdef DEBUG
  210.               refers_out ++;
  211.               if (verbose) {
  212.                   register short pos =
  213.                       (r - 1 - match_position) & (N2 - 1),
  214. --- 104,114 ----
  215.                   EncodeLength(match_length - THRESHOLD);
  216.                   EncodePosition(match_position);
  217.               }
  218. ! #if defined(GATHER_STAT) || defined (DEBUG)
  219.               refers_out ++;
  220. + #endif
  221. + #ifdef DEBUG
  222.               if (verbose) {
  223.                   register short pos =
  224.                       (r - 1 - match_position) & (N2 - 1),
  225. ***************
  226. *** 159,167 ****
  227.        */
  228.       if(quiet != 1) {
  229.   #ifdef GATHER_STAT
  230. !     fprintf(stderr, "Average number of steps: ");
  231. !     fprintf(stderr, "%d.%02d\n", (int) (node_steps / node_matches),
  232. !             (int)((node_steps * 100 / node_matches) % 100));
  233.   #endif
  234.   #ifdef DEBUG
  235.       fprintf( stderr,
  236. --- 160,171 ----
  237.        */
  238.       if(quiet != 1) {
  239.   #ifdef GATHER_STAT
  240. !     fprintf(stderr, "Average number of compares per matching: %d.%02d\n",
  241. !         (int) (node_compares / node_matches),
  242. !         (int)((node_compares * 100 / node_matches) % 100));
  243. !     fprintf(stderr, "Average number of prolongations per compare: %d.%02d\n",
  244. !         (int) (node_prolongations / node_compares),
  245. !         (int)((node_prolongations * 100 / node_compares) % 100));
  246.   #endif
  247.   #ifdef DEBUG
  248.       fprintf( stderr,
  249. *** distribution/freeze.1    Wed Feb 26 14:40:06 1992
  250. --- freeze.1    Mon Aug 17 17:02:13 1992
  251. ***************
  252. *** 62,70 ****
  253.   If the
  254.   .B \-g
  255.   flag is given, a slightly less powerful (compression
  256. ! rate is 1.5% less), but 40% faster heuristic is used. The more times this
  257. ! flag is present, the faster program works and the less compression
  258. ! rate is. This flag is quite useful when freezing bitmaps.
  259.   .PP
  260.   If the
  261.   .B \-f
  262. --- 62,70 ----
  263.   If the
  264.   .B \-g
  265.   flag is given, a slightly less powerful (compression
  266. ! rate is 1.5% less), but 40% faster heuristic is used. This flag may be
  267. ! used twice (this mode is quite useful when freezing bitmaps) for
  268. ! additional speedup.
  269.   .PP
  270.   If the
  271.   .B \-f
  272. *** distribution/freeze.c    Thu Jul 16 15:20:59 1992
  273. --- freeze.c    Thu Jul 30 13:27:11 1992
  274. ***************
  275. *** 95,102 ****
  276.   short debug = 0;
  277.   short verbose = 0;
  278.   char * pr_char();
  279. ! long symbols_out = 0, refers_out = 0;
  280.   #endif /* DEBUG */
  281.   
  282.   /* Do not sleep when freeze works :-) */
  283.   long indc_count, indc_threshold;
  284. --- 95,106 ----
  285.   short debug = 0;
  286.   short verbose = 0;
  287.   char * pr_char();
  288. ! long symbols_out = 0;
  289.   #endif /* DEBUG */
  290. + #if defined(GATHER_STAT) || defined(DEBUG)
  291. + long refers_out = 0;
  292. + #endif
  293.   
  294.   /* Do not sleep when freeze works :-) */
  295.   long indc_count, indc_threshold;
  296. *** distribution/freeze.h    Thu Jul 16 15:20:59 1992
  297. --- freeze.h    Wed Jul 29 21:54:52 1992
  298. ***************
  299. *** 4,13 ****
  300. --- 4,21 ----
  301.   #include <sys/stdtypes.h>
  302.   #else   /* SUN4 */
  303.   # ifndef getc
  304. + #  ifdef m88k            /* Green Hill C library bug. */
  305. + #   define getc(p)         (--(p)->_cnt < 0 ? __filbuf(p) : (int) *(p)->_ptr++)
  306. + #  else
  307.   #   define getc(p)         (--(p)->_cnt < 0 ? _filbuf(p) : (int) *(p)->_ptr++)
  308. + #  endif
  309.   # endif
  310.   # ifndef putc
  311. + #  ifdef m88k            /* Green Hill C library bug. */
  312. + #   define putc(x, p)      (--(p)->_cnt < 0 ? __flsbuf((unsigned char) (x), (p)) : (int) (*(p)->_ptr++ = (unsigned char) (x)))
  313. + #  else
  314.   #   define putc(x, p)      (--(p)->_cnt < 0 ? _flsbuf((unsigned char) (x), (p)) : (int) (*(p)->_ptr++ = (unsigned char) (x)))
  315. + #  endif
  316.   # endif
  317.   #endif  /* SUN4 */
  318.   
  319. ***************
  320. *** 87,95 ****
  321.   # else /* TOS */
  322.   #  include <ext.h>
  323.   # endif  /* MSDOS */
  324. - #if !defined(SIGTYPE)
  325. - #define SIGTYPE void
  326. - #endif
  327.   #endif /* __TURBOC__ */
  328.   
  329.   typedef unsigned short us_t;
  330. --- 95,100 ----
  331. ***************
  332. *** 136,146 ****
  333.   extern short debug;
  334.   extern short verbose;
  335.   extern char * pr_char();
  336. ! extern long symbols_out, refers_out;
  337.   #endif /* DEBUG */
  338.   
  339. ! #ifdef GATHER_STAT
  340. ! extern long node_steps, node_matches;
  341.   #endif
  342.   
  343.   extern short DecodeChar(), DecodePosition(), GetNBits();
  344. --- 141,151 ----
  345.   extern short debug;
  346.   extern short verbose;
  347.   extern char * pr_char();
  348. ! extern long symbols_out;
  349.   #endif /* DEBUG */
  350.   
  351. ! #if defined(GATHER_STAT) || defined(DEBUG)
  352. ! extern long refers_out;
  353.   #endif
  354.   
  355.   extern short DecodeChar(), DecodePosition(), GetNBits();
  356. ***************
  357. *** 177,179 ****
  358. --- 182,188 ----
  359.   #endif
  360.   
  361.   extern char *strchr(), *strrchr();
  362. + #ifndef SIGTYPE
  363. + #define SIGTYPE void
  364. + #endif
  365. *** distribution/huf.c    Wed Feb 26 14:39:48 1992
  366. --- huf.c    Thu Jul 30 17:55:36 1992
  367. ***************
  368. *** 76,83 ****
  369.   
  370.   void reconst ()
  371.   {
  372. !     register us_t i, j, k;
  373. !     register us_t f;
  374.   
  375.   #ifdef DEBUG
  376.       if (quiet < 0)
  377. --- 76,83 ----
  378.   
  379.   void reconst ()
  380.   {
  381. !     register int i, j, k;
  382. !     register int f;
  383.   
  384.   #ifdef DEBUG
  385.       if (quiet < 0)
  386. ***************
  387. *** 130,139 ****
  388.   /* Updates given code's frequency, and updates tree */
  389.   
  390.   void update (c)
  391. !     us_t c;
  392.   {
  393.       register us_t *p;
  394. !     register us_t i, j, k, l;
  395.   
  396.       if (freq[r] == MAX_FREQ) {
  397.           reconst();
  398. --- 130,139 ----
  399.   /* Updates given code's frequency, and updates tree */
  400.   
  401.   void update (c)
  402. !     register int c;
  403.   {
  404.       register us_t *p;
  405. !     register int i, j, k, l;
  406.   
  407.       if (freq[r] == MAX_FREQ) {
  408.           reconst();
  409. ***************
  410. *** 168,177 ****
  411.   /* Encodes the literal or the length information */
  412.   
  413.   void EncodeChar (c)
  414. !     us_t c;
  415.   {
  416.       ul_t i;
  417. !     register us_t j, k;
  418.   
  419.       i = 0;
  420.       j = 0;
  421. --- 168,177 ----
  422.   /* Encodes the literal or the length information */
  423.   
  424.   void EncodeChar (c)
  425. !     int c;
  426.   {
  427.       ul_t i;
  428. !     register int j, k;
  429.   
  430.       i = 0;
  431.       j = 0;
  432. ***************
  433. *** 202,208 ****
  434.   /* Encodes the position information */
  435.   
  436.   void EncodePosition (c)
  437. !     register us_t c;
  438.   {
  439.       register us_t i;
  440.   
  441. --- 202,208 ----
  442.   /* Encodes the position information */
  443.   
  444.   void EncodePosition (c)
  445. !     register int c;
  446.   {
  447.       register us_t i;
  448.   
  449. ***************
  450. *** 221,227 ****
  451.   
  452.   short DecodeChar ()
  453.   {
  454. !     register us_t c;
  455.       c = son[r];
  456.   
  457.       /* trace from root to leaf,
  458. --- 221,227 ----
  459.   
  460.   short DecodeChar ()
  461.   {
  462. !     register int c;
  463.       c = son[r];
  464.   
  465.       /* trace from root to leaf,
  466. *** distribution/lz.c    Thu Jul 16 15:20:59 1992
  467. --- lz.c    Thu Aug  6 18:16:58 1992
  468. ***************
  469. *** 8,16 ****
  470.   /*----------------------------------------------------------------------*/
  471.   
  472.   uc_t    text_buf[N2 + F2 - 1];          /* cyclic buffer with an overlay */
  473. ! us_t    match_position, match_length;   /* current characteristics of a
  474.                           matched pattern */
  475. ! us_t    chain_length;                   /* max_chain_length ==
  476.                           CHAIN_THRESHOLD / greedy */
  477.   
  478.   
  479. --- 8,16 ----
  480.   /*----------------------------------------------------------------------*/
  481.   
  482.   uc_t    text_buf[N2 + F2 - 1];          /* cyclic buffer with an overlay */
  483. ! int     match_position, match_length;   /* current characteristics of a
  484.                           matched pattern */
  485. ! int     chain_length;                   /* max_chain_length ==
  486.                           CHAIN_THRESHOLD / greedy */
  487.   
  488.   
  489. ***************
  490. *** 45,51 ****
  491.   #endif  /* __XENIX__ */
  492.   
  493.   #ifdef GATHER_STAT
  494. ! long node_steps, node_matches;
  495.   #endif  /* GATHER_STAT */
  496.   
  497.   /* Initialize the data structures and allocate memory, if needed.
  498. --- 45,51 ----
  499.   #endif  /* __XENIX__ */
  500.   
  501.   #ifdef GATHER_STAT
  502. ! long node_matches, node_compares, node_prolongations;
  503.   #endif  /* GATHER_STAT */
  504.   
  505.   /* Initialize the data structures and allocate memory, if needed.
  506. ***************
  507. *** 57,63 ****
  508.   {
  509.       hash_t i;
  510.   #ifdef GATHER_STAT
  511. !     node_steps = node_matches = 0;
  512.   #endif  /* GATHER_STAT */
  513.   
  514.   #ifdef __TURBOC__
  515. --- 57,63 ----
  516.   {
  517.       hash_t i;
  518.   #ifdef GATHER_STAT
  519. !     node_matches = node_compares = node_prolongations = 0;
  520.   #endif  /* GATHER_STAT */
  521.   
  522.   #ifdef __TURBOC__
  523. ***************
  524. *** 74,80 ****
  525.           nextof(i) = NIL;
  526.       for (i = 0; i < sizeof(prev)/sizeof(*prev); i++ )
  527.           prev[i] = NIL;
  528. !     chain_length = greedy ? CHAIN_THRESHOLD / greedy : 0;
  529.   }
  530.   
  531.   /* Get the longest (longer than `match_length' when entering in subroutine)
  532. --- 74,89 ----
  533.           nextof(i) = NIL;
  534.       for (i = 0; i < sizeof(prev)/sizeof(*prev); i++ )
  535.           prev[i] = NIL;
  536. !     switch (greedy) {
  537. !     case 0:
  538. !         chain_length = CHAIN_THRESHOLD;
  539. !         break;
  540. !     case 1:
  541. !         chain_length = 3;
  542. !         break;
  543. !     default:
  544. !         chain_length = 1;
  545. !     }
  546.   }
  547.   
  548.   /* Get the longest (longer than `match_length' when entering in subroutine)
  549. ***************
  550. *** 81,138 ****
  551.       nearest match of the string beginning in text_buf[r]
  552.       to the cyclic buffer. Result (length & position) is returned
  553.       in correspondent global variables (`match_length' &
  554. !     `match_position'). Unchanged `match_length' denotes failure.
  555.   */
  556.   
  557.   #ifndef FAST
  558.   void get_next_match (r)
  559. !     us_t r;
  560.   {
  561. !     register us_t p = r;
  562.       register int m;
  563.       register uc_t  *key FIX_SI, *pattern FIX_DI;
  564.       int     chain_count = chain_length;
  565.   #ifdef GATHER_STAT
  566.       node_matches++;
  567.   #endif
  568. !     key = text_buf + r;
  569. !     do {
  570.           do {
  571. !             /* From ZIP 1.0 by J.-L. Gailly et al. */
  572.   
  573. !             if ((p = nextof(p)) == NIL ||
  574. !                 (greedy && !chain_count--))
  575. !                 return;
  576.   
  577. !             pattern = text_buf + p;
  578.   
  579.   #ifdef GATHER_STAT
  580. !         node_steps++;
  581.   #endif
  582.   
  583. !             MATCHING;
  584.   
  585. !         } while NOT_YET;
  586.   
  587. !         for (m = match_length;
  588. !             ++m < F2 && key[m] == pattern[m]; );
  589.   
  590. -         match_length = m;
  591. -         match_position = ((r - p) & (N2 - 1)) - 1;
  592. -     } while (m < F2);
  593.   /* There are two equal F-char sequences, the oldest one must be
  594.       deleted from the list.
  595.   */
  596.   
  597.   #ifdef DEBUG
  598.       if (verbose)
  599.           fprintf(stderr, "Replacing node: %d -> %d\n", p, r);
  600.   #endif
  601. !     nextof(prev[p]) = nextof(p);
  602. !     prev[nextof(p)] = prev[p];
  603. !     prev[p] = NIL;  /* remove p, it is further than r */
  604. !     return;
  605.   }
  606.   #endif
  607. --- 90,172 ----
  608.       nearest match of the string beginning in text_buf[r]
  609.       to the cyclic buffer. Result (length & position) is returned
  610.       in correspondent global variables (`match_length' &
  611. !     `match_position'). Unchanged `match_length' denotes failure and
  612. !     `match_position' contains garbage !!
  613. !     In order to achieve faster operation, `match_length' is shifted
  614. !     down to F2.
  615.   */
  616.   
  617.   #ifndef FAST
  618.   void get_next_match (r)
  619. !     int r;
  620.   {
  621. !     register int p = r;
  622.       register int m;
  623. +     register uc_t lastbyte;
  624.       register uc_t  *key FIX_SI, *pattern FIX_DI;
  625.       int     chain_count = chain_length;
  626.   #ifdef GATHER_STAT
  627.       node_matches++;
  628.   #endif
  629. !     key = text_buf + r + F2;
  630. !     match_length -= F2;
  631. !     for(;chain_count--;) {
  632. !         lastbyte = key[match_length];
  633.           do {
  634. !             pattern = text_buf + match_length + F2;
  635.   
  636. !             do {
  637. !                 if ((p = nextof(p)) == NIL) {
  638. !                     match_length += F2;
  639. !                     match_position = ((r - match_position) & (N2 - 1)) - 1;
  640. !                     return;
  641. !                 }
  642. !             } while (pattern[p] != lastbyte);
  643.   
  644. !             pattern = text_buf + p + F2;
  645.   
  646.   #ifdef GATHER_STAT
  647. !         node_compares++;
  648.   #endif
  649.   
  650. !             for (m = -F2; key[m] == pattern[m] && ++m < 0;);
  651.   
  652. !         } while (m < match_length);
  653.   
  654. !         if (m == 0) {
  655.   
  656.   /* There are two equal F-char sequences, the oldest one must be
  657.       deleted from the list.
  658.   */
  659.   
  660.   #ifdef DEBUG
  661.       if (verbose)
  662.           fprintf(stderr, "Replacing node: %d -> %d\n", p, r);
  663.   #endif
  664. !             nextof(prev[p]) = nextof(p);
  665. !             prev[nextof(p)] = prev[p];
  666. !             prev[p] = NIL;  /* remove p, it is further than r */
  667. !             match_length = F2;
  668. !             match_position = ((r - p) & (N2 - 1)) - 1;
  669. !             return;
  670. !         }
  671. !         match_length = m;       /* remember new results */
  672. !         match_position = p;
  673. ! #ifdef GATHER_STAT
  674. !         node_prolongations++;
  675. ! #endif
  676. !     }
  677. !     /* chain length exceeded */
  678. !     match_length += F2;
  679. !     match_position = ((r - match_position) & (N2 - 1)) - 1;
  680.   }
  681.   #endif
  682. *** distribution/lz.h    Thu Jul 16 15:20:59 1992
  683. --- lz.h    Mon Aug 17 17:02:11 1992
  684. ***************
  685. *** 39,45 ****
  686.   #define array_size      (N2 + 1 + (1L << BITS))
  687.   
  688.   extern hash_t prev[];
  689. ! extern us_t      match_position, match_length, chain_length;
  690.   
  691.   #ifndef __XENIX__
  692.   #define nextof(i)       next[i]
  693. --- 39,45 ----
  694.   #define array_size      (N2 + 1 + (1L << BITS))
  695.   
  696.   extern hash_t prev[];
  697. ! extern int       match_position, match_length, chain_length;
  698.   
  699.   #ifndef __XENIX__
  700.   #define nextof(i)       next[i]
  701. ***************
  702. *** 75,81 ****
  703. --- 75,95 ----
  704.          nextof(prev[n]) = NIL;\
  705.          prev[n] = NIL;\
  706.   }
  707. + /* Hash function */
  708.   
  709. + #define hash(p)\
  710. +     ((hash_t)(p)[0] + ((hash_t)(p)[1] << LEN0) +\
  711. +     ((hash_t)(p)[2] << LEN1))
  712. + #ifdef FASTHASH
  713. + #define hashof(p)\
  714. +     (((p)[0] != (p)[1] ? hash(p) : hash(p) + hash((p) + 3)) &\
  715. +     ((1L << BITS) - 1))
  716. + #else
  717. + #define hashof(p)\
  718. +     (hash(p) & ((1L << BITS) - 1))
  719. + #endif
  720.   /* Inserting of a node `r' into hashed linked list: `r' becomes
  721.       the head of list.
  722.   */
  723. ***************
  724. *** 85,92 ****
  725.       register hash_t p; register us_t first_son;\
  726.       register uc_t  *key;\
  727.       key = &text_buf[r];\
  728. !     p = N2 + 1 + (((hash_t)key[0] + ((hash_t)key[1] << LEN0) +\
  729. !             ((hash_t)key[2] << LEN1)) & ((1L << BITS) - 1));\
  730.       first_son = nextof(p);\
  731.       nextof(r) = first_son;\
  732.       nextof(p) = r;\
  733. --- 99,105 ----
  734.       register hash_t p; register us_t first_son;\
  735.       register uc_t  *key;\
  736.       key = &text_buf[r];\
  737. !     p = N2 + 1 + hashof(key);\
  738.       first_son = nextof(p);\
  739.       nextof(r) = first_son;\
  740.       nextof(p) = r;\
  741. ***************
  742. *** 133,161 ****
  743.   #define FIX_DI
  744.   #endif
  745.   
  746. ! #ifndef DO_INLINE
  747.   
  748. ! /* This statement is due to ideas of Boyer and Moore: */
  749. ! /* Is somewhere an optimizing compiler which can vectorize this? ;-) */
  750.   
  751. ! #define MATCHING for (m = match_length; m >= 0 && key[m] == pattern[m]; m--)
  752. ! #define NOT_YET (m >= 0)
  753. ! #else
  754. ! /* Hope that memcmp will be intrinsic (Microsoft C).
  755.   */
  756. - #define MATCHING
  757. - #define NOT_YET (key[match_length] != pattern[match_length] || memcmp(key, pattern, match_length))
  758.   
  759. - #endif
  760. - #define CHAIN_THRESHOLD (F2 * 3)
  761. - #ifdef  FAST
  762. - /* Simple inline replacement for get_next_match; they match
  763. - literally except return --> goto quote(leave)l. No obfuscations !! */
  764.   #if defined(__STDC__) || defined (__TURBOC__)
  765.   #define LEAVE(num) leave##num
  766.   #else
  767. --- 146,159 ----
  768.   #define FIX_DI
  769.   #endif
  770.   
  771. ! #define CHAIN_THRESHOLD F2
  772.   
  773. ! #ifdef  FAST
  774.   
  775. ! /* Simple inline replacement for get_next_match; they match almost
  776. ! literally except return --> goto quote(leave)l. No obfuscations !!
  777.   */
  778.   
  779.   #if defined(__STDC__) || defined (__TURBOC__)
  780.   #define LEAVE(num) leave##num
  781.   #else
  782. ***************
  783. *** 163,178 ****
  784.   #define LEAVE(num) quote(leave)num
  785.   #endif
  786.   
  787. ! #define Get_Next_Match(r,l) {register us_t p=r;register int m;\
  788. ! register uc_t *key FIX_SI, *pattern FIX_DI;int chain_count=chain_length;\
  789. ! key=text_buf+r;do{ do{ if((p=nextof(p))==NIL||(greedy &&\
  790. ! !chain_count--))goto LEAVE(l);pattern=text_buf+p;MATCHING;}while NOT_YET;\
  791. ! for(m=match_length;++m<F2&&key[m]==pattern[m];);\
  792. ! match_length=m;match_position=((r-p)&(N2-1))-1;}while(m<F2);\
  793. ! nextof(prev[p])=nextof(p);prev[nextof(p)]=prev[p];prev[p]=NIL;LEAVE(l):;}
  794.   
  795.   #else
  796.   
  797.   #define Get_Next_Match(r,l)     get_next_match(r)
  798.   
  799.   #endif
  800. --- 161,187 ----
  801.   #define LEAVE(num) quote(leave)num
  802.   #endif
  803.   
  804. ! #define m_l match_length
  805. ! #define t_b text_buf
  806. ! #define m_p match_position
  807.   
  808. + #define Get_Next_Match(r,l) {register p=r;register m;register uc_t lb;\
  809. + register uc_t *key FIX_SI, *pat FIX_DI;int cc=chain_length;\
  810. + key=t_b+r+F2;m_l-=F2;for(;cc--;){lb=key[m_l];do{pat=t_b+m_l+F2;do{\
  811. + if((p=nextof(p))==NIL){m_p=((r-m_p)&(N2-1))-1;m_l+=F2;goto LEAVE(l);}\
  812. + }while(pat[p]!=lb);pat=t_b+p+F2;for(m= -F2;key[m]==pat[m]&&++m<0;);\
  813. + }while(m<m_l);if(m==0){nextof(prev[p])=nextof(p);prev[nextof(p)]=prev[p];\
  814. + prev[p]=NIL;m_l=F2;m_p=((r-p)&(N2-1))-1;goto LEAVE(l);}m_l=m;m_p=p;}\
  815. + m_p=((r-m_p)&(N2-1))-1;m_l+=F2;LEAVE(l):;}
  816.   #else
  817.   
  818.   #define Get_Next_Match(r,l)     get_next_match(r)
  819. + extern void get_next_match();
  820.   
  821.   #endif
  822. + #ifdef GATHER_STAT
  823. + extern long node_matches, node_compares, node_prolongations;
  824. + #endif
  825. *** distribution/makefile    Thu Jul 16 15:21:00 1992
  826. --- makefile    Thu Jul 30 13:27:39 1992
  827. ***************
  828. *** 4,14 ****
  829.       @echo ''
  830.       @echo 'Please indicate the system to make Freeze for.'
  831.       @echo 'Possible choices are: bsd, sysv, x286, sun4, hpux,'
  832. !     @echo 'generic.'
  833.       @echo ''
  834.   
  835. ! DEST          = /usr/local/bin
  836. ! MANDEST       = /usr/local/man/man1
  837.   SEC           = 1
  838.   
  839.   HDRS          = bitio.h\
  840. --- 4,19 ----
  841.       @echo ''
  842.       @echo 'Please indicate the system to make Freeze for.'
  843.       @echo 'Possible choices are: bsd, sysv, x286, sun4, hpux,'
  844. !     @echo 'm88k, sysv-longnames, generic.'
  845.       @echo ''
  846. +     @echo 'sysv-longnames is a target for SysV machines which allow'
  847. +     @echo 'filenames to be more than 14 characters long.'
  848. +     @echo ''
  849.   
  850. ! # Added the prefix macro, so that it was easier to change installation place.
  851. ! prefix        = /usr/local
  852. ! DEST          = $(prefix)/bin
  853. ! MANDEST       = $(prefix)/man/man1
  854.   SEC           = 1
  855.   
  856.   HDRS          = bitio.h\
  857. ***************
  858. *** 24,30 ****
  859.   OPTIONS       = -DCOMPAT
  860.   
  861.   LINTFLAGS     = -DBITS=15 -DSIGTYPE=void -DCOMPAT -DDEBUG\
  862. !         -DGATHER_STAT -x -DFAST
  863.   
  864.   MAKEFILE      = makefile
  865.   
  866. --- 29,35 ----
  867.   OPTIONS       = -DCOMPAT
  868.   
  869.   LINTFLAGS     = -DBITS=15 -DSIGTYPE=void -DCOMPAT -DDEBUG\
  870. !         -DGATHER_STAT -DUTIMES -x
  871.   
  872.   MAKEFILE      = makefile
  873.   
  874. ***************
  875. *** 74,80 ****
  876.           $(CC) $(CFLAGS) $(LDFLAGS) -o statist statist.o lz.o $(LIBS)
  877.   
  878.   clobber:        clean
  879. !         rm -f $(PROGRAM) statist *.man
  880.   
  881.   clean:;         rm -f *.o *.b .,* core *.out
  882.   
  883. --- 79,85 ----
  884.           $(CC) $(CFLAGS) $(LDFLAGS) -o statist statist.o lz.o $(LIBS)
  885.   
  886.   clobber:        clean
  887. !         rm -f $(PROGRAM) statist *.man \#* *~
  888.   
  889.   clean:;         rm -f *.o *.b .,* core *.out
  890.   
  891. ***************
  892. *** 91,96 ****
  893. --- 96,102 ----
  894.           -strip $@
  895.           -mcs -d $@
  896.           -ln -f $@ $(DEST)/melt
  897. +         -ln -f $@ $(DEST)/unfreeze
  898.           -ln -f $@ $(DEST)/fcat
  899.   
  900.   $(DEST)/statist: statist
  901. ***************
  902. *** 103,110 ****
  903. --- 109,122 ----
  904.           cp freeze.1 $@
  905.           chmod +r $@
  906.           -ln -f $@ $(MANDEST)/melt.$(SEC)
  907. +         -ln -f $@ $(MANDEST)/unfreeze.$(SEC)
  908.           -ln -f $@ $(MANDEST)/fcat.$(SEC)
  909. + # This is much better for places which keep preformated manpages.
  910. + #        echo ".so man1/freeze.$(SEC)" > $(MANDEST)/melt.$(SEC)
  911. + #        echo ".so man1/freeze.$(SEC)" > $(MANDEST)/unfreeze.$(SEC)
  912. + #        echo ".so man1/freeze.$(SEC)" > $(MANDEST)/fcat.$(SEC)
  913.   
  914.   $(MANDEST)/statist.$(SEC): statist.1
  915.           cp statist.1 $@
  916.           chmod +r $@
  917. ***************
  918. *** 111,125 ****
  919.   
  920.   bsd:
  921.           make prog CFLAGS="-O -DBSD -DUTIMES -DBITS=16\
  922. !         -DFAST -DSIGTYPE=void" CC=$(CC)
  923.   
  924. ! hpux:
  925.           make prog CFLAGS="-O -DLONGNAMES -DBITS=16\
  926. !         -DFAST -DSIGTYPE=void" CC=$(CC)
  927.   
  928.   sysv:
  929.           make prog CFLAGS="-O -DBITS=16 -DFAST -DSIGTYPE=void"\
  930. !         LIBS="-lc_s" CC=$(CC)
  931.   
  932.   x286:
  933.           make prog CC=cc CFLAGS="-Ox -Ml2 -DBITS=16 -DFAST\
  934. --- 123,141 ----
  935.   
  936.   bsd:
  937.           make prog CFLAGS="-O -DBSD -DUTIMES -DBITS=16\
  938. !         -DFAST -DSIGTYPE=void" CC="$(CC)"
  939.   
  940. ! sysv-longnames:
  941.           make prog CFLAGS="-O -DLONGNAMES -DBITS=16\
  942. !         -DFAST -DSIGTYPE=void" CC="$(CC)"
  943.   
  944. + hpux:        sysv-longnames
  945. + m88k:        sysv-longnames
  946.   sysv:
  947.           make prog CFLAGS="-O -DBITS=16 -DFAST -DSIGTYPE=void"\
  948. !         LIBS="-lc_s" CC="$(CC)"
  949.   
  950.   x286:
  951.           make prog CC=cc CFLAGS="-Ox -Ml2 -DBITS=16 -DFAST\
  952. ***************
  953. *** 129,140 ****
  954.           make install MANDEST=/usr/man/man.C SEC=C
  955.   
  956.   generic:
  957. !         make prog CFLAGS="-O -DBITS=16 -DFAST -DSIGTYPE=int" CC=$(CC)
  958.   
  959.   sun4:
  960. !         make prog CC=cc CFLAGS="-O4 -DBSD -DSUN4 -DSIGTYPE=void\
  961. !         -DUTIMES -DBITS=16 -DFAST"
  962.   
  963.   ###
  964.   bitio.o: freeze.h compat.h bitio.h
  965. --- 145,155 ----
  966.           make install MANDEST=/usr/man/man.C SEC=C
  967.   
  968.   generic:
  969. !         make prog CFLAGS="-O -DBITS=16 -DFAST -DSIGTYPE=int" CC="$(CC)"
  970.   
  971.   sun4:
  972. !         make prog CC="cc" CFLAGS="-O4 -DBSD -DSUN4 -DSIGTYPE=void\
  973. !         -DUTIMES -DBITS=16"
  974.   
  975.   ###
  976.   bitio.o: freeze.h compat.h bitio.h
  977. *** distribution/patchlevel.h    Thu Jul 16 15:21:00 1992
  978. --- patchlevel.h    Mon Aug 17 16:48:47 1992
  979. ***************
  980. *** 1,2 ****
  981. ! #define PATCHLEVEL 4
  982. ! #define PATCHDATE "6/3/92"
  983. --- 1,2 ----
  984. ! #define PATCHLEVEL 5
  985. ! #define PATCHDATE "17/8/92"
  986. *** distribution/statist.c    Thu Jul 16 15:20:52 1992
  987. --- statist.c    Thu Jul 30 13:43:21 1992
  988. ***************
  989. *** 113,118 ****
  990. --- 113,120 ----
  991.   
  992.       for (c = 1; c <= 6; c++) bits[c] = 0;
  993.   
  994. +     printf("Non-monotonities are in: ");
  995.       for(c = 0; c < N_POS; c++) {
  996.           j = 0;
  997.           k = c;
  998. ***************
  999. *** 119,134 ****
  1000.           do j++; while ((k = prnt[k]) != r);
  1001.           if (j <= 6)
  1002.               bits[j]++;
  1003. !         if (j < pr)
  1004.               f += pr - j;
  1005. !         else
  1006.               pr = j;
  1007.       }
  1008.   
  1009.       k = bits[1] + bits[2] + bits[3] + bits[4] +
  1010.       bits[5] + bits[6];
  1011.   
  1012. !     k = 62 - k;     /* free variable length codes for 7 & 8 bits */
  1013.   
  1014.       j = 128 * bits[1] + 64 * bits[2] + 32 * bits[3] +
  1015.       16 * bits[4] + 8 * bits[5] + 4 * bits[6];
  1016. --- 121,142 ----
  1017.           do j++; while ((k = prnt[k]) != r);
  1018.           if (j <= 6)
  1019.               bits[j]++;
  1020. !         if (j < pr) {
  1021.               f += pr - j;
  1022. !             printf("%d, ", c);
  1023. !         } else
  1024.               pr = j;
  1025.       }
  1026. +     if(f == 0)
  1027. +         printf("\b\b\b\babsent.\n");
  1028. +     else
  1029. +         printf("\b\b.\n");
  1030.   
  1031.       k = bits[1] + bits[2] + bits[3] + bits[4] +
  1032.       bits[5] + bits[6];
  1033.   
  1034. !     k = N_POS - k;  /* free variable length codes for 7 & 8 bits */
  1035.   
  1036.       j = 128 * bits[1] + 64 * bits[2] + 32 * bits[3] +
  1037.       16 * bits[4] + 8 * bits[5] + 4 * bits[6];
  1038. ***************
  1039. *** 216,222 ****
  1040.               match_length = 1;
  1041.           } else if (greedy) {
  1042.               lens[match_length] ++;
  1043. !             update((us_t)match_position >> 7);
  1044.               refers ++;
  1045.           } else {
  1046.               register us_t orig_length, orig_position;
  1047. --- 224,233 ----
  1048.               match_length = 1;
  1049.           } else if (greedy) {
  1050.               lens[match_length] ++;
  1051. !         if (match_position < 0 || match_position >= 8192 - 256)
  1052. !             printf("%d\n", match_position);
  1053. !             update(match_position >> 7);
  1054.               refers ++;
  1055.           } else {
  1056.               register us_t orig_length, orig_position;
  1057. ***************
  1058. *** 226,237 ****
  1059.               Next_Char(N2, F2);
  1060.               Get_Next_Match(r,2);
  1061.               if (match_length > len) match_length = len;
  1062. !             if (orig_length > match_length) {
  1063.                   lens[orig_length] ++;
  1064. !                 update((us_t)orig_position >> 7);
  1065.                   match_length = orig_length - 1;
  1066.               } else  {
  1067.                   lens[match_length] ++;
  1068.                   update(match_position >> 7);
  1069.               }
  1070.               refers ++;
  1071. --- 237,251 ----
  1072.               Next_Char(N2, F2);
  1073.               Get_Next_Match(r,2);
  1074.               if (match_length > len) match_length = len;
  1075. !             if (orig_length >= match_length) {
  1076.                   lens[orig_length] ++;
  1077. !                 update(orig_position >> 7);
  1078.                   match_length = orig_length - 1;
  1079.               } else  {
  1080.                   lens[match_length] ++;
  1081. +             if (match_position < 0 || match_position >= 8192 - 256)
  1082. +                 printf("%d\n", match_position);
  1083.                   update(match_position >> 7);
  1084.               }
  1085.               refers ++;
  1086.  
  1087. exit 0 # Just in case...
  1088.