abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
bzlib_private.h File Reference
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include "bzlib.h"

Go to the source code of this file.

Data Structures

struct  EState
 
struct  DState
 

Macros

#define BZ_VERSION   "1.0.5, 10-Dec-2007"
 
#define True   ((Bool)1)
 
#define False   ((Bool)0)
 
#define __inline__   /* */
 
#define AssertH(cond, errcode)   { if (!(cond)) BZ2_bz__AssertH__fail ( errcode ); }
 
#define AssertD(cond, msg)   /* */
 
#define VPrintf0(zf)   fprintf(stderr,zf)
 
#define VPrintf1(zf, za1)   fprintf(stderr,zf,za1)
 
#define VPrintf2(zf, za1, za2)   fprintf(stderr,zf,za1,za2)
 
#define VPrintf3(zf, za1, za2, za3)   fprintf(stderr,zf,za1,za2,za3)
 
#define VPrintf4(zf, za1, za2, za3, za4)   fprintf(stderr,zf,za1,za2,za3,za4)
 
#define VPrintf5(zf, za1, za2, za3, za4, za5)   fprintf(stderr,zf,za1,za2,za3,za4,za5)
 
#define BZALLOC(nnn)   (strm->bzalloc)(strm->opaque,(nnn),1)
 
#define BZFREE(ppp)   (strm->bzfree)(strm->opaque,(ppp))
 
#define BZ_HDR_B   0x42 /* 'B' */
 
#define BZ_HDR_Z   0x5a /* 'Z' */
 
#define BZ_HDR_h   0x68 /* 'h' */
 
#define BZ_HDR_0   0x30 /* '0' */
 
#define BZ_MAX_ALPHA_SIZE   258
 
#define BZ_MAX_CODE_LEN   23
 
#define BZ_RUNA   0
 
#define BZ_RUNB   1
 
#define BZ_N_GROUPS   6
 
#define BZ_G_SIZE   50
 
#define BZ_N_ITERS   4
 
#define BZ_MAX_SELECTORS   (2 + (900000 / BZ_G_SIZE))
 
#define BZ_RAND_DECLS
 
#define BZ_RAND_INIT_MASK
 
#define BZ_RAND_MASK   ((s->rNToGo == 1) ? 1 : 0)
 
#define BZ_RAND_UPD_MASK
 
#define BZ_INITIALISE_CRC(crcVar)
 
#define BZ_FINALISE_CRC(crcVar)
 
#define BZ_UPDATE_CRC(crcVar, cha)
 
#define BZ_M_IDLE   1
 
#define BZ_M_RUNNING   2
 
#define BZ_M_FLUSHING   3
 
#define BZ_M_FINISHING   4
 
#define BZ_S_OUTPUT   1
 
#define BZ_S_INPUT   2
 
#define BZ_N_RADIX   2
 
#define BZ_N_QSORT   12
 
#define BZ_N_SHELL   18
 
#define BZ_N_OVERSHOOT   (BZ_N_RADIX + BZ_N_QSORT + BZ_N_SHELL + 2)
 
#define BZ_X_IDLE   1
 
#define BZ_X_OUTPUT   2
 
#define BZ_X_MAGIC_1   10
 
#define BZ_X_MAGIC_2   11
 
#define BZ_X_MAGIC_3   12
 
#define BZ_X_MAGIC_4   13
 
#define BZ_X_BLKHDR_1   14
 
#define BZ_X_BLKHDR_2   15
 
#define BZ_X_BLKHDR_3   16
 
#define BZ_X_BLKHDR_4   17
 
#define BZ_X_BLKHDR_5   18
 
#define BZ_X_BLKHDR_6   19
 
#define BZ_X_BCRC_1   20
 
#define BZ_X_BCRC_2   21
 
#define BZ_X_BCRC_3   22
 
#define BZ_X_BCRC_4   23
 
#define BZ_X_RANDBIT   24
 
#define BZ_X_ORIGPTR_1   25
 
#define BZ_X_ORIGPTR_2   26
 
#define BZ_X_ORIGPTR_3   27
 
#define BZ_X_MAPPING_1   28
 
#define BZ_X_MAPPING_2   29
 
#define BZ_X_SELECTOR_1   30
 
#define BZ_X_SELECTOR_2   31
 
#define BZ_X_SELECTOR_3   32
 
#define BZ_X_CODING_1   33
 
#define BZ_X_CODING_2   34
 
#define BZ_X_CODING_3   35
 
#define BZ_X_MTF_1   36
 
#define BZ_X_MTF_2   37
 
#define BZ_X_MTF_3   38
 
#define BZ_X_MTF_4   39
 
#define BZ_X_MTF_5   40
 
#define BZ_X_MTF_6   41
 
#define BZ_X_ENDHDR_2   42
 
#define BZ_X_ENDHDR_3   43
 
#define BZ_X_ENDHDR_4   44
 
#define BZ_X_ENDHDR_5   45
 
#define BZ_X_ENDHDR_6   46
 
#define BZ_X_CCRC_1   47
 
#define BZ_X_CCRC_2   48
 
#define BZ_X_CCRC_3   49
 
#define BZ_X_CCRC_4   50
 
#define MTFA_SIZE   4096
 
#define MTFL_SIZE   16
 
#define BZ_GET_FAST(cccc)
 
#define BZ_GET_FAST_C(cccc)
 
#define SET_LL4(i, n)
 
#define GET_LL4(i)   ((((UInt32)(s->ll4[(i) >> 1])) >> (((i) << 2) & 0x4)) & 0xF)
 
#define SET_LL(i, n)
 
#define GET_LL(i)   (((UInt32)s->ll16[i]) | (GET_LL4(i) << 16))
 
#define BZ_GET_SMALL(cccc)
 

Typedefs

typedef char Char
 
typedef unsigned char Bool
 
typedef unsigned char UChar
 
typedef int Int32
 
typedef unsigned int UInt32
 
typedef short Int16
 
typedef unsigned short UInt16
 

Functions

void BZ2_bz__AssertH__fail (int errcode)
 
void BZ2_blockSort (EState *)
 
void BZ2_compressBlock (EState *, Bool)
 
void BZ2_bsInitWrite (EState *)
 
void BZ2_hbAssignCodes (Int32 *, UChar *, Int32, Int32, Int32)
 
void BZ2_hbMakeCodeLengths (UChar *, Int32 *, Int32, Int32)
 
Int32 BZ2_indexIntoF (Int32, Int32 *)
 
Int32 BZ2_decompress (DState *)
 
void BZ2_hbCreateDecodeTables (Int32 *, Int32 *, Int32 *, UChar *, Int32, Int32, Int32)
 

Variables

Int32 BZ2_rNums [512]
 
UInt32 BZ2_crc32Table [256]
 

Macro Definition Documentation

#define __inline__   /* */

Definition at line 55 of file bzlib_private.h.

#define AssertD (   cond,
  msg 
)    /* */

Definition at line 72 of file bzlib_private.h.

#define AssertH (   cond,
  errcode 
)    { if (!(cond)) BZ2_bz__AssertH__fail ( errcode ); }

Definition at line 61 of file bzlib_private.h.

#define BZ_FINALISE_CRC (   crcVar)
Value:
{ \
crcVar = ~(crcVar); \
}

Definition at line 164 of file bzlib_private.h.

#define BZ_G_SIZE   50

Definition at line 124 of file bzlib_private.h.

