***********************************************************/
#include "ar.h"
-static int j; /* remaining bytes to copy */
-
extern struct lha_opts opts;
void
-decode_start(void)
+decode_start(struct lzh_istream *rp)
{
- huf_decode_start(opts.method);
- j = 0;
+ huf_decode_start(rp, opts.method);
}
void
-decode(uint count, uchar buffer[])
+decode(struct lzh_istream *rp, uint count,
+ char *buf, unsigned int *slide_off, int *slide_len)
/* The calling function must keep the number of
bytes to be processed. This function decodes
either 'count' bytes or 'DICSIZ' bytes, whichever
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) & (MAXDICSIZ - 1);
+ while (--*slide_len >= 0) {
+ buf[r] = buf[*slide_off];
+ *slide_off = (*slide_off+1) & (MAXDICSIZ - 1);
if (++r == count)
return;
}
for (;;) {
- c = decode_c();
+ c = decode_c(rp);
if (c <= UCHAR_MAX) {
- buffer[r] = c;
+ buf[r] = c;
if (++r == count)
return;
}
else {
- j = c - (UCHAR_MAX + 1 - THRESHOLD);
- i = (r - decode_p() - 1) & (MAXDICSIZ - 1);
- while (--j >= 0) {
- buffer[r] = buffer[i];
- i = (i + 1) & (MAXDICSIZ - 1);
+ *slide_len = c - (UCHAR_MAX + 1 - THRESHOLD);
+ *slide_off = (r - decode_p(rp) - 1) & (MAXDICSIZ - 1);
+ while (--*slide_len >= 0) {
+ buf[r] = buf[*slide_off];
+ *slide_off = (*slide_off+1) & (MAXDICSIZ - 1);
if (++r == count)
return;
}