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)
47 #include <sys/types.h>
50 #define min(a,b) ((a>b) ? b : a)
53 #define HSIZE 69001 /* 95% occupancy */
56 * a code_int must be able to hold 2**BITS values of type int, and also -1
58 typedef long code_int;
59 typedef long count_int;
61 static char rcs_ident[] = "$Header: compress.c,v 4.0 85/07/30 12:50:00 joe Release $";
63 uchar magic_header[] = { 0x1F, 0x9D }; /* 1F 9D */
65 /* Defines for third byte of header */
67 #define BLOCK_MASK 0x80
68 /* Masks 0x40 and 0x20 are free. I think 0x20 should mean that there is
69 a fourth header byte (for expansion).
71 #define INIT_BITS 9 /* initial number of bits/code */
76 #define ARGVAL() (*++(*argv) || (--argc && *++argv))
78 int n_bits; /* number of bits/code */
79 int maxbits = BITS; /* user settable max # bits/code */
80 code_int maxcode; /* maximum code, given n_bits */
81 code_int maxmaxcode = 1 << BITS; /* should NEVER generate this code */
83 #define MAXCODE(n_bits) ((1 << (n_bits)) - 1)
85 count_int htab[HSIZE];
86 ushort codetab[HSIZE];
88 #define htabof(i) htab[i]
89 #define codetabof(i) codetab[i]
91 code_int hsize = HSIZE; /* for dynamic table sizing */
95 * To save much memory, we overlay the table used by compress() with those
96 * used by decompress(). The tab_prefix table is the same size and type
97 * as the codetab. The tab_suffix table needs 2**BITS characters. We
98 * get this from the beginning of htab. The output stack uses the rest
99 * of htab, and contains characters. There is plenty of room for any
100 * possible stack (stack used to be 8000 characters).
103 #define tab_prefixof(i) codetabof(i)
104 #define tab_suffixof(i) ((uchar *)(htab))[i]
105 #define de_stack ((uchar *)&tab_suffixof(1<<BITS))
107 code_int free_ent = 0; /* first unused entry */
115 fprintf(stderr,"Usage: compress [-cdfDV] [-b maxbits] [file ...]\n");
117 fprintf(stderr,"Usage: compress [-cdfvV] [-b maxbits] [file ...]\n");
122 int nomagic = 0; /* Use a 3-byte magic number header, unless old file */
123 int zcat_flg = 0; /* Write output on stdout, suppress messages */
124 int quiet = 1; /* don't tell me about compression */
127 * block compression parameters -- after all codes are used up,
128 * and compression rate changes, start over.
130 int block_compress = BLOCK_MASK;
133 #define CHECK_GAP 10000 /* ratio check interval */
134 count_int checkpoint = CHECK_GAP;
136 * the next two codes should not be changed lightly, as they must not
137 * lie within the contiguous general code space.
139 #define FIRST 257 /* first free entry */
140 #define CLEAR 256 /* table clear output code */
147 void (*bgnd_flag)(int);
155 int overwrite = 0; /* Do not overwrite unless given -f flag */
157 char **filelist, **fileptr;
161 if ( (bgnd_flag = signal ( SIGINT, SIG_IGN )) != SIG_IGN ) {
162 signal(SIGINT, onintr);
163 signal(SIGSEGV, oops);
166 filelist = fileptr = (char **)(malloc(argc * sizeof(*argv)));
169 if((cp = strrchr(argv[0], '/')) != 0)
173 if(strcmp(cp, "uncompress") == 0)
175 else if(strcmp(cp, "zcat") == 0) {
181 * Argument Processing
182 * All flags are optional.
183 * -C generate output compatible with compress 2.0.
185 * -V print Version; debug verbose
186 * -b maxbits maxbits. If -b is specified, then maxbits MUST be
188 * -c cat all output to stdout
190 * -f force overwrite of output file
191 * -n no header: useful to uncompress old files
193 * if a string is left, must be an input filename.
195 for (argc--, argv++; argc > 0; argc--, argv++) {
196 if (**argv == '-') { /* A flag argument */
197 while (*++(*argv)) { /* Process all flags in this arg */
217 fprintf(stderr, "Missing maxbits\n");
221 maxbits = atoi(*argv);
244 fprintf(stderr, "Unknown flag: '%c'; ", **argv);
249 } else { /* Input file name */
250 *fileptr++ = *argv; /* Build input file list */
252 /* process nextarg; */
258 if(maxbits < INIT_BITS) maxbits = INIT_BITS;
259 if (maxbits > BITS) maxbits = BITS;
260 maxmaxcode = 1 << maxbits;
262 if (*filelist != NULL) {
263 for (fileptr = filelist; *fileptr; fileptr++) {
265 if (do_decomp != 0) { /* DECOMPRESSION */
266 /* Check for .Z suffix */
267 if (strcmp(*fileptr + strlen(*fileptr) - 2, ".Z") != 0) {
268 /* No .Z: tack one on */
269 strcpy(tempname, *fileptr);
270 strcat(tempname, ".Z");
273 /* Open input file */
274 if ((freopen(*fileptr, "r", stdin)) == NULL) {
278 /* Check the magic number */
280 if ((getchar() != (magic_header[0] & 0xFF))
281 || (getchar() != (magic_header[1] & 0xFF))) {
282 fprintf(stderr, "%s: not in compressed format\n",
286 maxbits = getchar(); /* set -b from file */
287 block_compress = maxbits & BLOCK_MASK;
289 maxmaxcode = 1 << maxbits;
292 "%s: compressed with %d bits, can only handle %d bits\n",
293 *fileptr, maxbits, BITS);
297 /* Generate output filename */
298 strcpy(ofname, *fileptr);
299 ofname[strlen(*fileptr) - 2] = '\0'; /* Strip off .Z */
300 } else { /* COMPRESSION */
301 if (strcmp(*fileptr + strlen(*fileptr) - 2, ".Z") == 0) {
303 "%s: already has .Z suffix -- no change\n",
307 /* Open input file */
308 if ((freopen(*fileptr, "r", stdin)) == NULL) {
312 (void) stat(*fileptr, &statbuf);
313 fsize = (long) statbuf.st_size;
315 * tune hash table size for small files -- ad hoc,
316 * but the sizes match earlier #defines, which
317 * serve as upper bounds on the number of output codes.
320 if (fsize < (1 << 12))
321 hsize = min(5003, HSIZE);
322 else if (fsize < (1 << 13))
323 hsize = min(9001, HSIZE);
324 else if (fsize < (1 << 14))
325 hsize = min (18013, HSIZE);
326 else if (fsize < (1 << 15))
327 hsize = min (35023, HSIZE);
328 else if (fsize < 47000)
329 hsize = min (50021, HSIZE);
331 /* Generate output filename */
332 strcpy(ofname, *fileptr);
334 if ((cp=strrchr(ofname,'/')) != NULL)
339 *** changed 12 to 25; should be NAMELEN-3, but I don't want
340 * to fight the headers. ehg 5 Nov 92 **
342 if (strlen(cp) > 25) {
343 fprintf(stderr, "%s: filename too long to tack on .Z\n",
348 strcat(ofname, ".Z");
350 /* Check for overwrite of existing file */
351 if (overwrite == 0 && zcat_flg == 0 &&
352 stat(ofname, &statbuf) == 0) {
356 fprintf(stderr, "%s already exists;", ofname);
359 " do you wish to overwrite %s (y or n)? ",
362 (void) read(2, response, 2);
363 while (response[1] != '\n')
364 if (read(2, response+1, 1) < 0) {
370 if (response[0] != 'y') {
371 fprintf(stderr, "\tnot overwritten\n");
375 if(zcat_flg == 0) { /* Open output file */
376 if (freopen(ofname, "w", stdout) == NULL) {
381 fprintf(stderr, "%s: ", *fileptr);
384 /* Actually do the compression/decompression */
399 copystat(*fileptr, ofname); /* Copy stats */
400 if (exit_stat == 1 || !quiet)
404 } else { /* Standard input */
405 if (do_decomp == 0) {
414 /* Check the magic number */
416 if ((getchar()!=(magic_header[0] & 0xFF))
417 || (getchar()!=(magic_header[1] & 0xFF))) {
418 fprintf(stderr, "stdin: not in compressed format\n");
421 maxbits = getchar(); /* set -b from file */
422 block_compress = maxbits & BLOCK_MASK;
424 maxmaxcode = 1 << maxbits;
425 fsize = 100000; /* assume stdin large for USERMEM */
428 "stdin: compressed with %d bits, can only handle %d bits\n",
449 long in_count = 1; /* length of input */
450 long bytes_out; /* length of compressed output */
451 long out_count = 0; /* # of codes output (for debugging) */
454 * compress stdin to stdout
456 * Algorithm: use open addressing double hashing (no chaining) on the
457 * prefix code / next character combination. We do a variant of Knuth's
458 * algorithm D (vol. 3, sec. 6.4) along with G. Knott's relatively-prime
459 * secondary probe. Here, the modular division first probe is gives way
460 * to a faster exclusive-or manipulation. Also do block compression with
461 * an adaptive reset, whereby the code table is cleared when the compression
462 * ratio decreases, but after the table fills. The variable-length output
463 * codes are re-sized at this point, and a special CLEAR code is generated
464 * for the decompressor. Late addition: construct the table according to
465 * file size for noticeable speed improvement on small files. Please direct
466 * questions about this implementation to ames!jaw.
470 code_int ent, hsize_reg;
476 putchar(magic_header[0]);
477 putchar(magic_header[1]);
478 putchar((char)(maxbits | block_compress));
483 bytes_out = 3; /* includes 3-byte header mojo */
488 checkpoint = CHECK_GAP;
489 maxcode = MAXCODE(n_bits = INIT_BITS);
490 free_ent = (block_compress? FIRST: 256);
495 for (fcode = (long)hsize; fcode < 65536L; fcode *= 2)
497 hshift = 8 - hshift; /* set hash code range bound */
500 cl_hash( (count_int) hsize_reg); /* clear hash table */
502 while ((c = getchar()) != EOF) {
504 fcode = (long) (((long) c << maxbits) + ent);
505 i = ((c << hshift) ^ ent); /* xor hashing */
507 if (htabof (i) == fcode) {
510 } else if ((long)htabof(i) < 0 ) /* empty slot */
512 disp = hsize_reg - i; /* secondary hash (after G. Knott) */
519 if (htabof (i) == fcode) {
523 if ((long)htabof(i) > 0)
526 output((code_int)ent);
529 if (free_ent < maxmaxcode) {
530 codetabof(i) = free_ent++; /* code -> hashtable */
532 } else if ((count_int)in_count >= checkpoint && block_compress)
536 * Put out the final code.
538 output( (code_int)ent );
540 output( (code_int)-1 );
543 * Print out stats on stderr
545 if(zcat_flg == 0 && !quiet) {
548 "%ld chars in, %ld codes (%ld bytes) out, compression factor: ",
549 in_count, out_count, bytes_out );
550 prratio( stderr, in_count, bytes_out );
551 fprintf( stderr, "\n");
552 fprintf( stderr, "\tCompression as in compact: " );
553 prratio( stderr, in_count-bytes_out, in_count );
554 fprintf( stderr, "\n");
555 fprintf( stderr, "\tLargest code (of last block) was %d (%d bits)\n",
556 free_ent - 1, n_bits );
558 fprintf( stderr, "Compression: " );
559 prratio( stderr, in_count-bytes_out, in_count );
562 if(bytes_out > in_count) /* exit(2) if no savings */
569 * Output the given code.
571 * code: A n_bits-bit integer. If == -1, then EOF. This assumes
572 * that n_bits =< (long)wordsize - 1.
574 * Outputs code to the file.
576 * Chars are 8 bits long.
578 * Maintain a BITS character long buffer (so that 8 codes will
579 * fit in it exactly). When the buffer fills up empty it and start over.
582 static char buf[BITS];
584 uchar lmask[9] = {0xff, 0xfe, 0xfc, 0xf8, 0xf0, 0xe0, 0xc0, 0x80, 0x00};
585 uchar rmask[9] = {0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff};
593 int r_off = offset, bits= n_bits;
598 fprintf(stderr, "%5d%c", code,
599 (col+=6) >= 74? (col = 0, '\n'): ' ');
603 * byte/bit numbering on the VAX is simulated by the
607 * Get to the first byte.
612 * Since code is always >= 8 bits, only need to mask the first
615 *bp = (*bp & rmask[r_off]) | (code << r_off) & lmask[r_off];
619 /* Get any 8 bit parts in the middle (<=1 for up to 16 bits). */
630 if ( offset == (n_bits << 3) ) {
641 * If the next entry is going to be too big for the code size,
642 * then increase it, if possible.
644 if ( free_ent > maxcode || (clear_flg > 0)) {
646 * Write the whole buffer, because the input side won't
647 * discover the size increase until after it has read it.
650 if( fwrite( buf, 1, n_bits, stdout ) != n_bits)
657 maxcode = MAXCODE (n_bits = INIT_BITS);
661 if ( n_bits == maxbits )
662 maxcode = maxmaxcode;
664 maxcode = MAXCODE(n_bits);
669 "\nChange to %d bits\n", n_bits);
676 * At EOF, write the rest of the buffer.
679 fwrite( buf, 1, (offset + 7) / 8, stdout );
680 bytes_out += (offset + 7) / 8;
685 fprintf( stderr, "\n" );
687 if( ferror( stdout ) )
693 * Decompress stdin to stdout. This routine adapts to the codes in the
694 * file building the "string" table on-the-fly; requiring no table to
695 * be stored in the compressed file. The tables used herein are shared
696 * with those of the compress() routine. See the definitions above.
701 code_int code, oldcode, incode;
705 * As above, initialize the first 256 entries in the table.
707 maxcode = MAXCODE(n_bits = INIT_BITS);
708 for (code = 255; code >= 0; code--) {
709 tab_prefixof(code) = 0;
710 tab_suffixof(code) = (uchar)code;
712 free_ent = (block_compress? FIRST: 256);
714 finchar = oldcode = getcode();
715 if(oldcode == -1) /* EOF already? */
716 return; /* Get out of here */
717 putchar((char)finchar); /* first code must be 8 bits = char */
718 if(ferror(stdout)) /* Crash if can't write */
722 while ((code = getcode()) > -1) {
723 if ((code == CLEAR) && block_compress) {
724 for (code = 255; code >= 0; code--)
725 tab_prefixof(code) = 0;
727 free_ent = FIRST - 1;
728 if ((code = getcode()) == -1) /* O, untimely death! */
733 * Special case for KwKwK string.
735 if (code >= free_ent) {
741 * Generate output characters in reverse order
743 while (code >= 256) {
744 *stackp++ = tab_suffixof(code);
745 code = tab_prefixof(code);
747 *stackp++ = finchar = tab_suffixof(code);
750 * And put them out in forward order
754 } while (stackp > de_stack);
757 * Generate the new entry.
759 if ( (code=free_ent) < maxmaxcode ) {
760 tab_prefixof(code) = (ushort)oldcode;
761 tab_suffixof(code) = finchar;
765 * Remember previous code.
777 * Read one code from the standard input. If EOF, return -1.
781 * code or -1 is returned.
788 static int offset = 0, size = 0;
789 static uchar buf[BITS];
792 if ( clear_flg > 0 || offset >= size || free_ent > maxcode ) {
794 * If the next entry will be too big for the current code
795 * size, then we must increase the size. This implies reading
796 * a new buffer full, too.
798 if ( free_ent > maxcode ) {
800 if ( n_bits == maxbits )
801 maxcode = maxmaxcode; /* won't get any bigger now */
803 maxcode = MAXCODE(n_bits);
805 if ( clear_flg > 0) {
806 maxcode = MAXCODE(n_bits = INIT_BITS);
809 size = fread(buf, 1, n_bits, stdin);
811 return -1; /* end of file */
813 /* Round size down to integral number of codes */
814 size = (size << 3) - (n_bits - 1);
819 * Get to the first byte.
823 /* Get first part (low order bits) */
824 code = (*bp++ >> r_off);
826 r_off = 8 - r_off; /* now, offset into code word */
827 /* Get any 8 bit parts in the middle (<=1 for up to 16 bits). */
829 code |= *bp++ << r_off;
833 /* high order bits. */
834 code |= (*bp & rmask[bits]) << r_off;
843 * Just print out codes from input file. For debugging.
848 bits = n_bits = INIT_BITS;
849 maxcode = MAXCODE(n_bits);
850 free_ent = ((block_compress) ? FIRST : 256 );
851 while ( ( code = getcode() ) >= 0 ) {
852 if ( (code == CLEAR) && block_compress ) {
853 free_ent = FIRST - 1;
856 else if ( free_ent < maxmaxcode )
858 if ( bits != n_bits ) {
859 fprintf(stderr, "\nChange to %d bits\n", n_bits );
863 fprintf(stderr, "%5d%c", code, (col+=6) >= 74 ? (col = 0, '\n') : ' ' );
865 putc( '\n', stderr );
869 code_int sorttab[1<<BITS]; /* sorted pointers into htab */
871 #define STACK_SIZE 15000
873 dump_tab() /* dump string table */
875 int i, first, c, ent;
876 int stack_top = STACK_SIZE;
878 if(do_decomp == 0) { /* compressing */
881 for(i=0; i<hsize; i++) { /* build sort pointers */
882 if((long)htabof(i) >= 0) {
883 sorttab[codetabof(i)] = i;
886 first = block_compress ? FIRST : 256;
887 for(i = first; i < free_ent; i++) {
888 fprintf(stderr, "%5d: \"", i);
889 de_stack[--stack_top] = '\n';
890 de_stack[--stack_top] = '"';
891 stack_top = in_stack((htabof(sorttab[i])>>maxbits)&0xff,
893 for(ent=htabof(sorttab[i]) & ((1<<maxbits)-1);
895 ent=htabof(sorttab[ent]) & ((1<<maxbits)-1)) {
896 stack_top = in_stack(htabof(sorttab[ent]) >> maxbits,
899 stack_top = in_stack(ent, stack_top);
900 fwrite( &de_stack[stack_top], 1, STACK_SIZE-stack_top, stderr);
901 stack_top = STACK_SIZE;
903 } else if(!debug) { /* decompressing */
905 for ( i = 0; i < free_ent; i++ ) {
907 c = tab_suffixof(ent);
908 if ( isascii(c) && isprint(c) )
909 fprintf( stderr, "%5d: %5d/'%c' \"",
910 ent, tab_prefixof(ent), c );
912 fprintf( stderr, "%5d: %5d/\\%03o \"",
913 ent, tab_prefixof(ent), c );
914 de_stack[--stack_top] = '\n';
915 de_stack[--stack_top] = '"';
917 ent = (ent >= FIRST ? tab_prefixof(ent) : NULL) ) {
918 stack_top = in_stack(tab_suffixof(ent), stack_top);
920 fwrite( &de_stack[stack_top], 1, STACK_SIZE - stack_top, stderr );
921 stack_top = STACK_SIZE;
927 in_stack(int c, int stack_top)
929 if ( (isascii(c) && isprint(c) && c != '\\') || c == ' ' ) {
930 de_stack[--stack_top] = c;
933 case '\n': de_stack[--stack_top] = 'n'; break;
934 case '\t': de_stack[--stack_top] = 't'; break;
935 case '\b': de_stack[--stack_top] = 'b'; break;
936 case '\f': de_stack[--stack_top] = 'f'; break;
937 case '\r': de_stack[--stack_top] = 'r'; break;
938 case '\\': de_stack[--stack_top] = '\\'; break;
940 de_stack[--stack_top] = '0' + c % 8;
941 de_stack[--stack_top] = '0' + (c / 8) % 8;
942 de_stack[--stack_top] = '0' + c / 64;
945 de_stack[--stack_top] = '\\';
958 copystat(ifname, ofname)
959 char *ifname, *ofname;
966 if (stat(ifname, &statbuf)) { /* Get stat on input file */
970 if (!S_ISREG(statbuf.st_mode)) {
972 fprintf(stderr, "%s: ", ifname);
973 fprintf(stderr, " -- not a regular file: unchanged");
975 } else if (exit_stat == 2 && !force) {
976 /* No compression: remove file.Z */
978 fprintf(stderr, " -- file unchanged");
979 } else { /* Successful Compression */
981 mode = statbuf.st_mode & 0777;
982 if (chmod(ofname, mode)) /* Copy modes */
985 chown(ofname, statbuf.st_uid, statbuf.st_gid);
986 timep[0] = statbuf.st_atime;
987 timep[1] = statbuf.st_mtime;
988 /* Update last accessed and modified times */
989 utime(ofname, timep);
990 // if (unlink(ifname)) /* Remove input file */
992 return; /* success */
995 /* Unsuccessful return -- one of the tests failed */
1001 * This routine returns 1 if we are running in the foreground and stderr
1006 if(bgnd_flag) /* background? */
1008 else /* foreground */
1009 return isatty(2); /* and stderr is a tty */
1020 oops(int x) /* wild pointer -- assume bad input */
1023 fprintf(stderr, "uncompress: corrupt input\n");
1028 cl_block () /* table clear for block compress */
1032 checkpoint = in_count + CHECK_GAP;
1035 fprintf ( stderr, "count: %ld, ratio: ", in_count );
1036 prratio ( stderr, in_count, bytes_out );
1037 fprintf ( stderr, "\n");
1041 if (in_count > 0x007fffff) { /* shift will overflow */
1042 rat = bytes_out >> 8;
1043 if (rat == 0) /* Don't divide by zero */
1046 rat = in_count / rat;
1048 rat = (in_count << 8) / bytes_out; /* 8 fractional bits */
1055 dump_tab(); /* dump string table */
1057 cl_hash((count_int)hsize);
1060 output((code_int)CLEAR);
1063 fprintf(stderr, "clear\n");
1068 cl_hash(hsize) /* reset code table */
1071 count_int *htab_p = htab+hsize;
1076 do { /* might use Sys V memset(3) here */
1094 } while ((i -= 16) >= 0);
1095 for ( i += 16; i > 0; i-- )
1099 prratio(stream, num, den)
1103 int q; /* Doesn't need to be long */
1105 if(num > 214748L) /* 2147483647/10000 */
1106 q = num / (den / 10000L);
1108 q = 10000L * num / den; /* Long calculations, though */
1113 fprintf(stream, "%d.%02d%%", q / 100, q % 100);
1118 fprintf(stderr, "%s\n", rcs_ident);
1119 fprintf(stderr, "Options: ");
1121 fprintf(stderr, "DEBUG, ");
1124 fprintf(stderr, "BSD4_2, ");
1126 fprintf(stderr, "BITS = %d\n", BITS);
1130 * The revision-history novel:
1132 * $Header: compress.c,v 4.0 85/07/30 12:50:00 joe Release $
1133 * $Log: compress.c,v $
1134 * Revision 4.0 85/07/30 12:50:00 joe
1135 * Removed ferror() calls in output routine on every output except first.
1136 * Prepared for release to the world.
1138 * Revision 3.6 85/07/04 01:22:21 joe
1139 * Remove much wasted storage by overlaying hash table with the tables
1140 * used by decompress: tab_suffix[1<<BITS], stack[8000]. Updated USERMEM
1141 * computations. Fixed dump_tab() DEBUG routine.
1143 * Revision 3.5 85/06/30 20:47:21 jaw
1144 * Change hash function to use exclusive-or. Rip out hash cache. These
1145 * speedups render the megamemory version defunct, for now. Make decoder
1146 * stack global. Parts of the RCS trunks 2.7, 2.6, and 2.1 no longer apply.
1148 * Revision 3.4 85/06/27 12:00:00 ken
1149 * Get rid of all floating-point calculations by doing all compression ratio
1150 * calculations in fixed point.
1152 * Revision 3.3 85/06/24 21:53:24 joe
1153 * Incorporate portability suggestion for M_XENIX. Got rid of text on #else
1154 * and #endif lines. Cleaned up #ifdefs for vax and interdata.
1156 * Revision 3.2 85/06/06 21:53:24 jaw
1157 * Incorporate portability suggestions for Z8000, IBM PC/XT from mailing list.
1158 * Default to "quiet" output (no compression statistics).
1160 * Revision 3.1 85/05/12 18:56:13 jaw
1161 * Integrate decompress() stack speedups (from early pointer mods by McKie).
1162 * Repair multi-file USERMEM gaffe. Unify 'force' flags to mimic semantics
1163 * of SVR2 'pack'. Streamline block-compress table clear logic. Increase
1164 * output byte count by magic number size.
1166 * Revision 3.0 84/11/27 11:50:00 petsd!joe
1167 * Set HSIZE depending on BITS. Set BITS depending on USERMEM. Unrolled
1168 * loops in clear routines. Added "-C" flag for 2.0 compatibility. Used
1169 * unsigned compares on Perkin-Elmer. Fixed foreground check.
1171 * Revision 2.7 84/11/16 19:35:39 ames!jaw
1172 * Cache common hash codes based on input statistics; this improves
1173 * performance for low-density raster images. Pass on #ifdef bundle
1176 * Revision 2.6 84/11/05 19:18:21 ames!jaw
1177 * Vary size of hash tables to reduce time for small files.
1178 * Tune PDP-11 hash function.
1180 * Revision 2.5 84/10/30 20:15:14 ames!jaw
1181 * Junk chaining; replace with the simpler (and, on the VAX, faster)
1182 * double hashing, discussed within. Make block compression standard.
1184 * Revision 2.4 84/10/16 11:11:11 ames!jaw
1185 * Introduce adaptive reset for block compression, to boost the rate
1186 * another several percent. (See mailing list notes.)
1188 * Revision 2.3 84/09/22 22:00:00 petsd!joe
1189 * Implemented "-B" block compress. Implemented REVERSE sorting of tab_next.
1190 * Bug fix for last bits. Changed fwrite to putchar loop everywhere.
1192 * Revision 2.2 84/09/18 14:12:21 ames!jaw
1193 * Fold in news changes, small machine typedef from thomas,
1194 * #ifdef interdata from joe.
1196 * Revision 2.1 84/09/10 12:34:56 ames!jaw
1197 * Configured fast table lookup for 32-bit machines.
1198 * This cuts user time in half for b <= FBITS, and is useful for news batching
1199 * from VAX to PDP sites. Also sped up decompress() [fwrite->putc] and
1200 * added signal catcher [plus beef in writeerr()] to delete effluvia.
1202 * Revision 2.0 84/08/28 22:00:00 petsd!joe
1203 * Add check for foreground before prompting user. Insert maxbits into
1204 * compressed file. Force file being uncompressed to end with ".Z".
1205 * Added "-c" flag and "zcat". Prepared for release.
1207 * Revision 1.10 84/08/24 18:28:00 turtlevax!ken
1208 * Will only compress regular files (no directories), added a magic number
1209 * header (plus an undocumented -n flag to handle old files without headers),
1210 * added -f flag to force overwriting of possibly existing destination file,
1211 * otherwise the user is prompted for a response. Will tack on a .Z to a
1212 * filename if it doesn't have one when decompressing. Will only replace
1213 * file if it was compressed.
1215 * Revision 1.9 84/08/16 17:28:00 turtlevax!ken
1216 * Removed scanargs(), getopt(), added .Z extension and unlimited number of
1217 * filenames to compress. Flags may be clustered (-Ddvb12) or separated
1218 * (-D -d -v -b 12), or combination thereof. Modes and other status is
1219 * copied with copystat(). -O bug for 4.2 seems to have disappeared with
1222 * Revision 1.8 84/08/09 23:15:00 joe
1223 * Made it compatible with vax version, installed jim's fixes/enhancements
1225 * Revision 1.6 84/08/01 22:08:00 joe
1226 * Sped up algorithm significantly by sorting the compress chain.
1228 * Revision 1.5 84/07/13 13:11:00 srd
1229 * Added C version of vax asm routines. Changed structure to arrays to
1230 * save much memory. Do unsigned compares where possible (faster on
1233 * Revision 1.4 84/07/05 03:11:11 thomas
1234 * Clean up the code a little and lint it. (Lint complains about all
1235 * the regs used in the asm, but I'm not going to "fix" this.)
1237 * Revision 1.3 84/07/05 02:06:54 thomas
1240 * Revision 1.2 84/07/05 00:27:27 thomas
1241 * Add variable bit length output.