DEADSOFTWARE

Patched for Linux
[mp3cc.git] / MPC.3.5.LINUX / preverifier / jarint.h
1 /*
2 * Copyright (c) 1999 Sun Microsystems, Inc. All Rights Reserved.
3 *
4 * This software is the confidential and proprietary information of Sun
5 * Microsystems, Inc. ("Confidential Information"). You shall not
6 * disclose such Confidential Information and shall use it only in
7 * accordance with the terms of the license agreement you entered into
8 * with Sun.
9 *
10 * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
11 * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
12 * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
13 * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
14 * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
15 * THIS SOFTWARE OR ITS DERIVATIVES.
16 *
17 * Use is subject to license terms.
18 */
20 /*=========================================================================
21 * SYSTEM: KVM
22 * SUBSYSTEM: JAR file reader.
23 * FILE: jarint.h
24 * OVERVIEW: Internal declarations for JAR file reader. This file should
25 * be included only by files in the core KVM.
26 * AUTHOR: Ioi Lam.
27 *=======================================================================*/
29 #ifndef _JAR_INT_H_
30 #define _JAR_INT_H_
32 /*
33 * indicates whether JAR inflater uses standard i/o during decompression
34 */
35 #define JAR_INFLATER_USES_STDIO 1
37 /*
38 * The HuffmanCodeTable structure contains the dynamic huffman codes for
39 * the Code Length Codes or the Distance Codes. The structure is
40 * dynamically allocated. We just allocate enough space to contain all
41 * possible codes.
42 */
44 typedef struct HuffmanCodeTableHeader {
45 unsigned short quickBits; /* quick bit size */
46 unsigned short maxCodeLen; /* Max number of bits in any code */
47 } HuffmanCodeTableHeader;
50 /* If this bit is set in a huffman entry, it means that this is not
51 * really an entry, but a pointer into the long codes table.
52 * The remaining 15 bits is the offset (in bytes) from the table header
53 * to first "long" entry representing this item.
54 */
56 #define HUFFINFO_LONG_MASK 0x8000 /* high bit set */
58 #define MAX_QUICK_CXD 6
59 #define MAX_QUICK_LXL 9
61 /* For debugging, the following can be set to the name of a file (in quotes).
62 * If we are decompressing something that is the exact same length as that
63 * file, this will check to make sure that the decompressed bytes look
64 * exactly the same as the bytes in the specified file.
65 * java/lang/String.class is a particularly useful file to try.
66 *
67 */
69 #ifndef inflateVerbose
70 #define inflateVerbose 0
71 #endif
73 #if INCLUDEDEBUGCODE
74 static void ziperr(const char * msg);
75 # define ASSERT(x) assert((x))
76 #else
77 # define ziperr(msg)
78 # define ASSERT(x) (void)0
79 #endif
82 /* A normal sized huffman code table with a 9-bit quick bit */
83 typedef struct HuffmanCodeTable {
84 struct HuffmanCodeTableHeader h;
85 /* There are 1 << quickBit entries. 512 is just an example.
86 * For each entry:
87 * If the high bit is 0:
88 * Next 11 bits give the character
89 * Low 4 bits give the actual number of bits used
90 * If the high bit is 1:
91 * Next 15 bits give the offset (in bytes) from the header to
92 * the first long entry dealing with this long code.
93 */
94 unsigned short entries[512];
95 } HuffmanCodeTable;
98 /* A small sized huffman code table with a 9-bit quick bit. We have
99 * this so that we can initialize fixedHuffmanDistanceTable in jartables.h
100 */
101 typedef struct shortHuffmanCodeTable {
102 struct HuffmanCodeTableHeader h;
103 unsigned short entries[32];
104 } shortHuffmanCodeTable;
107 typedef struct inflaterState {
108 /* The input stream */
109 JarCompressedType inFile;
111 int inRemaining; /* Number of bytes left that we can read */
112 unsigned int inDataSize; /* Number of good bits in inData */
113 unsigned long inData; /* Low inDataSize bits are from stream.
114 * High unused bits must be zero
115 */
116 /* The output stream */
117 unsigned char *out; /* Current output position */
118 unsigned char *outStart; /* Start and end of output buffer */
119 unsigned char *outEnd;
120 #ifdef JAR_DEBUG_FILE
121 unsigned char *jarDebugBytes;
122 #endif
123 } inflaterState;
126 /*=========================================================================
127 * Macros used internally
128 *=======================================================================*/
130 /* Call this macro to make sure that we have at least "j" bits of
131 * input available
132 */
134 #define NEEDBITS(j) { \
135 while (inDataSize < (j)) { \
136 inData |= ((unsigned long)NEXTBYTE) << inDataSize; \
137 inRemaining--; inDataSize += 8; \
138 } \
139 ASSERT(inDataSize <= 32); \
143 /* Return (without consuming) the next "j" bits of the input */
144 #define NEXTBITS(j) \
145 (ASSERT((j) <= inDataSize), inData & ((1 << (j)) - 1))
147 /* Consume (quietly) "j" bits of input, and make them no longer available
148 * to the user
149 */
150 #define DUMPBITS(j) { \
151 ASSERT((j) <= inDataSize); \
152 inData >>= (j); \
153 inDataSize -= (j); \
154 }
156 /* Read bits from the input stream and decode it using the specified
157 * table. The resulting decoded character is placed into "result".
158 * If there is a problem, we goto "errorLabel"
160 * For speed, we assume that quickBits = table->h.quickBits and that
161 * it has been cached into a variable.
162 */
165 #define GET_HUFFMAN_ENTRY(table, quickBits, result, errorLabel) { \
166 unsigned int huff = table->entries[NEXTBITS(quickBits)]; \
167 if (huff & HUFFINFO_LONG_MASK) { \
168 long delta = (huff & ~HUFFINFO_LONG_MASK); \
169 unsigned short *table2 = (unsigned short *)((char *)table + delta); \
170 huff = table2[NEXTBITS(table->h.maxCodeLen) >> quickBits]; \
171 } \
172 if (huff == 0) { goto errorLabel; } \
173 DUMPBITS(huff & 0xF); \
174 result = huff >> 4; \
178 #if JAR_INFLATER_USES_STDIO
179 # define LOAD_INFILE_IF_NECESSARY
180 # define STORE_INFILE_IF_NECESSARY
181 # define INITIALIZE_INFILE_IF_NECESSARY = state->inFile
182 # define NEXTBYTE fgetc(inFile)
183 # define COPY_N_BYTES(buffer, n) (fread(buffer, 1, n, inFile) == n)
185 #else
186 # define LOAD_INFILE_IF_NECESSARY inFile = state->inFile;
187 # define STORE_INFILE_IF_NECESSARY state->inFile = inFile;
188 # define INITIALIZE_INFILE_IF_NECESSARY
189 # define NEXTBYTE (*inFile++)
190 # define COPY_N_BYTES(buffer, n) \
191 (memcpy(buffer, inFile, n), inFile += n, TRUE)
192 #endif
195 /* Copy values from the inflaterState structure to local variables */
196 #define LOAD_IN \
197 LOAD_INFILE_IF_NECESSARY \
198 inData = state->inData; \
199 inDataSize = state->inDataSize; \
200 inRemaining = state->inRemaining;
203 /* Copy values from local variables back to the inflaterState structure */
204 #define STORE_IN \
205 STORE_INFILE_IF_NECESSARY \
206 state->inData = inData; \
207 state->inDataSize = inDataSize; \
208 state->inRemaining = inRemaining;
211 #define DECLARE_IN_VARIABLES \
212 register JarCompressedType inFile INITIALIZE_INFILE_IF_NECESSARY; \
213 register unsigned long inData; \
214 register unsigned int inDataSize; \
215 register long inRemaining; \
217 #define LOAD_OUT out = state->out;
219 #define STORE_OUT state->out = out;
221 #define DECLARE_OUT_VARIABLES \
222 register unsigned char *out;
224 #endif /* JAR_INT_H_ */