#define BZ_GET_FAST (   cccc)
Value:
/* c_tPos is unsigned, hence test < 0 is pointless. */ \
if (s->tPos >= (UInt32)100000 * (UInt32)s->blockSize100k) return True; \
s->tPos = s->tt[s->tPos]; \
cccc = (UChar)(s->tPos & 0xff); \
s->tPos >>= 8;
if(last==0)
Definition: sparse_int.h:34
unsigned char UChar
Definition: bzlib_private.h:45
unsigned int UInt32
Definition: bzlib_private.h:47
#define True
Definition: bzlib_private.h:51

Definition at line 446 of file bzlib_private.h.

#define BZ_GET_FAST_C (   cccc)
Value:
/* c_tPos is unsigned, hence test < 0 is pointless. */ \
if (c_tPos >= (UInt32)100000 * (UInt32)ro_blockSize100k) return True; \
c_tPos = c_tt[c_tPos]; \
cccc = (UChar)(c_tPos & 0xff); \
c_tPos >>= 8;
if(last==0)
Definition: sparse_int.h:34
unsigned char UChar
Definition: bzlib_private.h:45
unsigned int UInt32
Definition: bzlib_private.h:47
#define True
Definition: bzlib_private.h:51

Definition at line 453 of file bzlib_private.h.

#define BZ_GET_SMALL (   cccc)
Value:
/* c_tPos is unsigned, hence test < 0 is pointless. */ \
if (s->tPos >= (UInt32)100000 * (UInt32)s->blockSize100k) return True; \
cccc = BZ2_indexIntoF ( s->tPos, s->cftab ); \
s->tPos = GET_LL(s->tPos);
Int32 BZ2_indexIntoF(Int32, Int32 *)
Definition: bzlib.c:698
if(last==0)
Definition: sparse_int.h:34
unsigned int UInt32
Definition: bzlib_private.h:47
#define True
Definition: bzlib_private.h:51
#define GET_LL(i)

Definition at line 477 of file bzlib_private.h.

#define BZ_HDR_0   0x30 /* '0' */

Definition at line 113 of file bzlib_private.h.

#define BZ_HDR_B   0x42 /* 'B' */

Definition at line 110 of file bzlib_private.h.

#define BZ_HDR_h   0x68 /* 'h' */

Definition at line 112 of file bzlib_private.h.

#define BZ_HDR_Z   0x5a /* 'Z' */

Definition at line 111 of file bzlib_private.h.

#define BZ_INITIALISE_CRC (   crcVar)
Value:
{ \
crcVar = 0xffffffffL; \
}

Definition at line 159 of file bzlib_private.h.

#define BZ_M_FINISHING   4

Definition at line 183 of file bzlib_private.h.

#define BZ_M_FLUSHING   3

Definition at line 182 of file bzlib_private.h.

#define BZ_M_IDLE   1

Definition at line 180 of file bzlib_private.h.

#define BZ_M_RUNNING   2

Definition at line 181 of file bzlib_private.h.

#define BZ_MAX_ALPHA_SIZE   258

Definition at line 117 of file bzlib_private.h.

#define BZ_MAX_CODE_LEN   23

Definition at line 118 of file bzlib_private.h.

#define BZ_MAX_SELECTORS   (2 + (900000 / BZ_G_SIZE))

Definition at line 127 of file bzlib_private.h.

#define BZ_N_GROUPS   6

Definition at line 123 of file bzlib_private.h.

#define BZ_N_ITERS   4

Definition at line 125 of file bzlib_private.h.

#define BZ_N_OVERSHOOT   (BZ_N_RADIX + BZ_N_QSORT + BZ_N_SHELL + 2)

Definition at line 191 of file bzlib_private.h.

#define BZ_N_QSORT   12

Definition at line 189 of file bzlib_private.h.

#define BZ_N_RADIX   2

Definition at line 188 of file bzlib_private.h.

#define BZ_N_SHELL   18

Definition at line 190 of file bzlib_private.h.

#define BZ_RAND_DECLS
Value:
Int32 rNToGo; \
Int32 rTPos \
int Int32
Definition: bzlib_private.h:46

Definition at line 135 of file bzlib_private.h.

#define BZ_RAND_INIT_MASK
Value:
s->rNToGo = 0; \
s->rTPos = 0 \

Definition at line 139 of file bzlib_private.h.

#define BZ_RAND_MASK   ((s->rNToGo == 1) ? 1 : 0)

Definition at line 143 of file bzlib_private.h.

#define BZ_RAND_UPD_MASK
Value:
if (s->rNToGo == 0) { \
s->rNToGo = BZ2_rNums[s->rTPos]; \
s->rTPos++; \
if (s->rTPos == 512) s->rTPos = 0; \
} \
s->rNToGo--;
Int32 BZ2_rNums[512]
Definition: randtable.c:29
if(last==0)
Definition: sparse_int.h:34

Definition at line 145 of file bzlib_private.h.

#define BZ_RUNA   0

Definition at line 120 of file bzlib_private.h.

#define BZ_RUNB   1

Definition at line 121 of file bzlib_private.h.

#define BZ_S_INPUT   2

Definition at line 186 of file bzlib_private.h.

#define BZ_S_OUTPUT   1

Definition at line 185 of file bzlib_private.h.

#define BZ_UPDATE_CRC (   crcVar,
  cha 
)
Value:
{ \
crcVar = (crcVar << 8) ^ \
BZ2_crc32Table[(crcVar >> 24) ^ \
((UChar)cha)]; \
}
unsigned char UChar
Definition: bzlib_private.h:45
UInt32 BZ2_crc32Table[256]
Definition: crctable.c:34

Definition at line 169 of file bzlib_private.h.

#define BZ_VERSION   "1.0.5, 10-Dec-2007"

Definition at line 41 of file bzlib_private.h.

#define BZ_X_BCRC_1   20

Definition at line 306 of file bzlib_private.h.

#define BZ_X_BCRC_2   21

Definition at line 307 of file bzlib_private.h.

#define BZ_X_BCRC_3   22

Definition at line 308 of file bzlib_private.h.

#define BZ_X_BCRC_4   23

Definition at line 309 of file bzlib_private.h.

#define BZ_X_BLKHDR_1   14

Definition at line 300 of file bzlib_private.h.

#define BZ_X_BLKHDR_2   15

Definition at line 301 of file bzlib_private.h.

#define BZ_X_BLKHDR_3   16

Definition at line 302 of file bzlib_private.h.

#define BZ_X_BLKHDR_4   17

Definition at line 303 of file bzlib_private.h.

#define BZ_X_BLKHDR_5   18

Definition at line 304 of file bzlib_private.h.

#define BZ_X_BLKHDR_6   19

Definition at line 305 of file bzlib_private.h.

#define BZ_X_CCRC_1   47

Definition at line 333 of file bzlib_private.h.

#define BZ_X_CCRC_2   48

Definition at line 334 of file bzlib_private.h.

#define BZ_X_CCRC_3   49

Definition at line 335 of file bzlib_private.h.

#define BZ_X_CCRC_4   50

Definition at line 336 of file bzlib_private.h.

#define BZ_X_CODING_1   33

Definition at line 319 of file bzlib_private.h.

#define BZ_X_CODING_2   34

Definition at line 320 of file bzlib_private.h.

#define BZ_X_CODING_3   35

Definition at line 321 of file bzlib_private.h.

#define BZ_X_ENDHDR_2   42

Definition at line 328 of file bzlib_private.h.

#define BZ_X_ENDHDR_3   43

Definition at line 329 of file bzlib_private.h.

#define BZ_X_ENDHDR_4   44

Definition at line 330 of file bzlib_private.h.

#define BZ_X_ENDHDR_5   45

Definition at line 331 of file bzlib_private.h.

