drd/tests/std_thread2.supp: Add a suppression pattern
[valgrind.git] / perf / test_input_for_tinycc.c
blob348a012a1b06a22d485d7f9754b22c7f8509c614
2 typedef unsigned int size_t;
4 typedef long int wchar_t;
7 typedef struct
9 int quot;
10 int rem;
11 } div_t;
15 typedef struct
17 long int quot;
18 long int rem;
19 } ldiv_t;
24 extern size_t __ctype_get_mb_cur_max (void) __attribute__ ((__nothrow__));
29 extern double atof (__const char *__nptr)
30 __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1)));
32 extern int atoi (__const char *__nptr)
33 __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1)));
35 extern long int atol (__const char *__nptr)
36 __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1)));
42 __extension__ extern long long int atoll (__const char *__nptr)
43 __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1)));
49 extern double strtod (__const char *__restrict __nptr,
50 char **__restrict __endptr) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));
55 extern long int strtol (__const char *__restrict __nptr,
56 char **__restrict __endptr, int __base)
57 __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));
59 extern unsigned long int strtoul (__const char *__restrict __nptr,
60 char **__restrict __endptr, int __base)
61 __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));
66 __extension__
67 extern long long int strtoq (__const char *__restrict __nptr,
68 char **__restrict __endptr, int __base)
69 __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));
71 __extension__
72 extern unsigned long long int strtouq (__const char *__restrict __nptr,
73 char **__restrict __endptr, int __base)
74 __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));
80 __extension__
81 extern long long int strtoll (__const char *__restrict __nptr,
82 char **__restrict __endptr, int __base)
83 __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));
85 __extension__
86 extern unsigned long long int strtoull (__const char *__restrict __nptr,
87 char **__restrict __endptr, int __base)
88 __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));
91 extern double __strtod_internal (__const char *__restrict __nptr,
92 char **__restrict __endptr, int __group)
93 __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));
94 extern float __strtof_internal (__const char *__restrict __nptr,
95 char **__restrict __endptr, int __group)
96 __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));
97 extern long double __strtold_internal (__const char *__restrict __nptr,
98 char **__restrict __endptr,
99 int __group) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));
101 extern long int __strtol_internal (__const char *__restrict __nptr,
102 char **__restrict __endptr,
103 int __base, int __group)
104 __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));
108 extern unsigned long int __strtoul_internal (__const char *__restrict __nptr,
109 char **__restrict __endptr,
110 int __base, int __group)
111 __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));
116 __extension__
117 extern long long int __strtoll_internal (__const char *__restrict __nptr,
118 char **__restrict __endptr,
119 int __base, int __group)
120 __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));
124 __extension__
125 extern unsigned long long int __strtoull_internal (__const char *
126 __restrict __nptr,
127 char **__restrict __endptr,
128 int __base, int __group)
129 __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));
131 extern char *l64a (long int __n) __attribute__ ((__nothrow__));
134 extern long int a64l (__const char *__s)
135 __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1)));
142 typedef unsigned char __u_char;
143 typedef unsigned short int __u_short;
144 typedef unsigned int __u_int;
145 typedef unsigned long int __u_long;
148 typedef signed char __int8_t;
149 typedef unsigned char __uint8_t;
150 typedef signed short int __int16_t;
151 typedef unsigned short int __uint16_t;
152 typedef signed int __int32_t;
153 typedef unsigned int __uint32_t;
158 __extension__ typedef signed long long int __int64_t;
159 __extension__ typedef unsigned long long int __uint64_t;
167 __extension__ typedef long long int __quad_t;
168 __extension__ typedef unsigned long long int __u_quad_t;
175 __extension__ typedef __u_quad_t __dev_t;
176 __extension__ typedef unsigned int __uid_t;
177 __extension__ typedef unsigned int __gid_t;
178 __extension__ typedef unsigned long int __ino_t;
179 __extension__ typedef __u_quad_t __ino64_t;
180 __extension__ typedef unsigned int __mode_t;
181 __extension__ typedef unsigned int __nlink_t;
182 __extension__ typedef long int __off_t;
183 __extension__ typedef __quad_t __off64_t;
184 __extension__ typedef int __pid_t;
185 __extension__ typedef struct { int __val[2]; } __fsid_t;
186 __extension__ typedef long int __clock_t;
187 __extension__ typedef unsigned long int __rlim_t;
188 __extension__ typedef __u_quad_t __rlim64_t;
189 __extension__ typedef unsigned int __id_t;
190 __extension__ typedef long int __time_t;
191 __extension__ typedef unsigned int __useconds_t;
192 __extension__ typedef long int __suseconds_t;
194 __extension__ typedef int __daddr_t;
195 __extension__ typedef long int __swblk_t;
196 __extension__ typedef int __key_t;
199 __extension__ typedef int __clockid_t;
202 __extension__ typedef int __timer_t;
205 __extension__ typedef long int __blksize_t;
210 __extension__ typedef long int __blkcnt_t;
211 __extension__ typedef __quad_t __blkcnt64_t;
214 __extension__ typedef unsigned long int __fsblkcnt_t;
215 __extension__ typedef __u_quad_t __fsblkcnt64_t;
218 __extension__ typedef unsigned long int __fsfilcnt_t;
219 __extension__ typedef __u_quad_t __fsfilcnt64_t;
221 __extension__ typedef int __ssize_t;
225 typedef __off64_t __loff_t;
226 typedef __quad_t *__qaddr_t;
227 typedef char *__caddr_t;
230 __extension__ typedef int __intptr_t;
233 __extension__ typedef unsigned int __socklen_t;
238 typedef __u_char u_char;
239 typedef __u_short u_short;
240 typedef __u_int u_int;
241 typedef __u_long u_long;
242 typedef __quad_t quad_t;
243 typedef __u_quad_t u_quad_t;
244 typedef __fsid_t fsid_t;
249 typedef __loff_t loff_t;
253 typedef __ino_t ino_t;
255 typedef __dev_t dev_t;
260 typedef __gid_t gid_t;
265 typedef __mode_t mode_t;
270 typedef __nlink_t nlink_t;
275 typedef __uid_t uid_t;
281 typedef __off_t off_t;
283 typedef __pid_t pid_t;
288 typedef __id_t id_t;
293 typedef __ssize_t ssize_t;
299 typedef __daddr_t daddr_t;
300 typedef __caddr_t caddr_t;
306 typedef __key_t key_t;
309 typedef __time_t time_t;
314 typedef __clockid_t clockid_t;
316 typedef __timer_t timer_t;
321 typedef unsigned long int ulong;
322 typedef unsigned short int ushort;
323 typedef unsigned int uint;
325 typedef int int8_t __attribute__ ((__mode__ (__QI__)));
326 typedef int int16_t __attribute__ ((__mode__ (__HI__)));
327 typedef int int32_t __attribute__ ((__mode__ (__SI__)));
328 typedef int int64_t __attribute__ ((__mode__ (__DI__)));
331 typedef unsigned int u_int8_t __attribute__ ((__mode__ (__QI__)));
332 typedef unsigned int u_int16_t __attribute__ ((__mode__ (__HI__)));
333 typedef unsigned int u_int32_t __attribute__ ((__mode__ (__SI__)));
334 typedef unsigned int u_int64_t __attribute__ ((__mode__ (__DI__)));
336 typedef int register_t __attribute__ ((__mode__ (__word__)));
338 typedef int __sig_atomic_t;
343 typedef struct
345 unsigned long int __val[(1024 / (8 * sizeof (unsigned long int)))];
346 } __sigset_t;
351 typedef __sigset_t sigset_t;
357 struct timespec
359 __time_t tv_sec;
360 long int tv_nsec;
363 struct timeval
365 __time_t tv_sec;
366 __suseconds_t tv_usec;
371 typedef __suseconds_t suseconds_t;
377 typedef long int __fd_mask;
379 typedef struct
387 __fd_mask __fds_bits[1024 / (8 * sizeof (__fd_mask))];
390 } fd_set;
397 typedef __fd_mask fd_mask;
401 extern int select (int __nfds, fd_set *__restrict __readfds,
402 fd_set *__restrict __writefds,
403 fd_set *__restrict __exceptfds,
404 struct timeval *__restrict __timeout);
406 __extension__
407 extern __inline unsigned int gnu_dev_major (unsigned long long int __dev)
408 __attribute__ ((__nothrow__));
409 __extension__
410 extern __inline unsigned int gnu_dev_minor (unsigned long long int __dev)
411 __attribute__ ((__nothrow__));
412 __extension__
413 extern __inline unsigned long long int gnu_dev_makedev (unsigned int __major,
414 unsigned int __minor)
415 __attribute__ ((__nothrow__));
418 __extension__ extern __inline unsigned int
419 __attribute__ ((__nothrow__)) gnu_dev_major (unsigned long long int __dev)
421 return ((__dev >> 8) & 0xfff) | ((unsigned int) (__dev >> 32) & ~0xfff);
424 __extension__ extern __inline unsigned int
425 __attribute__ ((__nothrow__)) gnu_dev_minor (unsigned long long int __dev)
427 return (__dev & 0xff) | ((unsigned int) (__dev >> 12) & ~0xff);
430 __extension__ extern __inline unsigned long long int
431 __attribute__ ((__nothrow__)) gnu_dev_makedev (unsigned int __major, unsigned int __minor)
433 return ((__minor & 0xff) | ((__major & 0xfff) << 8)
434 | (((unsigned long long int) (__minor & ~0xff)) << 12)
435 | (((unsigned long long int) (__major & ~0xfff)) << 32));
438 typedef __blkcnt_t blkcnt_t;
442 typedef __fsblkcnt_t fsblkcnt_t;
446 typedef __fsfilcnt_t fsfilcnt_t;
448 struct __sched_param
450 int __sched_priority;
455 struct _pthread_fastlock
457 long int __status;
458 int __spinlock;
464 typedef struct _pthread_descr_struct *_pthread_descr;
470 typedef struct __pthread_attr_s
472 int __detachstate;
473 int __schedpolicy;
474 struct __sched_param __schedparam;
475 int __inheritsched;
476 int __scope;
477 size_t __guardsize;
478 int __stackaddr_set;
479 void *__stackaddr;
480 size_t __stacksize;
481 } pthread_attr_t;
487 __extension__ typedef long long __pthread_cond_align_t;
492 typedef struct
494 struct _pthread_fastlock __c_lock;
495 _pthread_descr __c_waiting;
496 char __padding[48 - sizeof (struct _pthread_fastlock)
497 - sizeof (_pthread_descr) - sizeof (__pthread_cond_align_t)];
498 __pthread_cond_align_t __align;
499 } pthread_cond_t;
503 typedef struct
505 int __dummy;
506 } pthread_condattr_t;
509 typedef unsigned int pthread_key_t;
515 typedef struct
517 int __m_reserved;
518 int __m_count;
519 _pthread_descr __m_owner;
520 int __m_kind;
521 struct _pthread_fastlock __m_lock;
522 } pthread_mutex_t;
526 typedef struct
528 int __mutexkind;
529 } pthread_mutexattr_t;
533 typedef int pthread_once_t;
535 typedef unsigned long int pthread_t;
543 extern long int random (void) __attribute__ ((__nothrow__));
546 extern void srandom (unsigned int __seed) __attribute__ ((__nothrow__));
552 extern char *initstate (unsigned int __seed, char *__statebuf,
553 size_t __statelen) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (2)));
557 extern char *setstate (char *__statebuf) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));
565 struct random_data
567 int32_t *fptr;
568 int32_t *rptr;
569 int32_t *state;
570 int rand_type;
571 int rand_deg;
572 int rand_sep;
573 int32_t *end_ptr;
576 extern int random_r (struct random_data *__restrict __buf,
577 int32_t *__restrict __result) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2)));
579 extern int srandom_r (unsigned int __seed, struct random_data *__buf)
580 __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (2)));
582 extern int initstate_r (unsigned int __seed, char *__restrict __statebuf,
583 size_t __statelen,
584 struct random_data *__restrict __buf)
585 __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (2, 4)));
587 extern int setstate_r (char *__restrict __statebuf,
588 struct random_data *__restrict __buf)
589 __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2)));
596 extern int rand (void) __attribute__ ((__nothrow__));
598 extern void srand (unsigned int __seed) __attribute__ ((__nothrow__));
603 extern int rand_r (unsigned int *__seed) __attribute__ ((__nothrow__));
611 extern double drand48 (void) __attribute__ ((__nothrow__));
612 extern double erand48 (unsigned short int __xsubi[3]) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));
615 extern long int lrand48 (void) __attribute__ ((__nothrow__));
616 extern long int nrand48 (unsigned short int __xsubi[3])
617 __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));
620 extern long int mrand48 (void) __attribute__ ((__nothrow__));
621 extern long int jrand48 (unsigned short int __xsubi[3])
622 __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));
625 extern void srand48 (long int __seedval) __attribute__ ((__nothrow__));
626 extern unsigned short int *seed48 (unsigned short int __seed16v[3])
627 __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));
628 extern void lcong48 (unsigned short int __param[7]) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));
634 struct drand48_data
636 unsigned short int __x[3];
637 unsigned short int __old_x[3];
638 unsigned short int __c;
639 unsigned short int __init;
640 unsigned long long int __a;
644 extern int drand48_r (struct drand48_data *__restrict __buffer,
645 double *__restrict __result) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2)));
646 extern int erand48_r (unsigned short int __xsubi[3],
647 struct drand48_data *__restrict __buffer,
648 double *__restrict __result) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2)));
651 extern int lrand48_r (struct drand48_data *__restrict __buffer,
652 long int *__restrict __result)
653 __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2)));
654 extern int nrand48_r (unsigned short int __xsubi[3],
655 struct drand48_data *__restrict __buffer,
656 long int *__restrict __result)
657 __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2)));
660 extern int mrand48_r (struct drand48_data *__restrict __buffer,
661 long int *__restrict __result)
662 __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2)));
663 extern int jrand48_r (unsigned short int __xsubi[3],
664 struct drand48_data *__restrict __buffer,
665 long int *__restrict __result)
666 __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2)));
669 extern int srand48_r (long int __seedval, struct drand48_data *__buffer)
670 __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (2)));
672 extern int seed48_r (unsigned short int __seed16v[3],
673 struct drand48_data *__buffer) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2)));
675 extern int lcong48_r (unsigned short int __param[7],
676 struct drand48_data *__buffer)
677 __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2)));
687 extern void *malloc (size_t __size) __attribute__ ((__nothrow__)) __attribute__ ((__malloc__));
689 extern void *calloc (size_t __nmemb, size_t __size)
690 __attribute__ ((__nothrow__)) __attribute__ ((__malloc__));
698 extern void *realloc (void *__ptr, size_t __size) __attribute__ ((__nothrow__)) __attribute__ ((__malloc__));
700 extern void free (void *__ptr) __attribute__ ((__nothrow__));
705 extern void cfree (void *__ptr) __attribute__ ((__nothrow__));
710 extern void *alloca (size_t __size) __attribute__ ((__nothrow__));
717 extern void *valloc (size_t __size) __attribute__ ((__nothrow__)) __attribute__ ((__malloc__));
719 extern void abort (void) __attribute__ ((__nothrow__)) __attribute__ ((__noreturn__));
723 extern int atexit (void (*__func) (void)) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));
729 extern int on_exit (void (*__func) (int __status, void *__arg), void *__arg)
730 __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));
737 extern void exit (int __status) __attribute__ ((__nothrow__)) __attribute__ ((__noreturn__));
739 extern char *getenv (__const char *__name) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));
744 extern char *__secure_getenv (__const char *__name) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));
750 extern int putenv (char *__string) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));
756 extern int setenv (__const char *__name, __const char *__value, int __replace)
757 __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (2)));
760 extern int unsetenv (__const char *__name) __attribute__ ((__nothrow__));
767 extern int clearenv (void) __attribute__ ((__nothrow__));
769 extern char *mktemp (char *__template) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));
771 extern int mkstemp (char *__template) __attribute__ ((__nonnull__ (1)));
773 extern char *mkdtemp (char *__template) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));
782 extern int system (__const char *__command);
784 extern char *realpath (__const char *__restrict __name,
785 char *__restrict __resolved) __attribute__ ((__nothrow__));
792 typedef int (*__compar_fn_t) (__const void *, __const void *);
802 extern void *bsearch (__const void *__key, __const void *__base,
803 size_t __nmemb, size_t __size, __compar_fn_t __compar)
804 __attribute__ ((__nonnull__ (1, 2, 5)));
808 extern void qsort (void *__base, size_t __nmemb, size_t __size,
809 __compar_fn_t __compar) __attribute__ ((__nonnull__ (1, 4)));
813 extern int abs (int __x) __attribute__ ((__nothrow__)) __attribute__ ((__const__));
814 extern long int labs (long int __x) __attribute__ ((__nothrow__)) __attribute__ ((__const__));
827 extern div_t div (int __numer, int __denom)
828 __attribute__ ((__nothrow__)) __attribute__ ((__const__));
829 extern ldiv_t ldiv (long int __numer, long int __denom)
830 __attribute__ ((__nothrow__)) __attribute__ ((__const__));
832 extern char *ecvt (double __value, int __ndigit, int *__restrict __decpt,
833 int *__restrict __sign) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (3, 4)));
838 extern char *fcvt (double __value, int __ndigit, int *__restrict __decpt,
839 int *__restrict __sign) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (3, 4)));
844 extern char *gcvt (double __value, int __ndigit, char *__buf)
845 __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (3)));
850 extern char *qecvt (long double __value, int __ndigit,
851 int *__restrict __decpt, int *__restrict __sign)
852 __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (3, 4)));
853 extern char *qfcvt (long double __value, int __ndigit,
854 int *__restrict __decpt, int *__restrict __sign)
855 __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (3, 4)));
856 extern char *qgcvt (long double __value, int __ndigit, char *__buf)
857 __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (3)));
862 extern int ecvt_r (double __value, int __ndigit, int *__restrict __decpt,
863 int *__restrict __sign, char *__restrict __buf,
864 size_t __len) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (3, 4, 5)));
865 extern int fcvt_r (double __value, int __ndigit, int *__restrict __decpt,
866 int *__restrict __sign, char *__restrict __buf,
867 size_t __len) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (3, 4, 5)));
869 extern int qecvt_r (long double __value, int __ndigit,
870 int *__restrict __decpt, int *__restrict __sign,
871 char *__restrict __buf, size_t __len)
872 __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (3, 4, 5)));
873 extern int qfcvt_r (long double __value, int __ndigit,
874 int *__restrict __decpt, int *__restrict __sign,
875 char *__restrict __buf, size_t __len)
876 __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (3, 4, 5)));
884 extern int mblen (__const char *__s, size_t __n) __attribute__ ((__nothrow__));
887 extern int mbtowc (wchar_t *__restrict __pwc,
888 __const char *__restrict __s, size_t __n) __attribute__ ((__nothrow__));
891 extern int wctomb (char *__s, wchar_t __wchar) __attribute__ ((__nothrow__));
895 extern size_t mbstowcs (wchar_t *__restrict __pwcs,
896 __const char *__restrict __s, size_t __n) __attribute__ ((__nothrow__));
898 extern size_t wcstombs (char *__restrict __s,
899 __const wchar_t *__restrict __pwcs, size_t __n)
900 __attribute__ ((__nothrow__));
909 extern int rpmatch (__const char *__response) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));
910 extern int getloadavg (double __loadavg[], int __nelem)
911 __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));
919 typedef
920 struct {
921 char *next_in;
922 unsigned int avail_in;
923 unsigned int total_in_lo32;
924 unsigned int total_in_hi32;
926 char *next_out;
927 unsigned int avail_out;
928 unsigned int total_out_lo32;
929 unsigned int total_out_hi32;
931 void *state;
933 void *(*bzalloc)(void *,int,int);
934 void (*bzfree)(void *,void *);
935 void *opaque;
937 bz_stream;
939 extern int BZ2_bzCompressInit (
940 bz_stream* strm,
941 int blockSize100k,
942 int verbosity,
943 int workFactor
946 extern int BZ2_bzCompress (
947 bz_stream* strm,
948 int action
951 extern int BZ2_bzCompressEnd (
952 bz_stream* strm
955 extern int BZ2_bzDecompressInit (
956 bz_stream *strm,
957 int verbosity,
958 int small
961 extern int BZ2_bzDecompress (
962 bz_stream* strm
965 extern int BZ2_bzDecompressEnd (
966 bz_stream *strm
969 extern int BZ2_bzBuffToBuffCompress (
970 char* dest,
971 unsigned int* destLen,
972 char* source,
973 unsigned int sourceLen,
974 int blockSize100k,
975 int verbosity,
976 int workFactor
979 extern int BZ2_bzBuffToBuffDecompress (
980 char* dest,
981 unsigned int* destLen,
982 char* source,
983 unsigned int sourceLen,
984 int small,
985 int verbosity
988 extern const char * BZ2_bzlibVersion (
989 void
992 typedef char Char;
993 typedef unsigned char Bool;
994 typedef unsigned char UChar;
995 typedef int Int32;
996 typedef unsigned int UInt32;
997 typedef short Int16;
998 typedef unsigned short UInt16;
1000 extern void bz_internal_error ( int errcode );
1002 extern Int32 BZ2_rNums[512];
1004 extern UInt32 BZ2_crc32Table[256];
1006 typedef
1007 struct {
1009 bz_stream* strm;
1013 Int32 mode;
1014 Int32 state;
1017 UInt32 avail_in_expect;
1020 UInt32* arr1;
1021 UInt32* arr2;
1022 UInt32* ftab;
1023 Int32 origPtr;
1026 UInt32* ptr;
1027 UChar* block;
1028 UInt16* mtfv;
1029 UChar* zbits;
1032 Int32 workFactor;
1035 UInt32 state_in_ch;
1036 Int32 state_in_len;
1037 Int32 rNToGo; Int32 rTPos;
1040 Int32 nblock;
1041 Int32 nblockMAX;
1042 Int32 numZ;
1043 Int32 state_out_pos;
1046 Int32 nInUse;
1047 Bool inUse[256];
1048 UChar unseqToSeq[256];
1051 UInt32 bsBuff;
1052 Int32 bsLive;
1055 UInt32 blockCRC;
1056 UInt32 combinedCRC;
1059 Int32 verbosity;
1060 Int32 blockNo;
1061 Int32 blockSize100k;
1064 Int32 nMTF;
1065 Int32 mtfFreq [258];
1066 UChar selector [(2 + (900000 / 50))];
1067 UChar selectorMtf[(2 + (900000 / 50))];
1069 UChar len [6][258];
1070 Int32 code [6][258];
1071 Int32 rfreq [6][258];
1073 UInt32 len_pack[258][4];
1076 EState;
1082 extern void
1083 BZ2_blockSort ( EState* );
1085 extern void
1086 BZ2_compressBlock ( EState*, Bool );
1088 extern void
1089 BZ2_bsInitWrite ( EState* );
1091 extern void
1092 BZ2_hbAssignCodes ( Int32*, UChar*, Int32, Int32, Int32 );
1094 extern void
1095 BZ2_hbMakeCodeLengths ( UChar*, Int32*, Int32, Int32 );
1097 typedef
1098 struct {
1100 bz_stream* strm;
1103 Int32 state;
1106 UChar state_out_ch;
1107 Int32 state_out_len;
1108 Bool blockRandomised;
1109 Int32 rNToGo; Int32 rTPos;
1112 UInt32 bsBuff;
1113 Int32 bsLive;
1116 Int32 blockSize100k;
1117 Bool smallDecompress;
1118 Int32 currBlockNo;
1119 Int32 verbosity;
1122 Int32 origPtr;
1123 UInt32 tPos;
1124 Int32 k0;
1125 Int32 unzftab[256];
1126 Int32 nblock_used;
1127 Int32 cftab[257];
1128 Int32 cftabCopy[257];
1131 UInt32 *tt;
1134 UInt16 *ll16;
1135 UChar *ll4;
1138 UInt32 storedBlockCRC;
1139 UInt32 storedCombinedCRC;
1140 UInt32 calculatedBlockCRC;
1141 UInt32 calculatedCombinedCRC;
1144 Int32 nInUse;
1145 Bool inUse[256];
1146 Bool inUse16[16];
1147 UChar seqToUnseq[256];
1150 UChar mtfa [4096];
1151 Int32 mtfbase[256 / 16];
1152 UChar selector [(2 + (900000 / 50))];
1153 UChar selectorMtf[(2 + (900000 / 50))];
1154 UChar len [6][258];
1156 Int32 limit [6][258];
1157 Int32 base [6][258];
1158 Int32 perm [6][258];
1159 Int32 minLens[6];
1162 Int32 save_i;
1163 Int32 save_j;
1164 Int32 save_t;
1165 Int32 save_alphaSize;
1166 Int32 save_nGroups;
1167 Int32 save_nSelectors;
1168 Int32 save_EOB;
1169 Int32 save_groupNo;
1170 Int32 save_groupPos;
1171 Int32 save_nextSym;
1172 Int32 save_nblockMAX;
1173 Int32 save_nblock;
1174 Int32 save_es;
1175 Int32 save_N;
1176 Int32 save_curr;
1177 Int32 save_zt;
1178 Int32 save_zn;
1179 Int32 save_zvec;
1180 Int32 save_zj;
1181 Int32 save_gSel;
1182 Int32 save_gMinlen;
1183 Int32* save_gLimit;
1184 Int32* save_gBase;
1185 Int32* save_gPerm;
1188 DState;
1190 extern Int32
1191 BZ2_indexIntoF ( Int32, Int32* );
1193 extern Int32
1194 BZ2_decompress ( DState* );
1196 extern void
1197 BZ2_hbCreateDecodeTables ( Int32*, Int32*, Int32*, UChar*,
1198 Int32, Int32, Int32 );
1200 typedef unsigned long HWord;
1201 typedef char HChar;
1202 typedef signed int Int;
1203 typedef unsigned int UInt;
1205 typedef signed long long int Long;
1206 typedef unsigned long long int ULong;
1212 static HWord (*serviceFn)(HWord,HWord) = 0;
1214 char* my_strcat ( char* dest, const char* src )
1216 char* dest_orig = dest;
1217 while (*dest) dest++;
1218 while (*src) *dest++ = *src++;
1219 *dest = 0;
1220 return dest_orig;
1226 static void vex_log_bytes ( char* p, int n )
1228 int i;
1229 for (i = 0; i < n; i++)
1230 (*serviceFn)( 1, (int)p[i] );
1236 static HChar vex_toupper ( HChar c )
1238 if (c >= 'a' && c <= 'z')
1239 return c + ('A' - 'a');
1240 else
1241 return c;
1244 static Int vex_strlen ( const HChar* str )
1246 Int i = 0;
1247 while (str[i] != 0) i++;
1248 return i;
1251 Bool vex_streq ( const HChar* s1, const HChar* s2 )
1253 while (((Bool)1)) {
1254 if (*s1 == 0 && *s2 == 0)
1255 return ((Bool)1);
1256 if (*s1 != *s2)
1257 return ((Bool)0);
1258 s1++;
1259 s2++;
1263 static UInt
1264 myvprintf_str ( void(*send)(HChar), Int flags, Int width, HChar* str,
1265 Bool capitalise )
1268 UInt ret = 0;
1269 Int i, extra;
1270 Int len = vex_strlen(str);
1272 if (width == 0) {
1273 ret += len;
1274 for (i = 0; i < len; i++)
1275 send((capitalise ? vex_toupper(str[i]) : (str[i])));
1276 return ret;
1279 if (len > width) {
1280 ret += width;
1281 for (i = 0; i < width; i++)
1282 send((capitalise ? vex_toupper(str[i]) : (str[i])));
1283 return ret;
1286 extra = width - len;
1287 if (flags & 4) {
1288 ret += extra;
1289 for (i = 0; i < extra; i++)
1290 send(' ');
1292 ret += len;
1293 for (i = 0; i < len; i++)
1294 send((capitalise ? vex_toupper(str[i]) : (str[i])));
1295 if (!(flags & 4)) {
1296 ret += extra;
1297 for (i = 0; i < extra; i++)
1298 send(' ');
1303 return ret;
1312 static UInt
1313 myvprintf_int64 ( void(*send)(HChar), Int flags, Int base, Int width, ULong pL)
1315 HChar buf[40];
1316 Int ind = 0;
1317 Int i, nc = 0;
1318 Bool neg = ((Bool)0);
1319 HChar *digits = "0123456789ABCDEF";
1320 UInt ret = 0;
1321 UInt p = (UInt)pL;
1323 if (base < 2 || base > 16)
1324 return ret;
1326 if ((flags & 1) && (Int)p < 0) {
1327 p = - (Int)p;
1328 neg = ((Bool)1);
1331 if (p == 0)
1332 buf[ind++] = '0';
1333 else {
1334 while (p > 0) {
1335 if ((flags & 16) && 10 == base &&
1336 0 == (ind-nc) % 3 && 0 != ind)
1338 buf[ind++] = ',';
1339 nc++;
1341 buf[ind++] = digits[p % base];
1342 p /= base;
1346 if (neg)
1347 buf[ind++] = '-';
1349 if (width > 0 && !(flags & 4)) {
1350 for(; ind < width; ind++) {
1352 buf[ind] = ((flags & 2) ? '0': ' ');
1357 ret += ind;
1358 for (i = ind -1; i >= 0; i--) {
1359 send(buf[i]);
1361 if (width > 0 && (flags & 4)) {
1362 for(; ind < width; ind++) {
1363 ret++;
1364 send(' ');
1367 return ret;
1372 static
1373 UInt vprintf_wrk ( )
1375 return 0;
1383 static HChar myprintf_buf[1000];
1384 static Int n_myprintf_buf;
1386 static void add_to_myprintf_buf ( HChar c )
1388 if (c == '\n' || n_myprintf_buf >= 1000-10 ) {
1389 vex_log_bytes( myprintf_buf, vex_strlen(myprintf_buf) );
1390 n_myprintf_buf = 0;
1391 myprintf_buf[n_myprintf_buf] = 0;
1393 myprintf_buf[n_myprintf_buf++] = c;
1394 myprintf_buf[n_myprintf_buf] = 0;
1397 static UInt vex_printf ( const char *format, ... )
1399 return 0;
1402 static
1403 void makeMaps_d ( DState* s )
1405 Int32 i;
1406 s->nInUse = 0;
1407 for (i = 0; i < 256; i++)
1408 if (s->inUse[i]) {
1409 s->seqToUnseq[s->nInUse] = i;
1410 s->nInUse++;
1414 __inline__ Int32 BZ2_indexIntoF ( Int32 indx, Int32 *cftab )
1416 Int32 nb, na, mid;
1417 nb = 0;
1418 na = 256;
1419 do {
1420 mid = (nb + na) >> 1;
1421 if (indx >= cftab[mid]) nb = mid; else na = mid;
1423 while (na - nb != 1);
1424 return nb;
1428 Int32 BZ2_decompress ( DState* s )
1430 UChar uc;
1431 Int32 retVal;
1432 Int32 minLen, maxLen;
1433 bz_stream* strm = s->strm;
1436 Int32 i;
1437 Int32 j;
1438 Int32 t;
1439 Int32 alphaSize;
1440 Int32 nGroups;
1441 Int32 nSelectors;
1442 Int32 EOB;
1443 Int32 groupNo;
1444 Int32 groupPos;
1445 Int32 nextSym;
1446 Int32 nblockMAX;
1447 Int32 nblock;
1448 Int32 es;
1449 Int32 N;
1450 Int32 curr;
1451 Int32 zt;
1452 Int32 zn;
1453 Int32 zvec;
1454 Int32 zj;
1455 Int32 gSel;
1456 Int32 gMinlen;
1457 Int32* gLimit;
1458 Int32* gBase;
1459 Int32* gPerm;
1461 if (s->state == 10) {
1463 s->save_i = 0;
1464 s->save_j = 0;
1465 s->save_t = 0;
1466 s->save_alphaSize = 0;
1467 s->save_nGroups = 0;
1468 s->save_nSelectors = 0;
1469 s->save_EOB = 0;
1470 s->save_groupNo = 0;
1471 s->save_groupPos = 0;
1472 s->save_nextSym = 0;
1473 s->save_nblockMAX = 0;
1474 s->save_nblock = 0;
1475 s->save_es = 0;
1476 s->save_N = 0;
1477 s->save_curr = 0;
1478 s->save_zt = 0;
1479 s->save_zn = 0;
1480 s->save_zvec = 0;
1481 s->save_zj = 0;
1482 s->save_gSel = 0;
1483 s->save_gMinlen = 0;
1484 s->save_gLimit = ((void *)0);
1485 s->save_gBase = ((void *)0);
1486 s->save_gPerm = ((void *)0);
1490 i = s->save_i;
1491 j = s->save_j;
1492 t = s->save_t;
1493 alphaSize = s->save_alphaSize;
1494 nGroups = s->save_nGroups;
1495 nSelectors = s->save_nSelectors;
1496 EOB = s->save_EOB;
1497 groupNo = s->save_groupNo;
1498 groupPos = s->save_groupPos;
1499 nextSym = s->save_nextSym;
1500 nblockMAX = s->save_nblockMAX;
1501 nblock = s->save_nblock;
1502 es = s->save_es;
1503 N = s->save_N;
1504 curr = s->save_curr;
1505 zt = s->save_zt;
1506 zn = s->save_zn;
1507 zvec = s->save_zvec;
1508 zj = s->save_zj;
1509 gSel = s->save_gSel;
1510 gMinlen = s->save_gMinlen;
1511 gLimit = s->save_gLimit;
1512 gBase = s->save_gBase;
1513 gPerm = s->save_gPerm;
1515 retVal = 0;
1517 switch (s->state) {
1519 case 10: s->state = 10; while (((Bool)1)) { if (s->bsLive >= 8) { UInt32 v; v = (s->bsBuff >> (s->bsLive-8)) & ((1 << 8)-1); s->bsLive -= 8; uc = v; break; } if (s->strm->avail_in == 0) { retVal = 0; goto save_state_and_return; };; s->bsBuff = (s->bsBuff << 8) | ((UInt32) (*((UChar*)(s->strm->next_in)))); s->bsLive += 8; s->strm->next_in++; s->strm->avail_in--; s->strm->total_in_lo32++; if (s->strm->total_in_lo32 == 0) s->strm->total_in_hi32++; };
1520 if (uc != 0x42) { retVal = (-5); goto save_state_and_return; };;
1522 case 11: s->state = 11; while (((Bool)1)) { if (s->bsLive >= 8) { UInt32 v; v = (s->bsBuff >> (s->bsLive-8)) & ((1 << 8)-1); s->bsLive -= 8; uc = v; break; } if (s->strm->avail_in == 0) { retVal = 0; goto save_state_and_return; };; s->bsBuff = (s->bsBuff << 8) | ((UInt32) (*((UChar*)(s->strm->next_in)))); s->bsLive += 8; s->strm->next_in++; s->strm->avail_in--; s->strm->total_in_lo32++; if (s->strm->total_in_lo32 == 0) s->strm->total_in_hi32++; };
1523 if (uc != 0x5a) { retVal = (-5); goto save_state_and_return; };;
1525 case 12: s->state = 12; while (((Bool)1)) { if (s->bsLive >= 8) { UInt32 v; v = (s->bsBuff >> (s->bsLive-8)) & ((1 << 8)-1); s->bsLive -= 8; uc = v; break; } if (s->strm->avail_in == 0) { retVal = 0; goto save_state_and_return; };; s->bsBuff = (s->bsBuff << 8) | ((UInt32) (*((UChar*)(s->strm->next_in)))); s->bsLive += 8; s->strm->next_in++; s->strm->avail_in--; s->strm->total_in_lo32++; if (s->strm->total_in_lo32 == 0) s->strm->total_in_hi32++; }
1526 if (uc != 0x68) { retVal = (-5); goto save_state_and_return; };;
1528 case 13: s->state = 13; while (((Bool)1)) { if (s->bsLive >= 8) { UInt32 v; v = (s->bsBuff >> (s->bsLive-8)) & ((1 << 8)-1); s->bsLive -= 8; s->blockSize100k = v; break; } if (s->strm->avail_in == 0) { retVal = 0; goto save_state_and_return; };; s->bsBuff = (s->bsBuff << 8) | ((UInt32) (*((UChar*)(s->strm->next_in)))); s->bsLive += 8; s->strm->next_in++; s->strm->avail_in--; s->strm->total_in_lo32++; if (s->strm->total_in_lo32 == 0) s->strm->total_in_hi32++; }
1529 if (s->blockSize100k < (0x30 + 1) ||
1530 s->blockSize100k > (0x30 + 9)) { retVal = (-5); goto save_state_and_return; };;
1531 s->blockSize100k -= 0x30;
1533 if (s->smallDecompress) {
1534 s->ll16 = (strm->bzalloc)(strm->opaque,(s->blockSize100k * 100000 * sizeof(UInt16)),1);
1535 s->ll4 = (strm->bzalloc)(strm->opaque,(((1 + s->blockSize100k * 100000) >> 1) * sizeof(UChar)),1);
1538 if (s->ll16 == ((void *)0) || s->ll4 == ((void *)0)) { retVal = (-3); goto save_state_and_return; };;
1539 } else {
1540 s->tt = (strm->bzalloc)(strm->opaque,(s->blockSize100k * 100000 * sizeof(Int32)),1);
1541 if (s->tt == ((void *)0)) { retVal = (-3); goto save_state_and_return; };;
1544 case 14: s->state = 14; while (((Bool)1)) { if (s->bsLive >= 8) { UInt32 v; v = (s->bsBuff >> (s->bsLive-8)) & ((1 << 8)-1); s->bsLive -= 8; uc = v; break; } if (s->strm->avail_in == 0) { retVal = 0; goto save_state_and_return; };; s->bsBuff = (s->bsBuff << 8) | ((UInt32) (*((UChar*)(s->strm->next_in)))); s->bsLive += 8; s->strm->next_in++; s->strm->avail_in--; s->strm->total_in_lo32++; if (s->strm->total_in_lo32 == 0) s->strm->total_in_hi32++; };
1546 if (uc == 0x17) goto endhdr_2;
1547 if (uc != 0x31) { retVal = (-4); goto save_state_and_return; };;
1548 case 15: s->state = 15; while (((Bool)1)) { if (s->bsLive >= 8) { UInt32 v; v = (s->bsBuff >> (s->bsLive-8)) & ((1 << 8)-1); s->bsLive -= 8; uc = v; break; } if (s->strm->avail_in == 0) { retVal = 0; goto save_state_and_return; };; s->bsBuff = (s->bsBuff << 8) | ((UInt32) (*((UChar*)(s->strm->next_in)))); s->bsLive += 8; s->strm->next_in++; s->strm->avail_in--; s->strm->total_in_lo32++; if (s->strm->total_in_lo32 == 0) s->strm->total_in_hi32++; };
1549 if (uc != 0x41) { retVal = (-4); goto save_state_and_return; };;
1550 case 16: s->state = 16; while (((Bool)1)) { if (s->bsLive >= 8) { UInt32 v; v = (s->bsBuff >> (s->bsLive-8)) & ((1 << 8)-1); s->bsLive -= 8; uc = v; break; } if (s->strm->avail_in == 0) { retVal = 0; goto save_state_and_return; };; s->bsBuff = (s->bsBuff << 8) | ((UInt32) (*((UChar*)(s->strm->next_in)))); s->bsLive += 8; s->strm->next_in++; s->strm->avail_in--; s->strm->total_in_lo32++; if (s->strm->total_in_lo32 == 0) s->strm->total_in_hi32++; };
1551 if (uc != 0x59) { retVal = (-4); goto save_state_and_return; };;
1552 case 17: s->state = 17; while (((Bool)1)) { if (s->bsLive >= 8) { UInt32 v; v = (s->bsBuff >> (s->bsLive-8)) & ((1 << 8)-1); s->bsLive -= 8; uc = v; break; } if (s->strm->avail_in == 0) { retVal = 0; goto save_state_and_return; };; s->bsBuff = (s->bsBuff << 8) | ((UInt32) (*((UChar*)(s->strm->next_in)))); s->bsLive += 8; s->strm->next_in++; s->strm->avail_in--; s->strm->total_in_lo32++; if (s->strm->total_in_lo32 == 0) s->strm->total_in_hi32++; };
1553 if (uc != 0x26) { retVal = (-4); goto save_state_and_return; };;
1554 case 18: s->state = 18; while (((Bool)1)) { if (s->bsLive >= 8) { UInt32 v; v = (s->bsBuff >> (s->bsLive-8)) & ((1 << 8)-1); s->bsLive -= 8; uc = v; break; } if (s->strm->avail_in == 0) { retVal = 0; goto save_state_and_return; };; s->bsBuff = (s->bsBuff << 8) | ((UInt32) (*((UChar*)(s->strm->next_in)))); s->bsLive += 8; s->strm->next_in++; s->strm->avail_in--; s->strm->total_in_lo32++; if (s->strm->total_in_lo32 == 0) s->strm->total_in_hi32++; };
1555 if (uc != 0x53) { retVal = (-4); goto save_state_and_return; };;
1556 case 19: s->state = 19; while (((Bool)1)) { if (s->bsLive >= 8) { UInt32 v; v = (s->bsBuff >> (s->bsLive-8)) & ((1 << 8)-1); s->bsLive -= 8; uc = v; break; } if (s->strm->avail_in == 0) { retVal = 0; goto save_state_and_return; };; s->bsBuff = (s->bsBuff << 8) | ((UInt32) (*((UChar*)(s->strm->next_in)))); s->bsLive += 8; s->strm->next_in++; s->strm->avail_in--; s->strm->total_in_lo32++; if (s->strm->total_in_lo32 == 0) s->strm->total_in_hi32++; };
1557 if (uc != 0x59) { retVal = (-4); goto save_state_and_return; };;
1559 s->currBlockNo++;
1560 if (s->verbosity >= 2)
1561 vex_printf("\n [%d: huff+mtf ",s->currBlockNo);
1563 s->storedBlockCRC = 0;
1564 case 20: s->state = 20; while (((Bool)1)) { if (s->bsLive >= 8) { UInt32 v; v = (s->bsBuff >> (s->bsLive-8)) & ((1 << 8)-1); s->bsLive -= 8; uc = v; break; } if (s->strm->avail_in == 0) { retVal = 0; goto save_state_and_return; };; s->bsBuff = (s->bsBuff << 8) | ((UInt32) (*((UChar*)(s->strm->next_in)))); s->bsLive += 8; s->strm->next_in++; s->strm->avail_in--; s->strm->total_in_lo32++; if (s->strm->total_in_lo32 == 0) s->strm->total_in_hi32++; };
1565 s->storedBlockCRC = (s->storedBlockCRC << 8) | ((UInt32)uc);
1566 case 21: s->state = 21; while (((Bool)1)) { if (s->bsLive >= 8) { UInt32 v; v = (s->bsBuff >> (s->bsLive-8)) & ((1 << 8)-1); s->bsLive -= 8; uc = v; break; } if (s->strm->avail_in == 0) { retVal = 0; goto save_state_and_return; };; s->bsBuff = (s->bsBuff << 8) | ((UInt32) (*((UChar*)(s->strm->next_in)))); s->bsLive += 8; s->strm->next_in++; s->strm->avail_in--; s->strm->total_in_lo32++; if (s->strm->total_in_lo32 == 0) s->strm->total_in_hi32++; };
1567 s->storedBlockCRC = (s->storedBlockCRC << 8) | ((UInt32)uc);
1568 case 22: s->state = 22; while (((Bool)1)) { if (s->bsLive >= 8) { UInt32 v; v = (s->bsBuff >> (s->bsLive-8)) & ((1 << 8)-1); s->bsLive -= 8; uc = v; break; } if (s->strm->avail_in == 0) { retVal = 0; goto save_state_and_return; };; s->bsBuff = (s->bsBuff << 8) | ((UInt32) (*((UChar*)(s->strm->next_in)))); s->bsLive += 8; s->strm->next_in++; s->strm->avail_in--; s->strm->total_in_lo32++; if (s->strm->total_in_lo32 == 0) s->strm->total_in_hi32++; };
1569 s->storedBlockCRC = (s->storedBlockCRC << 8) | ((UInt32)uc);
1570 case 23: s->state = 23; while (((Bool)1)) { if (s->bsLive >= 8) { UInt32 v; v = (s->bsBuff >> (s->bsLive-8)) & ((1 << 8)-1); s->bsLive -= 8; uc = v; break; } if (s->strm->avail_in == 0) { retVal = 0; goto save_state_and_return; };; s->bsBuff = (s->bsBuff << 8) | ((UInt32) (*((UChar*)(s->strm->next_in)))); s->bsLive += 8; s->strm->next_in++; s->strm->avail_in--; s->strm->total_in_lo32++; if (s->strm->total_in_lo32 == 0) s->strm->total_in_hi32++; };
1571 s->storedBlockCRC = (s->storedBlockCRC << 8) | ((UInt32)uc);
1573 case 24: s->state = 24; while (((Bool)1)) { if (s->bsLive >= 1) { UInt32 v; v = (s->bsBuff >> (s->bsLive-1)) & ((1 << 1)-1); s->bsLive -= 1; s->blockRandomised = v; break; } if (s->strm->avail_in == 0) { retVal = 0; goto save_state_and_return; };; s->bsBuff = (s->bsBuff << 8) | ((UInt32) (*((UChar*)(s->strm->next_in)))); s->bsLive += 8; s->strm->next_in++; s->strm->avail_in--; s->strm->total_in_lo32++; if (s->strm->total_in_lo32 == 0) s->strm->total_in_hi32++; };
1575 s->origPtr = 0;
1576 case 25: s->state = 25; while (((Bool)1)) { if (s->bsLive >= 8) { UInt32 v; v = (s->bsBuff >> (s->bsLive-8)) & ((1 << 8)-1); s->bsLive -= 8; uc = v; break; } if (s->strm->avail_in == 0) { retVal = 0; goto save_state_and_return; };; s->bsBuff = (s->bsBuff << 8) | ((UInt32) (*((UChar*)(s->strm->next_in)))); s->bsLive += 8; s->strm->next_in++; s->strm->avail_in--; s->strm->total_in_lo32++; if (s->strm->total_in_lo32 == 0) s->strm->total_in_hi32++; };
1577 s->origPtr = (s->origPtr << 8) | ((Int32)uc);
1578 case 26: s->state = 26; while (((Bool)1)) { if (s->bsLive >= 8) { UInt32 v; v = (s->bsBuff >> (s->bsLive-8)) & ((1 << 8)-1); s->bsLive -= 8; uc = v; break; } if (s->strm->avail_in == 0) { retVal = 0; goto save_state_and_return; };; s->bsBuff = (s->bsBuff << 8) | ((UInt32) (*((UChar*)(s->strm->next_in)))); s->bsLive += 8; s->strm->next_in++; s->strm->avail_in--; s->strm->total_in_lo32++; if (s->strm->total_in_lo32 == 0) s->strm->total_in_hi32++; };
1579 s->origPtr = (s->origPtr << 8) | ((Int32)uc);
1580 case 27: s->state = 27; while (((Bool)1)) { if (s->bsLive >= 8) { UInt32 v; v = (s->bsBuff >> (s->bsLive-8)) & ((1 << 8)-1); s->bsLive -= 8; uc = v; break; } if (s->strm->avail_in == 0) { retVal = 0; goto save_state_and_return; };; s->bsBuff = (s->bsBuff << 8) | ((UInt32) (*((UChar*)(s->strm->next_in)))); s->bsLive += 8; s->strm->next_in++; s->strm->avail_in--; s->strm->total_in_lo32++; if (s->strm->total_in_lo32 == 0) s->strm->total_in_hi32++; };
1581 s->origPtr = (s->origPtr << 8) | ((Int32)uc);
1583 if (s->origPtr < 0)
1584 { retVal = (-4); goto save_state_and_return; };;
1585 if (s->origPtr > 10 + 100000*s->blockSize100k)
1586 { retVal = (-4); goto save_state_and_return; };;
1589 for (i = 0; i < 16; i++) {
1590 case 28: s->state = 28; while (((Bool)1)) { if (s->bsLive >= 1) { UInt32 v; v = (s->bsBuff >> (s->bsLive-1)) & ((1 << 1)-1); s->bsLive -= 1; uc = v; break; } if (s->strm->avail_in == 0) { retVal = 0; goto save_state_and_return; };; s->bsBuff = (s->bsBuff << 8) | ((UInt32) (*((UChar*)(s->strm->next_in)))); s->bsLive += 8; s->strm->next_in++; s->strm->avail_in--; s->strm->total_in_lo32++; if (s->strm->total_in_lo32 == 0) s->strm->total_in_hi32++; };
1591 if (uc == 1)
1592 s->inUse16[i] = ((Bool)1); else
1593 s->inUse16[i] = ((Bool)0);
1596 for (i = 0; i < 256; i++) s->inUse[i] = ((Bool)0);
1598 for (i = 0; i < 16; i++)
1599 if (s->inUse16[i])
1600 for (j = 0; j < 16; j++) {
1601 case 29: s->state = 29; while (((Bool)1)) { if (s->bsLive >= 1) { UInt32 v; v = (s->bsBuff >> (s->bsLive-1)) & ((1 << 1)-1); s->bsLive -= 1; uc = v; break; } if (s->strm->avail_in == 0) { retVal = 0; goto save_state_and_return; };; s->bsBuff = (s->bsBuff << 8) | ((UInt32) (*((UChar*)(s->strm->next_in)))); s->bsLive += 8; s->strm->next_in++; s->strm->avail_in--; s->strm->total_in_lo32++; if (s->strm->total_in_lo32 == 0) s->strm->total_in_hi32++; };
1602 if (uc == 1) s->inUse[i * 16 + j] = ((Bool)1);
1604 makeMaps_d ( s );
1605 if (s->nInUse == 0) { retVal = (-4); goto save_state_and_return; };;
1606 alphaSize = s->nInUse+2;
1609 case 30: s->state = 30; while (((Bool)1)) { if (s->bsLive >= 3) { UInt32 v; v = (s->bsBuff >> (s->bsLive-3)) & ((1 << 3)-1); s->bsLive -= 3; nGroups = v; break; } if (s->strm->avail_in == 0) { retVal = 0; goto save_state_and_return; };; s->bsBuff = (s->bsBuff << 8) | ((UInt32) (*((UChar*)(s->strm->next_in)))); s->bsLive += 8; s->strm->next_in++; s->strm->avail_in--; s->strm->total_in_lo32++; if (s->strm->total_in_lo32 == 0) s->strm->total_in_hi32++; };
1610 if (nGroups < 2 || nGroups > 6) { retVal = (-4); goto save_state_and_return; };;
1611 case 31: s->state = 31; while (((Bool)1)) { if (s->bsLive >= 15) { UInt32 v; v = (s->bsBuff >> (s->bsLive-15)) & ((1 << 15)-1); s->bsLive -= 15; nSelectors = v; break; } if (s->strm->avail_in == 0) { retVal = 0; goto save_state_and_return; };; s->bsBuff = (s->bsBuff << 8) | ((UInt32) (*((UChar*)(s->strm->next_in)))); s->bsLive += 8; s->strm->next_in++; s->strm->avail_in--; s->strm->total_in_lo32++; if (s->strm->total_in_lo32 == 0) s->strm->total_in_hi32++; };
1612 if (nSelectors < 1) { retVal = (-4); goto save_state_and_return; };;
1613 for (i = 0; i < nSelectors; i++) {
1614 j = 0;
1615 while (((Bool)1)) {
1616 case 32: s->state = 32; while (((Bool)1)) { if (s->bsLive >= 1) { UInt32 v; v = (s->bsBuff >> (s->bsLive-1)) & ((1 << 1)-1); s->bsLive -= 1; uc = v; break; } if (s->strm->avail_in == 0) { retVal = 0; goto save_state_and_return; };; s->bsBuff = (s->bsBuff << 8) | ((UInt32) (*((UChar*)(s->strm->next_in)))); s->bsLive += 8; s->strm->next_in++; s->strm->avail_in--; s->strm->total_in_lo32++; if (s->strm->total_in_lo32 == 0) s->strm->total_in_hi32++; };
1617 if (uc == 0) break;
1618 j++;
1619 if (j >= nGroups) { retVal = (-4); goto save_state_and_return; };;
1621 s->selectorMtf[i] = j;
1626 UChar pos[6], tmp, v;
1627 for (v = 0; v < nGroups; v++) pos[v] = v;
1629 for (i = 0; i < nSelectors; i++) {
1630 v = s->selectorMtf[i];
1631 tmp = pos[v];
1632 while (v > 0) { pos[v] = pos[v-1]; v--; }
1633 pos[0] = tmp;
1634 s->selector[i] = tmp;
1639 for (t = 0; t < nGroups; t++) {
1640 case 33: s->state = 33; while (((Bool)1)) { if (s->bsLive >= 5) { UInt32 v; v = (s->bsBuff >> (s->bsLive-5)) & ((1 << 5)-1); s->bsLive -= 5; curr = v; break; } if (s->strm->avail_in == 0) { retVal = 0; goto save_state_and_return; };; s->bsBuff = (s->bsBuff << 8) | ((UInt32) (*((UChar*)(s->strm->next_in)))); s->bsLive += 8; s->strm->next_in++; s->strm->avail_in--; s->strm->total_in_lo32++; if (s->strm->total_in_lo32 == 0) s->strm->total_in_hi32++; };
1641 for (i = 0; i < alphaSize; i++) {
1642 while (((Bool)1)) {
1643 if (curr < 1 || curr > 20) { retVal = (-4); goto save_state_and_return; };;
1644 case 34: s->state = 34; while (((Bool)1)) { if (s->bsLive >= 1) { UInt32 v; v = (s->bsBuff >> (s->bsLive-1)) & ((1 << 1)-1); s->bsLive -= 1; uc = v; break; } if (s->strm->avail_in == 0) { retVal = 0; goto save_state_and_return; };; s->bsBuff = (s->bsBuff << 8) | ((UInt32) (*((UChar*)(s->strm->next_in)))); s->bsLive += 8; s->strm->next_in++; s->strm->avail_in--; s->strm->total_in_lo32++; if (s->strm->total_in_lo32 == 0) s->strm->total_in_hi32++; };
1645 if (uc == 0) break;
1646 case 35: s->state = 35; while (((Bool)1)) { if (s->bsLive >= 1) { UInt32 v; v = (s->bsBuff >> (s->bsLive-1)) & ((1 << 1)-1); s->bsLive -= 1; uc = v; break; } if (s->strm->avail_in == 0) { retVal = 0; goto save_state_and_return; };; s->bsBuff = (s->bsBuff << 8) | ((UInt32) (*((UChar*)(s->strm->next_in)))); s->bsLive += 8; s->strm->next_in++; s->strm->avail_in--; s->strm->total_in_lo32++; if (s->strm->total_in_lo32 == 0) s->strm->total_in_hi32++; };
1647 if (uc == 0) curr++; else curr--;
1649 s->len[t][i] = curr;
1654 for (t = 0; t < nGroups; t++) {
1655 minLen = 32;
1656 maxLen = 0;
1657 for (i = 0; i < alphaSize; i++) {
1658 if (s->len[t][i] > maxLen) maxLen = s->len[t][i];
1659 if (s->len[t][i] < minLen) minLen = s->len[t][i];
1661 BZ2_hbCreateDecodeTables (
1662 &(s->limit[t][0]),
1663 &(s->base[t][0]),
1664 &(s->perm[t][0]),
1665 &(s->len[t][0]),
1666 minLen, maxLen, alphaSize
1668 s->minLens[t] = minLen;
1673 EOB = s->nInUse+1;
1674 nblockMAX = 100000 * s->blockSize100k;
1675 groupNo = -1;
1676 groupPos = 0;
1678 for (i = 0; i <= 255; i++) s->unzftab[i] = 0;
1682 Int32 ii, jj, kk;
1683 kk = 4096 -1;
1684 for (ii = 256 / 16 - 1; ii >= 0; ii--) {
1685 for (jj = 16 -1; jj >= 0; jj--) {
1686 s->mtfa[kk] = (UChar)(ii * 16 + jj);
1687 kk--;
1689 s->mtfbase[ii] = kk + 1;
1694 nblock = 0;
1695 { if (groupPos == 0) { groupNo++; if (groupNo >= nSelectors) { retVal = (-4); goto save_state_and_return; };; groupPos = 50; gSel = s->selector[groupNo]; gMinlen = s->minLens[gSel]; gLimit = &(s->limit[gSel][0]); gPerm = &(s->perm[gSel][0]); gBase = &(s->base[gSel][0]); } groupPos--; zn = gMinlen; case 36: s->state = 36; while (((Bool)1)) { if (s->bsLive >= zn) { UInt32 v; v = (s->bsBuff >> (s->bsLive-zn)) & ((1 << zn)-1); s->bsLive -= zn; zvec = v; break; } if (s->strm->avail_in == 0) { retVal = 0; goto save_state_and_return; };; s->bsBuff = (s->bsBuff << 8) | ((UInt32) (*((UChar*)(s->strm->next_in)))); s->bsLive += 8; s->strm->next_in++; s->strm->avail_in--; s->strm->total_in_lo32++; if (s->strm->total_in_lo32 == 0) s->strm->total_in_hi32++; }; while (1) { if (zn > 20 ) { retVal = (-4); goto save_state_and_return; };; if (zvec <= gLimit[zn]) break; zn++; case 37: s->state = 37; while (((Bool)1)) { if (s->bsLive >= 1) { UInt32 v; v = (s->bsBuff >> (s->bsLive-1)) & ((1 << 1)-1); s->bsLive -= 1; zj = v; break; } if (s->strm->avail_in == 0) { retVal = 0; goto save_state_and_return; };; s->bsBuff = (s->bsBuff << 8) | ((UInt32) (*((UChar*)(s->strm->next_in)))); s->bsLive += 8; s->strm->next_in++; s->strm->avail_in--; s->strm->total_in_lo32++; if (s->strm->total_in_lo32 == 0) s->strm->total_in_hi32++; }; zvec = (zvec << 1) | zj; }; if (zvec - gBase[zn] < 0 || zvec - gBase[zn] >= 258) { retVal = (-4); goto save_state_and_return; };; nextSym = gPerm[zvec - gBase[zn]]; };
1697 while (((Bool)1)) {
1699 if (nextSym == EOB) break;
1701 if (nextSym == 0 || nextSym == 1) {
1703 es = -1;
1704 N = 1;
1705 do {
1706 if (nextSym == 0) es = es + (0+1) * N; else
1707 if (nextSym == 1) es = es + (1+1) * N;
1708 N = N * 2;
1709 { if (groupPos == 0) { groupNo++; if (groupNo >= nSelectors) { retVal = (-4); goto save_state_and_return; };; groupPos = 50; gSel = s->selector[groupNo]; gMinlen = s->minLens[gSel]; gLimit = &(s->limit[gSel][0]); gPerm = &(s->perm[gSel][0]); gBase = &(s->base[gSel][0]); } groupPos--; zn = gMinlen; case 38: s->state = 38; while (((Bool)1)) { if (s->bsLive >= zn) { UInt32 v; v = (s->bsBuff >> (s->bsLive-zn)) & ((1 << zn)-1); s->bsLive -= zn; zvec = v; break; } if (s->strm->avail_in == 0) { retVal = 0; goto save_state_and_return; };; s->bsBuff = (s->bsBuff << 8) | ((UInt32) (*((UChar*)(s->strm->next_in)))); s->bsLive += 8; s->strm->next_in++; s->strm->avail_in--; s->strm->total_in_lo32++; if (s->strm->total_in_lo32 == 0) s->strm->total_in_hi32++; }; while (1) { if (zn > 20 ) { retVal = (-4); goto save_state_and_return; };; if (zvec <= gLimit[zn]) break; zn++; case 39: s->state = 39; while (((Bool)1)) { if (s->bsLive >= 1) { UInt32 v; v = (s->bsBuff >> (s->bsLive-1)) & ((1 << 1)-1); s->bsLive -= 1; zj = v; break; } if (s->strm->avail_in == 0) { retVal = 0; goto save_state_and_return; };; s->bsBuff = (s->bsBuff << 8) | ((UInt32) (*((UChar*)(s->strm->next_in)))); s->bsLive += 8; s->strm->next_in++; s->strm->avail_in--; s->strm->total_in_lo32++; if (s->strm->total_in_lo32 == 0) s->strm->total_in_hi32++; }; zvec = (zvec << 1) | zj; }; if (zvec - gBase[zn] < 0 || zvec - gBase[zn] >= 258) { retVal = (-4); goto save_state_and_return; };; nextSym = gPerm[zvec - gBase[zn]]; };
1711 while (nextSym == 0 || nextSym == 1);
1713 es++;
1714 uc = s->seqToUnseq[ s->mtfa[s->mtfbase[0]] ];
1715 s->unzftab[uc] += es;
1717 if (s->smallDecompress)
1718 while (es > 0) {
1719 if (nblock >= nblockMAX) { retVal = (-4); goto save_state_and_return; };;
1720 s->ll16[nblock] = (UInt16)uc;
1721 nblock++;
1722 es--;
1724 else
1725 while (es > 0) {
1726 if (nblock >= nblockMAX) { retVal = (-4); goto save_state_and_return; };;
1727 s->tt[nblock] = (UInt32)uc;
1728 nblock++;
1729 es--;
1732 continue;
1734 } else {
1736 if (nblock >= nblockMAX) { retVal = (-4); goto save_state_and_return; };;
1740 Int32 ii, jj, kk, pp, lno, off;
1741 UInt32 nn;
1742 nn = (UInt32)(nextSym - 1);
1744 if (nn < 16) {
1746 pp = s->mtfbase[0];
1747 uc = s->mtfa[pp+nn];
1748 while (nn > 3) {
1749 Int32 z = pp+nn;
1750 s->mtfa[(z) ] = s->mtfa[(z)-1];
1751 s->mtfa[(z)-1] = s->mtfa[(z)-2];
1752 s->mtfa[(z)-2] = s->mtfa[(z)-3];
1753 s->mtfa[(z)-3] = s->mtfa[(z)-4];
1754 nn -= 4;
1756 while (nn > 0) {
1757 s->mtfa[(pp+nn)] = s->mtfa[(pp+nn)-1]; nn--;
1759 s->mtfa[pp] = uc;
1760 } else {
1762 lno = nn / 16;
1763 off = nn % 16;
1764 pp = s->mtfbase[lno] + off;
1765 uc = s->mtfa[pp];
1766 while (pp > s->mtfbase[lno]) {
1767 s->mtfa[pp] = s->mtfa[pp-1]; pp--;
1769 s->mtfbase[lno]++;
1770 while (lno > 0) {
1771 s->mtfbase[lno]--;
1772 s->mtfa[s->mtfbase[lno]]
1773 = s->mtfa[s->mtfbase[lno-1] + 16 - 1];
1774 lno--;
1776 s->mtfbase[0]--;
1777 s->mtfa[s->mtfbase[0]] = uc;
1778 if (s->mtfbase[0] == 0) {
1779 kk = 4096 -1;
1780 for (ii = 256 / 16 -1; ii >= 0; ii--) {
1781 for (jj = 16 -1; jj >= 0; jj--) {
1782 s->mtfa[kk] = s->mtfa[s->mtfbase[ii] + jj];
1783 kk--;
1785 s->mtfbase[ii] = kk + 1;
1792 s->unzftab[s->seqToUnseq[uc]]++;
1793 if (s->smallDecompress)
1794 s->ll16[nblock] = (UInt16)(s->seqToUnseq[uc]); else
1795 s->tt[nblock] = (UInt32)(s->seqToUnseq[uc]);
1796 nblock++;
1798 { if (groupPos == 0) { groupNo++; if (groupNo >= nSelectors) { retVal = (-4); goto save_state_and_return; };; groupPos = 50; gSel = s->selector[groupNo]; gMinlen = s->minLens[gSel]; gLimit = &(s->limit[gSel][0]); gPerm = &(s->perm[gSel][0]); gBase = &(s->base[gSel][0]); } groupPos--; zn = gMinlen; case 40: s->state = 40; while (((Bool)1)) { if (s->bsLive >= zn) { UInt32 v; v = (s->bsBuff >> (s->bsLive-zn)) & ((1 << zn)-1); s->bsLive -= zn; zvec = v; break; } if (s->strm->avail_in == 0) { retVal = 0; goto save_state_and_return; };; s->bsBuff = (s->bsBuff << 8) | ((UInt32) (*((UChar*)(s->strm->next_in)))); s->bsLive += 8; s->strm->next_in++; s->strm->avail_in--; s->strm->total_in_lo32++; if (s->strm->total_in_lo32 == 0) s->strm->total_in_hi32++; }; while (1) { if (zn > 20 ) { retVal = (-4); goto save_state_and_return; };; if (zvec <= gLimit[zn]) break; zn++; case 41: s->state = 41; while (((Bool)1)) { if (s->bsLive >= 1) { UInt32 v; v = (s->bsBuff >> (s->bsLive-1)) & ((1 << 1)-1); s->bsLive -= 1; zj = v; break; } if (s->strm->avail_in == 0) { retVal = 0; goto save_state_and_return; };; s->bsBuff = (s->bsBuff << 8) | ((UInt32) (*((UChar*)(s->strm->next_in)))); s->bsLive += 8; s->strm->next_in++; s->strm->avail_in--; s->strm->total_in_lo32++; if (s->strm->total_in_lo32 == 0) s->strm->total_in_hi32++; }; zvec = (zvec << 1) | zj; }; if (zvec - gBase[zn] < 0 || zvec - gBase[zn] >= 258) { retVal = (-4); goto save_state_and_return; };; nextSym = gPerm[zvec - gBase[zn]]; };
1799 continue;
1806 if (s->origPtr < 0 || s->origPtr >= nblock)
1807 { retVal = (-4); goto save_state_and_return; };;
1810 s->cftab[0] = 0;
1811 for (i = 1; i <= 256; i++) s->cftab[i] = s->unzftab[i-1];
1812 for (i = 1; i <= 256; i++) s->cftab[i] += s->cftab[i-1];
1813 for (i = 0; i <= 256; i++) {
1814 if (s->cftab[i] < 0 || s->cftab[i] > nblock) {
1816 { retVal = (-4); goto save_state_and_return; };;
1820 s->state_out_len = 0;
1821 s->state_out_ch = 0;
1822 { s->calculatedBlockCRC = 0xffffffffL; };
1823 s->state = 2;
1824 if (s->verbosity >= 2) vex_printf("rt+rld");
1826 if (s->smallDecompress) {
1829 for (i = 0; i <= 256; i++) s->cftabCopy[i] = s->cftab[i];
1832 for (i = 0; i < nblock; i++) {
1833 uc = (UChar)(s->ll16[i]);
1834 { s->ll16[i] = (UInt16)(s->cftabCopy[uc] & 0x0000ffff); { if (((i) & 0x1) == 0) s->ll4[(i) >> 1] = (s->ll4[(i) >> 1] & 0xf0) | (s->cftabCopy[uc] >> 16); else s->ll4[(i) >> 1] = (s->ll4[(i) >> 1] & 0x0f) | ((s->cftabCopy[uc] >> 16) << 4); }; };
1835 s->cftabCopy[uc]++;
1839 i = s->origPtr;
1840 j = (((UInt32)s->ll16[i]) | (((((UInt32)(s->ll4[(i) >> 1])) >> (((i) << 2) & 0x4)) & 0xF) << 16));
1841 do {
1842 Int32 tmp = (((UInt32)s->ll16[j]) | (((((UInt32)(s->ll4[(j) >> 1])) >> (((j) << 2) & 0x4)) & 0xF) << 16));
1843 { s->ll16[j] = (UInt16)(i & 0x0000ffff); { if (((j) & 0x1) == 0) s->ll4[(j) >> 1] = (s->ll4[(j) >> 1] & 0xf0) | (i >> 16); else s->ll4[(j) >> 1] = (s->ll4[(j) >> 1] & 0x0f) | ((i >> 16) << 4); }; };
1844 i = j;
1845 j = tmp;
1847 while (i != s->origPtr);
1849 s->tPos = s->origPtr;
1850 s->nblock_used = 0;
1851 if (s->blockRandomised) {
1852 s->rNToGo = 0; s->rTPos = 0;
1853 s->k0 = BZ2_indexIntoF ( s->tPos, s->cftab ); s->tPos = (((UInt32)s->ll16[s->tPos]) | (((((UInt32)(s->ll4[(s->tPos) >> 1])) >> (((s->tPos) << 2) & 0x4)) & 0xF) << 16));; s->nblock_used++;
1854 if (s->rNToGo == 0) { s->rNToGo = BZ2_rNums[s->rTPos]; s->rTPos++; if (s->rTPos == 512) s->rTPos = 0; } s->rNToGo--;; s->k0 ^= ((s->rNToGo == 1) ? 1 : 0);
1855 } else {
1856 s->k0 = BZ2_indexIntoF ( s->tPos, s->cftab ); s->tPos = (((UInt32)s->ll16[s->tPos]) | (((((UInt32)(s->ll4[(s->tPos) >> 1])) >> (((s->tPos) << 2) & 0x4)) & 0xF) << 16));; s->nblock_used++;
1859 } else {
1862 for (i = 0; i < nblock; i++) {
1863 uc = (UChar)(s->tt[i] & 0xff);
1864 s->tt[s->cftab[uc]] |= (i << 8);
1865 s->cftab[uc]++;
1868 s->tPos = s->tt[s->origPtr] >> 8;
1869 s->nblock_used = 0;
1870 if (s->blockRandomised) {
1871 s->rNToGo = 0; s->rTPos = 0;
1872 s->tPos = s->tt[s->tPos]; s->k0 = (UChar)(s->tPos & 0xff); s->tPos >>= 8;; s->nblock_used++;
1873 if (s->rNToGo == 0) { s->rNToGo = BZ2_rNums[s->rTPos]; s->rTPos++; if (s->rTPos == 512) s->rTPos = 0; } s->rNToGo--;; s->k0 ^= ((s->rNToGo == 1) ? 1 : 0);
1874 } else {
1875 s->tPos = s->tt[s->tPos]; s->k0 = (UChar)(s->tPos & 0xff); s->tPos >>= 8;; s->nblock_used++;
1880 { retVal = 0; goto save_state_and_return; };;
1884 endhdr_2:
1886 case 42: s->state = 42; while (((Bool)1)) { if (s->bsLive >= 8) { UInt32 v; v = (s->bsBuff >> (s->bsLive-8)) & ((1 << 8)-1); s->bsLive -= 8; uc = v; break; } if (s->strm->avail_in == 0) { retVal = 0; goto save_state_and_return; };; s->bsBuff = (s->bsBuff << 8) | ((UInt32) (*((UChar*)(s->strm->next_in)))); s->bsLive += 8; s->strm->next_in++; s->strm->avail_in--; s->strm->total_in_lo32++; if (s->strm->total_in_lo32 == 0) s->strm->total_in_hi32++; };
1887 if (uc != 0x72) { retVal = (-4); goto save_state_and_return; };;
1888 case 43: s->state = 43; while (((Bool)1)) { if (s->bsLive >= 8) { UInt32 v; v = (s->bsBuff >> (s->bsLive-8)) & ((1 << 8)-1); s->bsLive -= 8; uc = v; break; } if (s->strm->avail_in == 0) { retVal = 0; goto save_state_and_return; };; s->bsBuff = (s->bsBuff << 8) | ((UInt32) (*((UChar*)(s->strm->next_in)))); s->bsLive += 8; s->strm->next_in++; s->strm->avail_in--; s->strm->total_in_lo32++; if (s->strm->total_in_lo32 == 0) s->strm->total_in_hi32++; };
1889 if (uc != 0x45) { retVal = (-4); goto save_state_and_return; };;
1890 case 44: s->state = 44; while (((Bool)1)) { if (s->bsLive >= 8) { UInt32 v; v = (s->bsBuff >> (s->bsLive-8)) & ((1 << 8)-1); s->bsLive -= 8; uc = v; break; } if (s->strm->avail_in == 0) { retVal = 0; goto save_state_and_return; };; s->bsBuff = (s->bsBuff << 8) | ((UInt32) (*((UChar*)(s->strm->next_in)))); s->bsLive += 8; s->strm->next_in++; s->strm->avail_in--; s->strm->total_in_lo32++; if (s->strm->total_in_lo32 == 0) s->strm->total_in_hi32++; };
1891 if (uc != 0x38) { retVal = (-4); goto save_state_and_return; };;
1892 case 45: s->state = 45; while (((Bool)1)) { if (s->bsLive >= 8) { UInt32 v; v = (s->bsBuff >> (s->bsLive-8)) & ((1 << 8)-1); s->bsLive -= 8; uc = v; break; } if (s->strm->avail_in == 0) { retVal = 0; goto save_state_and_return; };; s->bsBuff = (s->bsBuff << 8) | ((UInt32) (*((UChar*)(s->strm->next_in)))); s->bsLive += 8; s->strm->next_in++; s->strm->avail_in--; s->strm->total_in_lo32++; if (s->strm->total_in_lo32 == 0) s->strm->total_in_hi32++; };
1893 if (uc != 0x50) { retVal = (-4); goto save_state_and_return; };;
1894 case 46: s->state = 46; while (((Bool)1)) { if (s->bsLive >= 8) { UInt32 v; v = (s->bsBuff >> (s->bsLive-8)) & ((1 << 8)-1); s->bsLive -= 8; uc = v; break; } if (s->strm->avail_in == 0) { retVal = 0; goto save_state_and_return; };; s->bsBuff = (s->bsBuff << 8) | ((UInt32) (*((UChar*)(s->strm->next_in)))); s->bsLive += 8; s->strm->next_in++; s->strm->avail_in--; s->strm->total_in_lo32++; if (s->strm->total_in_lo32 == 0) s->strm->total_in_hi32++; };
1895 if (uc != 0x90) { retVal = (-4); goto save_state_and_return; };;
1897 s->storedCombinedCRC = 0;
1898 case 47: s->state = 47; while (((Bool)1)) { if (s->bsLive >= 8) { UInt32 v; v = (s->bsBuff >> (s->bsLive-8)) & ((1 << 8)-1); s->bsLive -= 8; uc = v; break; } if (s->strm->avail_in == 0) { retVal = 0; goto save_state_and_return; };; s->bsBuff = (s->bsBuff << 8) | ((UInt32) (*((UChar*)(s->strm->next_in)))); s->bsLive += 8; s->strm->next_in++; s->strm->avail_in--; s->strm->total_in_lo32++; if (s->strm->total_in_lo32 == 0) s->strm->total_in_hi32++; };
1899 s->storedCombinedCRC = (s->storedCombinedCRC << 8) | ((UInt32)uc);
1900 case 48: s->state = 48; while (((Bool)1)) { if (s->bsLive >= 8) { UInt32 v; v = (s->bsBuff >> (s->bsLive-8)) & ((1 << 8)-1); s->bsLive -= 8; uc = v; break; } if (s->strm->avail_in == 0) { retVal = 0; goto save_state_and_return; };; s->bsBuff = (s->bsBuff << 8) | ((UInt32) (*((UChar*)(s->strm->next_in)))); s->bsLive += 8; s->strm->next_in++; s->strm->avail_in--; s->strm->total_in_lo32++; if (s->strm->total_in_lo32 == 0) s->strm->total_in_hi32++; };
1901 s->storedCombinedCRC = (s->storedCombinedCRC << 8) | ((UInt32)uc);
1902 case 49: s->state = 49; while (((Bool)1)) { if (s->bsLive >= 8) { UInt32 v; v = (s->bsBuff >> (s->bsLive-8)) & ((1 << 8)-1); s->bsLive -= 8; uc = v; break; } if (s->strm->avail_in == 0) { retVal = 0; goto save_state_and_return; };; s->bsBuff = (s->bsBuff << 8) | ((UInt32) (*((UChar*)(s->strm->next_in)))); s->bsLive += 8; s->strm->next_in++; s->strm->avail_in--; s->strm->total_in_lo32++; if (s->strm->total_in_lo32 == 0) s->strm->total_in_hi32++; };
1903 s->storedCombinedCRC = (s->storedCombinedCRC << 8) | ((UInt32)uc);
1904 case 50: s->state = 50; while (((Bool)1)) { if (s->bsLive >= 8) { UInt32 v; v = (s->bsBuff >> (s->bsLive-8)) & ((1 << 8)-1); s->bsLive -= 8; uc = v; break; } if (s->strm->avail_in == 0) { retVal = 0; goto save_state_and_return; };; s->bsBuff = (s->bsBuff << 8) | ((UInt32) (*((UChar*)(s->strm->next_in)))); s->bsLive += 8; s->strm->next_in++; s->strm->avail_in--; s->strm->total_in_lo32++; if (s->strm->total_in_lo32 == 0) s->strm->total_in_hi32++; };
1905 s->storedCombinedCRC = (s->storedCombinedCRC << 8) | ((UInt32)uc);
1907 s->state = 1;
1908 { retVal = 4; goto save_state_and_return; };;
1910 default: { if (!(((Bool)0))) bz_internal_error ( 4001 ); };
1913 { if (!(((Bool)0))) bz_internal_error ( 4002 ); };
1915 save_state_and_return:
1917 s->save_i = i;
1918 s->save_j = j;
1919 s->save_t = t;
1920 s->save_alphaSize = alphaSize;
1921 s->save_nGroups = nGroups;
1922 s->save_nSelectors = nSelectors;
1923 s->save_EOB = EOB;
1924 s->save_groupNo = groupNo;
1925 s->save_groupPos = groupPos;
1926 s->save_nextSym = nextSym;
1927 s->save_nblockMAX = nblockMAX;
1928 s->save_nblock = nblock;
1929 s->save_es = es;
1930 s->save_N = N;
1931 s->save_curr = curr;
1932 s->save_zt = zt;
1933 s->save_zn = zn;
1934 s->save_zvec = zvec;
1935 s->save_zj = zj;
1936 s->save_gSel = gSel;
1937 s->save_gMinlen = gMinlen;
1938 s->save_gLimit = gLimit;
1939 s->save_gBase = gBase;
1940 s->save_gPerm = gPerm;
1942 return retVal;
1945 static
1946 __inline__
1947 void fallbackSimpleSort ( UInt32* fmap,
1948 UInt32* eclass,
1949 Int32 lo,
1950 Int32 hi )
1952 Int32 i, j, tmp;
1953 UInt32 ec_tmp;
1955 if (lo == hi) return;
1957 if (hi - lo > 3) {
1958 for ( i = hi-4; i >= lo; i-- ) {
1959 tmp = fmap[i];
1960 ec_tmp = eclass[tmp];
1961 for ( j = i+4; j <= hi && ec_tmp > eclass[fmap[j]]; j += 4 )
1962 fmap[j-4] = fmap[j];
1963 fmap[j-4] = tmp;
1967 for ( i = hi-1; i >= lo; i-- ) {
1968 tmp = fmap[i];
1969 ec_tmp = eclass[tmp];
1970 for ( j = i+1; j <= hi && ec_tmp > eclass[fmap[j]]; j++ )
1971 fmap[j-1] = fmap[j];
1972 fmap[j-1] = tmp;
1976 static
1977 void fallbackQSort3 ( UInt32* fmap,
1978 UInt32* eclass,
1979 Int32 loSt,
1980 Int32 hiSt )
1982 Int32 unLo, unHi, ltLo, gtHi, n, m;
1983 Int32 sp, lo, hi;
1984 UInt32 med, r, r3;
1985 Int32 stackLo[100];
1986 Int32 stackHi[100];
1988 r = 0;
1990 sp = 0;
1991 { stackLo[sp] = loSt; stackHi[sp] = hiSt; sp++; };
1993 while (sp > 0) {
1995 { if (!(sp < 100)) bz_internal_error ( 1004 ); };
1997 { sp--; lo = stackLo[sp]; hi = stackHi[sp]; };
1998 if (hi - lo < 10) {
1999 fallbackSimpleSort ( fmap, eclass, lo, hi );
2000 continue;
2003 r = ((r * 7621) + 1) % 32768;
2004 r3 = r % 3;
2005 if (r3 == 0) med = eclass[fmap[lo]]; else
2006 if (r3 == 1) med = eclass[fmap[(lo+hi)>>1]]; else
2007 med = eclass[fmap[hi]];
2009 unLo = ltLo = lo;
2010 unHi = gtHi = hi;
2012 while (1) {
2013 while (1) {
2014 if (unLo > unHi) break;
2015 n = (Int32)eclass[fmap[unLo]] - (Int32)med;
2016 if (n == 0) {
2017 { Int32 zztmp = fmap[unLo]; fmap[unLo] = fmap[ltLo]; fmap[ltLo] = zztmp; };
2018 ltLo++; unLo++;
2019 continue;
2021 if (n > 0) break;
2022 unLo++;
2024 while (1) {
2025 if (unLo > unHi) break;
2026 n = (Int32)eclass[fmap[unHi]] - (Int32)med;
2027 if (n == 0) {
2028 { Int32 zztmp = fmap[unHi]; fmap[unHi] = fmap[gtHi]; fmap[gtHi] = zztmp; };
2029 gtHi--; unHi--;
2030 continue;
2032 if (n < 0) break;
2033 unHi--;
2035 if (unLo > unHi) break;
2036 { Int32 zztmp = fmap[unLo]; fmap[unLo] = fmap[unHi]; fmap[unHi] = zztmp; }; unLo++; unHi--;
2041 if (gtHi < ltLo) continue;
2043 n = ((ltLo-lo) < (unLo-ltLo)) ? (ltLo-lo) : (unLo-ltLo); { Int32 yyp1 = (lo); Int32 yyp2 = (unLo-n); Int32 yyn = (n); while (yyn > 0) { { Int32 zztmp = fmap[yyp1]; fmap[yyp1] = fmap[yyp2]; fmap[yyp2] = zztmp; }; yyp1++; yyp2++; yyn--; } };
2044 m = ((hi-gtHi) < (gtHi-unHi)) ? (hi-gtHi) : (gtHi-unHi); { Int32 yyp1 = (unLo); Int32 yyp2 = (hi-m+1); Int32 yyn = (m); while (yyn > 0) { { Int32 zztmp = fmap[yyp1]; fmap[yyp1] = fmap[yyp2]; fmap[yyp2] = zztmp; }; yyp1++; yyp2++; yyn--; } };
2046 n = lo + unLo - ltLo - 1;
2047 m = hi - (gtHi - unHi) + 1;
2049 if (n - lo > hi - m) {
2050 { stackLo[sp] = lo; stackHi[sp] = n; sp++; };
2051 { stackLo[sp] = m; stackHi[sp] = hi; sp++; };
2052 } else {
2053 { stackLo[sp] = m; stackHi[sp] = hi; sp++; };
2054 { stackLo[sp] = lo; stackHi[sp] = n; sp++; };
2059 static
2060 void fallbackSort ( UInt32* fmap,
2061 UInt32* eclass,
2062 UInt32* bhtab,
2063 Int32 nblock,
2064 Int32 verb )
2066 Int32 ftab[257];
2067 Int32 ftabCopy[256];
2068 Int32 H, i, j, k, l, r, cc, cc1;
2069 Int32 nNotDone;
2070 Int32 nBhtab;
2071 UChar* eclass8 = (UChar*)eclass;
2077 if (verb >= 4)
2078 vex_printf(" bucket sorting ...\n");
2079 for (i = 0; i < 257; i++) ftab[i] = 0;
2080 for (i = 0; i < nblock; i++) ftab[eclass8[i]]++;
2081 for (i = 0; i < 256; i++) ftabCopy[i] = ftab[i];
2082 for (i = 1; i < 257; i++) ftab[i] += ftab[i-1];
2084 for (i = 0; i < nblock; i++) {
2085 j = eclass8[i];
2086 k = ftab[j] - 1;
2087 ftab[j] = k;
2088 fmap[k] = i;
2091 nBhtab = 2 + (nblock / 32);
2092 for (i = 0; i < nBhtab; i++) bhtab[i] = 0;
2093 for (i = 0; i < 256; i++) bhtab[(ftab[i]) >> 5] |= (1 << ((ftab[i]) & 31));
2095 for (i = 0; i < 32; i++) {
2096 bhtab[(nblock + 2*i) >> 5] |= (1 << ((nblock + 2*i) & 31));
2097 bhtab[(nblock + 2*i + 1) >> 5] &= ~(1 << ((nblock + 2*i + 1) & 31));
2101 H = 1;
2102 while (1) {
2104 if (verb >= 4)
2105 vex_printf(" depth %6d has ",H);
2107 j = 0;
2108 for (i = 0; i < nblock; i++) {
2109 if ((bhtab[(i) >> 5] & (1 << ((i) & 31)))) j = i;
2110 k = fmap[i] - H; if (k < 0) k += nblock;
2111 eclass[k] = j;
2114 nNotDone = 0;
2115 r = -1;
2116 while (1) {
2119 k = r + 1;
2120 while ((bhtab[(k) >> 5] & (1 << ((k) & 31))) && ((k) & 0x01f)) k++;
2121 if ((bhtab[(k) >> 5] & (1 << ((k) & 31)))) {
2122 while (bhtab[(k) >> 5] == 0xffffffff) k += 32;
2123 while ((bhtab[(k) >> 5] & (1 << ((k) & 31)))) k++;
2125 l = k - 1;
2126 if (l >= nblock) break;
2127 while (!(bhtab[(k) >> 5] & (1 << ((k) & 31))) && ((k) & 0x01f)) k++;
2128 if (!(bhtab[(k) >> 5] & (1 << ((k) & 31)))) {
2129 while (bhtab[(k) >> 5] == 0x00000000) k += 32;
2130 while (!(bhtab[(k) >> 5] & (1 << ((k) & 31)))) k++;
2132 r = k - 1;
2133 if (r >= nblock) break;
2136 if (r > l) {
2137 nNotDone += (r - l + 1);
2138 fallbackQSort3 ( fmap, eclass, l, r );
2141 cc = -1;
2142 for (i = l; i <= r; i++) {
2143 cc1 = eclass[fmap[i]];
2144 if (cc != cc1) { bhtab[(i) >> 5] |= (1 << ((i) & 31)); cc = cc1; };
2149 if (verb >= 4)
2150 vex_printf("%6d unresolved strings\n",nNotDone);
2152 H *= 2;
2153 if (H > nblock || nNotDone == 0) break;
2161 if (verb >= 4)
2162 vex_printf(" reconstructing block ...\n");
2163 j = 0;
2164 for (i = 0; i < nblock; i++) {
2165 while (ftabCopy[j] == 0) j++;
2166 ftabCopy[j]--;
2167 eclass8[fmap[i]] = (UChar)j;
2169 { if (!(j < 256)) bz_internal_error ( 1005 ); };
2172 static
2173 __inline__
2174 Bool mainGtU ( UInt32 i1,
2175 UInt32 i2,
2176 UChar* block,
2177 UInt16* quadrant,
2178 UInt32 nblock,
2179 Int32* budget )
2181 Int32 k;
2182 UChar c1, c2;
2183 UInt16 s1, s2;
2187 c1 = block[i1]; c2 = block[i2];
2188 if (c1 != c2) return (c1 > c2);
2189 i1++; i2++;
2191 c1 = block[i1]; c2 = block[i2];
2192 if (c1 != c2) return (c1 > c2);
2193 i1++; i2++;
2195 c1 = block[i1]; c2 = block[i2];
2196 if (c1 != c2) return (c1 > c2);
2197 i1++; i2++;
2199 c1 = block[i1]; c2 = block[i2];
2200 if (c1 != c2) return (c1 > c2);
2201 i1++; i2++;
2203 c1 = block[i1]; c2 = block[i2];
2204 if (c1 != c2) return (c1 > c2);
2205 i1++; i2++;
2207 c1 = block[i1]; c2 = block[i2];
2208 if (c1 != c2) return (c1 > c2);
2209 i1++; i2++;
2211 c1 = block[i1]; c2 = block[i2];
2212 if (c1 != c2) return (c1 > c2);
2213 i1++; i2++;
2215 c1 = block[i1]; c2 = block[i2];
2216 if (c1 != c2) return (c1 > c2);
2217 i1++; i2++;
2219 c1 = block[i1]; c2 = block[i2];
2220 if (c1 != c2) return (c1 > c2);
2221 i1++; i2++;
2223 c1 = block[i1]; c2 = block[i2];
2224 if (c1 != c2) return (c1 > c2);
2225 i1++; i2++;
2227 c1 = block[i1]; c2 = block[i2];
2228 if (c1 != c2) return (c1 > c2);
2229 i1++; i2++;
2231 c1 = block[i1]; c2 = block[i2];
2232 if (c1 != c2) return (c1 > c2);
2233 i1++; i2++;
2235 k = nblock + 8;
2237 do {
2239 c1 = block[i1]; c2 = block[i2];
2240 if (c1 != c2) return (c1 > c2);
2241 s1 = quadrant[i1]; s2 = quadrant[i2];
2242 if (s1 != s2) return (s1 > s2);
2243 i1++; i2++;
2245 c1 = block[i1]; c2 = block[i2];
2246 if (c1 != c2) return (c1 > c2);
2247 s1 = quadrant[i1]; s2 = quadrant[i2];
2248 if (s1 != s2) return (s1 > s2);
2249 i1++; i2++;
2251 c1 = block[i1]; c2 = block[i2];
2252 if (c1 != c2) return (c1 > c2);
2253 s1 = quadrant[i1]; s2 = quadrant[i2];
2254 if (s1 != s2) return (s1 > s2);
2255 i1++; i2++;
2257 c1 = block[i1]; c2 = block[i2];
2258 if (c1 != c2) return (c1 > c2);
2259 s1 = quadrant[i1]; s2 = quadrant[i2];
2260 if (s1 != s2) return (s1 > s2);
2261 i1++; i2++;
2263 c1 = block[i1]; c2 = block[i2];
2264 if (c1 != c2) return (c1 > c2);
2265 s1 = quadrant[i1]; s2 = quadrant[i2];
2266 if (s1 != s2) return (s1 > s2);
2267 i1++; i2++;
2269 c1 = block[i1]; c2 = block[i2];
2270 if (c1 != c2) return (c1 > c2);
2271 s1 = quadrant[i1]; s2 = quadrant[i2];
2272 if (s1 != s2) return (s1 > s2);
2273 i1++; i2++;
2275 c1 = block[i1]; c2 = block[i2];
2276 if (c1 != c2) return (c1 > c2);
2277 s1 = quadrant[i1]; s2 = quadrant[i2];
2278 if (s1 != s2) return (s1 > s2);
2279 i1++; i2++;
2281 c1 = block[i1]; c2 = block[i2];
2282 if (c1 != c2) return (c1 > c2);
2283 s1 = quadrant[i1]; s2 = quadrant[i2];
2284 if (s1 != s2) return (s1 > s2);
2285 i1++; i2++;
2287 if (i1 >= nblock) i1 -= nblock;
2288 if (i2 >= nblock) i2 -= nblock;
2290 k -= 8;
2291 (*budget)--;
2293 while (k >= 0);
2295 return ((Bool)0);
2298 static
2299 Int32 incs[14] = { 1, 4, 13, 40, 121, 364, 1093, 3280,
2300 9841, 29524, 88573, 265720,
2301 797161, 2391484 };
2303 static
2304 void mainSimpleSort ( UInt32* ptr,
2305 UChar* block,
2306 UInt16* quadrant,
2307 Int32 nblock,
2308 Int32 lo,
2309 Int32 hi,
2310 Int32 d,
2311 Int32* budget )
2313 Int32 i, j, h, bigN, hp;
2314 UInt32 v;
2316 bigN = hi - lo + 1;
2317 if (bigN < 2) return;
2319 hp = 0;
2320 while (incs[hp] < bigN) hp++;
2321 hp--;
2323 for (; hp >= 0; hp--) {
2324 h = incs[hp];
2326 i = lo + h;
2327 while (((Bool)1)) {
2330 if (i > hi) break;
2331 v = ptr[i];
2332 j = i;
2333 while ( mainGtU (
2334 ptr[j-h]+d, v+d, block, quadrant, nblock, budget
2335 ) ) {
2336 ptr[j] = ptr[j-h];
2337 j = j - h;
2338 if (j <= (lo + h - 1)) break;
2340 ptr[j] = v;
2341 i++;
2344 if (i > hi) break;
2345 v = ptr[i];
2346 j = i;
2347 while ( mainGtU (
2348 ptr[j-h]+d, v+d, block, quadrant, nblock, budget
2349 ) ) {
2350 ptr[j] = ptr[j-h];
2351 j = j - h;
2352 if (j <= (lo + h - 1)) break;
2354 ptr[j] = v;
2355 i++;
2358 if (i > hi) break;
2359 v = ptr[i];
2360 j = i;
2361 while ( mainGtU (
2362 ptr[j-h]+d, v+d, block, quadrant, nblock, budget
2363 ) ) {
2364 ptr[j] = ptr[j-h];
2365 j = j - h;
2366 if (j <= (lo + h - 1)) break;
2368 ptr[j] = v;
2369 i++;
2371 if (*budget < 0) return;
2376 static
2377 __inline__
2378 UChar mmed3 ( UChar a, UChar b, UChar c )
2380 UChar t;
2381 if (a > b) { t = a; a = b; b = t; };
2382 if (b > c) {
2383 b = c;
2384 if (a > b) b = a;
2386 return b;
2389 static
2390 void mainQSort3 ( UInt32* ptr,
2391 UChar* block,
2392 UInt16* quadrant,
2393 Int32 nblock,
2394 Int32 loSt,
2395 Int32 hiSt,
2396 Int32 dSt,
2397 Int32* budget )
2399 Int32 unLo, unHi, ltLo, gtHi, n, m, med;
2400 Int32 sp, lo, hi, d;
2402 Int32 stackLo[100];
2403 Int32 stackHi[100];
2404 Int32 stackD [100];
2406 Int32 nextLo[3];
2407 Int32 nextHi[3];
2408 Int32 nextD [3];
2410 sp = 0;
2411 { stackLo[sp] = loSt; stackHi[sp] = hiSt; stackD [sp] = dSt; sp++; };
2413 while (sp > 0) {
2415 { if (!(sp < 100)) bz_internal_error ( 1001 ); };
2417 { sp--; lo = stackLo[sp]; hi = stackHi[sp]; d = stackD [sp]; };
2418 if (hi - lo < 20 ||
2419 d > (2 + 12)) {
2420 mainSimpleSort ( ptr, block, quadrant, nblock, lo, hi, d, budget );
2421 if (*budget < 0) return;
2422 continue;
2425 med = (Int32)
2426 mmed3 ( block[ptr[ lo ]+d],
2427 block[ptr[ hi ]+d],
2428 block[ptr[ (lo+hi)>>1 ]+d] );
2430 unLo = ltLo = lo;
2431 unHi = gtHi = hi;
2433 while (((Bool)1)) {
2434 while (((Bool)1)) {
2435 if (unLo > unHi) break;
2436 n = ((Int32)block[ptr[unLo]+d]) - med;
2437 if (n == 0) {
2438 { Int32 zztmp = ptr[unLo]; ptr[unLo] = ptr[ltLo]; ptr[ltLo] = zztmp; };
2439 ltLo++; unLo++; continue;
2441 if (n > 0) break;
2442 unLo++;
2444 while (((Bool)1)) {
2445 if (unLo > unHi) break;
2446 n = ((Int32)block[ptr[unHi]+d]) - med;
2447 if (n == 0) {
2448 { Int32 zztmp = ptr[unHi]; ptr[unHi] = ptr[gtHi]; ptr[gtHi] = zztmp; };
2449 gtHi--; unHi--; continue;
2451 if (n < 0) break;
2452 unHi--;
2454 if (unLo > unHi) break;
2455 { Int32 zztmp = ptr[unLo]; ptr[unLo] = ptr[unHi]; ptr[unHi] = zztmp; }; unLo++; unHi--;
2460 if (gtHi < ltLo) {
2461 { stackLo[sp] = lo; stackHi[sp] = hi; stackD [sp] = d+1; sp++; };
2462 continue;
2465 n = ((ltLo-lo) < (unLo-ltLo)) ? (ltLo-lo) : (unLo-ltLo); { Int32 yyp1 = (lo); Int32 yyp2 = (unLo-n); Int32 yyn = (n); while (yyn > 0) { { Int32 zztmp = ptr[yyp1]; ptr[yyp1] = ptr[yyp2]; ptr[yyp2] = zztmp; }; yyp1++; yyp2++; yyn--; } };
2466 m = ((hi-gtHi) < (gtHi-unHi)) ? (hi-gtHi) : (gtHi-unHi); { Int32 yyp1 = (unLo); Int32 yyp2 = (hi-m+1); Int32 yyn = (m); while (yyn > 0) { { Int32 zztmp = ptr[yyp1]; ptr[yyp1] = ptr[yyp2]; ptr[yyp2] = zztmp; }; yyp1++; yyp2++; yyn--; } };
2468 n = lo + unLo - ltLo - 1;
2469 m = hi - (gtHi - unHi) + 1;
2471 nextLo[0] = lo; nextHi[0] = n; nextD[0] = d;
2472 nextLo[1] = m; nextHi[1] = hi; nextD[1] = d;
2473 nextLo[2] = n+1; nextHi[2] = m-1; nextD[2] = d+1;
2475 if ((nextHi[0]-nextLo[0]) < (nextHi[1]-nextLo[1])) { Int32 tz; tz = nextLo[0]; nextLo[0] = nextLo[1]; nextLo[1] = tz; tz = nextHi[0]; nextHi[0] = nextHi[1]; nextHi[1] = tz; tz = nextD [0]; nextD [0] = nextD [1]; nextD [1] = tz; };
2476 if ((nextHi[1]-nextLo[1]) < (nextHi[2]-nextLo[2])) { Int32 tz; tz = nextLo[1]; nextLo[1] = nextLo[2]; nextLo[2] = tz; tz = nextHi[1]; nextHi[1] = nextHi[2]; nextHi[2] = tz; tz = nextD [1]; nextD [1] = nextD [2]; nextD [2] = tz; };
2477 if ((nextHi[0]-nextLo[0]) < (nextHi[1]-nextLo[1])) { Int32 tz; tz = nextLo[0]; nextLo[0] = nextLo[1]; nextLo[1] = tz; tz = nextHi[0]; nextHi[0] = nextHi[1]; nextHi[1] = tz; tz = nextD [0]; nextD [0] = nextD [1]; nextD [1] = tz; };
2482 { stackLo[sp] = nextLo[0]; stackHi[sp] = nextHi[0]; stackD [sp] = nextD[0]; sp++; };
2483 { stackLo[sp] = nextLo[1]; stackHi[sp] = nextHi[1]; stackD [sp] = nextD[1]; sp++; };
2484 { stackLo[sp] = nextLo[2]; stackHi[sp] = nextHi[2]; stackD [sp] = nextD[2]; sp++; };
2488 static
2489 void mainSort ( UInt32* ptr,
2490 UChar* block,
2491 UInt16* quadrant,
2492 UInt32* ftab,
2493 Int32 nblock,
2494 Int32 verb,
2495 Int32* budget )
2497 Int32 i, j, k, ss, sb;
2498 Int32 runningOrder[256];
2499 Bool bigDone[256];
2500 Int32 copyStart[256];
2501 Int32 copyEnd [256];
2502 UChar c1;
2503 Int32 numQSorted;
2504 UInt16 s;
2505 if (verb >= 4) vex_printf(" main sort initialise ...\n");
2508 for (i = 65536; i >= 0; i--) ftab[i] = 0;
2510 j = block[0] << 8;
2511 i = nblock-1;
2512 for (; i >= 3; i -= 4) {
2513 quadrant[i] = 0;
2514 j = (j >> 8) | ( ((UInt16)block[i]) << 8);
2515 ftab[j]++;
2516 quadrant[i-1] = 0;
2517 j = (j >> 8) | ( ((UInt16)block[i-1]) << 8);
2518 ftab[j]++;
2519 quadrant[i-2] = 0;
2520 j = (j >> 8) | ( ((UInt16)block[i-2]) << 8);
2521 ftab[j]++;
2522 quadrant[i-3] = 0;
2523 j = (j >> 8) | ( ((UInt16)block[i-3]) << 8);
2524 ftab[j]++;
2526 for (; i >= 0; i--) {
2527 quadrant[i] = 0;
2528 j = (j >> 8) | ( ((UInt16)block[i]) << 8);
2529 ftab[j]++;
2533 for (i = 0; i < (2 + 12 + 18 + 2); i++) {
2534 block [nblock+i] = block[i];
2535 quadrant[nblock+i] = 0;
2538 if (verb >= 4) vex_printf(" bucket sorting ...\n");
2541 for (i = 1; i <= 65536; i++) ftab[i] += ftab[i-1];
2543 s = block[0] << 8;
2544 i = nblock-1;
2545 for (; i >= 3; i -= 4) {
2546 s = (s >> 8) | (block[i] << 8);
2547 j = ftab[s] -1;
2548 ftab[s] = j;
2549 ptr[j] = i;
2550 s = (s >> 8) | (block[i-1] << 8);
2551 j = ftab[s] -1;
2552 ftab[s] = j;
2553 ptr[j] = i-1;
2554 s = (s >> 8) | (block[i-2] << 8);
2555 j = ftab[s] -1;
2556 ftab[s] = j;
2557 ptr[j] = i-2;
2558 s = (s >> 8) | (block[i-3] << 8);
2559 j = ftab[s] -1;
2560 ftab[s] = j;
2561 ptr[j] = i-3;
2563 for (; i >= 0; i--) {
2564 s = (s >> 8) | (block[i] << 8);
2565 j = ftab[s] -1;
2566 ftab[s] = j;
2567 ptr[j] = i;
2575 for (i = 0; i <= 255; i++) {
2576 bigDone [i] = ((Bool)0);
2577 runningOrder[i] = i;
2581 Int32 vv;
2582 Int32 h = 1;
2583 do h = 3 * h + 1; while (h <= 256);
2584 do {
2585 h = h / 3;
2586 for (i = h; i <= 255; i++) {
2587 vv = runningOrder[i];
2588 j = i;
2589 while ( (ftab[((runningOrder[j-h])+1) << 8] - ftab[(runningOrder[j-h]) << 8]) > (ftab[((vv)+1) << 8] - ftab[(vv) << 8]) ) {
2590 runningOrder[j] = runningOrder[j-h];
2591 j = j - h;
2592 if (j <= (h - 1)) goto zero;
2594 zero:
2595 runningOrder[j] = vv;
2597 } while (h != 1);
2604 numQSorted = 0;
2606 for (i = 0; i <= 255; i++) {
2614 ss = runningOrder[i];
2616 for (j = 0; j <= 255; j++) {
2617 if (j != ss) {
2618 sb = (ss << 8) + j;
2619 if ( ! (ftab[sb] & (1 << 21)) ) {
2620 Int32 lo = ftab[sb] & (~((1 << 21)));
2621 Int32 hi = (ftab[sb+1] & (~((1 << 21)))) - 1;
2622 if (hi > lo) {
2623 if (verb >= 4)
2624 vex_printf(" qsort [0x%x, 0x%x] " "done %d this %d\n",ss,j,numQSorted,hi - lo + 1);
2627 mainQSort3 (
2628 ptr, block, quadrant, nblock,
2629 lo, hi, 2, budget
2631 numQSorted += (hi - lo + 1);
2632 if (*budget < 0) return;
2635 ftab[sb] |= (1 << 21);
2639 { if (!(!bigDone[ss])) bz_internal_error ( 1006 ); };
2642 for (j = 0; j <= 255; j++) {
2643 copyStart[j] = ftab[(j << 8) + ss] & (~((1 << 21)));
2644 copyEnd [j] = (ftab[(j << 8) + ss + 1] & (~((1 << 21)))) - 1;
2646 for (j = ftab[ss << 8] & (~((1 << 21))); j < copyStart[ss]; j++) {
2647 k = ptr[j]-1; if (k < 0) k += nblock;
2648 c1 = block[k];
2649 if (!bigDone[c1])
2650 ptr[ copyStart[c1]++ ] = k;
2652 for (j = (ftab[(ss+1) << 8] & (~((1 << 21)))) - 1; j > copyEnd[ss]; j--) {
2653 k = ptr[j]-1; if (k < 0) k += nblock;
2654 c1 = block[k];
2655 if (!bigDone[c1])
2656 ptr[ copyEnd[c1]-- ] = k;
2660 { if (!((copyStart[ss]-1 == copyEnd[ss]) || (copyStart[ss] == 0 && copyEnd[ss] == nblock-1))) bz_internal_error ( 1007 ); }
2662 for (j = 0; j <= 255; j++) ftab[(j << 8) + ss] |= (1 << 21);
2664 bigDone[ss] = ((Bool)1);
2666 if (i < 255) {
2667 Int32 bbStart = ftab[ss << 8] & (~((1 << 21)));
2668 Int32 bbSize = (ftab[(ss+1) << 8] & (~((1 << 21)))) - bbStart;
2669 Int32 shifts = 0;
2671 while ((bbSize >> shifts) > 65534) shifts++;
2673 for (j = bbSize-1; j >= 0; j--) {
2674 Int32 a2update = ptr[bbStart + j];
2675 UInt16 qVal = (UInt16)(j >> shifts);
2676 quadrant[a2update] = qVal;
2677 if (a2update < (2 + 12 + 18 + 2))
2678 quadrant[a2update + nblock] = qVal;
2680 { if (!(((bbSize-1) >> shifts) <= 65535)) bz_internal_error ( 1002 ); };
2685 if (verb >= 4)
2686 vex_printf(" %d pointers, %d sorted, %d scanned\n",nblock,numQSorted,nblock - numQSorted);
2690 void BZ2_blockSort ( EState* s )
2692 UInt32* ptr = s->ptr;
2693 UChar* block = s->block;
2694 UInt32* ftab = s->ftab;
2695 Int32 nblock = s->nblock;
2696 Int32 verb = s->verbosity;
2697 Int32 wfact = s->workFactor;
2698 UInt16* quadrant;
2699 Int32 budget;
2700 Int32 budgetInit;
2701 Int32 i;
2703 if (nblock < 1000 ) {
2704 fallbackSort ( s->arr1, s->arr2, ftab, nblock, verb );
2705 } else {
2711 i = nblock+(2 + 12 + 18 + 2);
2712 if (i & 1) i++;
2713 quadrant = (UInt16*)(&(block[i]));
2715 if (wfact < 1 ) wfact = 1;
2716 if (wfact > 100) wfact = 100;
2717 budgetInit = nblock * ((wfact-1) / 3);
2718 budget = budgetInit;
2720 mainSort ( ptr, block, quadrant, ftab, nblock, verb, &budget );
2721 if (0 && verb >= 3)
2722 vex_printf(" %d work, %d block, ratio %5.2f\n",budgetInit - budget,nblock,(float)(budgetInit - budget) / (float)(nblock==0 ? 1 : nblock));
2727 if (budget < 0) {
2728 if (verb >= 2)
2729 vex_printf(" too repetitive; using fallback" " sorting algorithm\n");
2731 fallbackSort ( s->arr1, s->arr2, ftab, nblock, verb );
2735 s->origPtr = -1;
2736 for (i = 0; i < s->nblock; i++)
2737 if (ptr[i] == 0)
2738 { s->origPtr = i; break; };
2740 { if (!(s->origPtr != -1)) bz_internal_error ( 1003 ); };
2743 void BZ2_hbMakeCodeLengths ( UChar *len,
2744 Int32 *freq,
2745 Int32 alphaSize,
2746 Int32 maxLen )
2752 Int32 nNodes, nHeap, n1, n2, i, j, k;
2753 Bool tooLong;
2755 Int32 heap [ 258 + 2 ];
2756 Int32 weight [ 258 * 2 ];
2757 Int32 parent [ 258 * 2 ];
2759 for (i = 0; i < alphaSize; i++)
2760 weight[i+1] = (freq[i] == 0 ? 1 : freq[i]) << 8;
2762 while (((Bool)1)) {
2764 nNodes = alphaSize;
2765 nHeap = 0;
2767 heap[0] = 0;
2768 weight[0] = 0;
2769 parent[0] = -2;
2771 for (i = 1; i <= alphaSize; i++) {
2772 parent[i] = -1;
2773 nHeap++;
2774 heap[nHeap] = i;
2775 { Int32 zz, tmp; zz = nHeap; tmp = heap[zz]; while (weight[tmp] < weight[heap[zz >> 1]]) { heap[zz] = heap[zz >> 1]; zz >>= 1; } heap[zz] = tmp; };
2778 { if (!(nHeap < (258 +2))) bz_internal_error ( 2001 ); };
2780 while (nHeap > 1) {
2781 n1 = heap[1]; heap[1] = heap[nHeap]; nHeap--; { Int32 zz, yy, tmp; zz = 1; tmp = heap[zz]; while (((Bool)1)) { yy = zz << 1; if (yy > nHeap) break; if (yy < nHeap && weight[heap[yy+1]] < weight[heap[yy]]) yy++; if (weight[tmp] < weight[heap[yy]]) break; heap[zz] = heap[yy]; zz = yy; } heap[zz] = tmp; };
2782 n2 = heap[1]; heap[1] = heap[nHeap]; nHeap--; { Int32 zz, yy, tmp; zz = 1; tmp = heap[zz]; while (((Bool)1)) { yy = zz << 1; if (yy > nHeap) break; if (yy < nHeap && weight[heap[yy+1]] < weight[heap[yy]]) yy++; if (weight[tmp] < weight[heap[yy]]) break; heap[zz] = heap[yy]; zz = yy; } heap[zz] = tmp; };
2783 nNodes++;
2784 parent[n1] = parent[n2] = nNodes;
2785 weight[nNodes] = (((weight[n1]) & 0xffffff00)+((weight[n2]) & 0xffffff00)) | (1 + ((((weight[n1]) & 0x000000ff)) > (((weight[n2]) & 0x000000ff)) ? (((weight[n1]) & 0x000000ff)) : (((weight[n2]) & 0x000000ff))));
2786 parent[nNodes] = -1;
2787 nHeap++;
2788 heap[nHeap] = nNodes;
2789 { Int32 zz, tmp; zz = nHeap; tmp = heap[zz]; while (weight[tmp] < weight[heap[zz >> 1]]) { heap[zz] = heap[zz >> 1]; zz >>= 1; } heap[zz] = tmp; };
2792 { if (!(nNodes < (258 * 2))) bz_internal_error ( 2002 ); };
2794 tooLong = ((Bool)0);
2795 for (i = 1; i <= alphaSize; i++) {
2796 j = 0;
2797 k = i;
2798 while (parent[k] >= 0) { k = parent[k]; j++; }
2799 len[i-1] = j;
2800 if (j > maxLen) tooLong = ((Bool)1);
2803 if (! tooLong) break;
2805 for (i = 1; i <= alphaSize; i++) {
2806 j = weight[i] >> 8;
2807 j = 1 + (j / 2);
2808 weight[i] = j << 8;
2815 void BZ2_hbAssignCodes ( Int32 *code,
2816 UChar *length,
2817 Int32 minLen,
2818 Int32 maxLen,
2819 Int32 alphaSize )
2821 Int32 n, vec, i;
2823 vec = 0;
2824 for (n = minLen; n <= maxLen; n++) {
2825 for (i = 0; i < alphaSize; i++)
2826 if (length[i] == n) { code[i] = vec; vec++; };
2827 vec <<= 1;
2833 void BZ2_hbCreateDecodeTables ( Int32 *limit,
2834 Int32 *base,
2835 Int32 *perm,
2836 UChar *length,
2837 Int32 minLen,
2838 Int32 maxLen,
2839 Int32 alphaSize )
2841 Int32 pp, i, j, vec;
2843 pp = 0;
2844 for (i = minLen; i <= maxLen; i++)
2845 for (j = 0; j < alphaSize; j++)
2846 if (length[j] == i) { perm[pp] = j; pp++; };
2848 for (i = 0; i < 23; i++) base[i] = 0;
2849 for (i = 0; i < alphaSize; i++) base[length[i]+1]++;
2851 for (i = 1; i < 23; i++) base[i] += base[i-1];
2853 for (i = 0; i < 23; i++) limit[i] = 0;
2854 vec = 0;
2856 for (i = minLen; i <= maxLen; i++) {
2857 vec += (base[i+1] - base[i]);
2858 limit[i] = vec-1;
2859 vec <<= 1;
2861 for (i = minLen + 1; i <= maxLen; i++)
2862 base[i] = ((limit[i-1] + 1) << 1) - base[i];
2865 void BZ2_bsInitWrite ( EState* s )
2867 s->bsLive = 0;
2868 s->bsBuff = 0;
2873 static
2874 void bsFinishWrite ( EState* s )
2876 while (s->bsLive > 0) {
2877 s->zbits[s->numZ] = (UChar)(s->bsBuff >> 24);
2878 s->numZ++;
2879 s->bsBuff <<= 8;
2880 s->bsLive -= 8;
2884 static
2885 __inline__
2886 void bsW ( EState* s, Int32 n, UInt32 v )
2888 { while (s->bsLive >= 8) { s->zbits[s->numZ] = (UChar)(s->bsBuff >> 24); s->numZ++; s->bsBuff <<= 8; s->bsLive -= 8; } };
2889 s->bsBuff |= (v << (32 - s->bsLive - n));
2890 s->bsLive += n;
2895 static
2896 void bsPutUInt32 ( EState* s, UInt32 u )
2898 bsW ( s, 8, (u >> 24) & 0xffL );
2899 bsW ( s, 8, (u >> 16) & 0xffL );
2900 bsW ( s, 8, (u >> 8) & 0xffL );
2901 bsW ( s, 8, u & 0xffL );
2906 static
2907 void bsPutUChar ( EState* s, UChar c )
2909 bsW( s, 8, (UInt32)c );
2918 static
2919 void makeMaps_e ( EState* s )
2921 Int32 i;
2922 s->nInUse = 0;
2923 for (i = 0; i < 256; i++)
2924 if (s->inUse[i]) {
2925 s->unseqToSeq[i] = s->nInUse;
2926 s->nInUse++;
2932 static
2933 void generateMTFValues ( EState* s )
2935 UChar yy[256];
2936 Int32 i, j;
2937 Int32 zPend;
2938 Int32 wr;
2939 Int32 EOB;
2941 UInt32* ptr = s->ptr;
2942 UChar* block = s->block;
2943 UInt16* mtfv = s->mtfv;
2945 makeMaps_e ( s );
2946 EOB = s->nInUse+1;
2948 for (i = 0; i <= EOB; i++) s->mtfFreq[i] = 0;
2950 wr = 0;
2951 zPend = 0;
2952 for (i = 0; i < s->nInUse; i++) yy[i] = (UChar) i;
2954 for (i = 0; i < s->nblock; i++) {
2955 UChar ll_i;
2957 j = ptr[i]-1; if (j < 0) j += s->nblock;
2958 ll_i = s->unseqToSeq[block[j]];
2961 if (yy[0] == ll_i) {
2962 zPend++;
2963 } else {
2965 if (zPend > 0) {
2966 zPend--;
2967 while (((Bool)1)) {
2968 if (zPend & 1) {
2969 mtfv[wr] = 1; wr++;
2970 s->mtfFreq[1]++;
2971 } else {
2972 mtfv[wr] = 0; wr++;
2973 s->mtfFreq[0]++;
2975 if (zPend < 2) break;
2976 zPend = (zPend - 2) / 2;
2978 zPend = 0;
2981 register UChar rtmp;
2982 register UChar* ryy_j;
2983 register UChar rll_i;
2984 rtmp = yy[1];
2985 yy[1] = yy[0];
2986 ryy_j = &(yy[1]);
2987 rll_i = ll_i;
2988 while ( rll_i != rtmp ) {
2989 register UChar rtmp2;
2990 ryy_j++;
2991 rtmp2 = rtmp;
2992 rtmp = *ryy_j;
2993 *ryy_j = rtmp2;
2995 yy[0] = rtmp;
2996 j = ryy_j - &(yy[0]);
2997 mtfv[wr] = j+1; wr++; s->mtfFreq[j+1]++;
3003 if (zPend > 0) {
3004 zPend--;
3005 while (((Bool)1)) {
3006 if (zPend & 1) {
3007 mtfv[wr] = 1; wr++;
3008 s->mtfFreq[1]++;
3009 } else {
3010 mtfv[wr] = 0; wr++;
3011 s->mtfFreq[0]++;
3013 if (zPend < 2) break;
3014 zPend = (zPend - 2) / 2;
3016 zPend = 0;
3019 mtfv[wr] = EOB; wr++; s->mtfFreq[EOB]++;
3021 s->nMTF = wr;
3029 static
3030 void sendMTFValues ( EState* s )
3032 Int32 v, t, i, j, gs, ge, totc, bt, bc, iter;
3033 Int32 nSelectors, alphaSize, minLen, maxLen, selCtr;
3034 Int32 nGroups, nBytes;
3036 UInt16 cost[6];
3037 Int32 fave[6];
3039 UInt16* mtfv = s->mtfv;
3041 if (s->verbosity >= 3)
3042 vex_printf(" %d in block, %d after MTF & 1-2 coding, " "%d+2 syms in use\n",s->nblock,s->nMTF,s->nInUse);
3046 alphaSize = s->nInUse+2;
3047 for (t = 0; t < 6; t++)
3048 for (v = 0; v < alphaSize; v++)
3049 s->len[t][v] = 15;
3052 { if (!(s->nMTF > 0)) bz_internal_error ( 3001 ); };
3053 if (s->nMTF < 200) nGroups = 2; else
3054 if (s->nMTF < 600) nGroups = 3; else
3055 if (s->nMTF < 1200) nGroups = 4; else
3056 if (s->nMTF < 2400) nGroups = 5; else
3057 nGroups = 6;
3061 Int32 nPart, remF, tFreq, aFreq;
3063 nPart = nGroups;
3064 remF = s->nMTF;
3065 gs = 0;
3066 while (nPart > 0) {
3067 tFreq = remF / nPart;
3068 ge = gs-1;
3069 aFreq = 0;
3070 while (aFreq < tFreq && ge < alphaSize-1) {
3071 ge++;
3072 aFreq += s->mtfFreq[ge];
3075 if (ge > gs
3076 && nPart != nGroups && nPart != 1
3077 && ((nGroups-nPart) % 2 == 1)) {
3078 aFreq -= s->mtfFreq[ge];
3079 ge--;
3082 if (0 && s->verbosity >= 3)
3083 vex_printf(" initial group %d, [%d .. %d], " "has %d syms (%4.1f%%)\n",nPart,gs,ge,aFreq,(100.0 * (float)aFreq) / (float)(s->nMTF));
3088 for (v = 0; v < alphaSize; v++)
3089 if (v >= gs && v <= ge)
3090 s->len[nPart-1][v] = 0; else
3091 s->len[nPart-1][v] = 15;
3093 nPart--;
3094 gs = ge+1;
3095 remF -= aFreq;
3102 for (iter = 0; iter < 4; iter++) {
3104 for (t = 0; t < nGroups; t++) fave[t] = 0;
3106 for (t = 0; t < nGroups; t++)
3107 for (v = 0; v < alphaSize; v++)
3108 s->rfreq[t][v] = 0;
3114 if (nGroups == 6) {
3115 for (v = 0; v < alphaSize; v++) {
3116 s->len_pack[v][0] = (s->len[1][v] << 16) | s->len[0][v];
3117 s->len_pack[v][1] = (s->len[3][v] << 16) | s->len[2][v];
3118 s->len_pack[v][2] = (s->len[5][v] << 16) | s->len[4][v];
3122 nSelectors = 0;
3123 totc = 0;
3124 gs = 0;
3125 while (((Bool)1)) {
3128 if (gs >= s->nMTF) break;
3129 ge = gs + 50 - 1;
3130 if (ge >= s->nMTF) ge = s->nMTF-1;
3136 for (t = 0; t < nGroups; t++) cost[t] = 0;
3138 if (nGroups == 6 && 50 == ge-gs+1) {
3140 register UInt32 cost01, cost23, cost45;
3141 register UInt16 icv;
3142 cost01 = cost23 = cost45 = 0;
3150 icv = mtfv[gs+(0)]; cost01 += s->len_pack[icv][0]; cost23 += s->len_pack[icv][1]; cost45 += s->len_pack[icv][2];; icv = mtfv[gs+(1)]; cost01 += s->len_pack[icv][0]; cost23 += s->len_pack[icv][1]; cost45 += s->len_pack[icv][2];; icv = mtfv[gs+(2)]; cost01 += s->len_pack[icv][0]; cost23 += s->len_pack[icv][1]; cost45 += s->len_pack[icv][2];; icv = mtfv[gs+(3)]; cost01 += s->len_pack[icv][0]; cost23 += s->len_pack[icv][1]; cost45 += s->len_pack[icv][2];; icv = mtfv[gs+(4)]; cost01 += s->len_pack[icv][0]; cost23 += s->len_pack[icv][1]; cost45 += s->len_pack[icv][2];;
3151 icv = mtfv[gs+(5)]; cost01 += s->len_pack[icv][0]; cost23 += s->len_pack[icv][1]; cost45 += s->len_pack[icv][2];; icv = mtfv[gs+(6)]; cost01 += s->len_pack[icv][0]; cost23 += s->len_pack[icv][1]; cost45 += s->len_pack[icv][2];; icv = mtfv[gs+(7)]; cost01 += s->len_pack[icv][0]; cost23 += s->len_pack[icv][1]; cost45 += s->len_pack[icv][2];; icv = mtfv[gs+(8)]; cost01 += s->len_pack[icv][0]; cost23 += s->len_pack[icv][1]; cost45 += s->len_pack[icv][2];; icv = mtfv[gs+(9)]; cost01 += s->len_pack[icv][0]; cost23 += s->len_pack[icv][1]; cost45 += s->len_pack[icv][2];;
3152 icv = mtfv[gs+(10)]; cost01 += s->len_pack[icv][0]; cost23 += s->len_pack[icv][1]; cost45 += s->len_pack[icv][2];; icv = mtfv[gs+(11)]; cost01 += s->len_pack[icv][0]; cost23 += s->len_pack[icv][1]; cost45 += s->len_pack[icv][2];; icv = mtfv[gs+(12)]; cost01 += s->len_pack[icv][0]; cost23 += s->len_pack[icv][1]; cost45 += s->len_pack[icv][2];; icv = mtfv[gs+(13)]; cost01 += s->len_pack[icv][0]; cost23 += s->len_pack[icv][1]; cost45 += s->len_pack[icv][2];; icv = mtfv[gs+(14)]; cost01 += s->len_pack[icv][0]; cost23 += s->len_pack[icv][1]; cost45 += s->len_pack[icv][2];;
3153 icv = mtfv[gs+(15)]; cost01 += s->len_pack[icv][0]; cost23 += s->len_pack[icv][1]; cost45 += s->len_pack[icv][2];; icv = mtfv[gs+(16)]; cost01 += s->len_pack[icv][0]; cost23 += s->len_pack[icv][1]; cost45 += s->len_pack[icv][2];; icv = mtfv[gs+(17)]; cost01 += s->len_pack[icv][0]; cost23 += s->len_pack[icv][1]; cost45 += s->len_pack[icv][2];; icv = mtfv[gs+(18)]; cost01 += s->len_pack[icv][0]; cost23 += s->len_pack[icv][1]; cost45 += s->len_pack[icv][2];; icv = mtfv[gs+(19)]; cost01 += s->len_pack[icv][0]; cost23 += s->len_pack[icv][1]; cost45 += s->len_pack[icv][2];;
3154 icv = mtfv[gs+(20)]; cost01 += s->len_pack[icv][0]; cost23 += s->len_pack[icv][1]; cost45 += s->len_pack[icv][2];; icv = mtfv[gs+(21)]; cost01 += s->len_pack[icv][0]; cost23 += s->len_pack[icv][1]; cost45 += s->len_pack[icv][2];; icv = mtfv[gs+(22)]; cost01 += s->len_pack[icv][0]; cost23 += s->len_pack[icv][1]; cost45 += s->len_pack[icv][2];; icv = mtfv[gs+(23)]; cost01 += s->len_pack[icv][0]; cost23 += s->len_pack[icv][1]; cost45 += s->len_pack[icv][2];; icv = mtfv[gs+(24)]; cost01 += s->len_pack[icv][0]; cost23 += s->len_pack[icv][1]; cost45 += s->len_pack[icv][2];;
3155 icv = mtfv[gs+(25)]; cost01 += s->len_pack[icv][0]; cost23 += s->len_pack[icv][1]; cost45 += s->len_pack[icv][2];; icv = mtfv[gs+(26)]; cost01 += s->len_pack[icv][0]; cost23 += s->len_pack[icv][1]; cost45 += s->len_pack[icv][2];; icv = mtfv[gs+(27)]; cost01 += s->len_pack[icv][0]; cost23 += s->len_pack[icv][1]; cost45 += s->len_pack[icv][2];; icv = mtfv[gs+(28)]; cost01 += s->len_pack[icv][0]; cost23 += s->len_pack[icv][1]; cost45 += s->len_pack[icv][2];; icv = mtfv[gs+(29)]; cost01 += s->len_pack[icv][0]; cost23 += s->len_pack[icv][1]; cost45 += s->len_pack[icv][2];;
3156 icv = mtfv[gs+(30)]; cost01 += s->len_pack[icv][0]; cost23 += s->len_pack[icv][1]; cost45 += s->len_pack[icv][2];; icv = mtfv[gs+(31)]; cost01 += s->len_pack[icv][0]; cost23 += s->len_pack[icv][1]; cost45 += s->len_pack[icv][2];; icv = mtfv[gs+(32)]; cost01 += s->len_pack[icv][0]; cost23 += s->len_pack[icv][1]; cost45 += s->len_pack[icv][2];; icv = mtfv[gs+(33)]; cost01 += s->len_pack[icv][0]; cost23 += s->len_pack[icv][1]; cost45 += s->len_pack[icv][2];; icv = mtfv[gs+(34)]; cost01 += s->len_pack[icv][0]; cost23 += s->len_pack[icv][1]; cost45 += s->len_pack[icv][2];;
3157 icv = mtfv[gs+(35)]; cost01 += s->len_pack[icv][0]; cost23 += s->len_pack[icv][1]; cost45 += s->len_pack[icv][2];; icv = mtfv[gs+(36)]; cost01 += s->len_pack[icv][0]; cost23 += s->len_pack[icv][1]; cost45 += s->len_pack[icv][2];; icv = mtfv[gs+(37)]; cost01 += s->len_pack[icv][0]; cost23 += s->len_pack[icv][1]; cost45 += s->len_pack[icv][2];; icv = mtfv[gs+(38)]; cost01 += s->len_pack[icv][0]; cost23 += s->len_pack[icv][1]; cost45 += s->len_pack[icv][2];; icv = mtfv[gs+(39)]; cost01 += s->len_pack[icv][0]; cost23 += s->len_pack[icv][1]; cost45 += s->len_pack[icv][2];;
3158 icv = mtfv[gs+(40)]; cost01 += s->len_pack[icv][0]; cost23 += s->len_pack[icv][1]; cost45 += s->len_pack[icv][2];; icv = mtfv[gs+(41)]; cost01 += s->len_pack[icv][0]; cost23 += s->len_pack[icv][1]; cost45 += s->len_pack[icv][2];; icv = mtfv[gs+(42)]; cost01 += s->len_pack[icv][0]; cost23 += s->len_pack[icv][1]; cost45 += s->len_pack[icv][2];; icv = mtfv[gs+(43)]; cost01 += s->len_pack[icv][0]; cost23 += s->len_pack[icv][1]; cost45 += s->len_pack[icv][2];; icv = mtfv[gs+(44)]; cost01 += s->len_pack[icv][0]; cost23 += s->len_pack[icv][1]; cost45 += s->len_pack[icv][2];;
3159 icv = mtfv[gs+(45)]; cost01 += s->len_pack[icv][0]; cost23 += s->len_pack[icv][1]; cost45 += s->len_pack[icv][2];; icv = mtfv[gs+(46)]; cost01 += s->len_pack[icv][0]; cost23 += s->len_pack[icv][1]; cost45 += s->len_pack[icv][2];; icv = mtfv[gs+(47)]; cost01 += s->len_pack[icv][0]; cost23 += s->len_pack[icv][1]; cost45 += s->len_pack[icv][2];; icv = mtfv[gs+(48)]; cost01 += s->len_pack[icv][0]; cost23 += s->len_pack[icv][1]; cost45 += s->len_pack[icv][2];; icv = mtfv[gs+(49)]; cost01 += s->len_pack[icv][0]; cost23 += s->len_pack[icv][1]; cost45 += s->len_pack[icv][2];;
3163 cost[0] = cost01 & 0xffff; cost[1] = cost01 >> 16;
3164 cost[2] = cost23 & 0xffff; cost[3] = cost23 >> 16;
3165 cost[4] = cost45 & 0xffff; cost[5] = cost45 >> 16;
3167 } else {
3169 for (i = gs; i <= ge; i++) {
3170 UInt16 icv = mtfv[i];
3171 for (t = 0; t < nGroups; t++) cost[t] += s->len[t][icv];
3179 bc = 999999999; bt = -1;
3180 for (t = 0; t < nGroups; t++)
3181 if (cost[t] < bc) { bc = cost[t]; bt = t; };
3182 totc += bc;
3183 fave[bt]++;
3184 s->selector[nSelectors] = bt;
3185 nSelectors++;
3190 if (nGroups == 6 && 50 == ge-gs+1) {
3195 s->rfreq[bt][ mtfv[gs+(0)] ]++; s->rfreq[bt][ mtfv[gs+(1)] ]++; s->rfreq[bt][ mtfv[gs+(2)] ]++; s->rfreq[bt][ mtfv[gs+(3)] ]++; s->rfreq[bt][ mtfv[gs+(4)] ]++;
3196 s->rfreq[bt][ mtfv[gs+(5)] ]++; s->rfreq[bt][ mtfv[gs+(6)] ]++; s->rfreq[bt][ mtfv[gs+(7)] ]++; s->rfreq[bt][ mtfv[gs+(8)] ]++; s->rfreq[bt][ mtfv[gs+(9)] ]++;
3197 s->rfreq[bt][ mtfv[gs+(10)] ]++; s->rfreq[bt][ mtfv[gs+(11)] ]++; s->rfreq[bt][ mtfv[gs+(12)] ]++; s->rfreq[bt][ mtfv[gs+(13)] ]++; s->rfreq[bt][ mtfv[gs+(14)] ]++;
3198 s->rfreq[bt][ mtfv[gs+(15)] ]++; s->rfreq[bt][ mtfv[gs+(16)] ]++; s->rfreq[bt][ mtfv[gs+(17)] ]++; s->rfreq[bt][ mtfv[gs+(18)] ]++; s->rfreq[bt][ mtfv[gs+(19)] ]++;
3199 s->rfreq[bt][ mtfv[gs+(20)] ]++; s->rfreq[bt][ mtfv[gs+(21)] ]++; s->rfreq[bt][ mtfv[gs+(22)] ]++; s->rfreq[bt][ mtfv[gs+(23)] ]++; s->rfreq[bt][ mtfv[gs+(24)] ]++;
3200 s->rfreq[bt][ mtfv[gs+(25)] ]++; s->rfreq[bt][ mtfv[gs+(26)] ]++; s->rfreq[bt][ mtfv[gs+(27)] ]++; s->rfreq[bt][ mtfv[gs+(28)] ]++; s->rfreq[bt][ mtfv[gs+(29)] ]++;
3201 s->rfreq[bt][ mtfv[gs+(30)] ]++; s->rfreq[bt][ mtfv[gs+(31)] ]++; s->rfreq[bt][ mtfv[gs+(32)] ]++; s->rfreq[bt][ mtfv[gs+(33)] ]++; s->rfreq[bt][ mtfv[gs+(34)] ]++;
3202 s->rfreq[bt][ mtfv[gs+(35)] ]++; s->rfreq[bt][ mtfv[gs+(36)] ]++; s->rfreq[bt][ mtfv[gs+(37)] ]++; s->rfreq[bt][ mtfv[gs+(38)] ]++; s->rfreq[bt][ mtfv[gs+(39)] ]++;
3203 s->rfreq[bt][ mtfv[gs+(40)] ]++; s->rfreq[bt][ mtfv[gs+(41)] ]++; s->rfreq[bt][ mtfv[gs+(42)] ]++; s->rfreq[bt][ mtfv[gs+(43)] ]++; s->rfreq[bt][ mtfv[gs+(44)] ]++;
3204 s->rfreq[bt][ mtfv[gs+(45)] ]++; s->rfreq[bt][ mtfv[gs+(46)] ]++; s->rfreq[bt][ mtfv[gs+(47)] ]++; s->rfreq[bt][ mtfv[gs+(48)] ]++; s->rfreq[bt][ mtfv[gs+(49)] ]++;
3208 } else {
3210 for (i = gs; i <= ge; i++)
3211 s->rfreq[bt][ mtfv[i] ]++;
3214 gs = ge+1;
3216 if (s->verbosity >= 3) {
3217 vex_printf(" pass %d: size is %d, grp uses are ",iter+1,totc/8);
3219 for (t = 0; t < nGroups; t++)
3220 vex_printf("%d ",fave[t]);
3221 vex_printf("\n");
3229 for (t = 0; t < nGroups; t++)
3230 BZ2_hbMakeCodeLengths ( &(s->len[t][0]), &(s->rfreq[t][0]),
3231 alphaSize, 17 );
3235 { if (!(nGroups < 8)) bz_internal_error ( 3002 ); };
3236 { if (!(nSelectors < 32768 && nSelectors <= (2 + (900000 / 50)))) bz_internal_error ( 3003 ); };
3243 UChar pos[6], ll_i, tmp2, tmp;
3244 for (i = 0; i < nGroups; i++) pos[i] = i;
3245 for (i = 0; i < nSelectors; i++) {
3246 ll_i = s->selector[i];
3247 j = 0;
3248 tmp = pos[j];
3249 while ( ll_i != tmp ) {
3250 j++;
3251 tmp2 = tmp;
3252 tmp = pos[j];
3253 pos[j] = tmp2;
3255 pos[0] = tmp;
3256 s->selectorMtf[i] = j;
3261 for (t = 0; t < nGroups; t++) {
3262 minLen = 32;
3263 maxLen = 0;
3264 for (i = 0; i < alphaSize; i++) {
3265 if (s->len[t][i] > maxLen) maxLen = s->len[t][i];
3266 if (s->len[t][i] < minLen) minLen = s->len[t][i];
3268 { if (!(!(maxLen > 17 ))) bz_internal_error ( 3004 ); };
3269 { if (!(!(minLen < 1))) bz_internal_error ( 3005 ); };
3270 BZ2_hbAssignCodes ( &(s->code[t][0]), &(s->len[t][0]),
3271 minLen, maxLen, alphaSize );
3276 Bool inUse16[16];
3277 for (i = 0; i < 16; i++) {
3278 inUse16[i] = ((Bool)0);
3279 for (j = 0; j < 16; j++)
3280 if (s->inUse[i * 16 + j]) inUse16[i] = ((Bool)1);
3283 nBytes = s->numZ;
3284 for (i = 0; i < 16; i++)
3285 if (inUse16[i]) bsW(s,1,1); else bsW(s,1,0);
3287 for (i = 0; i < 16; i++)
3288 if (inUse16[i])
3289 for (j = 0; j < 16; j++) {
3290 if (s->inUse[i * 16 + j]) bsW(s,1,1); else bsW(s,1,0);
3293 if (s->verbosity >= 3)
3294 vex_printf(" bytes: mapping %d, ",s->numZ-nBytes);
3298 nBytes = s->numZ;
3299 bsW ( s, 3, nGroups );
3300 bsW ( s, 15, nSelectors );
3301 for (i = 0; i < nSelectors; i++) {
3302 for (j = 0; j < s->selectorMtf[i]; j++) bsW(s,1,1);
3303 bsW(s,1,0);
3305 if (s->verbosity >= 3)
3306 vex_printf("selectors %d, ",s->numZ-nBytes);
3309 nBytes = s->numZ;
3311 for (t = 0; t < nGroups; t++) {
3312 Int32 curr = s->len[t][0];
3313 bsW ( s, 5, curr );
3314 for (i = 0; i < alphaSize; i++) {
3315 while (curr < s->len[t][i]) { bsW(s,2,2); curr++; };
3316 while (curr > s->len[t][i]) { bsW(s,2,3); curr--; };
3317 bsW ( s, 1, 0 );
3321 if (s->verbosity >= 3)
3322 vex_printf("code lengths %d, ",s->numZ-nBytes);
3325 nBytes = s->numZ;
3326 selCtr = 0;
3327 gs = 0;
3328 while (((Bool)1)) {
3329 if (gs >= s->nMTF) break;
3330 ge = gs + 50 - 1;
3331 if (ge >= s->nMTF) ge = s->nMTF-1;
3332 { if (!(s->selector[selCtr] < nGroups)) bz_internal_error ( 3006 ); };
3334 if (nGroups == 6 && 50 == ge-gs+1) {
3336 UInt16 mtfv_i;
3337 UChar* s_len_sel_selCtr
3338 = &(s->len[s->selector[selCtr]][0]);
3339 Int32* s_code_sel_selCtr
3340 = &(s->code[s->selector[selCtr]][0]);
3348 mtfv_i = mtfv[gs+(0)]; bsW ( s, s_len_sel_selCtr[mtfv_i], s_code_sel_selCtr[mtfv_i] ); mtfv_i = mtfv[gs+(1)]; bsW ( s, s_len_sel_selCtr[mtfv_i], s_code_sel_selCtr[mtfv_i] ); mtfv_i = mtfv[gs+(2)]; bsW ( s, s_len_sel_selCtr[mtfv_i], s_code_sel_selCtr[mtfv_i] ); mtfv_i = mtfv[gs+(3)]; bsW ( s, s_len_sel_selCtr[mtfv_i], s_code_sel_selCtr[mtfv_i] ); mtfv_i = mtfv[gs+(4)]; bsW ( s, s_len_sel_selCtr[mtfv_i], s_code_sel_selCtr[mtfv_i] );
3349 mtfv_i = mtfv[gs+(5)]; bsW ( s, s_len_sel_selCtr[mtfv_i], s_code_sel_selCtr[mtfv_i] ); mtfv_i = mtfv[gs+(6)]; bsW ( s, s_len_sel_selCtr[mtfv_i], s_code_sel_selCtr[mtfv_i] ); mtfv_i = mtfv[gs+(7)]; bsW ( s, s_len_sel_selCtr[mtfv_i], s_code_sel_selCtr[mtfv_i] ); mtfv_i = mtfv[gs+(8)]; bsW ( s, s_len_sel_selCtr[mtfv_i], s_code_sel_selCtr[mtfv_i] ); mtfv_i = mtfv[gs+(9)]; bsW ( s, s_len_sel_selCtr[mtfv_i], s_code_sel_selCtr[mtfv_i] );
3350 mtfv_i = mtfv[gs+(10)]; bsW ( s, s_len_sel_selCtr[mtfv_i], s_code_sel_selCtr[mtfv_i] ); mtfv_i = mtfv[gs+(11)]; bsW ( s, s_len_sel_selCtr[mtfv_i], s_code_sel_selCtr[mtfv_i] ); mtfv_i = mtfv[gs+(12)]; bsW ( s, s_len_sel_selCtr[mtfv_i], s_code_sel_selCtr[mtfv_i] ); mtfv_i = mtfv[gs+(13)]; bsW ( s, s_len_sel_selCtr[mtfv_i], s_code_sel_selCtr[mtfv_i] ); mtfv_i = mtfv[gs+(14)]; bsW ( s, s_len_sel_selCtr[mtfv_i], s_code_sel_selCtr[mtfv_i] );
3351 mtfv_i = mtfv[gs+(15)]; bsW ( s, s_len_sel_selCtr[mtfv_i], s_code_sel_selCtr[mtfv_i] ); mtfv_i = mtfv[gs+(16)]; bsW ( s, s_len_sel_selCtr[mtfv_i], s_code_sel_selCtr[mtfv_i] ); mtfv_i = mtfv[gs+(17)]; bsW ( s, s_len_sel_selCtr[mtfv_i], s_code_sel_selCtr[mtfv_i] ); mtfv_i = mtfv[gs+(18)]; bsW ( s, s_len_sel_selCtr[mtfv_i], s_code_sel_selCtr[mtfv_i] ); mtfv_i = mtfv[gs+(19)]; bsW ( s, s_len_sel_selCtr[mtfv_i], s_code_sel_selCtr[mtfv_i] );
3352 mtfv_i = mtfv[gs+(20)]; bsW ( s, s_len_sel_selCtr[mtfv_i], s_code_sel_selCtr[mtfv_i] ); mtfv_i = mtfv[gs+(21)]; bsW ( s, s_len_sel_selCtr[mtfv_i], s_code_sel_selCtr[mtfv_i] ); mtfv_i = mtfv[gs+(22)]; bsW ( s, s_len_sel_selCtr[mtfv_i], s_code_sel_selCtr[mtfv_i] ); mtfv_i = mtfv[gs+(23)]; bsW ( s, s_len_sel_selCtr[mtfv_i], s_code_sel_selCtr[mtfv_i] ); mtfv_i = mtfv[gs+(24)]; bsW ( s, s_len_sel_selCtr[mtfv_i], s_code_sel_selCtr[mtfv_i] );
3353 mtfv_i = mtfv[gs+(25)]; bsW ( s, s_len_sel_selCtr[mtfv_i], s_code_sel_selCtr[mtfv_i] ); mtfv_i = mtfv[gs+(26)]; bsW ( s, s_len_sel_selCtr[mtfv_i], s_code_sel_selCtr[mtfv_i] ); mtfv_i = mtfv[gs+(27)]; bsW ( s, s_len_sel_selCtr[mtfv_i], s_code_sel_selCtr[mtfv_i] ); mtfv_i = mtfv[gs+(28)]; bsW ( s, s_len_sel_selCtr[mtfv_i], s_code_sel_selCtr[mtfv_i] ); mtfv_i = mtfv[gs+(29)]; bsW ( s, s_len_sel_selCtr[mtfv_i], s_code_sel_selCtr[mtfv_i] );
3354 mtfv_i = mtfv[gs+(30)]; bsW ( s, s_len_sel_selCtr[mtfv_i], s_code_sel_selCtr[mtfv_i] ); mtfv_i = mtfv[gs+(31)]; bsW ( s, s_len_sel_selCtr[mtfv_i], s_code_sel_selCtr[mtfv_i] ); mtfv_i = mtfv[gs+(32)]; bsW ( s, s_len_sel_selCtr[mtfv_i], s_code_sel_selCtr[mtfv_i] ); mtfv_i = mtfv[gs+(33)]; bsW ( s, s_len_sel_selCtr[mtfv_i], s_code_sel_selCtr[mtfv_i] ); mtfv_i = mtfv[gs+(34)]; bsW ( s, s_len_sel_selCtr[mtfv_i], s_code_sel_selCtr[mtfv_i] );
3355 mtfv_i = mtfv[gs+(35)]; bsW ( s, s_len_sel_selCtr[mtfv_i], s_code_sel_selCtr[mtfv_i] ); mtfv_i = mtfv[gs+(36)]; bsW ( s, s_len_sel_selCtr[mtfv_i], s_code_sel_selCtr[mtfv_i] ); mtfv_i = mtfv[gs+(37)]; bsW ( s, s_len_sel_selCtr[mtfv_i], s_code_sel_selCtr[mtfv_i] ); mtfv_i = mtfv[gs+(38)]; bsW ( s, s_len_sel_selCtr[mtfv_i], s_code_sel_selCtr[mtfv_i] ); mtfv_i = mtfv[gs+(39)]; bsW ( s, s_len_sel_selCtr[mtfv_i], s_code_sel_selCtr[mtfv_i] );
3356 mtfv_i = mtfv[gs+(40)]; bsW ( s, s_len_sel_selCtr[mtfv_i], s_code_sel_selCtr[mtfv_i] ); mtfv_i = mtfv[gs+(41)]; bsW ( s, s_len_sel_selCtr[mtfv_i], s_code_sel_selCtr[mtfv_i] ); mtfv_i = mtfv[gs+(42)]; bsW ( s, s_len_sel_selCtr[mtfv_i], s_code_sel_selCtr[mtfv_i] ); mtfv_i = mtfv[gs+(43)]; bsW ( s, s_len_sel_selCtr[mtfv_i], s_code_sel_selCtr[mtfv_i] ); mtfv_i = mtfv[gs+(44)]; bsW ( s, s_len_sel_selCtr[mtfv_i], s_code_sel_selCtr[mtfv_i] );
3357 mtfv_i = mtfv[gs+(45)]; bsW ( s, s_len_sel_selCtr[mtfv_i], s_code_sel_selCtr[mtfv_i] ); mtfv_i = mtfv[gs+(46)]; bsW ( s, s_len_sel_selCtr[mtfv_i], s_code_sel_selCtr[mtfv_i] ); mtfv_i = mtfv[gs+(47)]; bsW ( s, s_len_sel_selCtr[mtfv_i], s_code_sel_selCtr[mtfv_i] ); mtfv_i = mtfv[gs+(48)]; bsW ( s, s_len_sel_selCtr[mtfv_i], s_code_sel_selCtr[mtfv_i] ); mtfv_i = mtfv[gs+(49)]; bsW ( s, s_len_sel_selCtr[mtfv_i], s_code_sel_selCtr[mtfv_i] );
3361 } else {
3363 for (i = gs; i <= ge; i++) {
3364 bsW ( s,
3365 s->len [s->selector[selCtr]] [mtfv[i]],
3366 s->code [s->selector[selCtr]] [mtfv[i]] );
3371 gs = ge+1;
3372 selCtr++;
3374 { if (!(selCtr == nSelectors)) bz_internal_error ( 3007 ); };
3376 if (s->verbosity >= 3)
3377 vex_printf("codes %d\n",s->numZ-nBytes);
3382 void BZ2_compressBlock ( EState* s, Bool is_last_block )
3384 if (s->nblock > 0) {
3386 { s->blockCRC = ~(s->blockCRC); };
3387 s->combinedCRC = (s->combinedCRC << 1) | (s->combinedCRC >> 31);
3388 s->combinedCRC ^= s->blockCRC;
3389 if (s->blockNo > 1) s->numZ = 0;
3391 if (s->verbosity >= 2)
3392 vex_printf(" block %d: crc = 0x%08x, " "combined CRC = 0x%08x, size = %d\n",s->blockNo,s->blockCRC,s->combinedCRC,s->nblock);
3396 BZ2_blockSort ( s );
3399 s->zbits = (UChar*) (&((UChar*)s->arr2)[s->nblock]);
3402 if (s->blockNo == 1) {
3403 BZ2_bsInitWrite ( s );
3404 bsPutUChar ( s, 0x42 );
3405 bsPutUChar ( s, 0x5a );
3406 bsPutUChar ( s, 0x68 );
3407 bsPutUChar ( s, (UChar)(0x30 + s->blockSize100k) );
3410 if (s->nblock > 0) {
3412 bsPutUChar ( s, 0x31 ); bsPutUChar ( s, 0x41 );
3413 bsPutUChar ( s, 0x59 ); bsPutUChar ( s, 0x26 );
3414 bsPutUChar ( s, 0x53 ); bsPutUChar ( s, 0x59 );
3417 bsPutUInt32 ( s, s->blockCRC );
3419 bsW(s,1,0);
3421 bsW ( s, 24, s->origPtr );
3422 generateMTFValues ( s );
3423 sendMTFValues ( s );
3428 if (is_last_block) {
3430 bsPutUChar ( s, 0x17 ); bsPutUChar ( s, 0x72 );
3431 bsPutUChar ( s, 0x45 ); bsPutUChar ( s, 0x38 );
3432 bsPutUChar ( s, 0x50 ); bsPutUChar ( s, 0x90 );
3433 bsPutUInt32 ( s, s->combinedCRC );
3434 if (s->verbosity >= 2)
3435 vex_printf(" final combined CRC = 0x%08x\n ",s->combinedCRC);
3436 bsFinishWrite ( s );
3440 Int32 BZ2_rNums[512] = {
3441 619, 720, 127, 481, 931, 816, 813, 233, 566, 247,
3442 985, 724, 205, 454, 863, 491, 741, 242, 949, 214,
3443 733, 859, 335, 708, 621, 574, 73, 654, 730, 472,
3444 419, 436, 278, 496, 867, 210, 399, 680, 480, 51,
3445 878, 465, 811, 169, 869, 675, 611, 697, 867, 561,
3446 862, 687, 507, 283, 482, 129, 807, 591, 733, 623,
3447 150, 238, 59, 379, 684, 877, 625, 169, 643, 105,
3448 170, 607, 520, 932, 727, 476, 693, 425, 174, 647,
3449 73, 122, 335, 530, 442, 853, 695, 249, 445, 515,
3450 909, 545, 703, 919, 874, 474, 882, 500, 594, 612,
3451 641, 801, 220, 162, 819, 984, 589, 513, 495, 799,
3452 161, 604, 958, 533, 221, 400, 386, 867, 600, 782,
3453 382, 596, 414, 171, 516, 375, 682, 485, 911, 276,
3454 98, 553, 163, 354, 666, 933, 424, 341, 533, 870,
3455 227, 730, 475, 186, 263, 647, 537, 686, 600, 224,
3456 469, 68, 770, 919, 190, 373, 294, 822, 808, 206,
3457 184, 943, 795, 384, 383, 461, 404, 758, 839, 887,
3458 715, 67, 618, 276, 204, 918, 873, 777, 604, 560,
3459 951, 160, 578, 722, 79, 804, 96, 409, 713, 940,
3460 652, 934, 970, 447, 318, 353, 859, 672, 112, 785,
3461 645, 863, 803, 350, 139, 93, 354, 99, 820, 908,
3462 609, 772, 154, 274, 580, 184, 79, 626, 630, 742,
3463 653, 282, 762, 623, 680, 81, 927, 626, 789, 125,
3464 411, 521, 938, 300, 821, 78, 343, 175, 128, 250,
3465 170, 774, 972, 275, 999, 639, 495, 78, 352, 126,
3466 857, 956, 358, 619, 580, 124, 737, 594, 701, 612,
3467 669, 112, 134, 694, 363, 992, 809, 743, 168, 974,
3468 944, 375, 748, 52, 600, 747, 642, 182, 862, 81,
3469 344, 805, 988, 739, 511, 655, 814, 334, 249, 515,
3470 897, 955, 664, 981, 649, 113, 974, 459, 893, 228,
3471 433, 837, 553, 268, 926, 240, 102, 654, 459, 51,
3472 686, 754, 806, 760, 493, 403, 415, 394, 687, 700,
3473 946, 670, 656, 610, 738, 392, 760, 799, 887, 653,
3474 978, 321, 576, 617, 626, 502, 894, 679, 243, 440,
3475 680, 879, 194, 572, 640, 724, 926, 56, 204, 700,
3476 707, 151, 457, 449, 797, 195, 791, 558, 945, 679,
3477 297, 59, 87, 824, 713, 663, 412, 693, 342, 606,
3478 134, 108, 571, 364, 631, 212, 174, 643, 304, 329,
3479 343, 97, 430, 751, 497, 314, 983, 374, 822, 928,
3480 140, 206, 73, 263, 980, 736, 876, 478, 430, 305,
3481 170, 514, 364, 692, 829, 82, 855, 953, 676, 246,
3482 369, 970, 294, 750, 807, 827, 150, 790, 288, 923,
3483 804, 378, 215, 828, 592, 281, 565, 555, 710, 82,
3484 896, 831, 547, 261, 524, 462, 293, 465, 502, 56,
3485 661, 821, 976, 991, 658, 869, 905, 758, 745, 193,
3486 768, 550, 608, 933, 378, 286, 215, 979, 792, 961,
3487 61, 688, 793, 644, 986, 403, 106, 366, 905, 644,
3488 372, 567, 466, 434, 645, 210, 389, 550, 919, 135,
3489 780, 773, 635, 389, 707, 100, 626, 958, 165, 504,
3490 920, 176, 193, 713, 857, 265, 203, 50, 668, 108,
3491 645, 990, 626, 197, 510, 357, 358, 850, 858, 364,
3492 936, 638
3495 UInt32 BZ2_crc32Table[256] = {
3499 0x00000000L, 0x04c11db7L, 0x09823b6eL, 0x0d4326d9L,
3500 0x130476dcL, 0x17c56b6bL, 0x1a864db2L, 0x1e475005L,
3501 0x2608edb8L, 0x22c9f00fL, 0x2f8ad6d6L, 0x2b4bcb61L,
3502 0x350c9b64L, 0x31cd86d3L, 0x3c8ea00aL, 0x384fbdbdL,
3503 0x4c11db70L, 0x48d0c6c7L, 0x4593e01eL, 0x4152fda9L,
3504 0x5f15adacL, 0x5bd4b01bL, 0x569796c2L, 0x52568b75L,
3505 0x6a1936c8L, 0x6ed82b7fL, 0x639b0da6L, 0x675a1011L,
3506 0x791d4014L, 0x7ddc5da3L, 0x709f7b7aL, 0x745e66cdL,
3507 0x9823b6e0L, 0x9ce2ab57L, 0x91a18d8eL, 0x95609039L,
3508 0x8b27c03cL, 0x8fe6dd8bL, 0x82a5fb52L, 0x8664e6e5L,
3509 0xbe2b5b58L, 0xbaea46efL, 0xb7a96036L, 0xb3687d81L,
3510 0xad2f2d84L, 0xa9ee3033L, 0xa4ad16eaL, 0xa06c0b5dL,
3511 0xd4326d90L, 0xd0f37027L, 0xddb056feL, 0xd9714b49L,
3512 0xc7361b4cL, 0xc3f706fbL, 0xceb42022L, 0xca753d95L,
3513 0xf23a8028L, 0xf6fb9d9fL, 0xfbb8bb46L, 0xff79a6f1L,
3514 0xe13ef6f4L, 0xe5ffeb43L, 0xe8bccd9aL, 0xec7dd02dL,
3515 0x34867077L, 0x30476dc0L, 0x3d044b19L, 0x39c556aeL,
3516 0x278206abL, 0x23431b1cL, 0x2e003dc5L, 0x2ac12072L,
3517 0x128e9dcfL, 0x164f8078L, 0x1b0ca6a1L, 0x1fcdbb16L,
3518 0x018aeb13L, 0x054bf6a4L, 0x0808d07dL, 0x0cc9cdcaL,
3519 0x7897ab07L, 0x7c56b6b0L, 0x71159069L, 0x75d48ddeL,
3520 0x6b93dddbL, 0x6f52c06cL, 0x6211e6b5L, 0x66d0fb02L,
3521 0x5e9f46bfL, 0x5a5e5b08L, 0x571d7dd1L, 0x53dc6066L,
3522 0x4d9b3063L, 0x495a2dd4L, 0x44190b0dL, 0x40d816baL,
3523 0xaca5c697L, 0xa864db20L, 0xa527fdf9L, 0xa1e6e04eL,
3524 0xbfa1b04bL, 0xbb60adfcL, 0xb6238b25L, 0xb2e29692L,
3525 0x8aad2b2fL, 0x8e6c3698L, 0x832f1041L, 0x87ee0df6L,
3526 0x99a95df3L, 0x9d684044L, 0x902b669dL, 0x94ea7b2aL,
3527 0xe0b41de7L, 0xe4750050L, 0xe9362689L, 0xedf73b3eL,
3528 0xf3b06b3bL, 0xf771768cL, 0xfa325055L, 0xfef34de2L,
3529 0xc6bcf05fL, 0xc27dede8L, 0xcf3ecb31L, 0xcbffd686L,
3530 0xd5b88683L, 0xd1799b34L, 0xdc3abdedL, 0xd8fba05aL,
3531 0x690ce0eeL, 0x6dcdfd59L, 0x608edb80L, 0x644fc637L,
3532 0x7a089632L, 0x7ec98b85L, 0x738aad5cL, 0x774bb0ebL,
3533 0x4f040d56L, 0x4bc510e1L, 0x46863638L, 0x42472b8fL,
3534 0x5c007b8aL, 0x58c1663dL, 0x558240e4L, 0x51435d53L,
3535 0x251d3b9eL, 0x21dc2629L, 0x2c9f00f0L, 0x285e1d47L,
3536 0x36194d42L, 0x32d850f5L, 0x3f9b762cL, 0x3b5a6b9bL,
3537 0x0315d626L, 0x07d4cb91L, 0x0a97ed48L, 0x0e56f0ffL,
3538 0x1011a0faL, 0x14d0bd4dL, 0x19939b94L, 0x1d528623L,
3539 0xf12f560eL, 0xf5ee4bb9L, 0xf8ad6d60L, 0xfc6c70d7L,
3540 0xe22b20d2L, 0xe6ea3d65L, 0xeba91bbcL, 0xef68060bL,
3541 0xd727bbb6L, 0xd3e6a601L, 0xdea580d8L, 0xda649d6fL,
3542 0xc423cd6aL, 0xc0e2d0ddL, 0xcda1f604L, 0xc960ebb3L,
3543 0xbd3e8d7eL, 0xb9ff90c9L, 0xb4bcb610L, 0xb07daba7L,
3544 0xae3afba2L, 0xaafbe615L, 0xa7b8c0ccL, 0xa379dd7bL,
3545 0x9b3660c6L, 0x9ff77d71L, 0x92b45ba8L, 0x9675461fL,
3546 0x8832161aL, 0x8cf30badL, 0x81b02d74L, 0x857130c3L,
3547 0x5d8a9099L, 0x594b8d2eL, 0x5408abf7L, 0x50c9b640L,
3548 0x4e8ee645L, 0x4a4ffbf2L, 0x470cdd2bL, 0x43cdc09cL,
3549 0x7b827d21L, 0x7f436096L, 0x7200464fL, 0x76c15bf8L,
3550 0x68860bfdL, 0x6c47164aL, 0x61043093L, 0x65c52d24L,
3551 0x119b4be9L, 0x155a565eL, 0x18197087L, 0x1cd86d30L,
3552 0x029f3d35L, 0x065e2082L, 0x0b1d065bL, 0x0fdc1becL,
3553 0x3793a651L, 0x3352bbe6L, 0x3e119d3fL, 0x3ad08088L,
3554 0x2497d08dL, 0x2056cd3aL, 0x2d15ebe3L, 0x29d4f654L,
3555 0xc5a92679L, 0xc1683bceL, 0xcc2b1d17L, 0xc8ea00a0L,
3556 0xd6ad50a5L, 0xd26c4d12L, 0xdf2f6bcbL, 0xdbee767cL,
3557 0xe3a1cbc1L, 0xe760d676L, 0xea23f0afL, 0xeee2ed18L,
3558 0xf0a5bd1dL, 0xf464a0aaL, 0xf9278673L, 0xfde69bc4L,
3559 0x89b8fd09L, 0x8d79e0beL, 0x803ac667L, 0x84fbdbd0L,
3560 0x9abc8bd5L, 0x9e7d9662L, 0x933eb0bbL, 0x97ffad0cL,
3561 0xafb010b1L, 0xab710d06L, 0xa6322bdfL, 0xa2f33668L,
3562 0xbcb4666dL, 0xb8757bdaL, 0xb5365d03L, 0xb1f740b4L
3565 void BZ2_bz__AssertH__fail ( int errcode )
3567 vex_printf("BZ2_bz__AssertH__fail(%d) called, exiting\n", errcode);
3568 (*serviceFn)(0,0);
3571 void bz_internal_error ( int errcode )
3573 vex_printf("bz_internal_error called, exiting\n", errcode);
3574 (*serviceFn)(0,0);
3578 static
3579 int bz_config_ok ( void )
3581 if (sizeof(int) != 4) return 0;
3582 if (sizeof(short) != 2) return 0;
3583 if (sizeof(char) != 1) return 0;
3584 return 1;
3589 static
3590 void* default_bzalloc ( void* opaque, Int32 items, Int32 size )
3592 void* v = (void*) (*serviceFn)(2, items * size );
3593 return v;
3596 static
3597 void default_bzfree ( void* opaque, void* addr )
3599 if (addr != ((void *)0)) (*serviceFn)( 3, (HWord)addr );
3604 static
3605 void prepare_new_block ( EState* s )
3607 Int32 i;
3608 s->nblock = 0;
3609 s->numZ = 0;
3610 s->state_out_pos = 0;
3611 { s->blockCRC = 0xffffffffL; };
3612 for (i = 0; i < 256; i++) s->inUse[i] = ((Bool)0);
3613 s->blockNo++;
3618 static
3619 void init_RL ( EState* s )
3621 s->state_in_ch = 256;
3622 s->state_in_len = 0;
3626 static
3627 Bool isempty_RL ( EState* s )
3629 if (s->state_in_ch < 256 && s->state_in_len > 0)
3630 return ((Bool)0); else
3631 return ((Bool)1);
3636 int BZ2_bzCompressInit
3637 ( bz_stream* strm,
3638 int blockSize100k,
3639 int verbosity,
3640 int workFactor )
3642 Int32 n;
3643 EState* s;
3645 if (!bz_config_ok()) return (-9);
3647 if (strm == ((void *)0) ||
3648 blockSize100k < 1 || blockSize100k > 9 ||
3649 workFactor < 0 || workFactor > 250)
3650 return (-2);
3652 if (workFactor == 0) workFactor = 30;
3653 if (strm->bzalloc == ((void *)0)) strm->bzalloc = default_bzalloc;
3654 if (strm->bzfree == ((void *)0)) strm->bzfree = default_bzfree;
3656 s = (strm->bzalloc)(strm->opaque,(sizeof(EState)),1);
3657 if (s == ((void *)0)) return (-3);
3658 s->strm = strm;
3660 s->arr1 = ((void *)0);
3661 s->arr2 = ((void *)0);
3662 s->ftab = ((void *)0);
3664 n = 100000 * blockSize100k;
3665 s->arr1 = (strm->bzalloc)(strm->opaque,(n * sizeof(UInt32)),1);
3666 s->arr2 = (strm->bzalloc)(strm->opaque,((n+(2 + 12 + 18 + 2)) * sizeof(UInt32)),1);
3667 s->ftab = (strm->bzalloc)(strm->opaque,(65537 * sizeof(UInt32)),1);
3669 if (s->arr1 == ((void *)0) || s->arr2 == ((void *)0) || s->ftab == ((void *)0)) {
3670 if (s->arr1 != ((void *)0)) (strm->bzfree)(strm->opaque,(s->arr1));
3671 if (s->arr2 != ((void *)0)) (strm->bzfree)(strm->opaque,(s->arr2));
3672 if (s->ftab != ((void *)0)) (strm->bzfree)(strm->opaque,(s->ftab));
3673 if (s != ((void *)0)) (strm->bzfree)(strm->opaque,(s));
3674 return (-3);
3677 s->blockNo = 0;
3678 s->state = 2;
3679 s->mode = 2;
3680 s->combinedCRC = 0;
3681 s->blockSize100k = blockSize100k;
3682 s->nblockMAX = 100000 * blockSize100k - 19;
3683 s->verbosity = verbosity;
3684 s->workFactor = workFactor;
3686 s->block = (UChar*)s->arr2;
3687 s->mtfv = (UInt16*)s->arr1;
3688 s->zbits = ((void *)0);
3689 s->ptr = (UInt32*)s->arr1;
3691 strm->state = s;
3692 strm->total_in_lo32 = 0;
3693 strm->total_in_hi32 = 0;
3694 strm->total_out_lo32 = 0;
3695 strm->total_out_hi32 = 0;
3696 init_RL ( s );
3697 prepare_new_block ( s );
3698 return 0;
3703 static
3704 void add_pair_to_block ( EState* s )
3706 Int32 i;
3707 UChar ch = (UChar)(s->state_in_ch);
3708 for (i = 0; i < s->state_in_len; i++) {
3709 { s->blockCRC = (s->blockCRC << 8) ^ BZ2_crc32Table[(s->blockCRC >> 24) ^ ((UChar)ch)]; };
3711 s->inUse[s->state_in_ch] = ((Bool)1);
3712 switch (s->state_in_len) {
3713 case 1:
3714 s->block[s->nblock] = (UChar)ch; s->nblock++;
3715 break;
3716 case 2:
3717 s->block[s->nblock] = (UChar)ch; s->nblock++;
3718 s->block[s->nblock] = (UChar)ch; s->nblock++;
3719 break;
3720 case 3:
3721 s->block[s->nblock] = (UChar)ch; s->nblock++;
3722 s->block[s->nblock] = (UChar)ch; s->nblock++;
3723 s->block[s->nblock] = (UChar)ch; s->nblock++;
3724 break;
3725 default:
3726 s->inUse[s->state_in_len-4] = ((Bool)1);
3727 s->block[s->nblock] = (UChar)ch; s->nblock++;
3728 s->block[s->nblock] = (UChar)ch; s->nblock++;
3729 s->block[s->nblock] = (UChar)ch; s->nblock++;
3730 s->block[s->nblock] = (UChar)ch; s->nblock++;
3731 s->block[s->nblock] = ((UChar)(s->state_in_len-4));
3732 s->nblock++;
3733 break;
3739 static
3740 void flush_RL ( EState* s )
3742 if (s->state_in_ch < 256) add_pair_to_block ( s );
3743 init_RL ( s );
3746 static
3747 Bool copy_input_until_stop ( EState* s )
3749 Bool progress_in = ((Bool)0);
3751 if (s->mode == 2) {
3754 while (((Bool)1)) {
3756 if (s->nblock >= s->nblockMAX) break;
3758 if (s->strm->avail_in == 0) break;
3759 progress_in = ((Bool)1);
3760 { UInt32 zchh = (UInt32)((UInt32)(*((UChar*)(s->strm->next_in)))); if (zchh != s->state_in_ch && s->state_in_len == 1) { UChar ch = (UChar)(s->state_in_ch); { s->blockCRC = (s->blockCRC << 8) ^ BZ2_crc32Table[(s->blockCRC >> 24) ^ ((UChar)ch)]; }; s->inUse[s->state_in_ch] = ((Bool)1); s->block[s->nblock] = (UChar)ch; s->nblock++; s->state_in_ch = zchh; } else if (zchh != s->state_in_ch || s->state_in_len == 255) { if (s->state_in_ch < 256) add_pair_to_block ( s ); s->state_in_ch = zchh; s->state_in_len = 1; } else { s->state_in_len++; } };
3761 s->strm->next_in++;
3762 s->strm->avail_in--;
3763 s->strm->total_in_lo32++;
3764 if (s->strm->total_in_lo32 == 0) s->strm->total_in_hi32++;
3767 } else {
3770 while (((Bool)1)) {
3772 if (s->nblock >= s->nblockMAX) break;
3774 if (s->strm->avail_in == 0) break;
3776 if (s->avail_in_expect == 0) break;
3777 progress_in = ((Bool)1);
3778 { UInt32 zchh = (UInt32)((UInt32)(*((UChar*)(s->strm->next_in)))); if (zchh != s->state_in_ch && s->state_in_len == 1) { UChar ch = (UChar)(s->state_in_ch); { s->blockCRC = (s->blockCRC << 8) ^ BZ2_crc32Table[(s->blockCRC >> 24) ^ ((UChar)ch)]; }; s->inUse[s->state_in_ch] = ((Bool)1); s->block[s->nblock] = (UChar)ch; s->nblock++; s->state_in_ch = zchh; } else if (zchh != s->state_in_ch || s->state_in_len == 255) { if (s->state_in_ch < 256) add_pair_to_block ( s ); s->state_in_ch = zchh; s->state_in_len = 1; } else { s->state_in_len++; } };
3779 s->strm->next_in++;
3780 s->strm->avail_in--;
3781 s->strm->total_in_lo32++;
3782 if (s->strm->total_in_lo32 == 0) s->strm->total_in_hi32++;
3783 s->avail_in_expect--;
3786 return progress_in;
3791 static
3792 Bool copy_output_until_stop ( EState* s )
3794 Bool progress_out = ((Bool)0);
3796 while (((Bool)1)) {
3799 if (s->strm->avail_out == 0) break;
3802 if (s->state_out_pos >= s->numZ) break;
3804 progress_out = ((Bool)1);
3805 *(s->strm->next_out) = s->zbits[s->state_out_pos];
3806 s->state_out_pos++;
3807 s->strm->avail_out--;
3808 s->strm->next_out++;
3809 s->strm->total_out_lo32++;
3810 if (s->strm->total_out_lo32 == 0) s->strm->total_out_hi32++;
3813 return progress_out;
3818 static
3819 Bool handle_compress ( bz_stream* strm )
3821 Bool progress_in = ((Bool)0);
3822 Bool progress_out = ((Bool)0);
3823 EState* s = strm->state;
3825 while (((Bool)1)) {
3827 if (s->state == 1) {
3828 progress_out |= copy_output_until_stop ( s );
3829 if (s->state_out_pos < s->numZ) break;
3830 if (s->mode == 4 &&
3831 s->avail_in_expect == 0 &&
3832 isempty_RL(s)) break;
3833 prepare_new_block ( s );
3834 s->state = 2;
3835 if (s->mode == 3 &&
3836 s->avail_in_expect == 0 &&
3837 isempty_RL(s)) break;
3840 if (s->state == 2) {
3841 progress_in |= copy_input_until_stop ( s );
3842 if (s->mode != 2 && s->avail_in_expect == 0) {
3843 flush_RL ( s );
3844 BZ2_compressBlock ( s, (Bool)(s->mode == 4) );
3845 s->state = 1;
3847 else
3848 if (s->nblock >= s->nblockMAX) {
3849 BZ2_compressBlock ( s, ((Bool)0) );
3850 s->state = 1;
3852 else
3853 if (s->strm->avail_in == 0) {
3854 break;
3860 return progress_in || progress_out;
3865 int BZ2_bzCompress ( bz_stream *strm, int action )
3867 Bool progress;
3868 EState* s;
3869 if (strm == ((void *)0)) return (-2);
3870 s = strm->state;
3871 if (s == ((void *)0)) return (-2);
3872 if (s->strm != strm) return (-2);
3874 preswitch:
3875 switch (s->mode) {
3877 case 1:
3878 return (-1);
3880 case 2:
3881 if (action == 0) {
3882 progress = handle_compress ( strm );
3883 return progress ? 1 : (-2);
3885 else
3886 if (action == 1) {
3887 s->avail_in_expect = strm->avail_in;
3888 s->mode = 3;
3889 goto preswitch;
3891 else
3892 if (action == 2) {
3893 s->avail_in_expect = strm->avail_in;
3894 s->mode = 4;
3895 goto preswitch;
3897 else
3898 return (-2);
3900 case 3:
3901 if (action != 1) return (-1);
3902 if (s->avail_in_expect != s->strm->avail_in)
3903 return (-1);
3904 progress = handle_compress ( strm );
3905 if (s->avail_in_expect > 0 || !isempty_RL(s) ||
3906 s->state_out_pos < s->numZ) return 2;
3907 s->mode = 2;
3908 return 1;
3910 case 4:
3911 if (action != 2) return (-1);
3912 if (s->avail_in_expect != s->strm->avail_in)
3913 return (-1);
3914 progress = handle_compress ( strm );
3915 if (!progress) return (-1);
3916 if (s->avail_in_expect > 0 || !isempty_RL(s) ||
3917 s->state_out_pos < s->numZ) return 3;
3918 s->mode = 1;
3919 return 4;
3921 return 0;
3926 int BZ2_bzCompressEnd ( bz_stream *strm )
3928 EState* s;
3929 if (strm == ((void *)0)) return (-2);
3930 s = strm->state;
3931 if (s == ((void *)0)) return (-2);
3932 if (s->strm != strm) return (-2);
3934 if (s->arr1 != ((void *)0)) (strm->bzfree)(strm->opaque,(s->arr1));
3935 if (s->arr2 != ((void *)0)) (strm->bzfree)(strm->opaque,(s->arr2));
3936 if (s->ftab != ((void *)0)) (strm->bzfree)(strm->opaque,(s->ftab));
3937 (strm->bzfree)(strm->opaque,(strm->state));
3939 strm->state = ((void *)0);
3941 return 0;
3950 int BZ2_bzDecompressInit
3951 ( bz_stream* strm,
3952 int verbosity,
3953 int small )
3955 DState* s;
3957 if (!bz_config_ok()) return (-9);
3959 if (strm == ((void *)0)) return (-2);
3960 if (small != 0 && small != 1) return (-2);
3961 if (verbosity < 0 || verbosity > 4) return (-2);
3963 if (strm->bzalloc == ((void *)0)) strm->bzalloc = default_bzalloc;
3964 if (strm->bzfree == ((void *)0)) strm->bzfree = default_bzfree;
3966 s = (strm->bzalloc)(strm->opaque,(sizeof(DState)),1);
3967 if (s == ((void *)0)) return (-3);
3968 s->strm = strm;
3969 strm->state = s;
3970 s->state = 10;
3971 s->bsLive = 0;
3972 s->bsBuff = 0;
3973 s->calculatedCombinedCRC = 0;
3974 strm->total_in_lo32 = 0;
3975 strm->total_in_hi32 = 0;
3976 strm->total_out_lo32 = 0;
3977 strm->total_out_hi32 = 0;
3978 s->smallDecompress = (Bool)small;
3979 s->ll4 = ((void *)0);
3980 s->ll16 = ((void *)0);
3981 s->tt = ((void *)0);
3982 s->currBlockNo = 0;
3983 s->verbosity = verbosity;
3985 return 0;
3993 static
3994 Bool unRLE_obuf_to_output_FAST ( DState* s )
3996 UChar k1;
3998 if (s->blockRandomised) {
4000 while (((Bool)1)) {
4002 while (((Bool)1)) {
4003 if (s->strm->avail_out == 0) return ((Bool)0);
4004 if (s->state_out_len == 0) break;
4005 *( (UChar*)(s->strm->next_out) ) = s->state_out_ch;
4006 { s->calculatedBlockCRC = (s->calculatedBlockCRC << 8) ^ BZ2_crc32Table[(s->calculatedBlockCRC >> 24) ^ ((UChar)s->state_out_ch)]; };
4007 s->state_out_len--;
4008 s->strm->next_out++;
4009 s->strm->avail_out--;
4010 s->strm->total_out_lo32++;
4011 if (s->strm->total_out_lo32 == 0) s->strm->total_out_hi32++;
4015 if (s->nblock_used == s->save_nblock+1) return ((Bool)0);
4018 if (s->nblock_used > s->save_nblock+1)
4019 return ((Bool)1);
4021 s->state_out_len = 1;
4022 s->state_out_ch = s->k0;
4023 s->tPos = s->tt[s->tPos]; k1 = (UChar)(s->tPos & 0xff); s->tPos >>= 8;; if (s->rNToGo == 0) { s->rNToGo = BZ2_rNums[s->rTPos]; s->rTPos++; if (s->rTPos == 512) s->rTPos = 0; } s->rNToGo--;;
4024 k1 ^= ((s->rNToGo == 1) ? 1 : 0); s->nblock_used++;
4025 if (s->nblock_used == s->save_nblock+1) continue;
4026 if (k1 != s->k0) { s->k0 = k1; continue; };
4028 s->state_out_len = 2;
4029 s->tPos = s->tt[s->tPos]; k1 = (UChar)(s->tPos & 0xff); s->tPos >>= 8;; if (s->rNToGo == 0) { s->rNToGo = BZ2_rNums[s->rTPos]; s->rTPos++; if (s->rTPos == 512) s->rTPos = 0; } s->rNToGo--;;
4030 k1 ^= ((s->rNToGo == 1) ? 1 : 0); s->nblock_used++;
4031 if (s->nblock_used == s->save_nblock+1) continue;
4032 if (k1 != s->k0) { s->k0 = k1; continue; };
4034 s->state_out_len = 3;
4035 s->tPos = s->tt[s->tPos]; k1 = (UChar)(s->tPos & 0xff); s->tPos >>= 8;; if (s->rNToGo == 0) { s->rNToGo = BZ2_rNums[s->rTPos]; s->rTPos++; if (s->rTPos == 512) s->rTPos = 0; } s->rNToGo--;;
4036 k1 ^= ((s->rNToGo == 1) ? 1 : 0); s->nblock_used++;
4037 if (s->nblock_used == s->save_nblock+1) continue;
4038 if (k1 != s->k0) { s->k0 = k1; continue; };
4040 s->tPos = s->tt[s->tPos]; k1 = (UChar)(s->tPos & 0xff); s->tPos >>= 8;; if (s->rNToGo == 0) { s->rNToGo = BZ2_rNums[s->rTPos]; s->rTPos++; if (s->rTPos == 512) s->rTPos = 0; } s->rNToGo--;;
4041 k1 ^= ((s->rNToGo == 1) ? 1 : 0); s->nblock_used++;
4042 s->state_out_len = ((Int32)k1) + 4;
4043 s->tPos = s->tt[s->tPos]; s->k0 = (UChar)(s->tPos & 0xff); s->tPos >>= 8;; if (s->rNToGo == 0) { s->rNToGo = BZ2_rNums[s->rTPos]; s->rTPos++; if (s->rTPos == 512) s->rTPos = 0; } s->rNToGo--;;
4044 s->k0 ^= ((s->rNToGo == 1) ? 1 : 0); s->nblock_used++;
4047 } else {
4050 UInt32 c_calculatedBlockCRC = s->calculatedBlockCRC;
4051 UChar c_state_out_ch = s->state_out_ch;
4052 Int32 c_state_out_len = s->state_out_len;
4053 Int32 c_nblock_used = s->nblock_used;
4054 Int32 c_k0 = s->k0;
4055 UInt32* c_tt = s->tt;
4056 UInt32 c_tPos = s->tPos;
4057 char* cs_next_out = s->strm->next_out;
4058 unsigned int cs_avail_out = s->strm->avail_out;
4061 UInt32 avail_out_INIT = cs_avail_out;
4062 Int32 s_save_nblockPP = s->save_nblock+1;
4063 unsigned int total_out_lo32_old;
4065 while (((Bool)1)) {
4068 if (c_state_out_len > 0) {
4069 while (((Bool)1)) {
4070 if (cs_avail_out == 0) goto return_notr;
4071 if (c_state_out_len == 1) break;
4072 *( (UChar*)(cs_next_out) ) = c_state_out_ch;
4073 { c_calculatedBlockCRC = (c_calculatedBlockCRC << 8) ^ BZ2_crc32Table[(c_calculatedBlockCRC >> 24) ^ ((UChar)c_state_out_ch)]; };
4074 c_state_out_len--;
4075 cs_next_out++;
4076 cs_avail_out--;
4078 s_state_out_len_eq_one:
4080 if (cs_avail_out == 0) {
4081 c_state_out_len = 1; goto return_notr;
4083 *( (UChar*)(cs_next_out) ) = c_state_out_ch;
4084 { c_calculatedBlockCRC = (c_calculatedBlockCRC << 8) ^ BZ2_crc32Table[(c_calculatedBlockCRC >> 24) ^ ((UChar)c_state_out_ch)]; };
4085 cs_next_out++;
4086 cs_avail_out--;
4090 if (c_nblock_used > s_save_nblockPP)
4091 return ((Bool)1);
4094 if (c_nblock_used == s_save_nblockPP) {
4095 c_state_out_len = 0; goto return_notr;
4097 c_state_out_ch = c_k0;
4098 c_tPos = c_tt[c_tPos]; k1 = (UChar)(c_tPos & 0xff); c_tPos >>= 8;; c_nblock_used++;
4099 if (k1 != c_k0) {
4100 c_k0 = k1; goto s_state_out_len_eq_one;
4102 if (c_nblock_used == s_save_nblockPP)
4103 goto s_state_out_len_eq_one;
4105 c_state_out_len = 2;
4106 c_tPos = c_tt[c_tPos]; k1 = (UChar)(c_tPos & 0xff); c_tPos >>= 8;; c_nblock_used++;
4107 if (c_nblock_used == s_save_nblockPP) continue;
4108 if (k1 != c_k0) { c_k0 = k1; continue; };
4110 c_state_out_len = 3;
4111 c_tPos = c_tt[c_tPos]; k1 = (UChar)(c_tPos & 0xff); c_tPos >>= 8;; c_nblock_used++;
4112 if (c_nblock_used == s_save_nblockPP) continue;
4113 if (k1 != c_k0) { c_k0 = k1; continue; };
4115 c_tPos = c_tt[c_tPos]; k1 = (UChar)(c_tPos & 0xff); c_tPos >>= 8;; c_nblock_used++;
4116 c_state_out_len = ((Int32)k1) + 4;
4117 c_tPos = c_tt[c_tPos]; c_k0 = (UChar)(c_tPos & 0xff); c_tPos >>= 8;; c_nblock_used++;
4120 return_notr:
4121 total_out_lo32_old = s->strm->total_out_lo32;
4122 s->strm->total_out_lo32 += (avail_out_INIT - cs_avail_out);
4123 if (s->strm->total_out_lo32 < total_out_lo32_old)
4124 s->strm->total_out_hi32++;
4127 s->calculatedBlockCRC = c_calculatedBlockCRC;
4128 s->state_out_ch = c_state_out_ch;
4129 s->state_out_len = c_state_out_len;
4130 s->nblock_used = c_nblock_used;
4131 s->k0 = c_k0;
4132 s->tt = c_tt;
4133 s->tPos = c_tPos;
4134 s->strm->next_out = cs_next_out;
4135 s->strm->avail_out = cs_avail_out;
4138 return ((Bool)0);
4147 static
4148 Bool unRLE_obuf_to_output_SMALL ( DState* s )
4150 UChar k1;
4152 if (s->blockRandomised) {
4154 while (((Bool)1)) {
4156 while (((Bool)1)) {
4157 if (s->strm->avail_out == 0) return ((Bool)0);
4158 if (s->state_out_len == 0) break;
4159 *( (UChar*)(s->strm->next_out) ) = s->state_out_ch;
4160 { s->calculatedBlockCRC = (s->calculatedBlockCRC << 8) ^ BZ2_crc32Table[(s->calculatedBlockCRC >> 24) ^ ((UChar)s->state_out_ch)]; };
4161 s->state_out_len--;
4162 s->strm->next_out++;
4163 s->strm->avail_out--;
4164 s->strm->total_out_lo32++;
4165 if (s->strm->total_out_lo32 == 0) s->strm->total_out_hi32++;
4169 if (s->nblock_used == s->save_nblock+1) return ((Bool)0);
4172 if (s->nblock_used > s->save_nblock+1)
4173 return ((Bool)1);
4175 s->state_out_len = 1;
4176 s->state_out_ch = s->k0;
4177 k1 = BZ2_indexIntoF ( s->tPos, s->cftab ); s->tPos = (((UInt32)s->ll16[s->tPos]) | (((((UInt32)(s->ll4[(s->tPos) >> 1])) >> (((s->tPos) << 2) & 0x4)) & 0xF) << 16));; if (s->rNToGo == 0) { s->rNToGo = BZ2_rNums[s->rTPos]; s->rTPos++; if (s->rTPos == 512) s->rTPos = 0; } s->rNToGo--;;
4178 k1 ^= ((s->rNToGo == 1) ? 1 : 0); s->nblock_used++;
4179 if (s->nblock_used == s->save_nblock+1) continue;
4180 if (k1 != s->k0) { s->k0 = k1; continue; };
4182 s->state_out_len = 2;
4183 k1 = BZ2_indexIntoF ( s->tPos, s->cftab ); s->tPos = (((UInt32)s->ll16[s->tPos]) | (((((UInt32)(s->ll4[(s->tPos) >> 1])) >> (((s->tPos) << 2) & 0x4)) & 0xF) << 16));; if (s->rNToGo == 0) { s->rNToGo = BZ2_rNums[s->rTPos]; s->rTPos++; if (s->rTPos == 512) s->rTPos = 0; } s->rNToGo--;;
4184 k1 ^= ((s->rNToGo == 1) ? 1 : 0); s->nblock_used++;
4185 if (s->nblock_used == s->save_nblock+1) continue;
4186 if (k1 != s->k0) { s->k0 = k1; continue; };
4188 s->state_out_len = 3;
4189 k1 = BZ2_indexIntoF ( s->tPos, s->cftab ); s->tPos = (((UInt32)s->ll16[s->tPos]) | (((((UInt32)(s->ll4[(s->tPos) >> 1])) >> (((s->tPos) << 2) & 0x4)) & 0xF) << 16));; if (s->rNToGo == 0) { s->rNToGo = BZ2_rNums[s->rTPos]; s->rTPos++; if (s->rTPos == 512) s->rTPos = 0; } s->rNToGo--;;
4190 k1 ^= ((s->rNToGo == 1) ? 1 : 0); s->nblock_used++;
4191 if (s->nblock_used == s->save_nblock+1) continue;
4192 if (k1 != s->k0) { s->k0 = k1; continue; };
4194 k1 = BZ2_indexIntoF ( s->tPos, s->cftab ); s->tPos = (((UInt32)s->ll16[s->tPos]) | (((((UInt32)(s->ll4[(s->tPos) >> 1])) >> (((s->tPos) << 2) & 0x4)) & 0xF) << 16));; if (s->rNToGo == 0) { s->rNToGo = BZ2_rNums[s->rTPos]; s->rTPos++; if (s->rTPos == 512) s->rTPos = 0; } s->rNToGo--;;
4195 k1 ^= ((s->rNToGo == 1) ? 1 : 0); s->nblock_used++;
4196 s->state_out_len = ((Int32)k1) + 4;
4197 s->k0 = BZ2_indexIntoF ( s->tPos, s->cftab ); s->tPos = (((UInt32)s->ll16[s->tPos]) | (((((UInt32)(s->ll4[(s->tPos) >> 1])) >> (((s->tPos) << 2) & 0x4)) & 0xF) << 16));; if (s->rNToGo == 0) { s->rNToGo = BZ2_rNums[s->rTPos]; s->rTPos++; if (s->rTPos == 512) s->rTPos = 0; } s->rNToGo--;;
4198 s->k0 ^= ((s->rNToGo == 1) ? 1 : 0); s->nblock_used++;
4201 } else {
4203 while (((Bool)1)) {
4205 while (((Bool)1)) {
4206 if (s->strm->avail_out == 0) return ((Bool)0);
4207 if (s->state_out_len == 0) break;
4208 *( (UChar*)(s->strm->next_out) ) = s->state_out_ch;
4209 { s->calculatedBlockCRC = (s->calculatedBlockCRC << 8) ^ BZ2_crc32Table[(s->calculatedBlockCRC >> 24) ^ ((UChar)s->state_out_ch)]; };
4210 s->state_out_len--;
4211 s->strm->next_out++;
4212 s->strm->avail_out--;
4213 s->strm->total_out_lo32++;
4214 if (s->strm->total_out_lo32 == 0) s->strm->total_out_hi32++;
4218 if (s->nblock_used == s->save_nblock+1) return ((Bool)0);
4221 if (s->nblock_used > s->save_nblock+1)
4222 return ((Bool)1);
4224 s->state_out_len = 1;
4225 s->state_out_ch = s->k0;
4226 k1 = BZ2_indexIntoF ( s->tPos, s->cftab ); s->tPos = (((UInt32)s->ll16[s->tPos]) | (((((UInt32)(s->ll4[(s->tPos) >> 1])) >> (((s->tPos) << 2) & 0x4)) & 0xF) << 16));; s->nblock_used++;
4227 if (s->nblock_used == s->save_nblock+1) continue;
4228 if (k1 != s->k0) { s->k0 = k1; continue; };
4230 s->state_out_len = 2;
4231 k1 = BZ2_indexIntoF ( s->tPos, s->cftab ); s->tPos = (((UInt32)s->ll16[s->tPos]) | (((((UInt32)(s->ll4[(s->tPos) >> 1])) >> (((s->tPos) << 2) & 0x4)) & 0xF) << 16));; s->nblock_used++;
4232 if (s->nblock_used == s->save_nblock+1) continue;
4233 if (k1 != s->k0) { s->k0 = k1; continue; };
4235 s->state_out_len = 3;
4236 k1 = BZ2_indexIntoF ( s->tPos, s->cftab ); s->tPos = (((UInt32)s->ll16[s->tPos]) | (((((UInt32)(s->ll4[(s->tPos) >> 1])) >> (((s->tPos) << 2) & 0x4)) & 0xF) << 16));; s->nblock_used++;
4237 if (s->nblock_used == s->save_nblock+1) continue;
4238 if (k1 != s->k0) { s->k0 = k1; continue; };
4240 k1 = BZ2_indexIntoF ( s->tPos, s->cftab ); s->tPos = (((UInt32)s->ll16[s->tPos]) | (((((UInt32)(s->ll4[(s->tPos) >> 1])) >> (((s->tPos) << 2) & 0x4)) & 0xF) << 16));; s->nblock_used++;
4241 s->state_out_len = ((Int32)k1) + 4;
4242 s->k0 = BZ2_indexIntoF ( s->tPos, s->cftab ); s->tPos = (((UInt32)s->ll16[s->tPos]) | (((((UInt32)(s->ll4[(s->tPos) >> 1])) >> (((s->tPos) << 2) & 0x4)) & 0xF) << 16));; s->nblock_used++;
4250 int BZ2_bzDecompress ( bz_stream *strm )
4252 Bool corrupt;
4253 DState* s;
4254 if (strm == ((void *)0)) return (-2);
4255 s = strm->state;
4256 if (s == ((void *)0)) return (-2);
4257 if (s->strm != strm) return (-2);
4259 while (((Bool)1)) {
4260 if (s->state == 1) return (-1);
4261 if (s->state == 2) {
4262 if (s->smallDecompress)
4263 corrupt = unRLE_obuf_to_output_SMALL ( s ); else
4264 corrupt = unRLE_obuf_to_output_FAST ( s );
4265 if (corrupt) return (-4);
4266 if (s->nblock_used == s->save_nblock+1 && s->state_out_len == 0) {
4267 { s->calculatedBlockCRC = ~(s->calculatedBlockCRC); };
4268 if (s->verbosity >= 3)
4269 vex_printf(" {0x%08x, 0x%08x}",s->storedBlockCRC,s->calculatedBlockCRC);
4271 if (s->verbosity >= 2) vex_printf("]");
4272 if (s->calculatedBlockCRC != s->storedBlockCRC)
4273 return (-4);
4274 s->calculatedCombinedCRC
4275 = (s->calculatedCombinedCRC << 1) |
4276 (s->calculatedCombinedCRC >> 31);
4277 s->calculatedCombinedCRC ^= s->calculatedBlockCRC;
4278 s->state = 14;
4279 } else {
4280 return 0;
4283 if (s->state >= 10) {
4284 Int32 r = BZ2_decompress ( s );
4285 if (r == 4) {
4286 if (s->verbosity >= 3)
4287 vex_printf("\n combined CRCs: stored = 0x%08x, computed = 0x%08x",s->storedCombinedCRC,s->calculatedCombinedCRC);
4289 if (s->calculatedCombinedCRC != s->storedCombinedCRC)
4290 return (-4);
4291 return r;
4293 if (s->state != 2) return r;
4297 { if (!(0)) bz_internal_error ( 6001 ); };
4299 return 0;
4304 int BZ2_bzDecompressEnd ( bz_stream *strm )
4306 DState* s;
4307 if (strm == ((void *)0)) return (-2);
4308 s = strm->state;
4309 if (s == ((void *)0)) return (-2);
4310 if (s->strm != strm) return (-2);
4312 if (s->tt != ((void *)0)) (strm->bzfree)(strm->opaque,(s->tt));
4313 if (s->ll16 != ((void *)0)) (strm->bzfree)(strm->opaque,(s->ll16));
4314 if (s->ll4 != ((void *)0)) (strm->bzfree)(strm->opaque,(s->ll4));
4316 (strm->bzfree)(strm->opaque,(strm->state));
4317 strm->state = ((void *)0);
4319 return 0;
4322 int BZ2_bzBuffToBuffCompress
4323 ( char* dest,
4324 unsigned int* destLen,
4325 char* source,
4326 unsigned int sourceLen,
4327 int blockSize100k,
4328 int verbosity,
4329 int workFactor )
4331 bz_stream strm;
4332 int ret;
4334 if (dest == ((void *)0) || destLen == ((void *)0) ||
4335 source == ((void *)0) ||
4336 blockSize100k < 1 || blockSize100k > 9 ||
4337 verbosity < 0 || verbosity > 4 ||
4338 workFactor < 0 || workFactor > 250)
4339 return (-2);
4341 if (workFactor == 0) workFactor = 30;
4342 strm.bzalloc = ((void *)0);
4343 strm.bzfree = ((void *)0);
4344 strm.opaque = ((void *)0);
4345 ret = BZ2_bzCompressInit ( &strm, blockSize100k,
4346 verbosity, workFactor );
4347 if (ret != 0) return ret;
4349 strm.next_in = source;
4350 strm.next_out = dest;
4351 strm.avail_in = sourceLen;
4352 strm.avail_out = *destLen;
4354 ret = BZ2_bzCompress ( &strm, 2 );
4355 if (ret == 3) goto output_overflow;
4356 if (ret != 4) goto errhandler;
4359 *destLen -= strm.avail_out;
4360 BZ2_bzCompressEnd ( &strm );
4361 return 0;
4363 output_overflow:
4364 BZ2_bzCompressEnd ( &strm );
4365 return (-8);
4367 errhandler:
4368 BZ2_bzCompressEnd ( &strm );
4369 return ret;
4374 int BZ2_bzBuffToBuffDecompress
4375 ( char* dest,
4376 unsigned int* destLen,
4377 char* source,
4378 unsigned int sourceLen,
4379 int small,
4380 int verbosity )
4382 bz_stream strm;
4383 int ret;
4385 if (dest == ((void *)0) || destLen == ((void *)0) ||
4386 source == ((void *)0) ||
4387 (small != 0 && small != 1) ||
4388 verbosity < 0 || verbosity > 4)
4389 return (-2);
4391 strm.bzalloc = ((void *)0);
4392 strm.bzfree = ((void *)0);
4393 strm.opaque = ((void *)0);
4394 ret = BZ2_bzDecompressInit ( &strm, verbosity, small );
4395 if (ret != 0) return ret;
4397 strm.next_in = source;
4398 strm.next_out = dest;
4399 strm.avail_in = sourceLen;
4400 strm.avail_out = *destLen;
4402 ret = BZ2_bzDecompress ( &strm );
4403 if (ret == 0) goto output_overflow_or_eof;
4404 if (ret != 4) goto errhandler;
4407 *destLen -= strm.avail_out;
4408 BZ2_bzDecompressEnd ( &strm );
4409 return 0;
4411 output_overflow_or_eof:
4412 if (strm.avail_out > 0) {
4413 BZ2_bzDecompressEnd ( &strm );
4414 return (-7);
4415 } else {
4416 BZ2_bzDecompressEnd ( &strm );
4417 return (-8);
4420 errhandler:
4421 BZ2_bzDecompressEnd ( &strm );
4422 return ret;
4425 const char * BZ2_bzlibVersion(void)
4427 return "1.0.3, 17-Oct-2004";
4430 typedef unsigned char uchar;
4433 char inbuf[1000000];
4434 char outbuf[(1000000 + 1000000)];
4435 char zbuf[1000000 + 600 + (1000000 / 100)];
4437 int nIn;
4438 unsigned int nOut;
4439 unsigned int nZ;
4441 void flip_bit ( int bit )
4443 int byteno = bit / 8;
4444 int bitno = bit % 8;
4445 uchar mask = 1 << bitno;
4448 zbuf[byteno] ^= mask;
4451 void set_inbuf ( void )
4453 inbuf[0] = 0;
4454 my_strcat(inbuf, "At her sixtieth birthday party, Margaret Thatcher ");
4455 my_strcat(inbuf, "blew on the cake to light the candles.\n");
4456 my_strcat(inbuf, "This program, bzip2, the associated library libbzip2, and all\n");
4457 my_strcat(inbuf, "documentation, are copyright (C) 1996-2004 Julian R Seward. All\n");
4458 my_strcat(inbuf, "rights reserved.\n");
4459 my_strcat(inbuf, "\n");
4460 my_strcat(inbuf, "Redistribution and use in source and binary forms, with or without\n");
4461 my_strcat(inbuf, "modification, are permitted provided that the following conditions\n");
4462 my_strcat(inbuf, "are met:\n");
4463 my_strcat(inbuf, "\n");
4464 my_strcat(inbuf, "1. Redistributions of source code must retain the above copyright\n");
4465 my_strcat(inbuf, " notice, this list of conditions and the following disclaimer.\n");
4466 my_strcat(inbuf, "\n");
4467 my_strcat(inbuf, "2. The origin of this software must not be misrepresented; you must\n");
4468 my_strcat(inbuf, " not claim that you wrote the original software. If you use this\n");
4469 my_strcat(inbuf, " software in a product, an acknowledgment in the product\n");
4470 my_strcat(inbuf, " documentation would be appreciated but is not required.\n");
4471 my_strcat(inbuf, "\n");
4472 my_strcat(inbuf, "3. Altered source versions must be plainly marked as such, and must\n");
4473 my_strcat(inbuf, " not be misrepresented as being the original software.\n");
4474 my_strcat(inbuf, "\n");
4475 my_strcat(inbuf, "4. The name of the author may not be used to endorse or promote\n");
4476 my_strcat(inbuf, " products derived from this software without specific prior written\n");
4477 my_strcat(inbuf, " permission.\n");
4478 my_strcat(inbuf, "\n");
4479 my_strcat(inbuf, "THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS\n");
4480 my_strcat(inbuf, "OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n");
4481 my_strcat(inbuf, "WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n");
4482 my_strcat(inbuf, "ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY\n");
4483 my_strcat(inbuf, "DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\n");
4484 my_strcat(inbuf, "DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE\n");
4485 my_strcat(inbuf, "GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\n");
4486 my_strcat(inbuf, "INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n");
4487 my_strcat(inbuf, "WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\n");
4488 my_strcat(inbuf, "NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\n");
4489 my_strcat(inbuf, "SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n");
4490 my_strcat(inbuf, "ababababababababababababababababababababababababababababababab");
4491 my_strcat(inbuf, "ababababababababababababababababababababababababababababababab");
4492 my_strcat(inbuf, "ababababababababababababababababababababababababababababababab");
4493 my_strcat(inbuf, "ababababababababababababababababababababababababababababababab");
4494 my_strcat(inbuf, "ababababababababababababababababababababababababababababababab");
4495 my_strcat(inbuf, "ababababababababababababababababababababababababababababababab");
4496 my_strcat(inbuf, "ababababababababababababababababababababababababababababababab");
4497 my_strcat(inbuf, "ababababababababababababababababababababababababababababababab");
4498 my_strcat(inbuf, "ababababababababababababababababababababababababababababababab");
4499 my_strcat(inbuf, "ababababababababababababababababababababababababababababababab");
4500 my_strcat(inbuf, "ababababababababababababababababababababababababababababababab");
4501 my_strcat(inbuf, "ababababababababababababababababababababababababababababababab");
4502 my_strcat(inbuf, "ababababababababababababababababababababababababababababababab");
4503 my_strcat(inbuf, "ababababababababababababababababababababababababababababababab");
4504 my_strcat(inbuf, "ababababababababababababababababababababababababababababababab");
4505 my_strcat(inbuf, "ababababababababababababababababababababababababababababababab");
4506 my_strcat(inbuf, "ababababababababababababababababababababababababababababababab");
4507 my_strcat(inbuf, "ababababababababababababababababababababababababababababababab");
4508 my_strcat(inbuf, "ababababababababababababababababababababababababababababababab");
4509 my_strcat(inbuf, "ababababababababababababababababababababababababababababababab");
4510 my_strcat(inbuf, "ababababababababababababababababababababababababababababababab");
4511 my_strcat(inbuf, "ababababababababababababababababababababababababababababababab");
4512 my_strcat(inbuf, "ababababababababababababababababababababababababababababababab");
4513 my_strcat(inbuf, "ababababababababababababababababababababababababababababababab");
4514 my_strcat(inbuf, "ababababababababababababababababababababababababababababababab");
4515 my_strcat(inbuf, "ababababababababababababababababababababababababababababababab");
4516 my_strcat(inbuf, "ababababababababababababababababababababababababababababababab");
4517 my_strcat(inbuf, "ababababababababababababababababababababababababababababababab");
4518 my_strcat(inbuf, "ababababababababababababababababababababababababababababababab");
4519 my_strcat(inbuf, "ababababababababababababababababababababababababababababababab");
4520 my_strcat(inbuf, "ababababababababababababababababababababababababababababababab");
4521 my_strcat(inbuf, "ababababababababababababababababababababababababababababababab");
4522 my_strcat(inbuf, "ababababababababababababababababababababababababababababababab");
4523 my_strcat(inbuf, "ababababababababababababababababababababababababababababababab");
4524 my_strcat(inbuf, "ababababababababababababababababababababababababababababababab");
4525 my_strcat(inbuf, "ababababababababababababababababababababababababababababababab");
4526 my_strcat(inbuf, "ababababababababababababababababababababababababababababababab");
4527 my_strcat(inbuf, "ababababababababababababababababababababababababababababababab");
4528 my_strcat(inbuf, "ababababababababababababababababababababababababababababababab");
4529 my_strcat(inbuf, "ababababababababababababababababababababababababababababababab");
4530 my_strcat(inbuf, "ababababababababababababababababababababababababababababababab");
4531 my_strcat(inbuf, "ababababababababababababababababababababababababababababababab");
4532 my_strcat(inbuf, " GNU GENERAL PUBLIC LICENSE\n");
4533 my_strcat(inbuf, " Version 2, June 1991\n");
4534 my_strcat(inbuf, "\n");
4535 my_strcat(inbuf, " Copyright (C) 1989, 1991 Free Software Foundation, Inc.\n");
4536 my_strcat(inbuf, " 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n");
4537 my_strcat(inbuf, " Everyone is permitted to copy and distribute verbatim copies\n");
4538 my_strcat(inbuf, " of this license document, but changing it is not allowed.\n");
4539 my_strcat(inbuf, "\n");
4540 my_strcat(inbuf, " Preamble\n");
4541 my_strcat(inbuf, "\n");
4542 my_strcat(inbuf, " The licenses for most software are designed to take away your\n");
4543 my_strcat(inbuf, "freedom to share and change it. By contrast, the GNU General Public\n");
4544 my_strcat(inbuf, "License is intended to guarantee your freedom to share and change free\n");
4545 my_strcat(inbuf, "software--to make sure the software is free for all its users. This\n");
4546 my_strcat(inbuf, "General Public License applies to most of the Free Software\n");
4547 my_strcat(inbuf, "Foundation's software and to any other program whose authors commit to\n");
4548 my_strcat(inbuf, "using it. (Some other Free Software Foundation software is covered by\n");
4549 my_strcat(inbuf, "the GNU Library General Public License instead.) You can apply it to\n");
4550 my_strcat(inbuf, "your programs, too.\n");
4551 my_strcat(inbuf, "\n");
4552 my_strcat(inbuf, " When we speak of free software, we are referring to freedom, not\n");
4553 my_strcat(inbuf, "price. Our General Public Licenses are designed to make sure that you\n");
4554 my_strcat(inbuf, "have the freedom to distribute copies of free software (and charge for\n");
4555 my_strcat(inbuf, "this service if you wish), that you receive source code or can get it\n");
4556 my_strcat(inbuf, "if you want it, that you can change the software or use pieces of it\n");
4557 my_strcat(inbuf, "in new free programs; and that you know you can do these things.\n");
4558 my_strcat(inbuf, "\n");
4559 my_strcat(inbuf, " To protect your rights, we need to make restrictions that forbid\n");
4560 my_strcat(inbuf, "anyone to deny you these rights or to ask you to surrender the rights.\n");
4561 my_strcat(inbuf, "These restrictions translate to certain responsibilities for you if you\n");
4562 my_strcat(inbuf, "distribute copies of the software, or if you modify it.\n");
4563 my_strcat(inbuf, "\n");
4564 my_strcat(inbuf, " For example, if you distribute copies of such a program, whether\n");
4565 my_strcat(inbuf, "gratis or for a fee, you must give the recipients all the rights that\n");
4566 my_strcat(inbuf, "you have. You must make sure that they, too, receive or can get the\n");
4567 my_strcat(inbuf, "source code. And you must show them these terms so they know their\n");
4568 my_strcat(inbuf, "rights.\n");
4569 my_strcat(inbuf, "\n");
4570 my_strcat(inbuf, " We protect your rights with two steps: (1) copyright the software, and\n");
4571 my_strcat(inbuf, "(2) offer you this license which gives you legal permission to copy,\n");
4572 my_strcat(inbuf, "distribute and/or modify the software.\n");
4573 my_strcat(inbuf, "\n");
4574 my_strcat(inbuf, " Also, for each author's protection and ours, we want to make certain\n");
4575 my_strcat(inbuf, "that everyone understands that there is no warranty for this free\n");
4576 my_strcat(inbuf, "software. If the software is modified by someone else and passed on, we\n");
4577 my_strcat(inbuf, "want its recipients to know that what they have is not the original, so\n");
4578 my_strcat(inbuf, "that any problems introduced by others will not reflect on the original\n");
4579 my_strcat(inbuf, "authors' reputations.\n");
4580 my_strcat(inbuf, "\n");
4581 my_strcat(inbuf, " Finally, any free program is threatened constantly by software\n");
4582 my_strcat(inbuf, "patents. We wish to avoid the danger that redistributors of a free\n");
4583 my_strcat(inbuf, "program will individually obtain patent licenses, in effect making the\n");
4584 my_strcat(inbuf, "program proprietary. To prevent this, we have made it clear that any\n");
4585 my_strcat(inbuf, "patent must be licensed for everyone's free use or not licensed at all.\n");
4586 my_strcat(inbuf, "\n");
4587 my_strcat(inbuf, " The precise terms and conditions for copying, distribution and\n");
4588 my_strcat(inbuf, "modification follow.\n");
4589 my_strcat(inbuf, "\n");
4590 my_strcat(inbuf, " GNU GENERAL PUBLIC LICENSE\n");
4591 my_strcat(inbuf, " TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\n");
4592 my_strcat(inbuf, "\n");
4593 my_strcat(inbuf, " 0. This License applies to any program or other work which contains\n");
4594 my_strcat(inbuf, "a notice placed by the copyright holder saying it may be distributed\n");
4595 my_strcat(inbuf, "under the terms of this General Public License. The Program, below,\n");
4596 my_strcat(inbuf, "refers to any such program or work, and a work based on the Program\n");
4597 my_strcat(inbuf, "means either the Program or any derivative work under copyright law:\n");
4598 my_strcat(inbuf, "that is to say, a work containing the Program or a portion of it,\n");
4599 my_strcat(inbuf, "either verbatim or with modifications and/or translated into another\n");
4600 my_strcat(inbuf, "language. (Hereinafter, translation is included without limitation in\n");
4601 my_strcat(inbuf, "the term modification.) Each licensee is addressed as you.\n");
4602 my_strcat(inbuf, "\n");
4603 my_strcat(inbuf, "Activities other than copying, distribution and modification are not\n");
4604 my_strcat(inbuf, "covered by this License; they are outside its scope. The act of\n");
4605 my_strcat(inbuf, "running the Program is not restricted, and the output from the Program\n");
4606 my_strcat(inbuf, "is covered only if its contents constitute a work based on the\n");
4607 my_strcat(inbuf, "Program (independent of having been made by running the Program).\n");
4608 my_strcat(inbuf, "Whether that is true depends on what the Program does.\n");
4609 my_strcat(inbuf, "\n");
4610 my_strcat(inbuf, " 1. You may copy and distribute verbatim copies of the Program's\n");
4611 my_strcat(inbuf, "source code as you receive it, in any medium, provided that you\n");
4612 my_strcat(inbuf, "conspicuously and appropriately publish on each copy an appropriate\n");
4613 my_strcat(inbuf, "copyright notice and disclaimer of warranty; keep intact all the\n");
4614 my_strcat(inbuf, "notices that refer to this License and to the absence of any warranty;\n");
4615 my_strcat(inbuf, "and give any other recipients of the Program a copy of this License\n");
4616 my_strcat(inbuf, "along with the Program.\n");
4617 my_strcat(inbuf, "\n");
4618 my_strcat(inbuf, "You may charge a fee for the physical act of transferring a copy, and\n");
4619 my_strcat(inbuf, "you may at your option offer warranty protection in exchange for a fee.\n");
4620 my_strcat(inbuf, "\n");
4621 my_strcat(inbuf, " 2. You may modify your copy or copies of the Program or any portion\n");
4622 my_strcat(inbuf, "of it, thus forming a work based on the Program, and copy and\n");
4623 my_strcat(inbuf, "distribute such modifications or work under the terms of Section 1\n");
4624 my_strcat(inbuf, "above, provided that you also meet all of these conditions:\n");
4625 my_strcat(inbuf, "\n");
4626 my_strcat(inbuf, " a) You must cause the modified files to carry prominent notices\n");
4627 my_strcat(inbuf, " stating that you changed the files and the date of any change.\n");
4628 my_strcat(inbuf, "\n");
4629 my_strcat(inbuf, " b) You must cause any work that you distribute or publish, that in\n");
4630 my_strcat(inbuf, " whole or in part contains or is derived from the Program or any\n");
4631 my_strcat(inbuf, " part thereof, to be licensed as a whole at no charge to all third\n");
4632 my_strcat(inbuf, " parties under the terms of this License.\n");
4633 my_strcat(inbuf, "\n");
4634 my_strcat(inbuf, " c) If the modified program normally reads commands interactively\n");
4635 my_strcat(inbuf, " when run, you must cause it, when started running for such\n");
4636 my_strcat(inbuf, " interactive use in the most ordinary way, to print or display an\n");
4637 my_strcat(inbuf, " announcement including an appropriate copyright notice and a\n");
4638 my_strcat(inbuf, " notice that there is no warranty (or else, saying that you provide\n");
4639 my_strcat(inbuf, " a warranty) and that users may redistribute the program under\n");
4640 my_strcat(inbuf, " these conditions, and telling the user how to view a copy of this\n");
4641 my_strcat(inbuf, " License. (Exception: if the Program itself is interactive but\n");
4642 my_strcat(inbuf, " does not normally print such an announcement, your work based on\n");
4643 my_strcat(inbuf, " the Program is not required to print an announcement.)\n");
4644 my_strcat(inbuf, "\n");
4645 my_strcat(inbuf, "These requirements apply to the modified work as a whole. If\n");
4646 my_strcat(inbuf, "identifiable sections of that work are not derived from the Program,\n");
4647 my_strcat(inbuf, "and can be reasonably considered independent and separate works in\n");
4648 my_strcat(inbuf, "themselves, then this License, and its terms, do not apply to those\n");
4649 my_strcat(inbuf, "sections when you distribute them as separate works. But when you\n");
4650 my_strcat(inbuf, "distribute the same sections as part of a whole which is a work based\n");
4651 my_strcat(inbuf, "on the Program, the distribution of the whole must be on the terms of\n");
4652 my_strcat(inbuf, "this License, whose permissions for other licensees extend to the\n");
4653 my_strcat(inbuf, "entire whole, and thus to each and every part regardless of who wrote it.\n");
4654 my_strcat(inbuf, "\n");
4655 my_strcat(inbuf, "Thus, it is not the intent of this section to claim rights or contest\n");
4656 my_strcat(inbuf, "your rights to work written entirely by you; rather, the intent is to\n");
4657 my_strcat(inbuf, "exercise the right to control the distribution of derivative or\n");
4658 my_strcat(inbuf, "collective works based on the Program.\n");
4659 my_strcat(inbuf, "\n");
4660 my_strcat(inbuf, "In addition, mere aggregation of another work not based on the Program\n");
4661 my_strcat(inbuf, "with the Program (or with a work based on the Program) on a volume of\n");
4662 my_strcat(inbuf, "a storage or distribution medium does not bring the other work under\n");
4663 my_strcat(inbuf, "the scope of this License.\n");
4664 my_strcat(inbuf, "\n");
4665 my_strcat(inbuf, " 3. You may copy and distribute the Program (or a work based on it,\n");
4666 my_strcat(inbuf, "under Section 2) in object code or executable form under the terms of\n");
4667 my_strcat(inbuf, "Sections 1 and 2 above provided that you also do one of the following:\n");
4668 my_strcat(inbuf, "\n");
4669 my_strcat(inbuf, " a) Accompany it with the complete corresponding machine-readable\n");
4670 my_strcat(inbuf, " source code, which must be distributed under the terms of Sections\n");
4671 my_strcat(inbuf, " 1 and 2 above on a medium customarily used for software interchange; or,\n");
4672 my_strcat(inbuf, "\n");
4673 my_strcat(inbuf, " b) Accompany it with a written offer, valid for at least three\n");
4674 my_strcat(inbuf, " years, to give any third party, for a charge no more than your\n");
4675 my_strcat(inbuf, " cost of physically performing source distribution, a complete\n");
4676 my_strcat(inbuf, " machine-readable copy of the corresponding source code, to be\n");
4677 my_strcat(inbuf, " distributed under the terms of Sections 1 and 2 above on a medium\n");
4678 my_strcat(inbuf, " customarily used for software interchange; or,\n");
4679 my_strcat(inbuf, "\n");
4680 my_strcat(inbuf, " c) Accompany it with the information you received as to the offer\n");
4681 my_strcat(inbuf, " to distribute corresponding source code. (This alternative is\n");
4682 my_strcat(inbuf, " allowed only for noncommercial distribution and only if you\n");
4683 my_strcat(inbuf, " received the program in object code or executable form with such\n");
4684 my_strcat(inbuf, " an offer, in accord with Subsection b above.)\n");
4685 my_strcat(inbuf, "\n");
4686 my_strcat(inbuf, "The source code for a work means the preferred form of the work for\n");
4687 my_strcat(inbuf, "making modifications to it. For an executable work, complete source\n");
4688 my_strcat(inbuf, "code means all the source code for all modules it contains, plus any\n");
4689 my_strcat(inbuf, "associated interface definition files, plus the scripts used to\n");
4690 my_strcat(inbuf, "control compilation and installation of the executable. However, as a\n");
4691 my_strcat(inbuf, "special exception, the source code distributed need not include\n");
4692 my_strcat(inbuf, "anything that is normally distributed (in either source or binary\n");
4693 my_strcat(inbuf, "form) with the major components (compiler, kernel, and so on) of the\n");
4694 my_strcat(inbuf, "operating system on which the executable runs, unless that component\n");
4695 my_strcat(inbuf, "itself accompanies the executable.\n");
4696 my_strcat(inbuf, "\n");
4697 my_strcat(inbuf, "If distribution of executable or object code is made by offering\n");
4698 my_strcat(inbuf, "access to copy from a designated place, then offering equivalent\n");
4699 my_strcat(inbuf, "access to copy the source code from the same place counts as\n");
4700 my_strcat(inbuf, "distribution of the source code, even though third parties are not\n");
4701 my_strcat(inbuf, "compelled to copy the source along with the object code.\n");
4702 my_strcat(inbuf, "\n");
4703 my_strcat(inbuf, " 4. You may not copy, modify, sublicense, or distribute the Program\n");
4704 my_strcat(inbuf, "except as expressly provided under this License. Any attempt\n");
4705 my_strcat(inbuf, "otherwise to copy, modify, sublicense or distribute the Program is\n");
4706 my_strcat(inbuf, "void, and will automatically terminate your rights under this License.\n");
4707 my_strcat(inbuf, "However, parties who have received copies, or rights, from you under\n");
4708 my_strcat(inbuf, "this License will not have their licenses terminated so long as such\n");
4709 my_strcat(inbuf, "parties remain in full compliance.\n");
4710 my_strcat(inbuf, "\n");
4711 my_strcat(inbuf, " 5. You are not required to accept this License, since you have not\n");
4712 my_strcat(inbuf, "signed it. However, nothing else grants you permission to modify or\n");
4713 my_strcat(inbuf, "distribute the Program or its derivative works. These actions are\n");
4714 my_strcat(inbuf, "prohibited by law if you do not accept this License. Therefore, by\n");
4715 my_strcat(inbuf, "modifying or distributing the Program (or any work based on the\n");
4716 my_strcat(inbuf, "Program), you indicate your acceptance of this License to do so, and\n");
4717 my_strcat(inbuf, "all its terms and conditions for copying, distributing or modifying\n");
4718 my_strcat(inbuf, "the Program or works based on it.\n");
4719 my_strcat(inbuf, "\n");
4720 my_strcat(inbuf, " 6. Each time you redistribute the Program (or any work based on the\n");
4721 my_strcat(inbuf, "Program), the recipient automatically receives a license from the\n");
4722 my_strcat(inbuf, "original licensor to copy, distribute or modify the Program subject to\n");
4723 my_strcat(inbuf, "these terms and conditions. You may not impose any further\n");
4724 my_strcat(inbuf, "restrictions on the recipients' exercise of the rights granted herein.\n");
4725 my_strcat(inbuf, "You are not responsible for enforcing compliance by third parties to\n");
4726 my_strcat(inbuf, "this License.\n");
4727 my_strcat(inbuf, "\n");
4728 my_strcat(inbuf, " 7. If, as a consequence of a court judgment or allegation of patent\n");
4729 my_strcat(inbuf, "infringement or for any other reason (not limited to patent issues),\n");
4730 my_strcat(inbuf, "conditions are imposed on you (whether by court order, agreement or\n");
4731 my_strcat(inbuf, "otherwise) that contradict the conditions of this License, they do not\n");
4732 my_strcat(inbuf, "excuse you from the conditions of this License. If you cannot\n");
4733 my_strcat(inbuf, "distribute so as to satisfy simultaneously your obligations under this\n");
4734 my_strcat(inbuf, "License and any other pertinent obligations, then as a consequence you\n");
4735 my_strcat(inbuf, "may not distribute the Program at all. For example, if a patent\n");
4736 my_strcat(inbuf, "license would not permit royalty-free redistribution of the Program by\n");
4737 my_strcat(inbuf, "all those who receive copies directly or indirectly through you, then\n");
4738 my_strcat(inbuf, "the only way you could satisfy both it and this License would be to\n");
4739 my_strcat(inbuf, "refrain entirely from distribution of the Program.\n");
4740 my_strcat(inbuf, "\n");
4741 my_strcat(inbuf, "If any portion of this section is held invalid or unenforceable under\n");
4742 my_strcat(inbuf, "any particular circumstance, the balance of the section is intended to\n");
4743 my_strcat(inbuf, "apply and the section as a whole is intended to apply in other\n");
4744 my_strcat(inbuf, "circumstances.\n");
4745 my_strcat(inbuf, "\n");
4746 my_strcat(inbuf, "It is not the purpose of this section to induce you to infringe any\n");
4747 my_strcat(inbuf, "patents or other property right claims or to contest validity of any\n");
4748 my_strcat(inbuf, "such claims; this section has the sole purpose of protecting the\n");
4749 my_strcat(inbuf, "integrity of the free software distribution system, which is\n");
4750 my_strcat(inbuf, "implemented by public license practices. Many people have made\n");
4751 my_strcat(inbuf, "generous contributions to the wide range of software distributed\n");
4752 my_strcat(inbuf, "through that system in reliance on consistent application of that\n");
4753 my_strcat(inbuf, "system; it is up to the author/donor to decide if he or she is willing\n");
4754 my_strcat(inbuf, "to distribute software through any other system and a licensee cannot\n");
4755 my_strcat(inbuf, "impose that choice.\n");
4756 my_strcat(inbuf, "\n");
4757 my_strcat(inbuf, "This section is intended to make thoroughly clear what is believed to\n");
4758 my_strcat(inbuf, "be a consequence of the rest of this License.\n");
4759 my_strcat(inbuf, "\n");
4760 my_strcat(inbuf, " 8. If the distribution and/or use of the Program is restricted in\n");
4761 my_strcat(inbuf, "certain countries either by patents or by copyrighted interfaces, the\n");
4762 my_strcat(inbuf, "original copyright holder who places the Program under this License\n");
4763 my_strcat(inbuf, "may add an explicit geographical distribution limitation excluding\n");
4764 my_strcat(inbuf, "those countries, so that distribution is permitted only in or among\n");
4765 my_strcat(inbuf, "countries not thus excluded. In such case, this License incorporates\n");
4766 my_strcat(inbuf, "the limitation as if written in the body of this License.\n");
4767 my_strcat(inbuf, "\n");
4768 my_strcat(inbuf, " 9. The Free Software Foundation may publish revised and/or new versions\n");
4769 my_strcat(inbuf, "of the General Public License from time to time. Such new versions will\n");
4770 my_strcat(inbuf, "be similar in spirit to the present version, but may differ in detail to\n");
4771 my_strcat(inbuf, "address new problems or concerns.\n");
4772 my_strcat(inbuf, "\n");
4773 my_strcat(inbuf, "Each version is given a distinguishing version number. If the Program\n");
4774 my_strcat(inbuf, "specifies a version number of this License which applies to it and any\n");
4775 my_strcat(inbuf, "later version, you have the option of following the terms and conditions\n");
4776 my_strcat(inbuf, "either of that version or of any later version published by the Free\n");
4777 my_strcat(inbuf, "Software Foundation. If the Program does not specify a version number of\n");
4778 my_strcat(inbuf, "this License, you may choose any version ever published by the Free Software\n");
4779 my_strcat(inbuf, "Foundation.\n");
4780 my_strcat(inbuf, "\n");
4781 my_strcat(inbuf, " 10. If you wish to incorporate parts of the Program into other free\n");
4782 my_strcat(inbuf, "programs whose distribution conditions are different, write to the author\n");
4783 my_strcat(inbuf, "to ask for permission. For software which is copyrighted by the Free\n");
4784 my_strcat(inbuf, "Software Foundation, write to the Free Software Foundation; we sometimes\n");
4785 my_strcat(inbuf, "make exceptions for this. Our decision will be guided by the two goals\n");
4786 my_strcat(inbuf, "of preserving the free status of all derivatives of our free software and\n");
4787 my_strcat(inbuf, "of promoting the sharing and reuse of software generally.\n");
4788 my_strcat(inbuf, "\n");
4789 my_strcat(inbuf, " NO WARRANTY\n");
4790 my_strcat(inbuf, "\n");
4791 my_strcat(inbuf, " 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY\n");
4792 my_strcat(inbuf, "FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN\n");
4793 my_strcat(inbuf, "OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES\n");
4794 my_strcat(inbuf, "PROVIDE THE PROGRAM AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED\n");
4795 my_strcat(inbuf, "OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\n");
4796 my_strcat(inbuf, "MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS\n");
4797 my_strcat(inbuf, "TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE\n");
4798 my_strcat(inbuf, "PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,\n");
4799 my_strcat(inbuf, "REPAIR OR CORRECTION.\n");
4800 my_strcat(inbuf, "\n");
4801 my_strcat(inbuf, " 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\n");
4802 my_strcat(inbuf, "WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR\n");
4803 my_strcat(inbuf, "REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,\n");
4804 my_strcat(inbuf, "INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING\n");
4805 my_strcat(inbuf, "OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED\n");
4806 my_strcat(inbuf, "TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY\n");
4807 my_strcat(inbuf, "YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER\n");
4808 my_strcat(inbuf, "PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE\n");
4809 my_strcat(inbuf, "POSSIBILITY OF SUCH DAMAGES.\n");
4810 my_strcat(inbuf, "\n");
4811 my_strcat(inbuf, " END OF TERMS AND CONDITIONS\n");
4812 my_strcat(inbuf, "\n");
4813 my_strcat(inbuf, " How to Apply These Terms to Your New Programs\n");
4814 my_strcat(inbuf, "\n");
4815 my_strcat(inbuf, " If you develop a new program, and you want it to be of the greatest\n");
4816 my_strcat(inbuf, "possible use to the public, the best way to achieve this is to make it\n");
4817 my_strcat(inbuf, "free software which everyone can redistribute and change under these terms.\n");
4818 my_strcat(inbuf, "\n");
4819 my_strcat(inbuf, " To do so, attach the following notices to the program. It is safest\n");
4820 my_strcat(inbuf, "to attach them to the start of each source file to most effectively\n");
4821 my_strcat(inbuf, "convey the exclusion of warranty; and each file should have at least\n");
4822 my_strcat(inbuf, "the copyright line and a pointer to where the full notice is found.\n");
4823 my_strcat(inbuf, "\n");
4824 my_strcat(inbuf, " <one line to give the program's name and a brief idea of what it does.>\n");
4825 my_strcat(inbuf, " Copyright (C) <year> <name of author>\n");
4826 my_strcat(inbuf, "\n");
4827 my_strcat(inbuf, " This program is free software; you can redistribute it and/or modify\n");
4828 my_strcat(inbuf, " it under the terms of the GNU General Public License as published by\n");
4829 my_strcat(inbuf, " the Free Software Foundation; either version 2 of the License, or\n");
4830 my_strcat(inbuf, " (at your option) any later version.\n");
4831 my_strcat(inbuf, "\n");
4832 my_strcat(inbuf, " This program is distributed in the hope that it will be useful,\n");
4833 my_strcat(inbuf, " but WITHOUT ANY WARRANTY; without even the implied warranty of\n");
4834 my_strcat(inbuf, " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n");
4835 my_strcat(inbuf, " GNU General Public License for more details.\n");
4836 my_strcat(inbuf, "\n");
4837 my_strcat(inbuf, " You should have received a copy of the GNU General Public License\n");
4838 my_strcat(inbuf, " along with this program; if not, write to the Free Software\n");
4839 my_strcat(inbuf, " Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n");
4840 my_strcat(inbuf, "\n");
4841 my_strcat(inbuf, "\n");
4842 my_strcat(inbuf, "Also add information on how to contact you by electronic and paper mail.\n");
4843 my_strcat(inbuf, "\n");
4844 my_strcat(inbuf, "If the program is interactive, make it output a short notice like this\n");
4845 my_strcat(inbuf, "when it starts in an interactive mode:\n");
4846 my_strcat(inbuf, "\n");
4847 my_strcat(inbuf, " Gnomovision version 69, Copyright (C) year name of author\n");
4848 my_strcat(inbuf, " Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.\n");
4849 my_strcat(inbuf, " This is free software, and you are welcome to redistribute it\n");
4850 my_strcat(inbuf, " under certain conditions; type `show c' for details.\n");
4851 my_strcat(inbuf, "\n");
4852 my_strcat(inbuf, "The hypothetical commands `show w' and `show c' should show the appropriate\n");
4853 my_strcat(inbuf, "parts of the General Public License. Of course, the commands you use may\n");
4854 my_strcat(inbuf, "be called something other than `show w' and `show c'; they could even be\n");
4855 my_strcat(inbuf, "mouse-clicks or menu items--whatever suits your program.\n");
4856 my_strcat(inbuf, "\n");
4857 my_strcat(inbuf, "You should also get your employer (if you work as a programmer) or your\n");
4858 my_strcat(inbuf, "school, if any, to sign a copyright disclaimer for the program, if\n");
4859 my_strcat(inbuf, "necessary. Here is a sample; alter the names:\n");
4860 my_strcat(inbuf, "\n");
4861 my_strcat(inbuf, " Yoyodyne, Inc., hereby disclaims all copyright interest in the program\n");
4862 my_strcat(inbuf, " `Gnomovision' (which makes passes at compilers) written by James Hacker.\n");
4863 my_strcat(inbuf, "\n");
4864 my_strcat(inbuf, " <signature of Ty Coon>, 1 April 1989\n");
4865 my_strcat(inbuf, " Ty Coon, President of Vice\n");
4866 my_strcat(inbuf, "\n");
4867 my_strcat(inbuf, "This General Public License does not permit incorporating your program into\n");
4868 my_strcat(inbuf, "proprietary programs. If your program is a subroutine library, you may\n");
4869 my_strcat(inbuf, "consider it more useful to permit linking proprietary applications with the\n");
4870 my_strcat(inbuf, "library. If this is what you want to do, use the GNU Library General\n");
4871 my_strcat(inbuf, "Public License instead of this License.\n");
4873 my_strcat(inbuf, "\n");
4877 typedef struct _IO_FILE FILE;
4881 typedef struct _IO_FILE __FILE;
4882 typedef unsigned int wint_t;
4884 typedef struct
4886 int __count;
4887 union
4889 wint_t __wch;
4890 char __wchb[4];
4891 } __value;
4892 } __mbstate_t;
4895 typedef struct
4897 __off_t __pos;
4898 __mbstate_t __state;
4899 } _G_fpos_t;
4900 typedef struct
4902 __off64_t __pos;
4903 __mbstate_t __state;
4904 } _G_fpos64_t;
4907 enum
4909 __GCONV_OK = 0,
4910 __GCONV_NOCONV,
4911 __GCONV_NODB,
4912 __GCONV_NOMEM,
4914 __GCONV_EMPTY_INPUT,
4915 __GCONV_FULL_OUTPUT,
4916 __GCONV_ILLEGAL_INPUT,
4917 __GCONV_INCOMPLETE_INPUT,
4919 __GCONV_ILLEGAL_DESCRIPTOR,
4920 __GCONV_INTERNAL_ERROR
4925 enum
4927 __GCONV_IS_LAST = 0x0001,
4928 __GCONV_IGNORE_ERRORS = 0x0002
4933 struct __gconv_step;
4934 struct __gconv_step_data;
4935 struct __gconv_loaded_object;
4936 struct __gconv_trans_data;
4940 typedef int (*__gconv_fct) (struct __gconv_step *, struct __gconv_step_data *,
4941 __const unsigned char **, __const unsigned char *,
4942 unsigned char **, size_t *, int, int);
4945 typedef wint_t (*__gconv_btowc_fct) (struct __gconv_step *, unsigned char);
4948 typedef int (*__gconv_init_fct) (struct __gconv_step *);
4949 typedef void (*__gconv_end_fct) (struct __gconv_step *);
4953 typedef int (*__gconv_trans_fct) (struct __gconv_step *,
4954 struct __gconv_step_data *, void *,
4955 __const unsigned char *,
4956 __const unsigned char **,
4957 __const unsigned char *, unsigned char **,
4958 size_t *);
4961 typedef int (*__gconv_trans_context_fct) (void *, __const unsigned char *,
4962 __const unsigned char *,
4963 unsigned char *, unsigned char *);
4966 typedef int (*__gconv_trans_query_fct) (__const char *, __const char ***,
4967 size_t *);
4970 typedef int (*__gconv_trans_init_fct) (void **, const char *);
4971 typedef void (*__gconv_trans_end_fct) (void *);
4973 struct __gconv_trans_data
4976 __gconv_trans_fct __trans_fct;
4977 __gconv_trans_context_fct __trans_context_fct;
4978 __gconv_trans_end_fct __trans_end_fct;
4979 void *__data;
4980 struct __gconv_trans_data *__next;
4985 struct __gconv_step
4987 struct __gconv_loaded_object *__shlib_handle;
4988 __const char *__modname;
4990 int __counter;
4992 char *__from_name;
4993 char *__to_name;
4995 __gconv_fct __fct;
4996 __gconv_btowc_fct __btowc_fct;
4997 __gconv_init_fct __init_fct;
4998 __gconv_end_fct __end_fct;
5002 int __min_needed_from;
5003 int __max_needed_from;
5004 int __min_needed_to;
5005 int __max_needed_to;
5008 int __stateful;
5010 void *__data;
5015 struct __gconv_step_data
5017 unsigned char *__outbuf;
5018 unsigned char *__outbufend;
5022 int __flags;
5026 int __invocation_counter;
5030 int __internal_use;
5032 __mbstate_t *__statep;
5033 __mbstate_t __state;
5037 struct __gconv_trans_data *__trans;
5042 typedef struct __gconv_info
5044 size_t __nsteps;
5045 struct __gconv_step *__steps;
5046 __extension__ struct __gconv_step_data __data [];
5047 } *__gconv_t;
5049 typedef union
5051 struct __gconv_info __cd;
5052 struct
5054 struct __gconv_info __cd;
5055 struct __gconv_step_data __data;
5056 } __combined;
5057 } _G_iconv_t;
5059 typedef int _G_int16_t __attribute__ ((__mode__ (__HI__)));
5060 typedef int _G_int32_t __attribute__ ((__mode__ (__SI__)));
5061 typedef unsigned int _G_uint16_t __attribute__ ((__mode__ (__HI__)));
5062 typedef unsigned int _G_uint32_t __attribute__ ((__mode__ (__SI__)));
5064 struct _IO_jump_t; struct _IO_FILE;
5066 typedef void _IO_lock_t;
5072 struct _IO_marker {
5073 struct _IO_marker *_next;
5074 struct _IO_FILE *_sbuf;
5078 int _pos;
5083 enum __codecvt_result
5085 __codecvt_ok,
5086 __codecvt_partial,
5087 __codecvt_error,
5088 __codecvt_noconv
5091 struct _IO_FILE {
5092 int _flags;
5097 char* _IO_read_ptr;
5098 char* _IO_read_end;
5099 char* _IO_read_base;
5100 char* _IO_write_base;
5101 char* _IO_write_ptr;
5102 char* _IO_write_end;
5103 char* _IO_buf_base;
5104 char* _IO_buf_end;
5106 char *_IO_save_base;
5107 char *_IO_backup_base;
5108 char *_IO_save_end;
5110 struct _IO_marker *_markers;
5112 struct _IO_FILE *_chain;
5114 int _fileno;
5118 int _flags2;
5120 __off_t _old_offset;
5124 unsigned short _cur_column;
5125 signed char _vtable_offset;
5126 char _shortbuf[1];
5130 _IO_lock_t *_lock;
5132 __off64_t _offset;
5138 void *__pad1;
5139 void *__pad2;
5141 int _mode;
5143 char _unused2[15 * sizeof (int) - 2 * sizeof (void *)];
5148 typedef struct _IO_FILE _IO_FILE;
5151 struct _IO_FILE_plus;
5153 extern struct _IO_FILE_plus _IO_2_1_stdin_;
5154 extern struct _IO_FILE_plus _IO_2_1_stdout_;
5155 extern struct _IO_FILE_plus _IO_2_1_stderr_;
5157 typedef __ssize_t __io_read_fn (void *__cookie, char *__buf, size_t __nbytes);
5165 typedef __ssize_t __io_write_fn (void *__cookie, __const char *__buf,
5166 size_t __n);
5174 typedef int __io_seek_fn (void *__cookie, __off64_t *__pos, int __w);
5177 typedef int __io_close_fn (void *__cookie);
5179 extern int __underflow (_IO_FILE *) __attribute__ ((__nothrow__));
5180 extern int __uflow (_IO_FILE *) __attribute__ ((__nothrow__));
5181 extern int __overflow (_IO_FILE *, int) __attribute__ ((__nothrow__));
5182 extern wint_t __wunderflow (_IO_FILE *) __attribute__ ((__nothrow__));
5183 extern wint_t __wuflow (_IO_FILE *) __attribute__ ((__nothrow__));
5184 extern wint_t __woverflow (_IO_FILE *, wint_t) __attribute__ ((__nothrow__));
5186 extern int _IO_getc (_IO_FILE *__fp) __attribute__ ((__nothrow__));
5187 extern int _IO_putc (int __c, _IO_FILE *__fp) __attribute__ ((__nothrow__));
5188 extern int _IO_feof (_IO_FILE *__fp) __attribute__ ((__nothrow__));
5189 extern int _IO_ferror (_IO_FILE *__fp) __attribute__ ((__nothrow__));
5191 extern int _IO_peekc_locked (_IO_FILE *__fp) __attribute__ ((__nothrow__));
5197 extern void _IO_flockfile (_IO_FILE *) __attribute__ ((__nothrow__));
5198 extern void _IO_funlockfile (_IO_FILE *) __attribute__ ((__nothrow__));
5199 extern int _IO_ftrylockfile (_IO_FILE *) __attribute__ ((__nothrow__));
5201 extern __ssize_t _IO_padn (_IO_FILE *, int, __ssize_t) __attribute__ ((__nothrow__));
5202 extern size_t _IO_sgetn (_IO_FILE *, void *, size_t) __attribute__ ((__nothrow__));
5204 extern __off64_t _IO_seekoff (_IO_FILE *, __off64_t, int, int) __attribute__ ((__nothrow__));
5205 extern __off64_t _IO_seekpos (_IO_FILE *, __off64_t, int) __attribute__ ((__nothrow__));
5207 extern void _IO_free_backup_area (_IO_FILE *) __attribute__ ((__nothrow__));
5210 typedef _G_fpos_t fpos_t;
5219 extern struct _IO_FILE *stdin;
5220 extern struct _IO_FILE *stdout;
5221 extern struct _IO_FILE *stderr;
5231 extern int remove (__const char *__filename) __attribute__ ((__nothrow__));
5233 extern int rename (__const char *__old, __const char *__new) __attribute__ ((__nothrow__));
5243 extern FILE *tmpfile (void);
5245 extern char *tmpnam (char *__s) __attribute__ ((__nothrow__));
5251 extern char *tmpnam_r (char *__s) __attribute__ ((__nothrow__));
5253 extern char *tempnam (__const char *__dir, __const char *__pfx)
5254 __attribute__ ((__nothrow__)) __attribute__ ((__malloc__));
5263 extern int fclose (FILE *__stream);
5268 extern int fflush (FILE *__stream);
5271 extern int fflush_unlocked (FILE *__stream);
5279 extern FILE *fopen (__const char *__restrict __filename,
5280 __const char *__restrict __modes);
5285 extern FILE *freopen (__const char *__restrict __filename,
5286 __const char *__restrict __modes,
5287 FILE *__restrict __stream);
5291 extern FILE *fdopen (int __fd, __const char *__modes) __attribute__ ((__nothrow__));
5296 extern void setbuf (FILE *__restrict __stream, char *__restrict __buf) __attribute__ ((__nothrow__));
5300 extern int setvbuf (FILE *__restrict __stream, char *__restrict __buf,
5301 int __modes, size_t __n) __attribute__ ((__nothrow__));
5307 extern void setbuffer (FILE *__restrict __stream, char *__restrict __buf,
5308 size_t __size) __attribute__ ((__nothrow__));
5311 extern void setlinebuf (FILE *__stream) __attribute__ ((__nothrow__));
5320 extern int fprintf (FILE *__restrict __stream,
5321 __const char *__restrict __format, ...);
5326 extern int printf (__const char *__restrict __format, ...);
5328 extern int sprintf (char *__restrict __s,
5329 __const char *__restrict __format, ...) __attribute__ ((__nothrow__));
5346 extern int snprintf (char *__restrict __s, size_t __maxlen,
5347 __const char *__restrict __format, ...)
5348 __attribute__ ((__nothrow__)) __attribute__ ((__format__ (__printf__, 3, 4)));
5357 extern int fscanf (FILE *__restrict __stream,
5358 __const char *__restrict __format, ...);
5363 extern int scanf (__const char *__restrict __format, ...);
5365 extern int sscanf (__const char *__restrict __s,
5366 __const char *__restrict __format, ...) __attribute__ ((__nothrow__));
5374 extern int fgetc (FILE *__stream);
5375 extern int getc (FILE *__stream);
5381 extern int getchar (void);
5384 extern int getc_unlocked (FILE *__stream);
5385 extern int getchar_unlocked (void);
5387 extern int fgetc_unlocked (FILE *__stream);
5399 extern int fputc (int __c, FILE *__stream);
5400 extern int putc (int __c, FILE *__stream);
5406 extern int putchar (int __c);
5409 extern int fputc_unlocked (int __c, FILE *__stream);
5417 extern int putc_unlocked (int __c, FILE *__stream);
5418 extern int putchar_unlocked (int __c);
5425 extern int getw (FILE *__stream);
5428 extern int putw (int __w, FILE *__stream);
5437 extern char *fgets (char *__restrict __s, int __n, FILE *__restrict __stream);
5444 extern char *gets (char *__s);
5452 extern int fputs (__const char *__restrict __s, FILE *__restrict __stream);
5458 extern int puts (__const char *__s);
5465 extern int ungetc (int __c, FILE *__stream);
5472 extern size_t fread (void *__restrict __ptr, size_t __size,
5473 size_t __n, FILE *__restrict __stream);
5478 extern size_t fwrite (__const void *__restrict __ptr, size_t __size,
5479 size_t __n, FILE *__restrict __s);
5482 extern size_t fread_unlocked (void *__restrict __ptr, size_t __size,
5483 size_t __n, FILE *__restrict __stream);
5484 extern size_t fwrite_unlocked (__const void *__restrict __ptr, size_t __size,
5485 size_t __n, FILE *__restrict __stream);
5494 extern int fseek (FILE *__stream, long int __off, int __whence);
5499 extern long int ftell (FILE *__stream);
5504 extern void rewind (FILE *__stream);
5513 extern int fgetpos (FILE *__restrict __stream, fpos_t *__restrict __pos);
5518 extern int fsetpos (FILE *__stream, __const fpos_t *__pos);
5522 extern void clearerr (FILE *__stream) __attribute__ ((__nothrow__));
5524 extern int feof (FILE *__stream) __attribute__ ((__nothrow__));
5526 extern int ferror (FILE *__stream) __attribute__ ((__nothrow__));
5531 extern void clearerr_unlocked (FILE *__stream) __attribute__ ((__nothrow__));
5532 extern int feof_unlocked (FILE *__stream) __attribute__ ((__nothrow__));
5533 extern int ferror_unlocked (FILE *__stream) __attribute__ ((__nothrow__));
5542 extern void perror (__const char *__s);
5549 extern int sys_nerr;
5550 extern __const char *__const sys_errlist[];
5556 extern int fileno (FILE *__stream) __attribute__ ((__nothrow__));
5561 extern int fileno_unlocked (FILE *__stream) __attribute__ ((__nothrow__));
5563 extern FILE *popen (__const char *__command, __const char *__modes);
5569 extern int pclose (FILE *__stream);
5575 extern char *ctermid (char *__s) __attribute__ ((__nothrow__));
5577 extern void flockfile (FILE *__stream) __attribute__ ((__nothrow__));
5581 extern int ftrylockfile (FILE *__stream) __attribute__ ((__nothrow__));
5584 extern void funlockfile (FILE *__stream) __attribute__ ((__nothrow__));
5586 typedef int ptrdiff_t;
5588 extern void * malloc (size_t __size) __attribute__ ((__nothrow__)) __attribute__ ((__malloc__));
5591 extern void * calloc (size_t __nmemb, size_t __size) __attribute__ ((__nothrow__))
5592 __attribute__ ((__malloc__));
5596 extern void * realloc (void * __ptr, size_t __size) __attribute__ ((__nothrow__))
5598 __attribute__ ((__malloc__));
5601 extern void free (void * __ptr) __attribute__ ((__nothrow__));
5604 extern void cfree (void * __ptr) __attribute__ ((__nothrow__));
5607 extern void * memalign (size_t __alignment, size_t __size) __attribute__ ((__nothrow__));
5610 extern void * valloc (size_t __size) __attribute__ ((__nothrow__)) __attribute__ ((__malloc__));
5614 extern void * pvalloc (size_t __size) __attribute__ ((__nothrow__))
5615 __attribute__ ((__malloc__));
5619 extern void * (*__morecore) (ptrdiff_t __size);
5622 extern void * __default_morecore (ptrdiff_t __size) __attribute__ ((__nothrow__))
5623 __attribute__ ((__malloc__));
5627 struct mallinfo {
5628 int arena;
5629 int ordblks;
5630 int smblks;
5631 int hblks;
5632 int hblkhd;
5633 int usmblks;
5634 int fsmblks;
5635 int uordblks;
5636 int fordblks;
5637 int keepcost;
5641 extern struct mallinfo mallinfo (void) __attribute__ ((__nothrow__));
5643 extern int mallopt (int __param, int __val) __attribute__ ((__nothrow__));
5647 extern int malloc_trim (size_t __pad) __attribute__ ((__nothrow__));
5651 extern size_t malloc_usable_size (void * __ptr) __attribute__ ((__nothrow__));
5654 extern void malloc_stats (void) __attribute__ ((__nothrow__));
5657 extern void * malloc_get_state (void) __attribute__ ((__nothrow__));
5661 extern int malloc_set_state (void * __ptr) __attribute__ ((__nothrow__));
5666 extern void (*__malloc_initialize_hook) (void);
5668 extern void (*__free_hook) (void * __ptr, __const void *);
5670 extern void * (*__malloc_hook) (size_t __size, __const void *);
5672 extern void * (*__realloc_hook) (void * __ptr, size_t __size, __const void *);
5675 extern void * (*__memalign_hook) (size_t __alignment, size_t __size, __const void *);
5678 extern void (*__after_morecore_hook) (void);
5681 extern void __malloc_check_init (void) __attribute__ ((__nothrow__));
5685 extern void __assert_fail (__const char *__assertion, __const char *__file,
5686 unsigned int __line, __const char *__function)
5687 __attribute__ ((__nothrow__)) __attribute__ ((__noreturn__));
5690 extern void __assert_perror_fail (int __errnum, __const char *__file,
5691 unsigned int __line,
5692 __const char *__function)
5693 __attribute__ ((__nothrow__)) __attribute__ ((__noreturn__));
5698 extern void __assert (const char *__assertion, const char *__file, int __line)
5699 __attribute__ ((__nothrow__)) __attribute__ ((__noreturn__));
5706 static HWord g_serviceFn ( HWord arg1, HWord arg2 )
5708 switch (arg1) {
5709 case 0:
5710 exit(0);
5711 case 1:
5712 putchar(arg2);
5713 return 0;
5714 case 2:
5715 return (HWord)malloc(arg2);
5716 case 3:
5717 free((void*)arg2);
5718 return 0;
5719 default:
5720 ((void) ((0) ? 0 : (__assert_fail ("0", "./bz2.c", 6428, "__PRETTY_FUNCTION__"), 0)));
5725 int main ( void )
5727 int r;
5728 int bit;
5729 int i;
5731 serviceFn = g_serviceFn;
5733 set_inbuf();
5734 nIn = vex_strlen(inbuf)+1;
5735 vex_printf( "%d bytes read\n", nIn );
5737 nZ = 1000000;
5738 r = BZ2_bzBuffToBuffCompress (
5739 zbuf, &nZ, inbuf, nIn, 9, 3 , 30 );
5741 if (r != 0) {
5742 vex_printf("initial compress failed!\n");
5743 (*serviceFn)(0,0);
5745 vex_printf( "%d after compression\n", nZ );
5747 for (bit = 0; bit < nZ*8; bit += (bit < 35 ? 1 : 137)) {
5749 flip_bit ( bit );
5750 nOut = (1000000 + 1000000);
5751 r = BZ2_bzBuffToBuffDecompress (
5752 outbuf, &nOut, zbuf, nZ, 1 , 0 );
5755 if (r != 0) {
5757 } else {
5758 if (nOut != nIn) {
5759 vex_printf( "nIn/nOut mismatch %d %d\n", nIn, nOut );
5760 (*serviceFn)(0,0);
5761 } else {
5762 for (i = 0; i < nOut; i++)
5763 if (inbuf[i] != outbuf[i]) {
5764 vex_printf( "mismatch at %d\n", i );
5765 (*serviceFn)(0,0);
5767 if (i == nOut) vex_printf( "really ok!\n" );
5771 flip_bit ( bit );
5774 vex_printf( "all ok\n" );
5775 (*serviceFn)(0,0);
5777 return 0;