static void
split(struct match_t *match, node old)
{
- node new, t;
+ node new;
new = avail;
avail = next[new];
#if PERCOLATE
node q, r, s, t, u;
#else
- node r, s, t, u;
+ node r, s, t;
#endif
if (parent[pos] == NIL)
}
static void
-get_next_match(struct match_t *match)
+get_next_match(struct lzh_ostream *wp, FILE *rfp, struct match_t *match)
{
int n;
remainder--;
if (++pos == DICSIZ * 2) {
memmove(&text[0], &text[DICSIZ], DICSIZ + MAXMATCH);
- n = fread_crc(&text[DICSIZ + MAXMATCH], DICSIZ, infile);
+ n = fread_crc(&text[DICSIZ + MAXMATCH], DICSIZ, rfp, &wp->crc);
+ wp->origsize += n;
remainder += n;
pos = DICSIZ;
- if (outfile != stdout && opts.quiet < 1) {
+ if (wp->fp != stdout && opts.quiet < 1) {
putc('.', stdout);
}
}
}
void
-encode(void)
+encode(struct lzh_ostream *wp, FILE *rfp)
{
struct match_t match, lastmatch;
allocate_memory();
init_slide();
- huf_encode_start(opts.method);
- remainder = fread_crc(&text[DICSIZ], DICSIZ + MAXMATCH, infile);
+ huf_encode_start(wp, opts.method);
+ remainder = fread_crc(&text[DICSIZ], DICSIZ + MAXMATCH, rfp, &wp->crc);
+ wp->origsize += remainder;
- if (outfile != stdout && opts.quiet < 1) {
+ if (wp->fp != stdout && opts.quiet < 1) {
putc('.', stdout);
}
match.len = 0;
insert_node(&match);
if (match.len > remainder)
match.len = remainder;
- while (remainder > 0 && !unpackable) {
+ while (remainder > 0 && !wp->unpackable) {
lastmatch = match;
- get_next_match(&match);
+ get_next_match(wp, rfp, &match);
if (match.len > remainder)
match.len = remainder;
if (match.len > lastmatch.len || lastmatch.len < THRESHOLD)
- output(text[pos - 1], 0);
+ output(wp, text[pos - 1], 0);
else {
- output(lastmatch.len + (UCHAR_MAX + 1 - THRESHOLD),
+ output(wp, lastmatch.len + (UCHAR_MAX + 1 - THRESHOLD),
(pos - lastmatch.pos - 2) & (DICSIZ - 1));
while (--lastmatch.len > 0)
- get_next_match(&match);
+ get_next_match(wp, rfp, &match);
if (match.len > remainder)
match.len = remainder;
}
}
- huf_encode_end();
+ huf_encode_end(wp);
}