#define BZ_X_ENDHDR_6   46

Definition at line 332 of file bzlib_private.h.

#define BZ_X_IDLE   1

Definition at line 293 of file bzlib_private.h.

#define BZ_X_MAGIC_1   10

Definition at line 296 of file bzlib_private.h.

#define BZ_X_MAGIC_2   11

Definition at line 297 of file bzlib_private.h.

#define BZ_X_MAGIC_3   12

Definition at line 298 of file bzlib_private.h.

#define BZ_X_MAGIC_4   13

Definition at line 299 of file bzlib_private.h.

#define BZ_X_MAPPING_1   28

Definition at line 314 of file bzlib_private.h.

#define BZ_X_MAPPING_2   29

Definition at line 315 of file bzlib_private.h.

#define BZ_X_MTF_1   36

Definition at line 322 of file bzlib_private.h.

#define BZ_X_MTF_2   37

Definition at line 323 of file bzlib_private.h.

#define BZ_X_MTF_3   38

Definition at line 324 of file bzlib_private.h.

#define BZ_X_MTF_4   39

Definition at line 325 of file bzlib_private.h.

#define BZ_X_MTF_5   40

Definition at line 326 of file bzlib_private.h.

#define BZ_X_MTF_6   41

Definition at line 327 of file bzlib_private.h.

#define BZ_X_ORIGPTR_1   25

Definition at line 311 of file bzlib_private.h.

#define BZ_X_ORIGPTR_2   26

Definition at line 312 of file bzlib_private.h.

#define BZ_X_ORIGPTR_3   27

Definition at line 313 of file bzlib_private.h.

#define BZ_X_OUTPUT   2

Definition at line 294 of file bzlib_private.h.

#define BZ_X_RANDBIT   24

Definition at line 310 of file bzlib_private.h.

#define BZ_X_SELECTOR_1   30

Definition at line 316 of file bzlib_private.h.

#define BZ_X_SELECTOR_2   31

Definition at line 317 of file bzlib_private.h.

#define BZ_X_SELECTOR_3   32

Definition at line 318 of file bzlib_private.h.

#define BZALLOC (   nnn)    (strm->bzalloc)(strm->opaque,(nnn),1)

Definition at line 104 of file bzlib_private.h.

#define BZFREE (   ppp)    (strm->bzfree)(strm->opaque,(ppp))

Definition at line 105 of file bzlib_private.h.

#define False   ((Bool)0)

Definition at line 52 of file bzlib_private.h.

#define GET_LL (   i)    (((UInt32)s->ll16[i]) | (GET_LL4(i) << 16))

Definition at line 474 of file bzlib_private.h.

#define GET_LL4 (   i)    ((((UInt32)(s->ll4[(i) >> 1])) >> (((i) << 2) & 0x4)) & 0xF)

Definition at line 466 of file bzlib_private.h.

#define MTFA_SIZE   4096

Definition at line 342 of file bzlib_private.h.

#define MTFL_SIZE   16

Definition at line 343 of file bzlib_private.h.

#define SET_LL (   i,
 
)
Value:
{ s->ll16[i] = (UInt16)(n & 0x0000ffff); \
SET_LL4(i, n >> 16); \
}
#define SET_LL4(i, n)
unsigned short UInt16
Definition: bzlib_private.h:49

Definition at line 469 of file bzlib_private.h.

#define SET_LL4 (   i,
 
)
Value:
{ if (((i) & 0x1) == 0) \
s->ll4[(i) >> 1] = (s->ll4[(i) >> 1] & 0xf0) | (n); else \
s->ll4[(i) >> 1] = (s->ll4[(i) >> 1] & 0x0f) | ((n) << 4); \
}

Definition at line 460 of file bzlib_private.h.

#define True   ((Bool)1)

Definition at line 51 of file bzlib_private.h.

#define VPrintf0 (   zf)    fprintf(stderr,zf)

Definition at line 75 of file bzlib_private.h.

#define VPrintf1 (   zf,
  za1 
)    fprintf(stderr,zf,za1)

Definition at line 77 of file bzlib_private.h.

#define VPrintf2 (   zf,
  za1,
  za2 
)    fprintf(stderr,zf,za1,za2)

Definition at line 79 of file bzlib_private.h.

#define VPrintf3 (   zf,
  za1,
  za2,
  za3 
)    fprintf(stderr,zf,za1,za2,za3)

Definition at line 81 of file bzlib_private.h.

#define VPrintf4 (   zf,
  za1,
  za2,
  za3,
  za4 
)    fprintf(stderr,zf,za1,za2,za3,za4)

Definition at line 83 of file bzlib_private.h.

#define VPrintf5 (   zf,
  za1,
  za2,
  za3,
  za4,
  za5 
)    fprintf(stderr,zf,za1,za2,za3,za4,za5)

Definition at line 85 of file bzlib_private.h.

Typedef Documentation

typedef unsigned char Bool

Definition at line 44 of file bzlib_private.h.

typedef char Char

Definition at line 43 of file bzlib_private.h.

typedef short Int16

Definition at line 48 of file bzlib_private.h.

typedef int Int32

Definition at line 46 of file bzlib_private.h.

typedef unsigned char UChar

Definition at line 45 of file bzlib_private.h.

typedef unsigned short UInt16

Definition at line 49 of file bzlib_private.h.

typedef unsigned int UInt32

Definition at line 47 of file bzlib_private.h.

Function Documentation

void BZ2_blockSort ( EState )

Definition at line 1033 of file blocksort.c.

1034 {
1035  UInt32* ptr = s->ptr;
1036  UChar* block = s->block;
1037  UInt32* ftab = s->ftab;
1038  Int32 nblock = s->nblock;
1039  Int32 verb = s->verbosity;
1040  Int32 wfact = s->workFactor;
1041  UInt16* quadrant;
1042  Int32 budget;
1043  Int32 budgetInit;
1044  Int32 i;
1045 
1046  if (nblock < 10000) {
1047  fallbackSort ( s->arr1, s->arr2, ftab, nblock, verb );
1048  } else {
1049  /* Calculate the location for quadrant, remembering to get
1050  the alignment right. Assumes that &(block[0]) is at least
1051  2-byte aligned -- this should be ok since block is really
1052  the first section of arr2.
1053  */
1054  i = nblock+BZ_N_OVERSHOOT;
1055  if (i & 1) i++;
1056  quadrant = (UInt16*)(&(block[i]));
1057 
1058  /* (wfact-1) / 3 puts the default-factor-30
1059  transition point at very roughly the same place as
1060  with v0.1 and v0.9.0.
1061  Not that it particularly matters any more, since the
1062  resulting compressed stream is now the same regardless
1063  of whether or not we use the main sort or fallback sort.
1064  */
1065  if (wfact < 1 ) wfact = 1;
1066  if (wfact > 100) wfact = 100;
1067  budgetInit = nblock * ((wfact-1) / 3);
1068  budget = budgetInit;
1069 
1070  mainSort ( ptr, block, quadrant, ftab, nblock, verb, &budget );
1071  if (verb >= 3)
1072  VPrintf3 ( " %d work, %d block, ratio %5.2f\n",
1073  budgetInit - budget,
1074  nblock,
1075  (float)(budgetInit - budget) /
1076  (float)(nblock==0 ? 1 : nblock) );
1077  if (budget < 0) {
1078  if (verb >= 2)
1079  VPrintf0 ( " too repetitive; using fallback"
1080  " sorting algorithm\n" );
1081  fallbackSort ( s->arr1, s->arr2, ftab, nblock, verb );
1082  }
1083  }
1084 
1085  s->origPtr = -1;
1086  for (i = 0; i < s->nblock; i++)
1087  if (ptr[i] == 0)
1088  { s->origPtr = i; break; };
1089 
1090  AssertH( s->origPtr != -1, 1003 );
1091 }
#define BZ_N_OVERSHOOT
#define AssertH(cond, errcode)
Definition: bzlib_private.h:61
unsigned char UChar
Definition: bzlib_private.h:45
unsigned int UInt32
Definition: bzlib_private.h:47
#define VPrintf0(zf)
Definition: bzlib_private.h:75
int Int32
Definition: bzlib_private.h:46
#define VPrintf3(zf, za1, za2, za3)
Definition: bzlib_private.h:81
static void fallbackSort(UInt32 *fmap, UInt32 *eclass, UInt32 *bhtab, Int32 nblock, Int32 verb)
Definition: blocksort.c:214
unsigned short UInt16
Definition: bzlib_private.h:49
static void mainSort(UInt32 *ptr, UChar *block, UInt16 *quadrant, UInt32 *ftab, Int32 nblock, Int32 verb, Int32 *budget)
Definition: blocksort.c:753
void BZ2_bsInitWrite ( EState )

