modules/libbz2/src/bzlib_private.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/modules/libbz2/src/bzlib_private.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,503 @@
     1.4 +
     1.5 +/*-------------------------------------------------------------*/
     1.6 +/*--- Private header file for the library.                  ---*/
     1.7 +/*---                                       bzlib_private.h ---*/
     1.8 +/*-------------------------------------------------------------*/
     1.9 +
    1.10 +/* ------------------------------------------------------------------
    1.11 +   This file is part of bzip2/libbzip2, a program and library for
    1.12 +   lossless, block-sorting data compression.
    1.13 +
    1.14 +   bzip2/libbzip2 version 1.0.4 of 20 December 2006
    1.15 +   Copyright (C) 1996-2006 Julian Seward <jseward@bzip.org>
    1.16 +
    1.17 +   Please read the WARNING, DISCLAIMER and PATENTS sections in the 
    1.18 +   README file.
    1.19 +
    1.20 +   This program is released under the terms of the license contained
    1.21 +   in the file LICENSE.
    1.22 +   ------------------------------------------------------------------ */
    1.23 +
    1.24 +
    1.25 +#ifndef _BZLIB_PRIVATE_H
    1.26 +#define _BZLIB_PRIVATE_H
    1.27 +
    1.28 +#include <stdlib.h>
    1.29 +
    1.30 +#ifndef BZ_NO_STDIO
    1.31 +#include <stdio.h>
    1.32 +#include <ctype.h>
    1.33 +#include <string.h>
    1.34 +#endif
    1.35 +
    1.36 +#include "bzlib.h"
    1.37 +
    1.38 +
    1.39 +
    1.40 +/*-- General stuff. --*/
    1.41 +
    1.42 +#define BZ_VERSION  "1.0.4, 20-Dec-2006"
    1.43 +
    1.44 +typedef char            Char;
    1.45 +typedef unsigned char   Bool;
    1.46 +typedef unsigned char   UChar;
    1.47 +typedef int             Int32;
    1.48 +typedef unsigned int    UInt32;
    1.49 +typedef short           Int16;
    1.50 +typedef unsigned short  UInt16;
    1.51 +
    1.52 +#define True  ((Bool)1)
    1.53 +#define False ((Bool)0)
    1.54 +
    1.55 +#ifndef __GNUC__
    1.56 +#define __inline__  /* */
    1.57 +#endif 
    1.58 +
    1.59 +#ifndef BZ_NO_STDIO
    1.60 +
    1.61 +extern void BZ2_bz__AssertH__fail ( int errcode );
    1.62 +#define AssertH(cond,errcode) \
    1.63 +   { if (!(cond)) BZ2_bz__AssertH__fail ( errcode ); }
    1.64 +
    1.65 +#if BZ_DEBUG
    1.66 +#define AssertD(cond,msg) \
    1.67 +   { if (!(cond)) {       \
    1.68 +      fprintf ( stderr,   \
    1.69 +        "\n\nlibbzip2(debug build): internal error\n\t%s\n", msg );\
    1.70 +      exit(1); \
    1.71 +   }}
    1.72 +#else
    1.73 +#define AssertD(cond,msg) /* */
    1.74 +#endif
    1.75 +
    1.76 +#define VPrintf0(zf) \
    1.77 +   fprintf(stderr,zf)
    1.78 +#define VPrintf1(zf,za1) \
    1.79 +   fprintf(stderr,zf,za1)
    1.80 +#define VPrintf2(zf,za1,za2) \
    1.81 +   fprintf(stderr,zf,za1,za2)
    1.82 +#define VPrintf3(zf,za1,za2,za3) \
    1.83 +   fprintf(stderr,zf,za1,za2,za3)
    1.84 +#define VPrintf4(zf,za1,za2,za3,za4) \
    1.85 +   fprintf(stderr,zf,za1,za2,za3,za4)
    1.86 +#define VPrintf5(zf,za1,za2,za3,za4,za5) \
    1.87 +   fprintf(stderr,zf,za1,za2,za3,za4,za5)
    1.88 +
    1.89 +#else
    1.90 +
    1.91 +extern void bz_internal_error ( int errcode );
    1.92 +#define AssertH(cond,errcode) \
    1.93 +   { if (!(cond)) bz_internal_error ( errcode ); }
    1.94 +#define AssertD(cond,msg)                do { } while (0)
    1.95 +#define VPrintf0(zf)                     do { } while (0)
    1.96 +#define VPrintf1(zf,za1)                 do { } while (0)
    1.97 +#define VPrintf2(zf,za1,za2)             do { } while (0)
    1.98 +#define VPrintf3(zf,za1,za2,za3)         do { } while (0)
    1.99 +#define VPrintf4(zf,za1,za2,za3,za4)     do { } while (0)
   1.100 +#define VPrintf5(zf,za1,za2,za3,za4,za5) do { } while (0)
   1.101 +
   1.102 +#endif
   1.103 +
   1.104 +
   1.105 +#define BZALLOC(nnn) (strm->bzalloc)(strm->opaque,(nnn),1)
   1.106 +#define BZFREE(ppp)  (strm->bzfree)(strm->opaque,(ppp))
   1.107 +
   1.108 +
   1.109 +/*-- Header bytes. --*/
   1.110 +
   1.111 +#define BZ_HDR_B 0x42   /* 'B' */
   1.112 +#define BZ_HDR_Z 0x5a   /* 'Z' */
   1.113 +#define BZ_HDR_h 0x68   /* 'h' */
   1.114 +#define BZ_HDR_0 0x30   /* '0' */
   1.115 +  
   1.116 +/*-- Constants for the back end. --*/
   1.117 +
   1.118 +#define BZ_MAX_ALPHA_SIZE 258
   1.119 +#define BZ_MAX_CODE_LEN    23
   1.120 +
   1.121 +#define BZ_RUNA 0
   1.122 +#define BZ_RUNB 1
   1.123 +
   1.124 +#define BZ_N_GROUPS 6
   1.125 +#define BZ_G_SIZE   50
   1.126 +#define BZ_N_ITERS  4
   1.127 +
   1.128 +#define BZ_MAX_SELECTORS (2 + (900000 / BZ_G_SIZE))
   1.129 +
   1.130 +
   1.131 +
   1.132 +/*-- Stuff for randomising repetitive blocks. --*/
   1.133 +
   1.134 +extern Int32 BZ2_rNums[512];
   1.135 +
   1.136 +#define BZ_RAND_DECLS                          \
   1.137 +   Int32 rNToGo;                               \
   1.138 +   Int32 rTPos                                 \
   1.139 +
   1.140 +#define BZ_RAND_INIT_MASK                      \
   1.141 +   s->rNToGo = 0;                              \
   1.142 +   s->rTPos  = 0                               \
   1.143 +
   1.144 +#define BZ_RAND_MASK ((s->rNToGo == 1) ? 1 : 0)
   1.145 +
   1.146 +#define BZ_RAND_UPD_MASK                       \
   1.147 +   if (s->rNToGo == 0) {                       \
   1.148 +      s->rNToGo = BZ2_rNums[s->rTPos];         \
   1.149 +      s->rTPos++;                              \
   1.150 +      if (s->rTPos == 512) s->rTPos = 0;       \
   1.151 +   }                                           \
   1.152 +   s->rNToGo--;
   1.153 +
   1.154 +
   1.155 +
   1.156 +/*-- Stuff for doing CRCs. --*/
   1.157 +
   1.158 +extern UInt32 BZ2_crc32Table[256];
   1.159 +
   1.160 +#define BZ_INITIALISE_CRC(crcVar)              \
   1.161 +{                                              \
   1.162 +   crcVar = 0xffffffffL;                       \
   1.163 +}
   1.164 +
   1.165 +#define BZ_FINALISE_CRC(crcVar)                \
   1.166 +{                                              \
   1.167 +   crcVar = ~(crcVar);                         \
   1.168 +}
   1.169 +
   1.170 +#define BZ_UPDATE_CRC(crcVar,cha)              \
   1.171 +{                                              \
   1.172 +   crcVar = (crcVar << 8) ^                    \
   1.173 +            BZ2_crc32Table[(crcVar >> 24) ^    \
   1.174 +                           ((UChar)cha)];      \
   1.175 +}
   1.176 +
   1.177 +
   1.178 +
   1.179 +/*-- States and modes for compression. --*/
   1.180 +
   1.181 +#define BZ_M_IDLE      1
   1.182 +#define BZ_M_RUNNING   2
   1.183 +#define BZ_M_FLUSHING  3
   1.184 +#define BZ_M_FINISHING 4
   1.185 +
   1.186 +#define BZ_S_OUTPUT    1
   1.187 +#define BZ_S_INPUT     2
   1.188 +
   1.189 +#define BZ_N_RADIX 2
   1.190 +#define BZ_N_QSORT 12
   1.191 +#define BZ_N_SHELL 18
   1.192 +#define BZ_N_OVERSHOOT (BZ_N_RADIX + BZ_N_QSORT + BZ_N_SHELL + 2)
   1.193 +
   1.194 +
   1.195 +
   1.196 +
   1.197 +/*-- Structure holding all the compression-side stuff. --*/
   1.198 +
   1.199 +typedef
   1.200 +   struct {
   1.201 +      /* pointer back to the struct bz_stream */
   1.202 +      bz_stream* strm;
   1.203 +
   1.204 +      /* mode this stream is in, and whether inputting */
   1.205 +      /* or outputting data */
   1.206 +      Int32    mode;
   1.207 +      Int32    state;
   1.208 +
   1.209 +      /* remembers avail_in when flush/finish requested */
   1.210 +      UInt32   avail_in_expect;
   1.211 +
   1.212 +      /* for doing the block sorting */
   1.213 +      UInt32*  arr1;
   1.214 +      UInt32*  arr2;
   1.215 +      UInt32*  ftab;
   1.216 +      Int32    origPtr;
   1.217 +
   1.218 +      /* aliases for arr1 and arr2 */
   1.219 +      UInt32*  ptr;
   1.220 +      UChar*   block;
   1.221 +      UInt16*  mtfv;
   1.222 +      UChar*   zbits;
   1.223 +
   1.224 +      /* for deciding when to use the fallback sorting algorithm */
   1.225 +      Int32    workFactor;
   1.226 +
   1.227 +      /* run-length-encoding of the input */
   1.228 +      UInt32   state_in_ch;
   1.229 +      Int32    state_in_len;
   1.230 +      BZ_RAND_DECLS;
   1.231 +
   1.232 +      /* input and output limits and current posns */
   1.233 +      Int32    nblock;
   1.234 +      Int32    nblockMAX;
   1.235 +      Int32    numZ;
   1.236 +      Int32    state_out_pos;
   1.237 +
   1.238 +      /* map of bytes used in block */
   1.239 +      Int32    nInUse;
   1.240 +      Bool     inUse[256];
   1.241 +      UChar    unseqToSeq[256];
   1.242 +
   1.243 +      /* the buffer for bit stream creation */
   1.244 +      UInt32   bsBuff;
   1.245 +      Int32    bsLive;
   1.246 +
   1.247 +      /* block and combined CRCs */
   1.248 +      UInt32   blockCRC;
   1.249 +      UInt32   combinedCRC;
   1.250 +
   1.251 +      /* misc administratium */
   1.252 +      Int32    verbosity;
   1.253 +      Int32    blockNo;
   1.254 +      Int32    blockSize100k;
   1.255 +
   1.256 +      /* stuff for coding the MTF values */
   1.257 +      Int32    nMTF;
   1.258 +      Int32    mtfFreq    [BZ_MAX_ALPHA_SIZE];
   1.259 +      UChar    selector   [BZ_MAX_SELECTORS];
   1.260 +      UChar    selectorMtf[BZ_MAX_SELECTORS];
   1.261 +
   1.262 +      UChar    len     [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
   1.263 +      Int32    code    [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
   1.264 +      Int32    rfreq   [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
   1.265 +      /* second dimension: only 3 needed; 4 makes index calculations faster */
   1.266 +      UInt32   len_pack[BZ_MAX_ALPHA_SIZE][4];
   1.267 +
   1.268 +   }
   1.269 +   EState;
   1.270 +
   1.271 +
   1.272 +
   1.273 +/*-- externs for compression. --*/
   1.274 +
   1.275 +extern void 
   1.276 +BZ2_blockSort ( EState* );
   1.277 +
   1.278 +extern void 
   1.279 +BZ2_compressBlock ( EState*, Bool );
   1.280 +
   1.281 +extern void 
   1.282 +BZ2_bsInitWrite ( EState* );
   1.283 +
   1.284 +extern void 
   1.285 +BZ2_hbAssignCodes ( Int32*, UChar*, Int32, Int32, Int32 );
   1.286 +
   1.287 +extern void 
   1.288 +BZ2_hbMakeCodeLengths ( UChar*, Int32*, Int32, Int32 );
   1.289 +
   1.290 +
   1.291 +
   1.292 +/*-- states for decompression. --*/
   1.293 +
   1.294 +#define BZ_X_IDLE        1
   1.295 +#define BZ_X_OUTPUT      2
   1.296 +
   1.297 +#define BZ_X_MAGIC_1     10
   1.298 +#define BZ_X_MAGIC_2     11
   1.299 +#define BZ_X_MAGIC_3     12
   1.300 +#define BZ_X_MAGIC_4     13
   1.301 +#define BZ_X_BLKHDR_1    14
   1.302 +#define BZ_X_BLKHDR_2    15
   1.303 +#define BZ_X_BLKHDR_3    16
   1.304 +#define BZ_X_BLKHDR_4    17
   1.305 +#define BZ_X_BLKHDR_5    18
   1.306 +#define BZ_X_BLKHDR_6    19
   1.307 +#define BZ_X_BCRC_1      20
   1.308 +#define BZ_X_BCRC_2      21
   1.309 +#define BZ_X_BCRC_3      22
   1.310 +#define BZ_X_BCRC_4      23
   1.311 +#define BZ_X_RANDBIT     24
   1.312 +#define BZ_X_ORIGPTR_1   25
   1.313 +#define BZ_X_ORIGPTR_2   26
   1.314 +#define BZ_X_ORIGPTR_3   27
   1.315 +#define BZ_X_MAPPING_1   28
   1.316 +#define BZ_X_MAPPING_2   29
   1.317 +#define BZ_X_SELECTOR_1  30
   1.318 +#define BZ_X_SELECTOR_2  31
   1.319 +#define BZ_X_SELECTOR_3  32
   1.320 +#define BZ_X_CODING_1    33
   1.321 +#define BZ_X_CODING_2    34
   1.322 +#define BZ_X_CODING_3    35
   1.323 +#define BZ_X_MTF_1       36
   1.324 +#define BZ_X_MTF_2       37
   1.325 +#define BZ_X_MTF_3       38
   1.326 +#define BZ_X_MTF_4       39
   1.327 +#define BZ_X_MTF_5       40
   1.328 +#define BZ_X_MTF_6       41
   1.329 +#define BZ_X_ENDHDR_2    42
   1.330 +#define BZ_X_ENDHDR_3    43
   1.331 +#define BZ_X_ENDHDR_4    44
   1.332 +#define BZ_X_ENDHDR_5    45
   1.333 +#define BZ_X_ENDHDR_6    46
   1.334 +#define BZ_X_CCRC_1      47
   1.335 +#define BZ_X_CCRC_2      48
   1.336 +#define BZ_X_CCRC_3      49
   1.337 +#define BZ_X_CCRC_4      50
   1.338 +
   1.339 +
   1.340 +
   1.341 +/*-- Constants for the fast MTF decoder. --*/
   1.342 +
   1.343 +#define MTFA_SIZE 4096
   1.344 +#define MTFL_SIZE 16
   1.345 +
   1.346 +
   1.347 +
   1.348 +/*-- Structure holding all the decompression-side stuff. --*/
   1.349 +
   1.350 +typedef
   1.351 +   struct {
   1.352 +      /* pointer back to the struct bz_stream */
   1.353 +      bz_stream* strm;
   1.354 +
   1.355 +      /* state indicator for this stream */
   1.356 +      Int32    state;
   1.357 +
   1.358 +      /* for doing the final run-length decoding */
   1.359 +      UChar    state_out_ch;
   1.360 +      Int32    state_out_len;
   1.361 +      Bool     blockRandomised;
   1.362 +      BZ_RAND_DECLS;
   1.363 +
   1.364 +      /* the buffer for bit stream reading */
   1.365 +      UInt32   bsBuff;
   1.366 +      Int32    bsLive;
   1.367 +
   1.368 +      /* misc administratium */
   1.369 +      Int32    blockSize100k;
   1.370 +      Bool     smallDecompress;
   1.371 +      Int32    currBlockNo;
   1.372 +      Int32    verbosity;
   1.373 +
   1.374 +      /* for undoing the Burrows-Wheeler transform */
   1.375 +      Int32    origPtr;
   1.376 +      UInt32   tPos;
   1.377 +      Int32    k0;
   1.378 +      Int32    unzftab[256];
   1.379 +      Int32    nblock_used;
   1.380 +      Int32    cftab[257];
   1.381 +      Int32    cftabCopy[257];
   1.382 +
   1.383 +      /* for undoing the Burrows-Wheeler transform (FAST) */
   1.384 +      UInt32   *tt;
   1.385 +
   1.386 +      /* for undoing the Burrows-Wheeler transform (SMALL) */
   1.387 +      UInt16   *ll16;
   1.388 +      UChar    *ll4;
   1.389 +
   1.390 +      /* stored and calculated CRCs */
   1.391 +      UInt32   storedBlockCRC;
   1.392 +      UInt32   storedCombinedCRC;
   1.393 +      UInt32   calculatedBlockCRC;
   1.394 +      UInt32   calculatedCombinedCRC;
   1.395 +
   1.396 +      /* map of bytes used in block */
   1.397 +      Int32    nInUse;
   1.398 +      Bool     inUse[256];
   1.399 +      Bool     inUse16[16];
   1.400 +      UChar    seqToUnseq[256];
   1.401 +
   1.402 +      /* for decoding the MTF values */
   1.403 +      UChar    mtfa   [MTFA_SIZE];
   1.404 +      Int32    mtfbase[256 / MTFL_SIZE];
   1.405 +      UChar    selector   [BZ_MAX_SELECTORS];
   1.406 +      UChar    selectorMtf[BZ_MAX_SELECTORS];
   1.407 +      UChar    len  [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
   1.408 +
   1.409 +      Int32    limit  [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
   1.410 +      Int32    base   [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
   1.411 +      Int32    perm   [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
   1.412 +      Int32    minLens[BZ_N_GROUPS];
   1.413 +
   1.414 +      /* save area for scalars in the main decompress code */
   1.415 +      Int32    save_i;
   1.416 +      Int32    save_j;
   1.417 +      Int32    save_t;
   1.418 +      Int32    save_alphaSize;
   1.419 +      Int32    save_nGroups;
   1.420 +      Int32    save_nSelectors;
   1.421 +      Int32    save_EOB;
   1.422 +      Int32    save_groupNo;
   1.423 +      Int32    save_groupPos;
   1.424 +      Int32    save_nextSym;
   1.425 +      Int32    save_nblockMAX;
   1.426 +      Int32    save_nblock;
   1.427 +      Int32    save_es;
   1.428 +      Int32    save_N;
   1.429 +      Int32    save_curr;
   1.430 +      Int32    save_zt;
   1.431 +      Int32    save_zn; 
   1.432 +      Int32    save_zvec;
   1.433 +      Int32    save_zj;
   1.434 +      Int32    save_gSel;
   1.435 +      Int32    save_gMinlen;
   1.436 +      Int32*   save_gLimit;
   1.437 +      Int32*   save_gBase;
   1.438 +      Int32*   save_gPerm;
   1.439 +
   1.440 +   }
   1.441 +   DState;
   1.442 +
   1.443 +
   1.444 +
   1.445 +/*-- Macros for decompression. --*/
   1.446 +
   1.447 +#define BZ_GET_FAST(cccc)                     \
   1.448 +    s->tPos = s->tt[s->tPos];                 \
   1.449 +    cccc = (UChar)(s->tPos & 0xff);           \
   1.450 +    s->tPos >>= 8;
   1.451 +
   1.452 +#define BZ_GET_FAST_C(cccc)                   \
   1.453 +    c_tPos = c_tt[c_tPos];                    \
   1.454 +    cccc = (UChar)(c_tPos & 0xff);            \
   1.455 +    c_tPos >>= 8;
   1.456 +
   1.457 +#define SET_LL4(i,n)                                          \
   1.458 +   { if (((i) & 0x1) == 0)                                    \
   1.459 +        s->ll4[(i) >> 1] = (s->ll4[(i) >> 1] & 0xf0) | (n); else    \
   1.460 +        s->ll4[(i) >> 1] = (s->ll4[(i) >> 1] & 0x0f) | ((n) << 4);  \
   1.461 +   }
   1.462 +
   1.463 +#define GET_LL4(i)                             \
   1.464 +   ((((UInt32)(s->ll4[(i) >> 1])) >> (((i) << 2) & 0x4)) & 0xF)
   1.465 +
   1.466 +#define SET_LL(i,n)                          \
   1.467 +   { s->ll16[i] = (UInt16)(n & 0x0000ffff);  \
   1.468 +     SET_LL4(i, n >> 16);                    \
   1.469 +   }
   1.470 +
   1.471 +#define GET_LL(i) \
   1.472 +   (((UInt32)s->ll16[i]) | (GET_LL4(i) << 16))
   1.473 +
   1.474 +#define BZ_GET_SMALL(cccc)                            \
   1.475 +      cccc = BZ2_indexIntoF ( s->tPos, s->cftab );    \
   1.476 +      s->tPos = GET_LL(s->tPos);
   1.477 +
   1.478 +
   1.479 +/*-- externs for decompression. --*/
   1.480 +
   1.481 +extern Int32 
   1.482 +BZ2_indexIntoF ( Int32, Int32* );
   1.483 +
   1.484 +extern Int32 
   1.485 +BZ2_decompress ( DState* );
   1.486 +
   1.487 +extern void 
   1.488 +BZ2_hbCreateDecodeTables ( Int32*, Int32*, Int32*, UChar*,
   1.489 +                           Int32,  Int32, Int32 );
   1.490 +
   1.491 +
   1.492 +#endif
   1.493 +
   1.494 +
   1.495 +/*-- BZ_NO_STDIO seems to make NULL disappear on some platforms. --*/
   1.496 +
   1.497 +#ifdef BZ_NO_STDIO
   1.498 +#ifndef NULL
   1.499 +#define NULL 0
   1.500 +#endif
   1.501 +#endif
   1.502 +
   1.503 +
   1.504 +/*-------------------------------------------------------------*/
   1.505 +/*--- end                                   bzlib_private.h ---*/
   1.506 +/*-------------------------------------------------------------*/

mercurial