2 * compress - File compression ala IEEE Computer, June 1984.
4 * Algorithm from "A Technique for High Performance Data Compression",
5 * Terry A. Welch, IEEE Computer Vol 17, No 6 (June 1984), pp 8-19.
7 * Usage: compress [-dfvc] [-b bits] [file ...]
9 * -b: limit the max number of bits/code.
10 * -c: write output on stdout, don't remove original.
11 * -d: decompress instead.
12 * -f: Forces output file to be generated, even if one already
13 * exists, and even if no space is saved by compressing.
14 * If -f is not used, the user will be prompted if stdin is
15 * a tty, otherwise, the output file will not be overwritten.
16 * -v: Write compression statistics
18 * file ...: Files to be compressed. If none specified, stdin is used.
20 * file.Z: Compressed form of file with same mode, owner, and utimes
21 * or stdout (if stdin used as input)
24 * When filenames are given, replaces with the compressed version
25 * (.Z suffix) only if the file decreases in size.
27 * Modified Lempel-Ziv method (LZW). Basically finds common
28 * substrings and replaces them with a variable size code. This is
29 * deterministic, and can be done on the fly. Thus, the decompression
30 * procedure needs no input table, but tracks the way the table was built.
32 * Authors: Spencer W. Thomas (decvax!harpo!utah-cs!utah-gr!thomas)
33 * Jim McKie (decvax!mcvax!jim)
34 * Steve Davies (decvax!vax135!petsd!peora!srd)
35 * Ken Turkowski (decvax!decwrl!turtlevax!ken)
36 * James A. Woods (decvax!ihnp4!ames!jaw)
37 * Joe Orost (decvax!vax135!petsd!joe)
41 # define USED(x) if(x);else
45 #define _BSD_EXTENSION
56 #include <sys/types.h>
59 #define min(a,b) ((a>b) ? b : a)
62 #define HSIZE 69001 /* 95% occupancy */
65 * a code_int must be able to hold 2**BITS values of type int, and also -1
67 typedef long code_int;
68 typedef long count_int;
70 static char rcs_ident[] = "$Header: compress.c,v 4.0 85/07/30 12:50:00 joe Release $";
72 uchar magic_header[] = { 0x1F, 0x9D }; /* 1F 9D */
74 /* Defines for third byte of header */
76 #define BLOCK_MASK 0x80
77 /* Masks 0x40 and 0x20 are free. I think 0x20 should mean that there is
78 a fourth header byte (for expansion).
80 #define INIT_BITS 9 /* initial number of bits/code */
82 #define ARGVAL() (*++(*argv) || (--argc && *++argv))
84 int n_bits; /* number of bits/code */
85 int maxbits = BITS; /* user settable max # bits/code */
86 code_int maxcode; /* maximum code, given n_bits */
87 code_int maxmaxcode = 1 << BITS; /* should NEVER generate this code */
89 #define MAXCODE(n_bits) ((1 << (n_bits)) - 1)
91 count_int htab[HSIZE];
92 ushort codetab[HSIZE];
94 #define htabof(i) htab[i]
95 #define codetabof(i) codetab[i]
97 code_int hsize = HSIZE; /* for dynamic table sizing */
101 * To save much memory, we overlay the table used by compress() with those
102 * used by decompress(). The tab_prefix table is the same size and type
103 * as the codetab. The tab_suffix table needs 2**BITS characters. We
104 * get this from the beginning of htab. The output stack uses the rest
105 * of htab, and contains characters. There is plenty of room for any
106 * possible stack (stack used to be 8000 characters).
109 #define tab_prefixof(i) codetabof(i)
110 #define tab_suffixof(i) ((uchar *)(htab))[i]
111 #define de_stack ((uchar *)&tab_suffixof(1<<BITS))
113 code_int free_ent = 0; /* first unused entry */
117 void cl_hash(count_int);
119 void copystat(char *, char *);
120 void decompress(void);
121 int foreground(void);
122 code_int getcode(void);
125 void output(code_int);
126 void prratio(FILE *, long, long);
134 fprintf(stderr,"Usage: compress [-cdfDV] [-b maxbits] [file ...]\n");
136 fprintf(stderr,"Usage: compress [-cdfvV] [-b maxbits] [file ...]\n");
141 int nomagic = 0; /* Use a 3-byte magic number header, unless old file */
142 int zcat_flg = 0; /* Write output on stdout, suppress messages */
143 int quiet = 1; /* don't tell me about compression */
146 * block compression parameters -- after all codes are used up,
147 * and compression rate changes, start over.
149 int block_compress = BLOCK_MASK;
152 #define CHECK_GAP 10000 /* ratio check interval */
153 count_int checkpoint = CHECK_GAP;
155 * the next two codes should not be changed lightly, as they must not
156 * lie within the contiguous general code space.
158 #define FIRST 257 /* first free entry */
159 #define CLEAR 256 /* table clear output code */
166 void (*bgnd_flag)(int);
175 int overwrite = 0; /* Do not overwrite unless given -f flag */
177 char **filelist, **fileptr;
181 if ( (bgnd_flag = signal ( SIGINT, SIG_IGN )) != SIG_IGN ) {
182 signal(SIGINT, onintr);
183 signal(SIGSEGV, oops);
186 filelist = fileptr = (char **)(malloc(argc * sizeof(*argv)));
189 if((cp = strrchr(argv[0], '/')) != 0)
193 if(strcmp(cp, "uncompress") == 0)
195 else if(strcmp(cp, "zcat") == 0) {
201 * Argument Processing
202 * All flags are optional.
203 * -C generate output compatible with compress 2.0.
205 * -V print Version; debug verbose
206 * -b maxbits maxbits. If -b is specified, then maxbits MUST be
208 * -c cat all output to stdout
210 * -f force overwrite of output file
211 * -n no header: useful to uncompress old files
213 * if a string is left, must be an input filename.
215 for (argc--, argv++; argc > 0; argc--, argv++) {
216 if (**argv == '-') { /* A flag argument */
217 while (*++(*argv)) { /* Process all flags in this arg */
237 fprintf(stderr, "Missing maxbits\n");
241 maxbits = atoi(*argv);
264 fprintf(stderr, "Unknown flag: '%c'; ", **argv);
269 } else { /* Input file name */
270 *fileptr++ = *argv; /* Build input file list */
272 /* process nextarg; */
278 if(maxbits < INIT_BITS) maxbits = INIT_BITS;
279 if (maxbits > BITS) maxbits = BITS;
280 maxmaxcode = 1 << maxbits;
282 if (*filelist != NULL) {
283 for (fileptr = filelist; *fileptr; fileptr++) {
285 if (do_decomp != 0) { /* DECOMPRESSION */
286 /* Check for .Z suffix */
287 if (strcmp(*fileptr + strlen(*fileptr) - 2, ".Z") != 0) {
288 /* No .Z: tack one on */
289 strcpy(tempname, *fileptr);
290 strcat(tempname, ".Z");
293 /* Open input file */
294 if ((freopen(*fileptr, "r", stdin)) == NULL) {
298 /* Check the magic number */
300 if ((getchar() != (magic_header[0] & 0xFF))
301 || (getchar() != (magic_header[1] & 0xFF))) {
302 fprintf(stderr, "%s: not in compressed format\n",
306 maxbits = getchar(); /* set -b from file */
307 block_compress = maxbits & BLOCK_MASK;
309 maxmaxcode = 1 << maxbits;
312 "%s: compressed with %d bits, can only handle %d bits\n",
313 *fileptr, maxbits, BITS);
317 /* Generate output filename */
318 strcpy(ofname, *fileptr);
319 ofname[strlen(*fileptr) - 2] = '\0'; /* Strip off .Z */
320 } else { /* COMPRESSION */
321 if (strcmp(*fileptr + strlen(*fileptr) - 2, ".Z") == 0) {
323 "%s: already has .Z suffix -- no change\n",
327 /* Open input file */
328 if ((freopen(*fileptr, "r", stdin)) == NULL) {
332 (void) stat(*fileptr, &statbuf);
333 fsize = (long) statbuf.st_size;
335 * tune hash table size for small files -- ad hoc,
336 * but the sizes match earlier #defines, which
337 * serve as upper bounds on the number of output codes.
340 if (fsize < (1 << 12))
341 hsize = min(5003, HSIZE);
342 else if (fsize < (1 << 13))
343 hsize = min(9001, HSIZE);
344 else if (fsize < (1 << 14))
345 hsize = min (18013, HSIZE);
346 else if (fsize < (1 << 15))
347 hsize = min (35023, HSIZE);
348 else if (fsize < 47000)
349 hsize = min (50021, HSIZE);
351 /* Generate output filename */
352 strcpy(ofname, *fileptr);
354 if ((cp=strrchr(ofname,'/')) != NULL)
359 *** changed 12 to 25; should be NAMELEN-3, but I don't want
360 * to fight the headers. ehg 5 Nov 92 **
362 if (strlen(cp) > 25) {
363 fprintf(stderr, "%s: filename too long to tack on .Z\n",
368 strcat(ofname, ".Z");
370 /* Check for overwrite of existing file */
371 if (overwrite == 0 && zcat_flg == 0 &&
372 stat(ofname, &statbuf) == 0) {
376 fprintf(stderr, "%s already exists;", ofname);
379 " do you wish to overwrite %s (y or n)? ",
382 (void) read(2, response, 2);
383 while (response[1] != '\n')
384 if (read(2, response+1, 1) < 0) {
390 if (response[0] != 'y') {
391 fprintf(stderr, "\tnot overwritten\n");
395 if(zcat_flg == 0) { /* Open output file */
396 if (freopen(ofname, "w", stdout) == NULL) {
401 fprintf(stderr, "%s: ", *fileptr);
404 /* Actually do the compression/decompression */
419 copystat(*fileptr, ofname); /* Copy stats */
420 if (exit_stat == 1 || !quiet)
424 } else { /* Standard input */
425 if (do_decomp == 0) {
434 /* Check the magic number */
436 if ((getchar()!=(magic_header[0] & 0xFF))
437 || (getchar()!=(magic_header[1] & 0xFF))) {
438 fprintf(stderr, "stdin: not in compressed format\n");
441 maxbits = getchar(); /* set -b from file */
442 block_compress = maxbits & BLOCK_MASK;
444 maxmaxcode = 1 << maxbits;
445 fsize = 100000; /* assume stdin large for USERMEM */
448 "stdin: compressed with %d bits, can only handle %d bits\n",
470 long in_count = 1; /* length of input */
471 long bytes_out; /* length of compressed output */
472 long out_count = 0; /* # of codes output (for debugging) */
475 * compress stdin to stdout
477 * Algorithm: use open addressing double hashing (no chaining) on the
478 * prefix code / next character combination. We do a variant of Knuth's
479 * algorithm D (vol. 3, sec. 6.4) along with G. Knott's relatively-prime
480 * secondary probe. Here, the modular division first probe is gives way
481 * to a faster exclusive-or manipulation. Also do block compression with
482 * an adaptive reset, whereby the code table is cleared when the compression
483 * ratio decreases, but after the table fills. The variable-length output
484 * codes are re-sized at this point, and a special CLEAR code is generated
485 * for the decompressor. Late addition: construct the table according to
486 * file size for noticeable speed improvement on small files. Please direct
487 * questions about this implementation to ames!jaw.
492 code_int ent, hsize_reg;
498 putchar(magic_header[0]);
499 putchar(magic_header[1]);
500 putchar((char)(maxbits | block_compress));
505 bytes_out = 3; /* includes 3-byte header mojo */
510 checkpoint = CHECK_GAP;
511 maxcode = MAXCODE(n_bits = INIT_BITS);
512 free_ent = (block_compress? FIRST: 256);
517 for (fcode = (long)hsize; fcode < 65536L; fcode *= 2)
519 hshift = 8 - hshift; /* set hash code range bound */
522 cl_hash( (count_int) hsize_reg); /* clear hash table */
524 while ((c = getchar()) != EOF) {
526 fcode = (long) (((long) c << maxbits) + ent);
527 i = ((c << hshift) ^ ent); /* xor hashing */
529 if (htabof (i) == fcode) {
532 } else if ((long)htabof(i) < 0 ) /* empty slot */
534 disp = hsize_reg - i; /* secondary hash (after G. Knott) */
541 if (htabof (i) == fcode) {
545 if ((long)htabof(i) > 0)
548 output((code_int)ent);
551 if (free_ent < maxmaxcode) {
552 codetabof(i) = free_ent++; /* code -> hashtable */
554 } else if ((count_int)in_count >= checkpoint && block_compress)
558 * Put out the final code.
560 output( (code_int)ent );
562 output( (code_int)-1 );
565 * Print out stats on stderr
567 if(zcat_flg == 0 && !quiet) {
570 "%ld chars in, %ld codes (%ld bytes) out, compression factor: ",
571 in_count, out_count, bytes_out );
572 prratio( stderr, in_count, bytes_out );
573 fprintf( stderr, "\n");
574 fprintf( stderr, "\tCompression as in compact: " );
575 prratio( stderr, in_count-bytes_out, in_count );
576 fprintf( stderr, "\n");
577 fprintf( stderr, "\tLargest code (of last block) was %d (%d bits)\n",
578 free_ent - 1, n_bits );
580 fprintf( stderr, "Compression: " );
581 prratio( stderr, in_count-bytes_out, in_count );
584 if(bytes_out > in_count) /* exit(2) if no savings */
591 * Output the given code.
593 * code: A n_bits-bit integer. If == -1, then EOF. This assumes
594 * that n_bits =< (long)wordsize - 1.
596 * Outputs code to the file.
598 * Chars are 8 bits long.
600 * Maintain a BITS character long buffer (so that 8 codes will
601 * fit in it exactly). When the buffer fills up empty it and start over.
604 static char buf[BITS];
606 uchar lmask[9] = {0xff, 0xfe, 0xfc, 0xf8, 0xf0, 0xe0, 0xc0, 0x80, 0x00};
607 uchar rmask[9] = {0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff};
616 int r_off = offset, bits= n_bits;
621 fprintf(stderr, "%5d%c", code,
622 (col+=6) >= 74? (col = 0, '\n'): ' ');
626 * byte/bit numbering on the VAX is simulated by the
630 * Get to the first byte.
635 * Since code is always >= 8 bits, only need to mask the first
638 *bp = (*bp & rmask[r_off]) | (code << r_off) & lmask[r_off];
642 /* Get any 8 bit parts in the middle (<=1 for up to 16 bits). */
653 if ( offset == (n_bits << 3) ) {
664 * If the next entry is going to be too big for the code size,
665 * then increase it, if possible.
667 if ( free_ent > maxcode || (clear_flg > 0)) {
669 * Write the whole buffer, because the input side won't
670 * discover the size increase until after it has read it.
673 if( fwrite( buf, 1, n_bits, stdout ) != n_bits)
680 maxcode = MAXCODE (n_bits = INIT_BITS);
684 if ( n_bits == maxbits )
685 maxcode = maxmaxcode;
687 maxcode = MAXCODE(n_bits);
692 "\nChange to %d bits\n", n_bits);
699 * At EOF, write the rest of the buffer.
702 fwrite( buf, 1, (offset + 7) / 8, stdout );
703 bytes_out += (offset + 7) / 8;
708 fprintf( stderr, "\n" );
710 if( ferror( stdout ) )
716 * Decompress stdin to stdout. This routine adapts to the codes in the
717 * file building the "string" table on-the-fly; requiring no table to
718 * be stored in the compressed file. The tables used herein are shared
719 * with those of the compress() routine. See the definitions above.
725 code_int code, oldcode, incode;
729 * As above, initialize the first 256 entries in the table.
731 maxcode = MAXCODE(n_bits = INIT_BITS);
732 for (code = 255; code >= 0; code--) {
733 tab_prefixof(code) = 0;
734 tab_suffixof(code) = (uchar)code;
736 free_ent = (block_compress? FIRST: 256);
738 finchar = oldcode = getcode();
739 if(oldcode == -1) /* EOF already? */
740 return; /* Get out of here */
741 putchar((char)finchar); /* first code must be 8 bits = char */
742 if(ferror(stdout)) /* Crash if can't write */
746 while ((code = getcode()) > -1) {
747 if ((code == CLEAR) && block_compress) {
748 for (code = 255; code >= 0; code--)
749 tab_prefixof(code) = 0;
751 free_ent = FIRST - 1;
752 if ((code = getcode()) == -1) /* O, untimely death! */
757 * Special case for KwKwK string.
759 if (code >= free_ent) {
765 * Generate output characters in reverse order
767 while (code >= 256) {
768 *stackp++ = tab_suffixof(code);
769 code = tab_prefixof(code);
771 *stackp++ = finchar = tab_suffixof(code);
774 * And put them out in forward order
778 } while (stackp > de_stack);
781 * Generate the new entry.
783 if ( (code=free_ent) < maxmaxcode ) {
784 tab_prefixof(code) = (ushort)oldcode;
785 tab_suffixof(code) = finchar;
789 * Remember previous code.
801 * Read one code from the standard input. If EOF, return -1.
805 * code or -1 is returned.
812 static int offset = 0, size = 0;
813 static uchar buf[BITS];
816 if ( clear_flg > 0 || offset >= size || free_ent > maxcode ) {
818 * If the next entry will be too big for the current code
819 * size, then we must increase the size. This implies reading
820 * a new buffer full, too.
822 if ( free_ent > maxcode ) {
824 if ( n_bits == maxbits )
825 maxcode = maxmaxcode; /* won't get any bigger now */
827 maxcode = MAXCODE(n_bits);
829 if ( clear_flg > 0) {
830 maxcode = MAXCODE(n_bits = INIT_BITS);
833 size = fread(buf, 1, n_bits, stdin);
835 return -1; /* end of file */
837 /* Round size down to integral number of codes */
838 size = (size << 3) - (n_bits - 1);
843 * Get to the first byte.
847 /* Get first part (low order bits) */
848 code = (*bp++ >> r_off);
850 r_off = 8 - r_off; /* now, offset into code word */
851 /* Get any 8 bit parts in the middle (<=1 for up to 16 bits). */
853 code |= *bp++ << r_off;
857 /* high order bits. */
858 code |= (*bp & rmask[bits]) << r_off;
867 * Just print out codes from input file. For debugging.
872 bits = n_bits = INIT_BITS;
873 maxcode = MAXCODE(n_bits);
874 free_ent = ((block_compress) ? FIRST : 256 );
875 while ( ( code = getcode() ) >= 0 ) {
876 if ( (code == CLEAR) && block_compress ) {
877 free_ent = FIRST - 1;
880 else if ( free_ent < maxmaxcode )
882 if ( bits != n_bits ) {
883 fprintf(stderr, "\nChange to %d bits\n", n_bits );
887 fprintf(stderr, "%5d%c", code, (col+=6) >= 74 ? (col = 0, '\n') : ' ' );
889 putc( '\n', stderr );
893 code_int sorttab[1<<BITS]; /* sorted pointers into htab */
895 #define STACK_SIZE 15000
897 dump_tab() /* dump string table */
899 int i, first, c, ent;
900 int stack_top = STACK_SIZE;
902 if(do_decomp == 0) { /* compressing */
905 for(i=0; i<hsize; i++) { /* build sort pointers */
906 if((long)htabof(i) >= 0) {
907 sorttab[codetabof(i)] = i;
910 first = block_compress ? FIRST : 256;
911 for(i = first; i < free_ent; i++) {
912 fprintf(stderr, "%5d: \"", i);
913 de_stack[--stack_top] = '\n';
914 de_stack[--stack_top] = '"';
915 stack_top = in_stack((htabof(sorttab[i])>>maxbits)&0xff,
917 for(ent=htabof(sorttab[i]) & ((1<<maxbits)-1);
919 ent=htabof(sorttab[ent]) & ((1<<maxbits)-1)) {
920 stack_top = in_stack(htabof(sorttab[ent]) >> maxbits,
923 stack_top = in_stack(ent, stack_top);
924 fwrite( &de_stack[stack_top], 1, STACK_SIZE-stack_top, stderr);
925 stack_top = STACK_SIZE;
927 } else if(!debug) { /* decompressing */
929 for ( i = 0; i < free_ent; i++ ) {
931 c = tab_suffixof(ent);
932 if ( isascii(c) && isprint(c) )
933 fprintf( stderr, "%5d: %5d/'%c' \"",
934 ent, tab_prefixof(ent), c );
936 fprintf( stderr, "%5d: %5d/\\%03o \"",
937 ent, tab_prefixof(ent), c );
938 de_stack[--stack_top] = '\n';
939 de_stack[--stack_top] = '"';
941 ent = (ent >= FIRST ? tab_prefixof(ent) : NULL) ) {
942 stack_top = in_stack(tab_suffixof(ent), stack_top);
944 fwrite( &de_stack[stack_top], 1, STACK_SIZE - stack_top, stderr );
945 stack_top = STACK_SIZE;
951 in_stack(int c, int stack_top)
953 if ( (isascii(c) && isprint(c) && c != '\\') || c == ' ' ) {
954 de_stack[--stack_top] = c;
957 case '\n': de_stack[--stack_top] = 'n'; break;
958 case '\t': de_stack[--stack_top] = 't'; break;
959 case '\b': de_stack[--stack_top] = 'b'; break;
960 case '\f': de_stack[--stack_top] = 'f'; break;
961 case '\r': de_stack[--stack_top] = 'r'; break;
962 case '\\': de_stack[--stack_top] = '\\'; break;
964 de_stack[--stack_top] = '0' + c % 8;
965 de_stack[--stack_top] = '0' + (c / 8) % 8;
966 de_stack[--stack_top] = '0' + c / 64;
969 de_stack[--stack_top] = '\\';
984 copystat(ifname, ofname)
985 char *ifname, *ofname;
988 time_t timep[2]; /* should be struct utimbuf */
992 if (stat(ifname, &statbuf)) { /* Get stat on input file */
996 if (!S_ISREG(statbuf.st_mode)) {
998 fprintf(stderr, "%s: ", ifname);
999 fprintf(stderr, " -- not a regular file: unchanged");
1001 } else if (exit_stat == 2 && !force) {
1002 /* No compression: remove file.Z */
1004 fprintf(stderr, " -- file unchanged");
1005 } else { /* Successful Compression */
1007 mode = statbuf.st_mode & 0777;
1008 if (chmod(ofname, mode)) /* Copy modes */
1010 /* Copy ownership */
1011 chown(ofname, statbuf.st_uid, statbuf.st_gid);
1012 timep[0] = statbuf.st_atime;
1013 timep[1] = statbuf.st_mtime;
1014 /* Update last accessed and modified times */
1015 utime(ofname, (struct utimbuf *)timep);
1016 // if (unlink(ifname)) /* Remove input file */
1018 return; /* success */
1021 /* Unsuccessful return -- one of the tests failed */
1027 * This routine returns 1 if we are running in the foreground and stderr
1033 if(bgnd_flag) /* background? */
1035 else /* foreground */
1036 return isatty(2); /* and stderr is a tty */
1048 oops(int x) /* wild pointer -- assume bad input */
1052 fprintf(stderr, "uncompress: corrupt input\n");
1058 cl_block(void) /* table clear for block compress */
1062 checkpoint = in_count + CHECK_GAP;
1065 fprintf ( stderr, "count: %ld, ratio: ", in_count );
1066 prratio ( stderr, in_count, bytes_out );
1067 fprintf ( stderr, "\n");
1071 if (in_count > 0x007fffff) { /* shift will overflow */
1072 rat = bytes_out >> 8;
1073 if (rat == 0) /* Don't divide by zero */
1076 rat = in_count / rat;
1078 rat = (in_count << 8) / bytes_out; /* 8 fractional bits */
1085 dump_tab(); /* dump string table */
1087 cl_hash((count_int)hsize);
1090 output((code_int)CLEAR);
1093 fprintf(stderr, "clear\n");
1099 cl_hash(count_int hsize) /* reset code table */
1101 count_int *htab_p = htab+hsize;
1106 do { /* might use Sys V memset(3) here */
1124 } while ((i -= 16) >= 0);
1125 for ( i += 16; i > 0; i-- )
1130 prratio(stream, num, den)
1134 int q; /* Doesn't need to be long */
1136 if(num > 214748L) /* 2147483647/10000 */
1137 q = num / (den / 10000L);
1139 q = 10000L * num / den; /* Long calculations, though */
1144 fprintf(stream, "%d.%02d%%", q / 100, q % 100);
1150 fprintf(stderr, "%s\n", rcs_ident);
1151 fprintf(stderr, "Options: ");
1153 fprintf(stderr, "DEBUG, ");
1156 fprintf(stderr, "BSD4_2, ");
1158 fprintf(stderr, "BITS = %d\n", BITS);
1162 * The revision-history novel:
1164 * $Header: compress.c,v 4.0 85/07/30 12:50:00 joe Release $
1165 * $Log: compress.c,v $
1166 * Revision 4.0 85/07/30 12:50:00 joe
1167 * Removed ferror() calls in output routine on every output except first.
1168 * Prepared for release to the world.
1170 * Revision 3.6 85/07/04 01:22:21 joe
1171 * Remove much wasted storage by overlaying hash table with the tables
1172 * used by decompress: tab_suffix[1<<BITS], stack[8000]. Updated USERMEM
1173 * computations. Fixed dump_tab() DEBUG routine.
1175 * Revision 3.5 85/06/30 20:47:21 jaw
1176 * Change hash function to use exclusive-or. Rip out hash cache. These
1177 * speedups render the megamemory version defunct, for now. Make decoder
1178 * stack global. Parts of the RCS trunks 2.7, 2.6, and 2.1 no longer apply.
1180 * Revision 3.4 85/06/27 12:00:00 ken
1181 * Get rid of all floating-point calculations by doing all compression ratio
1182 * calculations in fixed point.
1184 * Revision 3.3 85/06/24 21:53:24 joe
1185 * Incorporate portability suggestion for M_XENIX. Got rid of text on #else
1186 * and #endif lines. Cleaned up #ifdefs for vax and interdata.
1188 * Revision 3.2 85/06/06 21:53:24 jaw
1189 * Incorporate portability suggestions for Z8000, IBM PC/XT from mailing list.
1190 * Default to "quiet" output (no compression statistics).
1192 * Revision 3.1 85/05/12 18:56:13 jaw
1193 * Integrate decompress() stack speedups (from early pointer mods by McKie).
1194 * Repair multi-file USERMEM gaffe. Unify 'force' flags to mimic semantics
1195 * of SVR2 'pack'. Streamline block-compress table clear logic. Increase
1196 * output byte count by magic number size.
1198 * Revision 3.0 84/11/27 11:50:00 petsd!joe
1199 * Set HSIZE depending on BITS. Set BITS depending on USERMEM. Unrolled
1200 * loops in clear routines. Added "-C" flag for 2.0 compatibility. Used
1201 * unsigned compares on Perkin-Elmer. Fixed foreground check.
1203 * Revision 2.7 84/11/16 19:35:39 ames!jaw
1204 * Cache common hash codes based on input statistics; this improves
1205 * performance for low-density raster images. Pass on #ifdef bundle
1208 * Revision 2.6 84/11/05 19:18:21 ames!jaw
1209 * Vary size of hash tables to reduce time for small files.
1210 * Tune PDP-11 hash function.
1212 * Revision 2.5 84/10/30 20:15:14 ames!jaw
1213 * Junk chaining; replace with the simpler (and, on the VAX, faster)
1214 * double hashing, discussed within. Make block compression standard.
1216 * Revision 2.4 84/10/16 11:11:11 ames!jaw
1217 * Introduce adaptive reset for block compression, to boost the rate
1218 * another several percent. (See mailing list notes.)
1220 * Revision 2.3 84/09/22 22:00:00 petsd!joe
1221 * Implemented "-B" block compress. Implemented REVERSE sorting of tab_next.
1222 * Bug fix for last bits. Changed fwrite to putchar loop everywhere.
1224 * Revision 2.2 84/09/18 14:12:21 ames!jaw
1225 * Fold in news changes, small machine typedef from thomas,
1226 * #ifdef interdata from joe.
1228 * Revision 2.1 84/09/10 12:34:56 ames!jaw
1229 * Configured fast table lookup for 32-bit machines.
1230 * This cuts user time in half for b <= FBITS, and is useful for news batching
1231 * from VAX to PDP sites. Also sped up decompress() [fwrite->putc] and
1232 * added signal catcher [plus beef in writeerr()] to delete effluvia.
1234 * Revision 2.0 84/08/28 22:00:00 petsd!joe
1235 * Add check for foreground before prompting user. Insert maxbits into
1236 * compressed file. Force file being uncompressed to end with ".Z".
1237 * Added "-c" flag and "zcat". Prepared for release.
1239 * Revision 1.10 84/08/24 18:28:00 turtlevax!ken
1240 * Will only compress regular files (no directories), added a magic number
1241 * header (plus an undocumented -n flag to handle old files without headers),
1242 * added -f flag to force overwriting of possibly existing destination file,
1243 * otherwise the user is prompted for a response. Will tack on a .Z to a
1244 * filename if it doesn't have one when decompressing. Will only replace
1245 * file if it was compressed.
1247 * Revision 1.9 84/08/16 17:28:00 turtlevax!ken
1248 * Removed scanargs(), getopt(), added .Z extension and unlimited number of
1249 * filenames to compress. Flags may be clustered (-Ddvb12) or separated
1250 * (-D -d -v -b 12), or combination thereof. Modes and other status is
1251 * copied with copystat(). -O bug for 4.2 seems to have disappeared with
1254 * Revision 1.8 84/08/09 23:15:00 joe
1255 * Made it compatible with vax version, installed jim's fixes/enhancements
1257 * Revision 1.6 84/08/01 22:08:00 joe
1258 * Sped up algorithm significantly by sorting the compress chain.
1260 * Revision 1.5 84/07/13 13:11:00 srd
1261 * Added C version of vax asm routines. Changed structure to arrays to
1262 * save much memory. Do unsigned compares where possible (faster on
1265 * Revision 1.4 84/07/05 03:11:11 thomas
1266 * Clean up the code a little and lint it. (Lint complains about all
1267 * the regs used in the asm, but I'm not going to "fix" this.)
1269 * Revision 1.3 84/07/05 02:06:54 thomas
1272 * Revision 1.2 84/07/05 00:27:27 thomas
1273 * Add variable bit length output.