From 3dcec65dd1e8f6aeaa31d9d79c703d83e090316f Mon Sep 17 00:00:00 2001 From: arai Date: Fri, 25 Oct 2002 16:56:49 +0000 Subject: [PATCH] * src/dhuf.c (decode_start_dyn): call init_code_cache(). * src/huf.c (encode_start_st1): ditto. (decode_start_st1): ditto. * src/larc.c (decode_start_lzs): ditto. * src/shuf.c (decode_start_st0): ditto. (encode_start_fix): ditto. (decode_start_fix): ditto. * src/Makefile.am: added bitio.c * src/cproto.sh: added bitio.c * src/bitio.c: new file. * src/crcio.c: extracted bitio routines. git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/lha/lha/trunk@564 6a8cc165-1e22-0410-a132-eb4e3f353aba --- src/Makefile.am | 4 +-- src/bitio.c | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/cproto.sh | 2 +- src/crcio.c | 106 ------------------------------------------------------- src/dhuf.c | 1 + src/huf.c | 2 ++ src/larc.c | 1 + src/shuf.c | 3 ++ 8 files changed, 117 insertions(+), 109 deletions(-) create mode 100644 src/bitio.c diff --git a/src/Makefile.am b/src/Makefile.am index 5025548..fa4b094 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,7 +1,7 @@ ## Process this file with automake to produce Makefile.in bin_PROGRAMS = lha -lha_SOURCES = append.c crcio.c dhuf.c extract.c header.c huf.c larc.c lha.h \ - lha_macro.h prototypes.h lhadd.c lharc.c lhext.c lhlist.c \ +lha_SOURCES = append.c bitio.c crcio.c dhuf.c extract.c header.c huf.c larc.c \ + lha.h lha_macro.h prototypes.h lhadd.c lharc.c lhext.c lhlist.c \ maketbl.c maketree.c patmatch.c shuf.c slide.c util.c lha_LDADD = @LIBOBJS@ EXTRA_DIST = lhdir.h diff --git a/src/bitio.c b/src/bitio.c new file mode 100644 index 0000000..7134c00 --- /dev/null +++ b/src/bitio.c @@ -0,0 +1,107 @@ +/* ------------------------------------------------------------------------ */ +/* LHa for UNIX */ +/* crcio.c -- crc input / output */ +/* */ +/* Modified Nobutaka Watazaki */ +/* */ +/* Ver. 1.14 Source All chagned 1995.01.14 N.Watazaki */ +/* ------------------------------------------------------------------------ */ +#include "lha.h" + +static unsigned char subbitbuf, bitcount; + +void +fillbuf(n) /* Shift bitbuf n bits left, read n bits */ + unsigned char n; +{ + while (n > bitcount) { + n -= bitcount; + bitbuf = (bitbuf << bitcount) + (subbitbuf >> (CHAR_BIT - bitcount)); + if (compsize != 0) { + compsize--; + subbitbuf = (unsigned char) getc(infile); + } + else + subbitbuf = 0; + bitcount = CHAR_BIT; + } + bitcount -= n; + bitbuf = (bitbuf << n) + (subbitbuf >> (CHAR_BIT - n)); + subbitbuf <<= n; +} + +unsigned short +getbits(n) + unsigned char n; +{ + unsigned short x; + + x = bitbuf >> (2 * CHAR_BIT - n); + fillbuf(n); + return x; +} + +void +putcode(n, x) /* Write leftmost n bits of x */ + unsigned char n; + unsigned short x; +{ + while (n >= bitcount) { + n -= bitcount; + subbitbuf += x >> (USHRT_BIT - bitcount); + x <<= bitcount; + if (compsize < origsize) { + if (fwrite(&subbitbuf, 1, 1, outfile) == 0) { + fatal_error("Write error in crcio.c(putcode)"); + } + compsize++; + } + else + unpackable = 1; + subbitbuf = 0; + bitcount = CHAR_BIT; + } + subbitbuf += x >> (USHRT_BIT - bitcount); + bitcount -= n; +} + +void +putbits(n, x) /* Write rightmost n bits of x */ + unsigned char n; + unsigned short x; +{ + x <<= USHRT_BIT - n; + while (n >= bitcount) { + n -= bitcount; + subbitbuf += x >> (USHRT_BIT - bitcount); + x <<= bitcount; + if (compsize < origsize) { + if (fwrite(&subbitbuf, 1, 1, outfile) == 0) { + fatal_error("Write error in crcio.c(putbits)"); + } + compsize++; + } + else + unpackable = 1; + subbitbuf = 0; + bitcount = CHAR_BIT; + } + subbitbuf += x >> (USHRT_BIT - bitcount); + bitcount -= n; +} + +void +init_getbits( /* void */ ) +{ + bitbuf = 0; + subbitbuf = 0; + bitcount = 0; + fillbuf(2 * CHAR_BIT); +} + +void +init_putbits( /* void */ ) +{ + bitcount = CHAR_BIT; + subbitbuf = 0; +} diff --git a/src/cproto.sh b/src/cproto.sh index f644477..c2c07ae 100644 --- a/src/cproto.sh +++ b/src/cproto.sh @@ -13,7 +13,7 @@ CPPFLAGS='-DSTDC_HEADERS=1 -D__extension__= ' -SOURCES='append.c crcio.c dhuf.c extract.c header.c +SOURCES='append.c bitio.c crcio.c dhuf.c extract.c header.c huf.c larc.c lhadd.c lharc.c lhext.c lhlist.c maketbl.c maketree.c patmatch.c shuf.c slide.c util.c diff --git a/src/crcio.c b/src/crcio.c index 9f70d37..aba1c3d 100644 --- a/src/crcio.c +++ b/src/crcio.c @@ -9,7 +9,6 @@ #include "lha.h" /* ------------------------------------------------------------------------ */ -static unsigned char subbitbuf, bitcount; #ifdef EUC static int putc_euc_cache; #endif @@ -45,90 +44,6 @@ calccrc(crc, p, n) } /* ------------------------------------------------------------------------ */ -void -fillbuf(n) /* Shift bitbuf n bits left, read n bits */ - unsigned char n; -{ - while (n > bitcount) { - n -= bitcount; - bitbuf = (bitbuf << bitcount) + (subbitbuf >> (CHAR_BIT - bitcount)); - if (compsize != 0) { - compsize--; - subbitbuf = (unsigned char) getc(infile); - } - else - subbitbuf = 0; - bitcount = CHAR_BIT; - } - bitcount -= n; - bitbuf = (bitbuf << n) + (subbitbuf >> (CHAR_BIT - n)); - subbitbuf <<= n; -} - -/* ------------------------------------------------------------------------ */ -unsigned short -getbits(n) - unsigned char n; -{ - unsigned short x; - - x = bitbuf >> (2 * CHAR_BIT - n); - fillbuf(n); - return x; -} - -/* ------------------------------------------------------------------------ */ -void -putcode(n, x) /* Write rightmost n bits of x */ - unsigned char n; - unsigned short x; -{ - while (n >= bitcount) { - n -= bitcount; - subbitbuf += x >> (USHRT_BIT - bitcount); - x <<= bitcount; - if (compsize < origsize) { - if (fwrite(&subbitbuf, 1, 1, outfile) == 0) { - fatal_error("Write error in crcio.c(putcode)"); - } - compsize++; - } - else - unpackable = 1; - subbitbuf = 0; - bitcount = CHAR_BIT; - } - subbitbuf += x >> (USHRT_BIT - bitcount); - bitcount -= n; -} - -/* ------------------------------------------------------------------------ */ -void -putbits(n, x) /* Write rightmost n bits of x */ - unsigned char n; - unsigned short x; -{ - x <<= USHRT_BIT - n; - while (n >= bitcount) { - n -= bitcount; - subbitbuf += x >> (USHRT_BIT - bitcount); - x <<= bitcount; - if (compsize < origsize) { - if (fwrite(&subbitbuf, 1, 1, outfile) == 0) { - fatal_error("Write error in crcio.c(putbits)"); - } - compsize++; - } - else - unpackable = 1; - subbitbuf = 0; - bitcount = CHAR_BIT; - } - subbitbuf += x >> (USHRT_BIT - bitcount); - bitcount -= n; -} - -/* ------------------------------------------------------------------------ */ int fread_crc(crcp, p, n, fp) unsigned int *crcp; @@ -185,27 +100,6 @@ init_code_cache( /* void */ ) getc_euc_cache = EOF; } -void -init_getbits( /* void */ ) -{ - bitbuf = 0; - subbitbuf = 0; - bitcount = 0; - fillbuf(2 * CHAR_BIT); -#ifdef EUC - putc_euc_cache = EOF; -#endif -} - -/* ------------------------------------------------------------------------ */ -void -init_putbits( /* void */ ) -{ - bitcount = CHAR_BIT; - subbitbuf = 0; - getc_euc_cache = EOF; -} - /* ------------------------------------------------------------------------ */ #ifdef EUC int diff --git a/src/dhuf.c b/src/dhuf.c index dfdcfda..38494c9 100644 --- a/src/dhuf.c +++ b/src/dhuf.c @@ -75,6 +75,7 @@ decode_start_dyn( /* void */ ) n_max = 286; maxmatch = MAXMATCH; init_getbits(); + init_code_cache(); start_c_dyn(); start_p_dyn(); } diff --git a/src/huf.c b/src/huf.c index 6a0d246..4efa464 100644 --- a/src/huf.c +++ b/src/huf.c @@ -300,6 +300,7 @@ encode_start_st1( /* void */ ) p_freq[i] = 0; output_pos = output_mask = 0; init_putbits(); + init_code_cache(); buf[0] = 0; } @@ -487,6 +488,7 @@ decode_start_st1( /* void */ ) } #endif init_getbits(); + init_code_cache(); blocksize = 0; } diff --git a/src/larc.c b/src/larc.c index 099bdbc..4dcbc45 100644 --- a/src/larc.c +++ b/src/larc.c @@ -35,6 +35,7 @@ void decode_start_lzs( /*void*/ ) { init_getbits(); + init_code_cache(); } /* ------------------------------------------------------------------------ */ diff --git a/src/shuf.c b/src/shuf.c index 652358d..0e38593 100644 --- a/src/shuf.c +++ b/src/shuf.c @@ -27,6 +27,7 @@ decode_start_st0( /*void*/ ) n_max = 286; maxmatch = MAXMATCH; init_getbits(); + init_code_cache(); #ifdef SUPPORT_LH7 np = 1 << (MAX_DICBIT - 7); #endif @@ -81,6 +82,7 @@ encode_start_fix( /*void*/ ) maxmatch = 60; np = 1 << (12 - 6); init_putbits(); + init_code_cache(); start_c_dyn(); ready_made(0); } @@ -136,6 +138,7 @@ decode_start_fix(/*void*/) n_max = 314; maxmatch = 60; init_getbits(); + init_code_cache(); np = 1 << (LZHUFF1_DICBIT - 6); start_c_dyn(); ready_made(0); -- 2.11.0