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