#ifndef LZH_H
#define LZH_H
#define BUFSIZE (1024 * 4)
typedef uint8_t uchar;
typedef unsigned int uint;
typedef uint16_t ushort;
#ifndef CHAR_BIT
#define CHAR_BIT 8
#endif
#ifndef UCHAR_MAX
#define UCHAR_MAX 255
#endif
typedef ushort BITBUFTYPE;
#define BITBUFSIZ (CHAR_BIT * sizeof (BITBUFTYPE))
#define DICBIT 13
#define DICSIZ (1U << DICBIT)
#define MAXMATCH 256
#define THRESHOLD 3
#define NC (UCHAR_MAX + MAXMATCH + 2 - THRESHOLD)
#define CBIT 9
#define CODE_BIT 16
#define MAX_HASH_VAL (3 * DICSIZ + (DICSIZ / 512 + 1) * UCHAR_MAX)
#define NP (DICBIT + 1)
#define NT (CODE_BIT + 3)
#define PBIT 4
#define TBIT 5
#if NT > NP
#define NPT NT
#else
#define NPT NP
#endif
class CLzhDepacker
{
public:
bool LzUnpack(void *pSrc,int srcSize,void *pDst,int dstSize);
private:
uchar * m_pSrc;
int m_srcSize;
uchar * m_pDst;
int m_dstSize;
int DataIn(void *pBuffer,int nBytes);
int DataOut(void *pOut,int nBytes);
void fillbuf (int n);
ushort getbits (int n);
void init_getbits (void);
int make_table (int nchar, uchar *bitlen,int tablebits, ushort *table);
void read_pt_len (int nn, int nbit, int i_special);
void read_c_len (void);
ushort decode_c(void);
ushort decode_p(void);
void huf_decode_start (void);
void decode_start (void);
void decode (uint count, uchar buffer[]);
int fillbufsize;
uchar buf[BUFSIZE];
uchar outbuf[DICSIZ];
ushort left [2 * NC - 1];
ushort right[2 * NC - 1];
BITBUFTYPE bitbuf;
uint subbitbuf;
int bitcount;
int decode_j;
uchar c_len[NC];
uchar pt_len[NPT];
uint blocksize;
ushort c_table[4096];
ushort pt_table[256];
int with_error;
uint fillbuf_i; uint decode_i;
};
#endif