>From 4a3d2c59a280f11202f6b59465fd76119bb3eb75 Mon Sep 17 00:00:00 2001 From: John Reiser Date: Mon, 17 Jun 2013 14:24:29 -0700 Subject: [PATCH 1/2] Prepare to overlay arrays in either order (zip deflate vs LZW compress) by renaming constant BITS ==> LZW_BITS and creating file deflate.h. --- deflate.c | 24 +++--------------------- deflate.h | 41 +++++++++++++++++++++++++++++++++++++++++ gzip.c | 14 +++++++------- lzw.h | 6 +++--- unlzh.c | 2 +- unlzw.c | 14 +++++++------- 6 files changed, 62 insertions(+), 39 deletions(-) create mode 100644 deflate.h diff --git a/deflate.c b/deflate.c index f0f2394..31c81db 100644 --- a/deflate.c +++ b/deflate.c @@ -85,32 +85,14 @@ * Configuration parameters */ -/* Compile with MEDIUM_MEM to reduce the memory requirements or - * with SMALL_MEM to use as little memory as possible. Use BIG_MEM if the - * entire input file can be held in memory (not possible on 16 bit systems). - * Warning: defining these symbols affects HASH_BITS (see below) and thus - * affects the compression ratio. The compressed output - * is still correct, and might even be smaller in some cases. - */ - -#ifdef SMALL_MEM -# define HASH_BITS 13 /* Number of bits used to hash strings */ -#endif -#ifdef MEDIUM_MEM -# define HASH_BITS 14 -#endif -#ifndef HASH_BITS -# define HASH_BITS 15 - /* For portability to 16 bit machines, do not use values above 15. */ -#endif - +#include "deflate.h" /* To save space (see unlzw.c), we overlay prev+head with tab_prefix and * window with tab_suffix. Check that we can do this: */ -#if (WSIZE<<1) > (1< (1< BITS-1 +#if HASH_BITS > LZW_BITS-1 error: cannot overlay head with tab_prefix1 #endif diff --git a/deflate.h b/deflate.h new file mode 100644 index 0000000..43b02ea --- /dev/null +++ b/deflate.h @@ -0,0 +1,41 @@ +/* deflate.h -- factored from deflate.c; somewhat parallel to lzw.h + + Copyright (C) 1999, 2006, 2009-2013 Free Software Foundation, Inc. + Copyright (C) 1992-1993 Jean-loup Gailly + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Compile with MEDIUM_MEM to reduce the memory requirements or + * with SMALL_MEM to use as little memory as possible. Use BIG_MEM if the + * entire input file can be held in memory (not possible on 16 bit systems). + * Warning: defining these symbols affects HASH_BITS (see below) and thus + * affects the compression ratio. The compressed output + * is still correct, and might even be smaller in some cases. + */ + +#ifndef HASH_BITS + +#ifdef SMALL_MEM +# define HASH_BITS 13 /* Number of bits used to hash strings */ +#endif +#ifdef MEDIUM_MEM +# define HASH_BITS 14 +#endif +#ifndef HASH_BITS +# define HASH_BITS 15 + /* For portability to 16 bit machines, do not use values above 15. */ +#endif + +#endif diff --git a/gzip.c b/gzip.c index 93cc738..7da26ec 100644 --- a/gzip.c +++ b/gzip.c @@ -151,10 +151,10 @@ DECLARE(uch, outbuf, OUTBUFSIZ+OUTBUF_EXTRA); DECLARE(ush, d_buf, DIST_BUFSIZE); DECLARE(uch, window, 2L*WSIZE); #ifndef MAXSEG_64K - DECLARE(ush, tab_prefix, 1L< (1<<(BITS-2)) +#if NC > (1<<(LZW_BITS-2)) error cannot overlay left+right and prev #endif diff --git a/unlzw.c b/unlzw.c index 676d58c..3390440 100644 --- a/unlzw.c +++ b/unlzw.c @@ -70,12 +70,12 @@ union bytes { #endif #ifndef MAXSEG_64K - /* DECLARE(ush, tab_prefix, (1<>1] # define clear_tab_prefixof() \ @@ -128,15 +128,15 @@ int unlzw(in, out) maxbits &= BIT_MASK; maxmaxcode = MAXCODE(maxbits); - if (maxbits > BITS) { + if (maxbits > LZW_BITS) { fprintf(stderr, "\n%s: %s: compressed with %d bits, can only handle %d bits\n", - program_name, ifname, maxbits, BITS); + program_name, ifname, maxbits, LZW_BITS); exit_code = ERROR; return ERROR; } rsize = insize; - maxcode = MAXCODE(n_bits = INIT_BITS)-1; + maxcode = MAXCODE(n_bits = INIT_LZW_BITS)-1; bitmask = (1<