/* ------------------------------------------------------------------------ */
#include "lha.h"
-#include <assert.h>
-
#if HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif
#endif
/* ------------------------------------------------------------------------ */
-unsigned short left[2 * NC - 1], right[2 * NC - 1];
-unsigned char c_len[NC], pt_len[NPT];
-unsigned short c_freq[2 * NC - 1], c_table[4096], c_code[NC], p_freq[2 * NP - 1],
- pt_table[256], pt_code[NPT], t_freq[2 * NT - 1];
-
-static unsigned char *buf;
-static unsigned int bufsiz;
-static unsigned short blocksize;
-static unsigned short output_pos, output_mask;
-static int pbit;
-static int np;
+unsigned short left[2 * NC - 1], right[2 * NC - 1];
+
+unsigned short c_code[NC]; /* encode */
+unsigned short pt_code[NPT]; /* encode */
+
+unsigned short c_table[4096]; /* decode */
+unsigned short pt_table[256]; /* decode */
+
+unsigned short c_freq[2 * NC - 1]; /* encode */
+unsigned short p_freq[2 * NP - 1]; /* encode */
+unsigned short t_freq[2 * NT - 1]; /* encode */
+
+unsigned char c_len[NC];
+unsigned char pt_len[NPT];
+
+static unsigned char *buf; /* encode */
+static unsigned int bufsiz; /* encode */
+static unsigned short blocksize; /* decode */
+static unsigned short output_pos, output_mask; /* encode */
+
+static int pbit;
+static int np;
/* ------------------------------------------------------------------------ */
/* Encording */
/* ------------------------------------------------------------------------ */
if (k <= 6)
putbits(3, k);
else
+ /* k=7 -> 1110 k=8 -> 11110 k=9 -> 111110 ... */
putbits(k - 3, USHRT_MAX << 1);
if (i == i_special) {
while (i < 6 && pt_len[i] == 0)
}
/* ------------------------------------------------------------------------ */
-/* lh4, 5, 6 */
+/* lh4, 5, 6, 7 */
void
output_st1(c, p)
unsigned short c;
}
/* ------------------------------------------------------------------------ */
-/* lh4, 5, 6 */
+/* lh4, 5, 6, 7 */
void
encode_start_st1( /* void */ )
{
case LZHUFF6_DICBIT: pbit = 5; np = LZHUFF6_DICBIT + 1; break;
case LZHUFF7_DICBIT: pbit = 5; np = LZHUFF7_DICBIT + 1; break;
default:
- assert(0);
+ fatal_error("Cannot use %d bytes dictionary", 1 << dicbit);
}
-
+
for (i = 0; i < NC; i++)
c_freq[i] = 0;
for (i = 0; i < np; i++)
}
/* ------------------------------------------------------------------------ */
-/* lh4, 5, 6 */
+/* lh4, 5, 6, 7 */
void
encode_end_st1( /* void */ )
{
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 : c - 3);
+
pt_len[i++] = c;
if (i == i_special) {
c = getbits(2);
} 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 {
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 {
{
unsigned short j, mask;
- j = pt_table[bitbuf >> (16 - 8)];
+ j = pt_table[peekbits(8)];
if (j < np)
fillbuf(pt_len[j]);
else {
case LZHUFF6_DICBIT: pbit = 5; np = LZHUFF6_DICBIT + 1; break;
case LZHUFF7_DICBIT: pbit = 5; np = LZHUFF7_DICBIT + 1; break;
default:
- assert(0);
+ fatal_error("Cannot use %d bytes dictionary", 1 << dicbit);
}
init_getbits();