1/* infutil.h -- types and macros common to blocks and codes
2 * Copyright (C) 1995-2002 Mark Adler
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6/* WARNING: this file should *not* be used by applications. It is
7   part of the implementation of the compression library and is
8   subject to change. Applications should only use zlib.h.
9 */
10
11
12/* $Id: infutil.h 14574 2005-10-29 16:27:43Z bonefish $ */
13
14#ifndef _INFUTIL_H
15#define _INFUTIL_H
16
17typedef enum {
18      TYPE,     /* get type bits (3, including end bit) */
19      LENS,     /* get lengths for stored */
20      STORED,   /* processing stored block */
21      TABLE,    /* get table lengths */
22      BTREE,    /* get bit lengths tree for a dynamic block */
23      DTREE,    /* get length, distance trees for a dynamic block */
24      CODES,    /* processing fixed or dynamic block */
25      DRY,      /* output remaining window bytes */
26      DONE,     /* finished last block, done */
27      BAD}      /* got a data error--stuck here */
28inflate_block_mode;
29
30/* inflate blocks semi-private state */
31struct inflate_blocks_state {
32
33  /* mode */
34  inflate_block_mode  mode;     /* current inflate_block mode */
35
36  /* mode dependent information */
37  union {
38    uInt left;          /* if STORED, bytes left to copy */
39    struct {
40      uInt table;               /* table lengths (14 bits) */
41      uInt index;               /* index into blens (or border) */
42      uIntf *blens;             /* bit lengths of codes */
43      uInt bb;                  /* bit length tree depth */
44      inflate_huft *tb;         /* bit length decoding tree */
45    } trees;            /* if DTREE, decoding info for trees */
46    struct {
47      inflate_codes_statef
48         *codes;
49    } decode;           /* if CODES, current state */
50  } sub;                /* submode */
51  uInt last;            /* true if this block is the last block */
52
53  /* mode independent information */
54  uInt bitk;            /* bits in bit buffer */
55  uLong bitb;           /* bit buffer */
56  inflate_huft *hufts;  /* single malloc for tree space */
57  Bytef *window;        /* sliding window */
58  Bytef *end;           /* one byte after sliding window */
59  Bytef *read;          /* window read pointer */
60  Bytef *write;         /* window write pointer */
61  check_func checkfn;   /* check function */
62  uLong check;          /* check on output */
63
64};
65
66
67/* defines for inflate input/output */
68/*   update pointers and return */
69#define UPDBITS {s->bitb=b;s->bitk=k;}
70#define UPDIN {z->avail_in=n;z->total_in+=p-z->next_in;z->next_in=p;}
71#define UPDOUT {s->write=q;}
72#define UPDATE {UPDBITS UPDIN UPDOUT}
73#define LEAVE {UPDATE return inflate_flush(s,z,r);}
74/*   get bytes and bits */
75#define LOADIN {p=z->next_in;n=z->avail_in;b=s->bitb;k=s->bitk;}
76#define NEEDBYTE {if(n)r=Z_OK;else LEAVE}
77#define NEXTBYTE (n--,*p++)
78#define NEEDBITS(j) {while(k<(j)){NEEDBYTE;b|=((uLong)NEXTBYTE)<<k;k+=8;}}
79#define DUMPBITS(j) {b>>=(j);k-=(j);}
80/*   output bytes */
81#define WAVAIL (uInt)(q<s->read?s->read-q-1:s->end-q)
82#define LOADOUT {q=s->write;m=(uInt)WAVAIL;}
83#define WRAP {if(q==s->end&&s->read!=s->window){q=s->window;m=(uInt)WAVAIL;}}
84#define FLUSH {UPDOUT r=inflate_flush(s,z,r); LOADOUT}
85#define NEEDOUT {if(m==0){WRAP if(m==0){FLUSH WRAP if(m==0) LEAVE}}r=Z_OK;}
86#define OUTBYTE(a) {*q++=(Byte)(a);m--;}
87/*   load local pointers */
88#define LOAD {LOADIN LOADOUT}
89
90/* masks for lower bits (size given to avoid silly warnings with Visual C++) */
91extern uInt inflate_mask[17];
92
93/* copy as much as possible from the sliding window to the output area */
94extern int inflate_flush OF((
95    inflate_blocks_statef *,
96    z_streamp ,
97    int));
98
99/* PDFlib GmbH: conflicts with Visual Studio.NET
100struct internal_state      {int dummy;}; *//* for buggy compilers */
101
102#endif
103