⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 inflateint.h

📁 This is a java virtual machine implement in c
💻 H
字号:
/*0001*//*
/*0002./ * Copyright (c) 1999-2001 Sun Microsystems, Inc. All Rights Reserved.
/*0003./ *
/*0004./ * This software is the confidential and proprietary information of Sun
/*0005./ * Microsystems, Inc. ("Confidential Information").  You shall not
/*0006./ * disclose such Confidential Information and shall use it only in
/*0007./ * accordance with the terms of the license agreement you entered into
/*0008./ * with Sun.
/*0009./ *
/*0010./ * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
/*0011./ * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
/*0012./ * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
/*0013./ * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
/*0014./ * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
/*0015./ * THIS SOFTWARE OR ITS DERIVATIVES.
/*0016./ *
/*0017./ */
/*0018*/
/*0019*//*=========================================================================
/*0020./ * SYSTEM:    KVM
/*0021./ * SUBSYSTEM: JAR file reader / inflater.
/*0022./ * FILE:      inflateint.h
/*0023./ * OVERVIEW:  Internal declarations for JAR inflater module.
/*0024./ * AUTHOR:    Ioi Lam, Tasneem Sayeed, Frank Yellin
/*0025./ *=======================================================================*/
/*0026*/
/*0027*/#ifndef _INFLATE_INT_H_
/*0028*/#define _INFLATE_INT_H_
/*0029*/
/*0030*//*
/*0031./ * The HuffmanCodeTable structure contains the dynamic huffman codes for
/*0032./ * the Code Length Codes or the Distance Codes. The structure is
/*0033./ * dynamically allocated. We just allocate enough space to contain all
/*0034./ * possible codes.
/*0035./ */
/*0036*/typedef struct HuffmanCodeTableHeader {
/*0037*/    unsigned short quickBits;   /* quick bit size */
/*0038*/    unsigned short maxCodeLen;  /* Max number of bits in any code */
/*0039*/} HuffmanCodeTableHeader;
/*0040*/
/*0041*//* If this bit is set in a huffman entry, it means that this is not
/*0042./ * really an entry, but a pointer into the long codes table.
/*0043./ * The remaining 15 bits is the offset (in bytes) from the table header
/*0044./ * to first "long" entry representing this item.
/*0045./ */
/*0046*/#define HUFFINFO_LONG_MASK 0x8000 /*  high bit set */
/*0047*/
/*0048*/#define MAX_QUICK_CXD  6
/*0049*/#define MAX_QUICK_LXL  9
/*0050*/
/*0051*//* For debugging, the following can be set to the name of a file (in quotes).
/*0052./ * If we are decompressing something that is the exact same length as that
/*0053./ * file, this will check to make sure that the decompressed bytes look
/*0054./ * exactly the same as the bytes in the specified file.
/*0055./ * java/lang/String.class is a particularly useful file to try.
/*0056./ *
/*0057./ * That only works on machines that have stat(), and for which you
/*0058./ * can include sys/stat.h
/*0059./ *
/*0060./ * #define INFLATE_DEBUG_FILE java/lang/String.class
/*0061./ */
/*0067*/#   define ASSERT(x) (void)0
/*0069*/
/*0070*//*=========================================================================
/*0071./ * JAR file reader defines and macros
/*0072./ *=======================================================================*/
/*0073*/
/*0074*/#define BTYPE_NO_COMPRESSION 0x00  
/*0075*/#define BTYPE_FIXED_HUFFMAN  0x01  /* Fixed Huffman Code */
/*0076*/#define BTYPE_DYNA_HUFFMAN   0x02  /* Dynamic Huffman code */
/*0077*/#define BTYPE_INVALID        0x03  /* Invalid code */
/*0078*/
/*0079*/#define MAX_BITS 15   /* Maximum number of codes in Huffman Code Table */
/*0080*/
/*0081*/#define LITXLEN_BASE 257
/*0082*/
/*0083*//* A normal sized huffman code table with a 9-bit quick bit */
/*0084*/typedef struct HuffmanCodeTable { 
/*0085*/    struct HuffmanCodeTableHeader h;
/*0086*/    /* There are 1 << quickBit entries.  512 is just an example. 
/*0087./     * For each entry:
/*0088./     *     If the high bit is 0:
/*0089./     *        Next 11 bits give the character
/*0090./     *        Low   4 bits give the actual number of bits used
/*0091./     *     If the high bit is 1:
/*0092./     *        Next 15 bits give the offset (in bytes) from the header to 
/*0093./     *        the first long entry dealing with this long code.
/*0094./     */
/*0095*/    unsigned short entries[512];
/*0096*/} HuffmanCodeTable;
/*0097*/
/*0098*//* A small sized huffman code table with a 9-bit quick bit.  We have
/*0099./ * this so that we can initialize fixedHuffmanDistanceTable in jartables.h
/*0100./ */
/*0101*/typedef struct shortHuffmanCodeTable { 
/*0102*/    struct HuffmanCodeTableHeader h;
/*0103*/    unsigned short entries[32];
/*0104*/} shortHuffmanCodeTable;
/*0105*/
/*0106*/typedef struct inflaterState {
/*0107*/    /* The input stream */
/*0108*/    void *inFile;               /* The information */
/*0109*/    JarGetByteFunctionType getByte;
/*0110*/
/*0111*/    int inRemaining;            /* Number of bytes left that we can read */
/*0112*/    unsigned int inDataSize;    /* Number of good bits in inData */
/*0113*/    unsigned long inData;       /* Low inDataSize bits are from stream. */
/*0114*/                                /* High unused bits must be zero */
/*0115*/    /* The output stream */
/*0116*/    UNSIGNED_CHAR_HANDLE outFileH;
/*0117*/    unsigned long outOffset;
/*0118*/    unsigned long outLength;
/*0119*/#ifdef JAR_DEBUG_FILE  
/*0120*/    unsigned char *jarDebugBytes;
/*0121*/#endif
/*0122*/} inflaterState;
/*0123*/
/*0124*//*=========================================================================
/*0125./ * Macros used internally
/*0126./ *=======================================================================*/
/*0127*/
/*0128*//* Call this macro to make sure that we have at least "j" bits of
/*0129./ * input available
/*0130./ */
/*0131*/#define NEEDBITS(j) {                                         \
/*0132*/      while (inDataSize < (j)) {                              \
/*0133*/           inData |= ((unsigned long)NEXTBYTE) << inDataSize; \
/*0134*/           inRemaining--; inDataSize += 8;                    \
/*0135*/      }                                                       \
/*0136*/      ASSERT(inDataSize <= 32);                               \
/*0137*/}
/*0138*/
/*0139*//* Return (without consuming) the next "j" bits of the input */
/*0140*/#define NEXTBITS(j) \
/*0141*/       (ASSERT((j) <= inDataSize), inData & ((1 << (j)) - 1))
/*0142*/
/*0143*//* Consume (quietly) "j" bits of input, and make them no longer available
/*0144./ * to the user
/*0145./ */
/*0146*/#define DUMPBITS(j) {                                         \
/*0147*/       ASSERT((j) <= inDataSize);                             \
/*0148*/       inData >>= (j);                                        \
/*0149*/       inDataSize -= (j);                                     \
/*0150*/    }  
/*0151*/
/*0152*//* Read bits from the input stream and decode it using the specified
/*0153./ * table.  The resulting decoded character is placed into "result".
/*0154./ * If there is a problem, we goto "errorLabel"
/*0155./ *
/*0156./ * For speed, we assume that quickBits = table->h.quickBits and that
/*0157./ * it has been cached into a variable.
/*0158./ */
/*0159*/#define GET_HUFFMAN_ENTRY(table, quickBits, result, errorLabel) {  \
/*0160*/    unsigned int huff = table->entries[NEXTBITS(quickBits)];       \
/*0161*/    if (huff & HUFFINFO_LONG_MASK) {                               \
/*0162*/        long delta = (huff & ~HUFFINFO_LONG_MASK);                 \
/*0163*/        unsigned short *table2 = (unsigned short *)((char *)table + delta); \
/*0164*/        huff = table2[NEXTBITS(table->h.maxCodeLen) >> quickBits]; \
/*0165*/    }                                                              \
/*0166*/    if (huff == 0) { goto errorLabel; }                            \
/*0167*/    DUMPBITS(huff & 0xF);                                          \
/*0168*/    result = huff >> 4;                                            \
/*0169*/    }
/*0170*/
/*0171*/#define NEXTBYTE getByte(inFile)
/*0172*/
/*0173*/#define DECLARE_IN_VARIABLES                         \
/*0174*/    register void* inFile = state->inFile;           \
/*0175*/    JarGetByteFunctionType getByte = state->getByte; \
/*0176*/    register unsigned long inData;                   \
/*0177*/    register unsigned int inDataSize;                \
/*0178*/    register long inRemaining;                       \
/*0179*/
/*0180*//* Copy values from the inflaterState structure to local variables */
/*0181*/#define LOAD_IN                       \
/*0182*/    inData = state->inData;           \
/*0183*/    inDataSize = state->inDataSize;   \
/*0184*/    inRemaining = state->inRemaining; 
/*0185*/
/*0186*//* Copy values from local variables back to the inflaterState structure */
/*0187*/#define STORE_IN                      \
/*0188*/    state->inData = inData;           \
/*0189*/    state->inDataSize = inDataSize;   \
/*0190*/    state->inRemaining = inRemaining; 
/*0191*/
/*0192*/#define DECLARE_OUT_VARIABLES                                  \
/*0193*/    register unsigned char *outFile = unhand(state->outFileH); \
/*0194*/    register unsigned long outLength = state->outLength;       \
/*0195*/    register unsigned long outOffset;
/*0196*/
/*0197*/#define LOAD_OUT outOffset = state->outOffset;
/*0198*/
/*0199*/#define STORE_OUT state->outOffset = outOffset;
/*0200*/
/*0201*/#define UPDATE_IN_OUT_AFTER_POSSIBLE_GC  \
/*0202*/    outFile = unhand(state->outFileH); 
/*0203*/
/*0204*/#endif /* INFLATE_INT_H_ */
/*0205*/
/*0206*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -