From db351ee4868cbc0eec8ecf7d94f1063f9c7099e0 Mon Sep 17 00:00:00 2001 From: arai Date: Sat, 28 Dec 2002 02:03:44 +0000 Subject: [PATCH] * src/lha_macro.h (peekbits): newly added. * src/huf.c (read_pt_len): use peekbits(). (read_c_len): ditto. (decode_c_st1): ditto. (decode_p_st1): ditto. * src/shuf.c (decode_c_st0): ditto. (decode_p_st0): ditto. git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/lha/lha/trunk@608 6a8cc165-1e22-0410-a132-eb4e3f353aba --- src/huf.c | 15 +++++++++------ src/lha_macro.h | 3 +++ src/shuf.c | 4 ++-- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/huf.c b/src/huf.c index 0a37043..df093a3 100644 --- a/src/huf.c +++ b/src/huf.c @@ -329,15 +329,18 @@ read_pt_len(nn, nbit, i_special) else { i = 0; while (i < n) { - c = bitbuf >> (16 - 3); - if (c == 7) { + c = peekbits(3); + if (c != 7) + fillbuf(3); + else { unsigned short mask = 1 << (16 - 4); while (mask & bitbuf) { mask >>= 1; c++; } + fillbuf(c - 3); /* fillbuf(c - 7 + 3); ??? */ } - fillbuf((c < 7) ? 3 : c - 3); + pt_len[i++] = c; if (i == i_special) { c = getbits(2); @@ -367,7 +370,7 @@ read_c_len( /* void */ ) } else { i = 0; while (i < n) { - c = pt_table[bitbuf >> (16 - 8)]; + c = pt_table[peekbits(8)]; if (c >= NT) { unsigned short mask = 1 << (16 - 9); do { @@ -412,7 +415,7 @@ decode_c_st1( /*void*/ ) read_pt_len(np, pbit, -1); } blocksize--; - j = c_table[bitbuf >> 4]; + j = c_table[peekbits(12)]; if (j < NC) fillbuf(c_len[j]); else { @@ -437,7 +440,7 @@ decode_p_st1( /* void */ ) { unsigned short j, mask; - j = pt_table[bitbuf >> (16 - 8)]; + j = pt_table[peekbits(8)]; if (j < np) fillbuf(pt_len[j]); else { diff --git a/src/lha_macro.h b/src/lha_macro.h index 2c168b8..c1815c7 100644 --- a/src/lha_macro.h +++ b/src/lha_macro.h @@ -194,6 +194,9 @@ /* Individual macro define */ /* ------------------------------------------------------------------------ */ +/* bitio.c */ +#define peekbits(n) (bitbuf >> (sizeof(bitbuf)*8 - (n))) + /* from crcio.c */ #define CRCPOLY 0xA001 /* CRC-16 (x^16+x^15+x^2+1) */ #define INITIALIZE_CRC(crc) ((crc) = 0) diff --git a/src/shuf.c b/src/shuf.c index 90585f1..93d0f32 100644 --- a/src/shuf.c +++ b/src/shuf.c @@ -168,7 +168,7 @@ decode_c_st0(/*void*/) make_table(NP, pt_len, 8, pt_table); } blocksize--; - j = c_table[bitbuf >> 4]; + j = c_table[peekbits(12)]; if (j < N1) fillbuf(c_len[j]); else { @@ -195,7 +195,7 @@ decode_p_st0(/*void*/) { int i, j; - j = pt_table[bitbuf >> 8]; + j = pt_table[peekbits(8)]; if (j < np) { fillbuf(pt_len[j]); } -- 2.11.0