author | truelight |
Thu, 24 Mar 2005 14:43:40 +0000 | |
changeset 1540 | 6eef12dab5bf |
parent 1277 | afb2d6a3aa25 |
child 2186 | db48cf29b983 |
permissions | -rw-r--r-- |
0 | 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) 2002 Markus Franz Xaver Johannes Oberhumer |
|
6 |
Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer |
|
7 |
Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer |
|
8 |
Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer |
|
9 |
Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer |
|
10 |
Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer |
|
11 |
Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer |
|
12 |
All Rights Reserved. |
|
13 |
||
14 |
The LZO library is free software; you can redistribute it and/or |
|
15 |
modify it under the terms of the GNU General Public License as |
|
16 |
published by the Free Software Foundation; either version 2 of |
|
17 |
the License, or (at your option) any later version. |
|
18 |
||
19 |
The LZO library is distributed in the hope that it will be useful, |
|
20 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
21 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
22 |
GNU General Public License for more details. |
|
23 |
||
24 |
You should have received a copy of the GNU General Public License |
|
25 |
along with the LZO library; see the file COPYING. |
|
26 |
If not, write to the Free Software Foundation, Inc., |
|
27 |
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
28 |
||
29 |
Markus F.X.J. Oberhumer |
|
30 |
<markus@oberhumer.com> |
|
31 |
http://www.oberhumer.com/opensource/lzo/ |
|
32 |
*/ |
|
33 |
||
34 |
/* |
|
35 |
* NOTE: |
|
36 |
* the full LZO package can be found at |
|
37 |
* http://www.oberhumer.com/opensource/lzo/ |
|
38 |
*/ |
|
39 |
||
40 |
#define LZO_DISABLE_CHECKS |
|
41 |
#define LZO1X |
|
42 |
||
43 |
#define __LZO_IN_MINILZO |
|
44 |
#define LZO_BUILD |
|
45 |
||
46 |
#ifdef MINILZO_HAVE_CONFIG_H |
|
47 |
# include <config.h> |
|
48 |
#endif |
|
49 |
||
50 |
#undef LZO_HAVE_CONFIG_H |
|
51 |
#include "minilzo.h" |
|
52 |
||
53 |
#if !defined(MINILZO_VERSION) || (MINILZO_VERSION != 0x1080) |
|
54 |
# error "version mismatch in miniLZO source files" |
|
55 |
#endif |
|
56 |
||
57 |
#ifdef MINILZO_HAVE_CONFIG_H |
|
58 |
# define LZO_HAVE_CONFIG_H |
|
59 |
#endif |
|
60 |
||
61 |
#if !defined(LZO_NO_SYS_TYPES_H) |
|
62 |
# include <sys/types.h> |
|
63 |
#endif |
|
64 |
#include <stdio.h> |
|
65 |
||
66 |
#ifndef __LZO_CONF_H |
|
67 |
#define __LZO_CONF_H |
|
68 |
||
69 |
#if defined(__BOUNDS_CHECKING_ON) |
|
70 |
# include <unchecked.h> |
|
71 |
#else |
|
72 |
# define BOUNDS_CHECKING_OFF_DURING(stmt) stmt |
|
73 |
# define BOUNDS_CHECKING_OFF_IN_EXPR(expr) (expr) |
|
74 |
#endif |
|
75 |
||
76 |
#if !defined(LZO_HAVE_CONFIG_H) |
|
77 |
# include <stddef.h> |
|
78 |
# include <string.h> |
|
79 |
# if !defined(NO_STDLIB_H) |
|
80 |
# include <stdlib.h> |
|
81 |
# endif |
|
82 |
# define HAVE_MEMCMP |
|
83 |
# define HAVE_MEMCPY |
|
84 |
# define HAVE_MEMMOVE |
|
85 |
# define HAVE_MEMSET |
|
86 |
#else |
|
87 |
# include <sys/types.h> |
|
88 |
# if defined(HAVE_STDDEF_H) |
|
89 |
# include <stddef.h> |
|
90 |
# endif |
|
91 |
# if defined(STDC_HEADERS) |
|
92 |
# include <string.h> |
|
93 |
# include <stdlib.h> |
|
94 |
# endif |
|
95 |
#endif |
|
96 |
||
97 |
#if defined(__LZO_DOS16) || defined(__LZO_WIN16) |
|
98 |
# define HAVE_MALLOC_H |
|
99 |
# define HAVE_HALLOC |
|
100 |
#endif |
|
101 |
||
102 |
#undef NDEBUG |
|
103 |
#if !defined(LZO_DEBUG) |
|
104 |
# define NDEBUG |
|
105 |
#endif |
|
106 |
#if defined(LZO_DEBUG) || !defined(NDEBUG) |
|
107 |
# if !defined(NO_STDIO_H) |
|
108 |
# include <stdio.h> |
|
109 |
# endif |
|
110 |
#endif |
|
111 |
#include <assert.h> |
|
112 |
||
113 |
#if !defined(LZO_COMPILE_TIME_ASSERT) |
|
114 |
# define LZO_COMPILE_TIME_ASSERT(expr) \ |
|
115 |
{ typedef int __lzo_compile_time_assert_fail[1 - 2 * !(expr)]; } |
|
116 |
#endif |
|
117 |
||
118 |
#if !defined(LZO_UNUSED) |
|
119 |
# if 1 |
|
120 |
# define LZO_UNUSED(var) ((void)&var) |
|
121 |
# elif 0 |
|
122 |
# define LZO_UNUSED(var) { typedef int __lzo_unused[sizeof(var) ? 2 : 1]; } |
|
123 |
# else |
|
124 |
# define LZO_UNUSED(parm) (parm = parm) |
|
125 |
# endif |
|
126 |
#endif |
|
127 |
||
128 |
#if !defined(__inline__) && !defined(__GNUC__) |
|
129 |
# if defined(__cplusplus) |
|
130 |
# define __inline__ inline |
|
131 |
# else |
|
132 |
# define __inline__ |
|
133 |
# endif |
|
134 |
#endif |
|
135 |
||
136 |
#if defined(NO_MEMCMP) |
|
137 |
# undef HAVE_MEMCMP |
|
138 |
#endif |
|
139 |
||
140 |
#if 0 |
|
141 |
# define LZO_BYTE(x) ((unsigned char) (x)) |
|
142 |
#else |
|
143 |
# define LZO_BYTE(x) ((unsigned char) ((x) & 0xff)) |
|
144 |
#endif |
|
145 |
||
146 |
#define LZO_MAX(a,b) ((a) >= (b) ? (a) : (b)) |
|
147 |
#define LZO_MIN(a,b) ((a) <= (b) ? (a) : (b)) |
|
148 |
#define LZO_MAX3(a,b,c) ((a) >= (b) ? LZO_MAX(a,c) : LZO_MAX(b,c)) |
|
149 |
#define LZO_MIN3(a,b,c) ((a) <= (b) ? LZO_MIN(a,c) : LZO_MIN(b,c)) |
|
150 |
||
151 |
#define lzo_sizeof(type) ((lzo_uint) (sizeof(type))) |
|
152 |
||
153 |
#define LZO_HIGH(array) ((lzo_uint) (sizeof(array)/sizeof(*(array)))) |
|
154 |
||
155 |
#define LZO_SIZE(bits) (1u << (bits)) |
|
156 |
#define LZO_MASK(bits) (LZO_SIZE(bits) - 1) |
|
157 |
||
158 |
#define LZO_LSIZE(bits) (1ul << (bits)) |
|
159 |
#define LZO_LMASK(bits) (LZO_LSIZE(bits) - 1) |
|
160 |
||
161 |
#define LZO_USIZE(bits) ((lzo_uint) 1 << (bits)) |
|
162 |
#define LZO_UMASK(bits) (LZO_USIZE(bits) - 1) |
|
163 |
||
164 |
#define LZO_STYPE_MAX(b) (((1l << (8*(b)-2)) - 1l) + (1l << (8*(b)-2))) |
|
165 |
#define LZO_UTYPE_MAX(b) (((1ul << (8*(b)-1)) - 1ul) + (1ul << (8*(b)-1))) |
|
166 |
||
167 |
#if !defined(SIZEOF_UNSIGNED) |
|
168 |
# if (UINT_MAX == 0xffff) |
|
169 |
# define SIZEOF_UNSIGNED 2 |
|
170 |
# elif (UINT_MAX == LZO_0xffffffffL) |
|
171 |
# define SIZEOF_UNSIGNED 4 |
|
172 |
# elif (UINT_MAX >= LZO_0xffffffffL) |
|
173 |
# define SIZEOF_UNSIGNED 8 |
|
174 |
# else |
|
175 |
# error "SIZEOF_UNSIGNED" |
|
176 |
# endif |
|
177 |
#endif |
|
178 |
||
179 |
#if !defined(SIZEOF_UNSIGNED_LONG) |
|
180 |
# if (ULONG_MAX == LZO_0xffffffffL) |
|
181 |
# define SIZEOF_UNSIGNED_LONG 4 |
|
182 |
# elif (ULONG_MAX >= LZO_0xffffffffL) |
|
183 |
# define SIZEOF_UNSIGNED_LONG 8 |
|
184 |
# else |
|
185 |
# error "SIZEOF_UNSIGNED_LONG" |
|
186 |
# endif |
|
187 |
#endif |
|
188 |
||
189 |
#if !defined(SIZEOF_SIZE_T) |
|
190 |
# define SIZEOF_SIZE_T SIZEOF_UNSIGNED |
|
191 |
#endif |
|
192 |
#if !defined(SIZE_T_MAX) |
|
193 |
# define SIZE_T_MAX LZO_UTYPE_MAX(SIZEOF_SIZE_T) |
|
194 |
#endif |
|
195 |
||
196 |
#if 1 && defined(__LZO_i386) && (UINT_MAX == LZO_0xffffffffL) |
|
197 |
# if !defined(LZO_UNALIGNED_OK_2) && (USHRT_MAX == 0xffff) |
|
198 |
# define LZO_UNALIGNED_OK_2 |
|
199 |
# endif |
|
200 |
# if !defined(LZO_UNALIGNED_OK_4) && (LZO_UINT32_MAX == LZO_0xffffffffL) |
|
201 |
# define LZO_UNALIGNED_OK_4 |
|
202 |
# endif |
|
203 |
#endif |
|
204 |
||
205 |
#if defined(LZO_UNALIGNED_OK_2) || defined(LZO_UNALIGNED_OK_4) |
|
206 |
# if !defined(LZO_UNALIGNED_OK) |
|
207 |
# define LZO_UNALIGNED_OK |
|
208 |
# endif |
|
209 |
#endif |
|
210 |
||
211 |
#if defined(__LZO_NO_UNALIGNED) |
|
212 |
# undef LZO_UNALIGNED_OK |
|
213 |
# undef LZO_UNALIGNED_OK_2 |
|
214 |
# undef LZO_UNALIGNED_OK_4 |
|
215 |
#endif |
|
216 |
||
217 |
#if defined(LZO_UNALIGNED_OK_2) && (USHRT_MAX != 0xffff) |
|
218 |
# error "LZO_UNALIGNED_OK_2 must not be defined on this system" |
|
219 |
#endif |
|
220 |
#if defined(LZO_UNALIGNED_OK_4) && (LZO_UINT32_MAX != LZO_0xffffffffL) |
|
221 |
# error "LZO_UNALIGNED_OK_4 must not be defined on this system" |
|
222 |
#endif |
|
223 |
||
224 |
#if defined(__LZO_NO_ALIGNED) |
|
225 |
# undef LZO_ALIGNED_OK_4 |
|
226 |
#endif |
|
227 |
||
228 |
#if defined(LZO_ALIGNED_OK_4) && (LZO_UINT32_MAX != LZO_0xffffffffL) |
|
229 |
# error "LZO_ALIGNED_OK_4 must not be defined on this system" |
|
230 |
#endif |
|
231 |
||
232 |
#define LZO_LITTLE_ENDIAN 1234 |
|
233 |
#define LZO_BIG_ENDIAN 4321 |
|
234 |
#define LZO_PDP_ENDIAN 3412 |
|
235 |
||
236 |
#if !defined(LZO_BYTE_ORDER) |
|
237 |
# if defined(MFX_BYTE_ORDER) |
|
238 |
# define LZO_BYTE_ORDER MFX_BYTE_ORDER |
|
239 |
# elif defined(__LZO_i386) |
|
240 |
# define LZO_BYTE_ORDER LZO_LITTLE_ENDIAN |
|
241 |
# elif defined(BYTE_ORDER) |
|
242 |
# define LZO_BYTE_ORDER BYTE_ORDER |
|
243 |
# elif defined(__BYTE_ORDER) |
|
244 |
# define LZO_BYTE_ORDER __BYTE_ORDER |
|
245 |
# endif |
|
246 |
#endif |
|
247 |
||
248 |
#if defined(LZO_BYTE_ORDER) |
|
249 |
# if (LZO_BYTE_ORDER != LZO_LITTLE_ENDIAN) && \ |
|
250 |
(LZO_BYTE_ORDER != LZO_BIG_ENDIAN) |
|
251 |
# error "invalid LZO_BYTE_ORDER" |
|
252 |
# endif |
|
253 |
#endif |
|
254 |
||
255 |
#if defined(LZO_UNALIGNED_OK) && !defined(LZO_BYTE_ORDER) |
|
256 |
# error "LZO_BYTE_ORDER is not defined" |
|
257 |
#endif |
|
258 |
||
259 |
#define LZO_OPTIMIZE_GNUC_i386_IS_BUGGY |
|
260 |
||
261 |
#if defined(NDEBUG) && !defined(LZO_DEBUG) && !defined(__LZO_CHECKER) |
|
262 |
# if defined(__GNUC__) && defined(__i386__) |
|
263 |
# if !defined(LZO_OPTIMIZE_GNUC_i386_IS_BUGGY) |
|
264 |
# define LZO_OPTIMIZE_GNUC_i386 |
|
265 |
# endif |
|
266 |
# endif |
|
267 |
#endif |
|
268 |
||
269 |
__LZO_EXTERN_C int __lzo_init_done; |
|
270 |
__LZO_EXTERN_C const lzo_byte __lzo_copyright[]; |
|
271 |
LZO_EXTERN(const lzo_byte *) lzo_copyright(void); |
|
272 |
__LZO_EXTERN_C const lzo_uint32 _lzo_crc32_table[256]; |
|
273 |
||
274 |
#define _LZO_STRINGIZE(x) #x |
|
275 |
#define _LZO_MEXPAND(x) _LZO_STRINGIZE(x) |
|
276 |
||
277 |
#define _LZO_CONCAT2(a,b) a ## b |
|
278 |
#define _LZO_CONCAT3(a,b,c) a ## b ## c |
|
279 |
#define _LZO_CONCAT4(a,b,c,d) a ## b ## c ## d |
|
280 |
#define _LZO_CONCAT5(a,b,c,d,e) a ## b ## c ## d ## e |
|
281 |
||
282 |
#define _LZO_ECONCAT2(a,b) _LZO_CONCAT2(a,b) |
|
283 |
#define _LZO_ECONCAT3(a,b,c) _LZO_CONCAT3(a,b,c) |
|
284 |
#define _LZO_ECONCAT4(a,b,c,d) _LZO_CONCAT4(a,b,c,d) |
|
285 |
#define _LZO_ECONCAT5(a,b,c,d,e) _LZO_CONCAT5(a,b,c,d,e) |
|
286 |
||
287 |
#ifndef __LZO_PTR_H |
|
288 |
#define __LZO_PTR_H |
|
289 |
||
290 |
#ifdef __cplusplus |
|
291 |
extern "C" { |
|
292 |
#endif |
|
293 |
||
294 |
#if defined(__LZO_DOS16) || defined(__LZO_WIN16) |
|
295 |
# include <dos.h> |
|
296 |
# if 1 && defined(__WATCOMC__) |
|
297 |
# include <i86.h> |
|
298 |
__LZO_EXTERN_C unsigned char _HShift; |
|
299 |
# define __LZO_HShift _HShift |
|
300 |
# elif 1 && defined(_MSC_VER) |
|
301 |
__LZO_EXTERN_C unsigned short __near _AHSHIFT; |
|
302 |
# define __LZO_HShift ((unsigned) &_AHSHIFT) |
|
303 |
# elif defined(__LZO_WIN16) |
|
304 |
# define __LZO_HShift 3 |
|
305 |
# else |
|
306 |
# define __LZO_HShift 12 |
|
307 |
# endif |
|
308 |
# if !defined(_FP_SEG) && defined(FP_SEG) |
|
309 |
# define _FP_SEG FP_SEG |
|
310 |
# endif |
|
311 |
# if !defined(_FP_OFF) && defined(FP_OFF) |
|
312 |
# define _FP_OFF FP_OFF |
|
313 |
# endif |
|
314 |
#endif |
|
315 |
||
316 |
#if !defined(lzo_ptrdiff_t) |
|
317 |
# if (UINT_MAX >= LZO_0xffffffffL) |
|
318 |
typedef ptrdiff_t lzo_ptrdiff_t; |
|
319 |
# else |
|
320 |
typedef long lzo_ptrdiff_t; |
|
321 |
# endif |
|
322 |
#endif |
|
323 |
||
324 |
#if !defined(__LZO_HAVE_PTR_T) |
|
325 |
# if defined(lzo_ptr_t) |
|
326 |
# define __LZO_HAVE_PTR_T |
|
327 |
# endif |
|
328 |
#endif |
|
329 |
#if !defined(__LZO_HAVE_PTR_T) |
|
330 |
# if defined(SIZEOF_CHAR_P) && defined(SIZEOF_UNSIGNED_LONG) |
|
331 |
# if (SIZEOF_CHAR_P == SIZEOF_UNSIGNED_LONG) |
|
332 |
typedef unsigned long lzo_ptr_t; |
|
333 |
typedef long lzo_sptr_t; |
|
334 |
# define __LZO_HAVE_PTR_T |
|
335 |
# endif |
|
336 |
# endif |
|
337 |
#endif |
|
338 |
#if !defined(__LZO_HAVE_PTR_T) |
|
339 |
# if defined(SIZEOF_CHAR_P) && defined(SIZEOF_UNSIGNED) |
|
340 |
# if (SIZEOF_CHAR_P == SIZEOF_UNSIGNED) |
|
341 |
typedef unsigned int lzo_ptr_t; |
|
342 |
typedef int lzo_sptr_t; |
|
343 |
# define __LZO_HAVE_PTR_T |
|
344 |
# endif |
|
345 |
# endif |
|
346 |
#endif |
|
347 |
#if !defined(__LZO_HAVE_PTR_T) |
|
348 |
# if defined(SIZEOF_CHAR_P) && defined(SIZEOF_UNSIGNED_SHORT) |
|
349 |
# if (SIZEOF_CHAR_P == SIZEOF_UNSIGNED_SHORT) |
|
350 |
typedef unsigned short lzo_ptr_t; |
|
351 |
typedef short lzo_sptr_t; |
|
352 |
# define __LZO_HAVE_PTR_T |
|
353 |
# endif |
|
354 |
# endif |
|
355 |
#endif |
|
356 |
#if !defined(__LZO_HAVE_PTR_T) |
|
357 |
# if defined(LZO_HAVE_CONFIG_H) || defined(SIZEOF_CHAR_P) |
|
358 |
# error "no suitable type for lzo_ptr_t" |
|
359 |
# else |
|
360 |
typedef unsigned long lzo_ptr_t; |
|
361 |
typedef long lzo_sptr_t; |
|
362 |
# define __LZO_HAVE_PTR_T |
|
363 |
# endif |
|
364 |
#endif |
|
365 |
||
366 |
#if defined(__LZO_DOS16) || defined(__LZO_WIN16) |
|
367 |
#define PTR(a) ((lzo_bytep) (a)) |
|
368 |
#define PTR_ALIGNED_4(a) ((_FP_OFF(a) & 3) == 0) |
|
369 |
#define PTR_ALIGNED2_4(a,b) (((_FP_OFF(a) | _FP_OFF(b)) & 3) == 0) |
|
370 |
#else |
|
371 |
#define PTR(a) ((lzo_ptr_t) (a)) |
|
372 |
#define PTR_LINEAR(a) PTR(a) |
|
373 |
#define PTR_ALIGNED_4(a) ((PTR_LINEAR(a) & 3) == 0) |
|
374 |
#define PTR_ALIGNED_8(a) ((PTR_LINEAR(a) & 7) == 0) |
|
375 |
#define PTR_ALIGNED2_4(a,b) (((PTR_LINEAR(a) | PTR_LINEAR(b)) & 3) == 0) |
|
376 |
#define PTR_ALIGNED2_8(a,b) (((PTR_LINEAR(a) | PTR_LINEAR(b)) & 7) == 0) |
|
377 |
#endif |
|
378 |
||
379 |
#define PTR_LT(a,b) (PTR(a) < PTR(b)) |
|
380 |
#define PTR_GE(a,b) (PTR(a) >= PTR(b)) |
|
381 |
#define PTR_DIFF(a,b) ((lzo_ptrdiff_t) (PTR(a) - PTR(b))) |
|
382 |
#define pd(a,b) ((lzo_uint) ((a)-(b))) |
|
383 |
||
384 |
LZO_EXTERN(lzo_ptr_t) |
|
385 |
__lzo_ptr_linear(const lzo_voidp ptr); |
|
386 |
||
387 |
typedef union |
|
388 |
{ |
|
389 |
char a_char; |
|
390 |
unsigned char a_uchar; |
|
391 |
short a_short; |
|
392 |
unsigned short a_ushort; |
|
393 |
int a_int; |
|
394 |
unsigned int a_uint; |
|
395 |
long a_long; |
|
396 |
unsigned long a_ulong; |
|
397 |
lzo_int a_lzo_int; |
|
398 |
lzo_uint a_lzo_uint; |
|
399 |
lzo_int32 a_lzo_int32; |
|
400 |
lzo_uint32 a_lzo_uint32; |
|
401 |
ptrdiff_t a_ptrdiff_t; |
|
402 |
lzo_ptrdiff_t a_lzo_ptrdiff_t; |
|
403 |
lzo_ptr_t a_lzo_ptr_t; |
|
404 |
lzo_voidp a_lzo_voidp; |
|
405 |
void * a_void_p; |
|
406 |
lzo_bytep a_lzo_bytep; |
|
407 |
lzo_bytepp a_lzo_bytepp; |
|
408 |
lzo_uintp a_lzo_uintp; |
|
409 |
lzo_uint * a_lzo_uint_p; |
|
410 |
lzo_uint32p a_lzo_uint32p; |
|
411 |
lzo_uint32 * a_lzo_uint32_p; |
|
412 |
unsigned char * a_uchar_p; |
|
413 |
char * a_char_p; |
|
414 |
} |
|
415 |
lzo_full_align_t; |
|
416 |
||
417 |
#ifdef __cplusplus |
|
418 |
} |
|
419 |
#endif |
|
420 |
||
421 |
#endif |
|
422 |
||
423 |
#define LZO_DETERMINISTIC |
|
424 |
||
425 |
#define LZO_DICT_USE_PTR |
|
426 |
#if defined(__LZO_DOS16) || defined(__LZO_WIN16) || defined(__LZO_STRICT_16BIT) |
|
427 |
# undef LZO_DICT_USE_PTR |
|
428 |
#endif |
|
429 |
||
430 |
#if defined(LZO_DICT_USE_PTR) |
|
431 |
# define lzo_dict_t const lzo_bytep |
|
432 |
# define lzo_dict_p lzo_dict_t __LZO_MMODEL * |
|
433 |
#else |
|
434 |
# define lzo_dict_t lzo_uint |
|
435 |
# define lzo_dict_p lzo_dict_t __LZO_MMODEL * |
|
436 |
#endif |
|
437 |
||
438 |
#if !defined(lzo_moff_t) |
|
439 |
#define lzo_moff_t lzo_uint |
|
440 |
#endif |
|
441 |
||
442 |
#endif |
|
443 |
||
444 |
||
445 |
#ifndef __LZO_UTIL_H |
|
446 |
#define __LZO_UTIL_H |
|
447 |
||
448 |
#ifndef __LZO_CONF_H |
|
449 |
#endif |
|
450 |
||
451 |
#ifdef __cplusplus |
|
452 |
extern "C" { |
|
453 |
#endif |
|
454 |
||
455 |
#if 1 && defined(HAVE_MEMCPY) |
|
456 |
#if !defined(__LZO_DOS16) && !defined(__LZO_WIN16) |
|
457 |
||
458 |
#define MEMCPY8_DS(dest,src,len) \ |
|
459 |
memcpy(dest,src,len); \ |
|
460 |
dest += len; \ |
|
461 |
src += len |
|
462 |
||
463 |
#endif |
|
464 |
#endif |
|
465 |
||
466 |
#if 0 && !defined(MEMCPY8_DS) |
|
467 |
||
468 |
#define MEMCPY8_DS(dest,src,len) \ |
|
469 |
{ do { \ |
|
470 |
*dest++ = *src++; \ |
|
471 |
*dest++ = *src++; \ |
|
472 |
*dest++ = *src++; \ |
|
473 |
*dest++ = *src++; \ |
|
474 |
*dest++ = *src++; \ |
|
475 |
*dest++ = *src++; \ |
|
476 |
*dest++ = *src++; \ |
|
477 |
*dest++ = *src++; \ |
|
478 |
len -= 8; \ |
|
479 |
} while (len > 0); } |
|
480 |
||
481 |
#endif |
|
482 |
||
483 |
#if !defined(MEMCPY8_DS) |
|
484 |
||
485 |
#define MEMCPY8_DS(dest,src,len) \ |
|
486 |
{ register lzo_uint __l = (len) / 8; \ |
|
487 |
do { \ |
|
488 |
*dest++ = *src++; \ |
|
489 |
*dest++ = *src++; \ |
|
490 |
*dest++ = *src++; \ |
|
491 |
*dest++ = *src++; \ |
|
492 |
*dest++ = *src++; \ |
|
493 |
*dest++ = *src++; \ |
|
494 |
*dest++ = *src++; \ |
|
495 |
*dest++ = *src++; \ |
|
496 |
} while (--__l > 0); } |
|
497 |
||
498 |
#endif |
|
499 |
||
500 |
#define MEMCPY_DS(dest,src,len) \ |
|
501 |
do *dest++ = *src++; \ |
|
502 |
while (--len > 0) |
|
503 |
||
504 |
#define MEMMOVE_DS(dest,src,len) \ |
|
505 |
do *dest++ = *src++; \ |
|
506 |
while (--len > 0) |
|
507 |
||
508 |
#if 0 && defined(LZO_OPTIMIZE_GNUC_i386) |
|
509 |
||
510 |
#define BZERO8_PTR(s,l,n) \ |
|
511 |
__asm__ __volatile__( \ |
|
512 |
"movl %0,%%eax \n" \ |
|
513 |
"movl %1,%%edi \n" \ |
|
514 |
"movl %2,%%ecx \n" \ |
|
515 |
"cld \n" \ |
|
516 |
"rep \n" \ |
|
517 |
"stosl %%eax,(%%edi) \n" \ |
|
518 |
: \ |
|
519 |
:"g" (0),"g" (s),"g" (n) \ |
|
520 |
:"eax","edi","ecx", "memory", "cc" \ |
|
521 |
) |
|
522 |
||
523 |
#elif (LZO_UINT_MAX <= SIZE_T_MAX) && defined(HAVE_MEMSET) |
|
524 |
||
525 |
#if 1 |
|
526 |
#define BZERO8_PTR(s,l,n) memset((s),0,(lzo_uint)(l)*(n)) |
|
527 |
#else |
|
528 |
#define BZERO8_PTR(s,l,n) memset((lzo_voidp)(s),0,(lzo_uint)(l)*(n)) |
|
529 |
#endif |
|
530 |
||
531 |
#else |
|
532 |
||
533 |
#define BZERO8_PTR(s,l,n) \ |
|
534 |
lzo_memset((lzo_voidp)(s),0,(lzo_uint)(l)*(n)) |
|
535 |
||
536 |
#endif |
|
537 |
||
538 |
#if 0 |
|
539 |
#if defined(__GNUC__) && defined(__i386__) |
|
540 |
||
541 |
unsigned char lzo_rotr8(unsigned char value, int shift); |
|
542 |
extern __inline__ unsigned char lzo_rotr8(unsigned char value, int shift) |
|
543 |
{ |
|
544 |
unsigned char result; |
|
545 |
||
546 |
__asm__ __volatile__ ("movb %b1, %b0; rorb %b2, %b0" |
|
547 |
: "=a"(result) : "g"(value), "c"(shift)); |
|
548 |
return result; |
|
549 |
} |
|
550 |
||
551 |
unsigned short lzo_rotr16(unsigned short value, int shift); |
|
552 |
extern __inline__ unsigned short lzo_rotr16(unsigned short value, int shift) |
|
553 |
{ |
|
554 |
unsigned short result; |
|
555 |
||
556 |
__asm__ __volatile__ ("movw %b1, %b0; rorw %b2, %b0" |
|
557 |
: "=a"(result) : "g"(value), "c"(shift)); |
|
558 |
return result; |
|
559 |
} |
|
560 |
||
561 |
#endif |
|
562 |
#endif |
|
563 |
||
564 |
#ifdef __cplusplus |
|
565 |
} |
|
566 |
#endif |
|
567 |
||
568 |
#endif |
|
569 |
||
570 |
||
571 |
/* If you use the LZO library in a product, you *must* keep this |
|
572 |
* copyright string in the executable of your product. |
|
573 |
*/ |
|
574 |
||
1277
afb2d6a3aa25
(svn r1781) Fix static declaration after non-static declaration of same symbol
tron
parents:
0
diff
changeset
|
575 |
const lzo_byte __lzo_copyright[] = |
0 | 576 |
#if !defined(__LZO_IN_MINLZO) |
577 |
LZO_VERSION_STRING; |
|
578 |
#else |
|
579 |
"\n\n\n" |
|
580 |
"LZO real-time data compression library.\n" |
|
581 |
"Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002 Markus Franz Xaver Johannes Oberhumer\n" |
|
582 |
"<markus.oberhumer@jk.uni-linz.ac.at>\n" |
|
583 |
"http://www.oberhumer.com/opensource/lzo/\n" |
|
584 |
"\n" |
|
585 |
"LZO version: v" LZO_VERSION_STRING ", " LZO_VERSION_DATE "\n" |
|
586 |
"LZO build date: " __DATE__ " " __TIME__ "\n\n" |
|
587 |
"LZO special compilation options:\n" |
|
588 |
#ifdef __cplusplus |
|
589 |
" __cplusplus\n" |
|
590 |
#endif |
|
591 |
#if defined(__PIC__) |
|
592 |
" __PIC__\n" |
|
593 |
#elif defined(__pic__) |
|
594 |
" __pic__\n" |
|
595 |
#endif |
|
596 |
#if (UINT_MAX < LZO_0xffffffffL) |
|
597 |
" 16BIT\n" |
|
598 |
#endif |
|
599 |
#if defined(__LZO_STRICT_16BIT) |
|
600 |
" __LZO_STRICT_16BIT\n" |
|
601 |
#endif |
|
602 |
#if (UINT_MAX > LZO_0xffffffffL) |
|
603 |
" UINT_MAX=" _LZO_MEXPAND(UINT_MAX) "\n" |
|
604 |
#endif |
|
605 |
#if (ULONG_MAX > LZO_0xffffffffL) |
|
606 |
" ULONG_MAX=" _LZO_MEXPAND(ULONG_MAX) "\n" |
|
607 |
#endif |
|
608 |
#if defined(LZO_BYTE_ORDER) |
|
609 |
" LZO_BYTE_ORDER=" _LZO_MEXPAND(LZO_BYTE_ORDER) "\n" |
|
610 |
#endif |
|
611 |
#if defined(LZO_UNALIGNED_OK_2) |
|
612 |
" LZO_UNALIGNED_OK_2\n" |
|
613 |
#endif |
|
614 |
#if defined(LZO_UNALIGNED_OK_4) |
|
615 |
" LZO_UNALIGNED_OK_4\n" |
|
616 |
#endif |
|
617 |
#if defined(LZO_ALIGNED_OK_4) |
|
618 |
" LZO_ALIGNED_OK_4\n" |
|
619 |
#endif |
|
620 |
#if defined(LZO_DICT_USE_PTR) |
|
621 |
" LZO_DICT_USE_PTR\n" |
|
622 |
#endif |
|
623 |
#if defined(__LZO_QUERY_COMPRESS) |
|
624 |
" __LZO_QUERY_COMPRESS\n" |
|
625 |
#endif |
|
626 |
#if defined(__LZO_QUERY_DECOMPRESS) |
|
627 |
" __LZO_QUERY_DECOMPRESS\n" |
|
628 |
#endif |
|
629 |
#if defined(__LZO_IN_MINILZO) |
|
630 |
" __LZO_IN_MINILZO\n" |
|
631 |
#endif |
|
632 |
"\n\n" |
|
633 |
"$Id: LZO " LZO_VERSION_STRING " built " __DATE__ " " __TIME__ |
|
634 |
#if defined(__GNUC__) && defined(__VERSION__) |
|
635 |
" by gcc " __VERSION__ |
|
636 |
#elif defined(__BORLANDC__) |
|
637 |
" by Borland C " _LZO_MEXPAND(__BORLANDC__) |
|
638 |
#elif defined(_MSC_VER) |
|
639 |
" by Microsoft C " _LZO_MEXPAND(_MSC_VER) |
|
640 |
#elif defined(__PUREC__) |
|
641 |
" by Pure C " _LZO_MEXPAND(__PUREC__) |
|
642 |
#elif defined(__SC__) |
|
643 |
" by Symantec C " _LZO_MEXPAND(__SC__) |
|
644 |
#elif defined(__TURBOC__) |
|
645 |
" by Turbo C " _LZO_MEXPAND(__TURBOC__) |
|
646 |
#elif defined(__WATCOMC__) |
|
647 |
" by Watcom C " _LZO_MEXPAND(__WATCOMC__) |
|
648 |
#endif |
|
649 |
" $\n" |
|
650 |
"$Copyright: LZO (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002 Markus Franz Xaver Johannes Oberhumer $\n"; |
|
651 |
#endif |
|
652 |
||
653 |
#define LZO_BASE 65521u |
|
654 |
#define LZO_NMAX 5552 |
|
655 |
||
656 |
#define LZO_DO1(buf,i) {s1 += buf[i]; s2 += s1;} |
|
657 |
#define LZO_DO2(buf,i) LZO_DO1(buf,i); LZO_DO1(buf,i+1); |
|
658 |
#define LZO_DO4(buf,i) LZO_DO2(buf,i); LZO_DO2(buf,i+2); |
|
659 |
#define LZO_DO8(buf,i) LZO_DO4(buf,i); LZO_DO4(buf,i+4); |
|
660 |
#define LZO_DO16(buf,i) LZO_DO8(buf,i); LZO_DO8(buf,i+8); |
|
661 |
||
662 |
LZO_PUBLIC(lzo_uint32) |
|
663 |
lzo_adler32(lzo_uint32 adler, const lzo_byte *buf, lzo_uint len) |
|
664 |
{ |
|
665 |
lzo_uint32 s1 = adler & 0xffff; |
|
666 |
lzo_uint32 s2 = (adler >> 16) & 0xffff; |
|
667 |
int k; |
|
668 |
||
669 |
if (buf == NULL) |
|
670 |
return 1; |
|
671 |
||
672 |
while (len > 0) |
|
673 |
{ |
|
674 |
k = len < LZO_NMAX ? (int) len : LZO_NMAX; |
|
675 |
len -= k; |
|
676 |
if (k >= 16) do |
|
677 |
{ |
|
678 |
LZO_DO16(buf,0); |
|
679 |
buf += 16; |
|
680 |
k -= 16; |
|
681 |
} while (k >= 16); |
|
682 |
if (k != 0) do |
|
683 |
{ |
|
684 |
s1 += *buf++; |
|
685 |
s2 += s1; |
|
686 |
} while (--k > 0); |
|
687 |
s1 %= LZO_BASE; |
|
688 |
s2 %= LZO_BASE; |
|
689 |
} |
|
690 |
return (s2 << 16) | s1; |
|
691 |
} |
|
692 |
||
693 |
#if 0 |
|
694 |
# define IS_SIGNED(type) (((type) (1ul << (8 * sizeof(type) - 1))) < 0) |
|
695 |
# define IS_UNSIGNED(type) (((type) (1ul << (8 * sizeof(type) - 1))) > 0) |
|
696 |
#else |
|
697 |
# define IS_SIGNED(type) (((type) (-1)) < ((type) 0)) |
|
698 |
# define IS_UNSIGNED(type) (((type) (-1)) > ((type) 0)) |
|
699 |
#endif |
|
700 |
||
701 |
#define IS_POWER_OF_2(x) (((x) & ((x) - 1)) == 0) |
|
702 |
||
703 |
// static lzo_bool schedule_insns_bug(void); |
|
704 |
// static lzo_bool strength_reduce_bug(int *); |
|
705 |
||
706 |
#if 0 || defined(LZO_DEBUG) |
|
707 |
#include <stdio.h> |
|
708 |
static lzo_bool __lzo_assert_fail(const char *s, unsigned line) |
|
709 |
{ |
|
710 |
#if defined(__palmos__) |
|
711 |
printf("LZO assertion failed in line %u: '%s'\n",line,s); |
|
712 |
#else |
|
713 |
fprintf(stderr,"LZO assertion failed in line %u: '%s'\n",line,s); |
|
714 |
#endif |
|
715 |
return 0; |
|
716 |
} |
|
717 |
# define __lzo_assert(x) ((x) ? 1 : __lzo_assert_fail(#x,__LINE__)) |
|
718 |
#else |
|
719 |
# define __lzo_assert(x) ((x) ? 1 : 0) |
|
720 |
#endif |
|
721 |
||
722 |
#undef COMPILE_TIME_ASSERT |
|
723 |
#if 0 |
|
724 |
# define COMPILE_TIME_ASSERT(expr) r &= __lzo_assert(expr) |
|
725 |
#else |
|
726 |
# define COMPILE_TIME_ASSERT(expr) LZO_COMPILE_TIME_ASSERT(expr) |
|
727 |
#endif |
|
728 |
||
729 |
||
730 |
#define do_compress _lzo1x_1_do_compress |
|
731 |
||
732 |
#define LZO_NEED_DICT_H |
|
733 |
#define D_BITS 12 |
|
734 |
#define D_INDEX1(d,p) d = DM((0x21*DX3(p,5,5,6)) >> 5) |
|
735 |
#define D_INDEX2(d,p) d = (d & (D_MASK & 0x7ff)) ^ (D_HIGH | 0x1f) |
|
736 |
||
737 |
#ifndef __LZO_CONFIG1X_H |
|
738 |
#define __LZO_CONFIG1X_H |
|
739 |
||
740 |
#define LZO_EOF_CODE |
|
741 |
#undef LZO_DETERMINISTIC |
|
742 |
||
743 |
#define M1_MAX_OFFSET 0x0400 |
|
744 |
#ifndef M2_MAX_OFFSET |
|
745 |
#define M2_MAX_OFFSET 0x0800 |
|
746 |
#endif |
|
747 |
#define M3_MAX_OFFSET 0x4000 |
|
748 |
#define M4_MAX_OFFSET 0xbfff |
|
749 |
||
750 |
#define MX_MAX_OFFSET (M1_MAX_OFFSET + M2_MAX_OFFSET) |
|
751 |
||
752 |
#define M1_MIN_LEN 2 |
|
753 |
#define M1_MAX_LEN 2 |
|
754 |
#define M2_MIN_LEN 3 |
|
755 |
#ifndef M2_MAX_LEN |
|
756 |
#define M2_MAX_LEN 8 |
|
757 |
#endif |
|
758 |
#define M3_MIN_LEN 3 |
|
759 |
#define M3_MAX_LEN 33 |
|
760 |
#define M4_MIN_LEN 3 |
|
761 |
#define M4_MAX_LEN 9 |
|
762 |
||
763 |
#define M1_MARKER 0 |
|
764 |
#define M2_MARKER 64 |
|
765 |
#define M3_MARKER 32 |
|
766 |
#define M4_MARKER 16 |
|
767 |
||
768 |
#ifndef MIN_LOOKAHEAD |
|
769 |
#define MIN_LOOKAHEAD (M2_MAX_LEN + 1) |
|
770 |
#endif |
|
771 |
||
772 |
#if defined(LZO_NEED_DICT_H) |
|
773 |
||
774 |
#ifndef LZO_HASH |
|
775 |
#define LZO_HASH LZO_HASH_LZO_INCREMENTAL_B |
|
776 |
#endif |
|
777 |
#define DL_MIN_LEN M2_MIN_LEN |
|
778 |
||
779 |
#ifndef __LZO_DICT_H |
|
780 |
#define __LZO_DICT_H |
|
781 |
||
782 |
#ifdef __cplusplus |
|
783 |
extern "C" { |
|
784 |
#endif |
|
785 |
||
786 |
#if !defined(D_BITS) && defined(DBITS) |
|
787 |
# define D_BITS DBITS |
|
788 |
#endif |
|
789 |
#if !defined(D_BITS) |
|
790 |
# error "D_BITS is not defined" |
|
791 |
#endif |
|
792 |
#if (D_BITS < 16) |
|
793 |
# define D_SIZE LZO_SIZE(D_BITS) |
|
794 |
# define D_MASK LZO_MASK(D_BITS) |
|
795 |
#else |
|
796 |
# define D_SIZE LZO_USIZE(D_BITS) |
|
797 |
# define D_MASK LZO_UMASK(D_BITS) |
|
798 |
#endif |
|
799 |
#define D_HIGH ((D_MASK >> 1) + 1) |
|
800 |
||
801 |
#if !defined(DD_BITS) |
|
802 |
# define DD_BITS 0 |
|
803 |
#endif |
|
804 |
#define DD_SIZE LZO_SIZE(DD_BITS) |
|
805 |
#define DD_MASK LZO_MASK(DD_BITS) |
|
806 |
||
807 |
#if !defined(DL_BITS) |
|
808 |
# define DL_BITS (D_BITS - DD_BITS) |
|
809 |
#endif |
|
810 |
#if (DL_BITS < 16) |
|
811 |
# define DL_SIZE LZO_SIZE(DL_BITS) |
|
812 |
# define DL_MASK LZO_MASK(DL_BITS) |
|
813 |
#else |
|
814 |
# define DL_SIZE LZO_USIZE(DL_BITS) |
|
815 |
# define DL_MASK LZO_UMASK(DL_BITS) |
|
816 |
#endif |
|
817 |
||
818 |
#if (D_BITS != DL_BITS + DD_BITS) |
|
819 |
# error "D_BITS does not match" |
|
820 |
#endif |
|
821 |
#if (D_BITS < 8 || D_BITS > 18) |
|
822 |
# error "invalid D_BITS" |
|
823 |
#endif |
|
824 |
#if (DL_BITS < 8 || DL_BITS > 20) |
|
825 |
# error "invalid DL_BITS" |
|
826 |
#endif |
|
827 |
#if (DD_BITS < 0 || DD_BITS > 6) |
|
828 |
# error "invalid DD_BITS" |
|
829 |
#endif |
|
830 |
||
831 |
#if !defined(DL_MIN_LEN) |
|
832 |
# define DL_MIN_LEN 3 |
|
833 |
#endif |
|
834 |
#if !defined(DL_SHIFT) |
|
835 |
# define DL_SHIFT ((DL_BITS + (DL_MIN_LEN - 1)) / DL_MIN_LEN) |
|
836 |
#endif |
|
837 |
||
838 |
#define LZO_HASH_GZIP 1 |
|
839 |
#define LZO_HASH_GZIP_INCREMENTAL 2 |
|
840 |
#define LZO_HASH_LZO_INCREMENTAL_A 3 |
|
841 |
#define LZO_HASH_LZO_INCREMENTAL_B 4 |
|
842 |
||
843 |
#if !defined(LZO_HASH) |
|
844 |
# error "choose a hashing strategy" |
|
845 |
#endif |
|
846 |
||
847 |
#if (DL_MIN_LEN == 3) |
|
848 |
# define _DV2_A(p,shift1,shift2) \ |
|
849 |
(((( (lzo_uint32)((p)[0]) << shift1) ^ (p)[1]) << shift2) ^ (p)[2]) |
|
850 |
# define _DV2_B(p,shift1,shift2) \ |
|
851 |
(((( (lzo_uint32)((p)[2]) << shift1) ^ (p)[1]) << shift2) ^ (p)[0]) |
|
852 |
# define _DV3_B(p,shift1,shift2,shift3) \ |
|
853 |
((_DV2_B((p)+1,shift1,shift2) << (shift3)) ^ (p)[0]) |
|
854 |
#elif (DL_MIN_LEN == 2) |
|
855 |
# define _DV2_A(p,shift1,shift2) \ |
|
856 |
(( (lzo_uint32)(p[0]) << shift1) ^ p[1]) |
|
857 |
# define _DV2_B(p,shift1,shift2) \ |
|
858 |
(( (lzo_uint32)(p[1]) << shift1) ^ p[2]) |
|
859 |
#else |
|
860 |
# error "invalid DL_MIN_LEN" |
|
861 |
#endif |
|
862 |
#define _DV_A(p,shift) _DV2_A(p,shift,shift) |
|
863 |
#define _DV_B(p,shift) _DV2_B(p,shift,shift) |
|
864 |
#define DA2(p,s1,s2) \ |
|
865 |
(((((lzo_uint32)((p)[2]) << (s2)) + (p)[1]) << (s1)) + (p)[0]) |
|
866 |
#define DS2(p,s1,s2) \ |
|
867 |
(((((lzo_uint32)((p)[2]) << (s2)) - (p)[1]) << (s1)) - (p)[0]) |
|
868 |
#define DX2(p,s1,s2) \ |
|
869 |
(((((lzo_uint32)((p)[2]) << (s2)) ^ (p)[1]) << (s1)) ^ (p)[0]) |
|
870 |
#define DA3(p,s1,s2,s3) ((DA2((p)+1,s2,s3) << (s1)) + (p)[0]) |
|
871 |
#define DS3(p,s1,s2,s3) ((DS2((p)+1,s2,s3) << (s1)) - (p)[0]) |
|
872 |
#define DX3(p,s1,s2,s3) ((DX2((p)+1,s2,s3) << (s1)) ^ (p)[0]) |
|
873 |
#define DMS(v,s) ((lzo_uint) (((v) & (D_MASK >> (s))) << (s))) |
|
874 |
#define DM(v) DMS(v,0) |
|
875 |
||
876 |
#if (LZO_HASH == LZO_HASH_GZIP) |
|
877 |
# define _DINDEX(dv,p) (_DV_A((p),DL_SHIFT)) |
|
878 |
||
879 |
#elif (LZO_HASH == LZO_HASH_GZIP_INCREMENTAL) |
|
880 |
# define __LZO_HASH_INCREMENTAL |
|
881 |
# define DVAL_FIRST(dv,p) dv = _DV_A((p),DL_SHIFT) |
|
882 |
# define DVAL_NEXT(dv,p) dv = (((dv) << DL_SHIFT) ^ p[2]) |
|
883 |
# define _DINDEX(dv,p) (dv) |
|
884 |
# define DVAL_LOOKAHEAD DL_MIN_LEN |
|
885 |
||
886 |
#elif (LZO_HASH == LZO_HASH_LZO_INCREMENTAL_A) |
|
887 |
# define __LZO_HASH_INCREMENTAL |
|
888 |
# define DVAL_FIRST(dv,p) dv = _DV_A((p),5) |
|
889 |
# define DVAL_NEXT(dv,p) \ |
|
890 |
dv ^= (lzo_uint32)(p[-1]) << (2*5); dv = (((dv) << 5) ^ p[2]) |
|
891 |
# define _DINDEX(dv,p) ((0x9f5f * (dv)) >> 5) |
|
892 |
# define DVAL_LOOKAHEAD DL_MIN_LEN |
|
893 |
||
894 |
#elif (LZO_HASH == LZO_HASH_LZO_INCREMENTAL_B) |
|
895 |
# define __LZO_HASH_INCREMENTAL |
|
896 |
# define DVAL_FIRST(dv,p) dv = _DV_B((p),5) |
|
897 |
# define DVAL_NEXT(dv,p) \ |
|
898 |
dv ^= p[-1]; dv = (((dv) >> 5) ^ ((lzo_uint32)(p[2]) << (2*5))) |
|
899 |
# define _DINDEX(dv,p) ((0x9f5f * (dv)) >> 5) |
|
900 |
# define DVAL_LOOKAHEAD DL_MIN_LEN |
|
901 |
||
902 |
#else |
|
903 |
# error "choose a hashing strategy" |
|
904 |
#endif |
|
905 |
||
906 |
#ifndef DINDEX |
|
907 |
#define DINDEX(dv,p) ((lzo_uint)((_DINDEX(dv,p)) & DL_MASK) << DD_BITS) |
|
908 |
#endif |
|
909 |
#if !defined(DINDEX1) && defined(D_INDEX1) |
|
910 |
#define DINDEX1 D_INDEX1 |
|
911 |
#endif |
|
912 |
#if !defined(DINDEX2) && defined(D_INDEX2) |
|
913 |
#define DINDEX2 D_INDEX2 |
|
914 |
#endif |
|
915 |
||
916 |
#if !defined(__LZO_HASH_INCREMENTAL) |
|
917 |
# define DVAL_FIRST(dv,p) ((void) 0) |
|
918 |
# define DVAL_NEXT(dv,p) ((void) 0) |
|
919 |
# define DVAL_LOOKAHEAD 0 |
|
920 |
#endif |
|
921 |
||
922 |
#if !defined(DVAL_ASSERT) |
|
923 |
#if defined(__LZO_HASH_INCREMENTAL) && !defined(NDEBUG) |
|
924 |
static void DVAL_ASSERT(lzo_uint32 dv, const lzo_byte *p) |
|
925 |
{ |
|
926 |
lzo_uint32 df; |
|
927 |
DVAL_FIRST(df,(p)); |
|
928 |
assert(DINDEX(dv,p) == DINDEX(df,p)); |
|
929 |
} |
|
930 |
#else |
|
931 |
# define DVAL_ASSERT(dv,p) ((void) 0) |
|
932 |
#endif |
|
933 |
#endif |
|
934 |
||
935 |
#if defined(LZO_DICT_USE_PTR) |
|
936 |
# define DENTRY(p,in) (p) |
|
937 |
# define GINDEX(m_pos,m_off,dict,dindex,in) m_pos = dict[dindex] |
|
938 |
#else |
|
939 |
# define DENTRY(p,in) ((lzo_uint) ((p)-(in))) |
|
940 |
# define GINDEX(m_pos,m_off,dict,dindex,in) m_off = dict[dindex] |
|
941 |
#endif |
|
942 |
||
943 |
#if (DD_BITS == 0) |
|
944 |
||
945 |
# define UPDATE_D(dict,drun,dv,p,in) dict[ DINDEX(dv,p) ] = DENTRY(p,in) |
|
946 |
# define UPDATE_I(dict,drun,index,p,in) dict[index] = DENTRY(p,in) |
|
947 |
# define UPDATE_P(ptr,drun,p,in) (ptr)[0] = DENTRY(p,in) |
|
948 |
||
949 |
#else |
|
950 |
||
951 |
# define UPDATE_D(dict,drun,dv,p,in) \ |
|
952 |
dict[ DINDEX(dv,p) + drun++ ] = DENTRY(p,in); drun &= DD_MASK |
|
953 |
# define UPDATE_I(dict,drun,index,p,in) \ |
|
954 |
dict[ (index) + drun++ ] = DENTRY(p,in); drun &= DD_MASK |
|
955 |
# define UPDATE_P(ptr,drun,p,in) \ |
|
956 |
(ptr) [ drun++ ] = DENTRY(p,in); drun &= DD_MASK |
|
957 |
||
958 |
#endif |
|
959 |
||
960 |
#if defined(LZO_DICT_USE_PTR) |
|
961 |
||
962 |
#define LZO_CHECK_MPOS_DET(m_pos,m_off,in,ip,max_offset) \ |
|
963 |
(m_pos == NULL || (m_off = (lzo_moff_t) (ip - m_pos)) > max_offset) |
|
964 |
||
965 |
#define LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,max_offset) \ |
|
966 |
(BOUNDS_CHECKING_OFF_IN_EXPR( \ |
|
967 |
(PTR_LT(m_pos,in) || \ |
|
968 |
(m_off = (lzo_moff_t) PTR_DIFF(ip,m_pos)) <= 0 || \ |
|
969 |
m_off > max_offset) )) |
|
970 |
||
971 |
#else |
|
972 |
||
973 |
#define LZO_CHECK_MPOS_DET(m_pos,m_off,in,ip,max_offset) \ |
|
974 |
(m_off == 0 || \ |
|
975 |
((m_off = (lzo_moff_t) ((ip)-(in)) - m_off) > max_offset) || \ |
|
976 |
(m_pos = (ip) - (m_off), 0) ) |
|
977 |
||
978 |
#define LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,max_offset) \ |
|
979 |
((lzo_moff_t) ((ip)-(in)) <= m_off || \ |
|
980 |
((m_off = (lzo_moff_t) ((ip)-(in)) - m_off) > max_offset) || \ |
|
981 |
(m_pos = (ip) - (m_off), 0) ) |
|
982 |
||
983 |
#endif |
|
984 |
||
985 |
#if defined(LZO_DETERMINISTIC) |
|
986 |
# define LZO_CHECK_MPOS LZO_CHECK_MPOS_DET |
|
987 |
#else |
|
988 |
# define LZO_CHECK_MPOS LZO_CHECK_MPOS_NON_DET |
|
989 |
#endif |
|
990 |
||
991 |
#ifdef __cplusplus |
|
992 |
} |
|
993 |
#endif |
|
994 |
||
995 |
#endif |
|
996 |
||
997 |
#endif |
|
998 |
||
999 |
#endif |
|
1000 |
||
1001 |
#define DO_COMPRESS lzo1x_1_compress |
|
1002 |
||
1003 |
static |
|
1004 |
lzo_uint do_compress ( const lzo_byte *in , lzo_uint in_len, |
|
1005 |
lzo_byte *out, lzo_uintp out_len, |
|
1006 |
lzo_voidp wrkmem ) |
|
1007 |
{ |
|
1008 |
register const lzo_byte *ip; |
|
1009 |
lzo_byte *op; |
|
1010 |
const lzo_byte * const in_end = in + in_len; |
|
1011 |
const lzo_byte * const ip_end = in + in_len - M2_MAX_LEN - 5; |
|
1012 |
const lzo_byte *ii; |
|
1013 |
lzo_dict_p const dict = (lzo_dict_p) wrkmem; |
|
1014 |
||
1015 |
op = out; |
|
1016 |
ip = in; |
|
1017 |
ii = ip; |
|
1018 |
||
1019 |
ip += 4; |
|
1020 |
for (;;) |
|
1021 |
{ |
|
1022 |
register const lzo_byte *m_pos; |
|
1023 |
lzo_moff_t m_off; |
|
1024 |
lzo_uint m_len; |
|
1025 |
lzo_uint dindex; |
|
1026 |
||
1027 |
DINDEX1(dindex,ip); |
|
1028 |
GINDEX(m_pos,m_off,dict,dindex,in); |
|
1029 |
if (LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,M4_MAX_OFFSET)) |
|
1030 |
goto literal; |
|
1031 |
if (m_off <= M2_MAX_OFFSET || m_pos[3] == ip[3]) |
|
1032 |
goto try_match; |
|
1033 |
DINDEX2(dindex,ip); |
|
1034 |
GINDEX(m_pos,m_off,dict,dindex,in); |
|
1035 |
if (LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,M4_MAX_OFFSET)) |
|
1036 |
goto literal; |
|
1037 |
if (m_off <= M2_MAX_OFFSET || m_pos[3] == ip[3]) |
|
1038 |
goto try_match; |
|
1039 |
goto literal; |
|
1040 |
||
1041 |
try_match: |
|
1042 |
#if 1 && defined(LZO_UNALIGNED_OK_2) |
|
1043 |
if (* (const lzo_ushortp) m_pos != * (const lzo_ushortp) ip) |
|
1044 |
#else |
|
1045 |
if (m_pos[0] != ip[0] || m_pos[1] != ip[1]) |
|
1046 |
#endif |
|
1047 |
{ |
|
1048 |
} |
|
1049 |
else |
|
1050 |
{ |
|
1051 |
if (m_pos[2] == ip[2]) |
|
1052 |
{ |
|
1053 |
goto match; |
|
1054 |
} |
|
1055 |
} |
|
1056 |
||
1057 |
literal: |
|
1058 |
UPDATE_I(dict,0,dindex,ip,in); |
|
1059 |
++ip; |
|
1060 |
if (ip >= ip_end) |
|
1061 |
break; |
|
1062 |
continue; |
|
1063 |
||
1064 |
match: |
|
1065 |
UPDATE_I(dict,0,dindex,ip,in); |
|
1066 |
if (pd(ip,ii) > 0) |
|
1067 |
{ |
|
1068 |
register lzo_uint t = pd(ip,ii); |
|
1069 |
||
1070 |
if (t <= 3) |
|
1071 |
{ |
|
1072 |
assert(op - 2 > out); |
|
1073 |
op[-2] |= LZO_BYTE(t); |
|
1074 |
} |
|
1075 |
else if (t <= 18) |
|
1076 |
*op++ = LZO_BYTE(t - 3); |
|
1077 |
else |
|
1078 |
{ |
|
1079 |
register lzo_uint tt = t - 18; |
|
1080 |
||
1081 |
*op++ = 0; |
|
1082 |
while (tt > 255) |
|
1083 |
{ |
|
1084 |
tt -= 255; |
|
1085 |
*op++ = 0; |
|
1086 |
} |
|
1087 |
assert(tt > 0); |
|
1088 |
*op++ = LZO_BYTE(tt); |
|
1089 |
} |
|
1090 |
do *op++ = *ii++; while (--t > 0); |
|
1091 |
} |
|
1092 |
||
1093 |
assert(ii == ip); |
|
1094 |
ip += 3; |
|
1095 |
if (m_pos[3] != *ip++ || m_pos[4] != *ip++ || m_pos[5] != *ip++ || |
|
1096 |
m_pos[6] != *ip++ || m_pos[7] != *ip++ || m_pos[8] != *ip++) { |
|
1097 |
||
1098 |
--ip; |
|
1099 |
m_len = ip - ii; |
|
1100 |
assert(m_len >= 3); assert(m_len <= M2_MAX_LEN); |
|
1101 |
||
1102 |
if (m_off <= M2_MAX_OFFSET) |
|
1103 |
{ |
|
1104 |
m_off -= 1; |
|
1105 |
*op++ = LZO_BYTE(((m_len - 1) << 5) | ((m_off & 7) << 2)); |
|
1106 |
*op++ = LZO_BYTE(m_off >> 3); |
|
1107 |
} |
|
1108 |
else if (m_off <= M3_MAX_OFFSET) |
|
1109 |
{ |
|
1110 |
m_off -= 1; |
|
1111 |
*op++ = LZO_BYTE(M3_MARKER | (m_len - 2)); |
|
1112 |
goto m3_m4_offset; |
|
1113 |
} |
|
1114 |
else |
|
1115 |
{ |
|
1116 |
m_off -= 0x4000; |
|
1117 |
assert(m_off > 0); assert(m_off <= 0x7fff); |
|
1118 |
*op++ = LZO_BYTE(M4_MARKER | |
|
1119 |
((m_off & 0x4000) >> 11) | (m_len - 2)); |
|
1120 |
goto m3_m4_offset; |
|
1121 |
} |
|
1122 |
} |
|
1123 |
else |
|
1124 |
{ |
|
1125 |
{ |
|
1126 |
const lzo_byte *end = in_end; |
|
1127 |
const lzo_byte *m = m_pos + M2_MAX_LEN + 1; |
|
1128 |
while (ip < end && *m == *ip) |
|
1129 |
m++, ip++; |
|
1130 |
m_len = (ip - ii); |
|
1131 |
} |
|
1132 |
assert(m_len > M2_MAX_LEN); |
|
1133 |
||
1134 |
if (m_off <= M3_MAX_OFFSET) |
|
1135 |
{ |
|
1136 |
m_off -= 1; |
|
1137 |
if (m_len <= 33) |
|
1138 |
*op++ = LZO_BYTE(M3_MARKER | (m_len - 2)); |
|
1139 |
else |
|
1140 |
{ |
|
1141 |
m_len -= 33; |
|
1142 |
*op++ = M3_MARKER | 0; |
|
1143 |
goto m3_m4_len; |
|
1144 |
} |
|
1145 |
} |
|
1146 |
else |
|
1147 |
{ |
|
1148 |
m_off -= 0x4000; |
|
1149 |
assert(m_off > 0); assert(m_off <= 0x7fff); |
|
1150 |
if (m_len <= M4_MAX_LEN) |
|
1151 |
*op++ = LZO_BYTE(M4_MARKER | |
|
1152 |
((m_off & 0x4000) >> 11) | (m_len - 2)); |
|
1153 |
else |
|
1154 |
{ |
|
1155 |
m_len -= M4_MAX_LEN; |
|
1156 |
*op++ = LZO_BYTE(M4_MARKER | ((m_off & 0x4000) >> 11)); |
|
1157 |
m3_m4_len: |
|
1158 |
while (m_len > 255) |
|
1159 |
{ |
|
1160 |
m_len -= 255; |
|
1161 |
*op++ = 0; |
|
1162 |
} |
|
1163 |
assert(m_len > 0); |
|
1164 |
*op++ = LZO_BYTE(m_len); |
|
1165 |
} |
|
1166 |
} |
|
1167 |
||
1168 |
m3_m4_offset: |
|
1169 |
*op++ = LZO_BYTE((m_off & 63) << 2); |
|
1170 |
*op++ = LZO_BYTE(m_off >> 6); |
|
1171 |
} |
|
1172 |
||
1173 |
ii = ip; |
|
1174 |
if (ip >= ip_end) |
|
1175 |
break; |
|
1176 |
} |
|
1177 |
||
1178 |
*out_len = op - out; |
|
1179 |
return pd(in_end,ii); |
|
1180 |
} |
|
1181 |
||
1182 |
LZO_PUBLIC(int) |
|
1183 |
DO_COMPRESS ( const lzo_byte *in , lzo_uint in_len, |
|
1184 |
lzo_byte *out, lzo_uintp out_len, |
|
1185 |
lzo_voidp wrkmem ) |
|
1186 |
{ |
|
1187 |
lzo_byte *op = out; |
|
1188 |
lzo_uint t; |
|
1189 |
||
1190 |
if (in_len <= M2_MAX_LEN + 5) |
|
1191 |
t = in_len; |
|
1192 |
else |
|
1193 |
{ |
|
1194 |
t = do_compress(in,in_len,op,out_len,wrkmem); |
|
1195 |
op += *out_len; |
|
1196 |
} |
|
1197 |
||
1198 |
if (t > 0) |
|
1199 |
{ |
|
1200 |
const lzo_byte *ii = in + in_len - t; |
|
1201 |
||
1202 |
if (op == out && t <= 238) |
|
1203 |
*op++ = LZO_BYTE(17 + t); |
|
1204 |
else if (t <= 3) |
|
1205 |
op[-2] |= LZO_BYTE(t); |
|
1206 |
else if (t <= 18) |
|
1207 |
*op++ = LZO_BYTE(t - 3); |
|
1208 |
else |
|
1209 |
{ |
|
1210 |
lzo_uint tt = t - 18; |
|
1211 |
||
1212 |
*op++ = 0; |
|
1213 |
while (tt > 255) |
|
1214 |
{ |
|
1215 |
tt -= 255; |
|
1216 |
*op++ = 0; |
|
1217 |
} |
|
1218 |
assert(tt > 0); |
|
1219 |
*op++ = LZO_BYTE(tt); |
|
1220 |
} |
|
1221 |
do *op++ = *ii++; while (--t > 0); |
|
1222 |
} |
|
1223 |
||
1224 |
*op++ = M4_MARKER | 1; |
|
1225 |
*op++ = 0; |
|
1226 |
*op++ = 0; |
|
1227 |
||
1228 |
*out_len = op - out; |
|
1229 |
return LZO_E_OK; |
|
1230 |
} |
|
1231 |
||
1232 |
#undef do_compress |
|
1233 |
#undef DO_COMPRESS |
|
1234 |
#undef LZO_HASH |
|
1235 |
||
1236 |
#undef LZO_TEST_DECOMPRESS_OVERRUN |
|
1237 |
#undef LZO_TEST_DECOMPRESS_OVERRUN_INPUT |
|
1238 |
#undef LZO_TEST_DECOMPRESS_OVERRUN_OUTPUT |
|
1239 |
#undef LZO_TEST_DECOMPRESS_OVERRUN_LOOKBEHIND |
|
1240 |
#undef DO_DECOMPRESS |
|
1241 |
#define DO_DECOMPRESS lzo1x_decompress |
|
1242 |
||
1243 |
#if defined(LZO_TEST_DECOMPRESS_OVERRUN) |
|
1244 |
# if !defined(LZO_TEST_DECOMPRESS_OVERRUN_INPUT) |
|
1245 |
# define LZO_TEST_DECOMPRESS_OVERRUN_INPUT 2 |
|
1246 |
# endif |
|
1247 |
# if !defined(LZO_TEST_DECOMPRESS_OVERRUN_OUTPUT) |
|
1248 |
# define LZO_TEST_DECOMPRESS_OVERRUN_OUTPUT 2 |
|
1249 |
# endif |
|
1250 |
# if !defined(LZO_TEST_DECOMPRESS_OVERRUN_LOOKBEHIND) |
|
1251 |
# define LZO_TEST_DECOMPRESS_OVERRUN_LOOKBEHIND |
|
1252 |
# endif |
|
1253 |
#endif |
|
1254 |
||
1255 |
#undef TEST_IP |
|
1256 |
#undef TEST_OP |
|
1257 |
#undef TEST_LOOKBEHIND |
|
1258 |
#undef NEED_IP |
|
1259 |
#undef NEED_OP |
|
1260 |
#undef HAVE_TEST_IP |
|
1261 |
#undef HAVE_TEST_OP |
|
1262 |
#undef HAVE_NEED_IP |
|
1263 |
#undef HAVE_NEED_OP |
|
1264 |
#undef HAVE_ANY_IP |
|
1265 |
#undef HAVE_ANY_OP |
|
1266 |
||
1267 |
#if defined(LZO_TEST_DECOMPRESS_OVERRUN_INPUT) |
|
1268 |
# if (LZO_TEST_DECOMPRESS_OVERRUN_INPUT >= 1) |
|
1269 |
# define TEST_IP (ip < ip_end) |
|
1270 |
# endif |
|
1271 |
# if (LZO_TEST_DECOMPRESS_OVERRUN_INPUT >= 2) |
|
1272 |
# define NEED_IP(x) \ |
|
1273 |
if ((lzo_uint)(ip_end - ip) < (lzo_uint)(x)) goto input_overrun |
|
1274 |
# endif |
|
1275 |
#endif |
|
1276 |
||
1277 |
#if defined(LZO_TEST_DECOMPRESS_OVERRUN_OUTPUT) |
|
1278 |
# if (LZO_TEST_DECOMPRESS_OVERRUN_OUTPUT >= 1) |
|
1279 |
# define TEST_OP (op <= op_end) |
|
1280 |
# endif |
|
1281 |
# if (LZO_TEST_DECOMPRESS_OVERRUN_OUTPUT >= 2) |
|
1282 |
# undef TEST_OP |
|
1283 |
# define NEED_OP(x) \ |
|
1284 |
if ((lzo_uint)(op_end - op) < (lzo_uint)(x)) goto output_overrun |
|
1285 |
# endif |
|
1286 |
#endif |
|
1287 |
||
1288 |
#if defined(LZO_TEST_DECOMPRESS_OVERRUN_LOOKBEHIND) |
|
1289 |
# define TEST_LOOKBEHIND(m_pos,out) if (m_pos < out) goto lookbehind_overrun |
|
1290 |
#else |
|
1291 |
# define TEST_LOOKBEHIND(m_pos,op) ((void) 0) |
|
1292 |
#endif |
|
1293 |
||
1294 |
#if !defined(LZO_EOF_CODE) && !defined(TEST_IP) |
|
1295 |
# define TEST_IP (ip < ip_end) |
|
1296 |
#endif |
|
1297 |
||
1298 |
#if defined(TEST_IP) |
|
1299 |
# define HAVE_TEST_IP |
|
1300 |
#else |
|
1301 |
# define TEST_IP 1 |
|
1302 |
#endif |
|
1303 |
#if defined(TEST_OP) |
|
1304 |
# define HAVE_TEST_OP |
|
1305 |
#else |
|
1306 |
# define TEST_OP 1 |
|
1307 |
#endif |
|
1308 |
||
1309 |
#if defined(NEED_IP) |
|
1310 |
# define HAVE_NEED_IP |
|
1311 |
#else |
|
1312 |
# define NEED_IP(x) ((void) 0) |
|
1313 |
#endif |
|
1314 |
#if defined(NEED_OP) |
|
1315 |
# define HAVE_NEED_OP |
|
1316 |
#else |
|
1317 |
# define NEED_OP(x) ((void) 0) |
|
1318 |
#endif |
|
1319 |
||
1320 |
#if defined(HAVE_TEST_IP) || defined(HAVE_NEED_IP) |
|
1321 |
# define HAVE_ANY_IP |
|
1322 |
#endif |
|
1323 |
#if defined(HAVE_TEST_OP) || defined(HAVE_NEED_OP) |
|
1324 |
# define HAVE_ANY_OP |
|
1325 |
#endif |
|
1326 |
||
1327 |
#undef __COPY4 |
|
1328 |
#define __COPY4(dst,src) * (lzo_uint32p)(dst) = * (const lzo_uint32p)(src) |
|
1329 |
||
1330 |
#undef COPY4 |
|
1331 |
#if defined(LZO_UNALIGNED_OK_4) |
|
1332 |
# define COPY4(dst,src) __COPY4(dst,src) |
|
1333 |
#elif defined(LZO_ALIGNED_OK_4) |
|
1334 |
# define COPY4(dst,src) __COPY4((lzo_ptr_t)(dst),(lzo_ptr_t)(src)) |
|
1335 |
#endif |
|
1336 |
||
1337 |
#if defined(DO_DECOMPRESS) |
|
1338 |
LZO_PUBLIC(int) |
|
1339 |
DO_DECOMPRESS ( const lzo_byte *in , lzo_uint in_len, |
|
1340 |
lzo_byte *out, lzo_uintp out_len, |
|
1341 |
lzo_voidp wrkmem ) |
|
1342 |
#endif |
|
1343 |
{ |
|
1344 |
register lzo_byte *op; |
|
1345 |
register const lzo_byte *ip; |
|
1346 |
register lzo_uint t; |
|
1347 |
register const lzo_byte *m_pos; |
|
1348 |
||
1349 |
const lzo_byte * const ip_end = in + in_len; |
|
1350 |
#if defined(HAVE_ANY_OP) |
|
1351 |
lzo_byte * const op_end = out + *out_len; |
|
1352 |
#endif |
|
1353 |
||
1354 |
LZO_UNUSED(wrkmem); |
|
1355 |
||
1356 |
*out_len = 0; |
|
1357 |
||
1358 |
op = out; |
|
1359 |
ip = in; |
|
1360 |
||
1361 |
if (*ip > 17) |
|
1362 |
{ |
|
1363 |
t = *ip++ - 17; |
|
1364 |
if (t < 4) |
|
1365 |
goto match_next; |
|
1366 |
assert(t > 0); NEED_OP(t); NEED_IP(t+1); |
|
1367 |
do *op++ = *ip++; while (--t > 0); |
|
1368 |
goto first_literal_run; |
|
1369 |
} |
|
1370 |
||
1371 |
while (TEST_IP && TEST_OP) |
|
1372 |
{ |
|
1373 |
t = *ip++; |
|
1374 |
if (t >= 16) |
|
1375 |
goto match; |
|
1376 |
if (t == 0) |
|
1377 |
{ |
|
1378 |
NEED_IP(1); |
|
1379 |
while (*ip == 0) |
|
1380 |
{ |
|
1381 |
t += 255; |
|
1382 |
ip++; |
|
1383 |
NEED_IP(1); |
|
1384 |
} |
|
1385 |
t += 15 + *ip++; |
|
1386 |
} |
|
1387 |
assert(t > 0); NEED_OP(t+3); NEED_IP(t+4); |
|
1388 |
#if defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4) |
|
1389 |
#if !defined(LZO_UNALIGNED_OK_4) |
|
1390 |
if (PTR_ALIGNED2_4(op,ip)) |
|
1391 |
{ |
|
1392 |
#endif |
|
1393 |
COPY4(op,ip); |
|
1394 |
op += 4; ip += 4; |
|
1395 |
if (--t > 0) |
|
1396 |
{ |
|
1397 |
if (t >= 4) |
|
1398 |
{ |
|
1399 |
do { |
|
1400 |
COPY4(op,ip); |
|
1401 |
op += 4; ip += 4; t -= 4; |
|
1402 |
} while (t >= 4); |
|
1403 |
if (t > 0) do *op++ = *ip++; while (--t > 0); |
|
1404 |
} |
|
1405 |
else |
|
1406 |
do *op++ = *ip++; while (--t > 0); |
|
1407 |
} |
|
1408 |
#if !defined(LZO_UNALIGNED_OK_4) |
|
1409 |
} |
|
1410 |
else |
|
1411 |
#endif |
|
1412 |
#endif |
|
1413 |
#if !defined(LZO_UNALIGNED_OK_4) |
|
1414 |
{ |
|
1415 |
*op++ = *ip++; *op++ = *ip++; *op++ = *ip++; |
|
1416 |
do *op++ = *ip++; while (--t > 0); |
|
1417 |
} |
|
1418 |
#endif |
|
1419 |
||
1420 |
first_literal_run: |
|
1421 |
||
1422 |
t = *ip++; |
|
1423 |
if (t >= 16) |
|
1424 |
goto match; |
|
1425 |
m_pos = op - (1 + M2_MAX_OFFSET); |
|
1426 |
m_pos -= t >> 2; |
|
1427 |
m_pos -= *ip++ << 2; |
|
1428 |
TEST_LOOKBEHIND(m_pos,out); NEED_OP(3); |
|
1429 |
*op++ = *m_pos++; *op++ = *m_pos++; *op++ = *m_pos; |
|
1430 |
goto match_done; |
|
1431 |
||
1432 |
while (TEST_IP && TEST_OP) |
|
1433 |
{ |
|
1434 |
match: |
|
1435 |
if (t >= 64) |
|
1436 |
{ |
|
1437 |
#if defined(LZO1X) |
|
1438 |
m_pos = op - 1; |
|
1439 |
m_pos -= (t >> 2) & 7; |
|
1440 |
m_pos -= *ip++ << 3; |
|
1441 |
t = (t >> 5) - 1; |
|
1442 |
#endif |
|
1443 |
TEST_LOOKBEHIND(m_pos,out); assert(t > 0); NEED_OP(t+3-1); |
|
1444 |
goto copy_match; |
|
1445 |
} |
|
1446 |
else if (t >= 32) |
|
1447 |
{ |
|
1448 |
t &= 31; |
|
1449 |
if (t == 0) |
|
1450 |
{ |
|
1451 |
NEED_IP(1); |
|
1452 |
while (*ip == 0) |
|
1453 |
{ |
|
1454 |
t += 255; |
|
1455 |
ip++; |
|
1456 |
NEED_IP(1); |
|
1457 |
} |
|
1458 |
t += 31 + *ip++; |
|
1459 |
} |
|
1460 |
#if defined(LZO_UNALIGNED_OK_2) && (LZO_BYTE_ORDER == LZO_LITTLE_ENDIAN) |
|
1461 |
m_pos = op - 1; |
|
1462 |
m_pos -= (* (const lzo_ushortp) ip) >> 2; |
|
1463 |
#else |
|
1464 |
m_pos = op - 1; |
|
1465 |
m_pos -= (ip[0] >> 2) + (ip[1] << 6); |
|
1466 |
#endif |
|
1467 |
ip += 2; |
|
1468 |
} |
|
1469 |
else if (t >= 16) |
|
1470 |
{ |
|
1471 |
m_pos = op; |
|
1472 |
m_pos -= (t & 8) << 11; |
|
1473 |
t &= 7; |
|
1474 |
if (t == 0) |
|
1475 |
{ |
|
1476 |
NEED_IP(1); |
|
1477 |
while (*ip == 0) |
|
1478 |
{ |
|
1479 |
t += 255; |
|
1480 |
ip++; |
|
1481 |
NEED_IP(1); |
|
1482 |
} |
|
1483 |
t += 7 + *ip++; |
|
1484 |
} |
|
1485 |
#if defined(LZO_UNALIGNED_OK_2) && (LZO_BYTE_ORDER == LZO_LITTLE_ENDIAN) |
|
1486 |
m_pos -= (* (const lzo_ushortp) ip) >> 2; |
|
1487 |
#else |
|
1488 |
m_pos -= (ip[0] >> 2) + (ip[1] << 6); |
|
1489 |
#endif |
|
1490 |
ip += 2; |
|
1491 |
if (m_pos == op) |
|
1492 |
goto eof_found; |
|
1493 |
m_pos -= 0x4000; |
|
1494 |
} |
|
1495 |
else |
|
1496 |
{ |
|
1497 |
m_pos = op - 1; |
|
1498 |
m_pos -= t >> 2; |
|
1499 |
m_pos -= *ip++ << 2; |
|
1500 |
TEST_LOOKBEHIND(m_pos,out); NEED_OP(2); |
|
1501 |
*op++ = *m_pos++; *op++ = *m_pos; |
|
1502 |
goto match_done; |
|
1503 |
} |
|
1504 |
||
1505 |
TEST_LOOKBEHIND(m_pos,out); assert(t > 0); NEED_OP(t+3-1); |
|
1506 |
#if defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4) |
|
1507 |
#if !defined(LZO_UNALIGNED_OK_4) |
|
1508 |
if (t >= 2 * 4 - (3 - 1) && PTR_ALIGNED2_4(op,m_pos)) |
|
1509 |
{ |
|
1510 |
assert((op - m_pos) >= 4); |
|
1511 |
#else |
|
1512 |
if (t >= 2 * 4 - (3 - 1) && (op - m_pos) >= 4) |
|
1513 |
{ |
|
1514 |
#endif |
|
1515 |
COPY4(op,m_pos); |
|
1516 |
op += 4; m_pos += 4; t -= 4 - (3 - 1); |
|
1517 |
do { |
|
1518 |
COPY4(op,m_pos); |
|
1519 |
op += 4; m_pos += 4; t -= 4; |
|
1520 |
} while (t >= 4); |
|
1521 |
if (t > 0) do *op++ = *m_pos++; while (--t > 0); |
|
1522 |
} |
|
1523 |
else |
|
1524 |
#endif |
|
1525 |
{ |
|
1526 |
copy_match: |
|
1527 |
*op++ = *m_pos++; *op++ = *m_pos++; |
|
1528 |
do *op++ = *m_pos++; while (--t > 0); |
|
1529 |
} |
|
1530 |
||
1531 |
match_done: |
|
1532 |
t = ip[-2] & 3; |
|
1533 |
if (t == 0) |
|
1534 |
break; |
|
1535 |
||
1536 |
match_next: |
|
1537 |
assert(t > 0); NEED_OP(t); NEED_IP(t+1); |
|
1538 |
do *op++ = *ip++; while (--t > 0); |
|
1539 |
t = *ip++; |
|
1540 |
} |
|
1541 |
} |
|
1542 |
||
1543 |
#if defined(HAVE_TEST_IP) || defined(HAVE_TEST_OP) |
|
1544 |
*out_len = op - out; |
|
1545 |
return LZO_E_EOF_NOT_FOUND; |
|
1546 |
#endif |
|
1547 |
||
1548 |
eof_found: |
|
1549 |
assert(t == 1); |
|
1550 |
*out_len = op - out; |
|
1551 |
return (ip == ip_end ? LZO_E_OK : |
|
1552 |
(ip < ip_end ? LZO_E_INPUT_NOT_CONSUMED : LZO_E_INPUT_OVERRUN)); |
|
1553 |
||
1554 |
#if defined(HAVE_NEED_IP) |
|
1555 |
input_overrun: |
|
1556 |
*out_len = op - out; |
|
1557 |
return LZO_E_INPUT_OVERRUN; |
|
1558 |
#endif |
|
1559 |
||
1560 |
#if defined(HAVE_NEED_OP) |
|
1561 |
output_overrun: |
|
1562 |
*out_len = op - out; |
|
1563 |
return LZO_E_OUTPUT_OVERRUN; |
|
1564 |
#endif |
|
1565 |
||
1566 |
#if defined(LZO_TEST_DECOMPRESS_OVERRUN_LOOKBEHIND) |
|
1567 |
lookbehind_overrun: |
|
1568 |
*out_len = op - out; |
|
1569 |
return LZO_E_LOOKBEHIND_OVERRUN; |
|
1570 |
#endif |
|
1571 |
} |
|
1572 |
||
1573 |
#define LZO_TEST_DECOMPRESS_OVERRUN |
|
1574 |
#undef DO_DECOMPRESS |
|
1575 |
#define DO_DECOMPRESS lzo1x_decompress_safe |
|
1576 |
||
1577 |
#if defined(LZO_TEST_DECOMPRESS_OVERRUN) |
|
1578 |
# if !defined(LZO_TEST_DECOMPRESS_OVERRUN_INPUT) |
|
1579 |
# define LZO_TEST_DECOMPRESS_OVERRUN_INPUT 2 |
|
1580 |
# endif |
|
1581 |
# if !defined(LZO_TEST_DECOMPRESS_OVERRUN_OUTPUT) |
|
1582 |
# define LZO_TEST_DECOMPRESS_OVERRUN_OUTPUT 2 |
|
1583 |
# endif |
|
1584 |
# if !defined(LZO_TEST_DECOMPRESS_OVERRUN_LOOKBEHIND) |
|
1585 |
# define LZO_TEST_DECOMPRESS_OVERRUN_LOOKBEHIND |
|
1586 |
# endif |
|
1587 |
#endif |
|
1588 |
||
1589 |
#undef TEST_IP |
|
1590 |
#undef TEST_OP |
|
1591 |
#undef TEST_LOOKBEHIND |
|
1592 |
#undef NEED_IP |
|
1593 |
#undef NEED_OP |
|
1594 |
#undef HAVE_TEST_IP |
|
1595 |
#undef HAVE_TEST_OP |
|
1596 |
#undef HAVE_NEED_IP |
|
1597 |
#undef HAVE_NEED_OP |
|
1598 |
#undef HAVE_ANY_IP |
|
1599 |
#undef HAVE_ANY_OP |
|
1600 |
||
1601 |
||
1602 |
#if 0 |
|
1603 |
||
1604 |
#if defined(LZO_TEST_DECOMPRESS_OVERRUN_INPUT) |
|
1605 |
# if (LZO_TEST_DECOMPRESS_OVERRUN_INPUT >= 1) |
|
1606 |
# define TEST_IP (ip < ip_end) |
|
1607 |
# endif |
|
1608 |
# if (LZO_TEST_DECOMPRESS_OVERRUN_INPUT >= 2) |
|
1609 |
# define NEED_IP(x) \ |
|
1610 |
if ((lzo_uint)(ip_end - ip) < (lzo_uint)(x)) goto input_overrun |
|
1611 |
# endif |
|
1612 |
#endif |
|
1613 |
||
1614 |
#if defined(LZO_TEST_DECOMPRESS_OVERRUN_OUTPUT) |
|
1615 |
# if (LZO_TEST_DECOMPRESS_OVERRUN_OUTPUT >= 1) |
|
1616 |
# define TEST_OP (op <= op_end) |
|
1617 |
# endif |
|
1618 |
# if (LZO_TEST_DECOMPRESS_OVERRUN_OUTPUT >= 2) |
|
1619 |
# undef TEST_OP |
|
1620 |
# define NEED_OP(x) \ |
|
1621 |
if ((lzo_uint)(op_end - op) < (lzo_uint)(x)) goto output_overrun |
|
1622 |
# endif |
|
1623 |
#endif |
|
1624 |
||
1625 |
#if defined(LZO_TEST_DECOMPRESS_OVERRUN_LOOKBEHIND) |
|
1626 |
# define TEST_LOOKBEHIND(m_pos,out) if (m_pos < out) goto lookbehind_overrun |
|
1627 |
#else |
|
1628 |
# define TEST_LOOKBEHIND(m_pos,op) ((void) 0) |
|
1629 |
#endif |
|
1630 |
||
1631 |
#if !defined(LZO_EOF_CODE) && !defined(TEST_IP) |
|
1632 |
# define TEST_IP (ip < ip_end) |
|
1633 |
#endif |
|
1634 |
||
1635 |
#if defined(TEST_IP) |
|
1636 |
# define HAVE_TEST_IP |
|
1637 |
#else |
|
1638 |
# define TEST_IP 1 |
|
1639 |
#endif |
|
1640 |
#if defined(TEST_OP) |
|
1641 |
# define HAVE_TEST_OP |
|
1642 |
#else |
|
1643 |
# define TEST_OP 1 |
|
1644 |
#endif |
|
1645 |
||
1646 |
#if defined(NEED_IP) |
|
1647 |
# define HAVE_NEED_IP |
|
1648 |
#else |
|
1649 |
# define NEED_IP(x) ((void) 0) |
|
1650 |
#endif |
|
1651 |
#if defined(NEED_OP) |
|
1652 |
# define HAVE_NEED_OP |
|
1653 |
#else |
|
1654 |
# define NEED_OP(x) ((void) 0) |
|
1655 |
#endif |
|
1656 |
||
1657 |
#if defined(HAVE_TEST_IP) || defined(HAVE_NEED_IP) |
|
1658 |
# define HAVE_ANY_IP |
|
1659 |
#endif |
|
1660 |
#if defined(HAVE_TEST_OP) || defined(HAVE_NEED_OP) |
|
1661 |
# define HAVE_ANY_OP |
|
1662 |
#endif |
|
1663 |
||
1664 |
#undef __COPY4 |
|
1665 |
#define __COPY4(dst,src) * (lzo_uint32p)(dst) = * (const lzo_uint32p)(src) |
|
1666 |
||
1667 |
#undef COPY4 |
|
1668 |
#if defined(LZO_UNALIGNED_OK_4) |
|
1669 |
# define COPY4(dst,src) __COPY4(dst,src) |
|
1670 |
#elif defined(LZO_ALIGNED_OK_4) |
|
1671 |
# define COPY4(dst,src) __COPY4((lzo_ptr_t)(dst),(lzo_ptr_t)(src)) |
|
1672 |
#endif |
|
1673 |
||
1674 |
#if defined(DO_DECOMPRESS) |
|
1675 |
LZO_PUBLIC(int) |
|
1676 |
DO_DECOMPRESS ( const lzo_byte *in , lzo_uint in_len, |
|
1677 |
lzo_byte *out, lzo_uintp out_len, |
|
1678 |
lzo_voidp wrkmem ) |
|
1679 |
#endif |
|
1680 |
{ |
|
1681 |
register lzo_byte *op; |
|
1682 |
register const lzo_byte *ip; |
|
1683 |
register lzo_uint t; |
|
1684 |
register const lzo_byte *m_pos; |
|
1685 |
||
1686 |
const lzo_byte * const ip_end = in + in_len; |
|
1687 |
#if defined(HAVE_ANY_OP) |
|
1688 |
lzo_byte * const op_end = out + *out_len; |
|
1689 |
#endif |
|
1690 |
||
1691 |
LZO_UNUSED(wrkmem); |
|
1692 |
||
1693 |
*out_len = 0; |
|
1694 |
||
1695 |
op = out; |
|
1696 |
ip = in; |
|
1697 |
||
1698 |
if (*ip > 17) |
|
1699 |
{ |
|
1700 |
t = *ip++ - 17; |
|
1701 |
if (t < 4) |
|
1702 |
goto match_next; |
|
1703 |
assert(t > 0); NEED_OP(t); NEED_IP(t+1); |
|
1704 |
do *op++ = *ip++; while (--t > 0); |
|
1705 |
goto first_literal_run; |
|
1706 |
} |
|
1707 |
||
1708 |
while (TEST_IP && TEST_OP) |
|
1709 |
{ |
|
1710 |
t = *ip++; |
|
1711 |
if (t >= 16) |
|
1712 |
goto match; |
|
1713 |
if (t == 0) |
|
1714 |
{ |
|
1715 |
NEED_IP(1); |
|
1716 |
while (*ip == 0) |
|
1717 |
{ |
|
1718 |
t += 255; |
|
1719 |
ip++; |
|
1720 |
NEED_IP(1); |
|
1721 |
} |
|
1722 |
t += 15 + *ip++; |
|
1723 |
} |
|
1724 |
assert(t > 0); NEED_OP(t+3); NEED_IP(t+4); |
|
1725 |
#if defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4) |
|
1726 |
#if !defined(LZO_UNALIGNED_OK_4) |
|
1727 |
if (PTR_ALIGNED2_4(op,ip)) |
|
1728 |
{ |
|
1729 |
#endif |
|
1730 |
COPY4(op,ip); |
|
1731 |
op += 4; ip += 4; |
|
1732 |
if (--t > 0) |
|
1733 |
{ |
|
1734 |
if (t >= 4) |
|
1735 |
{ |
|
1736 |
do { |
|
1737 |
COPY4(op,ip); |
|
1738 |
op += 4; ip += 4; t -= 4; |
|
1739 |
} while (t >= 4); |
|
1740 |
if (t > 0) do *op++ = *ip++; while (--t > 0); |
|
1741 |
} |
|
1742 |
else |
|
1743 |
do *op++ = *ip++; while (--t > 0); |
|
1744 |
} |
|
1745 |
#if !defined(LZO_UNALIGNED_OK_4) |
|
1746 |
} |
|
1747 |
else |
|
1748 |
#endif |
|
1749 |
#endif |
|
1750 |
#if !defined(LZO_UNALIGNED_OK_4) |
|
1751 |
{ |
|
1752 |
*op++ = *ip++; *op++ = *ip++; *op++ = *ip++; |
|
1753 |
do *op++ = *ip++; while (--t > 0); |
|
1754 |
} |
|
1755 |
#endif |
|
1756 |
||
1757 |
first_literal_run: |
|
1758 |
||
1759 |
t = *ip++; |
|
1760 |
if (t >= 16) |
|
1761 |
goto match; |
|
1762 |
#if defined(LZO1Z) |
|
1763 |
t = (1 + M2_MAX_OFFSET) + (t << 6) + (*ip++ >> 2); |
|
1764 |
m_pos = op - t; |
|
1765 |
last_m_off = t; |
|
1766 |
#else |
|
1767 |
m_pos = op - (1 + M2_MAX_OFFSET); |
|
1768 |
m_pos -= t >> 2; |
|
1769 |
m_pos -= *ip++ << 2; |
|
1770 |
#endif |
|
1771 |
TEST_LOOKBEHIND(m_pos,out); NEED_OP(3); |
|
1772 |
*op++ = *m_pos++; *op++ = *m_pos++; *op++ = *m_pos; |
|
1773 |
goto match_done; |
|
1774 |
||
1775 |
while (TEST_IP && TEST_OP) |
|
1776 |
{ |
|
1777 |
match: |
|
1778 |
if (t >= 64) |
|
1779 |
{ |
|
1780 |
#if defined(LZO1X) |
|
1781 |
m_pos = op - 1; |
|
1782 |
m_pos -= (t >> 2) & 7; |
|
1783 |
m_pos -= *ip++ << 3; |
|
1784 |
t = (t >> 5) - 1; |
|
1785 |
#elif defined(LZO1Y) |
|
1786 |
m_pos = op - 1; |
|
1787 |
m_pos -= (t >> 2) & 3; |
|
1788 |
m_pos -= *ip++ << 2; |
|
1789 |
t = (t >> 4) - 3; |
|
1790 |
#elif defined(LZO1Z) |
|
1791 |
{ |
|
1792 |
lzo_uint off = t & 0x1f; |
|
1793 |
m_pos = op; |
|
1794 |
if (off >= 0x1c) |
|
1795 |
{ |
|
1796 |
assert(last_m_off > 0); |
|
1797 |
m_pos -= last_m_off; |
|
1798 |
} |
|
1799 |
else |
|
1800 |
{ |
|
1801 |
off = 1 + (off << 6) + (*ip++ >> 2); |
|
1802 |
m_pos -= off; |
|
1803 |
last_m_off = off; |
|
1804 |
} |
|
1805 |
} |
|
1806 |
t = (t >> 5) - 1; |
|
1807 |
#endif |
|
1808 |
TEST_LOOKBEHIND(m_pos,out); assert(t > 0); NEED_OP(t+3-1); |
|
1809 |
goto copy_match; |
|
1810 |
} |
|
1811 |
else if (t >= 32) |
|
1812 |
{ |
|
1813 |
t &= 31; |
|
1814 |
if (t == 0) |
|
1815 |
{ |
|
1816 |
NEED_IP(1); |
|
1817 |
while (*ip == 0) |
|
1818 |
{ |
|
1819 |
t += 255; |
|
1820 |
ip++; |
|
1821 |
NEED_IP(1); |
|
1822 |
} |
|
1823 |
t += 31 + *ip++; |
|
1824 |
} |
|
1825 |
#if defined(LZO1Z) |
|
1826 |
{ |
|
1827 |
lzo_uint off = 1 + (ip[0] << 6) + (ip[1] >> 2); |
|
1828 |
m_pos = op - off; |
|
1829 |
last_m_off = off; |
|
1830 |
} |
|
1831 |
#elif defined(LZO_UNALIGNED_OK_2) && (LZO_BYTE_ORDER == LZO_LITTLE_ENDIAN) |
|
1832 |
m_pos = op - 1; |
|
1833 |
m_pos -= (* (const lzo_ushortp) ip) >> 2; |
|
1834 |
#else |
|
1835 |
m_pos = op - 1; |
|
1836 |
m_pos -= (ip[0] >> 2) + (ip[1] << 6); |
|
1837 |
#endif |
|
1838 |
ip += 2; |
|
1839 |
} |
|
1840 |
else if (t >= 16) |
|
1841 |
{ |
|
1842 |
m_pos = op; |
|
1843 |
m_pos -= (t & 8) << 11; |
|
1844 |
t &= 7; |
|
1845 |
if (t == 0) |
|
1846 |
{ |
|
1847 |
NEED_IP(1); |
|
1848 |
while (*ip == 0) |
|
1849 |
{ |
|
1850 |
t += 255; |
|
1851 |
ip++; |
|
1852 |
NEED_IP(1); |
|
1853 |
} |
|
1854 |
t += 7 + *ip++; |
|
1855 |
} |
|
1856 |
#if defined(LZO1Z) |
|
1857 |
m_pos -= (ip[0] << 6) + (ip[1] >> 2); |
|
1858 |
#elif defined(LZO_UNALIGNED_OK_2) && (LZO_BYTE_ORDER == LZO_LITTLE_ENDIAN) |
|
1859 |
m_pos -= (* (const lzo_ushortp) ip) >> 2; |
|
1860 |
#else |
|
1861 |
m_pos -= (ip[0] >> 2) + (ip[1] << 6); |
|
1862 |
#endif |
|
1863 |
ip += 2; |
|
1864 |
if (m_pos == op) |
|
1865 |
goto eof_found; |
|
1866 |
m_pos -= 0x4000; |
|
1867 |
#if defined(LZO1Z) |
|
1868 |
last_m_off = op - m_pos; |
|
1869 |
#endif |
|
1870 |
} |
|
1871 |
else |
|
1872 |
{ |
|
1873 |
#if defined(LZO1Z) |
|
1874 |
t = 1 + (t << 6) + (*ip++ >> 2); |
|
1875 |
m_pos = op - t; |
|
1876 |
last_m_off = t; |
|
1877 |
#else |
|
1878 |
m_pos = op - 1; |
|
1879 |
m_pos -= t >> 2; |
|
1880 |
m_pos -= *ip++ << 2; |
|
1881 |
#endif |
|
1882 |
TEST_LOOKBEHIND(m_pos,out); NEED_OP(2); |
|
1883 |
*op++ = *m_pos++; *op++ = *m_pos; |
|
1884 |
goto match_done; |
|
1885 |
} |
|
1886 |
||
1887 |
TEST_LOOKBEHIND(m_pos,out); assert(t > 0); NEED_OP(t+3-1); |
|
1888 |
#if defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4) |
|
1889 |
#if !defined(LZO_UNALIGNED_OK_4) |
|
1890 |
if (t >= 2 * 4 - (3 - 1) && PTR_ALIGNED2_4(op,m_pos)) |
|
1891 |
{ |
|
1892 |
assert((op - m_pos) >= 4); |
|
1893 |
#else |
|
1894 |
if (t >= 2 * 4 - (3 - 1) && (op - m_pos) >= 4) |
|
1895 |
{ |
|
1896 |
#endif |
|
1897 |
COPY4(op,m_pos); |
|
1898 |
op += 4; m_pos += 4; t -= 4 - (3 - 1); |
|
1899 |
do { |
|
1900 |
COPY4(op,m_pos); |
|
1901 |
op += 4; m_pos += 4; t -= 4; |
|
1902 |
} while (t >= 4); |
|
1903 |
if (t > 0) do *op++ = *m_pos++; while (--t > 0); |
|
1904 |
} |
|
1905 |
else |
|
1906 |
#endif |
|
1907 |
{ |
|
1908 |
copy_match: |
|
1909 |
*op++ = *m_pos++; *op++ = *m_pos++; |
|
1910 |
do *op++ = *m_pos++; while (--t > 0); |
|
1911 |
} |
|
1912 |
||
1913 |
||
1914 |
match_done: |
|
1915 |
#if defined(LZO1Z) |
|
1916 |
t = ip[-1] & 3; |
|
1917 |
#else |
|
1918 |
t = ip[-2] & 3; |
|
1919 |
#endif |
|
1920 |
if (t == 0) |
|
1921 |
break; |
|
1922 |
||
1923 |
match_next: |
|
1924 |
assert(t > 0); NEED_OP(t); NEED_IP(t+1); |
|
1925 |
do *op++ = *ip++; while (--t > 0); |
|
1926 |
t = *ip++; |
|
1927 |
} |
|
1928 |
} |
|
1929 |
||
1930 |
#if defined(HAVE_TEST_IP) || defined(HAVE_TEST_OP) |
|
1931 |
*out_len = op - out; |
|
1932 |
return LZO_E_EOF_NOT_FOUND; |
|
1933 |
#endif |
|
1934 |
||
1935 |
eof_found: |
|
1936 |
assert(t == 1); |
|
1937 |
*out_len = op - out; |
|
1938 |
return (ip == ip_end ? LZO_E_OK : |
|
1939 |
(ip < ip_end ? LZO_E_INPUT_NOT_CONSUMED : LZO_E_INPUT_OVERRUN)); |
|
1940 |
||
1941 |
#if defined(HAVE_NEED_IP) |
|
1942 |
input_overrun: |
|
1943 |
*out_len = op - out; |
|
1944 |
return LZO_E_INPUT_OVERRUN; |
|
1945 |
#endif |
|
1946 |
||
1947 |
#if defined(HAVE_NEED_OP) |
|
1948 |
output_overrun: |
|
1949 |
*out_len = op - out; |
|
1950 |
return LZO_E_OUTPUT_OVERRUN; |
|
1951 |
#endif |
|
1952 |
||
1953 |
#if defined(LZO_TEST_DECOMPRESS_OVERRUN_LOOKBEHIND) |
|
1954 |
lookbehind_overrun: |
|
1955 |
*out_len = op - out; |
|
1956 |
return LZO_E_LOOKBEHIND_OVERRUN; |
|
1957 |
#endif |
|
1958 |
} |
|
1959 |
||
1960 |
#endif |
|
1961 |
||
1962 |
/***** End of minilzo.c *****/ |
|
1963 |
||
1964 |