author  Ryan C. Gordon <icculus@icculus.org> 
Sun, 07 Dec 2003 05:29:20 +0000  
changeset 602  691c1eadb8b7 
permissions  rwrr 
602
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1 
/* inflate.c  zlib decompression 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

2 
* Copyright (C) 19952003 Mark Adler 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

3 
* For conditions of distribution and use, see copyright notice in zlib.h 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

4 
*/ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

5 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

6 
/* 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

7 
* Change history: 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

8 
* 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

9 
* 1.2.beta0 24 Nov 2002 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

10 
*  First version  complete rewrite of inflate to simplify code, avoid 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

11 
* creation of window when not needed, minimize use of window when it is 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

12 
* needed, make inffast.c even faster, implement gzip decoding, and to 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

13 
* improve code readability and style over the previous zlib inflate code 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

14 
* 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

15 
* 1.2.beta1 25 Nov 2002 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

16 
*  Use pointers for available input and output checking in inffast.c 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

17 
*  Remove input and output counters in inffast.c 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

18 
*  Change inffast.c entry and loop from avail_in >= 7 to >= 6 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

19 
*  Remove unnecessary second byte pull from length extra in inffast.c 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

20 
*  Unroll direct copy to three copies per loop in inffast.c 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

21 
* 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

22 
* 1.2.beta2 4 Dec 2002 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

23 
*  Change external routine names to reduce potential conflicts 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

24 
*  Correct filename to inffixed.h for fixed tables in inflate.c 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

25 
*  Make hbuf[] unsigned char to match parameter type in inflate.c 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

26 
*  Change strm>next_out[state>offset] to *(strm>next_out  state>offset) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

27 
* to avoid negation problem on Alphas (64 bit) in inflate.c 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

28 
* 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

29 
* 1.2.beta3 22 Dec 2002 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

30 
*  Add comments on state>bits assertion in inffast.c 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

31 
*  Add comments on op field in inftrees.h 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

32 
*  Fix bug in reuse of allocated window after inflateReset() 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

33 
*  Remove bit fieldsback to byte structure for speed 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

34 
*  Remove distance extra == 0 check in inflate_fast()only helps for lengths 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

35 
*  Change postincrements to preincrements in inflate_fast(), PPC biased? 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

36 
*  Add compile time option, POSTINC, to use postincrements instead (Intel?) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

37 
*  Make MATCH copy in inflate() much faster for when inflate_fast() not used 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

38 
*  Use local copies of stream next and avail values, as well as local bit 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

39 
* buffer and bit count in inflate()for speed when inflate_fast() not used 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

40 
* 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

41 
* 1.2.beta4 1 Jan 2003 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

42 
*  Split ptr  257 statements in inflate_table() to avoid compiler warnings 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

43 
*  Move a comment on output buffer sizes from inffast.c to inflate.c 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

44 
*  Add comments in inffast.c to introduce the inflate_fast() routine 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

45 
*  Rearrange window copies in inflate_fast() for speed and simplification 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

46 
*  Unroll last copy for window match in inflate_fast() 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

47 
*  Use local copies of window variables in inflate_fast() for speed 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

48 
*  Pull out common write == 0 case for speed in inflate_fast() 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

49 
*  Make op and len in inflate_fast() unsigned for consistency 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

50 
*  Add FAR to lcode and dcode declarations in inflate_fast() 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

51 
*  Simplified bad distance check in inflate_fast() 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

52 
*  Added inflateBackInit(), inflateBack(), and inflateBackEnd() in new 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

53 
* source file infback.c to provide a callback interface to inflate for 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

54 
* programs like gzip and unzip  uses window as output buffer to avoid 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

55 
* window copying 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

56 
* 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

57 
* 1.2.beta5 1 Jan 2003 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

58 
*  Improved inflateBack() interface to allow the caller to provide initial 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

59 
* input in strm. 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

60 
*  Fixed stored blocks bug in inflateBack() 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

61 
* 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

62 
* 1.2.beta6 4 Jan 2003 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

63 
*  Added comments in inffast.c on effectiveness of POSTINC 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

64 
*  Typecasting all around to reduce compiler warnings 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

65 
*  Changed loops from while (1) or do {} while (1) to for (;;), again to 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

66 
* make compilers happy 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

67 
*  Changed type of window in inflateBackInit() to unsigned char * 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

68 
* 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

69 
* 1.2.beta7 27 Jan 2003 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

70 
*  Changed many types to unsigned or unsigned short to avoid warnings 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

71 
*  Added inflateCopy() function 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

72 
* 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

73 
* 1.2.0 9 Mar 2003 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

74 
*  Changed inflateBack() interface to provide separate opaque descriptors 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

75 
* for the in() and out() functions 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

76 
*  Changed inflateBack() argument and in_func typedef to swap the length 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

77 
* and buffer address return values for the input function 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

78 
*  Check next_in and next_out for Z_NULL on entry to inflate() 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

79 
* 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

80 
* The history for versions after 1.2.0 are in ChangeLog in zlib distribution. 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

81 
*/ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

82 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

83 
#include "zutil.h" 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

84 
#include "inftrees.h" 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

85 
#include "inflate.h" 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

86 
#include "inffast.h" 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

87 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

88 
#ifdef MAKEFIXED 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

89 
# ifndef BUILDFIXED 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

90 
# define BUILDFIXED 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

91 
# endif 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

92 
#endif 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

93 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

94 
/* function prototypes */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

95 
local void fixedtables OF((struct inflate_state FAR *state)); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

96 
local int updatewindow OF((z_streamp strm, unsigned out)); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

97 
#ifdef BUILDFIXED 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

98 
void makefixed OF((void)); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

99 
#endif 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

100 
local unsigned syncsearch OF((unsigned FAR *have, unsigned char FAR *buf, 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

101 
unsigned len)); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

102 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

103 
int ZEXPORT inflateReset(strm) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

104 
z_streamp strm; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