Definition at line 40 of file compress.c.

41 {
42  s->bsLive = 0;
43  s->bsBuff = 0;
44 }
void BZ2_bz__AssertH__fail ( int  errcode)

Definition at line 52 of file bzlib.c.

53 {
54  fprintf(stderr,
55  "\n\nbzip2/libbzip2: internal error number %d.\n"
56  "This is a bug in bzip2/libbzip2, %s.\n"
57  "Please report it to me at: jseward@bzip.org. If this happened\n"
58  "when you were using some program which uses libbzip2 as a\n"
59  "component, you should also report this bug to the author(s)\n"
60  "of that program. Please make an effort to report this bug;\n"
61  "timely and accurate bug reports eventually lead to higher\n"
62  "quality software. Thanks. Julian Seward, 10 December 2007.\n\n",
63  errcode,
65  );
66 
67  if (errcode == 1007) {
68  fprintf(stderr,
69  "\n*** A special note about internal error number 1007 ***\n"
70  "\n"
71  "Experience suggests that a common cause of i.e. 1007\n"
72  "is unreliable memory or other hardware. The 1007 assertion\n"
73  "just happens to cross-check the results of huge numbers of\n"
74  "memory reads/writes, and so acts (unintendedly) as a stress\n"
75  "test of your memory system.\n"
76  "\n"
77  "I suggest the following: try compressing the file again,\n"
78  "possibly monitoring progress in detail with the -vv flag.\n"
79  "\n"
80  "* If the error cannot be reproduced, and/or happens at different\n"
81  " points in compression, you may have a flaky memory system.\n"
82  " Try a memory-test program. I have used Memtest86\n"
83  " (www.memtest86.com). At the time of writing it is free (GPLd).\n"
84  " Memtest86 tests memory much more thorougly than your BIOSs\n"
85  " power-on test, and may find failures that the BIOS doesn't.\n"
86  "\n"
87  "* If the error can be repeatably reproduced, this is a bug in\n"
88  " bzip2, and I would very much like to hear about it. Please\n"
89  " let me know, and, ideally, save a copy of the file causing the\n"
90  " problem -- without which I will be unable to investigate it.\n"
91  "\n"
92  );
93  }
94 
95  exit(3);
96 }
VOID_HACK exit()
const char *BZ_API() BZ2_bzlibVersion(void)
Definition: bzlib.c:1377
void BZ2_compressBlock ( EState ,
Bool   
)

Definition at line 605 of file compress.c.

606 {
607  if (s->nblock > 0) {
608 
609  BZ_FINALISE_CRC ( s->blockCRC );
610  s->combinedCRC = (s->combinedCRC << 1) | (s->combinedCRC >> 31);
611  s->combinedCRC ^= s->blockCRC;
612  if (s->blockNo > 1) s->numZ = 0;
613 
614  if (s->verbosity >= 2)
615  VPrintf4( " block %d: crc = 0x%08x, "
616  "combined CRC = 0x%08x, size = %d\n",
617  s->blockNo, s->blockCRC, s->combinedCRC, s->nblock );
618 
619  BZ2_blockSort ( s );
620  }
621 
622  s->zbits = (UChar*) (&((UChar*)s->arr2)[s->nblock]);
623 
624  /*-- If this is the first block, create the stream header. --*/
625  if (s->blockNo == 1) {
626  BZ2_bsInitWrite ( s );
627  bsPutUChar ( s, BZ_HDR_B );
628  bsPutUChar ( s, BZ_HDR_Z );
629  bsPutUChar ( s, BZ_HDR_h );
630  bsPutUChar ( s, (UChar)(BZ_HDR_0 + s->blockSize100k) );
631  }
632 
633  if (s->nblock > 0) {
634 
635  bsPutUChar ( s, 0x31 ); bsPutUChar ( s, 0x41 );
636  bsPutUChar ( s, 0x59 ); bsPutUChar ( s, 0x26 );
637  bsPutUChar ( s, 0x53 ); bsPutUChar ( s, 0x59 );
638 
639  /*-- Now the block's CRC, so it is in a known place. --*/
640  bsPutUInt32 ( s, s->blockCRC );
641 
642  /*--
643  Now a single bit indicating (non-)randomisation.
644  As of version 0.9.5, we use a better sorting algorithm
645  which makes randomisation unnecessary. So always set
646  the randomised bit to 'no'. Of course, the decoder
647  still needs to be able to handle randomised blocks
648  so as to maintain backwards compatibility with
649  older versions of bzip2.
650  --*/
651  bsW(s,1,0);
652 
653  bsW ( s, 24, s->origPtr );
654  generateMTFValues ( s );
655  sendMTFValues ( s );
656  }
657 
658 
659  /*-- If this is the last block, add the stream trailer. --*/
660  if (is_last_block) {
661 
662  bsPutUChar ( s, 0x17 ); bsPutUChar ( s, 0x72 );
663  bsPutUChar ( s, 0x45 ); bsPutUChar ( s, 0x38 );
664  bsPutUChar ( s, 0x50 ); bsPutUChar ( s, 0x90 );
665  bsPutUInt32 ( s, s->combinedCRC );
666  if (s->verbosity >= 2)
667  VPrintf1( " final combined CRC = 0x%08x\n ", s->combinedCRC );
668  bsFinishWrite ( s );
669  }
670 }
#define BZ_FINALISE_CRC(crcVar)
#define VPrintf1(zf, za1)
Definition: bzlib_private.h:77
ABC_NAMESPACE_IMPL_START void BZ2_bsInitWrite(EState *s)
Definition: compress.c:40
#define BZ_HDR_B
void BZ2_blockSort(EState *s)
Definition: blocksort.c:1033
static void bsFinishWrite(EState *s)
Definition: compress.c:49
unsigned char UChar
Definition: bzlib_private.h:45
static void sendMTFValues(EState *s)
Definition: compress.c:242
#define BZ_HDR_0
#define BZ_HDR_h
static void bsPutUInt32(EState *s, UInt32 u)
Definition: compress.c:86
static __inline__ void bsW(EState *s, Int32 n, UInt32 v)
Definition: compress.c:76
#define BZ_HDR_Z
#define VPrintf4(zf, za1, za2, za3, za4)
Definition: bzlib_private.h:83
static void generateMTFValues(EState *s)
Definition: compress.c:123
static void bsPutUChar(EState *s, UChar c)
Definition: compress.c:97
Int32 BZ2_decompress ( DState )

