home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume26 / freeze / patch01 < prev    next >
Encoding:
Text File  |  1991-11-24  |  56.3 KB  |  2,369 lines

  1. Newsgroups: comp.sources.misc
  2. From: leo@s514.ipmce.su (Leonid A. Broukhis)
  3. Subject:  REPOST: v26i053:  freeze - Freeze/melt compression program, Patch01
  4. Message-ID: <1991Nov24.205630.23773@sparky.imd.sterling.com>
  5. X-Md4-Signature: 27fe93a79067bfa88e2d3c88febb5514
  6. Date: Sun, 24 Nov 1991 20:56:30 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: leo@s514.ipmce.su (Leonid A. Broukhis)
  10. Posting-number: Volume 26, Issue 53
  11. Archive-name: freeze/patch01
  12. Environment: ISC, Xenix, SunOS, MS-DOS
  13. Patch-To: freeze: Volume 25, Issue 12-13
  14.  
  15. [ This is being reposted to correct invalid headers.  This is a   
  16. [ patch and not a complete repost. It was posted as a "Part".
  17. [ -Kent+ 
  18.  
  19. Here is a quite big patch:
  20.  
  21.  - I decided to not deal with u_short, ushort, u_char and uchar
  22.    and I've defined us_t, uc_t and ul_t;
  23.  - A little bug with utime corrected (usecs are now handled -
  24.     by pa@verano.sba.ca.us);
  25.  - Statist's man page added;
  26.  - Hash table size reduced;
  27.  - A speedup a la ZIP ("chain threshold" by the kind permission
  28.     of J.-L. Gailly);
  29.  - Typos fixed ("<" au lieu of "<="), etc.
  30.  - Improved compression rate.
  31.  
  32. diff -cr ../orig/README ./README
  33. *** ../orig/README    Sun Nov 24 00:09:17 1991
  34. --- ./README    Sun Nov 24 00:22:15 1991
  35. ***************
  36. *** 25,34 ****
  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.                   which give better code.
  43.   
  44.   Please! If your computer supports the string operations, try to write
  45.   "asm" instructions (GNU style) which realize the right-to-left memory
  46. --- 25,36 ----
  47.                   to be inline. This gives additional
  48.                   percents of speedup.
  49.       o __TURBOC__            For compiling under TURBO C
  50.       o __i386__              When compiling under GNU C causes
  51.                   some fixed register allocations,
  52.                   which give better code.
  53. +     o BIN_DEFAULT           (For MS-DOS only!) Define, if you
  54. +                 forget to use -i option when freezing
  55. +                 binary files.
  56.   
  57.   Please! If your computer supports the string operations, try to write
  58.   "asm" instructions (GNU style) which realize the right-to-left memory
  59. ***************
  60. *** 109,118 ****
  61.   Note: If you use "gensample | statist", remember that INTR influence BOTH
  62.   processes !!
  63.   
  64. - Sometimes `statist' can output the string "not enough information".
  65. - This means it cannot build the appropriate static Huffman table
  66. - (the given file is too trivial or random).
  67.   You may create the /etc/default/freeze file (if you don't like
  68.   /etc/default/ directory, choose another - in MS-DOS it is FREEZE.CNF in
  69.   the directory of FREEZE.EXE), which has the following format:  name =
  70. --- 111,116 ----
  71. ***************
  72. *** 120,126 ****
  73.   
  74.   ---------- cut here -----------
  75.   # This is freeze's defaults file
  76. ! gif =   0 0 0 0 2 60 0 0        # This is NOT! an optimal data
  77.                   # for GIF files
  78.   doc=0 0 1 2 7 16 36 0           # The sample was gcc.lp
  79.   # End of file
  80. --- 118,124 ----
  81.   
  82.   ---------- cut here -----------
  83.   # This is freeze's defaults file
  84. ! gif =   0 0 0 0 2 60 0 0        # This is NOT! optimal data
  85.                   # for GIF files
  86.   doc=0 0 1 2 7 16 36 0           # The sample was gcc.lp
  87.   # End of file
  88. ***************
  89. *** 182,184 ****
  90. --- 180,208 ----
  91.   
  92.   (I tried to implement splay trees instead of Huffman ones and instead of
  93.   static table for position information, but this gives nothing, alas.)
  94. + --------- CALGARY COMPRESSION CORPUS RESULTS --------
  95. + total 2308
  96. +    41515 May  9  1990 bib.F
  97. +   344793 May  9  1990 book1.F
  98. +   230861 May  9  1990 book2.F
  99. +    68626 May  9  1990 geo.F
  100. +   155783 May  9  1990 news.F
  101. +    10453 May  9  1990 obj1.F
  102. +    85500 May  9  1990 obj2.F
  103. +    20021 May  9  1990 paper1.F
  104. +    32693 May  9  1990 paper2.F
  105. +    19430 May  9  1990 paper3.F
  106. +     5771 May  9  1990 paper4.F
  107. +     5170 May  9  1990 paper5.F
  108. +    14091 May  9  1990 paper6.F
  109. +    53291 May  9  1990 pic.F
  110. +    14143 May  9  1990 progc.F
  111. +    17064 May  9  1990 progl.F
  112. +    11686 May  9  1990 progp.F
  113. +    22861 May  9  1990 trans.F
  114. + Average bits/byte on the standard set (except paper3-6) =
  115. +     1109290 * 8 / 3141622 = 2.825
  116. +     (With the "-g" flag = 2.892)
  117. diff -cr ../orig/bitio.c ./bitio.c
  118. *** ../orig/bitio.c    Sun Nov 24 00:09:20 1991
  119. --- ./bitio.c    Sun Nov 24 00:22:15 1991
  120. ***************
  121. *** 1,19 ****
  122.   #include "freeze.h"
  123.   #include "bitio.h"
  124.   
  125. ! unsigned long getbuf = 0;       /* assume sizeof (unsigned long) >= 4 */
  126. ! u_short putbuf;
  127. ! uchar   bitlen = 0, __, crpt_flag = 0;
  128.   
  129.   /* get N bits (N <= 16), returning in Bit(N-1)...Bit 0 */
  130.   
  131.   short GetNBits (n)
  132. !     register u_short n;
  133.   {
  134. !     register unsigned long dx = getbuf;
  135. !     register uchar c;
  136.   
  137. !     static u_short mask[17] = {
  138.           0x0000,
  139.           0x0001, 0x0003, 0x0007, 0x000f,
  140.           0x001f, 0x003f, 0x007f, 0x00ff,
  141. --- 1,19 ----
  142.   #include "freeze.h"
  143.   #include "bitio.h"
  144.   
  145. ! ul_t     getbuf = 0;     /* assume sizeof (ul_t) >= 4 */
  146. ! us_t     putbuf;
  147. ! uc_t     bitlen = 0, __, crpt_flag = 0;
  148.   
  149.   /* get N bits (N <= 16), returning in Bit(N-1)...Bit 0 */
  150.   
  151.   short GetNBits (n)
  152. !     register us_t n;
  153.   {
  154. !     register ul_t dx = getbuf;
  155. !     register uc_t c;
  156.   
  157. !     static us_t mask[17] = {
  158.           0x0000,
  159.           0x0001, 0x0003, 0x0007, 0x000f,
  160.           0x001f, 0x003f, 0x007f, 0x00ff,
  161. ***************
  162. *** 23,29 ****
  163.       while (bitlen < n)
  164.           {
  165.               c = getchar ();
  166. !             dx |= (unsigned long) c << (BYSH - bitlen);
  167.               bitlen += 8;
  168.           }
  169.       crpt_flag = feof(stdin);
  170. --- 23,29 ----
  171.       while (bitlen < n)
  172.           {
  173.               c = getchar ();
  174. !             dx |= (ul_t) c << (BYSH - bitlen);
  175.               bitlen += 8;
  176.           }
  177.       crpt_flag = feof(stdin);
  178. ***************
  179. *** 35,45 ****
  180.   /* output `l' high bits of `c' */
  181.   
  182.   void Putcode (l, c)
  183. !     register u_short l;
  184. !     u_short c;
  185.   {
  186. !     register u_short len = bitlen;
  187. !     register u_short b = (u_short)putbuf;
  188.       b |= c >> len;
  189.       if ((len += l) >= 8) {
  190.           putchar ((int)(b >> 8));
  191. --- 35,45 ----
  192.   /* output `l' high bits of `c' */
  193.   
  194.   void Putcode (l, c)
  195. !     register us_t l;
  196. !     us_t c;
  197.   {
  198. !     register us_t len = bitlen;
  199. !     register us_t b = (us_t)putbuf;
  200.       b |= c >> len;
  201.       if ((len += l) >= 8) {
  202.           putchar ((int)(b >> 8));
  203. diff -cr ../orig/bitio.h ./bitio.h
  204. *** ../orig/bitio.h    Sun Nov 24 00:09:17 1991
  205. --- ./bitio.h    Sun Nov 24 00:22:15 1991
  206. ***************
  207. *** 1,11 ****
  208.   /* Some definitions for faster bit-level I/O */
  209.   
  210. ! extern unsigned long getbuf;    /* Bit I/O buffers */
  211. ! extern u_short putbuf;
  212. ! extern uchar bitlen;            /* Number of bits actually in `???buf' */
  213.   
  214. ! extern uchar crpt_flag; /* 1 == EOF was read when melting */
  215. ! extern  uchar   __;     /* temporary variable for GetBit/Byte */
  216.   
  217.   extern void EncodeEnd(), Putcode(), crpt_message();
  218.   
  219. --- 1,11 ----
  220.   /* Some definitions for faster bit-level I/O */
  221.   
  222. ! extern ul_t getbuf;    /* Bit I/O buffers */
  223. ! extern us_t putbuf;
  224. ! extern uc_t bitlen;            /* Number of bits actually in `???buf' */
  225.   
  226. ! extern uc_t crpt_flag;   /* 1 == EOF was read when melting */
  227. ! extern uc_t __;          /* temporary variable for GetBit/Byte */
  228.   
  229.   extern void EncodeEnd(), Putcode(), crpt_message();
  230.   
  231. ***************
  232. *** 14,20 ****
  233.   #define BISH  (bits(getbuf)-1)
  234.   
  235.   #define GetByte()       (bitlen >= 8 ? (__ = getbuf >> BYSH, bitlen -= 8,\
  236. !             getbuf <<= 8, __) : (getbuf |= (unsigned long) \
  237.               (getchar() & 0xFF) << (BYSH - bitlen), __ = getbuf\
  238.               >> BYSH, getbuf <<= 8, __))
  239.   
  240. --- 14,20 ----
  241.   #define BISH  (bits(getbuf)-1)
  242.   
  243.   #define GetByte()       (bitlen >= 8 ? (__ = getbuf >> BYSH, bitlen -= 8,\
  244. !             getbuf <<= 8, __) : (getbuf |= (ul_t) \
  245.               (getchar() & 0xFF) << (BYSH - bitlen), __ = getbuf\
  246.               >> BYSH, getbuf <<= 8, __))
  247.   
  248. diff -cr ../orig/compat.h ./compat.h
  249. *** ../orig/compat.h    Sun Nov 24 00:09:20 1991
  250. --- ./compat.h    Sun Nov 24 00:22:16 1991
  251. ***************
  252. *** 1,4 ****
  253. ! extern uchar    Table1[];
  254.   
  255.   #define F1              60
  256.   #define N1              4096
  257. --- 1,4 ----
  258. ! extern uc_t    Table1[];
  259.   
  260.   #define F1              60
  261.   #define N1              4096
  262. diff -cr ../orig/debug.c ./debug.c
  263. *** ../orig/debug.c    Sun Nov 24 00:09:21 1991
  264. --- ./debug.c    Sun Nov 24 00:22:16 1991
  265. ***************
  266. *** 55,61 ****
  267.   
  268.   char *
  269.   pr_char(c)
  270. !     register uchar c;
  271.   {
  272.       static char buf[5];
  273.       register i = 4;
  274. --- 55,61 ----
  275.   
  276.   char *
  277.   pr_char(c)
  278. !     register uc_t c;
  279.   {
  280.       static char buf[5];
  281.       register i = 4;
  282. diff -cr ../orig/decode.c ./decode.c
  283. *** ../orig/decode.c    Sun Nov 24 00:09:21 1991
  284. --- ./decode.c    Sun Nov 24 00:22:16 1991
  285. ***************
  286. *** 29,35 ****
  287.           if (c < 256) {
  288.   #ifdef DEBUG
  289.               if (debug)
  290. !                 fprintf(stderr, "'%s'\n", pr_char((uchar)c));
  291.               else
  292.   #endif /* DEBUG */
  293.                   putchar (c);
  294. --- 29,35 ----
  295.           if (c < 256) {
  296.   #ifdef DEBUG
  297.               if (debug)
  298. !                 fprintf(stderr, "'%s'\n", pr_char((uc_t)c));
  299.               else
  300.   #endif /* DEBUG */
  301.                   putchar (c);
  302. ***************
  303. *** 47,53 ****
  304.                   c = text_buf[(i + k) & (N2 - 1)];
  305.   #ifdef DEBUG
  306.                   if (debug)
  307. !                     fprintf(stderr, "%s", pr_char((uchar)c));
  308.                   else
  309.   #endif
  310.                       putchar (c);
  311. --- 47,53 ----
  312.                   c = text_buf[(i + k) & (N2 - 1)];
  313.   #ifdef DEBUG
  314.                   if (debug)
  315. !                     fprintf(stderr, "%s", pr_char((uc_t)c));
  316.                   else
  317.   #endif
  318.                       putchar (c);
  319. ***************
  320. *** 84,90 ****
  321.           if (c < 256) {
  322.   #ifdef DEBUG
  323.               if (debug)
  324. !                 fprintf(stderr, "'%s'\n", pr_char((uchar)c));
  325.               else
  326.   #endif /* DEBUG */
  327.                   putchar (c);
  328. --- 84,90 ----
  329.           if (c < 256) {
  330.   #ifdef DEBUG
  331.               if (debug)
  332. !                 fprintf(stderr, "'%s'\n", pr_char((uc_t)c));
  333.               else
  334.   #endif /* DEBUG */
  335.                   putchar (c);
  336. ***************
  337. *** 102,108 ****
  338.                   c = text_buf[(i + k) & (N1 - 1)];
  339.   #ifdef DEBUG
  340.                   if (debug)
  341. !                     fprintf(stderr, "%s", pr_char((uchar)c));
  342.                   else
  343.   #endif
  344.                       putchar (c);
  345. --- 102,108 ----
  346.                   c = text_buf[(i + k) & (N1 - 1)];
  347.   #ifdef DEBUG
  348.                   if (debug)
  349. !                     fprintf(stderr, "%s", pr_char((uc_t)c));
  350.                   else
  351.   #endif
  352.                       putchar (c);
  353. diff -cr ../orig/default.c ./default.c
  354. *** ../orig/default.c    Sun Nov 24 00:09:21 1991
  355. --- ./default.c    Sun Nov 24 00:22:16 1991
  356. ***************
  357. *** 20,26 ****
  358.   
  359.       if (!fname) {
  360.           if (defd)
  361. !             fclose(defd);
  362.           defd = NOFILE;
  363.           return OK;
  364.       }
  365. --- 20,26 ----
  366.   
  367.       if (!fname) {
  368.           if (defd)
  369. !             (void) fclose(defd);
  370.           defd = NOFILE;
  371.           return OK;
  372.       }
  373. diff -cr ../orig/encode.c ./encode.c
  374. *** ../orig/encode.c    Sun Nov 24 00:09:17 1991
  375. --- ./encode.c    Sun Nov 24 00:22:17 1991
  376. ***************
  377. *** 15,21 ****
  378.   
  379.   void freeze ()
  380.   {
  381. !     register u_short i, len, r, s;
  382.       register short c;
  383.       putchar(MAGIC1);
  384.       putchar(MAGIC2_2);
  385. --- 15,21 ----
  386.   
  387.   void freeze ()
  388.   {
  389. !     register us_t i, len, r, s;
  390.       register short c;
  391.       putchar(MAGIC1);
  392.       putchar(MAGIC2_2);
  393. ***************
  394. *** 50,55 ****
  395. --- 50,56 ----
  396.           InsertNode(r + i - F2);
  397.   
  398.       while (len != 0) {
  399. +         match_length = THRESHOLD;
  400.           Get_Next_Match(r,1);
  401.           if (match_length > len)
  402.               match_length = len;
  403. ***************
  404. *** 66,76 ****
  405.           } else if (greedy) {
  406.   /* GREEDY parsing (compression rate 1.5% worse, but 40% faster) */
  407.   
  408. !             EncodeLength((u_short) (match_length - THRESHOLD));
  409. !             EncodePosition((u_short)match_position);
  410.   
  411.           } else {
  412. !             register u_short orig_length, orig_position, oldchar;
  413.   
  414.   /* This fragment (delayed coding, non-greedy) is due to ideas of
  415.       Jan Mark Wams' <jms@cs.vu.nl> COMIC:
  416. --- 67,77 ----
  417.           } else if (greedy) {
  418.   /* GREEDY parsing (compression rate 1.5% worse, but 40% faster) */
  419.   
  420. !             EncodeLength((us_t) (match_length - THRESHOLD));
  421. !             EncodePosition((us_t)match_position);
  422.   
  423.           } else {
  424. !             register us_t orig_length, orig_position, oldchar;
  425.   
  426.   /* This fragment (delayed coding, non-greedy) is due to ideas of
  427.       Jan Mark Wams' <jms@cs.vu.nl> COMIC:
  428. ***************
  429. *** 85,94 ****
  430.   
  431.               if (match_length > len) match_length = len;
  432.   
  433. !             if (orig_length > match_length) {
  434. !                 EncodeLength((u_short)
  435.                       (orig_length - THRESHOLD));
  436. !                 EncodePosition((u_short)orig_position);
  437.   #ifdef DEBUG
  438.                   match_position = orig_position;
  439.   #endif  /* DEBUG */
  440. --- 86,95 ----
  441.   
  442.               if (match_length > len) match_length = len;
  443.   
  444. !             if (orig_length >= match_length) {
  445. !                 EncodeLength((us_t)
  446.                       (orig_length - THRESHOLD));
  447. !                 EncodePosition((us_t)orig_position);
  448.   #ifdef DEBUG
  449.                   match_position = orig_position;
  450.   #endif  /* DEBUG */
  451. diff -cr ../orig/freeze.1 ./freeze.1
  452. *** ../orig/freeze.1    Sun Nov 24 00:09:18 1991
  453. --- ./freeze.1    Sun Nov 24 00:22:17 1991
  454. ***************
  455. *** 53,59 ****
  456.   If the
  457.   .B \-g
  458.   flag is given, a slightly less powerful (compression
  459. ! rate is 1.5% less), but 40% faster heuristic is used.
  460.   .PP
  461.   If the
  462.   .B \-f
  463. --- 53,61 ----
  464.   If the
  465.   .B \-g
  466.   flag is given, a slightly less powerful (compression
  467. ! rate is 1.5% less), but 40% faster heuristic is used. The more times this
  468. ! flag is present, the faster program works and the less compression
  469. ! rate is. This flag is quite useful when freezing bitmaps.
  470.   .PP
  471.   If the
  472.   .B \-f
  473. ***************
  474. *** 262,264 ****
  475. --- 264,269 ----
  476.   Unknown values of flag bits were discovered in the header
  477.   of frozen file.
  478.   .in -8
  479. + .SH "BUGS"
  480. + Found bugs descriptions, incompatibilities, etc.  please send to
  481. + leo@s514.ipmce.su.
  482. diff -cr ../orig/freeze.c ./freeze.c
  483. *** ../orig/freeze.c    Sun Nov 24 00:09:19 1991
  484. --- ./freeze.c    Sun Nov 24 00:22:17 1991
  485. ***************
  486. *** 29,34 ****
  487. --- 29,38 ----
  488.    * Version 2.3: Minor bug fixes (DOS filenames handling, backward
  489.    * compatibility feature improved, "bits" compression ratio display,
  490.    * preventive check for special files), speedups, more comments added.
  491. +  * Version 2.3.1: Typedefs cleaned, utime bug on the m88k corrected
  492. +  * (pa@verano.sba.ca.us, clewis@ferret.ocunix.on.ca (Chris Lewis)),
  493. +  * "chain threshold" euristic used for speedup (in "greedy" mode) -
  494. +  * a la ZIP (Jean-Loup Gailly). Max. hash bits reduced to 16.
  495.    */
  496.   
  497.   static char ident[] = "@(#) freeze.c 2.3.%d %s leo@s514.ipmce.su\n";
  498. ***************
  499. *** 76,82 ****
  500.       short image = O_TEXT;
  501.   # endif
  502.   #else
  503. ! #  define last_sep(s) rindex((s), '/')    /* Unix always uses slashes */
  504.   char deffile[] = "/etc/default/freeze";
  505.   #endif
  506.   
  507. --- 80,86 ----
  508.       short image = O_TEXT;
  509.   # endif
  510.   #else
  511. ! #  define last_sep(s) strrchr((s), '/')  /* Unix always uses slashes */
  512.   char deffile[] = "/etc/default/freeze";
  513.   #endif
  514.   
  515. ***************
  516. *** 89,94 ****
  517. --- 93,99 ----
  518.   
  519.   /* Do not sleep when freeze works :-) */
  520.   long indc_count, indc_threshold;
  521. + long file_length = 0;   /* initial length of file */
  522.   
  523.   #ifdef INT_SIG
  524.   int
  525. ***************
  526. *** 109,115 ****
  527.    *      -d:         If given, melting is done instead.
  528.    *
  529.    *      -g:         Use "greedy" parsing (1.5% worse, 40% faster).
  530. !  *                  (Means nothing when melting)
  531.    *
  532.    *      -f:         Forces output file to be generated, even if one already
  533.    *                  exists, and even if no space is saved by freezeing.
  534. --- 114,120 ----
  535.    *      -d:         If given, melting is done instead.
  536.    *
  537.    *      -g:         Use "greedy" parsing (1.5% worse, 40% faster).
  538. !  *                  (Means nothing when melting). May be repeated.
  539.    *
  540.    *      -f:         Forces output file to be generated, even if one already
  541.    *                  exists, and even if no space is saved by freezeing.
  542. ***************
  543. *** 129,135 ****
  544.    *                  as text (CR-LF and ^Z special) in melted form.  Default
  545.    *                  unless BIN_DEFAULT specified.
  546.    *
  547. !  *      -v:         Write freezing statistics
  548.    *
  549.    *      -V:         Write version and compilation options.
  550.    *
  551. --- 134,141 ----
  552.    *                  as text (CR-LF and ^Z special) in melted form.  Default
  553.    *                  unless BIN_DEFAULT specified.
  554.    *
  555. !  *      -v:         Write freezing statistics. -vv means "draw progress
  556. !  *                  indicator".
  557.    *
  558.    *      -V:         Write version and compilation options.
  559.    *
  560. ***************
  561. *** 158,164 ****
  562.       short overwrite = 0;  /* Do not overwrite unless given -f flag */
  563.       char tempname[100];
  564.       char **filelist, **fileptr;
  565. !     char *cp, *rindex();
  566.   
  567.   #ifndef MSDOS
  568.       char *malloc();
  569. --- 164,170 ----
  570.       short overwrite = 0;  /* Do not overwrite unless given -f flag */
  571.       char tempname[100];
  572.       char **filelist, **fileptr;
  573. !     char *cp;
  574.   
  575.   #ifndef MSDOS
  576.       char *malloc();
  577. ***************
  578. *** 184,195 ****
  579.       if ( (bgnd_flag = signal ( SIGINT, SIG_IGN )) != SIG_IGN )
  580.   #endif
  581.       {
  582. !     signal ( SIGINT, onintr );
  583.   #ifdef __TURBOC__
  584.       setcbrk(1);
  585.   #endif
  586.   #ifndef MSDOS
  587. !     signal ( SIGSEGV, oops );
  588.   #endif
  589.       }
  590.   
  591. --- 190,201 ----
  592.       if ( (bgnd_flag = signal ( SIGINT, SIG_IGN )) != SIG_IGN )
  593.   #endif
  594.       {
  595. !     (void) signal ( SIGINT, onintr );
  596.   #ifdef __TURBOC__
  597.       setcbrk(1);
  598.   #endif
  599.   #ifndef MSDOS
  600. !     (void) signal ( SIGSEGV, oops );
  601.   #endif
  602.       }
  603.   
  604. ***************
  605. *** 224,237 ****
  606.       } else {
  607.       /* Freezing */
  608.   #ifndef MSDOS
  609. !     defopen(deffile);
  610.   #else
  611. !     cp = rindex(cp, '.');
  612.       *++cp = 'C';
  613.       *++cp = 'N';
  614.       *++cp = 'F';
  615.       *++cp = '\0';
  616. !     defopen(argv[0]);
  617.   #endif
  618.       }
  619.   #ifdef BSD4_2
  620. --- 230,243 ----
  621.       } else {
  622.       /* Freezing */
  623.   #ifndef MSDOS
  624. !     (void) defopen(deffile);
  625.   #else
  626. !     cp = strrchr(cp, '.');
  627.       *++cp = 'C';
  628.       *++cp = 'N';
  629.       *++cp = 'F';
  630.       *++cp = '\0';
  631. !     (void) defopen(argv[0]);
  632.   #endif
  633.       }
  634.   #ifdef BSD4_2
  635. ***************
  636. *** 279,285 ****
  637.               quiet--;
  638.               break;
  639.               case 'g':
  640. !             greedy = 1;
  641.               break;
  642.               case 'd':
  643.               do_melt = 1;
  644. --- 285,291 ----
  645.               quiet--;
  646.               break;
  647.               case 'g':
  648. !             greedy++;
  649.               break;
  650.               case 'd':
  651.               do_melt = 1;
  652. ***************
  653. *** 330,348 ****
  654.           cp = *fileptr + strlen(*fileptr) - 2;
  655.           if ((*cp != '.' && *cp != 'X' && *cp != 'x') ||
  656.               (*(++cp) != 'F' && *cp != 'f')) {
  657. !             strcpy(tempname, *fileptr);
  658.               *tail = '\0';
  659. !             if ((cp=rindex(tempname,'.')) == NULL)
  660. !             strcat(tempname, ".F");
  661.               else if(*(++cp) == '\0')
  662.               /* pseudo-extension: FOOBAR. */
  663. !             strcat(tempname, "F");
  664.               else {
  665.               /* cp now points to file extension */
  666.               tail[0] = cp[1];        /* save two chars */
  667.               tail[1] = cp[2];
  668.               *(++cp) = '\0';
  669. !             strcat(tempname, "XF");
  670.               }
  671.               *fileptr = tempname;
  672.           }
  673. --- 336,354 ----
  674.           cp = *fileptr + strlen(*fileptr) - 2;
  675.           if ((*cp != '.' && *cp != 'X' && *cp != 'x') ||
  676.               (*(++cp) != 'F' && *cp != 'f')) {
  677. !             (void) strcpy(tempname, *fileptr);
  678.               *tail = '\0';
  679. !             if ((cp=strrchr(tempname,'.')) == NULL)
  680. !             (void) strcat(tempname, ".F");
  681.               else if(*(++cp) == '\0')
  682.               /* pseudo-extension: FOOBAR. */
  683. !             (void) strcat(tempname, "F");
  684.               else {
  685.               /* cp now points to file extension */
  686.               tail[0] = cp[1];        /* save two chars */
  687.               tail[1] = cp[2];
  688.               *(++cp) = '\0';
  689. !             (void) strcat(tempname, "XF");
  690.               }
  691.               *fileptr = tempname;
  692.           }
  693. ***************
  694. *** 350,357 ****
  695.           /* Check for .F suffix */
  696.           if (strcmp(*fileptr + strlen(*fileptr) - 2, ".F") != 0) {
  697.               /* No .F: tack one on */
  698. !             strcpy(tempname, *fileptr);
  699. !             strcat(tempname, ".F");
  700.               *fileptr = tempname;
  701.           }
  702.   #endif /*MSDOS */
  703. --- 356,363 ----
  704.           /* Check for .F suffix */
  705.           if (strcmp(*fileptr + strlen(*fileptr) - 2, ".F") != 0) {
  706.               /* No .F: tack one on */
  707. !             (void) strcpy(tempname, *fileptr);
  708. !             (void) strcat(tempname, ".F");
  709.               *fileptr = tempname;
  710.           }
  711.   #endif /*MSDOS */
  712. ***************
  713. *** 389,398 ****
  714.           }
  715.   
  716.           /* Generate output filename */
  717. !         strcpy(ofname, *fileptr);
  718.           ofname[strlen(*fileptr) - 2] = '\0';  /* Strip off .F */
  719.   #ifdef MSDOS
  720. !         strcat(ofname, tail);
  721.   #endif
  722.           } else {
  723.   
  724. --- 395,405 ----
  725.           }
  726.   
  727.           /* Generate output filename */
  728. !         precious = 1;
  729. !         (void) strcpy(ofname, *fileptr);
  730.           ofname[strlen(*fileptr) - 2] = '\0';  /* Strip off .F */
  731.   #ifdef MSDOS
  732. !         (void) strcat(ofname, tail);
  733.   #endif
  734.           } else {
  735.   
  736. ***************
  737. *** 427,438 ****
  738.           }
  739.   
  740.           /* Generate output filename */
  741. !         strcpy(ofname, *fileptr);
  742.   #ifndef BSD4_2        /* Short filenames */
  743.           if ((cp = last_sep(ofname)) != NULL) cp++;
  744.           else cp = ofname;
  745.   # ifdef MSDOS
  746. !         if (topipe == 0 && (sufp = rindex(cp, '.')) != NULL &&
  747.               strlen(sufp) > 2) fprintf(stderr,
  748.               "%s: part of filename extension will be replaced by XF\n",
  749.               cp);
  750. --- 434,445 ----
  751.           }
  752.   
  753.           /* Generate output filename */
  754. !         (void) strcpy(ofname, *fileptr);
  755.   #ifndef BSD4_2        /* Short filenames */
  756.           if ((cp = last_sep(ofname)) != NULL) cp++;
  757.           else cp = ofname;
  758.   # ifdef MSDOS
  759. !         if (topipe == 0 && (sufp = strrchr(cp, '.')) != NULL &&
  760.               strlen(sufp) > 2) fprintf(stderr,
  761.               "%s: part of filename extension will be replaced by XF\n",
  762.               cp);
  763. ***************
  764. *** 446,466 ****
  765.                                
  766.   #ifdef MSDOS
  767.           /* There is no difference between FOOBAR and FOOBAR. names */
  768. !         if ((cp = rindex(ofname, '.')) == NULL)
  769. !             strcat(ofname, ".F");
  770.           else if (cp[1] == '\0')
  771.               /* FOOBAR. case */
  772. !             strcat(ofname, "F");
  773.           else {
  774.               cp[2] = '\0';
  775. !             strcat(ofname, "XF");
  776.           }
  777.   #else
  778. !         strcat(ofname, ".F");
  779.   #endif /* MSDOS */
  780.   
  781.           }
  782. -         precious = 0;
  783.           /* Check for overwrite of existing file */
  784.           if (overwrite == 0 && topipe == 0) {
  785.           if (stat(ofname, &statbuf) == 0) {
  786. --- 453,472 ----
  787.                                
  788.   #ifdef MSDOS
  789.           /* There is no difference between FOOBAR and FOOBAR. names */
  790. !         if ((cp = strrchr(ofname, '.')) == NULL)
  791. !             (void) strcat(ofname, ".F");
  792.           else if (cp[1] == '\0')
  793.               /* FOOBAR. case */
  794. !             (void) strcat(ofname, "F");
  795.           else {
  796.               cp[2] = '\0';
  797. !             (void) strcat(ofname, "XF");
  798.           }
  799.   #else
  800. !         (void) strcat(ofname, ".F");
  801.   #endif /* MSDOS */
  802.   
  803.           }
  804.           /* Check for overwrite of existing file */
  805.           if (overwrite == 0 && topipe == 0) {
  806.           if (stat(ofname, &statbuf) == 0) {
  807. ***************
  808. *** 472,479 ****
  809.   #endif
  810.               fprintf(stderr,
  811.                   " do you wish to overwrite %s (y or n)? ", ofname);
  812. !             fflush(stderr);
  813. !             read(2, response, 2);
  814.               while (response[1] != '\n') {
  815.                   if (read(2, response+1, 1) < 0) {    /* Ack! */
  816.                   perror("stderr"); break;
  817. --- 478,485 ----
  818.   #endif
  819.               fprintf(stderr,
  820.                   " do you wish to overwrite %s (y or n)? ", ofname);
  821. !             (void) fflush(stderr);
  822. !             (void) read(2, response, 2);
  823.               while (response[1] != '\n') {
  824.                   if (read(2, response+1, 1) < 0) {    /* Ack! */
  825.                   perror("stderr"); break;
  826. ***************
  827. *** 505,513 ****
  828.   #ifdef DEBUG
  829.           }
  830.   #endif
  831.           if(quiet != 1)  {
  832.               fprintf(stderr, "%s:", *fileptr);
  833. -             indc_threshold = 2048;
  834.               indc_count = 1024;
  835.           }
  836.           }
  837. --- 511,519 ----
  838.   #ifdef DEBUG
  839.           }
  840.   #endif
  841. +         precious = 0;
  842.           if(quiet != 1)  {
  843.               fprintf(stderr, "%s:", *fileptr);
  844.               indc_count = 1024;
  845.           }
  846.           }
  847. ***************
  848. *** 539,544 ****
  849. --- 545,551 ----
  850.   
  851.           if(topipe == 0)
  852.           copystat(*fileptr);     /* Copy stats */
  853. +         precious = 1;
  854.        }
  855.       } else {        /* Standard input */
  856.   Pipe:
  857. ***************
  858. *** 546,559 ****
  859.           perror("stdin");
  860.           exit(1);
  861.       }
  862. !     file_length = statbuf.st_size;
  863.   
  864.       indc_threshold = file_length / 100;
  865.       if (indc_threshold < 4096)
  866.           indc_threshold = 4096;
  867. - #ifdef DEBUG
  868. -     fprintf(stderr, "File length: %ld\n", file_length);
  869. - #endif
  870.   
  871.       topipe = 1;
  872.       if (do_melt == 0) {
  873. --- 553,563 ----
  874.           perror("stdin");
  875.           exit(1);
  876.       }
  877. !     file_length = statbuf.st_mode & S_IFREG ? statbuf.st_size : 0;
  878.   
  879.       indc_threshold = file_length / 100;
  880.       if (indc_threshold < 4096)
  881.           indc_threshold = 4096;
  882.   
  883.       topipe = 1;
  884.       if (do_melt == 0) {
  885. ***************
  886. *** 606,612 ****
  887.   
  888.   long in_count = 1;      /* length of input */
  889.   long bytes_out;         /* length of frozen output */
  890. - long file_length = 0;   /* initial length of file */
  891.   
  892.   /* Calculates and prints the compression ratio w/o floating point OPs */
  893.   
  894. --- 610,615 ----
  895. ***************
  896. *** 651,669 ****
  897.       fprintf(stream, " (%d.%02d bits)", (int)(q / 100), (int)(q % 100));
  898.   }
  899.   
  900. - /* From compress.c */
  901. - char *
  902. - rindex(s, c)        /* For those who don't have it in libc.a */
  903. - register char *s, c;
  904. - {
  905. -     char *p;
  906. -     for (p = NULL; *s; s++)
  907. -         if (*s == c)
  908. -         p = s;
  909. -     return(p);
  910. - }
  911.   /* There was an error when reading or writing files */
  912.   
  913.   void writeerr()
  914. --- 654,659 ----
  915. ***************
  916. *** 670,676 ****
  917.   {
  918.       if (!topipe) {
  919.       perror ( ofname );
  920. !     unlink ( ofname );
  921.       }
  922.       exit ( 1 );
  923.   }
  924. --- 660,666 ----
  925.   {
  926.       if (!topipe) {
  927.       perror ( ofname );
  928. !     (void) unlink ( ofname );
  929.       }
  930.       exit ( 1 );
  931.   }
  932. ***************
  933. *** 680,696 ****
  934.   {
  935.   #ifdef __TURBOC__
  936.   struct ftime utimbuf;
  937.   #endif
  938.       int mode;
  939. - #ifndef __TURBOC__
  940. -     time_t timep[2];
  941. - #endif
  942.   
  943.   #ifdef MSDOS
  944.       if (_osmajor < 3) freopen("CON","at",stdout); else      /* MS-DOS 2.xx bug */
  945.   #endif
  946.   
  947. !     fclose(stdout);
  948.   
  949.       if (exit_stat == 2 && (!force)) { /* No freezing: remove file.F */
  950.   
  951. --- 670,686 ----
  952.   {
  953.   #ifdef __TURBOC__
  954.   struct ftime utimbuf;
  955. + #else
  956. + struct utimbuf timep;
  957.   #endif
  958.       int mode;
  959.   
  960.   #ifdef MSDOS
  961.       if (_osmajor < 3) freopen("CON","at",stdout); else      /* MS-DOS 2.xx bug */
  962.   #endif
  963.   
  964. !     (void) fclose(stdout);
  965.   
  966.       if (exit_stat == 2 && (!force)) { /* No freezing: remove file.F */
  967.   
  968. ***************
  969. *** 712,718 ****
  970.   
  971.   #ifndef MSDOS
  972.       /* Copy ownership */
  973. !     chown(ofname, (int) statbuf.st_uid, (int) statbuf.st_gid);
  974.   #endif
  975.   
  976.   #ifdef __TURBOC__
  977. --- 702,708 ----
  978.   
  979.   #ifndef MSDOS
  980.       /* Copy ownership */
  981. !     (void) chown(ofname, (int) statbuf.st_uid, (int) statbuf.st_gid);
  982.   #endif
  983.   
  984.   #ifdef __TURBOC__
  985. ***************
  986. *** 719,731 ****
  987.           getftime(fileno(stdin),&utimbuf);
  988.           freopen(ofname,"rb",stdout);
  989.           setftime(fileno(stdout),&utimbuf);
  990. !         fclose(stdout);
  991.   #else
  992. !     timep[0] = statbuf.st_atime;
  993. !     timep[1] = statbuf.st_mtime;
  994. !     utime(ofname, timep);    /* Update last accessed and modified times */
  995.   #endif
  996. -     precious = 1;
  997.       if (unlink(ifname))    /* Remove input file */
  998.           perror(ifname);
  999.       if(quiet != 1)
  1000. --- 709,727 ----
  1001.           getftime(fileno(stdin),&utimbuf);
  1002.           freopen(ofname,"rb",stdout);
  1003.           setftime(fileno(stdout),&utimbuf);
  1004. !     (void) fclose(stdout);
  1005.   #else
  1006. !     timep.actime = statbuf.st_atime;
  1007. !     timep.modtime = statbuf.st_mtime;
  1008. ! #if defined(__m88k__)
  1009. !       timep.acusec=  statbuf.st_ausec;        /* pa@verano */
  1010. !       timep.modusec= statbuf.st_musec;
  1011. ! #endif /* !m88k */
  1012. !     /* Update last accessed and modified times */
  1013. !     (void) utime(ofname, &timep);
  1014.   #endif
  1015.       if (unlink(ifname))    /* Remove input file */
  1016.           perror(ifname);
  1017.       if(quiet != 1)
  1018. ***************
  1019. *** 800,810 ****
  1020.   /* Exception handler (SIGINT) */
  1021.   
  1022.   onintr ( ) {
  1023. !     if (!precious) {
  1024. !     fclose(stdout);
  1025. !     unlink ( ofname );
  1026.       }
  1027. !     exit ( 1 );
  1028.   }
  1029.   
  1030.   #if defined(__TURBOC__) || !defined(INT_SIG)
  1031. --- 796,806 ----
  1032.   /* Exception handler (SIGINT) */
  1033.   
  1034.   onintr ( ) {
  1035. !     if (!precious) {            /* topipe == 1 implies precious == 1 */
  1036. !     (void) fclose(stdout);
  1037. !     (void) unlink(ofname);
  1038.       }
  1039. !     exit(1);
  1040.   }
  1041.   
  1042.   #if defined(__TURBOC__) || !defined(INT_SIG)
  1043. ***************
  1044. *** 815,821 ****
  1045.   
  1046.   oops ( )        /* file is corrupt or internal error */
  1047.   {
  1048. !     fflush(stdout);
  1049.       fprintf(stderr, "Segmentation violation occured...\n");
  1050.       exit ( 1 );
  1051.   }
  1052. --- 811,817 ----
  1053.   
  1054.   oops ( )        /* file is corrupt or internal error */
  1055.   {
  1056. !     (void) fflush(stdout);
  1057.       fprintf(stderr, "Segmentation violation occured...\n");
  1058.       exit ( 1 );
  1059.   }
  1060. ***************
  1061. *** 868,874 ****
  1062.       int i, is_list = 0;
  1063.       if(!s) {
  1064.       /* try to consider 'type' as a list of values: n1,n2, ... */
  1065. !         if(rindex(type, ','))
  1066.               is_list = 1;
  1067.           else {
  1068.               fprintf(stderr, "\"%s\" - no such file type\n", type);
  1069. --- 864,870 ----
  1070.       int i, is_list = 0;
  1071.       if(!s) {
  1072.       /* try to consider 'type' as a list of values: n1,n2, ... */
  1073. !         if(strrchr(type, ','))
  1074.               is_list = 1;
  1075.           else {
  1076.               fprintf(stderr, "\"%s\" - no such file type\n", type);
  1077. ***************
  1078. *** 881,887 ****
  1079.               exit(1);
  1080.           }
  1081.       }
  1082. !     if(!is_list && (!(t = rindex(s, '=')) ||
  1083.           sscanf(++t, "%d %d %d %d %d %d %d %d",
  1084.           v, v+1, v+2, v+3, v+4, v+5, v+6, v+7) != 8)) {
  1085.           fprintf(stderr,
  1086. --- 877,883 ----
  1087.               exit(1);
  1088.           }
  1089.       }
  1090. !     if(!is_list && (!(t = strrchr(s, '=')) ||
  1091.           sscanf(++t, "%d %d %d %d %d %d %d %d",
  1092.           v, v+1, v+2, v+3, v+4, v+5, v+6, v+7) != 8)) {
  1093.           fprintf(stderr,
  1094. diff -cr ../orig/freeze.h ./freeze.h
  1095. *** ../orig/freeze.h    Sun Nov 24 00:09:22 1991
  1096. --- ./freeze.h    Sun Nov 24 00:22:18 1991
  1097. ***************
  1098. *** 1,4 ****
  1099.   #include <stdio.h>
  1100.   
  1101.   #ifdef SUN4
  1102. --- 1,3 ----
  1103. ***************
  1104. *** 10,18 ****
  1105.   # ifndef putc
  1106.   #   define putc(x, p)      (--(p)->_cnt < 0 ? _flsbuf((unsigned char) (x), (p)) : (int) (*(p)->_ptr++ = (unsigned char) (x)))
  1107.   # endif
  1108. - #ifndef BSD4_2
  1109. - typedef unsigned short u_short;
  1110. - #endif  /* BSD4_2 */
  1111.   #endif  /* SUN4 */
  1112.   
  1113.   #include <ctype.h>
  1114. --- 9,14 ----
  1115. ***************
  1116. *** 20,25 ****
  1117. --- 16,29 ----
  1118.   #include <sys/types.h>
  1119.   #include <sys/stat.h>
  1120.   
  1121. + #ifndef __TURBOC__
  1122. + #include <utime.h>      /* Some systems have sys/utime.h instead of this */
  1123. + #endif
  1124. + #if defined(BSD42) && !defined(BSD4_2)
  1125. + #define BSD4_2
  1126. + #endif
  1127.   /* for MAXNAMLEN only !!! */
  1128.   #ifdef unix
  1129.   #ifndef BSD4_2
  1130. ***************
  1131. *** 53,64 ****
  1132.   #include <fcntl.h>
  1133.   #endif  /* MSDOS */
  1134.   
  1135. ! typedef unsigned char uchar;
  1136.   
  1137.   #if defined(BITS) && BITS > 14
  1138. ! typedef unsigned long hash_t;
  1139.   #else
  1140. ! typedef u_short hash_t;
  1141.   #endif  /* BITS */
  1142.   
  1143.   #ifdef  lint
  1144. --- 57,70 ----
  1145.   #include <fcntl.h>
  1146.   #endif  /* MSDOS */
  1147.   
  1148. ! typedef unsigned short us_t;
  1149. ! typedef unsigned char uc_t;
  1150. ! typedef unsigned long ul_t;
  1151.   
  1152.   #if defined(BITS) && BITS > 14
  1153. ! typedef ul_t hash_t;
  1154.   #else
  1155. ! typedef us_t hash_t;
  1156.   #endif  /* BITS */
  1157.   
  1158.   #ifdef  lint
  1159. ***************
  1160. *** 75,99 ****
  1161.   
  1162.   #define ENDOF           256                     /* pseudo-literal */
  1163.   
  1164. ! extern uchar    Table2[];
  1165.   
  1166.   extern long     in_count, bytes_out, file_length;
  1167.   
  1168. ! extern uchar    text_buf[];
  1169. ! extern u_short  match_position, match_length;
  1170.   
  1171. ! extern short    quiet, force;      /* useful flags */
  1172.   
  1173. ! /* Note ind_threshold is triangle number of Kbytes */
  1174.   
  1175. ! extern long indc_threshold, indc_count;
  1176.   
  1177. - extern short    do_melt, topipe, greedy;
  1178. - #define MAGIC1          ((uchar)'\037')
  1179. - #define MAGIC2_1        ((uchar)'\236')          /* freeze vers. 1.X */
  1180. - #define MAGIC2_2        ((uchar)'\237')
  1181.   extern int exit_stat;
  1182.   
  1183.   #ifdef DEBUG
  1184. --- 81,100 ----
  1185.   
  1186.   #define ENDOF           256                     /* pseudo-literal */
  1187.   
  1188. ! extern uc_t    Table2[];
  1189.   
  1190.   extern long     in_count, bytes_out, file_length;
  1191.   
  1192. ! extern uc_t      text_buf[];
  1193.   
  1194. ! extern long     indc_threshold, indc_count;
  1195.   
  1196. ! extern short    do_melt, topipe, greedy, quiet, force;  /* useful flags */
  1197.   
  1198. ! #define MAGIC1          ((uc_t)'\037')
  1199. ! #define MAGIC2_1        ((uc_t)'\236')          /* freeze vers. 1.X */
  1200. ! #define MAGIC2_2        ((uc_t)'\237')
  1201.   
  1202.   extern int exit_stat;
  1203.   
  1204.   #ifdef DEBUG
  1205. ***************
  1206. *** 110,119 ****
  1207.   extern short DecodeChar(), DecodePosition(), GetNBits();
  1208.   extern void melt2(), (*meltfunc)(), writeerr(), prratio(), prbits(), freeze();
  1209.   
  1210. - #if defined(BSD42) && !defined(BSD4_2)
  1211. - #define BSD4_2
  1212. - #endif
  1213.   #ifdef COMPAT
  1214.   #include "compat.h"
  1215.   #endif
  1216. --- 111,116 ----
  1217. ***************
  1218. *** 123,130 ****
  1219.       if (ferror(stdout))\
  1220.           writeerr();\
  1221.       if (file_length) {\
  1222. !         fprintf(stderr, " %2d%%\b\b\b\b",\
  1223. !             ftell(stdin) * 100 / file_length);\
  1224.           indc_count += indc_threshold;\
  1225.       } else {\
  1226.           fprintf(stderr, " %5ldK\b\b\b\b\b\b\b", in_count / 1024);\
  1227. --- 120,131 ----
  1228.       if (ferror(stdout))\
  1229.           writeerr();\
  1230.       if (file_length) {\
  1231. !         static int percents, old_percents = -1;\
  1232. !         if ((percents = ftell(stdin) * 100 / file_length) !=\
  1233. !             old_percents) {\
  1234. !             fprintf(stderr, " %2d%%\b\b\b\b", percents);\
  1235. !             old_percents = percents;\
  1236. !         }\
  1237.           indc_count += indc_threshold;\
  1238.       } else {\
  1239.           fprintf(stderr, " %5ldK\b\b\b\b\b\b\b", in_count / 1024);\
  1240. ***************
  1241. *** 136,139 ****
  1242. --- 137,143 ----
  1243.   
  1244.   #ifdef BSD4_2
  1245.   #define strchr index
  1246. + #define strrchr rindex
  1247.   #endif
  1248. + extern char *strchr(), *strrchr();
  1249. diff -cr ../orig/huf.c ./huf.c
  1250. *** ../orig/huf.c    Sun Nov 24 00:09:19 1991
  1251. --- ./huf.c    Sun Nov 24 00:22:18 1991
  1252. ***************
  1253. *** 14,28 ****
  1254.    * it freely when melting.
  1255.    */
  1256.   
  1257. ! uchar Table2[9] = { 0, 0, 1, 1, 1, 4, 10, 27, 18 };
  1258.   
  1259. ! uchar p_len[64];        /* These arrays are built accordingly to values */
  1260. ! uchar d_len[256];       /* of `Table' above which are default, from the */
  1261. !             /* command line or from the header of frozen file */
  1262.   
  1263. ! uchar code[256];
  1264.   
  1265. ! u_short freq[T2 + 1];           /* frequency table */
  1266.   short   son[T2];                /* points to son node (son[i],son[i+1]) */
  1267.   short   prnt[T2 + N_CHAR2];     /* points to parent node */
  1268.   
  1269. --- 14,28 ----
  1270.    * it freely when melting.
  1271.    */
  1272.   
  1273. ! uc_t Table2[9] = { 0, 0, 1, 1, 1, 4, 10, 27, 18 };
  1274.   
  1275. ! uc_t p_len[64];        /* These arrays are built accordingly to values */
  1276. ! uc_t d_len[256];       /* of `Table' above which are default, from the */
  1277. !               /* command line or from the header of frozen file */
  1278.   
  1279. ! uc_t code[256];
  1280.   
  1281. ! us_t freq[T2 + 1];           /* frequency table */
  1282.   short   son[T2];                /* points to son node (son[i],son[i+1]) */
  1283.   short   prnt[T2 + N_CHAR2];     /* points to parent node */
  1284.   
  1285. ***************
  1286. *** 76,83 ****
  1287.   
  1288.   void reconst ()
  1289.   {
  1290. !     register u_short i, j, k;
  1291. !     register u_short f;
  1292.   
  1293.   #ifdef DEBUG
  1294.       if (quiet < 0)
  1295. --- 76,83 ----
  1296.   
  1297.   void reconst ()
  1298.   {
  1299. !     register us_t i, j, k;
  1300. !     register us_t f;
  1301.   
  1302.   #ifdef DEBUG
  1303.       if (quiet < 0)
  1304. ***************
  1305. *** 104,110 ****
  1306.           f = freq[j] = freq[i] + freq[k];
  1307.           for (k = j - 1; f < freq[k]; k--);
  1308.           k++;
  1309. !         {       register u_short *p, *e;
  1310.               for (p = &freq[j], e = &freq[k]; p > e; p--)
  1311.                   p[0] = p[-1];
  1312.               freq[k] = f;
  1313. --- 104,110 ----
  1314.           f = freq[j] = freq[i] + freq[k];
  1315.           for (k = j - 1; f < freq[k]; k--);
  1316.           k++;
  1317. !         {       register us_t *p, *e;
  1318.               for (p = &freq[j], e = &freq[k]; p > e; p--)
  1319.                   p[0] = p[-1];
  1320.               freq[k] = f;
  1321. ***************
  1322. *** 130,139 ****
  1323.   /* Updates given code's frequency, and updates tree */
  1324.   
  1325.   void update (c)
  1326. !     u_short c;
  1327.   {
  1328. !     register u_short *p;
  1329. !     register u_short i, j, k, l;
  1330.   
  1331.       if (freq[r] == MAX_FREQ) {
  1332.           reconst();
  1333. --- 130,139 ----
  1334.   /* Updates given code's frequency, and updates tree */
  1335.   
  1336.   void update (c)
  1337. !     us_t c;
  1338.   {
  1339. !     register us_t *p;
  1340. !     register us_t i, j, k, l;
  1341.   
  1342.       if (freq[r] == MAX_FREQ) {
  1343.           reconst();
  1344. ***************
  1345. *** 168,177 ****
  1346.   /* Encodes the literal or the length information */
  1347.   
  1348.   void EncodeChar (c)
  1349. !     u_short c;
  1350.   {
  1351. !     unsigned long i;
  1352. !     register u_short j, k;
  1353.   
  1354.       i = 0;
  1355.       j = 0;
  1356. --- 168,177 ----
  1357.   /* Encodes the literal or the length information */
  1358.   
  1359.   void EncodeChar (c)
  1360. !     us_t c;
  1361.   {
  1362. !     ul_t i;
  1363. !     register us_t j, k;
  1364.   
  1365.       i = 0;
  1366.       j = 0;
  1367. ***************
  1368. *** 191,200 ****
  1369.   /* `j' never reaches the value of 32 ! */
  1370.   
  1371.       if (j > 16) {
  1372. !         Putcode(16, (u_short)(i >> 16));
  1373. !         Putcode(j - 16, (u_short)i);
  1374.       } else {
  1375. !         Putcode(j, (u_short)(i >> 16));
  1376.       }
  1377.       update(c);
  1378.   }
  1379. --- 191,200 ----
  1380.   /* `j' never reaches the value of 32 ! */
  1381.   
  1382.       if (j > 16) {
  1383. !         Putcode(16, (us_t)(i >> 16));
  1384. !         Putcode(j - 16, (us_t)i);
  1385.       } else {
  1386. !         Putcode(j, (us_t)(i >> 16));
  1387.       }
  1388.       update(c);
  1389.   }
  1390. ***************
  1391. *** 202,217 ****
  1392.   /* Encodes the position information */
  1393.   
  1394.   void EncodePosition (c)
  1395. !     register u_short c;
  1396.   {
  1397. !     register u_short i;
  1398.   
  1399.       /* output upper 6 bit from table */
  1400.       i = c >> 7;
  1401. !     Putcode((u_short)(p_len[i]), (u_short)(code[i]) << 8);
  1402.   
  1403.       /* output lower 7 bit */
  1404. !     Putcode(7, (u_short)(c & 0x7f) << 9);
  1405.   }
  1406.   
  1407.   
  1408. --- 202,217 ----
  1409.   /* Encodes the position information */
  1410.   
  1411.   void EncodePosition (c)
  1412. !     register us_t c;
  1413.   {
  1414. !     register us_t i;
  1415.   
  1416.       /* output upper 6 bit from table */
  1417.       i = c >> 7;
  1418. !     Putcode((us_t)(p_len[i]), (us_t)(code[i]) << 8);
  1419.   
  1420.       /* output lower 7 bit */
  1421. !     Putcode(7, (us_t)(c & 0x7f) << 9);
  1422.   }
  1423.   
  1424.   
  1425. ***************
  1426. *** 221,227 ****
  1427.   
  1428.   short DecodeChar ()
  1429.   {
  1430. !     register u_short c;
  1431.       c = son[r];
  1432.   
  1433.       /* trace from root to leaf,
  1434. --- 221,227 ----
  1435.   
  1436.   short DecodeChar ()
  1437.   {
  1438. !     register us_t c;
  1439.       c = son[r];
  1440.   
  1441.       /* trace from root to leaf,
  1442. ***************
  1443. *** 245,251 ****
  1444.   
  1445.   short DecodePosition ()
  1446.   {
  1447. !     register u_short i, j, c;
  1448.   
  1449.       /* decode upper 6 bits from the table */
  1450.   
  1451. --- 245,251 ----
  1452.   
  1453.   short DecodePosition ()
  1454.   {
  1455. !     register us_t i, j, c;
  1456.   
  1457.       /* decode upper 6 bits from the table */
  1458.   
  1459. ***************
  1460. *** 252,258 ****
  1461.       i = GetByte();
  1462.       crpt_flag = feof(stdin);
  1463.   
  1464. !     c = (u_short)code[i] << 7;
  1465.       j = d_len[i] - 1;
  1466.   
  1467.       /* get lower 7 bits literally */
  1468. --- 252,258 ----
  1469.       i = GetByte();
  1470.       crpt_flag = feof(stdin);
  1471.   
  1472. !     c = (us_t)code[i] << 7;
  1473.       j = d_len[i] - 1;
  1474.   
  1475.       /* get lower 7 bits literally */
  1476. ***************
  1477. *** 263,269 ****
  1478.   
  1479.   /* Initializes static Huffman arrays */
  1480.   
  1481. ! void init(table) uchar * table; {
  1482.       short i, j, k, num;
  1483.       num = 0;
  1484.   
  1485. --- 263,269 ----
  1486.   
  1487.   /* Initializes static Huffman arrays */
  1488.   
  1489. ! void init(table) uc_t * table; {
  1490.       short i, j, k, num;
  1491.       num = 0;
  1492.   
  1493. ***************
  1494. *** 309,315 ****
  1495.   */
  1496.   
  1497.   void write_header() {
  1498. !     u_short i;
  1499.   
  1500.       i = Table2[5] & 0x1F; i <<= 4;
  1501.       i |= Table2[4] & 0xF; i <<= 3;
  1502. --- 309,315 ----
  1503.   */
  1504.   
  1505.   void write_header() {
  1506. !     us_t i;
  1507.   
  1508.       i = Table2[5] & 0x1F; i <<= 4;
  1509.       i |= Table2[4] & 0xF; i <<= 3;
  1510. ***************
  1511. *** 378,384 ****
  1512.   
  1513.   #ifdef COMPAT
  1514.   
  1515. ! uchar Table1[9] = { 0, 0, 0, 1, 3, 8, 12, 24, 16 };
  1516.   
  1517.   /* Old version of a routine above for handling files made by
  1518.       the 1st version of Freeze.
  1519. --- 378,384 ----
  1520.   
  1521.   #ifdef COMPAT
  1522.   
  1523. ! uc_t Table1[9] = { 0, 0, 0, 1, 3, 8, 12, 24, 16 };
  1524.   
  1525.   /* Old version of a routine above for handling files made by
  1526.       the 1st version of Freeze.
  1527. ***************
  1528. *** 386,397 ****
  1529.   
  1530.   short DecodePOld ()
  1531.   {
  1532. !     register u_short i, j, c;
  1533.   
  1534.       i = GetByte();
  1535.       crpt_flag = feof(stdin);
  1536.   
  1537. !     c = (u_short)code[i] << 6;
  1538.       j = d_len[i] - 2;
  1539.   
  1540.       return c | (((i << j) | GetNBits (j)) & 0x3f);
  1541. --- 386,397 ----
  1542.   
  1543.   short DecodePOld ()
  1544.   {
  1545. !     register us_t i, j, c;
  1546.   
  1547.       i = GetByte();
  1548.       crpt_flag = feof(stdin);
  1549.   
  1550. !     c = (us_t)code[i] << 6;
  1551.       j = d_len[i] - 2;
  1552.   
  1553.       return c | (((i << j) | GetNBits (j)) & 0x3f);
  1554. diff -cr ../orig/huf.h ./huf.h
  1555. *** ../orig/huf.h    Sun Nov 24 00:09:22 1991
  1556. --- ./huf.h    Sun Nov 24 00:22:18 1991
  1557. ***************
  1558. *** 1,6 ****
  1559.   
  1560. ! extern u_short freq[];
  1561.   extern short son[], prnt[];
  1562.   extern void StartHuff(), init(), write_header(), EncodeChar();
  1563.   extern void EncodePosition();
  1564. ! #define MAX_FREQ        (u_short)0x8000 /* Tree update timing */
  1565. --- 1,6 ----
  1566.   
  1567. ! extern us_t freq[];
  1568.   extern short son[], prnt[];
  1569.   extern void StartHuff(), init(), write_header(), EncodeChar();
  1570.   extern void EncodePosition();
  1571. ! #define MAX_FREQ        (us_t)0x8000 /* Tree update timing */
  1572. diff -cr ../orig/lz.c ./lz.c
  1573. *** ../orig/lz.c    Sun Nov 24 00:09:23 1991
  1574. --- ./lz.c    Sun Nov 24 00:22:19 1991
  1575. ***************
  1576. *** 7,16 ****
  1577.   /*                                                                      */
  1578.   /*----------------------------------------------------------------------*/
  1579.   
  1580. ! uchar    text_buf[N2 + F2 - 1];          /* cyclic buffer with an overlay */
  1581. ! u_short   match_position, match_length; /* current characteristics of a
  1582. !                        matched pattern */
  1583.   
  1584.   /*      next[N+1..] is used as hash table,
  1585.       the rest of next is a link down,
  1586.       prev is a link up.
  1587. --- 7,19 ----
  1588.   /*                                                                      */
  1589.   /*----------------------------------------------------------------------*/
  1590.   
  1591. ! uc_t    text_buf[N2 + F2 - 1];          /* cyclic buffer with an overlay */
  1592. ! us_t    match_position, match_length;   /* current characteristics of a
  1593. !                         matched pattern */
  1594. ! us_t    chain_length;                   /* max_chain_length ==
  1595. !                         CHAIN_THRESHOLD / greedy */
  1596.   
  1597.   /*      next[N+1..] is used as hash table,
  1598.       the rest of next is a link down,
  1599.       prev is a link up.
  1600. ***************
  1601. *** 20,59 ****
  1602.   
  1603.   #ifndef __XENIX__
  1604.   #ifdef __TURBOC__
  1605. ! u_short huge * next = (u_short huge *) NULL;
  1606.   #else  /* __TURBOC__ */
  1607. ! u_short next[array_size];       /* a VERY large array :-) */
  1608.   #endif /* __TURBOC__ */
  1609.   #else  /* __XENIX__ */
  1610.   #if parts == 2
  1611. ! u_short next0[32768L], next1[8193];
  1612.   #else
  1613. ! #       if parts == 3
  1614. ! u_short next0[32768L], next1[32768L], next2[8193];
  1615. ! #       else
  1616. ! #               if parts == 5
  1617. ! u_short next0[32768L], next1[32768L], next2[32768L], next3[32768L], next4[8193];
  1618. ! #               else
  1619. ! u_short next0[32768L], next1[32768L], next2[32768L], next3[32768L], next4[32768L],
  1620. !     next5[32768L], next6[32768L], next7[32768L], next8[8193];
  1621. ! #               endif
  1622. ! #       endif
  1623.   #endif  /* parts */
  1624.   
  1625.   /* A list of `next's parts */
  1626.   
  1627. ! u_short *next[parts] = {
  1628.   next0, next1
  1629.   #if parts > 2
  1630.   ,next2
  1631. - #if parts > 3
  1632. - ,next3, next4
  1633. - #if parts > 5
  1634. - ,next5, next6,
  1635. - next7, next8
  1636.   #endif
  1637. - #endif
  1638. - #endif
  1639.   };
  1640.   #endif  /* __XENIX__ */
  1641.   
  1642. --- 23,46 ----
  1643.   
  1644.   #ifndef __XENIX__
  1645.   #ifdef __TURBOC__
  1646. ! us_t huge * next = (us_t huge *) NULL;
  1647.   #else  /* __TURBOC__ */
  1648. ! us_t next[array_size];       /* a VERY large array :-) */
  1649.   #endif /* __TURBOC__ */
  1650.   #else  /* __XENIX__ */
  1651.   #if parts == 2
  1652. ! us_t next0[32768L], next1[8193];
  1653.   #else
  1654. ! us_t next0[32768L], next1[32768L], next2[8193];
  1655.   #endif  /* parts */
  1656.   
  1657.   /* A list of `next's parts */
  1658.   
  1659. ! us_t *next[parts] = {
  1660.   next0, next1
  1661.   #if parts > 2
  1662.   ,next2
  1663.   #endif
  1664.   };
  1665.   #endif  /* __XENIX__ */
  1666.   
  1667. ***************
  1668. *** 74,84 ****
  1669.   #endif  /* GATHER_STAT */
  1670.   
  1671.   #ifdef __TURBOC__
  1672. !     if (!next && (next = (u_short huge *) farmalloc(
  1673. !         (unsigned long)array_size * sizeof(u_short))) == NULL) {
  1674.   
  1675.           fprintf(stderr, "Not enough memory (%luK wanted)\n",
  1676. !             (unsigned long)array_size * sizeof(u_short) / 1024);
  1677.           exit(3);
  1678.       }
  1679.   #endif  /* __TURBOC__ */
  1680. --- 61,71 ----
  1681.   #endif  /* GATHER_STAT */
  1682.   
  1683.   #ifdef __TURBOC__
  1684. !     if (!next && (next = (us_t huge *) farmalloc(
  1685. !         (ul_t)array_size * sizeof(us_t))) == NULL) {
  1686.   
  1687.           fprintf(stderr, "Not enough memory (%luK wanted)\n",
  1688. !             (ul_t)array_size * sizeof(us_t) / 1024);
  1689.           exit(3);
  1690.       }
  1691.   #endif  /* __TURBOC__ */
  1692. ***************
  1693. *** 87,116 ****
  1694.           nextof(i) = NIL;
  1695.       for (i = 0; i < sizeof(prev)/sizeof(*prev); i++ )
  1696.           prev[i] = NIL;
  1697.   }
  1698.   
  1699. ! /* Get the longest nearest match of the string beginning in text_buf[r]
  1700.       to the cyclic buffer. Result (length & position) is returned
  1701.       in correspondent global variables (`match_length' &
  1702. !     `match_position'). `match_length' == 0 denotes failure.
  1703.   */
  1704.   
  1705.   #ifndef FAST
  1706.   void get_next_match (r)
  1707. !     u_short r;
  1708.   {
  1709. !     register u_short p = r;
  1710.       register int m;
  1711. !     register uchar  *key FIX_SI, *pattern FIX_DI;
  1712.   #ifdef GATHER_STAT
  1713.       node_matches++;
  1714.   #endif
  1715.       key = text_buf + r;
  1716. -     match_length = 0;
  1717.       do {
  1718.           do {
  1719. !             if ((p = nextof(p)) == NIL)
  1720.                   return;
  1721.               pattern = text_buf + p;
  1722.   
  1723.               MATCHING;
  1724. --- 74,109 ----
  1725.           nextof(i) = NIL;
  1726.       for (i = 0; i < sizeof(prev)/sizeof(*prev); i++ )
  1727.           prev[i] = NIL;
  1728. +     chain_length = greedy ? CHAIN_THRESHOLD / greedy : 0;
  1729.   }
  1730.   
  1731. ! /* Get the longest (longer than `match_length' when entering in subroutine)
  1732. !     nearest match of the string beginning in text_buf[r]
  1733.       to the cyclic buffer. Result (length & position) is returned
  1734.       in correspondent global variables (`match_length' &
  1735. !     `match_position'). Unchanged `match_length' denotes failure.
  1736.   */
  1737.   
  1738.   #ifndef FAST
  1739.   void get_next_match (r)
  1740. !     us_t r;
  1741.   {
  1742. !     register us_t p = r;
  1743.       register int m;
  1744. !     register uc_t  *key FIX_SI, *pattern FIX_DI;
  1745. !     int     chain_count = chain_length;
  1746.   #ifdef GATHER_STAT
  1747.       node_matches++;
  1748.   #endif
  1749.       key = text_buf + r;
  1750.       do {
  1751.           do {
  1752. !             /* From ZIP 1.0 by J.-L. Gailly et al. */
  1753. !             if ((p = nextof(p)) == NIL ||
  1754. !                 (greedy && !chain_count--))
  1755.                   return;
  1756.               pattern = text_buf + p;
  1757.   
  1758.               MATCHING;
  1759. diff -cr ../orig/lz.h ./lz.h
  1760. *** ../orig/lz.h    Sun Nov 24 00:09:23 1991
  1761. --- ./lz.h    Sun Nov 24 00:22:19 1991
  1762. ***************
  1763. *** 9,17 ****
  1764.   #define BITS    13      /* 1:1 hash */
  1765.   #endif
  1766.   
  1767. ! #if BITS > 21
  1768.   #undef BITS
  1769. ! #define BITS    21      /* 4 MB hash table, if sizeof(u_short) == 2 */
  1770.   #endif
  1771.   
  1772.   /* The following hash-function isn't optimal but it is very fast:
  1773. --- 9,17 ----
  1774.   #define BITS    13      /* 1:1 hash */
  1775.   #endif
  1776.   
  1777. ! #if BITS > 16
  1778.   #undef BITS
  1779. ! #define BITS    16      /* 128K hash table, if sizeof(us_t) == 2 */
  1780.   #endif
  1781.   
  1782.   /* The following hash-function isn't optimal but it is very fast:
  1783. ***************
  1784. *** 29,39 ****
  1785.   
  1786.   #if defined(M_XENIX) && defined(I_286) && (BITS > 14)
  1787.   #define __XENIX__
  1788. - #if BITS > 18
  1789. - #undef BITS
  1790. - #define BITS 18
  1791.   #endif
  1792. - #endif
  1793.   
  1794.   /* `array_size' is the size of array `next', which contains
  1795.       the heads of linked lists and the references to
  1796. --- 29,35 ----
  1797. ***************
  1798. *** 43,80 ****
  1799.   #define array_size      (N2 + 1 + (1L << BITS))
  1800.   
  1801.   extern hash_t prev[];
  1802.   
  1803.   #ifndef __XENIX__
  1804.   #define nextof(i)       next[i]
  1805.   
  1806.   #ifdef __TURBOC__
  1807. ! extern u_short huge * next;
  1808.   #else   /* __TURBOC__ */
  1809. ! extern u_short next[];
  1810.   #endif  /* __TURBOC__ */
  1811.   
  1812.   #else   /* __XENIX__ */
  1813.   
  1814.   /* We divide the array `next' in `parts' which fit into 286's segment */
  1815.   
  1816.   #define parts (array_size/32768 + 1)
  1817.   #define nextof(i)       next[(i) >> 15][(i) & 0x7fff]
  1818.   #if parts == 2
  1819. ! extern u_short next0[], next1[];
  1820.   #else
  1821. ! #    if parts == 3
  1822. ! extern u_short next0[], next1[], next2[];
  1823. ! #       else
  1824. ! #        if parts == 5
  1825. ! extern u_short next0[], next1[], next2[], next3[], next4[];
  1826. ! #        else
  1827. ! extern u_short next0[], next1[], next2[], next3[], next4[],
  1828. !     next5[], next6[], next7[], next8[];
  1829. ! #        endif
  1830. ! #    endif
  1831.   #endif  /* parts */
  1832.   
  1833. ! extern u_short *next[];
  1834.   #endif  /* __XENIX__ */
  1835.   
  1836.   /* Some defines to eliminate function-call overhead */
  1837. --- 39,69 ----
  1838.   #define array_size      (N2 + 1 + (1L << BITS))
  1839.   
  1840.   extern hash_t prev[];
  1841. + extern us_t      match_position, match_length, chain_length;
  1842.   
  1843.   #ifndef __XENIX__
  1844.   #define nextof(i)       next[i]
  1845.   
  1846.   #ifdef __TURBOC__
  1847. ! extern us_t huge * next;
  1848.   #else   /* __TURBOC__ */
  1849. ! extern us_t next[];
  1850.   #endif  /* __TURBOC__ */
  1851.   
  1852.   #else   /* __XENIX__ */
  1853.   
  1854.   /* We divide the array `next' in `parts' which fit into 286's segment */
  1855. + /* There may be 2 or 3 parts, because BITS <= 16 now */
  1856.   
  1857.   #define parts (array_size/32768 + 1)
  1858.   #define nextof(i)       next[(i) >> 15][(i) & 0x7fff]
  1859.   #if parts == 2
  1860. ! extern us_t next0[], next1[];
  1861.   #else
  1862. ! extern us_t next0[], next1[], next2[];
  1863.   #endif  /* parts */
  1864.   
  1865. ! extern us_t *next[];
  1866.   #endif  /* __XENIX__ */
  1867.   
  1868.   /* Some defines to eliminate function-call overhead */
  1869. ***************
  1870. *** 93,100 ****
  1871.   
  1872.   #define InsertNode(r)\
  1873.   {\
  1874. !     register hash_t p; register u_short first_son;\
  1875. !     register uchar  *key;\
  1876.       key = &text_buf[r];\
  1877.       p = N2 + 1 + (((hash_t)key[0] + ((hash_t)key[1] << LEN0) +\
  1878.               ((hash_t)key[2] << LEN1)) & ((1L << BITS) - 1));\
  1879. --- 82,89 ----
  1880.   
  1881.   #define InsertNode(r)\
  1882.   {\
  1883. !     register hash_t p; register us_t first_son;\
  1884. !     register uc_t  *key;\
  1885.       key = &text_buf[r];\
  1886.       p = N2 + 1 + (((hash_t)key[0] + ((hash_t)key[1] << LEN0) +\
  1887.               ((hash_t)key[2] << LEN1)) & ((1L << BITS) - 1));\
  1888. ***************
  1889. *** 163,168 ****
  1890. --- 152,159 ----
  1891.   
  1892.   #endif
  1893.   
  1894. + #define CHAIN_THRESHOLD (F2 * 3)
  1895.   #ifdef  FAST
  1896.   /* Simple inline replacement for get_next_match; they match
  1897.   literally except return --> goto quote(leave)l. No obfuscations !! */
  1898. ***************
  1899. *** 173,186 ****
  1900.   #define LEAVE(num) leave/**/num
  1901.   #endif
  1902.   
  1903. ! #define Get_Next_Match(r,l) {register u_short p=r;register int m;\
  1904. ! register uchar *key FIX_SI, *pattern FIX_DI;key=text_buf+r;\
  1905. ! match_length=0;do{ do{ if((p=nextof(p))==NIL)goto LEAVE(l);\
  1906. ! pattern=text_buf+p;MATCHING;}while NOT_YET;\
  1907. ! for(m=match_length;++m<F2&&key[m]==pattern[m];);   \
  1908.   match_length=m;match_position=((r-p)&(N2-1))-1;}while(m<F2);\
  1909. ! nextof(prev[p])=nextof(p);prev[nextof(p)]=prev[p];prev[p]=NIL;   \
  1910. ! LEAVE(l):;}
  1911.   
  1912.   #else
  1913.   
  1914. --- 164,176 ----
  1915.   #define LEAVE(num) leave/**/num
  1916.   #endif
  1917.   
  1918. ! #define Get_Next_Match(r,l) {register us_t p=r;register int m;\
  1919. ! register uc_t *key FIX_SI, *pattern FIX_DI;int chain_count=chain_length;\
  1920. ! key=text_buf+r;do{ do{ if((p=nextof(p))==NIL||(greedy &&\
  1921. ! !chain_count--))goto LEAVE(l);pattern=text_buf+p;MATCHING;}while NOT_YET;\
  1922. ! for(m=match_length;++m<F2&&key[m]==pattern[m];);\
  1923.   match_length=m;match_position=((r-p)&(N2-1))-1;}while(m<F2);\
  1924. ! nextof(prev[p])=nextof(p);prev[nextof(p)]=prev[p];prev[p]=NIL;LEAVE(l):;}
  1925.   
  1926.   #else
  1927.   
  1928. diff -cr ../orig/makefile ./makefile
  1929. *** ../orig/makefile    Sun Nov 24 00:09:24 1991
  1930. --- ./makefile    Sun Nov 24 00:22:19 1991
  1931. ***************
  1932. *** 13,19 ****
  1933.   
  1934.   CC            = gcc
  1935.   
  1936. ! CFLAGS        = -DBITS=18 -O -DCOMPAT -DFAST -fstrength-reduce #-DBSD42 -DSUN4
  1937.   
  1938.   LINTFLAGS     = -DBITS=15 -DCOMPAT -DDEBUG -DGATHER_STAT -x -DFAST
  1939.   
  1940. --- 13,19 ----
  1941.   
  1942.   CC            = gcc
  1943.   
  1944. ! CFLAGS        = -DBITS=16 -O -DCOMPAT -DFAST -fstrength-reduce #-DBSD42 -DSUN4
  1945.   
  1946.   LINTFLAGS     = -DBITS=15 -DCOMPAT -DDEBUG -DGATHER_STAT -x -DFAST
  1947.   
  1948. ***************
  1949. *** 30,38 ****
  1950.   
  1951.   PROGRAM       = freeze
  1952.   
  1953. ! CATMAN        = freeze.man
  1954.   
  1955. ! MAN           = freeze.1
  1956.   
  1957.   SRCS          = bitio.c\
  1958.           debug.c\
  1959. --- 30,38 ----
  1960.   
  1961.   PROGRAM       = freeze
  1962.   
  1963. ! CATMAN        = freeze.man statist.man
  1964.   
  1965. ! MAN           = freeze.1 statist.1
  1966.   
  1967.   SRCS          = bitio.c\
  1968.           debug.c\
  1969. ***************
  1970. *** 43,50 ****
  1971.           huf.c\
  1972.           lz.c
  1973.   
  1974. ! all:            $(PROGRAM) statist $(CATMAN)
  1975.   
  1976.   lint:           $(SRCS)
  1977.           lint $(LINTFLAGS) $(SRCS) > lint.out
  1978.   
  1979. --- 43,57 ----
  1980.           huf.c\
  1981.           lz.c
  1982.   
  1983. ! .SUFFIXES:       .1 .man
  1984.   
  1985. + .1.man:
  1986. +         nroff -man < $< > $@
  1987. + all:            $(PROGRAM) statist man
  1988. + man:            $(CATMAN)
  1989.   lint:           $(SRCS)
  1990.           lint $(LINTFLAGS) $(SRCS) > lint.out
  1991.   
  1992. ***************
  1993. *** 54,63 ****
  1994.   statist: statist.o lz.o
  1995.           $(CC) $(CFLAGS) $(LDFLAGS) -o statist statist.o lz.o $(LIBS)
  1996.   
  1997. ! clean:;         rm -f *.o *.b .,* core *.out $(PROGRAM) statist
  1998.   
  1999. ! install:        $(DEST)/$(PROGRAM) $(MANDEST)/$(MAN)
  2000.   
  2001.   patch:;         rm -f patch.out
  2002.           -for i in ../distribution/* ; do \
  2003.           (diff -c $$i `basename $$i` >> patch.out); \
  2004. --- 61,73 ----
  2005.   statist: statist.o lz.o
  2006.           $(CC) $(CFLAGS) $(LDFLAGS) -o statist statist.o lz.o $(LIBS)
  2007.   
  2008. ! clobber:        clean
  2009. !         rm -f $(PROGRAM) statist *.man
  2010.   
  2011. ! clean:;         rm -f *.o *.b .,* core *.out
  2012.   
  2013. + install:        $(DEST)/$(PROGRAM) $(MANDEST)/freeze.1 $(MANDEST)/statist.1
  2014.   patch:;         rm -f patch.out
  2015.           -for i in ../distribution/* ; do \
  2016.           (diff -c $$i `basename $$i` >> patch.out); \
  2017. ***************
  2018. *** 64,81 ****
  2019.           done
  2020.   
  2021.   $(DEST)/$(PROGRAM): $(PROGRAM)
  2022. !         install -s -c $(PROGRAM) $(DEST)
  2023. !         ln -f $(DEST)/$(PROGRAM) $(DEST)/melt
  2024. !         ln -f $(DEST)/$(PROGRAM) $(DEST)/fcat
  2025.   
  2026. ! $(MANDEST)/$(MAN): $(CATMAN)
  2027. !         cp $(CATMAN) $(MANDEST)/$(MAN)
  2028. !         chmod +r $(MANDEST)/$(MAN)
  2029. !         ln -f $(MANDEST)/$(MAN) $(MANDEST)/melt.1
  2030. !         ln -f $(MANDEST)/$(MAN) $(MANDEST)/fcat.1
  2031.   
  2032. ! $(CATMAN):      $(MAN)
  2033. !         nroff -man < $(MAN) > $(CATMAN)
  2034.   
  2035.   ###
  2036.   bitio.o: freeze.h compat.h bitio.h
  2037. --- 74,94 ----
  2038.           done
  2039.   
  2040.   $(DEST)/$(PROGRAM): $(PROGRAM)
  2041. !         -strip $(PROGRAM)
  2042. !         -mcs -d $(PROGRAM)
  2043. !         install -m 755 $(PROGRAM) $(DEST)
  2044. !         -ln -f $@ $(DEST)/melt
  2045. !         -ln -f $@ $(DEST)/fcat
  2046.   
  2047. ! $(MANDEST)/freeze.1: freeze.man
  2048. !         cp freeze.man $@
  2049. !         chmod +r $@
  2050. !         -ln -f $@ $(MANDEST)/melt.1
  2051. !         -ln -f $@ $(MANDEST)/fcat.1
  2052.   
  2053. ! $(MANDEST)/statist.1: statist.man
  2054. !         cp statist.man $@
  2055. !         chmod +r $@
  2056.   
  2057.   ###
  2058.   bitio.o: freeze.h compat.h bitio.h
  2059. diff -cr ../orig/patchlevel.h ./patchlevel.h
  2060. *** ../orig/patchlevel.h    Sun Nov 24 00:09:24 1991
  2061. --- ./patchlevel.h    Sun Nov 24 00:29:56 1991
  2062. ***************
  2063. *** 1,2 ****
  2064. ! #define PATCHLEVEL 0
  2065. ! #define PATCHDATE "11/1/91"
  2066. --- 1,2 ----
  2067. ! #define PATCHLEVEL 1
  2068. ! #define PATCHDATE "11/20/91"
  2069. diff -cr ../orig/statist.c ./statist.c
  2070. *** ../orig/statist.c    Sun Nov 24 00:09:25 1991
  2071. --- ./statist.c    Sun Nov 24 00:22:20 1991
  2072. ***************
  2073. *** 11,17 ****
  2074.   
  2075.   #define update(c) (freq[c]++)
  2076.   
  2077. ! long in_count, bytes_out;
  2078.   
  2079.   long indc_count;
  2080.   short reduceflag = 0, greedy = 0;
  2081. --- 11,17 ----
  2082.   
  2083.   #define update(c) (freq[c]++)
  2084.   
  2085. ! long in_count, refers = 0;
  2086.   
  2087.   long indc_count;
  2088.   short reduceflag = 0, greedy = 0;
  2089. ***************
  2090. *** 18,27 ****
  2091.   
  2092.   int lens[F2+1];
  2093.   
  2094. ! u_short bits[9];
  2095.   
  2096.   short   prnt[T];
  2097. ! unsigned long freq[T];
  2098.   short used[T];
  2099.   
  2100.   void freeze(), StartHuff();
  2101. --- 18,27 ----
  2102.   
  2103.   int lens[F2+1];
  2104.   
  2105. ! us_t bits[9];
  2106.   
  2107.   short   prnt[T];
  2108. ! ul_t freq[T];
  2109.   short used[T];
  2110.   
  2111.   void freeze(), StartHuff();
  2112. ***************
  2113. *** 35,50 ****
  2114.       argv++;
  2115.       while (argc > 1) {
  2116.           if (**argv == '-') {
  2117. !             if ((*argv)[1] == 'g') {
  2118. !                 argc--; argv++;
  2119.                   greedy++;
  2120. !             } else
  2121. !                 break;
  2122.           } else
  2123.               break;
  2124.       }
  2125.       if(argc != 1) {
  2126. !         fprintf(stderr, "Usage: statist [-g] < sample_file\n");
  2127.           fprintf(stderr, "Press INTR to display current values\n");
  2128.           exit(0);
  2129.       }
  2130. --- 35,51 ----
  2131.       argv++;
  2132.       while (argc > 1) {
  2133.           if (**argv == '-') {
  2134. !             while (*++(*argv) == 'g')
  2135.                   greedy++;
  2136. !             if (**argv)
  2137. !                 goto usage;
  2138. !             argc--; argv++;
  2139.           } else
  2140.               break;
  2141.       }
  2142. +     usage:
  2143.       if(argc != 1) {
  2144. !         fprintf(stderr, "Usage: statist [-g...] < sample_file\n");
  2145.           fprintf(stderr, "Press INTR to display current values\n");
  2146.           exit(0);
  2147.       }
  2148. ***************
  2149. *** 59,75 ****
  2150.       return 0;
  2151.   }
  2152.   
  2153. ! unsigned long isqrt(val)
  2154. ! unsigned long val;
  2155.   {
  2156. !   unsigned long result = 0;
  2157. !   unsigned long side = 0;
  2158. !   unsigned long left = 0;
  2159.     int digit = 0;
  2160.     int i;
  2161. !   for (i=0; i<sizeof(unsigned long)*4; i++)
  2162.     {
  2163. !     left = (left << 2) + (val >> 30);
  2164.       val <<= 2;
  2165.       if (left >= side*2 + 1)
  2166.       {
  2167. --- 60,76 ----
  2168.       return 0;
  2169.   }
  2170.   
  2171. ! ul_t isqrt(val)
  2172. ! ul_t val;
  2173.   {
  2174. !   ul_t result = 0;
  2175. !   ul_t side = 0;
  2176. !   ul_t left = 0;
  2177.     int digit = 0;
  2178.     int i;
  2179. !   for (i=0; i<sizeof(ul_t)*4; i++)
  2180.     {
  2181. !     left = (left << 2) + (val >> (sizeof(ul_t) * 8 - 2));
  2182.       val <<= 2;
  2183.       if (left >= side*2 + 1)
  2184.       {
  2185. ***************
  2186. *** 99,107 ****
  2187.   void
  2188.   #endif
  2189.   giveres() {
  2190. !     u_short c;
  2191.       register int i, j, k, pr, f, average, sum;
  2192. !     unsigned long cumul, sigma2;
  2193.       short r, percent;
  2194.       signal(SIGINT, giveres);
  2195.       newtry:
  2196. --- 100,108 ----
  2197.   void
  2198.   #endif
  2199.   giveres() {
  2200. !     us_t c;
  2201.       register int i, j, k, pr, f, average, sum;
  2202. !     ul_t cumul, sigma2;
  2203.       short r, percent;
  2204.       signal(SIGINT, giveres);
  2205.       newtry:
  2206. ***************
  2207. *** 126,132 ****
  2208.               bits[j]++;
  2209.           if (j < pr)
  2210.               f += pr - j;
  2211. !         pr = j;
  2212.       }
  2213.   
  2214.       k = bits[1] + bits[2] + bits[3] + bits[4] +
  2215. --- 127,134 ----
  2216.               bits[j]++;
  2217.           if (j < pr)
  2218.               f += pr - j;
  2219. !         else
  2220. !             pr = j;
  2221.       }
  2222.   
  2223.       k = bits[1] + bits[2] + bits[3] + bits[4] +
  2224. ***************
  2225. *** 162,168 ****
  2226.       }
  2227.       sum = 0; cumul = 0;
  2228.       for(i = 3; i <= F2; i++) {
  2229. !         cumul += (unsigned long) i * lens[i];
  2230.           sum += lens[i];
  2231.       }
  2232.       sum || sum++;
  2233. --- 164,170 ----
  2234.       }
  2235.       sum = 0; cumul = 0;
  2236.       for(i = 3; i <= F2; i++) {
  2237. !         cumul += (ul_t) i * lens[i];
  2238.           sum += lens[i];
  2239.       }
  2240.       sum || sum++;
  2241. ***************
  2242. *** 187,196 ****
  2243.           }
  2244.       }
  2245.       for (sigma2 = 0, i = 3; i <= F2; i++)
  2246. !         sigma2 += (unsigned long)(i - average)*(i - average)*lens[i];
  2247.       sigma2 = sigma2 * 100 / sum;
  2248.       j = (int)isqrt(sigma2);
  2249.       printf("Sigma: %d.%1d\n", j / 10, j % 10);
  2250.       fflush(stdout);
  2251.   }
  2252.   
  2253. --- 189,199 ----
  2254.           }
  2255.       }
  2256.       for (sigma2 = 0, i = 3; i <= F2; i++)
  2257. !         sigma2 += (ul_t)(i - average)*(i - average)*lens[i];
  2258.       sigma2 = sigma2 * 100 / sum;
  2259.       j = (int)isqrt(sigma2);
  2260.       printf("Sigma: %d.%1d\n", j / 10, j % 10);
  2261. +     printf("References: %ld\n", refers);
  2262.       fflush(stdout);
  2263.   }
  2264.   
  2265. ***************
  2266. *** 197,203 ****
  2267.   
  2268.   void freeze ()
  2269.   {
  2270. !     register u_short i, len, r, s;
  2271.       register short c;
  2272.       StartHuff(0);
  2273.       InitTree();
  2274. --- 200,206 ----
  2275.   
  2276.   void freeze ()
  2277.   {
  2278. !     register us_t i, len, r, s;
  2279.       register short c;
  2280.       StartHuff(0);
  2281.       InitTree();
  2282. ***************
  2283. *** 211,216 ****
  2284. --- 214,220 ----
  2285.       for (i = 0; i <= F2; i++)
  2286.           InsertNode(r + i - F2);
  2287.       while (len != 0) {
  2288. +         match_length = THRESHOLD;
  2289.           Get_Next_Match(r,1);
  2290.           if (match_length > len)
  2291.               match_length = len;
  2292. ***************
  2293. *** 218,226 ****
  2294.               match_length = 1;
  2295.           } else if (greedy) {
  2296.               lens[match_length] ++;
  2297. !             update((u_short)match_position >> 7);
  2298.           } else {
  2299. !             register u_short orig_length, orig_position;
  2300.               orig_length = match_length;
  2301.               orig_position = match_position;
  2302.               DeleteNode(s);
  2303. --- 222,231 ----
  2304.               match_length = 1;
  2305.           } else if (greedy) {
  2306.               lens[match_length] ++;
  2307. !             update((us_t)match_position >> 7);
  2308. !             refers ++;
  2309.           } else {
  2310. !             register us_t orig_length, orig_position;
  2311.               orig_length = match_length;
  2312.               orig_position = match_position;
  2313.               DeleteNode(s);
  2314. ***************
  2315. *** 229,240 ****
  2316.               if (match_length > len) match_length = len;
  2317.               if (orig_length > match_length) {
  2318.                   lens[orig_length] ++;
  2319. !                 update((u_short)orig_position >> 7);
  2320.                   match_length = orig_length - 1;
  2321.               } else  {
  2322.                   lens[match_length] ++;
  2323.                   update(match_position >> 7);
  2324.               }
  2325.           }
  2326.           for (i = 0; i < match_length &&
  2327.                   (c = getchar()) != EOF; i++) {
  2328. --- 234,246 ----
  2329.               if (match_length > len) match_length = len;
  2330.               if (orig_length > match_length) {
  2331.                   lens[orig_length] ++;
  2332. !                 update((us_t)orig_position >> 7);
  2333.                   match_length = orig_length - 1;
  2334.               } else  {
  2335.                   lens[match_length] ++;
  2336.                   update(match_position >> 7);
  2337.               }
  2338. +             refers ++;
  2339.           }
  2340.           for (i = 0; i < match_length &&
  2341.                   (c = getchar()) != EOF; i++) {
  2342. exit 0 # Just in case...
  2343. exit 0 # Just in case...
  2344.