1
2typedef unsigned int size_t;
3
4typedef long int wchar_t;
5
6
7typedef struct
8  {
9    int quot;
10    int rem;
11  } div_t;
12
13
14
15typedef struct
16  {
17    long int quot;
18    long int rem;
19  } ldiv_t;
20
21
22
23
24extern size_t __ctype_get_mb_cur_max (void) __attribute__ ((__nothrow__));
25
26
27
28
29extern double atof (__const char *__nptr)
30     __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1)));
31
32extern int atoi (__const char *__nptr)
33     __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1)));
34
35extern long int atol (__const char *__nptr)
36     __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1)));
37
38
39
40
41
42__extension__ extern long long int atoll (__const char *__nptr)
43     __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1)));
44
45
46
47
48
49extern double strtod (__const char *__restrict __nptr,
50        char **__restrict __endptr) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));
51
52
53
54
55extern long int strtol (__const char *__restrict __nptr,
56   char **__restrict __endptr, int __base)
57     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));
58
59extern unsigned long int strtoul (__const char *__restrict __nptr,
60      char **__restrict __endptr, int __base)
61     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));
62
63
64
65
66__extension__
67extern long long int strtoq (__const char *__restrict __nptr,
68        char **__restrict __endptr, int __base)
69     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));
70
71__extension__
72extern unsigned long long int strtouq (__const char *__restrict __nptr,
73           char **__restrict __endptr, int __base)
74     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));
75
76
77
78
79
80__extension__
81extern long long int strtoll (__const char *__restrict __nptr,
82         char **__restrict __endptr, int __base)
83     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));
84
85__extension__
86extern unsigned long long int strtoull (__const char *__restrict __nptr,
87     char **__restrict __endptr, int __base)
88     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));
89
90
91extern double __strtod_internal (__const char *__restrict __nptr,
92     char **__restrict __endptr, int __group)
93     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));
94extern float __strtof_internal (__const char *__restrict __nptr,
95    char **__restrict __endptr, int __group)
96     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));
97extern long double __strtold_internal (__const char *__restrict __nptr,
98           char **__restrict __endptr,
99           int __group) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));
100
101extern long int __strtol_internal (__const char *__restrict __nptr,
102       char **__restrict __endptr,
103       int __base, int __group)
104     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));
105
106
107
108extern unsigned long int __strtoul_internal (__const char *__restrict __nptr,
109          char **__restrict __endptr,
110          int __base, int __group)
111     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));
112
113
114
115
116__extension__
117extern long long int __strtoll_internal (__const char *__restrict __nptr,
118      char **__restrict __endptr,
119      int __base, int __group)
120     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));
121
122
123
124__extension__
125extern 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)));
130
131extern char *l64a (long int __n) __attribute__ ((__nothrow__));
132
133
134extern long int a64l (__const char *__s)
135     __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1)));
136
137
138
139
140
141
142typedef unsigned char __u_char;
143typedef unsigned short int __u_short;
144typedef unsigned int __u_int;
145typedef unsigned long int __u_long;
146
147
148typedef signed char __int8_t;
149typedef unsigned char __uint8_t;
150typedef signed short int __int16_t;
151typedef unsigned short int __uint16_t;
152typedef signed int __int32_t;
153typedef unsigned int __uint32_t;
154
155
156
157
158__extension__ typedef signed long long int __int64_t;
159__extension__ typedef unsigned long long int __uint64_t;
160
161
162
163
164
165
166
167__extension__ typedef long long int __quad_t;
168__extension__ typedef unsigned long long int __u_quad_t;
169
170
171
172
173
174
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;
193
194__extension__ typedef int __daddr_t;
195__extension__ typedef long int __swblk_t;
196__extension__ typedef int __key_t;
197
198
199__extension__ typedef int __clockid_t;
200
201
202__extension__ typedef int __timer_t;
203
204
205__extension__ typedef long int __blksize_t;
206
207
208
209
210__extension__ typedef long int __blkcnt_t;
211__extension__ typedef __quad_t __blkcnt64_t;
212
213
214__extension__ typedef unsigned long int __fsblkcnt_t;
215__extension__ typedef __u_quad_t __fsblkcnt64_t;
216
217
218__extension__ typedef unsigned long int __fsfilcnt_t;
219__extension__ typedef __u_quad_t __fsfilcnt64_t;
220
221__extension__ typedef int __ssize_t;
222
223
224
225typedef __off64_t __loff_t;
226typedef __quad_t *__qaddr_t;
227typedef char *__caddr_t;
228
229
230__extension__ typedef int __intptr_t;
231
232
233__extension__ typedef unsigned int __socklen_t;
234
235
236
237
238typedef __u_char u_char;
239typedef __u_short u_short;
240typedef __u_int u_int;
241typedef __u_long u_long;
242typedef __quad_t quad_t;
243typedef __u_quad_t u_quad_t;
244typedef __fsid_t fsid_t;
245
246
247
248
249typedef __loff_t loff_t;
250
251
252
253typedef __ino_t ino_t;
254
255typedef __dev_t dev_t;
256
257
258
259
260typedef __gid_t gid_t;
261
262
263
264
265typedef __mode_t mode_t;
266
267
268
269
270typedef __nlink_t nlink_t;
271
272
273
274
275typedef __uid_t uid_t;
276
277
278
279
280
281typedef __off_t off_t;
282
283typedef __pid_t pid_t;
284
285
286
287
288typedef __id_t id_t;
289
290
291
292
293typedef __ssize_t ssize_t;
294
295
296
297
298
299typedef __daddr_t daddr_t;
300typedef __caddr_t caddr_t;
301
302
303
304
305
306typedef __key_t key_t;
307
308
309typedef __time_t time_t;
310
311
312
313
314typedef __clockid_t clockid_t;
315
316typedef __timer_t timer_t;
317
318
319
320
321typedef unsigned long int ulong;
322typedef unsigned short int ushort;
323typedef unsigned int uint;
324
325typedef int int8_t __attribute__ ((__mode__ (__QI__)));
326typedef int int16_t __attribute__ ((__mode__ (__HI__)));
327typedef int int32_t __attribute__ ((__mode__ (__SI__)));
328typedef int int64_t __attribute__ ((__mode__ (__DI__)));
329
330
331typedef unsigned int u_int8_t __attribute__ ((__mode__ (__QI__)));
332typedef unsigned int u_int16_t __attribute__ ((__mode__ (__HI__)));
333typedef unsigned int u_int32_t __attribute__ ((__mode__ (__SI__)));
334typedef unsigned int u_int64_t __attribute__ ((__mode__ (__DI__)));
335
336typedef int register_t __attribute__ ((__mode__ (__word__)));
337
338typedef int __sig_atomic_t;
339
340
341
342
343typedef struct
344  {
345    unsigned long int __val[(1024 / (8 * sizeof (unsigned long int)))];
346  } __sigset_t;
347
348
349
350
351typedef __sigset_t sigset_t;
352
353
354
355
356
357struct timespec
358  {
359    __time_t tv_sec;
360    long int tv_nsec;
361  };
362
363struct timeval
364  {
365    __time_t tv_sec;
366    __suseconds_t tv_usec;
367  };
368
369
370
371typedef __suseconds_t suseconds_t;
372
373
374
375
376
377typedef long int __fd_mask;
378
379typedef struct
380  {
381
382
383
384
385
386
387    __fd_mask __fds_bits[1024 / (8 * sizeof (__fd_mask))];
388
389
390  } fd_set;
391
392
393
394
395
396
397typedef __fd_mask fd_mask;
398
399
400
401extern int select (int __nfds, fd_set *__restrict __readfds,
402     fd_set *__restrict __writefds,
403     fd_set *__restrict __exceptfds,
404     struct timeval *__restrict __timeout);
405
406__extension__
407extern __inline unsigned int gnu_dev_major (unsigned long long int __dev)
408     __attribute__ ((__nothrow__));
409__extension__
410extern __inline unsigned int gnu_dev_minor (unsigned long long int __dev)
411     __attribute__ ((__nothrow__));
412__extension__
413extern __inline unsigned long long int gnu_dev_makedev (unsigned int __major,
414       unsigned int __minor)
415     __attribute__ ((__nothrow__));
416
417
418__extension__ extern __inline unsigned int
419__attribute__ ((__nothrow__)) gnu_dev_major (unsigned long long int __dev)
420{
421  return ((__dev >> 8) & 0xfff) | ((unsigned int) (__dev >> 32) & ~0xfff);
422}
423
424__extension__ extern __inline unsigned int
425__attribute__ ((__nothrow__)) gnu_dev_minor (unsigned long long int __dev)
426{
427  return (__dev & 0xff) | ((unsigned int) (__dev >> 12) & ~0xff);
428}
429
430__extension__ extern __inline unsigned long long int
431__attribute__ ((__nothrow__)) gnu_dev_makedev (unsigned int __major, unsigned int __minor)
432{
433  return ((__minor & 0xff) | ((__major & 0xfff) << 8)
434   | (((unsigned long long int) (__minor & ~0xff)) << 12)
435   | (((unsigned long long int) (__major & ~0xfff)) << 32));
436}
437
438typedef __blkcnt_t blkcnt_t;
439
440
441
442typedef __fsblkcnt_t fsblkcnt_t;
443
444
445
446typedef __fsfilcnt_t fsfilcnt_t;
447
448struct __sched_param
449  {
450    int __sched_priority;
451  };
452
453
454
455struct _pthread_fastlock
456{
457  long int __status;
458  int __spinlock;
459
460};
461
462
463
464typedef struct _pthread_descr_struct *_pthread_descr;
465
466
467
468
469
470typedef struct __pthread_attr_s
471{
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;
482
483
484
485
486
487__extension__ typedef long long __pthread_cond_align_t;
488
489
490
491
492typedef struct
493{
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;
500
501
502
503typedef struct
504{
505  int __dummy;
506} pthread_condattr_t;
507
508
509typedef unsigned int pthread_key_t;
510
511
512
513
514
515typedef struct
516{
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;
523
524
525
526typedef struct
527{
528  int __mutexkind;
529} pthread_mutexattr_t;
530
531
532
533typedef int pthread_once_t;
534
535typedef unsigned long int pthread_t;
536
537
538
539
540
541
542
543extern long int random (void) __attribute__ ((__nothrow__));
544
545
546extern void srandom (unsigned int __seed) __attribute__ ((__nothrow__));
547
548
549
550
551
552extern char *initstate (unsigned int __seed, char *__statebuf,
553   size_t __statelen) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (2)));
554
555
556
557extern char *setstate (char *__statebuf) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));
558
559
560
561
562
563
564
565struct random_data
566  {
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;
574  };
575
576extern int random_r (struct random_data *__restrict __buf,
577       int32_t *__restrict __result) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2)));
578
579extern int srandom_r (unsigned int __seed, struct random_data *__buf)
580     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (2)));
581
582extern 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)));
586
587extern int setstate_r (char *__restrict __statebuf,
588         struct random_data *__restrict __buf)
589     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2)));
590
591
592
593
594
595
596extern int rand (void) __attribute__ ((__nothrow__));
597
598extern void srand (unsigned int __seed) __attribute__ ((__nothrow__));
599
600
601
602
603extern int rand_r (unsigned int *__seed) __attribute__ ((__nothrow__));
604
605
606
607
608
609
610
611extern double drand48 (void) __attribute__ ((__nothrow__));
612extern double erand48 (unsigned short int __xsubi[3]) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));
613
614
615extern long int lrand48 (void) __attribute__ ((__nothrow__));
616extern long int nrand48 (unsigned short int __xsubi[3])
617     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));
618
619
620extern long int mrand48 (void) __attribute__ ((__nothrow__));
621extern long int jrand48 (unsigned short int __xsubi[3])
622     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));
623
624
625extern void srand48 (long int __seedval) __attribute__ ((__nothrow__));
626extern unsigned short int *seed48 (unsigned short int __seed16v[3])
627     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));
628extern void lcong48 (unsigned short int __param[7]) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));
629
630
631
632
633
634struct drand48_data
635  {
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;
641  };
642
643
644extern int drand48_r (struct drand48_data *__restrict __buffer,
645        double *__restrict __result) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2)));
646extern int erand48_r (unsigned short int __xsubi[3],
647        struct drand48_data *__restrict __buffer,
648        double *__restrict __result) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2)));
649
650
651extern int lrand48_r (struct drand48_data *__restrict __buffer,
652        long int *__restrict __result)
653     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2)));
654extern 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)));
658
659
660extern int mrand48_r (struct drand48_data *__restrict __buffer,
661        long int *__restrict __result)
662     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2)));
663extern 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)));
667
668
669extern int srand48_r (long int __seedval, struct drand48_data *__buffer)
670     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (2)));
671
672extern int seed48_r (unsigned short int __seed16v[3],
673       struct drand48_data *__buffer) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2)));
674
675extern int lcong48_r (unsigned short int __param[7],
676        struct drand48_data *__buffer)
677     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2)));
678
679
680
681
682
683
684
685
686
687extern void *malloc (size_t __size) __attribute__ ((__nothrow__)) __attribute__ ((__malloc__));
688
689extern void *calloc (size_t __nmemb, size_t __size)
690     __attribute__ ((__nothrow__)) __attribute__ ((__malloc__));
691
692
693
694
695
696
697
698extern void *realloc (void *__ptr, size_t __size) __attribute__ ((__nothrow__)) __attribute__ ((__malloc__));
699
700extern void free (void *__ptr) __attribute__ ((__nothrow__));
701
702
703
704
705extern void cfree (void *__ptr) __attribute__ ((__nothrow__));
706
707
708
709
710extern void *alloca (size_t __size) __attribute__ ((__nothrow__));
711
712
713
714
715
716
717extern void *valloc (size_t __size) __attribute__ ((__nothrow__)) __attribute__ ((__malloc__));
718
719extern void abort (void) __attribute__ ((__nothrow__)) __attribute__ ((__noreturn__));
720
721
722
723extern int atexit (void (*__func) (void)) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));
724
725
726
727
728
729extern int on_exit (void (*__func) (int __status, void *__arg), void *__arg)
730     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));
731
732
733
734
735
736
737extern void exit (int __status) __attribute__ ((__nothrow__)) __attribute__ ((__noreturn__));
738
739extern char *getenv (__const char *__name) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));
740
741
742
743
744extern char *__secure_getenv (__const char *__name) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));
745
746
747
748
749
750extern int putenv (char *__string) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));
751
752
753
754
755
756extern int setenv (__const char *__name, __const char *__value, int __replace)
757     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (2)));
758
759
760extern int unsetenv (__const char *__name) __attribute__ ((__nothrow__));
761
762
763
764
765
766
767extern int clearenv (void) __attribute__ ((__nothrow__));
768
769extern char *mktemp (char *__template) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));
770
771extern int mkstemp (char *__template) __attribute__ ((__nonnull__ (1)));
772
773extern char *mkdtemp (char *__template) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));
774
775
776
777
778
779
780
781
782extern int system (__const char *__command);
783
784extern char *realpath (__const char *__restrict __name,
785         char *__restrict __resolved) __attribute__ ((__nothrow__));
786
787
788
789
790
791
792typedef int (*__compar_fn_t) (__const void *, __const void *);
793
794
795
796
797
798
799
800
801
802extern 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)));
805
806
807
808extern void qsort (void *__base, size_t __nmemb, size_t __size,
809     __compar_fn_t __compar) __attribute__ ((__nonnull__ (1, 4)));
810
811
812
813extern int abs (int __x) __attribute__ ((__nothrow__)) __attribute__ ((__const__));
814extern long int labs (long int __x) __attribute__ ((__nothrow__)) __attribute__ ((__const__));
815
816
817
818
819
820
821
822
823
824
825
826
827extern div_t div (int __numer, int __denom)
828     __attribute__ ((__nothrow__)) __attribute__ ((__const__));
829extern ldiv_t ldiv (long int __numer, long int __denom)
830     __attribute__ ((__nothrow__)) __attribute__ ((__const__));
831
832extern char *ecvt (double __value, int __ndigit, int *__restrict __decpt,
833     int *__restrict __sign) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (3, 4)));
834
835
836
837
838extern char *fcvt (double __value, int __ndigit, int *__restrict __decpt,
839     int *__restrict __sign) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (3, 4)));
840
841
842
843
844extern char *gcvt (double __value, int __ndigit, char *__buf)
845     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (3)));
846
847
848
849
850extern char *qecvt (long double __value, int __ndigit,
851      int *__restrict __decpt, int *__restrict __sign)
852     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (3, 4)));
853extern char *qfcvt (long double __value, int __ndigit,
854      int *__restrict __decpt, int *__restrict __sign)
855     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (3, 4)));
856extern char *qgcvt (long double __value, int __ndigit, char *__buf)
857     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (3)));
858
859
860
861
862extern 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)));
865extern 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)));
868
869extern 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)));
873extern 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)));
877
878
879
880
881
882
883
884extern int mblen (__const char *__s, size_t __n) __attribute__ ((__nothrow__));
885
886
887extern int mbtowc (wchar_t *__restrict __pwc,
888     __const char *__restrict __s, size_t __n) __attribute__ ((__nothrow__));
889
890
891extern int wctomb (char *__s, wchar_t __wchar) __attribute__ ((__nothrow__));
892
893
894
895extern size_t mbstowcs (wchar_t *__restrict __pwcs,
896   __const char *__restrict __s, size_t __n) __attribute__ ((__nothrow__));
897
898extern size_t wcstombs (char *__restrict __s,
899   __const wchar_t *__restrict __pwcs, size_t __n)
900     __attribute__ ((__nothrow__));
901
902
903
904
905
906
907
908
909extern int rpmatch (__const char *__response) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));
910extern int getloadavg (double __loadavg[], int __nelem)
911     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));
912
913
914
915
916
917
918
919typedef
920   struct {
921      char *next_in;
922      unsigned int avail_in;
923      unsigned int total_in_lo32;
924      unsigned int total_in_hi32;
925
926      char *next_out;
927      unsigned int avail_out;
928      unsigned int total_out_lo32;
929      unsigned int total_out_hi32;
930
931      void *state;
932
933      void *(*bzalloc)(void *,int,int);
934      void (*bzfree)(void *,void *);
935      void *opaque;
936   }
937   bz_stream;
938
939extern int BZ2_bzCompressInit (
940      bz_stream* strm,
941      int blockSize100k,
942      int verbosity,
943      int workFactor
944   );
945
946extern int BZ2_bzCompress (
947      bz_stream* strm,
948      int action
949   );
950
951extern int BZ2_bzCompressEnd (
952      bz_stream* strm
953   );
954
955extern int BZ2_bzDecompressInit (
956      bz_stream *strm,
957      int verbosity,
958      int small
959   );
960
961extern int BZ2_bzDecompress (
962      bz_stream* strm
963   );
964
965extern int BZ2_bzDecompressEnd (
966      bz_stream *strm
967   );
968
969extern 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
977   );
978
979extern int BZ2_bzBuffToBuffDecompress (
980      char* dest,
981      unsigned int* destLen,
982      char* source,
983      unsigned int sourceLen,
984      int small,
985      int verbosity
986   );
987
988extern const char * BZ2_bzlibVersion (
989      void
990   );
991
992typedef char Char;
993typedef unsigned char Bool;
994typedef unsigned char UChar;
995typedef int Int32;
996typedef unsigned int UInt32;
997typedef short Int16;
998typedef unsigned short UInt16;
999
1000extern void bz_internal_error ( int errcode );
1001
1002extern Int32 BZ2_rNums[512];
1003
1004extern UInt32 BZ2_crc32Table[256];
1005
1006typedef
1007   struct {
1008
1009      bz_stream* strm;
1010
1011
1012
1013      Int32 mode;
1014      Int32 state;
1015
1016
1017      UInt32 avail_in_expect;
1018
1019
1020      UInt32* arr1;
1021      UInt32* arr2;
1022      UInt32* ftab;
1023      Int32 origPtr;
1024
1025
1026      UInt32* ptr;
1027      UChar* block;
1028      UInt16* mtfv;
1029      UChar* zbits;
1030
1031
1032      Int32 workFactor;
1033
1034
1035      UInt32 state_in_ch;
1036      Int32 state_in_len;
1037      Int32 rNToGo; Int32 rTPos;
1038
1039
1040      Int32 nblock;
1041      Int32 nblockMAX;
1042      Int32 numZ;
1043      Int32 state_out_pos;
1044
1045
1046      Int32 nInUse;
1047      Bool inUse[256];
1048      UChar unseqToSeq[256];
1049
1050
1051      UInt32 bsBuff;
1052      Int32 bsLive;
1053
1054
1055      UInt32 blockCRC;
1056      UInt32 combinedCRC;
1057
1058
1059      Int32 verbosity;
1060      Int32 blockNo;
1061      Int32 blockSize100k;
1062
1063
1064      Int32 nMTF;
1065      Int32 mtfFreq [258];
1066      UChar selector [(2 + (900000 / 50))];
1067      UChar selectorMtf[(2 + (900000 / 50))];
1068
1069      UChar len [6][258];
1070      Int32 code [6][258];
1071      Int32 rfreq [6][258];
1072
1073      UInt32 len_pack[258][4];
1074
1075   }
1076   EState;
1077
1078
1079
1080
1081
1082extern void
1083BZ2_blockSort ( EState* );
1084
1085extern void
1086BZ2_compressBlock ( EState*, Bool );
1087
1088extern void
1089BZ2_bsInitWrite ( EState* );
1090
1091extern void
1092BZ2_hbAssignCodes ( Int32*, UChar*, Int32, Int32, Int32 );
1093
1094extern void
1095BZ2_hbMakeCodeLengths ( UChar*, Int32*, Int32, Int32 );
1096
1097typedef
1098   struct {
1099
1100      bz_stream* strm;
1101
1102
1103      Int32 state;
1104
1105
1106      UChar state_out_ch;
1107      Int32 state_out_len;
1108      Bool blockRandomised;
1109      Int32 rNToGo; Int32 rTPos;
1110
1111
1112      UInt32 bsBuff;
1113      Int32 bsLive;
1114
1115
1116      Int32 blockSize100k;
1117      Bool smallDecompress;
1118      Int32 currBlockNo;
1119      Int32 verbosity;
1120
1121
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];
1129
1130
1131      UInt32 *tt;
1132
1133
1134      UInt16 *ll16;
1135      UChar *ll4;
1136
1137
1138      UInt32 storedBlockCRC;
1139      UInt32 storedCombinedCRC;
1140      UInt32 calculatedBlockCRC;
1141      UInt32 calculatedCombinedCRC;
1142
1143
1144      Int32 nInUse;
1145      Bool inUse[256];
1146      Bool inUse16[16];
1147      UChar seqToUnseq[256];
1148
1149
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];
1155
1156      Int32 limit [6][258];
1157      Int32 base [6][258];
1158      Int32 perm [6][258];
1159      Int32 minLens[6];
1160
1161
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;
1186
1187   }
1188   DState;
1189
1190extern Int32
1191BZ2_indexIntoF ( Int32, Int32* );
1192
1193extern Int32
1194BZ2_decompress ( DState* );
1195
1196extern void
1197BZ2_hbCreateDecodeTables ( Int32*, Int32*, Int32*, UChar*,
1198                           Int32, Int32, Int32 );
1199
1200typedef unsigned long HWord;
1201typedef char HChar;
1202typedef signed int Int;
1203typedef unsigned int UInt;
1204
1205typedef signed long long int Long;
1206typedef unsigned long long int ULong;
1207
1208
1209
1210
1211
1212static HWord (*serviceFn)(HWord,HWord) = 0;
1213
1214char* my_strcat ( char* dest, const char* src )
1215{
1216   char* dest_orig = dest;
1217   while (*dest) dest++;
1218   while (*src) *dest++ = *src++;
1219   *dest = 0;
1220   return dest_orig;
1221}
1222
1223
1224
1225
1226static void vex_log_bytes ( char* p, int n )
1227{
1228   int i;
1229   for (i = 0; i < n; i++)
1230      (*serviceFn)( 1, (int)p[i] );
1231}
1232
1233
1234
1235
1236static HChar vex_toupper ( HChar c )
1237{
1238   if (c >= 'a' && c <= 'z')
1239      return c + ('A' - 'a');
1240   else
1241      return c;
1242}
1243
1244static Int vex_strlen ( const HChar* str )
1245{
1246   Int i = 0;
1247   while (str[i] != 0) i++;
1248   return i;
1249}
1250
1251Bool vex_streq ( const HChar* s1, const HChar* s2 )
1252{
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++;
1260   }
1261}
1262
1263static UInt
1264myvprintf_str ( void(*send)(HChar), Int flags, Int width, HChar* str,
1265                Bool capitalise )
1266{
1267
1268   UInt ret = 0;
1269   Int i, extra;
1270   Int len = vex_strlen(str);
1271
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;
1277   }
1278
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;
1284   }
1285
1286   extra = width - len;
1287   if (flags & 4) {
1288      ret += extra;
1289      for (i = 0; i < extra; i++)
1290         send(' ');
1291   }
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(' ');
1299   }
1300
1301
1302
1303   return ret;
1304}
1305
1306
1307
1308
1309
1310
1311
1312static UInt
1313myvprintf_int64 ( void(*send)(HChar), Int flags, Int base, Int width, ULong pL)
1314{
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;
1322
1323   if (base < 2 || base > 16)
1324      return ret;
1325
1326   if ((flags & 1) && (Int)p < 0) {
1327      p = - (Int)p;
1328      neg = ((Bool)1);
1329   }
1330
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)
1337         {
1338            buf[ind++] = ',';
1339            nc++;
1340         }
1341         buf[ind++] = digits[p % base];
1342         p /= base;
1343      }
1344   }
1345
1346   if (neg)
1347      buf[ind++] = '-';
1348
1349   if (width > 0 && !(flags & 4)) {
1350      for(; ind < width; ind++) {
1351
1352         buf[ind] = ((flags & 2) ? '0': ' ');
1353      }
1354   }
1355
1356
1357   ret += ind;
1358   for (i = ind -1; i >= 0; i--) {
1359      send(buf[i]);
1360   }
1361   if (width > 0 && (flags & 4)) {
1362      for(; ind < width; ind++) {
1363  ret++;
1364         send(' ');
1365      }
1366   }
1367   return ret;
1368}
1369
1370
1371
1372static
1373UInt vprintf_wrk ( )
1374{
1375  return 0;
1376}
1377
1378
1379
1380
1381
1382
1383static HChar myprintf_buf[1000];
1384static Int n_myprintf_buf;
1385
1386static void add_to_myprintf_buf ( HChar c )
1387{
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;
1392   }
1393   myprintf_buf[n_myprintf_buf++] = c;
1394   myprintf_buf[n_myprintf_buf] = 0;
1395}
1396
1397static UInt vex_printf ( const char *format, ... )
1398{
1399  return 0;
1400}
1401
1402static
1403void makeMaps_d ( DState* s )
1404{
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++;
1411      }
1412}
1413
1414__inline__ Int32 BZ2_indexIntoF ( Int32 indx, Int32 *cftab )
1415{
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;
1422   }
1423   while (na - nb != 1);
1424   return nb;
1425}
1426
1427
1428Int32 BZ2_decompress ( DState* s )
1429{
1430   UChar uc;
1431   Int32 retVal;
1432   Int32 minLen, maxLen;
1433   bz_stream* strm = s->strm;
1434
1435
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;
1460
1461   if (s->state == 10) {
1462
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);
1487   }
1488
1489
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;
1514
1515   retVal = 0;
1516
1517   switch (s->state) {
1518
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; };;
1521
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; };;
1524
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; };;
1527
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;
1532
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);
1536
1537
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; };;
1542      }
1543
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++; };
1545
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; };;
1558
1559      s->currBlockNo++;
1560      if (s->verbosity >= 2)
1561         vex_printf("\n    [%d: huff+mtf ",s->currBlockNo);
1562
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);
1572
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++; };
1574
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);
1582
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; };;
1587
1588
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);
1594      }
1595
1596      for (i = 0; i < 256; i++) s->inUse[i] = ((Bool)0);
1597
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);
1603            }
1604      makeMaps_d ( s );
1605      if (s->nInUse == 0) { retVal = (-4); goto save_state_and_return; };;
1606      alphaSize = s->nInUse+2;
1607
1608
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; };;
1620         }
1621         s->selectorMtf[i] = j;
1622      }
1623
1624
1625      {
1626         UChar pos[6], tmp, v;
1627         for (v = 0; v < nGroups; v++) pos[v] = v;
1628
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;
1635         }
1636      }
1637
1638
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--;
1648            }
1649            s->len[t][i] = curr;
1650         }
1651      }
1652
1653
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];
1660         }
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
1667         );
1668         s->minLens[t] = minLen;
1669      }
1670
1671
1672
1673      EOB = s->nInUse+1;
1674      nblockMAX = 100000 * s->blockSize100k;
1675      groupNo = -1;
1676      groupPos = 0;
1677
1678      for (i = 0; i <= 255; i++) s->unzftab[i] = 0;
1679
1680
1681      {
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--;
1688            }
1689            s->mtfbase[ii] = kk + 1;
1690         }
1691      }
1692
1693
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]]; };
1696
1697      while (((Bool)1)) {
1698
1699         if (nextSym == EOB) break;
1700
1701         if (nextSym == 0 || nextSym == 1) {
1702
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]]; };
1710            }
1711               while (nextSym == 0 || nextSym == 1);
1712
1713            es++;
1714            uc = s->seqToUnseq[ s->mtfa[s->mtfbase[0]] ];
1715            s->unzftab[uc] += es;
1716
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--;
1723               }
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--;
1730               };
1731
1732            continue;
1733
1734         } else {
1735
1736            if (nblock >= nblockMAX) { retVal = (-4); goto save_state_and_return; };;
1737
1738
1739            {
1740               Int32 ii, jj, kk, pp, lno, off;
1741               UInt32 nn;
1742               nn = (UInt32)(nextSym - 1);
1743
1744               if (nn < 16) {
1745
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;
1755                  }
1756                  while (nn > 0) {
1757                     s->mtfa[(pp+nn)] = s->mtfa[(pp+nn)-1]; nn--;
1758                  };
1759                  s->mtfa[pp] = uc;
1760               } else {
1761
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--;
1768                  };
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--;
1775                  }
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--;
1784                        }
1785                        s->mtfbase[ii] = kk + 1;
1786                     }
1787                  }
1788               }
1789            }
1790
1791
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++;
1797
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;
1800         }
1801      }
1802
1803
1804
1805
1806      if (s->origPtr < 0 || s->origPtr >= nblock)
1807         { retVal = (-4); goto save_state_and_return; };;
1808
1809
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) {
1815
1816            { retVal = (-4); goto save_state_and_return; };;
1817         }
1818      }
1819
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");
1825
1826      if (s->smallDecompress) {
1827
1828
1829         for (i = 0; i <= 256; i++) s->cftabCopy[i] = s->cftab[i];
1830
1831
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]++;
1836         }
1837
1838
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;
1846         }
1847            while (i != s->origPtr);
1848
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++;
1857         }
1858
1859      } else {
1860
1861
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]++;
1866         }
1867
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++;
1876         }
1877
1878      }
1879
1880      { retVal = 0; goto save_state_and_return; };;
1881
1882
1883
1884    endhdr_2:
1885
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; };;
1896
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);
1906
1907      s->state = 1;
1908      { retVal = 4; goto save_state_and_return; };;
1909
1910      default: { if (!(((Bool)0))) bz_internal_error ( 4001 ); };
1911   }
1912
1913   { if (!(((Bool)0))) bz_internal_error ( 4002 ); };
1914
1915   save_state_and_return:
1916
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;
1941
1942   return retVal;
1943}
1944
1945static
1946__inline__
1947void fallbackSimpleSort ( UInt32* fmap,
1948                          UInt32* eclass,
1949                          Int32 lo,
1950                          Int32 hi )
1951{
1952   Int32 i, j, tmp;
1953   UInt32 ec_tmp;
1954
1955   if (lo == hi) return;
1956
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;
1964      }
1965   }
1966
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;
1973   }
1974}
1975
1976static
1977void fallbackQSort3 ( UInt32* fmap,
1978                      UInt32* eclass,
1979                      Int32 loSt,
1980                      Int32 hiSt )
1981{
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];
1987
1988   r = 0;
1989
1990   sp = 0;
1991   { stackLo[sp] = loSt; stackHi[sp] = hiSt; sp++; };
1992
1993   while (sp > 0) {
1994
1995      { if (!(sp < 100)) bz_internal_error ( 1004 ); };
1996
1997      { sp--; lo = stackLo[sp]; hi = stackHi[sp]; };
1998      if (hi - lo < 10) {
1999         fallbackSimpleSort ( fmap, eclass, lo, hi );
2000         continue;
2001      }
2002
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]];
2008
2009      unLo = ltLo = lo;
2010      unHi = gtHi = hi;
2011
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;
2020            };
2021            if (n > 0) break;
2022            unLo++;
2023         }
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;
2031            };
2032            if (n < 0) break;
2033            unHi--;
2034         }
2035         if (unLo > unHi) break;
2036         { Int32 zztmp = fmap[unLo]; fmap[unLo] = fmap[unHi]; fmap[unHi] = zztmp; }; unLo++; unHi--;
2037      }
2038
2039      ;
2040
2041      if (gtHi < ltLo) continue;
2042
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--; } };
2045
2046      n = lo + unLo - ltLo - 1;
2047      m = hi - (gtHi - unHi) + 1;
2048
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++; };
2055      }
2056   }
2057}
2058
2059static
2060void fallbackSort ( UInt32* fmap,
2061                    UInt32* eclass,
2062                    UInt32* bhtab,
2063                    Int32 nblock,
2064                    Int32 verb )
2065{
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;
2072
2073
2074
2075
2076
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];
2083
2084   for (i = 0; i < nblock; i++) {
2085      j = eclass8[i];
2086      k = ftab[j] - 1;
2087      ftab[j] = k;
2088      fmap[k] = i;
2089   }
2090
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));
2094
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));
2098   }
2099
2100
2101   H = 1;
2102   while (1) {
2103
2104      if (verb >= 4)
2105         vex_printf("        depth %6d has ",H);
2106
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;
2112      }
2113
2114      nNotDone = 0;
2115      r = -1;
2116      while (1) {
2117
2118
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++;
2124         }
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++;
2131         }
2132         r = k - 1;
2133         if (r >= nblock) break;
2134
2135
2136         if (r > l) {
2137            nNotDone += (r - l + 1);
2138            fallbackQSort3 ( fmap, eclass, l, r );
2139
2140
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; };
2145            }
2146         }
2147      }
2148
2149      if (verb >= 4)
2150         vex_printf("%6d unresolved strings\n",nNotDone);
2151
2152      H *= 2;
2153      if (H > nblock || nNotDone == 0) break;
2154   }
2155
2156
2157
2158
2159
2160
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;
2168   }
2169   { if (!(j < 256)) bz_internal_error ( 1005 ); };
2170}
2171
2172static
2173__inline__
2174Bool mainGtU ( UInt32 i1,
2175               UInt32 i2,
2176               UChar* block,
2177               UInt16* quadrant,
2178               UInt32 nblock,
2179               Int32* budget )
2180{
2181   Int32 k;
2182   UChar c1, c2;
2183   UInt16 s1, s2;
2184
2185   ;
2186
2187   c1 = block[i1]; c2 = block[i2];
2188   if (c1 != c2) return (c1 > c2);
2189   i1++; i2++;
2190
2191   c1 = block[i1]; c2 = block[i2];
2192   if (c1 != c2) return (c1 > c2);
2193   i1++; i2++;
2194
2195   c1 = block[i1]; c2 = block[i2];
2196   if (c1 != c2) return (c1 > c2);
2197   i1++; i2++;
2198
2199   c1 = block[i1]; c2 = block[i2];
2200   if (c1 != c2) return (c1 > c2);
2201   i1++; i2++;
2202
2203   c1 = block[i1]; c2 = block[i2];
2204   if (c1 != c2) return (c1 > c2);
2205   i1++; i2++;
2206
2207   c1 = block[i1]; c2 = block[i2];
2208   if (c1 != c2) return (c1 > c2);
2209   i1++; i2++;
2210
2211   c1 = block[i1]; c2 = block[i2];
2212   if (c1 != c2) return (c1 > c2);
2213   i1++; i2++;
2214
2215   c1 = block[i1]; c2 = block[i2];
2216   if (c1 != c2) return (c1 > c2);
2217   i1++; i2++;
2218
2219   c1 = block[i1]; c2 = block[i2];
2220   if (c1 != c2) return (c1 > c2);
2221   i1++; i2++;
2222
2223   c1 = block[i1]; c2 = block[i2];
2224   if (c1 != c2) return (c1 > c2);
2225   i1++; i2++;
2226
2227   c1 = block[i1]; c2 = block[i2];
2228   if (c1 != c2) return (c1 > c2);
2229   i1++; i2++;
2230
2231   c1 = block[i1]; c2 = block[i2];
2232   if (c1 != c2) return (c1 > c2);
2233   i1++; i2++;
2234
2235   k = nblock + 8;
2236
2237   do {
2238
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++;
2244
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++;
2250
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++;
2256
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++;
2262
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++;
2268
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++;
2274
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++;
2280
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++;
2286
2287      if (i1 >= nblock) i1 -= nblock;
2288      if (i2 >= nblock) i2 -= nblock;
2289
2290      k -= 8;
2291      (*budget)--;
2292   }
2293      while (k >= 0);
2294
2295   return ((Bool)0);
2296}
2297
2298static
2299Int32 incs[14] = { 1, 4, 13, 40, 121, 364, 1093, 3280,
2300                   9841, 29524, 88573, 265720,
2301                   797161, 2391484 };
2302
2303static
2304void mainSimpleSort ( UInt32* ptr,
2305                      UChar* block,
2306                      UInt16* quadrant,
2307                      Int32 nblock,
2308                      Int32 lo,
2309                      Int32 hi,
2310                      Int32 d,
2311                      Int32* budget )
2312{
2313   Int32 i, j, h, bigN, hp;
2314   UInt32 v;
2315
2316   bigN = hi - lo + 1;
2317   if (bigN < 2) return;
2318
2319   hp = 0;
2320   while (incs[hp] < bigN) hp++;
2321   hp--;
2322
2323   for (; hp >= 0; hp--) {
2324      h = incs[hp];
2325
2326      i = lo + h;
2327      while (((Bool)1)) {
2328
2329
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;
2339         }
2340         ptr[j] = v;
2341         i++;
2342
2343
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;
2353         }
2354         ptr[j] = v;
2355         i++;
2356
2357
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;
2367         }
2368         ptr[j] = v;
2369         i++;
2370
2371         if (*budget < 0) return;
2372      }
2373   }
2374}
2375
2376static
2377__inline__
2378UChar mmed3 ( UChar a, UChar b, UChar c )
2379{
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;
2385   }
2386   return b;
2387}
2388
2389static
2390void mainQSort3 ( UInt32* ptr,
2391                  UChar* block,
2392                  UInt16* quadrant,
2393                  Int32 nblock,
2394                  Int32 loSt,
2395                  Int32 hiSt,
2396                  Int32 dSt,
2397                  Int32* budget )
2398{
2399   Int32 unLo, unHi, ltLo, gtHi, n, m, med;
2400   Int32 sp, lo, hi, d;
2401
2402   Int32 stackLo[100];
2403   Int32 stackHi[100];
2404   Int32 stackD [100];
2405
2406   Int32 nextLo[3];
2407   Int32 nextHi[3];
2408   Int32 nextD [3];
2409
2410   sp = 0;
2411   { stackLo[sp] = loSt; stackHi[sp] = hiSt; stackD [sp] = dSt; sp++; };
2412
2413   while (sp > 0) {
2414
2415      { if (!(sp < 100)) bz_internal_error ( 1001 ); };
2416
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;
2423      }
2424
2425      med = (Int32)
2426            mmed3 ( block[ptr[ lo ]+d],
2427                    block[ptr[ hi ]+d],
2428                    block[ptr[ (lo+hi)>>1 ]+d] );
2429
2430      unLo = ltLo = lo;
2431      unHi = gtHi = hi;
2432
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;
2440            };
2441            if (n > 0) break;
2442            unLo++;
2443         }
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;
2450            };
2451            if (n < 0) break;
2452            unHi--;
2453         }
2454         if (unLo > unHi) break;
2455         { Int32 zztmp = ptr[unLo]; ptr[unLo] = ptr[unHi]; ptr[unHi] = zztmp; }; unLo++; unHi--;
2456      }
2457
2458      ;
2459
2460      if (gtHi < ltLo) {
2461         { stackLo[sp] = lo; stackHi[sp] = hi; stackD [sp] = d+1; sp++; };
2462         continue;
2463      }
2464
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--; } };
2467
2468      n = lo + unLo - ltLo - 1;
2469      m = hi - (gtHi - unHi) + 1;
2470
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;
2474
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; };
2478
2479      ;
2480      ;
2481
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++; };
2485   }
2486}
2487
2488static
2489void mainSort ( UInt32* ptr,
2490                UChar* block,
2491                UInt16* quadrant,
2492                UInt32* ftab,
2493                Int32 nblock,
2494                Int32 verb,
2495                Int32* budget )
2496{
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");
2506
2507
2508   for (i = 65536; i >= 0; i--) ftab[i] = 0;
2509
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]++;
2525   }
2526   for (; i >= 0; i--) {
2527      quadrant[i] = 0;
2528      j = (j >> 8) | ( ((UInt16)block[i]) << 8);
2529      ftab[j]++;
2530   }
2531
2532
2533   for (i = 0; i < (2 + 12 + 18 + 2); i++) {
2534      block [nblock+i] = block[i];
2535      quadrant[nblock+i] = 0;
2536   }
2537
2538   if (verb >= 4) vex_printf("        bucket sorting ...\n");
2539
2540
2541   for (i = 1; i <= 65536; i++) ftab[i] += ftab[i-1];
2542
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;
2562   }
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;
2568   }
2569
2570
2571
2572
2573
2574
2575   for (i = 0; i <= 255; i++) {
2576      bigDone [i] = ((Bool)0);
2577      runningOrder[i] = i;
2578   }
2579
2580   {
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;
2593            }
2594            zero:
2595            runningOrder[j] = vv;
2596         }
2597      } while (h != 1);
2598   }
2599
2600
2601
2602
2603
2604   numQSorted = 0;
2605
2606   for (i = 0; i <= 255; i++) {
2607
2608
2609
2610
2611
2612
2613
2614      ss = runningOrder[i];
2615
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);
2625
2626
2627                  mainQSort3 (
2628                     ptr, block, quadrant, nblock,
2629                     lo, hi, 2, budget
2630                  );
2631                  numQSorted += (hi - lo + 1);
2632                  if (*budget < 0) return;
2633               }
2634            }
2635            ftab[sb] |= (1 << 21);
2636         }
2637      }
2638
2639      { if (!(!bigDone[ss])) bz_internal_error ( 1006 ); };
2640
2641      {
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;
2645         }
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;
2651         }
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;
2657         }
2658      }
2659
2660      { if (!((copyStart[ss]-1 == copyEnd[ss]) || (copyStart[ss] == 0 && copyEnd[ss] == nblock-1))) bz_internal_error ( 1007 ); }
2661
2662      for (j = 0; j <= 255; j++) ftab[(j << 8) + ss] |= (1 << 21);
2663
2664      bigDone[ss] = ((Bool)1);
2665
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;
2670
2671         while ((bbSize >> shifts) > 65534) shifts++;
2672
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;
2679         }
2680         { if (!(((bbSize-1) >> shifts) <= 65535)) bz_internal_error ( 1002 ); };
2681      }
2682
2683   }
2684
2685   if (verb >= 4)
2686      vex_printf("        %d pointers, %d sorted, %d scanned\n",nblock,numQSorted,nblock - numQSorted);
2687
2688}
2689
2690void BZ2_blockSort ( EState* s )
2691{
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;
2702
2703   if (nblock < 1000 ) {
2704      fallbackSort ( s->arr1, s->arr2, ftab, nblock, verb );
2705   } else {
2706
2707
2708
2709
2710
2711      i = nblock+(2 + 12 + 18 + 2);
2712      if (i & 1) i++;
2713      quadrant = (UInt16*)(&(block[i]));
2714
2715      if (wfact < 1 ) wfact = 1;
2716      if (wfact > 100) wfact = 100;
2717      budgetInit = nblock * ((wfact-1) / 3);
2718      budget = budgetInit;
2719
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));
2723
2724
2725
2726
2727      if (budget < 0) {
2728         if (verb >= 2)
2729            vex_printf("    too repetitive; using fallback" " sorting algorithm\n");
2730
2731         fallbackSort ( s->arr1, s->arr2, ftab, nblock, verb );
2732      }
2733   }
2734
2735   s->origPtr = -1;
2736   for (i = 0; i < s->nblock; i++)
2737      if (ptr[i] == 0)
2738         { s->origPtr = i; break; };
2739
2740   { if (!(s->origPtr != -1)) bz_internal_error ( 1003 ); };
2741}
2742
2743void BZ2_hbMakeCodeLengths ( UChar *len,
2744                             Int32 *freq,
2745                             Int32 alphaSize,
2746                             Int32 maxLen )
2747{
2748
2749
2750
2751
2752   Int32 nNodes, nHeap, n1, n2, i, j, k;
2753   Bool tooLong;
2754
2755   Int32 heap [ 258 + 2 ];
2756   Int32 weight [ 258 * 2 ];
2757   Int32 parent [ 258 * 2 ];
2758
2759   for (i = 0; i < alphaSize; i++)
2760      weight[i+1] = (freq[i] == 0 ? 1 : freq[i]) << 8;
2761
2762   while (((Bool)1)) {
2763
2764      nNodes = alphaSize;
2765      nHeap = 0;
2766
2767      heap[0] = 0;
2768      weight[0] = 0;
2769      parent[0] = -2;
2770
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; };
2776      }
2777
2778      { if (!(nHeap < (258 +2))) bz_internal_error ( 2001 ); };
2779
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; };
2790      }
2791
2792      { if (!(nNodes < (258 * 2))) bz_internal_error ( 2002 ); };
2793
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);
2801      }
2802
2803      if (! tooLong) break;
2804
2805      for (i = 1; i <= alphaSize; i++) {
2806         j = weight[i] >> 8;
2807         j = 1 + (j / 2);
2808         weight[i] = j << 8;
2809      }
2810   }
2811}
2812
2813
2814
2815void BZ2_hbAssignCodes ( Int32 *code,
2816                         UChar *length,
2817                         Int32 minLen,
2818                         Int32 maxLen,
2819                         Int32 alphaSize )
2820{
2821   Int32 n, vec, i;
2822
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;
2828   }
2829}
2830
2831
2832
2833void BZ2_hbCreateDecodeTables ( Int32 *limit,
2834                                Int32 *base,
2835                                Int32 *perm,
2836                                UChar *length,
2837                                Int32 minLen,
2838                                Int32 maxLen,
2839                                Int32 alphaSize )
2840{
2841   Int32 pp, i, j, vec;
2842
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++; };
2847
2848   for (i = 0; i < 23; i++) base[i] = 0;
2849   for (i = 0; i < alphaSize; i++) base[length[i]+1]++;
2850
2851   for (i = 1; i < 23; i++) base[i] += base[i-1];
2852
2853   for (i = 0; i < 23; i++) limit[i] = 0;
2854   vec = 0;
2855
2856   for (i = minLen; i <= maxLen; i++) {
2857      vec += (base[i+1] - base[i]);
2858      limit[i] = vec-1;
2859      vec <<= 1;
2860   }
2861   for (i = minLen + 1; i <= maxLen; i++)
2862      base[i] = ((limit[i-1] + 1) << 1) - base[i];
2863}
2864
2865void BZ2_bsInitWrite ( EState* s )
2866{
2867   s->bsLive = 0;
2868   s->bsBuff = 0;
2869}
2870
2871
2872
2873static
2874void bsFinishWrite ( EState* s )
2875{
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;
2881   }
2882}
2883
2884static
2885__inline__
2886void bsW ( EState* s, Int32 n, UInt32 v )
2887{
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;
2891}
2892
2893
2894
2895static
2896void bsPutUInt32 ( EState* s, UInt32 u )
2897{
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 );
2902}
2903
2904
2905
2906static
2907void bsPutUChar ( EState* s, UChar c )
2908{
2909   bsW( s, 8, (UInt32)c );
2910}
2911
2912
2913
2914
2915
2916
2917
2918static
2919void makeMaps_e ( EState* s )
2920{
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++;
2927      }
2928}
2929
2930
2931
2932static
2933void generateMTFValues ( EState* s )
2934{
2935   UChar yy[256];
2936   Int32 i, j;
2937   Int32 zPend;
2938   Int32 wr;
2939   Int32 EOB;
2940
2941   UInt32* ptr = s->ptr;
2942   UChar* block = s->block;
2943   UInt16* mtfv = s->mtfv;
2944
2945   makeMaps_e ( s );
2946   EOB = s->nInUse+1;
2947
2948   for (i = 0; i <= EOB; i++) s->mtfFreq[i] = 0;
2949
2950   wr = 0;
2951   zPend = 0;
2952   for (i = 0; i < s->nInUse; i++) yy[i] = (UChar) i;
2953
2954   for (i = 0; i < s->nblock; i++) {
2955      UChar ll_i;
2956      ;
2957      j = ptr[i]-1; if (j < 0) j += s->nblock;
2958      ll_i = s->unseqToSeq[block[j]];
2959      ;
2960
2961      if (yy[0] == ll_i) {
2962         zPend++;
2963      } else {
2964
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]++;
2974               }
2975               if (zPend < 2) break;
2976               zPend = (zPend - 2) / 2;
2977            };
2978            zPend = 0;
2979         }
2980         {
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;
2994            };
2995            yy[0] = rtmp;
2996            j = ryy_j - &(yy[0]);
2997            mtfv[wr] = j+1; wr++; s->mtfFreq[j+1]++;
2998         }
2999
3000      }
3001   }
3002
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]++;
3012         }
3013         if (zPend < 2) break;
3014         zPend = (zPend - 2) / 2;
3015      };
3016      zPend = 0;
3017   }
3018
3019   mtfv[wr] = EOB; wr++; s->mtfFreq[EOB]++;
3020
3021   s->nMTF = wr;
3022}
3023
3024
3025
3026
3027
3028
3029static
3030void sendMTFValues ( EState* s )
3031{
3032   Int32 v, t, i, j, gs, ge, totc, bt, bc, iter;
3033   Int32 nSelectors, alphaSize, minLen, maxLen, selCtr;
3034   Int32 nGroups, nBytes;
3035
3036   UInt16 cost[6];
3037   Int32 fave[6];
3038
3039   UInt16* mtfv = s->mtfv;
3040
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);
3043
3044
3045
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;
3050
3051
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;
3058
3059
3060   {
3061      Int32 nPart, remF, tFreq, aFreq;
3062
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];
3073         }
3074
3075         if (ge > gs
3076             && nPart != nGroups && nPart != 1
3077             && ((nGroups-nPart) % 2 == 1)) {
3078            aFreq -= s->mtfFreq[ge];
3079            ge--;
3080         }
3081
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));
3084
3085
3086
3087
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;
3092
3093         nPart--;
3094         gs = ge+1;
3095         remF -= aFreq;
3096      }
3097   }
3098
3099
3100
3101
3102   for (iter = 0; iter < 4; iter++) {
3103
3104      for (t = 0; t < nGroups; t++) fave[t] = 0;
3105
3106      for (t = 0; t < nGroups; t++)
3107         for (v = 0; v < alphaSize; v++)
3108            s->rfreq[t][v] = 0;
3109
3110
3111
3112
3113
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];
3119  }
3120      }
3121
3122      nSelectors = 0;
3123      totc = 0;
3124      gs = 0;
3125      while (((Bool)1)) {
3126
3127
3128         if (gs >= s->nMTF) break;
3129         ge = gs + 50 - 1;
3130         if (ge >= s->nMTF) ge = s->nMTF-1;
3131
3132
3133
3134
3135
3136         for (t = 0; t < nGroups; t++) cost[t] = 0;
3137
3138         if (nGroups == 6 && 50 == ge-gs+1) {
3139
3140            register UInt32 cost01, cost23, cost45;
3141            register UInt16 icv;
3142            cost01 = cost23 = cost45 = 0;
3143
3144
3145
3146
3147
3148
3149
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];;
3160
3161
3162
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;
3166
3167         } else {
3168
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];
3172            }
3173         }
3174
3175
3176
3177
3178
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++;
3186
3187
3188
3189
3190         if (nGroups == 6 && 50 == ge-gs+1) {
3191
3192
3193
3194
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)] ]++;
3205
3206
3207
3208         } else {
3209
3210            for (i = gs; i <= ge; i++)
3211               s->rfreq[bt][ mtfv[i] ]++;
3212         }
3213
3214         gs = ge+1;
3215      }
3216      if (s->verbosity >= 3) {
3217         vex_printf("      pass %d: size is %d, grp uses are ",iter+1,totc/8);
3218
3219         for (t = 0; t < nGroups; t++)
3220            vex_printf("%d ",fave[t]);
3221         vex_printf("\n");
3222      }
3223
3224
3225
3226
3227
3228
3229      for (t = 0; t < nGroups; t++)
3230         BZ2_hbMakeCodeLengths ( &(s->len[t][0]), &(s->rfreq[t][0]),
3231                                 alphaSize, 17 );
3232   }
3233
3234
3235   { if (!(nGroups < 8)) bz_internal_error ( 3002 ); };
3236   { if (!(nSelectors < 32768 && nSelectors <= (2 + (900000 / 50)))) bz_internal_error ( 3003 ); };
3237
3238
3239
3240
3241
3242   {
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;
3254         };
3255         pos[0] = tmp;
3256         s->selectorMtf[i] = j;
3257      }
3258   };
3259
3260
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];
3267      }
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 );
3272   }
3273
3274
3275   {
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);
3281      }
3282
3283      nBytes = s->numZ;
3284      for (i = 0; i < 16; i++)
3285         if (inUse16[i]) bsW(s,1,1); else bsW(s,1,0);
3286
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);
3291            }
3292
3293      if (s->verbosity >= 3)
3294         vex_printf("      bytes: mapping %d, ",s->numZ-nBytes);
3295   }
3296
3297
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);
3304   }
3305   if (s->verbosity >= 3)
3306      vex_printf("selectors %d, ",s->numZ-nBytes);
3307
3308
3309   nBytes = s->numZ;
3310
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 );
3318      }
3319   }
3320
3321   if (s->verbosity >= 3)
3322      vex_printf("code lengths %d, ",s->numZ-nBytes);
3323
3324
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 ); };
3333
3334      if (nGroups == 6 && 50 == ge-gs+1) {
3335
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]);
3341
3342
3343
3344
3345
3346
3347
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] );
3358
3359
3360
3361      } else {
3362
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]] );
3367         }
3368      }
3369
3370
3371      gs = ge+1;
3372      selCtr++;
3373   }
3374   { if (!(selCtr == nSelectors)) bz_internal_error ( 3007 ); };
3375
3376   if (s->verbosity >= 3)
3377      vex_printf("codes %d\n",s->numZ-nBytes);
3378}
3379
3380
3381
3382void BZ2_compressBlock ( EState* s, Bool is_last_block )
3383{
3384   if (s->nblock > 0) {
3385
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;
3390
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);
3393
3394
3395
3396      BZ2_blockSort ( s );
3397   }
3398
3399   s->zbits = (UChar*) (&((UChar*)s->arr2)[s->nblock]);
3400
3401
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) );
3408   }
3409
3410   if (s->nblock > 0) {
3411
3412      bsPutUChar ( s, 0x31 ); bsPutUChar ( s, 0x41 );
3413      bsPutUChar ( s, 0x59 ); bsPutUChar ( s, 0x26 );
3414      bsPutUChar ( s, 0x53 ); bsPutUChar ( s, 0x59 );
3415
3416
3417      bsPutUInt32 ( s, s->blockCRC );
3418
3419      bsW(s,1,0);
3420
3421      bsW ( s, 24, s->origPtr );
3422      generateMTFValues ( s );
3423      sendMTFValues ( s );
3424   }
3425
3426
3427
3428   if (is_last_block) {
3429
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 );
3437   }
3438}
3439
3440Int32 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
3493};
3494
3495UInt32 BZ2_crc32Table[256] = {
3496
3497
3498
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
3563};
3564
3565void BZ2_bz__AssertH__fail ( int errcode )
3566{
3567   vex_printf("BZ2_bz__AssertH__fail(%d) called, exiting\n", errcode);
3568   (*serviceFn)(0,0);
3569}
3570
3571void bz_internal_error ( int errcode )
3572{
3573   vex_printf("bz_internal_error called, exiting\n", errcode);
3574   (*serviceFn)(0,0);
3575}
3576
3577
3578static
3579int bz_config_ok ( void )
3580{
3581   if (sizeof(int) != 4) return 0;
3582   if (sizeof(short) != 2) return 0;
3583   if (sizeof(char) != 1) return 0;
3584   return 1;
3585}
3586
3587
3588
3589static
3590void* default_bzalloc ( void* opaque, Int32 items, Int32 size )
3591{
3592   void* v = (void*) (*serviceFn)(2, items * size );
3593   return v;
3594}
3595
3596static
3597void default_bzfree ( void* opaque, void* addr )
3598{
3599   if (addr != ((void *)0)) (*serviceFn)( 3, (HWord)addr );
3600}
3601
3602
3603
3604static
3605void prepare_new_block ( EState* s )
3606{
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++;
3614}
3615
3616
3617
3618static
3619void init_RL ( EState* s )
3620{
3621   s->state_in_ch = 256;
3622   s->state_in_len = 0;
3623}
3624
3625
3626static
3627Bool isempty_RL ( EState* s )
3628{
3629   if (s->state_in_ch < 256 && s->state_in_len > 0)
3630      return ((Bool)0); else
3631      return ((Bool)1);
3632}
3633
3634
3635
3636int BZ2_bzCompressInit
3637                    ( bz_stream* strm,
3638                     int blockSize100k,
3639                     int verbosity,
3640                     int workFactor )
3641{
3642   Int32 n;
3643   EState* s;
3644
3645   if (!bz_config_ok()) return (-9);
3646
3647   if (strm == ((void *)0) ||
3648       blockSize100k < 1 || blockSize100k > 9 ||
3649       workFactor < 0 || workFactor > 250)
3650     return (-2);
3651
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;
3655
3656   s = (strm->bzalloc)(strm->opaque,(sizeof(EState)),1);
3657   if (s == ((void *)0)) return (-3);
3658   s->strm = strm;
3659
3660   s->arr1 = ((void *)0);
3661   s->arr2 = ((void *)0);
3662   s->ftab = ((void *)0);
3663
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);
3668
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);
3675   }
3676
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;
3685
3686   s->block = (UChar*)s->arr2;
3687   s->mtfv = (UInt16*)s->arr1;
3688   s->zbits = ((void *)0);
3689   s->ptr = (UInt32*)s->arr1;
3690
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;
3699}
3700
3701
3702
3703static
3704void add_pair_to_block ( EState* s )
3705{
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)]; };
3710   }
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;
3734   }
3735}
3736
3737
3738
3739static
3740void flush_RL ( EState* s )
3741{
3742   if (s->state_in_ch < 256) add_pair_to_block ( s );
3743   init_RL ( s );
3744}
3745
3746static
3747Bool copy_input_until_stop ( EState* s )
3748{
3749   Bool progress_in = ((Bool)0);
3750
3751   if (s->mode == 2) {
3752
3753
3754      while (((Bool)1)) {
3755
3756         if (s->nblock >= s->nblockMAX) break;
3757
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++;
3765      }
3766
3767   } else {
3768
3769
3770      while (((Bool)1)) {
3771
3772         if (s->nblock >= s->nblockMAX) break;
3773
3774         if (s->strm->avail_in == 0) break;
3775
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--;
3784      }
3785   }
3786   return progress_in;
3787}
3788
3789
3790
3791static
3792Bool copy_output_until_stop ( EState* s )
3793{
3794   Bool progress_out = ((Bool)0);
3795
3796   while (((Bool)1)) {
3797
3798
3799      if (s->strm->avail_out == 0) break;
3800
3801
3802      if (s->state_out_pos >= s->numZ) break;
3803
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++;
3811   }
3812
3813   return progress_out;
3814}
3815
3816
3817
3818static
3819Bool handle_compress ( bz_stream* strm )
3820{
3821   Bool progress_in = ((Bool)0);
3822   Bool progress_out = ((Bool)0);
3823   EState* s = strm->state;
3824
3825   while (((Bool)1)) {
3826
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;
3838      }
3839
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;
3846         }
3847         else
3848         if (s->nblock >= s->nblockMAX) {
3849            BZ2_compressBlock ( s, ((Bool)0) );
3850            s->state = 1;
3851         }
3852         else
3853         if (s->strm->avail_in == 0) {
3854            break;
3855         }
3856      }
3857
3858   }
3859
3860   return progress_in || progress_out;
3861}
3862
3863
3864
3865int BZ2_bzCompress ( bz_stream *strm, int action )
3866{
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);
3873
3874   preswitch:
3875   switch (s->mode) {
3876
3877      case 1:
3878         return (-1);
3879
3880      case 2:
3881         if (action == 0) {
3882            progress = handle_compress ( strm );
3883            return progress ? 1 : (-2);
3884         }
3885         else
3886  if (action == 1) {
3887            s->avail_in_expect = strm->avail_in;
3888            s->mode = 3;
3889            goto preswitch;
3890         }
3891         else
3892         if (action == 2) {
3893            s->avail_in_expect = strm->avail_in;
3894            s->mode = 4;
3895            goto preswitch;
3896         }
3897         else
3898            return (-2);
3899
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;
3909
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;
3920   }
3921   return 0;
3922}
3923
3924
3925
3926int BZ2_bzCompressEnd ( bz_stream *strm )
3927{
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);
3933
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));
3938
3939   strm->state = ((void *)0);
3940
3941   return 0;
3942}
3943
3944
3945
3946
3947
3948
3949
3950int BZ2_bzDecompressInit
3951                     ( bz_stream* strm,
3952                       int verbosity,
3953                       int small )
3954{
3955   DState* s;
3956
3957   if (!bz_config_ok()) return (-9);
3958
3959   if (strm == ((void *)0)) return (-2);
3960   if (small != 0 && small != 1) return (-2);
3961   if (verbosity < 0 || verbosity > 4) return (-2);
3962
3963   if (strm->bzalloc == ((void *)0)) strm->bzalloc = default_bzalloc;
3964   if (strm->bzfree == ((void *)0)) strm->bzfree = default_bzfree;
3965
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;
3984
3985   return 0;
3986}
3987
3988
3989
3990
3991
3992
3993static
3994Bool unRLE_obuf_to_output_FAST ( DState* s )
3995{
3996   UChar k1;
3997
3998   if (s->blockRandomised) {
3999
4000      while (((Bool)1)) {
4001
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++;
4012         }
4013
4014
4015         if (s->nblock_used == s->save_nblock+1) return ((Bool)0);
4016
4017
4018         if (s->nblock_used > s->save_nblock+1)
4019            return ((Bool)1);
4020
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; };
4027
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; };
4033
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; };
4039
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++;
4045      }
4046
4047   } else {
4048
4049
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;
4059
4060
4061      UInt32 avail_out_INIT = cs_avail_out;
4062      Int32 s_save_nblockPP = s->save_nblock+1;
4063      unsigned int total_out_lo32_old;
4064
4065      while (((Bool)1)) {
4066
4067
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--;
4077            }
4078            s_state_out_len_eq_one:
4079            {
4080               if (cs_avail_out == 0) {
4081                  c_state_out_len = 1; goto return_notr;
4082               };
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--;
4087            }
4088         }
4089
4090         if (c_nblock_used > s_save_nblockPP)
4091            return ((Bool)1);
4092
4093
4094         if (c_nblock_used == s_save_nblockPP) {
4095            c_state_out_len = 0; goto return_notr;
4096         };
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;
4101         };
4102         if (c_nblock_used == s_save_nblockPP)
4103            goto s_state_out_len_eq_one;
4104
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; };
4109
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; };
4114
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++;
4118      }
4119
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++;
4125
4126
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;
4136
4137   }
4138   return ((Bool)0);
4139}
4140
4141
4142
4143
4144
4145
4146
4147static
4148Bool unRLE_obuf_to_output_SMALL ( DState* s )
4149{
4150   UChar k1;
4151
4152   if (s->blockRandomised) {
4153
4154      while (((Bool)1)) {
4155
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++;
4166         }
4167
4168
4169         if (s->nblock_used == s->save_nblock+1) return ((Bool)0);
4170
4171
4172         if (s->nblock_used > s->save_nblock+1)
4173            return ((Bool)1);
4174
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; };
4181
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; };
4187
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; };
4193
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++;
4199      }
4200
4201   } else {
4202
4203      while (((Bool)1)) {
4204
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++;
4215         }
4216
4217
4218         if (s->nblock_used == s->save_nblock+1) return ((Bool)0);
4219
4220
4221         if (s->nblock_used > s->save_nblock+1)
4222            return ((Bool)1);
4223
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; };
4229
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; };
4234
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; };
4239
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++;
4243      }
4244
4245   }
4246}
4247
4248
4249
4250int BZ2_bzDecompress ( bz_stream *strm )
4251{
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);
4258
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);
4270
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;
4281         }
4282      }
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);
4288
4289            if (s->calculatedCombinedCRC != s->storedCombinedCRC)
4290               return (-4);
4291            return r;
4292         }
4293         if (s->state != 2) return r;
4294      }
4295   }
4296
4297   { if (!(0)) bz_internal_error ( 6001 ); };
4298
4299   return 0;
4300}
4301
4302
4303
4304int BZ2_bzDecompressEnd ( bz_stream *strm )
4305{
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);
4311
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));
4315
4316   (strm->bzfree)(strm->opaque,(strm->state));
4317   strm->state = ((void *)0);
4318
4319   return 0;
4320}
4321
4322int 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 )
4330{
4331   bz_stream strm;
4332   int ret;
4333
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);
4340
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;
4348
4349   strm.next_in = source;
4350   strm.next_out = dest;
4351   strm.avail_in = sourceLen;
4352   strm.avail_out = *destLen;
4353
4354   ret = BZ2_bzCompress ( &strm, 2 );
4355   if (ret == 3) goto output_overflow;
4356   if (ret != 4) goto errhandler;
4357
4358
4359   *destLen -= strm.avail_out;
4360   BZ2_bzCompressEnd ( &strm );
4361   return 0;
4362
4363   output_overflow:
4364   BZ2_bzCompressEnd ( &strm );
4365   return (-8);
4366
4367   errhandler:
4368   BZ2_bzCompressEnd ( &strm );
4369   return ret;
4370}
4371
4372
4373
4374int BZ2_bzBuffToBuffDecompress
4375                           ( char* dest,
4376                             unsigned int* destLen,
4377                             char* source,
4378                             unsigned int sourceLen,
4379                             int small,
4380                             int verbosity )
4381{
4382   bz_stream strm;
4383   int ret;
4384
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);
4390
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;
4396
4397   strm.next_in = source;
4398   strm.next_out = dest;
4399   strm.avail_in = sourceLen;
4400   strm.avail_out = *destLen;
4401
4402   ret = BZ2_bzDecompress ( &strm );
4403   if (ret == 0) goto output_overflow_or_eof;
4404   if (ret != 4) goto errhandler;
4405
4406
4407   *destLen -= strm.avail_out;
4408   BZ2_bzDecompressEnd ( &strm );
4409   return 0;
4410
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);
4418   };
4419
4420   errhandler:
4421   BZ2_bzDecompressEnd ( &strm );
4422   return ret;
4423}
4424
4425const char * BZ2_bzlibVersion(void)
4426{
4427   return "1.0.3, 17-Oct-2004";
4428}
4429
4430typedef unsigned char uchar;
4431
4432
4433 char inbuf[1000000];
4434 char outbuf[(1000000 + 1000000)];
4435 char zbuf[1000000 + 600 + (1000000 / 100)];
4436
4437int nIn;
4438unsigned int nOut;
4439unsigned int nZ;
4440
4441void flip_bit ( int bit )
4442{
4443   int byteno = bit / 8;
4444   int bitno = bit % 8;
4445   uchar mask = 1 << bitno;
4446
4447
4448   zbuf[byteno] ^= mask;
4449}
4450
4451void set_inbuf ( void )
4452{
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");
4872
4873  my_strcat(inbuf, "\n");
4874}
4875
4876
4877typedef struct _IO_FILE FILE;
4878
4879
4880
4881typedef struct _IO_FILE __FILE;
4882typedef unsigned int wint_t;
4883
4884typedef struct
4885{
4886  int __count;
4887  union
4888  {
4889    wint_t __wch;
4890    char __wchb[4];
4891  } __value;
4892} __mbstate_t;
4893
4894
4895typedef struct
4896{
4897  __off_t __pos;
4898  __mbstate_t __state;
4899} _G_fpos_t;
4900typedef struct
4901{
4902  __off64_t __pos;
4903  __mbstate_t __state;
4904} _G_fpos64_t;
4905
4906
4907enum
4908{
4909  __GCONV_OK = 0,
4910  __GCONV_NOCONV,
4911  __GCONV_NODB,
4912  __GCONV_NOMEM,
4913
4914  __GCONV_EMPTY_INPUT,
4915  __GCONV_FULL_OUTPUT,
4916  __GCONV_ILLEGAL_INPUT,
4917  __GCONV_INCOMPLETE_INPUT,
4918
4919  __GCONV_ILLEGAL_DESCRIPTOR,
4920  __GCONV_INTERNAL_ERROR
4921};
4922
4923
4924
4925enum
4926{
4927  __GCONV_IS_LAST = 0x0001,
4928  __GCONV_IGNORE_ERRORS = 0x0002
4929};
4930
4931
4932
4933struct __gconv_step;
4934struct __gconv_step_data;
4935struct __gconv_loaded_object;
4936struct __gconv_trans_data;
4937
4938
4939
4940typedef int (*__gconv_fct) (struct __gconv_step *, struct __gconv_step_data *,
4941       __const unsigned char **, __const unsigned char *,
4942       unsigned char **, size_t *, int, int);
4943
4944
4945typedef wint_t (*__gconv_btowc_fct) (struct __gconv_step *, unsigned char);
4946
4947
4948typedef int (*__gconv_init_fct) (struct __gconv_step *);
4949typedef void (*__gconv_end_fct) (struct __gconv_step *);
4950
4951
4952
4953typedef 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 *);
4959
4960
4961typedef int (*__gconv_trans_context_fct) (void *, __const unsigned char *,
4962       __const unsigned char *,
4963       unsigned char *, unsigned char *);
4964
4965
4966typedef int (*__gconv_trans_query_fct) (__const char *, __const char ***,
4967     size_t *);
4968
4969
4970typedef int (*__gconv_trans_init_fct) (void **, const char *);
4971typedef void (*__gconv_trans_end_fct) (void *);
4972
4973struct __gconv_trans_data
4974{
4975
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;
4981};
4982
4983
4984
4985struct __gconv_step
4986{
4987  struct __gconv_loaded_object *__shlib_handle;
4988  __const char *__modname;
4989
4990  int __counter;
4991
4992  char *__from_name;
4993  char *__to_name;
4994
4995  __gconv_fct __fct;
4996  __gconv_btowc_fct __btowc_fct;
4997  __gconv_init_fct __init_fct;
4998  __gconv_end_fct __end_fct;
4999
5000
5001
5002  int __min_needed_from;
5003  int __max_needed_from;
5004  int __min_needed_to;
5005  int __max_needed_to;
5006
5007
5008  int __stateful;
5009
5010  void *__data;
5011};
5012
5013
5014
5015struct __gconv_step_data
5016{
5017  unsigned char *__outbuf;
5018  unsigned char *__outbufend;
5019
5020
5021
5022  int __flags;
5023
5024
5025
5026  int __invocation_counter;
5027
5028
5029
5030  int __internal_use;
5031
5032  __mbstate_t *__statep;
5033  __mbstate_t __state;
5034
5035
5036
5037  struct __gconv_trans_data *__trans;
5038};
5039
5040
5041
5042typedef struct __gconv_info
5043{
5044  size_t __nsteps;
5045  struct __gconv_step *__steps;
5046  __extension__ struct __gconv_step_data __data [];
5047} *__gconv_t;
5048
5049typedef union
5050{
5051  struct __gconv_info __cd;
5052  struct
5053  {
5054    struct __gconv_info __cd;
5055    struct __gconv_step_data __data;
5056  } __combined;
5057} _G_iconv_t;
5058
5059typedef int _G_int16_t __attribute__ ((__mode__ (__HI__)));
5060typedef int _G_int32_t __attribute__ ((__mode__ (__SI__)));
5061typedef unsigned int _G_uint16_t __attribute__ ((__mode__ (__HI__)));
5062typedef unsigned int _G_uint32_t __attribute__ ((__mode__ (__SI__)));
5063
5064struct _IO_jump_t; struct _IO_FILE;
5065
5066typedef void _IO_lock_t;
5067
5068
5069
5070
5071
5072struct _IO_marker {
5073  struct _IO_marker *_next;
5074  struct _IO_FILE *_sbuf;
5075
5076
5077
5078  int _pos;
5079
5080};
5081
5082
5083enum __codecvt_result
5084{
5085  __codecvt_ok,
5086  __codecvt_partial,
5087  __codecvt_error,
5088  __codecvt_noconv
5089};
5090
5091struct _IO_FILE {
5092  int _flags;
5093
5094
5095
5096
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;
5105
5106  char *_IO_save_base;
5107  char *_IO_backup_base;
5108  char *_IO_save_end;
5109
5110  struct _IO_marker *_markers;
5111
5112  struct _IO_FILE *_chain;
5113
5114  int _fileno;
5115
5116
5117
5118  int _flags2;
5119
5120  __off_t _old_offset;
5121
5122
5123
5124  unsigned short _cur_column;
5125  signed char _vtable_offset;
5126  char _shortbuf[1];
5127
5128
5129
5130  _IO_lock_t *_lock;
5131
5132  __off64_t _offset;
5133
5134
5135
5136
5137
5138  void *__pad1;
5139  void *__pad2;
5140
5141  int _mode;
5142
5143  char _unused2[15 * sizeof (int) - 2 * sizeof (void *)];
5144
5145};
5146
5147
5148typedef struct _IO_FILE _IO_FILE;
5149
5150
5151struct _IO_FILE_plus;
5152
5153extern struct _IO_FILE_plus _IO_2_1_stdin_;
5154extern struct _IO_FILE_plus _IO_2_1_stdout_;
5155extern struct _IO_FILE_plus _IO_2_1_stderr_;
5156
5157typedef __ssize_t __io_read_fn (void *__cookie, char *__buf, size_t __nbytes);
5158
5159
5160
5161
5162
5163
5164
5165typedef __ssize_t __io_write_fn (void *__cookie, __const char *__buf,
5166     size_t __n);
5167
5168
5169
5170
5171
5172
5173
5174typedef int __io_seek_fn (void *__cookie, __off64_t *__pos, int __w);
5175
5176
5177typedef int __io_close_fn (void *__cookie);
5178
5179extern int __underflow (_IO_FILE *) __attribute__ ((__nothrow__));
5180extern int __uflow (_IO_FILE *) __attribute__ ((__nothrow__));
5181extern int __overflow (_IO_FILE *, int) __attribute__ ((__nothrow__));
5182extern wint_t __wunderflow (_IO_FILE *) __attribute__ ((__nothrow__));
5183extern wint_t __wuflow (_IO_FILE *) __attribute__ ((__nothrow__));
5184extern wint_t __woverflow (_IO_FILE *, wint_t) __attribute__ ((__nothrow__));
5185
5186extern int _IO_getc (_IO_FILE *__fp) __attribute__ ((__nothrow__));
5187extern int _IO_putc (int __c, _IO_FILE *__fp) __attribute__ ((__nothrow__));
5188extern int _IO_feof (_IO_FILE *__fp) __attribute__ ((__nothrow__));
5189extern int _IO_ferror (_IO_FILE *__fp) __attribute__ ((__nothrow__));
5190
5191extern int _IO_peekc_locked (_IO_FILE *__fp) __attribute__ ((__nothrow__));
5192
5193
5194
5195
5196
5197extern void _IO_flockfile (_IO_FILE *) __attribute__ ((__nothrow__));
5198extern void _IO_funlockfile (_IO_FILE *) __attribute__ ((__nothrow__));
5199extern int _IO_ftrylockfile (_IO_FILE *) __attribute__ ((__nothrow__));
5200
5201extern __ssize_t _IO_padn (_IO_FILE *, int, __ssize_t) __attribute__ ((__nothrow__));
5202extern size_t _IO_sgetn (_IO_FILE *, void *, size_t) __attribute__ ((__nothrow__));
5203
5204extern __off64_t _IO_seekoff (_IO_FILE *, __off64_t, int, int) __attribute__ ((__nothrow__));
5205extern __off64_t _IO_seekpos (_IO_FILE *, __off64_t, int) __attribute__ ((__nothrow__));
5206
5207extern void _IO_free_backup_area (_IO_FILE *) __attribute__ ((__nothrow__));
5208
5209
5210typedef _G_fpos_t fpos_t;
5211
5212
5213
5214
5215
5216
5217
5218
5219extern struct _IO_FILE *stdin;
5220extern struct _IO_FILE *stdout;
5221extern struct _IO_FILE *stderr;
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231extern int remove (__const char *__filename) __attribute__ ((__nothrow__));
5232
5233extern int rename (__const char *__old, __const char *__new) __attribute__ ((__nothrow__));
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243extern FILE *tmpfile (void);
5244
5245extern char *tmpnam (char *__s) __attribute__ ((__nothrow__));
5246
5247
5248
5249
5250
5251extern char *tmpnam_r (char *__s) __attribute__ ((__nothrow__));
5252
5253extern char *tempnam (__const char *__dir, __const char *__pfx)
5254     __attribute__ ((__nothrow__)) __attribute__ ((__malloc__));
5255
5256
5257
5258
5259
5260
5261
5262
5263extern int fclose (FILE *__stream);
5264
5265
5266
5267
5268extern int fflush (FILE *__stream);
5269
5270
5271extern int fflush_unlocked (FILE *__stream);
5272
5273
5274
5275
5276
5277
5278
5279extern FILE *fopen (__const char *__restrict __filename,
5280      __const char *__restrict __modes);
5281
5282
5283
5284
5285extern FILE *freopen (__const char *__restrict __filename,
5286        __const char *__restrict __modes,
5287        FILE *__restrict __stream);
5288
5289
5290
5291extern FILE *fdopen (int __fd, __const char *__modes) __attribute__ ((__nothrow__));
5292
5293
5294
5295
5296extern void setbuf (FILE *__restrict __stream, char *__restrict __buf) __attribute__ ((__nothrow__));
5297
5298
5299
5300extern int setvbuf (FILE *__restrict __stream, char *__restrict __buf,
5301      int __modes, size_t __n) __attribute__ ((__nothrow__));
5302
5303
5304
5305
5306
5307extern void setbuffer (FILE *__restrict __stream, char *__restrict __buf,
5308         size_t __size) __attribute__ ((__nothrow__));
5309
5310
5311extern void setlinebuf (FILE *__stream) __attribute__ ((__nothrow__));
5312
5313
5314
5315
5316
5317
5318
5319
5320extern int fprintf (FILE *__restrict __stream,
5321      __const char *__restrict __format, ...);
5322
5323
5324
5325
5326extern int printf (__const char *__restrict __format, ...);
5327
5328extern int sprintf (char *__restrict __s,
5329      __const char *__restrict __format, ...) __attribute__ ((__nothrow__));
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346extern int snprintf (char *__restrict __s, size_t __maxlen,
5347       __const char *__restrict __format, ...)
5348     __attribute__ ((__nothrow__)) __attribute__ ((__format__ (__printf__, 3, 4)));
5349
5350
5351
5352
5353
5354
5355
5356
5357extern int fscanf (FILE *__restrict __stream,
5358     __const char *__restrict __format, ...);
5359
5360
5361
5362
5363extern int scanf (__const char *__restrict __format, ...);
5364
5365extern int sscanf (__const char *__restrict __s,
5366     __const char *__restrict __format, ...) __attribute__ ((__nothrow__));
5367
5368
5369
5370
5371
5372
5373
5374extern int fgetc (FILE *__stream);
5375extern int getc (FILE *__stream);
5376
5377
5378
5379
5380
5381extern int getchar (void);
5382
5383
5384extern int getc_unlocked (FILE *__stream);
5385extern int getchar_unlocked (void);
5386
5387extern int fgetc_unlocked (FILE *__stream);
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399extern int fputc (int __c, FILE *__stream);
5400extern int putc (int __c, FILE *__stream);
5401
5402
5403
5404
5405
5406extern int putchar (int __c);
5407
5408
5409extern int fputc_unlocked (int __c, FILE *__stream);
5410
5411
5412
5413
5414
5415
5416
5417extern int putc_