1 | /* minilzo.c -- mini subset of the LZO real-time data compression library
|
---|
2 |
|
---|
3 | This file is part of the LZO real-time data compression library.
|
---|
4 |
|
---|
5 | Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer
|
---|
6 | Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer
|
---|
7 | Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer
|
---|
8 | Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer
|
---|
9 |
|
---|
10 | The LZO library is free software; you can redistribute it and/or
|
---|
11 | modify it under the terms of the GNU General Public License as
|
---|
12 | published by the Free Software Foundation; either version 2 of
|
---|
13 | the License, or (at your option) any later version.
|
---|
14 |
|
---|
15 | The LZO library is distributed in the hope that it will be useful,
|
---|
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
18 | GNU General Public License for more details.
|
---|
19 |
|
---|
20 | You should have received a copy of the GNU General Public License
|
---|
21 | along with the LZO library; see the file COPYING.
|
---|
22 | If not, write to the Free Software Foundation, Inc.,
|
---|
23 | 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
---|
24 |
|
---|
25 | Markus F.X.J. Oberhumer
|
---|
26 | <markus.oberhumer@jk.uni-linz.ac.at>
|
---|
27 | http://wildsau.idv.uni-linz.ac.at/mfx/lzo.html
|
---|
28 | */
|
---|
29 |
|
---|
30 | /*
|
---|
31 | * NOTE:
|
---|
32 | * the full LZO package can be found at
|
---|
33 | * http://wildsau.idv.uni-linz.ac.at/mfx/lzo.html
|
---|
34 | */
|
---|
35 |
|
---|
36 | #define _ANSI_C_SOURCE
|
---|
37 | #define _POSIX_SOURCE
|
---|
38 |
|
---|
39 |
|
---|
40 |
|
---|
41 | #define __LZO_IN_MINILZO
|
---|
42 |
|
---|
43 | #ifdef MINILZO_HAVE_CONFIG_H
|
---|
44 | # include <config.h>
|
---|
45 | #endif
|
---|
46 |
|
---|
47 | #undef LZO_HAVE_CONFIG_H
|
---|
48 | #include "minilzo.h"
|
---|
49 |
|
---|
50 | #if !defined(MINILZO_VERSION) || (MINILZO_VERSION != 0x1060)
|
---|
51 | # error "version mismatch in miniLZO source files"
|
---|
52 | #endif
|
---|
53 |
|
---|
54 | #ifdef MINILZO_HAVE_CONFIG_H
|
---|
55 | # define LZO_HAVE_CONFIG_H
|
---|
56 | #endif
|
---|
57 |
|
---|
58 | #if !defined(LZO_NO_SYS_TYPES_H)
|
---|
59 | # include <sys/types.h>
|
---|
60 | #endif
|
---|
61 | #include <stdio.h>
|
---|
62 |
|
---|
63 | #ifndef __LZO_CONF_H
|
---|
64 | #define __LZO_CONF_H
|
---|
65 |
|
---|
66 | #if !defined(__LZO_IN_MINILZO)
|
---|
67 | # ifndef __LZOCONF_H
|
---|
68 | # include <lzoconf.h>
|
---|
69 | # endif
|
---|
70 | #endif
|
---|
71 |
|
---|
72 | #if !defined(LZO_HAVE_CONFIG_H)
|
---|
73 | # include <stddef.h>
|
---|
74 | # include <string.h>
|
---|
75 | # if !defined(NO_STDLIB_H)
|
---|
76 | # include <stdlib.h>
|
---|
77 | # endif
|
---|
78 | # define HAVE_MEMCMP
|
---|
79 | # define HAVE_MEMCPY
|
---|
80 | # define HAVE_MEMMOVE
|
---|
81 | # define HAVE_MEMSET
|
---|
82 | #else
|
---|
83 | # include <sys/types.h>
|
---|
84 | # if defined(__STDC__)
|
---|
85 | # include <string.h>
|
---|
86 | # include <stdlib.h>
|
---|
87 | # include <stddef.h>
|
---|
88 | # include <memory.h>
|
---|
89 | # endif
|
---|
90 | #endif
|
---|
91 |
|
---|
92 | #if defined(__LZO_DOS16) || defined(__LZO_WIN16)
|
---|
93 | # define HAVE_MALLOC_H
|
---|
94 | # define HAVE_HALLOC
|
---|
95 | #endif
|
---|
96 |
|
---|
97 | #undef NDEBUG
|
---|
98 | #if !defined(LZO_DEBUG)
|
---|
99 | # define NDEBUG
|
---|
100 | #endif
|
---|
101 | #if defined(LZO_DEBUG) || !defined(NDEBUG)
|
---|
102 | # if !defined(NO_STDIO_H)
|
---|
103 | # include <stdio.h>
|
---|
104 | # endif
|
---|
105 | #endif
|
---|
106 | #include <assert.h>
|
---|
107 |
|
---|
108 | #if defined(__BOUNDS_CHECKING_ON)
|
---|
109 | # include <unchecked.h>
|
---|
110 | #else
|
---|
111 | # define BOUNDS_CHECKING_OFF_DURING(stmt) stmt
|
---|
112 | # define BOUNDS_CHECKING_OFF_IN_EXPR(expr) (expr)
|
---|
113 | #endif
|
---|
114 |
|
---|
115 | #if !defined(LZO_UNUSED)
|
---|
116 | # define LZO_UNUSED(parm) (parm = parm)
|
---|
117 | #endif
|
---|
118 |
|
---|
119 | #if !defined(__inline__) && !defined(__GNUC__)
|
---|
120 | # if defined(__cplusplus)
|
---|
121 | # define __inline__ inline
|
---|
122 | # else
|
---|
123 | # define __inline__
|
---|
124 | # endif
|
---|
125 | #endif
|
---|
126 |
|
---|
127 | #if defined(NO_MEMCMP)
|
---|
128 | # undef HAVE_MEMCMP
|
---|
129 | #endif
|
---|
130 |
|
---|
131 | #if !defined(HAVE_MEMCMP)
|
---|
132 | # undef memcmp
|
---|
133 | # define memcmp lzo_memcmp
|
---|
134 | #endif
|
---|
135 | #if !defined(HAVE_MEMCPY)
|
---|
136 | # undef memcpy
|
---|
137 | # define memcpy lzo_memcpy
|
---|
138 | #endif
|
---|
139 | #if !defined(HAVE_MEMMOVE)
|
---|
140 | # undef memmove
|
---|
141 | # define memmove lzo_memmove
|
---|
142 | #endif
|
---|
143 | #if !defined(HAVE_MEMSET)
|
---|
144 | # undef memset
|
---|
145 | # define memset lzo_memset
|
---|
146 | #endif
|
---|
147 |
|
---|
148 | #if 1
|
---|
149 | # define LZO_BYTE(x) ((unsigned char) (x))
|
---|
150 | #else
|
---|
151 | # define LZO_BYTE(x) ((unsigned char) ((x) & 0xff))
|
---|
152 | #endif
|
---|
153 | #if 0
|
---|
154 | # define LZO_USHORT(x) ((unsigned short) (x))
|
---|
155 | #else
|
---|
156 | # define LZO_USHORT(x) ((unsigned short) ((x) & 0xffff))
|
---|
157 | #endif
|
---|
158 |
|
---|
159 | #define LZO_MAX(a,b) ((a) >= (b) ? (a) : (b))
|
---|
160 | #define LZO_MIN(a,b) ((a) <= (b) ? (a) : (b))
|
---|
161 | #define LZO_MAX3(a,b,c) ((a) >= (b) ? LZO_MAX(a,c) : LZO_MAX(b,c))
|
---|
162 | #define LZO_MIN3(a,b,c) ((a) <= (b) ? LZO_MIN(a,c) : LZO_MIN(b,c))
|
---|
163 |
|
---|
164 | #define lzo_sizeof(type) ((lzo_uint) (sizeof(type)))
|
---|
165 |
|
---|
166 | #define LZO_HIGH(array) ((lzo_uint) (sizeof(array)/sizeof(*(array))))
|
---|
167 |
|
---|
168 | #define LZO_SIZE(bits) (1u << (bits))
|
---|
169 | #define LZO_MASK(bits) (LZO_SIZE(bits) - 1)
|
---|
170 |
|
---|
171 | #define LZO_LSIZE(bits) (1ul << (bits))
|
---|
172 | #define LZO_LMASK(bits) (LZO_LSIZE(bits) - 1)
|
---|
173 |
|
---|
174 | #define LZO_USIZE(bits) ((lzo_uint) 1 << (bits))
|
---|
175 | #define LZO_UMASK(bits) (LZO_USIZE(bits) - 1)
|
---|
176 |
|
---|
177 | #define LZO_STYPE_MAX(b) (((1l << (8*(b)-2)) - 1l) + (1l << (8*(b)-2)))
|
---|
178 | #define LZO_UTYPE_MAX(b) (((1ul << (8*(b)-1)) - 1ul) + (1ul << (8*(b)-1)))
|
---|
179 |
|
---|
180 | #if !defined(SIZEOF_UNSIGNED)
|
---|
181 | # if (UINT_MAX == 0xffff)
|
---|
182 | # define SIZEOF_UNSIGNED 2
|
---|
183 | # elif (UINT_MAX == LZO_0xffffffffL)
|
---|
184 | # define SIZEOF_UNSIGNED 4
|
---|
185 | # elif (UINT_MAX >= LZO_0xffffffffL)
|
---|
186 | # define SIZEOF_UNSIGNED 8
|
---|
187 | # else
|
---|
188 | # error SIZEOF_UNSIGNED
|
---|
189 | # endif
|
---|
190 | #endif
|
---|
191 |
|
---|
192 | #if !defined(SIZEOF_UNSIGNED_LONG)
|
---|
193 | # if (ULONG_MAX == LZO_0xffffffffL)
|
---|
194 | # define SIZEOF_UNSIGNED_LONG 4
|
---|
195 | # elif (ULONG_MAX >= LZO_0xffffffffL)
|
---|
196 | # define SIZEOF_UNSIGNED_LONG 8
|
---|
197 | # else
|
---|
198 | # error SIZEOF_UNSIGNED_LONG
|
---|
199 | # endif
|
---|
200 | #endif
|
---|
201 |
|
---|
202 | #if !defined(SIZEOF_SIZE_T)
|
---|
203 | # define SIZEOF_SIZE_T SIZEOF_UNSIGNED
|
---|
204 | #endif
|
---|
205 | #if !defined(SIZE_T_MAX)
|
---|
206 | # define SIZE_T_MAX LZO_UTYPE_MAX(SIZEOF_SIZE_T)
|
---|
207 | #endif
|
---|
208 |
|
---|
209 | #if 1 && defined(__LZO_i386) && (UINT_MAX == LZO_0xffffffffL)
|
---|
210 | # if !defined(LZO_UNALIGNED_OK_2) && (USHRT_MAX == 0xffff)
|
---|
211 | # define LZO_UNALIGNED_OK_2
|
---|
212 | # endif
|
---|
213 | # if !defined(LZO_UNALIGNED_OK_4) && (LZO_UINT32_MAX == LZO_0xffffffffL)
|
---|
214 | # define LZO_UNALIGNED_OK_4
|
---|
215 | # endif
|
---|
216 | #endif
|
---|
217 |
|
---|
218 | #if defined(LZO_UNALIGNED_OK_2) || defined(LZO_UNALIGNED_OK_4)
|
---|
219 | # if !defined(LZO_UNALIGNED_OK)
|
---|
220 | # define LZO_UNALIGNED_OK
|
---|
221 | # endif
|
---|
222 | #endif
|
---|
223 |
|
---|
224 | #if defined(__LZO_NO_UNALIGNED)
|
---|
225 | # undef LZO_UNALIGNED_OK
|
---|
226 | # undef LZO_UNALIGNED_OK_2
|
---|
227 | # undef LZO_UNALIGNED_OK_4
|
---|
228 | #endif
|
---|
229 |
|
---|
230 | #if defined(LZO_UNALIGNED_OK_2) && (USHRT_MAX != 0xffff)
|
---|
231 | # error "LZO_UNALIGNED_OK_2 must not be defined on this system"
|
---|
232 | #endif
|
---|
233 | #if defined(LZO_UNALIGNED_OK_4) && (LZO_UINT32_MAX != LZO_0xffffffffL)
|
---|
234 | # error "LZO_UNALIGNED_OK_4 must not be defined on this system"
|
---|
235 | #endif
|
---|
236 |
|
---|
237 | #if defined(__LZO_NO_ALIGNED)
|
---|
238 | # undef LZO_ALIGNED_OK_4
|
---|
239 | #endif
|
---|
240 |
|
---|
241 | #if defined(LZO_ALIGNED_OK_4) && (LZO_UINT32_MAX != LZO_0xffffffffL)
|
---|
242 | # error "LZO_ALIGNED_OK_4 must not be defined on this system"
|
---|
243 | #endif
|
---|
244 |
|
---|
245 | #define LZO_LITTLE_ENDIAN 1234
|
---|
246 | #define LZO_BIG_ENDIAN 4321
|
---|
247 | #define LZO_PDP_ENDIAN 3412
|
---|
248 |
|
---|
249 | #if !defined(LZO_BYTE_ORDER)
|
---|
250 | # if defined(MFX_BYTE_ORDER)
|
---|
251 | # define LZO_BYTE_ORDER MFX_BYTE_ORDER
|
---|
252 | # elif defined(__LZO_i386)
|
---|
253 | # define LZO_BYTE_ORDER LZO_LITTLE_ENDIAN
|
---|
254 | # elif defined(BYTE_ORDER)
|
---|
255 | # define LZO_BYTE_ORDER BYTE_ORDER
|
---|
256 | # elif defined(__BYTE_ORDER)
|
---|
257 | # define LZO_BYTE_ORDER __BYTE_ORDER
|
---|
258 | # endif
|
---|
259 | #endif
|
---|
260 |
|
---|
261 | #if defined(LZO_BYTE_ORDER)
|
---|
262 | # if (LZO_BYTE_ORDER != LZO_LITTLE_ENDIAN) && \
|
---|
263 | (LZO_BYTE_ORDER != LZO_BIG_ENDIAN)
|
---|
264 | # error "invalid LZO_BYTE_ORDER"
|
---|
265 | # endif
|
---|
266 | #endif
|
---|
267 |
|
---|
268 | #if defined(LZO_UNALIGNED_OK) && !defined(LZO_BYTE_ORDER)
|
---|
269 | # error "LZO_BYTE_ORDER is not defined"
|
---|
270 | #endif
|
---|
271 |
|
---|
272 | #define LZO_OPTIMIZE_GNUC_i386_IS_BUGGY
|
---|
273 |
|
---|
274 | #if defined(NDEBUG) && !defined(LZO_DEBUG) && !defined(__BOUNDS_CHECKING_ON)
|
---|
275 | # if defined(__GNUC__) && defined(__i386__)
|
---|
276 | # if !defined(LZO_OPTIMIZE_GNUC_i386_IS_BUGGY)
|
---|
277 | # define LZO_OPTIMIZE_GNUC_i386
|
---|
278 | # endif
|
---|
279 | # endif
|
---|
280 | #endif
|
---|
281 |
|
---|
282 | __LZO_EXTERN_C int __lzo_init_done;
|
---|
283 | __LZO_EXTERN_C const lzo_byte __lzo_copyright[];
|
---|
284 | LZO_EXTERN(const lzo_byte *) lzo_copyright(void);
|
---|
285 | __LZO_EXTERN_C const lzo_uint32 _lzo_crc32_table[256];
|
---|
286 |
|
---|
287 | #define _LZO_STRINGIZE(x) #x
|
---|
288 | #define _LZO_MEXPAND(x) _LZO_STRINGIZE(x)
|
---|
289 |
|
---|
290 | #define _LZO_CONCAT2(a,b) a ## b
|
---|
291 | #define _LZO_CONCAT3(a,b,c) a ## b ## c
|
---|
292 | #define _LZO_CONCAT4(a,b,c,d) a ## b ## c ## d
|
---|
293 | #define _LZO_CONCAT5(a,b,c,d,e) a ## b ## c ## d ## e
|
---|
294 |
|
---|
295 | #define _LZO_ECONCAT2(a,b) _LZO_CONCAT2(a,b)
|
---|
296 | #define _LZO_ECONCAT3(a,b,c) _LZO_CONCAT3(a,b,c)
|
---|
297 | #define _LZO_ECONCAT4(a,b,c,d) _LZO_CONCAT4(a,b,c,d)
|
---|
298 | #define _LZO_ECONCAT5(a,b,c,d,e) _LZO_CONCAT5(a,b,c,d,e)
|
---|
299 |
|
---|
300 | #if 0
|
---|
301 |
|
---|
302 | #define __LZO_IS_COMPRESS_QUERY(i,il,o,ol,w) ((lzo_voidp)(o) == (w))
|
---|
303 | #define __LZO_QUERY_COMPRESS(i,il,o,ol,w,n,s) \
|
---|
304 | (*ol = (n)*(s), LZO_E_OK)
|
---|
305 |
|
---|
306 | #define __LZO_IS_DECOMPRESS_QUERY(i,il,o,ol,w) ((lzo_voidp)(o) == (w))
|
---|
307 | #define __LZO_QUERY_DECOMPRESS(i,il,o,ol,w,n,s) \
|
---|
308 | (*ol = (n)*(s), LZO_E_OK)
|
---|
309 |
|
---|
310 | #define __LZO_IS_OPTIMIZE_QUERY(i,il,o,ol,w) ((lzo_voidp)(o) == (w))
|
---|
311 | #define __LZO_QUERY_OPTIMIZE(i,il,o,ol,w,n,s) \
|
---|
312 | (*ol = (n)*(s), LZO_E_OK)
|
---|
313 |
|
---|
314 | #endif
|
---|
315 |
|
---|
316 | #ifndef __LZO_PTR_H
|
---|
317 | #define __LZO_PTR_H
|
---|
318 |
|
---|
319 | #ifdef __cplusplus
|
---|
320 | extern "C" {
|
---|
321 | #endif
|
---|
322 |
|
---|
323 | #if defined(__LZO_DOS16) || defined(__LZO_WIN16)
|
---|
324 | # include <dos.h>
|
---|
325 | # if 1 && defined(__WATCOMC__)
|
---|
326 | # include <i86.h>
|
---|
327 | __LZO_EXTERN_C unsigned char _HShift;
|
---|
328 | # define __LZO_HShift _HShift
|
---|
329 | # elif 1 && defined(_MSC_VER)
|
---|
330 | __LZO_EXTERN_C unsigned short __near _AHSHIFT;
|
---|
331 | # define __LZO_HShift ((unsigned) &_AHSHIFT)
|
---|
332 | # elif defined(__LZO_WIN16)
|
---|
333 | # define __LZO_HShift 3
|
---|
334 | # else
|
---|
335 | # define __LZO_HShift 12
|
---|
336 | # endif
|
---|
337 | # if !defined(_FP_SEG) && defined(FP_SEG)
|
---|
338 | # define _FP_SEG FP_SEG
|
---|
339 | # endif
|
---|
340 | # if !defined(_FP_OFF) && defined(FP_OFF)
|
---|
341 | # define _FP_OFF FP_OFF
|
---|
342 | # endif
|
---|
343 | #endif
|
---|
344 |
|
---|
345 | #if (UINT_MAX >= LZO_0xffffffffL)
|
---|
346 | typedef ptrdiff_t lzo_ptrdiff_t;
|
---|
347 | #else
|
---|
348 | typedef long lzo_ptrdiff_t;
|
---|
349 | #endif
|
---|
350 |
|
---|
351 | #if !defined(__LZO_HAVE_PTR_T)
|
---|
352 | # if defined(lzo_ptr_t)
|
---|
353 | # define __LZO_HAVE_PTR_T
|
---|
354 | # endif
|
---|
355 | #endif
|
---|
356 | #if !defined(__LZO_HAVE_PTR_T)
|
---|
357 | # if defined(SIZEOF_CHAR_P) && defined(SIZEOF_UNSIGNED_LONG)
|
---|
358 | # if (SIZEOF_CHAR_P == SIZEOF_UNSIGNED_LONG)
|
---|
359 | typedef unsigned long lzo_ptr_t;
|
---|
360 | typedef long lzo_sptr_t;
|
---|
361 | # define __LZO_HAVE_PTR_T
|
---|
362 | # endif
|
---|
363 | # endif
|
---|
364 | #endif
|
---|
365 | #if !defined(__LZO_HAVE_PTR_T)
|
---|
366 | # if defined(SIZEOF_CHAR_P) && defined(SIZEOF_UNSIGNED)
|
---|
367 | # if (SIZEOF_CHAR_P == SIZEOF_UNSIGNED)
|
---|
368 | typedef unsigned int lzo_ptr_t;
|
---|
369 | typedef int lzo_sptr_t;
|
---|
370 | # define __LZO_HAVE_PTR_T
|
---|
371 | # endif
|
---|
372 | # endif
|
---|
373 | #endif
|
---|
374 | #if !defined(__LZO_HAVE_PTR_T)
|
---|
375 | # if defined(SIZEOF_CHAR_P) && defined(SIZEOF_UNSIGNED_SHORT)
|
---|
376 | # if (SIZEOF_CHAR_P == SIZEOF_UNSIGNED_SHORT)
|
---|
377 | typedef unsigned short lzo_ptr_t;
|
---|
378 | typedef short lzo_sptr_t;
|
---|
379 | # define __LZO_HAVE_PTR_T
|
---|
380 | # endif
|
---|
381 | # endif
|
---|
382 | #endif
|
---|
383 | #if !defined(__LZO_HAVE_PTR_T)
|
---|
384 | # if defined(LZO_HAVE_CONFIG_H) || defined(SIZEOF_CHAR_P)
|
---|
385 | # error "no suitable type for lzo_ptr_t"
|
---|
386 | # else
|
---|
387 | typedef unsigned long lzo_ptr_t;
|
---|
388 | typedef long lzo_sptr_t;
|
---|
389 | # define __LZO_HAVE_PTR_T
|
---|
390 | # endif
|
---|
391 | #endif
|
---|
392 |
|
---|
393 | #if defined(__LZO_DOS16) || defined(__LZO_WIN16)
|
---|
394 | #define PTR(a) ((lzo_bytep) (a))
|
---|
395 | #define PTR_ALIGNED_4(a) ((_FP_OFF(a) & 3) == 0)
|
---|
396 | #define PTR_ALIGNED2_4(a,b) (((_FP_OFF(a) | _FP_OFF(b)) & 3) == 0)
|
---|
397 | #else
|
---|
398 | #define PTR(a) ((lzo_ptr_t) (a))
|
---|
399 | #define PTR_LINEAR(a) PTR(a)
|
---|
400 | #define PTR_ALIGNED_4(a) ((PTR_LINEAR(a) & 3) == 0)
|
---|
401 | #define PTR_ALIGNED_8(a) ((PTR_LINEAR(a) & 7) == 0)
|
---|
402 | #define PTR_ALIGNED2_4(a,b) (((PTR_LINEAR(a) | PTR_LINEAR(b)) & 3) == 0)
|
---|
403 | #define PTR_ALIGNED2_8(a,b) (((PTR_LINEAR(a) | PTR_LINEAR(b)) & 7) == 0)
|
---|
404 | #endif
|
---|
405 |
|
---|
406 | #define PTR_LT(a,b) (PTR(a) < PTR(b))
|
---|
407 | #define PTR_GE(a,b) (PTR(a) >= PTR(b))
|
---|
408 | #define PTR_DIFF(a,b) ((lzo_ptrdiff_t) (PTR(a) - PTR(b)))
|
---|
409 |
|
---|
410 | LZO_EXTERN(lzo_ptr_t)
|
---|
411 | __lzo_ptr_linear(const lzo_voidp ptr);
|
---|
412 |
|
---|
413 | typedef union
|
---|
414 | {
|
---|
415 | char a_char;
|
---|
416 | unsigned char a_uchar;
|
---|
417 | short a_short;
|
---|
418 | unsigned short a_ushort;
|
---|
419 | int a_int;
|
---|
420 | unsigned int a_uint;
|
---|
421 | long a_long;
|
---|
422 | unsigned long a_ulong;
|
---|
423 | lzo_int a_lzo_int;
|
---|
424 | lzo_uint a_lzo_uint;
|
---|
425 | lzo_int32 a_lzo_int32;
|
---|
426 | lzo_uint32 a_lzo_uint32;
|
---|
427 | ptrdiff_t a_ptrdiff_t;
|
---|
428 | lzo_ptrdiff_t a_lzo_ptrdiff_t;
|
---|
429 | lzo_ptr_t a_lzo_ptr_t;
|
---|
430 | char * a_charp;
|
---|
431 | lzo_bytep a_lzo_bytep;
|
---|
432 | lzo_bytepp a_lzo_bytepp;
|
---|
433 | }
|
---|
434 | lzo_align_t;
|
---|
435 |
|
---|
436 | #ifdef __cplusplus
|
---|
437 | }
|
---|
438 | #endif
|
---|
439 |
|
---|
440 | #endif
|
---|
441 |
|
---|
442 | #define LZO_DETERMINISTIC
|
---|
443 |
|
---|
444 | #define LZO_DICT_USE_PTR
|
---|
445 | #if defined(__LZO_DOS16) || defined(__LZO_WIN16) || defined(__LZO_STRICT_16BIT)
|
---|
446 | # undef LZO_DICT_USE_PTR
|
---|
447 | #endif
|
---|
448 |
|
---|
449 | #if defined(LZO_DICT_USE_PTR)
|
---|
450 | # define lzo_dict_t const lzo_bytep
|
---|
451 | # define lzo_dict_p lzo_dict_t __LZO_MMODEL *
|
---|
452 | #else
|
---|
453 | # define lzo_dict_t lzo_uint
|
---|
454 | # define lzo_dict_p lzo_dict_t __LZO_MMODEL *
|
---|
455 | #endif
|
---|
456 |
|
---|
457 | #if !defined(lzo_moff_t)
|
---|
458 | #define lzo_moff_t lzo_uint
|
---|
459 | #endif
|
---|
460 |
|
---|
461 | #endif
|
---|
462 |
|
---|
463 | LZO_PUBLIC(lzo_ptr_t)
|
---|
464 | __lzo_ptr_linear(const lzo_voidp ptr)
|
---|
465 | {
|
---|
466 | lzo_ptr_t p;
|
---|
467 |
|
---|
468 | #if defined(__LZO_DOS16) || defined(__LZO_WIN16)
|
---|
469 | p = (((lzo_ptr_t)(_FP_SEG(ptr))) << (16 - __LZO_HShift)) + (_FP_OFF(ptr));
|
---|
470 | #else
|
---|
471 | p = PTR_LINEAR(ptr);
|
---|
472 | #endif
|
---|
473 |
|
---|
474 | return p;
|
---|
475 | }
|
---|
476 |
|
---|
477 | LZO_PUBLIC(unsigned)
|
---|
478 | __lzo_align_gap(const lzo_voidp ptr, lzo_uint size)
|
---|
479 | {
|
---|
480 | lzo_ptr_t p, s, n;
|
---|
481 |
|
---|
482 | assert(size > 0);
|
---|
483 |
|
---|
484 | p = __lzo_ptr_linear(ptr);
|
---|
485 | s = (lzo_ptr_t) (size - 1);
|
---|
486 | #if 0
|
---|
487 | assert((size & (size - 1)) == 0);
|
---|
488 | n = ((p + s) & ~s) - p;
|
---|
489 | #else
|
---|
490 | n = (((p + s) / size) * size) - p;
|
---|
491 | #endif
|
---|
492 |
|
---|
493 | assert((long)n >= 0);
|
---|
494 | assert(n <= s);
|
---|
495 |
|
---|
496 | return (unsigned)n;
|
---|
497 | }
|
---|
498 |
|
---|
499 | #ifndef __LZO_UTIL_H
|
---|
500 | #define __LZO_UTIL_H
|
---|
501 |
|
---|
502 | #ifndef __LZO_CONF_H
|
---|
503 | #endif
|
---|
504 |
|
---|
505 | #ifdef __cplusplus
|
---|
506 | extern "C" {
|
---|
507 | #endif
|
---|
508 |
|
---|
509 | #if 1 && defined(HAVE_MEMCPY)
|
---|
510 | #if !defined(__LZO_DOS16) && !defined(__LZO_WIN16)
|
---|
511 |
|
---|
512 | #define MEMCPY8_DS(dest,src,len) \
|
---|
513 | memcpy(dest,src,len); \
|
---|
514 | dest += len; \
|
---|
515 | src += len
|
---|
516 |
|
---|
517 | #endif
|
---|
518 | #endif
|
---|
519 |
|
---|
520 | #if 0 && !defined(MEMCPY8_DS)
|
---|
521 |
|
---|
522 | #define MEMCPY8_DS(dest,src,len) \
|
---|
523 | { do { \
|
---|
524 | *dest++ = *src++; \
|
---|
525 | *dest++ = *src++; \
|
---|
526 | *dest++ = *src++; \
|
---|
527 | *dest++ = *src++; \
|
---|
528 | *dest++ = *src++; \
|
---|
529 | *dest++ = *src++; \
|
---|
530 | *dest++ = *src++; \
|
---|
531 | *dest++ = *src++; \
|
---|
532 | len -= 8; \
|
---|
533 | } while (len > 0); }
|
---|
534 |
|
---|
535 | #endif
|
---|
536 |
|
---|
537 | #if !defined(MEMCPY8_DS)
|
---|
538 |
|
---|
539 | #define MEMCPY8_DS(dest,src,len) \
|
---|
540 | { register lzo_uint __l = (len) / 8; \
|
---|
541 | do { \
|
---|
542 | *dest++ = *src++; \
|
---|
543 | *dest++ = *src++; \
|
---|
544 | *dest++ = *src++; \
|
---|
545 | *dest++ = *src++; \
|
---|
546 | *dest++ = *src++; \
|
---|
547 | *dest++ = *src++; \
|
---|
548 | *dest++ = *src++; \
|
---|
549 | *dest++ = *src++; \
|
---|
550 | } while (--__l > 0); }
|
---|
551 |
|
---|
552 | #endif
|
---|
553 |
|
---|
554 | #define MEMCPY_DS(dest,src,len) \
|
---|
555 | do *dest++ = *src++; \
|
---|
556 | while (--len > 0)
|
---|
557 |
|
---|
558 | #define MEMMOVE_DS(dest,src,len) \
|
---|
559 | do *dest++ = *src++; \
|
---|
560 | while (--len > 0)
|
---|
561 |
|
---|
562 | #if 0 && defined(LZO_OPTIMIZE_GNUC_i386)
|
---|
563 |
|
---|
564 | #define BZERO8_PTR(s,l,n) \
|
---|
565 | __asm__ __volatile__( \
|
---|
566 | "movl %0,%%eax \n" \
|
---|
567 | "movl %1,%%edi \n" \
|
---|
568 | "movl %2,%%ecx \n" \
|
---|
569 | "cld \n" \
|
---|
570 | "rep \n" \
|
---|
571 | "stosl %%eax,(%%edi) \n" \
|
---|
572 | : \
|
---|
573 | :"g" (0),"g" (s),"g" (n) \
|
---|
574 | :"eax","edi","ecx", "memory", "cc" \
|
---|
575 | )
|
---|
576 |
|
---|
577 | #elif (LZO_UINT_MAX <= SIZE_T_MAX) && defined(HAVE_MEMSET)
|
---|
578 |
|
---|
579 | #if 1
|
---|
580 | #define BZERO8_PTR(s,l,n) memset((s),0,(lzo_uint)(l)*(n))
|
---|
581 | #else
|
---|
582 | #define BZERO8_PTR(s,l,n) memset((lzo_voidp)(s),0,(lzo_uint)(l)*(n))
|
---|
583 | #endif
|
---|
584 |
|
---|
585 | #else
|
---|
586 |
|
---|
587 | #define BZERO8_PTR(s,l,n) \
|
---|
588 | lzo_memset((lzo_voidp)(s),0,(lzo_uint)(l)*(n))
|
---|
589 |
|
---|
590 | #endif
|
---|
591 |
|
---|
592 | #if 0
|
---|
593 | #if defined(__GNUC__) && defined(__i386__)
|
---|
594 |
|
---|
595 | unsigned char lzo_rotr8(unsigned char value, int shift);
|
---|
596 | extern __inline__ unsigned char lzo_rotr8(unsigned char value, int shift)
|
---|
597 | {
|
---|
598 | unsigned char result;
|
---|
599 |
|
---|
600 | __asm__ __volatile__ ("movb %b1, %b0; rorb %b2, %b0"
|
---|
601 | : "=a"(result) : "g"(value), "c"(shift));
|
---|
602 | return result;
|
---|
603 | }
|
---|
604 |
|
---|
605 | unsigned short lzo_rotr16(unsigned short value, int shift);
|
---|
606 | extern __inline__ unsigned short lzo_rotr16(unsigned short value, int shift)
|
---|
607 | {
|
---|
608 | unsigned short result;
|
---|
609 |
|
---|
610 | __asm__ __volatile__ ("movw %b1, %b0; rorw %b2, %b0"
|
---|
611 | : "=a"(result) : "g"(value), "c"(shift));
|
---|
612 | return result;
|
---|
613 | }
|
---|
614 |
|
---|
615 | #endif
|
---|
616 | #endif
|
---|
617 |
|
---|
618 | #ifdef __cplusplus
|
---|
619 | }
|
---|
620 | #endif
|
---|
621 |
|
---|
622 | #endif
|
---|
623 |
|
---|
624 | LZO_PUBLIC(lzo_bool)
|
---|
625 | lzo_assert(int expr)
|
---|
626 | {
|
---|
627 | return (expr) ? 1 : 0;
|
---|
628 | }
|
---|
629 |
|
---|
630 | /* If you use the LZO library in a product, you *must* keep this
|
---|
631 | * copyright string in the executable of your product.
|
---|
632 | */
|
---|
633 |
|
---|
634 | const lzo_byte __lzo_copyright[] =
|
---|
635 | #if !defined(__LZO_IN_MINLZO)
|
---|
636 | LZO_VERSION_STRING;
|
---|
637 | #else
|
---|
638 | "\n\n\n"
|
---|
639 | "LZO real-time data compression library.\n"
|
---|
640 | "Copyright (C) 1996, 1997, 1998, 1999 Markus Franz Xaver Johannes Oberhumer\n"
|
---|
641 | "<markus.oberhumer@jk.uni-linz.ac.at>\n"
|
---|
642 | "http://wildsau.idv.uni-linz.ac.at/mfx/lzo.html\n"
|
---|
643 | "\n"
|
---|
644 | "LZO version: v" LZO_VERSION_STRING ", " LZO_VERSION_DATE "\n"
|
---|
645 | "LZO build date: " __DATE__ " " __TIME__ "\n\n"
|
---|
646 | "LZO special compilation options:\n"
|
---|
647 | #ifdef __cplusplus
|
---|
648 | " __cplusplus\n"
|
---|
649 | #endif
|
---|
650 | #if defined(__PIC__)
|
---|
651 | " __PIC__\n"
|
---|
652 | #elif defined(__pic__)
|
---|
653 | " __pic__\n"
|
---|
654 | #endif
|
---|
655 | #if (UINT_MAX < LZO_0xffffffffL)
|
---|
656 | " 16BIT\n"
|
---|
657 | #endif
|
---|
658 | #if defined(__LZO_STRICT_16BIT)
|
---|
659 | " __LZO_STRICT_16BIT\n"
|
---|
660 | #endif
|
---|
661 | #if (UINT_MAX > LZO_0xffffffffL)
|
---|
662 | " UINT_MAX=" _LZO_MEXPAND(UINT_MAX) "\n"
|
---|
663 | #endif
|
---|
664 | #if (ULONG_MAX > LZO_0xffffffffL)
|
---|
665 | " ULONG_MAX=" _LZO_MEXPAND(ULONG_MAX) "\n"
|
---|
666 | #endif
|
---|
667 | #if defined(LZO_BYTE_ORDER)
|
---|
668 | " LZO_BYTE_ORDER=" _LZO_MEXPAND(LZO_BYTE_ORDER) "\n"
|
---|
669 | #endif
|
---|
670 | #if defined(LZO_UNALIGNED_OK_2)
|
---|
671 | " LZO_UNALIGNED_OK_2\n"
|
---|
672 | #endif
|
---|
673 | #if defined(LZO_UNALIGNED_OK_4)
|
---|
674 | " LZO_UNALIGNED_OK_4\n"
|
---|
675 | #endif
|
---|
676 | #if defined(LZO_ALIGNED_OK_4)
|
---|
677 | " LZO_ALIGNED_OK_4\n"
|
---|
678 | #endif
|
---|
679 | #if defined(LZO_DICT_USE_PTR)
|
---|
680 | " LZO_DICT_USE_PTR\n"
|
---|
681 | #endif
|
---|
682 | #if defined(__LZO_QUERY_COMPRESS)
|
---|
683 | " __LZO_QUERY_COMPRESS\n"
|
---|
684 | #endif
|
---|
685 | #if defined(__LZO_QUERY_DECOMPRESS)
|
---|
686 | " __LZO_QUERY_DECOMPRESS\n"
|
---|
687 | #endif
|
---|
688 | #if defined(__LZO_IN_MINILZO)
|
---|
689 | " __LZO_IN_MINILZO\n"
|
---|
690 | #endif
|
---|
691 | "\n\n"
|
---|
692 | "$Id: LZO " LZO_VERSION_STRING " built " __DATE__ " " __TIME__
|
---|
693 | #if defined(__GNUC__) && defined(__VERSION__)
|
---|
694 | " by gcc " __VERSION__
|
---|
695 | #elif defined(__BORLANDC__)
|
---|
696 | " by Borland C " _LZO_MEXPAND(__BORLANDC__)
|
---|
697 | #elif defined(_MSC_VER)
|
---|
698 | " by Microsoft C " _LZO_MEXPAND(_MSC_VER)
|
---|
699 | #elif defined(__PUREC__)
|
---|
700 | " by Pure C " _LZO_MEXPAND(__PUREC__)
|
---|
701 | #elif defined(__SC__)
|
---|
702 | " by Symantec C " _LZO_MEXPAND(__SC__)
|
---|
703 | #elif defined(__TURBOC__)
|
---|
704 | " by Turbo C " _LZO_MEXPAND(__TURBOC__)
|
---|
705 | #elif defined(__WATCOMC__)
|
---|
706 | " by Watcom C " _LZO_MEXPAND(__WATCOMC__)
|
---|
707 | #endif
|
---|
708 | " $\n"
|
---|
709 | "$Copyright: LZO (C) 1996, 1997, 1998, 1999 Markus Franz Xaver Johannes Oberhumer $\n";
|
---|
710 | #endif
|
---|
711 |
|
---|
712 | LZO_PUBLIC(const lzo_byte *)
|
---|
713 | lzo_copyright(void)
|
---|
714 | {
|
---|
715 | return __lzo_copyright;
|
---|
716 | }
|
---|
717 |
|
---|
718 | LZO_PUBLIC(unsigned)
|
---|
719 | lzo_version(void)
|
---|
720 | {
|
---|
721 | return LZO_VERSION;
|
---|
722 | }
|
---|
723 |
|
---|
724 | LZO_PUBLIC(const char *)
|
---|
725 | lzo_version_string(void)
|
---|
726 | {
|
---|
727 | return LZO_VERSION_STRING;
|
---|
728 | }
|
---|
729 |
|
---|
730 | LZO_PUBLIC(const char *)
|
---|
731 | lzo_version_date(void)
|
---|
732 | {
|
---|
733 | return LZO_VERSION_DATE;
|
---|
734 | }
|
---|
735 |
|
---|
736 | LZO_PUBLIC(const lzo_charp)
|
---|
737 | _lzo_version_string(void)
|
---|
738 | {
|
---|
739 | return LZO_VERSION_STRING;
|
---|
740 | }
|
---|
741 |
|
---|
742 | LZO_PUBLIC(const lzo_charp)
|
---|
743 | _lzo_version_date(void)
|
---|
744 | {
|
---|
745 | return LZO_VERSION_DATE;
|
---|
746 | }
|
---|
747 |
|
---|
748 | #define LZO_BASE 65521u
|
---|
749 | #define LZO_NMAX 5552
|
---|
750 |
|
---|
751 | #define LZO_DO1(buf,i) {s1 += buf[i]; s2 += s1;}
|
---|
752 | #define LZO_DO2(buf,i) LZO_DO1(buf,i); LZO_DO1(buf,i+1);
|
---|
753 | #define LZO_DO4(buf,i) LZO_DO2(buf,i); LZO_DO2(buf,i+2);
|
---|
754 | #define LZO_DO8(buf,i) LZO_DO4(buf,i); LZO_DO4(buf,i+4);
|
---|
755 | #define LZO_DO16(buf,i) LZO_DO8(buf,i); LZO_DO8(buf,i+8);
|
---|
756 |
|
---|
757 | LZO_PUBLIC(lzo_uint32)
|
---|
758 | lzo_adler32(lzo_uint32 adler, const lzo_byte *buf, lzo_uint len)
|
---|
759 | {
|
---|
760 | lzo_uint32 s1 = adler & 0xffff;
|
---|
761 | lzo_uint32 s2 = (adler >> 16) & 0xffff;
|
---|
762 | int k;
|
---|
763 |
|
---|
764 | if (buf == NULL)
|
---|
765 | return 1;
|
---|
766 |
|
---|
767 | while (len > 0)
|
---|
768 | {
|
---|
769 | k = len < LZO_NMAX ? (int) len : LZO_NMAX;
|
---|
770 | len -= k;
|
---|
771 | if (k >= 16) do
|
---|
772 | {
|
---|
773 | LZO_DO16(buf,0);
|
---|
774 | buf += 16;
|
---|
775 | k -= 16;
|
---|
776 | } while (k >= 16);
|
---|
777 | if (k != 0) do
|
---|
778 | {
|
---|
779 | s1 += *buf++;
|
---|
780 | s2 += s1;
|
---|
781 | } while (--k > 0);
|
---|
782 | s1 %= LZO_BASE;
|
---|
783 | s2 %= LZO_BASE;
|
---|
784 | }
|
---|
785 | return (s2 << 16) | s1;
|
---|
786 | }
|
---|
787 |
|
---|
788 | LZO_PUBLIC(int)
|
---|
789 | lzo_memcmp(const lzo_voidp s1, const lzo_voidp s2, lzo_uint len)
|
---|
790 | {
|
---|
791 | #if (LZO_UINT_MAX <= SIZE_T_MAX) && defined(HAVE_MEMCMP)
|
---|
792 | return memcmp(s1,s2,len);
|
---|
793 | #else
|
---|
794 | const lzo_byte *p1 = (const lzo_byte *) s1;
|
---|
795 | const lzo_byte *p2 = (const lzo_byte *) s2;
|
---|
796 | int d;
|
---|
797 |
|
---|
798 | if (len > 0) do
|
---|
799 | {
|
---|
800 | d = *p1 - *p2;
|
---|
801 | if (d != 0)
|
---|
802 | return d;
|
---|
803 | p1++;
|
---|
804 | p2++;
|
---|
805 | }
|
---|
806 | while (--len > 0);
|
---|
807 | return 0;
|
---|
808 | #endif
|
---|
809 | }
|
---|
810 |
|
---|
811 | LZO_PUBLIC(lzo_voidp)
|
---|
812 | lzo_memcpy(lzo_voidp dest, const lzo_voidp src, lzo_uint len)
|
---|
813 | {
|
---|
814 | #if (LZO_UINT_MAX <= SIZE_T_MAX) && defined(HAVE_MEMCPY)
|
---|
815 | return memcpy(dest,src,len);
|
---|
816 | #else
|
---|
817 | lzo_byte *p1 = (lzo_byte *) dest;
|
---|
818 | const lzo_byte *p2 = (const lzo_byte *) src;
|
---|
819 |
|
---|
820 | if (len <= 0 || p1 == p2)
|
---|
821 | return dest;
|
---|
822 | do
|
---|
823 | *p1++ = *p2++;
|
---|
824 | while (--len > 0);
|
---|
825 | return dest;
|
---|
826 | #endif
|
---|
827 | }
|
---|
828 |
|
---|
829 | LZO_PUBLIC(lzo_voidp)
|
---|
830 | lzo_memmove(lzo_voidp dest, const lzo_voidp src, lzo_uint len)
|
---|
831 | {
|
---|
832 | #if (LZO_UINT_MAX <= SIZE_T_MAX) && defined(HAVE_MEMMOVE)
|
---|
833 | return memmove(dest,src,len);
|
---|
834 | #else
|
---|
835 | lzo_byte *p1 = (lzo_byte *) dest;
|
---|
836 | const lzo_byte *p2 = (const lzo_byte *) src;
|
---|
837 |
|
---|
838 | if (len <= 0 || p1 == p2)
|
---|
839 | return dest;
|
---|
840 |
|
---|
841 | if (p1 < p2)
|
---|
842 | {
|
---|
843 | do
|
---|
844 | *p1++ = *p2++;
|
---|
845 | while (--len > 0);
|
---|
846 | }
|
---|
847 | else
|
---|
848 | {
|
---|
849 | p1 += len;
|
---|
850 | p2 += len;
|
---|
851 | do
|
---|
852 | *--p1 = *--p2;
|
---|
853 | while (--len > 0);
|
---|
854 | }
|
---|
855 | return dest;
|
---|
856 | #endif
|
---|
857 | }
|
---|
858 |
|
---|
859 | LZO_PUBLIC(lzo_voidp)
|
---|
860 | lzo_memset(lzo_voidp s, int c, lzo_uint len)
|
---|
861 | {
|
---|
862 | #if (LZO_UINT_MAX <= SIZE_T_MAX) && defined(HAVE_MEMSET)
|
---|
863 | return memset(s,c,len);
|
---|
864 | #else
|
---|
865 | lzo_byte *p = (lzo_byte *) s;
|
---|
866 |
|
---|
867 | if (len > 0) do
|
---|
868 | *p++ = LZO_BYTE(c);
|
---|
869 | while (--len > 0);
|
---|
870 | return s;
|
---|
871 | #endif
|
---|
872 | }
|
---|
873 |
|
---|
874 | #include <stdio.h>
|
---|
875 |
|
---|
876 | #if 0
|
---|
877 | # define IS_SIGNED(type) (((type) (1ul << (8 * sizeof(type) - 1))) < 0)
|
---|
878 | # define IS_UNSIGNED(type) (((type) (1ul << (8 * sizeof(type) - 1))) > 0)
|
---|
879 | #else
|
---|
880 | # define IS_SIGNED(type) (((type) (-1)) < ((type) 0))
|
---|
881 | # define IS_UNSIGNED(type) (((type) (-1)) > ((type) 0))
|
---|
882 | #endif
|
---|
883 |
|
---|
884 | static lzo_bool schedule_insns_bug(void);
|
---|
885 | static lzo_bool strength_reduce_bug(int *);
|
---|
886 |
|
---|
887 | #if 0 || defined(LZO_DEBUG)
|
---|
888 | static lzo_bool __lzo_assert_fail(const char *s, unsigned line)
|
---|
889 | {
|
---|
890 | #if defined(__palmos__)
|
---|
891 | printf("LZO assertion failed in line %u: '%s'\n",line,s);
|
---|
892 | #else
|
---|
893 | fprintf(stderr,"LZO assertion failed in line %u: '%s'\n",line,s);
|
---|
894 | #endif
|
---|
895 | return 0;
|
---|
896 | }
|
---|
897 | # define __lzo_assert(x) ((x) ? 1 : __lzo_assert_fail(#x,__LINE__))
|
---|
898 | #else
|
---|
899 | # define __lzo_assert(x) ((x) ? 1 : 0)
|
---|
900 | #endif
|
---|
901 |
|
---|
902 | static lzo_bool basic_integral_check(void)
|
---|
903 | {
|
---|
904 | lzo_bool r = 1;
|
---|
905 | lzo_bool sanity;
|
---|
906 |
|
---|
907 | r &= __lzo_assert(CHAR_BIT == 8);
|
---|
908 | r &= __lzo_assert(sizeof(char) == 1);
|
---|
909 | r &= __lzo_assert(sizeof(short) >= 2);
|
---|
910 | r &= __lzo_assert(sizeof(long) >= 4);
|
---|
911 | r &= __lzo_assert(sizeof(int) >= sizeof(short));
|
---|
912 | r &= __lzo_assert(sizeof(long) >= sizeof(int));
|
---|
913 |
|
---|
914 | r &= __lzo_assert(sizeof(lzo_uint32) >= 4);
|
---|
915 | r &= __lzo_assert(sizeof(lzo_uint32) >= sizeof(unsigned));
|
---|
916 | #if defined(__LZO_STRICT_16BIT)
|
---|
917 | r &= __lzo_assert(sizeof(lzo_uint) == 2);
|
---|
918 | #else
|
---|
919 | r &= __lzo_assert(sizeof(lzo_uint) >= 4);
|
---|
920 | r &= __lzo_assert(sizeof(lzo_uint) >= sizeof(unsigned));
|
---|
921 | #endif
|
---|
922 |
|
---|
923 | #if defined(SIZEOF_UNSIGNED)
|
---|
924 | r &= __lzo_assert(SIZEOF_UNSIGNED == sizeof(unsigned));
|
---|
925 | #endif
|
---|
926 | #if defined(SIZEOF_UNSIGNED_LONG)
|
---|
927 | r &= __lzo_assert(SIZEOF_UNSIGNED_LONG == sizeof(unsigned long));
|
---|
928 | #endif
|
---|
929 | #if defined(SIZEOF_UNSIGNED_SHORT)
|
---|
930 | r &= __lzo_assert(SIZEOF_UNSIGNED_SHORT == sizeof(unsigned short));
|
---|
931 | #endif
|
---|
932 | #if !defined(__LZO_IN_MINILZO)
|
---|
933 | #if defined(SIZEOF_SIZE_T)
|
---|
934 | r &= __lzo_assert(SIZEOF_SIZE_T == sizeof(size_t));
|
---|
935 | #endif
|
---|
936 | #endif
|
---|
937 |
|
---|
938 | sanity = IS_UNSIGNED(unsigned short) && IS_UNSIGNED(unsigned) &&
|
---|
939 | IS_UNSIGNED(unsigned long) &&
|
---|
940 | IS_SIGNED(short) && IS_SIGNED(int) && IS_SIGNED(long);
|
---|
941 | if (sanity)
|
---|
942 | {
|
---|
943 | r &= __lzo_assert(IS_UNSIGNED(lzo_uint32));
|
---|
944 | r &= __lzo_assert(IS_UNSIGNED(lzo_uint));
|
---|
945 | r &= __lzo_assert(IS_SIGNED(lzo_int32));
|
---|
946 | r &= __lzo_assert(IS_SIGNED(lzo_int));
|
---|
947 |
|
---|
948 | r &= __lzo_assert(INT_MAX == LZO_STYPE_MAX(sizeof(int)));
|
---|
949 | r &= __lzo_assert(UINT_MAX == LZO_UTYPE_MAX(sizeof(unsigned)));
|
---|
950 | r &= __lzo_assert(LONG_MAX == LZO_STYPE_MAX(sizeof(long)));
|
---|
951 | r &= __lzo_assert(ULONG_MAX == LZO_UTYPE_MAX(sizeof(unsigned long)));
|
---|
952 | r &= __lzo_assert(SHRT_MAX == LZO_STYPE_MAX(sizeof(short)));
|
---|
953 | r &= __lzo_assert(USHRT_MAX == LZO_UTYPE_MAX(sizeof(unsigned short)));
|
---|
954 | r &= __lzo_assert(LZO_UINT32_MAX == LZO_UTYPE_MAX(sizeof(lzo_uint32)));
|
---|
955 | r &= __lzo_assert(LZO_UINT_MAX == LZO_UTYPE_MAX(sizeof(lzo_uint)));
|
---|
956 | #if !defined(__LZO_IN_MINILZO)
|
---|
957 | r &= __lzo_assert(SIZE_T_MAX == LZO_UTYPE_MAX(sizeof(size_t)));
|
---|
958 | #endif
|
---|
959 | }
|
---|
960 |
|
---|
961 | #if 0
|
---|
962 | r &= __lzo_assert(LZO_BYTE(257) == 1);
|
---|
963 | r &= __lzo_assert(LZO_USHORT(65537L) == 1);
|
---|
964 | #endif
|
---|
965 |
|
---|
966 | return r;
|
---|
967 | }
|
---|
968 |
|
---|
969 | static lzo_bool basic_ptr_check(void)
|
---|
970 | {
|
---|
971 | lzo_bool r = 1;
|
---|
972 | lzo_bool sanity;
|
---|
973 |
|
---|
974 | r &= __lzo_assert(sizeof(char *) >= sizeof(int));
|
---|
975 | r &= __lzo_assert(sizeof(lzo_byte *) >= sizeof(char *));
|
---|
976 |
|
---|
977 | r &= __lzo_assert(sizeof(lzo_voidp) == sizeof(lzo_byte *));
|
---|
978 | r &= __lzo_assert(sizeof(lzo_voidp) == sizeof(lzo_voidpp));
|
---|
979 | r &= __lzo_assert(sizeof(lzo_voidp) == sizeof(lzo_bytepp));
|
---|
980 | r &= __lzo_assert(sizeof(lzo_voidp) >= sizeof(lzo_uint));
|
---|
981 |
|
---|
982 | r &= __lzo_assert(sizeof(lzo_ptr_t) == sizeof(lzo_voidp));
|
---|
983 | r &= __lzo_assert(sizeof(lzo_ptr_t) >= sizeof(lzo_uint));
|
---|
984 |
|
---|
985 | r &= __lzo_assert(sizeof(lzo_ptrdiff_t) >= 4);
|
---|
986 | r &= __lzo_assert(sizeof(lzo_ptrdiff_t) >= sizeof(ptrdiff_t));
|
---|
987 |
|
---|
988 | #if defined(SIZEOF_CHAR_P)
|
---|
989 | r &= __lzo_assert(SIZEOF_CHAR_P == sizeof(char *));
|
---|
990 | #endif
|
---|
991 | #if defined(SIZEOF_PTRDIFF_T)
|
---|
992 | r &= __lzo_assert(SIZEOF_PTRDIFF_T == sizeof(ptrdiff_t));
|
---|
993 | #endif
|
---|
994 |
|
---|
995 | sanity = IS_UNSIGNED(unsigned short) && IS_UNSIGNED(unsigned) &&
|
---|
996 | IS_UNSIGNED(unsigned long) &&
|
---|
997 | IS_SIGNED(short) && IS_SIGNED(int) && IS_SIGNED(long);
|
---|
998 | if (sanity)
|
---|
999 | {
|
---|
1000 | r &= __lzo_assert(IS_UNSIGNED(lzo_ptr_t));
|
---|
1001 | r &= __lzo_assert(IS_UNSIGNED(lzo_moff_t));
|
---|
1002 | r &= __lzo_assert(IS_SIGNED(lzo_ptrdiff_t));
|
---|
1003 | r &= __lzo_assert(IS_SIGNED(lzo_sptr_t));
|
---|
1004 | }
|
---|
1005 |
|
---|
1006 | return r;
|
---|
1007 | }
|
---|
1008 |
|
---|
1009 | static lzo_bool ptr_check(void)
|
---|
1010 | {
|
---|
1011 | lzo_bool r = 1;
|
---|
1012 | int i;
|
---|
1013 | char _wrkmem[10 * sizeof(lzo_byte *) + sizeof(lzo_align_t)];
|
---|
1014 | lzo_byte *wrkmem;
|
---|
1015 | const lzo_bytepp dict;
|
---|
1016 | unsigned char x[4 * sizeof(lzo_align_t)];
|
---|
1017 | long d;
|
---|
1018 | lzo_align_t a;
|
---|
1019 |
|
---|
1020 | for (i = 0; i < (int) sizeof(x); i++)
|
---|
1021 | x[i] = LZO_BYTE(i);
|
---|
1022 |
|
---|
1023 | wrkmem = (lzo_byte *) LZO_PTR_ALIGN_UP(_wrkmem,sizeof(lzo_align_t));
|
---|
1024 | dict = (const lzo_bytepp) wrkmem;
|
---|
1025 |
|
---|
1026 | d = (long) ((const lzo_bytep) dict - (const lzo_bytep) _wrkmem);
|
---|
1027 | r &= __lzo_assert(d >= 0);
|
---|
1028 | r &= __lzo_assert(d < (long) sizeof(lzo_align_t));
|
---|
1029 |
|
---|
1030 | memset(&a,0xff,sizeof(a));
|
---|
1031 | r &= __lzo_assert(a.a_ushort == USHRT_MAX);
|
---|
1032 | r &= __lzo_assert(a.a_uint == UINT_MAX);
|
---|
1033 | r &= __lzo_assert(a.a_ulong == ULONG_MAX);
|
---|
1034 | r &= __lzo_assert(a.a_lzo_uint == LZO_UINT_MAX);
|
---|
1035 |
|
---|
1036 | if (r == 1)
|
---|
1037 | {
|
---|
1038 | for (i = 0; i < 8; i++)
|
---|
1039 | r &= __lzo_assert((const lzo_voidp) (&dict[i]) == (const lzo_voidp) (&wrkmem[i * sizeof(lzo_byte *)]));
|
---|
1040 | }
|
---|
1041 |
|
---|
1042 | memset(&a,0,sizeof(a));
|
---|
1043 | r &= __lzo_assert(a.a_charp == NULL);
|
---|
1044 | r &= __lzo_assert(a.a_lzo_bytep == NULL);
|
---|
1045 | r &= __lzo_assert(NULL == 0);
|
---|
1046 | if (r == 1)
|
---|
1047 | {
|
---|
1048 | for (i = 0; i < 10; i++)
|
---|
1049 | dict[i] = wrkmem;
|
---|
1050 | BZERO8_PTR(dict+1,sizeof(dict[0]),8);
|
---|
1051 | r &= __lzo_assert(dict[0] == wrkmem);
|
---|
1052 | for (i = 1; i < 9; i++)
|
---|
1053 | r &= __lzo_assert(dict[i] == NULL);
|
---|
1054 | r &= __lzo_assert(dict[9] == wrkmem);
|
---|
1055 | }
|
---|
1056 |
|
---|
1057 | if (r == 1)
|
---|
1058 | {
|
---|
1059 | unsigned k = 1;
|
---|
1060 | const unsigned n = (unsigned) sizeof(lzo_uint32);
|
---|
1061 | lzo_byte *p0;
|
---|
1062 | lzo_byte *p1;
|
---|
1063 |
|
---|
1064 | k += __lzo_align_gap(&x[k],n);
|
---|
1065 | p0 = (lzo_bytep) &x[k];
|
---|
1066 | #if defined(PTR_LINEAR)
|
---|
1067 | r &= __lzo_assert((PTR_LINEAR(p0) & (n-1)) == 0);
|
---|
1068 | #else
|
---|
1069 | r &= __lzo_assert(n == 4);
|
---|
1070 | r &= __lzo_assert(PTR_ALIGNED_4(p0));
|
---|
1071 | #endif
|
---|
1072 |
|
---|
1073 | r &= __lzo_assert(k >= 1);
|
---|
1074 | p1 = (lzo_bytep) &x[1];
|
---|
1075 | r &= __lzo_assert(PTR_GE(p0,p1));
|
---|
1076 |
|
---|
1077 | r &= __lzo_assert(k < 1+n);
|
---|
1078 | p1 = (lzo_bytep) &x[1+n];
|
---|
1079 | r &= __lzo_assert(PTR_LT(p0,p1));
|
---|
1080 |
|
---|
1081 | if (r == 1)
|
---|
1082 | {
|
---|
1083 | lzo_uint32 v0 = * (lzo_uint32 *) &x[k];
|
---|
1084 | lzo_uint32 v1 = * (lzo_uint32 *) &x[k+n];
|
---|
1085 |
|
---|
1086 | r &= __lzo_assert(v0 > 0);
|
---|
1087 | r &= __lzo_assert(v1 > 0);
|
---|
1088 | }
|
---|
1089 | }
|
---|
1090 |
|
---|
1091 | return r;
|
---|
1092 | }
|
---|
1093 |
|
---|
1094 | LZO_PUBLIC(int)
|
---|
1095 | _lzo_config_check(void)
|
---|
1096 | {
|
---|
1097 | lzo_bool r = 1;
|
---|
1098 | int i;
|
---|
1099 | union {
|
---|
1100 | lzo_uint32 a;
|
---|
1101 | unsigned short b;
|
---|
1102 | lzo_uint32 aa[4];
|
---|
1103 | unsigned char x[4*sizeof(lzo_align_t)];
|
---|
1104 | } u;
|
---|
1105 |
|
---|
1106 | #if 0
|
---|
1107 | r &= __lzo_assert((const void *)&u == (const void *)&u.a);
|
---|
1108 | r &= __lzo_assert((const void *)&u == (const void *)&u.b);
|
---|
1109 | r &= __lzo_assert((const void *)&u == (const void *)&u.x[0]);
|
---|
1110 | r &= __lzo_assert((const void *)&u == (const void *)&u.aa[0]);
|
---|
1111 | #endif
|
---|
1112 |
|
---|
1113 | r &= basic_integral_check();
|
---|
1114 | r &= basic_ptr_check();
|
---|
1115 | if (r != 1)
|
---|
1116 | return LZO_E_ERROR;
|
---|
1117 |
|
---|
1118 | for (i = 0; i < (int) sizeof(u.x); i++)
|
---|
1119 | u.x[i] = LZO_BYTE(i);
|
---|
1120 |
|
---|
1121 | #if 0
|
---|
1122 | r &= __lzo_assert( (int) (unsigned char) ((char) -1) == 255);
|
---|
1123 | #endif
|
---|
1124 |
|
---|
1125 | #if defined(LZO_BYTE_ORDER)
|
---|
1126 | if (r == 1)
|
---|
1127 | {
|
---|
1128 | # if (LZO_BYTE_ORDER == LZO_LITTLE_ENDIAN)
|
---|
1129 | lzo_uint32 a = (lzo_uint32) (u.a & LZO_0xffffffffL);
|
---|
1130 | unsigned short b = (unsigned short) (u.b & 0xffff);
|
---|
1131 | r &= __lzo_assert(a == 0x03020100L);
|
---|
1132 | r &= __lzo_assert(b == 0x0100);
|
---|
1133 | # elif (LZO_BYTE_ORDER == LZO_BIG_ENDIAN)
|
---|
1134 | lzo_uint32 a = u.a >> (8 * sizeof(u.a) - 32);
|
---|
1135 | unsigned short b = u.b >> (8 * sizeof(u.b) - 16);
|
---|
1136 | r &= __lzo_assert(a == 0x00010203L);
|
---|
1137 | r &= __lzo_assert(b == 0x0001);
|
---|
1138 | # else
|
---|
1139 | # error invalid LZO_BYTE_ORDER
|
---|
1140 | # endif
|
---|
1141 | }
|
---|
1142 | #endif
|
---|
1143 |
|
---|
1144 | #if defined(LZO_UNALIGNED_OK_2)
|
---|
1145 | r &= __lzo_assert(sizeof(short) == 2);
|
---|
1146 | if (r == 1)
|
---|
1147 | {
|
---|
1148 | unsigned short b[4];
|
---|
1149 |
|
---|
1150 | for (i = 0; i < 4; i++)
|
---|
1151 | b[i] = * (const unsigned short *) &u.x[i];
|
---|
1152 |
|
---|
1153 | # if (LZO_BYTE_ORDER == LZO_LITTLE_ENDIAN)
|
---|
1154 | r &= __lzo_assert(b[0] == 0x0100);
|
---|
1155 | r &= __lzo_assert(b[1] == 0x0201);
|
---|
1156 | r &= __lzo_assert(b[2] == 0x0302);
|
---|
1157 | r &= __lzo_assert(b[3] == 0x0403);
|
---|
1158 | # elif (LZO_BYTE_ORDER == LZO_BIG_ENDIAN)
|
---|
1159 | r &= __lzo_assert(b[0] == 0x0001);
|
---|
1160 | r &= __lzo_assert(b[1] == 0x0102);
|
---|
1161 | r &= __lzo_assert(b[2] == 0x0203);
|
---|
1162 | r &= __lzo_assert(b[3] == 0x0304);
|
---|
1163 | # endif
|
---|
1164 | }
|
---|
1165 | #endif
|
---|
1166 |
|
---|
1167 | #if defined(LZO_UNALIGNED_OK_4)
|
---|
1168 | r &= __lzo_assert(sizeof(lzo_uint32) == 4);
|
---|
1169 | if (r == 1)
|
---|
1170 | {
|
---|
1171 | lzo_uint32 a[4];
|
---|
1172 |
|
---|
1173 | for (i = 0; i < 4; i++)
|
---|
1174 | a[i] = * (const lzo_uint32 *) &u.x[i];
|
---|
1175 |
|
---|
1176 | # if (LZO_BYTE_ORDER == LZO_LITTLE_ENDIAN)
|
---|
1177 | r &= __lzo_assert(a[0] == 0x03020100L);
|
---|
1178 | r &= __lzo_assert(a[1] == 0x04030201L);
|
---|
1179 | r &= __lzo_assert(a[2] == 0x05040302L);
|
---|
1180 | r &= __lzo_assert(a[3] == 0x06050403L);
|
---|
1181 | # elif (LZO_BYTE_ORDER == LZO_BIG_ENDIAN)
|
---|
1182 | r &= __lzo_assert(a[0] == 0x00010203L);
|
---|
1183 | r &= __lzo_assert(a[1] == 0x01020304L);
|
---|
1184 | r &= __lzo_assert(a[2] == 0x02030405L);
|
---|
1185 | r &= __lzo_assert(a[3] == 0x03040506L);
|
---|
1186 | # endif
|
---|
1187 | }
|
---|
1188 | #endif
|
---|
1189 |
|
---|
1190 | #if defined(LZO_ALIGNED_OK_4)
|
---|
1191 | r &= __lzo_assert(sizeof(lzo_uint32) == 4);
|
---|
1192 | #endif
|
---|
1193 |
|
---|
1194 | r &= __lzo_assert(lzo_sizeof_dict_t == sizeof(lzo_dict_t));
|
---|
1195 |
|
---|
1196 | #if defined(__LZO_IN_MINLZO)
|
---|
1197 | if (r == 1)
|
---|
1198 | {
|
---|
1199 | lzo_uint32 adler;
|
---|
1200 | adler = lzo_adler32(0, NULL, 0);
|
---|
1201 | adler = lzo_adler32(adler, lzo_copyright(), 200);
|
---|
1202 | r &= __lzo_assert(adler == 0x7ea34377L);
|
---|
1203 | }
|
---|
1204 | #endif
|
---|
1205 |
|
---|
1206 | if (r == 1)
|
---|
1207 | {
|
---|
1208 | r &= __lzo_assert(!schedule_insns_bug());
|
---|
1209 | }
|
---|
1210 |
|
---|
1211 | if (r == 1)
|
---|
1212 | {
|
---|
1213 | static int x[3];
|
---|
1214 | static unsigned xn = 3;
|
---|
1215 | register unsigned j;
|
---|
1216 |
|
---|
1217 | for (j = 0; j < xn; j++)
|
---|
1218 | x[j] = (int)j - 3;
|
---|
1219 | r &= __lzo_assert(!strength_reduce_bug(x));
|
---|
1220 | }
|
---|
1221 |
|
---|
1222 | if (r == 1)
|
---|
1223 | {
|
---|
1224 | r &= ptr_check();
|
---|
1225 | }
|
---|
1226 |
|
---|
1227 | return r == 1 ? LZO_E_OK : LZO_E_ERROR;
|
---|
1228 | }
|
---|
1229 |
|
---|
1230 | static lzo_bool schedule_insns_bug(void)
|
---|
1231 | {
|
---|
1232 | #if defined(__BOUNDS_CHECKING_ON) || defined(__CHECKER__)
|
---|
1233 | return 0;
|
---|
1234 | #else
|
---|
1235 | const int clone[] = {1, 2, 0};
|
---|
1236 | const int *q;
|
---|
1237 | q = clone;
|
---|
1238 | return (*q) ? 0 : 1;
|
---|
1239 | #endif
|
---|
1240 | }
|
---|
1241 |
|
---|
1242 | static lzo_bool strength_reduce_bug(int *x)
|
---|
1243 | {
|
---|
1244 | return x[0] != -3 || x[1] != -2 || x[2] != -1;
|
---|
1245 | }
|
---|
1246 |
|
---|
1247 | int __lzo_init_done = 0;
|
---|
1248 |
|
---|
1249 | LZO_PUBLIC(int)
|
---|
1250 | __lzo_init2(unsigned v, int s1, int s2, int s3, int s4, int s5,
|
---|
1251 | int s6, int s7, int s8, int s9)
|
---|
1252 | {
|
---|
1253 | int r;
|
---|
1254 |
|
---|
1255 | __lzo_init_done = 1;
|
---|
1256 |
|
---|
1257 | if (v == 0)
|
---|
1258 | return LZO_E_ERROR;
|
---|
1259 |
|
---|
1260 | r = (s1 == -1 || s1 == (int) sizeof(short)) &&
|
---|
1261 | (s2 == -1 || s2 == (int) sizeof(int)) &&
|
---|
1262 | (s3 == -1 || s3 == (int) sizeof(long)) &&
|
---|
1263 | (s4 == -1 || s4 == (int) sizeof(lzo_uint32)) &&
|
---|
1264 | (s5 == -1 || s5 == (int) sizeof(lzo_uint)) &&
|
---|
1265 | (s6 == -1 || s6 == (int) lzo_sizeof_dict_t) &&
|
---|
1266 | (s7 == -1 || s7 == (int) sizeof(char *)) &&
|
---|
1267 | (s8 == -1 || s8 == (int) sizeof(lzo_voidp)) &&
|
---|
1268 | (s9 == -1 || s9 == (int) sizeof(lzo_compress_t));
|
---|
1269 | if (!r)
|
---|
1270 | return LZO_E_ERROR;
|
---|
1271 |
|
---|
1272 | r = _lzo_config_check();
|
---|
1273 | if (r != LZO_E_OK)
|
---|
1274 | return r;
|
---|
1275 |
|
---|
1276 | return r;
|
---|
1277 | }
|
---|
1278 |
|
---|
1279 | #if !defined(__LZO_IN_MINILZO)
|
---|
1280 |
|
---|
1281 | LZO_EXTERN(int)
|
---|
1282 | __lzo_init(unsigned v,int s1,int s2,int s3,int s4,int s5,int s6,int s7);
|
---|
1283 |
|
---|
1284 | LZO_PUBLIC(int)
|
---|
1285 | __lzo_init(unsigned v,int s1,int s2,int s3,int s4,int s5,int s6,int s7)
|
---|
1286 | {
|
---|
1287 | if (v == 0 || v > 0x1010)
|
---|
1288 | return LZO_E_ERROR;
|
---|
1289 | return __lzo_init2(v,s1,s2,s3,s4,s5,-1,-1,s6,s7);
|
---|
1290 | }
|
---|
1291 |
|
---|
1292 | #endif
|
---|
1293 |
|
---|
1294 | #define do_compress _lzo1x_1_do_compress
|
---|
1295 |
|
---|
1296 | #define LZO_NEED_DICT_H
|
---|
1297 | #define D_BITS 14
|
---|
1298 | #define D_INDEX1(d,p) d = DM((0x21*DX3(p,5,5,6)) >> 5)
|
---|
1299 | #define D_INDEX2(d,p) d = (d & (D_MASK & 0x7ff)) ^ (D_HIGH | 0x1f)
|
---|
1300 |
|
---|
1301 | #ifndef __LZO_CONFIG1X_H
|
---|
1302 | #define __LZO_CONFIG1X_H
|
---|
1303 |
|
---|
1304 | #if !defined(LZO1X) && !defined(LZO1Y) && !defined(LZO1Z)
|
---|
1305 | # define LZO1X
|
---|
1306 | #endif
|
---|
1307 |
|
---|
1308 | #if !defined(__LZO_IN_MINILZO)
|
---|
1309 | #include <lzo1x.h>
|
---|
1310 | #endif
|
---|
1311 |
|
---|
1312 | #define LZO_EOF_CODE
|
---|
1313 | #undef LZO_DETERMINISTIC
|
---|
1314 |
|
---|
1315 | #define M1_MAX_OFFSET 0x0400
|
---|
1316 | #ifndef M2_MAX_OFFSET
|
---|
1317 | #define M2_MAX_OFFSET 0x0800
|
---|
1318 | #endif
|
---|
1319 | #define M3_MAX_OFFSET 0x4000
|
---|
1320 | #define M4_MAX_OFFSET 0xbfff
|
---|
1321 |
|
---|
1322 | #define MX_MAX_OFFSET (M1_MAX_OFFSET + M2_MAX_OFFSET)
|
---|
1323 |
|
---|
1324 | #define M1_MIN_LEN 2
|
---|
1325 | #define M1_MAX_LEN 2
|
---|
1326 | #define M2_MIN_LEN 3
|
---|
1327 | #ifndef M2_MAX_LEN
|
---|
1328 | #define M2_MAX_LEN 8
|
---|
1329 | #endif
|
---|
1330 | #define M3_MIN_LEN 3
|
---|
1331 | #define M3_MAX_LEN 33
|
---|
1332 | #define M4_MIN_LEN 3
|
---|
1333 | #define M4_MAX_LEN 9
|
---|
1334 |
|
---|
1335 | #define M1_MARKER 0
|
---|
1336 | #define M2_MARKER 64
|
---|
1337 | #define M3_MARKER 32
|
---|
1338 | #define M4_MARKER 16
|
---|
1339 |
|
---|
1340 | #ifndef MIN_LOOKAHEAD
|
---|
1341 | #define MIN_LOOKAHEAD (M2_MAX_LEN + 1)
|
---|
1342 | #endif
|
---|
1343 |
|
---|
1344 | #if defined(LZO_NEED_DICT_H)
|
---|
1345 |
|
---|
1346 | #ifndef LZO_HASH
|
---|
1347 | #define LZO_HASH LZO_HASH_LZO_INCREMENTAL_B
|
---|
1348 | #endif
|
---|
1349 | #define DL_MIN_LEN M2_MIN_LEN
|
---|
1350 |
|
---|
1351 | #ifndef __LZO_DICT_H
|
---|
1352 | #define __LZO_DICT_H
|
---|
1353 |
|
---|
1354 | #ifdef __cplusplus
|
---|
1355 | extern "C" {
|
---|
1356 | #endif
|
---|
1357 |
|
---|
1358 | #if !defined(D_BITS) && defined(DBITS)
|
---|
1359 | # define D_BITS DBITS
|
---|
1360 | #endif
|
---|
1361 | #if !defined(D_BITS)
|
---|
1362 | # error D_BITS is not defined
|
---|
1363 | #endif
|
---|
1364 | #if (D_BITS < 16)
|
---|
1365 | # define D_SIZE LZO_SIZE(D_BITS)
|
---|
1366 | # define D_MASK LZO_MASK(D_BITS)
|
---|
1367 | #else
|
---|
1368 | # define D_SIZE LZO_USIZE(D_BITS)
|
---|
1369 | # define D_MASK LZO_UMASK(D_BITS)
|
---|
1370 | #endif
|
---|
1371 | #define D_HIGH ((D_MASK >> 1) + 1)
|
---|
1372 |
|
---|
1373 | #if !defined(DD_BITS)
|
---|
1374 | # define DD_BITS 0
|
---|
1375 | #endif
|
---|
1376 | #define DD_SIZE LZO_SIZE(DD_BITS)
|
---|
1377 | #define DD_MASK LZO_MASK(DD_BITS)
|
---|
1378 |
|
---|
1379 | #if !defined(DL_BITS)
|
---|
1380 | # define DL_BITS (D_BITS - DD_BITS)
|
---|
1381 | #endif
|
---|
1382 | #if (DL_BITS < 16)
|
---|
1383 | # define DL_SIZE LZO_SIZE(DL_BITS)
|
---|
1384 | # define DL_MASK LZO_MASK(DL_BITS)
|
---|
1385 | #else
|
---|
1386 | # define DL_SIZE LZO_USIZE(DL_BITS)
|
---|
1387 | # define DL_MASK LZO_UMASK(DL_BITS)
|
---|
1388 | #endif
|
---|
1389 |
|
---|
1390 | #if (D_BITS != DL_BITS + DD_BITS)
|
---|
1391 | # error D_BITS does not match
|
---|
1392 | #endif
|
---|
1393 | #if (D_BITS < 8 || D_BITS > 18)
|
---|
1394 | # error invalid D_BITS
|
---|
1395 | #endif
|
---|
1396 | #if (DL_BITS < 8 || DL_BITS > 20)
|
---|
1397 | # error invalid DL_BITS
|
---|
1398 | #endif
|
---|
1399 | #if (DD_BITS < 0 || DD_BITS > 6)
|
---|
1400 | # error invalid DD_BITS
|
---|
1401 | #endif
|
---|
1402 |
|
---|
1403 | #if !defined(DL_MIN_LEN)
|
---|
1404 | # define DL_MIN_LEN 3
|
---|
1405 | #endif
|
---|
1406 | #if !defined(DL_SHIFT)
|
---|
1407 | # define DL_SHIFT ((DL_BITS + (DL_MIN_LEN - 1)) / DL_MIN_LEN)
|
---|
1408 | #endif
|
---|
1409 |
|
---|
1410 | #define LZO_HASH_GZIP 1
|
---|
1411 | #define LZO_HASH_GZIP_INCREMENTAL 2
|
---|
1412 | #define LZO_HASH_LZO_INCREMENTAL_A 3
|
---|
1413 | #define LZO_HASH_LZO_INCREMENTAL_B 4
|
---|
1414 |
|
---|
1415 | #if !defined(LZO_HASH)
|
---|
1416 | # error choose a hashing strategy
|
---|
1417 | #endif
|
---|
1418 |
|
---|
1419 | #if (DL_MIN_LEN == 3)
|
---|
1420 | # define _DV2_A(p,shift1,shift2) \
|
---|
1421 | (((( (lzo_uint32)((p)[0]) << shift1) ^ (p)[1]) << shift2) ^ (p)[2])
|
---|
1422 | # define _DV2_B(p,shift1,shift2) \
|
---|
1423 | (((( (lzo_uint32)((p)[2]) << shift1) ^ (p)[1]) << shift2) ^ (p)[0])
|
---|
1424 | # define _DV3_B(p,shift1,shift2,shift3) \
|
---|
1425 | ((_DV2_B((p)+1,shift1,shift2) << (shift3)) ^ (p)[0])
|
---|
1426 | #elif (DL_MIN_LEN == 2)
|
---|
1427 | # define _DV2_A(p,shift1,shift2) \
|
---|
1428 | (( (lzo_uint32)(p[0]) << shift1) ^ p[1])
|
---|
1429 | # define _DV2_B(p,shift1,shift2) \
|
---|
1430 | (( (lzo_uint32)(p[1]) << shift1) ^ p[2])
|
---|
1431 | #else
|
---|
1432 | # error invalid DL_MIN_LEN
|
---|
1433 | #endif
|
---|
1434 | #define _DV_A(p,shift) _DV2_A(p,shift,shift)
|
---|
1435 | #define _DV_B(p,shift) _DV2_B(p,shift,shift)
|
---|
1436 | #define DA2(p,s1,s2) \
|
---|
1437 | (((((lzo_uint32)((p)[2]) << (s2)) + (p)[1]) << (s1)) + (p)[0])
|
---|
1438 | #define DS2(p,s1,s2) \
|
---|
1439 | (((((lzo_uint32)((p)[2]) << (s2)) - (p)[1]) << (s1)) - (p)[0])
|
---|
1440 | #define DX2(p,s1,s2) \
|
---|
1441 | (((((lzo_uint32)((p)[2]) << (s2)) ^ (p)[1]) << (s1)) ^ (p)[0])
|
---|
1442 | #define DA3(p,s1,s2,s3) ((DA2((p)+1,s2,s3) << (s1)) + (p)[0])
|
---|
1443 | #define DS3(p,s1,s2,s3) ((DS2((p)+1,s2,s3) << (s1)) - (p)[0])
|
---|
1444 | #define DX3(p,s1,s2,s3) ((DX2((p)+1,s2,s3) << (s1)) ^ (p)[0])
|
---|
1445 | #define DMS(v,s) ((lzo_uint) (((v) & (D_MASK >> (s))) << (s)))
|
---|
1446 | #define DM(v) DMS(v,0)
|
---|
1447 |
|
---|
1448 | #if (LZO_HASH == LZO_HASH_GZIP)
|
---|
1449 | # define _DINDEX(dv,p) (_DV_A((p),DL_SHIFT))
|
---|
1450 |
|
---|
1451 | #elif (LZO_HASH == LZO_HASH_GZIP_INCREMENTAL)
|
---|
1452 | # define __LZO_HASH_INCREMENTAL
|
---|
1453 | # define DVAL_FIRST(dv,p) dv = _DV_A((p),DL_SHIFT)
|
---|
1454 | # define DVAL_NEXT(dv,p) dv = (((dv) << DL_SHIFT) ^ p[2])
|
---|
1455 | # define _DINDEX(dv,p) (dv)
|
---|
1456 | # define DVAL_LOOKAHEAD DL_MIN_LEN
|
---|
1457 |
|
---|
1458 | #elif (LZO_HASH == LZO_HASH_LZO_INCREMENTAL_A)
|
---|
1459 | # define __LZO_HASH_INCREMENTAL
|
---|
1460 | # define DVAL_FIRST(dv,p) dv = _DV_A((p),5)
|
---|
1461 | # define DVAL_NEXT(dv,p) \
|
---|
1462 | dv ^= (lzo_uint32)(p[-1]) << (2*5); dv = (((dv) << 5) ^ p[2])
|
---|
1463 | # define _DINDEX(dv,p) ((0x9f5f * (dv)) >> 5)
|
---|
1464 | # define DVAL_LOOKAHEAD DL_MIN_LEN
|
---|
1465 |
|
---|
1466 | #elif (LZO_HASH == LZO_HASH_LZO_INCREMENTAL_B)
|
---|
1467 | # define __LZO_HASH_INCREMENTAL
|
---|
1468 | # define DVAL_FIRST(dv,p) dv = _DV_B((p),5)
|
---|
1469 | # define DVAL_NEXT(dv,p) \
|
---|
1470 | dv ^= p[-1]; dv = (((dv) >> 5) ^ ((lzo_uint32)(p[2]) << (2*5)))
|
---|
1471 | # define _DINDEX(dv,p) ((0x9f5f * (dv)) >> 5)
|
---|
1472 | # define DVAL_LOOKAHEAD DL_MIN_LEN
|
---|
1473 |
|
---|
1474 | #else
|
---|
1475 | # error choose a hashing strategy
|
---|
1476 | #endif
|
---|
1477 |
|
---|
1478 | #ifndef DINDEX
|
---|
1479 | #define DINDEX(dv,p) ((lzo_uint)((_DINDEX(dv,p)) & DL_MASK) << DD_BITS)
|
---|
1480 | #endif
|
---|
1481 | #if !defined(DINDEX1) && defined(D_INDEX1)
|
---|
1482 | #define DINDEX1 D_INDEX1
|
---|
1483 | #endif
|
---|
1484 | #if !defined(DINDEX2) && defined(D_INDEX2)
|
---|
1485 | #define DINDEX2 D_INDEX2
|
---|
1486 | #endif
|
---|
1487 |
|
---|
1488 | #if !defined(__LZO_HASH_INCREMENTAL)
|
---|
1489 | # define DVAL_FIRST(dv,p) ((void) 0)
|
---|
1490 | # define DVAL_NEXT(dv,p) ((void) 0)
|
---|
1491 | # define DVAL_LOOKAHEAD 0
|
---|
1492 | #endif
|
---|
1493 |
|
---|
1494 | #if !defined(DVAL_ASSERT)
|
---|
1495 | #if defined(__LZO_HASH_INCREMENTAL) && !defined(NDEBUG)
|
---|
1496 | static void DVAL_ASSERT(lzo_uint32 dv, const lzo_byte *p)
|
---|
1497 | {
|
---|
1498 | lzo_uint32 df;
|
---|
1499 | DVAL_FIRST(df,(p));
|
---|
1500 | assert(DINDEX(dv,p) == DINDEX(df,p));
|
---|
1501 | }
|
---|
1502 | #else
|
---|
1503 | # define DVAL_ASSERT(dv,p) ((void) 0)
|
---|
1504 | #endif
|
---|
1505 | #endif
|
---|
1506 |
|
---|
1507 | #if defined(LZO_DICT_USE_PTR)
|
---|
1508 | # define DENTRY(p,in) (p)
|
---|
1509 | # define GINDEX(m_pos,m_off,dict,dindex,in) m_pos = dict[dindex]
|
---|
1510 | #else
|
---|
1511 | # define DENTRY(p,in) ((lzo_uint) ((p)-(in)))
|
---|
1512 | # define GINDEX(m_pos,m_off,dict,dindex,in) m_off = dict[dindex]
|
---|
1513 | #endif
|
---|
1514 |
|
---|
1515 | #if (DD_BITS == 0)
|
---|
1516 |
|
---|
1517 | # define UPDATE_D(dict,drun,dv,p,in) dict[ DINDEX(dv,p) ] = DENTRY(p,in)
|
---|
1518 | # define UPDATE_I(dict,drun,index,p,in) dict[index] = DENTRY(p,in)
|
---|
1519 | # define UPDATE_P(ptr,drun,p,in) (ptr)[0] = DENTRY(p,in)
|
---|
1520 |
|
---|
1521 | #else
|
---|
1522 |
|
---|
1523 | # define UPDATE_D(dict,drun,dv,p,in) \
|
---|
1524 | dict[ DINDEX(dv,p) + drun++ ] = DENTRY(p,in); drun &= DD_MASK
|
---|
1525 | # define UPDATE_I(dict,drun,index,p,in) \
|
---|
1526 | dict[ (index) + drun++ ] = DENTRY(p,in); drun &= DD_MASK
|
---|
1527 | # define UPDATE_P(ptr,drun,p,in) \
|
---|
1528 | (ptr) [ drun++ ] = DENTRY(p,in); drun &= DD_MASK
|
---|
1529 |
|
---|
1530 | #endif
|
---|
1531 |
|
---|
1532 | #if defined(LZO_DICT_USE_PTR)
|
---|
1533 |
|
---|
1534 | #define LZO_CHECK_MPOS_DET(m_pos,m_off,in,ip,max_offset) \
|
---|
1535 | (m_pos == NULL || (m_off = (lzo_moff_t) (ip - m_pos)) > max_offset)
|
---|
1536 |
|
---|
1537 | #define LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,max_offset) \
|
---|
1538 | (BOUNDS_CHECKING_OFF_IN_EXPR( \
|
---|
1539 | (PTR_LT(m_pos,in) || \
|
---|
1540 | (m_off = (lzo_moff_t) PTR_DIFF(ip,m_pos)) <= 0 || \
|
---|
1541 | m_off > max_offset) ))
|
---|
1542 |
|
---|
1543 | #else
|
---|
1544 |
|
---|
1545 | #define LZO_CHECK_MPOS_DET(m_pos,m_off,in,ip,max_offset) \
|
---|
1546 | (m_off == 0 || \
|
---|
1547 | ((m_off = (lzo_moff_t) ((ip)-(in)) - m_off) > max_offset) || \
|
---|
1548 | (m_pos = (ip) - (m_off), 0) )
|
---|
1549 |
|
---|
1550 | #define LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,max_offset) \
|
---|
1551 | ((lzo_moff_t) ((ip)-(in)) <= m_off || \
|
---|
1552 | ((m_off = (lzo_moff_t) ((ip)-(in)) - m_off) > max_offset) || \
|
---|
1553 | (m_pos = (ip) - (m_off), 0) )
|
---|
1554 |
|
---|
1555 | #endif
|
---|
1556 |
|
---|
1557 | #if defined(LZO_DETERMINISTIC)
|
---|
1558 | # define LZO_CHECK_MPOS LZO_CHECK_MPOS_DET
|
---|
1559 | #else
|
---|
1560 | # define LZO_CHECK_MPOS LZO_CHECK_MPOS_NON_DET
|
---|
1561 | #endif
|
---|
1562 |
|
---|
1563 | #ifdef __cplusplus
|
---|
1564 | }
|
---|
1565 | #endif
|
---|
1566 |
|
---|
1567 | #endif
|
---|
1568 |
|
---|
1569 | #endif
|
---|
1570 |
|
---|
1571 | #endif
|
---|
1572 |
|
---|
1573 | #define DO_COMPRESS lzo1x_1_compress
|
---|
1574 |
|
---|
1575 | static
|
---|
1576 | lzo_uint do_compress ( const lzo_byte *in , lzo_uint in_len,
|
---|
1577 | lzo_byte *out, lzo_uint *out_len,
|
---|
1578 | lzo_voidp wrkmem )
|
---|
1579 | {
|
---|
1580 | #if 0 && defined(__GNUC__) && defined(__i386__)
|
---|
1581 | register const lzo_byte *ip __asm__("%esi");
|
---|
1582 | #else
|
---|
1583 | register const lzo_byte *ip;
|
---|
1584 | #endif
|
---|
1585 | lzo_byte *op;
|
---|
1586 | const lzo_byte * const in_end = in + in_len;
|
---|
1587 | const lzo_byte * const ip_end = in + in_len - M2_MAX_LEN - 5;
|
---|
1588 | const lzo_byte *ii;
|
---|
1589 | lzo_dict_p const dict = (lzo_dict_p) wrkmem;
|
---|
1590 |
|
---|
1591 | op = out;
|
---|
1592 | ip = in;
|
---|
1593 | ii = ip;
|
---|
1594 |
|
---|
1595 | ip += 4;
|
---|
1596 | for (;;)
|
---|
1597 | {
|
---|
1598 | #if 0 && defined(__GNUC__) && defined(__i386__)
|
---|
1599 | register const lzo_byte *m_pos __asm__("%edi");
|
---|
1600 | #else
|
---|
1601 | register const lzo_byte *m_pos;
|
---|
1602 | #endif
|
---|
1603 | lzo_moff_t m_off;
|
---|
1604 | lzo_uint m_len;
|
---|
1605 | lzo_uint dindex;
|
---|
1606 |
|
---|
1607 | DINDEX1(dindex,ip);
|
---|
1608 | GINDEX(m_pos,m_off,dict,dindex,in);
|
---|
1609 | if (LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,M4_MAX_OFFSET))
|
---|
1610 | goto literal;
|
---|
1611 | #if 1
|
---|
1612 | if (m_off <= M2_MAX_OFFSET || m_pos[3] == ip[3])
|
---|
1613 | goto try_match;
|
---|
1614 | DINDEX2(dindex,ip);
|
---|
1615 | #endif
|
---|
1616 | GINDEX(m_pos,m_off,dict,dindex,in);
|
---|
1617 | if (LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,M4_MAX_OFFSET))
|
---|
1618 | goto literal;
|
---|
1619 | if (m_off <= M2_MAX_OFFSET || m_pos[3] == ip[3])
|
---|
1620 | goto try_match;
|
---|
1621 | goto literal;
|
---|
1622 |
|
---|
1623 | try_match:
|
---|
1624 | #if 1 && defined(LZO_UNALIGNED_OK_2)
|
---|
1625 | if (* (const lzo_ushortp) m_pos != * (const lzo_ushortp) ip)
|
---|
1626 | #else
|
---|
1627 | if (m_pos[0] != ip[0] || m_pos[1] != ip[1])
|
---|
1628 | #endif
|
---|
1629 | {
|
---|
1630 | }
|
---|
1631 | else
|
---|
1632 | {
|
---|
1633 | if (m_pos[2] == ip[2])
|
---|
1634 | {
|
---|
1635 | #if 0
|
---|
1636 | if (m_off <= M2_MAX_OFFSET)
|
---|
1637 | goto match;
|
---|
1638 | if (lit <= 3)
|
---|
1639 | goto match;
|
---|
1640 | if (lit == 3)
|
---|
1641 | {
|
---|
1642 | assert(op - 2 > out); op[-2] |= LZO_BYTE(3);
|
---|
1643 | *op++ = *ii++; *op++ = *ii++; *op++ = *ii++;
|
---|
1644 | goto code_match;
|
---|
1645 | }
|
---|
1646 | if (m_pos[3] == ip[3])
|
---|
1647 | #endif
|
---|
1648 | goto match;
|
---|
1649 | }
|
---|
1650 | else
|
---|
1651 | {
|
---|
1652 | #if 0
|
---|
1653 | #if 0
|
---|
1654 | if (m_off <= M1_MAX_OFFSET && lit > 0 && lit <= 3)
|
---|
1655 | #else
|
---|
1656 | if (m_off <= M1_MAX_OFFSET && lit == 3)
|
---|
1657 | #endif
|
---|
1658 | {
|
---|
1659 | register lzo_uint t;
|
---|
1660 |
|
---|
1661 | t = lit;
|
---|
1662 | assert(op - 2 > out); op[-2] |= LZO_BYTE(t);
|
---|
1663 | do *op++ = *ii++; while (--t > 0);
|
---|
1664 | assert(ii == ip);
|
---|
1665 | m_off -= 1;
|
---|
1666 | *op++ = LZO_BYTE(M1_MARKER | ((m_off & 3) << 2));
|
---|
1667 | *op++ = LZO_BYTE(m_off >> 2);
|
---|
1668 | ip += 2;
|
---|
1669 | goto match_done;
|
---|
1670 | }
|
---|
1671 | #endif
|
---|
1672 | }
|
---|
1673 | }
|
---|
1674 |
|
---|
1675 | literal:
|
---|
1676 | UPDATE_I(dict,0,dindex,ip,in);
|
---|
1677 | ++ip;
|
---|
1678 | if (ip >= ip_end)
|
---|
1679 | break;
|
---|
1680 | continue;
|
---|
1681 |
|
---|
1682 | match:
|
---|
1683 | UPDATE_I(dict,0,dindex,ip,in);
|
---|
1684 | if (ip - ii > 0)
|
---|
1685 | {
|
---|
1686 | register lzo_uint t = ip - ii;
|
---|
1687 |
|
---|
1688 | if (t <= 3)
|
---|
1689 | {
|
---|
1690 | assert(op - 2 > out);
|
---|
1691 | op[-2] |= LZO_BYTE(t);
|
---|
1692 | }
|
---|
1693 | else if (t <= 18)
|
---|
1694 | *op++ = LZO_BYTE(t - 3);
|
---|
1695 | else
|
---|
1696 | {
|
---|
1697 | register lzo_uint tt = t - 18;
|
---|
1698 |
|
---|
1699 | *op++ = 0;
|
---|
1700 | while (tt > 255)
|
---|
1701 | {
|
---|
1702 | tt -= 255;
|
---|
1703 | *op++ = 0;
|
---|
1704 | }
|
---|
1705 | assert(tt > 0);
|
---|
1706 | *op++ = LZO_BYTE(tt);
|
---|
1707 | }
|
---|
1708 | do *op++ = *ii++; while (--t > 0);
|
---|
1709 | }
|
---|
1710 |
|
---|
1711 | assert(ii == ip);
|
---|
1712 | ip += 3;
|
---|
1713 | if (m_pos[3] != *ip++ || m_pos[4] != *ip++ || m_pos[5] != *ip++ ||
|
---|
1714 | m_pos[6] != *ip++ || m_pos[7] != *ip++ || m_pos[8] != *ip++
|
---|
1715 | #ifdef LZO1Y
|
---|
1716 | || m_pos[ 9] != *ip++ || m_pos[10] != *ip++ || m_pos[11] != *ip++
|
---|
1717 | || m_pos[12] != *ip++ || m_pos[13] != *ip++ || m_pos[14] != *ip++
|
---|
1718 | #endif
|
---|
1719 | )
|
---|
1720 | {
|
---|
1721 | --ip;
|
---|
1722 | m_len = ip - ii;
|
---|
1723 | assert(m_len >= 3); assert(m_len <= M2_MAX_LEN);
|
---|
1724 |
|
---|
1725 | if (m_off <= M2_MAX_OFFSET)
|
---|
1726 | {
|
---|
1727 | m_off -= 1;
|
---|
1728 | #if defined(LZO1X)
|
---|
1729 | *op++ = LZO_BYTE(((m_len - 1) << 5) | ((m_off & 7) << 2));
|
---|
1730 | *op++ = LZO_BYTE(m_off >> 3);
|
---|
1731 | #elif defined(LZO1Y)
|
---|
1732 | *op++ = LZO_BYTE(((m_len + 1) << 4) | ((m_off & 3) << 2));
|
---|
1733 | *op++ = LZO_BYTE(m_off >> 2);
|
---|
1734 | #endif
|
---|
1735 | }
|
---|
1736 | else if (m_off <= M3_MAX_OFFSET)
|
---|
1737 | {
|
---|
1738 | m_off -= 1;
|
---|
1739 | *op++ = LZO_BYTE(M3_MARKER | (m_len - 2));
|
---|
1740 | goto m3_m4_offset;
|
---|
1741 | }
|
---|
1742 | else
|
---|
1743 | #if defined(LZO1X)
|
---|
1744 | {
|
---|
1745 | m_off -= 0x4000;
|
---|
1746 | assert(m_off > 0); assert(m_off <= 0x7fff);
|
---|
1747 | *op++ = LZO_BYTE(M4_MARKER |
|
---|
1748 | ((m_off & 0x4000) >> 11) | (m_len - 2));
|
---|
1749 | goto m3_m4_offset;
|
---|
1750 | }
|
---|
1751 | #elif defined(LZO1Y)
|
---|
1752 | goto m4_match;
|
---|
1753 | #endif
|
---|
1754 | }
|
---|
1755 | else
|
---|
1756 | {
|
---|
1757 | {
|
---|
1758 | const lzo_byte *end = in_end;
|
---|
1759 | const lzo_byte *m = m_pos + M2_MAX_LEN + 1;
|
---|
1760 | while (ip < end && *m == *ip)
|
---|
1761 | m++, ip++;
|
---|
1762 | m_len = (ip - ii);
|
---|
1763 | }
|
---|
1764 | assert(m_len > M2_MAX_LEN);
|
---|
1765 |
|
---|
1766 | if (m_off <= M3_MAX_OFFSET)
|
---|
1767 | {
|
---|
1768 | m_off -= 1;
|
---|
1769 | if (m_len <= 33)
|
---|
1770 | *op++ = LZO_BYTE(M3_MARKER | (m_len - 2));
|
---|
1771 | else
|
---|
1772 | {
|
---|
1773 | m_len -= 33;
|
---|
1774 | *op++ = M3_MARKER | 0;
|
---|
1775 | goto m3_m4_len;
|
---|
1776 | }
|
---|
1777 | }
|
---|
1778 | else
|
---|
1779 | {
|
---|
1780 | #if defined(LZO1Y)
|
---|
1781 | m4_match:
|
---|
1782 | #endif
|
---|
1783 | m_off -= 0x4000;
|
---|
1784 | assert(m_off > 0); assert(m_off <= 0x7fff);
|
---|
1785 | if (m_len <= M4_MAX_LEN)
|
---|
1786 | *op++ = LZO_BYTE(M4_MARKER |
|
---|
1787 | ((m_off & 0x4000) >> 11) | (m_len - 2));
|
---|
1788 | else
|
---|
1789 | {
|
---|
1790 | m_len -= M4_MAX_LEN;
|
---|
1791 | *op++ = LZO_BYTE(M4_MARKER | ((m_off & 0x4000) >> 11));
|
---|
1792 | m3_m4_len:
|
---|
1793 | while (m_len > 255)
|
---|
1794 | {
|
---|
1795 | m_len -= 255;
|
---|
1796 | *op++ = 0;
|
---|
1797 | }
|
---|
1798 | assert(m_len > 0);
|
---|
1799 | *op++ = LZO_BYTE(m_len);
|
---|
1800 | }
|
---|
1801 | }
|
---|
1802 |
|
---|
1803 | m3_m4_offset:
|
---|
1804 | *op++ = LZO_BYTE((m_off & 63) << 2);
|
---|
1805 | *op++ = LZO_BYTE(m_off >> 6);
|
---|
1806 | }
|
---|
1807 |
|
---|
1808 | #if 0
|
---|
1809 | match_done:
|
---|
1810 | #endif
|
---|
1811 | ii = ip;
|
---|
1812 | if (ip >= ip_end)
|
---|
1813 | break;
|
---|
1814 | }
|
---|
1815 |
|
---|
1816 | *out_len = op - out;
|
---|
1817 | return (lzo_uint) (in_end - ii);
|
---|
1818 | }
|
---|
1819 |
|
---|
1820 | LZO_PUBLIC(int)
|
---|
1821 | DO_COMPRESS ( const lzo_byte *in , lzo_uint in_len,
|
---|
1822 | lzo_byte *out, lzo_uint *out_len,
|
---|
1823 | lzo_voidp wrkmem )
|
---|
1824 | {
|
---|
1825 | lzo_byte *op = out;
|
---|
1826 | lzo_uint t;
|
---|
1827 |
|
---|
1828 | #if defined(__LZO_QUERY_COMPRESS)
|
---|
1829 | if (__LZO_IS_COMPRESS_QUERY(in,in_len,out,out_len,wrkmem))
|
---|
1830 | return __LZO_QUERY_COMPRESS(in,in_len,out,out_len,wrkmem,D_SIZE,lzo_sizeof(lzo_dict_t));
|
---|
1831 | #endif
|
---|
1832 |
|
---|
1833 | if (in_len <= M2_MAX_LEN + 5)
|
---|
1834 | t = in_len;
|
---|
1835 | else
|
---|
1836 | {
|
---|
1837 | t = do_compress(in,in_len,op,out_len,wrkmem);
|
---|
1838 | op += *out_len;
|
---|
1839 | }
|
---|
1840 |
|
---|
1841 | if (t > 0)
|
---|
1842 | {
|
---|
1843 | const lzo_byte *ii = in + in_len - t;
|
---|
1844 |
|
---|
1845 | if (op == out && t <= 238)
|
---|
1846 | *op++ = LZO_BYTE(17 + t);
|
---|
1847 | else if (t <= 3)
|
---|
1848 | op[-2] |= LZO_BYTE(t);
|
---|
1849 | else if (t <= 18)
|
---|
1850 | *op++ = LZO_BYTE(t - 3);
|
---|
1851 | else
|
---|
1852 | {
|
---|
1853 | lzo_uint tt = t - 18;
|
---|
1854 |
|
---|
1855 | *op++ = 0;
|
---|
1856 | while (tt > 255)
|
---|
1857 | {
|
---|
1858 | tt -= 255;
|
---|
1859 | *op++ = 0;
|
---|
1860 | }
|
---|
1861 | assert(tt > 0);
|
---|
1862 | *op++ = LZO_BYTE(tt);
|
---|
1863 | }
|
---|
1864 | do *op++ = *ii++; while (--t > 0);
|
---|
1865 | }
|
---|
1866 |
|
---|
1867 | *op++ = M4_MARKER | 1;
|
---|
1868 | *op++ = 0;
|
---|
1869 | *op++ = 0;
|
---|
1870 |
|
---|
1871 | *out_len = op - out;
|
---|
1872 | return LZO_E_OK;
|
---|
1873 | }
|
---|
1874 |
|
---|
1875 | #undef do_compress
|
---|
1876 | #undef DO_COMPRESS
|
---|
1877 | #undef LZO_HASH
|
---|
1878 |
|
---|
1879 | #undef LZO_TEST_DECOMPRESS_OVERRUN
|
---|
1880 | #undef LZO_TEST_DECOMPRESS_OVERRUN_INPUT
|
---|
1881 | #undef LZO_TEST_DECOMPRESS_OVERRUN_OUTPUT
|
---|
1882 | #undef LZO_TEST_DECOMPRESS_OVERRUN_LOOKBEHIND
|
---|
1883 | #undef DO_DECOMPRESS
|
---|
1884 | #define DO_DECOMPRESS lzo1x_decompress
|
---|
1885 |
|
---|
1886 | #if defined(LZO_TEST_DECOMPRESS_OVERRUN)
|
---|
1887 | # if !defined(LZO_TEST_DECOMPRESS_OVERRUN_INPUT)
|
---|
1888 | # define LZO_TEST_DECOMPRESS_OVERRUN_INPUT 2
|
---|
1889 | # endif
|
---|
1890 | # if !defined(LZO_TEST_DECOMPRESS_OVERRUN_OUTPUT)
|
---|
1891 | # define LZO_TEST_DECOMPRESS_OVERRUN_OUTPUT 2
|
---|
1892 | # endif
|
---|
1893 | # if !defined(LZO_TEST_DECOMPRESS_OVERRUN_LOOKBEHIND)
|
---|
1894 | # define LZO_TEST_DECOMPRESS_OVERRUN_LOOKBEHIND
|
---|
1895 | # endif
|
---|
1896 | #endif
|
---|
1897 |
|
---|
1898 | #undef TEST_IP
|
---|
1899 | #undef TEST_OP
|
---|
1900 | #undef TEST_LOOKBEHIND
|
---|
1901 | #undef NEED_IP
|
---|
1902 | #undef NEED_OP
|
---|
1903 | #undef HAVE_TEST_IP
|
---|
1904 | #undef HAVE_TEST_OP
|
---|
1905 | #undef HAVE_NEED_IP
|
---|
1906 | #undef HAVE_NEED_OP
|
---|
1907 | #undef HAVE_ANY_IP
|
---|
1908 | #undef HAVE_ANY_OP
|
---|
1909 |
|
---|
1910 | #if defined(LZO_TEST_DECOMPRESS_OVERRUN_INPUT)
|
---|
1911 | # if (LZO_TEST_DECOMPRESS_OVERRUN_INPUT >= 1)
|
---|
1912 | # define TEST_IP (ip < ip_end)
|
---|
1913 | # endif
|
---|
1914 | # if (LZO_TEST_DECOMPRESS_OVERRUN_INPUT >= 2)
|
---|
1915 | # define NEED_IP(x) \
|
---|
1916 | if ((lzo_uint)(ip_end - ip) < (lzo_uint)(x)) goto input_overrun
|
---|
1917 | # endif
|
---|
1918 | #endif
|
---|
1919 |
|
---|
1920 | #if defined(LZO_TEST_DECOMPRESS_OVERRUN_OUTPUT)
|
---|
1921 | # if (LZO_TEST_DECOMPRESS_OVERRUN_OUTPUT >= 1)
|
---|
1922 | # define TEST_OP (op <= op_end)
|
---|
1923 | # endif
|
---|
1924 | # if (LZO_TEST_DECOMPRESS_OVERRUN_OUTPUT >= 2)
|
---|
1925 | # undef TEST_OP
|
---|
1926 | # define NEED_OP(x) \
|
---|
1927 | if ((lzo_uint)(op_end - op) < (lzo_uint)(x)) goto output_overrun
|
---|
1928 | # endif
|
---|
1929 | #endif
|
---|
1930 |
|
---|
1931 | #if defined(LZO_TEST_DECOMPRESS_OVERRUN_LOOKBEHIND)
|
---|
1932 | # define TEST_LOOKBEHIND(m_pos,out) if (m_pos < out) goto lookbehind_overrun
|
---|
1933 | #else
|
---|
1934 | # define TEST_LOOKBEHIND(m_pos,op) ((void) 0)
|
---|
1935 | #endif
|
---|
1936 |
|
---|
1937 | #if !defined(LZO_EOF_CODE) && !defined(TEST_IP)
|
---|
1938 | # define TEST_IP (ip < ip_end)
|
---|
1939 | #endif
|
---|
1940 |
|
---|
1941 | #if defined(TEST_IP)
|
---|
1942 | # define HAVE_TEST_IP
|
---|
1943 | #else
|
---|
1944 | # define TEST_IP 1
|
---|
1945 | #endif
|
---|
1946 | #if defined(TEST_OP)
|
---|
1947 | # define HAVE_TEST_OP
|
---|
1948 | #else
|
---|
1949 | # define TEST_OP 1
|
---|
1950 | #endif
|
---|
1951 |
|
---|
1952 | #if defined(NEED_IP)
|
---|
1953 | # define HAVE_NEED_IP
|
---|
1954 | #else
|
---|
1955 | # define NEED_IP(x) ((void) 0)
|
---|
1956 | #endif
|
---|
1957 | #if defined(NEED_OP)
|
---|
1958 | # define HAVE_NEED_OP
|
---|
1959 | #else
|
---|
1960 | # define NEED_OP(x) ((void) 0)
|
---|
1961 | #endif
|
---|
1962 |
|
---|
1963 | #if defined(HAVE_TEST_IP) || defined(HAVE_NEED_IP)
|
---|
1964 | # define HAVE_ANY_IP
|
---|
1965 | #endif
|
---|
1966 | #if defined(HAVE_TEST_OP) || defined(HAVE_NEED_OP)
|
---|
1967 | # define HAVE_ANY_OP
|
---|
1968 | #endif
|
---|
1969 |
|
---|
1970 | #if defined(DO_DECOMPRESS)
|
---|
1971 | LZO_PUBLIC(int)
|
---|
1972 | DO_DECOMPRESS ( const lzo_byte *in , lzo_uint in_len,
|
---|
1973 | lzo_byte *out, lzo_uint *out_len,
|
---|
1974 | lzo_voidp wrkmem )
|
---|
1975 | #endif
|
---|
1976 | {
|
---|
1977 | register lzo_byte *op;
|
---|
1978 | register const lzo_byte *ip;
|
---|
1979 | register lzo_uint t;
|
---|
1980 | #if defined(COPY_DICT)
|
---|
1981 | lzo_uint m_off;
|
---|
1982 | const lzo_byte *dict_end;
|
---|
1983 | #else
|
---|
1984 | register const lzo_byte *m_pos;
|
---|
1985 | #endif
|
---|
1986 |
|
---|
1987 | const lzo_byte * const ip_end = in + in_len;
|
---|
1988 | #if defined(HAVE_ANY_OP)
|
---|
1989 | lzo_byte * const op_end = out + *out_len;
|
---|
1990 | #endif
|
---|
1991 | #if defined(LZO1Z)
|
---|
1992 | lzo_uint last_m_off = 0;
|
---|
1993 | #endif
|
---|
1994 |
|
---|
1995 | LZO_UNUSED(wrkmem);
|
---|
1996 |
|
---|
1997 | #if defined(__LZO_QUERY_DECOMPRESS)
|
---|
1998 | if (__LZO_IS_DECOMPRESS_QUERY(in,in_len,out,out_len,wrkmem))
|
---|
1999 | return __LZO_QUERY_DECOMPRESS(in,in_len,out,out_len,wrkmem,0,0);
|
---|
2000 | #endif
|
---|
2001 |
|
---|
2002 | #if defined(COPY_DICT)
|
---|
2003 | if (dict)
|
---|
2004 | {
|
---|
2005 | if (dict_len > M4_MAX_OFFSET)
|
---|
2006 | {
|
---|
2007 | dict += dict_len - M4_MAX_OFFSET;
|
---|
2008 | dict_len = M4_MAX_OFFSET;
|
---|
2009 | }
|
---|
2010 | dict_end = dict + dict_len;
|
---|
2011 | }
|
---|
2012 | else
|
---|
2013 | {
|
---|
2014 | dict_len = 0;
|
---|
2015 | dict_end = NULL;
|
---|
2016 | }
|
---|
2017 | #endif
|
---|
2018 |
|
---|
2019 | *out_len = 0;
|
---|
2020 |
|
---|
2021 | op = out;
|
---|
2022 | ip = in;
|
---|
2023 |
|
---|
2024 | if (*ip > 17)
|
---|
2025 | {
|
---|
2026 | t = *ip++ - 17;
|
---|
2027 | if (t < 4)
|
---|
2028 | goto match_next;
|
---|
2029 | assert(t > 0); NEED_OP(t); NEED_IP(t+1);
|
---|
2030 | do *op++ = *ip++; while (--t > 0);
|
---|
2031 | goto first_literal_run;
|
---|
2032 | }
|
---|
2033 |
|
---|
2034 | while (TEST_IP && TEST_OP)
|
---|
2035 | {
|
---|
2036 | t = *ip++;
|
---|
2037 | if (t >= 16)
|
---|
2038 | goto match;
|
---|
2039 | if (t == 0)
|
---|
2040 | {
|
---|
2041 | NEED_IP(1);
|
---|
2042 | while (*ip == 0)
|
---|
2043 | {
|
---|
2044 | t += 255;
|
---|
2045 | ip++;
|
---|
2046 | NEED_IP(1);
|
---|
2047 | }
|
---|
2048 | t += 15 + *ip++;
|
---|
2049 | }
|
---|
2050 | assert(t > 0); NEED_OP(t+3); NEED_IP(t+4);
|
---|
2051 | #if defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4)
|
---|
2052 | #if !defined(LZO_UNALIGNED_OK_4)
|
---|
2053 | if (PTR_ALIGNED2_4(op,ip))
|
---|
2054 | {
|
---|
2055 | #endif
|
---|
2056 | * (lzo_uint32p) op = * (const lzo_uint32p) ip;
|
---|
2057 | op += 4; ip += 4;
|
---|
2058 | if (--t > 0)
|
---|
2059 | {
|
---|
2060 | if (t >= 4)
|
---|
2061 | {
|
---|
2062 | do {
|
---|
2063 | * (lzo_uint32p) op = * (const lzo_uint32p) ip;
|
---|
2064 | op += 4; ip += 4; t -= 4;
|
---|
2065 | } while (t >= 4);
|
---|
2066 | if (t > 0) do *op++ = *ip++; while (--t > 0);
|
---|
2067 | }
|
---|
2068 | else
|
---|
2069 | do *op++ = *ip++; while (--t > 0);
|
---|
2070 | }
|
---|
2071 | #if !defined(LZO_UNALIGNED_OK_4)
|
---|
2072 | }
|
---|
2073 | else
|
---|
2074 | #endif
|
---|
2075 | #endif
|
---|
2076 | #if !defined(LZO_UNALIGNED_OK_4)
|
---|
2077 | {
|
---|
2078 | *op++ = *ip++; *op++ = *ip++; *op++ = *ip++;
|
---|
2079 | do *op++ = *ip++; while (--t > 0);
|
---|
2080 | }
|
---|
2081 | #endif
|
---|
2082 |
|
---|
2083 | first_literal_run:
|
---|
2084 |
|
---|
2085 | t = *ip++;
|
---|
2086 | if (t >= 16)
|
---|
2087 | goto match;
|
---|
2088 | #if defined(COPY_DICT)
|
---|
2089 | #if defined(LZO1Z)
|
---|
2090 | m_off = (1 + M2_MAX_OFFSET) + (t << 6) + (*ip++ >> 2);
|
---|
2091 | last_m_off = m_off;
|
---|
2092 | #else
|
---|
2093 | m_off = (1 + M2_MAX_OFFSET) + (t >> 2) + (*ip++ << 2);
|
---|
2094 | #endif
|
---|
2095 | NEED_OP(3);
|
---|
2096 | t = 3; COPY_DICT(t,m_off)
|
---|
2097 | #else
|
---|
2098 | #if defined(LZO1Z)
|
---|
2099 | t = (1 + M2_MAX_OFFSET) + (t << 6) + (*ip++ >> 2);
|
---|
2100 | m_pos = op - t;
|
---|
2101 | last_m_off = t;
|
---|
2102 | #else
|
---|
2103 | m_pos = op - (1 + M2_MAX_OFFSET);
|
---|
2104 | m_pos -= t >> 2;
|
---|
2105 | m_pos -= *ip++ << 2;
|
---|
2106 | #endif
|
---|
2107 | TEST_LOOKBEHIND(m_pos,out); NEED_OP(3);
|
---|
2108 | *op++ = *m_pos++; *op++ = *m_pos++; *op++ = *m_pos;
|
---|
2109 | #endif
|
---|
2110 | goto match_done;
|
---|
2111 |
|
---|
2112 | while (TEST_IP && TEST_OP)
|
---|
2113 | {
|
---|
2114 | match:
|
---|
2115 | if (t >= 64)
|
---|
2116 | {
|
---|
2117 | #if defined(COPY_DICT)
|
---|
2118 | #if defined(LZO1X)
|
---|
2119 | m_off = 1 + ((t >> 2) & 7) + (*ip++ << 3);
|
---|
2120 | t = (t >> 5) - 1;
|
---|
2121 | #elif defined(LZO1Y)
|
---|
2122 | m_off = 1 + ((t >> 2) & 3) + (*ip++ << 2);
|
---|
2123 | t = (t >> 4) - 3;
|
---|
2124 | #elif defined(LZO1Z)
|
---|
2125 | m_off = t & 0x1f;
|
---|
2126 | if (m_off >= 0x1c)
|
---|
2127 | m_off = last_m_off;
|
---|
2128 | else
|
---|
2129 | {
|
---|
2130 | m_off = 1 + (m_off << 6) + (*ip++ >> 2);
|
---|
2131 | last_m_off = m_off;
|
---|
2132 | }
|
---|
2133 | t = (t >> 5) - 1;
|
---|
2134 | #endif
|
---|
2135 | #else
|
---|
2136 | #if defined(LZO1X)
|
---|
2137 | m_pos = op - 1;
|
---|
2138 | m_pos -= (t >> 2) & 7;
|
---|
2139 | m_pos -= *ip++ << 3;
|
---|
2140 | t = (t >> 5) - 1;
|
---|
2141 | #elif defined(LZO1Y)
|
---|
2142 | m_pos = op - 1;
|
---|
2143 | m_pos -= (t >> 2) & 3;
|
---|
2144 | m_pos -= *ip++ << 2;
|
---|
2145 | t = (t >> 4) - 3;
|
---|
2146 | #elif defined(LZO1Z)
|
---|
2147 | {
|
---|
2148 | lzo_uint off = t & 0x1f;
|
---|
2149 | m_pos = op;
|
---|
2150 | if (off >= 0x1c)
|
---|
2151 | {
|
---|
2152 | assert(last_m_off > 0);
|
---|
2153 | m_pos -= last_m_off;
|
---|
2154 | }
|
---|
2155 | else
|
---|
2156 | {
|
---|
2157 | off = 1 + (off << 6) + (*ip++ >> 2);
|
---|
2158 | m_pos -= off;
|
---|
2159 | last_m_off = off;
|
---|
2160 | }
|
---|
2161 | }
|
---|
2162 | t = (t >> 5) - 1;
|
---|
2163 | #endif
|
---|
2164 | TEST_LOOKBEHIND(m_pos,out); assert(t > 0); NEED_OP(t+3-1);
|
---|
2165 | goto copy_match;
|
---|
2166 | #endif
|
---|
2167 | }
|
---|
2168 | else if (t >= 32)
|
---|
2169 | {
|
---|
2170 | t &= 31;
|
---|
2171 | if (t == 0)
|
---|
2172 | {
|
---|
2173 | NEED_IP(1);
|
---|
2174 | while (*ip == 0)
|
---|
2175 | {
|
---|
2176 | t += 255;
|
---|
2177 | ip++;
|
---|
2178 | NEED_IP(1);
|
---|
2179 | }
|
---|
2180 | t += 31 + *ip++;
|
---|
2181 | }
|
---|
2182 | #if defined(COPY_DICT)
|
---|
2183 | #if defined(LZO1Z)
|
---|
2184 | m_off = 1 + (ip[0] << 6) + (ip[1] >> 2);
|
---|
2185 | last_m_off = m_off;
|
---|
2186 | #else
|
---|
2187 | m_off = 1 + (ip[0] >> 2) + (ip[1] << 6);
|
---|
2188 | #endif
|
---|
2189 | #else
|
---|
2190 | #if defined(LZO1Z)
|
---|
2191 | {
|
---|
2192 | lzo_uint off = 1 + (ip[0] << 6) + (ip[1] >> 2);
|
---|
2193 | m_pos = op - off;
|
---|
2194 | last_m_off = off;
|
---|
2195 | }
|
---|
2196 | #elif defined(LZO_UNALIGNED_OK_2) && (LZO_BYTE_ORDER == LZO_LITTLE_ENDIAN)
|
---|
2197 | m_pos = op - 1;
|
---|
2198 | m_pos -= (* (const lzo_ushortp) ip) >> 2;
|
---|
2199 | #else
|
---|
2200 | m_pos = op - 1;
|
---|
2201 | m_pos -= (ip[0] >> 2) + (ip[1] << 6);
|
---|
2202 | #endif
|
---|
2203 | #endif
|
---|
2204 | ip += 2;
|
---|
2205 | }
|
---|
2206 | else if (t >= 16)
|
---|
2207 | {
|
---|
2208 | #if defined(COPY_DICT)
|
---|
2209 | m_off = (t & 8) << 11;
|
---|
2210 | #else
|
---|
2211 | m_pos = op;
|
---|
2212 | m_pos -= (t & 8) << 11;
|
---|
2213 | #endif
|
---|
2214 | t &= 7;
|
---|
2215 | if (t == 0)
|
---|
2216 | {
|
---|
2217 | NEED_IP(1);
|
---|
2218 | while (*ip == 0)
|
---|
2219 | {
|
---|
2220 | t += 255;
|
---|
2221 | ip++;
|
---|
2222 | NEED_IP(1);
|
---|
2223 | }
|
---|
2224 | t += 7 + *ip++;
|
---|
2225 | }
|
---|
2226 | #if defined(COPY_DICT)
|
---|
2227 | #if defined(LZO1Z)
|
---|
2228 | m_off += (ip[0] << 6) + (ip[1] >> 2);
|
---|
2229 | #else
|
---|
2230 | m_off += (ip[0] >> 2) + (ip[1] << 6);
|
---|
2231 | #endif
|
---|
2232 | ip += 2;
|
---|
2233 | if (m_off == 0)
|
---|
2234 | goto eof_found;
|
---|
2235 | m_off += 0x4000;
|
---|
2236 | #if defined(LZO1Z)
|
---|
2237 | last_m_off = m_off;
|
---|
2238 | #endif
|
---|
2239 | #else
|
---|
2240 | #if defined(LZO1Z)
|
---|
2241 | m_pos -= (ip[0] << 6) + (ip[1] >> 2);
|
---|
2242 | #elif defined(LZO_UNALIGNED_OK_2) && (LZO_BYTE_ORDER == LZO_LITTLE_ENDIAN)
|
---|
2243 | m_pos -= (* (const lzo_ushortp) ip) >> 2;
|
---|
2244 | #else
|
---|
2245 | m_pos -= (ip[0] >> 2) + (ip[1] << 6);
|
---|
2246 | #endif
|
---|
2247 | ip += 2;
|
---|
2248 | if (m_pos == op)
|
---|
2249 | goto eof_found;
|
---|
2250 | m_pos -= 0x4000;
|
---|
2251 | #if defined(LZO1Z)
|
---|
2252 | last_m_off = op - m_pos;
|
---|
2253 | #endif
|
---|
2254 | #endif
|
---|
2255 | }
|
---|
2256 | else
|
---|
2257 | {
|
---|
2258 | #if defined(COPY_DICT)
|
---|
2259 | #if defined(LZO1Z)
|
---|
2260 | m_off = 1 + (t << 6) + (*ip++ >> 2);
|
---|
2261 | last_m_off = m_off;
|
---|
2262 | #else
|
---|
2263 | m_off = 1 + (t >> 2) + (*ip++ << 2);
|
---|
2264 | #endif
|
---|
2265 | NEED_OP(2);
|
---|
2266 | t = 2; COPY_DICT(t,m_off)
|
---|
2267 | #else
|
---|
2268 | #if defined(LZO1Z)
|
---|
2269 | t = 1 + (t << 6) + (*ip++ >> 2);
|
---|
2270 | m_pos = op - t;
|
---|
2271 | last_m_off = t;
|
---|
2272 | #else
|
---|
2273 | m_pos = op - 1;
|
---|
2274 | m_pos -= t >> 2;
|
---|
2275 | m_pos -= *ip++ << 2;
|
---|
2276 | #endif
|
---|
2277 | TEST_LOOKBEHIND(m_pos,out); NEED_OP(2);
|
---|
2278 | *op++ = *m_pos++; *op++ = *m_pos;
|
---|
2279 | #endif
|
---|
2280 | goto match_done;
|
---|
2281 | }
|
---|
2282 |
|
---|
2283 | #if defined(COPY_DICT)
|
---|
2284 |
|
---|
2285 | NEED_OP(t+3-1);
|
---|
2286 | t += 3-1; COPY_DICT(t,m_off)
|
---|
2287 |
|
---|
2288 | #else
|
---|
2289 |
|
---|
2290 | TEST_LOOKBEHIND(m_pos,out); assert(t > 0); NEED_OP(t+3-1);
|
---|
2291 | #if defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4)
|
---|
2292 | #if !defined(LZO_UNALIGNED_OK_4)
|
---|
2293 | if (t >= 2 * 4 - (3 - 1) && PTR_ALIGNED2_4(op,m_pos))
|
---|
2294 | {
|
---|
2295 | assert((op - m_pos) >= 4);
|
---|
2296 | #else
|
---|
2297 | if (t >= 2 * 4 - (3 - 1) && (op - m_pos) >= 4)
|
---|
2298 | {
|
---|
2299 | #endif
|
---|
2300 | * (lzo_uint32p) op = * (const lzo_uint32p) m_pos;
|
---|
2301 | op += 4; m_pos += 4; t -= 4 - (3 - 1);
|
---|
2302 | do {
|
---|
2303 | * (lzo_uint32p) op = * (const lzo_uint32p) m_pos;
|
---|
2304 | op += 4; m_pos += 4; t -= 4;
|
---|
2305 | } while (t >= 4);
|
---|
2306 | if (t > 0) do *op++ = *m_pos++; while (--t > 0);
|
---|
2307 | }
|
---|
2308 | else
|
---|
2309 | #endif
|
---|
2310 | {
|
---|
2311 | copy_match:
|
---|
2312 | *op++ = *m_pos++; *op++ = *m_pos++;
|
---|
2313 | do *op++ = *m_pos++; while (--t > 0);
|
---|
2314 | }
|
---|
2315 |
|
---|
2316 | #endif
|
---|
2317 |
|
---|
2318 | match_done:
|
---|
2319 | #if defined(LZO1Z)
|
---|
2320 | t = ip[-1] & 3;
|
---|
2321 | #else
|
---|
2322 | t = ip[-2] & 3;
|
---|
2323 | #endif
|
---|
2324 | if (t == 0)
|
---|
2325 | break;
|
---|
2326 |
|
---|
2327 | match_next:
|
---|
2328 | assert(t > 0); NEED_OP(t); NEED_IP(t+1);
|
---|
2329 | do *op++ = *ip++; while (--t > 0);
|
---|
2330 | t = *ip++;
|
---|
2331 | }
|
---|
2332 | }
|
---|
2333 |
|
---|
2334 | #if defined(HAVE_TEST_IP) || defined(HAVE_TEST_OP)
|
---|
2335 | *out_len = op - out;
|
---|
2336 | return LZO_E_EOF_NOT_FOUND;
|
---|
2337 | #endif
|
---|
2338 |
|
---|
2339 | eof_found:
|
---|
2340 | assert(t == 1);
|
---|
2341 | *out_len = op - out;
|
---|
2342 | return (ip == ip_end ? LZO_E_OK :
|
---|
2343 | (ip < ip_end ? LZO_E_INPUT_NOT_CONSUMED : LZO_E_INPUT_OVERRUN));
|
---|
2344 |
|
---|
2345 | #if defined(HAVE_NEED_IP)
|
---|
2346 | input_overrun:
|
---|
2347 | *out_len = op - out;
|
---|
2348 | return LZO_E_INPUT_OVERRUN;
|
---|
2349 | #endif
|
---|
2350 |
|
---|
2351 | #if defined(HAVE_NEED_OP)
|
---|
2352 | output_overrun:
|
---|
2353 | *out_len = op - out;
|
---|
2354 | return LZO_E_OUTPUT_OVERRUN;
|
---|
2355 | #endif
|
---|
2356 |
|
---|
2357 | #if defined(LZO_TEST_DECOMPRESS_OVERRUN_LOOKBEHIND)
|
---|
2358 | lookbehind_overrun:
|
---|
2359 | *out_len = op - out;
|
---|
2360 | return LZO_E_LOOKBEHIND_OVERRUN;
|
---|
2361 | #endif
|
---|
2362 | }
|
---|
2363 |
|
---|
2364 | #define LZO_TEST_DECOMPRESS_OVERRUN
|
---|
2365 | #undef DO_DECOMPRESS
|
---|
2366 | #define DO_DECOMPRESS lzo1x_decompress_safe
|
---|
2367 |
|
---|
2368 | #if defined(LZO_TEST_DECOMPRESS_OVERRUN)
|
---|
2369 | # if !defined(LZO_TEST_DECOMPRESS_OVERRUN_INPUT)
|
---|
2370 | # define LZO_TEST_DECOMPRESS_OVERRUN_INPUT 2
|
---|
2371 | # endif
|
---|
2372 | # if !defined(LZO_TEST_DECOMPRESS_OVERRUN_OUTPUT)
|
---|
2373 | # define LZO_TEST_DECOMPRESS_OVERRUN_OUTPUT 2
|
---|
2374 | # endif
|
---|
2375 | # if !defined(LZO_TEST_DECOMPRESS_OVERRUN_LOOKBEHIND)
|
---|
2376 | # define LZO_TEST_DECOMPRESS_OVERRUN_LOOKBEHIND
|
---|
2377 | # endif
|
---|
2378 | #endif
|
---|
2379 |
|
---|
2380 | #undef TEST_IP
|
---|
2381 | #undef TEST_OP
|
---|
2382 | #undef TEST_LOOKBEHIND
|
---|
2383 | #undef NEED_IP
|
---|
2384 | #undef NEED_OP
|
---|
2385 | #undef HAVE_TEST_IP
|
---|
2386 | #undef HAVE_TEST_OP
|
---|
2387 | #undef HAVE_NEED_IP
|
---|
2388 | #undef HAVE_NEED_OP
|
---|
2389 | #undef HAVE_ANY_IP
|
---|
2390 | #undef HAVE_ANY_OP
|
---|
2391 |
|
---|
2392 | #if defined(LZO_TEST_DECOMPRESS_OVERRUN_INPUT)
|
---|
2393 | # if (LZO_TEST_DECOMPRESS_OVERRUN_INPUT >= 1)
|
---|
2394 | # define TEST_IP (ip < ip_end)
|
---|
2395 | # endif
|
---|
2396 | # if (LZO_TEST_DECOMPRESS_OVERRUN_INPUT >= 2)
|
---|
2397 | # define NEED_IP(x, y) \
|
---|
2398 | if ( ((y > 0) && (x > (LZO_UINT_MAX - y))) || ((lzo_uint)(ip_end - ip) < (lzo_uint)((x)+(y))) ) goto input_overrun
|
---|
2399 | # endif
|
---|
2400 | #endif
|
---|
2401 |
|
---|
2402 | #if defined(LZO_TEST_DECOMPRESS_OVERRUN_OUTPUT)
|
---|
2403 | # if (LZO_TEST_DECOMPRESS_OVERRUN_OUTPUT >= 1)
|
---|
2404 | # define TEST_OP (op <= op_end)
|
---|
2405 | # endif
|
---|
2406 | # if (LZO_TEST_DECOMPRESS_OVERRUN_OUTPUT >= 2)
|
---|
2407 | # undef TEST_OP
|
---|
2408 | # define NEED_OP(x,y) \
|
---|
2409 | if ( ((y > 0) && (x > (LZO_UINT_MAX - y))) || ((lzo_uint)(op_end - op) < (lzo_uint)((x)+(y))) ) goto output_overrun
|
---|
2410 | # endif
|
---|
2411 | #endif
|
---|
2412 |
|
---|
2413 | #if defined(LZO_TEST_DECOMPRESS_OVERRUN_LOOKBEHIND)
|
---|
2414 | # define TEST_LOOKBEHIND(m_pos,out) if (m_pos < out) goto lookbehind_overrun
|
---|
2415 | #else
|
---|
2416 | # define TEST_LOOKBEHIND(m_pos,op) ((void) 0)
|
---|
2417 | #endif
|
---|
2418 |
|
---|
2419 | #if !defined(LZO_EOF_CODE) && !defined(TEST_IP)
|
---|
2420 | # define TEST_IP (ip < ip_end)
|
---|
2421 | #endif
|
---|
2422 |
|
---|
2423 | #if defined(TEST_IP)
|
---|
2424 | # define HAVE_TEST_IP
|
---|
2425 | #else
|
---|
2426 | # define TEST_IP 1
|
---|
2427 | #endif
|
---|
2428 | #if defined(TEST_OP)
|
---|
2429 | # define HAVE_TEST_OP
|
---|
2430 | #else
|
---|
2431 | # define TEST_OP 1
|
---|
2432 | #endif
|
---|
2433 |
|
---|
2434 | #if defined(NEED_IP)
|
---|
2435 | # define HAVE_NEED_IP
|
---|
2436 | #else
|
---|
2437 | /* # define NEED_IP(x) ((void) 0) */
|
---|
2438 | #error "no need_ip"
|
---|
2439 | #endif
|
---|
2440 | #if defined(NEED_OP)
|
---|
2441 | # define HAVE_NEED_OP
|
---|
2442 | #else
|
---|
2443 | /* # define NEED_OP(x) ((void) 0) */
|
---|
2444 | #error "no need_op"
|
---|
2445 | #endif
|
---|
2446 |
|
---|
2447 | #if defined(HAVE_TEST_IP) || defined(HAVE_NEED_IP)
|
---|
2448 | # define HAVE_ANY_IP
|
---|
2449 | #endif
|
---|
2450 | #if defined(HAVE_TEST_OP) || defined(HAVE_NEED_OP)
|
---|
2451 | # define HAVE_ANY_OP
|
---|
2452 | #endif
|
---|
2453 |
|
---|
2454 | #if defined(DO_DECOMPRESS)
|
---|
2455 | LZO_PUBLIC(int)
|
---|
2456 | DO_DECOMPRESS ( const lzo_byte *in , lzo_uint in_len,
|
---|
2457 | lzo_byte *out, lzo_uint *out_len,
|
---|
2458 | lzo_voidp wrkmem )
|
---|
2459 | #endif
|
---|
2460 | {
|
---|
2461 | register lzo_byte *op;
|
---|
2462 | register const lzo_byte *ip;
|
---|
2463 | register lzo_uint t;
|
---|
2464 | #if defined(COPY_DICT)
|
---|
2465 | lzo_uint m_off;
|
---|
2466 | const lzo_byte *dict_end;
|
---|
2467 | #else
|
---|
2468 | register const lzo_byte *m_pos;
|
---|
2469 | #endif
|
---|
2470 |
|
---|
2471 | const lzo_byte * const ip_end = in + in_len;
|
---|
2472 | #if defined(HAVE_ANY_OP)
|
---|
2473 | lzo_byte * const op_end = out + *out_len;
|
---|
2474 | #endif
|
---|
2475 | #if defined(LZO1Z)
|
---|
2476 | lzo_uint last_m_off = 0;
|
---|
2477 | #endif
|
---|
2478 |
|
---|
2479 | LZO_UNUSED(wrkmem);
|
---|
2480 |
|
---|
2481 | #if defined(__LZO_QUERY_DECOMPRESS)
|
---|
2482 | if (__LZO_IS_DECOMPRESS_QUERY(in,in_len,out,out_len,wrkmem))
|
---|
2483 | return __LZO_QUERY_DECOMPRESS(in,in_len,out,out_len,wrkmem,0,0);
|
---|
2484 | #endif
|
---|
2485 |
|
---|
2486 | #if defined(COPY_DICT)
|
---|
2487 | if (dict)
|
---|
2488 | {
|
---|
2489 | if (dict_len > M4_MAX_OFFSET)
|
---|
2490 | {
|
---|
2491 | dict += dict_len - M4_MAX_OFFSET;
|
---|
2492 | dict_len = M4_MAX_OFFSET;
|
---|
2493 | }
|
---|
2494 | dict_end = dict + dict_len;
|
---|
2495 | }
|
---|
2496 | else
|
---|
2497 | {
|
---|
2498 | dict_len = 0;
|
---|
2499 | dict_end = NULL;
|
---|
2500 | }
|
---|
2501 | #endif
|
---|
2502 |
|
---|
2503 | *out_len = 0;
|
---|
2504 |
|
---|
2505 | op = out;
|
---|
2506 | ip = in;
|
---|
2507 |
|
---|
2508 | if (*ip > 17)
|
---|
2509 | {
|
---|
2510 | t = *ip++ - 17;
|
---|
2511 | if (t < 4)
|
---|
2512 | goto match_next;
|
---|
2513 | assert(t > 0); NEED_OP(t, 0); NEED_IP(t, 1);
|
---|
2514 | do *op++ = *ip++; while (--t > 0);
|
---|
2515 | goto first_literal_run;
|
---|
2516 | }
|
---|
2517 |
|
---|
2518 | while (TEST_IP && TEST_OP)
|
---|
2519 | {
|
---|
2520 | t = *ip++;
|
---|
2521 | if (t >= 16)
|
---|
2522 | goto match;
|
---|
2523 | if (t == 0)
|
---|
2524 | {
|
---|
2525 | NEED_IP(1, 0);
|
---|
2526 | while (*ip == 0)
|
---|
2527 | {
|
---|
2528 | t += 255;
|
---|
2529 | ip++;
|
---|
2530 | NEED_IP(1, 0);
|
---|
2531 | }
|
---|
2532 | t += 15 + *ip++;
|
---|
2533 | }
|
---|
2534 | assert(t > 0); NEED_OP(t,3); NEED_IP(t,4);
|
---|
2535 | #if defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4)
|
---|
2536 | #if !defined(LZO_UNALIGNED_OK_4)
|
---|
2537 | if (PTR_ALIGNED2_4(op,ip))
|
---|
2538 | {
|
---|
2539 | #endif
|
---|
2540 | * (lzo_uint32p) op = * (const lzo_uint32p) ip;
|
---|
2541 | op += 4; ip += 4;
|
---|
2542 | if (--t > 0)
|
---|
2543 | {
|
---|
2544 | if (t >= 4)
|
---|
2545 | {
|
---|
2546 | do {
|
---|
2547 | * (lzo_uint32p) op = * (const lzo_uint32p) ip;
|
---|
2548 | op += 4; ip += 4; t -= 4;
|
---|
2549 | } while (t >= 4);
|
---|
2550 | if (t > 0) do *op++ = *ip++; while (--t > 0);
|
---|
2551 | }
|
---|
2552 | else
|
---|
2553 | do *op++ = *ip++; while (--t > 0);
|
---|
2554 | }
|
---|
2555 | #if !defined(LZO_UNALIGNED_OK_4)
|
---|
2556 | }
|
---|
2557 | else
|
---|
2558 | #endif
|
---|
2559 | #endif
|
---|
2560 | #if !defined(LZO_UNALIGNED_OK_4)
|
---|
2561 | {
|
---|
2562 | *op++ = *ip++; *op++ = *ip++; *op++ = *ip++;
|
---|
2563 | do *op++ = *ip++; while (--t > 0);
|
---|
2564 | }
|
---|
2565 | #endif
|
---|
2566 |
|
---|
2567 | first_literal_run:
|
---|
2568 |
|
---|
2569 | t = *ip++;
|
---|
2570 | if (t >= 16)
|
---|
2571 | goto match;
|
---|
2572 | #if defined(COPY_DICT)
|
---|
2573 | #if defined(LZO1Z)
|
---|
2574 | m_off = (1 + M2_MAX_OFFSET) + (t << 6) + (*ip++ >> 2);
|
---|
2575 | last_m_off = m_off;
|
---|
2576 | #else
|
---|
2577 | m_off = (1 + M2_MAX_OFFSET) + (t >> 2) + (*ip++ << 2);
|
---|
2578 | #endif
|
---|
2579 | NEED_OP(3);
|
---|
2580 | t = 3; COPY_DICT(t,m_off)
|
---|
2581 | #else
|
---|
2582 | #if defined(LZO1Z)
|
---|
2583 | t = (1 + M2_MAX_OFFSET) + (t << 6) + (*ip++ >> 2);
|
---|
2584 | m_pos = op - t;
|
---|
2585 | last_m_off = t;
|
---|
2586 | #else
|
---|
2587 | m_pos = op - (1 + M2_MAX_OFFSET);
|
---|
2588 | m_pos -= t >> 2;
|
---|
2589 | m_pos -= *ip++ << 2;
|
---|
2590 | #endif
|
---|
2591 | TEST_LOOKBEHIND(m_pos,out); NEED_OP(3,0);
|
---|
2592 | *op++ = *m_pos++; *op++ = *m_pos++; *op++ = *m_pos;
|
---|
2593 | #endif
|
---|
2594 | goto match_done;
|
---|
2595 |
|
---|
2596 | while (TEST_IP && TEST_OP)
|
---|
2597 | {
|
---|
2598 | match:
|
---|
2599 | if (t >= 64)
|
---|
2600 | {
|
---|
2601 | #if defined(COPY_DICT)
|
---|
2602 | #if defined(LZO1X)
|
---|
2603 | m_off = 1 + ((t >> 2) & 7) + (*ip++ << 3);
|
---|
2604 | t = (t >> 5) - 1;
|
---|
2605 | #elif defined(LZO1Y)
|
---|
2606 | m_off = 1 + ((t >> 2) & 3) + (*ip++ << 2);
|
---|
2607 | t = (t >> 4) - 3;
|
---|
2608 | #elif defined(LZO1Z)
|
---|
2609 | m_off = t & 0x1f;
|
---|
2610 | if (m_off >= 0x1c)
|
---|
2611 | m_off = last_m_off;
|
---|
2612 | else
|
---|
2613 | {
|
---|
2614 | m_off = 1 + (m_off << 6) + (*ip++ >> 2);
|
---|
2615 | last_m_off = m_off;
|
---|
2616 | }
|
---|
2617 | t = (t >> 5) - 1;
|
---|
2618 | #endif
|
---|
2619 | #else
|
---|
2620 | #if defined(LZO1X)
|
---|
2621 | m_pos = op - 1;
|
---|
2622 | m_pos -= (t >> 2) & 7;
|
---|
2623 | m_pos -= *ip++ << 3;
|
---|
2624 | t = (t >> 5) - 1;
|
---|
2625 | #elif defined(LZO1Y)
|
---|
2626 | m_pos = op - 1;
|
---|
2627 | m_pos -= (t >> 2) & 3;
|
---|
2628 | m_pos -= *ip++ << 2;
|
---|
2629 | t = (t >> 4) - 3;
|
---|
2630 | #elif defined(LZO1Z)
|
---|
2631 | {
|
---|
2632 | lzo_uint off = t & 0x1f;
|
---|
2633 | m_pos = op;
|
---|
2634 | if (off >= 0x1c)
|
---|
2635 | {
|
---|
2636 | assert(last_m_off > 0);
|
---|
2637 | m_pos -= last_m_off;
|
---|
2638 | }
|
---|
2639 | else
|
---|
2640 | {
|
---|
2641 | off = 1 + (off << 6) + (*ip++ >> 2);
|
---|
2642 | m_pos -= off;
|
---|
2643 | last_m_off = off;
|
---|
2644 | }
|
---|
2645 | }
|
---|
2646 | t = (t >> 5) - 1;
|
---|
2647 | #endif
|
---|
2648 | TEST_LOOKBEHIND(m_pos,out); assert(t > 0); NEED_OP(t,(3-1));
|
---|
2649 | goto copy_match;
|
---|
2650 | #endif
|
---|
2651 | }
|
---|
2652 | else if (t >= 32)
|
---|
2653 | {
|
---|
2654 | t &= 31;
|
---|
2655 | if (t == 0)
|
---|
2656 | {
|
---|
2657 | NEED_IP(1,0);
|
---|
2658 | while (*ip == 0)
|
---|
2659 | {
|
---|
2660 | t += 255;
|
---|
2661 | ip++;
|
---|
2662 | NEED_IP(1,0);
|
---|
2663 | }
|
---|
2664 | t += 31 + *ip++;
|
---|
2665 | }
|
---|
2666 | #if defined(COPY_DICT)
|
---|
2667 | #if defined(LZO1Z)
|
---|
2668 | m_off = 1 + (ip[0] << 6) + (ip[1] >> 2);
|
---|
2669 | last_m_off = m_off;
|
---|
2670 | #else
|
---|
2671 | m_off = 1 + (ip[0] >> 2) + (ip[1] << 6);
|
---|
2672 | #endif
|
---|
2673 | #else
|
---|
2674 | #if defined(LZO1Z)
|
---|
2675 | {
|
---|
2676 | lzo_uint off = 1 + (ip[0] << 6) + (ip[1] >> 2);
|
---|
2677 | m_pos = op - off;
|
---|
2678 | last_m_off = off;
|
---|
2679 | }
|
---|
2680 | #elif defined(LZO_UNALIGNED_OK_2) && (LZO_BYTE_ORDER == LZO_LITTLE_ENDIAN)
|
---|
2681 | m_pos = op - 1;
|
---|
2682 | m_pos -= (* (const lzo_ushortp) ip) >> 2;
|
---|
2683 | #else
|
---|
2684 | m_pos = op - 1;
|
---|
2685 | m_pos -= (ip[0] >> 2) + (ip[1] << 6);
|
---|
2686 | #endif
|
---|
2687 | #endif
|
---|
2688 | ip += 2;
|
---|
2689 | }
|
---|
2690 | else if (t >= 16)
|
---|
2691 | {
|
---|
2692 | #if defined(COPY_DICT)
|
---|
2693 | m_off = (t & 8) << 11;
|
---|
2694 | #else
|
---|
2695 | m_pos = op;
|
---|
2696 | m_pos -= (t & 8) << 11;
|
---|
2697 | #endif
|
---|
2698 | t &= 7;
|
---|
2699 | if (t == 0)
|
---|
2700 | {
|
---|
2701 | NEED_IP(1,0);
|
---|
2702 | while (*ip == 0)
|
---|
2703 | {
|
---|
2704 | t += 255;
|
---|
2705 | ip++;
|
---|
2706 | NEED_IP(1,0);
|
---|
2707 | }
|
---|
2708 | t += 7 + *ip++;
|
---|
2709 | }
|
---|
2710 | #if defined(COPY_DICT)
|
---|
2711 | #if defined(LZO1Z)
|
---|
2712 | m_off += (ip[0] << 6) + (ip[1] >> 2);
|
---|
2713 | #else
|
---|
2714 | m_off += (ip[0] >> 2) + (ip[1] << 6);
|
---|
2715 | #endif
|
---|
2716 | ip += 2;
|
---|
2717 | if (m_off == 0)
|
---|
2718 | goto eof_found;
|
---|
2719 | m_off += 0x4000;
|
---|
2720 | #if defined(LZO1Z)
|
---|
2721 | last_m_off = m_off;
|
---|
2722 | #endif
|
---|
2723 | #else
|
---|
2724 | #if defined(LZO1Z)
|
---|
2725 | m_pos -= (ip[0] << 6) + (ip[1] >> 2);
|
---|
2726 | #elif defined(LZO_UNALIGNED_OK_2) && (LZO_BYTE_ORDER == LZO_LITTLE_ENDIAN)
|
---|
2727 | m_pos -= (* (const lzo_ushortp) ip) >> 2;
|
---|
2728 | #else
|
---|
2729 | m_pos -= (ip[0] >> 2) + (ip[1] << 6);
|
---|
2730 | #endif
|
---|
2731 | ip += 2;
|
---|
2732 | if (m_pos == op)
|
---|
2733 | goto eof_found;
|
---|
2734 | m_pos -= 0x4000;
|
---|
2735 | #if defined(LZO1Z)
|
---|
2736 | last_m_off = op - m_pos;
|
---|
2737 | #endif
|
---|
2738 | #endif
|
---|
2739 | }
|
---|
2740 | else
|
---|
2741 | {
|
---|
2742 | #if defined(COPY_DICT)
|
---|
2743 | #if defined(LZO1Z)
|
---|
2744 | m_off = 1 + (t << 6) + (*ip++ >> 2);
|
---|
2745 | last_m_off = m_off;
|
---|
2746 | #else
|
---|
2747 | m_off = 1 + (t >> 2) + (*ip++ << 2);
|
---|
2748 | #endif
|
---|
2749 | NEED_OP(2,0);
|
---|
2750 | t = 2; COPY_DICT(t,m_off)
|
---|
2751 | #else
|
---|
2752 | #if defined(LZO1Z)
|
---|
2753 | t = 1 + (t << 6) + (*ip++ >> 2);
|
---|
2754 | m_pos = op - t;
|
---|
2755 | last_m_off = t;
|
---|
2756 | #else
|
---|
2757 | m_pos = op - 1;
|
---|
2758 | m_pos -= t >> 2;
|
---|
2759 | m_pos -= *ip++ << 2;
|
---|
2760 | #endif
|
---|
2761 | TEST_LOOKBEHIND(m_pos,out); NEED_OP(2,0);
|
---|
2762 | *op++ = *m_pos++; *op++ = *m_pos;
|
---|
2763 | #endif
|
---|
2764 | goto match_done;
|
---|
2765 | }
|
---|
2766 |
|
---|
2767 | #if defined(COPY_DICT)
|
---|
2768 |
|
---|
2769 | NEED_OP(t,(3-1));
|
---|
2770 | t += 3-1; COPY_DICT(t,m_off)
|
---|
2771 |
|
---|
2772 | #else
|
---|
2773 |
|
---|
2774 | TEST_LOOKBEHIND(m_pos,out); assert(t > 0); NEED_OP(t,(3-1));
|
---|
2775 | #if defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4)
|
---|
2776 | #if !defined(LZO_UNALIGNED_OK_4)
|
---|
2777 | if (t >= 2 * 4 - (3 - 1) && PTR_ALIGNED2_4(op,m_pos))
|
---|
2778 | {
|
---|
2779 | assert((op - m_pos) >= 4);
|
---|
2780 | #else
|
---|
2781 | if (t >= 2 * 4 - (3 - 1) && (op - m_pos) >= 4)
|
---|
2782 | {
|
---|
2783 | #endif
|
---|
2784 | * (lzo_uint32p) op = * (const lzo_uint32p) m_pos;
|
---|
2785 | op += 4; m_pos += 4; t -= 4 - (3 - 1);
|
---|
2786 | do {
|
---|
2787 | * (lzo_uint32p) op = * (const lzo_uint32p) m_pos;
|
---|
2788 | op += 4; m_pos += 4; t -= 4;
|
---|
2789 | } while (t >= 4);
|
---|
2790 | if (t > 0) do *op++ = *m_pos++; while (--t > 0);
|
---|
2791 | }
|
---|
2792 | else
|
---|
2793 | #endif
|
---|
2794 | {
|
---|
2795 | copy_match:
|
---|
2796 | *op++ = *m_pos++; *op++ = *m_pos++;
|
---|
2797 | do *op++ = *m_pos++; while (--t > 0);
|
---|
2798 | }
|
---|
2799 |
|
---|
2800 | #endif
|
---|
2801 |
|
---|
2802 | match_done:
|
---|
2803 | #if defined(LZO1Z)
|
---|
2804 | t = ip[-1] & 3;
|
---|
2805 | #else
|
---|
2806 | t = ip[-2] & 3;
|
---|
2807 | #endif
|
---|
2808 | if (t == 0)
|
---|
2809 | break;
|
---|
2810 |
|
---|
2811 | match_next:
|
---|
2812 | assert(t > 0); NEED_OP(t,0); NEED_IP(t,1);
|
---|
2813 | do *op++ = *ip++; while (--t > 0);
|
---|
2814 | t = *ip++;
|
---|
2815 | }
|
---|
2816 | }
|
---|
2817 |
|
---|
2818 | #if defined(HAVE_TEST_IP) || defined(HAVE_TEST_OP)
|
---|
2819 | *out_len = op - out;
|
---|
2820 | return LZO_E_EOF_NOT_FOUND;
|
---|
2821 | #endif
|
---|
2822 |
|
---|
2823 | eof_found:
|
---|
2824 | assert(t == 1);
|
---|
2825 | *out_len = op - out;
|
---|
2826 | return (ip == ip_end ? LZO_E_OK :
|
---|
2827 | (ip < ip_end ? LZO_E_INPUT_NOT_CONSUMED : LZO_E_INPUT_OVERRUN));
|
---|
2828 |
|
---|
2829 | #if defined(HAVE_NEED_IP)
|
---|
2830 | input_overrun:
|
---|
2831 | *out_len = op - out;
|
---|
2832 | return LZO_E_INPUT_OVERRUN;
|
---|
2833 | #endif
|
---|
2834 |
|
---|
2835 | #if defined(HAVE_NEED_OP)
|
---|
2836 | output_overrun:
|
---|
2837 | *out_len = op - out;
|
---|
2838 | return LZO_E_OUTPUT_OVERRUN;
|
---|
2839 | #endif
|
---|
2840 |
|
---|
2841 | #if defined(LZO_TEST_DECOMPRESS_OVERRUN_LOOKBEHIND)
|
---|
2842 | lookbehind_overrun:
|
---|
2843 | *out_len = op - out;
|
---|
2844 | return LZO_E_LOOKBEHIND_OVERRUN;
|
---|
2845 | #endif
|
---|
2846 | }
|
---|
2847 |
|
---|
2848 | /***** End of minilzo.c *****/
|
---|
2849 |
|
---|