OSDN Git Service

remove global variables on maketree.c
[lha/olha.git] / decode.c
1 /***********************************************************
2         decode.c
3 ***********************************************************/
4 #include "ar.h"
5
6 extern struct lha_opts opts;
7
8 void
9 decode_start(struct lzh_istream *rp)
10 {
11     huf_decode_start(rp, opts.method);
12 }
13
14 void
15 decode(struct lzh_istream *rp, uint count,
16        char *buf, unsigned int *slide_off, int *slide_len)
17         /* The calling function must keep the number of
18            bytes to be processed.  This function decodes
19            either 'count' bytes or 'DICSIZ' bytes, whichever
20            is smaller, into the array 'buffer[]' of size
21            'DICSIZ' or more.
22            Call decode_start() once for each new file
23            before calling this function. */
24 {
25     uint r, c;
26
27     r = 0;
28     while (--*slide_len >= 0) {
29         buf[r] = buf[*slide_off];
30         *slide_off = (*slide_off+1) & (MAXDICSIZ - 1);
31         if (++r == count)
32             return;
33     }
34     for (;;) {
35         c = decode_c(rp);
36         if (c <= UCHAR_MAX) {
37             buf[r] = c;
38             if (++r == count)
39                 return;
40         }
41         else {
42             *slide_len = c - (UCHAR_MAX + 1 - THRESHOLD);
43             *slide_off = (r - decode_p(rp) - 1) & (MAXDICSIZ - 1);
44             while (--*slide_len >= 0) {
45                 buf[r] = buf[*slide_off];
46                 *slide_off = (*slide_off+1) & (MAXDICSIZ - 1);
47                 if (++r == count)
48                     return;
49             }
50         }
51     }
52 }