infutil.h 3.6 KB

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