Definition at line 109 of file decompress.c.

110 {
111  UChar uc;
112  Int32 retVal;
113  Int32 minLen, maxLen;
114  bz_stream* strm = s->strm;
115 
116  /* stuff that needs to be saved/restored */
117  Int32 i;
118  Int32 j;
119  Int32 t;
120  Int32 alphaSize;
121  Int32 nGroups;
122  Int32 nSelectors;
123  Int32 EOB;
124  Int32 groupNo;
125  Int32 groupPos;
126  Int32 nextSym;
127  Int32 nblockMAX;
128  Int32 nblock;
129  Int32 es;
130  Int32 N;
131  Int32 curr;
132  Int32 zt;
133  Int32 zn;
134  Int32 zvec;
135  Int32 zj;
136  Int32 gSel;
137  Int32 gMinlen;
138  Int32* gLimit;
139  Int32* gBase;
140  Int32* gPerm;
141 
142  if (s->state == BZ_X_MAGIC_1) {
143  /*initialise the save area*/
144  s->save_i = 0;
145  s->save_j = 0;
146  s->save_t = 0;
147  s->save_alphaSize = 0;
148  s->save_nGroups = 0;
149  s->save_nSelectors = 0;
150  s->save_EOB = 0;
151  s->save_groupNo = 0;
152  s->save_groupPos = 0;
153  s->save_nextSym = 0;
154  s->save_nblockMAX = 0;
155  s->save_nblock = 0;
156  s->save_es = 0;
157  s->save_N = 0;
158  s->save_curr = 0;
159  s->save_zt = 0;
160  s->save_zn = 0;
161  s->save_zvec = 0;
162  s->save_zj = 0;
163  s->save_gSel = 0;
164  s->save_gMinlen = 0;
165  s->save_gLimit = NULL;
166  s->save_gBase = NULL;
167  s->save_gPerm = NULL;
168  }
169 
170  /*restore from the save area*/
171  i = s->save_i;
172  j = s->save_j;
173  t = s->save_t;
174  alphaSize = s->save_alphaSize;
175  nGroups = s->save_nGroups;
176  nSelectors = s->save_nSelectors;
177  EOB = s->save_EOB;
178  groupNo = s->save_groupNo;
179  groupPos = s->save_groupPos;
180  nextSym = s->save_nextSym;
181  nblockMAX = s->save_nblockMAX;
182  nblock = s->save_nblock;
183  es = s->save_es;
184  N = s->save_N;
185  curr = s->save_curr;
186  zt = s->save_zt;
187  zn = s->save_zn;
188  zvec = s->save_zvec;
189  zj = s->save_zj;
190  gSel = s->save_gSel;
191  gMinlen = s->save_gMinlen;
192  gLimit = s->save_gLimit;
193  gBase = s->save_gBase;
194  gPerm = s->save_gPerm;
195 
196  retVal = BZ_OK;
197 
198  switch (s->state) {
199 
200  GET_UCHAR(BZ_X_MAGIC_1, uc);
201  if (uc != BZ_HDR_B) RETURN(BZ_DATA_ERROR_MAGIC);
202 
203  GET_UCHAR(BZ_X_MAGIC_2, uc);
204  if (uc != BZ_HDR_Z) RETURN(BZ_DATA_ERROR_MAGIC);
205 
208 
209  GET_BITS(BZ_X_MAGIC_4, s->blockSize100k, 8)
210  if (s->blockSize100k < (BZ_HDR_0 + 1) ||
211  s->blockSize100k > (BZ_HDR_0 + 9)) RETURN(BZ_DATA_ERROR_MAGIC);
212  s->blockSize100k -= BZ_HDR_0;
213 
214  if (s->smallDecompress) {
215  s->ll16 = (unsigned short *)BZALLOC( s->blockSize100k * 100000 * sizeof(UInt16) );
216  s->ll4 = (unsigned char *)BZALLOC(
217  ((1 + s->blockSize100k * 100000) >> 1) * sizeof(UChar)
218  );
219  if (s->ll16 == NULL || s->ll4 == NULL) RETURN(BZ_MEM_ERROR);
220  } else {
221  s->tt = (unsigned *)BZALLOC( s->blockSize100k * 100000 * sizeof(Int32) );
222  if (s->tt == NULL) RETURN(BZ_MEM_ERROR);
223  }
224 
226 
227  if (uc == 0x17) goto endhdr_2;
228  if (uc != 0x31) RETURN(BZ_DATA_ERROR);
230  if (uc != 0x41) RETURN(BZ_DATA_ERROR);
232  if (uc != 0x59) RETURN(BZ_DATA_ERROR);
234  if (uc != 0x26) RETURN(BZ_DATA_ERROR);
236  if (uc != 0x53) RETURN(BZ_DATA_ERROR);
238  if (uc != 0x59) RETURN(BZ_DATA_ERROR);
239 
240  s->currBlockNo++;
241  if (s->verbosity >= 2)
242  VPrintf1 ( "\n [%d: huff+mtf ", s->currBlockNo );
243 
244  s->storedBlockCRC = 0;
245  GET_UCHAR(BZ_X_BCRC_1, uc);
246  s->storedBlockCRC = (s->storedBlockCRC << 8) | ((UInt32)uc);
247  GET_UCHAR(BZ_X_BCRC_2, uc);
248  s->storedBlockCRC = (s->storedBlockCRC << 8) | ((UInt32)uc);
249  GET_UCHAR(BZ_X_BCRC_3, uc);
250  s->storedBlockCRC = (s->storedBlockCRC << 8) | ((UInt32)uc);
251  GET_UCHAR(BZ_X_BCRC_4, uc);
252  s->storedBlockCRC = (s->storedBlockCRC << 8) | ((UInt32)uc);
253 
254  GET_BITS(BZ_X_RANDBIT, s->blockRandomised, 1);
255 
256  s->origPtr = 0;
258  s->origPtr = (s->origPtr << 8) | ((Int32)uc);
260  s->origPtr = (s->origPtr << 8) | ((Int32)uc);
262  s->origPtr = (s->origPtr << 8) | ((Int32)uc);
263 
264  if (s->origPtr < 0)
266  if (s->origPtr > 10 + 100000*s->blockSize100k)
268 
269  /*--- Receive the mapping table ---*/
270  for (i = 0; i < 16; i++) {
271  GET_BIT(BZ_X_MAPPING_1, uc);
272  if (uc == 1)
273  s->inUse16[i] = True; else
274  s->inUse16[i] = False;
275  }
276 
277  for (i = 0; i < 256; i++) s->inUse[i] = False;
278 
279  for (i = 0; i < 16; i++)
280  if (s->inUse16[i])
281  for (j = 0; j < 16; j++) {
282  GET_BIT(BZ_X_MAPPING_2, uc);
283  if (uc == 1) s->inUse[i * 16 + j] = True;
284  }
285  makeMaps_d ( s );
286  if (s->nInUse == 0) RETURN(BZ_DATA_ERROR);
287  alphaSize = s->nInUse+2;
288 
289  /*--- Now the selectors ---*/
290  GET_BITS(BZ_X_SELECTOR_1, nGroups, 3);
291  if (nGroups < 2 || nGroups > 6) RETURN(BZ_DATA_ERROR);
292  GET_BITS(BZ_X_SELECTOR_2, nSelectors, 15);
293  if (nSelectors < 1) RETURN(BZ_DATA_ERROR);
294  for (i = 0; i < nSelectors; i++) {
295  j = 0;
296  while (True) {
298  if (uc == 0) break;
299  j++;
300  if (j >= nGroups) RETURN(BZ_DATA_ERROR);
301  }
302  s->selectorMtf[i] = j;
303  }
304 
305  /*--- Undo the MTF values for the selectors. ---*/
306  {
307  UChar pos[BZ_N_GROUPS], tmp, v;
308  for (v = 0; v < nGroups; v++) pos[v] = v;
309 
310  for (i = 0; i < nSelectors; i++) {
311  v = s->selectorMtf[i];
312  tmp = pos[v];
313  while (v > 0) { pos[v] = pos[v-1]; v--; }
314  pos[0] = tmp;
315  s->selector[i] = tmp;
316  }
317  }
318 
319  /*--- Now the coding tables ---*/
320  for (t = 0; t < nGroups; t++) {
321  GET_BITS(BZ_X_CODING_1, curr, 5);
322  for (i = 0; i < alphaSize; i++) {
323  while (True) {
324  if (curr < 1 || curr > 20) RETURN(BZ_DATA_ERROR);
325  GET_BIT(BZ_X_CODING_2, uc);
326  if (uc == 0) break;
327  GET_BIT(BZ_X_CODING_3, uc);
328  if (uc == 0) curr++; else curr--;
329  }
330  s->len[t][i] = curr;
331  }
332  }
333 
334  /*--- Create the Huffman decoding tables ---*/
335  for (t = 0; t < nGroups; t++) {
336  minLen = 32;
337  maxLen = 0;
338  for (i = 0; i < alphaSize; i++) {
339  if (s->len[t][i] > maxLen) maxLen = s->len[t][i];
340  if (s->len[t][i] < minLen) minLen = s->len[t][i];
341  }
343  &(s->limit[t][0]),
344  &(s->base[t][0]),
345  &(s->perm[t][0]),
346  &(s->len[t][0]),
347  minLen, maxLen, alphaSize
348  );
349  s->minLens[t] = minLen;
350  }
351 
352  /*--- Now the MTF values ---*/
353 
354  EOB = s->nInUse+1;
355  nblockMAX = 100000 * s->blockSize100k;
356  groupNo = -1;
357  groupPos = 0;
358 
359  for (i = 0; i <= 255; i++) s->unzftab[i] = 0;
360 
361  /*-- MTF init --*/
362  {
363  Int32 ii, jj, kk;
364  kk = MTFA_SIZE-1;
365  for (ii = 256 / MTFL_SIZE - 1; ii >= 0; ii--) {
366  for (jj = MTFL_SIZE-1; jj >= 0; jj--) {
367  s->mtfa[kk] = (UChar)(ii * MTFL_SIZE + jj);
368  kk--;
369  }
370  s->mtfbase[ii] = kk + 1;
371  }
372  }
373  /*-- end MTF init --*/
374 
375  nblock = 0;
376  GET_MTF_VAL(BZ_X_MTF_1, BZ_X_MTF_2, nextSym);
377 
378  while (True) {
379 
380  if (nextSym == EOB) break;
381 
382  if (nextSym == BZ_RUNA || nextSym == BZ_RUNB) {
383 
384  es = -1;
385  N = 1;
386  do {
387  if (nextSym == BZ_RUNA) es = es + (0+1) * N; else
388  if (nextSym == BZ_RUNB) es = es + (1+1) * N;
389  N = N * 2;
390  GET_MTF_VAL(BZ_X_MTF_3, BZ_X_MTF_4, nextSym);
391  }
392  while (nextSym == BZ_RUNA || nextSym == BZ_RUNB);
393 
394  es++;
395  uc = s->seqToUnseq[ s->mtfa[s->mtfbase[0]] ];
396  s->unzftab[uc] += es;
397 
398  if (s->smallDecompress)
399  while (es > 0) {
400  if (nblock >= nblockMAX) RETURN(BZ_DATA_ERROR);
401  s->ll16[nblock] = (UInt16)uc;
402  nblock++;
403  es--;
404  }
405  else
406  while (es > 0) {
407  if (nblock >= nblockMAX) RETURN(BZ_DATA_ERROR);
408  s->tt[nblock] = (UInt32)uc;
409  nblock++;
410  es--;
411  };
412 
413  continue;
414 
415  } else {
416 
417  if (nblock >= nblockMAX) RETURN(BZ_DATA_ERROR);
418 
419  /*-- uc = MTF ( nextSym-1 ) --*/
420  {
421  Int32 ii, jj, kk, pp, lno, off;
422  UInt32 nn;
423  nn = (UInt32)(nextSym - 1);
424 
425  if (nn < MTFL_SIZE) {
426  /* avoid general-case expense */
427  pp = s->mtfbase[0];
428  uc = s->mtfa[pp+nn];
429  while (nn > 3) {
430  Int32 z = pp+nn;
431  s->mtfa[(z) ] = s->mtfa[(z)-1];
432  s->mtfa[(z)-1] = s->mtfa[(z)-2];
433  s->mtfa[(z)-2] = s->mtfa[(z)-3];
434  s->mtfa[(z)-3] = s->mtfa[(z)-4];
435  nn -= 4;
436  }
437  while (nn > 0) {
438  s->mtfa[(pp+nn)] = s->mtfa[(pp+nn)-1]; nn--;
439  };
440  s->mtfa[pp] = uc;
441  } else {
442  /* general case */
443  lno = nn / MTFL_SIZE;
444  off = nn % MTFL_SIZE;
445  pp = s->mtfbase[lno] + off;
446  uc = s->mtfa[pp];
447  while (pp > s->mtfbase[lno]) {
448  s->mtfa[pp] = s->mtfa[pp-1]; pp--;
449  };
450  s->mtfbase[lno]++;
451  while (lno > 0) {
452  s->mtfbase[lno]--;
453  s->mtfa[s->mtfbase[lno]]
454  = s->mtfa[s->mtfbase[lno-1] + MTFL_SIZE - 1];
455  lno--;
456  }
457  s->mtfbase[0]--;
458  s->mtfa[s->mtfbase[0]] = uc;
459  if (s->mtfbase[0] == 0) {
460  kk = MTFA_SIZE-1;
461  for (ii = 256 / MTFL_SIZE-1; ii >= 0; ii--) {
462  for (jj = MTFL_SIZE-1; jj >= 0; jj--) {
463  s->mtfa[kk] = s->mtfa[s->mtfbase[ii] + jj];
464  kk--;
465  }
466  s->mtfbase[ii] = kk + 1;
467  }
468  }
469  }
470  }
471  /*-- end uc = MTF ( nextSym-1 ) --*/
472 
473  s->unzftab[s->seqToUnseq[uc]]++;
474  if (s->smallDecompress)
475  s->ll16[nblock] = (UInt16)(s->seqToUnseq[uc]); else
476  s->tt[nblock] = (UInt32)(s->seqToUnseq[uc]);
477  nblock++;
478 
479  GET_MTF_VAL(BZ_X_MTF_5, BZ_X_MTF_6, nextSym);
480  continue;
481  }
482  }
483 
484  /* Now we know what nblock is, we can do a better sanity
485  check on s->origPtr.
486  */
487  if (s->origPtr < 0 || s->origPtr >= nblock)
489 
490  /*-- Set up cftab to facilitate generation of T^(-1) --*/
491  s->cftab[0] = 0;
492  for (i = 1; i <= 256; i++) s->cftab[i] = s->unzftab[i-1];
493  for (i = 1; i <= 256; i++) s->cftab[i] += s->cftab[i-1];
494  for (i = 0; i <= 256; i++) {
495  if (s->cftab[i] < 0 || s->cftab[i] > nblock) {
496  /* s->cftab[i] can legitimately be == nblock */
498  }
499  }
500 
501  s->state_out_len = 0;
502  s->state_out_ch = 0;
503  BZ_INITIALISE_CRC ( s->calculatedBlockCRC );
504  s->state = BZ_X_OUTPUT;
505  if (s->verbosity >= 2) VPrintf0 ( "rt+rld" );
506 
507  if (s->smallDecompress) {
508 
509  /*-- Make a copy of cftab, used in generation of T --*/
510  for (i = 0; i <= 256; i++) s->cftabCopy[i] = s->cftab[i];
511 
512  /*-- compute the T vector --*/
513  for (i = 0; i < nblock; i++) {
514  uc = (UChar)(s->ll16[i]);
515  SET_LL(i, s->cftabCopy[uc]);
516  s->cftabCopy[uc]++;
517  }
518 
519  /*-- Compute T^(-1) by pointer reversal on T --*/
520  i = s->origPtr;
521  j = GET_LL(i);
522  do {
523  Int32 tmp = GET_LL(j);
524  SET_LL(j, i);
525  i = j;
526  j = tmp;
527  }
528  while (i != s->origPtr);
529 
530  s->tPos = s->origPtr;
531  s->nblock_used = 0;
532  if (s->blockRandomised) {
534  BZ_GET_SMALL(s->k0); s->nblock_used++;
535  BZ_RAND_UPD_MASK; s->k0 ^= BZ_RAND_MASK;
536  } else {
537  BZ_GET_SMALL(s->k0); s->nblock_used++;
538  }
539 
540  } else {
541 
542  /*-- compute the T^(-1) vector --*/
543  for (i = 0; i < nblock; i++) {
544  uc = (UChar)(s->tt[i] & 0xff);
545  s->tt[s->cftab[uc]] |= (i << 8);
546  s->cftab[uc]++;
547  }
548 
549  s->tPos = s->tt[s->origPtr] >> 8;
550  s->nblock_used = 0;
551  if (s->blockRandomised) {
553  BZ_GET_FAST(s->k0); s->nblock_used++;
554  BZ_RAND_UPD_MASK; s->k0 ^= BZ_RAND_MASK;
555  } else {
556  BZ_GET_FAST(s->k0); s->nblock_used++;
557  }
558 
559  }
560 
561  RETURN(BZ_OK);
562 
563 
564 
565  endhdr_2:
566 
568  if (uc != 0x72) RETURN(BZ_DATA_ERROR);
570  if (uc != 0x45) RETURN(BZ_DATA_ERROR);
572  if (uc != 0x38) RETURN(BZ_DATA_ERROR);
574  if (uc != 0x50) RETURN(BZ_DATA_ERROR);
576  if (uc != 0x90) RETURN(BZ_DATA_ERROR);
577 
578  s->storedCombinedCRC = 0;
579  GET_UCHAR(BZ_X_CCRC_1, uc);
580  s->storedCombinedCRC = (s->storedCombinedCRC << 8) | ((UInt32)uc);
581  GET_UCHAR(BZ_X_CCRC_2, uc);
582  s->storedCombinedCRC = (s->storedCombinedCRC << 8) | ((UInt32)uc);
583  GET_UCHAR(BZ_X_CCRC_3, uc);
584  s->storedCombinedCRC = (s->storedCombinedCRC << 8) | ((UInt32)uc);
585  GET_UCHAR(BZ_X_CCRC_4, uc);
586  s->storedCombinedCRC = (s->storedCombinedCRC << 8) | ((UInt32)uc);
587 
588  s->state = BZ_X_IDLE;
590 
591  default: AssertH ( False, 4001 );
592  }
593 
594  AssertH ( False, 4002 );
595 
596  save_state_and_return:
597 
598  s->save_i = i;
599  s->save_j = j;
600  s->save_t = t;
601  s->save_alphaSize = alphaSize;
602  s->save_nGroups = nGroups;
603  s->save_nSelectors = nSelectors;
604  s->save_EOB = EOB;
605  s->save_groupNo = groupNo;
606  s->save_groupPos = groupPos;
607  s->save_nextSym = nextSym;
608  s->save_nblockMAX = nblockMAX;
609  s->save_nblock = nblock;
610  s->save_es = es;
611  s->save_N = N;
612  s->save_curr = curr;
613  s->save_zt = zt;
614  s->save_zn = zn;
615  s->save_zvec = zvec;
616  s->save_zj = zj;
617  s->save_gSel = gSel;
618  s->save_gMinlen = gMinlen;
619  s->save_gLimit = gLimit;
620  s->save_gBase = gBase;
621  s->save_gPerm = gPerm;
622 
623  return retVal;
624 }
#define MTFA_SIZE
#define BZ_X_CCRC_3
#define BZ_MEM_ERROR
Definition: bzlib.h:41
#define BZ_X_CODING_1
#define BZ_X_ENDHDR_2
#define GET_BIT(lll, uuu)
Definition: decompress.c:73
#define SET_LL(i, n)
#define BZ_X_MAGIC_4
#define BZ_X_MAGIC_1
#define BZ_RAND_INIT_MASK
#define BZ_X_BCRC_1
#define BZ_DATA_ERROR_MAGIC
Definition: bzlib.h:43
static ABC_NAMESPACE_IMPL_START void makeMaps_d(DState *s)
Definition: decompress.c:30
#define BZ_GET_FAST(cccc)
#define BZ_X_ORIGPTR_2
#define BZ_X_CCRC_4
#define VPrintf1(zf, za1)
Definition: bzlib_private.h:77
#define GET_UCHAR(lll, uuu)
Definition: decompress.c:70
#define BZ_RAND_MASK
#define BZ_X_MTF_5
bool pos
Definition: globals.c:30
#define BZ_X_MAPPING_2
#define BZ_X_CODING_2
#define BZ_X_RANDBIT
#define BZ_X_MAGIC_2
#define BZ_RUNB
#define BZALLOC(nnn)
#define BZ_X_BLKHDR_3
for(p=first;p->value< newval;p=p->next)
#define BZ_X_CCRC_1
#define AssertH(cond, errcode)
Definition: bzlib_private.h:61
#define BZ_X_ENDHDR_3
#define GET_BITS(lll, vvv, nnn)
Definition: decompress.c:46
#define BZ_X_BLKHDR_2
#define BZ_X_CODING_3
#define BZ_HDR_B
#define BZ_X_BLKHDR_5
#define BZ_X_SELECTOR_3
#define BZ_OK
Definition: bzlib.h:34
#define BZ_X_OUTPUT
#define BZ_X_BCRC_2
#define BZ_STREAM_END
Definition: bzlib.h:38
#define BZ_X_SELECTOR_2
#define BZ_X_CCRC_2
if(last==0)
Definition: sparse_int.h:34
unsigned char UChar
Definition: bzlib_private.h:45
#define BZ_X_BCRC_3
unsigned int UInt32
Definition: bzlib_private.h:47
#define BZ_X_MTF_1
#define BZ_X_ORIGPTR_3
#define BZ_RAND_UPD_MASK
#define BZ_X_MTF_3
#define BZ_X_SELECTOR_1
#define BZ_X_ENDHDR_4
#define BZ_RUNA
#define BZ_X_ENDHDR_6
#define BZ_N_GROUPS
#define VPrintf0(zf)
Definition: bzlib_private.h:75
#define BZ_X_BLKHDR_1
int Int32
Definition: bzlib_private.h:46
#define BZ_DATA_ERROR
Definition: bzlib.h:42
#define BZ_HDR_0
#define BZ_X_BLKHDR_4
#define BZ_INITIALISE_CRC(crcVar)
#define BZ_HDR_h
#define BZ_X_BCRC_4
#define BZ_X_MAPPING_1
#define BZ_X_MTF_4
#define True
Definition: bzlib_private.h:51
#define BZ_X_MAGIC_3
#define BZ_X_MTF_6
#define BZ_HDR_Z
#define GET_LL(i)
#define False
Definition: bzlib_private.h:52
unsigned short UInt16
Definition: bzlib_private.h:49
#define BZ_X_ORIGPTR_1
#define MTFL_SIZE
#define BZ_X_IDLE
#define BZ_X_BLKHDR_6
#define GET_MTF_VAL(label1, label2, lval)
Definition: decompress.c:77
void BZ2_hbCreateDecodeTables(Int32 *, Int32 *, Int32 *, UChar *, Int32, Int32, Int32)
Definition: huffman.c:173
#define RETURN(rrr)
Definition: decompress.c:43
#define BZ_GET_SMALL(cccc)
#define BZ_X_ENDHDR_5
#define BZ_X_MTF_2
void BZ2_hbAssignCodes ( Int32 ,
UChar ,
Int32  ,
Int32  ,
Int32   
)

