void decode(uint count, uchar buffer[]) /* The calling function must keep the number of bytes to be processed. This function decodes either 'count' bytes or 'DICSIZ' bytes, whichever is smaller, into the array 'buffer[]' of size 'DICSIZ' or more. Call decode_start() once for each new file before calling this function. */ { static uint i; uint r, c; r = 0; while (--j >= 0) { buffer[r] = buffer[i]; i = (i + 1) & (DICSIZ - 1); if (++r == count) return; } for ( ; ; ) { c = decode_c(); if (c <= UCHAR_MAX) { buffer[r] = c; if (++r == count) return; } else { j = c - (UCHAR_MAX + 1 - THRESHOLD); i = (r - decode_p() - 1) & (DICSIZ - 1); while (--j >= 0) { buffer[r] = buffer[i]; i = (i + 1) & (DICSIZ - 1); if (++r == count) return; } } } }
USHORT Unpack_HEAVY(UCHAR *in, UCHAR *out, UCHAR flags, USHORT origsize){ USHORT j, i, c, bitmask; UCHAR *outend; /* Heavy 1 uses a 4Kb dictionary, Heavy 2 uses 8Kb */ if (flags & 8) { np = 15; bitmask = 0x1fff; } else { np = 14; bitmask = 0x0fff; } initbitbuf(in); if (flags & 2) { if (read_tree_c()) return 1; if (read_tree_p()) return 2; } outend = out+origsize; while (out<outend) { c = decode_c(); if (c < 256) { *out++ = text[heavy_text_loc++ & bitmask] = (UCHAR)c; } else { j = (USHORT) (c - OFFSET); i = (USHORT) (heavy_text_loc - decode_p() - 1); while(j--) *out++ = text[heavy_text_loc++ & bitmask] = text[i++ & bitmask]; } } return 0; }