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