1*4a711beaSLionel Sambuc /* $NetBSD: bzlib_private.h,v 1.3 2012/05/07 00:45:47 wiz Exp $ */ 2*4a711beaSLionel Sambuc 3*4a711beaSLionel Sambuc 4*4a711beaSLionel Sambuc /*-------------------------------------------------------------*/ 5*4a711beaSLionel Sambuc /*--- Private header file for the library. ---*/ 6*4a711beaSLionel Sambuc /*--- bzlib_private.h ---*/ 7*4a711beaSLionel Sambuc /*-------------------------------------------------------------*/ 8*4a711beaSLionel Sambuc 9*4a711beaSLionel Sambuc /* ------------------------------------------------------------------ 10*4a711beaSLionel Sambuc This file is part of bzip2/libbzip2, a program and library for 11*4a711beaSLionel Sambuc lossless, block-sorting data compression. 12*4a711beaSLionel Sambuc 13*4a711beaSLionel Sambuc bzip2/libbzip2 version 1.0.6 of 6 September 2010 14*4a711beaSLionel Sambuc Copyright (C) 1996-2010 Julian Seward <jseward@bzip.org> 15*4a711beaSLionel Sambuc 16*4a711beaSLionel Sambuc Please read the WARNING, DISCLAIMER and PATENTS sections in the 17*4a711beaSLionel Sambuc README file. 18*4a711beaSLionel Sambuc 19*4a711beaSLionel Sambuc This program is released under the terms of the license contained 20*4a711beaSLionel Sambuc in the file LICENSE. 21*4a711beaSLionel Sambuc ------------------------------------------------------------------ */ 22*4a711beaSLionel Sambuc 23*4a711beaSLionel Sambuc 24*4a711beaSLionel Sambuc #ifndef _BZLIB_PRIVATE_H 25*4a711beaSLionel Sambuc #define _BZLIB_PRIVATE_H 26*4a711beaSLionel Sambuc 27*4a711beaSLionel Sambuc #include <stdlib.h> 28*4a711beaSLionel Sambuc 29*4a711beaSLionel Sambuc #ifndef BZ_NO_STDIO 30*4a711beaSLionel Sambuc #include <stdio.h> 31*4a711beaSLionel Sambuc #include <ctype.h> 32*4a711beaSLionel Sambuc #include <string.h> 33*4a711beaSLionel Sambuc #endif 34*4a711beaSLionel Sambuc 35*4a711beaSLionel Sambuc #include "bzlib.h" 36*4a711beaSLionel Sambuc 37*4a711beaSLionel Sambuc 38*4a711beaSLionel Sambuc 39*4a711beaSLionel Sambuc /*-- General stuff. --*/ 40*4a711beaSLionel Sambuc 41*4a711beaSLionel Sambuc #define BZ_VERSION "1.0.6, 6-Sept-2010" 42*4a711beaSLionel Sambuc 43*4a711beaSLionel Sambuc typedef char Char; 44*4a711beaSLionel Sambuc typedef unsigned char Bool; 45*4a711beaSLionel Sambuc typedef unsigned char UChar; 46*4a711beaSLionel Sambuc typedef int Int32; 47*4a711beaSLionel Sambuc typedef unsigned int UInt32; 48*4a711beaSLionel Sambuc typedef short Int16; 49*4a711beaSLionel Sambuc typedef unsigned short UInt16; 50*4a711beaSLionel Sambuc 51*4a711beaSLionel Sambuc #define True ((Bool)1) 52*4a711beaSLionel Sambuc #define False ((Bool)0) 53*4a711beaSLionel Sambuc 54*4a711beaSLionel Sambuc #ifndef __GNUC__ 55*4a711beaSLionel Sambuc #define __inline__ /* */ 56*4a711beaSLionel Sambuc #endif 57*4a711beaSLionel Sambuc 58*4a711beaSLionel Sambuc #ifndef BZ_NO_STDIO 59*4a711beaSLionel Sambuc 60*4a711beaSLionel Sambuc __dead void BZ2_bz__AssertH__fail ( int errcode ); 61*4a711beaSLionel Sambuc #define AssertH(cond,errcode) \ 62*4a711beaSLionel Sambuc { if (!(cond)) BZ2_bz__AssertH__fail ( errcode ); } 63*4a711beaSLionel Sambuc 64*4a711beaSLionel Sambuc #if BZ_DEBUG 65*4a711beaSLionel Sambuc #define AssertD(cond,msg) \ 66*4a711beaSLionel Sambuc { if (!(cond)) { \ 67*4a711beaSLionel Sambuc fprintf ( stderr, \ 68*4a711beaSLionel Sambuc "\n\nlibbzip2(debug build): internal error\n\t%s\n", msg );\ 69*4a711beaSLionel Sambuc exit(1); \ 70*4a711beaSLionel Sambuc }} 71*4a711beaSLionel Sambuc #else 72*4a711beaSLionel Sambuc #define AssertD(cond,msg) /* */ 73*4a711beaSLionel Sambuc #endif 74*4a711beaSLionel Sambuc 75*4a711beaSLionel Sambuc #define VPrintf0(zf) \ 76*4a711beaSLionel Sambuc fprintf(stderr,zf) 77*4a711beaSLionel Sambuc #define VPrintf1(zf,za1) \ 78*4a711beaSLionel Sambuc fprintf(stderr,zf,za1) 79*4a711beaSLionel Sambuc #define VPrintf2(zf,za1,za2) \ 80*4a711beaSLionel Sambuc fprintf(stderr,zf,za1,za2) 81*4a711beaSLionel Sambuc #define VPrintf3(zf,za1,za2,za3) \ 82*4a711beaSLionel Sambuc fprintf(stderr,zf,za1,za2,za3) 83*4a711beaSLionel Sambuc #define VPrintf4(zf,za1,za2,za3,za4) \ 84*4a711beaSLionel Sambuc fprintf(stderr,zf,za1,za2,za3,za4) 85*4a711beaSLionel Sambuc #define VPrintf5(zf,za1,za2,za3,za4,za5) \ 86*4a711beaSLionel Sambuc fprintf(stderr,zf,za1,za2,za3,za4,za5) 87*4a711beaSLionel Sambuc 88*4a711beaSLionel Sambuc #else 89*4a711beaSLionel Sambuc 90*4a711beaSLionel Sambuc extern void bz_internal_error ( int errcode ); 91*4a711beaSLionel Sambuc #define AssertH(cond,errcode) \ 92*4a711beaSLionel Sambuc { if (!(cond)) bz_internal_error ( errcode ); } 93*4a711beaSLionel Sambuc #define AssertD(cond,msg) do { } while (0) 94*4a711beaSLionel Sambuc #define VPrintf0(zf) do { } while (0) 95*4a711beaSLionel Sambuc #define VPrintf1(zf,za1) do { } while (0) 96*4a711beaSLionel Sambuc #define VPrintf2(zf,za1,za2) do { } while (0) 97*4a711beaSLionel Sambuc #define VPrintf3(zf,za1,za2,za3) do { } while (0) 98*4a711beaSLionel Sambuc #define VPrintf4(zf,za1,za2,za3,za4) do { } while (0) 99*4a711beaSLionel Sambuc #define VPrintf5(zf,za1,za2,za3,za4,za5) do { } while (0) 100*4a711beaSLionel Sambuc 101*4a711beaSLionel Sambuc #endif 102*4a711beaSLionel Sambuc 103*4a711beaSLionel Sambuc 104*4a711beaSLionel Sambuc #define BZALLOC(nnn) (strm->bzalloc)(strm->opaque,(nnn),1) 105*4a711beaSLionel Sambuc #define BZFREE(ppp) (strm->bzfree)(strm->opaque,(ppp)) 106*4a711beaSLionel Sambuc 107*4a711beaSLionel Sambuc 108*4a711beaSLionel Sambuc /*-- Header bytes. --*/ 109*4a711beaSLionel Sambuc 110*4a711beaSLionel Sambuc #define BZ_HDR_B 0x42 /* 'B' */ 111*4a711beaSLionel Sambuc #define BZ_HDR_Z 0x5a /* 'Z' */ 112*4a711beaSLionel Sambuc #define BZ_HDR_h 0x68 /* 'h' */ 113*4a711beaSLionel Sambuc #define BZ_HDR_0 0x30 /* '0' */ 114*4a711beaSLionel Sambuc 115*4a711beaSLionel Sambuc /*-- Constants for the back end. --*/ 116*4a711beaSLionel Sambuc 117*4a711beaSLionel Sambuc #define BZ_MAX_ALPHA_SIZE 258 118*4a711beaSLionel Sambuc #define BZ_MAX_CODE_LEN 23 119*4a711beaSLionel Sambuc 120*4a711beaSLionel Sambuc #define BZ_RUNA 0 121*4a711beaSLionel Sambuc #define BZ_RUNB 1 122*4a711beaSLionel Sambuc 123*4a711beaSLionel Sambuc #define BZ_N_GROUPS 6 124*4a711beaSLionel Sambuc #define BZ_G_SIZE 50 125*4a711beaSLionel Sambuc #define BZ_N_ITERS 4 126*4a711beaSLionel Sambuc 127*4a711beaSLionel Sambuc #define BZ_MAX_SELECTORS (2 + (900000 / BZ_G_SIZE)) 128*4a711beaSLionel Sambuc 129*4a711beaSLionel Sambuc 130*4a711beaSLionel Sambuc 131*4a711beaSLionel Sambuc /*-- Stuff for randomising repetitive blocks. --*/ 132*4a711beaSLionel Sambuc 133*4a711beaSLionel Sambuc extern Int32 BZ2_rNums[512]; 134*4a711beaSLionel Sambuc 135*4a711beaSLionel Sambuc #define BZ_RAND_DECLS \ 136*4a711beaSLionel Sambuc Int32 rNToGo; \ 137*4a711beaSLionel Sambuc Int32 rTPos \ 138*4a711beaSLionel Sambuc 139*4a711beaSLionel Sambuc #define BZ_RAND_INIT_MASK \ 140*4a711beaSLionel Sambuc s->rNToGo = 0; \ 141*4a711beaSLionel Sambuc s->rTPos = 0 \ 142*4a711beaSLionel Sambuc 143*4a711beaSLionel Sambuc #define BZ_RAND_MASK ((s->rNToGo == 1) ? 1 : 0) 144*4a711beaSLionel Sambuc 145*4a711beaSLionel Sambuc #define BZ_RAND_UPD_MASK \ 146*4a711beaSLionel Sambuc if (s->rNToGo == 0) { \ 147*4a711beaSLionel Sambuc s->rNToGo = BZ2_rNums[s->rTPos]; \ 148*4a711beaSLionel Sambuc s->rTPos++; \ 149*4a711beaSLionel Sambuc if (s->rTPos == 512) s->rTPos = 0; \ 150*4a711beaSLionel Sambuc } \ 151*4a711beaSLionel Sambuc s->rNToGo--; 152*4a711beaSLionel Sambuc 153*4a711beaSLionel Sambuc 154*4a711beaSLionel Sambuc 155*4a711beaSLionel Sambuc /*-- Stuff for doing CRCs. --*/ 156*4a711beaSLionel Sambuc 157*4a711beaSLionel Sambuc extern UInt32 BZ2_crc32Table[256]; 158*4a711beaSLionel Sambuc 159*4a711beaSLionel Sambuc #define BZ_INITIALISE_CRC(crcVar) \ 160*4a711beaSLionel Sambuc { \ 161*4a711beaSLionel Sambuc crcVar = 0xffffffffL; \ 162*4a711beaSLionel Sambuc } 163*4a711beaSLionel Sambuc 164*4a711beaSLionel Sambuc #define BZ_FINALISE_CRC(crcVar) \ 165*4a711beaSLionel Sambuc { \ 166*4a711beaSLionel Sambuc crcVar = ~(crcVar); \ 167*4a711beaSLionel Sambuc } 168*4a711beaSLionel Sambuc 169*4a711beaSLionel Sambuc #define BZ_UPDATE_CRC(crcVar,cha) \ 170*4a711beaSLionel Sambuc { \ 171*4a711beaSLionel Sambuc crcVar = (crcVar << 8) ^ \ 172*4a711beaSLionel Sambuc BZ2_crc32Table[(crcVar >> 24) ^ \ 173*4a711beaSLionel Sambuc ((UChar)cha)]; \ 174*4a711beaSLionel Sambuc } 175*4a711beaSLionel Sambuc 176*4a711beaSLionel Sambuc 177*4a711beaSLionel Sambuc 178*4a711beaSLionel Sambuc /*-- States and modes for compression. --*/ 179*4a711beaSLionel Sambuc 180*4a711beaSLionel Sambuc #define BZ_M_IDLE 1 181*4a711beaSLionel Sambuc #define BZ_M_RUNNING 2 182*4a711beaSLionel Sambuc #define BZ_M_FLUSHING 3 183*4a711beaSLionel Sambuc #define BZ_M_FINISHING 4 184*4a711beaSLionel Sambuc 185*4a711beaSLionel Sambuc #define BZ_S_OUTPUT 1 186*4a711beaSLionel Sambuc #define BZ_S_INPUT 2 187*4a711beaSLionel Sambuc 188*4a711beaSLionel Sambuc #define BZ_N_RADIX 2 189*4a711beaSLionel Sambuc #define BZ_N_QSORT 12 190*4a711beaSLionel Sambuc #define BZ_N_SHELL 18 191*4a711beaSLionel Sambuc #define BZ_N_OVERSHOOT (BZ_N_RADIX + BZ_N_QSORT + BZ_N_SHELL + 2) 192*4a711beaSLionel Sambuc 193*4a711beaSLionel Sambuc 194*4a711beaSLionel Sambuc 195*4a711beaSLionel Sambuc 196*4a711beaSLionel Sambuc /*-- Structure holding all the compression-side stuff. --*/ 197*4a711beaSLionel Sambuc 198*4a711beaSLionel Sambuc typedef 199*4a711beaSLionel Sambuc struct { 200*4a711beaSLionel Sambuc /* pointer back to the struct bz_stream */ 201*4a711beaSLionel Sambuc bz_stream* strm; 202*4a711beaSLionel Sambuc 203*4a711beaSLionel Sambuc /* mode this stream is in, and whether inputting */ 204*4a711beaSLionel Sambuc /* or outputting data */ 205*4a711beaSLionel Sambuc Int32 mode; 206*4a711beaSLionel Sambuc Int32 state; 207*4a711beaSLionel Sambuc 208*4a711beaSLionel Sambuc /* remembers avail_in when flush/finish requested */ 209*4a711beaSLionel Sambuc UInt32 avail_in_expect; 210*4a711beaSLionel Sambuc 211*4a711beaSLionel Sambuc /* for doing the block sorting */ 212*4a711beaSLionel Sambuc UInt32* arr1; 213*4a711beaSLionel Sambuc UInt32* arr2; 214*4a711beaSLionel Sambuc UInt32* ftab; 215*4a711beaSLionel Sambuc Int32 origPtr; 216*4a711beaSLionel Sambuc 217*4a711beaSLionel Sambuc /* aliases for arr1 and arr2 */ 218*4a711beaSLionel Sambuc UInt32* ptr; 219*4a711beaSLionel Sambuc UChar* block; 220*4a711beaSLionel Sambuc UInt16* mtfv; 221*4a711beaSLionel Sambuc UChar* zbits; 222*4a711beaSLionel Sambuc 223*4a711beaSLionel Sambuc /* for deciding when to use the fallback sorting algorithm */ 224*4a711beaSLionel Sambuc Int32 workFactor; 225*4a711beaSLionel Sambuc 226*4a711beaSLionel Sambuc /* run-length-encoding of the input */ 227*4a711beaSLionel Sambuc UInt32 state_in_ch; 228*4a711beaSLionel Sambuc Int32 state_in_len; 229*4a711beaSLionel Sambuc BZ_RAND_DECLS; 230*4a711beaSLionel Sambuc 231*4a711beaSLionel Sambuc /* input and output limits and current posns */ 232*4a711beaSLionel Sambuc Int32 nblock; 233*4a711beaSLionel Sambuc Int32 nblockMAX; 234*4a711beaSLionel Sambuc Int32 numZ; 235*4a711beaSLionel Sambuc Int32 state_out_pos; 236*4a711beaSLionel Sambuc 237*4a711beaSLionel Sambuc /* map of bytes used in block */ 238*4a711beaSLionel Sambuc Int32 nInUse; 239*4a711beaSLionel Sambuc Bool inUse[256]; 240*4a711beaSLionel Sambuc UChar unseqToSeq[256]; 241*4a711beaSLionel Sambuc 242*4a711beaSLionel Sambuc /* the buffer for bit stream creation */ 243*4a711beaSLionel Sambuc UInt32 bsBuff; 244*4a711beaSLionel Sambuc Int32 bsLive; 245*4a711beaSLionel Sambuc 246*4a711beaSLionel Sambuc /* block and combined CRCs */ 247*4a711beaSLionel Sambuc UInt32 blockCRC; 248*4a711beaSLionel Sambuc UInt32 combinedCRC; 249*4a711beaSLionel Sambuc 250*4a711beaSLionel Sambuc /* misc administratium */ 251*4a711beaSLionel Sambuc Int32 verbosity; 252*4a711beaSLionel Sambuc Int32 blockNo; 253*4a711beaSLionel Sambuc Int32 blockSize100k; 254*4a711beaSLionel Sambuc 255*4a711beaSLionel Sambuc /* stuff for coding the MTF values */ 256*4a711beaSLionel Sambuc Int32 nMTF; 257*4a711beaSLionel Sambuc Int32 mtfFreq [BZ_MAX_ALPHA_SIZE]; 258*4a711beaSLionel Sambuc UChar selector [BZ_MAX_SELECTORS]; 259*4a711beaSLionel Sambuc UChar selectorMtf[BZ_MAX_SELECTORS]; 260*4a711beaSLionel Sambuc 261*4a711beaSLionel Sambuc UChar len [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE]; 262*4a711beaSLionel Sambuc Int32 code [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE]; 263*4a711beaSLionel Sambuc Int32 rfreq [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE]; 264*4a711beaSLionel Sambuc /* second dimension: only 3 needed; 4 makes index calculations faster */ 265*4a711beaSLionel Sambuc UInt32 len_pack[BZ_MAX_ALPHA_SIZE][4]; 266*4a711beaSLionel Sambuc 267*4a711beaSLionel Sambuc } 268*4a711beaSLionel Sambuc EState; 269*4a711beaSLionel Sambuc 270*4a711beaSLionel Sambuc 271*4a711beaSLionel Sambuc 272*4a711beaSLionel Sambuc /*-- externs for compression. --*/ 273*4a711beaSLionel Sambuc 274*4a711beaSLionel Sambuc extern void 275*4a711beaSLionel Sambuc BZ2_blockSort ( EState* ); 276*4a711beaSLionel Sambuc 277*4a711beaSLionel Sambuc extern void 278*4a711beaSLionel Sambuc BZ2_compressBlock ( EState*, Bool ); 279*4a711beaSLionel Sambuc 280*4a711beaSLionel Sambuc extern void 281*4a711beaSLionel Sambuc BZ2_bsInitWrite ( EState* ); 282*4a711beaSLionel Sambuc 283*4a711beaSLionel Sambuc extern void 284*4a711beaSLionel Sambuc BZ2_hbAssignCodes ( Int32*, UChar*, Int32, Int32, Int32 ); 285*4a711beaSLionel Sambuc 286*4a711beaSLionel Sambuc extern void 287*4a711beaSLionel Sambuc BZ2_hbMakeCodeLengths ( UChar*, Int32*, Int32, Int32 ); 288*4a711beaSLionel Sambuc 289*4a711beaSLionel Sambuc 290*4a711beaSLionel Sambuc 291*4a711beaSLionel Sambuc /*-- states for decompression. --*/ 292*4a711beaSLionel Sambuc 293*4a711beaSLionel Sambuc #define BZ_X_IDLE 1 294*4a711beaSLionel Sambuc #define BZ_X_OUTPUT 2 295*4a711beaSLionel Sambuc 296*4a711beaSLionel Sambuc #define BZ_X_MAGIC_1 10 297*4a711beaSLionel Sambuc #define BZ_X_MAGIC_2 11 298*4a711beaSLionel Sambuc #define BZ_X_MAGIC_3 12 299*4a711beaSLionel Sambuc #define BZ_X_MAGIC_4 13 300*4a711beaSLionel Sambuc #define BZ_X_BLKHDR_1 14 301*4a711beaSLionel Sambuc #define BZ_X_BLKHDR_2 15 302*4a711beaSLionel Sambuc #define BZ_X_BLKHDR_3 16 303*4a711beaSLionel Sambuc #define BZ_X_BLKHDR_4 17 304*4a711beaSLionel Sambuc #define BZ_X_BLKHDR_5 18 305*4a711beaSLionel Sambuc #define BZ_X_BLKHDR_6 19 306*4a711beaSLionel Sambuc #define BZ_X_BCRC_1 20 307*4a711beaSLionel Sambuc #define BZ_X_BCRC_2 21 308*4a711beaSLionel Sambuc #define BZ_X_BCRC_3 22 309*4a711beaSLionel Sambuc #define BZ_X_BCRC_4 23 310*4a711beaSLionel Sambuc #define BZ_X_RANDBIT 24 311*4a711beaSLionel Sambuc #define BZ_X_ORIGPTR_1 25 312*4a711beaSLionel Sambuc #define BZ_X_ORIGPTR_2 26 313*4a711beaSLionel Sambuc #define BZ_X_ORIGPTR_3 27 314*4a711beaSLionel Sambuc #define BZ_X_MAPPING_1 28 315*4a711beaSLionel Sambuc #define BZ_X_MAPPING_2 29 316*4a711beaSLionel Sambuc #define BZ_X_SELECTOR_1 30 317*4a711beaSLionel Sambuc #define BZ_X_SELECTOR_2 31 318*4a711beaSLionel Sambuc #define BZ_X_SELECTOR_3 32 319*4a711beaSLionel Sambuc #define BZ_X_CODING_1 33 320*4a711beaSLionel Sambuc #define BZ_X_CODING_2 34 321*4a711beaSLionel Sambuc #define BZ_X_CODING_3 35 322*4a711beaSLionel Sambuc #define BZ_X_MTF_1 36 323*4a711beaSLionel Sambuc #define BZ_X_MTF_2 37 324*4a711beaSLionel Sambuc #define BZ_X_MTF_3 38 325*4a711beaSLionel Sambuc #define BZ_X_MTF_4 39 326*4a711beaSLionel Sambuc #define BZ_X_MTF_5 40 327*4a711beaSLionel Sambuc #define BZ_X_MTF_6 41 328*4a711beaSLionel Sambuc #define BZ_X_ENDHDR_2 42 329*4a711beaSLionel Sambuc #define BZ_X_ENDHDR_3 43 330*4a711beaSLionel Sambuc #define BZ_X_ENDHDR_4 44 331*4a711beaSLionel Sambuc #define BZ_X_ENDHDR_5 45 332*4a711beaSLionel Sambuc #define BZ_X_ENDHDR_6 46 333*4a711beaSLionel Sambuc #define BZ_X_CCRC_1 47 334*4a711beaSLionel Sambuc #define BZ_X_CCRC_2 48 335*4a711beaSLionel Sambuc #define BZ_X_CCRC_3 49 336*4a711beaSLionel Sambuc #define BZ_X_CCRC_4 50 337*4a711beaSLionel Sambuc 338*4a711beaSLionel Sambuc 339*4a711beaSLionel Sambuc 340*4a711beaSLionel Sambuc /*-- Constants for the fast MTF decoder. --*/ 341*4a711beaSLionel Sambuc 342*4a711beaSLionel Sambuc #define MTFA_SIZE 4096 343*4a711beaSLionel Sambuc #define MTFL_SIZE 16 344*4a711beaSLionel Sambuc 345*4a711beaSLionel Sambuc 346*4a711beaSLionel Sambuc 347*4a711beaSLionel Sambuc /*-- Structure holding all the decompression-side stuff. --*/ 348*4a711beaSLionel Sambuc 349*4a711beaSLionel Sambuc typedef 350*4a711beaSLionel Sambuc struct { 351*4a711beaSLionel Sambuc /* pointer back to the struct bz_stream */ 352*4a711beaSLionel Sambuc bz_stream* strm; 353*4a711beaSLionel Sambuc 354*4a711beaSLionel Sambuc /* state indicator for this stream */ 355*4a711beaSLionel Sambuc Int32 state; 356*4a711beaSLionel Sambuc 357*4a711beaSLionel Sambuc /* for doing the final run-length decoding */ 358*4a711beaSLionel Sambuc UChar state_out_ch; 359*4a711beaSLionel Sambuc Int32 state_out_len; 360*4a711beaSLionel Sambuc Bool blockRandomised; 361*4a711beaSLionel Sambuc BZ_RAND_DECLS; 362*4a711beaSLionel Sambuc 363*4a711beaSLionel Sambuc /* the buffer for bit stream reading */ 364*4a711beaSLionel Sambuc UInt32 bsBuff; 365*4a711beaSLionel Sambuc Int32 bsLive; 366*4a711beaSLionel Sambuc 367*4a711beaSLionel Sambuc /* misc administratium */ 368*4a711beaSLionel Sambuc Int32 blockSize100k; 369*4a711beaSLionel Sambuc Bool smallDecompress; 370*4a711beaSLionel Sambuc Int32 currBlockNo; 371*4a711beaSLionel Sambuc Int32 verbosity; 372*4a711beaSLionel Sambuc 373*4a711beaSLionel Sambuc /* for undoing the Burrows-Wheeler transform */ 374*4a711beaSLionel Sambuc Int32 origPtr; 375*4a711beaSLionel Sambuc UInt32 tPos; 376*4a711beaSLionel Sambuc Int32 k0; 377*4a711beaSLionel Sambuc Int32 unzftab[256]; 378*4a711beaSLionel Sambuc Int32 nblock_used; 379*4a711beaSLionel Sambuc Int32 cftab[257]; 380*4a711beaSLionel Sambuc Int32 cftabCopy[257]; 381*4a711beaSLionel Sambuc 382*4a711beaSLionel Sambuc /* for undoing the Burrows-Wheeler transform (FAST) */ 383*4a711beaSLionel Sambuc UInt32 *tt; 384*4a711beaSLionel Sambuc 385*4a711beaSLionel Sambuc /* for undoing the Burrows-Wheeler transform (SMALL) */ 386*4a711beaSLionel Sambuc UInt16 *ll16; 387*4a711beaSLionel Sambuc UChar *ll4; 388*4a711beaSLionel Sambuc 389*4a711beaSLionel Sambuc /* stored and calculated CRCs */ 390*4a711beaSLionel Sambuc UInt32 storedBlockCRC; 391*4a711beaSLionel Sambuc UInt32 storedCombinedCRC; 392*4a711beaSLionel Sambuc UInt32 calculatedBlockCRC; 393*4a711beaSLionel Sambuc UInt32 calculatedCombinedCRC; 394*4a711beaSLionel Sambuc 395*4a711beaSLionel Sambuc /* map of bytes used in block */ 396*4a711beaSLionel Sambuc Int32 nInUse; 397*4a711beaSLionel Sambuc Bool inUse[256]; 398*4a711beaSLionel Sambuc Bool inUse16[16]; 399*4a711beaSLionel Sambuc UChar seqToUnseq[256]; 400*4a711beaSLionel Sambuc 401*4a711beaSLionel Sambuc /* for decoding the MTF values */ 402*4a711beaSLionel Sambuc UChar mtfa [MTFA_SIZE]; 403*4a711beaSLionel Sambuc Int32 mtfbase[256 / MTFL_SIZE]; 404*4a711beaSLionel Sambuc UChar selector [BZ_MAX_SELECTORS]; 405*4a711beaSLionel Sambuc UChar selectorMtf[BZ_MAX_SELECTORS]; 406*4a711beaSLionel Sambuc UChar len [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE]; 407*4a711beaSLionel Sambuc 408*4a711beaSLionel Sambuc Int32 limit [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE]; 409*4a711beaSLionel Sambuc Int32 base [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE]; 410*4a711beaSLionel Sambuc Int32 perm [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE]; 411*4a711beaSLionel Sambuc Int32 minLens[BZ_N_GROUPS]; 412*4a711beaSLionel Sambuc 413*4a711beaSLionel Sambuc /* save area for scalars in the main decompress code */ 414*4a711beaSLionel Sambuc Int32 save_i; 415*4a711beaSLionel Sambuc Int32 save_j; 416*4a711beaSLionel Sambuc Int32 save_t; 417*4a711beaSLionel Sambuc Int32 save_alphaSize; 418*4a711beaSLionel Sambuc Int32 save_nGroups; 419*4a711beaSLionel Sambuc Int32 save_nSelectors; 420*4a711beaSLionel Sambuc Int32 save_EOB; 421*4a711beaSLionel Sambuc Int32 save_groupNo; 422*4a711beaSLionel Sambuc Int32 save_groupPos; 423*4a711beaSLionel Sambuc Int32 save_nextSym; 424*4a711beaSLionel Sambuc Int32 save_nblockMAX; 425*4a711beaSLionel Sambuc Int32 save_nblock; 426*4a711beaSLionel Sambuc Int32 save_es; 427*4a711beaSLionel Sambuc Int32 save_N; 428*4a711beaSLionel Sambuc Int32 save_curr; 429*4a711beaSLionel Sambuc Int32 save_zt; 430*4a711beaSLionel Sambuc Int32 save_zn; 431*4a711beaSLionel Sambuc Int32 save_zvec; 432*4a711beaSLionel Sambuc Int32 save_zj; 433*4a711beaSLionel Sambuc Int32 save_gSel; 434*4a711beaSLionel Sambuc Int32 save_gMinlen; 435*4a711beaSLionel Sambuc Int32* save_gLimit; 436*4a711beaSLionel Sambuc Int32* save_gBase; 437*4a711beaSLionel Sambuc Int32* save_gPerm; 438*4a711beaSLionel Sambuc 439*4a711beaSLionel Sambuc } 440*4a711beaSLionel Sambuc DState; 441*4a711beaSLionel Sambuc 442*4a711beaSLionel Sambuc 443*4a711beaSLionel Sambuc 444*4a711beaSLionel Sambuc /*-- Macros for decompression. --*/ 445*4a711beaSLionel Sambuc 446*4a711beaSLionel Sambuc #define BZ_GET_FAST(cccc) \ 447*4a711beaSLionel Sambuc /* c_tPos is unsigned, hence test < 0 is pointless. */ \ 448*4a711beaSLionel Sambuc if (s->tPos >= (UInt32)100000 * (UInt32)s->blockSize100k) return True; \ 449*4a711beaSLionel Sambuc s->tPos = s->tt[s->tPos]; \ 450*4a711beaSLionel Sambuc cccc = (UChar)(s->tPos & 0xff); \ 451*4a711beaSLionel Sambuc s->tPos >>= 8; 452*4a711beaSLionel Sambuc 453*4a711beaSLionel Sambuc #define BZ_GET_FAST_C(cccc) \ 454*4a711beaSLionel Sambuc /* c_tPos is unsigned, hence test < 0 is pointless. */ \ 455*4a711beaSLionel Sambuc if (c_tPos >= (UInt32)100000 * (UInt32)ro_blockSize100k) return True; \ 456*4a711beaSLionel Sambuc c_tPos = c_tt[c_tPos]; \ 457*4a711beaSLionel Sambuc cccc = (UChar)(c_tPos & 0xff); \ 458*4a711beaSLionel Sambuc c_tPos >>= 8; 459*4a711beaSLionel Sambuc 460*4a711beaSLionel Sambuc #define SET_LL4(i,n) \ 461*4a711beaSLionel Sambuc { if (((i) & 0x1) == 0) \ 462*4a711beaSLionel Sambuc s->ll4[(i) >> 1] = (s->ll4[(i) >> 1] & 0xf0) | (n); else \ 463*4a711beaSLionel Sambuc s->ll4[(i) >> 1] = (s->ll4[(i) >> 1] & 0x0f) | ((n) << 4); \ 464*4a711beaSLionel Sambuc } 465*4a711beaSLionel Sambuc 466*4a711beaSLionel Sambuc #define GET_LL4(i) \ 467*4a711beaSLionel Sambuc ((((UInt32)(s->ll4[(i) >> 1])) >> (((i) << 2) & 0x4)) & 0xF) 468*4a711beaSLionel Sambuc 469*4a711beaSLionel Sambuc #define SET_LL(i,n) \ 470*4a711beaSLionel Sambuc { s->ll16[i] = (UInt16)(n & 0x0000ffff); \ 471*4a711beaSLionel Sambuc SET_LL4(i, n >> 16); \ 472*4a711beaSLionel Sambuc } 473*4a711beaSLionel Sambuc 474*4a711beaSLionel Sambuc #define GET_LL(i) \ 475*4a711beaSLionel Sambuc (((UInt32)s->ll16[i]) | (GET_LL4(i) << 16)) 476*4a711beaSLionel Sambuc 477*4a711beaSLionel Sambuc #define BZ_GET_SMALL(cccc) \ 478*4a711beaSLionel Sambuc /* c_tPos is unsigned, hence test < 0 is pointless. */ \ 479*4a711beaSLionel Sambuc if (s->tPos >= (UInt32)100000 * (UInt32)s->blockSize100k) return True; \ 480*4a711beaSLionel Sambuc cccc = BZ2_indexIntoF ( s->tPos, s->cftab ); \ 481*4a711beaSLionel Sambuc s->tPos = GET_LL(s->tPos); 482*4a711beaSLionel Sambuc 483*4a711beaSLionel Sambuc 484*4a711beaSLionel Sambuc /*-- externs for decompression. --*/ 485*4a711beaSLionel Sambuc 486*4a711beaSLionel Sambuc extern Int32 487*4a711beaSLionel Sambuc BZ2_indexIntoF ( Int32, Int32* ); 488*4a711beaSLionel Sambuc 489*4a711beaSLionel Sambuc extern Int32 490*4a711beaSLionel Sambuc BZ2_decompress ( DState* ); 491*4a711beaSLionel Sambuc 492*4a711beaSLionel Sambuc extern void 493*4a711beaSLionel Sambuc BZ2_hbCreateDecodeTables ( Int32*, Int32*, Int32*, UChar*, 494*4a711beaSLionel Sambuc Int32, Int32, Int32 ); 495*4a711beaSLionel Sambuc 496*4a711beaSLionel Sambuc 497*4a711beaSLionel Sambuc #endif 498*4a711beaSLionel Sambuc 499*4a711beaSLionel Sambuc 500*4a711beaSLionel Sambuc /*-- BZ_NO_STDIO seems to make NULL disappear on some platforms. --*/ 501*4a711beaSLionel Sambuc 502*4a711beaSLionel Sambuc #ifdef BZ_NO_STDIO 503*4a711beaSLionel Sambuc #ifndef NULL 504*4a711beaSLionel Sambuc #define NULL 0 505*4a711beaSLionel Sambuc #endif 506*4a711beaSLionel Sambuc #endif 507*4a711beaSLionel Sambuc 508*4a711beaSLionel Sambuc 509*4a711beaSLionel Sambuc /*-------------------------------------------------------------*/ 510*4a711beaSLionel Sambuc /*--- end bzlib_private.h ---*/ 511*4a711beaSLionel Sambuc /*-------------------------------------------------------------*/ 512