/* ------------------------------------------------------------------------ */
#include "lha.h"
+#include <assert.h>
+
#if HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif
}
/* ------------------------------------------------------------------------ */
+/* lh4, 5, 6 */
void
output_st1(c, p)
unsigned short c;
}
/* ------------------------------------------------------------------------ */
+/* lh4, 5, 6 */
void
encode_start_st1( /* void */ )
{
int i;
-#if 0
- if (dicbit <= (MAX_DICBIT - 2)) {
- pbit = 4; /* lh4,5 etc. */
- np = 14;
- } else {
- pbit = 5; /* lh6 */
- np = 16;
- }
-#endif
-
- if (dicbit <= 13) {
- pbit = 4; /* lh4,5 etc. */
- np = 14;
- } else {
- pbit = 5; /* lh6,7 */
- if (dicbit == 16)
- np = 17;
- else
- np = 16;
- }
-
+ switch (dicbit) {
+ case LZHUFF4_DICBIT:
+ case LZHUFF5_DICBIT: pbit = 4; np = LZHUFF5_DICBIT + 1; break;
+ case LZHUFF6_DICBIT: pbit = 5; np = LZHUFF6_DICBIT + 1; break;
+ case LZHUFF7_DICBIT: pbit = 5; np = LZHUFF7_DICBIT + 1; break;
+ default:
+ assert(0);
+ }
+
for (i = 0; i < NC; i++)
c_freq[i] = 0;
for (i = 0; i < np; i++)
}
/* ------------------------------------------------------------------------ */
+/* lh4, 5, 6 */
void
encode_end_st1( /* void */ )
{
}
/* ------------------------------------------------------------------------ */
+/* lh4, 5, 6, 7 */
unsigned short
decode_c_st1( /*void*/ )
{
}
/* ------------------------------------------------------------------------ */
+/* lh4, 5, 6, 7 */
unsigned short
decode_p_st1( /* void */ )
{
}
/* ------------------------------------------------------------------------ */
+/* lh4, 5, 6, 7 */
void
decode_start_st1( /* void */ )
{
- if (dicbit <= 13) {
- np = 14;
- pbit = 4;
- } else {
- if (dicbit == 16) {
- np = 17; /* for -lh7- */
- } else {
- np = 16;
- }
- pbit = 5;
- }
+ switch (dicbit) {
+ case LZHUFF4_DICBIT:
+ case LZHUFF5_DICBIT: pbit = 4; np = LZHUFF5_DICBIT + 1; break;
+ case LZHUFF6_DICBIT: pbit = 5; np = LZHUFF6_DICBIT + 1; break;
+ case LZHUFF7_DICBIT: pbit = 5; np = LZHUFF7_DICBIT + 1; break;
+ default:
+ assert(0);
+ }
-#if 0
- if (dicbit <= 13) { /* 13 ... Changed N.Watazaki */
- np = 14;
- pbit = 4;
- } else {
- np = 16;
- pbit = 5;
- }
-#endif
init_getbits();
init_code_cache();
blocksize = 0;
#endif
#include "lha.h"
-
+#include <assert.h>
#ifdef DEBUG
FILE *fout = NULL;
static struct encode_option encode_set;
static struct decode_option decode_set;
-#if 0
-static node pos, matchpos, avail, *position, *parent, *prev;
-static int remainder, matchlen;
-static unsigned char *level, *childcount;
-static unsigned long dicsiz; /* t.okamoto */
-static unsigned short max_hash_val;
-static unsigned short hash1, hash2;
-#endif
-
-#ifdef SUPPORT_LH7
-#define DICSIZ (1L << 16)
-#define TXTSIZ (DICSIZ * 2L + MAXMATCH)
-#else
-#define DICSIZ (((unsigned long)1) << 15)
-#define TXTSIZ (DICSIZ * 2 + MAXMATCH)
-#endif
-
+#define TXTSIZ (MAX_DICSIZ * 2L + MAXMATCH)
#define HSHSIZ (((unsigned long)1) <<15)
#define NIL 0
#define LIMIT 0x100 /* chain ŤΠlimit */
encode_alloc(method)
int method;
{
- if (method == LZHUFF1_METHOD_NUM) { /* Changed N.Watazaki */
- encode_set = encode_define[0];
- maxmatch = 60;
- dicbit = 12; /* 12 Changed N.Watazaki */
- } else { /* method LH4(12),LH5(13),LH6(15) */
- encode_set = encode_define[1];
- maxmatch = MAXMATCH;
- if (method == LZHUFF7_METHOD_NUM)
- dicbit = LZHUFF7_DICBIT; /* 16 bits */
- else if (method == LZHUFF6_METHOD_NUM)
- dicbit = LZHUFF6_DICBIT; /* 15 bits */
- else /* LH5 LH4 is not used */
- dicbit = LZHUFF5_DICBIT; /* 13 bits */
- }
+ switch (method) {
+ case LZHUFF1_METHOD_NUM:
+ encode_set = encode_define[0];
+ maxmatch = 60;
+ dicbit = LZHUFF1_DICBIT; /* 12 bits Changed N.Watazaki */
+ break;
+ case LZHUFF5_METHOD_NUM:
+ encode_set = encode_define[1];
+ maxmatch = MAXMATCH;
+ dicbit = LZHUFF5_DICBIT; /* 13 bits */
+ break;
+ case LZHUFF6_METHOD_NUM:
+ encode_set = encode_define[1];
+ maxmatch = MAXMATCH;
+ dicbit = LZHUFF6_DICBIT; /* 15 bits */
+ break;
+ case LZHUFF7_METHOD_NUM:
+ encode_set = encode_define[1];
+ maxmatch = MAXMATCH;
+ dicbit = LZHUFF7_DICBIT; /* 16 bits */
+ break;
+ default:
+ assert(0);
+ }
dicsiz = (((unsigned long)1) << dicbit);
txtsiz = dicsiz*2+maxmatch;
alloc_buf();
hash = (unsigned int*)xmalloc(HSHSIZ * sizeof(unsigned int));
- prev = (unsigned int*)xmalloc(DICSIZ * sizeof(unsigned int));
+ prev = (unsigned int*)xmalloc(MAX_DICSIZ * sizeof(unsigned int));
text = (unsigned char*)xmalloc(TXTSIZ);
too_flag = (unsigned char*)xmalloc(HSHSIZ);
unsigned int i, j;
long n;
-#if 0
- memmove(&text[0], &text[dicsiz], (unsigned)(txtsiz - dicsiz));
-#else
- {
- int m;
- i = 0; j = dicsiz; m = txtsiz-dicsiz;
- while (m-- > 0) {
- text[i++] = text[j++];
- }
- }
-#endif
- n = fread_crc(&crc, &text[(unsigned)(txtsiz - dicsiz)],
- (unsigned)dicsiz, infile);
+ assert(dicsiz > 0);
+ assert(txtsiz - dicsiz > 0);
+ memmove(&text[0], &text[dicsiz], txtsiz - dicsiz);
+
+ n = fread_crc(&crc, &text[txtsiz - dicsiz], dicsiz, infile);
remainder += n;
- encoded_origsize += n;
+ encoded_origsize += n; /* total size of read bytes */
pos -= dicsiz;
for (i = 0; i < HSHSIZ; i++) {
init_slide();
encode_set.encode_start();
- memset(&text[0], ' ', (long)TXTSIZ);
+ memset(&text[0], ' ', TXTSIZ);
remainder = fread_crc(&crc, &text[dicsiz], txtsiz-dicsiz, infile);
encoded_origsize = remainder;