1*83c6fa43Sbostic/*
2*83c6fa43Sbostic * $Header: compress.c,v 4.0 85/07/30 12:50:00 joe Release $
3*83c6fa43Sbostic * $Log:	compress.c,v $
4*83c6fa43Sbostic * Revision 4.0  85/07/30  12:50:00  joe
5*83c6fa43Sbostic * Removed ferror() calls in output routine on every output except first.
6*83c6fa43Sbostic * Prepared for release to the world.
7*83c6fa43Sbostic *
8*83c6fa43Sbostic * Revision 3.6  85/07/04  01:22:21  joe
9*83c6fa43Sbostic * Remove much wasted storage by overlaying hash table with the tables
10*83c6fa43Sbostic * used by decompress: tab_suffix[1<<BITS], stack[8000].  Updated USERMEM
11*83c6fa43Sbostic * computations.  Fixed dump_tab() DEBUG routine.
12*83c6fa43Sbostic *
13*83c6fa43Sbostic * Revision 3.5  85/06/30  20:47:21  jaw
14*83c6fa43Sbostic * Change hash function to use exclusive-or.  Rip out hash cache.  These
15*83c6fa43Sbostic * speedups render the megamemory version defunct, for now.  Make decoder
16*83c6fa43Sbostic * stack global.  Parts of the RCS trunks 2.7, 2.6, and 2.1 no longer apply.
17*83c6fa43Sbostic *
18*83c6fa43Sbostic * Revision 3.4  85/06/27  12:00:00  ken
19*83c6fa43Sbostic * Get rid of all floating-point calculations by doing all compression ratio
20*83c6fa43Sbostic * calculations in fixed point.
21*83c6fa43Sbostic *
22*83c6fa43Sbostic * Revision 3.3  85/06/24  21:53:24  joe
23*83c6fa43Sbostic * Incorporate portability suggestion for M_XENIX.  Got rid of text on #else
24*83c6fa43Sbostic * and #endif lines.  Cleaned up #ifdefs for vax and interdata.
25*83c6fa43Sbostic *
26*83c6fa43Sbostic * Revision 3.2  85/06/06  21:53:24  jaw
27*83c6fa43Sbostic * Incorporate portability suggestions for Z8000, IBM PC/XT from mailing list.
28*83c6fa43Sbostic * Default to "quiet" output (no compression statistics).
29*83c6fa43Sbostic *
30*83c6fa43Sbostic * Revision 3.1  85/05/12  18:56:13  jaw
31*83c6fa43Sbostic * Integrate decompress() stack speedups (from early pointer mods by McKie).
32*83c6fa43Sbostic * Repair multi-file USERMEM gaffe.  Unify 'force' flags to mimic semantics
33*83c6fa43Sbostic * of SVR2 'pack'.  Streamline block-compress table clear logic.  Increase
34*83c6fa43Sbostic * output byte count by magic number size.
35*83c6fa43Sbostic *
36*83c6fa43Sbostic * Revision 3.0   84/11/27  11:50:00  petsd!joe
37*83c6fa43Sbostic * Set HSIZE depending on BITS.  Set BITS depending on USERMEM.  Unrolled
38*83c6fa43Sbostic * loops in clear routines.  Added "-C" flag for 2.0 compatibility.  Used
39*83c6fa43Sbostic * unsigned compares on Perkin-Elmer.  Fixed foreground check.
40*83c6fa43Sbostic *
41*83c6fa43Sbostic * Revision 2.7   84/11/16  19:35:39  ames!jaw
42*83c6fa43Sbostic * Cache common hash codes based on input statistics; this improves
43*83c6fa43Sbostic * performance for low-density raster images.  Pass on #ifdef bundle
44*83c6fa43Sbostic * from Turkowski.
45*83c6fa43Sbostic *
46*83c6fa43Sbostic * Revision 2.6   84/11/05  19:18:21  ames!jaw
47*83c6fa43Sbostic * Vary size of hash tables to reduce time for small files.
48*83c6fa43Sbostic * Tune PDP-11 hash function.
49*83c6fa43Sbostic *
50*83c6fa43Sbostic * Revision 2.5   84/10/30  20:15:14  ames!jaw
51*83c6fa43Sbostic * Junk chaining; replace with the simpler (and, on the VAX, faster)
52*83c6fa43Sbostic * double hashing, discussed within.  Make block compression standard.
53*83c6fa43Sbostic *
54*83c6fa43Sbostic * Revision 2.4   84/10/16  11:11:11  ames!jaw
55*83c6fa43Sbostic * Introduce adaptive reset for block compression, to boost the rate
56*83c6fa43Sbostic * another several percent.  (See mailing list notes.)
57*83c6fa43Sbostic *
58*83c6fa43Sbostic * Revision 2.3   84/09/22  22:00:00  petsd!joe
59*83c6fa43Sbostic * Implemented "-B" block compress.  Implemented REVERSE sorting of tab_next.
60*83c6fa43Sbostic * Bug fix for last bits.  Changed fwrite to putchar loop everywhere.
61*83c6fa43Sbostic *
62*83c6fa43Sbostic * Revision 2.2   84/09/18  14:12:21  ames!jaw
63*83c6fa43Sbostic * Fold in news changes, small machine typedef from thomas,
64*83c6fa43Sbostic * #ifdef interdata from joe.
65*83c6fa43Sbostic *
66*83c6fa43Sbostic * Revision 2.1   84/09/10  12:34:56  ames!jaw
67*83c6fa43Sbostic * Configured fast table lookup for 32-bit machines.
68*83c6fa43Sbostic * This cuts user time in half for b <= FBITS, and is useful for news batching
69*83c6fa43Sbostic * from VAX to PDP sites.  Also sped up decompress() [fwrite->putc] and
70*83c6fa43Sbostic * added signal catcher [plus beef in writeerr()] to delete effluvia.
71*83c6fa43Sbostic *
72*83c6fa43Sbostic * Revision 2.0   84/08/28  22:00:00  petsd!joe
73*83c6fa43Sbostic * Add check for foreground before prompting user.  Insert maxbits into
74*83c6fa43Sbostic * compressed file.  Force file being uncompressed to end with ".Z".
75*83c6fa43Sbostic * Added "-c" flag and "zcat".  Prepared for release.
76*83c6fa43Sbostic *
77*83c6fa43Sbostic * Revision 1.10  84/08/24  18:28:00  turtlevax!ken
78*83c6fa43Sbostic * Will only compress regular files (no directories), added a magic number
79*83c6fa43Sbostic * header (plus an undocumented -n flag to handle old files without headers),
80*83c6fa43Sbostic * added -f flag to force overwriting of possibly existing destination file,
81*83c6fa43Sbostic * otherwise the user is prompted for a response.  Will tack on a .Z to a
82*83c6fa43Sbostic * filename if it doesn't have one when decompressing.  Will only replace
83*83c6fa43Sbostic * file if it was compressed.
84*83c6fa43Sbostic *
85*83c6fa43Sbostic * Revision 1.9  84/08/16  17:28:00  turtlevax!ken
86*83c6fa43Sbostic * Removed scanargs(), getopt(), added .Z extension and unlimited number of
87*83c6fa43Sbostic * filenames to compress.  Flags may be clustered (-Ddvb12) or separated
88*83c6fa43Sbostic * (-D -d -v -b 12), or combination thereof.  Modes and other status is
89*83c6fa43Sbostic * copied with copystat().  -O bug for 4.2 seems to have disappeared with
90*83c6fa43Sbostic * 1.8.
91*83c6fa43Sbostic *
92*83c6fa43Sbostic * Revision 1.8  84/08/09  23:15:00  joe
93*83c6fa43Sbostic * Made it compatible with vax version, installed jim's fixes/enhancements
94*83c6fa43Sbostic *
95*83c6fa43Sbostic * Revision 1.6  84/08/01  22:08:00  joe
96*83c6fa43Sbostic * Sped up algorithm significantly by sorting the compress chain.
97*83c6fa43Sbostic *
98*83c6fa43Sbostic * Revision 1.5  84/07/13  13:11:00  srd
99*83c6fa43Sbostic * Added C version of vax asm routines.  Changed structure to arrays to
100*83c6fa43Sbostic * save much memory.  Do unsigned compares where possible (faster on
101*83c6fa43Sbostic * Perkin-Elmer)
102*83c6fa43Sbostic *
103*83c6fa43Sbostic * Revision 1.4  84/07/05  03:11:11  thomas
104*83c6fa43Sbostic * Clean up the code a little and lint it.  (Lint complains about all
105*83c6fa43Sbostic * the regs used in the asm, but I'm not going to "fix" this.)
106*83c6fa43Sbostic *
107*83c6fa43Sbostic * Revision 1.3  84/07/05  02:06:54  thomas
108*83c6fa43Sbostic * Minor fixes.
109*83c6fa43Sbostic *
110*83c6fa43Sbostic * Revision 1.2  84/07/05  00:27:27  thomas
111*83c6fa43Sbostic * Add variable bit length output.
112*83c6fa43Sbostic *
113*83c6fa43Sbostic */
114*83c6fa43Sbostic
115*83c6fa43Sbosticstatic char rcs_ident[] =
116*83c6fa43Sbostic	"$Header: compress.c,v 4.0 85/07/30 12:50:00 joe Release $";
117