home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 March / CMCD0304.ISO / Software / Freeware / Programare / nullsoft / nsis20.exe / Source / bzip2 / bzlib.h < prev    next >
C/C++ Source or Header  |  2004-01-05  |  12KB  |  437 lines

  1.  
  2. /*-------------------------------------------------------------*/
  3. /*--- Public header file for the library.                   ---*/
  4. /*---                                               bzlib.h ---*/
  5. /*-------------------------------------------------------------*/
  6.  
  7. // (this has been hacked to pieces by dave laundon and justin frankel,
  8. //  and others, to make it small for nsis. it is not compatible with
  9. //  bzip2 any longer. yay. )
  10.  
  11. /*--
  12.   This file is a part of bzip2 and/or libbzip2, a program and
  13.   library for lossless, block-sorting data compression.
  14.  
  15.   Copyright (C) 1996-2000 Julian R Seward.  All rights reserved.
  16.  
  17.   Redistribution and use in source and binary forms, with or without
  18.   modification, are permitted provided that the following conditions
  19.   are met:
  20.  
  21.   1. Redistributions of source code must retain the above copyright
  22.      notice, this list of conditions and the following disclaimer.
  23.  
  24.   2. The origin of this software must not be misrepresented; you must
  25.      not claim that you wrote the original software.  If you use this
  26.      software in a product, an acknowledgment in the product
  27.      documentation would be appreciated but is not required.
  28.  
  29.   3. Altered source versions must be plainly marked as such, and must
  30.      not be misrepresented as being the original software.
  31.  
  32.   4. The name of the author may not be used to endorse or promote
  33.      products derived from this software without specific prior written
  34.      permission.
  35.  
  36.   THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
  37.   OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  38.   WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  39.   ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  40.   DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  41.   DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  42.   GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  43.   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  44.   WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  45.   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  46.   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  47.  
  48.   Julian Seward, Cambridge, UK.
  49.   jseward@acm.org
  50.   bzip2/libbzip2 version 1.0 of 21 March 2000
  51.  
  52.   This program is based on (at least) the work of:
  53.      Mike Burrows
  54.      David Wheeler
  55.      Peter Fenwick
  56.      Alistair Moffat
  57.      Radford Neal
  58.      Ian H. Witten
  59.      Robert Sedgewick
  60.      Jon L. Bentley
  61.  
  62.   For more information on these sources, see the manual.
  63. --*/
  64.  
  65.  
  66. #ifndef _BZLIB_H
  67. #define _BZLIB_H
  68.  
  69. #ifdef __cplusplus
  70. extern "C" {
  71. #endif
  72.  
  73. #include "../exehead/config.h"
  74. #include <windows.h>
  75.  
  76. #define BZ_RUN               0
  77. #define BZ_FLUSH             1
  78. #define BZ_FINISH            2
  79.  
  80. #define BZ_OK                0
  81. #define BZ_RUN_OK            1
  82. #define BZ_FLUSH_OK          2
  83. #define BZ_FINISH_OK         3
  84. #define BZ_STREAM_END        4
  85. #define BZ_SEQUENCE_ERROR    (-1)
  86. #define BZ_PARAM_ERROR       (-2)
  87. #define BZ_MEM_ERROR         (-3)
  88. #define BZ_DATA_ERROR        (-4)
  89. #define BZ_DATA_ERROR_MAGIC  (-5)
  90. #define BZ_IO_ERROR          (-6)
  91. #define BZ_UNEXPECTED_EOF    (-7)
  92. #define BZ_OUTBUFF_FULL      (-8)
  93. #define BZ_CONFIG_ERROR      (-9)
  94.  
  95. /*-- Constants for the back end. --*/
  96.  
  97. #define BZ_MAX_ALPHA_SIZE 258
  98. #define BZ_MAX_CODE_LEN    23
  99.  
  100. #define BZ_RUNA 0
  101. #define BZ_RUNB 1
  102.  
  103. #define BZ_N_GROUPS 6
  104. #define BZ_G_SIZE   50
  105. #define BZ_N_ITERS  4
  106.  
  107. #define BZ_MAX_SELECTORS (2 + (900000 / BZ_G_SIZE))
  108.  
  109. typedef char            Char;
  110. typedef unsigned char   Bool;
  111. typedef unsigned char   UChar;
  112. typedef int             Int32;
  113. typedef unsigned int    UInt32;
  114. typedef short           Int16;
  115. typedef unsigned short  UInt16;
  116.  
  117. #define True  ((Bool)1)
  118. #define False ((Bool)0)
  119.  
  120. #define AssertD(cond,msg) /* */
  121. #define AssertH(cond,errcode) /* */
  122. #define AssertD(cond,msg) /* */
  123. #define VPrintf0(zf) /* */
  124. #define VPrintf1(zf,za1) /* */
  125. #define VPrintf2(zf,za1,za2) /* */
  126. #define VPrintf3(zf,za1,za2,za3) /* */
  127. #define VPrintf4(zf,za1,za2,za3,za4) /* */
  128. #define VPrintf5(zf,za1,za2,za3,za4,za5) /* */
  129.  
  130. #ifndef EXEHEAD
  131.  
  132. #define BZALLOC(items) GlobalAlloc(GPTR,items)
  133. #define BZFREE(addr)  { if (addr) GlobalFree(addr); }
  134. #define mini_memcpy memcpy
  135.  
  136. typedef struct {
  137.   char *next_in;
  138.   unsigned int avail_in;
  139.  
  140.   char *next_out;
  141.   unsigned int avail_out;
  142.  
  143.   void *state;
  144. } bz_stream;
  145.  
  146. /*-- Core (low-level) library functions --*/
  147.  
  148. extern int BZ2_bzCompressInit(
  149.       bz_stream* strm,
  150.       int        blockSize100k,
  151.       int        verbosity,
  152.       int        workFactor
  153.    );
  154.  
  155. extern int BZ2_bzCompress( bz_stream* strm, int action );
  156. extern int BZ2_bzCompressEnd(bz_stream* strm );
  157.  
  158. /*-- States and modes for compression. --*/
  159.  
  160. #define BZ_M_IDLE      1
  161. #define BZ_M_RUNNING   2
  162. #define BZ_M_FLUSHING  3
  163. #define BZ_M_FINISHING 4
  164.  
  165. #define BZ_S_OUTPUT    1
  166. #define BZ_S_INPUT     2
  167.  
  168. #define BZ_N_RADIX 2
  169. #define BZ_N_QSORT 12
  170. #define BZ_N_SHELL 18
  171. #define BZ_N_OVERSHOOT (BZ_N_RADIX + BZ_N_QSORT + BZ_N_SHELL + 2)
  172.  
  173. /*-- Structure holding all the compression-side stuff. --*/
  174.  
  175. typedef struct {
  176.   /* pointer back to the struct bz_stream */
  177.   bz_stream *strm;
  178.  
  179.   /* mode this stream is in, and whether inputting */
  180.   /* or outputting data */
  181.   Int32    mode;
  182.   Int32    state;
  183.  
  184.   /* remembers avail_in when flush/finish requested */
  185.   UInt32   avail_in_expect;
  186.  
  187.   /* for doing the block sorting */
  188.   UInt32*  arr1;
  189.   UInt32*  arr2;
  190.   UInt32*  ftab;
  191.   Int32    origPtr;
  192.  
  193.   /* aliases for arr1 and arr2 */
  194.   UInt32*  ptr;
  195.   UChar*   block;
  196.   UInt16*  mtfv;
  197.   UChar*   zbits;
  198.  
  199.   /* for deciding when to use the fallback sorting algorithm */
  200.   Int32    workFactor;
  201.  
  202.   /* run-length-encoding of the input */
  203.   UInt32   state_in_ch;
  204.   Int32    state_in_len;
  205.  
  206.   /* input and output limits and current posns */
  207.   Int32    nblock;
  208.   Int32    nblockMAX;
  209.   Int32    numZ;
  210.   Int32    state_out_pos;
  211.  
  212.   /* map of bytes used in block */
  213.   Int32    nInUse;
  214.   Bool     inUse[256];
  215.   UChar    unseqToSeq[256];
  216.  
  217.   /* the buffer for bit stream creation */
  218.   UInt32   bsBuff;
  219.   Int32    bsLive;
  220.  
  221.   /* misc administratium */
  222.   Int32    blockNo;
  223.  
  224.   /* stuff for coding the MTF values */
  225.   Int32    nMTF;
  226.   Int32    mtfFreq    [BZ_MAX_ALPHA_SIZE];
  227.   UChar    selector   [BZ_MAX_SELECTORS];
  228.   UChar    selectorMtf[BZ_MAX_SELECTORS];
  229.  
  230.   UChar    len     [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
  231.   Int32    code    [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
  232.   Int32    rfreq   [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
  233.   /* second dimension: only 3 needed; 4 makes index calculations faster */
  234.   UInt32   len_pack[BZ_MAX_ALPHA_SIZE][4];
  235.  
  236. } EState;
  237.  
  238.  
  239.  
  240. /*-- externs for compression. --*/
  241.  
  242. extern void BZ2_blockSort ( EState* );
  243. extern void BZ2_compressBlock ( EState*, Bool );
  244. extern void BZ2_bsInitWrite ( EState* );
  245. extern void BZ2_hbAssignCodes ( Int32*, UChar*, Int32, Int32, Int32 );
  246. extern void BZ2_hbMakeCodeLengths ( UChar*, Int32*, Int32, Int32 );
  247.  
  248. #else//EXEHEAD
  249.  
  250. #include "../exehead/util.h"
  251.  
  252. /*-- states for decompression. --*/
  253.  
  254. #define BZ_X_IDLE        1
  255. #define BZ_X_OUTPUT      2
  256.  
  257. #define BZ_X_BLKHDR_1    11
  258. #define BZ_X_RANDBIT     12
  259. #define BZ_X_ORIGPTR_1   13
  260. #define BZ_X_ORIGPTR_2   14
  261. #define BZ_X_ORIGPTR_3   15
  262. #define BZ_X_MAPPING_1   16
  263. #define BZ_X_MAPPING_2   17
  264. #define BZ_X_SELECTOR_1  18
  265. #define BZ_X_SELECTOR_2  19
  266. #define BZ_X_SELECTOR_3  20
  267. #define BZ_X_CODING_1    21
  268. #define BZ_X_CODING_2    22
  269. #define BZ_X_CODING_3    23
  270. #define BZ_X_MTF_1       24
  271. #define BZ_X_MTF_2       25
  272. #define BZ_X_MTF_3       26
  273. #define BZ_X_MTF_4       27
  274. #define BZ_X_MTF_5       28
  275. #define BZ_X_MTF_6       29
  276.  
  277.  
  278.  
  279. /*-- Constants for the fast MTF decoder. --*/
  280.  
  281. #define MTFA_SIZE 4096
  282. #define MTFL_SIZE 16
  283.  
  284.  
  285.  
  286. /* save area for scalars in the main decompress code */
  287. typedef struct {
  288.   Int32    i;
  289.   Int32    j;
  290.   Int32    t;
  291.   Int32    alphaSize;
  292.   Int32    nGroups;
  293.   Int32    nSelectors;
  294.   Int32    EOB;
  295.   Int32    groupNo;
  296.   Int32    groupPos;
  297.   Int32    nextSym;
  298.   Int32    nblockMAX;
  299.   Int32    nblock;
  300.   Int32    es;
  301.   Int32    N;
  302.   Int32    curr;
  303.   Int32    zt;
  304.   Int32    zn;
  305.   Int32    zvec;
  306.   Int32    zj;
  307.   Int32    gSel;
  308.   Int32    gMinlen;
  309.   Int32*   gLimit;
  310.   Int32*   gBase;
  311.   Int32*   gPerm;
  312. } DState_save;
  313.  
  314. /*-- Structure holding all the decompression-side stuff. --*/
  315.  
  316. typedef struct {
  317.   /* pointer back to the struct bz_stream */
  318.   char *next_in;
  319.   unsigned int avail_in;
  320.  
  321.   char *next_out;
  322.   unsigned int avail_out;
  323.  
  324.   /* state indicator for this stream */
  325.   char state;
  326.  
  327.   UChar    state_out_ch;
  328.   Int32    state_out_len;
  329.   Int32    nblock_used;
  330.   Int32    k0;
  331.   UInt32   tPos;
  332.  
  333.   /* the buffer for bit stream reading */
  334.   UInt32   bsBuff;
  335.   Int32    bsLive;
  336.  
  337.   /* for undoing the Burrows-Wheeler transform */
  338.   Int32    origPtr;
  339.   Int32    unzftab[256];
  340.   Int32    cftab[257];
  341.   Int32    cftabCopy[257];
  342.  
  343. #ifndef NSIS_COMPRESS_BZIP2_SMALLMODE
  344.   /* for undoing the Burrows-Wheeler transform (FAST) */
  345.   UInt32   tt[ NSIS_COMPRESS_BZIP2_LEVEL * 100000 ];
  346. #else
  347.   /* for undoing the Burrows-Wheeler transform (SMALL) */
  348.   UInt16   ll16 [ NSIS_COMPRESS_BZIP2_LEVEL*100000 ];
  349.   UChar    ll4 [((1 + NSIS_COMPRESS_BZIP2_LEVEL*100000) >> 1) ];
  350. #endif
  351.  
  352.   /* map of bytes used in block */
  353.   Int32    nInUse;
  354.   Bool     inUse[256];
  355.   Bool     inUse16[16];
  356.   UChar    seqToUnseq[256];
  357.  
  358.   /* for decoding the MTF values */
  359.   UChar    mtfa   [MTFA_SIZE];
  360.   Int32    mtfbase[256 / MTFL_SIZE];
  361.   UChar    selector   [BZ_MAX_SELECTORS];
  362.   UChar    selectorMtf[BZ_MAX_SELECTORS];
  363.   UChar    len  [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
  364.  
  365.   Int32    limit  [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
  366.   Int32    base   [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
  367.   Int32    perm   [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
  368.   Int32    minLens[BZ_N_GROUPS];
  369.  
  370.   /* save area for scalars in the main decompress code */
  371.   DState_save save;
  372. } DState;
  373.  
  374.  
  375. #ifndef NSIS_COMPRESS_BZIP2_SMALLMODE
  376. /*-- Macros for decompression. --*/
  377.  
  378. #define BZ_GET_FAST(cccc)                     \
  379.     s->tPos = s->tt[s->tPos];                 \
  380.     cccc = (UChar)(s->tPos & 0xff);           \
  381.     s->tPos >>= 8;
  382.  
  383. #define BZ_GET_FAST_C(cccc)                   \
  384.     c_tPos = c_tt[c_tPos];                    \
  385.     cccc = (UChar)(c_tPos & 0xff);            \
  386.     c_tPos >>= 8;
  387.  
  388.  
  389. #else//NSIS_COMPRESS_BZIP2_SMALLMODE
  390.  
  391. #define SET_LL4(i,n)                                          \
  392.    { if (((i) & 0x1) == 0)                                    \
  393.         s->ll4[(i) >> 1] = (s->ll4[(i) >> 1] & 0xf0) | (n); else    \
  394.         s->ll4[(i) >> 1] = (s->ll4[(i) >> 1] & 0x0f) | ((n) << 4);  \
  395.    }
  396.  
  397. #define GET_LL4(i)                             \
  398.    ((((UInt32)(s->ll4[(i) >> 1])) >> (((i) << 2) & 0x4)) & 0xF)
  399.  
  400. #define SET_LL(i,n)                          \
  401.    { s->ll16[i] = (UInt16)(n & 0x0000ffff);  \
  402.      SET_LL4(i, n >> 16);                    \
  403.    }
  404.  
  405. #define GET_LL(i) \
  406.    (((UInt32)s->ll16[i]) | (GET_LL4(i) << 16))
  407.  
  408. #define BZ_GET_SMALL(cccc)                            \
  409.       cccc = BZ2_indexIntoF ( s->tPos, s->cftab );    \
  410.       s->tPos = GET_LL(s->tPos);
  411.  
  412. extern Int32 BZ2_indexIntoF( Int32, Int32* );
  413.  
  414. #endif//smallmode
  415.  
  416. /*-- externs for decompression. --*/
  417. extern Int32 BZ2_decompress ( DState* );
  418.  
  419. extern void BZ2_hbCreateDecodeTables ( Int32*, Int32*, Int32*, UChar*,
  420.                            Int32,  Int32, Int32 );
  421.  
  422.  
  423. #define BZ2_bzDecompressInit(s) { (s)->state = BZ_X_BLKHDR_1; (s)->bsLive = 0; }
  424. int NSISCALL BZ2_bzDecompress(DState *s);
  425.  
  426. #endif//EXEHEAD
  427.  
  428. #ifdef __cplusplus
  429. }
  430. #endif
  431.  
  432. #endif
  433.  
  434. /*-------------------------------------------------------------*/
  435. /*--- end                                           bzlib.h ---*/
  436. /*-------------------------------------------------------------*/
  437.