/*----------------------------------------------------------------------------
LZSS.C -- A Data Compression Program
4/6/1989 Haruhiko Okumura
Use, distribute, and modify this program freely.
Please send me your improved versions.
PC-VANSCIENCE
NIFTY-ServePAF01022
CompuServe74050,1022
Some changes made June, 2003 by Chris Giese
, /~geezer
- Changed F from 16 to 18, for compatability with Microsoft COMPRESS/EXPAND
EXPAND.EXE is on the install disks for MS-DOS version 6 and Windows 3.1
COMPRESS.EXE is in the Win 3.1 SDK, and comes with Borland C++ 3.1
- Changed compress/expand chars on command line from e/d to c/u
- Where possible and correct, changed ints to unsigned
- Made all functions static
- Changed formatting, indenting, global variable names, and function names
- Tried to simplify/clarify code in some areas
----------------------------------------------------------------------------*/
#include
#include
#include
#include
/* size of ring buffer */
#defineN4096
/* index for root of binary search trees */
#define NILN
/* upper limit for g_match_len. Changed from 18 to 16 for binary
compatability with Microsoft COMPRESS.EXE and EXPAND.EXE
#defineF18 */
#defineF16
/* encode string into position and length
if match_length is greater than this: */
#defineTHRESHOLD2
/* these assume little-endian CPU like Intel x86
-- need byte-swap function for big endian CPU */
#defineREAD_LE32(X)*(uint32_t *)(X)
#defineWRITE_LE32(X,Y)*(uint32_t *)(X) = (Y)
/* this assumes sizeof(long)==4 */
typedef unsigned longuint32_t;
/* text (input) size counter, code (output) size counter,
and counter for reporting progress every 1K bytes */
static unsigned long g_text_size, g_code_size, g_print_count;
/* ring buffer of size N, with extra F-1 bytes
to facilitate string comparison */
static unsigned char g_ring_buffer[N + F - 1];
/* position and length of longest match; set by insert_node() */
static unsigned g_match_