#pragma prototyped
/*
* lzh decoder
*/
#include <codex.h>
#define ROOT_C 0
struct State_s
{
int method;
int avail;
int eof;
int n1;
int most_p;
int flag;
int flagcnt;
int matchpos;
int offset;
};
static int
{
ssize_t r;
return 0;
{
return 0;
}
}
#define GETBITS(p,n) ((n)<=(p)->bitcount ? ((((p)->bitbuf)>>((p)->bitcount-=(n)))&((1L<<(n))-1)) : getbits(p,n,0))
#define PEEKBITS(p,n) ((n)<=(p)->bitcount ? ((((p)->bitbuf)>>((p)->bitcount-(n)))&((1L<<(n))-1)) : getbits(p,n,1))
static int
{
{
}
if (peek)
{
}
}
static int
{
#if 1
int i;
int j;
int k;
int l;
int m;
int n;
int available;
ui2* p;
return -1;
/* initialize */
for (i = 1; i <= 16; i++)
{
count[i] = 0;
}
/* count */
for (i = 0; i < nchar; i++)
/* calculate first code */
total = 0;
for (i = 1; i <= 16; i++)
{
}
if (total)
{
(*state->codex->disc->errorf)(NiL, state->codex->disc, 2, "%s: invalid compression table", state->codex->meth->name);
return -1;
}
/* shift data for make table. */
m = 16 - tablebits;
for (i = 1; i <= tablebits; i++)
{
start[i] >>= m;
weight[i] >>= m;
}
/* initialize */
k = 1 << tablebits;
if (j != 0)
for (i = j; i < k; i++)
table[i] = 0;
/* create table and tree */
for (j = 0; j < nchar; j++)
{
k = bitlen[j];
if (k == 0)
continue;
i = start[k];
l = i + weight[k];
if (k <= tablebits)
{
if (l > tablesize)
{
(*state->codex->disc->errorf)(NiL, state->codex->disc, 2, "%s: compression table overflow", state->codex->meth->name);
return -1;
}
/* code in table */
while (i < l)
table[i++] = j;
}
else
{
/* code not in table */
p = &table[i >> m];
i <<= tablebits;
n = k - tablebits;
/* make tree (n length) */
while (--n >= 0)
{
if (*p == 0)
{
*p = available++;
}
if (i & 0x8000)
else
i <<= 1;
}
*p = j;
}
start[k] = l;
}
#else
start[1] = 0;
for (i = 1; i <= 16; i++)
{
(*state->codex->disc->errorf)(NiL, state->codex->disc, 2, "%s: invalid compression table", state->codex->meth->name);
return -1;
}
for (i = 1; i <= tablebits; i++) {
}
while (i <= 16) {
i++;
}
k = 1 << tablebits;
while (i != k) table[i++] = 0;
}
{
(*state->codex->disc->errorf)(NiL, state->codex->disc, 2, "%s: compression table overflow", state->codex->meth->name);
return -1;
}
} else {
while (i != 0) {
if (*p == 0) {
*p = avail++;
}
k <<= 1; i--;
}
*p = ch;
}
}
#endif
return 0;
}
static int
{
int i;
int c;
int n;
{
for (i = 0; i < k; i++)
}
else
{
i = 0;
while (i < n)
{
c++;
if (i == i_special)
{
while (--c >= 0)
}
}
while (i < k)
return -1;
}
return 0;
}
static int
{
int i;
int c;
int n;
ui2 b;
return -1;
if (n == 0)
{
}
else
{
i = 0;
while (i < n)
{
while (c >= NT)
if (c <= 2)
{
if (c == 0)
c = 1;
else if (c == 1)
else
while (--c >= 0)
}
else
}
while (i < NC)
return -1;
}
return 0;
}
static void
{
int i;
int j;
int k;
int l;
int b;
ui4 f;
ui4 g;
b = 0;
{
{
j++;
}
}
j--;
i = end - 1;
l = end - 2;
while (i >= start)
{
while (i >= l)
{
i--;
j--;
}
;
while (j >= k)
{
i--;
j--;
}
i--;
l -= 2;
}
f = 0;
{
else
else
{
f = g;
}
}
}
static int
{
int b;
int q;
int r;
int s;
{
if (r >= 0)
else
if (s >= 0)
else
p = q;
}
{
{
}
}
else
}
static void
{
int q;
do
{
} while (q != ROOT_C);
}
static void
{
int q;
{
}
while (q != ROOT_P)
{
}
}
static void
{
int q;
int r;
q = r + 1;
{
}
}
static void
{
int i;
int j;
j = *tbl++;
code = 0;
{
while (*tbl == i)
{
j++;
tbl++;
weight >>= 1;
}
}
}
static int
{
int i;
int c;
i = 0;
while (i < N1)
{
else
{
for (i = 0; i < N1; i++)
for (i = 0; i < 4096; i++)
return 0;
}
}
}
static void
{
int i;
int c;
i = 0;
while (i < SNP)
{
{
for (i = 0; i < SNP; i++)
for (i = 0; i < 256; i++)
return;
}
}
}
static int
{
int i;
int j;
int f;
for (i = 0; i < TREESIZE_C; i++)
{
}
{
}
while (j >= 0)
{
else
i -= 2;
j--;
}
return 0;
}
{
3, 0x01, 0x04, 0x0c, 0x18, 0x30
};
static int
{
}
static int
{
int c;
while (c)
c = ~c;
return c;
}
static int
{
return 0;
}
static int
{
int c;
{
}
while (c)
c = (~c) - N_CHAR;
}
static int
{
}
static int
{
#if 0
#endif
}
static int
{
return 0;
}
{
2, 0x01, 0x01, 0x03, 0x06, 0x0D, 0x1F, 0x4E
};
static int
{
int j;
{
/* read block blocksize */
if (read_tree_c(state))
return -1;
else
return 0;
}
while (j >= N1)
{
else
}
if (j == N1 - 1)
return j;
}
static int
{
return 0;
}
static int
{
int j;
{
do
{
else
}
}
static int
{
{
}
else
{
}
return 0;
}
static int
{
ui4 j;
ui2 b;
if (!state->blocksize && (!(state->blocksize = GETBITS(state, 16)) || get_p_len(state, NT, TBIT, 3) || get_c_len(state) || get_p_len(state, state->snp, state->pbit, -1)))
return -1;
while (j >= NC)
}
static int
{
return 0;
}
static int
{
ui4 j;
ui2 b;
if (j)
return j;
}
static int
{
return 0;
}
static int
{
}
static int
{
return 0;
}
static int
{
}
static int
{
int i;
for (i = 0; i < 256; i++)
for (i = 0; i < 256; i++)
for (i = 0; i < 256; i++)
return 0;
}
static int
{
int c;
{
}
{
c &= 0x0f;
c += 0x100;
}
return c;
}
static int
{
return 0;
}
static int
{
}
{
};
static int
{
register int i;
register int n;
if (!(n = *s++))
{
return -1;
}
if (n == 'd')
i = 0;
else if (n == 's')
i = 2 * N_D;
else
{
return -1;
}
{
return -1;
}
if (p)
return i;
}
{
{ "lh0" },
{ "lh1", "4k", "d0", "s0" },
{ "lh2", "8k", "d1" },
{ "lh3", "8k", "s0" },
{ "lh4", "4k", "s1" },
{ "lh5", "8k", "s1" },
{ "lhd" },
{ "lhj", "26624","s1" },
{ "lz4" },
{ "lz5", "4k", "s3" },
{ "lz6", "32k", "s1" },
{ "lz7", "64k", "s1" },
{ "lzs", "2k", "s2" },
};
static int
{
register int i;
register int j;
for (i = 0; i < elementsof(arc); i++)
{
if (!arc[i][1])
else
{
}
}
return 0;
}
static int
{
const char* name;
char* s;
int i;
int j;
int w;
args += 2;
if (!args[0])
{
return -1;
}
if (!args[1])
{
for (i = 0;; i++)
{
if (i >= elementsof(arc))
{
return 0;
}
{
break;
}
}
if (!args[0])
{
p->meth = 0;
return 0;
}
}
{
(*p->disc->errorf)(NiL, p->disc, 2, "%s: window size must be in [%d..%d]", args[0], WINDOW_MIN, WINDOW_MAX);
return -1;
}
if (!args[1])
{
return -1;
}
if ((i = lzh_decoder(args[1], 0, p->disc)) < 0 || (j = lzh_decoder(args[2] ? args[2] : args[1], 1, p->disc)) < 0)
return -1;
{
return -1;
}
return 0;
}
static int
{
}
static ssize_t
{
register char* s = (char*)buf;
register char* e = s + n;
int c;
int i;
ui4 j;
return 0;
{
if (s >= e)
return s - (char*)buf;
}
for (;;)
{
if (c < 0)
break;
else if (c <= UCHAR_MAX)
{
if (s >= e)
break;
}
else
{
if (i < 0)
while (j--)
{
i = 0;
if (s >= e)
{
return s - (char*)buf;
}
}
}
}
return (n = s - (char*)buf) ? n : -1;
}
{
"lzh",
"lzh compression. The options are ordered. A single option alias"
" (example \blzh-lh5\b) or \awindow-ccode\a[-\apcode\a]"
" (example \blzh-4k-d0-s0\b) are accepted. \apcode\a defaults to"
" \accode\a if omitted.",
"[+window?Window size <= 64k.]:[size]"
"[+coding?\accode\a or \apcode\a coding method { d0 s0 s1 s2 s3 }.]"
"[+(version)?codex-lzh 1998-11-11]",
0,
0,
0,
0,
0,
0,
0,
0,
0,
};