-
Notifications
You must be signed in to change notification settings - Fork 2
/
WSFComp.c
3022 lines (2615 loc) · 65.8 KB
/
WSFComp.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/********************************************************************
**
** Copyright (c) 1989 Mark R. Nelson
**
** LZW data compression/expansion demonstration program.
**
** April 13, 1989
**
*****************************************************************************/
///
/// \file WSFComp.c Compression Source
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <memory.h>
#include <string.h>
#include "WSFComp.h"
#ifdef ITCOMPSUPPORT
typedef unsigned char byte;
typedef unsigned short word;
typedef unsigned int dword;
byte *g_b;
unsigned int g_p;
unsigned int g_s;
#define BYTE byte
static unsigned char *sourcebuf = NULL;
static unsigned char *sourcepos = NULL;
static unsigned char *sourceend;
static int rembits = 0;
int getiw (void)
{
int l, h;
l = (*(byte*)g_b);
h = (*(byte*)g_b+1);
g_p+=2;
g_b+=2;
return l | (h << 8);
}
static int readblock(void)
{
int size;
size = getiw();
if (size < 0)
return size;
sourcebuf = malloc(size);
if (!sourcebuf)
return -1;
memcpy(sourcebuf,g_b,size);
g_p+=size;
g_b+=size;
sourcepos = sourcebuf;
sourceend = sourcebuf + size;
rembits = 8;
return 0;
}
static void freeblock(void)
{
free(sourcebuf);
sourceend = NULL;
sourcepos = NULL;
sourcebuf = NULL;
}
static int readbits(int bitwidth)
{
int val = 0;
int b = 0;
if (sourcepos >= sourceend) return val;
while (bitwidth > rembits) {
val |= *sourcepos++ << b;
if (sourcepos >= sourceend) return val;
b += rembits;
bitwidth -= rembits;
rembits = 8;
}
val |= (*sourcepos & ((1 << bitwidth) - 1)) << b;
*sourcepos >>= bitwidth;
rembits -= bitwidth;
return val;
}
/** WARNING - do we even need to pass `right`? */
/** WARNING - why bother memsetting at all? The whole array is written... */
/** WARNING - check for endianness safety */
unsigned int wsf_decompress8(unsigned char *f, signed char *left, signed char *right, int len, int cmwt)
{
int blocklen, blockpos;
byte bitwidth;
word val;
char d1, d2;
g_b = f;
g_p = 0;
memset(left, 0, len * sizeof(*left));
if (right) {
memset(right, 0, len * sizeof(*right));
len <<= 1;
}
while (len > 0) {
//Read a block of compressed data:
if (readblock())
return g_b-f;
//Set up a few variables
blocklen = (len < 0x8000) ? len : 0x8000; //Max block length is 0x8000 bytes
blockpos = 0;
bitwidth = 9;
d1 = d2 = 0;
//Start the decompression:
while (blockpos < blocklen) {
//Read a value:
val = (word)readbits(bitwidth);
//Check for bit width change:
if (bitwidth < 7) { //Method 1:
if (val == (1 << (bitwidth - 1))) {
val = (word)readbits(3) + 1;
bitwidth = (val < bitwidth) ? val : val + 1;
continue;
}
}
else if (bitwidth < 9) { //Method 2
byte border = (0xFF >> (9 - bitwidth)) - 4;
if (val > border && val <= (border + 8)) {
val -= border;
bitwidth = (val < bitwidth) ? val : val + 1;
continue;
}
}
else if (bitwidth == 9) { //Method 3
if (val & 0x100) {
bitwidth = (val + 1) & 0xFF;
continue;
}
}
else { //Illegal width, abort ?
freeblock();
return g_b-f;
}
//Expand the value to signed byte:
{
char v; //The sample value:
if (bitwidth < 8) {
byte shift = 8 - bitwidth;
v = (val << shift);
v >>= shift;
}
else
v = (char)val;
//And integrate the sample value
//(It always has to end with integration doesn't it ? ;-)
d1 += v;
d2 += d1;
}
//Store !
/* Version 2.15 was an unofficial version with hacked compression
* code. Yay, better compression :D
*/
if (right && (len & 1))
*right++ = (int)(signed char)(cmwt == 0x215 ? d2 : d1) << 8;
else
*left++ = (int)(signed char)(cmwt == 0x215 ? d2 : d1) << 8;
len--;
blockpos++;
}
freeblock();
}
return g_b-f;
}
unsigned int wsf_decompress16(unsigned char *f, signed char *left, signed char *right, int len, int cmwt)
{
int blocklen, blockpos;
byte bitwidth;
int val;
short d1, d2;
g_b = f;
g_p = 0;
memset(left, 0, len * sizeof(*left));
if (right) {
memset(right, 0, len * sizeof(*right));
len <<= 1;
}
while (len > 0) {
//Read a block of compressed data:
if (readblock())
return g_b-f;
//Set up a few variables
blocklen = (len < 0x4000) ? len : 0x4000; // Max block length is 0x4000 bytes
blockpos = 0;
bitwidth = 17;
d1 = d2 = 0;
//Start the decompression:
while (blockpos < blocklen) {
val = readbits(bitwidth);
//Check for bit width change:
if (bitwidth < 7) { //Method 1:
if (val == (1 << (bitwidth - 1))) {
val = readbits(4) + 1;
bitwidth = (val < bitwidth) ? val : val + 1;
continue;
}
}
else if (bitwidth < 17) { //Method 2
word border = (0xFFFF >> (17 - bitwidth)) - 8;
if (val > border && val <= (border + 16)) {
val -= border;
bitwidth = val < bitwidth ? val : val + 1;
continue;
}
}
else if (bitwidth == 17) { //Method 3
if (val & 0x10000) {
bitwidth = (val + 1) & 0xFF;
continue;
}
}
else { //Illegal width, abort ?
freeblock();
return g_b-f;
}
//Expand the value to signed byte:
{
short v; //The sample value:
if (bitwidth < 16) {
byte shift = 16 - bitwidth;
v = (short)(val << shift);
v >>= shift;
}
else
v = (short)val;
//And integrate the sample value
//(It always has to end with integration doesn't it ? ;-)
d1 += v;
d2 += d1;
}
//Store !
/* Version 2.15 was an unofficial version with hacked compression
* code. Yay, better compression :D
*/
if (right && (len & 1))
*right++ = (int)(signed short)(cmwt == 0x215 ? d2 : d1);
else
*left++ = (int)(signed short)(cmwt == 0x215 ? d2 : d1);
len--;
blockpos++;
}
freeblock();
}
return g_b-f;
}
unsigned int ITReadBits(unsigned int *bitbuf, unsigned int *bitnum, byte *ibuf, char n)
//-----------------------------------------------------------------
{
dword retval = 0;
unsigned int i = n;
if (n > 0)
{
do
{
if (!bitnum)
{
bitbuf[0] = *ibuf++;
bitnum[0] = 8;
}
retval >>= 1;
retval |= bitbuf[0] << 31;
bitbuf[0] >>= 1;
bitnum--;
i--;
} while (i);
i = n;
}
return (retval >> (32-i));
}
#define IT215_SUPPORT
unsigned int wsfITUnpack8Bit(char *pSample, unsigned int dwLen, byte * lpMemFile, unsigned int dwMemLength, int b215)
//-------------------------------------------------------------------------------------------
{
char *pDst = pSample;
byte *pSrc = lpMemFile;
unsigned int wHdr = 0;
unsigned int wCount = 0;
unsigned int bitbuf = 0;
unsigned int bitnum = 0;
BYTE bLeft = 0, bTemp = 0, bTemp2 = 0;
memset(pSample,0,dwLen);
while (dwLen)
{
unsigned int dwPos;
unsigned int d;
if (!wCount)
{
wCount = 0x8000;
wHdr = *((short*)pSrc);
pSrc += 2;
bLeft = 9;
bTemp = bTemp2 = 0;
bitbuf = bitnum = 0;
}
d = wCount;
if (d > dwLen) d = dwLen;
// Unpacking
dwPos = 0;
do
{
word wBits = (word)ITReadBits(&bitbuf, &bitnum, pSrc, bLeft);
if (bLeft < 7)
{
unsigned int i = 1 << (bLeft-1);
unsigned int j = wBits & 0xFFFF;
if (i != j) goto UnpackByte;
wBits = (word)(ITReadBits(&bitbuf, &bitnum, pSrc, 3) + 1) & 0xFF;
bLeft = ((BYTE)wBits < bLeft) ? (BYTE)wBits : (BYTE)((wBits+1) & 0xFF);
goto Next;
}
if (bLeft < 9)
{
word i = (0xFF >> (9 - bLeft)) + 4;
word j = i - 8;
if ((wBits <= j) || (wBits > i)) goto UnpackByte;
wBits -= j;
bLeft = ((BYTE)(wBits & 0xFF) < bLeft) ? (BYTE)(wBits & 0xFF) : (BYTE)((wBits+1) & 0xFF);
goto Next;
}
if (bLeft >= 10) goto SkipByte;
if (wBits >= 256)
{
bLeft = (BYTE)(wBits + 1) & 0xFF;
goto Next;
}
UnpackByte:
if (bLeft < 8)
{
BYTE shift = 8 - bLeft;
char c = (char)(wBits << shift);
c >>= shift;
wBits = (word)c;
}
wBits += bTemp;
bTemp = (BYTE)wBits;
bTemp2 += bTemp;
#ifdef IT215_SUPPORT
pDst[dwPos] = (b215) ? bTemp2 : bTemp;
#else
pDst[dwPos] = bTemp;
#endif
SkipByte:
dwPos++;
Next:
if (pSrc >= lpMemFile+dwMemLength+1) return 0;
} while (dwPos < d);
// Move On
wCount -= d;
dwLen -= d;
pDst += d;
}
return pSrc-lpMemFile;
}
unsigned int wsfITUnpack16Bit(char *pSample, unsigned int dwLen, byte *lpMemFile, unsigned int dwMemLength, int b215)
//--------------------------------------------------------------------------------------------
{
signed short *pDst = (signed short *)pSample;
byte *pSrc = lpMemFile;
unsigned int wHdr = 0;
unsigned int wCount = 0;
unsigned int bitbuf = 0;
unsigned int bitnum = 0;
BYTE bLeft = 0;
signed short wTemp = 0, wTemp2 = 0;
while (dwLen)
{
unsigned int d;
unsigned int dwPos;
if (!wCount)
{
wCount = 0x4000;
wHdr = *((short *)pSrc);
pSrc += 2;
bLeft = 17;
wTemp = wTemp2 = 0;
bitbuf = bitnum = 0;
}
d = wCount;
if (d > dwLen) d = dwLen;
// Unpacking
dwPos = 0;
do
{
unsigned int dwBits = ITReadBits(&bitbuf, &bitnum, pSrc, bLeft);
if (bLeft < 7)
{
unsigned int i = 1 << (bLeft-1);
unsigned int j = dwBits;
if (i != j) goto UnpackByte;
dwBits = ITReadBits(&bitbuf, &bitnum, pSrc, 4) + 1;
bLeft = ((BYTE)(dwBits & 0xFF) < bLeft) ? (BYTE)(dwBits & 0xFF) : (BYTE)((dwBits+1) & 0xFF);
goto Next;
}
if (bLeft < 17)
{
unsigned int i = (0xFFFF >> (17 - bLeft)) + 8;
unsigned int j = (i - 16) & 0xFFFF;
if ((dwBits <= j) || (dwBits > (i & 0xFFFF))) goto UnpackByte;
dwBits -= j;
bLeft = ((BYTE)(dwBits & 0xFF) < bLeft) ? (BYTE)(dwBits & 0xFF) : (BYTE)((dwBits+1) & 0xFF);
goto Next;
}
if (bLeft >= 18) goto SkipByte;
if (dwBits >= 0x10000)
{
bLeft = (BYTE)(dwBits + 1) & 0xFF;
goto Next;
}
UnpackByte:
if (bLeft < 16)
{
BYTE shift = 16 - bLeft;
signed short c = (signed short)(dwBits << shift);
c >>= shift;
dwBits = (unsigned int)c;
}
dwBits += wTemp;
wTemp = (signed short)dwBits;
wTemp2 += wTemp;
#ifdef IT215_SUPPORT
pDst[dwPos] = (b215) ? wTemp2 : wTemp;
#else
pDst[dwPos] = wTemp;
#endif
SkipByte:
dwPos++;
Next:
if (pSrc >= lpMemFile+dwMemLength+1) return 0;
} while (dwPos < d);
// Move On
wCount -= d;
dwLen -= d;
pDst += d;
if (pSrc >= lpMemFile+dwMemLength) break;
}
return (short*)pSrc-(short*)lpMemFile;
}
#endif
/********************************************************************
**
** This program gets a file name from the command line. It compresses the
** file, placing its output in a file named test.lzw. It then expands
** test.lzw into test.out. Test.out should then be an exact duplicate of
** the input file.
**
*************************************************************************/
/* minilzo.c -- mini version of the LZO real-time data compression library
This file is part of the LZO real-time data compression library.
Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer
The LZO library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.
The LZO library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with the LZO library; see the file COPYING.
If not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer
*/
/*
* NOTE:
* the full LZO package can be found at
* http://www.infosys.tuwien.ac.at/Staff/lux/marco/lzo.html
*/
#ifdef MINILZO_HAVE_CONFIG_H
# include <config.h>
#endif
#undef LZO_HAVE_CONFIG_H
#ifdef MINILZO_HAVE_CONFIG_H
# define LZO_HAVE_CONFIG_H
#endif
#define __LZO_IN_MINILZO
#if !defined(LZO_NO_SYS_TYPES_H)
# include <sys/types.h>
#endif
#ifndef __LZO_CONF_H
#define __LZO_CONF_H
#ifndef __LZOCONF_H
# include <lzoconf.h>
#endif
#if defined(__LZO_DOS16) || defined(__LZO_WIN16)
# if defined(__TURBOC__) && (__TURBOC__ < 0x452)
# error You need a newer compiler version
# endif
#endif
#if !defined(LZO_HAVE_CONFIG_H)
# include <stddef.h>
# include <string.h>
# include <stdlib.h>
# define HAVE_MEMCMP
# define HAVE_MEMCPY
# define HAVE_MEMMOVE
# define HAVE_MEMSET
#else
# include <sys/types.h>
# if defined(STDC_HEADERS)
# include <string.h>
# include <stdlib.h>
# endif
# if defined(HAVE_STDDEF_H)
# include <stddef.h>
# endif
# if defined(HAVE_MEMORY_H)
# include <memory.h>
# endif
#endif
#if defined(MFX_MEMCMP_BROKEN)
# undef HAVE_MEMCMP
#endif
#undef NDEBUG
#if !defined(LZO_DEBUG)
# define NDEBUG
#endif
#if defined(LZO_DEBUG) || !defined(NDEBUG)
# include <stdio.h>
#endif
#include <assert.h>
#if defined(__BOUNDS_CHECKING_ON)
# include <unchecked.h>
#else
# define BOUNDS_CHECKING_OFF_DURING(stmt) stmt
# define BOUNDS_CHECKING_OFF_IN_EXPR(expr) (expr)
#endif
#if !defined(LZO_UNUSED)
# define LZO_UNUSED(parm) (parm = parm)
#endif
#if !defined(__inline__) && !defined(__GNUC__)
# if defined(__cplusplus)
# define __inline__ inline
# else
# define __inline__
# endif
#endif
#if 1
# define LZO_BYTE(x) ((unsigned char) (x))
#else
# define LZO_BYTE(x) ((unsigned char) ((x) & 0xff))
#endif
#if 0
# define LZO_USHORT(x) ((unsigned short) (x))
#else
# define LZO_USHORT(x) ((unsigned short) ((x) & 0xffff))
#endif
#define LZO_MAX(a,b) ((a) >= (b) ? (a) : (b))
#define LZO_MIN(a,b) ((a) <= (b) ? (a) : (b))
#define lzo_sizeof(type) ((lzo_uint) (sizeof(type)))
#define LZO_HIGH(array) ((lzo_uint) (sizeof(array)/sizeof(*(array))))
#define LZO_SIZE(bits) (1u << (bits))
#define LZO_MASK(bits) (LZO_SIZE(bits) - 1)
#define LZO_LSIZE(bits) (1ul << (bits))
#define LZO_LMASK(bits) (LZO_LSIZE(bits) - 1)
#define LZO_USIZE(bits) ((lzo_uint) 1 << (bits))
#define LZO_UMASK(bits) (LZO_USIZE(bits) - 1)
#define LZO_STYPE_MAX(b) (((1l << (8*(b)-2)) - 1l) + (1l << (8*(b)-2)))
#define LZO_UTYPE_MAX(b) (((1ul << (8*(b)-1)) - 1ul) + (1ul << (8*(b)-1)))
#if !defined(SIZEOF_UNSIGNED)
# if (UINT_MAX == 0xffff)
# define SIZEOF_UNSIGNED 2
# elif (UINT_MAX == 0xffffffffL)
# define SIZEOF_UNSIGNED 4
# else
# define SIZEOF_UNSIGNED 8
# endif
#endif
#if !defined(SIZEOF_UNSIGNED_LONG)
# if (ULONG_MAX == 0xffffffffL)
# define SIZEOF_UNSIGNED_LONG 4
# else
# define SIZEOF_UNSIGNED_LONG 8
# endif
#endif
#if !defined(SIZEOF_SIZE_T)
# define SIZEOF_SIZE_T SIZEOF_UNSIGNED
#endif
#if !defined(SIZE_T_MAX)
# define SIZE_T_MAX LZO_UTYPE_MAX(SIZEOF_SIZE_T)
#endif
#if 1 && defined(__LZO_i386) && (UINT_MAX == 0xffffffffL)
# if !defined(LZO_UNALIGNED_OK_2) && (USHRT_MAX == 0xffff)
# define LZO_UNALIGNED_OK_2
# endif
# if !defined(LZO_UNALIGNED_OK_4) && (LZO_UINT32_MAX == 0xffffffffL)
# define LZO_UNALIGNED_OK_4
# endif
#endif
#if defined(LZO_UNALIGNED_OK_2) || defined(LZO_UNALIGNED_OK_4)
# if !defined(LZO_UNALIGNED_OK)
# define LZO_UNALIGNED_OK
# endif
#endif
#if defined(LZO_ALIGNED_OK_4) && (LZO_UINT32_MAX != 0xffffffffL)
# error LZO_ALIGNED_OK_4 is defined
#endif
#define LZO_LITTLE_ENDIAN 1234
#define LZO_BIG_ENDIAN 4321
#define LZO_PDP_ENDIAN 3412
#if !defined(LZO_BYTE_ORDER)
# if defined(MFX_BYTE_ORDER)
# define LZO_BYTE_ORDER MFX_BYTE_ORDER
# elif defined(__LZO_i386)
# define LZO_BYTE_ORDER LZO_LITTLE_ENDIAN
# elif defined(BYTE_ORDER)
# define LZO_BYTE_ORDER BYTE_ORDER
# elif defined(__BYTE_ORDER)
# define LZO_BYTE_ORDER __BYTE_ORDER
# endif
#endif
#if defined(LZO_BYTE_ORDER)
# if (LZO_BYTE_ORDER != LZO_LITTLE_ENDIAN) && \
(LZO_BYTE_ORDER != LZO_BIG_ENDIAN)
# error invalid LZO_BYTE_ORDER
# endif
#endif
#if defined(LZO_UNALIGNED_OK) && !defined(LZO_BYTE_ORDER)
# error LZO_BYTE_ORDER is not defined
#endif
#define LZO_OPTIMIZE_GNUC_i386_IS_BUGGY
#if defined(NDEBUG) && !defined(LZO_DEBUG) && !defined(__BOUNDS_CHECKING_ON)
# if defined(__GNUC__) && defined(__i386__)
# if !defined(LZO_OPTIMIZE_GNUC_i386_IS_BUGGY)
# define LZO_OPTIMIZE_GNUC_i386
# endif
# endif
#endif
__LZO_EXTERN_C int __lzo_init_done;
__LZO_EXTERN_C const lzo_byte __lzo_copyright[];
__LZO_EXTERN_C const lzo_uint32 _lzo_crc32_table[256];
#define _LZO_STRINGIZE(x) #x
#define _LZO_MEXPAND(x) _LZO_STRINGIZE(x)
#define _LZO_CONCAT2(a,b) a ## b
#define _LZO_CONCAT3(a,b,c) a ## b ## c
#define _LZO_CONCAT4(a,b,c,d) a ## b ## c ## d
#define _LZO_CONCAT5(a,b,c,d,e) a ## b ## c ## d ## e
#define _LZO_ECONCAT2(a,b) _LZO_CONCAT2(a,b)
#define _LZO_ECONCAT3(a,b,c) _LZO_CONCAT3(a,b,c)
#define _LZO_ECONCAT4(a,b,c,d) _LZO_CONCAT4(a,b,c,d)
#define _LZO_ECONCAT5(a,b,c,d,e) _LZO_CONCAT5(a,b,c,d,e)
#ifndef __LZO_PTR_H
#define __LZO_PTR_H
#ifdef __cplusplus
extern "C" {
#endif
#if defined(__LZO_DOS16) || defined(__LZO_WIN16)
# include <dos.h>
# if 1 && defined(__WATCOMC__)
# include <i86.h>
__LZO_EXTERN_C unsigned char _HShift;
# define __LZO_HShift _HShift
# elif 1 && defined(_MSC_VER)
__LZO_EXTERN_C unsigned short __near _AHSHIFT;
# define __LZO_HShift ((unsigned) &_AHSHIFT)
# elif defined(__LZO_WIN16)
# define __LZO_HShift 3
# else
# define __LZO_HShift 12
# endif
# if !defined(_FP_SEG) && defined(FP_SEG)
# define _FP_SEG FP_SEG
# endif
# if !defined(_FP_OFF) && defined(FP_OFF)
# define _FP_OFF FP_OFF
# endif
#endif
#if (UINT_MAX >= 0xffffffffL)
typedef ptrdiff_t lzo_ptrdiff_t;
#else
typedef long lzo_ptrdiff_t;
#endif
#if !defined(__LZO_HAVE_PTR_T)
# if defined(lzo_ptr_t)
# define __LZO_HAVE_PTR_T
# endif
#endif
#if !defined(__LZO_HAVE_PTR_T)
# if defined(SIZEOF_CHAR_P) && defined(SIZEOF_UNSIGNED_LONG)
# if (SIZEOF_CHAR_P == SIZEOF_UNSIGNED_LONG)
typedef unsigned long lzo_ptr_t;
typedef long lzo_sptr_t;
# define __LZO_HAVE_PTR_T
# endif
# endif
#endif
#if !defined(__LZO_HAVE_PTR_T)
# if defined(SIZEOF_CHAR_P) && defined(SIZEOF_UNSIGNED)
# if (SIZEOF_CHAR_P == SIZEOF_UNSIGNED)
typedef unsigned int lzo_ptr_t;
typedef int lzo_sptr_t;
# define __LZO_HAVE_PTR_T
# endif
# endif
#endif
#if !defined(__LZO_HAVE_PTR_T)
# if defined(SIZEOF_CHAR_P) && defined(SIZEOF_UNSIGNED_SHORT)
# if (SIZEOF_CHAR_P == SIZEOF_UNSIGNED_SHORT)
typedef unsigned short lzo_ptr_t;
typedef short lzo_sptr_t;
# define __LZO_HAVE_PTR_T
# endif
# endif
#endif
#if !defined(__LZO_HAVE_PTR_T)
# if defined(LZO_HAVE_CONFIG_H) || defined(SIZEOF_CHAR_P)
# error no suitable type for lzo_ptr_t
# else
typedef unsigned long lzo_ptr_t;
typedef long lzo_sptr_t;
# define __LZO_HAVE_PTR_T
# endif
#endif
#if defined(__LZO_DOS16) || defined(__LZO_WIN16)
#define PTR(a) ((lzo_bytep) (a))
#define PTR_ALIGNED_4(a) ((_FP_OFF(a) & 3) == 0)
#define PTR_ALIGNED2_4(a,b) (((_FP_OFF(a) | _FP_OFF(b)) & 3) == 0)
#else
#define PTR(a) ((lzo_ptr_t) (a))
#define PTR_LINEAR(a) PTR(a)
#define PTR_ALIGNED_4(a) ((PTR_LINEAR(a) & 3) == 0)
#define PTR_ALIGNED2_4(a,b) (((PTR_LINEAR(a) | PTR_LINEAR(b)) & 3) == 0)
#endif
#define PTR_LT(a,b) (PTR(a) < PTR(b))
#define PTR_GE(a,b) (PTR(a) >= PTR(b))
#define PTR_DIFF(a,b) ((lzo_ptrdiff_t) (PTR(a) - PTR(b)))
LZO_EXTERN(lzo_ptr_t)
__lzo_ptr_linear(const lzo_voidp ptr);
typedef union
{
short a_short;
int a_int;
long a_long;
char * a_char_p;
lzo_uint a_lzo_uint;
lzo_uint32 a_lzo_uint32;
lzo_ptrdiff_t a_lzo_ptrdiff_t;
lzo_ptr_t a_lzo_ptr_t;
lzo_bytep a_lzo_bytep;
lzo_bytepp a_lzo_bytepp;
}
lzo_align_t;
#ifdef __cplusplus
}
#endif
#endif
#define LZO_DETERMINISTIC
#define LZO_DICT_USE_PTR
#if 0 || defined(__LZO_DOS16) || defined(__LZO_WIN16)
# undef LZO_DICT_USE_PTR
#endif
#if !defined(lzo_moff_t)
#if 1
#define lzo_moff_t lzo_uint
#define lzo_cmoff_t lzo_uint
#else
#define lzo_moff_t lzo_ptrdiff_t
#define lzo_cmoff_t lzo_ptrdiff_t
#endif
#endif
#endif
LZO_PUBLIC(lzo_ptr_t)
__lzo_ptr_linear(const lzo_voidp ptr)
{
lzo_ptr_t p;
#if defined(__LZO_DOS16) || defined(__LZO_WIN16)
p = (((lzo_ptr_t)(_FP_SEG(ptr))) << (16 - __LZO_HShift)) + (_FP_OFF(ptr));
#else
p = PTR_LINEAR(ptr);
#endif
return p;
}
LZO_PUBLIC(unsigned)
__lzo_align_gap(const lzo_voidp ptr, lzo_uint size)
{
lzo_ptr_t p, s, n;
assert(size > 0);
p = __lzo_ptr_linear(ptr);
s = (lzo_ptr_t) (size - 1);
#if 0
assert((size & (size - 1)) == 0);
n = ((p + s) & ~s) - p;
#else
n = (((p + s) / size) * size) - p;
#endif
assert((long)n >= 0);
assert(n <= s);
return (unsigned)n;
}
#ifndef __LZO_UTIL_H
#define __LZO_UTIL_H
#ifndef __LZO_CONF_H
#endif
#ifdef __cplusplus
extern "C" {
#endif
#if 1 && defined(HAVE_MEMCPY)
#if !defined(__LZO_DOS16) && !defined(__LZO_WIN16)
#define MEMCPY8_DS(dest,src,len) \
memcpy(dest,src,len); \
dest += len; \
src += len
#endif
#endif
#if !defined(MEMCPY8_DS)
#define MEMCPY8_DS(dest,src,len) \
{ register lzo_uint __l = (len) / 8; \
do { \
*dest++ = *src++; \
*dest++ = *src++; \
*dest++ = *src++; \
*dest++ = *src++; \
*dest++ = *src++; \
*dest++ = *src++; \
*dest++ = *src++; \
*dest++ = *src++; \
} while (--__l > 0); }
#endif
#define MEMCPY_DS(dest,src,len) \
do *dest++ = *src++; \
while (--len > 0)
#define MEMMOVE_DS(dest,src,len) \
do *dest++ = *src++; \
while (--len > 0)
#if defined(LZO_OPTIMIZE_GNUC_i386)
#define BZERO8_PTR(s,n) \
__asm__ __volatile__( \
"movl %0,%%eax \n" \
"movl %1,%%edi \n" \
"movl %2,%%ecx \n" \
"cld \n" \
"rep \n" \
"stosl %%eax,(%%edi) \n" \
: \
:"g" (0),"g" (s),"g" (n) \
:"eax","edi","ecx", "memory", "cc" \
)
#elif (LZO_UINT_MAX <= SIZE_T_MAX) && defined(HAVE_MEMSET)
#define BZERO8_PTR(s,n) \
memset((lzo_voidp)(s),0,(n)*sizeof(lzo_byte *))
#else
#define BZERO8_PTR(s,n) \
lzo_memset((lzo_voidp)(s),0,(n)*lzo_sizeof(lzo_byte *))
#endif
#if 0
#if defined(__GNUC__) && defined(__i386__)
unsigned char lzo_rotr8(unsigned char value, int shift);
extern __inline__ unsigned char lzo_rotr8(unsigned char value, int shift)
{
unsigned char result;