105 
{ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

106 
struct inflate_state FAR *state; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

107 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

108 
if (strm == Z_NULL  strm>state == Z_NULL) return Z_STREAM_ERROR; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

109 
state = (struct inflate_state FAR *)strm>state; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

110 
strm>total_in = strm>total_out = state>total = 0; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

111 
strm>msg = Z_NULL; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

112 
state>mode = HEAD; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

113 
state>last = 0; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

114 
state>havedict = 0; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

115 
state>wsize = 0; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

116 
state>whave = 0; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

117 
state>hold = 0; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

118 
state>bits = 0; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

119 
state>lencode = state>distcode = state>next = state>codes; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

120 
Tracev((stderr, "inflate: reset\n")); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

121 
return Z_OK; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

122 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

123 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

124 
int ZEXPORT inflateInit2_(strm, windowBits, version, stream_size) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

125 
z_streamp strm; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

126 
int windowBits; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

127 
const char *version; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

128 
int stream_size; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

129 
{ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

130 
struct inflate_state FAR *state; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

131 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

132 
if (version == Z_NULL  version[0] != ZLIB_VERSION[0]  
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

133 
stream_size != (int)(sizeof(z_stream))) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

134 
return Z_VERSION_ERROR; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

135 
if (strm == Z_NULL) return Z_STREAM_ERROR; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

136 
strm>msg = Z_NULL; /* in case we return an error */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

137 
if (strm>zalloc == (alloc_func)0) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

138 
strm>zalloc = zcalloc; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

139 
strm>opaque = (voidpf)0; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

140 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

141 
if (strm>zfree == (free_func)0) strm>zfree = zcfree; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

142 
state = (struct inflate_state FAR *) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

143 
ZALLOC(strm, 1, sizeof(struct inflate_state)); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

144 
if (state == Z_NULL) return Z_MEM_ERROR; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

145 
Tracev((stderr, "inflate: allocated\n")); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

146 
strm>state = (voidpf)state; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

147 
if (windowBits < 0) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

148 
state>wrap = 0; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

149 
windowBits = windowBits; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

150 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

151 
else { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

152 
state>wrap = (windowBits >> 4) + 1; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

153 
#ifdef GUNZIP 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

154 
if (windowBits < 48) windowBits &= 15; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

155 
#endif 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

156 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

157 
if (windowBits < 8  windowBits > 15) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

158 
ZFREE(strm, state); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

159 
strm>state = Z_NULL; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

160 
return Z_STREAM_ERROR; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

161 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

162 
state>wbits = (unsigned)windowBits; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

163 
state>window = Z_NULL; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

164 
return inflateReset(strm); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

165 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

166 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

167 
int ZEXPORT inflateInit_(strm, version, stream_size) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

168 
z_streamp strm; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

169 
const char *version; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

170 
int stream_size; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

171 
{ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

172 
return inflateInit2_(strm, DEF_WBITS, version, stream_size); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

173 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

174 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

175 
/* 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

176 
Return state with length and distance decoding tables and index sizes set to 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

177 
fixed code decoding. Normally this returns fixed tables from inffixed.h. 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

178 
If BUILDFIXED is defined, then instead this routine builds the tables the 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

179 
first time it's called, and returns those tables the first time and 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

180 
thereafter. This reduces the size of the code by about 2K bytes, in 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

181 
exchange for a little execution time. However, BUILDFIXED should not be 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

182 
used for threaded applications, since the rewriting of the tables and virgin 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

183 
may not be threadsafe. 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

184 
*/ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

185 
local void fixedtables(state) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

186 
struct inflate_state FAR *state; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

187 
{ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

188 
#ifdef BUILDFIXED 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

189 
static int virgin = 1; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

190 
static code *lenfix, *distfix; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

191 
static code fixed[544]; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

192 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

193 
/* build fixed huffman tables if first call (may not be thread safe) */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

194 
if (virgin) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

195 
unsigned sym, bits; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

196 
static code *next; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

197 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

198 
/* literal/length table */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

199 
sym = 0; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

200 
while (sym < 144) state>lens[sym++] = 8; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

201 
while (sym < 256) state>lens[sym++] = 9; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

202 
while (sym < 280) state>lens[sym++] = 7; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

203 
while (sym < 288) state>lens[sym++] = 8; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

204 
next = fixed; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

205 
lenfix = next; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

206 
bits = 9; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

207 
inflate_table(LENS, state>lens, 288, &(next), &(bits), state>work); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

208 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

209 
/* distance table */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

210 
sym = 0; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

211 
while (sym < 32) state>lens[sym++] = 5; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

212 
distfix = next; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

213 
bits = 5; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

214 
inflate_table(DISTS, state>lens, 32, &(next), &(bits), state>work); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

215 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

216 
/* do this just once */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

217 
virgin = 0; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

218 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

219 
#else /* !BUILDFIXED */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

220 
# include "inffixed.h" 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

221 
#endif /* BUILDFIXED */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

222 
state>lencode = lenfix; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

223 
state>lenbits = 9; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

224 
state>distcode = distfix; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

225 
state>distbits = 5; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

226 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

227 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

228 
#ifdef MAKEFIXED 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

229 
#include <stdio.h> 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

230 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

231 
/* 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

232 
Write out the inffixed.h that is #include'd above. Defining MAKEFIXED also 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

233 
defines BUILDFIXED, so the tables are built on the fly. makefixed() writes 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

234 
those tables to stdout, which would be piped to inffixed.h. A small program 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

235 
can simply call makefixed to do this: 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

236 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

237 
void makefixed(void); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

238 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

239 
int main(void) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

240 
{ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

241 
makefixed(); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

242 
return 0; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

243 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

244 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

245 
Then that can be linked with zlib built with MAKEFIXED defined and run: 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

246 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

247 
a.out > inffixed.h 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

248 
*/ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

249 
void makefixed() 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

250 
{ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

251 
unsigned low, size; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

252 
struct inflate_state state; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

253 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

254 
fixedtables(&state); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

255 
puts(" /* inffixed.h  table for decoding fixed codes"); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

256 
puts(" * Generated automatically by makefixed()."); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

257 
puts(" */"); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

258 
puts(""); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

259 
puts(" /* WARNING: this file should *not* be used by applications."); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

260 
puts(" It is part of the implementation of this library and is"); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

261 
puts(" subject to change. Applications should only use zlib.h."); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

262 
puts(" */"); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

263 
puts(""); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

264 
size = 1U << 9; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

265 
printf(" static const code lenfix[%u] = {", size); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

266 
low = 0; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

267 
for (;;) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

268 
if ((low % 7) == 0) printf("\n "); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

269 
printf("{%u,%u,%d}", state.lencode[low].op, state.lencode[low].bits, 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

270 
state.lencode[low].val); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

271 
if (++low == size) break; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

272 
putchar(','); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

273 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

274 
puts("\n };"); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

275 
size = 1U << 5; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

276 
printf("\n static const code distfix[%u] = {", size); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

277 
low = 0; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

278 
for (;;) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

279 
if ((low % 6) == 0) printf("\n "); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

280 
printf("{%u,%u,%d}", state.distcode[low].op, state.distcode[low].bits, 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

281 
state.distcode[low].val); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

282 
if (++low == size) break; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

283 
putchar(','); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

284 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

285 
puts("\n };"); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

286 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

287 
#endif /* MAKEFIXED */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

288 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

289 
/* 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

290 
Update the window with the last wsize (normally 32K) bytes written before 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

291 
returning. If window does not exist yet, create it. This is only called 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

292 
when a window is already in use, or when output has been written during this 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

293 
inflate call, but the end of the deflate stream has not been reached yet. 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

294 
It is also called to create a window for dictionary data when a dictionary 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

295 
is loaded. 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

296 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

297 
Providing output buffers larger than 32K to inflate() should provide a speed 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

298 
advantage, since only the last 32K of output is copied to the sliding window 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

299 
upon return from inflate(), and since all distances after the first 32K of 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

300 
output will fall in the output data, making match copies simpler and faster. 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

301 
The advantage may be dependent on the size of the processor's data caches. 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

302 
*/ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

303 
local int updatewindow(strm, out) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

304 
z_streamp strm; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

305 
unsigned out; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

306 
{ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

307 
struct inflate_state FAR *state; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

308 
unsigned copy, dist; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

309 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

310 
state = (struct inflate_state FAR *)strm>state; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

311 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

312 
/* if it hasn't been done already, allocate space for the window */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

313 
if (state>window == Z_NULL) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

314 
state>window = (unsigned char FAR *) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

315 
ZALLOC(strm, 1U << state>wbits, 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

316 
sizeof(unsigned char)); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

317 
if (state>window == Z_NULL) return 1; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

318 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

319 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

320 
/* if window not in use yet, initialize */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

321 
if (state>wsize == 0) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

322 
state>wsize = 1U << state>wbits; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

323 
state>write = 0; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

324 
state>whave = 0; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

325 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

326 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

327 
/* copy state>wsize or less output bytes into the circular window */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

328 
copy = out  strm>avail_out; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

329 
if (copy >= state>wsize) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

330 
zmemcpy(state>window, strm>next_out  state>wsize, state>wsize); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

331 
state>write = 0; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

332 
state>whave = state>wsize; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

333 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

334 
else { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

335 
dist = state>wsize  state>write; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

336 
if (dist > copy) dist = copy; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

337 
zmemcpy(state>window + state>write, strm>next_out  copy, dist); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

338 
copy = dist; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

339 
if (copy) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

340 
zmemcpy(state>window, strm>next_out  copy, copy); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

341 
state>write = copy; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

342 
state>whave = state>wsize; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

343 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

344 
else { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

345 
state>write += dist; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

346 
if (state>write == state>wsize) state>write = 0; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

347 
if (state>whave < state>wsize) state>whave += dist; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

348 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

349 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

350 
return 0; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

351 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

352 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

353 
/* Macros for inflate(): */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

354 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

355 
/* check function to use adler32() for zlib or crc32() for gzip */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

356 
#ifdef GUNZIP 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

357 
# define UPDATE(check, buf, len) \ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

358 
(state>flags ? crc32(check, buf, len) : adler32(check, buf, len)) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

359 
#else 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

360 
# define UPDATE(check, buf, len) adler32(check, buf, len) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

361 
#endif 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

362 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

363 
/* check macros for header crc */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

364 
#ifdef GUNZIP 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

365 
# define CRC2(check, word) \ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

366 
do { \ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

367 
hbuf[0] = (unsigned char)(word); \ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

368 
hbuf[1] = (unsigned char)((word) >> 8); \ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

369 
check = crc32(check, hbuf, 2); \ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

370 
} while (0) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

371 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

372 
# define CRC4(check, word) \ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

373 
do { \ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

374 
hbuf[0] = (unsigned char)(word); \ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

375 
hbuf[1] = (unsigned char)((word) >> 8); \ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

376 
hbuf[2] = (unsigned char)((word) >> 16); \ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

377 
hbuf[3] = (unsigned char)((word) >> 24); \ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

378 
check = crc32(check, hbuf, 4); \ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

379 
} while (0) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

380 
#endif 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

381 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

382 
/* Load registers with state in inflate() for speed */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

383 
#define LOAD() \ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

384 
do { \ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

385 
put = strm>next_out; \ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

386 
left = strm>avail_out; \ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

387 
next = strm>next_in; \ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

388 
have = strm>avail_in; \ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

389 
hold = state>hold; \ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

390 
bits = state>bits; \ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

391 
} while (0) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

392 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

393 
/* Restore state from registers in inflate() */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

394 
#define RESTORE() \ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

395 
do { \ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

396 
strm>next_out = put; \ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

397 
strm>avail_out = left; \ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

398 
strm>next_in = next; \ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

399 
strm>avail_in = have; \ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

400 
state>hold = hold; \ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

401 
state>bits = bits; \ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

402 
} while (0) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

403 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

404 
/* Clear the input bit accumulator */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

405 
#define INITBITS() \ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

406 
do { \ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

407 
hold = 0; \ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

408 
bits = 0; \ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

409 
} while (0) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

410 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

411 
/* Get a byte of input into the bit accumulator, or return from inflate() 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

412 
if there is no input available. */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

413 
#define PULLBYTE() \ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

414 
do { \ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

415 
if (have == 0) goto inf_leave; \ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

416 
have; \ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

417 
hold += (unsigned long)(*next++) << bits; \ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

418 
bits += 8; \ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

419 
} while (0) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

420 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

421 
/* Assure that there are at least n bits in the bit accumulator. If there is 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

422 
not enough available input to do that, then return from inflate(). */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

423 
#define NEEDBITS(n) \ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

424 
do { \ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

425 
while (bits < (unsigned)(n)) \ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

426 
PULLBYTE(); \ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

427 
} while (0) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

428 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

429 
/* Return the low n bits of the bit accumulator (n < 16) */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

430 
#define BITS(n) \ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

431 
((unsigned)hold & ((1U << (n))  1)) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

432 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

433 
/* Remove n bits from the bit accumulator */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

434 
#define DROPBITS(n) \ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

435 
do { \ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

436 
hold >>= (n); \ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

437 
bits = (unsigned)(n); \ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

438 
} while (0) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

439 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

440 
/* Remove zero to seven bits as needed to go to a byte boundary */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

441 
#define BYTEBITS() \ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

442 
do { \ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

443 
hold >>= bits & 7; \ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

444 
bits = bits & 7; \ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

445 
} while (0) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

446 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

447 
/* Reverse the bytes in a 32bit value */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

448 
#define REVERSE(q) \ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

449 
((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

450 
(((q) & 0xff00) << 8) + (((q) & 0xff) << 24)) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

451 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

452 
/* 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

453 
inflate() uses a state machine to process as much input data and generate as 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

454 
much output data as possible before returning. The state machine is 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

455 
structured roughly as follows: 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

456 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

457 
for (;;) switch (state) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

458 
... 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

459 
case STATEn: 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

460 
if (not enough input data or output space to make progress) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

461 
return; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

462 
... make progress ... 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

463 
state = STATEm; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

464 
break; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

465 
... 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

466 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

467 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

468 
so when inflate() is called again, the same case is attempted again, and 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

469 
if the appropriate resources are provided, the machine proceeds to the 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

470 
next state. The NEEDBITS() macro is usually the way the state evaluates 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

471 
whether it can proceed or should return. NEEDBITS() does the return if 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

472 
the requested bits are not available. The typical use of the BITS macros 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

473 
is: 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

474 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

475 
NEEDBITS(n); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

476 
... do something with BITS(n) ... 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

477 
DROPBITS(n); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

478 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

479 
where NEEDBITS(n) either returns from inflate() if there isn't enough 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

480 
input left to load n bits into the accumulator, or it continues. BITS(n) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

481 
gives the low n bits in the accumulator. When done, DROPBITS(n) drops 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

482 
the low n bits off the accumulator. INITBITS() clears the accumulator 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

483 
and sets the number of available bits to zero. BYTEBITS() discards just 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

484 
enough bits to put the accumulator on a byte boundary. After BYTEBITS() 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

485 
and a NEEDBITS(8), then BITS(8) would return the next byte in the stream. 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

486 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

487 
NEEDBITS(n) uses PULLBYTE() to get an available byte of input, or to return 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

488 
if there is no input available. The decoding of variable length codes uses 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

489 
PULLBYTE() directly in order to pull just enough bytes to decode the next 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

490 
code, and no more. 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

491 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

492 
Some states loop until they get enough input, making sure that enough 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

493 
state information is maintained to continue the loop where it left off 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

494 
if NEEDBITS() returns in the loop. For example, want, need, and keep 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

495 
would all have to actually be part of the saved state in case NEEDBITS() 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

496 
returns: 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

497 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

498 
case STATEw: 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

499 
while (want < need) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

500 
NEEDBITS(n); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

501 
keep[want++] = BITS(n); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

502 
DROPBITS(n); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

503 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

504 
state = STATEx; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

505 
case STATEx: 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

506 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

507 
As shown above, if the next state is also the next case, then the break 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

508 
is omitted. 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

509 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

510 
A state may also return if there is not enough output space available to 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

511 
complete that state. Those states are copying stored data, writing a 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

512 
literal byte, and copying a matching string. 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

513 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

514 
When returning, a "goto inf_leave" is used to update the total counters, 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

515 
update the check value, and determine whether any progress has been made 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

516 
during that inflate() call in order to return the proper return code. 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

517 
Progress is defined as a change in either strm>avail_in or strm>avail_out. 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

518 
When there is a window, goto inf_leave will update the window with the last 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

519 
output written. If a goto inf_leave occurs in the middle of decompression 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

520 
and there is no window currently, goto inf_leave will create one and copy 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

521 
output to the window for the next call of inflate(). 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

522 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

523 
In this implementation, the flush parameter of inflate() only affects the 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

524 
return code (per zlib.h). inflate() always writes as much as possible to 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

525 
strm>next_out, given the space available and the provided inputthe effect 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

526 
documented in zlib.h of Z_SYNC_FLUSH. Furthermore, inflate() always defers 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

527 
the allocation of and copying into a sliding window until necessary, which 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

528 
provides the effect documented in zlib.h for Z_FINISH when the entire input 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

529 
stream available. So the only thing the flush parameter actually does is: 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

530 
when flush is set to Z_FINISH, inflate() cannot return Z_OK. Instead it 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

531 
will return Z_BUF_ERROR if it has not reached the end of the stream. 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

532 
*/ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

533 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

534 
int ZEXPORT inflate(strm, flush) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

535 
z_streamp strm; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

536 
int flush; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

537 
{ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

538 
struct inflate_state FAR *state; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

539 
unsigned char FAR *next; /* next input */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

540 
unsigned char FAR *put; /* next output */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

541 
unsigned have, left; /* available input and output */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

542 
unsigned long hold; /* bit buffer */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

543 
unsigned bits; /* bits in bit buffer */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

544 
unsigned in, out; /* save starting available input and output */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

545 
unsigned copy; /* number of stored or match bytes to copy */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

546 
unsigned char FAR *from; /* where to copy match bytes from */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

547 
code this; /* current decoding table entry */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

548 
code last; /* parent table entry */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

549 
unsigned len; /* length to copy for repeats, bits to drop */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

550 
int ret; /* return code */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

551 
#ifdef GUNZIP 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

552 
unsigned char hbuf[4]; /* buffer for gzip header crc calculation */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

553 
#endif 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

554 
static const unsigned short order[19] = /* permutation of code lengths */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

555 
{16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

556 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

557 
if (strm == Z_NULL  strm>state == Z_NULL  strm>next_out == Z_NULL  
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

558 
(strm>next_in == Z_NULL && strm>avail_in != 0)) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

559 
return Z_STREAM_ERROR; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

560 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

561 
state = (struct inflate_state FAR *)strm>state; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

562 
if (state>mode == TYPE) state>mode = TYPEDO; /* skip check */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

563 
LOAD(); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

564 
in = have; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

565 
out = left; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

566 
ret = Z_OK; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

567 
for (;;) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

568 
switch (state>mode) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

569 
case HEAD: 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

570 
if (state>wrap == 0) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

571 
state>mode = TYPEDO; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

572 
break; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

573 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

574 
NEEDBITS(16); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

575 
#ifdef GUNZIP 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

576 
if ((state>wrap & 2) && hold == 0x8b1f) { /* gzip header */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

577 
state>check = crc32(0L, Z_NULL, 0); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

578 
CRC2(state>check, hold); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

579 
INITBITS(); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

580 
state>mode = FLAGS; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

581 
break; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

582 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

583 
state>flags = 0; /* expect zlib header */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

584 
if (!(state>wrap & 1)  /* check if zlib header allowed */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

585 
#else 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

586 
if ( 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

587 
#endif 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

588 
((BITS(8) << 8) + (hold >> 8)) % 31) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

589 
strm>msg = (char *)"incorrect header check"; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

590 
state>mode = BAD; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

591 
break; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

592 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

593 
if (BITS(4) != Z_DEFLATED) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

594 
strm>msg = (char *)"unknown compression method"; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

595 
state>mode = BAD; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

596 
break; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

597 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

598 
DROPBITS(4); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

599 
if (BITS(4) + 8 > state>wbits) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

600 
strm>msg = (char *)"invalid window size"; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

601 
state>mode = BAD; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

602 
break; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

603 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

604 
Tracev((stderr, "inflate: zlib header ok\n")); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

605 
strm>adler = state>check = adler32(0L, Z_NULL, 0); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

606 
state>mode = hold & 0x200 ? DICTID : TYPE; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

607 
INITBITS(); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

608 
break; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

609 
#ifdef GUNZIP 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

610 
case FLAGS: 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

611 
NEEDBITS(16); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

612 
state>flags = (int)(hold); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

613 
if ((state>flags & 0xff) != Z_DEFLATED) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

614 
strm>msg = (char *)"unknown compression method"; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

615 
state>mode = BAD; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

616 
break; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

617 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

618 
if (state>flags & 0xe000) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

619 
strm>msg = (char *)"unknown header flags set"; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

620 
state>mode = BAD; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

621 
break; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

622 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

623 
if (state>flags & 0x0200) CRC2(state>check, hold); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

624 
INITBITS(); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

625 
state>mode = TIME; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

626 
case TIME: 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

627 
NEEDBITS(32); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

628 
if (state>flags & 0x0200) CRC4(state>check, hold); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

629 
INITBITS(); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

630 
state>mode = OS; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

631 
case OS: 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

632 
NEEDBITS(16); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

633 
if (state>flags & 0x0200) CRC2(state>check, hold); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

634 
INITBITS(); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

635 
state>mode = EXLEN; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

636 
case EXLEN: 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

637 
if (state>flags & 0x0400) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

638 
NEEDBITS(16); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

639 
state>length = (unsigned)(hold); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

640 
if (state>flags & 0x0200) CRC2(state>check, hold); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

641 
INITBITS(); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

642 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

643 
state>mode = EXTRA; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

644 
case EXTRA: 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

645 
if (state>flags & 0x0400) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

646 
copy = state>length; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

647 
if (copy > have) copy = have; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

648 
if (copy) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

649 
if (state>flags & 0x0200) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

650 
state>check = crc32(state>check, next, copy); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

651 
have = copy; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

652 
next += copy; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

653 
state>length = copy; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

654 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

655 
if (state>length) goto inf_leave; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

656 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

657 
state>mode = NAME; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

658 
case NAME: 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

659 
if (state>flags & 0x0800) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

660 
if (have == 0) goto inf_leave; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

661 
copy = 0; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

662 
do { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

663 
len = (unsigned)(next[copy++]); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

664 
} while (len && copy < have); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

665 
if (state>flags & 0x02000) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

666 
state>check = crc32(state>check, next, copy); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

667 
have = copy; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

668 
next += copy; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

669 
if (len) goto inf_leave; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

670 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

671 
state>mode = COMMENT; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

672 
case COMMENT: 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

673 
if (state>flags & 0x1000) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

674 
if (have == 0) goto inf_leave; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

675 
copy = 0; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

676 
do { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

677 
len = (unsigned)(next[copy++]); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

678 
} while (len && copy < have); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

679 
if (state>flags & 0x02000) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

680 
state>check = crc32(state>check, next, copy); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

681 
have = copy; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

682 
next += copy; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

683 
if (len) goto inf_leave; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

684 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

685 
state>mode = HCRC; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

686 
case HCRC: 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

687 
if (state>flags & 0x0200) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

688 
NEEDBITS(16); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

689 
if (hold != (state>check & 0xffff)) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

690 
strm>msg = (char *)"header crc mismatch"; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

691 
state>mode = BAD; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

692 
break; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

693 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

694 
INITBITS(); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

695 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

696 
strm>adler = state>check = crc32(0L, Z_NULL, 0); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

697 
state>mode = TYPE; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

698 
break; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

699 
#endif 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

700 
case DICTID: 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

701 
NEEDBITS(32); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

702 
strm>adler = state>check = REVERSE(hold); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

703 
INITBITS(); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

704 
state>mode = DICT; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

705 
case DICT: 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

706 
if (state>havedict == 0) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

707 
RESTORE(); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

708 
return Z_NEED_DICT; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

709 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

710 
strm>adler = state>check = adler32(0L, Z_NULL, 0); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

711 
state>mode = TYPE; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

712 
case TYPE: 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

713 
if (flush == Z_BLOCK) goto inf_leave; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

714 
case TYPEDO: 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

715 
if (state>last) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

716 
BYTEBITS(); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

717 
state>mode = CHECK; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

718 
break; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

719 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

720 
NEEDBITS(3); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

721 
state>last = BITS(1); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

722 
DROPBITS(1); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

723 
switch (BITS(2)) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

724 
case 0: /* stored block */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

725 
Tracev((stderr, "inflate: stored block%s\n", 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

726 
state>last ? " (last)" : "")); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

727 
state>mode = STORED; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

728 
break; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

729 
case 1: /* fixed block */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

730 
fixedtables(state); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

731 
Tracev((stderr, "inflate: fixed codes block%s\n", 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

732 
state>last ? " (last)" : "")); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

733 
state>mode = LEN; /* decode codes */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

734 
break; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

735 
case 2: /* dynamic block */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

736 
Tracev((stderr, "inflate: dynamic codes block%s\n", 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

737 
state>last ? " (last)" : "")); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

738 
state>mode = TABLE; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

739 
break; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

740 
case 3: 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

741 
strm>msg = (char *)"invalid block type"; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

742 
state>mode = BAD; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

743 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

744 
DROPBITS(2); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

745 
break; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

746 
case STORED: 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

747 
BYTEBITS(); /* go to byte boundary */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

748 
NEEDBITS(32); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

749 
if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

750 
strm>msg = (char *)"invalid stored block lengths"; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

751 
state>mode = BAD; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

752 
break; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

753 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

754 
state>length = (unsigned)hold & 0xffff; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

755 
Tracev((stderr, "inflate: stored length %u\n", 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

756 
state>length)); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

757 
INITBITS(); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

758 
state>mode = COPY; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

759 
case COPY: 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

760 
copy = state>length; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

761 
if (copy) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

762 
if (copy > have) copy = have; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

763 
if (copy > left) copy = left; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

764 
if (copy == 0) goto inf_leave; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

765 
zmemcpy(put, next, copy); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

766 
have = copy; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

767 
next += copy; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

768 
left = copy; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

769 
put += copy; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

770 
state>length = copy; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

771 
break; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

772 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

773 
Tracev((stderr, "inflate: stored end\n")); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

774 
state>mode = TYPE; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

775 
break; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

776 
case TABLE: 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

777 
NEEDBITS(14); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

778 
state>nlen = BITS(5) + 257; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

779 
DROPBITS(5); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

780 
state>ndist = BITS(5) + 1; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

781 
DROPBITS(5); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

782 
state>ncode = BITS(4) + 4; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

783 
DROPBITS(4); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

784 
#ifndef PKZIP_BUG_WORKAROUND 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

785 
if (state>nlen > 286  state>ndist > 30) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

786 
strm>msg = (char *)"too many length or distance symbols"; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

787 
state>mode = BAD; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

788 
break; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

789 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

790 
#endif 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

791 
Tracev((stderr, "inflate: table sizes ok\n")); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

792 
state>have = 0; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

793 
state>mode = LENLENS; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

794 
case LENLENS: 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

795 
while (state>have < state>ncode) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

796 
NEEDBITS(3); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

797 
state>lens[order[state>have++]] = (unsigned short)BITS(3); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

798 
DROPBITS(3); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

799 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

800 
while (state>have < 19) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

801 
state>lens[order[state>have++]] = 0; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

802 
state>next = state>codes; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

803 
state>lencode = (code const FAR *)(state>next); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

804 
state>lenbits = 7; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

805 
ret = inflate_table(CODES, state>lens, 19, &(state>next), 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

806 
&(state>lenbits), state>work); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

807 
if (ret) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

808 
strm>msg = (char *)"invalid code lengths set"; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

809 
state>mode = BAD; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

810 
break; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

811 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

812 
Tracev((stderr, "inflate: code lengths ok\n")); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

813 
state>have = 0; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

814 
state>mode = CODELENS; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

815 
case CODELENS: 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

816 
while (state>have < state>nlen + state>ndist) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

817 
for (;;) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

818 
this = state>lencode[BITS(state>lenbits)]; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

819 
if ((unsigned)(this.bits) <= bits) break; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

820 
PULLBYTE(); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

821 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

822 
if (this.val < 16) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

823 
NEEDBITS(this.bits); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

824 
DROPBITS(this.bits); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

825 
state>lens[state>have++] = this.val; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

826 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

827 
else { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

828 
if (this.val == 16) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

829 
NEEDBITS(this.bits + 2); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

830 
DROPBITS(this.bits); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

831 
if (state>have == 0) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

832 
strm>msg = (char *)"invalid bit length repeat"; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

833 
state>mode = BAD; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

834 
break; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

835 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

836 
len = state>lens[state>have  1]; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

837 
copy = 3 + BITS(2); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

838 
DROPBITS(2); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

839 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

840 
else if (this.val == 17) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

841 
NEEDBITS(this.bits + 3); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

842 
DROPBITS(this.bits); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

843 
len = 0; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

844 
copy = 3 + BITS(3); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

845 
DROPBITS(3); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

846 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

847 
else { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

848 
NEEDBITS(this.bits + 7); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

849 
DROPBITS(this.bits); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

850 
len = 0; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

851 
copy = 11 + BITS(7); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

852 
DROPBITS(7); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

853 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

854 
if (state>have + copy > state>nlen + state>ndist) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

855 
strm>msg = (char *)"invalid bit length repeat"; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

856 
state>mode = BAD; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

857 
break; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

858 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

859 
while (copy) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

860 
state>lens[state>have++] = (unsigned short)len; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

861 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

862 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

863 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

864 
/* build code tables */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

865 
state>next = state>codes; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

866 
state>lencode = (code const FAR *)(state>next); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

867 
state>lenbits = 9; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

868 
ret = inflate_table(LENS, state>lens, state>nlen, &(state>next), 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

869 
&(state>lenbits), state>work); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

870 
if (ret) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

871 
strm>msg = (char *)"invalid literal/lengths set"; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

872 
state>mode = BAD; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

873 
break; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

874 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

875 
state>distcode = (code const FAR *)(state>next); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

876 
state>distbits = 6; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

877 
ret = inflate_table(DISTS, state>lens + state>nlen, state>ndist, 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

878 
&(state>next), &(state>distbits), state>work); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

879 
if (ret) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

880 
strm>msg = (char *)"invalid distances set"; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

881 
state>mode = BAD; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

882 
break; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

883 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

884 
Tracev((stderr, "inflate: codes ok\n")); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

885 
state>mode = LEN; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

886 
case LEN: 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

887 
if (have >= 6 && left >= 258) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

888 
RESTORE(); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

889 
inflate_fast(strm, out); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

890 
LOAD(); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

891 
break; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

892 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

893 
for (;;) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

894 
this = state>lencode[BITS(state>lenbits)]; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

895 
if ((unsigned)(this.bits) <= bits) break; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

896 
PULLBYTE(); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

897 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

898 
if (this.op && (this.op & 0xf0) == 0) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

899 
last = this; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

900 
for (;;) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

901 
this = state>lencode[last.val + 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

902 
(BITS(last.bits + last.op) >> last.bits)]; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

903 
if ((unsigned)(last.bits + this.bits) <= bits) break; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

904 
PULLBYTE(); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

905 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

906 
DROPBITS(last.bits); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

907 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

908 
DROPBITS(this.bits); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

909 
state>length = (unsigned)this.val; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

910 
if ((int)(this.op) == 0) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

911 
Tracevv((stderr, this.val >= 0x20 && this.val < 0x7f ? 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

912 
"inflate: literal '%c'\n" : 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

913 
"inflate: literal 0x%02x\n", this.val)); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

914 
state>mode = LIT; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

915 
break; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

916 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

917 
if (this.op & 32) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

918 
Tracevv((stderr, "inflate: end of block\n")); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

919 
state>mode = TYPE; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

920 
break; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

921 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

922 
if (this.op & 64) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

923 
strm>msg = (char *)"invalid literal/length code"; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

924 
state>mode = BAD; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

925 
break; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

926 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

927 
state>extra = (unsigned)(this.op) & 15; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

928 
state>mode = LENEXT; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

929 
case LENEXT: 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

930 
if (state>extra) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

931 
NEEDBITS(state>extra); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

932 
state>length += BITS(state>extra); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

933 
DROPBITS(state>extra); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

934 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

935 
Tracevv((stderr, "inflate: length %u\n", state>length)); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

936 
state>mode = DIST; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

937 
case DIST: 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

938 
for (;;) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

939 
this = state>distcode[BITS(state>distbits)]; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

940 
if ((unsigned)(this.bits) <= bits) break; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

941 
PULLBYTE(); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

942 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

943 
if ((this.op & 0xf0) == 0) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

944 
last = this; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

945 
for (;;) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

946 
this = state>distcode[last.val + 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

947 
(BITS(last.bits + last.op) >> last.bits)]; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

948 
if ((unsigned)(last.bits + this.bits) <= bits) break; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

949 
PULLBYTE(); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

950 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

951 
DROPBITS(last.bits); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

952 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

953 
DROPBITS(this.bits); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

954 
if (this.op & 64) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

955 
strm>msg = (char *)"invalid distance code"; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

956 
state>mode = BAD; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

957 
break; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

958 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

959 
state>offset = (unsigned)this.val; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

960 
state>extra = (unsigned)(this.op) & 15; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

961 
state>mode = DISTEXT; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

962 
case DISTEXT: 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

963 
if (state>extra) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

964 
NEEDBITS(state>extra); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

965 
state>offset += BITS(state>extra); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

966 
DROPBITS(state>extra); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

967 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

968 
if (state>offset > state>whave + out  left) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

969 
strm>msg = (char *)"invalid distance too far back"; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

970 
state>mode = BAD; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

971 
break; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

972 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

973 
Tracevv((stderr, "inflate: distance %u\n", state>offset)); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

974 
state>mode = MATCH; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

975 
case MATCH: 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

976 
if (left == 0) goto inf_leave; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

977 
copy = out  left; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

978 
if (state>offset > copy) { /* copy from window */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

979 
copy = state>offset  copy; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

980 
if (copy > state>write) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

981 
copy = state>write; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

982 
from = state>window + (state>wsize  copy); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

983 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

984 
else 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

985 
from = state>window + (state>write  copy); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

986 
if (copy > state>length) copy = state>length; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

987 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

988 
else { /* copy from output */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

989 
from = put  state>offset; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

990 
copy = state>length; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

991 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

992 
if (copy > left) copy = left; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

993 
left = copy; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

994 
state>length = copy; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

995 
do { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

996 
*put++ = *from++; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

997 
} while (copy); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

998 
if (state>length == 0) state>mode = LEN; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

999 
break; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1000 
case LIT: 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1001 
if (left == 0) goto inf_leave; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1002 
*put++ = (unsigned char)(state>length); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1003 
left; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1004 
state>mode = LEN; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1005 
break; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1006 
case CHECK: 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1007 
if (state>wrap) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1008 
NEEDBITS(32); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1009 
out = left; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1010 
strm>total_out += out; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1011 
state>total += out; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1012 
if (out) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1013 
strm>adler = state>check = 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1014 
UPDATE(state>check, put  out, out); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1015 
out = left; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1016 
if (( 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1017 
#ifdef GUNZIP 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1018 
state>flags ? hold : 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1019 
#endif 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1020 
REVERSE(hold)) != state>check) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1021 
strm>msg = (char *)"incorrect data check"; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1022 
state>mode = BAD; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1023 
break; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1024 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1025 
INITBITS(); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1026 
Tracev((stderr, "inflate: check matches trailer\n")); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1027 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1028 
#ifdef GUNZIP 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1029 
state>mode = LENGTH; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1030 
case LENGTH: 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1031 
if (state>wrap && state>flags) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1032 
NEEDBITS(32); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1033 
if (hold != (state>total & 0xffffffffUL)) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1034 
strm>msg = (char *)"incorrect length check"; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1035 
state>mode = BAD; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1036 
break; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1037 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1038 
INITBITS(); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1039 
Tracev((stderr, "inflate: length matches trailer\n")); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1040 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1041 
#endif 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1042 
state>mode = DONE; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1043 
case DONE: 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1044 
ret = Z_STREAM_END; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1045 
goto inf_leave; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1046 
case BAD: 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1047 
ret = Z_DATA_ERROR; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1048 
goto inf_leave; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1049 
case MEM: 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1050 
return Z_MEM_ERROR; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1051 
case SYNC: 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1052 
default: 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1053 
return Z_STREAM_ERROR; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1054 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1055 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1056 
/* 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1057 
Return from inflate(), updating the total counts and the check value. 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1058 
If there was no progress during the inflate() call, return a buffer 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1059 
error. Call updatewindow() to create and/or update the window state. 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1060 
Note: a memory error from inflate() is nonrecoverable. 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1061 
*/ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1062 
inf_leave: 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1063 
RESTORE(); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1064 
if (state>wsize  (state>mode < CHECK && out != strm>avail_out)) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1065 
if (updatewindow(strm, out)) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1066 
state>mode = MEM; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1067 
return Z_MEM_ERROR; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1068 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1069 
in = strm>avail_in; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1070 
out = strm>avail_out; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1071 
strm>total_in += in; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1072 
strm>total_out += out; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1073 
state>total += out; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1074 
if (state>wrap && out) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1075 
strm>adler = state>check = 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1076 
UPDATE(state>check, strm>next_out  out, out); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1077 
strm>data_type = state>bits + (state>last ? 64 : 0) + 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1078 
(state>mode == TYPE ? 128 : 0); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1079 
if (((in == 0 && out == 0)  flush == Z_FINISH) && ret == Z_OK) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1080 
ret = Z_BUF_ERROR; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1081 
return ret; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1082 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1083 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1084 
int ZEXPORT inflateEnd(strm) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1085 
z_streamp strm; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1086 
{ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1087 
struct inflate_state FAR *state; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1088 
if (strm == Z_NULL  strm>state == Z_NULL  strm>zfree == (free_func)0) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1089 
return Z_STREAM_ERROR; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1090 
state = (struct inflate_state FAR *)strm>state; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1091 
if (state>window != Z_NULL) ZFREE(strm, state>window); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1092 
ZFREE(strm, strm>state); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1093 
strm>state = Z_NULL; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1094 
Tracev((stderr, "inflate: end\n")); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1095 
return Z_OK; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1096 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1097 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1098 
int ZEXPORT inflateSetDictionary(strm, dictionary, dictLength) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1099 
z_streamp strm; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1100 
const Bytef *dictionary; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1101 
uInt dictLength; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1102 
{ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1103 
struct inflate_state FAR *state; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1104 
unsigned long id; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1105 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1106 
/* check state */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1107 
if (strm == Z_NULL  strm>state == Z_NULL) return Z_STREAM_ERROR; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1108 
state = (struct inflate_state FAR *)strm>state; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1109 
if (state>mode != DICT) return Z_STREAM_ERROR; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1110 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1111 
/* check for correct dictionary id */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1112 
id = adler32(0L, Z_NULL, 0); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1113 
id = adler32(id, dictionary, dictLength); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1114 
if (id != state>check) return Z_DATA_ERROR; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1115 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1116 
/* copy dictionary to window */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1117 
if (updatewindow(strm, strm>avail_out)) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1118 
state>mode = MEM; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1119 
return Z_MEM_ERROR; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1120 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1121 
if (dictLength > state>wsize) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1122 
zmemcpy(state>window, dictionary + dictLength  state>wsize, 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1123 
state>wsize); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1124 
state>whave = state>wsize; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1125 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1126 
else { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1127 
zmemcpy(state>window + state>wsize  dictLength, dictionary, 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1128 
dictLength); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1129 
state>whave = dictLength; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1130 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1131 
state>havedict = 1; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1132 
Tracev((stderr, "inflate: dictionary set\n")); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1133 
return Z_OK; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1134 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1135 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1136 
/* 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1137 
Search buf[0..len1] for the pattern: 0, 0, 0xff, 0xff. Return when found 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1138 
or when out of input. When called, *have is the number of pattern bytes 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1139 
found in order so far, in 0..3. On return *have is updated to the new 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1140 
state. If on return *have equals four, then the pattern was found and the 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1141 
return value is how many bytes were read including the last byte of the 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1142 
pattern. If *have is less than four, then the pattern has not been found 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1143 
yet and the return value is len. In the latter case, syncsearch() can be 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1144 
called again with more data and the *have state. *have is initialized to 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1145 
zero for the first call. 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1146 
*/ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1147 
local unsigned syncsearch(have, buf, len) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1148 
unsigned FAR *have; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1149 
unsigned char FAR *buf; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1150 
unsigned len; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1151 
{ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1152 
unsigned got; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1153 
unsigned next; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1154 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1155 
got = *have; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1156 
next = 0; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1157 
while (next < len && got < 4) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1158 
if ((int)(buf[next]) == (got < 2 ? 0 : 0xff)) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1159 
got++; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1160 
else if (buf[next]) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1161 
got = 0; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1162 
else 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1163 
got = 4  got; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1164 
next++; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1165 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1166 
*have = got; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1167 
return next; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1168 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1169 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1170 
int ZEXPORT inflateSync(strm) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1171 
z_streamp strm; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1172 
{ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1173 
unsigned len; /* number of bytes to look at or looked at */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1174 
unsigned long in, out; /* temporary to save total_in and total_out */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1175 
unsigned char buf[4]; /* to restore bit buffer to byte string */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1176 
struct inflate_state FAR *state; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1177 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1178 
/* check parameters */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1179 
if (strm == Z_NULL  strm>state == Z_NULL) return Z_STREAM_ERROR; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1180 
state = (struct inflate_state FAR *)strm>state; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1181 
if (strm>avail_in == 0 && state>bits < 8) return Z_BUF_ERROR; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1182 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1183 
/* if first time, start search in bit buffer */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1184 
if (state>mode != SYNC) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1185 
state>mode = SYNC; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1186 
state>hold <<= state>bits & 7; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1187 
state>bits = state>bits & 7; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1188 
len = 0; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1189 
while (state>bits >= 8) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1190 
buf[len++] = (unsigned char)(state>hold); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1191 
state>hold >>= 8; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1192 
state>bits = 8; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1193 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1194 
state>have = 0; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1195 
syncsearch(&(state>have), buf, len); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1196 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1197 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1198 
/* search available input */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1199 
len = syncsearch(&(state>have), strm>next_in, strm>avail_in); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1200 
strm>avail_in = len; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1201 
strm>next_in += len; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1202 
strm>total_in += len; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1203 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1204 
/* return no joy or set up to restart inflate() on a new block */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1205 
if (state>have != 4) return Z_DATA_ERROR; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1206 
in = strm>total_in; out = strm>total_out; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1207 
inflateReset(strm); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1208 
strm>total_in = in; strm>total_out = out; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1209 
state>mode = TYPE; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1210 
return Z_OK; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1211 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1212 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1213 
/* 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1214 
Returns true if inflate is currently at the end of a block generated by 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1215 
Z_SYNC_FLUSH or Z_FULL_FLUSH. This function is used by one PPP 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1216 
implementation to provide an additional safety check. PPP uses 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1217 
Z_SYNC_FLUSH but removes the length bytes of the resulting empty stored 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1218 
block. When decompressing, PPP checks that at the end of input packet, 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1219 
inflate is waiting for these length bytes. 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1220 
*/ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1221 
int ZEXPORT inflateSyncPoint(strm) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1222 
z_streamp strm; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1223 
{ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1224 
struct inflate_state FAR *state; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan 