Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
3.6 KiB

  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. /* 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_codes_statef
  39. *codes;
  40. } decode; /* if CODES, current state */
  41. } sub; /* submode */
  42. uInt last; /* true if this block is the last block */
  43. /* mode independent information */
  44. uInt bitk; /* bits in bit buffer */
  45. uLong bitb; /* bit buffer */
  46. inflate_huft *hufts; /* single malloc for tree space */
  47. Bytef *window; /* sliding window */
  48. Bytef *end; /* one byte after sliding window */
  49. Bytef *read; /* window read pointer */
  50. Bytef *write; /* window write pointer */
  51. check_func checkfn; /* check function */
  52. uLong check; /* check on output */
  53. };
  54. /* defines for inflate input/output */
  55. /* update pointers and return */
  56. #define UPDBITS {s->bitb=b;s->bitk=k;}
  57. #define UPDIN {z->avail_in=n;z->total_in+=(uLong)(p-z->next_in);z->next_in=p;}
  58. #define UPDOUT {s->write=q;}
  59. #define UPDATE {UPDBITS UPDIN UPDOUT}
  60. #define LEAVE {UPDATE return inflate_flush(s,z,r);}
  61. /* get bytes and bits */
  62. #define LOADIN {p=z->next_in;n=z->avail_in;b=s->bitb;k=s->bitk;}
  63. #define NEEDBYTE {if(n)r=Z_OK;else LEAVE}
  64. #define NEXTBYTE (n--,*p++)
  65. #define NEEDBITS(j) {while(k<(j)){NEEDBYTE;b|=((uLong)NEXTBYTE)<<k;k+=8;}}
  66. #define DUMPBITS(j) {b>>=(j);k-=(j);}
  67. /* output bytes */
  68. #define WAVAIL (uInt)(q<s->read?s->read-q-1:s->end-q)
  69. #define LOADOUT {q=s->write;m=(uInt)WAVAIL;}
  70. #define WRAP {if(q==s->end&&s->read!=s->window){q=s->window;m=(uInt)WAVAIL;}}
  71. #define FLUSH {UPDOUT r=inflate_flush(s,z,r); LOADOUT}
  72. #define NEEDOUT {if(m==0){WRAP if(m==0){FLUSH WRAP if(m==0) LEAVE}}r=Z_OK;}
  73. #define OUTBYTE(a) {*q++=(Byte)(a);m--;}
  74. /* load local pointers */
  75. #define LOAD {LOADIN LOADOUT}
  76. /* masks for lower bits (size given to avoid silly warnings with Visual C++) */
  77. extern uInt inflate_mask[17];
  78. /* copy as much as possible from the sliding window to the output area */
  79. extern int inflate_flush OF((
  80. inflate_blocks_statef *,
  81. z_streamp ,
  82. int));
  83. struct internal_state {int dummy;}; /* for buggy compilers */
  84. #endif