Definition at line 155 of file huffman.c.

160 {
161  Int32 n, vec, i;
162 
163  vec = 0;
164  for (n = minLen; n <= maxLen; n++) {
165  for (i = 0; i < alphaSize; i++)
166  if (length[i] == n) { code[i] = vec; vec++; };
167  vec <<= 1;
168  }
169 }
Definition: inftrees.h:26
int Int32
Definition: bzlib_private.h:46
void BZ2_hbCreateDecodeTables ( Int32 ,
Int32 ,
Int32 ,
UChar ,
Int32  ,
Int32  ,
Int32   
)

Definition at line 173 of file huffman.c.

180 {
181  Int32 pp, i, j, vec;
182 
183  pp = 0;
184  for (i = minLen; i <= maxLen; i++)
185  for (j = 0; j < alphaSize; j++)
186  if (length[j] == i) { perm[pp] = j; pp++; };
187 
188  for (i = 0; i < BZ_MAX_CODE_LEN; i++) base[i] = 0;
189  for (i = 0; i < alphaSize; i++) base[length[i]+1]++;
190 
191  for (i = 1; i < BZ_MAX_CODE_LEN; i++) base[i] += base[i-1];
192 
193  for (i = 0; i < BZ_MAX_CODE_LEN; i++) limit[i] = 0;
194  vec = 0;
195 
196  for (i = minLen; i <= maxLen; i++) {
197  vec += (base[i+1] - base[i]);
198  limit[i] = vec-1;
199  vec <<= 1;
200  }
201  for (i = minLen + 1; i <= maxLen; i++)
202  base[i] = ((limit[i-1] + 1) << 1) - base[i];
203 }
int Int32
Definition: bzlib_private.h:46
#define BZ_MAX_CODE_LEN
void BZ2_hbMakeCodeLengths ( UChar ,
Int32 ,
Int32  ,
Int32   
)

