181586Sru/* $FreeBSD$ */
281586Sru
31590Srgrimes/*
481586Sru * $Header: compress.c,v 4.0 85/07/30 12:50:00 joe Release $
5220201Semaste *
61590Srgrimes * Revision 4.0  85/07/30  12:50:00  joe
71590Srgrimes * Removed ferror() calls in output routine on every output except first.
81590Srgrimes * Prepared for release to the world.
91590Srgrimes * 
101590Srgrimes * Revision 3.6  85/07/04  01:22:21  joe
111590Srgrimes * Remove much wasted storage by overlaying hash table with the tables
121590Srgrimes * used by decompress: tab_suffix[1<<BITS], stack[8000].  Updated USERMEM
131590Srgrimes * computations.  Fixed dump_tab() DEBUG routine.
141590Srgrimes *
151590Srgrimes * Revision 3.5  85/06/30  20:47:21  jaw
161590Srgrimes * Change hash function to use exclusive-or.  Rip out hash cache.  These
171590Srgrimes * speedups render the megamemory version defunct, for now.  Make decoder
181590Srgrimes * stack global.  Parts of the RCS trunks 2.7, 2.6, and 2.1 no longer apply.
191590Srgrimes *
201590Srgrimes * Revision 3.4  85/06/27  12:00:00  ken
211590Srgrimes * Get rid of all floating-point calculations by doing all compression ratio
221590Srgrimes * calculations in fixed point.
231590Srgrimes *
241590Srgrimes * Revision 3.3  85/06/24  21:53:24  joe
251590Srgrimes * Incorporate portability suggestion for M_XENIX.  Got rid of text on #else
261590Srgrimes * and #endif lines.  Cleaned up #ifdefs for vax and interdata.
271590Srgrimes *
281590Srgrimes * Revision 3.2  85/06/06  21:53:24  jaw
291590Srgrimes * Incorporate portability suggestions for Z8000, IBM PC/XT from mailing list.
301590Srgrimes * Default to "quiet" output (no compression statistics).
311590Srgrimes *
321590Srgrimes * Revision 3.1  85/05/12  18:56:13  jaw
331590Srgrimes * Integrate decompress() stack speedups (from early pointer mods by McKie).
341590Srgrimes * Repair multi-file USERMEM gaffe.  Unify 'force' flags to mimic semantics
351590Srgrimes * of SVR2 'pack'.  Streamline block-compress table clear logic.  Increase 
361590Srgrimes * output byte count by magic number size.
371590Srgrimes * 
381590Srgrimes * Revision 3.0   84/11/27  11:50:00  petsd!joe
391590Srgrimes * Set HSIZE depending on BITS.  Set BITS depending on USERMEM.  Unrolled
401590Srgrimes * loops in clear routines.  Added "-C" flag for 2.0 compatibility.  Used
411590Srgrimes * unsigned compares on Perkin-Elmer.  Fixed foreground check.
421590Srgrimes *
431590Srgrimes * Revision 2.7   84/11/16  19:35:39  ames!jaw
441590Srgrimes * Cache common hash codes based on input statistics; this improves
451590Srgrimes * performance for low-density raster images.  Pass on #ifdef bundle
461590Srgrimes * from Turkowski.
471590Srgrimes *
481590Srgrimes * Revision 2.6   84/11/05  19:18:21  ames!jaw
491590Srgrimes * Vary size of hash tables to reduce time for small files.
501590Srgrimes * Tune PDP-11 hash function.
511590Srgrimes *
521590Srgrimes * Revision 2.5   84/10/30  20:15:14  ames!jaw
531590Srgrimes * Junk chaining; replace with the simpler (and, on the VAX, faster)
541590Srgrimes * double hashing, discussed within.  Make block compression standard.
551590Srgrimes *
561590Srgrimes * Revision 2.4   84/10/16  11:11:11  ames!jaw
571590Srgrimes * Introduce adaptive reset for block compression, to boost the rate
581590Srgrimes * another several percent.  (See mailing list notes.)
591590Srgrimes *
601590Srgrimes * Revision 2.3   84/09/22  22:00:00  petsd!joe
611590Srgrimes * Implemented "-B" block compress.  Implemented REVERSE sorting of tab_next.
621590Srgrimes * Bug fix for last bits.  Changed fwrite to putchar loop everywhere.
631590Srgrimes *
641590Srgrimes * Revision 2.2   84/09/18  14:12:21  ames!jaw
651590Srgrimes * Fold in news changes, small machine typedef from thomas,
661590Srgrimes * #ifdef interdata from joe.
671590Srgrimes *
681590Srgrimes * Revision 2.1   84/09/10  12:34:56  ames!jaw
691590Srgrimes * Configured fast table lookup for 32-bit machines.
701590Srgrimes * This cuts user time in half for b <= FBITS, and is useful for news batching
711590Srgrimes * from VAX to PDP sites.  Also sped up decompress() [fwrite->putc] and
721590Srgrimes * added signal catcher [plus beef in writeerr()] to delete effluvia.
731590Srgrimes *
741590Srgrimes * Revision 2.0   84/08/28  22:00:00  petsd!joe
751590Srgrimes * Add check for foreground before prompting user.  Insert maxbits into
761590Srgrimes * compressed file.  Force file being uncompressed to end with ".Z".
771590Srgrimes * Added "-c" flag and "zcat".  Prepared for release.
781590Srgrimes *
791590Srgrimes * Revision 1.10  84/08/24  18:28:00  turtlevax!ken
801590Srgrimes * Will only compress regular files (no directories), added a magic number
811590Srgrimes * header (plus an undocumented -n flag to handle old files without headers),
821590Srgrimes * added -f flag to force overwriting of possibly existing destination file,
831590Srgrimes * otherwise the user is prompted for a response.  Will tack on a .Z to a
841590Srgrimes * filename if it doesn't have one when decompressing.  Will only replace
851590Srgrimes * file if it was compressed.
861590Srgrimes *
871590Srgrimes * Revision 1.9  84/08/16  17:28:00  turtlevax!ken
881590Srgrimes * Removed scanargs(), getopt(), added .Z extension and unlimited number of
891590Srgrimes * filenames to compress.  Flags may be clustered (-Ddvb12) or separated
901590Srgrimes * (-D -d -v -b 12), or combination thereof.  Modes and other status is
911590Srgrimes * copied with copystat().  -O bug for 4.2 seems to have disappeared with
921590Srgrimes * 1.8.
931590Srgrimes *
941590Srgrimes * Revision 1.8  84/08/09  23:15:00  joe
951590Srgrimes * Made it compatible with vax version, installed jim's fixes/enhancements
961590Srgrimes *
971590Srgrimes * Revision 1.6  84/08/01  22:08:00  joe
981590Srgrimes * Sped up algorithm significantly by sorting the compress chain.
991590Srgrimes *
1001590Srgrimes * Revision 1.5  84/07/13  13:11:00  srd
1011590Srgrimes * Added C version of vax asm routines.  Changed structure to arrays to
1021590Srgrimes * save much memory.  Do unsigned compares where possible (faster on
1031590Srgrimes * Perkin-Elmer)
1041590Srgrimes *
1051590Srgrimes * Revision 1.4  84/07/05  03:11:11  thomas
1061590Srgrimes * Clean up the code a little and lint it.  (Lint complains about all
1071590Srgrimes * the regs used in the asm, but I'm not going to "fix" this.)
1081590Srgrimes *
1091590Srgrimes * Revision 1.3  84/07/05  02:06:54  thomas
1101590Srgrimes * Minor fixes.
1111590Srgrimes *
1121590Srgrimes * Revision 1.2  84/07/05  00:27:27  thomas
1131590Srgrimes * Add variable bit length output.
1141590Srgrimes *
1151590Srgrimes */
1161590Srgrimes
1171590Srgrimesstatic char rcs_ident[] =
11881586Sru	"$Header: compress.c,v 4.0 85/07/30 12:50:00 joe Release $";
119