OSDN Git Service

* src/dhuf.c (decode_start_dyn): call init_code_cache().
[lha/lha.git] / src / larc.c
1 /* ------------------------------------------------------------------------ */
2 /* LHa for UNIX                                                                                                                         */
3 /*                              larc.c -- extra *.lzs                                                                           */
4 /*                                                                                                                                                      */
5 /*              Modified                        Nobutaka Watazaki                                                       */
6 /*                                                                                                                                                      */
7 /*      Ver. 1.14       Source All chagned                              1995.01.14      N.Watazaki              */
8 /* ------------------------------------------------------------------------ */
9 #include "lha.h"
10
11 /* ------------------------------------------------------------------------ */
12 static int      flag, flagcnt, matchpos;
13 /* ------------------------------------------------------------------------ */
14 unsigned short
15 decode_c_lzs( /*void*/ )
16 {
17         if (getbits(1)) {
18                 return getbits(8);
19         }
20         else {
21                 matchpos = getbits(11);
22                 return getbits(4) + 0x100;
23         }
24 }
25
26 /* ------------------------------------------------------------------------ */
27 unsigned short
28 decode_p_lzs( /*void*/ )
29 {
30         return (loc - matchpos - MAGIC0) & 0x7ff;
31 }
32
33 /* ------------------------------------------------------------------------ */
34 void
35 decode_start_lzs( /*void*/ )
36 {
37         init_getbits();
38     init_code_cache();
39 }
40
41 /* ------------------------------------------------------------------------ */
42 unsigned short
43 decode_c_lz5( /*void*/ )
44 {
45         int             c;
46
47         if (flagcnt == 0) {
48                 flagcnt = 8;
49                 flag = getc(infile);
50         }
51         flagcnt--;
52         c = getc(infile);
53         if ((flag & 1) == 0) {
54                 matchpos = c;
55                 c = getc(infile);
56                 matchpos += (c & 0xf0) << 4;
57                 c &= 0x0f;
58                 c += 0x100;
59         }
60         flag >>= 1;
61         return c;
62 }
63
64 /* ------------------------------------------------------------------------ */
65 unsigned short
66 decode_p_lz5( /*void*/ )
67 {
68         return (loc - matchpos - MAGIC5) & 0xfff;
69 }
70
71 /* ------------------------------------------------------------------------ */
72 void
73 decode_start_lz5( /*void*/ )
74 {
75         int             i;
76
77         flagcnt = 0;
78         for (i = 0; i < 256; i++)
79                 memset(&text[i * 13 + 18], i, 13);
80         for (i = 0; i < 256; i++)
81                 text[256 * 13 + 18 + i] = i;
82         for (i = 0; i < 256; i++)
83                 text[256 * 13 + 256 + 18 + i] = 255 - i;
84         memset(&text[256 * 13 + 512 + 18], 0, 128);
85         memset(&text[256 * 13 + 512 + 128 + 18], ' ', 128 - 18);
86 }
87 /* Local Variables: */
88 /* tab-width : 4 */
89 /* End: */
90 /* vi: set tabstop=4: */