Definition at line 66 of file huffman.c.

70 {
71  /*--
72  Nodes and heap entries run from 1. Entry 0
73  for both the heap and nodes is a sentinel.
74  --*/
75  Int32 nNodes, nHeap, n1, n2, i, j, k;
76  Bool tooLong;
77 
78  Int32 heap [ BZ_MAX_ALPHA_SIZE + 2 ];
79  Int32 weight [ BZ_MAX_ALPHA_SIZE * 2 ];
80  Int32 parent [ BZ_MAX_ALPHA_SIZE * 2 ];
81 
82  for (i = 0; i < alphaSize; i++)
83  weight[i+1] = (freq[i] == 0 ? 1 : freq[i]) << 8;
84 
85  while (True) {
86 
87  nNodes = alphaSize;
88  nHeap = 0;
89 
90  heap[0] = 0;
91  weight[0] = 0;
92  parent[0] = -2;
93 
94  for (i = 1; i <= alphaSize; i++) {
95  parent[i] = -1;
96  nHeap++;
97  heap[nHeap] = i;
98  UPHEAP(nHeap);
99  }
100 
101  AssertH( nHeap < (BZ_MAX_ALPHA_SIZE+2), 2001 );
102 
103  while (nHeap > 1) {
104  n1 = heap[1]; heap[1] = heap[nHeap]; nHeap--; DOWNHEAP(1);
105  n2 = heap[1]; heap[1] = heap[nHeap]; nHeap--; DOWNHEAP(1);
106  nNodes++;
107  parent[n1] = parent[n2] = nNodes;
108  weight[nNodes] = ADDWEIGHTS(weight[n1], weight[n2]);
109  parent[nNodes] = -1;
110  nHeap++;
111  heap[nHeap] = nNodes;
112  UPHEAP(nHeap);
113  }
114 
115  AssertH( nNodes < (BZ_MAX_ALPHA_SIZE * 2), 2002 );
116 
117  tooLong = False;
118  for (i = 1; i <= alphaSize; i++) {
119  j = 0;
120  k = i;
121  while (parent[k] >= 0) { k = parent[k]; j++; }
122  len[i-1] = j;
123  if (j > maxLen) tooLong = True;
124  }
125 
126  if (! tooLong) break;
127 
128  /* 17 Oct 04: keep-going condition for the following loop used
129  to be 'i < alphaSize', which missed the last element,
130  theoretically leading to the possibility of the compressor
131  looping. However, this count-scaling step is only needed if
132  one of the generated Huffman code words is longer than
133  maxLen, which up to and including version 1.0.2 was 20 bits,
134  which is extremely unlikely. In version 1.0.3 maxLen was
135  changed to 17 bits, which has minimal effect on compression
136  ratio, but does mean this scaling step is used from time to
137  time, enough to verify that it works.
138 
139  This means that bzip2-1.0.3 and later will only produce
140  Huffman codes with a maximum length of 17 bits. However, in
141  order to preserve backwards compatibility with bitstreams
142  produced by versions pre-1.0.3, the decompressor must still
143  handle lengths of up to 20. */
144 
145  for (i = 1; i <= alphaSize; i++) {
146  j = weight[i] >> 8;
147  j = 1 + (j / 2);
148  weight[i] = j << 8;
149  }
150  }
151 }
#define ADDWEIGHTS(zw1, zw2)
Definition: huffman.c:32
unsigned char Bool
Definition: bzlib_private.h:44
#define AssertH(cond, errcode)
Definition: bzlib_private.h:61
#define UPHEAP(z)
Definition: huffman.c:36
int Int32
Definition: bzlib_private.h:46
#define BZ_MAX_ALPHA_SIZE
#define True
Definition: bzlib_private.h:51
#define False
Definition: bzlib_private.h:52
#define DOWNHEAP(z)
Definition: huffman.c:47
Int32 BZ2_indexIntoF ( Int32  ,
Int32  
)

Definition at line 698 of file bzlib.c.

699 {
700  Int32 nb, na, mid;
701  nb = 0;
702  na = 256;
703  do {
704  mid = (nb + na) >> 1;
705  if (indx >= cftab[mid]) nb = mid; else na = mid;
706  }
707  while (na - nb != 1);
708  return nb;
709 }
int Int32
Definition: bzlib_private.h:46

Variable Documentation

UInt32 BZ2_crc32Table[256]

Definition at line 34 of file crctable.c.

Int32 BZ2_rNums[512]

Definition at line 29 of file randtable.c.