home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-11-24 | 56.3 KB | 2,369 lines |
- Newsgroups: comp.sources.misc
- From: leo@s514.ipmce.su (Leonid A. Broukhis)
- Subject: REPOST: v26i053: freeze - Freeze/melt compression program, Patch01
- Message-ID: <1991Nov24.205630.23773@sparky.imd.sterling.com>
- X-Md4-Signature: 27fe93a79067bfa88e2d3c88febb5514
- Date: Sun, 24 Nov 1991 20:56:30 GMT
- Approved: kent@sparky.imd.sterling.com
-
- Submitted-by: leo@s514.ipmce.su (Leonid A. Broukhis)
- Posting-number: Volume 26, Issue 53
- Archive-name: freeze/patch01
- Environment: ISC, Xenix, SunOS, MS-DOS
- Patch-To: freeze: Volume 25, Issue 12-13
-
- [ This is being reposted to correct invalid headers. This is a
- [ patch and not a complete repost. It was posted as a "Part".
- [ -Kent+
-
- Here is a quite big patch:
-
- - I decided to not deal with u_short, ushort, u_char and uchar
- and I've defined us_t, uc_t and ul_t;
- - A little bug with utime corrected (usecs are now handled -
- by pa@verano.sba.ca.us);
- - Statist's man page added;
- - Hash table size reduced;
- - A speedup a la ZIP ("chain threshold" by the kind permission
- of J.-L. Gailly);
- - Typos fixed ("<" au lieu of "<="), etc.
- - Improved compression rate.
-
- diff -cr ../orig/README ./README
- *** ../orig/README Sun Nov 24 00:09:17 1991
- --- ./README Sun Nov 24 00:22:15 1991
- ***************
- *** 25,34 ****
- to be inline. This gives additional
- percents of speedup.
- o __TURBOC__ For compiling under TURBO C
- -
- o __i386__ When compiling under GNU C causes
- some fixed register allocations,
- which give better code.
-
- Please! If your computer supports the string operations, try to write
- "asm" instructions (GNU style) which realize the right-to-left memory
- --- 25,36 ----
- to be inline. This gives additional
- percents of speedup.
- o __TURBOC__ For compiling under TURBO C
- o __i386__ When compiling under GNU C causes
- some fixed register allocations,
- which give better code.
- + o BIN_DEFAULT (For MS-DOS only!) Define, if you
- + forget to use -i option when freezing
- + binary files.
-
- Please! If your computer supports the string operations, try to write
- "asm" instructions (GNU style) which realize the right-to-left memory
- ***************
- *** 109,118 ****
- Note: If you use "gensample | statist", remember that INTR influence BOTH
- processes !!
-
- - Sometimes `statist' can output the string "not enough information".
- - This means it cannot build the appropriate static Huffman table
- - (the given file is too trivial or random).
- -
- You may create the /etc/default/freeze file (if you don't like
- /etc/default/ directory, choose another - in MS-DOS it is FREEZE.CNF in
- the directory of FREEZE.EXE), which has the following format: name =
- --- 111,116 ----
- ***************
- *** 120,126 ****
-
- ---------- cut here -----------
- # This is freeze's defaults file
- ! gif = 0 0 0 0 2 60 0 0 # This is NOT! an optimal data
- # for GIF files
- doc=0 0 1 2 7 16 36 0 # The sample was gcc.lp
- # End of file
- --- 118,124 ----
-
- ---------- cut here -----------
- # This is freeze's defaults file
- ! gif = 0 0 0 0 2 60 0 0 # This is NOT! optimal data
- # for GIF files
- doc=0 0 1 2 7 16 36 0 # The sample was gcc.lp
- # End of file
- ***************
- *** 182,184 ****
- --- 180,208 ----
-
- (I tried to implement splay trees instead of Huffman ones and instead of
- static table for position information, but this gives nothing, alas.)
- +
- + --------- CALGARY COMPRESSION CORPUS RESULTS --------
- +
- + total 2308
- + 41515 May 9 1990 bib.F
- + 344793 May 9 1990 book1.F
- + 230861 May 9 1990 book2.F
- + 68626 May 9 1990 geo.F
- + 155783 May 9 1990 news.F
- + 10453 May 9 1990 obj1.F
- + 85500 May 9 1990 obj2.F
- + 20021 May 9 1990 paper1.F
- + 32693 May 9 1990 paper2.F
- + 19430 May 9 1990 paper3.F
- + 5771 May 9 1990 paper4.F
- + 5170 May 9 1990 paper5.F
- + 14091 May 9 1990 paper6.F
- + 53291 May 9 1990 pic.F
- + 14143 May 9 1990 progc.F
- + 17064 May 9 1990 progl.F
- + 11686 May 9 1990 progp.F
- + 22861 May 9 1990 trans.F
- +
- + Average bits/byte on the standard set (except paper3-6) =
- + 1109290 * 8 / 3141622 = 2.825
- + (With the "-g" flag = 2.892)
- diff -cr ../orig/bitio.c ./bitio.c
- *** ../orig/bitio.c Sun Nov 24 00:09:20 1991
- --- ./bitio.c Sun Nov 24 00:22:15 1991
- ***************
- *** 1,19 ****
- #include "freeze.h"
- #include "bitio.h"
-
- ! unsigned long getbuf = 0; /* assume sizeof (unsigned long) >= 4 */
- ! u_short putbuf;
- ! uchar bitlen = 0, __, crpt_flag = 0;
-
- /* get N bits (N <= 16), returning in Bit(N-1)...Bit 0 */
-
- short GetNBits (n)
- ! register u_short n;
- {
- ! register unsigned long dx = getbuf;
- ! register uchar c;
-
- ! static u_short mask[17] = {
- 0x0000,
- 0x0001, 0x0003, 0x0007, 0x000f,
- 0x001f, 0x003f, 0x007f, 0x00ff,
- --- 1,19 ----
- #include "freeze.h"
- #include "bitio.h"
-
- ! ul_t getbuf = 0; /* assume sizeof (ul_t) >= 4 */
- ! us_t putbuf;
- ! uc_t bitlen = 0, __, crpt_flag = 0;
-
- /* get N bits (N <= 16), returning in Bit(N-1)...Bit 0 */
-
- short GetNBits (n)
- ! register us_t n;
- {
- ! register ul_t dx = getbuf;
- ! register uc_t c;
-
- ! static us_t mask[17] = {
- 0x0000,
- 0x0001, 0x0003, 0x0007, 0x000f,
- 0x001f, 0x003f, 0x007f, 0x00ff,
- ***************
- *** 23,29 ****
- while (bitlen < n)
- {
- c = getchar ();
- ! dx |= (unsigned long) c << (BYSH - bitlen);
- bitlen += 8;
- }
- crpt_flag = feof(stdin);
- --- 23,29 ----
- while (bitlen < n)
- {
- c = getchar ();
- ! dx |= (ul_t) c << (BYSH - bitlen);
- bitlen += 8;
- }
- crpt_flag = feof(stdin);
- ***************
- *** 35,45 ****
- /* output `l' high bits of `c' */
-
- void Putcode (l, c)
- ! register u_short l;
- ! u_short c;
- {
- ! register u_short len = bitlen;
- ! register u_short b = (u_short)putbuf;
- b |= c >> len;
- if ((len += l) >= 8) {
- putchar ((int)(b >> 8));
- --- 35,45 ----
- /* output `l' high bits of `c' */
-
- void Putcode (l, c)
- ! register us_t l;
- ! us_t c;
- {
- ! register us_t len = bitlen;
- ! register us_t b = (us_t)putbuf;
- b |= c >> len;
- if ((len += l) >= 8) {
- putchar ((int)(b >> 8));
- diff -cr ../orig/bitio.h ./bitio.h
- *** ../orig/bitio.h Sun Nov 24 00:09:17 1991
- --- ./bitio.h Sun Nov 24 00:22:15 1991
- ***************
- *** 1,11 ****
- /* Some definitions for faster bit-level I/O */
-
- ! extern unsigned long getbuf; /* Bit I/O buffers */
- ! extern u_short putbuf;
- ! extern uchar bitlen; /* Number of bits actually in `???buf' */
-
- ! extern uchar crpt_flag; /* 1 == EOF was read when melting */
- ! extern uchar __; /* temporary variable for GetBit/Byte */
-
- extern void EncodeEnd(), Putcode(), crpt_message();
-
- --- 1,11 ----
- /* Some definitions for faster bit-level I/O */
-
- ! extern ul_t getbuf; /* Bit I/O buffers */
- ! extern us_t putbuf;
- ! extern uc_t bitlen; /* Number of bits actually in `???buf' */
-
- ! extern uc_t crpt_flag; /* 1 == EOF was read when melting */
- ! extern uc_t __; /* temporary variable for GetBit/Byte */
-
- extern void EncodeEnd(), Putcode(), crpt_message();
-
- ***************
- *** 14,20 ****
- #define BISH (bits(getbuf)-1)
-
- #define GetByte() (bitlen >= 8 ? (__ = getbuf >> BYSH, bitlen -= 8,\
- ! getbuf <<= 8, __) : (getbuf |= (unsigned long) \
- (getchar() & 0xFF) << (BYSH - bitlen), __ = getbuf\
- >> BYSH, getbuf <<= 8, __))
-
- --- 14,20 ----
- #define BISH (bits(getbuf)-1)
-
- #define GetByte() (bitlen >= 8 ? (__ = getbuf >> BYSH, bitlen -= 8,\
- ! getbuf <<= 8, __) : (getbuf |= (ul_t) \
- (getchar() & 0xFF) << (BYSH - bitlen), __ = getbuf\
- >> BYSH, getbuf <<= 8, __))
-
- diff -cr ../orig/compat.h ./compat.h
- *** ../orig/compat.h Sun Nov 24 00:09:20 1991
- --- ./compat.h Sun Nov 24 00:22:16 1991
- ***************
- *** 1,4 ****
- ! extern uchar Table1[];
-
- #define F1 60
- #define N1 4096
- --- 1,4 ----
- ! extern uc_t Table1[];
-
- #define F1 60
- #define N1 4096
- diff -cr ../orig/debug.c ./debug.c
- *** ../orig/debug.c Sun Nov 24 00:09:21 1991
- --- ./debug.c Sun Nov 24 00:22:16 1991
- ***************
- *** 55,61 ****
-
- char *
- pr_char(c)
- ! register uchar c;
- {
- static char buf[5];
- register i = 4;
- --- 55,61 ----
-
- char *
- pr_char(c)
- ! register uc_t c;
- {
- static char buf[5];
- register i = 4;
- diff -cr ../orig/decode.c ./decode.c
- *** ../orig/decode.c Sun Nov 24 00:09:21 1991
- --- ./decode.c Sun Nov 24 00:22:16 1991
- ***************
- *** 29,35 ****
- if (c < 256) {
- #ifdef DEBUG
- if (debug)
- ! fprintf(stderr, "'%s'\n", pr_char((uchar)c));
- else
- #endif /* DEBUG */
- putchar (c);
- --- 29,35 ----
- if (c < 256) {
- #ifdef DEBUG
- if (debug)
- ! fprintf(stderr, "'%s'\n", pr_char((uc_t)c));
- else
- #endif /* DEBUG */
- putchar (c);
- ***************
- *** 47,53 ****
- c = text_buf[(i + k) & (N2 - 1)];
- #ifdef DEBUG
- if (debug)
- ! fprintf(stderr, "%s", pr_char((uchar)c));
- else
- #endif
- putchar (c);
- --- 47,53 ----
- c = text_buf[(i + k) & (N2 - 1)];
- #ifdef DEBUG
- if (debug)
- ! fprintf(stderr, "%s", pr_char((uc_t)c));
- else
- #endif
- putchar (c);
- ***************
- *** 84,90 ****
- if (c < 256) {
- #ifdef DEBUG
- if (debug)
- ! fprintf(stderr, "'%s'\n", pr_char((uchar)c));
- else
- #endif /* DEBUG */
- putchar (c);
- --- 84,90 ----
- if (c < 256) {
- #ifdef DEBUG
- if (debug)
- ! fprintf(stderr, "'%s'\n", pr_char((uc_t)c));
- else
- #endif /* DEBUG */
- putchar (c);
- ***************
- *** 102,108 ****
- c = text_buf[(i + k) & (N1 - 1)];
- #ifdef DEBUG
- if (debug)
- ! fprintf(stderr, "%s", pr_char((uchar)c));
- else
- #endif
- putchar (c);
- --- 102,108 ----
- c = text_buf[(i + k) & (N1 - 1)];
- #ifdef DEBUG
- if (debug)
- ! fprintf(stderr, "%s", pr_char((uc_t)c));
- else
- #endif
- putchar (c);
- diff -cr ../orig/default.c ./default.c
- *** ../orig/default.c Sun Nov 24 00:09:21 1991
- --- ./default.c Sun Nov 24 00:22:16 1991
- ***************
- *** 20,26 ****
-
- if (!fname) {
- if (defd)
- ! fclose(defd);
- defd = NOFILE;
- return OK;
- }
- --- 20,26 ----
-
- if (!fname) {
- if (defd)
- ! (void) fclose(defd);
- defd = NOFILE;
- return OK;
- }
- diff -cr ../orig/encode.c ./encode.c
- *** ../orig/encode.c Sun Nov 24 00:09:17 1991
- --- ./encode.c Sun Nov 24 00:22:17 1991
- ***************
- *** 15,21 ****
-
- void freeze ()
- {
- ! register u_short i, len, r, s;
- register short c;
- putchar(MAGIC1);
- putchar(MAGIC2_2);
- --- 15,21 ----
-
- void freeze ()
- {
- ! register us_t i, len, r, s;
- register short c;
- putchar(MAGIC1);
- putchar(MAGIC2_2);
- ***************
- *** 50,55 ****
- --- 50,56 ----
- InsertNode(r + i - F2);
-
- while (len != 0) {
- + match_length = THRESHOLD;
- Get_Next_Match(r,1);
- if (match_length > len)
- match_length = len;
- ***************
- *** 66,76 ****
- } else if (greedy) {
- /* GREEDY parsing (compression rate 1.5% worse, but 40% faster) */
-
- ! EncodeLength((u_short) (match_length - THRESHOLD));
- ! EncodePosition((u_short)match_position);
-
- } else {
- ! register u_short orig_length, orig_position, oldchar;
-
- /* This fragment (delayed coding, non-greedy) is due to ideas of
- Jan Mark Wams' <jms@cs.vu.nl> COMIC:
- --- 67,77 ----
- } else if (greedy) {
- /* GREEDY parsing (compression rate 1.5% worse, but 40% faster) */
-
- ! EncodeLength((us_t) (match_length - THRESHOLD));
- ! EncodePosition((us_t)match_position);
-
- } else {
- ! register us_t orig_length, orig_position, oldchar;
-
- /* This fragment (delayed coding, non-greedy) is due to ideas of
- Jan Mark Wams' <jms@cs.vu.nl> COMIC:
- ***************
- *** 85,94 ****
-
- if (match_length > len) match_length = len;
-
- ! if (orig_length > match_length) {
- ! EncodeLength((u_short)
- (orig_length - THRESHOLD));
- ! EncodePosition((u_short)orig_position);
- #ifdef DEBUG
- match_position = orig_position;
- #endif /* DEBUG */
- --- 86,95 ----
-
- if (match_length > len) match_length = len;
-
- ! if (orig_length >= match_length) {
- ! EncodeLength((us_t)
- (orig_length - THRESHOLD));
- ! EncodePosition((us_t)orig_position);
- #ifdef DEBUG
- match_position = orig_position;
- #endif /* DEBUG */
- diff -cr ../orig/freeze.1 ./freeze.1
- *** ../orig/freeze.1 Sun Nov 24 00:09:18 1991
- --- ./freeze.1 Sun Nov 24 00:22:17 1991
- ***************
- *** 53,59 ****
- If the
- .B \-g
- flag is given, a slightly less powerful (compression
- ! rate is 1.5% less), but 40% faster heuristic is used.
- .PP
- If the
- .B \-f
- --- 53,61 ----
- If the
- .B \-g
- flag is given, a slightly less powerful (compression
- ! rate is 1.5% less), but 40% faster heuristic is used. The more times this
- ! flag is present, the faster program works and the less compression
- ! rate is. This flag is quite useful when freezing bitmaps.
- .PP
- If the
- .B \-f
- ***************
- *** 262,264 ****
- --- 264,269 ----
- Unknown values of flag bits were discovered in the header
- of frozen file.
- .in -8
- + .SH "BUGS"
- + Found bugs descriptions, incompatibilities, etc. please send to
- + leo@s514.ipmce.su.
- diff -cr ../orig/freeze.c ./freeze.c
- *** ../orig/freeze.c Sun Nov 24 00:09:19 1991
- --- ./freeze.c Sun Nov 24 00:22:17 1991
- ***************
- *** 29,34 ****
- --- 29,38 ----
- * Version 2.3: Minor bug fixes (DOS filenames handling, backward
- * compatibility feature improved, "bits" compression ratio display,
- * preventive check for special files), speedups, more comments added.
- + * Version 2.3.1: Typedefs cleaned, utime bug on the m88k corrected
- + * (pa@verano.sba.ca.us, clewis@ferret.ocunix.on.ca (Chris Lewis)),
- + * "chain threshold" euristic used for speedup (in "greedy" mode) -
- + * a la ZIP (Jean-Loup Gailly). Max. hash bits reduced to 16.
- */
-
- static char ident[] = "@(#) freeze.c 2.3.%d %s leo@s514.ipmce.su\n";
- ***************
- *** 76,82 ****
- short image = O_TEXT;
- # endif
- #else
- ! # define last_sep(s) rindex((s), '/') /* Unix always uses slashes */
- char deffile[] = "/etc/default/freeze";
- #endif
-
- --- 80,86 ----
- short image = O_TEXT;
- # endif
- #else
- ! # define last_sep(s) strrchr((s), '/') /* Unix always uses slashes */
- char deffile[] = "/etc/default/freeze";
- #endif
-
- ***************
- *** 89,94 ****
- --- 93,99 ----
-
- /* Do not sleep when freeze works :-) */
- long indc_count, indc_threshold;
- + long file_length = 0; /* initial length of file */
-
- #ifdef INT_SIG
- int
- ***************
- *** 109,115 ****
- * -d: If given, melting is done instead.
- *
- * -g: Use "greedy" parsing (1.5% worse, 40% faster).
- ! * (Means nothing when melting)
- *
- * -f: Forces output file to be generated, even if one already
- * exists, and even if no space is saved by freezeing.
- --- 114,120 ----
- * -d: If given, melting is done instead.
- *
- * -g: Use "greedy" parsing (1.5% worse, 40% faster).
- ! * (Means nothing when melting). May be repeated.
- *
- * -f: Forces output file to be generated, even if one already
- * exists, and even if no space is saved by freezeing.
- ***************
- *** 129,135 ****
- * as text (CR-LF and ^Z special) in melted form. Default
- * unless BIN_DEFAULT specified.
- *
- ! * -v: Write freezing statistics
- *
- * -V: Write version and compilation options.
- *
- --- 134,141 ----
- * as text (CR-LF and ^Z special) in melted form. Default
- * unless BIN_DEFAULT specified.
- *
- ! * -v: Write freezing statistics. -vv means "draw progress
- ! * indicator".
- *
- * -V: Write version and compilation options.
- *
- ***************
- *** 158,164 ****
- short overwrite = 0; /* Do not overwrite unless given -f flag */
- char tempname[100];
- char **filelist, **fileptr;
- ! char *cp, *rindex();
-
- #ifndef MSDOS
- char *malloc();
- --- 164,170 ----
- short overwrite = 0; /* Do not overwrite unless given -f flag */
- char tempname[100];
- char **filelist, **fileptr;
- ! char *cp;
-
- #ifndef MSDOS
- char *malloc();
- ***************
- *** 184,195 ****
- if ( (bgnd_flag = signal ( SIGINT, SIG_IGN )) != SIG_IGN )
- #endif
- {
- ! signal ( SIGINT, onintr );
- #ifdef __TURBOC__
- setcbrk(1);
- #endif
- #ifndef MSDOS
- ! signal ( SIGSEGV, oops );
- #endif
- }
-
- --- 190,201 ----
- if ( (bgnd_flag = signal ( SIGINT, SIG_IGN )) != SIG_IGN )
- #endif
- {
- ! (void) signal ( SIGINT, onintr );
- #ifdef __TURBOC__
- setcbrk(1);
- #endif
- #ifndef MSDOS
- ! (void) signal ( SIGSEGV, oops );
- #endif
- }
-
- ***************
- *** 224,237 ****
- } else {
- /* Freezing */
- #ifndef MSDOS
- ! defopen(deffile);
- #else
- ! cp = rindex(cp, '.');
- *++cp = 'C';
- *++cp = 'N';
- *++cp = 'F';
- *++cp = '\0';
- ! defopen(argv[0]);
- #endif
- }
- #ifdef BSD4_2
- --- 230,243 ----
- } else {
- /* Freezing */
- #ifndef MSDOS
- ! (void) defopen(deffile);
- #else
- ! cp = strrchr(cp, '.');
- *++cp = 'C';
- *++cp = 'N';
- *++cp = 'F';
- *++cp = '\0';
- ! (void) defopen(argv[0]);
- #endif
- }
- #ifdef BSD4_2
- ***************
- *** 279,285 ****
- quiet--;
- break;
- case 'g':
- ! greedy = 1;
- break;
- case 'd':
- do_melt = 1;
- --- 285,291 ----
- quiet--;
- break;
- case 'g':
- ! greedy++;
- break;
- case 'd':
- do_melt = 1;
- ***************
- *** 330,348 ****
- cp = *fileptr + strlen(*fileptr) - 2;
- if ((*cp != '.' && *cp != 'X' && *cp != 'x') ||
- (*(++cp) != 'F' && *cp != 'f')) {
- ! strcpy(tempname, *fileptr);
- *tail = '\0';
- ! if ((cp=rindex(tempname,'.')) == NULL)
- ! strcat(tempname, ".F");
- else if(*(++cp) == '\0')
- /* pseudo-extension: FOOBAR. */
- ! strcat(tempname, "F");
- else {
- /* cp now points to file extension */
- tail[0] = cp[1]; /* save two chars */
- tail[1] = cp[2];
- *(++cp) = '\0';
- ! strcat(tempname, "XF");
- }
- *fileptr = tempname;
- }
- --- 336,354 ----
- cp = *fileptr + strlen(*fileptr) - 2;
- if ((*cp != '.' && *cp != 'X' && *cp != 'x') ||
- (*(++cp) != 'F' && *cp != 'f')) {
- ! (void) strcpy(tempname, *fileptr);
- *tail = '\0';
- ! if ((cp=strrchr(tempname,'.')) == NULL)
- ! (void) strcat(tempname, ".F");
- else if(*(++cp) == '\0')
- /* pseudo-extension: FOOBAR. */
- ! (void) strcat(tempname, "F");
- else {
- /* cp now points to file extension */
- tail[0] = cp[1]; /* save two chars */
- tail[1] = cp[2];
- *(++cp) = '\0';
- ! (void) strcat(tempname, "XF");
- }
- *fileptr = tempname;
- }
- ***************
- *** 350,357 ****
- /* Check for .F suffix */
- if (strcmp(*fileptr + strlen(*fileptr) - 2, ".F") != 0) {
- /* No .F: tack one on */
- ! strcpy(tempname, *fileptr);
- ! strcat(tempname, ".F");
- *fileptr = tempname;
- }
- #endif /*MSDOS */
- --- 356,363 ----
- /* Check for .F suffix */
- if (strcmp(*fileptr + strlen(*fileptr) - 2, ".F") != 0) {
- /* No .F: tack one on */
- ! (void) strcpy(tempname, *fileptr);
- ! (void) strcat(tempname, ".F");
- *fileptr = tempname;
- }
- #endif /*MSDOS */
- ***************
- *** 389,398 ****
- }
-
- /* Generate output filename */
- ! strcpy(ofname, *fileptr);
- ofname[strlen(*fileptr) - 2] = '\0'; /* Strip off .F */
- #ifdef MSDOS
- ! strcat(ofname, tail);
- #endif
- } else {
-
- --- 395,405 ----
- }
-
- /* Generate output filename */
- ! precious = 1;
- ! (void) strcpy(ofname, *fileptr);
- ofname[strlen(*fileptr) - 2] = '\0'; /* Strip off .F */
- #ifdef MSDOS
- ! (void) strcat(ofname, tail);
- #endif
- } else {
-
- ***************
- *** 427,438 ****
- }
-
- /* Generate output filename */
- ! strcpy(ofname, *fileptr);
- #ifndef BSD4_2 /* Short filenames */
- if ((cp = last_sep(ofname)) != NULL) cp++;
- else cp = ofname;
- # ifdef MSDOS
- ! if (topipe == 0 && (sufp = rindex(cp, '.')) != NULL &&
- strlen(sufp) > 2) fprintf(stderr,
- "%s: part of filename extension will be replaced by XF\n",
- cp);
- --- 434,445 ----
- }
-
- /* Generate output filename */
- ! (void) strcpy(ofname, *fileptr);
- #ifndef BSD4_2 /* Short filenames */
- if ((cp = last_sep(ofname)) != NULL) cp++;
- else cp = ofname;
- # ifdef MSDOS
- ! if (topipe == 0 && (sufp = strrchr(cp, '.')) != NULL &&
- strlen(sufp) > 2) fprintf(stderr,
- "%s: part of filename extension will be replaced by XF\n",
- cp);
- ***************
- *** 446,466 ****
-
- #ifdef MSDOS
- /* There is no difference between FOOBAR and FOOBAR. names */
- ! if ((cp = rindex(ofname, '.')) == NULL)
- ! strcat(ofname, ".F");
- else if (cp[1] == '\0')
- /* FOOBAR. case */
- ! strcat(ofname, "F");
- else {
- cp[2] = '\0';
- ! strcat(ofname, "XF");
- }
- #else
- ! strcat(ofname, ".F");
- #endif /* MSDOS */
-
- }
- - precious = 0;
- /* Check for overwrite of existing file */
- if (overwrite == 0 && topipe == 0) {
- if (stat(ofname, &statbuf) == 0) {
- --- 453,472 ----
-
- #ifdef MSDOS
- /* There is no difference between FOOBAR and FOOBAR. names */
- ! if ((cp = strrchr(ofname, '.')) == NULL)
- ! (void) strcat(ofname, ".F");
- else if (cp[1] == '\0')
- /* FOOBAR. case */
- ! (void) strcat(ofname, "F");
- else {
- cp[2] = '\0';
- ! (void) strcat(ofname, "XF");
- }
- #else
- ! (void) strcat(ofname, ".F");
- #endif /* MSDOS */
-
- }
- /* Check for overwrite of existing file */
- if (overwrite == 0 && topipe == 0) {
- if (stat(ofname, &statbuf) == 0) {
- ***************
- *** 472,479 ****
- #endif
- fprintf(stderr,
- " do you wish to overwrite %s (y or n)? ", ofname);
- ! fflush(stderr);
- ! read(2, response, 2);
- while (response[1] != '\n') {
- if (read(2, response+1, 1) < 0) { /* Ack! */
- perror("stderr"); break;
- --- 478,485 ----
- #endif
- fprintf(stderr,
- " do you wish to overwrite %s (y or n)? ", ofname);
- ! (void) fflush(stderr);
- ! (void) read(2, response, 2);
- while (response[1] != '\n') {
- if (read(2, response+1, 1) < 0) { /* Ack! */
- perror("stderr"); break;
- ***************
- *** 505,513 ****
- #ifdef DEBUG
- }
- #endif
- if(quiet != 1) {
- fprintf(stderr, "%s:", *fileptr);
- - indc_threshold = 2048;
- indc_count = 1024;
- }
- }
- --- 511,519 ----
- #ifdef DEBUG
- }
- #endif
- + precious = 0;
- if(quiet != 1) {
- fprintf(stderr, "%s:", *fileptr);
- indc_count = 1024;
- }
- }
- ***************
- *** 539,544 ****
- --- 545,551 ----
-
- if(topipe == 0)
- copystat(*fileptr); /* Copy stats */
- + precious = 1;
- }
- } else { /* Standard input */
- Pipe:
- ***************
- *** 546,559 ****
- perror("stdin");
- exit(1);
- }
- ! file_length = statbuf.st_size;
-
- indc_threshold = file_length / 100;
- if (indc_threshold < 4096)
- indc_threshold = 4096;
- - #ifdef DEBUG
- - fprintf(stderr, "File length: %ld\n", file_length);
- - #endif
-
- topipe = 1;
- if (do_melt == 0) {
- --- 553,563 ----
- perror("stdin");
- exit(1);
- }
- ! file_length = statbuf.st_mode & S_IFREG ? statbuf.st_size : 0;
-
- indc_threshold = file_length / 100;
- if (indc_threshold < 4096)
- indc_threshold = 4096;
-
- topipe = 1;
- if (do_melt == 0) {
- ***************
- *** 606,612 ****
-
- long in_count = 1; /* length of input */
- long bytes_out; /* length of frozen output */
- - long file_length = 0; /* initial length of file */
-
- /* Calculates and prints the compression ratio w/o floating point OPs */
-
- --- 610,615 ----
- ***************
- *** 651,669 ****
- fprintf(stream, " (%d.%02d bits)", (int)(q / 100), (int)(q % 100));
- }
-
- - /* From compress.c */
- -
- - char *
- - rindex(s, c) /* For those who don't have it in libc.a */
- - register char *s, c;
- - {
- - char *p;
- - for (p = NULL; *s; s++)
- - if (*s == c)
- - p = s;
- - return(p);
- - }
- -
- /* There was an error when reading or writing files */
-
- void writeerr()
- --- 654,659 ----
- ***************
- *** 670,676 ****
- {
- if (!topipe) {
- perror ( ofname );
- ! unlink ( ofname );
- }
- exit ( 1 );
- }
- --- 660,666 ----
- {
- if (!topipe) {
- perror ( ofname );
- ! (void) unlink ( ofname );
- }
- exit ( 1 );
- }
- ***************
- *** 680,696 ****
- {
- #ifdef __TURBOC__
- struct ftime utimbuf;
- #endif
- int mode;
- - #ifndef __TURBOC__
- - time_t timep[2];
- - #endif
-
- #ifdef MSDOS
- if (_osmajor < 3) freopen("CON","at",stdout); else /* MS-DOS 2.xx bug */
- #endif
-
- ! fclose(stdout);
-
- if (exit_stat == 2 && (!force)) { /* No freezing: remove file.F */
-
- --- 670,686 ----
- {
- #ifdef __TURBOC__
- struct ftime utimbuf;
- + #else
- + struct utimbuf timep;
- #endif
- +
- int mode;
-
- #ifdef MSDOS
- if (_osmajor < 3) freopen("CON","at",stdout); else /* MS-DOS 2.xx bug */
- #endif
-
- ! (void) fclose(stdout);
-
- if (exit_stat == 2 && (!force)) { /* No freezing: remove file.F */
-
- ***************
- *** 712,718 ****
-
- #ifndef MSDOS
- /* Copy ownership */
- ! chown(ofname, (int) statbuf.st_uid, (int) statbuf.st_gid);
- #endif
-
- #ifdef __TURBOC__
- --- 702,708 ----
-
- #ifndef MSDOS
- /* Copy ownership */
- ! (void) chown(ofname, (int) statbuf.st_uid, (int) statbuf.st_gid);
- #endif
-
- #ifdef __TURBOC__
- ***************
- *** 719,731 ****
- getftime(fileno(stdin),&utimbuf);
- freopen(ofname,"rb",stdout);
- setftime(fileno(stdout),&utimbuf);
- ! fclose(stdout);
- #else
- ! timep[0] = statbuf.st_atime;
- ! timep[1] = statbuf.st_mtime;
- ! utime(ofname, timep); /* Update last accessed and modified times */
- #endif
- - precious = 1;
- if (unlink(ifname)) /* Remove input file */
- perror(ifname);
- if(quiet != 1)
- --- 709,727 ----
- getftime(fileno(stdin),&utimbuf);
- freopen(ofname,"rb",stdout);
- setftime(fileno(stdout),&utimbuf);
- ! (void) fclose(stdout);
- #else
- ! timep.actime = statbuf.st_atime;
- ! timep.modtime = statbuf.st_mtime;
- !
- ! #if defined(__m88k__)
- ! timep.acusec= statbuf.st_ausec; /* pa@verano */
- ! timep.modusec= statbuf.st_musec;
- ! #endif /* !m88k */
- !
- ! /* Update last accessed and modified times */
- ! (void) utime(ofname, &timep);
- #endif
- if (unlink(ifname)) /* Remove input file */
- perror(ifname);
- if(quiet != 1)
- ***************
- *** 800,810 ****
- /* Exception handler (SIGINT) */
-
- onintr ( ) {
- ! if (!precious) {
- ! fclose(stdout);
- ! unlink ( ofname );
- }
- ! exit ( 1 );
- }
-
- #if defined(__TURBOC__) || !defined(INT_SIG)
- --- 796,806 ----
- /* Exception handler (SIGINT) */
-
- onintr ( ) {
- ! if (!precious) { /* topipe == 1 implies precious == 1 */
- ! (void) fclose(stdout);
- ! (void) unlink(ofname);
- }
- ! exit(1);
- }
-
- #if defined(__TURBOC__) || !defined(INT_SIG)
- ***************
- *** 815,821 ****
-
- oops ( ) /* file is corrupt or internal error */
- {
- ! fflush(stdout);
- fprintf(stderr, "Segmentation violation occured...\n");
- exit ( 1 );
- }
- --- 811,817 ----
-
- oops ( ) /* file is corrupt or internal error */
- {
- ! (void) fflush(stdout);
- fprintf(stderr, "Segmentation violation occured...\n");
- exit ( 1 );
- }
- ***************
- *** 868,874 ****
- int i, is_list = 0;
- if(!s) {
- /* try to consider 'type' as a list of values: n1,n2, ... */
- ! if(rindex(type, ','))
- is_list = 1;
- else {
- fprintf(stderr, "\"%s\" - no such file type\n", type);
- --- 864,870 ----
- int i, is_list = 0;
- if(!s) {
- /* try to consider 'type' as a list of values: n1,n2, ... */
- ! if(strrchr(type, ','))
- is_list = 1;
- else {
- fprintf(stderr, "\"%s\" - no such file type\n", type);
- ***************
- *** 881,887 ****
- exit(1);
- }
- }
- ! if(!is_list && (!(t = rindex(s, '=')) ||
- sscanf(++t, "%d %d %d %d %d %d %d %d",
- v, v+1, v+2, v+3, v+4, v+5, v+6, v+7) != 8)) {
- fprintf(stderr,
- --- 877,883 ----
- exit(1);
- }
- }
- ! if(!is_list && (!(t = strrchr(s, '=')) ||
- sscanf(++t, "%d %d %d %d %d %d %d %d",
- v, v+1, v+2, v+3, v+4, v+5, v+6, v+7) != 8)) {
- fprintf(stderr,
- diff -cr ../orig/freeze.h ./freeze.h
- *** ../orig/freeze.h Sun Nov 24 00:09:22 1991
- --- ./freeze.h Sun Nov 24 00:22:18 1991
- ***************
- *** 1,4 ****
- -
- #include <stdio.h>
-
- #ifdef SUN4
- --- 1,3 ----
- ***************
- *** 10,18 ****
- # ifndef putc
- # define putc(x, p) (--(p)->_cnt < 0 ? _flsbuf((unsigned char) (x), (p)) : (int) (*(p)->_ptr++ = (unsigned char) (x)))
- # endif
- - #ifndef BSD4_2
- - typedef unsigned short u_short;
- - #endif /* BSD4_2 */
- #endif /* SUN4 */
-
- #include <ctype.h>
- --- 9,14 ----
- ***************
- *** 20,25 ****
- --- 16,29 ----
- #include <sys/types.h>
- #include <sys/stat.h>
-
- + #ifndef __TURBOC__
- + #include <utime.h> /* Some systems have sys/utime.h instead of this */
- + #endif
- +
- + #if defined(BSD42) && !defined(BSD4_2)
- + #define BSD4_2
- + #endif
- +
- /* for MAXNAMLEN only !!! */
- #ifdef unix
- #ifndef BSD4_2
- ***************
- *** 53,64 ****
- #include <fcntl.h>
- #endif /* MSDOS */
-
- ! typedef unsigned char uchar;
-
- #if defined(BITS) && BITS > 14
- ! typedef unsigned long hash_t;
- #else
- ! typedef u_short hash_t;
- #endif /* BITS */
-
- #ifdef lint
- --- 57,70 ----
- #include <fcntl.h>
- #endif /* MSDOS */
-
- ! typedef unsigned short us_t;
- ! typedef unsigned char uc_t;
- ! typedef unsigned long ul_t;
-
- #if defined(BITS) && BITS > 14
- ! typedef ul_t hash_t;
- #else
- ! typedef us_t hash_t;
- #endif /* BITS */
-
- #ifdef lint
- ***************
- *** 75,99 ****
-
- #define ENDOF 256 /* pseudo-literal */
-
- ! extern uchar Table2[];
-
- extern long in_count, bytes_out, file_length;
-
- ! extern uchar text_buf[];
- ! extern u_short match_position, match_length;
-
- ! extern short quiet, force; /* useful flags */
-
- ! /* Note ind_threshold is triangle number of Kbytes */
-
- ! extern long indc_threshold, indc_count;
-
- - extern short do_melt, topipe, greedy;
- -
- - #define MAGIC1 ((uchar)'\037')
- - #define MAGIC2_1 ((uchar)'\236') /* freeze vers. 1.X */
- - #define MAGIC2_2 ((uchar)'\237')
- -
- extern int exit_stat;
-
- #ifdef DEBUG
- --- 81,100 ----
-
- #define ENDOF 256 /* pseudo-literal */
-
- ! extern uc_t Table2[];
-
- extern long in_count, bytes_out, file_length;
-
- ! extern uc_t text_buf[];
-
- ! extern long indc_threshold, indc_count;
-
- ! extern short do_melt, topipe, greedy, quiet, force; /* useful flags */
-
- ! #define MAGIC1 ((uc_t)'\037')
- ! #define MAGIC2_1 ((uc_t)'\236') /* freeze vers. 1.X */
- ! #define MAGIC2_2 ((uc_t)'\237')
-
- extern int exit_stat;
-
- #ifdef DEBUG
- ***************
- *** 110,119 ****
- extern short DecodeChar(), DecodePosition(), GetNBits();
- extern void melt2(), (*meltfunc)(), writeerr(), prratio(), prbits(), freeze();
-
- - #if defined(BSD42) && !defined(BSD4_2)
- - #define BSD4_2
- - #endif
- -
- #ifdef COMPAT
- #include "compat.h"
- #endif
- --- 111,116 ----
- ***************
- *** 123,130 ****
- if (ferror(stdout))\
- writeerr();\
- if (file_length) {\
- ! fprintf(stderr, " %2d%%\b\b\b\b",\
- ! ftell(stdin) * 100 / file_length);\
- indc_count += indc_threshold;\
- } else {\
- fprintf(stderr, " %5ldK\b\b\b\b\b\b\b", in_count / 1024);\
- --- 120,131 ----
- if (ferror(stdout))\
- writeerr();\
- if (file_length) {\
- ! static int percents, old_percents = -1;\
- ! if ((percents = ftell(stdin) * 100 / file_length) !=\
- ! old_percents) {\
- ! fprintf(stderr, " %2d%%\b\b\b\b", percents);\
- ! old_percents = percents;\
- ! }\
- indc_count += indc_threshold;\
- } else {\
- fprintf(stderr, " %5ldK\b\b\b\b\b\b\b", in_count / 1024);\
- ***************
- *** 136,139 ****
- --- 137,143 ----
-
- #ifdef BSD4_2
- #define strchr index
- + #define strrchr rindex
- #endif
- +
- + extern char *strchr(), *strrchr();
- diff -cr ../orig/huf.c ./huf.c
- *** ../orig/huf.c Sun Nov 24 00:09:19 1991
- --- ./huf.c Sun Nov 24 00:22:18 1991
- ***************
- *** 14,28 ****
- * it freely when melting.
- */
-
- ! uchar Table2[9] = { 0, 0, 1, 1, 1, 4, 10, 27, 18 };
-
- ! uchar p_len[64]; /* These arrays are built accordingly to values */
- ! uchar d_len[256]; /* of `Table' above which are default, from the */
- ! /* command line or from the header of frozen file */
-
- ! uchar code[256];
-
- ! u_short freq[T2 + 1]; /* frequency table */
- short son[T2]; /* points to son node (son[i],son[i+1]) */
- short prnt[T2 + N_CHAR2]; /* points to parent node */
-
- --- 14,28 ----
- * it freely when melting.
- */
-
- ! uc_t Table2[9] = { 0, 0, 1, 1, 1, 4, 10, 27, 18 };
-
- ! uc_t p_len[64]; /* These arrays are built accordingly to values */
- ! uc_t d_len[256]; /* of `Table' above which are default, from the */
- ! /* command line or from the header of frozen file */
-
- ! uc_t code[256];
-
- ! us_t freq[T2 + 1]; /* frequency table */
- short son[T2]; /* points to son node (son[i],son[i+1]) */
- short prnt[T2 + N_CHAR2]; /* points to parent node */
-
- ***************
- *** 76,83 ****
-
- void reconst ()
- {
- ! register u_short i, j, k;
- ! register u_short f;
-
- #ifdef DEBUG
- if (quiet < 0)
- --- 76,83 ----
-
- void reconst ()
- {
- ! register us_t i, j, k;
- ! register us_t f;
-
- #ifdef DEBUG
- if (quiet < 0)
- ***************
- *** 104,110 ****
- f = freq[j] = freq[i] + freq[k];
- for (k = j - 1; f < freq[k]; k--);
- k++;
- ! { register u_short *p, *e;
- for (p = &freq[j], e = &freq[k]; p > e; p--)
- p[0] = p[-1];
- freq[k] = f;
- --- 104,110 ----
- f = freq[j] = freq[i] + freq[k];
- for (k = j - 1; f < freq[k]; k--);
- k++;
- ! { register us_t *p, *e;
- for (p = &freq[j], e = &freq[k]; p > e; p--)
- p[0] = p[-1];
- freq[k] = f;
- ***************
- *** 130,139 ****
- /* Updates given code's frequency, and updates tree */
-
- void update (c)
- ! u_short c;
- {
- ! register u_short *p;
- ! register u_short i, j, k, l;
-
- if (freq[r] == MAX_FREQ) {
- reconst();
- --- 130,139 ----
- /* Updates given code's frequency, and updates tree */
-
- void update (c)
- ! us_t c;
- {
- ! register us_t *p;
- ! register us_t i, j, k, l;
-
- if (freq[r] == MAX_FREQ) {
- reconst();
- ***************
- *** 168,177 ****
- /* Encodes the literal or the length information */
-
- void EncodeChar (c)
- ! u_short c;
- {
- ! unsigned long i;
- ! register u_short j, k;
-
- i = 0;
- j = 0;
- --- 168,177 ----
- /* Encodes the literal or the length information */
-
- void EncodeChar (c)
- ! us_t c;
- {
- ! ul_t i;
- ! register us_t j, k;
-
- i = 0;
- j = 0;
- ***************
- *** 191,200 ****
- /* `j' never reaches the value of 32 ! */
-
- if (j > 16) {
- ! Putcode(16, (u_short)(i >> 16));
- ! Putcode(j - 16, (u_short)i);
- } else {
- ! Putcode(j, (u_short)(i >> 16));
- }
- update(c);
- }
- --- 191,200 ----
- /* `j' never reaches the value of 32 ! */
-
- if (j > 16) {
- ! Putcode(16, (us_t)(i >> 16));
- ! Putcode(j - 16, (us_t)i);
- } else {
- ! Putcode(j, (us_t)(i >> 16));
- }
- update(c);
- }
- ***************
- *** 202,217 ****
- /* Encodes the position information */
-
- void EncodePosition (c)
- ! register u_short c;
- {
- ! register u_short i;
-
- /* output upper 6 bit from table */
- i = c >> 7;
- ! Putcode((u_short)(p_len[i]), (u_short)(code[i]) << 8);
-
- /* output lower 7 bit */
- ! Putcode(7, (u_short)(c & 0x7f) << 9);
- }
-
-
- --- 202,217 ----
- /* Encodes the position information */
-
- void EncodePosition (c)
- ! register us_t c;
- {
- ! register us_t i;
-
- /* output upper 6 bit from table */
- i = c >> 7;
- ! Putcode((us_t)(p_len[i]), (us_t)(code[i]) << 8);
-
- /* output lower 7 bit */
- ! Putcode(7, (us_t)(c & 0x7f) << 9);
- }
-
-
- ***************
- *** 221,227 ****
-
- short DecodeChar ()
- {
- ! register u_short c;
- c = son[r];
-
- /* trace from root to leaf,
- --- 221,227 ----
-
- short DecodeChar ()
- {
- ! register us_t c;
- c = son[r];
-
- /* trace from root to leaf,
- ***************
- *** 245,251 ****
-
- short DecodePosition ()
- {
- ! register u_short i, j, c;
-
- /* decode upper 6 bits from the table */
-
- --- 245,251 ----
-
- short DecodePosition ()
- {
- ! register us_t i, j, c;
-
- /* decode upper 6 bits from the table */
-
- ***************
- *** 252,258 ****
- i = GetByte();
- crpt_flag = feof(stdin);
-
- ! c = (u_short)code[i] << 7;
- j = d_len[i] - 1;
-
- /* get lower 7 bits literally */
- --- 252,258 ----
- i = GetByte();
- crpt_flag = feof(stdin);
-
- ! c = (us_t)code[i] << 7;
- j = d_len[i] - 1;
-
- /* get lower 7 bits literally */
- ***************
- *** 263,269 ****
-
- /* Initializes static Huffman arrays */
-
- ! void init(table) uchar * table; {
- short i, j, k, num;
- num = 0;
-
- --- 263,269 ----
-
- /* Initializes static Huffman arrays */
-
- ! void init(table) uc_t * table; {
- short i, j, k, num;
- num = 0;
-
- ***************
- *** 309,315 ****
- */
-
- void write_header() {
- ! u_short i;
-
- i = Table2[5] & 0x1F; i <<= 4;
- i |= Table2[4] & 0xF; i <<= 3;
- --- 309,315 ----
- */
-
- void write_header() {
- ! us_t i;
-
- i = Table2[5] & 0x1F; i <<= 4;
- i |= Table2[4] & 0xF; i <<= 3;
- ***************
- *** 378,384 ****
-
- #ifdef COMPAT
-
- ! uchar Table1[9] = { 0, 0, 0, 1, 3, 8, 12, 24, 16 };
-
- /* Old version of a routine above for handling files made by
- the 1st version of Freeze.
- --- 378,384 ----
-
- #ifdef COMPAT
-
- ! uc_t Table1[9] = { 0, 0, 0, 1, 3, 8, 12, 24, 16 };
-
- /* Old version of a routine above for handling files made by
- the 1st version of Freeze.
- ***************
- *** 386,397 ****
-
- short DecodePOld ()
- {
- ! register u_short i, j, c;
-
- i = GetByte();
- crpt_flag = feof(stdin);
-
- ! c = (u_short)code[i] << 6;
- j = d_len[i] - 2;
-
- return c | (((i << j) | GetNBits (j)) & 0x3f);
- --- 386,397 ----
-
- short DecodePOld ()
- {
- ! register us_t i, j, c;
-
- i = GetByte();
- crpt_flag = feof(stdin);
-
- ! c = (us_t)code[i] << 6;
- j = d_len[i] - 2;
-
- return c | (((i << j) | GetNBits (j)) & 0x3f);
- diff -cr ../orig/huf.h ./huf.h
- *** ../orig/huf.h Sun Nov 24 00:09:22 1991
- --- ./huf.h Sun Nov 24 00:22:18 1991
- ***************
- *** 1,6 ****
-
- ! extern u_short freq[];
- extern short son[], prnt[];
- extern void StartHuff(), init(), write_header(), EncodeChar();
- extern void EncodePosition();
- ! #define MAX_FREQ (u_short)0x8000 /* Tree update timing */
- --- 1,6 ----
-
- ! extern us_t freq[];
- extern short son[], prnt[];
- extern void StartHuff(), init(), write_header(), EncodeChar();
- extern void EncodePosition();
- ! #define MAX_FREQ (us_t)0x8000 /* Tree update timing */
- diff -cr ../orig/lz.c ./lz.c
- *** ../orig/lz.c Sun Nov 24 00:09:23 1991
- --- ./lz.c Sun Nov 24 00:22:19 1991
- ***************
- *** 7,16 ****
- /* */
- /*----------------------------------------------------------------------*/
-
- ! uchar text_buf[N2 + F2 - 1]; /* cyclic buffer with an overlay */
- ! u_short match_position, match_length; /* current characteristics of a
- ! matched pattern */
-
- /* next[N+1..] is used as hash table,
- the rest of next is a link down,
- prev is a link up.
- --- 7,19 ----
- /* */
- /*----------------------------------------------------------------------*/
-
- ! uc_t text_buf[N2 + F2 - 1]; /* cyclic buffer with an overlay */
- ! us_t match_position, match_length; /* current characteristics of a
- ! matched pattern */
- ! us_t chain_length; /* max_chain_length ==
- ! CHAIN_THRESHOLD / greedy */
-
- +
- /* next[N+1..] is used as hash table,
- the rest of next is a link down,
- prev is a link up.
- ***************
- *** 20,59 ****
-
- #ifndef __XENIX__
- #ifdef __TURBOC__
- ! u_short huge * next = (u_short huge *) NULL;
- #else /* __TURBOC__ */
- ! u_short next[array_size]; /* a VERY large array :-) */
- #endif /* __TURBOC__ */
- #else /* __XENIX__ */
- #if parts == 2
- ! u_short next0[32768L], next1[8193];
- #else
- ! # if parts == 3
- ! u_short next0[32768L], next1[32768L], next2[8193];
- ! # else
- ! # if parts == 5
- ! u_short next0[32768L], next1[32768L], next2[32768L], next3[32768L], next4[8193];
- ! # else
- ! u_short next0[32768L], next1[32768L], next2[32768L], next3[32768L], next4[32768L],
- ! next5[32768L], next6[32768L], next7[32768L], next8[8193];
- ! # endif
- ! # endif
- #endif /* parts */
-
- /* A list of `next's parts */
-
- ! u_short *next[parts] = {
- next0, next1
- #if parts > 2
- ,next2
- - #if parts > 3
- - ,next3, next4
- - #if parts > 5
- - ,next5, next6,
- - next7, next8
- #endif
- - #endif
- - #endif
- };
- #endif /* __XENIX__ */
-
- --- 23,46 ----
-
- #ifndef __XENIX__
- #ifdef __TURBOC__
- ! us_t huge * next = (us_t huge *) NULL;
- #else /* __TURBOC__ */
- ! us_t next[array_size]; /* a VERY large array :-) */
- #endif /* __TURBOC__ */
- #else /* __XENIX__ */
- #if parts == 2
- ! us_t next0[32768L], next1[8193];
- #else
- ! us_t next0[32768L], next1[32768L], next2[8193];
- #endif /* parts */
-
- /* A list of `next's parts */
-
- ! us_t *next[parts] = {
- next0, next1
- #if parts > 2
- ,next2
- #endif
- };
- #endif /* __XENIX__ */
-
- ***************
- *** 74,84 ****
- #endif /* GATHER_STAT */
-
- #ifdef __TURBOC__
- ! if (!next && (next = (u_short huge *) farmalloc(
- ! (unsigned long)array_size * sizeof(u_short))) == NULL) {
-
- fprintf(stderr, "Not enough memory (%luK wanted)\n",
- ! (unsigned long)array_size * sizeof(u_short) / 1024);
- exit(3);
- }
- #endif /* __TURBOC__ */
- --- 61,71 ----
- #endif /* GATHER_STAT */
-
- #ifdef __TURBOC__
- ! if (!next && (next = (us_t huge *) farmalloc(
- ! (ul_t)array_size * sizeof(us_t))) == NULL) {
-
- fprintf(stderr, "Not enough memory (%luK wanted)\n",
- ! (ul_t)array_size * sizeof(us_t) / 1024);
- exit(3);
- }
- #endif /* __TURBOC__ */
- ***************
- *** 87,116 ****
- nextof(i) = NIL;
- for (i = 0; i < sizeof(prev)/sizeof(*prev); i++ )
- prev[i] = NIL;
- }
-
- ! /* Get the longest nearest match of the string beginning in text_buf[r]
- to the cyclic buffer. Result (length & position) is returned
- in correspondent global variables (`match_length' &
- ! `match_position'). `match_length' == 0 denotes failure.
- */
-
- #ifndef FAST
- void get_next_match (r)
- ! u_short r;
- {
- ! register u_short p = r;
- register int m;
- ! register uchar *key FIX_SI, *pattern FIX_DI;
- #ifdef GATHER_STAT
- node_matches++;
- #endif
- key = text_buf + r;
- - match_length = 0;
- do {
- do {
- ! if ((p = nextof(p)) == NIL)
- return;
- pattern = text_buf + p;
-
- MATCHING;
- --- 74,109 ----
- nextof(i) = NIL;
- for (i = 0; i < sizeof(prev)/sizeof(*prev); i++ )
- prev[i] = NIL;
- + chain_length = greedy ? CHAIN_THRESHOLD / greedy : 0;
- }
-
- ! /* Get the longest (longer than `match_length' when entering in subroutine)
- ! nearest match of the string beginning in text_buf[r]
- to the cyclic buffer. Result (length & position) is returned
- in correspondent global variables (`match_length' &
- ! `match_position'). Unchanged `match_length' denotes failure.
- */
-
- #ifndef FAST
- void get_next_match (r)
- ! us_t r;
- {
- ! register us_t p = r;
- register int m;
- ! register uc_t *key FIX_SI, *pattern FIX_DI;
- ! int chain_count = chain_length;
- #ifdef GATHER_STAT
- node_matches++;
- #endif
- key = text_buf + r;
- do {
- do {
- ! /* From ZIP 1.0 by J.-L. Gailly et al. */
- !
- ! if ((p = nextof(p)) == NIL ||
- ! (greedy && !chain_count--))
- return;
- +
- pattern = text_buf + p;
-
- MATCHING;
- diff -cr ../orig/lz.h ./lz.h
- *** ../orig/lz.h Sun Nov 24 00:09:23 1991
- --- ./lz.h Sun Nov 24 00:22:19 1991
- ***************
- *** 9,17 ****
- #define BITS 13 /* 1:1 hash */
- #endif
-
- ! #if BITS > 21
- #undef BITS
- ! #define BITS 21 /* 4 MB hash table, if sizeof(u_short) == 2 */
- #endif
-
- /* The following hash-function isn't optimal but it is very fast:
- --- 9,17 ----
- #define BITS 13 /* 1:1 hash */
- #endif
-
- ! #if BITS > 16
- #undef BITS
- ! #define BITS 16 /* 128K hash table, if sizeof(us_t) == 2 */
- #endif
-
- /* The following hash-function isn't optimal but it is very fast:
- ***************
- *** 29,39 ****
-
- #if defined(M_XENIX) && defined(I_286) && (BITS > 14)
- #define __XENIX__
- - #if BITS > 18
- - #undef BITS
- - #define BITS 18
- #endif
- - #endif
-
- /* `array_size' is the size of array `next', which contains
- the heads of linked lists and the references to
- --- 29,35 ----
- ***************
- *** 43,80 ****
- #define array_size (N2 + 1 + (1L << BITS))
-
- extern hash_t prev[];
-
- #ifndef __XENIX__
- #define nextof(i) next[i]
-
- #ifdef __TURBOC__
- ! extern u_short huge * next;
- #else /* __TURBOC__ */
- ! extern u_short next[];
- #endif /* __TURBOC__ */
-
- #else /* __XENIX__ */
-
- /* We divide the array `next' in `parts' which fit into 286's segment */
-
- #define parts (array_size/32768 + 1)
- #define nextof(i) next[(i) >> 15][(i) & 0x7fff]
- #if parts == 2
- ! extern u_short next0[], next1[];
- #else
- ! # if parts == 3
- ! extern u_short next0[], next1[], next2[];
- ! # else
- ! # if parts == 5
- ! extern u_short next0[], next1[], next2[], next3[], next4[];
- ! # else
- ! extern u_short next0[], next1[], next2[], next3[], next4[],
- ! next5[], next6[], next7[], next8[];
- ! # endif
- ! # endif
- #endif /* parts */
-
- ! extern u_short *next[];
- #endif /* __XENIX__ */
-
- /* Some defines to eliminate function-call overhead */
- --- 39,69 ----
- #define array_size (N2 + 1 + (1L << BITS))
-
- extern hash_t prev[];
- + extern us_t match_position, match_length, chain_length;
-
- #ifndef __XENIX__
- #define nextof(i) next[i]
-
- #ifdef __TURBOC__
- ! extern us_t huge * next;
- #else /* __TURBOC__ */
- ! extern us_t next[];
- #endif /* __TURBOC__ */
-
- #else /* __XENIX__ */
-
- /* We divide the array `next' in `parts' which fit into 286's segment */
- + /* There may be 2 or 3 parts, because BITS <= 16 now */
-
- #define parts (array_size/32768 + 1)
- #define nextof(i) next[(i) >> 15][(i) & 0x7fff]
- #if parts == 2
- ! extern us_t next0[], next1[];
- #else
- ! extern us_t next0[], next1[], next2[];
- #endif /* parts */
-
- ! extern us_t *next[];
- #endif /* __XENIX__ */
-
- /* Some defines to eliminate function-call overhead */
- ***************
- *** 93,100 ****
-
- #define InsertNode(r)\
- {\
- ! register hash_t p; register u_short first_son;\
- ! register uchar *key;\
- key = &text_buf[r];\
- p = N2 + 1 + (((hash_t)key[0] + ((hash_t)key[1] << LEN0) +\
- ((hash_t)key[2] << LEN1)) & ((1L << BITS) - 1));\
- --- 82,89 ----
-
- #define InsertNode(r)\
- {\
- ! register hash_t p; register us_t first_son;\
- ! register uc_t *key;\
- key = &text_buf[r];\
- p = N2 + 1 + (((hash_t)key[0] + ((hash_t)key[1] << LEN0) +\
- ((hash_t)key[2] << LEN1)) & ((1L << BITS) - 1));\
- ***************
- *** 163,168 ****
- --- 152,159 ----
-
- #endif
-
- + #define CHAIN_THRESHOLD (F2 * 3)
- +
- #ifdef FAST
- /* Simple inline replacement for get_next_match; they match
- literally except return --> goto quote(leave)l. No obfuscations !! */
- ***************
- *** 173,186 ****
- #define LEAVE(num) leave/**/num
- #endif
-
- ! #define Get_Next_Match(r,l) {register u_short p=r;register int m;\
- ! register uchar *key FIX_SI, *pattern FIX_DI;key=text_buf+r;\
- ! match_length=0;do{ do{ if((p=nextof(p))==NIL)goto LEAVE(l);\
- ! pattern=text_buf+p;MATCHING;}while NOT_YET;\
- ! for(m=match_length;++m<F2&&key[m]==pattern[m];); \
- match_length=m;match_position=((r-p)&(N2-1))-1;}while(m<F2);\
- ! nextof(prev[p])=nextof(p);prev[nextof(p)]=prev[p];prev[p]=NIL; \
- ! LEAVE(l):;}
-
- #else
-
- --- 164,176 ----
- #define LEAVE(num) leave/**/num
- #endif
-
- ! #define Get_Next_Match(r,l) {register us_t p=r;register int m;\
- ! register uc_t *key FIX_SI, *pattern FIX_DI;int chain_count=chain_length;\
- ! key=text_buf+r;do{ do{ if((p=nextof(p))==NIL||(greedy &&\
- ! !chain_count--))goto LEAVE(l);pattern=text_buf+p;MATCHING;}while NOT_YET;\
- ! for(m=match_length;++m<F2&&key[m]==pattern[m];);\
- match_length=m;match_position=((r-p)&(N2-1))-1;}while(m<F2);\
- ! nextof(prev[p])=nextof(p);prev[nextof(p)]=prev[p];prev[p]=NIL;LEAVE(l):;}
-
- #else
-
- diff -cr ../orig/makefile ./makefile
- *** ../orig/makefile Sun Nov 24 00:09:24 1991
- --- ./makefile Sun Nov 24 00:22:19 1991
- ***************
- *** 13,19 ****
-
- CC = gcc
-
- ! CFLAGS = -DBITS=18 -O -DCOMPAT -DFAST -fstrength-reduce #-DBSD42 -DSUN4
-
- LINTFLAGS = -DBITS=15 -DCOMPAT -DDEBUG -DGATHER_STAT -x -DFAST
-
- --- 13,19 ----
-
- CC = gcc
-
- ! CFLAGS = -DBITS=16 -O -DCOMPAT -DFAST -fstrength-reduce #-DBSD42 -DSUN4
-
- LINTFLAGS = -DBITS=15 -DCOMPAT -DDEBUG -DGATHER_STAT -x -DFAST
-
- ***************
- *** 30,38 ****
-
- PROGRAM = freeze
-
- ! CATMAN = freeze.man
-
- ! MAN = freeze.1
-
- SRCS = bitio.c\
- debug.c\
- --- 30,38 ----
-
- PROGRAM = freeze
-
- ! CATMAN = freeze.man statist.man
-
- ! MAN = freeze.1 statist.1
-
- SRCS = bitio.c\
- debug.c\
- ***************
- *** 43,50 ****
- huf.c\
- lz.c
-
- ! all: $(PROGRAM) statist $(CATMAN)
-
- lint: $(SRCS)
- lint $(LINTFLAGS) $(SRCS) > lint.out
-
- --- 43,57 ----
- huf.c\
- lz.c
-
- ! .SUFFIXES: .1 .man
-
- + .1.man:
- + nroff -man < $< > $@
- +
- + all: $(PROGRAM) statist man
- +
- + man: $(CATMAN)
- +
- lint: $(SRCS)
- lint $(LINTFLAGS) $(SRCS) > lint.out
-
- ***************
- *** 54,63 ****
- statist: statist.o lz.o
- $(CC) $(CFLAGS) $(LDFLAGS) -o statist statist.o lz.o $(LIBS)
-
- ! clean:; rm -f *.o *.b .,* core *.out $(PROGRAM) statist
-
- ! install: $(DEST)/$(PROGRAM) $(MANDEST)/$(MAN)
-
- patch:; rm -f patch.out
- -for i in ../distribution/* ; do \
- (diff -c $$i `basename $$i` >> patch.out); \
- --- 61,73 ----
- statist: statist.o lz.o
- $(CC) $(CFLAGS) $(LDFLAGS) -o statist statist.o lz.o $(LIBS)
-
- ! clobber: clean
- ! rm -f $(PROGRAM) statist *.man
-
- ! clean:; rm -f *.o *.b .,* core *.out
-
- + install: $(DEST)/$(PROGRAM) $(MANDEST)/freeze.1 $(MANDEST)/statist.1
- +
- patch:; rm -f patch.out
- -for i in ../distribution/* ; do \
- (diff -c $$i `basename $$i` >> patch.out); \
- ***************
- *** 64,81 ****
- done
-
- $(DEST)/$(PROGRAM): $(PROGRAM)
- ! install -s -c $(PROGRAM) $(DEST)
- ! ln -f $(DEST)/$(PROGRAM) $(DEST)/melt
- ! ln -f $(DEST)/$(PROGRAM) $(DEST)/fcat
-
- ! $(MANDEST)/$(MAN): $(CATMAN)
- ! cp $(CATMAN) $(MANDEST)/$(MAN)
- ! chmod +r $(MANDEST)/$(MAN)
- ! ln -f $(MANDEST)/$(MAN) $(MANDEST)/melt.1
- ! ln -f $(MANDEST)/$(MAN) $(MANDEST)/fcat.1
-
- ! $(CATMAN): $(MAN)
- ! nroff -man < $(MAN) > $(CATMAN)
-
- ###
- bitio.o: freeze.h compat.h bitio.h
- --- 74,94 ----
- done
-
- $(DEST)/$(PROGRAM): $(PROGRAM)
- ! -strip $(PROGRAM)
- ! -mcs -d $(PROGRAM)
- ! install -m 755 $(PROGRAM) $(DEST)
- ! -ln -f $@ $(DEST)/melt
- ! -ln -f $@ $(DEST)/fcat
-
- ! $(MANDEST)/freeze.1: freeze.man
- ! cp freeze.man $@
- ! chmod +r $@
- ! -ln -f $@ $(MANDEST)/melt.1
- ! -ln -f $@ $(MANDEST)/fcat.1
-
- ! $(MANDEST)/statist.1: statist.man
- ! cp statist.man $@
- ! chmod +r $@
-
- ###
- bitio.o: freeze.h compat.h bitio.h
- diff -cr ../orig/patchlevel.h ./patchlevel.h
- *** ../orig/patchlevel.h Sun Nov 24 00:09:24 1991
- --- ./patchlevel.h Sun Nov 24 00:29:56 1991
- ***************
- *** 1,2 ****
- ! #define PATCHLEVEL 0
- ! #define PATCHDATE "11/1/91"
- --- 1,2 ----
- ! #define PATCHLEVEL 1
- ! #define PATCHDATE "11/20/91"
- diff -cr ../orig/statist.c ./statist.c
- *** ../orig/statist.c Sun Nov 24 00:09:25 1991
- --- ./statist.c Sun Nov 24 00:22:20 1991
- ***************
- *** 11,17 ****
-
- #define update(c) (freq[c]++)
-
- ! long in_count, bytes_out;
-
- long indc_count;
- short reduceflag = 0, greedy = 0;
- --- 11,17 ----
-
- #define update(c) (freq[c]++)
-
- ! long in_count, refers = 0;
-
- long indc_count;
- short reduceflag = 0, greedy = 0;
- ***************
- *** 18,27 ****
-
- int lens[F2+1];
-
- ! u_short bits[9];
-
- short prnt[T];
- ! unsigned long freq[T];
- short used[T];
-
- void freeze(), StartHuff();
- --- 18,27 ----
-
- int lens[F2+1];
-
- ! us_t bits[9];
-
- short prnt[T];
- ! ul_t freq[T];
- short used[T];
-
- void freeze(), StartHuff();
- ***************
- *** 35,50 ****
- argv++;
- while (argc > 1) {
- if (**argv == '-') {
- ! if ((*argv)[1] == 'g') {
- ! argc--; argv++;
- greedy++;
- ! } else
- ! break;
- } else
- break;
- }
- if(argc != 1) {
- ! fprintf(stderr, "Usage: statist [-g] < sample_file\n");
- fprintf(stderr, "Press INTR to display current values\n");
- exit(0);
- }
- --- 35,51 ----
- argv++;
- while (argc > 1) {
- if (**argv == '-') {
- ! while (*++(*argv) == 'g')
- greedy++;
- ! if (**argv)
- ! goto usage;
- ! argc--; argv++;
- } else
- break;
- }
- + usage:
- if(argc != 1) {
- ! fprintf(stderr, "Usage: statist [-g...] < sample_file\n");
- fprintf(stderr, "Press INTR to display current values\n");
- exit(0);
- }
- ***************
- *** 59,75 ****
- return 0;
- }
-
- ! unsigned long isqrt(val)
- ! unsigned long val;
- {
- ! unsigned long result = 0;
- ! unsigned long side = 0;
- ! unsigned long left = 0;
- int digit = 0;
- int i;
- ! for (i=0; i<sizeof(unsigned long)*4; i++)
- {
- ! left = (left << 2) + (val >> 30);
- val <<= 2;
- if (left >= side*2 + 1)
- {
- --- 60,76 ----
- return 0;
- }
-
- ! ul_t isqrt(val)
- ! ul_t val;
- {
- ! ul_t result = 0;
- ! ul_t side = 0;
- ! ul_t left = 0;
- int digit = 0;
- int i;
- ! for (i=0; i<sizeof(ul_t)*4; i++)
- {
- ! left = (left << 2) + (val >> (sizeof(ul_t) * 8 - 2));
- val <<= 2;
- if (left >= side*2 + 1)
- {
- ***************
- *** 99,107 ****
- void
- #endif
- giveres() {
- ! u_short c;
- register int i, j, k, pr, f, average, sum;
- ! unsigned long cumul, sigma2;
- short r, percent;
- signal(SIGINT, giveres);
- newtry:
- --- 100,108 ----
- void
- #endif
- giveres() {
- ! us_t c;
- register int i, j, k, pr, f, average, sum;
- ! ul_t cumul, sigma2;
- short r, percent;
- signal(SIGINT, giveres);
- newtry:
- ***************
- *** 126,132 ****
- bits[j]++;
- if (j < pr)
- f += pr - j;
- ! pr = j;
- }
-
- k = bits[1] + bits[2] + bits[3] + bits[4] +
- --- 127,134 ----
- bits[j]++;
- if (j < pr)
- f += pr - j;
- ! else
- ! pr = j;
- }
-
- k = bits[1] + bits[2] + bits[3] + bits[4] +
- ***************
- *** 162,168 ****
- }
- sum = 0; cumul = 0;
- for(i = 3; i <= F2; i++) {
- ! cumul += (unsigned long) i * lens[i];
- sum += lens[i];
- }
- sum || sum++;
- --- 164,170 ----
- }
- sum = 0; cumul = 0;
- for(i = 3; i <= F2; i++) {
- ! cumul += (ul_t) i * lens[i];
- sum += lens[i];
- }
- sum || sum++;
- ***************
- *** 187,196 ****
- }
- }
- for (sigma2 = 0, i = 3; i <= F2; i++)
- ! sigma2 += (unsigned long)(i - average)*(i - average)*lens[i];
- sigma2 = sigma2 * 100 / sum;
- j = (int)isqrt(sigma2);
- printf("Sigma: %d.%1d\n", j / 10, j % 10);
- fflush(stdout);
- }
-
- --- 189,199 ----
- }
- }
- for (sigma2 = 0, i = 3; i <= F2; i++)
- ! sigma2 += (ul_t)(i - average)*(i - average)*lens[i];
- sigma2 = sigma2 * 100 / sum;
- j = (int)isqrt(sigma2);
- printf("Sigma: %d.%1d\n", j / 10, j % 10);
- + printf("References: %ld\n", refers);
- fflush(stdout);
- }
-
- ***************
- *** 197,203 ****
-
- void freeze ()
- {
- ! register u_short i, len, r, s;
- register short c;
- StartHuff(0);
- InitTree();
- --- 200,206 ----
-
- void freeze ()
- {
- ! register us_t i, len, r, s;
- register short c;
- StartHuff(0);
- InitTree();
- ***************
- *** 211,216 ****
- --- 214,220 ----
- for (i = 0; i <= F2; i++)
- InsertNode(r + i - F2);
- while (len != 0) {
- + match_length = THRESHOLD;
- Get_Next_Match(r,1);
- if (match_length > len)
- match_length = len;
- ***************
- *** 218,226 ****
- match_length = 1;
- } else if (greedy) {
- lens[match_length] ++;
- ! update((u_short)match_position >> 7);
- } else {
- ! register u_short orig_length, orig_position;
- orig_length = match_length;
- orig_position = match_position;
- DeleteNode(s);
- --- 222,231 ----
- match_length = 1;
- } else if (greedy) {
- lens[match_length] ++;
- ! update((us_t)match_position >> 7);
- ! refers ++;
- } else {
- ! register us_t orig_length, orig_position;
- orig_length = match_length;
- orig_position = match_position;
- DeleteNode(s);
- ***************
- *** 229,240 ****
- if (match_length > len) match_length = len;
- if (orig_length > match_length) {
- lens[orig_length] ++;
- ! update((u_short)orig_position >> 7);
- match_length = orig_length - 1;
- } else {
- lens[match_length] ++;
- update(match_position >> 7);
- }
- }
- for (i = 0; i < match_length &&
- (c = getchar()) != EOF; i++) {
- --- 234,246 ----
- if (match_length > len) match_length = len;
- if (orig_length > match_length) {
- lens[orig_length] ++;
- ! update((us_t)orig_position >> 7);
- match_length = orig_length - 1;
- } else {
- lens[match_length] ++;
- update(match_position >> 7);
- }
- + refers ++;
- }
- for (i = 0; i < match_length &&
- (c = getchar()) != EOF; i++) {
- exit 0 # Just in case...
- exit 0 # Just in case...
-