diff options
Diffstat (limited to 'archival/bz/bzlib_private.h')
-rw-r--r-- | archival/bz/bzlib_private.h | 234 |
1 files changed, 234 insertions, 0 deletions
diff --git a/archival/bz/bzlib_private.h b/archival/bz/bzlib_private.h new file mode 100644 index 000000000..24ffbee9c --- /dev/null +++ b/archival/bz/bzlib_private.h | |||
@@ -0,0 +1,234 @@ | |||
1 | /* | ||
2 | * bzip2 is written by Julian Seward <jseward@bzip.org>. | ||
3 | * Adapted for busybox by Denys Vlasenko <vda.linux@googlemail.com>. | ||
4 | * See README and LICENSE files in this directory for more information. | ||
5 | */ | ||
6 | |||
7 | /*-------------------------------------------------------------*/ | ||
8 | /*--- Private header file for the library. ---*/ | ||
9 | /*--- bzlib_private.h ---*/ | ||
10 | /*-------------------------------------------------------------*/ | ||
11 | |||
12 | /* ------------------------------------------------------------------ | ||
13 | This file is part of bzip2/libbzip2, a program and library for | ||
14 | lossless, block-sorting data compression. | ||
15 | |||
16 | bzip2/libbzip2 version 1.0.4 of 20 December 2006 | ||
17 | Copyright (C) 1996-2006 Julian Seward <jseward@bzip.org> | ||
18 | |||
19 | Please read the WARNING, DISCLAIMER and PATENTS sections in the | ||
20 | README file. | ||
21 | |||
22 | This program is released under the terms of the license contained | ||
23 | in the file LICENSE. | ||
24 | ------------------------------------------------------------------ */ | ||
25 | |||
26 | /* #include "bzlib.h" */ | ||
27 | |||
28 | #define BZ_DEBUG 0 | ||
29 | //#define BZ_NO_STDIO 1 - does not work | ||
30 | |||
31 | |||
32 | /*-- General stuff. --*/ | ||
33 | |||
34 | typedef unsigned char Bool; | ||
35 | typedef unsigned char UChar; | ||
36 | |||
37 | #define True ((Bool)1) | ||
38 | #define False ((Bool)0) | ||
39 | |||
40 | static void bz_assert_fail(int errcode) ATTRIBUTE_NORETURN; | ||
41 | #define AssertH(cond, errcode) \ | ||
42 | { \ | ||
43 | if (!(cond)) \ | ||
44 | bz_assert_fail(errcode); \ | ||
45 | } | ||
46 | |||
47 | #if BZ_DEBUG | ||
48 | #define AssertD(cond, msg) \ | ||
49 | { \ | ||
50 | if (!(cond)) \ | ||
51 | bb_error_msg_and_die("(debug build): internal error %s", msg); \ | ||
52 | } | ||
53 | #else | ||
54 | #define AssertD(cond, msg) do { } while (0) | ||
55 | #endif | ||
56 | |||
57 | |||
58 | /*-- Header bytes. --*/ | ||
59 | |||
60 | #define BZ_HDR_B 0x42 /* 'B' */ | ||
61 | #define BZ_HDR_Z 0x5a /* 'Z' */ | ||
62 | #define BZ_HDR_h 0x68 /* 'h' */ | ||
63 | #define BZ_HDR_0 0x30 /* '0' */ | ||
64 | |||
65 | #define BZ_HDR_BZh0 0x425a6830 | ||
66 | |||
67 | /*-- Constants for the back end. --*/ | ||
68 | |||
69 | #define BZ_MAX_ALPHA_SIZE 258 | ||
70 | #define BZ_MAX_CODE_LEN 23 | ||
71 | |||
72 | #define BZ_RUNA 0 | ||
73 | #define BZ_RUNB 1 | ||
74 | |||
75 | #define BZ_N_GROUPS 6 | ||
76 | #define BZ_G_SIZE 50 | ||
77 | #define BZ_N_ITERS 4 | ||
78 | |||
79 | #define BZ_MAX_SELECTORS (2 + (900000 / BZ_G_SIZE)) | ||
80 | |||
81 | |||
82 | /*-- Stuff for randomising repetitive blocks. --*/ | ||
83 | |||
84 | static const int32_t BZ2_rNums[512]; | ||
85 | |||
86 | #define BZ_RAND_DECLS \ | ||
87 | int32_t rNToGo; \ | ||
88 | int32_t rTPos \ | ||
89 | |||
90 | #define BZ_RAND_INIT_MASK \ | ||
91 | s->rNToGo = 0; \ | ||
92 | s->rTPos = 0 \ | ||
93 | |||
94 | #define BZ_RAND_MASK ((s->rNToGo == 1) ? 1 : 0) | ||
95 | |||
96 | #define BZ_RAND_UPD_MASK \ | ||
97 | { \ | ||
98 | if (s->rNToGo == 0) { \ | ||
99 | s->rNToGo = BZ2_rNums[s->rTPos]; \ | ||
100 | s->rTPos++; \ | ||
101 | if (s->rTPos == 512) s->rTPos = 0; \ | ||
102 | } \ | ||
103 | s->rNToGo--; \ | ||
104 | } | ||
105 | |||
106 | |||
107 | /*-- Stuff for doing CRCs. --*/ | ||
108 | |||
109 | static const uint32_t BZ2_crc32Table[256]; | ||
110 | |||
111 | #define BZ_INITIALISE_CRC(crcVar) \ | ||
112 | { \ | ||
113 | crcVar = 0xffffffffL; \ | ||
114 | } | ||
115 | |||
116 | #define BZ_FINALISE_CRC(crcVar) \ | ||
117 | { \ | ||
118 | crcVar = ~(crcVar); \ | ||
119 | } | ||
120 | |||
121 | #define BZ_UPDATE_CRC(crcVar,cha) \ | ||
122 | { \ | ||
123 | crcVar = (crcVar << 8) ^ BZ2_crc32Table[(crcVar >> 24) ^ ((UChar)cha)]; \ | ||
124 | } | ||
125 | |||
126 | |||
127 | /*-- States and modes for compression. --*/ | ||
128 | |||
129 | #define BZ_M_IDLE 1 | ||
130 | #define BZ_M_RUNNING 2 | ||
131 | #define BZ_M_FLUSHING 3 | ||
132 | #define BZ_M_FINISHING 4 | ||
133 | |||
134 | #define BZ_S_OUTPUT 1 | ||
135 | #define BZ_S_INPUT 2 | ||
136 | |||
137 | #define BZ_N_RADIX 2 | ||
138 | #define BZ_N_QSORT 12 | ||
139 | #define BZ_N_SHELL 18 | ||
140 | #define BZ_N_OVERSHOOT (BZ_N_RADIX + BZ_N_QSORT + BZ_N_SHELL + 2) | ||
141 | |||
142 | |||
143 | /*-- Structure holding all the compression-side stuff. --*/ | ||
144 | |||
145 | typedef struct EState { | ||
146 | /* pointer back to the struct bz_stream */ | ||
147 | bz_stream *strm; | ||
148 | |||
149 | /* mode this stream is in, and whether inputting */ | ||
150 | /* or outputting data */ | ||
151 | int32_t mode; | ||
152 | int32_t state; | ||
153 | |||
154 | /* remembers avail_in when flush/finish requested */ | ||
155 | uint32_t avail_in_expect; //vda: do we need this? | ||
156 | |||
157 | /* for doing the block sorting */ | ||
158 | uint32_t *arr1; | ||
159 | uint32_t *arr2; | ||
160 | uint32_t *ftab; | ||
161 | int32_t origPtr; | ||
162 | |||
163 | /* aliases for arr1 and arr2 */ | ||
164 | uint32_t *ptr; | ||
165 | UChar *block; | ||
166 | uint16_t *mtfv; | ||
167 | UChar *zbits; | ||
168 | |||
169 | /* run-length-encoding of the input */ | ||
170 | uint32_t state_in_ch; | ||
171 | int32_t state_in_len; | ||
172 | BZ_RAND_DECLS; | ||
173 | |||
174 | /* input and output limits and current posns */ | ||
175 | int32_t nblock; | ||
176 | int32_t nblockMAX; | ||
177 | int32_t numZ; | ||
178 | int32_t state_out_pos; | ||
179 | |||
180 | /* the buffer for bit stream creation */ | ||
181 | uint32_t bsBuff; | ||
182 | int32_t bsLive; | ||
183 | |||
184 | /* block and combined CRCs */ | ||
185 | uint32_t blockCRC; | ||
186 | uint32_t combinedCRC; | ||
187 | |||
188 | /* misc administratium */ | ||
189 | int32_t blockNo; | ||
190 | int32_t blockSize100k; | ||
191 | |||
192 | /* stuff for coding the MTF values */ | ||
193 | int32_t nMTF; | ||
194 | |||
195 | /* map of bytes used in block */ | ||
196 | int32_t nInUse; | ||
197 | Bool inUse[256]; | ||
198 | UChar unseqToSeq[256]; | ||
199 | |||
200 | /* stuff for coding the MTF values */ | ||
201 | int32_t mtfFreq [BZ_MAX_ALPHA_SIZE]; | ||
202 | UChar selector [BZ_MAX_SELECTORS]; | ||
203 | UChar selectorMtf[BZ_MAX_SELECTORS]; | ||
204 | |||
205 | UChar len [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE]; | ||
206 | int32_t code [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE]; | ||
207 | int32_t rfreq [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE]; | ||
208 | #ifdef FAST_GROUP6 | ||
209 | /* second dimension: only 3 needed; 4 makes index calculations faster */ | ||
210 | uint32_t len_pack[BZ_MAX_ALPHA_SIZE][4]; | ||
211 | #endif | ||
212 | } EState; | ||
213 | |||
214 | |||
215 | /*-- compression. --*/ | ||
216 | |||
217 | static void | ||
218 | BZ2_blockSort(EState*); | ||
219 | |||
220 | static void | ||
221 | BZ2_compressBlock(EState*, Bool); | ||
222 | |||
223 | static void | ||
224 | BZ2_bsInitWrite(EState*); | ||
225 | |||
226 | static void | ||
227 | BZ2_hbAssignCodes(int32_t*, UChar*, int32_t, int32_t, int32_t); | ||
228 | |||
229 | static void | ||
230 | BZ2_hbMakeCodeLengths(UChar*, int32_t*, int32_t, int32_t); | ||
231 | |||
232 | /*-------------------------------------------------------------*/ | ||
233 | /*--- end bzlib_private.h ---*/ | ||
234 | /*-------------------------------------------------------------*/ | ||