v0.20
This commit is contained in:
commit
0f9dddcc52
40 changed files with 12839 additions and 0 deletions
86
Makefile.win
Normal file
86
Makefile.win
Normal file
|
@ -0,0 +1,86 @@
|
||||||
|
# Project: unalz
|
||||||
|
# Makefile created by Dev-C++ 4.9.9.0
|
||||||
|
|
||||||
|
CPP = g++.exe
|
||||||
|
CC = gcc.exe
|
||||||
|
WINDRES = windres.exe
|
||||||
|
RES =
|
||||||
|
OBJ = main.o UnAlz.o UnAlzBz2decompress.o UnAlzBzip2.o UnAlzbzlib.o zlib/adler32.o zlib/crc32.o zlib/infblock.o zlib/infcodes.o zlib/inffast.o zlib/inflate.o zlib/inftrees.o zlib/infutil.o zlib/uncompr.o zlib/zutil.o bzip2/blocksort.o bzip2/compress.o bzip2/crctable.o bzip2/huffman.o bzip2/randtable.o $(RES)
|
||||||
|
LINKOBJ = main.o UnAlz.o UnAlzBz2decompress.o UnAlzBzip2.o UnAlzbzlib.o zlib/adler32.o zlib/crc32.o zlib/infblock.o zlib/infcodes.o zlib/inffast.o zlib/inflate.o zlib/inftrees.o zlib/infutil.o zlib/uncompr.o zlib/zutil.o bzip2/blocksort.o bzip2/compress.o bzip2/crctable.o bzip2/huffman.o bzip2/randtable.o $(RES)
|
||||||
|
LIBS = -L"C:/Dev-Cpp/lib" -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -luuid -lodbc32 -lodbccp32 -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -luuid -lodbc32 -lodbccp32
|
||||||
|
INCS = -I"C:/Dev-Cpp/include"
|
||||||
|
CXXINCS = -I"C:/Dev-Cpp/include/c++/3.3.1" -I"C:/Dev-Cpp/include/c++/3.3.1/mingw32" -I"C:/Dev-Cpp/include/c++/3.3.1/backward" -I"C:/Dev-Cpp/lib/gcc-lib/mingw32/3.3.1/include" -I"C:/Dev-Cpp/include"
|
||||||
|
BIN = bin/unalz.exe
|
||||||
|
CXXFLAGS = $(CXXINCS) -D__GNUWIN32__ -W -DWIN32 -DNDEBUG -D_CONSOLE -D_MBCS
|
||||||
|
CFLAGS = $(INCS) -D__GNUWIN32__ -W -DWIN32 -DNDEBUG -D_CONSOLE -D_MBCS
|
||||||
|
|
||||||
|
.PHONY: all all-before all-after clean clean-custom
|
||||||
|
|
||||||
|
all: all-before bin/unalz.exe all-after
|
||||||
|
|
||||||
|
|
||||||
|
clean: clean-custom
|
||||||
|
rm -f $(OBJ) $(BIN)
|
||||||
|
|
||||||
|
$(BIN): $(OBJ)
|
||||||
|
$(CPP) $(LINKOBJ) -o "bin\unalz.exe" $(LIBS)
|
||||||
|
|
||||||
|
main.o: main.cpp
|
||||||
|
$(CPP) -c main.cpp -o main.o $(CXXFLAGS)
|
||||||
|
|
||||||
|
UnAlz.o: UnAlz.cpp
|
||||||
|
$(CPP) -c UnAlz.cpp -o UnAlz.o $(CXXFLAGS)
|
||||||
|
|
||||||
|
UnAlzBz2decompress.o: UnAlzBz2decompress.c
|
||||||
|
$(CC) -c UnAlzBz2decompress.c -o UnAlzBz2decompress.o $(CFLAGS)
|
||||||
|
|
||||||
|
UnAlzBzip2.o: UnAlzBzip2.cpp
|
||||||
|
$(CPP) -c UnAlzBzip2.cpp -o UnAlzBzip2.o $(CXXFLAGS)
|
||||||
|
|
||||||
|
UnAlzbzlib.o: UnAlzbzlib.c
|
||||||
|
$(CC) -c UnAlzbzlib.c -o UnAlzbzlib.o $(CFLAGS)
|
||||||
|
|
||||||
|
zlib/adler32.o: zlib/adler32.c
|
||||||
|
$(CC) -c zlib/adler32.c -o zlib/adler32.o $(CFLAGS)
|
||||||
|
|
||||||
|
zlib/crc32.o: zlib/crc32.c
|
||||||
|
$(CC) -c zlib/crc32.c -o zlib/crc32.o $(CFLAGS)
|
||||||
|
|
||||||
|
zlib/infblock.o: zlib/infblock.c
|
||||||
|
$(CC) -c zlib/infblock.c -o zlib/infblock.o $(CFLAGS)
|
||||||
|
|
||||||
|
zlib/infcodes.o: zlib/infcodes.c
|
||||||
|
$(CC) -c zlib/infcodes.c -o zlib/infcodes.o $(CFLAGS)
|
||||||
|
|
||||||
|
zlib/inffast.o: zlib/inffast.c
|
||||||
|
$(CC) -c zlib/inffast.c -o zlib/inffast.o $(CFLAGS)
|
||||||
|
|
||||||
|
zlib/inflate.o: zlib/inflate.c
|
||||||
|
$(CC) -c zlib/inflate.c -o zlib/inflate.o $(CFLAGS)
|
||||||
|
|
||||||
|
zlib/inftrees.o: zlib/inftrees.c
|
||||||
|
$(CC) -c zlib/inftrees.c -o zlib/inftrees.o $(CFLAGS)
|
||||||
|
|
||||||
|
zlib/infutil.o: zlib/infutil.c
|
||||||
|
$(CC) -c zlib/infutil.c -o zlib/infutil.o $(CFLAGS)
|
||||||
|
|
||||||
|
zlib/uncompr.o: zlib/uncompr.c
|
||||||
|
$(CC) -c zlib/uncompr.c -o zlib/uncompr.o $(CFLAGS)
|
||||||
|
|
||||||
|
zlib/zutil.o: zlib/zutil.c
|
||||||
|
$(CC) -c zlib/zutil.c -o zlib/zutil.o $(CFLAGS)
|
||||||
|
|
||||||
|
bzip2/blocksort.o: bzip2/blocksort.c
|
||||||
|
$(CC) -c bzip2/blocksort.c -o bzip2/blocksort.o $(CFLAGS)
|
||||||
|
|
||||||
|
bzip2/compress.o: bzip2/compress.c
|
||||||
|
$(CC) -c bzip2/compress.c -o bzip2/compress.o $(CFLAGS)
|
||||||
|
|
||||||
|
bzip2/crctable.o: bzip2/crctable.c
|
||||||
|
$(CC) -c bzip2/crctable.c -o bzip2/crctable.o $(CFLAGS)
|
||||||
|
|
||||||
|
bzip2/huffman.o: bzip2/huffman.c
|
||||||
|
$(CC) -c bzip2/huffman.c -o bzip2/huffman.o $(CFLAGS)
|
||||||
|
|
||||||
|
bzip2/randtable.o: bzip2/randtable.c
|
||||||
|
$(CC) -c bzip2/randtable.c -o bzip2/randtable.o $(CFLAGS)
|
428
UnAlz.h
Normal file
428
UnAlz.h
Normal file
|
@ -0,0 +1,428 @@
|
||||||
|
/*
|
||||||
|
|
||||||
|
COPYRIGHT(C) 2004 hardkoder@gmail.com / http://www.kipple.pe.kr
|
||||||
|
저작권 정보 :
|
||||||
|
- 이 소스는 자유로이 사용/수정/재배포 가능합니다.
|
||||||
|
- 단, 당신이 만들었다고 주장하거나 거짓말하면 안됨.
|
||||||
|
- 소스의 오류를 찾았거나, 문제점을 수정하였을 경우 이에 대한 내용을 알려주면 정말 고마울껄..
|
||||||
|
- 자신의 프로그램에 이 소스를 사용하였을 경우 원 저작자에게 알려주면 원 저작자가 고마워 할껄..
|
||||||
|
|
||||||
|
소스 설명 :
|
||||||
|
- .ALZ 의 압축을 해제하기 위한 모듈.
|
||||||
|
- ALZ는 BZIP2변형(변형이라고 뭐 개선한게 아니고, 헤더나 CRC 정보등을 빼서 크기를 줄인 것임)과,
|
||||||
|
DEFLATE 압축 알고리즘에 ZIP과 유사한 헤더를 만들어서 씌운 포맷임.
|
||||||
|
( bzip2 는 4.9x 에서 사용하였고, deflate 는 5.x 부터 사용하였음. 5.x 부터는 bzip2는 너무 느려서 사용 안함 )
|
||||||
|
- UnAlzBz2decompress.c 와 UnAlzbzlib.c 는 원래의 bzip2 소스에서 alz 용으로 수정된 파일임
|
||||||
|
( deflate 는 변형이 안되었기 때문에 그냥 zlib 를 써도 되지만.. bzip2 는 변형이 되어서
|
||||||
|
원래의 bzip2 소스를 그대로 쓰면 안된다. )
|
||||||
|
- 이 소스는 4칸 탭을 사용 하였음.
|
||||||
|
|
||||||
|
참고 :
|
||||||
|
- 원래 소스는 다중 플랫폼에서 사용할수 있게 하기 위해서 stdio 를 사용하였지만
|
||||||
|
2GB 이상의 파일을 처리하기 위해서 어쩔수 없이 WINDOWS I/O 함수로 전부 바꾸었음.
|
||||||
|
- 리눅스등에서 사용하기 위해서 소스 수정이 필요하다면, 공동 작업을 요청해 주셈.
|
||||||
|
|
||||||
|
개발 순서 :
|
||||||
|
2004/02/06 - http://www.wotsit.org/ 에서 ZIP File Format Specification version 4.5 [PKWARE Inc.] 를
|
||||||
|
다운로드 받아서 분석.
|
||||||
|
2004/02/07 - 도큐먼트로 unzip 클래스 대충 구현
|
||||||
|
2004/02/08 - unzip 클래스를 alzip 포맷에 맞추어 변형 및 테스트
|
||||||
|
- deflate, rawdata 압축 해제 구현.
|
||||||
|
- 다이알로그 박스 껍데기 씌움.
|
||||||
|
2004/02/08 - bzip2 대충 지원
|
||||||
|
2004/03/01 - bzip2 거의 완벽 지원 乃
|
||||||
|
- callback 구현..
|
||||||
|
2004/03/07 - 유틸 함수 추가 ( ExtractCurrentFileToBuf() )
|
||||||
|
2004/10/03 - 분할 압축 해제 기능 추가 ( FILE I/O 에 대한 래퍼 클래스 구현 )
|
||||||
|
- 2GB 이상의 파일 처리 지원
|
||||||
|
|
||||||
|
할일 :
|
||||||
|
- bzip2 로 압축된 파일의 압축 해제
|
||||||
|
- UI 개선 ( PROGRESS, 에러 메시지 출력, 압축 해제 결과 )
|
||||||
|
- 분할 압축 파일 지원
|
||||||
|
|
||||||
|
- 암호 걸린 파일 지원
|
||||||
|
- 손상된 파일에서의 좀더 많은 테스트
|
||||||
|
- 파일 CRC 체크
|
||||||
|
|
||||||
|
할일중 한일 :
|
||||||
|
- bzip2 로 압축된 파일의 압축 해제
|
||||||
|
- UI 개선 ( PROGRESS, 에러 메시지 출력, 압축 해제 결과 )
|
||||||
|
- 분할 압축 파일 지원
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef _UNALZ_H_
|
||||||
|
#define _UNALZ_H_
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef INT64
|
||||||
|
#ifdef _WIN32
|
||||||
|
# define INT64 __int64
|
||||||
|
#else
|
||||||
|
# define INT64 long long
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef DWORD
|
||||||
|
typedef unsigned long DWORD;
|
||||||
|
#endif // DWORD
|
||||||
|
#ifndef SHORT
|
||||||
|
typedef short SHORT;
|
||||||
|
#endif
|
||||||
|
#ifndef BYTE
|
||||||
|
typedef unsigned char BYTE;
|
||||||
|
#endif
|
||||||
|
#ifndef CHAR
|
||||||
|
typedef char CHAR;
|
||||||
|
#endif
|
||||||
|
#ifndef BYTE
|
||||||
|
typedef unsigned char BYTE;
|
||||||
|
#endif
|
||||||
|
#ifndef UINT
|
||||||
|
typedef unsigned int UINT;
|
||||||
|
#endif
|
||||||
|
#ifndef LONG
|
||||||
|
typedef long LONG;
|
||||||
|
#endif
|
||||||
|
#ifndef BOOL
|
||||||
|
typedef int BOOL;
|
||||||
|
#endif
|
||||||
|
#ifndef FALSE
|
||||||
|
# define FALSE 0
|
||||||
|
#endif
|
||||||
|
#ifndef TRUE
|
||||||
|
# define TRUE 1
|
||||||
|
#endif
|
||||||
|
#ifndef LPCTSTR
|
||||||
|
typedef const char* LPCSTR;
|
||||||
|
#endif
|
||||||
|
#ifndef HANDLE
|
||||||
|
# ifdef _WIN32
|
||||||
|
typedef void *HANDLE;
|
||||||
|
# else
|
||||||
|
typedef FILE *HANDLE;
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
#ifndef ASSERT
|
||||||
|
# include <assert.h>
|
||||||
|
# define ASSERT(x) assert(x)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace UNALZ
|
||||||
|
{
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
# pragma pack(push, UNALZ, 1) // structure packing
|
||||||
|
#else
|
||||||
|
# pragma pack(1)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static const char UNALZ_VERSION[] = "CUnAlz0.2";
|
||||||
|
static const char UNALZ_COPYRIGHT[] = "Copyright(C) 2004 hardkoder@gmail.com";
|
||||||
|
|
||||||
|
|
||||||
|
// 맨 파일 앞..
|
||||||
|
struct SAlzHeader
|
||||||
|
{
|
||||||
|
DWORD unknown; // ??
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
union _UGeneralPurposeBitFlag // zip 에서만 사용..
|
||||||
|
{
|
||||||
|
SHORT data;
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
BYTE bit0 : 1;
|
||||||
|
BYTE bit1 : 1;
|
||||||
|
BYTE bit2 : 1;
|
||||||
|
BYTE bit3 : 1;
|
||||||
|
BYTE bit4 : 1;
|
||||||
|
BYTE bit5 : 1;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
*/
|
||||||
|
|
||||||
|
enum COMPRESSION_METHOD ///< 압축 방법..
|
||||||
|
{
|
||||||
|
COMP_NOCOMP = 0,
|
||||||
|
COMP_BZIP2 = 1,
|
||||||
|
COMP_DEFLATE = 2,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct _SLocalFileHeaderHead ///< 고정 헤더.
|
||||||
|
{
|
||||||
|
SHORT fileNameLength;
|
||||||
|
BYTE unknown[5]; ///< ???
|
||||||
|
BYTE fileSizeByte; ///< 파일 크기 필드의 크기 : 0x10, 0x20, 0x40, 0x80 각각 1byte, 2byte, 4byte, 8byte
|
||||||
|
BYTE unknown2[1]; ///< ???
|
||||||
|
|
||||||
|
/*
|
||||||
|
SHORT versionNeededToExtract;
|
||||||
|
_UGeneralPurposeBitFlag generalPurposeBitFlag;
|
||||||
|
SHORT compressionMethod;
|
||||||
|
SHORT lastModFileTime;
|
||||||
|
SHORT lastModFileDate;
|
||||||
|
DWORD crc32;
|
||||||
|
DWORD compressedSize;
|
||||||
|
DWORD uncompressedSize;
|
||||||
|
SHORT fileNameLength;
|
||||||
|
SHORT extraFieldLength;
|
||||||
|
*/
|
||||||
|
};
|
||||||
|
|
||||||
|
struct _SDataDescriptor
|
||||||
|
{
|
||||||
|
DWORD crc32;
|
||||||
|
DWORD compressed;
|
||||||
|
DWORD uncompressed;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SLocalFileHeader
|
||||||
|
{
|
||||||
|
SLocalFileHeader() { memset(this, 0, sizeof(*this)); }
|
||||||
|
//~SLocalFileHeader() { if(fileName) free(fileName); if(extraField) free(extraField); }
|
||||||
|
void Clear() { if(fileName) free(fileName); fileName=NULL; if(extraField) free(extraField);extraField=NULL; }
|
||||||
|
_SLocalFileHeaderHead head;
|
||||||
|
|
||||||
|
BYTE compressionMethod; ///< 압축 방법 : 2 - deflate, 1 - bzip2(?), 0 - 압축 안함.
|
||||||
|
BYTE unknown3[1]; ///< ???
|
||||||
|
DWORD maybeCRC; ///< 아마도 crc
|
||||||
|
|
||||||
|
INT64 compressedSize;
|
||||||
|
INT64 uncompressedSize;
|
||||||
|
|
||||||
|
CHAR* fileName;
|
||||||
|
BYTE* extraField;
|
||||||
|
_SDataDescriptor dataDescriptor;
|
||||||
|
INT64 dwFileDataPos; ///< file data 가 저장된 위치..
|
||||||
|
};
|
||||||
|
|
||||||
|
struct _SCentralDirectoryStructureHead
|
||||||
|
{
|
||||||
|
DWORD dwUnknown; ///< 항상 NULL 이던데..
|
||||||
|
DWORD dwMaybeCRC; ///< 아마도 crc
|
||||||
|
DWORD dwCLZ03; ///< "CLZ0x03" - 0x035a4c43 끝을 표시하는듯.
|
||||||
|
/*
|
||||||
|
SHORT versionMadeBy;
|
||||||
|
SHORT versionNeededToExtract;
|
||||||
|
_UGeneralPurposeBitFlag generalPurposeBitFlag;
|
||||||
|
SHORT compressionMethod;
|
||||||
|
SHORT lastModFileTime;
|
||||||
|
SHORT lastModFileDate;
|
||||||
|
DWORD crc32;
|
||||||
|
DWORD compressedSize;
|
||||||
|
DWORD uncompressedSize;
|
||||||
|
SHORT fileNameLength;
|
||||||
|
SHORT extraFieldLength;
|
||||||
|
SHORT fileCommentLength;
|
||||||
|
SHORT diskNumberStart;
|
||||||
|
SHORT internalFileAttributes;
|
||||||
|
DWORD externalFileAttributes;
|
||||||
|
DWORD relativeOffsetOfLocalHeader;
|
||||||
|
*/
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SCentralDirectoryStructure
|
||||||
|
{
|
||||||
|
SCentralDirectoryStructure() { memset(this, 0, sizeof(*this)); }
|
||||||
|
//~SCentralDirectoryStructure() { if(fileName) free(fileName); if(extraField) free(extraField);if(fileComment)free(fileComment); }
|
||||||
|
_SCentralDirectoryStructureHead head;
|
||||||
|
/*
|
||||||
|
CHAR* fileName;
|
||||||
|
BYTE* extraField;
|
||||||
|
CHAR* fileComment;
|
||||||
|
*/
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
struct _SEndOfCentralDirectoryRecordHead
|
||||||
|
{
|
||||||
|
SHORT numberOfThisDisk;
|
||||||
|
SHORT numberOfTheDiskWithTheStartOfTheCentralDirectory;
|
||||||
|
SHORT centralDirectoryOnThisDisk;
|
||||||
|
SHORT totalNumberOfEntriesInTheCentralDirectoryOnThisDisk;
|
||||||
|
DWORD sizeOfTheCentralDirectory;
|
||||||
|
DWORD offsetOfStartOfCentralDirectoryWithREspectoTotheStartingDiskNumber;
|
||||||
|
SHORT zipFileCommentLength;
|
||||||
|
};
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
struct SEndOfCentralDirectoryRecord
|
||||||
|
{
|
||||||
|
SEndOfCentralDirectoryRecord() { memset(this, 0, sizeof(*this)); }
|
||||||
|
~SEndOfCentralDirectoryRecord() { if(fileComment) free(fileComment); }
|
||||||
|
_SEndOfCentralDirectoryRecordHead head;
|
||||||
|
CHAR* fileComment;
|
||||||
|
};
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#pragma pack(pop, UNALZ) ///< PACKING 원상 복구
|
||||||
|
#else
|
||||||
|
#pragma pack(4)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
///< PROGRESS CALLBACK FUNCTION - 압축 해제 진행 상황을 알고 싶으면 이걸 쓰면 된다.
|
||||||
|
typedef void (_UnAlzCallback)(const char* szMessage, INT64 nCurrent, INT64 nRange, void* param, BOOL* bHalt);
|
||||||
|
|
||||||
|
|
||||||
|
class CUnAlz
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CUnAlz();
|
||||||
|
~CUnAlz();
|
||||||
|
BOOL Open(const char* szPathName);
|
||||||
|
void Close();
|
||||||
|
BOOL SetCurrentFile(const char* szFileName);
|
||||||
|
BOOL ExtractCurrentFile(const char* szDestPathName, const char* szDestFileName=NULL);
|
||||||
|
BOOL ExtractCurrentFileToBuf(BYTE* pDestBuf, int nBufSize);
|
||||||
|
BOOL ExtractAll(const char* szDestPathName);
|
||||||
|
void SetCallback(_UnAlzCallback* pFunc, void* param=NULL);
|
||||||
|
|
||||||
|
public : ///< WIN32 전용 ( UNICODE 처리용 )
|
||||||
|
/*
|
||||||
|
#ifdef _WIN32
|
||||||
|
BOOL Open(LPCWSTR szPathName);
|
||||||
|
BOOL SetCurrentFile(LPCWSTR szFileName);
|
||||||
|
static BOOL IsFolder(LPCWSTR szPathName);
|
||||||
|
#endif
|
||||||
|
*/
|
||||||
|
|
||||||
|
public :
|
||||||
|
typedef vector<SLocalFileHeader> FileList; ///< 파일 목록.
|
||||||
|
const FileList& GetFileList() { return m_fileList; }; ///< file 목록 리턴
|
||||||
|
FileList::iterator GetCurFileHeader() { return m_posCur; }; ///< 현재 (SetCurrentFile() 로 세팅된) 파일 정보
|
||||||
|
// const SLocalFileHeader* GetCurFileHeader() { return _posCur; }; ///< 현재 (SetCurrentFile() 로 세팅된) 파일 정보
|
||||||
|
|
||||||
|
public :
|
||||||
|
enum ERR ///< 에러 코드 - 정리 필요..
|
||||||
|
{
|
||||||
|
ERR_NOERR,
|
||||||
|
ERR_CANT_OPEN_FILE, ///< 파일 열기 실패
|
||||||
|
ERR_CANT_READ_SIG, ///< signature 읽기 실패
|
||||||
|
ERR_CANT_READ_FILE,
|
||||||
|
|
||||||
|
ERR_AT_READ_HEADER,
|
||||||
|
ERR_INVALID_FILENAME_LENGTH,
|
||||||
|
ERR_INVALID_EXTRAFIELD_LENGTH,
|
||||||
|
ERR_CANT_READ_CENTRAL_DIRECTORY_STRUCTURE_HEAD,
|
||||||
|
ERR_INVALID_FILENAME_SIZE,
|
||||||
|
ERR_INVALID_EXTRAFIELD_SIZE,
|
||||||
|
ERR_INVALID_FILECOMMENT_SIZE,
|
||||||
|
ERR_CANT_READ_HEADER,
|
||||||
|
ERR_MEM_ALLOC_FAILED,
|
||||||
|
ERR_FILE_READ_ERROR,
|
||||||
|
ERR_INFLATE_FAILED,
|
||||||
|
};
|
||||||
|
ERR GetLastErr(){return m_nErr;}
|
||||||
|
|
||||||
|
enum SIGNATURE ///< zip file signature
|
||||||
|
{
|
||||||
|
SIG_ERR = 0x00,
|
||||||
|
SIG_EOF = 0x01,
|
||||||
|
SIG_ALZ_FILE_HEADER = 0x015a4c41, ///< ALZ 0x01
|
||||||
|
SIG_LOCAL_FILE_HEADER = 0x015a4c42, ///< BLZ 0x01
|
||||||
|
SIG_CENTRAL_DIRECTORY_STRUCTURE = 0x015a4c43, ///< CLZ 0x01
|
||||||
|
SIG_ENDOF_CENTRAL_DIRECTORY_RECORD = 0x025a4c43, ///< CLZ 0x02
|
||||||
|
};
|
||||||
|
|
||||||
|
public :
|
||||||
|
static BOOL DigPath(const char* szPathName);
|
||||||
|
static BOOL IsFolder(LPCSTR szPathName);
|
||||||
|
static const char* GetVersion() { return UNALZ_VERSION; }
|
||||||
|
static const char* GetCopyright() { return UNALZ_COPYRIGHT; }
|
||||||
|
|
||||||
|
private :
|
||||||
|
SIGNATURE ReadSignature();
|
||||||
|
BOOL ReadAlzFileHeader();
|
||||||
|
BOOL ReadLocalFileheader();
|
||||||
|
BOOL ReadCentralDirectoryStructure();
|
||||||
|
BOOL ReadEndofCentralDirectoryRecord();
|
||||||
|
|
||||||
|
private :
|
||||||
|
enum EXTRACT_TYPE ///< 압축 해제 타입.
|
||||||
|
{
|
||||||
|
ET_FILE, ///< FILE*
|
||||||
|
ET_MEM, ///< memory buffer
|
||||||
|
};
|
||||||
|
struct SExtractDest ///< 압축 해제 대상.
|
||||||
|
{
|
||||||
|
SExtractDest() { memset(this, 0, sizeof(SExtractDest)); }
|
||||||
|
EXTRACT_TYPE nType; ///< 대상이 파일인가 메모리 인가..
|
||||||
|
FILE* fp; ///< ET_FILE 일 경우 대상 FILE*
|
||||||
|
BYTE* buf; ///< ET_MEM 일 경우 대상 포인터
|
||||||
|
DWORD bufsize; ///< ET_MEM 일 경우 대상 버퍼의 크기
|
||||||
|
DWORD bufpos; ///< ET_MEM 일 경우 대상 버퍼에 쓰고 있는 위치
|
||||||
|
};
|
||||||
|
int WriteToDest(SExtractDest* dest, BYTE* buf, int nSize);
|
||||||
|
|
||||||
|
private :
|
||||||
|
BOOL ExtractTo(SExtractDest* dest);
|
||||||
|
|
||||||
|
//BOOL ExtractDeflate(FILE* fp, SLocalFileHeader& file);
|
||||||
|
//BOOL ExtractBzip2_bak(FILE* fp, SLocalFileHeader& file); - 실패한(잘못된) 방법
|
||||||
|
BOOL ExtractDeflate2(SExtractDest* dest, SLocalFileHeader& file);
|
||||||
|
BOOL ExtractBzip2(SExtractDest* dest, SLocalFileHeader& file);
|
||||||
|
BOOL ExtractRawfile(SExtractDest* dest, SLocalFileHeader& file);
|
||||||
|
|
||||||
|
private : // bzip2 파일 처리 함수..
|
||||||
|
typedef void MYBZFILE;
|
||||||
|
MYBZFILE* BZ2_bzReadOpen(int* bzerror, CUnAlz* f, int verbosity, int _small, void* unused, int nUnused);
|
||||||
|
int BZ2_bzread(MYBZFILE* b, void* buf, int len );
|
||||||
|
int BZ2_bzRead(int* bzerror, MYBZFILE* b, void* buf, int len);
|
||||||
|
void BZ2_bzReadClose( int *bzerror, MYBZFILE *b );
|
||||||
|
|
||||||
|
private : // 분할 압축 파일 처리를 위한 래퍼(lapper?) 클래스
|
||||||
|
BOOL FOpen(const char* szPathName);
|
||||||
|
void FClose();
|
||||||
|
INT64 FTell();
|
||||||
|
BOOL FEof();
|
||||||
|
BOOL FSeek(INT64 offset);
|
||||||
|
BOOL FRead(void* buffer, DWORD nBytesToRead, int* pTotRead=NULL);
|
||||||
|
|
||||||
|
enum {MAX_FILES=1000}; ///< 처리 가능한 분할 압축 파일 수.
|
||||||
|
enum {MULTIVOL_TAIL_SIZE=16,MULTIVOL_HEAD_SIZE=8}; ///< 분할 압축시 꼴랑지, 헤더 크기
|
||||||
|
struct SFile ///< 분할 파일 정보
|
||||||
|
{
|
||||||
|
HANDLE fp;
|
||||||
|
INT64 nFileSize;
|
||||||
|
int nMultivolHeaderSize;
|
||||||
|
int nMultivolTailSize;
|
||||||
|
};
|
||||||
|
|
||||||
|
SFile m_files[MAX_FILES]; ///< 분할 파일 저장 array - 무식한가?
|
||||||
|
int m_nCurFile; ///< m_files 에서 현재 처리중인 파일의 위치.
|
||||||
|
int m_nFileCount; ///< 분할 파일 갯수..
|
||||||
|
INT64 m_nVirtualFilePos; ///< 멀티볼륨에서의 가상의 위치
|
||||||
|
INT64 m_nCurFilePos; ///< 현재 파일의 물리적 위치.
|
||||||
|
BOOL m_bIsEOF; ///< 파일의 끝까지 (분할 파일 포함해서) 왔나?
|
||||||
|
|
||||||
|
|
||||||
|
private :
|
||||||
|
FileList m_fileList; ///< 압축파일 내의 파일 목록
|
||||||
|
ERR m_nErr;
|
||||||
|
FileList::iterator m_posCur; ///< 현재 파일
|
||||||
|
_UnAlzCallback* m_pFuncCallBack;
|
||||||
|
void* m_pCallbackParam;
|
||||||
|
BOOL m_bHalt;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
using namespace UNALZ;
|
||||||
|
|
||||||
|
#endif
|
728
UnAlzBz2decompress.c
Normal file
728
UnAlzBz2decompress.c
Normal file
|
@ -0,0 +1,728 @@
|
||||||
|
// ALZ 압축 해제를 위해서 수정된 bzip2 소스
|
||||||
|
// [ALZ] 라고 표시된 부분이 수정된 부분이다.
|
||||||
|
|
||||||
|
|
||||||
|
/*-------------------------------------------------------------*/
|
||||||
|
/*--- Decompression machinery ---*/
|
||||||
|
/*--- decompress.c ---*/
|
||||||
|
/*-------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/*--
|
||||||
|
This file is a part of bzip2 and/or libbzip2, a program and
|
||||||
|
library for lossless, block-sorting data compression.
|
||||||
|
|
||||||
|
Copyright (C) 1996-2002 Julian R Seward. All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions
|
||||||
|
are met:
|
||||||
|
|
||||||
|
1. Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
2. The origin of this software must not be misrepresented; you must
|
||||||
|
not claim that you wrote the original software. If you use this
|
||||||
|
software in a product, an acknowledgment in the product
|
||||||
|
documentation would be appreciated but is not required.
|
||||||
|
|
||||||
|
3. Altered source versions must be plainly marked as such, and must
|
||||||
|
not be misrepresented as being the original software.
|
||||||
|
|
||||||
|
4. The name of the author may not be used to endorse or promote
|
||||||
|
products derived from this software without specific prior written
|
||||||
|
permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
|
||||||
|
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||||
|
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||||
|
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||||
|
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
|
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
Julian Seward, Cambridge, UK.
|
||||||
|
jseward@acm.org
|
||||||
|
bzip2/libbzip2 version 1.0 of 21 March 2000
|
||||||
|
|
||||||
|
This program is based on (at least) the work of:
|
||||||
|
Mike Burrows
|
||||||
|
David Wheeler
|
||||||
|
Peter Fenwick
|
||||||
|
Alistair Moffat
|
||||||
|
Radford Neal
|
||||||
|
Ian H. Witten
|
||||||
|
Robert Sedgewick
|
||||||
|
Jon L. Bentley
|
||||||
|
|
||||||
|
For more information on these sources, see the manual.
|
||||||
|
--*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "bzip2/bzlib_private.h"
|
||||||
|
|
||||||
|
|
||||||
|
/*---------------------------------------------------*/
|
||||||
|
static
|
||||||
|
void makeMaps_d ( DState* s )
|
||||||
|
{
|
||||||
|
Int32 i;
|
||||||
|
s->nInUse = 0;
|
||||||
|
for (i = 0; i < 256; i++)
|
||||||
|
if (s->inUse[i]) {
|
||||||
|
s->seqToUnseq[s->nInUse] = i;
|
||||||
|
s->nInUse++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*---------------------------------------------------*/
|
||||||
|
#define RETURN(rrr) \
|
||||||
|
{ retVal = rrr; goto save_state_and_return; };
|
||||||
|
|
||||||
|
#define GET_BITS(lll,vvv,nnn) \
|
||||||
|
case lll: s->state = lll; \
|
||||||
|
while (True) { \
|
||||||
|
if (s->bsLive >= nnn) { \
|
||||||
|
UInt32 v; \
|
||||||
|
v = (s->bsBuff >> \
|
||||||
|
(s->bsLive-nnn)) & ((1 << nnn)-1); \
|
||||||
|
s->bsLive -= nnn; \
|
||||||
|
vvv = v; \
|
||||||
|
break; \
|
||||||
|
} \
|
||||||
|
if (s->strm->avail_in == 0) RETURN(BZ_OK); \
|
||||||
|
s->bsBuff \
|
||||||
|
= (s->bsBuff << 8) | \
|
||||||
|
((UInt32) \
|
||||||
|
(*((UChar*)(s->strm->next_in)))); \
|
||||||
|
s->bsLive += 8; \
|
||||||
|
s->strm->next_in++; \
|
||||||
|
s->strm->avail_in--; \
|
||||||
|
s->strm->total_in_lo32++; \
|
||||||
|
if (s->strm->total_in_lo32 == 0) \
|
||||||
|
s->strm->total_in_hi32++; \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define GET_UCHAR(lll,uuu) \
|
||||||
|
GET_BITS(lll,uuu,8)
|
||||||
|
|
||||||
|
#define GET_BIT(lll,uuu) \
|
||||||
|
GET_BITS(lll,uuu,1)
|
||||||
|
|
||||||
|
/*---------------------------------------------------*/
|
||||||
|
#define GET_MTF_VAL(label1,label2,lval) \
|
||||||
|
{ \
|
||||||
|
if (groupPos == 0) { \
|
||||||
|
groupNo++; \
|
||||||
|
if (groupNo >= nSelectors) \
|
||||||
|
RETURN(BZ_DATA_ERROR); \
|
||||||
|
groupPos = BZ_G_SIZE; \
|
||||||
|
gSel = s->selector[groupNo]; \
|
||||||
|
gMinlen = s->minLens[gSel]; \
|
||||||
|
gLimit = &(s->limit[gSel][0]); \
|
||||||
|
gPerm = &(s->perm[gSel][0]); \
|
||||||
|
gBase = &(s->base[gSel][0]); \
|
||||||
|
} \
|
||||||
|
groupPos--; \
|
||||||
|
zn = gMinlen; \
|
||||||
|
GET_BITS(label1, zvec, zn); \
|
||||||
|
while (1) { \
|
||||||
|
if (zn > 20 /* the longest code */) \
|
||||||
|
RETURN(BZ_DATA_ERROR); \
|
||||||
|
if (zvec <= gLimit[zn]) break; \
|
||||||
|
zn++; \
|
||||||
|
GET_BIT(label2, zj); \
|
||||||
|
zvec = (zvec << 1) | zj; \
|
||||||
|
}; \
|
||||||
|
if (zvec - gBase[zn] < 0 \
|
||||||
|
|| zvec - gBase[zn] >= BZ_MAX_ALPHA_SIZE) \
|
||||||
|
RETURN(BZ_DATA_ERROR); \
|
||||||
|
lval = gPerm[zvec - gBase[zn]]; \
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*---------------------------------------------------*/
|
||||||
|
Int32 BZ2_decompress ( DState* s )
|
||||||
|
{
|
||||||
|
UChar uc;
|
||||||
|
Int32 retVal;
|
||||||
|
Int32 minLen, maxLen;
|
||||||
|
bz_stream* strm = s->strm;
|
||||||
|
|
||||||
|
/* stuff that needs to be saved/restored */
|
||||||
|
Int32 i;
|
||||||
|
Int32 j;
|
||||||
|
Int32 t;
|
||||||
|
Int32 alphaSize;
|
||||||
|
Int32 nGroups;
|
||||||
|
Int32 nSelectors;
|
||||||
|
Int32 EOB;
|
||||||
|
Int32 groupNo;
|
||||||
|
Int32 groupPos;
|
||||||
|
Int32 nextSym;
|
||||||
|
Int32 nblockMAX;
|
||||||
|
Int32 nblock;
|
||||||
|
Int32 es;
|
||||||
|
Int32 N;
|
||||||
|
Int32 curr;
|
||||||
|
Int32 zt;
|
||||||
|
Int32 zn;
|
||||||
|
Int32 zvec;
|
||||||
|
Int32 zj;
|
||||||
|
Int32 gSel;
|
||||||
|
Int32 gMinlen;
|
||||||
|
Int32* gLimit;
|
||||||
|
Int32* gBase;
|
||||||
|
Int32* gPerm;
|
||||||
|
|
||||||
|
if (s->state == BZ_X_MAGIC_1) {
|
||||||
|
/*initialise the save area*/
|
||||||
|
s->save_i = 0;
|
||||||
|
s->save_j = 0;
|
||||||
|
s->save_t = 0;
|
||||||
|
s->save_alphaSize = 0;
|
||||||
|
s->save_nGroups = 0;
|
||||||
|
s->save_nSelectors = 0;
|
||||||
|
s->save_EOB = 0;
|
||||||
|
s->save_groupNo = 0;
|
||||||
|
s->save_groupPos = 0;
|
||||||
|
s->save_nextSym = 0;
|
||||||
|
s->save_nblockMAX = 0;
|
||||||
|
s->save_nblock = 0;
|
||||||
|
s->save_es = 0;
|
||||||
|
s->save_N = 0;
|
||||||
|
s->save_curr = 0;
|
||||||
|
s->save_zt = 0;
|
||||||
|
s->save_zn = 0;
|
||||||
|
s->save_zvec = 0;
|
||||||
|
s->save_zj = 0;
|
||||||
|
s->save_gSel = 0;
|
||||||
|
s->save_gMinlen = 0;
|
||||||
|
s->save_gLimit = NULL;
|
||||||
|
s->save_gBase = NULL;
|
||||||
|
s->save_gPerm = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*restore from the save area*/
|
||||||
|
i = s->save_i;
|
||||||
|
j = s->save_j;
|
||||||
|
t = s->save_t;
|
||||||
|
alphaSize = s->save_alphaSize;
|
||||||
|
nGroups = s->save_nGroups;
|
||||||
|
nSelectors = s->save_nSelectors;
|
||||||
|
EOB = s->save_EOB;
|
||||||
|
groupNo = s->save_groupNo;
|
||||||
|
groupPos = s->save_groupPos;
|
||||||
|
nextSym = s->save_nextSym;
|
||||||
|
nblockMAX = s->save_nblockMAX;
|
||||||
|
nblock = s->save_nblock;
|
||||||
|
es = s->save_es;
|
||||||
|
N = s->save_N;
|
||||||
|
curr = s->save_curr;
|
||||||
|
zt = s->save_zt;
|
||||||
|
zn = s->save_zn;
|
||||||
|
zvec = s->save_zvec;
|
||||||
|
zj = s->save_zj;
|
||||||
|
gSel = s->save_gSel;
|
||||||
|
gMinlen = s->save_gMinlen;
|
||||||
|
gLimit = s->save_gLimit;
|
||||||
|
gBase = s->save_gBase;
|
||||||
|
gPerm = s->save_gPerm;
|
||||||
|
|
||||||
|
retVal = BZ_OK;
|
||||||
|
|
||||||
|
switch (s->state) {
|
||||||
|
|
||||||
|
// [ALZ] - 머리 떼기
|
||||||
|
/*
|
||||||
|
GET_UCHAR(BZ_X_MAGIC_1, uc);
|
||||||
|
if (uc != BZ_HDR_B)
|
||||||
|
RETURN(BZ_DATA_ERROR_MAGIC);
|
||||||
|
|
||||||
|
GET_UCHAR(BZ_X_MAGIC_2, uc);
|
||||||
|
if (uc != BZ_HDR_Z)
|
||||||
|
RETURN(BZ_DATA_ERROR_MAGIC);
|
||||||
|
|
||||||
|
GET_UCHAR(BZ_X_MAGIC_3, uc)
|
||||||
|
if (uc != BZ_HDR_h)
|
||||||
|
RETURN(BZ_DATA_ERROR_MAGIC);
|
||||||
|
*/
|
||||||
|
|
||||||
|
case BZ_X_MAGIC_1 : // 없어진 헤더 인식 대신
|
||||||
|
|
||||||
|
// [ALZ] - blocksize 지정 없음
|
||||||
|
//GET_BITS(BZ_X_MAGIC_4, s->blockSize100k, 8)
|
||||||
|
s->blockSize100k = 0x39; // static 할당.
|
||||||
|
|
||||||
|
if (s->blockSize100k < (BZ_HDR_0 + 1) ||
|
||||||
|
s->blockSize100k > (BZ_HDR_0 + 9))
|
||||||
|
RETURN(BZ_DATA_ERROR_MAGIC);
|
||||||
|
s->blockSize100k -= BZ_HDR_0;
|
||||||
|
|
||||||
|
if (s->smallDecompress) {
|
||||||
|
s->ll16 = BZALLOC( s->blockSize100k * 100000 * sizeof(UInt16) );
|
||||||
|
s->ll4 = BZALLOC(
|
||||||
|
((1 + s->blockSize100k * 100000) >> 1) * sizeof(UChar)
|
||||||
|
);
|
||||||
|
if (s->ll16 == NULL || s->ll4 == NULL)
|
||||||
|
RETURN(BZ_MEM_ERROR);
|
||||||
|
} else {
|
||||||
|
s->tt = BZALLOC( s->blockSize100k * 100000 * sizeof(Int32) );
|
||||||
|
if (s->tt == NULL)
|
||||||
|
RETURN(BZ_MEM_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
GET_UCHAR(BZ_X_BLKHDR_1, uc);
|
||||||
|
|
||||||
|
// [ALZ] - 변형된 헤더
|
||||||
|
|
||||||
|
if (uc != 'D')
|
||||||
|
RETURN(BZ_DATA_ERROR_MAGIC);
|
||||||
|
|
||||||
|
GET_UCHAR(BZ_X_BLKHDR_2, uc);
|
||||||
|
if (uc != 'L')
|
||||||
|
RETURN(BZ_DATA_ERROR_MAGIC);
|
||||||
|
|
||||||
|
GET_UCHAR(BZ_X_BLKHDR_3, uc)
|
||||||
|
if (uc != 'Z')
|
||||||
|
RETURN(BZ_DATA_ERROR_MAGIC);
|
||||||
|
|
||||||
|
GET_UCHAR(BZ_X_BLKHDR_4, uc)
|
||||||
|
|
||||||
|
if (uc == 0x02)
|
||||||
|
goto endhdr_2;
|
||||||
|
|
||||||
|
if (uc != 0x01)
|
||||||
|
RETURN(BZ_DATA_ERROR_MAGIC);
|
||||||
|
|
||||||
|
/* [ALZ] - 원래 헤더
|
||||||
|
if (uc == 0x17) goto endhdr_2;
|
||||||
|
if (uc != 0x31)
|
||||||
|
RETURN(BZ_DATA_ERROR);
|
||||||
|
GET_UCHAR(BZ_X_BLKHDR_2, uc);
|
||||||
|
if (uc != 0x41)
|
||||||
|
RETURN(BZ_DATA_ERROR);
|
||||||
|
GET_UCHAR(BZ_X_BLKHDR_3, uc);
|
||||||
|
if (uc != 0x59)
|
||||||
|
RETURN(BZ_DATA_ERROR);
|
||||||
|
GET_UCHAR(BZ_X_BLKHDR_4, uc);
|
||||||
|
if (uc != 0x26)
|
||||||
|
RETURN(BZ_DATA_ERROR);
|
||||||
|
GET_UCHAR(BZ_X_BLKHDR_5, uc);
|
||||||
|
if (uc != 0x53)
|
||||||
|
RETURN(BZ_DATA_ERROR);
|
||||||
|
GET_UCHAR(BZ_X_BLKHDR_6, uc);
|
||||||
|
if (uc != 0x59)
|
||||||
|
RETURN(BZ_DATA_ERROR);
|
||||||
|
*/
|
||||||
|
|
||||||
|
s->currBlockNo++;
|
||||||
|
if (s->verbosity >= 2)
|
||||||
|
VPrintf1 ( "\n [%d: huff+mtf ", s->currBlockNo );
|
||||||
|
|
||||||
|
s->storedBlockCRC = 0;
|
||||||
|
|
||||||
|
/* [ALZ] - crc 빼기
|
||||||
|
GET_UCHAR(BZ_X_BCRC_1, uc);
|
||||||
|
s->storedBlockCRC = (s->storedBlockCRC << 8) | ((UInt32)uc);
|
||||||
|
GET_UCHAR(BZ_X_BCRC_2, uc);
|
||||||
|
s->storedBlockCRC = (s->storedBlockCRC << 8) | ((UInt32)uc);
|
||||||
|
GET_UCHAR(BZ_X_BCRC_3, uc);
|
||||||
|
s->storedBlockCRC = (s->storedBlockCRC << 8) | ((UInt32)uc);
|
||||||
|
GET_UCHAR(BZ_X_BCRC_4, uc);
|
||||||
|
s->storedBlockCRC = (s->storedBlockCRC << 8) | ((UInt32)uc);
|
||||||
|
*/
|
||||||
|
|
||||||
|
// [ALZ] - 1bit 아끼기
|
||||||
|
//GET_BITS(BZ_X_RANDBIT, s->blockRandomised, 1);
|
||||||
|
|
||||||
|
s->origPtr = 0;
|
||||||
|
GET_UCHAR(BZ_X_ORIGPTR_1, uc);
|
||||||
|
s->origPtr = (s->origPtr << 8) | ((Int32)uc);
|
||||||
|
GET_UCHAR(BZ_X_ORIGPTR_2, uc);
|
||||||
|
s->origPtr = (s->origPtr << 8) | ((Int32)uc);
|
||||||
|
GET_UCHAR(BZ_X_ORIGPTR_3, uc);
|
||||||
|
s->origPtr = (s->origPtr << 8) | ((Int32)uc);
|
||||||
|
|
||||||
|
if (s->origPtr < 0)
|
||||||
|
RETURN(BZ_DATA_ERROR);
|
||||||
|
if (s->origPtr > 10 + 100000*s->blockSize100k)
|
||||||
|
RETURN(BZ_DATA_ERROR);
|
||||||
|
|
||||||
|
/*--- Receive the mapping table ---*/
|
||||||
|
for (i = 0; i < 16; i++) {
|
||||||
|
GET_BIT(BZ_X_MAPPING_1, uc);
|
||||||
|
if (uc == 1)
|
||||||
|
s->inUse16[i] = True; else
|
||||||
|
s->inUse16[i] = False;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < 256; i++) s->inUse[i] = False;
|
||||||
|
|
||||||
|
for (i = 0; i < 16; i++)
|
||||||
|
if (s->inUse16[i])
|
||||||
|
for (j = 0; j < 16; j++) {
|
||||||
|
GET_BIT(BZ_X_MAPPING_2, uc);
|
||||||
|
if (uc == 1) s->inUse[i * 16 + j] = True;
|
||||||
|
}
|
||||||
|
makeMaps_d ( s );
|
||||||
|
if (s->nInUse == 0)
|
||||||
|
RETURN(BZ_DATA_ERROR);
|
||||||
|
alphaSize = s->nInUse+2;
|
||||||
|
|
||||||
|
/*--- Now the selectors ---*/
|
||||||
|
GET_BITS(BZ_X_SELECTOR_1, nGroups, 3);
|
||||||
|
if (nGroups < 2 || nGroups > 6)
|
||||||
|
RETURN(BZ_DATA_ERROR);
|
||||||
|
GET_BITS(BZ_X_SELECTOR_2, nSelectors, 15);
|
||||||
|
if (nSelectors < 1)
|
||||||
|
RETURN(BZ_DATA_ERROR);
|
||||||
|
for (i = 0; i < nSelectors; i++) {
|
||||||
|
j = 0;
|
||||||
|
while (True) {
|
||||||
|
GET_BIT(BZ_X_SELECTOR_3, uc);
|
||||||
|
if (uc == 0) break;
|
||||||
|
j++;
|
||||||
|
if (j >= nGroups)
|
||||||
|
RETURN(BZ_DATA_ERROR);
|
||||||
|
}
|
||||||
|
s->selectorMtf[i] = j;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--- Undo the MTF values for the selectors. ---*/
|
||||||
|
{
|
||||||
|
UChar pos[BZ_N_GROUPS], tmp, v;
|
||||||
|
for (v = 0; v < nGroups; v++) pos[v] = v;
|
||||||
|
|
||||||
|
for (i = 0; i < nSelectors; i++) {
|
||||||
|
v = s->selectorMtf[i];
|
||||||
|
tmp = pos[v];
|
||||||
|
while (v > 0) { pos[v] = pos[v-1]; v--; }
|
||||||
|
pos[0] = tmp;
|
||||||
|
s->selector[i] = tmp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--- Now the coding tables ---*/
|
||||||
|
for (t = 0; t < nGroups; t++) {
|
||||||
|
GET_BITS(BZ_X_CODING_1, curr, 5);
|
||||||
|
for (i = 0; i < alphaSize; i++) {
|
||||||
|
while (True) {
|
||||||
|
if (curr < 1 || curr > 20)
|
||||||
|
RETURN(BZ_DATA_ERROR);
|
||||||
|
GET_BIT(BZ_X_CODING_2, uc);
|
||||||
|
if (uc == 0) break;
|
||||||
|
GET_BIT(BZ_X_CODING_3, uc);
|
||||||
|
if (uc == 0) curr++; else curr--;
|
||||||
|
}
|
||||||
|
s->len[t][i] = curr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--- Create the Huffman decoding tables ---*/
|
||||||
|
for (t = 0; t < nGroups; t++) {
|
||||||
|
minLen = 32;
|
||||||
|
maxLen = 0;
|
||||||
|
for (i = 0; i < alphaSize; i++) {
|
||||||
|
if (s->len[t][i] > maxLen) maxLen = s->len[t][i];
|
||||||
|
if (s->len[t][i] < minLen) minLen = s->len[t][i];
|
||||||
|
}
|
||||||
|
BZ2_hbCreateDecodeTables (
|
||||||
|
&(s->limit[t][0]),
|
||||||
|
&(s->base[t][0]),
|
||||||
|
&(s->perm[t][0]),
|
||||||
|
&(s->len[t][0]),
|
||||||
|
minLen, maxLen, alphaSize
|
||||||
|
);
|
||||||
|
s->minLens[t] = minLen;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--- Now the MTF values ---*/
|
||||||
|
|
||||||
|
EOB = s->nInUse+1;
|
||||||
|
nblockMAX = 100000 * s->blockSize100k;
|
||||||
|
groupNo = -1;
|
||||||
|
groupPos = 0;
|
||||||
|
|
||||||
|
for (i = 0; i <= 255; i++) s->unzftab[i] = 0;
|
||||||
|
|
||||||
|
/*-- MTF init --*/
|
||||||
|
{
|
||||||
|
Int32 ii, jj, kk;
|
||||||
|
kk = MTFA_SIZE-1;
|
||||||
|
for (ii = 256 / MTFL_SIZE - 1; ii >= 0; ii--) {
|
||||||
|
for (jj = MTFL_SIZE-1; jj >= 0; jj--) {
|
||||||
|
s->mtfa[kk] = (UChar)(ii * MTFL_SIZE + jj);
|
||||||
|
kk--;
|
||||||
|
}
|
||||||
|
s->mtfbase[ii] = kk + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*-- end MTF init --*/
|
||||||
|
|
||||||
|
nblock = 0;
|
||||||
|
GET_MTF_VAL(BZ_X_MTF_1, BZ_X_MTF_2, nextSym);
|
||||||
|
|
||||||
|
while (True) {
|
||||||
|
|
||||||
|
if (nextSym == EOB) break;
|
||||||
|
|
||||||
|
if (nextSym == BZ_RUNA || nextSym == BZ_RUNB) {
|
||||||
|
|
||||||
|
es = -1;
|
||||||
|
N = 1;
|
||||||
|
do {
|
||||||
|
if (nextSym == BZ_RUNA) es = es + (0+1) * N; else
|
||||||
|
if (nextSym == BZ_RUNB) es = es + (1+1) * N;
|
||||||
|
N = N * 2;
|
||||||
|
GET_MTF_VAL(BZ_X_MTF_3, BZ_X_MTF_4, nextSym);
|
||||||
|
}
|
||||||
|
while (nextSym == BZ_RUNA || nextSym == BZ_RUNB);
|
||||||
|
|
||||||
|
es++;
|
||||||
|
uc = s->seqToUnseq[ s->mtfa[s->mtfbase[0]] ];
|
||||||
|
s->unzftab[uc] += es;
|
||||||
|
|
||||||
|
if (s->smallDecompress)
|
||||||
|
while (es > 0) {
|
||||||
|
if (nblock >= nblockMAX)
|
||||||
|
RETURN(BZ_DATA_ERROR);
|
||||||
|
s->ll16[nblock] = (UInt16)uc;
|
||||||
|
nblock++;
|
||||||
|
es--;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
while (es > 0) {
|
||||||
|
if (nblock >= nblockMAX)
|
||||||
|
RETURN(BZ_DATA_ERROR);
|
||||||
|
s->tt[nblock] = (UInt32)uc;
|
||||||
|
nblock++;
|
||||||
|
es--;
|
||||||
|
};
|
||||||
|
|
||||||
|
continue;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
if (nblock >= nblockMAX)
|
||||||
|
RETURN(BZ_DATA_ERROR);
|
||||||
|
|
||||||
|
/*-- uc = MTF ( nextSym-1 ) --*/
|
||||||
|
{
|
||||||
|
Int32 ii, jj, kk, pp, lno, off;
|
||||||
|
UInt32 nn;
|
||||||
|
nn = (UInt32)(nextSym - 1);
|
||||||
|
|
||||||
|
if (nn < MTFL_SIZE) {
|
||||||
|
/* avoid general-case expense */
|
||||||
|
pp = s->mtfbase[0];
|
||||||
|
uc = s->mtfa[pp+nn];
|
||||||
|
while (nn > 3) {
|
||||||
|
Int32 z = pp+nn;
|
||||||
|
s->mtfa[(z) ] = s->mtfa[(z)-1];
|
||||||
|
s->mtfa[(z)-1] = s->mtfa[(z)-2];
|
||||||
|
s->mtfa[(z)-2] = s->mtfa[(z)-3];
|
||||||
|
s->mtfa[(z)-3] = s->mtfa[(z)-4];
|
||||||
|
nn -= 4;
|
||||||
|
}
|
||||||
|
while (nn > 0) {
|
||||||
|
s->mtfa[(pp+nn)] = s->mtfa[(pp+nn)-1]; nn--;
|
||||||
|
};
|
||||||
|
s->mtfa[pp] = uc;
|
||||||
|
} else {
|
||||||
|
/* general case */
|
||||||
|
lno = nn / MTFL_SIZE;
|
||||||
|
off = nn % MTFL_SIZE;
|
||||||
|
pp = s->mtfbase[lno] + off;
|
||||||
|
uc = s->mtfa[pp];
|
||||||
|
while (pp > s->mtfbase[lno]) {
|
||||||
|
s->mtfa[pp] = s->mtfa[pp-1]; pp--;
|
||||||
|
};
|
||||||
|
s->mtfbase[lno]++;
|
||||||
|
while (lno > 0) {
|
||||||
|
s->mtfbase[lno]--;
|
||||||
|
s->mtfa[s->mtfbase[lno]]
|
||||||
|
= s->mtfa[s->mtfbase[lno-1] + MTFL_SIZE - 1];
|
||||||
|
lno--;
|
||||||
|
}
|
||||||
|
s->mtfbase[0]--;
|
||||||
|
s->mtfa[s->mtfbase[0]] = uc;
|
||||||
|
if (s->mtfbase[0] == 0) {
|
||||||
|
kk = MTFA_SIZE-1;
|
||||||
|
for (ii = 256 / MTFL_SIZE-1; ii >= 0; ii--) {
|
||||||
|
for (jj = MTFL_SIZE-1; jj >= 0; jj--) {
|
||||||
|
s->mtfa[kk] = s->mtfa[s->mtfbase[ii] + jj];
|
||||||
|
kk--;
|
||||||
|
}
|
||||||
|
s->mtfbase[ii] = kk + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*-- end uc = MTF ( nextSym-1 ) --*/
|
||||||
|
|
||||||
|
s->unzftab[s->seqToUnseq[uc]]++;
|
||||||
|
if (s->smallDecompress)
|
||||||
|
s->ll16[nblock] = (UInt16)(s->seqToUnseq[uc]); else
|
||||||
|
s->tt[nblock] = (UInt32)(s->seqToUnseq[uc]);
|
||||||
|
nblock++;
|
||||||
|
|
||||||
|
GET_MTF_VAL(BZ_X_MTF_5, BZ_X_MTF_6, nextSym);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Now we know what nblock is, we can do a better sanity
|
||||||
|
check on s->origPtr.
|
||||||
|
*/
|
||||||
|
if (s->origPtr < 0 || s->origPtr >= nblock)
|
||||||
|
RETURN(BZ_DATA_ERROR);
|
||||||
|
|
||||||
|
s->state_out_len = 0;
|
||||||
|
s->state_out_ch = 0;
|
||||||
|
BZ_INITIALISE_CRC ( s->calculatedBlockCRC );
|
||||||
|
s->state = BZ_X_OUTPUT;
|
||||||
|
if (s->verbosity >= 2) VPrintf0 ( "rt+rld" );
|
||||||
|
|
||||||
|
/*-- Set up cftab to facilitate generation of T^(-1) --*/
|
||||||
|
s->cftab[0] = 0;
|
||||||
|
for (i = 1; i <= 256; i++) s->cftab[i] = s->unzftab[i-1];
|
||||||
|
for (i = 1; i <= 256; i++) s->cftab[i] += s->cftab[i-1];
|
||||||
|
|
||||||
|
if (s->smallDecompress) {
|
||||||
|
|
||||||
|
/*-- Make a copy of cftab, used in generation of T --*/
|
||||||
|
for (i = 0; i <= 256; i++) s->cftabCopy[i] = s->cftab[i];
|
||||||
|
|
||||||
|
/*-- compute the T vector --*/
|
||||||
|
for (i = 0; i < nblock; i++) {
|
||||||
|
uc = (UChar)(s->ll16[i]);
|
||||||
|
SET_LL(i, s->cftabCopy[uc]);
|
||||||
|
s->cftabCopy[uc]++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*-- Compute T^(-1) by pointer reversal on T --*/
|
||||||
|
i = s->origPtr;
|
||||||
|
j = GET_LL(i);
|
||||||
|
do {
|
||||||
|
Int32 tmp = GET_LL(j);
|
||||||
|
SET_LL(j, i);
|
||||||
|
i = j;
|
||||||
|
j = tmp;
|
||||||
|
}
|
||||||
|
while (i != s->origPtr);
|
||||||
|
|
||||||
|
s->tPos = s->origPtr;
|
||||||
|
s->nblock_used = 0;
|
||||||
|
if (s->blockRandomised) {
|
||||||
|
BZ_RAND_INIT_MASK;
|
||||||
|
BZ_GET_SMALL(s->k0); s->nblock_used++;
|
||||||
|
BZ_RAND_UPD_MASK; s->k0 ^= BZ_RAND_MASK;
|
||||||
|
} else {
|
||||||
|
BZ_GET_SMALL(s->k0); s->nblock_used++;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
/*-- compute the T^(-1) vector --*/
|
||||||
|
for (i = 0; i < nblock; i++) {
|
||||||
|
uc = (UChar)(s->tt[i] & 0xff);
|
||||||
|
s->tt[s->cftab[uc]] |= (i << 8);
|
||||||
|
s->cftab[uc]++;
|
||||||
|
}
|
||||||
|
|
||||||
|
s->tPos = s->tt[s->origPtr] >> 8;
|
||||||
|
s->nblock_used = 0;
|
||||||
|
// [ALZ] - s->blockRandomised 는 생략 되었다.
|
||||||
|
/*
|
||||||
|
if (s->blockRandomised) {
|
||||||
|
BZ_RAND_INIT_MASK;
|
||||||
|
BZ_GET_FAST(s->k0); s->nblock_used++;
|
||||||
|
BZ_RAND_UPD_MASK; s->k0 ^= BZ_RAND_MASK;
|
||||||
|
} else*/ {
|
||||||
|
BZ_GET_FAST(s->k0); s->nblock_used++;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
RETURN(BZ_OK);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
endhdr_2:
|
||||||
|
|
||||||
|
// [ALZ] - 꼬리 떼기
|
||||||
|
/*
|
||||||
|
GET_UCHAR(BZ_X_ENDHDR_2, uc);
|
||||||
|
if (uc != 0x72)
|
||||||
|
RETURN(BZ_DATA_ERROR);
|
||||||
|
GET_UCHAR(BZ_X_ENDHDR_3, uc);
|
||||||
|
if (uc != 0x45)
|
||||||
|
RETURN(BZ_DATA_ERROR);
|
||||||
|
GET_UCHAR(BZ_X_ENDHDR_4, uc);
|
||||||
|
if (uc != 0x38)
|
||||||
|
RETURN(BZ_DATA_ERROR);
|
||||||
|
GET_UCHAR(BZ_X_ENDHDR_5, uc);
|
||||||
|
if (uc != 0x50)
|
||||||
|
RETURN(BZ_DATA_ERROR);
|
||||||
|
GET_UCHAR(BZ_X_ENDHDR_6, uc);
|
||||||
|
if (uc != 0x90)
|
||||||
|
RETURN(BZ_DATA_ERROR);
|
||||||
|
|
||||||
|
s->storedCombinedCRC = 0;
|
||||||
|
GET_UCHAR(BZ_X_CCRC_1, uc);
|
||||||
|
s->storedCombinedCRC = (s->storedCombinedCRC << 8) | ((UInt32)uc);
|
||||||
|
GET_UCHAR(BZ_X_CCRC_2, uc);
|
||||||
|
s->storedCombinedCRC = (s->storedCombinedCRC << 8) | ((UInt32)uc);
|
||||||
|
GET_UCHAR(BZ_X_CCRC_3, uc);
|
||||||
|
s->storedCombinedCRC = (s->storedCombinedCRC << 8) | ((UInt32)uc);
|
||||||
|
GET_UCHAR(BZ_X_CCRC_4, uc);
|
||||||
|
s->storedCombinedCRC = (s->storedCombinedCRC << 8) | ((UInt32)uc);
|
||||||
|
*/
|
||||||
|
|
||||||
|
s->state = BZ_X_IDLE;
|
||||||
|
RETURN(BZ_STREAM_END);
|
||||||
|
|
||||||
|
default: AssertH ( False, 4001 );
|
||||||
|
}
|
||||||
|
|
||||||
|
AssertH ( False, 4002 );
|
||||||
|
|
||||||
|
save_state_and_return:
|
||||||
|
|
||||||
|
s->save_i = i;
|
||||||
|
s->save_j = j;
|
||||||
|
s->save_t = t;
|
||||||
|
s->save_alphaSize = alphaSize;
|
||||||
|
s->save_nGroups = nGroups;
|
||||||
|
s->save_nSelectors = nSelectors;
|
||||||
|
s->save_EOB = EOB;
|
||||||
|
s->save_groupNo = groupNo;
|
||||||
|
s->save_groupPos = groupPos;
|
||||||
|
s->save_nextSym = nextSym;
|
||||||
|
s->save_nblockMAX = nblockMAX;
|
||||||
|
s->save_nblock = nblock;
|
||||||
|
s->save_es = es;
|
||||||
|
s->save_N = N;
|
||||||
|
s->save_curr = curr;
|
||||||
|
s->save_zt = zt;
|
||||||
|
s->save_zn = zn;
|
||||||
|
s->save_zvec = zvec;
|
||||||
|
s->save_zj = zj;
|
||||||
|
s->save_gSel = gSel;
|
||||||
|
s->save_gMinlen = gMinlen;
|
||||||
|
s->save_gLimit = gLimit;
|
||||||
|
s->save_gBase = gBase;
|
||||||
|
s->save_gPerm = gPerm;
|
||||||
|
|
||||||
|
return retVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*-------------------------------------------------------------*/
|
||||||
|
/*--- end decompress.c ---*/
|
||||||
|
/*-------------------------------------------------------------*/
|
180
UnAlzBzip2.cpp
Normal file
180
UnAlzBzip2.cpp
Normal file
|
@ -0,0 +1,180 @@
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
///
|
||||||
|
/// bzip2 관련 file i/o 함수들 - 원래 UnAlzbzlib.c (bzlib.c) 에 있던 함수들은 분할 압축 처리를 위해서
|
||||||
|
/// 약간의 수정을 가한 소스들이다..
|
||||||
|
/// FILE* handle 관련 부분들이 수정되었다.
|
||||||
|
///
|
||||||
|
/// @author hardkoder@gmail.com
|
||||||
|
/// @date 2004-10-03 오후 3:09:11
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
//#include "stdafx.h"
|
||||||
|
#include "zlib/zlib.h"
|
||||||
|
#include "bzip2/bzlib.h"
|
||||||
|
#include "bzip2/bzlib_private.h"
|
||||||
|
#include "UnAlz.h"
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
CUnAlz* handle;
|
||||||
|
Char buf[BZ_MAX_UNUSED];
|
||||||
|
Int32 bufN;
|
||||||
|
Bool writing;
|
||||||
|
bz_stream strm;
|
||||||
|
Int32 lastErr;
|
||||||
|
Bool initialisedOk;
|
||||||
|
}
|
||||||
|
MybzFile;
|
||||||
|
|
||||||
|
#define BZ_SETERR(eee) \
|
||||||
|
{ \
|
||||||
|
if (bzerror != NULL) *bzerror = eee; \
|
||||||
|
if (bzf != NULL) bzf->lastErr = eee; \
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// BZIP2 파일 처리 함수
|
||||||
|
/// @param bzerror
|
||||||
|
/// @param f
|
||||||
|
/// @param verbosity
|
||||||
|
/// @param _small
|
||||||
|
/// @param unused
|
||||||
|
/// @param nUnused
|
||||||
|
/// @return
|
||||||
|
/// @date 2004-10-03 오전 3:16:45
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
CUnAlz::MYBZFILE* CUnAlz::BZ2_bzReadOpen(int* bzerror, CUnAlz* f, int verbosity, int _small,void* unused, int nUnused)
|
||||||
|
{
|
||||||
|
MybzFile* bzf = NULL;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
BZ_SETERR(BZ_OK);
|
||||||
|
|
||||||
|
if (f == NULL ||
|
||||||
|
(_small != 0 && _small != 1) ||
|
||||||
|
(verbosity < 0 || verbosity > 4) ||
|
||||||
|
(unused == NULL && nUnused != 0) ||
|
||||||
|
(unused != NULL && (nUnused < 0 || nUnused > BZ_MAX_UNUSED)))
|
||||||
|
{ BZ_SETERR(BZ_PARAM_ERROR); return NULL; };
|
||||||
|
|
||||||
|
// if (f->FEof())
|
||||||
|
// { BZ_SETERR(BZ_IO_ERROR); return NULL; };
|
||||||
|
|
||||||
|
bzf = (MybzFile*)malloc ( sizeof(MybzFile) );
|
||||||
|
if (bzf == NULL)
|
||||||
|
{ BZ_SETERR(BZ_MEM_ERROR); return NULL; };
|
||||||
|
|
||||||
|
BZ_SETERR(BZ_OK);
|
||||||
|
|
||||||
|
bzf->initialisedOk = False;
|
||||||
|
bzf->handle = f;
|
||||||
|
bzf->bufN = 0;
|
||||||
|
bzf->writing = False;
|
||||||
|
bzf->strm.bzalloc = NULL;
|
||||||
|
bzf->strm.bzfree = NULL;
|
||||||
|
bzf->strm.opaque = NULL;
|
||||||
|
|
||||||
|
while (nUnused > 0) {
|
||||||
|
bzf->buf[bzf->bufN] = *((UChar*)(unused)); bzf->bufN++;
|
||||||
|
unused = ((void*)( 1 + ((UChar*)(unused)) ));
|
||||||
|
nUnused--;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = BZ2_bzDecompressInit ( &(bzf->strm), verbosity, _small );
|
||||||
|
if (ret != BZ_OK)
|
||||||
|
{ BZ_SETERR(ret); free(bzf); return NULL; };
|
||||||
|
|
||||||
|
bzf->strm.avail_in = bzf->bufN;
|
||||||
|
bzf->strm.next_in = bzf->buf;
|
||||||
|
|
||||||
|
bzf->initialisedOk = True;
|
||||||
|
return bzf;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int CUnAlz::BZ2_bzread(MYBZFILE* b, void* buf, int len )
|
||||||
|
{
|
||||||
|
int bzerr, nread;
|
||||||
|
if (((MybzFile*)b)->lastErr == BZ_STREAM_END) return 0;
|
||||||
|
nread = BZ2_bzRead(&bzerr,b,buf,len);
|
||||||
|
if (bzerr == BZ_OK || bzerr == BZ_STREAM_END) {
|
||||||
|
return nread;
|
||||||
|
} else {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int CUnAlz::BZ2_bzRead(int* bzerror, MYBZFILE* b, void* buf, int len)
|
||||||
|
{
|
||||||
|
Int32 n, ret;
|
||||||
|
MybzFile* bzf = (MybzFile*)b;
|
||||||
|
|
||||||
|
BZ_SETERR(BZ_OK);
|
||||||
|
|
||||||
|
if (bzf == NULL || buf == NULL || len < 0)
|
||||||
|
{ BZ_SETERR(BZ_PARAM_ERROR); return 0; };
|
||||||
|
|
||||||
|
if (bzf->writing)
|
||||||
|
{ BZ_SETERR(BZ_SEQUENCE_ERROR); return 0; };
|
||||||
|
|
||||||
|
if (len == 0)
|
||||||
|
{ BZ_SETERR(BZ_OK); return 0; };
|
||||||
|
|
||||||
|
bzf->strm.avail_out = len;
|
||||||
|
bzf->strm.next_out = (char*)buf;
|
||||||
|
|
||||||
|
while (True) {
|
||||||
|
|
||||||
|
// if (ferror(bzf->handle))
|
||||||
|
// { BZ_SETERR(BZ_IO_ERROR); return 0; };
|
||||||
|
|
||||||
|
if (bzf->strm.avail_in == 0 && !bzf->handle->FEof()) {
|
||||||
|
bzf->handle->FRead(bzf->buf, sizeof(UChar)*BZ_MAX_UNUSED, &n);
|
||||||
|
|
||||||
|
if(n==0)
|
||||||
|
{ BZ_SETERR(BZ_IO_ERROR); return 0; };
|
||||||
|
bzf->bufN = n;
|
||||||
|
bzf->strm.avail_in = bzf->bufN;
|
||||||
|
bzf->strm.next_in = bzf->buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = BZ2_bzDecompress ( &(bzf->strm) );
|
||||||
|
|
||||||
|
if (ret != BZ_OK && ret != BZ_STREAM_END)
|
||||||
|
{ BZ_SETERR(ret); return 0; };
|
||||||
|
|
||||||
|
if (ret == BZ_OK && bzf->handle->FEof() &&
|
||||||
|
bzf->strm.avail_in == 0 && bzf->strm.avail_out > 0)
|
||||||
|
{ BZ_SETERR(BZ_UNEXPECTED_EOF); return 0; };
|
||||||
|
|
||||||
|
if (ret == BZ_STREAM_END)
|
||||||
|
{ BZ_SETERR(BZ_STREAM_END);
|
||||||
|
return len - bzf->strm.avail_out; };
|
||||||
|
if (bzf->strm.avail_out == 0)
|
||||||
|
{ BZ_SETERR(BZ_OK); return len; };
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0; /*not reached*/
|
||||||
|
}
|
||||||
|
|
||||||
|
void CUnAlz::BZ2_bzReadClose( int *bzerror, MYBZFILE *b )
|
||||||
|
{
|
||||||
|
MybzFile* bzf = (MybzFile*)b;
|
||||||
|
|
||||||
|
BZ_SETERR(BZ_OK);
|
||||||
|
if (bzf == NULL)
|
||||||
|
{ BZ_SETERR(BZ_OK); return; };
|
||||||
|
|
||||||
|
if (bzf->writing)
|
||||||
|
{ BZ_SETERR(BZ_SEQUENCE_ERROR); return; };
|
||||||
|
|
||||||
|
if (bzf->initialisedOk)
|
||||||
|
(void)BZ2_bzDecompressEnd ( &(bzf->strm) );
|
||||||
|
free ( bzf );
|
||||||
|
}
|
||||||
|
|
1601
UnAlzbzlib.c
Normal file
1601
UnAlzbzlib.c
Normal file
File diff suppressed because it is too large
Load diff
1141
bzip2/blocksort.c
Normal file
1141
bzip2/blocksort.c
Normal file
File diff suppressed because it is too large
Load diff
321
bzip2/bzlib.h
Normal file
321
bzip2/bzlib.h
Normal file
|
@ -0,0 +1,321 @@
|
||||||
|
|
||||||
|
/*-------------------------------------------------------------*/
|
||||||
|
/*--- Public header file for the library. ---*/
|
||||||
|
/*--- bzlib.h ---*/
|
||||||
|
/*-------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/*--
|
||||||
|
This file is a part of bzip2 and/or libbzip2, a program and
|
||||||
|
library for lossless, block-sorting data compression.
|
||||||
|
|
||||||
|
Copyright (C) 1996-2002 Julian R Seward. All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions
|
||||||
|
are met:
|
||||||
|
|
||||||
|
1. Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
2. The origin of this software must not be misrepresented; you must
|
||||||
|
not claim that you wrote the original software. If you use this
|
||||||
|
software in a product, an acknowledgment in the product
|
||||||
|
documentation would be appreciated but is not required.
|
||||||
|
|
||||||
|
3. Altered source versions must be plainly marked as such, and must
|
||||||
|
not be misrepresented as being the original software.
|
||||||
|
|
||||||
|
4. The name of the author may not be used to endorse or promote
|
||||||
|
products derived from this software without specific prior written
|
||||||
|
permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
|
||||||
|
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||||
|
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||||
|
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||||
|
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
|
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
Julian Seward, Cambridge, UK.
|
||||||
|
jseward@acm.org
|
||||||
|
bzip2/libbzip2 version 1.0 of 21 March 2000
|
||||||
|
|
||||||
|
This program is based on (at least) the work of:
|
||||||
|
Mike Burrows
|
||||||
|
David Wheeler
|
||||||
|
Peter Fenwick
|
||||||
|
Alistair Moffat
|
||||||
|
Radford Neal
|
||||||
|
Ian H. Witten
|
||||||
|
Robert Sedgewick
|
||||||
|
Jon L. Bentley
|
||||||
|
|
||||||
|
For more information on these sources, see the manual.
|
||||||
|
--*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef _BZLIB_H
|
||||||
|
#define _BZLIB_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define BZ_RUN 0
|
||||||
|
#define BZ_FLUSH 1
|
||||||
|
#define BZ_FINISH 2
|
||||||
|
|
||||||
|
#define BZ_OK 0
|
||||||
|
#define BZ_RUN_OK 1
|
||||||
|
#define BZ_FLUSH_OK 2
|
||||||
|
#define BZ_FINISH_OK 3
|
||||||
|
#define BZ_STREAM_END 4
|
||||||
|
#define BZ_SEQUENCE_ERROR (-1)
|
||||||
|
#define BZ_PARAM_ERROR (-2)
|
||||||
|
#define BZ_MEM_ERROR (-3)
|
||||||
|
#define BZ_DATA_ERROR (-4)
|
||||||
|
#define BZ_DATA_ERROR_MAGIC (-5)
|
||||||
|
#define BZ_IO_ERROR (-6)
|
||||||
|
#define BZ_UNEXPECTED_EOF (-7)
|
||||||
|
#define BZ_OUTBUFF_FULL (-8)
|
||||||
|
#define BZ_CONFIG_ERROR (-9)
|
||||||
|
|
||||||
|
typedef
|
||||||
|
struct {
|
||||||
|
char *next_in;
|
||||||
|
unsigned int avail_in;
|
||||||
|
unsigned int total_in_lo32;
|
||||||
|
unsigned int total_in_hi32;
|
||||||
|
|
||||||
|
char *next_out;
|
||||||
|
unsigned int avail_out;
|
||||||
|
unsigned int total_out_lo32;
|
||||||
|
unsigned int total_out_hi32;
|
||||||
|
|
||||||
|
void *state;
|
||||||
|
|
||||||
|
void *(*bzalloc)(void *,int,int);
|
||||||
|
void (*bzfree)(void *,void *);
|
||||||
|
void *opaque;
|
||||||
|
}
|
||||||
|
bz_stream;
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef BZ_IMPORT
|
||||||
|
#define BZ_EXPORT
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Need a definitition for FILE */
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
# include <windows.h>
|
||||||
|
# ifdef small
|
||||||
|
/* windows.h define small to char */
|
||||||
|
# undef small
|
||||||
|
# endif
|
||||||
|
# ifdef BZ_EXPORT
|
||||||
|
# define BZ_API(func) WINAPI func
|
||||||
|
# define BZ_EXTERN extern
|
||||||
|
# else
|
||||||
|
/* import windows dll dynamically */
|
||||||
|
# define BZ_API(func) (WINAPI * func)
|
||||||
|
# define BZ_EXTERN
|
||||||
|
# endif
|
||||||
|
#else
|
||||||
|
# define BZ_API(func) func
|
||||||
|
# define BZ_EXTERN extern
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/*-- Core (low-level) library functions --*/
|
||||||
|
|
||||||
|
BZ_EXTERN int BZ_API(BZ2_bzCompressInit) (
|
||||||
|
bz_stream* strm,
|
||||||
|
int blockSize100k,
|
||||||
|
int verbosity,
|
||||||
|
int workFactor
|
||||||
|
);
|
||||||
|
|
||||||
|
BZ_EXTERN int BZ_API(BZ2_bzCompress) (
|
||||||
|
bz_stream* strm,
|
||||||
|
int action
|
||||||
|
);
|
||||||
|
|
||||||
|
BZ_EXTERN int BZ_API(BZ2_bzCompressEnd) (
|
||||||
|
bz_stream* strm
|
||||||
|
);
|
||||||
|
|
||||||
|
BZ_EXTERN int BZ_API(BZ2_bzDecompressInit) (
|
||||||
|
bz_stream *strm,
|
||||||
|
int verbosity,
|
||||||
|
int small
|
||||||
|
);
|
||||||
|
|
||||||
|
BZ_EXTERN int BZ_API(BZ2_bzDecompress) (
|
||||||
|
bz_stream* strm
|
||||||
|
);
|
||||||
|
|
||||||
|
BZ_EXTERN int BZ_API(BZ2_bzDecompressEnd) (
|
||||||
|
bz_stream *strm
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*-- High(er) level library functions --*/
|
||||||
|
|
||||||
|
#ifndef BZ_NO_STDIO
|
||||||
|
#define BZ_MAX_UNUSED 5000
|
||||||
|
|
||||||
|
typedef void BZFILE;
|
||||||
|
|
||||||
|
BZ_EXTERN BZFILE* BZ_API(BZ2_bzReadOpen) (
|
||||||
|
int* bzerror,
|
||||||
|
FILE* f,
|
||||||
|
int verbosity,
|
||||||
|
int small,
|
||||||
|
void* unused,
|
||||||
|
int nUnused
|
||||||
|
);
|
||||||
|
|
||||||
|
BZ_EXTERN void BZ_API(BZ2_bzReadClose) (
|
||||||
|
int* bzerror,
|
||||||
|
BZFILE* b
|
||||||
|
);
|
||||||
|
|
||||||
|
BZ_EXTERN void BZ_API(BZ2_bzReadGetUnused) (
|
||||||
|
int* bzerror,
|
||||||
|
BZFILE* b,
|
||||||
|
void** unused,
|
||||||
|
int* nUnused
|
||||||
|
);
|
||||||
|
|
||||||
|
BZ_EXTERN int BZ_API(BZ2_bzRead) (
|
||||||
|
int* bzerror,
|
||||||
|
BZFILE* b,
|
||||||
|
void* buf,
|
||||||
|
int len
|
||||||
|
);
|
||||||
|
|
||||||
|
BZ_EXTERN BZFILE* BZ_API(BZ2_bzWriteOpen) (
|
||||||
|
int* bzerror,
|
||||||
|
FILE* f,
|
||||||
|
int blockSize100k,
|
||||||
|
int verbosity,
|
||||||
|
int workFactor
|
||||||
|
);
|
||||||
|
|
||||||
|
BZ_EXTERN void BZ_API(BZ2_bzWrite) (
|
||||||
|
int* bzerror,
|
||||||
|
BZFILE* b,
|
||||||
|
void* buf,
|
||||||
|
int len
|
||||||
|
);
|
||||||
|
|
||||||
|
BZ_EXTERN void BZ_API(BZ2_bzWriteClose) (
|
||||||
|
int* bzerror,
|
||||||
|
BZFILE* b,
|
||||||
|
int abandon,
|
||||||
|
unsigned int* nbytes_in,
|
||||||
|
unsigned int* nbytes_out
|
||||||
|
);
|
||||||
|
|
||||||
|
BZ_EXTERN void BZ_API(BZ2_bzWriteClose64) (
|
||||||
|
int* bzerror,
|
||||||
|
BZFILE* b,
|
||||||
|
int abandon,
|
||||||
|
unsigned int* nbytes_in_lo32,
|
||||||
|
unsigned int* nbytes_in_hi32,
|
||||||
|
unsigned int* nbytes_out_lo32,
|
||||||
|
unsigned int* nbytes_out_hi32
|
||||||
|
);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/*-- Utility functions --*/
|
||||||
|
|
||||||
|
BZ_EXTERN int BZ_API(BZ2_bzBuffToBuffCompress) (
|
||||||
|
char* dest,
|
||||||
|
unsigned int* destLen,
|
||||||
|
char* source,
|
||||||
|
unsigned int sourceLen,
|
||||||
|
int blockSize100k,
|
||||||
|
int verbosity,
|
||||||
|
int workFactor
|
||||||
|
);
|
||||||
|
|
||||||
|
BZ_EXTERN int BZ_API(BZ2_bzBuffToBuffDecompress) (
|
||||||
|
char* dest,
|
||||||
|
unsigned int* destLen,
|
||||||
|
char* source,
|
||||||
|
unsigned int sourceLen,
|
||||||
|
int small,
|
||||||
|
int verbosity
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
/*--
|
||||||
|
Code contributed by Yoshioka Tsuneo
|
||||||
|
(QWF00133@niftyserve.or.jp/tsuneo-y@is.aist-nara.ac.jp),
|
||||||
|
to support better zlib compatibility.
|
||||||
|
This code is not _officially_ part of libbzip2 (yet);
|
||||||
|
I haven't tested it, documented it, or considered the
|
||||||
|
threading-safeness of it.
|
||||||
|
If this code breaks, please contact both Yoshioka and me.
|
||||||
|
--*/
|
||||||
|
|
||||||
|
BZ_EXTERN const char * BZ_API(BZ2_bzlibVersion) (
|
||||||
|
void
|
||||||
|
);
|
||||||
|
|
||||||
|
#ifndef BZ_NO_STDIO
|
||||||
|
BZ_EXTERN BZFILE * BZ_API(BZ2_bzopen) (
|
||||||
|
const char *path,
|
||||||
|
const char *mode
|
||||||
|
);
|
||||||
|
|
||||||
|
BZ_EXTERN BZFILE * BZ_API(BZ2_bzdopen) (
|
||||||
|
int fd,
|
||||||
|
const char *mode
|
||||||
|
);
|
||||||
|
|
||||||
|
BZ_EXTERN int BZ_API(BZ2_bzread) (
|
||||||
|
BZFILE* b,
|
||||||
|
void* buf,
|
||||||
|
int len
|
||||||
|
);
|
||||||
|
|
||||||
|
BZ_EXTERN int BZ_API(BZ2_bzwrite) (
|
||||||
|
BZFILE* b,
|
||||||
|
void* buf,
|
||||||
|
int len
|
||||||
|
);
|
||||||
|
|
||||||
|
BZ_EXTERN int BZ_API(BZ2_bzflush) (
|
||||||
|
BZFILE* b
|
||||||
|
);
|
||||||
|
|
||||||
|
BZ_EXTERN void BZ_API(BZ2_bzclose) (
|
||||||
|
BZFILE* b
|
||||||
|
);
|
||||||
|
|
||||||
|
BZ_EXTERN const char * BZ_API(BZ2_bzerror) (
|
||||||
|
BZFILE *b,
|
||||||
|
int *errnum
|
||||||
|
);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*-------------------------------------------------------------*/
|
||||||
|
/*--- end bzlib.h ---*/
|
||||||
|
/*-------------------------------------------------------------*/
|
537
bzip2/bzlib_private.h
Normal file
537
bzip2/bzlib_private.h
Normal file
|
@ -0,0 +1,537 @@
|
||||||
|
|
||||||
|
/*-------------------------------------------------------------*/
|
||||||
|
/*--- Private header file for the library. ---*/
|
||||||
|
/*--- bzlib_private.h ---*/
|
||||||
|
/*-------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/*--
|
||||||
|
This file is a part of bzip2 and/or libbzip2, a program and
|
||||||
|
library for lossless, block-sorting data compression.
|
||||||
|
|
||||||
|
Copyright (C) 1996-2002 Julian R Seward. All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions
|
||||||
|
are met:
|
||||||
|
|
||||||
|
1. Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
2. The origin of this software must not be misrepresented; you must
|
||||||
|
not claim that you wrote the original software. If you use this
|
||||||
|
software in a product, an acknowledgment in the product
|
||||||
|
documentation would be appreciated but is not required.
|
||||||
|
|
||||||
|
3. Altered source versions must be plainly marked as such, and must
|
||||||
|
not be misrepresented as being the original software.
|
||||||
|
|
||||||
|
4. The name of the author may not be used to endorse or promote
|
||||||
|
products derived from this software without specific prior written
|
||||||
|
permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
|
||||||
|
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||||
|
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||||
|
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||||
|
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
|
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
Julian Seward, Cambridge, UK.
|
||||||
|
jseward@acm.org
|
||||||
|
bzip2/libbzip2 version 1.0 of 21 March 2000
|
||||||
|
|
||||||
|
This program is based on (at least) the work of:
|
||||||
|
Mike Burrows
|
||||||
|
David Wheeler
|
||||||
|
Peter Fenwick
|
||||||
|
Alistair Moffat
|
||||||
|
Radford Neal
|
||||||
|
Ian H. Witten
|
||||||
|
Robert Sedgewick
|
||||||
|
Jon L. Bentley
|
||||||
|
|
||||||
|
For more information on these sources, see the manual.
|
||||||
|
--*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef _BZLIB_PRIVATE_H
|
||||||
|
#define _BZLIB_PRIVATE_H
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#ifndef BZ_NO_STDIO
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <string.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "bzlib.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*-- General stuff. --*/
|
||||||
|
|
||||||
|
#define BZ_VERSION "1.0.2, 30-Dec-2001"
|
||||||
|
|
||||||
|
typedef char Char;
|
||||||
|
typedef unsigned char Bool;
|
||||||
|
typedef unsigned char UChar;
|
||||||
|
typedef int Int32;
|
||||||
|
typedef unsigned int UInt32;
|
||||||
|
typedef short Int16;
|
||||||
|
typedef unsigned short UInt16;
|
||||||
|
|
||||||
|
#define True ((Bool)1)
|
||||||
|
#define False ((Bool)0)
|
||||||
|
|
||||||
|
#ifndef __GNUC__
|
||||||
|
#define __inline__ /* */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef BZ_NO_STDIO
|
||||||
|
extern void BZ2_bz__AssertH__fail ( int errcode );
|
||||||
|
#define AssertH(cond,errcode) \
|
||||||
|
{ if (!(cond)) BZ2_bz__AssertH__fail ( errcode ); }
|
||||||
|
#if BZ_DEBUG
|
||||||
|
#define AssertD(cond,msg) \
|
||||||
|
{ if (!(cond)) { \
|
||||||
|
fprintf ( stderr, \
|
||||||
|
"\n\nlibbzip2(debug build): internal error\n\t%s\n", msg );\
|
||||||
|
exit(1); \
|
||||||
|
}}
|
||||||
|
#else
|
||||||
|
#define AssertD(cond,msg) /* */
|
||||||
|
#endif
|
||||||
|
#define VPrintf0(zf) \
|
||||||
|
fprintf(stderr,zf)
|
||||||
|
#define VPrintf1(zf,za1) \
|
||||||
|
fprintf(stderr,zf,za1)
|
||||||
|
#define VPrintf2(zf,za1,za2) \
|
||||||
|
fprintf(stderr,zf,za1,za2)
|
||||||
|
#define VPrintf3(zf,za1,za2,za3) \
|
||||||
|
fprintf(stderr,zf,za1,za2,za3)
|
||||||
|
#define VPrintf4(zf,za1,za2,za3,za4) \
|
||||||
|
fprintf(stderr,zf,za1,za2,za3,za4)
|
||||||
|
#define VPrintf5(zf,za1,za2,za3,za4,za5) \
|
||||||
|
fprintf(stderr,zf,za1,za2,za3,za4,za5)
|
||||||
|
#else
|
||||||
|
extern void bz_internal_error ( int errcode );
|
||||||
|
#define AssertH(cond,errcode) \
|
||||||
|
{ if (!(cond)) bz_internal_error ( errcode ); }
|
||||||
|
#define AssertD(cond,msg) /* */
|
||||||
|
#define VPrintf0(zf) /* */
|
||||||
|
#define VPrintf1(zf,za1) /* */
|
||||||
|
#define VPrintf2(zf,za1,za2) /* */
|
||||||
|
#define VPrintf3(zf,za1,za2,za3) /* */
|
||||||
|
#define VPrintf4(zf,za1,za2,za3,za4) /* */
|
||||||
|
#define VPrintf5(zf,za1,za2,za3,za4,za5) /* */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#define BZALLOC(nnn) (strm->bzalloc)(strm->opaque,(nnn),1)
|
||||||
|
#define BZFREE(ppp) (strm->bzfree)(strm->opaque,(ppp))
|
||||||
|
|
||||||
|
|
||||||
|
/*-- Header bytes. --*/
|
||||||
|
|
||||||
|
#define BZ_HDR_B 0x42 /* 'B' */
|
||||||
|
#define BZ_HDR_Z 0x5a /* 'Z' */
|
||||||
|
#define BZ_HDR_h 0x68 /* 'h' */
|
||||||
|
#define BZ_HDR_0 0x30 /* '0' */
|
||||||
|
|
||||||
|
/*-- Constants for the back end. --*/
|
||||||
|
|
||||||
|
#define BZ_MAX_ALPHA_SIZE 258
|
||||||
|
#define BZ_MAX_CODE_LEN 23
|
||||||
|
|
||||||
|
#define BZ_RUNA 0
|
||||||
|
#define BZ_RUNB 1
|
||||||
|
|
||||||
|
#define BZ_N_GROUPS 6
|
||||||
|
#define BZ_G_SIZE 50
|
||||||
|
#define BZ_N_ITERS 4
|
||||||
|
|
||||||
|
#define BZ_MAX_SELECTORS (2 + (900000 / BZ_G_SIZE))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*-- Stuff for randomising repetitive blocks. --*/
|
||||||
|
|
||||||
|
extern Int32 BZ2_rNums[512];
|
||||||
|
|
||||||
|
#define BZ_RAND_DECLS \
|
||||||
|
Int32 rNToGo; \
|
||||||
|
Int32 rTPos \
|
||||||
|
|
||||||
|
#define BZ_RAND_INIT_MASK \
|
||||||
|
s->rNToGo = 0; \
|
||||||
|
s->rTPos = 0 \
|
||||||
|
|
||||||
|
#define BZ_RAND_MASK ((s->rNToGo == 1) ? 1 : 0)
|
||||||
|
|
||||||
|
#define BZ_RAND_UPD_MASK \
|
||||||
|
if (s->rNToGo == 0) { \
|
||||||
|
s->rNToGo = BZ2_rNums[s->rTPos]; \
|
||||||
|
s->rTPos++; \
|
||||||
|
if (s->rTPos == 512) s->rTPos = 0; \
|
||||||
|
} \
|
||||||
|
s->rNToGo--;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*-- Stuff for doing CRCs. --*/
|
||||||
|
|
||||||
|
extern UInt32 BZ2_crc32Table[256];
|
||||||
|
|
||||||
|
#define BZ_INITIALISE_CRC(crcVar) \
|
||||||
|
{ \
|
||||||
|
crcVar = 0xffffffffL; \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define BZ_FINALISE_CRC(crcVar) \
|
||||||
|
{ \
|
||||||
|
crcVar = ~(crcVar); \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define BZ_UPDATE_CRC(crcVar,cha) \
|
||||||
|
{ \
|
||||||
|
crcVar = (crcVar << 8) ^ \
|
||||||
|
BZ2_crc32Table[(crcVar >> 24) ^ \
|
||||||
|
((UChar)cha)]; \
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*-- States and modes for compression. --*/
|
||||||
|
|
||||||
|
#define BZ_M_IDLE 1
|
||||||
|
#define BZ_M_RUNNING 2
|
||||||
|
#define BZ_M_FLUSHING 3
|
||||||
|
#define BZ_M_FINISHING 4
|
||||||
|
|
||||||
|
#define BZ_S_OUTPUT 1
|
||||||
|
#define BZ_S_INPUT 2
|
||||||
|
|
||||||
|
#define BZ_N_RADIX 2
|
||||||
|
#define BZ_N_QSORT 12
|
||||||
|
#define BZ_N_SHELL 18
|
||||||
|
#define BZ_N_OVERSHOOT (BZ_N_RADIX + BZ_N_QSORT + BZ_N_SHELL + 2)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*-- Structure holding all the compression-side stuff. --*/
|
||||||
|
|
||||||
|
typedef
|
||||||
|
struct {
|
||||||
|
/* pointer back to the struct bz_stream */
|
||||||
|
bz_stream* strm;
|
||||||
|
|
||||||
|
/* mode this stream is in, and whether inputting */
|
||||||
|
/* or outputting data */
|
||||||
|
Int32 mode;
|
||||||
|
Int32 state;
|
||||||
|
|
||||||
|
/* remembers avail_in when flush/finish requested */
|
||||||
|
UInt32 avail_in_expect;
|
||||||
|
|
||||||
|
/* for doing the block sorting */
|
||||||
|
UInt32* arr1;
|
||||||
|
UInt32* arr2;
|
||||||
|
UInt32* ftab;
|
||||||
|
Int32 origPtr;
|
||||||
|
|
||||||
|
/* aliases for arr1 and arr2 */
|
||||||
|
UInt32* ptr;
|
||||||
|
UChar* block;
|
||||||
|
UInt16* mtfv;
|
||||||
|
UChar* zbits;
|
||||||
|
|
||||||
|
/* for deciding when to use the fallback sorting algorithm */
|
||||||
|
Int32 workFactor;
|
||||||
|
|
||||||
|
/* run-length-encoding of the input */
|
||||||
|
UInt32 state_in_ch;
|
||||||
|
Int32 state_in_len;
|
||||||
|
BZ_RAND_DECLS;
|
||||||
|
|
||||||
|
/* input and output limits and current posns */
|
||||||
|
Int32 nblock;
|
||||||
|
Int32 nblockMAX;
|
||||||
|
Int32 numZ;
|
||||||
|
Int32 state_out_pos;
|
||||||
|
|
||||||
|
/* map of bytes used in block */
|
||||||
|
Int32 nInUse;
|
||||||
|
Bool inUse[256];
|
||||||
|
UChar unseqToSeq[256];
|
||||||
|
|
||||||
|
/* the buffer for bit stream creation */
|
||||||
|
UInt32 bsBuff;
|
||||||
|
Int32 bsLive;
|
||||||
|
|
||||||
|
/* block and combined CRCs */
|
||||||
|
UInt32 blockCRC;
|
||||||
|
UInt32 combinedCRC;
|
||||||
|
|
||||||
|
/* misc administratium */
|
||||||
|
Int32 verbosity;
|
||||||
|
Int32 blockNo;
|
||||||
|
Int32 blockSize100k;
|
||||||
|
|
||||||
|
/* stuff for coding the MTF values */
|
||||||
|
Int32 nMTF;
|
||||||
|
Int32 mtfFreq [BZ_MAX_ALPHA_SIZE];
|
||||||
|
UChar selector [BZ_MAX_SELECTORS];
|
||||||
|
UChar selectorMtf[BZ_MAX_SELECTORS];
|
||||||
|
|
||||||
|
UChar len [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
|
||||||
|
Int32 code [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
|
||||||
|
Int32 rfreq [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
|
||||||
|
/* second dimension: only 3 needed; 4 makes index calculations faster */
|
||||||
|
UInt32 len_pack[BZ_MAX_ALPHA_SIZE][4];
|
||||||
|
|
||||||
|
}
|
||||||
|
EState;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*-- externs for compression. --*/
|
||||||
|
|
||||||
|
extern void
|
||||||
|
BZ2_blockSort ( EState* );
|
||||||
|
|
||||||
|
extern void
|
||||||
|
BZ2_compressBlock ( EState*, Bool );
|
||||||
|
|
||||||
|
extern void
|
||||||
|
BZ2_bsInitWrite ( EState* );
|
||||||
|
|
||||||
|
extern void
|
||||||
|
BZ2_hbAssignCodes ( Int32*, UChar*, Int32, Int32, Int32 );
|
||||||
|
|
||||||
|
extern void
|
||||||
|
BZ2_hbMakeCodeLengths ( UChar*, Int32*, Int32, Int32 );
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*-- states for decompression. --*/
|
||||||
|
|
||||||
|
#define BZ_X_IDLE 1
|
||||||
|
#define BZ_X_OUTPUT 2
|
||||||
|
|
||||||
|
#define BZ_X_MAGIC_1 10
|
||||||
|
#define BZ_X_MAGIC_2 11
|
||||||
|
#define BZ_X_MAGIC_3 12
|
||||||
|
#define BZ_X_MAGIC_4 13
|
||||||
|
#define BZ_X_BLKHDR_1 14
|
||||||
|
#define BZ_X_BLKHDR_2 15
|
||||||
|
#define BZ_X_BLKHDR_3 16
|
||||||
|
#define BZ_X_BLKHDR_4 17
|
||||||
|
#define BZ_X_BLKHDR_5 18
|
||||||
|
#define BZ_X_BLKHDR_6 19
|
||||||
|
#define BZ_X_BCRC_1 20
|
||||||
|
#define BZ_X_BCRC_2 21
|
||||||
|
#define BZ_X_BCRC_3 22
|
||||||
|
#define BZ_X_BCRC_4 23
|
||||||
|
#define BZ_X_RANDBIT 24
|
||||||
|
#define BZ_X_ORIGPTR_1 25
|
||||||
|
#define BZ_X_ORIGPTR_2 26
|
||||||
|
#define BZ_X_ORIGPTR_3 27
|
||||||
|
#define BZ_X_MAPPING_1 28
|
||||||
|
#define BZ_X_MAPPING_2 29
|
||||||
|
#define BZ_X_SELECTOR_1 30
|
||||||
|
#define BZ_X_SELECTOR_2 31
|
||||||
|
#define BZ_X_SELECTOR_3 32
|
||||||
|
#define BZ_X_CODING_1 33
|
||||||
|
#define BZ_X_CODING_2 34
|
||||||
|
#define BZ_X_CODING_3 35
|
||||||
|
#define BZ_X_MTF_1 36
|
||||||
|
#define BZ_X_MTF_2 37
|
||||||
|
#define BZ_X_MTF_3 38
|
||||||
|
#define BZ_X_MTF_4 39
|
||||||
|
#define BZ_X_MTF_5 40
|
||||||
|
#define BZ_X_MTF_6 41
|
||||||
|
#define BZ_X_ENDHDR_2 42
|
||||||
|
#define BZ_X_ENDHDR_3 43
|
||||||
|
#define BZ_X_ENDHDR_4 44
|
||||||
|
#define BZ_X_ENDHDR_5 45
|
||||||
|
#define BZ_X_ENDHDR_6 46
|
||||||
|
#define BZ_X_CCRC_1 47
|
||||||
|
#define BZ_X_CCRC_2 48
|
||||||
|
#define BZ_X_CCRC_3 49
|
||||||
|
#define BZ_X_CCRC_4 50
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*-- Constants for the fast MTF decoder. --*/
|
||||||
|
|
||||||
|
#define MTFA_SIZE 4096
|
||||||
|
#define MTFL_SIZE 16
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*-- Structure holding all the decompression-side stuff. --*/
|
||||||
|
|
||||||
|
typedef
|
||||||
|
struct {
|
||||||
|
/* pointer back to the struct bz_stream */
|
||||||
|
bz_stream* strm;
|
||||||
|
|
||||||
|
/* state indicator for this stream */
|
||||||
|
Int32 state;
|
||||||
|
|
||||||
|
/* for doing the final run-length decoding */
|
||||||
|
UChar state_out_ch;
|
||||||
|
Int32 state_out_len;
|
||||||
|
Bool blockRandomised;
|
||||||
|
BZ_RAND_DECLS;
|
||||||
|
|
||||||
|
/* the buffer for bit stream reading */
|
||||||
|
UInt32 bsBuff;
|
||||||
|
Int32 bsLive;
|
||||||
|
|
||||||
|
/* misc administratium */
|
||||||
|
Int32 blockSize100k;
|
||||||
|
Bool smallDecompress;
|
||||||
|
Int32 currBlockNo;
|
||||||
|
Int32 verbosity;
|
||||||
|
|
||||||
|
/* for undoing the Burrows-Wheeler transform */
|
||||||
|
Int32 origPtr;
|
||||||
|
UInt32 tPos;
|
||||||
|
Int32 k0;
|
||||||
|
Int32 unzftab[256];
|
||||||
|
Int32 nblock_used;
|
||||||
|
Int32 cftab[257];
|
||||||
|
Int32 cftabCopy[257];
|
||||||
|
|
||||||
|
/* for undoing the Burrows-Wheeler transform (FAST) */
|
||||||
|
UInt32 *tt;
|
||||||
|
|
||||||
|
/* for undoing the Burrows-Wheeler transform (SMALL) */
|
||||||
|
UInt16 *ll16;
|
||||||
|
UChar *ll4;
|
||||||
|
|
||||||
|
/* stored and calculated CRCs */
|
||||||
|
UInt32 storedBlockCRC;
|
||||||
|
UInt32 storedCombinedCRC;
|
||||||
|
UInt32 calculatedBlockCRC;
|
||||||
|
UInt32 calculatedCombinedCRC;
|
||||||
|
|
||||||
|
/* map of bytes used in block */
|
||||||
|
Int32 nInUse;
|
||||||
|
Bool inUse[256];
|
||||||
|
Bool inUse16[16];
|
||||||
|
UChar seqToUnseq[256];
|
||||||
|
|
||||||
|
/* for decoding the MTF values */
|
||||||
|
UChar mtfa [MTFA_SIZE];
|
||||||
|
Int32 mtfbase[256 / MTFL_SIZE];
|
||||||
|
UChar selector [BZ_MAX_SELECTORS];
|
||||||
|
UChar selectorMtf[BZ_MAX_SELECTORS];
|
||||||
|
UChar len [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
|
||||||
|
|
||||||
|
Int32 limit [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
|
||||||
|
Int32 base [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
|
||||||
|
Int32 perm [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
|
||||||
|
Int32 minLens[BZ_N_GROUPS];
|
||||||
|
|
||||||
|
/* save area for scalars in the main decompress code */
|
||||||
|
Int32 save_i;
|
||||||
|
Int32 save_j;
|
||||||
|
Int32 save_t;
|
||||||
|
Int32 save_alphaSize;
|
||||||
|
Int32 save_nGroups;
|
||||||
|
Int32 save_nSelectors;
|
||||||
|
Int32 save_EOB;
|
||||||
|
Int32 save_groupNo;
|
||||||
|
Int32 save_groupPos;
|
||||||
|
Int32 save_nextSym;
|
||||||
|
Int32 save_nblockMAX;
|
||||||
|
Int32 save_nblock;
|
||||||
|
Int32 save_es;
|
||||||
|
Int32 save_N;
|
||||||
|
Int32 save_curr;
|
||||||
|
Int32 save_zt;
|
||||||
|
Int32 save_zn;
|
||||||
|
Int32 save_zvec;
|
||||||
|
Int32 save_zj;
|
||||||
|
Int32 save_gSel;
|
||||||
|
Int32 save_gMinlen;
|
||||||
|
Int32* save_gLimit;
|
||||||
|
Int32* save_gBase;
|
||||||
|
Int32* save_gPerm;
|
||||||
|
|
||||||
|
}
|
||||||
|
DState;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*-- Macros for decompression. --*/
|
||||||
|
|
||||||
|
#define BZ_GET_FAST(cccc) \
|
||||||
|
s->tPos = s->tt[s->tPos]; \
|
||||||
|
cccc = (UChar)(s->tPos & 0xff); \
|
||||||
|
s->tPos >>= 8;
|
||||||
|
|
||||||
|
#define BZ_GET_FAST_C(cccc) \
|
||||||
|
c_tPos = c_tt[c_tPos]; \
|
||||||
|
cccc = (UChar)(c_tPos & 0xff); \
|
||||||
|
c_tPos >>= 8;
|
||||||
|
|
||||||
|
#define SET_LL4(i,n) \
|
||||||
|
{ if (((i) & 0x1) == 0) \
|
||||||
|
s->ll4[(i) >> 1] = (s->ll4[(i) >> 1] & 0xf0) | (n); else \
|
||||||
|
s->ll4[(i) >> 1] = (s->ll4[(i) >> 1] & 0x0f) | ((n) << 4); \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define GET_LL4(i) \
|
||||||
|
((((UInt32)(s->ll4[(i) >> 1])) >> (((i) << 2) & 0x4)) & 0xF)
|
||||||
|
|
||||||
|
#define SET_LL(i,n) \
|
||||||
|
{ s->ll16[i] = (UInt16)(n & 0x0000ffff); \
|
||||||
|
SET_LL4(i, n >> 16); \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define GET_LL(i) \
|
||||||
|
(((UInt32)s->ll16[i]) | (GET_LL4(i) << 16))
|
||||||
|
|
||||||
|
#define BZ_GET_SMALL(cccc) \
|
||||||
|
cccc = BZ2_indexIntoF ( s->tPos, s->cftab ); \
|
||||||
|
s->tPos = GET_LL(s->tPos);
|
||||||
|
|
||||||
|
|
||||||
|
/*-- externs for decompression. --*/
|
||||||
|
|
||||||
|
extern Int32
|
||||||
|
BZ2_indexIntoF ( Int32, Int32* );
|
||||||
|
|
||||||
|
extern Int32
|
||||||
|
BZ2_decompress ( DState* );
|
||||||
|
|
||||||
|
extern void
|
||||||
|
BZ2_hbCreateDecodeTables ( Int32*, Int32*, Int32*, UChar*,
|
||||||
|
Int32, Int32, Int32 );
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/*-- BZ_NO_STDIO seems to make NULL disappear on some platforms. --*/
|
||||||
|
|
||||||
|
#ifdef BZ_NO_STDIO
|
||||||
|
#ifndef NULL
|
||||||
|
#define NULL 0
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/*-------------------------------------------------------------*/
|
||||||
|
/*--- end bzlib_private.h ---*/
|
||||||
|
/*-------------------------------------------------------------*/
|
714
bzip2/compress.c
Normal file
714
bzip2/compress.c
Normal file
|
@ -0,0 +1,714 @@
|
||||||
|
|
||||||
|
/*-------------------------------------------------------------*/
|
||||||
|
/*--- Compression machinery (not incl block sorting) ---*/
|
||||||
|
/*--- compress.c ---*/
|
||||||
|
/*-------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/*--
|
||||||
|
This file is a part of bzip2 and/or libbzip2, a program and
|
||||||
|
library for lossless, block-sorting data compression.
|
||||||
|
|
||||||
|
Copyright (C) 1996-2002 Julian R Seward. All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions
|
||||||
|
are met:
|
||||||
|
|
||||||
|
1. Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
2. The origin of this software must not be misrepresented; you must
|
||||||
|
not claim that you wrote the original software. If you use this
|
||||||
|
software in a product, an acknowledgment in the product
|
||||||
|
documentation would be appreciated but is not required.
|
||||||
|
|
||||||
|
3. Altered source versions must be plainly marked as such, and must
|
||||||
|
not be misrepresented as being the original software.
|
||||||
|
|
||||||
|
4. The name of the author may not be used to endorse or promote
|
||||||
|
products derived from this software without specific prior written
|
||||||
|
permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
|
||||||
|
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||||
|
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||||
|
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||||
|
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
|
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
Julian Seward, Cambridge, UK.
|
||||||
|
jseward@acm.org
|
||||||
|
bzip2/libbzip2 version 1.0 of 21 March 2000
|
||||||
|
|
||||||
|
This program is based on (at least) the work of:
|
||||||
|
Mike Burrows
|
||||||
|
David Wheeler
|
||||||
|
Peter Fenwick
|
||||||
|
Alistair Moffat
|
||||||
|
Radford Neal
|
||||||
|
Ian H. Witten
|
||||||
|
Robert Sedgewick
|
||||||
|
Jon L. Bentley
|
||||||
|
|
||||||
|
For more information on these sources, see the manual.
|
||||||
|
--*/
|
||||||
|
|
||||||
|
/*--
|
||||||
|
CHANGES
|
||||||
|
~~~~~~~
|
||||||
|
0.9.0 -- original version.
|
||||||
|
|
||||||
|
0.9.0a/b -- no changes in this file.
|
||||||
|
|
||||||
|
0.9.0c
|
||||||
|
* changed setting of nGroups in sendMTFValues() so as to
|
||||||
|
do a bit better on small files
|
||||||
|
--*/
|
||||||
|
|
||||||
|
#include "bzlib_private.h"
|
||||||
|
|
||||||
|
|
||||||
|
/*---------------------------------------------------*/
|
||||||
|
/*--- Bit stream I/O ---*/
|
||||||
|
/*---------------------------------------------------*/
|
||||||
|
|
||||||
|
/*---------------------------------------------------*/
|
||||||
|
void BZ2_bsInitWrite ( EState* s )
|
||||||
|
{
|
||||||
|
s->bsLive = 0;
|
||||||
|
s->bsBuff = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*---------------------------------------------------*/
|
||||||
|
static
|
||||||
|
void bsFinishWrite ( EState* s )
|
||||||
|
{
|
||||||
|
while (s->bsLive > 0) {
|
||||||
|
s->zbits[s->numZ] = (UChar)(s->bsBuff >> 24);
|
||||||
|
s->numZ++;
|
||||||
|
s->bsBuff <<= 8;
|
||||||
|
s->bsLive -= 8;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*---------------------------------------------------*/
|
||||||
|
#define bsNEEDW(nz) \
|
||||||
|
{ \
|
||||||
|
while (s->bsLive >= 8) { \
|
||||||
|
s->zbits[s->numZ] \
|
||||||
|
= (UChar)(s->bsBuff >> 24); \
|
||||||
|
s->numZ++; \
|
||||||
|
s->bsBuff <<= 8; \
|
||||||
|
s->bsLive -= 8; \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*---------------------------------------------------*/
|
||||||
|
static
|
||||||
|
__inline__
|
||||||
|
void bsW ( EState* s, Int32 n, UInt32 v )
|
||||||
|
{
|
||||||
|
bsNEEDW ( n );
|
||||||
|
s->bsBuff |= (v << (32 - s->bsLive - n));
|
||||||
|
s->bsLive += n;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*---------------------------------------------------*/
|
||||||
|
static
|
||||||
|
void bsPutUInt32 ( EState* s, UInt32 u )
|
||||||
|
{
|
||||||
|
bsW ( s, 8, (u >> 24) & 0xffL );
|
||||||
|
bsW ( s, 8, (u >> 16) & 0xffL );
|
||||||
|
bsW ( s, 8, (u >> 8) & 0xffL );
|
||||||
|
bsW ( s, 8, u & 0xffL );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*---------------------------------------------------*/
|
||||||
|
static
|
||||||
|
void bsPutUChar ( EState* s, UChar c )
|
||||||
|
{
|
||||||
|
bsW( s, 8, (UInt32)c );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*---------------------------------------------------*/
|
||||||
|
/*--- The back end proper ---*/
|
||||||
|
/*---------------------------------------------------*/
|
||||||
|
|
||||||
|
/*---------------------------------------------------*/
|
||||||
|
static
|
||||||
|
void makeMaps_e ( EState* s )
|
||||||
|
{
|
||||||
|
Int32 i;
|
||||||
|
s->nInUse = 0;
|
||||||
|
for (i = 0; i < 256; i++)
|
||||||
|
if (s->inUse[i]) {
|
||||||
|
s->unseqToSeq[i] = s->nInUse;
|
||||||
|
s->nInUse++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*---------------------------------------------------*/
|
||||||
|
static
|
||||||
|
void generateMTFValues ( EState* s )
|
||||||
|
{
|
||||||
|
UChar yy[256];
|
||||||
|
Int32 i, j;
|
||||||
|
Int32 zPend;
|
||||||
|
Int32 wr;
|
||||||
|
Int32 EOB;
|
||||||
|
|
||||||
|
/*
|
||||||
|
After sorting (eg, here),
|
||||||
|
s->arr1 [ 0 .. s->nblock-1 ] holds sorted order,
|
||||||
|
and
|
||||||
|
((UChar*)s->arr2) [ 0 .. s->nblock-1 ]
|
||||||
|
holds the original block data.
|
||||||
|
|
||||||
|
The first thing to do is generate the MTF values,
|
||||||
|
and put them in
|
||||||
|
((UInt16*)s->arr1) [ 0 .. s->nblock-1 ].
|
||||||
|
Because there are strictly fewer or equal MTF values
|
||||||
|
than block values, ptr values in this area are overwritten
|
||||||
|
with MTF values only when they are no longer needed.
|
||||||
|
|
||||||
|
The final compressed bitstream is generated into the
|
||||||
|
area starting at
|
||||||
|
(UChar*) (&((UChar*)s->arr2)[s->nblock])
|
||||||
|
|
||||||
|
These storage aliases are set up in bzCompressInit(),
|
||||||
|
except for the last one, which is arranged in
|
||||||
|
compressBlock().
|
||||||
|
*/
|
||||||
|
UInt32* ptr = s->ptr;
|
||||||
|
UChar* block = s->block;
|
||||||
|
UInt16* mtfv = s->mtfv;
|
||||||
|
|
||||||
|
makeMaps_e ( s );
|
||||||
|
EOB = s->nInUse+1;
|
||||||
|
|
||||||
|
for (i = 0; i <= EOB; i++) s->mtfFreq[i] = 0;
|
||||||
|
|
||||||
|
wr = 0;
|
||||||
|
zPend = 0;
|
||||||
|
for (i = 0; i < s->nInUse; i++) yy[i] = (UChar) i;
|
||||||
|
|
||||||
|
for (i = 0; i < s->nblock; i++) {
|
||||||
|
UChar ll_i;
|
||||||
|
AssertD ( wr <= i, "generateMTFValues(1)" );
|
||||||
|
j = ptr[i]-1; if (j < 0) j += s->nblock;
|
||||||
|
ll_i = s->unseqToSeq[block[j]];
|
||||||
|
AssertD ( ll_i < s->nInUse, "generateMTFValues(2a)" );
|
||||||
|
|
||||||
|
if (yy[0] == ll_i) {
|
||||||
|
zPend++;
|
||||||
|
} else {
|
||||||
|
|
||||||
|
if (zPend > 0) {
|
||||||
|
zPend--;
|
||||||
|
while (True) {
|
||||||
|
if (zPend & 1) {
|
||||||
|
mtfv[wr] = BZ_RUNB; wr++;
|
||||||
|
s->mtfFreq[BZ_RUNB]++;
|
||||||
|
} else {
|
||||||
|
mtfv[wr] = BZ_RUNA; wr++;
|
||||||
|
s->mtfFreq[BZ_RUNA]++;
|
||||||
|
}
|
||||||
|
if (zPend < 2) break;
|
||||||
|
zPend = (zPend - 2) / 2;
|
||||||
|
};
|
||||||
|
zPend = 0;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
register UChar rtmp;
|
||||||
|
register UChar* ryy_j;
|
||||||
|
register UChar rll_i;
|
||||||
|
rtmp = yy[1];
|
||||||
|
yy[1] = yy[0];
|
||||||
|
ryy_j = &(yy[1]);
|
||||||
|
rll_i = ll_i;
|
||||||
|
while ( rll_i != rtmp ) {
|
||||||
|
register UChar rtmp2;
|
||||||
|
ryy_j++;
|
||||||
|
rtmp2 = rtmp;
|
||||||
|
rtmp = *ryy_j;
|
||||||
|
*ryy_j = rtmp2;
|
||||||
|
};
|
||||||
|
yy[0] = rtmp;
|
||||||
|
j = ryy_j - &(yy[0]);
|
||||||
|
mtfv[wr] = j+1; wr++; s->mtfFreq[j+1]++;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (zPend > 0) {
|
||||||
|
zPend--;
|
||||||
|
while (True) {
|
||||||
|
if (zPend & 1) {
|
||||||
|
mtfv[wr] = BZ_RUNB; wr++;
|
||||||
|
s->mtfFreq[BZ_RUNB]++;
|
||||||
|
} else {
|
||||||
|
mtfv[wr] = BZ_RUNA; wr++;
|
||||||
|
s->mtfFreq[BZ_RUNA]++;
|
||||||
|
}
|
||||||
|
if (zPend < 2) break;
|
||||||
|
zPend = (zPend - 2) / 2;
|
||||||
|
};
|
||||||
|
zPend = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
mtfv[wr] = EOB; wr++; s->mtfFreq[EOB]++;
|
||||||
|
|
||||||
|
s->nMTF = wr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*---------------------------------------------------*/
|
||||||
|
#define BZ_LESSER_ICOST 0
|
||||||
|
#define BZ_GREATER_ICOST 15
|
||||||
|
|
||||||
|
static
|
||||||
|
void sendMTFValues ( EState* s )
|
||||||
|
{
|
||||||
|
Int32 v, t, i, j, gs, ge, totc, bt, bc, iter;
|
||||||
|
Int32 nSelectors, alphaSize, minLen, maxLen, selCtr;
|
||||||
|
Int32 nGroups, nBytes;
|
||||||
|
|
||||||
|
/*--
|
||||||
|
UChar len [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
|
||||||
|
is a global since the decoder also needs it.
|
||||||
|
|
||||||
|
Int32 code[BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
|
||||||
|
Int32 rfreq[BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
|
||||||
|
are also globals only used in this proc.
|
||||||
|
Made global to keep stack frame size small.
|
||||||
|
--*/
|
||||||
|
|
||||||
|
|
||||||
|
UInt16 cost[BZ_N_GROUPS];
|
||||||
|
Int32 fave[BZ_N_GROUPS];
|
||||||
|
|
||||||
|
UInt16* mtfv = s->mtfv;
|
||||||
|
|
||||||
|
if (s->verbosity >= 3)
|
||||||
|
VPrintf3( " %d in block, %d after MTF & 1-2 coding, "
|
||||||
|
"%d+2 syms in use\n",
|
||||||
|
s->nblock, s->nMTF, s->nInUse );
|
||||||
|
|
||||||
|
alphaSize = s->nInUse+2;
|
||||||
|
for (t = 0; t < BZ_N_GROUPS; t++)
|
||||||
|
for (v = 0; v < alphaSize; v++)
|
||||||
|
s->len[t][v] = BZ_GREATER_ICOST;
|
||||||
|
|
||||||
|
/*--- Decide how many coding tables to use ---*/
|
||||||
|
AssertH ( s->nMTF > 0, 3001 );
|
||||||
|
if (s->nMTF < 200) nGroups = 2; else
|
||||||
|
if (s->nMTF < 600) nGroups = 3; else
|
||||||
|
if (s->nMTF < 1200) nGroups = 4; else
|
||||||
|
if (s->nMTF < 2400) nGroups = 5; else
|
||||||
|
nGroups = 6;
|
||||||
|
|
||||||
|
/*--- Generate an initial set of coding tables ---*/
|
||||||
|
{
|
||||||
|
Int32 nPart, remF, tFreq, aFreq;
|
||||||
|
|
||||||
|
nPart = nGroups;
|
||||||
|
remF = s->nMTF;
|
||||||
|
gs = 0;
|
||||||
|
while (nPart > 0) {
|
||||||
|
tFreq = remF / nPart;
|
||||||
|
ge = gs-1;
|
||||||
|
aFreq = 0;
|
||||||
|
while (aFreq < tFreq && ge < alphaSize-1) {
|
||||||
|
ge++;
|
||||||
|
aFreq += s->mtfFreq[ge];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ge > gs
|
||||||
|
&& nPart != nGroups && nPart != 1
|
||||||
|
&& ((nGroups-nPart) % 2 == 1)) {
|
||||||
|
aFreq -= s->mtfFreq[ge];
|
||||||
|
ge--;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (s->verbosity >= 3)
|
||||||
|
VPrintf5( " initial group %d, [%d .. %d], "
|
||||||
|
"has %d syms (%4.1f%%)\n",
|
||||||
|
nPart, gs, ge, aFreq,
|
||||||
|
(100.0 * (float)aFreq) / (float)(s->nMTF) );
|
||||||
|
|
||||||
|
for (v = 0; v < alphaSize; v++)
|
||||||
|
if (v >= gs && v <= ge)
|
||||||
|
s->len[nPart-1][v] = BZ_LESSER_ICOST; else
|
||||||
|
s->len[nPart-1][v] = BZ_GREATER_ICOST;
|
||||||
|
|
||||||
|
nPart--;
|
||||||
|
gs = ge+1;
|
||||||
|
remF -= aFreq;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*---
|
||||||
|
Iterate up to BZ_N_ITERS times to improve the tables.
|
||||||
|
---*/
|
||||||
|
for (iter = 0; iter < BZ_N_ITERS; iter++) {
|
||||||
|
|
||||||
|
for (t = 0; t < nGroups; t++) fave[t] = 0;
|
||||||
|
|
||||||
|
for (t = 0; t < nGroups; t++)
|
||||||
|
for (v = 0; v < alphaSize; v++)
|
||||||
|
s->rfreq[t][v] = 0;
|
||||||
|
|
||||||
|
/*---
|
||||||
|
Set up an auxiliary length table which is used to fast-track
|
||||||
|
the common case (nGroups == 6).
|
||||||
|
---*/
|
||||||
|
if (nGroups == 6) {
|
||||||
|
for (v = 0; v < alphaSize; v++) {
|
||||||
|
s->len_pack[v][0] = (s->len[1][v] << 16) | s->len[0][v];
|
||||||
|
s->len_pack[v][1] = (s->len[3][v] << 16) | s->len[2][v];
|
||||||
|
s->len_pack[v][2] = (s->len[5][v] << 16) | s->len[4][v];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
nSelectors = 0;
|
||||||
|
totc = 0;
|
||||||
|
gs = 0;
|
||||||
|
while (True) {
|
||||||
|
|
||||||
|
/*--- Set group start & end marks. --*/
|
||||||
|
if (gs >= s->nMTF) break;
|
||||||
|
ge = gs + BZ_G_SIZE - 1;
|
||||||
|
if (ge >= s->nMTF) ge = s->nMTF-1;
|
||||||
|
|
||||||
|
/*--
|
||||||
|
Calculate the cost of this group as coded
|
||||||
|
by each of the coding tables.
|
||||||
|
--*/
|
||||||
|
for (t = 0; t < nGroups; t++) cost[t] = 0;
|
||||||
|
|
||||||
|
if (nGroups == 6 && 50 == ge-gs+1) {
|
||||||
|
/*--- fast track the common case ---*/
|
||||||
|
register UInt32 cost01, cost23, cost45;
|
||||||
|
register UInt16 icv;
|
||||||
|
cost01 = cost23 = cost45 = 0;
|
||||||
|
|
||||||
|
# define BZ_ITER(nn) \
|
||||||
|
icv = mtfv[gs+(nn)]; \
|
||||||
|
cost01 += s->len_pack[icv][0]; \
|
||||||
|
cost23 += s->len_pack[icv][1]; \
|
||||||
|
cost45 += s->len_pack[icv][2]; \
|
||||||
|
|
||||||
|
BZ_ITER(0); BZ_ITER(1); BZ_ITER(2); BZ_ITER(3); BZ_ITER(4);
|
||||||
|
BZ_ITER(5); BZ_ITER(6); BZ_ITER(7); BZ_ITER(8); BZ_ITER(9);
|
||||||
|
BZ_ITER(10); BZ_ITER(11); BZ_ITER(12); BZ_ITER(13); BZ_ITER(14);
|
||||||
|
BZ_ITER(15); BZ_ITER(16); BZ_ITER(17); BZ_ITER(18); BZ_ITER(19);
|
||||||
|
BZ_ITER(20); BZ_ITER(21); BZ_ITER(22); BZ_ITER(23); BZ_ITER(24);
|
||||||
|
BZ_ITER(25); BZ_ITER(26); BZ_ITER(27); BZ_ITER(28); BZ_ITER(29);
|
||||||
|
BZ_ITER(30); BZ_ITER(31); BZ_ITER(32); BZ_ITER(33); BZ_ITER(34);
|
||||||
|
BZ_ITER(35); BZ_ITER(36); BZ_ITER(37); BZ_ITER(38); BZ_ITER(39);
|
||||||
|
BZ_ITER(40); BZ_ITER(41); BZ_ITER(42); BZ_ITER(43); BZ_ITER(44);
|
||||||
|
BZ_ITER(45); BZ_ITER(46); BZ_ITER(47); BZ_ITER(48); BZ_ITER(49);
|
||||||
|
|
||||||
|
# undef BZ_ITER
|
||||||
|
|
||||||
|
cost[0] = cost01 & 0xffff; cost[1] = cost01 >> 16;
|
||||||
|
cost[2] = cost23 & 0xffff; cost[3] = cost23 >> 16;
|
||||||
|
cost[4] = cost45 & 0xffff; cost[5] = cost45 >> 16;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
/*--- slow version which correctly handles all situations ---*/
|
||||||
|
for (i = gs; i <= ge; i++) {
|
||||||
|
UInt16 icv = mtfv[i];
|
||||||
|
for (t = 0; t < nGroups; t++) cost[t] += s->len[t][icv];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--
|
||||||
|
Find the coding table which is best for this group,
|
||||||
|
and record its identity in the selector table.
|
||||||
|
--*/
|
||||||
|
bc = 999999999; bt = -1;
|
||||||
|
for (t = 0; t < nGroups; t++)
|
||||||
|
if (cost[t] < bc) { bc = cost[t]; bt = t; };
|
||||||
|
totc += bc;
|
||||||
|
fave[bt]++;
|
||||||
|
s->selector[nSelectors] = bt;
|
||||||
|
nSelectors++;
|
||||||
|
|
||||||
|
/*--
|
||||||
|
Increment the symbol frequencies for the selected table.
|
||||||
|
--*/
|
||||||
|
if (nGroups == 6 && 50 == ge-gs+1) {
|
||||||
|
/*--- fast track the common case ---*/
|
||||||
|
|
||||||
|
# define BZ_ITUR(nn) s->rfreq[bt][ mtfv[gs+(nn)] ]++
|
||||||
|
|
||||||
|
BZ_ITUR(0); BZ_ITUR(1); BZ_ITUR(2); BZ_ITUR(3); BZ_ITUR(4);
|
||||||
|
BZ_ITUR(5); BZ_ITUR(6); BZ_ITUR(7); BZ_ITUR(8); BZ_ITUR(9);
|
||||||
|
BZ_ITUR(10); BZ_ITUR(11); BZ_ITUR(12); BZ_ITUR(13); BZ_ITUR(14);
|
||||||
|
BZ_ITUR(15); BZ_ITUR(16); BZ_ITUR(17); BZ_ITUR(18); BZ_ITUR(19);
|
||||||
|
BZ_ITUR(20); BZ_ITUR(21); BZ_ITUR(22); BZ_ITUR(23); BZ_ITUR(24);
|
||||||
|
BZ_ITUR(25); BZ_ITUR(26); BZ_ITUR(27); BZ_ITUR(28); BZ_ITUR(29);
|
||||||
|
BZ_ITUR(30); BZ_ITUR(31); BZ_ITUR(32); BZ_ITUR(33); BZ_ITUR(34);
|
||||||
|
BZ_ITUR(35); BZ_ITUR(36); BZ_ITUR(37); BZ_ITUR(38); BZ_ITUR(39);
|
||||||
|
BZ_ITUR(40); BZ_ITUR(41); BZ_ITUR(42); BZ_ITUR(43); BZ_ITUR(44);
|
||||||
|
BZ_ITUR(45); BZ_ITUR(46); BZ_ITUR(47); BZ_ITUR(48); BZ_ITUR(49);
|
||||||
|
|
||||||
|
# undef BZ_ITUR
|
||||||
|
|
||||||
|
} else {
|
||||||
|
/*--- slow version which correctly handles all situations ---*/
|
||||||
|
for (i = gs; i <= ge; i++)
|
||||||
|
s->rfreq[bt][ mtfv[i] ]++;
|
||||||
|
}
|
||||||
|
|
||||||
|
gs = ge+1;
|
||||||
|
}
|
||||||
|
if (s->verbosity >= 3) {
|
||||||
|
VPrintf2 ( " pass %d: size is %d, grp uses are ",
|
||||||
|
iter+1, totc/8 );
|
||||||
|
for (t = 0; t < nGroups; t++)
|
||||||
|
VPrintf1 ( "%d ", fave[t] );
|
||||||
|
VPrintf0 ( "\n" );
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--
|
||||||
|
Recompute the tables based on the accumulated frequencies.
|
||||||
|
--*/
|
||||||
|
for (t = 0; t < nGroups; t++)
|
||||||
|
BZ2_hbMakeCodeLengths ( &(s->len[t][0]), &(s->rfreq[t][0]),
|
||||||
|
alphaSize, 20 );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
AssertH( nGroups < 8, 3002 );
|
||||||
|
AssertH( nSelectors < 32768 &&
|
||||||
|
nSelectors <= (2 + (900000 / BZ_G_SIZE)),
|
||||||
|
3003 );
|
||||||
|
|
||||||
|
|
||||||
|
/*--- Compute MTF values for the selectors. ---*/
|
||||||
|
{
|
||||||
|
UChar pos[BZ_N_GROUPS], ll_i, tmp2, tmp;
|
||||||
|
for (i = 0; i < nGroups; i++) pos[i] = i;
|
||||||
|
for (i = 0; i < nSelectors; i++) {
|
||||||
|
ll_i = s->selector[i];
|
||||||
|
j = 0;
|
||||||
|
tmp = pos[j];
|
||||||
|
while ( ll_i != tmp ) {
|
||||||
|
j++;
|
||||||
|
tmp2 = tmp;
|
||||||
|
tmp = pos[j];
|
||||||
|
pos[j] = tmp2;
|
||||||
|
};
|
||||||
|
pos[0] = tmp;
|
||||||
|
s->selectorMtf[i] = j;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/*--- Assign actual codes for the tables. --*/
|
||||||
|
for (t = 0; t < nGroups; t++) {
|
||||||
|
minLen = 32;
|
||||||
|
maxLen = 0;
|
||||||
|
for (i = 0; i < alphaSize; i++) {
|
||||||
|
if (s->len[t][i] > maxLen) maxLen = s->len[t][i];
|
||||||
|
if (s->len[t][i] < minLen) minLen = s->len[t][i];
|
||||||
|
}
|
||||||
|
AssertH ( !(maxLen > 20), 3004 );
|
||||||
|
AssertH ( !(minLen < 1), 3005 );
|
||||||
|
BZ2_hbAssignCodes ( &(s->code[t][0]), &(s->len[t][0]),
|
||||||
|
minLen, maxLen, alphaSize );
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--- Transmit the mapping table. ---*/
|
||||||
|
{
|
||||||
|
Bool inUse16[16];
|
||||||
|
for (i = 0; i < 16; i++) {
|
||||||
|
inUse16[i] = False;
|
||||||
|
for (j = 0; j < 16; j++)
|
||||||
|
if (s->inUse[i * 16 + j]) inUse16[i] = True;
|
||||||
|
}
|
||||||
|
|
||||||
|
nBytes = s->numZ;
|
||||||
|
for (i = 0; i < 16; i++)
|
||||||
|
if (inUse16[i]) bsW(s,1,1); else bsW(s,1,0);
|
||||||
|
|
||||||
|
for (i = 0; i < 16; i++)
|
||||||
|
if (inUse16[i])
|
||||||
|
for (j = 0; j < 16; j++) {
|
||||||
|
if (s->inUse[i * 16 + j]) bsW(s,1,1); else bsW(s,1,0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (s->verbosity >= 3)
|
||||||
|
VPrintf1( " bytes: mapping %d, ", s->numZ-nBytes );
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--- Now the selectors. ---*/
|
||||||
|
nBytes = s->numZ;
|
||||||
|
bsW ( s, 3, nGroups );
|
||||||
|
bsW ( s, 15, nSelectors );
|
||||||
|
for (i = 0; i < nSelectors; i++) {
|
||||||
|
for (j = 0; j < s->selectorMtf[i]; j++) bsW(s,1,1);
|
||||||
|
bsW(s,1,0);
|
||||||
|
}
|
||||||
|
if (s->verbosity >= 3)
|
||||||
|
VPrintf1( "selectors %d, ", s->numZ-nBytes );
|
||||||
|
|
||||||
|
/*--- Now the coding tables. ---*/
|
||||||
|
nBytes = s->numZ;
|
||||||
|
|
||||||
|
for (t = 0; t < nGroups; t++) {
|
||||||
|
Int32 curr = s->len[t][0];
|
||||||
|
bsW ( s, 5, curr );
|
||||||
|
for (i = 0; i < alphaSize; i++) {
|
||||||
|
while (curr < s->len[t][i]) { bsW(s,2,2); curr++; /* 10 */ };
|
||||||
|
while (curr > s->len[t][i]) { bsW(s,2,3); curr--; /* 11 */ };
|
||||||
|
bsW ( s, 1, 0 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (s->verbosity >= 3)
|
||||||
|
VPrintf1 ( "code lengths %d, ", s->numZ-nBytes );
|
||||||
|
|
||||||
|
/*--- And finally, the block data proper ---*/
|
||||||
|
nBytes = s->numZ;
|
||||||
|
selCtr = 0;
|
||||||
|
gs = 0;
|
||||||
|
while (True) {
|
||||||
|
if (gs >= s->nMTF) break;
|
||||||
|
ge = gs + BZ_G_SIZE - 1;
|
||||||
|
if (ge >= s->nMTF) ge = s->nMTF-1;
|
||||||
|
AssertH ( s->selector[selCtr] < nGroups, 3006 );
|
||||||
|
|
||||||
|
if (nGroups == 6 && 50 == ge-gs+1) {
|
||||||
|
/*--- fast track the common case ---*/
|
||||||
|
UInt16 mtfv_i;
|
||||||
|
UChar* s_len_sel_selCtr
|
||||||
|
= &(s->len[s->selector[selCtr]][0]);
|
||||||
|
Int32* s_code_sel_selCtr
|
||||||
|
= &(s->code[s->selector[selCtr]][0]);
|
||||||
|
|
||||||
|
# define BZ_ITAH(nn) \
|
||||||
|
mtfv_i = mtfv[gs+(nn)]; \
|
||||||
|
bsW ( s, \
|
||||||
|
s_len_sel_selCtr[mtfv_i], \
|
||||||
|
s_code_sel_selCtr[mtfv_i] )
|
||||||
|
|
||||||
|
BZ_ITAH(0); BZ_ITAH(1); BZ_ITAH(2); BZ_ITAH(3); BZ_ITAH(4);
|
||||||
|
BZ_ITAH(5); BZ_ITAH(6); BZ_ITAH(7); BZ_ITAH(8); BZ_ITAH(9);
|
||||||
|
BZ_ITAH(10); BZ_ITAH(11); BZ_ITAH(12); BZ_ITAH(13); BZ_ITAH(14);
|
||||||
|
BZ_ITAH(15); BZ_ITAH(16); BZ_ITAH(17); BZ_ITAH(18); BZ_ITAH(19);
|
||||||
|
BZ_ITAH(20); BZ_ITAH(21); BZ_ITAH(22); BZ_ITAH(23); BZ_ITAH(24);
|
||||||
|
BZ_ITAH(25); BZ_ITAH(26); BZ_ITAH(27); BZ_ITAH(28); BZ_ITAH(29);
|
||||||
|
BZ_ITAH(30); BZ_ITAH(31); BZ_ITAH(32); BZ_ITAH(33); BZ_ITAH(34);
|
||||||
|
BZ_ITAH(35); BZ_ITAH(36); BZ_ITAH(37); BZ_ITAH(38); BZ_ITAH(39);
|
||||||
|
BZ_ITAH(40); BZ_ITAH(41); BZ_ITAH(42); BZ_ITAH(43); BZ_ITAH(44);
|
||||||
|
BZ_ITAH(45); BZ_ITAH(46); BZ_ITAH(47); BZ_ITAH(48); BZ_ITAH(49);
|
||||||
|
|
||||||
|
# undef BZ_ITAH
|
||||||
|
|
||||||
|
} else {
|
||||||
|
/*--- slow version which correctly handles all situations ---*/
|
||||||
|
for (i = gs; i <= ge; i++) {
|
||||||
|
bsW ( s,
|
||||||
|
s->len [s->selector[selCtr]] [mtfv[i]],
|
||||||
|
s->code [s->selector[selCtr]] [mtfv[i]] );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
gs = ge+1;
|
||||||
|
selCtr++;
|
||||||
|
}
|
||||||
|
AssertH( selCtr == nSelectors, 3007 );
|
||||||
|
|
||||||
|
if (s->verbosity >= 3)
|
||||||
|
VPrintf1( "codes %d\n", s->numZ-nBytes );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*---------------------------------------------------*/
|
||||||
|
void BZ2_compressBlock ( EState* s, Bool is_last_block )
|
||||||
|
{
|
||||||
|
if (s->nblock > 0) {
|
||||||
|
|
||||||
|
BZ_FINALISE_CRC ( s->blockCRC );
|
||||||
|
s->combinedCRC = (s->combinedCRC << 1) | (s->combinedCRC >> 31);
|
||||||
|
s->combinedCRC ^= s->blockCRC;
|
||||||
|
if (s->blockNo > 1) s->numZ = 0;
|
||||||
|
|
||||||
|
if (s->verbosity >= 2)
|
||||||
|
VPrintf4( " block %d: crc = 0x%8x, "
|
||||||
|
"combined CRC = 0x%8x, size = %d\n",
|
||||||
|
s->blockNo, s->blockCRC, s->combinedCRC, s->nblock );
|
||||||
|
|
||||||
|
BZ2_blockSort ( s );
|
||||||
|
}
|
||||||
|
|
||||||
|
s->zbits = (UChar*) (&((UChar*)s->arr2)[s->nblock]);
|
||||||
|
|
||||||
|
/*-- If this is the first block, create the stream header. --*/
|
||||||
|
if (s->blockNo == 1) {
|
||||||
|
BZ2_bsInitWrite ( s );
|
||||||
|
bsPutUChar ( s, BZ_HDR_B );
|
||||||
|
bsPutUChar ( s, BZ_HDR_Z );
|
||||||
|
bsPutUChar ( s, BZ_HDR_h );
|
||||||
|
bsPutUChar ( s, (UChar)(BZ_HDR_0 + s->blockSize100k) );
|
||||||
|
}
|
||||||
|
|
||||||
|
if (s->nblock > 0) {
|
||||||
|
|
||||||
|
bsPutUChar ( s, 0x31 ); bsPutUChar ( s, 0x41 );
|
||||||
|
bsPutUChar ( s, 0x59 ); bsPutUChar ( s, 0x26 );
|
||||||
|
bsPutUChar ( s, 0x53 ); bsPutUChar ( s, 0x59 );
|
||||||
|
|
||||||
|
/*-- Now the block's CRC, so it is in a known place. --*/
|
||||||
|
bsPutUInt32 ( s, s->blockCRC );
|
||||||
|
|
||||||
|
/*--
|
||||||
|
Now a single bit indicating (non-)randomisation.
|
||||||
|
As of version 0.9.5, we use a better sorting algorithm
|
||||||
|
which makes randomisation unnecessary. So always set
|
||||||
|
the randomised bit to 'no'. Of course, the decoder
|
||||||
|
still needs to be able to handle randomised blocks
|
||||||
|
so as to maintain backwards compatibility with
|
||||||
|
older versions of bzip2.
|
||||||
|
--*/
|
||||||
|
bsW(s,1,0);
|
||||||
|
|
||||||
|
bsW ( s, 24, s->origPtr );
|
||||||
|
generateMTFValues ( s );
|
||||||
|
sendMTFValues ( s );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*-- If this is the last block, add the stream trailer. --*/
|
||||||
|
if (is_last_block) {
|
||||||
|
|
||||||
|
bsPutUChar ( s, 0x17 ); bsPutUChar ( s, 0x72 );
|
||||||
|
bsPutUChar ( s, 0x45 ); bsPutUChar ( s, 0x38 );
|
||||||
|
bsPutUChar ( s, 0x50 ); bsPutUChar ( s, 0x90 );
|
||||||
|
bsPutUInt32 ( s, s->combinedCRC );
|
||||||
|
if (s->verbosity >= 2)
|
||||||
|
VPrintf1( " final combined CRC = 0x%x\n ", s->combinedCRC );
|
||||||
|
bsFinishWrite ( s );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*-------------------------------------------------------------*/
|
||||||
|
/*--- end compress.c ---*/
|
||||||
|
/*-------------------------------------------------------------*/
|
144
bzip2/crctable.c
Normal file
144
bzip2/crctable.c
Normal file
|
@ -0,0 +1,144 @@
|
||||||
|
|
||||||
|
/*-------------------------------------------------------------*/
|
||||||
|
/*--- Table for doing CRCs ---*/
|
||||||
|
/*--- crctable.c ---*/
|
||||||
|
/*-------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/*--
|
||||||
|
This file is a part of bzip2 and/or libbzip2, a program and
|
||||||
|
library for lossless, block-sorting data compression.
|
||||||
|
|
||||||
|
Copyright (C) 1996-2002 Julian R Seward. All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions
|
||||||
|
are met:
|
||||||
|
|
||||||
|
1. Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
2. The origin of this software must not be misrepresented; you must
|
||||||
|
not claim that you wrote the original software. If you use this
|
||||||
|
software in a product, an acknowledgment in the product
|
||||||
|
documentation would be appreciated but is not required.
|
||||||
|
|
||||||
|
3. Altered source versions must be plainly marked as such, and must
|
||||||
|
not be misrepresented as being the original software.
|
||||||
|
|
||||||
|
4. The name of the author may not be used to endorse or promote
|
||||||
|
products derived from this software without specific prior written
|
||||||
|
permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
|
||||||
|
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||||
|
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||||
|
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||||
|
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
|
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
Julian Seward, Cambridge, UK.
|
||||||
|
jseward@acm.org
|
||||||
|
bzip2/libbzip2 version 1.0 of 21 March 2000
|
||||||
|
|
||||||
|
This program is based on (at least) the work of:
|
||||||
|
Mike Burrows
|
||||||
|
David Wheeler
|
||||||
|
Peter Fenwick
|
||||||
|
Alistair Moffat
|
||||||
|
Radford Neal
|
||||||
|
Ian H. Witten
|
||||||
|
Robert Sedgewick
|
||||||
|
Jon L. Bentley
|
||||||
|
|
||||||
|
For more information on these sources, see the manual.
|
||||||
|
--*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "bzlib_private.h"
|
||||||
|
|
||||||
|
/*--
|
||||||
|
I think this is an implementation of the AUTODIN-II,
|
||||||
|
Ethernet & FDDI 32-bit CRC standard. Vaguely derived
|
||||||
|
from code by Rob Warnock, in Section 51 of the
|
||||||
|
comp.compression FAQ.
|
||||||
|
--*/
|
||||||
|
|
||||||
|
UInt32 BZ2_crc32Table[256] = {
|
||||||
|
|
||||||
|
/*-- Ugly, innit? --*/
|
||||||
|
|
||||||
|
0x00000000L, 0x04c11db7L, 0x09823b6eL, 0x0d4326d9L,
|
||||||
|
0x130476dcL, 0x17c56b6bL, 0x1a864db2L, 0x1e475005L,
|
||||||
|
0x2608edb8L, 0x22c9f00fL, 0x2f8ad6d6L, 0x2b4bcb61L,
|
||||||
|
0x350c9b64L, 0x31cd86d3L, 0x3c8ea00aL, 0x384fbdbdL,
|
||||||
|
0x4c11db70L, 0x48d0c6c7L, 0x4593e01eL, 0x4152fda9L,
|
||||||
|
0x5f15adacL, 0x5bd4b01bL, 0x569796c2L, 0x52568b75L,
|
||||||
|
0x6a1936c8L, 0x6ed82b7fL, 0x639b0da6L, 0x675a1011L,
|
||||||
|
0x791d4014L, 0x7ddc5da3L, 0x709f7b7aL, 0x745e66cdL,
|
||||||
|
0x9823b6e0L, 0x9ce2ab57L, 0x91a18d8eL, 0x95609039L,
|
||||||
|
0x8b27c03cL, 0x8fe6dd8bL, 0x82a5fb52L, 0x8664e6e5L,
|
||||||
|
0xbe2b5b58L, 0xbaea46efL, 0xb7a96036L, 0xb3687d81L,
|
||||||
|
0xad2f2d84L, 0xa9ee3033L, 0xa4ad16eaL, 0xa06c0b5dL,
|
||||||
|
0xd4326d90L, 0xd0f37027L, 0xddb056feL, 0xd9714b49L,
|
||||||
|
0xc7361b4cL, 0xc3f706fbL, 0xceb42022L, 0xca753d95L,
|
||||||
|
0xf23a8028L, 0xf6fb9d9fL, 0xfbb8bb46L, 0xff79a6f1L,
|
||||||
|
0xe13ef6f4L, 0xe5ffeb43L, 0xe8bccd9aL, 0xec7dd02dL,
|
||||||
|
0x34867077L, 0x30476dc0L, 0x3d044b19L, 0x39c556aeL,
|
||||||
|
0x278206abL, 0x23431b1cL, 0x2e003dc5L, 0x2ac12072L,
|
||||||
|
0x128e9dcfL, 0x164f8078L, 0x1b0ca6a1L, 0x1fcdbb16L,
|
||||||
|
0x018aeb13L, 0x054bf6a4L, 0x0808d07dL, 0x0cc9cdcaL,
|
||||||
|
0x7897ab07L, 0x7c56b6b0L, 0x71159069L, 0x75d48ddeL,
|
||||||
|
0x6b93dddbL, 0x6f52c06cL, 0x6211e6b5L, 0x66d0fb02L,
|
||||||
|
0x5e9f46bfL, 0x5a5e5b08L, 0x571d7dd1L, 0x53dc6066L,
|
||||||
|
0x4d9b3063L, 0x495a2dd4L, 0x44190b0dL, 0x40d816baL,
|
||||||
|
0xaca5c697L, 0xa864db20L, 0xa527fdf9L, 0xa1e6e04eL,
|
||||||
|
0xbfa1b04bL, 0xbb60adfcL, 0xb6238b25L, 0xb2e29692L,
|
||||||
|
0x8aad2b2fL, 0x8e6c3698L, 0x832f1041L, 0x87ee0df6L,
|
||||||
|
0x99a95df3L, 0x9d684044L, 0x902b669dL, 0x94ea7b2aL,
|
||||||
|
0xe0b41de7L, 0xe4750050L, 0xe9362689L, 0xedf73b3eL,
|
||||||
|
0xf3b06b3bL, 0xf771768cL, 0xfa325055L, 0xfef34de2L,
|
||||||
|
0xc6bcf05fL, 0xc27dede8L, 0xcf3ecb31L, 0xcbffd686L,
|
||||||
|
0xd5b88683L, 0xd1799b34L, 0xdc3abdedL, 0xd8fba05aL,
|
||||||
|
0x690ce0eeL, 0x6dcdfd59L, 0x608edb80L, 0x644fc637L,
|
||||||
|
0x7a089632L, 0x7ec98b85L, 0x738aad5cL, 0x774bb0ebL,
|
||||||
|
0x4f040d56L, 0x4bc510e1L, 0x46863638L, 0x42472b8fL,
|
||||||
|
0x5c007b8aL, 0x58c1663dL, 0x558240e4L, 0x51435d53L,
|
||||||
|
0x251d3b9eL, 0x21dc2629L, 0x2c9f00f0L, 0x285e1d47L,
|
||||||
|
0x36194d42L, 0x32d850f5L, 0x3f9b762cL, 0x3b5a6b9bL,
|
||||||
|
0x0315d626L, 0x07d4cb91L, 0x0a97ed48L, 0x0e56f0ffL,
|
||||||
|
0x1011a0faL, 0x14d0bd4dL, 0x19939b94L, 0x1d528623L,
|
||||||
|
0xf12f560eL, 0xf5ee4bb9L, 0xf8ad6d60L, 0xfc6c70d7L,
|
||||||
|
0xe22b20d2L, 0xe6ea3d65L, 0xeba91bbcL, 0xef68060bL,
|
||||||
|
0xd727bbb6L, 0xd3e6a601L, 0xdea580d8L, 0xda649d6fL,
|
||||||
|
0xc423cd6aL, 0xc0e2d0ddL, 0xcda1f604L, 0xc960ebb3L,
|
||||||
|
0xbd3e8d7eL, 0xb9ff90c9L, 0xb4bcb610L, 0xb07daba7L,
|
||||||
|
0xae3afba2L, 0xaafbe615L, 0xa7b8c0ccL, 0xa379dd7bL,
|
||||||
|
0x9b3660c6L, 0x9ff77d71L, 0x92b45ba8L, 0x9675461fL,
|
||||||
|
0x8832161aL, 0x8cf30badL, 0x81b02d74L, 0x857130c3L,
|
||||||
|
0x5d8a9099L, 0x594b8d2eL, 0x5408abf7L, 0x50c9b640L,
|
||||||
|
0x4e8ee645L, 0x4a4ffbf2L, 0x470cdd2bL, 0x43cdc09cL,
|
||||||
|
0x7b827d21L, 0x7f436096L, 0x7200464fL, 0x76c15bf8L,
|
||||||
|
0x68860bfdL, 0x6c47164aL, 0x61043093L, 0x65c52d24L,
|
||||||
|
0x119b4be9L, 0x155a565eL, 0x18197087L, 0x1cd86d30L,
|
||||||
|
0x029f3d35L, 0x065e2082L, 0x0b1d065bL, 0x0fdc1becL,
|
||||||
|
0x3793a651L, 0x3352bbe6L, 0x3e119d3fL, 0x3ad08088L,
|
||||||
|
0x2497d08dL, 0x2056cd3aL, 0x2d15ebe3L, 0x29d4f654L,
|
||||||
|
0xc5a92679L, 0xc1683bceL, 0xcc2b1d17L, 0xc8ea00a0L,
|
||||||
|
0xd6ad50a5L, 0xd26c4d12L, 0xdf2f6bcbL, 0xdbee767cL,
|
||||||
|
0xe3a1cbc1L, 0xe760d676L, 0xea23f0afL, 0xeee2ed18L,
|
||||||
|
0xf0a5bd1dL, 0xf464a0aaL, 0xf9278673L, 0xfde69bc4L,
|
||||||
|
0x89b8fd09L, 0x8d79e0beL, 0x803ac667L, 0x84fbdbd0L,
|
||||||
|
0x9abc8bd5L, 0x9e7d9662L, 0x933eb0bbL, 0x97ffad0cL,
|
||||||
|
0xafb010b1L, 0xab710d06L, 0xa6322bdfL, 0xa2f33668L,
|
||||||
|
0xbcb4666dL, 0xb8757bdaL, 0xb5365d03L, 0xb1f740b4L
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/*-------------------------------------------------------------*/
|
||||||
|
/*--- end crctable.c ---*/
|
||||||
|
/*-------------------------------------------------------------*/
|
228
bzip2/huffman.c
Normal file
228
bzip2/huffman.c
Normal file
|
@ -0,0 +1,228 @@
|
||||||
|
|
||||||
|
/*-------------------------------------------------------------*/
|
||||||
|
/*--- Huffman coding low-level stuff ---*/
|
||||||
|
/*--- huffman.c ---*/
|
||||||
|
/*-------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/*--
|
||||||
|
This file is a part of bzip2 and/or libbzip2, a program and
|
||||||
|
library for lossless, block-sorting data compression.
|
||||||
|
|
||||||
|
Copyright (C) 1996-2002 Julian R Seward. All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions
|
||||||
|
are met:
|
||||||
|
|
||||||
|
1. Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
2. The origin of this software must not be misrepresented; you must
|
||||||
|
not claim that you wrote the original software. If you use this
|
||||||
|
software in a product, an acknowledgment in the product
|
||||||
|
documentation would be appreciated but is not required.
|
||||||
|
|
||||||
|
3. Altered source versions must be plainly marked as such, and must
|
||||||
|
not be misrepresented as being the original software.
|
||||||
|
|
||||||
|
4. The name of the author may not be used to endorse or promote
|
||||||
|
products derived from this software without specific prior written
|
||||||
|
permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
|
||||||
|
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||||
|
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||||
|
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||||
|
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
|
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
Julian Seward, Cambridge, UK.
|
||||||
|
jseward@acm.org
|
||||||
|
bzip2/libbzip2 version 1.0 of 21 March 2000
|
||||||
|
|
||||||
|
This program is based on (at least) the work of:
|
||||||
|
Mike Burrows
|
||||||
|
David Wheeler
|
||||||
|
Peter Fenwick
|
||||||
|
Alistair Moffat
|
||||||
|
Radford Neal
|
||||||
|
Ian H. Witten
|
||||||
|
Robert Sedgewick
|
||||||
|
Jon L. Bentley
|
||||||
|
|
||||||
|
For more information on these sources, see the manual.
|
||||||
|
--*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "bzlib_private.h"
|
||||||
|
|
||||||
|
/*---------------------------------------------------*/
|
||||||
|
#define WEIGHTOF(zz0) ((zz0) & 0xffffff00)
|
||||||
|
#define DEPTHOF(zz1) ((zz1) & 0x000000ff)
|
||||||
|
#define MYMAX(zz2,zz3) ((zz2) > (zz3) ? (zz2) : (zz3))
|
||||||
|
|
||||||
|
#define ADDWEIGHTS(zw1,zw2) \
|
||||||
|
(WEIGHTOF(zw1)+WEIGHTOF(zw2)) | \
|
||||||
|
(1 + MYMAX(DEPTHOF(zw1),DEPTHOF(zw2)))
|
||||||
|
|
||||||
|
#define UPHEAP(z) \
|
||||||
|
{ \
|
||||||
|
Int32 zz, tmp; \
|
||||||
|
zz = z; tmp = heap[zz]; \
|
||||||
|
while (weight[tmp] < weight[heap[zz >> 1]]) { \
|
||||||
|
heap[zz] = heap[zz >> 1]; \
|
||||||
|
zz >>= 1; \
|
||||||
|
} \
|
||||||
|
heap[zz] = tmp; \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define DOWNHEAP(z) \
|
||||||
|
{ \
|
||||||
|
Int32 zz, yy, tmp; \
|
||||||
|
zz = z; tmp = heap[zz]; \
|
||||||
|
while (True) { \
|
||||||
|
yy = zz << 1; \
|
||||||
|
if (yy > nHeap) break; \
|
||||||
|
if (yy < nHeap && \
|
||||||
|
weight[heap[yy+1]] < weight[heap[yy]]) \
|
||||||
|
yy++; \
|
||||||
|
if (weight[tmp] < weight[heap[yy]]) break; \
|
||||||
|
heap[zz] = heap[yy]; \
|
||||||
|
zz = yy; \
|
||||||
|
} \
|
||||||
|
heap[zz] = tmp; \
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*---------------------------------------------------*/
|
||||||
|
void BZ2_hbMakeCodeLengths ( UChar *len,
|
||||||
|
Int32 *freq,
|
||||||
|
Int32 alphaSize,
|
||||||
|
Int32 maxLen )
|
||||||
|
{
|
||||||
|
/*--
|
||||||
|
Nodes and heap entries run from 1. Entry 0
|
||||||
|
for both the heap and nodes is a sentinel.
|
||||||
|
--*/
|
||||||
|
Int32 nNodes, nHeap, n1, n2, i, j, k;
|
||||||
|
Bool tooLong;
|
||||||
|
|
||||||
|
Int32 heap [ BZ_MAX_ALPHA_SIZE + 2 ];
|
||||||
|
Int32 weight [ BZ_MAX_ALPHA_SIZE * 2 ];
|
||||||
|
Int32 parent [ BZ_MAX_ALPHA_SIZE * 2 ];
|
||||||
|
|
||||||
|
for (i = 0; i < alphaSize; i++)
|
||||||
|
weight[i+1] = (freq[i] == 0 ? 1 : freq[i]) << 8;
|
||||||
|
|
||||||
|
while (True) {
|
||||||
|
|
||||||
|
nNodes = alphaSize;
|
||||||
|
nHeap = 0;
|
||||||
|
|
||||||
|
heap[0] = 0;
|
||||||
|
weight[0] = 0;
|
||||||
|
parent[0] = -2;
|
||||||
|
|
||||||
|
for (i = 1; i <= alphaSize; i++) {
|
||||||
|
parent[i] = -1;
|
||||||
|
nHeap++;
|
||||||
|
heap[nHeap] = i;
|
||||||
|
UPHEAP(nHeap);
|
||||||
|
}
|
||||||
|
|
||||||
|
AssertH( nHeap < (BZ_MAX_ALPHA_SIZE+2), 2001 );
|
||||||
|
|
||||||
|
while (nHeap > 1) {
|
||||||
|
n1 = heap[1]; heap[1] = heap[nHeap]; nHeap--; DOWNHEAP(1);
|
||||||
|
n2 = heap[1]; heap[1] = heap[nHeap]; nHeap--; DOWNHEAP(1);
|
||||||
|
nNodes++;
|
||||||
|
parent[n1] = parent[n2] = nNodes;
|
||||||
|
weight[nNodes] = ADDWEIGHTS(weight[n1], weight[n2]);
|
||||||
|
parent[nNodes] = -1;
|
||||||
|
nHeap++;
|
||||||
|
heap[nHeap] = nNodes;
|
||||||
|
UPHEAP(nHeap);
|
||||||
|
}
|
||||||
|
|
||||||
|
AssertH( nNodes < (BZ_MAX_ALPHA_SIZE * 2), 2002 );
|
||||||
|
|
||||||
|
tooLong = False;
|
||||||
|
for (i = 1; i <= alphaSize; i++) {
|
||||||
|
j = 0;
|
||||||
|
k = i;
|
||||||
|
while (parent[k] >= 0) { k = parent[k]; j++; }
|
||||||
|
len[i-1] = j;
|
||||||
|
if (j > maxLen) tooLong = True;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! tooLong) break;
|
||||||
|
|
||||||
|
for (i = 1; i < alphaSize; i++) {
|
||||||
|
j = weight[i] >> 8;
|
||||||
|
j = 1 + (j / 2);
|
||||||
|
weight[i] = j << 8;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*---------------------------------------------------*/
|
||||||
|
void BZ2_hbAssignCodes ( Int32 *code,
|
||||||
|
UChar *length,
|
||||||
|
Int32 minLen,
|
||||||
|
Int32 maxLen,
|
||||||
|
Int32 alphaSize )
|
||||||
|
{
|
||||||
|
Int32 n, vec, i;
|
||||||
|
|
||||||
|
vec = 0;
|
||||||
|
for (n = minLen; n <= maxLen; n++) {
|
||||||
|
for (i = 0; i < alphaSize; i++)
|
||||||
|
if (length[i] == n) { code[i] = vec; vec++; };
|
||||||
|
vec <<= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*---------------------------------------------------*/
|
||||||
|
void BZ2_hbCreateDecodeTables ( Int32 *limit,
|
||||||
|
Int32 *base,
|
||||||
|
Int32 *perm,
|
||||||
|
UChar *length,
|
||||||
|
Int32 minLen,
|
||||||
|
Int32 maxLen,
|
||||||
|
Int32 alphaSize )
|
||||||
|
{
|
||||||
|
Int32 pp, i, j, vec;
|
||||||
|
|
||||||
|
pp = 0;
|
||||||
|
for (i = minLen; i <= maxLen; i++)
|
||||||
|
for (j = 0; j < alphaSize; j++)
|
||||||
|
if (length[j] == i) { perm[pp] = j; pp++; };
|
||||||
|
|
||||||
|
for (i = 0; i < BZ_MAX_CODE_LEN; i++) base[i] = 0;
|
||||||
|
for (i = 0; i < alphaSize; i++) base[length[i]+1]++;
|
||||||
|
|
||||||
|
for (i = 1; i < BZ_MAX_CODE_LEN; i++) base[i] += base[i-1];
|
||||||
|
|
||||||
|
for (i = 0; i < BZ_MAX_CODE_LEN; i++) limit[i] = 0;
|
||||||
|
vec = 0;
|
||||||
|
|
||||||
|
for (i = minLen; i <= maxLen; i++) {
|
||||||
|
vec += (base[i+1] - base[i]);
|
||||||
|
limit[i] = vec-1;
|
||||||
|
vec <<= 1;
|
||||||
|
}
|
||||||
|
for (i = minLen + 1; i <= maxLen; i++)
|
||||||
|
base[i] = ((limit[i-1] + 1) << 1) - base[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*-------------------------------------------------------------*/
|
||||||
|
/*--- end huffman.c ---*/
|
||||||
|
/*-------------------------------------------------------------*/
|
124
bzip2/randtable.c
Normal file
124
bzip2/randtable.c
Normal file
|
@ -0,0 +1,124 @@
|
||||||
|
|
||||||
|
/*-------------------------------------------------------------*/
|
||||||
|
/*--- Table for randomising repetitive blocks ---*/
|
||||||
|
/*--- randtable.c ---*/
|
||||||
|
/*-------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/*--
|
||||||
|
This file is a part of bzip2 and/or libbzip2, a program and
|
||||||
|
library for lossless, block-sorting data compression.
|
||||||
|
|
||||||
|
Copyright (C) 1996-2002 Julian R Seward. All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions
|
||||||
|
are met:
|
||||||
|
|
||||||
|
1. Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
2. The origin of this software must not be misrepresented; you must
|
||||||
|
not claim that you wrote the original software. If you use this
|
||||||
|
software in a product, an acknowledgment in the product
|
||||||
|
documentation would be appreciated but is not required.
|
||||||
|
|
||||||
|
3. Altered source versions must be plainly marked as such, and must
|
||||||
|
not be misrepresented as being the original software.
|
||||||
|
|
||||||
|
4. The name of the author may not be used to endorse or promote
|
||||||
|
products derived from this software without specific prior written
|
||||||
|
permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
|
||||||
|
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||||
|
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||||
|
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||||
|
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
|
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
Julian Seward, Cambridge, UK.
|
||||||
|
jseward@acm.org
|
||||||
|
bzip2/libbzip2 version 1.0 of 21 March 2000
|
||||||
|
|
||||||
|
This program is based on (at least) the work of:
|
||||||
|
Mike Burrows
|
||||||
|
David Wheeler
|
||||||
|
Peter Fenwick
|
||||||
|
Alistair Moffat
|
||||||
|
Radford Neal
|
||||||
|
Ian H. Witten
|
||||||
|
Robert Sedgewick
|
||||||
|
Jon L. Bentley
|
||||||
|
|
||||||
|
For more information on these sources, see the manual.
|
||||||
|
--*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "bzlib_private.h"
|
||||||
|
|
||||||
|
|
||||||
|
/*---------------------------------------------*/
|
||||||
|
Int32 BZ2_rNums[512] = {
|
||||||
|
619, 720, 127, 481, 931, 816, 813, 233, 566, 247,
|
||||||
|
985, 724, 205, 454, 863, 491, 741, 242, 949, 214,
|
||||||
|
733, 859, 335, 708, 621, 574, 73, 654, 730, 472,
|
||||||
|
419, 436, 278, 496, 867, 210, 399, 680, 480, 51,
|
||||||
|
878, 465, 811, 169, 869, 675, 611, 697, 867, 561,
|
||||||
|
862, 687, 507, 283, 482, 129, 807, 591, 733, 623,
|
||||||
|
150, 238, 59, 379, 684, 877, 625, 169, 643, 105,
|
||||||
|
170, 607, 520, 932, 727, 476, 693, 425, 174, 647,
|
||||||
|
73, 122, 335, 530, 442, 853, 695, 249, 445, 515,
|
||||||
|
909, 545, 703, 919, 874, 474, 882, 500, 594, 612,
|
||||||
|
641, 801, 220, 162, 819, 984, 589, 513, 495, 799,
|
||||||
|
161, 604, 958, 533, 221, 400, 386, 867, 600, 782,
|
||||||
|
382, 596, 414, 171, 516, 375, 682, 485, 911, 276,
|
||||||
|
98, 553, 163, 354, 666, 933, 424, 341, 533, 870,
|
||||||
|
227, 730, 475, 186, 263, 647, 537, 686, 600, 224,
|
||||||
|
469, 68, 770, 919, 190, 373, 294, 822, 808, 206,
|
||||||
|
184, 943, 795, 384, 383, 461, 404, 758, 839, 887,
|
||||||
|
715, 67, 618, 276, 204, 918, 873, 777, 604, 560,
|
||||||
|
951, 160, 578, 722, 79, 804, 96, 409, 713, 940,
|
||||||
|
652, 934, 970, 447, 318, 353, 859, 672, 112, 785,
|
||||||
|
645, 863, 803, 350, 139, 93, 354, 99, 820, 908,
|
||||||
|
609, 772, 154, 274, 580, 184, 79, 626, 630, 742,
|
||||||
|
653, 282, 762, 623, 680, 81, 927, 626, 789, 125,
|
||||||
|
411, 521, 938, 300, 821, 78, 343, 175, 128, 250,
|
||||||
|
170, 774, 972, 275, 999, 639, 495, 78, 352, 126,
|
||||||
|
857, 956, 358, 619, 580, 124, 737, 594, 701, 612,
|
||||||
|
669, 112, 134, 694, 363, 992, 809, 743, 168, 974,
|
||||||
|
944, 375, 748, 52, 600, 747, 642, 182, 862, 81,
|
||||||
|
344, 805, 988, 739, 511, 655, 814, 334, 249, 515,
|
||||||
|
897, 955, 664, 981, 649, 113, 974, 459, 893, 228,
|
||||||
|
433, 837, 553, 268, 926, 240, 102, 654, 459, 51,
|
||||||
|
686, 754, 806, 760, 493, 403, 415, 394, 687, 700,
|
||||||
|
946, 670, 656, 610, 738, 392, 760, 799, 887, 653,
|
||||||
|
978, 321, 576, 617, 626, 502, 894, 679, 243, 440,
|
||||||
|
680, 879, 194, 572, 640, 724, 926, 56, 204, 700,
|
||||||
|
707, 151, 457, 449, 797, 195, 791, 558, 945, 679,
|
||||||
|
297, 59, 87, 824, 713, 663, 412, 693, 342, 606,
|
||||||
|
134, 108, 571, 364, 631, 212, 174, 643, 304, 329,
|
||||||
|
343, 97, 430, 751, 497, 314, 983, 374, 822, 928,
|
||||||
|
140, 206, 73, 263, 980, 736, 876, 478, 430, 305,
|
||||||
|
170, 514, 364, 692, 829, 82, 855, 953, 676, 246,
|
||||||
|
369, 970, 294, 750, 807, 827, 150, 790, 288, 923,
|
||||||
|
804, 378, 215, 828, 592, 281, 565, 555, 710, 82,
|
||||||
|
896, 831, 547, 261, 524, 462, 293, 465, 502, 56,
|
||||||
|
661, 821, 976, 991, 658, 869, 905, 758, 745, 193,
|
||||||
|
768, 550, 608, 933, 378, 286, 215, 979, 792, 961,
|
||||||
|
61, 688, 793, 644, 986, 403, 106, 366, 905, 644,
|
||||||
|
372, 567, 466, 434, 645, 210, 389, 550, 919, 135,
|
||||||
|
780, 773, 635, 389, 707, 100, 626, 958, 165, 504,
|
||||||
|
920, 176, 193, 713, 857, 265, 203, 50, 668, 108,
|
||||||
|
645, 990, 626, 197, 510, 357, 358, 850, 858, 364,
|
||||||
|
936, 638
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/*-------------------------------------------------------------*/
|
||||||
|
/*--- end randtable.c ---*/
|
||||||
|
/*-------------------------------------------------------------*/
|
1
clear.bat
Normal file
1
clear.bat
Normal file
|
@ -0,0 +1 @@
|
||||||
|
del *.plg *.obj *.o *.sbr *.pch *.pdb *.res *.bsc *.pcc *.idb *.pdb *.ncb *.aps *.ilk 2*.log *.map *.opt *.exp *.sup *.dpbcd gebug.txt *_d.exe *_d.dll *_d.lib *_debug.dll *_debug.exe *.tlh *.tli /s
|
89
main.cpp
Normal file
89
main.cpp
Normal file
|
@ -0,0 +1,89 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "UnAlz.h"
|
||||||
|
|
||||||
|
|
||||||
|
void Usage()
|
||||||
|
{
|
||||||
|
printf("\n");
|
||||||
|
printf("USAGE : unalz sourcefile.alz [dest path] \n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void UnAlzCallback(const char* szMessage, INT64 nCurrent, INT64 nRange, void* param, BOOL* bHalt)
|
||||||
|
{
|
||||||
|
// progress
|
||||||
|
char buf[1000];
|
||||||
|
INT64 percent;
|
||||||
|
static INT64 nPrevPercent = -1;
|
||||||
|
int buflen;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
// 파일명 출력..
|
||||||
|
if(szMessage)
|
||||||
|
{
|
||||||
|
printf("\n");
|
||||||
|
printf("Extracting : %s ", szMessage);
|
||||||
|
nPrevPercent = -1;
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
percent = nCurrent*100/nRange;
|
||||||
|
|
||||||
|
if(nPrevPercent==percent) return; // 너무 잦은 업데이트 방지..
|
||||||
|
nPrevPercent = percent;
|
||||||
|
#ifdef _WIN32
|
||||||
|
sprintf(buf, "%I64d/%I64d (%I64d%%)", nCurrent, nRange, percent);
|
||||||
|
#else
|
||||||
|
sprintf(buf, "%d/%d (%d%%)", (int)nCurrent, (int)nRange, (int)percent);
|
||||||
|
#endif
|
||||||
|
printf("%s", buf);
|
||||||
|
buflen = strlen(buf);
|
||||||
|
fflush(stdout);
|
||||||
|
|
||||||
|
for(i=0;i<buflen;i++)
|
||||||
|
printf("\b");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
printf("unalz v0.20 (2004/10/22) \n");
|
||||||
|
printf("copyright(C) 2004 http://www.kipple.pe.kr\n");
|
||||||
|
|
||||||
|
|
||||||
|
if(argc<2)
|
||||||
|
{
|
||||||
|
Usage();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
char* source = argv[1];
|
||||||
|
char* dest = argv[2];
|
||||||
|
|
||||||
|
if(argc<3) dest="."; // current dir
|
||||||
|
else dest = argv[2];
|
||||||
|
|
||||||
|
|
||||||
|
CUnAlz unalz;
|
||||||
|
|
||||||
|
if(unalz.Open(source)==FALSE)
|
||||||
|
{
|
||||||
|
printf("file open error : %s\nerr code(%d)\n", source,unalz.GetLastErr());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("\nExtract %s to %s\n", source, dest);
|
||||||
|
|
||||||
|
|
||||||
|
// callback 함수 세팅
|
||||||
|
unalz.SetCallback(UnAlzCallback, (void*)NULL);
|
||||||
|
if(unalz.ExtractAll(dest)==FALSE)
|
||||||
|
{
|
||||||
|
printf("extract %s to %s failed.\n", source, dest);
|
||||||
|
}
|
||||||
|
printf("\ndone..\n");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
72
makefile
Normal file
72
makefile
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
CPP = g++
|
||||||
|
CC = gcc
|
||||||
|
OBJ = main.o UnAlz.o UnAlzBz2decompress.o UnAlzBzip2.o UnAlzbzlib.o zlib/adler32.o zlib/crc32.o zlib/infblock.o zlib/infcodes.o zlib/inffast.o zlib/inflate.o zlib/inftrees.o zlib/infutil.o zlib/zutil.o bzip2/blocksort.o bzip2/compress.o bzip2/crctable.o bzip2/huffman.o bzip2/randtable.o
|
||||||
|
LINKOBJ = main.o UnAlz.o UnAlzBz2decompress.o UnAlzBzip2.o UnAlzbzlib.o zlib/adler32.o zlib/crc32.o zlib/infblock.o zlib/infcodes.o zlib/inffast.o zlib/inflate.o zlib/inftrees.o zlib/infutil.o zlib/zutil.o bzip2/blocksort.o bzip2/compress.o bzip2/crctable.o bzip2/huffman.o bzip2/randtable.o
|
||||||
|
BIN = unalz
|
||||||
|
CFLAGS =
|
||||||
|
|
||||||
|
all: unalz
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f $(OBJ) $(BIN)
|
||||||
|
|
||||||
|
$(BIN): $(OBJ)
|
||||||
|
$(CPP) $(LINKOBJ) -o "unalz"
|
||||||
|
|
||||||
|
main.o: main.cpp
|
||||||
|
$(CPP) -c main.cpp -o main.o
|
||||||
|
|
||||||
|
UnAlz.o: UnAlz.cpp
|
||||||
|
$(CPP) -c UnAlz.cpp -o UnAlz.o
|
||||||
|
|
||||||
|
UnAlzBz2decompress.o: UnAlzBz2decompress.c
|
||||||
|
$(CC) -c UnAlzBz2decompress.c -o UnAlzBz2decompress.o $(CFLAGS)
|
||||||
|
|
||||||
|
UnAlzBzip2.o: UnAlzBzip2.cpp
|
||||||
|
$(CPP) -c UnAlzBzip2.cpp -o UnAlzBzip2.o
|
||||||
|
|
||||||
|
UnAlzbzlib.o: UnAlzbzlib.c
|
||||||
|
$(CC) -c UnAlzbzlib.c -o UnAlzbzlib.o $(CFLAGS)
|
||||||
|
|
||||||
|
zlib/adler32.o: zlib/adler32.c
|
||||||
|
$(CC) -c zlib/adler32.c -o zlib/adler32.o $(CFLAGS)
|
||||||
|
|
||||||
|
zlib/crc32.o: zlib/crc32.c
|
||||||
|
$(CC) -c zlib/crc32.c -o zlib/crc32.o $(CFLAGS)
|
||||||
|
|
||||||
|
zlib/infblock.o: zlib/infblock.c
|
||||||
|
$(CC) -c zlib/infblock.c -o zlib/infblock.o $(CFLAGS)
|
||||||
|
|
||||||
|
zlib/infcodes.o: zlib/infcodes.c
|
||||||
|
$(CC) -c zlib/infcodes.c -o zlib/infcodes.o $(CFLAGS)
|
||||||
|
|
||||||
|
zlib/inffast.o: zlib/inffast.c
|
||||||
|
$(CC) -c zlib/inffast.c -o zlib/inffast.o $(CFLAGS)
|
||||||
|
|
||||||
|
zlib/inflate.o: zlib/inflate.c
|
||||||
|
$(CC) -c zlib/inflate.c -o zlib/inflate.o $(CFLAGS)
|
||||||
|
|
||||||
|
zlib/inftrees.o: zlib/inftrees.c
|
||||||
|
$(CC) -c zlib/inftrees.c -o zlib/inftrees.o $(CFLAGS)
|
||||||
|
|
||||||
|
zlib/infutil.o: zlib/infutil.c
|
||||||
|
$(CC) -c zlib/infutil.c -o zlib/infutil.o $(CFLAGS)
|
||||||
|
|
||||||
|
zlib/zutil.o: zlib/zutil.c
|
||||||
|
$(CC) -c zlib/zutil.c -o zlib/zutil.o $(CFLAGS)
|
||||||
|
|
||||||
|
bzip2/blocksort.o: bzip2/blocksort.c
|
||||||
|
$(CC) -c bzip2/blocksort.c -o bzip2/blocksort.o $(CFLAGS)
|
||||||
|
|
||||||
|
bzip2/compress.o: bzip2/compress.c
|
||||||
|
$(CC) -c bzip2/compress.c -o bzip2/compress.o $(CFLAGS)
|
||||||
|
|
||||||
|
bzip2/crctable.o: bzip2/crctable.c
|
||||||
|
$(CC) -c bzip2/crctable.c -o bzip2/crctable.o $(CFLAGS)
|
||||||
|
|
||||||
|
bzip2/huffman.o: bzip2/huffman.c
|
||||||
|
$(CC) -c bzip2/huffman.c -o bzip2/huffman.o $(CFLAGS)
|
||||||
|
|
||||||
|
bzip2/randtable.o: bzip2/randtable.c
|
||||||
|
$(CC) -c bzip2/randtable.c -o bzip2/randtable.o $(CFLAGS)
|
||||||
|
|
19
readme.txt
Normal file
19
readme.txt
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
|
||||||
|
|
||||||
|
unalz v0.2
|
||||||
|
|
||||||
|
copyright(C) 2004 http://www.kipple.pe.kr
|
||||||
|
|
||||||
|
|
||||||
|
- 최종 갱신일 : 2004/10/22
|
||||||
|
|
||||||
|
- 기능
|
||||||
|
. alz 파일 압축 해제 프로그램
|
||||||
|
. deflate/변형 bzip2/raw 포맷 지원
|
||||||
|
. 분할 압축 파일 지원
|
||||||
|
. WIN32(VC60/VC70/DEV-C++) , Free-BSD/LINUX(gcc/g++) 지원
|
||||||
|
|
||||||
|
|
||||||
|
- 라이선스
|
||||||
|
. 자유로이 변형/배포 가능 (BSD-license)
|
||||||
|
|
369
unalz.dev
Normal file
369
unalz.dev
Normal file
|
@ -0,0 +1,369 @@
|
||||||
|
[Project]
|
||||||
|
FileName=unalz.dev
|
||||||
|
Name=unalz
|
||||||
|
Ver=1
|
||||||
|
IsCpp=1
|
||||||
|
Type=1
|
||||||
|
Compiler=-D__GNUWIN32__ -W -DWIN32 -DNDEBUG -D_CONSOLE -D_MBCS_@@_
|
||||||
|
CppCompiler=-D__GNUWIN32__ -W -DWIN32 -DNDEBUG -D_CONSOLE -D_MBCS_@@_
|
||||||
|
Includes=
|
||||||
|
Linker=-lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -luuid -lodbc32 -lodbccp32 -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -luuid -lodbc32 -lodbccp32_@@_
|
||||||
|
Libs=
|
||||||
|
UnitCount=32
|
||||||
|
Folders=bzip2,main,unalz,zlib
|
||||||
|
ObjFiles=
|
||||||
|
PrivateResource=
|
||||||
|
ResourceIncludes=
|
||||||
|
MakeIncludes=
|
||||||
|
Icon=
|
||||||
|
ExeOutput=./bin/
|
||||||
|
ObjectOutput=
|
||||||
|
OverrideOutput=0
|
||||||
|
OverrideOutputName=unalz.exe
|
||||||
|
HostApplication=
|
||||||
|
CommandLine=
|
||||||
|
UseCustomMakefile=0
|
||||||
|
CustomMakefile=
|
||||||
|
IncludeVersionInfo=0
|
||||||
|
SupportXPThemes=0
|
||||||
|
CompilerSet=0
|
||||||
|
CompilerSettings=0000000000000000000000
|
||||||
|
|
||||||
|
[Unit1]
|
||||||
|
FileName=main.cpp
|
||||||
|
Folder=main
|
||||||
|
Compile=1
|
||||||
|
CompileCpp=1
|
||||||
|
Link=1
|
||||||
|
Priority=1000
|
||||||
|
OverrideBuildCmd=0
|
||||||
|
BuildCmd=
|
||||||
|
|
||||||
|
[Unit2]
|
||||||
|
FileName=UnAlz.cpp
|
||||||
|
Folder=unalz
|
||||||
|
Compile=1
|
||||||
|
CompileCpp=1
|
||||||
|
Link=1
|
||||||
|
Priority=1000
|
||||||
|
OverrideBuildCmd=0
|
||||||
|
BuildCmd=
|
||||||
|
|
||||||
|
[Unit3]
|
||||||
|
FileName=UnAlz.h
|
||||||
|
Folder=unalz
|
||||||
|
Compile=1
|
||||||
|
CompileCpp=1
|
||||||
|
Link=1
|
||||||
|
Priority=1000
|
||||||
|
OverrideBuildCmd=0
|
||||||
|
BuildCmd=
|
||||||
|
|
||||||
|
[Unit4]
|
||||||
|
FileName=UnAlzBz2decompress.c
|
||||||
|
Folder=unalz
|
||||||
|
Compile=1
|
||||||
|
CompileCpp=0
|
||||||
|
Link=1
|
||||||
|
Priority=1000
|
||||||
|
OverrideBuildCmd=0
|
||||||
|
BuildCmd=
|
||||||
|
|
||||||
|
[Unit5]
|
||||||
|
FileName=UnAlzBzip2.cpp
|
||||||
|
Folder=unalz
|
||||||
|
Compile=1
|
||||||
|
CompileCpp=1
|
||||||
|
Link=1
|
||||||
|
Priority=1000
|
||||||
|
OverrideBuildCmd=0
|
||||||
|
BuildCmd=
|
||||||
|
|
||||||
|
[Unit6]
|
||||||
|
FileName=UnAlzbzlib.c
|
||||||
|
Folder=unalz
|
||||||
|
Compile=1
|
||||||
|
CompileCpp=0
|
||||||
|
Link=1
|
||||||
|
Priority=1000
|
||||||
|
OverrideBuildCmd=0
|
||||||
|
BuildCmd=
|
||||||
|
|
||||||
|
[Unit7]
|
||||||
|
FileName=zlib\adler32.c
|
||||||
|
Folder=zlib
|
||||||
|
Compile=1
|
||||||
|
CompileCpp=0
|
||||||
|
Link=1
|
||||||
|
Priority=1000
|
||||||
|
OverrideBuildCmd=0
|
||||||
|
BuildCmd=
|
||||||
|
|
||||||
|
[Unit8]
|
||||||
|
FileName=zlib\crc32.c
|
||||||
|
Folder=zlib
|
||||||
|
Compile=1
|
||||||
|
CompileCpp=0
|
||||||
|
Link=1
|
||||||
|
Priority=1000
|
||||||
|
OverrideBuildCmd=0
|
||||||
|
BuildCmd=
|
||||||
|
|
||||||
|
[Unit9]
|
||||||
|
FileName=zlib\infblock.c
|
||||||
|
Folder=zlib
|
||||||
|
Compile=1
|
||||||
|
CompileCpp=0
|
||||||
|
Link=1
|
||||||
|
Priority=1000
|
||||||
|
OverrideBuildCmd=0
|
||||||
|
BuildCmd=
|
||||||
|
|
||||||
|
[Unit10]
|
||||||
|
FileName=zlib\INFBLOCK.H
|
||||||
|
Folder=zlib
|
||||||
|
Compile=1
|
||||||
|
CompileCpp=1
|
||||||
|
Link=1
|
||||||
|
Priority=1000
|
||||||
|
OverrideBuildCmd=0
|
||||||
|
BuildCmd=
|
||||||
|
|
||||||
|
[Unit11]
|
||||||
|
FileName=zlib\infcodes.c
|
||||||
|
Folder=zlib
|
||||||
|
Compile=1
|
||||||
|
CompileCpp=0
|
||||||
|
Link=1
|
||||||
|
Priority=1000
|
||||||
|
OverrideBuildCmd=0
|
||||||
|
BuildCmd=
|
||||||
|
|
||||||
|
[Unit12]
|
||||||
|
FileName=zlib\INFCODES.H
|
||||||
|
Folder=zlib
|
||||||
|
Compile=1
|
||||||
|
CompileCpp=1
|
||||||
|
Link=1
|
||||||
|
Priority=1000
|
||||||
|
OverrideBuildCmd=0
|
||||||
|
BuildCmd=
|
||||||
|
|
||||||
|
[Unit13]
|
||||||
|
FileName=zlib\inffast.c
|
||||||
|
Folder=zlib
|
||||||
|
Compile=1
|
||||||
|
CompileCpp=0
|
||||||
|
Link=1
|
||||||
|
Priority=1000
|
||||||
|
OverrideBuildCmd=0
|
||||||
|
BuildCmd=
|
||||||
|
|
||||||
|
[Unit14]
|
||||||
|
FileName=zlib\INFFAST.H
|
||||||
|
Folder=zlib
|
||||||
|
Compile=1
|
||||||
|
CompileCpp=1
|
||||||
|
Link=1
|
||||||
|
Priority=1000
|
||||||
|
OverrideBuildCmd=0
|
||||||
|
BuildCmd=
|
||||||
|
|
||||||
|
[Unit15]
|
||||||
|
FileName=zlib\INFFIXED.H
|
||||||
|
Folder=zlib
|
||||||
|
Compile=1
|
||||||
|
CompileCpp=1
|
||||||
|
Link=1
|
||||||
|
Priority=1000
|
||||||
|
OverrideBuildCmd=0
|
||||||
|
BuildCmd=
|
||||||
|
|
||||||
|
[Unit16]
|
||||||
|
FileName=zlib\inflate.c
|
||||||
|
Folder=zlib
|
||||||
|
Compile=1
|
||||||
|
CompileCpp=0
|
||||||
|
Link=1
|
||||||
|
Priority=1000
|
||||||
|
OverrideBuildCmd=0
|
||||||
|
BuildCmd=
|
||||||
|
|
||||||
|
[Unit17]
|
||||||
|
FileName=zlib\inftrees.c
|
||||||
|
Folder=zlib
|
||||||
|
Compile=1
|
||||||
|
CompileCpp=0
|
||||||
|
Link=1
|
||||||
|
Priority=1000
|
||||||
|
OverrideBuildCmd=0
|
||||||
|
BuildCmd=
|
||||||
|
|
||||||
|
[Unit18]
|
||||||
|
FileName=zlib\INFTREES.H
|
||||||
|
Folder=zlib
|
||||||
|
Compile=1
|
||||||
|
CompileCpp=1
|
||||||
|
Link=1
|
||||||
|
Priority=1000
|
||||||
|
OverrideBuildCmd=0
|
||||||
|
BuildCmd=
|
||||||
|
|
||||||
|
[Unit19]
|
||||||
|
FileName=zlib\infutil.c
|
||||||
|
Folder=zlib
|
||||||
|
Compile=1
|
||||||
|
CompileCpp=0
|
||||||
|
Link=1
|
||||||
|
Priority=1000
|
||||||
|
OverrideBuildCmd=0
|
||||||
|
BuildCmd=
|
||||||
|
|
||||||
|
[Unit20]
|
||||||
|
FileName=zlib\INFUTIL.H
|
||||||
|
Folder=zlib
|
||||||
|
Compile=1
|
||||||
|
CompileCpp=1
|
||||||
|
Link=1
|
||||||
|
Priority=1000
|
||||||
|
OverrideBuildCmd=0
|
||||||
|
BuildCmd=
|
||||||
|
|
||||||
|
[Unit21]
|
||||||
|
FileName=zlib\uncompr.c
|
||||||
|
Folder=zlib
|
||||||
|
Compile=1
|
||||||
|
CompileCpp=0
|
||||||
|
Link=1
|
||||||
|
Priority=1000
|
||||||
|
OverrideBuildCmd=0
|
||||||
|
BuildCmd=
|
||||||
|
|
||||||
|
[Unit22]
|
||||||
|
FileName=zlib\ZCONF.H
|
||||||
|
Folder=zlib
|
||||||
|
Compile=1
|
||||||
|
CompileCpp=1
|
||||||
|
Link=1
|
||||||
|
Priority=1000
|
||||||
|
OverrideBuildCmd=0
|
||||||
|
BuildCmd=
|
||||||
|
|
||||||
|
[Unit23]
|
||||||
|
FileName=zlib\ZLIB.H
|
||||||
|
Folder=zlib
|
||||||
|
Compile=1
|
||||||
|
CompileCpp=1
|
||||||
|
Link=1
|
||||||
|
Priority=1000
|
||||||
|
OverrideBuildCmd=0
|
||||||
|
BuildCmd=
|
||||||
|
|
||||||
|
[Unit24]
|
||||||
|
FileName=zlib\zutil.c
|
||||||
|
Folder=zlib
|
||||||
|
Compile=1
|
||||||
|
CompileCpp=0
|
||||||
|
Link=1
|
||||||
|
Priority=1000
|
||||||
|
OverrideBuildCmd=0
|
||||||
|
BuildCmd=
|
||||||
|
|
||||||
|
[Unit25]
|
||||||
|
FileName=zlib\ZUTIL.H
|
||||||
|
Folder=zlib
|
||||||
|
Compile=1
|
||||||
|
CompileCpp=1
|
||||||
|
Link=1
|
||||||
|
Priority=1000
|
||||||
|
OverrideBuildCmd=0
|
||||||
|
BuildCmd=
|
||||||
|
|
||||||
|
[Unit26]
|
||||||
|
FileName=bzip2\blocksort.c
|
||||||
|
Folder=bzip2
|
||||||
|
Compile=1
|
||||||
|
CompileCpp=0
|
||||||
|
Link=1
|
||||||
|
Priority=1000
|
||||||
|
OverrideBuildCmd=0
|
||||||
|
BuildCmd=
|
||||||
|
|
||||||
|
[Unit27]
|
||||||
|
FileName=bzip2\bzlib.h
|
||||||
|
Folder=bzip2
|
||||||
|
Compile=1
|
||||||
|
CompileCpp=1
|
||||||
|
Link=1
|
||||||
|
Priority=1000
|
||||||
|
OverrideBuildCmd=0
|
||||||
|
BuildCmd=
|
||||||
|
|
||||||
|
[Unit28]
|
||||||
|
FileName=bzip2\bzlib_private.h
|
||||||
|
Folder=bzip2
|
||||||
|
Compile=1
|
||||||
|
CompileCpp=1
|
||||||
|
Link=1
|
||||||
|
Priority=1000
|
||||||
|
OverrideBuildCmd=0
|
||||||
|
BuildCmd=
|
||||||
|
|
||||||
|
[Unit29]
|
||||||
|
FileName=bzip2\compress.c
|
||||||
|
Folder=bzip2
|
||||||
|
Compile=1
|
||||||
|
CompileCpp=0
|
||||||
|
Link=1
|
||||||
|
Priority=1000
|
||||||
|
OverrideBuildCmd=0
|
||||||
|
BuildCmd=
|
||||||
|
|
||||||
|
[Unit30]
|
||||||
|
FileName=bzip2\crctable.c
|
||||||
|
Folder=bzip2
|
||||||
|
Compile=1
|
||||||
|
CompileCpp=0
|
||||||
|
Link=1
|
||||||
|
Priority=1000
|
||||||
|
OverrideBuildCmd=0
|
||||||
|
BuildCmd=
|
||||||
|
|
||||||
|
[Unit31]
|
||||||
|
FileName=bzip2\huffman.c
|
||||||
|
Folder=bzip2
|
||||||
|
Compile=1
|
||||||
|
CompileCpp=0
|
||||||
|
Link=1
|
||||||
|
Priority=1000
|
||||||
|
OverrideBuildCmd=0
|
||||||
|
BuildCmd=
|
||||||
|
|
||||||
|
[Unit32]
|
||||||
|
FileName=bzip2\randtable.c
|
||||||
|
Folder=bzip2
|
||||||
|
Compile=1
|
||||||
|
CompileCpp=0
|
||||||
|
Link=1
|
||||||
|
Priority=1000
|
||||||
|
OverrideBuildCmd=0
|
||||||
|
BuildCmd=
|
||||||
|
|
||||||
|
[VersionInfo]
|
||||||
|
Major=0
|
||||||
|
Minor=1
|
||||||
|
Release=1
|
||||||
|
Build=1
|
||||||
|
LanguageID=1033
|
||||||
|
CharsetID=1252
|
||||||
|
CompanyName=
|
||||||
|
FileVersion=0.1
|
||||||
|
FileDescription=Developed using the Dev-C++ IDE
|
||||||
|
InternalName=
|
||||||
|
LegalCopyright=
|
||||||
|
LegalTrademarks=
|
||||||
|
OriginalFilename=unalz.exe
|
||||||
|
ProductName=unalz
|
||||||
|
ProductVersion=0.1
|
||||||
|
AutoIncBuildNr=0
|
||||||
|
|
230
unalz.dsp
Normal file
230
unalz.dsp
Normal file
|
@ -0,0 +1,230 @@
|
||||||
|
# Microsoft Developer Studio Project File - Name="unalz" - Package Owner=<4>
|
||||||
|
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||||
|
# ** DO NOT EDIT **
|
||||||
|
|
||||||
|
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
||||||
|
|
||||||
|
CFG=unalz - Win32 Debug
|
||||||
|
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||||
|
!MESSAGE use the Export Makefile command and run
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "unalz.mak".
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE You can specify a configuration when running NMAKE
|
||||||
|
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "unalz.mak" CFG="unalz - Win32 Debug"
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE Possible choices for configuration are:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE "unalz - Win32 Release" (based on "Win32 (x86) Console Application")
|
||||||
|
!MESSAGE "unalz - Win32 Debug" (based on "Win32 (x86) Console Application")
|
||||||
|
!MESSAGE
|
||||||
|
|
||||||
|
# Begin Project
|
||||||
|
# PROP AllowPerConfigDependencies 0
|
||||||
|
# PROP Scc_ProjName ""$/Home/unalz", VXBAAAAA"
|
||||||
|
# PROP Scc_LocalPath "."
|
||||||
|
CPP=cl.exe
|
||||||
|
RSC=rc.exe
|
||||||
|
|
||||||
|
!IF "$(CFG)" == "unalz - Win32 Release"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 0
|
||||||
|
# PROP BASE Output_Dir "Release"
|
||||||
|
# PROP BASE Intermediate_Dir "Release"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 0
|
||||||
|
# PROP Output_Dir "Release"
|
||||||
|
# PROP Intermediate_Dir "Release"
|
||||||
|
# PROP Ignore_Export_Lib 0
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||||
|
# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||||
|
# ADD BASE RSC /l 0x412 /d "NDEBUG"
|
||||||
|
# ADD RSC /l 0x412 /d "NDEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||||
|
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:"bin/unalz.exe"
|
||||||
|
|
||||||
|
!ELSEIF "$(CFG)" == "unalz - Win32 Debug"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 1
|
||||||
|
# PROP BASE Output_Dir "Debug"
|
||||||
|
# PROP BASE Intermediate_Dir "Debug"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 1
|
||||||
|
# PROP Output_Dir "Debug"
|
||||||
|
# PROP Intermediate_Dir "Debug"
|
||||||
|
# PROP Ignore_Export_Lib 0
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||||
|
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||||
|
# ADD BASE RSC /l 0x412 /d "_DEBUG"
|
||||||
|
# ADD RSC /l 0x412 /d "_DEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||||
|
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:"bin/unalz_d.exe" /pdbtype:sept
|
||||||
|
|
||||||
|
!ENDIF
|
||||||
|
|
||||||
|
# Begin Target
|
||||||
|
|
||||||
|
# Name "unalz - Win32 Release"
|
||||||
|
# Name "unalz - Win32 Debug"
|
||||||
|
# Begin Group "main"
|
||||||
|
|
||||||
|
# PROP Default_Filter ""
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\main.cpp
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\readme.txt
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# Begin Group "bzip2"
|
||||||
|
|
||||||
|
# PROP Default_Filter ""
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\bzip2\blocksort.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\bzip2\bzlib.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\bzip2\bzlib_private.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\bzip2\compress.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\bzip2\crctable.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\bzip2\huffman.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\bzip2\randtable.c
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# Begin Group "zlib"
|
||||||
|
|
||||||
|
# PROP Default_Filter ""
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\zlib\adler32.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\zlib\crc32.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\zlib\infblock.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\zlib\infblock.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\zlib\infcodes.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\zlib\infcodes.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\zlib\inffast.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\zlib\inffast.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\zlib\inffixed.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\zlib\inflate.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\zlib\inftrees.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\zlib\inftrees.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\zlib\infutil.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\zlib\infutil.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\zlib\zconf.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\zlib\zlib.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\zlib\zutil.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\zlib\zutil.h
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# Begin Group "unalz"
|
||||||
|
|
||||||
|
# PROP Default_Filter ""
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\UnAlz.cpp
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\UnAlz.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\UnAlzBz2decompress.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\UnAlzBzip2.cpp
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\UnAlzbzlib.c
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# End Target
|
||||||
|
# End Project
|
33
unalz.dsw
Normal file
33
unalz.dsw
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
Microsoft Developer Studio Workspace File, Format Version 6.00
|
||||||
|
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Project: "unalz"=.\unalz.dsp - Package Owner=<4>
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
begin source code control
|
||||||
|
"$/Home/unalz", VXBAAAAA
|
||||||
|
.
|
||||||
|
end source code control
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<4>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
Global:
|
||||||
|
|
||||||
|
Package=<5>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Package=<3>
|
||||||
|
{{{
|
||||||
|
}}}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
29
unalz.sln
Normal file
29
unalz.sln
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 8.00
|
||||||
|
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "unalz", "unalz.vcproj", "{E92968E8-DF95-411B-80E2-23F17B3DDFF8}"
|
||||||
|
ProjectSection(ProjectDependencies) = postProject
|
||||||
|
EndProjectSection
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SourceCodeControl) = preSolution
|
||||||
|
SccNumberOfProjects = 1
|
||||||
|
SccProjectUniqueName0 = unalz.vcproj
|
||||||
|
SccProjectName0 = \u0022$/Home/unalz\u0022,\u0020VXBAAAAA
|
||||||
|
SccLocalPath0 = .
|
||||||
|
SccProvider0 = MSSCCI:Microsoft\u0020Visual\u0020SourceSafe
|
||||||
|
CanCheckoutShared = false
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionConfiguration) = preSolution
|
||||||
|
Debug = Debug
|
||||||
|
Release = Release
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfiguration) = postSolution
|
||||||
|
{E92968E8-DF95-411B-80E2-23F17B3DDFF8}.Debug.ActiveCfg = Debug|Win32
|
||||||
|
{E92968E8-DF95-411B-80E2-23F17B3DDFF8}.Debug.Build.0 = Debug|Win32
|
||||||
|
{E92968E8-DF95-411B-80E2-23F17B3DDFF8}.Release.ActiveCfg = Release|Win32
|
||||||
|
{E92968E8-DF95-411B-80E2-23F17B3DDFF8}.Release.Build.0 = Release|Win32
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityAddIns) = postSolution
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
532
unalz.vcproj
Normal file
532
unalz.vcproj
Normal file
|
@ -0,0 +1,532 @@
|
||||||
|
<?xml version="1.0" encoding="ks_c_5601-1987"?>
|
||||||
|
<VisualStudioProject
|
||||||
|
ProjectType="Visual C++"
|
||||||
|
Version="7.10"
|
||||||
|
Name="unalz"
|
||||||
|
SccProjectName=""$/Home/unalz", VXBAAAAA"
|
||||||
|
SccAuxPath=""
|
||||||
|
SccLocalPath="."
|
||||||
|
SccProvider="MSSCCI:Microsoft Visual SourceSafe">
|
||||||
|
<Platforms>
|
||||||
|
<Platform
|
||||||
|
Name="Win32"/>
|
||||||
|
</Platforms>
|
||||||
|
<Configurations>
|
||||||
|
<Configuration
|
||||||
|
Name="Debug|Win32"
|
||||||
|
OutputDirectory=".\Debug"
|
||||||
|
IntermediateDirectory=".\Debug"
|
||||||
|
ConfigurationType="1"
|
||||||
|
UseOfMFC="0"
|
||||||
|
ATLMinimizesCRunTimeLibraryUsage="FALSE"
|
||||||
|
CharacterSet="2">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
Optimization="0"
|
||||||
|
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
|
||||||
|
BasicRuntimeChecks="3"
|
||||||
|
RuntimeLibrary="5"
|
||||||
|
UsePrecompiledHeader="2"
|
||||||
|
PrecompiledHeaderFile=".\Debug/unalz.pch"
|
||||||
|
AssemblerListingLocation=".\Debug/"
|
||||||
|
ObjectFile=".\Debug/"
|
||||||
|
ProgramDataBaseFileName=".\Debug/"
|
||||||
|
WarningLevel="3"
|
||||||
|
SuppressStartupBanner="TRUE"
|
||||||
|
DebugInformationFormat="4"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCCustomBuildTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCLinkerTool"
|
||||||
|
OutputFile="bin/unalz_d.exe"
|
||||||
|
LinkIncremental="1"
|
||||||
|
SuppressStartupBanner="TRUE"
|
||||||
|
GenerateDebugInformation="TRUE"
|
||||||
|
ProgramDatabaseFile=".\Debug/unalz_d.pdb"
|
||||||
|
SubSystem="1"
|
||||||
|
TargetMachine="1"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCMIDLTool"
|
||||||
|
TypeLibraryName=".\Debug/unalz.tlb"
|
||||||
|
HeaderFileName=""/>
|
||||||
|
<Tool
|
||||||
|
Name="VCPostBuildEventTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCPreBuildEventTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCPreLinkEventTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCResourceCompilerTool"
|
||||||
|
PreprocessorDefinitions="_DEBUG"
|
||||||
|
Culture="1042"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCWebServiceProxyGeneratorTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCXMLDataGeneratorTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCWebDeploymentTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCManagedWrapperGeneratorTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||||
|
</Configuration>
|
||||||
|
<Configuration
|
||||||
|
Name="Release|Win32"
|
||||||
|
OutputDirectory=".\Release"
|
||||||
|
IntermediateDirectory=".\Release"
|
||||||
|
ConfigurationType="1"
|
||||||
|
UseOfMFC="0"
|
||||||
|
ATLMinimizesCRunTimeLibraryUsage="FALSE"
|
||||||
|
CharacterSet="2">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
Optimization="2"
|
||||||
|
InlineFunctionExpansion="1"
|
||||||
|
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
|
||||||
|
StringPooling="TRUE"
|
||||||
|
RuntimeLibrary="4"
|
||||||
|
EnableFunctionLevelLinking="TRUE"
|
||||||
|
UsePrecompiledHeader="2"
|
||||||
|
PrecompiledHeaderFile=".\Release/unalz.pch"
|
||||||
|
AssemblerListingLocation=".\Release/"
|
||||||
|
ObjectFile=".\Release/"
|
||||||
|
ProgramDataBaseFileName=".\Release/"
|
||||||
|
WarningLevel="3"
|
||||||
|
SuppressStartupBanner="TRUE"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCCustomBuildTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCLinkerTool"
|
||||||
|
OutputFile="bin/unalz.exe"
|
||||||
|
LinkIncremental="1"
|
||||||
|
SuppressStartupBanner="TRUE"
|
||||||
|
ProgramDatabaseFile=".\Release/unalz.pdb"
|
||||||
|
SubSystem="1"
|
||||||
|
TargetMachine="1"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCMIDLTool"
|
||||||
|
TypeLibraryName=".\Release/unalz.tlb"
|
||||||
|
HeaderFileName=""/>
|
||||||
|
<Tool
|
||||||
|
Name="VCPostBuildEventTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCPreBuildEventTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCPreLinkEventTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCResourceCompilerTool"
|
||||||
|
PreprocessorDefinitions="NDEBUG"
|
||||||
|
Culture="1042"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCWebServiceProxyGeneratorTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCXMLDataGeneratorTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCWebDeploymentTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCManagedWrapperGeneratorTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||||
|
</Configuration>
|
||||||
|
</Configurations>
|
||||||
|
<References>
|
||||||
|
</References>
|
||||||
|
<Files>
|
||||||
|
<Filter
|
||||||
|
Name="main"
|
||||||
|
Filter="">
|
||||||
|
<File
|
||||||
|
RelativePath="main.cpp">
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Debug|Win32">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
Optimization="0"
|
||||||
|
PreprocessorDefinitions=""
|
||||||
|
BasicRuntimeChecks="3"/>
|
||||||
|
</FileConfiguration>
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Release|Win32">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
Optimization="2"
|
||||||
|
PreprocessorDefinitions=""/>
|
||||||
|
</FileConfiguration>
|
||||||
|
</File>
|
||||||
|
</Filter>
|
||||||
|
<Filter
|
||||||
|
Name="bzip2"
|
||||||
|
Filter="">
|
||||||
|
<File
|
||||||
|
RelativePath="bzip2\blocksort.c">
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Debug|Win32">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
Optimization="0"
|
||||||
|
PreprocessorDefinitions=""
|
||||||
|
BasicRuntimeChecks="3"/>
|
||||||
|
</FileConfiguration>
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Release|Win32">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
Optimization="2"
|
||||||
|
PreprocessorDefinitions=""/>
|
||||||
|
</FileConfiguration>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="bzip2\bzlib.h">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="bzip2\bzlib_private.h">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="bzip2\compress.c">
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Debug|Win32">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
Optimization="0"
|
||||||
|
PreprocessorDefinitions=""
|
||||||
|
BasicRuntimeChecks="3"/>
|
||||||
|
</FileConfiguration>
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Release|Win32">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
Optimization="2"
|
||||||
|
PreprocessorDefinitions=""/>
|
||||||
|
</FileConfiguration>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="bzip2\crctable.c">
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Debug|Win32">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
Optimization="0"
|
||||||
|
PreprocessorDefinitions=""
|
||||||
|
BasicRuntimeChecks="3"/>
|
||||||
|
</FileConfiguration>
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Release|Win32">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
Optimization="2"
|
||||||
|
PreprocessorDefinitions=""/>
|
||||||
|
</FileConfiguration>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="bzip2\huffman.c">
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Debug|Win32">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
Optimization="0"
|
||||||
|
PreprocessorDefinitions=""
|
||||||
|
BasicRuntimeChecks="3"/>
|
||||||
|
</FileConfiguration>
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Release|Win32">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
Optimization="2"
|
||||||
|
PreprocessorDefinitions=""/>
|
||||||
|
</FileConfiguration>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="bzip2\randtable.c">
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Debug|Win32">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
Optimization="0"
|
||||||
|
PreprocessorDefinitions=""
|
||||||
|
BasicRuntimeChecks="3"/>
|
||||||
|
</FileConfiguration>
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Release|Win32">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
Optimization="2"
|
||||||
|
PreprocessorDefinitions=""/>
|
||||||
|
</FileConfiguration>
|
||||||
|
</File>
|
||||||
|
</Filter>
|
||||||
|
<Filter
|
||||||
|
Name="zlib"
|
||||||
|
Filter="">
|
||||||
|
<File
|
||||||
|
RelativePath="zlib\adler32.c">
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Debug|Win32">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
Optimization="0"
|
||||||
|
PreprocessorDefinitions=""
|
||||||
|
BasicRuntimeChecks="3"/>
|
||||||
|
</FileConfiguration>
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Release|Win32">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
Optimization="2"
|
||||||
|
PreprocessorDefinitions=""/>
|
||||||
|
</FileConfiguration>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="zlib\crc32.c">
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Debug|Win32">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
Optimization="0"
|
||||||
|
PreprocessorDefinitions=""
|
||||||
|
BasicRuntimeChecks="3"/>
|
||||||
|
</FileConfiguration>
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Release|Win32">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
Optimization="2"
|
||||||
|
PreprocessorDefinitions=""/>
|
||||||
|
</FileConfiguration>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="zlib\infblock.c">
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Debug|Win32">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
Optimization="0"
|
||||||
|
PreprocessorDefinitions=""
|
||||||
|
BasicRuntimeChecks="3"/>
|
||||||
|
</FileConfiguration>
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Release|Win32">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
Optimization="2"
|
||||||
|
PreprocessorDefinitions=""/>
|
||||||
|
</FileConfiguration>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="zlib\infblock.h">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="zlib\infcodes.c">
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Debug|Win32">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
Optimization="0"
|
||||||
|
PreprocessorDefinitions=""
|
||||||
|
BasicRuntimeChecks="3"/>
|
||||||
|
</FileConfiguration>
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Release|Win32">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
Optimization="2"
|
||||||
|
PreprocessorDefinitions=""/>
|
||||||
|
</FileConfiguration>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="zlib\infcodes.h">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="zlib\inffast.c">
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Debug|Win32">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
Optimization="0"
|
||||||
|
PreprocessorDefinitions=""
|
||||||
|
BasicRuntimeChecks="3"/>
|
||||||
|
</FileConfiguration>
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Release|Win32">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
Optimization="2"
|
||||||
|
PreprocessorDefinitions=""/>
|
||||||
|
</FileConfiguration>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="zlib\inffast.h">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="zlib\inffixed.h">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="zlib\inflate.c">
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Debug|Win32">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
Optimization="0"
|
||||||
|
PreprocessorDefinitions=""
|
||||||
|
BasicRuntimeChecks="3"/>
|
||||||
|
</FileConfiguration>
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Release|Win32">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
Optimization="2"
|
||||||
|
PreprocessorDefinitions=""/>
|
||||||
|
</FileConfiguration>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="zlib\inftrees.c">
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Debug|Win32">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
Optimization="0"
|
||||||
|
PreprocessorDefinitions=""
|
||||||
|
BasicRuntimeChecks="3"/>
|
||||||
|
</FileConfiguration>
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Release|Win32">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
Optimization="2"
|
||||||
|
PreprocessorDefinitions=""/>
|
||||||
|
</FileConfiguration>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="zlib\inftrees.h">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="zlib\infutil.c">
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Debug|Win32">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
Optimization="0"
|
||||||
|
PreprocessorDefinitions=""
|
||||||
|
BasicRuntimeChecks="3"/>
|
||||||
|
</FileConfiguration>
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Release|Win32">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
Optimization="2"
|
||||||
|
PreprocessorDefinitions=""/>
|
||||||
|
</FileConfiguration>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="zlib\infutil.h">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="zlib\zconf.h">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="zlib\zlib.h">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="zlib\zutil.c">
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Debug|Win32">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
Optimization="0"
|
||||||
|
PreprocessorDefinitions=""
|
||||||
|
BasicRuntimeChecks="3"/>
|
||||||
|
</FileConfiguration>
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Release|Win32">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
Optimization="2"
|
||||||
|
PreprocessorDefinitions=""/>
|
||||||
|
</FileConfiguration>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="zlib\zutil.h">
|
||||||
|
</File>
|
||||||
|
</Filter>
|
||||||
|
<Filter
|
||||||
|
Name="unalz"
|
||||||
|
Filter="">
|
||||||
|
<File
|
||||||
|
RelativePath="UnAlz.cpp">
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Debug|Win32">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
Optimization="0"
|
||||||
|
PreprocessorDefinitions=""
|
||||||
|
BasicRuntimeChecks="3"/>
|
||||||
|
</FileConfiguration>
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Release|Win32">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
Optimization="2"
|
||||||
|
PreprocessorDefinitions=""/>
|
||||||
|
</FileConfiguration>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="UnAlz.h">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="UnAlzBz2decompress.c">
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Debug|Win32">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
Optimization="0"
|
||||||
|
PreprocessorDefinitions=""
|
||||||
|
BasicRuntimeChecks="3"/>
|
||||||
|
</FileConfiguration>
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Release|Win32">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
Optimization="2"
|
||||||
|
PreprocessorDefinitions=""/>
|
||||||
|
</FileConfiguration>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="UnAlzBzip2.cpp">
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Debug|Win32">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
Optimization="0"
|
||||||
|
PreprocessorDefinitions=""
|
||||||
|
BasicRuntimeChecks="3"/>
|
||||||
|
</FileConfiguration>
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Release|Win32">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
Optimization="2"
|
||||||
|
PreprocessorDefinitions=""/>
|
||||||
|
</FileConfiguration>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="UnAlzbzlib.c">
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Debug|Win32">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
Optimization="0"
|
||||||
|
PreprocessorDefinitions=""
|
||||||
|
BasicRuntimeChecks="3"/>
|
||||||
|
</FileConfiguration>
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Release|Win32">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
Optimization="2"
|
||||||
|
PreprocessorDefinitions=""/>
|
||||||
|
</FileConfiguration>
|
||||||
|
</File>
|
||||||
|
</Filter>
|
||||||
|
</Files>
|
||||||
|
<Globals>
|
||||||
|
</Globals>
|
||||||
|
</VisualStudioProject>
|
48
zlib/adler32.c
Normal file
48
zlib/adler32.c
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
/* adler32.c -- compute the Adler-32 checksum of a data stream
|
||||||
|
* Copyright (C) 1995-2002 Mark Adler
|
||||||
|
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* @(#) $Id$ */
|
||||||
|
|
||||||
|
#include "zlib.h"
|
||||||
|
|
||||||
|
#define BASE 65521L /* largest prime smaller than 65536 */
|
||||||
|
#define NMAX 5552
|
||||||
|
/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
|
||||||
|
|
||||||
|
#define DO1(buf,i) {s1 += buf[i]; s2 += s1;}
|
||||||
|
#define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
|
||||||
|
#define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
|
||||||
|
#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
|
||||||
|
#define DO16(buf) DO8(buf,0); DO8(buf,8);
|
||||||
|
|
||||||
|
/* ========================================================================= */
|
||||||
|
uLong ZEXPORT adler32(adler, buf, len)
|
||||||
|
uLong adler;
|
||||||
|
const Bytef *buf;
|
||||||
|
uInt len;
|
||||||
|
{
|
||||||
|
unsigned long s1 = adler & 0xffff;
|
||||||
|
unsigned long s2 = (adler >> 16) & 0xffff;
|
||||||
|
int k;
|
||||||
|
|
||||||
|
if (buf == Z_NULL) return 1L;
|
||||||
|
|
||||||
|
while (len > 0) {
|
||||||
|
k = len < NMAX ? len : NMAX;
|
||||||
|
len -= k;
|
||||||
|
while (k >= 16) {
|
||||||
|
DO16(buf);
|
||||||
|
buf += 16;
|
||||||
|
k -= 16;
|
||||||
|
}
|
||||||
|
if (k != 0) do {
|
||||||
|
s1 += *buf++;
|
||||||
|
s2 += s1;
|
||||||
|
} while (--k);
|
||||||
|
s1 %= BASE;
|
||||||
|
s2 %= BASE;
|
||||||
|
}
|
||||||
|
return (s2 << 16) | s1;
|
||||||
|
}
|
162
zlib/crc32.c
Normal file
162
zlib/crc32.c
Normal file
|
@ -0,0 +1,162 @@
|
||||||
|
/* crc32.c -- compute the CRC-32 of a data stream
|
||||||
|
* Copyright (C) 1995-2002 Mark Adler
|
||||||
|
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* @(#) $Id$ */
|
||||||
|
|
||||||
|
#include "zlib.h"
|
||||||
|
|
||||||
|
#define local static
|
||||||
|
|
||||||
|
#ifdef DYNAMIC_CRC_TABLE
|
||||||
|
|
||||||
|
local int crc_table_empty = 1;
|
||||||
|
local uLongf crc_table[256];
|
||||||
|
local void make_crc_table OF((void));
|
||||||
|
|
||||||
|
/*
|
||||||
|
Generate a table for a byte-wise 32-bit CRC calculation on the polynomial:
|
||||||
|
x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1.
|
||||||
|
|
||||||
|
Polynomials over GF(2) are represented in binary, one bit per coefficient,
|
||||||
|
with the lowest powers in the most significant bit. Then adding polynomials
|
||||||
|
is just exclusive-or, and multiplying a polynomial by x is a right shift by
|
||||||
|
one. If we call the above polynomial p, and represent a byte as the
|
||||||
|
polynomial q, also with the lowest power in the most significant bit (so the
|
||||||
|
byte 0xb1 is the polynomial x^7+x^3+x+1), then the CRC is (q*x^32) mod p,
|
||||||
|
where a mod b means the remainder after dividing a by b.
|
||||||
|
|
||||||
|
This calculation is done using the shift-register method of multiplying and
|
||||||
|
taking the remainder. The register is initialized to zero, and for each
|
||||||
|
incoming bit, x^32 is added mod p to the register if the bit is a one (where
|
||||||
|
x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by
|
||||||
|
x (which is shifting right by one and adding x^32 mod p if the bit shifted
|
||||||
|
out is a one). We start with the highest power (least significant bit) of
|
||||||
|
q and repeat for all eight bits of q.
|
||||||
|
|
||||||
|
The table is simply the CRC of all possible eight bit values. This is all
|
||||||
|
the information needed to generate CRC's on data a byte at a time for all
|
||||||
|
combinations of CRC register values and incoming bytes.
|
||||||
|
*/
|
||||||
|
local void make_crc_table()
|
||||||
|
{
|
||||||
|
uLong c;
|
||||||
|
int n, k;
|
||||||
|
uLong poly; /* polynomial exclusive-or pattern */
|
||||||
|
/* terms of polynomial defining this crc (except x^32): */
|
||||||
|
static const Byte p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
|
||||||
|
|
||||||
|
/* make exclusive-or pattern from polynomial (0xedb88320L) */
|
||||||
|
poly = 0L;
|
||||||
|
for (n = 0; n < sizeof(p)/sizeof(Byte); n++)
|
||||||
|
poly |= 1L << (31 - p[n]);
|
||||||
|
|
||||||
|
for (n = 0; n < 256; n++)
|
||||||
|
{
|
||||||
|
c = (uLong)n;
|
||||||
|
for (k = 0; k < 8; k++)
|
||||||
|
c = c & 1 ? poly ^ (c >> 1) : c >> 1;
|
||||||
|
crc_table[n] = c;
|
||||||
|
}
|
||||||
|
crc_table_empty = 0;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
/* ========================================================================
|
||||||
|
* Table of CRC-32's of all single-byte values (made by make_crc_table)
|
||||||
|
*/
|
||||||
|
local const uLongf crc_table[256] = {
|
||||||
|
0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L,
|
||||||
|
0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L,
|
||||||
|
0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L,
|
||||||
|
0x90bf1d91L, 0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL,
|
||||||
|
0x1adad47dL, 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L, 0x136c9856L,
|
||||||
|
0x646ba8c0L, 0xfd62f97aL, 0x8a65c9ecL, 0x14015c4fL, 0x63066cd9L,
|
||||||
|
0xfa0f3d63L, 0x8d080df5L, 0x3b6e20c8L, 0x4c69105eL, 0xd56041e4L,
|
||||||
|
0xa2677172L, 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL, 0xa50ab56bL,
|
||||||
|
0x35b5a8faL, 0x42b2986cL, 0xdbbbc9d6L, 0xacbcf940L, 0x32d86ce3L,
|
||||||
|
0x45df5c75L, 0xdcd60dcfL, 0xabd13d59L, 0x26d930acL, 0x51de003aL,
|
||||||
|
0xc8d75180L, 0xbfd06116L, 0x21b4f4b5L, 0x56b3c423L, 0xcfba9599L,
|
||||||
|
0xb8bda50fL, 0x2802b89eL, 0x5f058808L, 0xc60cd9b2L, 0xb10be924L,
|
||||||
|
0x2f6f7c87L, 0x58684c11L, 0xc1611dabL, 0xb6662d3dL, 0x76dc4190L,
|
||||||
|
0x01db7106L, 0x98d220bcL, 0xefd5102aL, 0x71b18589L, 0x06b6b51fL,
|
||||||
|
0x9fbfe4a5L, 0xe8b8d433L, 0x7807c9a2L, 0x0f00f934L, 0x9609a88eL,
|
||||||
|
0xe10e9818L, 0x7f6a0dbbL, 0x086d3d2dL, 0x91646c97L, 0xe6635c01L,
|
||||||
|
0x6b6b51f4L, 0x1c6c6162L, 0x856530d8L, 0xf262004eL, 0x6c0695edL,
|
||||||
|
0x1b01a57bL, 0x8208f4c1L, 0xf50fc457L, 0x65b0d9c6L, 0x12b7e950L,
|
||||||
|
0x8bbeb8eaL, 0xfcb9887cL, 0x62dd1ddfL, 0x15da2d49L, 0x8cd37cf3L,
|
||||||
|
0xfbd44c65L, 0x4db26158L, 0x3ab551ceL, 0xa3bc0074L, 0xd4bb30e2L,
|
||||||
|
0x4adfa541L, 0x3dd895d7L, 0xa4d1c46dL, 0xd3d6f4fbL, 0x4369e96aL,
|
||||||
|
0x346ed9fcL, 0xad678846L, 0xda60b8d0L, 0x44042d73L, 0x33031de5L,
|
||||||
|
0xaa0a4c5fL, 0xdd0d7cc9L, 0x5005713cL, 0x270241aaL, 0xbe0b1010L,
|
||||||
|
0xc90c2086L, 0x5768b525L, 0x206f85b3L, 0xb966d409L, 0xce61e49fL,
|
||||||
|
0x5edef90eL, 0x29d9c998L, 0xb0d09822L, 0xc7d7a8b4L, 0x59b33d17L,
|
||||||
|
0x2eb40d81L, 0xb7bd5c3bL, 0xc0ba6cadL, 0xedb88320L, 0x9abfb3b6L,
|
||||||
|
0x03b6e20cL, 0x74b1d29aL, 0xead54739L, 0x9dd277afL, 0x04db2615L,
|
||||||
|
0x73dc1683L, 0xe3630b12L, 0x94643b84L, 0x0d6d6a3eL, 0x7a6a5aa8L,
|
||||||
|
0xe40ecf0bL, 0x9309ff9dL, 0x0a00ae27L, 0x7d079eb1L, 0xf00f9344L,
|
||||||
|
0x8708a3d2L, 0x1e01f268L, 0x6906c2feL, 0xf762575dL, 0x806567cbL,
|
||||||
|
0x196c3671L, 0x6e6b06e7L, 0xfed41b76L, 0x89d32be0L, 0x10da7a5aL,
|
||||||
|
0x67dd4accL, 0xf9b9df6fL, 0x8ebeeff9L, 0x17b7be43L, 0x60b08ed5L,
|
||||||
|
0xd6d6a3e8L, 0xa1d1937eL, 0x38d8c2c4L, 0x4fdff252L, 0xd1bb67f1L,
|
||||||
|
0xa6bc5767L, 0x3fb506ddL, 0x48b2364bL, 0xd80d2bdaL, 0xaf0a1b4cL,
|
||||||
|
0x36034af6L, 0x41047a60L, 0xdf60efc3L, 0xa867df55L, 0x316e8eefL,
|
||||||
|
0x4669be79L, 0xcb61b38cL, 0xbc66831aL, 0x256fd2a0L, 0x5268e236L,
|
||||||
|
0xcc0c7795L, 0xbb0b4703L, 0x220216b9L, 0x5505262fL, 0xc5ba3bbeL,
|
||||||
|
0xb2bd0b28L, 0x2bb45a92L, 0x5cb36a04L, 0xc2d7ffa7L, 0xb5d0cf31L,
|
||||||
|
0x2cd99e8bL, 0x5bdeae1dL, 0x9b64c2b0L, 0xec63f226L, 0x756aa39cL,
|
||||||
|
0x026d930aL, 0x9c0906a9L, 0xeb0e363fL, 0x72076785L, 0x05005713L,
|
||||||
|
0x95bf4a82L, 0xe2b87a14L, 0x7bb12baeL, 0x0cb61b38L, 0x92d28e9bL,
|
||||||
|
0xe5d5be0dL, 0x7cdcefb7L, 0x0bdbdf21L, 0x86d3d2d4L, 0xf1d4e242L,
|
||||||
|
0x68ddb3f8L, 0x1fda836eL, 0x81be16cdL, 0xf6b9265bL, 0x6fb077e1L,
|
||||||
|
0x18b74777L, 0x88085ae6L, 0xff0f6a70L, 0x66063bcaL, 0x11010b5cL,
|
||||||
|
0x8f659effL, 0xf862ae69L, 0x616bffd3L, 0x166ccf45L, 0xa00ae278L,
|
||||||
|
0xd70dd2eeL, 0x4e048354L, 0x3903b3c2L, 0xa7672661L, 0xd06016f7L,
|
||||||
|
0x4969474dL, 0x3e6e77dbL, 0xaed16a4aL, 0xd9d65adcL, 0x40df0b66L,
|
||||||
|
0x37d83bf0L, 0xa9bcae53L, 0xdebb9ec5L, 0x47b2cf7fL, 0x30b5ffe9L,
|
||||||
|
0xbdbdf21cL, 0xcabac28aL, 0x53b39330L, 0x24b4a3a6L, 0xbad03605L,
|
||||||
|
0xcdd70693L, 0x54de5729L, 0x23d967bfL, 0xb3667a2eL, 0xc4614ab8L,
|
||||||
|
0x5d681b02L, 0x2a6f2b94L, 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL,
|
||||||
|
0x2d02ef8dL
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* =========================================================================
|
||||||
|
* This function can be used by asm versions of crc32()
|
||||||
|
*/
|
||||||
|
const uLongf * ZEXPORT get_crc_table()
|
||||||
|
{
|
||||||
|
#ifdef DYNAMIC_CRC_TABLE
|
||||||
|
if (crc_table_empty) make_crc_table();
|
||||||
|
#endif
|
||||||
|
return (const uLongf *)crc_table;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ========================================================================= */
|
||||||
|
#define DO1(buf) crc = crc_table[((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8);
|
||||||
|
#define DO2(buf) DO1(buf); DO1(buf);
|
||||||
|
#define DO4(buf) DO2(buf); DO2(buf);
|
||||||
|
#define DO8(buf) DO4(buf); DO4(buf);
|
||||||
|
|
||||||
|
/* ========================================================================= */
|
||||||
|
uLong ZEXPORT crc32(crc, buf, len)
|
||||||
|
uLong crc;
|
||||||
|
const Bytef *buf;
|
||||||
|
uInt len;
|
||||||
|
{
|
||||||
|
if (buf == Z_NULL) return 0L;
|
||||||
|
#ifdef DYNAMIC_CRC_TABLE
|
||||||
|
if (crc_table_empty)
|
||||||
|
make_crc_table();
|
||||||
|
#endif
|
||||||
|
crc = crc ^ 0xffffffffL;
|
||||||
|
while (len >= 8)
|
||||||
|
{
|
||||||
|
DO8(buf);
|
||||||
|
len -= 8;
|
||||||
|
}
|
||||||
|
if (len) do {
|
||||||
|
DO1(buf);
|
||||||
|
} while (--len);
|
||||||
|
return crc ^ 0xffffffffL;
|
||||||
|
}
|
403
zlib/infblock.c
Normal file
403
zlib/infblock.c
Normal file
|
@ -0,0 +1,403 @@
|
||||||
|
/* infblock.c -- interpret and process block types to last block
|
||||||
|
* Copyright (C) 1995-2002 Mark Adler
|
||||||
|
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "zutil.h"
|
||||||
|
#include "infblock.h"
|
||||||
|
#include "inftrees.h"
|
||||||
|
#include "infcodes.h"
|
||||||
|
#include "infutil.h"
|
||||||
|
|
||||||
|
struct inflate_codes_state {int dummy;}; /* for buggy compilers */
|
||||||
|
|
||||||
|
/* simplify the use of the inflate_huft type with some defines */
|
||||||
|
#define exop word.what.Exop
|
||||||
|
#define bits word.what.Bits
|
||||||
|
|
||||||
|
/* Table for deflate from PKZIP's appnote.txt. */
|
||||||
|
local const uInt border[] = { /* Order of the bit length code lengths */
|
||||||
|
16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
|
||||||
|
|
||||||
|
/*
|
||||||
|
Notes beyond the 1.93a appnote.txt:
|
||||||
|
|
||||||
|
1. Distance pointers never point before the beginning of the output
|
||||||
|
stream.
|
||||||
|
2. Distance pointers can point back across blocks, up to 32k away.
|
||||||
|
3. There is an implied maximum of 7 bits for the bit length table and
|
||||||
|
15 bits for the actual data.
|
||||||
|
4. If only one code exists, then it is encoded using one bit. (Zero
|
||||||
|
would be more efficient, but perhaps a little confusing.) If two
|
||||||
|
codes exist, they are coded using one bit each (0 and 1).
|
||||||
|
5. There is no way of sending zero distance codes--a dummy must be
|
||||||
|
sent if there are none. (History: a pre 2.0 version of PKZIP would
|
||||||
|
store blocks with no distance codes, but this was discovered to be
|
||||||
|
too harsh a criterion.) Valid only for 1.93a. 2.04c does allow
|
||||||
|
zero distance codes, which is sent as one code of zero bits in
|
||||||
|
length.
|
||||||
|
6. There are up to 286 literal/length codes. Code 256 represents the
|
||||||
|
end-of-block. Note however that the static length tree defines
|
||||||
|
288 codes just to fill out the Huffman codes. Codes 286 and 287
|
||||||
|
cannot be used though, since there is no length base or extra bits
|
||||||
|
defined for them. Similarily, there are up to 30 distance codes.
|
||||||
|
However, static trees define 32 codes (all 5 bits) to fill out the
|
||||||
|
Huffman codes, but the last two had better not show up in the data.
|
||||||
|
7. Unzip can check dynamic Huffman blocks for complete code sets.
|
||||||
|
The exception is that a single code would not be complete (see #4).
|
||||||
|
8. The five bits following the block type is really the number of
|
||||||
|
literal codes sent minus 257.
|
||||||
|
9. Length codes 8,16,16 are interpreted as 13 length codes of 8 bits
|
||||||
|
(1+6+6). Therefore, to output three times the length, you output
|
||||||
|
three codes (1+1+1), whereas to output four times the same length,
|
||||||
|
you only need two codes (1+3). Hmm.
|
||||||
|
10. In the tree reconstruction algorithm, Code = Code + Increment
|
||||||
|
only if BitLength(i) is not zero. (Pretty obvious.)
|
||||||
|
11. Correction: 4 Bits: # of Bit Length codes - 4 (4 - 19)
|
||||||
|
12. Note: length code 284 can represent 227-258, but length code 285
|
||||||
|
really is 258. The last length deserves its own, short code
|
||||||
|
since it gets used a lot in very redundant files. The length
|
||||||
|
258 is special since 258 - 3 (the min match length) is 255.
|
||||||
|
13. The literal/length and distance code bit lengths are read as a
|
||||||
|
single stream of lengths. It is possible (and advantageous) for
|
||||||
|
a repeat code (16, 17, or 18) to go across the boundary between
|
||||||
|
the two sets of lengths.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
void inflate_blocks_reset(s, z, c)
|
||||||
|
inflate_blocks_statef *s;
|
||||||
|
z_streamp z;
|
||||||
|
uLongf *c;
|
||||||
|
{
|
||||||
|
if (c != Z_NULL)
|
||||||
|
*c = s->check;
|
||||||
|
if (s->mode == BTREE || s->mode == DTREE)
|
||||||
|
ZFREE(z, s->sub.trees.blens);
|
||||||
|
if (s->mode == CODES)
|
||||||
|
inflate_codes_free(s->sub.decode.codes, z);
|
||||||
|
s->mode = TYPE;
|
||||||
|
s->bitk = 0;
|
||||||
|
s->bitb = 0;
|
||||||
|
s->read = s->write = s->window;
|
||||||
|
if (s->checkfn != Z_NULL)
|
||||||
|
z->adler = s->check = (*s->checkfn)(0L, (const Bytef *)Z_NULL, 0);
|
||||||
|
Tracev((stderr, "inflate: blocks reset\n"));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inflate_blocks_statef *inflate_blocks_new(z, c, w)
|
||||||
|
z_streamp z;
|
||||||
|
check_func c;
|
||||||
|
uInt w;
|
||||||
|
{
|
||||||
|
inflate_blocks_statef *s;
|
||||||
|
|
||||||
|
if ((s = (inflate_blocks_statef *)ZALLOC
|
||||||
|
(z,1,sizeof(struct inflate_blocks_state))) == Z_NULL)
|
||||||
|
return s;
|
||||||
|
if ((s->hufts =
|
||||||
|
(inflate_huft *)ZALLOC(z, sizeof(inflate_huft), MANY)) == Z_NULL)
|
||||||
|
{
|
||||||
|
ZFREE(z, s);
|
||||||
|
return Z_NULL;
|
||||||
|
}
|
||||||
|
if ((s->window = (Bytef *)ZALLOC(z, 1, w)) == Z_NULL)
|
||||||
|
{
|
||||||
|
ZFREE(z, s->hufts);
|
||||||
|
ZFREE(z, s);
|
||||||
|
return Z_NULL;
|
||||||
|
}
|
||||||
|
s->end = s->window + w;
|
||||||
|
s->checkfn = c;
|
||||||
|
s->mode = TYPE;
|
||||||
|
Tracev((stderr, "inflate: blocks allocated\n"));
|
||||||
|
inflate_blocks_reset(s, z, Z_NULL);
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int inflate_blocks(s, z, r)
|
||||||
|
inflate_blocks_statef *s;
|
||||||
|
z_streamp z;
|
||||||
|
int r;
|
||||||
|
{
|
||||||
|
uInt t; /* temporary storage */
|
||||||
|
uLong b; /* bit buffer */
|
||||||
|
uInt k; /* bits in bit buffer */
|
||||||
|
Bytef *p; /* input data pointer */
|
||||||
|
uInt n; /* bytes available there */
|
||||||
|
Bytef *q; /* output window write pointer */
|
||||||
|
uInt m; /* bytes to end of window or read pointer */
|
||||||
|
|
||||||
|
/* copy input/output information to locals (UPDATE macro restores) */
|
||||||
|
LOAD
|
||||||
|
|
||||||
|
/* process input based on current state */
|
||||||
|
while (1) switch (s->mode)
|
||||||
|
{
|
||||||
|
case TYPE:
|
||||||
|
NEEDBITS(3)
|
||||||
|
t = (uInt)b & 7;
|
||||||
|
s->last = t & 1;
|
||||||
|
switch (t >> 1)
|
||||||
|
{
|
||||||
|
case 0: /* stored */
|
||||||
|
Tracev((stderr, "inflate: stored block%s\n",
|
||||||
|
s->last ? " (last)" : ""));
|
||||||
|
DUMPBITS(3)
|
||||||
|
t = k & 7; /* go to byte boundary */
|
||||||
|
DUMPBITS(t)
|
||||||
|
s->mode = LENS; /* get length of stored block */
|
||||||
|
break;
|
||||||
|
case 1: /* fixed */
|
||||||
|
Tracev((stderr, "inflate: fixed codes block%s\n",
|
||||||
|
s->last ? " (last)" : ""));
|
||||||
|
{
|
||||||
|
uInt bl, bd;
|
||||||
|
inflate_huft *tl, *td;
|
||||||
|
|
||||||
|
inflate_trees_fixed(&bl, &bd, &tl, &td, z);
|
||||||
|
s->sub.decode.codes = inflate_codes_new(bl, bd, tl, td, z);
|
||||||
|
if (s->sub.decode.codes == Z_NULL)
|
||||||
|
{
|
||||||
|
r = Z_MEM_ERROR;
|
||||||
|
LEAVE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
DUMPBITS(3)
|
||||||
|
s->mode = CODES;
|
||||||
|
break;
|
||||||
|
case 2: /* dynamic */
|
||||||
|
Tracev((stderr, "inflate: dynamic codes block%s\n",
|
||||||
|
s->last ? " (last)" : ""));
|
||||||
|
DUMPBITS(3)
|
||||||
|
s->mode = TABLE;
|
||||||
|
break;
|
||||||
|
case 3: /* illegal */
|
||||||
|
DUMPBITS(3)
|
||||||
|
s->mode = BAD;
|
||||||
|
z->msg = (char*)"invalid block type";
|
||||||
|
r = Z_DATA_ERROR;
|
||||||
|
LEAVE
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case LENS:
|
||||||
|
NEEDBITS(32)
|
||||||
|
if ((((~b) >> 16) & 0xffff) != (b & 0xffff))
|
||||||
|
{
|
||||||
|
s->mode = BAD;
|
||||||
|
z->msg = (char*)"invalid stored block lengths";
|
||||||
|
r = Z_DATA_ERROR;
|
||||||
|
LEAVE
|
||||||
|
}
|
||||||
|
s->sub.left = (uInt)b & 0xffff;
|
||||||
|
b = k = 0; /* dump bits */
|
||||||
|
Tracev((stderr, "inflate: stored length %u\n", s->sub.left));
|
||||||
|
s->mode = s->sub.left ? STORED : (s->last ? DRY : TYPE);
|
||||||
|
break;
|
||||||
|
case STORED:
|
||||||
|
if (n == 0)
|
||||||
|
LEAVE
|
||||||
|
NEEDOUT
|
||||||
|
t = s->sub.left;
|
||||||
|
if (t > n) t = n;
|
||||||
|
if (t > m) t = m;
|
||||||
|
zmemcpy(q, p, t);
|
||||||
|
p += t; n -= t;
|
||||||
|
q += t; m -= t;
|
||||||
|
if ((s->sub.left -= t) != 0)
|
||||||
|
break;
|
||||||
|
Tracev((stderr, "inflate: stored end, %lu total out\n",
|
||||||
|
z->total_out + (q >= s->read ? q - s->read :
|
||||||
|
(s->end - s->read) + (q - s->window))));
|
||||||
|
s->mode = s->last ? DRY : TYPE;
|
||||||
|
break;
|
||||||
|
case TABLE:
|
||||||
|
NEEDBITS(14)
|
||||||
|
s->sub.trees.table = t = (uInt)b & 0x3fff;
|
||||||
|
#ifndef PKZIP_BUG_WORKAROUND
|
||||||
|
if ((t & 0x1f) > 29 || ((t >> 5) & 0x1f) > 29)
|
||||||
|
{
|
||||||
|
s->mode = BAD;
|
||||||
|
z->msg = (char*)"too many length or distance symbols";
|
||||||
|
r = Z_DATA_ERROR;
|
||||||
|
LEAVE
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
t = 258 + (t & 0x1f) + ((t >> 5) & 0x1f);
|
||||||
|
if ((s->sub.trees.blens = (uIntf*)ZALLOC(z, t, sizeof(uInt))) == Z_NULL)
|
||||||
|
{
|
||||||
|
r = Z_MEM_ERROR;
|
||||||
|
LEAVE
|
||||||
|
}
|
||||||
|
DUMPBITS(14)
|
||||||
|
s->sub.trees.index = 0;
|
||||||
|
Tracev((stderr, "inflate: table sizes ok\n"));
|
||||||
|
s->mode = BTREE;
|
||||||
|
case BTREE:
|
||||||
|
while (s->sub.trees.index < 4 + (s->sub.trees.table >> 10))
|
||||||
|
{
|
||||||
|
NEEDBITS(3)
|
||||||
|
s->sub.trees.blens[border[s->sub.trees.index++]] = (uInt)b & 7;
|
||||||
|
DUMPBITS(3)
|
||||||
|
}
|
||||||
|
while (s->sub.trees.index < 19)
|
||||||
|
s->sub.trees.blens[border[s->sub.trees.index++]] = 0;
|
||||||
|
s->sub.trees.bb = 7;
|
||||||
|
t = inflate_trees_bits(s->sub.trees.blens, &s->sub.trees.bb,
|
||||||
|
&s->sub.trees.tb, s->hufts, z);
|
||||||
|
if (t != Z_OK)
|
||||||
|
{
|
||||||
|
r = t;
|
||||||
|
if (r == Z_DATA_ERROR)
|
||||||
|
{
|
||||||
|
ZFREE(z, s->sub.trees.blens);
|
||||||
|
s->mode = BAD;
|
||||||
|
}
|
||||||
|
LEAVE
|
||||||
|
}
|
||||||
|
s->sub.trees.index = 0;
|
||||||
|
Tracev((stderr, "inflate: bits tree ok\n"));
|
||||||
|
s->mode = DTREE;
|
||||||
|
case DTREE:
|
||||||
|
while (t = s->sub.trees.table,
|
||||||
|
s->sub.trees.index < 258 + (t & 0x1f) + ((t >> 5) & 0x1f))
|
||||||
|
{
|
||||||
|
inflate_huft *h;
|
||||||
|
uInt i, j, c;
|
||||||
|
|
||||||
|
t = s->sub.trees.bb;
|
||||||
|
NEEDBITS(t)
|
||||||
|
h = s->sub.trees.tb + ((uInt)b & inflate_mask[t]);
|
||||||
|
t = h->bits;
|
||||||
|
c = h->base;
|
||||||
|
if (c < 16)
|
||||||
|
{
|
||||||
|
DUMPBITS(t)
|
||||||
|
s->sub.trees.blens[s->sub.trees.index++] = c;
|
||||||
|
}
|
||||||
|
else /* c == 16..18 */
|
||||||
|
{
|
||||||
|
i = c == 18 ? 7 : c - 14;
|
||||||
|
j = c == 18 ? 11 : 3;
|
||||||
|
NEEDBITS(t + i)
|
||||||
|
DUMPBITS(t)
|
||||||
|
j += (uInt)b & inflate_mask[i];
|
||||||
|
DUMPBITS(i)
|
||||||
|
i = s->sub.trees.index;
|
||||||
|
t = s->sub.trees.table;
|
||||||
|
if (i + j > 258 + (t & 0x1f) + ((t >> 5) & 0x1f) ||
|
||||||
|
(c == 16 && i < 1))
|
||||||
|
{
|
||||||
|
ZFREE(z, s->sub.trees.blens);
|
||||||
|
s->mode = BAD;
|
||||||
|
z->msg = (char*)"invalid bit length repeat";
|
||||||
|
r = Z_DATA_ERROR;
|
||||||
|
LEAVE
|
||||||
|
}
|
||||||
|
c = c == 16 ? s->sub.trees.blens[i - 1] : 0;
|
||||||
|
do {
|
||||||
|
s->sub.trees.blens[i++] = c;
|
||||||
|
} while (--j);
|
||||||
|
s->sub.trees.index = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
s->sub.trees.tb = Z_NULL;
|
||||||
|
{
|
||||||
|
uInt bl, bd;
|
||||||
|
inflate_huft *tl, *td;
|
||||||
|
inflate_codes_statef *c;
|
||||||
|
|
||||||
|
bl = 9; /* must be <= 9 for lookahead assumptions */
|
||||||
|
bd = 6; /* must be <= 9 for lookahead assumptions */
|
||||||
|
t = s->sub.trees.table;
|
||||||
|
t = inflate_trees_dynamic(257 + (t & 0x1f), 1 + ((t >> 5) & 0x1f),
|
||||||
|
s->sub.trees.blens, &bl, &bd, &tl, &td,
|
||||||
|
s->hufts, z);
|
||||||
|
if (t != Z_OK)
|
||||||
|
{
|
||||||
|
if (t == (uInt)Z_DATA_ERROR)
|
||||||
|
{
|
||||||
|
ZFREE(z, s->sub.trees.blens);
|
||||||
|
s->mode = BAD;
|
||||||
|
}
|
||||||
|
r = t;
|
||||||
|
LEAVE
|
||||||
|
}
|
||||||
|
Tracev((stderr, "inflate: trees ok\n"));
|
||||||
|
if ((c = inflate_codes_new(bl, bd, tl, td, z)) == Z_NULL)
|
||||||
|
{
|
||||||
|
r = Z_MEM_ERROR;
|
||||||
|
LEAVE
|
||||||
|
}
|
||||||
|
s->sub.decode.codes = c;
|
||||||
|
}
|
||||||
|
ZFREE(z, s->sub.trees.blens);
|
||||||
|
s->mode = CODES;
|
||||||
|
case CODES:
|
||||||
|
UPDATE
|
||||||
|
if ((r = inflate_codes(s, z, r)) != Z_STREAM_END)
|
||||||
|
return inflate_flush(s, z, r);
|
||||||
|
r = Z_OK;
|
||||||
|
inflate_codes_free(s->sub.decode.codes, z);
|
||||||
|
LOAD
|
||||||
|
Tracev((stderr, "inflate: codes end, %lu total out\n",
|
||||||
|
z->total_out + (q >= s->read ? q - s->read :
|
||||||
|
(s->end - s->read) + (q - s->window))));
|
||||||
|
if (!s->last)
|
||||||
|
{
|
||||||
|
s->mode = TYPE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
s->mode = DRY;
|
||||||
|
case DRY:
|
||||||
|
FLUSH
|
||||||
|
if (s->read != s->write)
|
||||||
|
LEAVE
|
||||||
|
s->mode = DONE;
|
||||||
|
case DONE:
|
||||||
|
r = Z_STREAM_END;
|
||||||
|
LEAVE
|
||||||
|
case BAD:
|
||||||
|
r = Z_DATA_ERROR;
|
||||||
|
LEAVE
|
||||||
|
default:
|
||||||
|
r = Z_STREAM_ERROR;
|
||||||
|
LEAVE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int inflate_blocks_free(s, z)
|
||||||
|
inflate_blocks_statef *s;
|
||||||
|
z_streamp z;
|
||||||
|
{
|
||||||
|
inflate_blocks_reset(s, z, Z_NULL);
|
||||||
|
ZFREE(z, s->window);
|
||||||
|
ZFREE(z, s->hufts);
|
||||||
|
ZFREE(z, s);
|
||||||
|
Tracev((stderr, "inflate: blocks freed\n"));
|
||||||
|
return Z_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void inflate_set_dictionary(s, d, n)
|
||||||
|
inflate_blocks_statef *s;
|
||||||
|
const Bytef *d;
|
||||||
|
uInt n;
|
||||||
|
{
|
||||||
|
zmemcpy(s->window, d, n);
|
||||||
|
s->read = s->write = s->window + n;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Returns true if inflate is currently at the end of a block generated
|
||||||
|
* by Z_SYNC_FLUSH or Z_FULL_FLUSH.
|
||||||
|
* IN assertion: s != Z_NULL
|
||||||
|
*/
|
||||||
|
int inflate_blocks_sync_point(s)
|
||||||
|
inflate_blocks_statef *s;
|
||||||
|
{
|
||||||
|
return s->mode == LENS;
|
||||||
|
}
|
39
zlib/infblock.h
Normal file
39
zlib/infblock.h
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
/* infblock.h -- header to use infblock.c
|
||||||
|
* Copyright (C) 1995-2002 Mark Adler
|
||||||
|
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* WARNING: this file should *not* be used by applications. It is
|
||||||
|
part of the implementation of the compression library and is
|
||||||
|
subject to change. Applications should only use zlib.h.
|
||||||
|
*/
|
||||||
|
|
||||||
|
struct inflate_blocks_state;
|
||||||
|
typedef struct inflate_blocks_state FAR inflate_blocks_statef;
|
||||||
|
|
||||||
|
extern inflate_blocks_statef * inflate_blocks_new OF((
|
||||||
|
z_streamp z,
|
||||||
|
check_func c, /* check function */
|
||||||
|
uInt w)); /* window size */
|
||||||
|
|
||||||
|
extern int inflate_blocks OF((
|
||||||
|
inflate_blocks_statef *,
|
||||||
|
z_streamp ,
|
||||||
|
int)); /* initial return code */
|
||||||
|
|
||||||
|
extern void inflate_blocks_reset OF((
|
||||||
|
inflate_blocks_statef *,
|
||||||
|
z_streamp ,
|
||||||
|
uLongf *)); /* check value on output */
|
||||||
|
|
||||||
|
extern int inflate_blocks_free OF((
|
||||||
|
inflate_blocks_statef *,
|
||||||
|
z_streamp));
|
||||||
|
|
||||||
|
extern void inflate_set_dictionary OF((
|
||||||
|
inflate_blocks_statef *s,
|
||||||
|
const Bytef *d, /* dictionary */
|
||||||
|
uInt n)); /* dictionary length */
|
||||||
|
|
||||||
|
extern int inflate_blocks_sync_point OF((
|
||||||
|
inflate_blocks_statef *s));
|
251
zlib/infcodes.c
Normal file
251
zlib/infcodes.c
Normal file
|
@ -0,0 +1,251 @@
|
||||||
|
/* infcodes.c -- process literals and length/distance pairs
|
||||||
|
* Copyright (C) 1995-2002 Mark Adler
|
||||||
|
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "zutil.h"
|
||||||
|
#include "inftrees.h"
|
||||||
|
#include "infblock.h"
|
||||||
|
#include "infcodes.h"
|
||||||
|
#include "infutil.h"
|
||||||
|
#include "inffast.h"
|
||||||
|
|
||||||
|
/* simplify the use of the inflate_huft type with some defines */
|
||||||
|
#define exop word.what.Exop
|
||||||
|
#define bits word.what.Bits
|
||||||
|
|
||||||
|
typedef enum { /* waiting for "i:"=input, "o:"=output, "x:"=nothing */
|
||||||
|
START, /* x: set up for LEN */
|
||||||
|
LEN, /* i: get length/literal/eob next */
|
||||||
|
LENEXT, /* i: getting length extra (have base) */
|
||||||
|
DIST, /* i: get distance next */
|
||||||
|
DISTEXT, /* i: getting distance extra */
|
||||||
|
COPY, /* o: copying bytes in window, waiting for space */
|
||||||
|
LIT, /* o: got literal, waiting for output space */
|
||||||
|
WASH, /* o: got eob, possibly still output waiting */
|
||||||
|
END, /* x: got eob and all data flushed */
|
||||||
|
BADCODE} /* x: got error */
|
||||||
|
inflate_codes_mode;
|
||||||
|
|
||||||
|
/* inflate codes private state */
|
||||||
|
struct inflate_codes_state {
|
||||||
|
|
||||||
|
/* mode */
|
||||||
|
inflate_codes_mode mode; /* current inflate_codes mode */
|
||||||
|
|
||||||
|
/* mode dependent information */
|
||||||
|
uInt len;
|
||||||
|
union {
|
||||||
|
struct {
|
||||||
|
inflate_huft *tree; /* pointer into tree */
|
||||||
|
uInt need; /* bits needed */
|
||||||
|
} code; /* if LEN or DIST, where in tree */
|
||||||
|
uInt lit; /* if LIT, literal */
|
||||||
|
struct {
|
||||||
|
uInt get; /* bits to get for extra */
|
||||||
|
uInt dist; /* distance back to copy from */
|
||||||
|
} copy; /* if EXT or COPY, where and how much */
|
||||||
|
} sub; /* submode */
|
||||||
|
|
||||||
|
/* mode independent information */
|
||||||
|
Byte lbits; /* ltree bits decoded per branch */
|
||||||
|
Byte dbits; /* dtree bits decoder per branch */
|
||||||
|
inflate_huft *ltree; /* literal/length/eob tree */
|
||||||
|
inflate_huft *dtree; /* distance tree */
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
inflate_codes_statef *inflate_codes_new(bl, bd, tl, td, z)
|
||||||
|
uInt bl, bd;
|
||||||
|
inflate_huft *tl;
|
||||||
|
inflate_huft *td; /* need separate declaration for Borland C++ */
|
||||||
|
z_streamp z;
|
||||||
|
{
|
||||||
|
inflate_codes_statef *c;
|
||||||
|
|
||||||
|
if ((c = (inflate_codes_statef *)
|
||||||
|
ZALLOC(z,1,sizeof(struct inflate_codes_state))) != Z_NULL)
|
||||||
|
{
|
||||||
|
c->mode = START;
|
||||||
|
c->lbits = (Byte)bl;
|
||||||
|
c->dbits = (Byte)bd;
|
||||||
|
c->ltree = tl;
|
||||||
|
c->dtree = td;
|
||||||
|
Tracev((stderr, "inflate: codes new\n"));
|
||||||
|
}
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int inflate_codes(s, z, r)
|
||||||
|
inflate_blocks_statef *s;
|
||||||
|
z_streamp z;
|
||||||
|
int r;
|
||||||
|
{
|
||||||
|
uInt j; /* temporary storage */
|
||||||
|
inflate_huft *t; /* temporary pointer */
|
||||||
|
uInt e; /* extra bits or operation */
|
||||||
|
uLong b; /* bit buffer */
|
||||||
|
uInt k; /* bits in bit buffer */
|
||||||
|
Bytef *p; /* input data pointer */
|
||||||
|
uInt n; /* bytes available there */
|
||||||
|
Bytef *q; /* output window write pointer */
|
||||||
|
uInt m; /* bytes to end of window or read pointer */
|
||||||
|
Bytef *f; /* pointer to copy strings from */
|
||||||
|
inflate_codes_statef *c = s->sub.decode.codes; /* codes state */
|
||||||
|
|
||||||
|
/* copy input/output information to locals (UPDATE macro restores) */
|
||||||
|
LOAD
|
||||||
|
|
||||||
|
/* process input and output based on current state */
|
||||||
|
while (1) switch (c->mode)
|
||||||
|
{ /* waiting for "i:"=input, "o:"=output, "x:"=nothing */
|
||||||
|
case START: /* x: set up for LEN */
|
||||||
|
#ifndef SLOW
|
||||||
|
if (m >= 258 && n >= 10)
|
||||||
|
{
|
||||||
|
UPDATE
|
||||||
|
r = inflate_fast(c->lbits, c->dbits, c->ltree, c->dtree, s, z);
|
||||||
|
LOAD
|
||||||
|
if (r != Z_OK)
|
||||||
|
{
|
||||||
|
c->mode = r == Z_STREAM_END ? WASH : BADCODE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif /* !SLOW */
|
||||||
|
c->sub.code.need = c->lbits;
|
||||||
|
c->sub.code.tree = c->ltree;
|
||||||
|
c->mode = LEN;
|
||||||
|
case LEN: /* i: get length/literal/eob next */
|
||||||
|
j = c->sub.code.need;
|
||||||
|
NEEDBITS(j)
|
||||||
|
t = c->sub.code.tree + ((uInt)b & inflate_mask[j]);
|
||||||
|
DUMPBITS(t->bits)
|
||||||
|
e = (uInt)(t->exop);
|
||||||
|
if (e == 0) /* literal */
|
||||||
|
{
|
||||||
|
c->sub.lit = t->base;
|
||||||
|
Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ?
|
||||||
|
"inflate: literal '%c'\n" :
|
||||||
|
"inflate: literal 0x%02x\n", t->base));
|
||||||
|
c->mode = LIT;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (e & 16) /* length */
|
||||||
|
{
|
||||||
|
c->sub.copy.get = e & 15;
|
||||||
|
c->len = t->base;
|
||||||
|
c->mode = LENEXT;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if ((e & 64) == 0) /* next table */
|
||||||
|
{
|
||||||
|
c->sub.code.need = e;
|
||||||
|
c->sub.code.tree = t + t->base;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (e & 32) /* end of block */
|
||||||
|
{
|
||||||
|
Tracevv((stderr, "inflate: end of block\n"));
|
||||||
|
c->mode = WASH;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
c->mode = BADCODE; /* invalid code */
|
||||||
|
z->msg = (char*)"invalid literal/length code";
|
||||||
|
r = Z_DATA_ERROR;
|
||||||
|
LEAVE
|
||||||
|
case LENEXT: /* i: getting length extra (have base) */
|
||||||
|
j = c->sub.copy.get;
|
||||||
|
NEEDBITS(j)
|
||||||
|
c->len += (uInt)b & inflate_mask[j];
|
||||||
|
DUMPBITS(j)
|
||||||
|
c->sub.code.need = c->dbits;
|
||||||
|
c->sub.code.tree = c->dtree;
|
||||||
|
Tracevv((stderr, "inflate: length %u\n", c->len));
|
||||||
|
c->mode = DIST;
|
||||||
|
case DIST: /* i: get distance next */
|
||||||
|
j = c->sub.code.need;
|
||||||
|
NEEDBITS(j)
|
||||||
|
t = c->sub.code.tree + ((uInt)b & inflate_mask[j]);
|
||||||
|
DUMPBITS(t->bits)
|
||||||
|
e = (uInt)(t->exop);
|
||||||
|
if (e & 16) /* distance */
|
||||||
|
{
|
||||||
|
c->sub.copy.get = e & 15;
|
||||||
|
c->sub.copy.dist = t->base;
|
||||||
|
c->mode = DISTEXT;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if ((e & 64) == 0) /* next table */
|
||||||
|
{
|
||||||
|
c->sub.code.need = e;
|
||||||
|
c->sub.code.tree = t + t->base;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
c->mode = BADCODE; /* invalid code */
|
||||||
|
z->msg = (char*)"invalid distance code";
|
||||||
|
r = Z_DATA_ERROR;
|
||||||
|
LEAVE
|
||||||
|
case DISTEXT: /* i: getting distance extra */
|
||||||
|
j = c->sub.copy.get;
|
||||||
|
NEEDBITS(j)
|
||||||
|
c->sub.copy.dist += (uInt)b & inflate_mask[j];
|
||||||
|
DUMPBITS(j)
|
||||||
|
Tracevv((stderr, "inflate: distance %u\n", c->sub.copy.dist));
|
||||||
|
c->mode = COPY;
|
||||||
|
case COPY: /* o: copying bytes in window, waiting for space */
|
||||||
|
f = q - c->sub.copy.dist;
|
||||||
|
while (f < s->window) /* modulo window size-"while" instead */
|
||||||
|
f += s->end - s->window; /* of "if" handles invalid distances */
|
||||||
|
while (c->len)
|
||||||
|
{
|
||||||
|
NEEDOUT
|
||||||
|
OUTBYTE(*f++)
|
||||||
|
if (f == s->end)
|
||||||
|
f = s->window;
|
||||||
|
c->len--;
|
||||||
|
}
|
||||||
|
c->mode = START;
|
||||||
|
break;
|
||||||
|
case LIT: /* o: got literal, waiting for output space */
|
||||||
|
NEEDOUT
|
||||||
|
OUTBYTE(c->sub.lit)
|
||||||
|
c->mode = START;
|
||||||
|
break;
|
||||||
|
case WASH: /* o: got eob, possibly more output */
|
||||||
|
if (k > 7) /* return unused byte, if any */
|
||||||
|
{
|
||||||
|
Assert(k < 16, "inflate_codes grabbed too many bytes")
|
||||||
|
k -= 8;
|
||||||
|
n++;
|
||||||
|
p--; /* can always return one */
|
||||||
|
}
|
||||||
|
FLUSH
|
||||||
|
if (s->read != s->write)
|
||||||
|
LEAVE
|
||||||
|
c->mode = END;
|
||||||
|
case END:
|
||||||
|
r = Z_STREAM_END;
|
||||||
|
LEAVE
|
||||||
|
case BADCODE: /* x: got error */
|
||||||
|
r = Z_DATA_ERROR;
|
||||||
|
LEAVE
|
||||||
|
default:
|
||||||
|
r = Z_STREAM_ERROR;
|
||||||
|
LEAVE
|
||||||
|
}
|
||||||
|
#ifdef NEED_DUMMY_RETURN
|
||||||
|
return Z_STREAM_ERROR; /* Some dumb compilers complain without this */
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void inflate_codes_free(c, z)
|
||||||
|
inflate_codes_statef *c;
|
||||||
|
z_streamp z;
|
||||||
|
{
|
||||||
|
ZFREE(z, c);
|
||||||
|
Tracev((stderr, "inflate: codes free\n"));
|
||||||
|
}
|
27
zlib/infcodes.h
Normal file
27
zlib/infcodes.h
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
/* infcodes.h -- header to use infcodes.c
|
||||||
|
* Copyright (C) 1995-2002 Mark Adler
|
||||||
|
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* WARNING: this file should *not* be used by applications. It is
|
||||||
|
part of the implementation of the compression library and is
|
||||||
|
subject to change. Applications should only use zlib.h.
|
||||||
|
*/
|
||||||
|
|
||||||
|
struct inflate_codes_state;
|
||||||
|
typedef struct inflate_codes_state FAR inflate_codes_statef;
|
||||||
|
|
||||||
|
extern inflate_codes_statef *inflate_codes_new OF((
|
||||||
|
uInt, uInt,
|
||||||
|
inflate_huft *, inflate_huft *,
|
||||||
|
z_streamp ));
|
||||||
|
|
||||||
|
extern int inflate_codes OF((
|
||||||
|
inflate_blocks_statef *,
|
||||||
|
z_streamp ,
|
||||||
|
int));
|
||||||
|
|
||||||
|
extern void inflate_codes_free OF((
|
||||||
|
inflate_codes_statef *,
|
||||||
|
z_streamp ));
|
||||||
|
|
183
zlib/inffast.c
Normal file
183
zlib/inffast.c
Normal file
|
@ -0,0 +1,183 @@
|
||||||
|
/* inffast.c -- process literals and length/distance pairs fast
|
||||||
|
* Copyright (C) 1995-2002 Mark Adler
|
||||||
|
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "zutil.h"
|
||||||
|
#include "inftrees.h"
|
||||||
|
#include "infblock.h"
|
||||||
|
#include "infcodes.h"
|
||||||
|
#include "infutil.h"
|
||||||
|
#include "inffast.h"
|
||||||
|
|
||||||
|
struct inflate_codes_state {int dummy;}; /* for buggy compilers */
|
||||||
|
|
||||||
|
/* simplify the use of the inflate_huft type with some defines */
|
||||||
|
#define exop word.what.Exop
|
||||||
|
#define bits word.what.Bits
|
||||||
|
|
||||||
|
/* macros for bit input with no checking and for returning unused bytes */
|
||||||
|
#define GRABBITS(j) {while(k<(j)){b|=((uLong)NEXTBYTE)<<k;k+=8;}}
|
||||||
|
#define UNGRAB {c=z->avail_in-n;c=(k>>3)<c?k>>3:c;n+=c;p-=c;k-=c<<3;}
|
||||||
|
|
||||||
|
/* Called with number of bytes left to write in window at least 258
|
||||||
|
(the maximum string length) and number of input bytes available
|
||||||
|
at least ten. The ten bytes are six bytes for the longest length/
|
||||||
|
distance pair plus four bytes for overloading the bit buffer. */
|
||||||
|
|
||||||
|
int inflate_fast(bl, bd, tl, td, s, z)
|
||||||
|
uInt bl, bd;
|
||||||
|
inflate_huft *tl;
|
||||||
|
inflate_huft *td; /* need separate declaration for Borland C++ */
|
||||||
|
inflate_blocks_statef *s;
|
||||||
|
z_streamp z;
|
||||||
|
{
|
||||||
|
inflate_huft *t; /* temporary pointer */
|
||||||
|
uInt e; /* extra bits or operation */
|
||||||
|
uLong b; /* bit buffer */
|
||||||
|
uInt k; /* bits in bit buffer */
|
||||||
|
Bytef *p; /* input data pointer */
|
||||||
|
uInt n; /* bytes available there */
|
||||||
|
Bytef *q; /* output window write pointer */
|
||||||
|
uInt m; /* bytes to end of window or read pointer */
|
||||||
|
uInt ml; /* mask for literal/length tree */
|
||||||
|
uInt md; /* mask for distance tree */
|
||||||
|
uInt c; /* bytes to copy */
|
||||||
|
uInt d; /* distance back to copy from */
|
||||||
|
Bytef *r; /* copy source pointer */
|
||||||
|
|
||||||
|
/* load input, output, bit values */
|
||||||
|
LOAD
|
||||||
|
|
||||||
|
/* initialize masks */
|
||||||
|
ml = inflate_mask[bl];
|
||||||
|
md = inflate_mask[bd];
|
||||||
|
|
||||||
|
/* do until not enough input or output space for fast loop */
|
||||||
|
do { /* assume called with m >= 258 && n >= 10 */
|
||||||
|
/* get literal/length code */
|
||||||
|
GRABBITS(20) /* max bits for literal/length code */
|
||||||
|
if ((e = (t = tl + ((uInt)b & ml))->exop) == 0)
|
||||||
|
{
|
||||||
|
DUMPBITS(t->bits)
|
||||||
|
Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ?
|
||||||
|
"inflate: * literal '%c'\n" :
|
||||||
|
"inflate: * literal 0x%02x\n", t->base));
|
||||||
|
*q++ = (Byte)t->base;
|
||||||
|
m--;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
do {
|
||||||
|
DUMPBITS(t->bits)
|
||||||
|
if (e & 16)
|
||||||
|
{
|
||||||
|
/* get extra bits for length */
|
||||||
|
e &= 15;
|
||||||
|
c = t->base + ((uInt)b & inflate_mask[e]);
|
||||||
|
DUMPBITS(e)
|
||||||
|
Tracevv((stderr, "inflate: * length %u\n", c));
|
||||||
|
|
||||||
|
/* decode distance base of block to copy */
|
||||||
|
GRABBITS(15); /* max bits for distance code */
|
||||||
|
e = (t = td + ((uInt)b & md))->exop;
|
||||||
|
do {
|
||||||
|
DUMPBITS(t->bits)
|
||||||
|
if (e & 16)
|
||||||
|
{
|
||||||
|
/* get extra bits to add to distance base */
|
||||||
|
e &= 15;
|
||||||
|
GRABBITS(e) /* get extra bits (up to 13) */
|
||||||
|
d = t->base + ((uInt)b & inflate_mask[e]);
|
||||||
|
DUMPBITS(e)
|
||||||
|
Tracevv((stderr, "inflate: * distance %u\n", d));
|
||||||
|
|
||||||
|
/* do the copy */
|
||||||
|
m -= c;
|
||||||
|
r = q - d;
|
||||||
|
if (r < s->window) /* wrap if needed */
|
||||||
|
{
|
||||||
|
do {
|
||||||
|
r += s->end - s->window; /* force pointer in window */
|
||||||
|
} while (r < s->window); /* covers invalid distances */
|
||||||
|
e = s->end - r;
|
||||||
|
if (c > e)
|
||||||
|
{
|
||||||
|
c -= e; /* wrapped copy */
|
||||||
|
do {
|
||||||
|
*q++ = *r++;
|
||||||
|
} while (--e);
|
||||||
|
r = s->window;
|
||||||
|
do {
|
||||||
|
*q++ = *r++;
|
||||||
|
} while (--c);
|
||||||
|
}
|
||||||
|
else /* normal copy */
|
||||||
|
{
|
||||||
|
*q++ = *r++; c--;
|
||||||
|
*q++ = *r++; c--;
|
||||||
|
do {
|
||||||
|
*q++ = *r++;
|
||||||
|
} while (--c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else /* normal copy */
|
||||||
|
{
|
||||||
|
*q++ = *r++; c--;
|
||||||
|
*q++ = *r++; c--;
|
||||||
|
do {
|
||||||
|
*q++ = *r++;
|
||||||
|
} while (--c);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if ((e & 64) == 0)
|
||||||
|
{
|
||||||
|
t += t->base;
|
||||||
|
e = (t += ((uInt)b & inflate_mask[e]))->exop;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
z->msg = (char*)"invalid distance code";
|
||||||
|
UNGRAB
|
||||||
|
UPDATE
|
||||||
|
return Z_DATA_ERROR;
|
||||||
|
}
|
||||||
|
} while (1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if ((e & 64) == 0)
|
||||||
|
{
|
||||||
|
t += t->base;
|
||||||
|
if ((e = (t += ((uInt)b & inflate_mask[e]))->exop) == 0)
|
||||||
|
{
|
||||||
|
DUMPBITS(t->bits)
|
||||||
|
Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ?
|
||||||
|
"inflate: * literal '%c'\n" :
|
||||||
|
"inflate: * literal 0x%02x\n", t->base));
|
||||||
|
*q++ = (Byte)t->base;
|
||||||
|
m--;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (e & 32)
|
||||||
|
{
|
||||||
|
Tracevv((stderr, "inflate: * end of block\n"));
|
||||||
|
UNGRAB
|
||||||
|
UPDATE
|
||||||
|
return Z_STREAM_END;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
z->msg = (char*)"invalid literal/length code";
|
||||||
|
UNGRAB
|
||||||
|
UPDATE
|
||||||
|
return Z_DATA_ERROR;
|
||||||
|
}
|
||||||
|
} while (1);
|
||||||
|
} while (m >= 258 && n >= 10);
|
||||||
|
|
||||||
|
/* not enough input or output--restore pointers and return */
|
||||||
|
UNGRAB
|
||||||
|
UPDATE
|
||||||
|
return Z_OK;
|
||||||
|
}
|
17
zlib/inffast.h
Normal file
17
zlib/inffast.h
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
/* inffast.h -- header to use inffast.c
|
||||||
|
* Copyright (C) 1995-2002 Mark Adler
|
||||||
|
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* WARNING: this file should *not* be used by applications. It is
|
||||||
|
part of the implementation of the compression library and is
|
||||||
|
subject to change. Applications should only use zlib.h.
|
||||||
|
*/
|
||||||
|
|
||||||
|
extern int inflate_fast OF((
|
||||||
|
uInt,
|
||||||
|
uInt,
|
||||||
|
inflate_huft *,
|
||||||
|
inflate_huft *,
|
||||||
|
inflate_blocks_statef *,
|
||||||
|
z_streamp ));
|
151
zlib/inffixed.h
Normal file
151
zlib/inffixed.h
Normal file
|
@ -0,0 +1,151 @@
|
||||||
|
/* inffixed.h -- table for decoding fixed codes
|
||||||
|
* Generated automatically by the maketree.c program
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* WARNING: this file should *not* be used by applications. It is
|
||||||
|
part of the implementation of the compression library and is
|
||||||
|
subject to change. Applications should only use zlib.h.
|
||||||
|
*/
|
||||||
|
|
||||||
|
local uInt fixed_bl = 9;
|
||||||
|
local uInt fixed_bd = 5;
|
||||||
|
local inflate_huft fixed_tl[] = {
|
||||||
|
{{{96,7}},256}, {{{0,8}},80}, {{{0,8}},16}, {{{84,8}},115},
|
||||||
|
{{{82,7}},31}, {{{0,8}},112}, {{{0,8}},48}, {{{0,9}},192},
|
||||||
|
{{{80,7}},10}, {{{0,8}},96}, {{{0,8}},32}, {{{0,9}},160},
|
||||||
|
{{{0,8}},0}, {{{0,8}},128}, {{{0,8}},64}, {{{0,9}},224},
|
||||||
|
{{{80,7}},6}, {{{0,8}},88}, {{{0,8}},24}, {{{0,9}},144},
|
||||||
|
{{{83,7}},59}, {{{0,8}},120}, {{{0,8}},56}, {{{0,9}},208},
|
||||||
|
{{{81,7}},17}, {{{0,8}},104}, {{{0,8}},40}, {{{0,9}},176},
|
||||||
|
{{{0,8}},8}, {{{0,8}},136}, {{{0,8}},72}, {{{0,9}},240},
|
||||||
|
{{{80,7}},4}, {{{0,8}},84}, {{{0,8}},20}, {{{85,8}},227},
|
||||||
|
{{{83,7}},43}, {{{0,8}},116}, {{{0,8}},52}, {{{0,9}},200},
|
||||||
|
{{{81,7}},13}, {{{0,8}},100}, {{{0,8}},36}, {{{0,9}},168},
|
||||||
|
{{{0,8}},4}, {{{0,8}},132}, {{{0,8}},68}, {{{0,9}},232},
|
||||||
|
{{{80,7}},8}, {{{0,8}},92}, {{{0,8}},28}, {{{0,9}},152},
|
||||||
|
{{{84,7}},83}, {{{0,8}},124}, {{{0,8}},60}, {{{0,9}},216},
|
||||||
|
{{{82,7}},23}, {{{0,8}},108}, {{{0,8}},44}, {{{0,9}},184},
|
||||||
|
{{{0,8}},12}, {{{0,8}},140}, {{{0,8}},76}, {{{0,9}},248},
|
||||||
|
{{{80,7}},3}, {{{0,8}},82}, {{{0,8}},18}, {{{85,8}},163},
|
||||||
|
{{{83,7}},35}, {{{0,8}},114}, {{{0,8}},50}, {{{0,9}},196},
|
||||||
|
{{{81,7}},11}, {{{0,8}},98}, {{{0,8}},34}, {{{0,9}},164},
|
||||||
|
{{{0,8}},2}, {{{0,8}},130}, {{{0,8}},66}, {{{0,9}},228},
|
||||||
|
{{{80,7}},7}, {{{0,8}},90}, {{{0,8}},26}, {{{0,9}},148},
|
||||||
|
{{{84,7}},67}, {{{0,8}},122}, {{{0,8}},58}, {{{0,9}},212},
|
||||||
|
{{{82,7}},19}, {{{0,8}},106}, {{{0,8}},42}, {{{0,9}},180},
|
||||||
|
{{{0,8}},10}, {{{0,8}},138}, {{{0,8}},74}, {{{0,9}},244},
|
||||||
|
{{{80,7}},5}, {{{0,8}},86}, {{{0,8}},22}, {{{192,8}},0},
|
||||||
|
{{{83,7}},51}, {{{0,8}},118}, {{{0,8}},54}, {{{0,9}},204},
|
||||||
|
{{{81,7}},15}, {{{0,8}},102}, {{{0,8}},38}, {{{0,9}},172},
|
||||||
|
{{{0,8}},6}, {{{0,8}},134}, {{{0,8}},70}, {{{0,9}},236},
|
||||||
|
{{{80,7}},9}, {{{0,8}},94}, {{{0,8}},30}, {{{0,9}},156},
|
||||||
|
{{{84,7}},99}, {{{0,8}},126}, {{{0,8}},62}, {{{0,9}},220},
|
||||||
|
{{{82,7}},27}, {{{0,8}},110}, {{{0,8}},46}, {{{0,9}},188},
|
||||||
|
{{{0,8}},14}, {{{0,8}},142}, {{{0,8}},78}, {{{0,9}},252},
|
||||||
|
{{{96,7}},256}, {{{0,8}},81}, {{{0,8}},17}, {{{85,8}},131},
|
||||||
|
{{{82,7}},31}, {{{0,8}},113}, {{{0,8}},49}, {{{0,9}},194},
|
||||||
|
{{{80,7}},10}, {{{0,8}},97}, {{{0,8}},33}, {{{0,9}},162},
|
||||||
|
{{{0,8}},1}, {{{0,8}},129}, {{{0,8}},65}, {{{0,9}},226},
|
||||||
|
{{{80,7}},6}, {{{0,8}},89}, {{{0,8}},25}, {{{0,9}},146},
|
||||||
|
{{{83,7}},59}, {{{0,8}},121}, {{{0,8}},57}, {{{0,9}},210},
|
||||||
|
{{{81,7}},17}, {{{0,8}},105}, {{{0,8}},41}, {{{0,9}},178},
|
||||||
|
{{{0,8}},9}, {{{0,8}},137}, {{{0,8}},73}, {{{0,9}},242},
|
||||||
|
{{{80,7}},4}, {{{0,8}},85}, {{{0,8}},21}, {{{80,8}},258},
|
||||||
|
{{{83,7}},43}, {{{0,8}},117}, {{{0,8}},53}, {{{0,9}},202},
|
||||||
|
{{{81,7}},13}, {{{0,8}},101}, {{{0,8}},37}, {{{0,9}},170},
|
||||||
|
{{{0,8}},5}, {{{0,8}},133}, {{{0,8}},69}, {{{0,9}},234},
|
||||||
|
{{{80,7}},8}, {{{0,8}},93}, {{{0,8}},29}, {{{0,9}},154},
|
||||||
|
{{{84,7}},83}, {{{0,8}},125}, {{{0,8}},61}, {{{0,9}},218},
|
||||||
|
{{{82,7}},23}, {{{0,8}},109}, {{{0,8}},45}, {{{0,9}},186},
|
||||||
|
{{{0,8}},13}, {{{0,8}},141}, {{{0,8}},77}, {{{0,9}},250},
|
||||||
|
{{{80,7}},3}, {{{0,8}},83}, {{{0,8}},19}, {{{85,8}},195},
|
||||||
|
{{{83,7}},35}, {{{0,8}},115}, {{{0,8}},51}, {{{0,9}},198},
|
||||||
|
{{{81,7}},11}, {{{0,8}},99}, {{{0,8}},35}, {{{0,9}},166},
|
||||||
|
{{{0,8}},3}, {{{0,8}},131}, {{{0,8}},67}, {{{0,9}},230},
|
||||||
|
{{{80,7}},7}, {{{0,8}},91}, {{{0,8}},27}, {{{0,9}},150},
|
||||||
|
{{{84,7}},67}, {{{0,8}},123}, {{{0,8}},59}, {{{0,9}},214},
|
||||||
|
{{{82,7}},19}, {{{0,8}},107}, {{{0,8}},43}, {{{0,9}},182},
|
||||||
|
{{{0,8}},11}, {{{0,8}},139}, {{{0,8}},75}, {{{0,9}},246},
|
||||||
|
{{{80,7}},5}, {{{0,8}},87}, {{{0,8}},23}, {{{192,8}},0},
|
||||||
|
{{{83,7}},51}, {{{0,8}},119}, {{{0,8}},55}, {{{0,9}},206},
|
||||||
|
{{{81,7}},15}, {{{0,8}},103}, {{{0,8}},39}, {{{0,9}},174},
|
||||||
|
{{{0,8}},7}, {{{0,8}},135}, {{{0,8}},71}, {{{0,9}},238},
|
||||||
|
{{{80,7}},9}, {{{0,8}},95}, {{{0,8}},31}, {{{0,9}},158},
|
||||||
|
{{{84,7}},99}, {{{0,8}},127}, {{{0,8}},63}, {{{0,9}},222},
|
||||||
|
{{{82,7}},27}, {{{0,8}},111}, {{{0,8}},47}, {{{0,9}},190},
|
||||||
|
{{{0,8}},15}, {{{0,8}},143}, {{{0,8}},79}, {{{0,9}},254},
|
||||||
|
{{{96,7}},256}, {{{0,8}},80}, {{{0,8}},16}, {{{84,8}},115},
|
||||||
|
{{{82,7}},31}, {{{0,8}},112}, {{{0,8}},48}, {{{0,9}},193},
|
||||||
|
{{{80,7}},10}, {{{0,8}},96}, {{{0,8}},32}, {{{0,9}},161},
|
||||||
|
{{{0,8}},0}, {{{0,8}},128}, {{{0,8}},64}, {{{0,9}},225},
|
||||||
|
{{{80,7}},6}, {{{0,8}},88}, {{{0,8}},24}, {{{0,9}},145},
|
||||||
|
{{{83,7}},59}, {{{0,8}},120}, {{{0,8}},56}, {{{0,9}},209},
|
||||||
|
{{{81,7}},17}, {{{0,8}},104}, {{{0,8}},40}, {{{0,9}},177},
|
||||||
|
{{{0,8}},8}, {{{0,8}},136}, {{{0,8}},72}, {{{0,9}},241},
|
||||||
|
{{{80,7}},4}, {{{0,8}},84}, {{{0,8}},20}, {{{85,8}},227},
|
||||||
|
{{{83,7}},43}, {{{0,8}},116}, {{{0,8}},52}, {{{0,9}},201},
|
||||||
|
{{{81,7}},13}, {{{0,8}},100}, {{{0,8}},36}, {{{0,9}},169},
|
||||||
|
{{{0,8}},4}, {{{0,8}},132}, {{{0,8}},68}, {{{0,9}},233},
|
||||||
|
{{{80,7}},8}, {{{0,8}},92}, {{{0,8}},28}, {{{0,9}},153},
|
||||||
|
{{{84,7}},83}, {{{0,8}},124}, {{{0,8}},60}, {{{0,9}},217},
|
||||||
|
{{{82,7}},23}, {{{0,8}},108}, {{{0,8}},44}, {{{0,9}},185},
|
||||||
|
{{{0,8}},12}, {{{0,8}},140}, {{{0,8}},76}, {{{0,9}},249},
|
||||||
|
{{{80,7}},3}, {{{0,8}},82}, {{{0,8}},18}, {{{85,8}},163},
|
||||||
|
{{{83,7}},35}, {{{0,8}},114}, {{{0,8}},50}, {{{0,9}},197},
|
||||||
|
{{{81,7}},11}, {{{0,8}},98}, {{{0,8}},34}, {{{0,9}},165},
|
||||||
|
{{{0,8}},2}, {{{0,8}},130}, {{{0,8}},66}, {{{0,9}},229},
|
||||||
|
{{{80,7}},7}, {{{0,8}},90}, {{{0,8}},26}, {{{0,9}},149},
|
||||||
|
{{{84,7}},67}, {{{0,8}},122}, {{{0,8}},58}, {{{0,9}},213},
|
||||||
|
{{{82,7}},19}, {{{0,8}},106}, {{{0,8}},42}, {{{0,9}},181},
|
||||||
|
{{{0,8}},10}, {{{0,8}},138}, {{{0,8}},74}, {{{0,9}},245},
|
||||||
|
{{{80,7}},5}, {{{0,8}},86}, {{{0,8}},22}, {{{192,8}},0},
|
||||||
|
{{{83,7}},51}, {{{0,8}},118}, {{{0,8}},54}, {{{0,9}},205},
|
||||||
|
{{{81,7}},15}, {{{0,8}},102}, {{{0,8}},38}, {{{0,9}},173},
|
||||||
|
{{{0,8}},6}, {{{0,8}},134}, {{{0,8}},70}, {{{0,9}},237},
|
||||||
|
{{{80,7}},9}, {{{0,8}},94}, {{{0,8}},30}, {{{0,9}},157},
|
||||||
|
{{{84,7}},99}, {{{0,8}},126}, {{{0,8}},62}, {{{0,9}},221},
|
||||||
|
{{{82,7}},27}, {{{0,8}},110}, {{{0,8}},46}, {{{0,9}},189},
|
||||||
|
{{{0,8}},14}, {{{0,8}},142}, {{{0,8}},78}, {{{0,9}},253},
|
||||||
|
{{{96,7}},256}, {{{0,8}},81}, {{{0,8}},17}, {{{85,8}},131},
|
||||||
|
{{{82,7}},31}, {{{0,8}},113}, {{{0,8}},49}, {{{0,9}},195},
|
||||||
|
{{{80,7}},10}, {{{0,8}},97}, {{{0,8}},33}, {{{0,9}},163},
|
||||||
|
{{{0,8}},1}, {{{0,8}},129}, {{{0,8}},65}, {{{0,9}},227},
|
||||||
|
{{{80,7}},6}, {{{0,8}},89}, {{{0,8}},25}, {{{0,9}},147},
|
||||||
|
{{{83,7}},59}, {{{0,8}},121}, {{{0,8}},57}, {{{0,9}},211},
|
||||||
|
{{{81,7}},17}, {{{0,8}},105}, {{{0,8}},41}, {{{0,9}},179},
|
||||||
|
{{{0,8}},9}, {{{0,8}},137}, {{{0,8}},73}, {{{0,9}},243},
|
||||||
|
{{{80,7}},4}, {{{0,8}},85}, {{{0,8}},21}, {{{80,8}},258},
|
||||||
|
{{{83,7}},43}, {{{0,8}},117}, {{{0,8}},53}, {{{0,9}},203},
|
||||||
|
{{{81,7}},13}, {{{0,8}},101}, {{{0,8}},37}, {{{0,9}},171},
|
||||||
|
{{{0,8}},5}, {{{0,8}},133}, {{{0,8}},69}, {{{0,9}},235},
|
||||||
|
{{{80,7}},8}, {{{0,8}},93}, {{{0,8}},29}, {{{0,9}},155},
|
||||||
|
{{{84,7}},83}, {{{0,8}},125}, {{{0,8}},61}, {{{0,9}},219},
|
||||||
|
{{{82,7}},23}, {{{0,8}},109}, {{{0,8}},45}, {{{0,9}},187},
|
||||||
|
{{{0,8}},13}, {{{0,8}},141}, {{{0,8}},77}, {{{0,9}},251},
|
||||||
|
{{{80,7}},3}, {{{0,8}},83}, {{{0,8}},19}, {{{85,8}},195},
|
||||||
|
{{{83,7}},35}, {{{0,8}},115}, {{{0,8}},51}, {{{0,9}},199},
|
||||||
|
{{{81,7}},11}, {{{0,8}},99}, {{{0,8}},35}, {{{0,9}},167},
|
||||||
|
{{{0,8}},3}, {{{0,8}},131}, {{{0,8}},67}, {{{0,9}},231},
|
||||||
|
{{{80,7}},7}, {{{0,8}},91}, {{{0,8}},27}, {{{0,9}},151},
|
||||||
|
{{{84,7}},67}, {{{0,8}},123}, {{{0,8}},59}, {{{0,9}},215},
|
||||||
|
{{{82,7}},19}, {{{0,8}},107}, {{{0,8}},43}, {{{0,9}},183},
|
||||||
|
{{{0,8}},11}, {{{0,8}},139}, {{{0,8}},75}, {{{0,9}},247},
|
||||||
|
{{{80,7}},5}, {{{0,8}},87}, {{{0,8}},23}, {{{192,8}},0},
|
||||||
|
{{{83,7}},51}, {{{0,8}},119}, {{{0,8}},55}, {{{0,9}},207},
|
||||||
|
{{{81,7}},15}, {{{0,8}},103}, {{{0,8}},39}, {{{0,9}},175},
|
||||||
|
{{{0,8}},7}, {{{0,8}},135}, {{{0,8}},71}, {{{0,9}},239},
|
||||||
|
{{{80,7}},9}, {{{0,8}},95}, {{{0,8}},31}, {{{0,9}},159},
|
||||||
|
{{{84,7}},99}, {{{0,8}},127}, {{{0,8}},63}, {{{0,9}},223},
|
||||||
|
{{{82,7}},27}, {{{0,8}},111}, {{{0,8}},47}, {{{0,9}},191},
|
||||||
|
{{{0,8}},15}, {{{0,8}},143}, {{{0,8}},79}, {{{0,9}},255}
|
||||||
|
};
|
||||||
|
local inflate_huft fixed_td[] = {
|
||||||
|
{{{80,5}},1}, {{{87,5}},257}, {{{83,5}},17}, {{{91,5}},4097},
|
||||||
|
{{{81,5}},5}, {{{89,5}},1025}, {{{85,5}},65}, {{{93,5}},16385},
|
||||||
|
{{{80,5}},3}, {{{88,5}},513}, {{{84,5}},33}, {{{92,5}},8193},
|
||||||
|
{{{82,5}},9}, {{{90,5}},2049}, {{{86,5}},129}, {{{192,5}},24577},
|
||||||
|
{{{80,5}},2}, {{{87,5}},385}, {{{83,5}},25}, {{{91,5}},6145},
|
||||||
|
{{{81,5}},7}, {{{89,5}},1537}, {{{85,5}},97}, {{{93,5}},24577},
|
||||||
|
{{{80,5}},4}, {{{88,5}},769}, {{{84,5}},49}, {{{92,5}},12289},
|
||||||
|
{{{82,5}},13}, {{{90,5}},3073}, {{{86,5}},193}, {{{192,5}},24577}
|
||||||
|
};
|
366
zlib/inflate.c
Normal file
366
zlib/inflate.c
Normal file
|
@ -0,0 +1,366 @@
|
||||||
|
/* inflate.c -- zlib interface to inflate modules
|
||||||
|
* Copyright (C) 1995-2002 Mark Adler
|
||||||
|
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "zutil.h"
|
||||||
|
#include "infblock.h"
|
||||||
|
|
||||||
|
struct inflate_blocks_state {int dummy;}; /* for buggy compilers */
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
METHOD, /* waiting for method byte */
|
||||||
|
FLAG, /* waiting for flag byte */
|
||||||
|
DICT4, /* four dictionary check bytes to go */
|
||||||
|
DICT3, /* three dictionary check bytes to go */
|
||||||
|
DICT2, /* two dictionary check bytes to go */
|
||||||
|
DICT1, /* one dictionary check byte to go */
|
||||||
|
DICT0, /* waiting for inflateSetDictionary */
|
||||||
|
BLOCKS, /* decompressing blocks */
|
||||||
|
CHECK4, /* four check bytes to go */
|
||||||
|
CHECK3, /* three check bytes to go */
|
||||||
|
CHECK2, /* two check bytes to go */
|
||||||
|
CHECK1, /* one check byte to go */
|
||||||
|
DONE, /* finished check, done */
|
||||||
|
BAD} /* got an error--stay here */
|
||||||
|
inflate_mode;
|
||||||
|
|
||||||
|
/* inflate private state */
|
||||||
|
struct internal_state {
|
||||||
|
|
||||||
|
/* mode */
|
||||||
|
inflate_mode mode; /* current inflate mode */
|
||||||
|
|
||||||
|
/* mode dependent information */
|
||||||
|
union {
|
||||||
|
uInt method; /* if FLAGS, method byte */
|
||||||
|
struct {
|
||||||
|
uLong was; /* computed check value */
|
||||||
|
uLong need; /* stream check value */
|
||||||
|
} check; /* if CHECK, check values to compare */
|
||||||
|
uInt marker; /* if BAD, inflateSync's marker bytes count */
|
||||||
|
} sub; /* submode */
|
||||||
|
|
||||||
|
/* mode independent information */
|
||||||
|
int nowrap; /* flag for no wrapper */
|
||||||
|
uInt wbits; /* log2(window size) (8..15, defaults to 15) */
|
||||||
|
inflate_blocks_statef
|
||||||
|
*blocks; /* current inflate_blocks state */
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
int ZEXPORT inflateReset(z)
|
||||||
|
z_streamp z;
|
||||||
|
{
|
||||||
|
if (z == Z_NULL || z->state == Z_NULL)
|
||||||
|
return Z_STREAM_ERROR;
|
||||||
|
z->total_in = z->total_out = 0;
|
||||||
|
z->msg = Z_NULL;
|
||||||
|
z->state->mode = z->state->nowrap ? BLOCKS : METHOD;
|
||||||
|
inflate_blocks_reset(z->state->blocks, z, Z_NULL);
|
||||||
|
Tracev((stderr, "inflate: reset\n"));
|
||||||
|
return Z_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int ZEXPORT inflateEnd(z)
|
||||||
|
z_streamp z;
|
||||||
|
{
|
||||||
|
if (z == Z_NULL || z->state == Z_NULL || z->zfree == Z_NULL)
|
||||||
|
return Z_STREAM_ERROR;
|
||||||
|
if (z->state->blocks != Z_NULL)
|
||||||
|
inflate_blocks_free(z->state->blocks, z);
|
||||||
|
ZFREE(z, z->state);
|
||||||
|
z->state = Z_NULL;
|
||||||
|
Tracev((stderr, "inflate: end\n"));
|
||||||
|
return Z_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int ZEXPORT inflateInit2_(z, w, version, stream_size)
|
||||||
|
z_streamp z;
|
||||||
|
int w;
|
||||||
|
const char *version;
|
||||||
|
int stream_size;
|
||||||
|
{
|
||||||
|
if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
|
||||||
|
stream_size != sizeof(z_stream))
|
||||||
|
return Z_VERSION_ERROR;
|
||||||
|
|
||||||
|
/* initialize state */
|
||||||
|
if (z == Z_NULL)
|
||||||
|
return Z_STREAM_ERROR;
|
||||||
|
z->msg = Z_NULL;
|
||||||
|
if (z->zalloc == Z_NULL)
|
||||||
|
{
|
||||||
|
z->zalloc = zcalloc;
|
||||||
|
z->opaque = (voidpf)0;
|
||||||
|
}
|
||||||
|
if (z->zfree == Z_NULL) z->zfree = zcfree;
|
||||||
|
if ((z->state = (struct internal_state FAR *)
|
||||||
|
ZALLOC(z,1,sizeof(struct internal_state))) == Z_NULL)
|
||||||
|
return Z_MEM_ERROR;
|
||||||
|
z->state->blocks = Z_NULL;
|
||||||
|
|
||||||
|
/* handle undocumented nowrap option (no zlib header or check) */
|
||||||
|
z->state->nowrap = 0;
|
||||||
|
if (w < 0)
|
||||||
|
{
|
||||||
|
w = - w;
|
||||||
|
z->state->nowrap = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* set window size */
|
||||||
|
if (w < 8 || w > 15)
|
||||||
|
{
|
||||||
|
inflateEnd(z);
|
||||||
|
return Z_STREAM_ERROR;
|
||||||
|
}
|
||||||
|
z->state->wbits = (uInt)w;
|
||||||
|
|
||||||
|
/* create inflate_blocks state */
|
||||||
|
if ((z->state->blocks =
|
||||||
|
inflate_blocks_new(z, z->state->nowrap ? Z_NULL : adler32, (uInt)1 << w))
|
||||||
|
== Z_NULL)
|
||||||
|
{
|
||||||
|
inflateEnd(z);
|
||||||
|
return Z_MEM_ERROR;
|
||||||
|
}
|
||||||
|
Tracev((stderr, "inflate: allocated\n"));
|
||||||
|
|
||||||
|
/* reset state */
|
||||||
|
inflateReset(z);
|
||||||
|
return Z_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int ZEXPORT inflateInit_(z, version, stream_size)
|
||||||
|
z_streamp z;
|
||||||
|
const char *version;
|
||||||
|
int stream_size;
|
||||||
|
{
|
||||||
|
return inflateInit2_(z, DEF_WBITS, version, stream_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#define NEEDBYTE {if(z->avail_in==0)return r;r=f;}
|
||||||
|
#define NEXTBYTE (z->avail_in--,z->total_in++,*z->next_in++)
|
||||||
|
|
||||||
|
int ZEXPORT inflate(z, f)
|
||||||
|
z_streamp z;
|
||||||
|
int f;
|
||||||
|
{
|
||||||
|
int r;
|
||||||
|
uInt b;
|
||||||
|
|
||||||
|
if (z == Z_NULL || z->state == Z_NULL || z->next_in == Z_NULL)
|
||||||
|
return Z_STREAM_ERROR;
|
||||||
|
f = f == Z_FINISH ? Z_BUF_ERROR : Z_OK;
|
||||||
|
r = Z_BUF_ERROR;
|
||||||
|
while (1) switch (z->state->mode)
|
||||||
|
{
|
||||||
|
case METHOD:
|
||||||
|
NEEDBYTE
|
||||||
|
if (((z->state->sub.method = NEXTBYTE) & 0xf) != Z_DEFLATED)
|
||||||
|
{
|
||||||
|
z->state->mode = BAD;
|
||||||
|
z->msg = (char*)"unknown compression method";
|
||||||
|
z->state->sub.marker = 5; /* can't try inflateSync */
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if ((z->state->sub.method >> 4) + 8 > z->state->wbits)
|
||||||
|
{
|
||||||
|
z->state->mode = BAD;
|
||||||
|
z->msg = (char*)"invalid window size";
|
||||||
|
z->state->sub.marker = 5; /* can't try inflateSync */
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
z->state->mode = FLAG;
|
||||||
|
case FLAG:
|
||||||
|
NEEDBYTE
|
||||||
|
b = NEXTBYTE;
|
||||||
|
if (((z->state->sub.method << 8) + b) % 31)
|
||||||
|
{
|
||||||
|
z->state->mode = BAD;
|
||||||
|
z->msg = (char*)"incorrect header check";
|
||||||
|
z->state->sub.marker = 5; /* can't try inflateSync */
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Tracev((stderr, "inflate: zlib header ok\n"));
|
||||||
|
if (!(b & PRESET_DICT))
|
||||||
|
{
|
||||||
|
z->state->mode = BLOCKS;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
z->state->mode = DICT4;
|
||||||
|
case DICT4:
|
||||||
|
NEEDBYTE
|
||||||
|
z->state->sub.check.need = (uLong)NEXTBYTE << 24;
|
||||||
|
z->state->mode = DICT3;
|
||||||
|
case DICT3:
|
||||||
|
NEEDBYTE
|
||||||
|
z->state->sub.check.need += (uLong)NEXTBYTE << 16;
|
||||||
|
z->state->mode = DICT2;
|
||||||
|
case DICT2:
|
||||||
|
NEEDBYTE
|
||||||
|
z->state->sub.check.need += (uLong)NEXTBYTE << 8;
|
||||||
|
z->state->mode = DICT1;
|
||||||
|
case DICT1:
|
||||||
|
NEEDBYTE
|
||||||
|
z->state->sub.check.need += (uLong)NEXTBYTE;
|
||||||
|
z->adler = z->state->sub.check.need;
|
||||||
|
z->state->mode = DICT0;
|
||||||
|
return Z_NEED_DICT;
|
||||||
|
case DICT0:
|
||||||
|
z->state->mode = BAD;
|
||||||
|
z->msg = (char*)"need dictionary";
|
||||||
|
z->state->sub.marker = 0; /* can try inflateSync */
|
||||||
|
return Z_STREAM_ERROR;
|
||||||
|
case BLOCKS:
|
||||||
|
r = inflate_blocks(z->state->blocks, z, r);
|
||||||
|
if (r == Z_DATA_ERROR)
|
||||||
|
{
|
||||||
|
z->state->mode = BAD;
|
||||||
|
z->state->sub.marker = 0; /* can try inflateSync */
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (r == Z_OK)
|
||||||
|
r = f;
|
||||||
|
if (r != Z_STREAM_END)
|
||||||
|
return r;
|
||||||
|
r = f;
|
||||||
|
inflate_blocks_reset(z->state->blocks, z, &z->state->sub.check.was);
|
||||||
|
if (z->state->nowrap)
|
||||||
|
{
|
||||||
|
z->state->mode = DONE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
z->state->mode = CHECK4;
|
||||||
|
case CHECK4:
|
||||||
|
NEEDBYTE
|
||||||
|
z->state->sub.check.need = (uLong)NEXTBYTE << 24;
|
||||||
|
z->state->mode = CHECK3;
|
||||||
|
case CHECK3:
|
||||||
|
NEEDBYTE
|
||||||
|
z->state->sub.check.need += (uLong)NEXTBYTE << 16;
|
||||||
|
z->state->mode = CHECK2;
|
||||||
|
case CHECK2:
|
||||||
|
NEEDBYTE
|
||||||
|
z->state->sub.check.need += (uLong)NEXTBYTE << 8;
|
||||||
|
z->state->mode = CHECK1;
|
||||||
|
case CHECK1:
|
||||||
|
NEEDBYTE
|
||||||
|
z->state->sub.check.need += (uLong)NEXTBYTE;
|
||||||
|
|
||||||
|
if (z->state->sub.check.was != z->state->sub.check.need)
|
||||||
|
{
|
||||||
|
z->state->mode = BAD;
|
||||||
|
z->msg = (char*)"incorrect data check";
|
||||||
|
z->state->sub.marker = 5; /* can't try inflateSync */
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Tracev((stderr, "inflate: zlib check ok\n"));
|
||||||
|
z->state->mode = DONE;
|
||||||
|
case DONE:
|
||||||
|
return Z_STREAM_END;
|
||||||
|
case BAD:
|
||||||
|
return Z_DATA_ERROR;
|
||||||
|
default:
|
||||||
|
return Z_STREAM_ERROR;
|
||||||
|
}
|
||||||
|
#ifdef NEED_DUMMY_RETURN
|
||||||
|
return Z_STREAM_ERROR; /* Some dumb compilers complain without this */
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int ZEXPORT inflateSetDictionary(z, dictionary, dictLength)
|
||||||
|
z_streamp z;
|
||||||
|
const Bytef *dictionary;
|
||||||
|
uInt dictLength;
|
||||||
|
{
|
||||||
|
uInt length = dictLength;
|
||||||
|
|
||||||
|
if (z == Z_NULL || z->state == Z_NULL || z->state->mode != DICT0)
|
||||||
|
return Z_STREAM_ERROR;
|
||||||
|
|
||||||
|
if (adler32(1L, dictionary, dictLength) != z->adler) return Z_DATA_ERROR;
|
||||||
|
z->adler = 1L;
|
||||||
|
|
||||||
|
if (length >= ((uInt)1<<z->state->wbits))
|
||||||
|
{
|
||||||
|
length = (1<<z->state->wbits)-1;
|
||||||
|
dictionary += dictLength - length;
|
||||||
|
}
|
||||||
|
inflate_set_dictionary(z->state->blocks, dictionary, length);
|
||||||
|
z->state->mode = BLOCKS;
|
||||||
|
return Z_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int ZEXPORT inflateSync(z)
|
||||||
|
z_streamp z;
|
||||||
|
{
|
||||||
|
uInt n; /* number of bytes to look at */
|
||||||
|
Bytef *p; /* pointer to bytes */
|
||||||
|
uInt m; /* number of marker bytes found in a row */
|
||||||
|
uLong r, w; /* temporaries to save total_in and total_out */
|
||||||
|
|
||||||
|
/* set up */
|
||||||
|
if (z == Z_NULL || z->state == Z_NULL)
|
||||||
|
return Z_STREAM_ERROR;
|
||||||
|
if (z->state->mode != BAD)
|
||||||
|
{
|
||||||
|
z->state->mode = BAD;
|
||||||
|
z->state->sub.marker = 0;
|
||||||
|
}
|
||||||
|
if ((n = z->avail_in) == 0)
|
||||||
|
return Z_BUF_ERROR;
|
||||||
|
p = z->next_in;
|
||||||
|
m = z->state->sub.marker;
|
||||||
|
|
||||||
|
/* search */
|
||||||
|
while (n && m < 4)
|
||||||
|
{
|
||||||
|
static const Byte mark[4] = {0, 0, 0xff, 0xff};
|
||||||
|
if (*p == mark[m])
|
||||||
|
m++;
|
||||||
|
else if (*p)
|
||||||
|
m = 0;
|
||||||
|
else
|
||||||
|
m = 4 - m;
|
||||||
|
p++, n--;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* restore */
|
||||||
|
z->total_in += p - z->next_in;
|
||||||
|
z->next_in = p;
|
||||||
|
z->avail_in = n;
|
||||||
|
z->state->sub.marker = m;
|
||||||
|
|
||||||
|
/* return no joy or set up to restart on a new block */
|
||||||
|
if (m != 4)
|
||||||
|
return Z_DATA_ERROR;
|
||||||
|
r = z->total_in; w = z->total_out;
|
||||||
|
inflateReset(z);
|
||||||
|
z->total_in = r; z->total_out = w;
|
||||||
|
z->state->mode = BLOCKS;
|
||||||
|
return Z_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Returns true if inflate is currently at the end of a block generated
|
||||||
|
* by Z_SYNC_FLUSH or Z_FULL_FLUSH. This function is used by one PPP
|
||||||
|
* implementation to provide an additional safety check. PPP uses Z_SYNC_FLUSH
|
||||||
|
* but removes the length bytes of the resulting empty stored block. When
|
||||||
|
* decompressing, PPP checks that at the end of input packet, inflate is
|
||||||
|
* waiting for these length bytes.
|
||||||
|
*/
|
||||||
|
int ZEXPORT inflateSyncPoint(z)
|
||||||
|
z_streamp z;
|
||||||
|
{
|
||||||
|
if (z == Z_NULL || z->state == Z_NULL || z->state->blocks == Z_NULL)
|
||||||
|
return Z_STREAM_ERROR;
|
||||||
|
return inflate_blocks_sync_point(z->state->blocks);
|
||||||
|
}
|
454
zlib/inftrees.c
Normal file
454
zlib/inftrees.c
Normal file
|
@ -0,0 +1,454 @@
|
||||||
|
/* inftrees.c -- generate Huffman trees for efficient decoding
|
||||||
|
* Copyright (C) 1995-2002 Mark Adler
|
||||||
|
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "zutil.h"
|
||||||
|
#include "inftrees.h"
|
||||||
|
|
||||||
|
#if !defined(BUILDFIXED) && !defined(STDC)
|
||||||
|
# define BUILDFIXED /* non ANSI compilers may not accept inffixed.h */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
const char inflate_copyright[] =
|
||||||
|
" inflate 1.1.4 Copyright 1995-2002 Mark Adler ";
|
||||||
|
/*
|
||||||
|
If you use the zlib library in a product, an acknowledgment is welcome
|
||||||
|
in the documentation of your product. If for some reason you cannot
|
||||||
|
include such an acknowledgment, I would appreciate that you keep this
|
||||||
|
copyright string in the executable of your product.
|
||||||
|
*/
|
||||||
|
struct internal_state {int dummy;}; /* for buggy compilers */
|
||||||
|
|
||||||
|
/* simplify the use of the inflate_huft type with some defines */
|
||||||
|
#define exop word.what.Exop
|
||||||
|
#define bits word.what.Bits
|
||||||
|
|
||||||
|
|
||||||
|
local int huft_build OF((
|
||||||
|
uIntf *, /* code lengths in bits */
|
||||||
|
uInt, /* number of codes */
|
||||||
|
uInt, /* number of "simple" codes */
|
||||||
|
const uIntf *, /* list of base values for non-simple codes */
|
||||||
|
const uIntf *, /* list of extra bits for non-simple codes */
|
||||||
|
inflate_huft * FAR*,/* result: starting table */
|
||||||
|
uIntf *, /* maximum lookup bits (returns actual) */
|
||||||
|
inflate_huft *, /* space for trees */
|
||||||
|
uInt *, /* hufts used in space */
|
||||||
|
uIntf * )); /* space for values */
|
||||||
|
|
||||||
|
/* Tables for deflate from PKZIP's appnote.txt. */
|
||||||
|
local const uInt cplens[31] = { /* Copy lengths for literal codes 257..285 */
|
||||||
|
3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
|
||||||
|
35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
|
||||||
|
/* see note #13 above about 258 */
|
||||||
|
local const uInt cplext[31] = { /* Extra bits for literal codes 257..285 */
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
|
||||||
|
3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 112, 112}; /* 112==invalid */
|
||||||
|
local const uInt cpdist[30] = { /* Copy offsets for distance codes 0..29 */
|
||||||
|
1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
|
||||||
|
257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
|
||||||
|
8193, 12289, 16385, 24577};
|
||||||
|
local const uInt cpdext[30] = { /* Extra bits for distance codes */
|
||||||
|
0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
|
||||||
|
7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
|
||||||
|
12, 12, 13, 13};
|
||||||
|
|
||||||
|
/*
|
||||||
|
Huffman code decoding is performed using a multi-level table lookup.
|
||||||
|
The fastest way to decode is to simply build a lookup table whose
|
||||||
|
size is determined by the longest code. However, the time it takes
|
||||||
|
to build this table can also be a factor if the data being decoded
|
||||||
|
is not very long. The most common codes are necessarily the
|
||||||
|
shortest codes, so those codes dominate the decoding time, and hence
|
||||||
|
the speed. The idea is you can have a shorter table that decodes the
|
||||||
|
shorter, more probable codes, and then point to subsidiary tables for
|
||||||
|
the longer codes. The time it costs to decode the longer codes is
|
||||||
|
then traded against the time it takes to make longer tables.
|
||||||
|
|
||||||
|
This results of this trade are in the variables lbits and dbits
|
||||||
|
below. lbits is the number of bits the first level table for literal/
|
||||||
|
length codes can decode in one step, and dbits is the same thing for
|
||||||
|
the distance codes. Subsequent tables are also less than or equal to
|
||||||
|
those sizes. These values may be adjusted either when all of the
|
||||||
|
codes are shorter than that, in which case the longest code length in
|
||||||
|
bits is used, or when the shortest code is *longer* than the requested
|
||||||
|
table size, in which case the length of the shortest code in bits is
|
||||||
|
used.
|
||||||
|
|
||||||
|
There are two different values for the two tables, since they code a
|
||||||
|
different number of possibilities each. The literal/length table
|
||||||
|
codes 286 possible values, or in a flat code, a little over eight
|
||||||
|
bits. The distance table codes 30 possible values, or a little less
|
||||||
|
than five bits, flat. The optimum values for speed end up being
|
||||||
|
about one bit more than those, so lbits is 8+1 and dbits is 5+1.
|
||||||
|
The optimum values may differ though from machine to machine, and
|
||||||
|
possibly even between compilers. Your mileage may vary.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/* If BMAX needs to be larger than 16, then h and x[] should be uLong. */
|
||||||
|
#define BMAX 15 /* maximum bit length of any code */
|
||||||
|
|
||||||
|
local int huft_build(b, n, s, d, e, t, m, hp, hn, v)
|
||||||
|
uIntf *b; /* code lengths in bits (all assumed <= BMAX) */
|
||||||
|
uInt n; /* number of codes (assumed <= 288) */
|
||||||
|
uInt s; /* number of simple-valued codes (0..s-1) */
|
||||||
|
const uIntf *d; /* list of base values for non-simple codes */
|
||||||
|
const uIntf *e; /* list of extra bits for non-simple codes */
|
||||||
|
inflate_huft * FAR *t; /* result: starting table */
|
||||||
|
uIntf *m; /* maximum lookup bits, returns actual */
|
||||||
|
inflate_huft *hp; /* space for trees */
|
||||||
|
uInt *hn; /* hufts used in space */
|
||||||
|
uIntf *v; /* working area: values in order of bit length */
|
||||||
|
/* Given a list of code lengths and a maximum table size, make a set of
|
||||||
|
tables to decode that set of codes. Return Z_OK on success, Z_BUF_ERROR
|
||||||
|
if the given code set is incomplete (the tables are still built in this
|
||||||
|
case), or Z_DATA_ERROR if the input is invalid. */
|
||||||
|
{
|
||||||
|
|
||||||
|
uInt a; /* counter for codes of length k */
|
||||||
|
uInt c[BMAX+1]; /* bit length count table */
|
||||||
|
uInt f; /* i repeats in table every f entries */
|
||||||
|
int g; /* maximum code length */
|
||||||
|
int h; /* table level */
|
||||||
|
register uInt i; /* counter, current code */
|
||||||
|
register uInt j; /* counter */
|
||||||
|
register int k; /* number of bits in current code */
|
||||||
|
int l; /* bits per table (returned in m) */
|
||||||
|
uInt mask; /* (1 << w) - 1, to avoid cc -O bug on HP */
|
||||||
|
register uIntf *p; /* pointer into c[], b[], or v[] */
|
||||||
|
inflate_huft *q; /* points to current table */
|
||||||
|
struct inflate_huft_s r; /* table entry for structure assignment */
|
||||||
|
inflate_huft *u[BMAX]; /* table stack */
|
||||||
|
register int w; /* bits before this table == (l * h) */
|
||||||
|
uInt x[BMAX+1]; /* bit offsets, then code stack */
|
||||||
|
uIntf *xp; /* pointer into x */
|
||||||
|
int y; /* number of dummy codes added */
|
||||||
|
uInt z; /* number of entries in current table */
|
||||||
|
|
||||||
|
|
||||||
|
/* Generate counts for each bit length */
|
||||||
|
p = c;
|
||||||
|
#define C0 *p++ = 0;
|
||||||
|
#define C2 C0 C0 C0 C0
|
||||||
|
#define C4 C2 C2 C2 C2
|
||||||
|
C4 /* clear c[]--assume BMAX+1 is 16 */
|
||||||
|
p = b; i = n;
|
||||||
|
do {
|
||||||
|
c[*p++]++; /* assume all entries <= BMAX */
|
||||||
|
} while (--i);
|
||||||
|
if (c[0] == n) /* null input--all zero length codes */
|
||||||
|
{
|
||||||
|
*t = (inflate_huft *)Z_NULL;
|
||||||
|
*m = 0;
|
||||||
|
return Z_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Find minimum and maximum length, bound *m by those */
|
||||||
|
l = *m;
|
||||||
|
for (j = 1; j <= BMAX; j++)
|
||||||
|
if (c[j])
|
||||||
|
break;
|
||||||
|
k = j; /* minimum code length */
|
||||||
|
if ((uInt)l < j)
|
||||||
|
l = j;
|
||||||
|
for (i = BMAX; i; i--)
|
||||||
|
if (c[i])
|
||||||
|
break;
|
||||||
|
g = i; /* maximum code length */
|
||||||
|
if ((uInt)l > i)
|
||||||
|
l = i;
|
||||||
|
*m = l;
|
||||||
|
|
||||||
|
|
||||||
|
/* Adjust last length count to fill out codes, if needed */
|
||||||
|
for (y = 1 << j; j < i; j++, y <<= 1)
|
||||||
|
if ((y -= c[j]) < 0)
|
||||||
|
return Z_DATA_ERROR;
|
||||||
|
if ((y -= c[i]) < 0)
|
||||||
|
return Z_DATA_ERROR;
|
||||||
|
c[i] += y;
|
||||||
|
|
||||||
|
|
||||||
|
/* Generate starting offsets into the value table for each length */
|
||||||
|
x[1] = j = 0;
|
||||||
|
p = c + 1; xp = x + 2;
|
||||||
|
while (--i) { /* note that i == g from above */
|
||||||
|
*xp++ = (j += *p++);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Make a table of values in order of bit lengths */
|
||||||
|
p = b; i = 0;
|
||||||
|
do {
|
||||||
|
if ((j = *p++) != 0)
|
||||||
|
v[x[j]++] = i;
|
||||||
|
} while (++i < n);
|
||||||
|
n = x[g]; /* set n to length of v */
|
||||||
|
|
||||||
|
|
||||||
|
/* Generate the Huffman codes and for each, make the table entries */
|
||||||
|
x[0] = i = 0; /* first Huffman code is zero */
|
||||||
|
p = v; /* grab values in bit order */
|
||||||
|
h = -1; /* no tables yet--level -1 */
|
||||||
|
w = -l; /* bits decoded == (l * h) */
|
||||||
|
u[0] = (inflate_huft *)Z_NULL; /* just to keep compilers happy */
|
||||||
|
q = (inflate_huft *)Z_NULL; /* ditto */
|
||||||
|
z = 0; /* ditto */
|
||||||
|
|
||||||
|
/* go through the bit lengths (k already is bits in shortest code) */
|
||||||
|
for (; k <= g; k++)
|
||||||
|
{
|
||||||
|
a = c[k];
|
||||||
|
while (a--)
|
||||||
|
{
|
||||||
|
/* here i is the Huffman code of length k bits for value *p */
|
||||||
|
/* make tables up to required level */
|
||||||
|
while (k > w + l)
|
||||||
|
{
|
||||||
|
h++;
|
||||||
|
w += l; /* previous table always l bits */
|
||||||
|
|
||||||
|
/* compute minimum size table less than or equal to l bits */
|
||||||
|
z = g - w;
|
||||||
|
z = z > (uInt)l ? l : z; /* table size upper limit */
|
||||||
|
if ((f = 1 << (j = k - w)) > a + 1) /* try a k-w bit table */
|
||||||
|
{ /* too few codes for k-w bit table */
|
||||||
|
f -= a + 1; /* deduct codes from patterns left */
|
||||||
|
xp = c + k;
|
||||||
|
if (j < z)
|
||||||
|
while (++j < z) /* try smaller tables up to z bits */
|
||||||
|
{
|
||||||
|
if ((f <<= 1) <= *++xp)
|
||||||
|
break; /* enough codes to use up j bits */
|
||||||
|
f -= *xp; /* else deduct codes from patterns */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
z = 1 << j; /* table entries for j-bit table */
|
||||||
|
|
||||||
|
/* allocate new table */
|
||||||
|
if (*hn + z > MANY) /* (note: doesn't matter for fixed) */
|
||||||
|
return Z_DATA_ERROR; /* overflow of MANY */
|
||||||
|
u[h] = q = hp + *hn;
|
||||||
|
*hn += z;
|
||||||
|
|
||||||
|
/* connect to last table, if there is one */
|
||||||
|
if (h)
|
||||||
|
{
|
||||||
|
x[h] = i; /* save pattern for backing up */
|
||||||
|
r.bits = (Byte)l; /* bits to dump before this table */
|
||||||
|
r.exop = (Byte)j; /* bits in this table */
|
||||||
|
j = i >> (w - l);
|
||||||
|
r.base = (uInt)(q - u[h-1] - j); /* offset to this table */
|
||||||
|
u[h-1][j] = r; /* connect to last table */
|
||||||
|
}
|
||||||
|
else
|
||||||
|
*t = q; /* first table is returned result */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* set up table entry in r */
|
||||||
|
r.bits = (Byte)(k - w);
|
||||||
|
if (p >= v + n)
|
||||||
|
r.exop = 128 + 64; /* out of values--invalid code */
|
||||||
|
else if (*p < s)
|
||||||
|
{
|
||||||
|
r.exop = (Byte)(*p < 256 ? 0 : 32 + 64); /* 256 is end-of-block */
|
||||||
|
r.base = *p++; /* simple code is just the value */
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
r.exop = (Byte)(e[*p - s] + 16 + 64);/* non-simple--look up in lists */
|
||||||
|
r.base = d[*p++ - s];
|
||||||
|
}
|
||||||
|
|
||||||
|
/* fill code-like entries with r */
|
||||||
|
f = 1 << (k - w);
|
||||||
|
for (j = i >> w; j < z; j += f)
|
||||||
|
q[j] = r;
|
||||||
|
|
||||||
|
/* backwards increment the k-bit code i */
|
||||||
|
for (j = 1 << (k - 1); i & j; j >>= 1)
|
||||||
|
i ^= j;
|
||||||
|
i ^= j;
|
||||||
|
|
||||||
|
/* backup over finished tables */
|
||||||
|
mask = (1 << w) - 1; /* needed on HP, cc -O bug */
|
||||||
|
while ((i & mask) != x[h])
|
||||||
|
{
|
||||||
|
h--; /* don't need to update q */
|
||||||
|
w -= l;
|
||||||
|
mask = (1 << w) - 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Return Z_BUF_ERROR if we were given an incomplete table */
|
||||||
|
return y != 0 && g != 1 ? Z_BUF_ERROR : Z_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int inflate_trees_bits(c, bb, tb, hp, z)
|
||||||
|
uIntf *c; /* 19 code lengths */
|
||||||
|
uIntf *bb; /* bits tree desired/actual depth */
|
||||||
|
inflate_huft * FAR *tb; /* bits tree result */
|
||||||
|
inflate_huft *hp; /* space for trees */
|
||||||
|
z_streamp z; /* for messages */
|
||||||
|
{
|
||||||
|
int r;
|
||||||
|
uInt hn = 0; /* hufts used in space */
|
||||||
|
uIntf *v; /* work area for huft_build */
|
||||||
|
|
||||||
|
if ((v = (uIntf*)ZALLOC(z, 19, sizeof(uInt))) == Z_NULL)
|
||||||
|
return Z_MEM_ERROR;
|
||||||
|
r = huft_build(c, 19, 19, (uIntf*)Z_NULL, (uIntf*)Z_NULL,
|
||||||
|
tb, bb, hp, &hn, v);
|
||||||
|
if (r == Z_DATA_ERROR)
|
||||||
|
z->msg = (char*)"oversubscribed dynamic bit lengths tree";
|
||||||
|
else if (r == Z_BUF_ERROR || *bb == 0)
|
||||||
|
{
|
||||||
|
z->msg = (char*)"incomplete dynamic bit lengths tree";
|
||||||
|
r = Z_DATA_ERROR;
|
||||||
|
}
|
||||||
|
ZFREE(z, v);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int inflate_trees_dynamic(nl, nd, c, bl, bd, tl, td, hp, z)
|
||||||
|
uInt nl; /* number of literal/length codes */
|
||||||
|
uInt nd; /* number of distance codes */
|
||||||
|
uIntf *c; /* that many (total) code lengths */
|
||||||
|
uIntf *bl; /* literal desired/actual bit depth */
|
||||||
|
uIntf *bd; /* distance desired/actual bit depth */
|
||||||
|
inflate_huft * FAR *tl; /* literal/length tree result */
|
||||||
|
inflate_huft * FAR *td; /* distance tree result */
|
||||||
|
inflate_huft *hp; /* space for trees */
|
||||||
|
z_streamp z; /* for messages */
|
||||||
|
{
|
||||||
|
int r;
|
||||||
|
uInt hn = 0; /* hufts used in space */
|
||||||
|
uIntf *v; /* work area for huft_build */
|
||||||
|
|
||||||
|
/* allocate work area */
|
||||||
|
if ((v = (uIntf*)ZALLOC(z, 288, sizeof(uInt))) == Z_NULL)
|
||||||
|
return Z_MEM_ERROR;
|
||||||
|
|
||||||
|
/* build literal/length tree */
|
||||||
|
r = huft_build(c, nl, 257, cplens, cplext, tl, bl, hp, &hn, v);
|
||||||
|
if (r != Z_OK || *bl == 0)
|
||||||
|
{
|
||||||
|
if (r == Z_DATA_ERROR)
|
||||||
|
z->msg = (char*)"oversubscribed literal/length tree";
|
||||||
|
else if (r != Z_MEM_ERROR)
|
||||||
|
{
|
||||||
|
z->msg = (char*)"incomplete literal/length tree";
|
||||||
|
r = Z_DATA_ERROR;
|
||||||
|
}
|
||||||
|
ZFREE(z, v);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* build distance tree */
|
||||||
|
r = huft_build(c + nl, nd, 0, cpdist, cpdext, td, bd, hp, &hn, v);
|
||||||
|
if (r != Z_OK || (*bd == 0 && nl > 257))
|
||||||
|
{
|
||||||
|
if (r == Z_DATA_ERROR)
|
||||||
|
z->msg = (char*)"oversubscribed distance tree";
|
||||||
|
else if (r == Z_BUF_ERROR) {
|
||||||
|
#ifdef PKZIP_BUG_WORKAROUND
|
||||||
|
r = Z_OK;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
z->msg = (char*)"incomplete distance tree";
|
||||||
|
r = Z_DATA_ERROR;
|
||||||
|
}
|
||||||
|
else if (r != Z_MEM_ERROR)
|
||||||
|
{
|
||||||
|
z->msg = (char*)"empty distance tree with lengths";
|
||||||
|
r = Z_DATA_ERROR;
|
||||||
|
}
|
||||||
|
ZFREE(z, v);
|
||||||
|
return r;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/* done */
|
||||||
|
ZFREE(z, v);
|
||||||
|
return Z_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* build fixed tables only once--keep them here */
|
||||||
|
#ifdef BUILDFIXED
|
||||||
|
local int fixed_built = 0;
|
||||||
|
#define FIXEDH 544 /* number of hufts used by fixed tables */
|
||||||
|
local inflate_huft fixed_mem[FIXEDH];
|
||||||
|
local uInt fixed_bl;
|
||||||
|
local uInt fixed_bd;
|
||||||
|
local inflate_huft *fixed_tl;
|
||||||
|
local inflate_huft *fixed_td;
|
||||||
|
#else
|
||||||
|
#include "inffixed.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
int inflate_trees_fixed(bl, bd, tl, td, z)
|
||||||
|
uIntf *bl; /* literal desired/actual bit depth */
|
||||||
|
uIntf *bd; /* distance desired/actual bit depth */
|
||||||
|
inflate_huft * FAR *tl; /* literal/length tree result */
|
||||||
|
inflate_huft * FAR *td; /* distance tree result */
|
||||||
|
z_streamp z; /* for memory allocation */
|
||||||
|
{
|
||||||
|
#ifdef BUILDFIXED
|
||||||
|
/* build fixed tables if not already */
|
||||||
|
if (!fixed_built)
|
||||||
|
{
|
||||||
|
int k; /* temporary variable */
|
||||||
|
uInt f = 0; /* number of hufts used in fixed_mem */
|
||||||
|
uIntf *c; /* length list for huft_build */
|
||||||
|
uIntf *v; /* work area for huft_build */
|
||||||
|
|
||||||
|
/* allocate memory */
|
||||||
|
if ((c = (uIntf*)ZALLOC(z, 288, sizeof(uInt))) == Z_NULL)
|
||||||
|
return Z_MEM_ERROR;
|
||||||
|
if ((v = (uIntf*)ZALLOC(z, 288, sizeof(uInt))) == Z_NULL)
|
||||||
|
{
|
||||||
|
ZFREE(z, c);
|
||||||
|
return Z_MEM_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* literal table */
|
||||||
|
for (k = 0; k < 144; k++)
|
||||||
|
c[k] = 8;
|
||||||
|
for (; k < 256; k++)
|
||||||
|
c[k] = 9;
|
||||||
|
for (; k < 280; k++)
|
||||||
|
c[k] = 7;
|
||||||
|
for (; k < 288; k++)
|
||||||
|
c[k] = 8;
|
||||||
|
fixed_bl = 9;
|
||||||
|
huft_build(c, 288, 257, cplens, cplext, &fixed_tl, &fixed_bl,
|
||||||
|
fixed_mem, &f, v);
|
||||||
|
|
||||||
|
/* distance table */
|
||||||
|
for (k = 0; k < 30; k++)
|
||||||
|
c[k] = 5;
|
||||||
|
fixed_bd = 5;
|
||||||
|
huft_build(c, 30, 0, cpdist, cpdext, &fixed_td, &fixed_bd,
|
||||||
|
fixed_mem, &f, v);
|
||||||
|
|
||||||
|
/* done */
|
||||||
|
ZFREE(z, v);
|
||||||
|
ZFREE(z, c);
|
||||||
|
fixed_built = 1;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
*bl = fixed_bl;
|
||||||
|
*bd = fixed_bd;
|
||||||
|
*tl = fixed_tl;
|
||||||
|
*td = fixed_td;
|
||||||
|
return Z_OK;
|
||||||
|
}
|
58
zlib/inftrees.h
Normal file
58
zlib/inftrees.h
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
/* inftrees.h -- header to use inftrees.c
|
||||||
|
* Copyright (C) 1995-2002 Mark Adler
|
||||||
|
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* WARNING: this file should *not* be used by applications. It is
|
||||||
|
part of the implementation of the compression library and is
|
||||||
|
subject to change. Applications should only use zlib.h.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Huffman code lookup table entry--this entry is four bytes for machines
|
||||||
|
that have 16-bit pointers (e.g. PC's in the small or medium model). */
|
||||||
|
|
||||||
|
typedef struct inflate_huft_s FAR inflate_huft;
|
||||||
|
|
||||||
|
struct inflate_huft_s {
|
||||||
|
union {
|
||||||
|
struct {
|
||||||
|
Byte Exop; /* number of extra bits or operation */
|
||||||
|
Byte Bits; /* number of bits in this code or subcode */
|
||||||
|
} what;
|
||||||
|
uInt pad; /* pad structure to a power of 2 (4 bytes for */
|
||||||
|
} word; /* 16-bit, 8 bytes for 32-bit int's) */
|
||||||
|
uInt base; /* literal, length base, distance base,
|
||||||
|
or table offset */
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Maximum size of dynamic tree. The maximum found in a long but non-
|
||||||
|
exhaustive search was 1004 huft structures (850 for length/literals
|
||||||
|
and 154 for distances, the latter actually the result of an
|
||||||
|
exhaustive search). The actual maximum is not known, but the
|
||||||
|
value below is more than safe. */
|
||||||
|
#define MANY 1440
|
||||||
|
|
||||||
|
extern int inflate_trees_bits OF((
|
||||||
|
uIntf *, /* 19 code lengths */
|
||||||
|
uIntf *, /* bits tree desired/actual depth */
|
||||||
|
inflate_huft * FAR *, /* bits tree result */
|
||||||
|
inflate_huft *, /* space for trees */
|
||||||
|
z_streamp)); /* for messages */
|
||||||
|
|
||||||
|
extern int inflate_trees_dynamic OF((
|
||||||
|
uInt, /* number of literal/length codes */
|
||||||
|
uInt, /* number of distance codes */
|
||||||
|
uIntf *, /* that many (total) code lengths */
|
||||||
|
uIntf *, /* literal desired/actual bit depth */
|
||||||
|
uIntf *, /* distance desired/actual bit depth */
|
||||||
|
inflate_huft * FAR *, /* literal/length tree result */
|
||||||
|
inflate_huft * FAR *, /* distance tree result */
|
||||||
|
inflate_huft *, /* space for trees */
|
||||||
|
z_streamp)); /* for messages */
|
||||||
|
|
||||||
|
extern int inflate_trees_fixed OF((
|
||||||
|
uIntf *, /* literal desired/actual bit depth */
|
||||||
|
uIntf *, /* distance desired/actual bit depth */
|
||||||
|
inflate_huft * FAR *, /* literal/length tree result */
|
||||||
|
inflate_huft * FAR *, /* distance tree result */
|
||||||
|
z_streamp)); /* for memory allocation */
|
87
zlib/infutil.c
Normal file
87
zlib/infutil.c
Normal file
|
@ -0,0 +1,87 @@
|
||||||
|
/* inflate_util.c -- data and routines common to blocks and codes
|
||||||
|
* Copyright (C) 1995-2002 Mark Adler
|
||||||
|
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "zutil.h"
|
||||||
|
#include "infblock.h"
|
||||||
|
#include "inftrees.h"
|
||||||
|
#include "infcodes.h"
|
||||||
|
#include "infutil.h"
|
||||||
|
|
||||||
|
struct inflate_codes_state {int dummy;}; /* for buggy compilers */
|
||||||
|
|
||||||
|
/* And'ing with mask[n] masks the lower n bits */
|
||||||
|
uInt inflate_mask[17] = {
|
||||||
|
0x0000,
|
||||||
|
0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff,
|
||||||
|
0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/* copy as much as possible from the sliding window to the output area */
|
||||||
|
int inflate_flush(s, z, r)
|
||||||
|
inflate_blocks_statef *s;
|
||||||
|
z_streamp z;
|
||||||
|
int r;
|
||||||
|
{
|
||||||
|
uInt n;
|
||||||
|
Bytef *p;
|
||||||
|
Bytef *q;
|
||||||
|
|
||||||
|
/* local copies of source and destination pointers */
|
||||||
|
p = z->next_out;
|
||||||
|
q = s->read;
|
||||||
|
|
||||||
|
/* compute number of bytes to copy as far as end of window */
|
||||||
|
n = (uInt)((q <= s->write ? s->write : s->end) - q);
|
||||||
|
if (n > z->avail_out) n = z->avail_out;
|
||||||
|
if (n && r == Z_BUF_ERROR) r = Z_OK;
|
||||||
|
|
||||||
|
/* update counters */
|
||||||
|
z->avail_out -= n;
|
||||||
|
z->total_out += n;
|
||||||
|
|
||||||
|
/* update check information */
|
||||||
|
if (s->checkfn != Z_NULL)
|
||||||
|
z->adler = s->check = (*s->checkfn)(s->check, q, n);
|
||||||
|
|
||||||
|
/* copy as far as end of window */
|
||||||
|
zmemcpy(p, q, n);
|
||||||
|
p += n;
|
||||||
|
q += n;
|
||||||
|
|
||||||
|
/* see if more to copy at beginning of window */
|
||||||
|
if (q == s->end)
|
||||||
|
{
|
||||||
|
/* wrap pointers */
|
||||||
|
q = s->window;
|
||||||
|
if (s->write == s->end)
|
||||||
|
s->write = s->window;
|
||||||
|
|
||||||
|
/* compute bytes to copy */
|
||||||
|
n = (uInt)(s->write - q);
|
||||||
|
if (n > z->avail_out) n = z->avail_out;
|
||||||
|
if (n && r == Z_BUF_ERROR) r = Z_OK;
|
||||||
|
|
||||||
|
/* update counters */
|
||||||
|
z->avail_out -= n;
|
||||||
|
z->total_out += n;
|
||||||
|
|
||||||
|
/* update check information */
|
||||||
|
if (s->checkfn != Z_NULL)
|
||||||
|
z->adler = s->check = (*s->checkfn)(s->check, q, n);
|
||||||
|
|
||||||
|
/* copy */
|
||||||
|
zmemcpy(p, q, n);
|
||||||
|
p += n;
|
||||||
|
q += n;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* update pointers */
|
||||||
|
z->next_out = p;
|
||||||
|
s->read = q;
|
||||||
|
|
||||||
|
/* done */
|
||||||
|
return r;
|
||||||
|
}
|
98
zlib/infutil.h
Normal file
98
zlib/infutil.h
Normal file
|
@ -0,0 +1,98 @@
|
||||||
|
/* infutil.h -- types and macros common to blocks and codes
|
||||||
|
* Copyright (C) 1995-2002 Mark Adler
|
||||||
|
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* WARNING: this file should *not* be used by applications. It is
|
||||||
|
part of the implementation of the compression library and is
|
||||||
|
subject to change. Applications should only use zlib.h.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _INFUTIL_H
|
||||||
|
#define _INFUTIL_H
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
TYPE, /* get type bits (3, including end bit) */
|
||||||
|
LENS, /* get lengths for stored */
|
||||||
|
STORED, /* processing stored block */
|
||||||
|
TABLE, /* get table lengths */
|
||||||
|
BTREE, /* get bit lengths tree for a dynamic block */
|
||||||
|
DTREE, /* get length, distance trees for a dynamic block */
|
||||||
|
CODES, /* processing fixed or dynamic block */
|
||||||
|
DRY, /* output remaining window bytes */
|
||||||
|
DONE, /* finished last block, done */
|
||||||
|
BAD} /* got a data error--stuck here */
|
||||||
|
inflate_block_mode;
|
||||||
|
|
||||||
|
/* inflate blocks semi-private state */
|
||||||
|
struct inflate_blocks_state {
|
||||||
|
|
||||||
|
/* mode */
|
||||||
|
inflate_block_mode mode; /* current inflate_block mode */
|
||||||
|
|
||||||
|
/* mode dependent information */
|
||||||
|
union {
|
||||||
|
uInt left; /* if STORED, bytes left to copy */
|
||||||
|
struct {
|
||||||
|
uInt table; /* table lengths (14 bits) */
|
||||||
|
uInt index; /* index into blens (or border) */
|
||||||
|
uIntf *blens; /* bit lengths of codes */
|
||||||
|
uInt bb; /* bit length tree depth */
|
||||||
|
inflate_huft *tb; /* bit length decoding tree */
|
||||||
|
} trees; /* if DTREE, decoding info for trees */
|
||||||
|
struct {
|
||||||
|
inflate_codes_statef
|
||||||
|
*codes;
|
||||||
|
} decode; /* if CODES, current state */
|
||||||
|
} sub; /* submode */
|
||||||
|
uInt last; /* true if this block is the last block */
|
||||||
|
|
||||||
|
/* mode independent information */
|
||||||
|
uInt bitk; /* bits in bit buffer */
|
||||||
|
uLong bitb; /* bit buffer */
|
||||||
|
inflate_huft *hufts; /* single malloc for tree space */
|
||||||
|
Bytef *window; /* sliding window */
|
||||||
|
Bytef *end; /* one byte after sliding window */
|
||||||
|
Bytef *read; /* window read pointer */
|
||||||
|
Bytef *write; /* window write pointer */
|
||||||
|
check_func checkfn; /* check function */
|
||||||
|
uLong check; /* check on output */
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/* defines for inflate input/output */
|
||||||
|
/* update pointers and return */
|
||||||
|
#define UPDBITS {s->bitb=b;s->bitk=k;}
|
||||||
|
#define UPDIN {z->avail_in=n;z->total_in+=p-z->next_in;z->next_in=p;}
|
||||||
|
#define UPDOUT {s->write=q;}
|
||||||
|
#define UPDATE {UPDBITS UPDIN UPDOUT}
|
||||||
|
#define LEAVE {UPDATE return inflate_flush(s,z,r);}
|
||||||
|
/* get bytes and bits */
|
||||||
|
#define LOADIN {p=z->next_in;n=z->avail_in;b=s->bitb;k=s->bitk;}
|
||||||
|
#define NEEDBYTE {if(n)r=Z_OK;else LEAVE}
|
||||||
|
#define NEXTBYTE (n--,*p++)
|
||||||
|
#define NEEDBITS(j) {while(k<(j)){NEEDBYTE;b|=((uLong)NEXTBYTE)<<k;k+=8;}}
|
||||||
|
#define DUMPBITS(j) {b>>=(j);k-=(j);}
|
||||||
|
/* output bytes */
|
||||||
|
#define WAVAIL (uInt)(q<s->read?s->read-q-1:s->end-q)
|
||||||
|
#define LOADOUT {q=s->write;m=(uInt)WAVAIL;}
|
||||||
|
#define WRAP {if(q==s->end&&s->read!=s->window){q=s->window;m=(uInt)WAVAIL;}}
|
||||||
|
#define FLUSH {UPDOUT r=inflate_flush(s,z,r); LOADOUT}
|
||||||
|
#define NEEDOUT {if(m==0){WRAP if(m==0){FLUSH WRAP if(m==0) LEAVE}}r=Z_OK;}
|
||||||
|
#define OUTBYTE(a) {*q++=(Byte)(a);m--;}
|
||||||
|
/* load local pointers */
|
||||||
|
#define LOAD {LOADIN LOADOUT}
|
||||||
|
|
||||||
|
/* masks for lower bits (size given to avoid silly warnings with Visual C++) */
|
||||||
|
extern uInt inflate_mask[17];
|
||||||
|
|
||||||
|
/* copy as much as possible from the sliding window to the output area */
|
||||||
|
extern int inflate_flush OF((
|
||||||
|
inflate_blocks_statef *,
|
||||||
|
z_streamp ,
|
||||||
|
int));
|
||||||
|
|
||||||
|
struct internal_state {int dummy;}; /* for buggy compilers */
|
||||||
|
|
||||||
|
#endif
|
280
zlib/zconf.h
Normal file
280
zlib/zconf.h
Normal file
|
@ -0,0 +1,280 @@
|
||||||
|
/* zconf.h -- configuration of the zlib compression library
|
||||||
|
* Copyright (C) 1995-2002 Jean-loup Gailly.
|
||||||
|
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* @(#) $Id$ */
|
||||||
|
|
||||||
|
#ifndef _ZCONF_H
|
||||||
|
#define _ZCONF_H
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If you *really* need a unique prefix for all types and library functions,
|
||||||
|
* compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
|
||||||
|
*/
|
||||||
|
#ifdef Z_PREFIX
|
||||||
|
# define deflateInit_ z_deflateInit_
|
||||||
|
# define deflate z_deflate
|
||||||
|
# define deflateEnd z_deflateEnd
|
||||||
|
# define inflateInit_ z_inflateInit_
|
||||||
|
# define inflate z_inflate
|
||||||
|
# define inflateEnd z_inflateEnd
|
||||||
|
# define deflateInit2_ z_deflateInit2_
|
||||||
|
# define deflateSetDictionary z_deflateSetDictionary
|
||||||
|
# define deflateCopy z_deflateCopy
|
||||||
|
# define deflateReset z_deflateReset
|
||||||
|
# define deflateParams z_deflateParams
|
||||||
|
# define inflateInit2_ z_inflateInit2_
|
||||||
|
# define inflateSetDictionary z_inflateSetDictionary
|
||||||
|
# define inflateSync z_inflateSync
|
||||||
|
# define inflateSyncPoint z_inflateSyncPoint
|
||||||
|
# define inflateReset z_inflateReset
|
||||||
|
# define compress z_compress
|
||||||
|
# define compress2 z_compress2
|
||||||
|
# define uncompress z_uncompress
|
||||||
|
# define adler32 z_adler32
|
||||||
|
# define crc32 z_crc32
|
||||||
|
# define get_crc_table z_get_crc_table
|
||||||
|
|
||||||
|
# define Byte z_Byte
|
||||||
|
# define uInt z_uInt
|
||||||
|
# define uLong z_uLong
|
||||||
|
# define Bytef z_Bytef
|
||||||
|
# define charf z_charf
|
||||||
|
# define intf z_intf
|
||||||
|
# define uIntf z_uIntf
|
||||||
|
# define uLongf z_uLongf
|
||||||
|
# define voidpf z_voidpf
|
||||||
|
# define voidp z_voidp
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32)
|
||||||
|
# define WIN32
|
||||||
|
#endif
|
||||||
|
#if defined(__GNUC__) || defined(WIN32) || defined(__386__) || defined(i386)
|
||||||
|
# ifndef __32BIT__
|
||||||
|
# define __32BIT__
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
#if defined(__MSDOS__) && !defined(MSDOS)
|
||||||
|
# define MSDOS
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Compile with -DMAXSEG_64K if the alloc function cannot allocate more
|
||||||
|
* than 64k bytes at a time (needed on systems with 16-bit int).
|
||||||
|
*/
|
||||||
|
#if defined(MSDOS) && !defined(__32BIT__)
|
||||||
|
# define MAXSEG_64K
|
||||||
|
#endif
|
||||||
|
#ifdef MSDOS
|
||||||
|
# define UNALIGNED_OK
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if (defined(MSDOS) || defined(_WINDOWS) || defined(WIN32)) && !defined(STDC)
|
||||||
|
# define STDC
|
||||||
|
#endif
|
||||||
|
#if defined(__STDC__) || defined(__cplusplus) || defined(__OS2__)
|
||||||
|
# ifndef STDC
|
||||||
|
# define STDC
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef STDC
|
||||||
|
# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
|
||||||
|
# define const
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Some Mac compilers merge all .h files incorrectly: */
|
||||||
|
#if defined(__MWERKS__) || defined(applec) ||defined(THINK_C) ||defined(__SC__)
|
||||||
|
# define NO_DUMMY_DECL
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Old Borland C incorrectly complains about missing returns: */
|
||||||
|
#if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
|
||||||
|
# define NEED_DUMMY_RETURN
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* Maximum value for memLevel in deflateInit2 */
|
||||||
|
#ifndef MAX_MEM_LEVEL
|
||||||
|
# ifdef MAXSEG_64K
|
||||||
|
# define MAX_MEM_LEVEL 8
|
||||||
|
# else
|
||||||
|
# define MAX_MEM_LEVEL 9
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Maximum value for windowBits in deflateInit2 and inflateInit2.
|
||||||
|
* WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files
|
||||||
|
* created by gzip. (Files created by minigzip can still be extracted by
|
||||||
|
* gzip.)
|
||||||
|
*/
|
||||||
|
#ifndef MAX_WBITS
|
||||||
|
# define MAX_WBITS 15 /* 32K LZ77 window */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* The memory requirements for deflate are (in bytes):
|
||||||
|
(1 << (windowBits+2)) + (1 << (memLevel+9))
|
||||||
|
that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values)
|
||||||
|
plus a few kilobytes for small objects. For example, if you want to reduce
|
||||||
|
the default memory requirements from 256K to 128K, compile with
|
||||||
|
make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
|
||||||
|
Of course this will generally degrade compression (there's no free lunch).
|
||||||
|
|
||||||
|
The memory requirements for inflate are (in bytes) 1 << windowBits
|
||||||
|
that is, 32K for windowBits=15 (default value) plus a few kilobytes
|
||||||
|
for small objects.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Type declarations */
|
||||||
|
|
||||||
|
#ifndef OF /* function prototypes */
|
||||||
|
# ifdef STDC
|
||||||
|
# define OF(args) args
|
||||||
|
# else
|
||||||
|
# define OF(args) ()
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* The following definitions for FAR are needed only for MSDOS mixed
|
||||||
|
* model programming (small or medium model with some far allocations).
|
||||||
|
* This was tested only with MSC; for other MSDOS compilers you may have
|
||||||
|
* to define NO_MEMCPY in zutil.h. If you don't need the mixed model,
|
||||||
|
* just define FAR to be empty.
|
||||||
|
*/
|
||||||
|
#if (defined(M_I86SM) || defined(M_I86MM)) && !defined(__32BIT__)
|
||||||
|
/* MSC small or medium model */
|
||||||
|
# define SMALL_MEDIUM
|
||||||
|
# ifdef _MSC_VER
|
||||||
|
# define FAR _far
|
||||||
|
# else
|
||||||
|
# define FAR far
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
#if defined(__BORLANDC__) && (defined(__SMALL__) || defined(__MEDIUM__))
|
||||||
|
# ifndef __32BIT__
|
||||||
|
# define SMALL_MEDIUM
|
||||||
|
# define FAR _far
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Compile with -DZLIB_DLL for Windows DLL support */
|
||||||
|
#if defined(ZLIB_DLL)
|
||||||
|
# if defined(_WINDOWS) || defined(WINDOWS)
|
||||||
|
# ifdef FAR
|
||||||
|
# undef FAR
|
||||||
|
# endif
|
||||||
|
# include <windows.h>
|
||||||
|
# define ZEXPORT WINAPI
|
||||||
|
# define ZEXTERN __declspec(dllexport) // dll export 를 위해서 추가..
|
||||||
|
# ifdef WIN32
|
||||||
|
# define ZEXPORTVA WINAPIV
|
||||||
|
# else
|
||||||
|
# define ZEXPORTVA FAR _cdecl _export
|
||||||
|
# endif
|
||||||
|
# endif
|
||||||
|
# if defined (__BORLANDC__)
|
||||||
|
# if (__BORLANDC__ >= 0x0500) && defined (WIN32)
|
||||||
|
# include <windows.h>
|
||||||
|
# define ZEXPORT __declspec(dllexport) WINAPI
|
||||||
|
# define ZEXPORTRVA __declspec(dllexport) WINAPIV
|
||||||
|
# else
|
||||||
|
# if defined (_Windows) && defined (__DLL__)
|
||||||
|
# define ZEXPORT _export
|
||||||
|
# define ZEXPORTVA _export
|
||||||
|
# endif
|
||||||
|
# endif
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined (__BEOS__)
|
||||||
|
# if defined (ZLIB_DLL)
|
||||||
|
# define ZEXTERN extern __declspec(dllexport)
|
||||||
|
# else
|
||||||
|
# define ZEXTERN extern __declspec(dllimport)
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef ZEXPORT
|
||||||
|
# define ZEXPORT
|
||||||
|
#endif
|
||||||
|
#ifndef ZEXPORTVA
|
||||||
|
# define ZEXPORTVA
|
||||||
|
#endif
|
||||||
|
#ifndef ZEXTERN
|
||||||
|
# define ZEXTERN ///extern STATIC lib 를 위해서 막아버림..
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef FAR
|
||||||
|
# define FAR
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !defined(MACOS) && !defined(TARGET_OS_MAC)
|
||||||
|
typedef unsigned char Byte; /* 8 bits */
|
||||||
|
#endif
|
||||||
|
typedef unsigned int uInt; /* 16 bits or more */
|
||||||
|
typedef unsigned long uLong; /* 32 bits or more */
|
||||||
|
|
||||||
|
#ifdef SMALL_MEDIUM
|
||||||
|
/* Borland C/C++ and some old MSC versions ignore FAR inside typedef */
|
||||||
|
# define Bytef Byte FAR
|
||||||
|
#else
|
||||||
|
typedef Byte FAR Bytef;
|
||||||
|
#endif
|
||||||
|
typedef char FAR charf;
|
||||||
|
typedef int FAR intf;
|
||||||
|
typedef uInt FAR uIntf;
|
||||||
|
typedef uLong FAR uLongf;
|
||||||
|
|
||||||
|
#ifdef STDC
|
||||||
|
typedef void FAR *voidpf;
|
||||||
|
typedef void *voidp;
|
||||||
|
#else
|
||||||
|
typedef Byte FAR *voidpf;
|
||||||
|
typedef Byte *voidp;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_UNISTD_H
|
||||||
|
# include <sys/types.h> /* for off_t */
|
||||||
|
# include <unistd.h> /* for SEEK_* and off_t */
|
||||||
|
# define z_off_t off_t
|
||||||
|
#endif
|
||||||
|
#ifndef SEEK_SET
|
||||||
|
# define SEEK_SET 0 /* Seek from beginning of file. */
|
||||||
|
# define SEEK_CUR 1 /* Seek from current position. */
|
||||||
|
# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
|
||||||
|
#endif
|
||||||
|
#ifndef z_off_t
|
||||||
|
# define z_off_t long
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* MVS linker does not support external names larger than 8 bytes */
|
||||||
|
#if defined(__MVS__)
|
||||||
|
# pragma map(deflateInit_,"DEIN")
|
||||||
|
# pragma map(deflateInit2_,"DEIN2")
|
||||||
|
# pragma map(deflateEnd,"DEEND")
|
||||||
|
# pragma map(inflateInit_,"ININ")
|
||||||
|
# pragma map(inflateInit2_,"ININ2")
|
||||||
|
# pragma map(inflateEnd,"INEND")
|
||||||
|
# pragma map(inflateSync,"INSY")
|
||||||
|
# pragma map(inflateSetDictionary,"INSEDI")
|
||||||
|
# pragma map(inflate_blocks,"INBL")
|
||||||
|
# pragma map(inflate_blocks_new,"INBLNE")
|
||||||
|
# pragma map(inflate_blocks_free,"INBLFR")
|
||||||
|
# pragma map(inflate_blocks_reset,"INBLRE")
|
||||||
|
# pragma map(inflate_codes_free,"INCOFR")
|
||||||
|
# pragma map(inflate_codes,"INCO")
|
||||||
|
# pragma map(inflate_fast,"INFA")
|
||||||
|
# pragma map(inflate_flush,"INFLU")
|
||||||
|
# pragma map(inflate_mask,"INMA")
|
||||||
|
# pragma map(inflate_set_dictionary,"INSEDI2")
|
||||||
|
# pragma map(inflate_copyright,"INCOPY")
|
||||||
|
# pragma map(inflate_trees_bits,"INTRBI")
|
||||||
|
# pragma map(inflate_trees_dynamic,"INTRDY")
|
||||||
|
# pragma map(inflate_trees_fixed,"INTRFI")
|
||||||
|
# pragma map(inflate_trees_free,"INTRFR")
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* _ZCONF_H */
|
888
zlib/zlib.h
Normal file
888
zlib/zlib.h
Normal file
|
@ -0,0 +1,888 @@
|
||||||
|
/* zlib.h -- interface of the 'zlib' general purpose compression library
|
||||||
|
version 1.1.4, March 11th, 2002
|
||||||
|
|
||||||
|
Copyright (C) 1995-2002 Jean-loup Gailly and Mark Adler
|
||||||
|
|
||||||
|
This software is provided 'as-is', without any express or implied
|
||||||
|
warranty. In no event will the authors be held liable for any damages
|
||||||
|
arising from the use of this software.
|
||||||
|
|
||||||
|
Permission is granted to anyone to use this software for any purpose,
|
||||||
|
including commercial applications, and to alter it and redistribute it
|
||||||
|
freely, subject to the following restrictions:
|
||||||
|
|
||||||
|
1. The origin of this software must not be misrepresented; you must not
|
||||||
|
claim that you wrote the original software. If you use this software
|
||||||
|
in a product, an acknowledgment in the product documentation would be
|
||||||
|
appreciated but is not required.
|
||||||
|
2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
misrepresented as being the original software.
|
||||||
|
3. This notice may not be removed or altered from any source distribution.
|
||||||
|
|
||||||
|
Jean-loup Gailly Mark Adler
|
||||||
|
jloup@gzip.org madler@alumni.caltech.edu
|
||||||
|
|
||||||
|
|
||||||
|
The data format used by the zlib library is described by RFCs (Request for
|
||||||
|
Comments) 1950 to 1952 in the files ftp://ds.internic.net/rfc/rfc1950.txt
|
||||||
|
(zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format).
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _ZLIB_H
|
||||||
|
#define _ZLIB_H
|
||||||
|
|
||||||
|
#include "zconf.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define ZLIB_VERSION "1.1.4"
|
||||||
|
|
||||||
|
/*
|
||||||
|
The 'zlib' compression library provides in-memory compression and
|
||||||
|
decompression functions, including integrity checks of the uncompressed
|
||||||
|
data. This version of the library supports only one compression method
|
||||||
|
(deflation) but other algorithms will be added later and will have the same
|
||||||
|
stream interface.
|
||||||
|
|
||||||
|
Compression can be done in a single step if the buffers are large
|
||||||
|
enough (for example if an input file is mmap'ed), or can be done by
|
||||||
|
repeated calls of the compression function. In the latter case, the
|
||||||
|
application must provide more input and/or consume the output
|
||||||
|
(providing more output space) before each call.
|
||||||
|
|
||||||
|
The library also supports reading and writing files in gzip (.gz) format
|
||||||
|
with an interface similar to that of stdio.
|
||||||
|
|
||||||
|
The library does not install any signal handler. The decoder checks
|
||||||
|
the consistency of the compressed data, so the library should never
|
||||||
|
crash even in case of corrupted input.
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
|
||||||
|
typedef void (*free_func) OF((voidpf opaque, voidpf address));
|
||||||
|
|
||||||
|
struct internal_state;
|
||||||
|
|
||||||
|
typedef struct z_stream_s {
|
||||||
|
Bytef *next_in; /* next input byte */
|
||||||
|
uInt avail_in; /* number of bytes available at next_in */
|
||||||
|
uLong total_in; /* total nb of input bytes read so far */
|
||||||
|
|
||||||
|
Bytef *next_out; /* next output byte should be put there */
|
||||||
|
uInt avail_out; /* remaining free space at next_out */
|
||||||
|
uLong total_out; /* total nb of bytes output so far */
|
||||||
|
|
||||||
|
char *msg; /* last error message, NULL if no error */
|
||||||
|
struct internal_state FAR *state; /* not visible by applications */
|
||||||
|
|
||||||
|
alloc_func zalloc; /* used to allocate the internal state */
|
||||||
|
free_func zfree; /* used to free the internal state */
|
||||||
|
voidpf opaque; /* private data object passed to zalloc and zfree */
|
||||||
|
|
||||||
|
int data_type; /* best guess about the data type: ascii or binary */
|
||||||
|
uLong adler; /* adler32 value of the uncompressed data */
|
||||||
|
uLong reserved; /* reserved for future use */
|
||||||
|
} z_stream;
|
||||||
|
|
||||||
|
typedef z_stream FAR *z_streamp;
|
||||||
|
|
||||||
|
/*
|
||||||
|
The application must update next_in and avail_in when avail_in has
|
||||||
|
dropped to zero. It must update next_out and avail_out when avail_out
|
||||||
|
has dropped to zero. The application must initialize zalloc, zfree and
|
||||||
|
opaque before calling the init function. All other fields are set by the
|
||||||
|
compression library and must not be updated by the application.
|
||||||
|
|
||||||
|
The opaque value provided by the application will be passed as the first
|
||||||
|
parameter for calls of zalloc and zfree. This can be useful for custom
|
||||||
|
memory management. The compression library attaches no meaning to the
|
||||||
|
opaque value.
|
||||||
|
|
||||||
|
zalloc must return Z_NULL if there is not enough memory for the object.
|
||||||
|
If zlib is used in a multi-threaded application, zalloc and zfree must be
|
||||||
|
thread safe.
|
||||||
|
|
||||||
|
On 16-bit systems, the functions zalloc and zfree must be able to allocate
|
||||||
|
exactly 65536 bytes, but will not be required to allocate more than this
|
||||||
|
if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS,
|
||||||
|
pointers returned by zalloc for objects of exactly 65536 bytes *must*
|
||||||
|
have their offset normalized to zero. The default allocation function
|
||||||
|
provided by this library ensures this (see zutil.c). To reduce memory
|
||||||
|
requirements and avoid any allocation of 64K objects, at the expense of
|
||||||
|
compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h).
|
||||||
|
|
||||||
|
The fields total_in and total_out can be used for statistics or
|
||||||
|
progress reports. After compression, total_in holds the total size of
|
||||||
|
the uncompressed data and may be saved for use in the decompressor
|
||||||
|
(particularly if the decompressor wants to decompress everything in
|
||||||
|
a single step).
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* constants */
|
||||||
|
|
||||||
|
#define Z_NO_FLUSH 0
|
||||||
|
#define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */
|
||||||
|
#define Z_SYNC_FLUSH 2
|
||||||
|
#define Z_FULL_FLUSH 3
|
||||||
|
#define Z_FINISH 4
|
||||||
|
/* Allowed flush values; see deflate() below for details */
|
||||||
|
|
||||||
|
#define Z_OK 0
|
||||||
|
#define Z_STREAM_END 1
|
||||||
|
#define Z_NEED_DICT 2
|
||||||
|
#define Z_ERRNO (-1)
|
||||||
|
#define Z_STREAM_ERROR (-2)
|
||||||
|
#define Z_DATA_ERROR (-3)
|
||||||
|
#define Z_MEM_ERROR (-4)
|
||||||
|
#define Z_BUF_ERROR (-5)
|
||||||
|
#define Z_VERSION_ERROR (-6)
|
||||||
|
/* Return codes for the compression/decompression functions. Negative
|
||||||
|
* values are errors, positive values are used for special but normal events.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define Z_NO_COMPRESSION 0
|
||||||
|
#define Z_BEST_SPEED 1
|
||||||
|
#define Z_BEST_COMPRESSION 9
|
||||||
|
#define Z_DEFAULT_COMPRESSION (-1)
|
||||||
|
/* compression levels */
|
||||||
|
|
||||||
|
#define Z_FILTERED 1
|
||||||
|
#define Z_HUFFMAN_ONLY 2
|
||||||
|
#define Z_DEFAULT_STRATEGY 0
|
||||||
|
/* compression strategy; see deflateInit2() below for details */
|
||||||
|
|
||||||
|
#define Z_BINARY 0
|
||||||
|
#define Z_ASCII 1
|
||||||
|
#define Z_UNKNOWN 2
|
||||||
|
/* Possible values of the data_type field */
|
||||||
|
|
||||||
|
#define Z_DEFLATED 8
|
||||||
|
/* The deflate compression method (the only one supported in this version) */
|
||||||
|
|
||||||
|
#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */
|
||||||
|
|
||||||
|
#define zlib_version zlibVersion()
|
||||||
|
/* for compatibility with versions < 1.0.2 */
|
||||||
|
|
||||||
|
/* basic functions */
|
||||||
|
|
||||||
|
ZEXTERN const char * ZEXPORT zlibVersion OF((void));
|
||||||
|
/* The application can compare zlibVersion and ZLIB_VERSION for consistency.
|
||||||
|
If the first character differs, the library code actually used is
|
||||||
|
not compatible with the zlib.h header file used by the application.
|
||||||
|
This check is automatically made by deflateInit and inflateInit.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level));
|
||||||
|
|
||||||
|
Initializes the internal stream state for compression. The fields
|
||||||
|
zalloc, zfree and opaque must be initialized before by the caller.
|
||||||
|
If zalloc and zfree are set to Z_NULL, deflateInit updates them to
|
||||||
|
use default allocation functions.
|
||||||
|
|
||||||
|
The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9:
|
||||||
|
1 gives best speed, 9 gives best compression, 0 gives no compression at
|
||||||
|
all (the input data is simply copied a block at a time).
|
||||||
|
Z_DEFAULT_COMPRESSION requests a default compromise between speed and
|
||||||
|
compression (currently equivalent to level 6).
|
||||||
|
|
||||||
|
deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not
|
||||||
|
enough memory, Z_STREAM_ERROR if level is not a valid compression level,
|
||||||
|
Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible
|
||||||
|
with the version assumed by the caller (ZLIB_VERSION).
|
||||||
|
msg is set to null if there is no error message. deflateInit does not
|
||||||
|
perform any compression: this will be done by deflate().
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
|
||||||
|
/*
|
||||||
|
deflate compresses as much data as possible, and stops when the input
|
||||||
|
buffer becomes empty or the output buffer becomes full. It may introduce some
|
||||||
|
output latency (reading input without producing any output) except when
|
||||||
|
forced to flush.
|
||||||
|
|
||||||
|
The detailed semantics are as follows. deflate performs one or both of the
|
||||||
|
following actions:
|
||||||
|
|
||||||
|
- Compress more input starting at next_in and update next_in and avail_in
|
||||||
|
accordingly. If not all input can be processed (because there is not
|
||||||
|
enough room in the output buffer), next_in and avail_in are updated and
|
||||||
|
processing will resume at this point for the next call of deflate().
|
||||||
|
|
||||||
|
- Provide more output starting at next_out and update next_out and avail_out
|
||||||
|
accordingly. This action is forced if the parameter flush is non zero.
|
||||||
|
Forcing flush frequently degrades the compression ratio, so this parameter
|
||||||
|
should be set only when necessary (in interactive applications).
|
||||||
|
Some output may be provided even if flush is not set.
|
||||||
|
|
||||||
|
Before the call of deflate(), the application should ensure that at least
|
||||||
|
one of the actions is possible, by providing more input and/or consuming
|
||||||
|
more output, and updating avail_in or avail_out accordingly; avail_out
|
||||||
|
should never be zero before the call. The application can consume the
|
||||||
|
compressed output when it wants, for example when the output buffer is full
|
||||||
|
(avail_out == 0), or after each call of deflate(). If deflate returns Z_OK
|
||||||
|
and with zero avail_out, it must be called again after making room in the
|
||||||
|
output buffer because there might be more output pending.
|
||||||
|
|
||||||
|
If the parameter flush is set to Z_SYNC_FLUSH, all pending output is
|
||||||
|
flushed to the output buffer and the output is aligned on a byte boundary, so
|
||||||
|
that the decompressor can get all input data available so far. (In particular
|
||||||
|
avail_in is zero after the call if enough output space has been provided
|
||||||
|
before the call.) Flushing may degrade compression for some compression
|
||||||
|
algorithms and so it should be used only when necessary.
|
||||||
|
|
||||||
|
If flush is set to Z_FULL_FLUSH, all output is flushed as with
|
||||||
|
Z_SYNC_FLUSH, and the compression state is reset so that decompression can
|
||||||
|
restart from this point if previous compressed data has been damaged or if
|
||||||
|
random access is desired. Using Z_FULL_FLUSH too often can seriously degrade
|
||||||
|
the compression.
|
||||||
|
|
||||||
|
If deflate returns with avail_out == 0, this function must be called again
|
||||||
|
with the same value of the flush parameter and more output space (updated
|
||||||
|
avail_out), until the flush is complete (deflate returns with non-zero
|
||||||
|
avail_out).
|
||||||
|
|
||||||
|
If the parameter flush is set to Z_FINISH, pending input is processed,
|
||||||
|
pending output is flushed and deflate returns with Z_STREAM_END if there
|
||||||
|
was enough output space; if deflate returns with Z_OK, this function must be
|
||||||
|
called again with Z_FINISH and more output space (updated avail_out) but no
|
||||||
|
more input data, until it returns with Z_STREAM_END or an error. After
|
||||||
|
deflate has returned Z_STREAM_END, the only possible operations on the
|
||||||
|
stream are deflateReset or deflateEnd.
|
||||||
|
|
||||||
|
Z_FINISH can be used immediately after deflateInit if all the compression
|
||||||
|
is to be done in a single step. In this case, avail_out must be at least
|
||||||
|
0.1% larger than avail_in plus 12 bytes. If deflate does not return
|
||||||
|
Z_STREAM_END, then it must be called again as described above.
|
||||||
|
|
||||||
|
deflate() sets strm->adler to the adler32 checksum of all input read
|
||||||
|
so far (that is, total_in bytes).
|
||||||
|
|
||||||
|
deflate() may update data_type if it can make a good guess about
|
||||||
|
the input data type (Z_ASCII or Z_BINARY). In doubt, the data is considered
|
||||||
|
binary. This field is only for information purposes and does not affect
|
||||||
|
the compression algorithm in any manner.
|
||||||
|
|
||||||
|
deflate() returns Z_OK if some progress has been made (more input
|
||||||
|
processed or more output produced), Z_STREAM_END if all input has been
|
||||||
|
consumed and all output has been produced (only when flush is set to
|
||||||
|
Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example
|
||||||
|
if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible
|
||||||
|
(for example avail_in or avail_out was zero).
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
|
||||||
|
/*
|
||||||
|
All dynamically allocated data structures for this stream are freed.
|
||||||
|
This function discards any unprocessed input and does not flush any
|
||||||
|
pending output.
|
||||||
|
|
||||||
|
deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the
|
||||||
|
stream state was inconsistent, Z_DATA_ERROR if the stream was freed
|
||||||
|
prematurely (some input or output was discarded). In the error case,
|
||||||
|
msg may be set but then points to a static string (which must not be
|
||||||
|
deallocated).
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm));
|
||||||
|
|
||||||
|
Initializes the internal stream state for decompression. The fields
|
||||||
|
next_in, avail_in, zalloc, zfree and opaque must be initialized before by
|
||||||
|
the caller. If next_in is not Z_NULL and avail_in is large enough (the exact
|
||||||
|
value depends on the compression method), inflateInit determines the
|
||||||
|
compression method from the zlib header and allocates all data structures
|
||||||
|
accordingly; otherwise the allocation will be deferred to the first call of
|
||||||
|
inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them to
|
||||||
|
use default allocation functions.
|
||||||
|
|
||||||
|
inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough
|
||||||
|
memory, Z_VERSION_ERROR if the zlib library version is incompatible with the
|
||||||
|
version assumed by the caller. msg is set to null if there is no error
|
||||||
|
message. inflateInit does not perform any decompression apart from reading
|
||||||
|
the zlib header if present: this will be done by inflate(). (So next_in and
|
||||||
|
avail_in may be modified, but next_out and avail_out are unchanged.)
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
|
||||||
|
/*
|
||||||
|
inflate decompresses as much data as possible, and stops when the input
|
||||||
|
buffer becomes empty or the output buffer becomes full. It may some
|
||||||
|
introduce some output latency (reading input without producing any output)
|
||||||
|
except when forced to flush.
|
||||||
|
|
||||||
|
The detailed semantics are as follows. inflate performs one or both of the
|
||||||
|
following actions:
|
||||||
|
|
||||||
|
- Decompress more input starting at next_in and update next_in and avail_in
|
||||||
|
accordingly. If not all input can be processed (because there is not
|
||||||
|
enough room in the output buffer), next_in is updated and processing
|
||||||
|
will resume at this point for the next call of inflate().
|
||||||
|
|
||||||
|
- Provide more output starting at next_out and update next_out and avail_out
|
||||||
|
accordingly. inflate() provides as much output as possible, until there
|
||||||
|
is no more input data or no more space in the output buffer (see below
|
||||||
|
about the flush parameter).
|
||||||
|
|
||||||
|
Before the call of inflate(), the application should ensure that at least
|
||||||
|
one of the actions is possible, by providing more input and/or consuming
|
||||||
|
more output, and updating the next_* and avail_* values accordingly.
|
||||||
|
The application can consume the uncompressed output when it wants, for
|
||||||
|
example when the output buffer is full (avail_out == 0), or after each
|
||||||
|
call of inflate(). If inflate returns Z_OK and with zero avail_out, it
|
||||||
|
must be called again after making room in the output buffer because there
|
||||||
|
might be more output pending.
|
||||||
|
|
||||||
|
If the parameter flush is set to Z_SYNC_FLUSH, inflate flushes as much
|
||||||
|
output as possible to the output buffer. The flushing behavior of inflate is
|
||||||
|
not specified for values of the flush parameter other than Z_SYNC_FLUSH
|
||||||
|
and Z_FINISH, but the current implementation actually flushes as much output
|
||||||
|
as possible anyway.
|
||||||
|
|
||||||
|
inflate() should normally be called until it returns Z_STREAM_END or an
|
||||||
|
error. However if all decompression is to be performed in a single step
|
||||||
|
(a single call of inflate), the parameter flush should be set to
|
||||||
|
Z_FINISH. In this case all pending input is processed and all pending
|
||||||
|
output is flushed; avail_out must be large enough to hold all the
|
||||||
|
uncompressed data. (The size of the uncompressed data may have been saved
|
||||||
|
by the compressor for this purpose.) The next operation on this stream must
|
||||||
|
be inflateEnd to deallocate the decompression state. The use of Z_FINISH
|
||||||
|
is never required, but can be used to inform inflate that a faster routine
|
||||||
|
may be used for the single inflate() call.
|
||||||
|
|
||||||
|
If a preset dictionary is needed at this point (see inflateSetDictionary
|
||||||
|
below), inflate sets strm-adler to the adler32 checksum of the
|
||||||
|
dictionary chosen by the compressor and returns Z_NEED_DICT; otherwise
|
||||||
|
it sets strm->adler to the adler32 checksum of all output produced
|
||||||
|
so far (that is, total_out bytes) and returns Z_OK, Z_STREAM_END or
|
||||||
|
an error code as described below. At the end of the stream, inflate()
|
||||||
|
checks that its computed adler32 checksum is equal to that saved by the
|
||||||
|
compressor and returns Z_STREAM_END only if the checksum is correct.
|
||||||
|
|
||||||
|
inflate() returns Z_OK if some progress has been made (more input processed
|
||||||
|
or more output produced), Z_STREAM_END if the end of the compressed data has
|
||||||
|
been reached and all uncompressed output has been produced, Z_NEED_DICT if a
|
||||||
|
preset dictionary is needed at this point, Z_DATA_ERROR if the input data was
|
||||||
|
corrupted (input stream not conforming to the zlib format or incorrect
|
||||||
|
adler32 checksum), Z_STREAM_ERROR if the stream structure was inconsistent
|
||||||
|
(for example if next_in or next_out was NULL), Z_MEM_ERROR if there was not
|
||||||
|
enough memory, Z_BUF_ERROR if no progress is possible or if there was not
|
||||||
|
enough room in the output buffer when Z_FINISH is used. In the Z_DATA_ERROR
|
||||||
|
case, the application may then call inflateSync to look for a good
|
||||||
|
compression block.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
|
||||||
|
/*
|
||||||
|
All dynamically allocated data structures for this stream are freed.
|
||||||
|
This function discards any unprocessed input and does not flush any
|
||||||
|
pending output.
|
||||||
|
|
||||||
|
inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state
|
||||||
|
was inconsistent. In the error case, msg may be set but then points to a
|
||||||
|
static string (which must not be deallocated).
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Advanced functions */
|
||||||
|
|
||||||
|
/*
|
||||||
|
The following functions are needed only in some special applications.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm,
|
||||||
|
int level,
|
||||||
|
int method,
|
||||||
|
int windowBits,
|
||||||
|
int memLevel,
|
||||||
|
int strategy));
|
||||||
|
|
||||||
|
This is another version of deflateInit with more compression options. The
|
||||||
|
fields next_in, zalloc, zfree and opaque must be initialized before by
|
||||||
|
the caller.
|
||||||
|
|
||||||
|
The method parameter is the compression method. It must be Z_DEFLATED in
|
||||||
|
this version of the library.
|
||||||
|
|
||||||
|
The windowBits parameter is the base two logarithm of the window size
|
||||||
|
(the size of the history buffer). It should be in the range 8..15 for this
|
||||||
|
version of the library. Larger values of this parameter result in better
|
||||||
|
compression at the expense of memory usage. The default value is 15 if
|
||||||
|
deflateInit is used instead.
|
||||||
|
|
||||||
|
The memLevel parameter specifies how much memory should be allocated
|
||||||
|
for the internal compression state. memLevel=1 uses minimum memory but
|
||||||
|
is slow and reduces compression ratio; memLevel=9 uses maximum memory
|
||||||
|
for optimal speed. The default value is 8. See zconf.h for total memory
|
||||||
|
usage as a function of windowBits and memLevel.
|
||||||
|
|
||||||
|
The strategy parameter is used to tune the compression algorithm. Use the
|
||||||
|
value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a
|
||||||
|
filter (or predictor), or Z_HUFFMAN_ONLY to force Huffman encoding only (no
|
||||||
|
string match). Filtered data consists mostly of small values with a
|
||||||
|
somewhat random distribution. In this case, the compression algorithm is
|
||||||
|
tuned to compress them better. The effect of Z_FILTERED is to force more
|
||||||
|
Huffman coding and less string matching; it is somewhat intermediate
|
||||||
|
between Z_DEFAULT and Z_HUFFMAN_ONLY. The strategy parameter only affects
|
||||||
|
the compression ratio but not the correctness of the compressed output even
|
||||||
|
if it is not set appropriately.
|
||||||
|
|
||||||
|
deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
|
||||||
|
memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid
|
||||||
|
method). msg is set to null if there is no error message. deflateInit2 does
|
||||||
|
not perform any compression: this will be done by deflate().
|
||||||
|
*/
|
||||||
|
|
||||||
|
ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
|
||||||
|
const Bytef *dictionary,
|
||||||
|
uInt dictLength));
|
||||||
|
/*
|
||||||
|
Initializes the compression dictionary from the given byte sequence
|
||||||
|
without producing any compressed output. This function must be called
|
||||||
|
immediately after deflateInit, deflateInit2 or deflateReset, before any
|
||||||
|
call of deflate. The compressor and decompressor must use exactly the same
|
||||||
|
dictionary (see inflateSetDictionary).
|
||||||
|
|
||||||
|
The dictionary should consist of strings (byte sequences) that are likely
|
||||||
|
to be encountered later in the data to be compressed, with the most commonly
|
||||||
|
used strings preferably put towards the end of the dictionary. Using a
|
||||||
|
dictionary is most useful when the data to be compressed is short and can be
|
||||||
|
predicted with good accuracy; the data can then be compressed better than
|
||||||
|
with the default empty dictionary.
|
||||||
|
|
||||||
|
Depending on the size of the compression data structures selected by
|
||||||
|
deflateInit or deflateInit2, a part of the dictionary may in effect be
|
||||||
|
discarded, for example if the dictionary is larger than the window size in
|
||||||
|
deflate or deflate2. Thus the strings most likely to be useful should be
|
||||||
|
put at the end of the dictionary, not at the front.
|
||||||
|
|
||||||
|
Upon return of this function, strm->adler is set to the Adler32 value
|
||||||
|
of the dictionary; the decompressor may later use this value to determine
|
||||||
|
which dictionary has been used by the compressor. (The Adler32 value
|
||||||
|
applies to the whole dictionary even if only a subset of the dictionary is
|
||||||
|
actually used by the compressor.)
|
||||||
|
|
||||||
|
deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a
|
||||||
|
parameter is invalid (such as NULL dictionary) or the stream state is
|
||||||
|
inconsistent (for example if deflate has already been called for this stream
|
||||||
|
or if the compression method is bsort). deflateSetDictionary does not
|
||||||
|
perform any compression: this will be done by deflate().
|
||||||
|
*/
|
||||||
|
|
||||||
|
ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
|
||||||
|
z_streamp source));
|
||||||
|
/*
|
||||||
|
Sets the destination stream as a complete copy of the source stream.
|
||||||
|
|
||||||
|
This function can be useful when several compression strategies will be
|
||||||
|
tried, for example when there are several ways of pre-processing the input
|
||||||
|
data with a filter. The streams that will be discarded should then be freed
|
||||||
|
by calling deflateEnd. Note that deflateCopy duplicates the internal
|
||||||
|
compression state which can be quite large, so this strategy is slow and
|
||||||
|
can consume lots of memory.
|
||||||
|
|
||||||
|
deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
|
||||||
|
enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
|
||||||
|
(such as zalloc being NULL). msg is left unchanged in both source and
|
||||||
|
destination.
|
||||||
|
*/
|
||||||
|
|
||||||
|
ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm));
|
||||||
|
/*
|
||||||
|
This function is equivalent to deflateEnd followed by deflateInit,
|
||||||
|
but does not free and reallocate all the internal compression state.
|
||||||
|
The stream will keep the same compression level and any other attributes
|
||||||
|
that may have been set by deflateInit2.
|
||||||
|
|
||||||
|
deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
|
||||||
|
stream state was inconsistent (such as zalloc or state being NULL).
|
||||||
|
*/
|
||||||
|
|
||||||
|
ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
|
||||||
|
int level,
|
||||||
|
int strategy));
|
||||||
|
/*
|
||||||
|
Dynamically update the compression level and compression strategy. The
|
||||||
|
interpretation of level and strategy is as in deflateInit2. This can be
|
||||||
|
used to switch between compression and straight copy of the input data, or
|
||||||
|
to switch to a different kind of input data requiring a different
|
||||||
|
strategy. If the compression level is changed, the input available so far
|
||||||
|
is compressed with the old level (and may be flushed); the new level will
|
||||||
|
take effect only at the next call of deflate().
|
||||||
|
|
||||||
|
Before the call of deflateParams, the stream state must be set as for
|
||||||
|
a call of deflate(), since the currently available input may have to
|
||||||
|
be compressed and flushed. In particular, strm->avail_out must be non-zero.
|
||||||
|
|
||||||
|
deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source
|
||||||
|
stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR
|
||||||
|
if strm->avail_out was zero.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm,
|
||||||
|
int windowBits));
|
||||||
|
|
||||||
|
This is another version of inflateInit with an extra parameter. The
|
||||||
|
fields next_in, avail_in, zalloc, zfree and opaque must be initialized
|
||||||
|
before by the caller.
|
||||||
|
|
||||||
|
The windowBits parameter is the base two logarithm of the maximum window
|
||||||
|
size (the size of the history buffer). It should be in the range 8..15 for
|
||||||
|
this version of the library. The default value is 15 if inflateInit is used
|
||||||
|
instead. If a compressed stream with a larger window size is given as
|
||||||
|
input, inflate() will return with the error code Z_DATA_ERROR instead of
|
||||||
|
trying to allocate a larger window.
|
||||||
|
|
||||||
|
inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
|
||||||
|
memory, Z_STREAM_ERROR if a parameter is invalid (such as a negative
|
||||||
|
memLevel). msg is set to null if there is no error message. inflateInit2
|
||||||
|
does not perform any decompression apart from reading the zlib header if
|
||||||
|
present: this will be done by inflate(). (So next_in and avail_in may be
|
||||||
|
modified, but next_out and avail_out are unchanged.)
|
||||||
|
*/
|
||||||
|
|
||||||
|
ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
|
||||||
|
const Bytef *dictionary,
|
||||||
|
uInt dictLength));
|
||||||
|
/*
|
||||||
|
Initializes the decompression dictionary from the given uncompressed byte
|
||||||
|
sequence. This function must be called immediately after a call of inflate
|
||||||
|
if this call returned Z_NEED_DICT. The dictionary chosen by the compressor
|
||||||
|
can be determined from the Adler32 value returned by this call of
|
||||||
|
inflate. The compressor and decompressor must use exactly the same
|
||||||
|
dictionary (see deflateSetDictionary).
|
||||||
|
|
||||||
|
inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a
|
||||||
|
parameter is invalid (such as NULL dictionary) or the stream state is
|
||||||
|
inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the
|
||||||
|
expected one (incorrect Adler32 value). inflateSetDictionary does not
|
||||||
|
perform any decompression: this will be done by subsequent calls of
|
||||||
|
inflate().
|
||||||
|
*/
|
||||||
|
|
||||||
|
ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));
|
||||||
|
/*
|
||||||
|
Skips invalid compressed data until a full flush point (see above the
|
||||||
|
description of deflate with Z_FULL_FLUSH) can be found, or until all
|
||||||
|
available input is skipped. No output is provided.
|
||||||
|
|
||||||
|
inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR
|
||||||
|
if no more input was provided, Z_DATA_ERROR if no flush point has been found,
|
||||||
|
or Z_STREAM_ERROR if the stream structure was inconsistent. In the success
|
||||||
|
case, the application may save the current current value of total_in which
|
||||||
|
indicates where valid compressed data was found. In the error case, the
|
||||||
|
application may repeatedly call inflateSync, providing more input each time,
|
||||||
|
until success or end of the input data.
|
||||||
|
*/
|
||||||
|
|
||||||
|
ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
|
||||||
|
/*
|
||||||
|
This function is equivalent to inflateEnd followed by inflateInit,
|
||||||
|
but does not free and reallocate all the internal decompression state.
|
||||||
|
The stream will keep attributes that may have been set by inflateInit2.
|
||||||
|
|
||||||
|
inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
|
||||||
|
stream state was inconsistent (such as zalloc or state being NULL).
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/* utility functions */
|
||||||
|
|
||||||
|
/*
|
||||||
|
The following utility functions are implemented on top of the
|
||||||
|
basic stream-oriented functions. To simplify the interface, some
|
||||||
|
default options are assumed (compression level and memory usage,
|
||||||
|
standard memory allocation functions). The source code of these
|
||||||
|
utility functions can easily be modified if you need special options.
|
||||||
|
*/
|
||||||
|
|
||||||
|
ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen,
|
||||||
|
const Bytef *source, uLong sourceLen));
|
||||||
|
/*
|
||||||
|
Compresses the source buffer into the destination buffer. sourceLen is
|
||||||
|
the byte length of the source buffer. Upon entry, destLen is the total
|
||||||
|
size of the destination buffer, which must be at least 0.1% larger than
|
||||||
|
sourceLen plus 12 bytes. Upon exit, destLen is the actual size of the
|
||||||
|
compressed buffer.
|
||||||
|
This function can be used to compress a whole file at once if the
|
||||||
|
input file is mmap'ed.
|
||||||
|
compress returns Z_OK if success, Z_MEM_ERROR if there was not
|
||||||
|
enough memory, Z_BUF_ERROR if there was not enough room in the output
|
||||||
|
buffer.
|
||||||
|
*/
|
||||||
|
|
||||||
|
ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen,
|
||||||
|
const Bytef *source, uLong sourceLen,
|
||||||
|
int level));
|
||||||
|
/*
|
||||||
|
Compresses the source buffer into the destination buffer. The level
|
||||||
|
parameter has the same meaning as in deflateInit. sourceLen is the byte
|
||||||
|
length of the source buffer. Upon entry, destLen is the total size of the
|
||||||
|
destination buffer, which must be at least 0.1% larger than sourceLen plus
|
||||||
|
12 bytes. Upon exit, destLen is the actual size of the compressed buffer.
|
||||||
|
|
||||||
|
compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
|
||||||
|
memory, Z_BUF_ERROR if there was not enough room in the output buffer,
|
||||||
|
Z_STREAM_ERROR if the level parameter is invalid.
|
||||||
|
*/
|
||||||
|
|
||||||
|
ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
|
||||||
|
const Bytef *source, uLong sourceLen));
|
||||||
|
/*
|
||||||
|
Decompresses the source buffer into the destination buffer. sourceLen is
|
||||||
|
the byte length of the source buffer. Upon entry, destLen is the total
|
||||||
|
size of the destination buffer, which must be large enough to hold the
|
||||||
|
entire uncompressed data. (The size of the uncompressed data must have
|
||||||
|
been saved previously by the compressor and transmitted to the decompressor
|
||||||
|
by some mechanism outside the scope of this compression library.)
|
||||||
|
Upon exit, destLen is the actual size of the compressed buffer.
|
||||||
|
This function can be used to decompress a whole file at once if the
|
||||||
|
input file is mmap'ed.
|
||||||
|
|
||||||
|
uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
|
||||||
|
enough memory, Z_BUF_ERROR if there was not enough room in the output
|
||||||
|
buffer, or Z_DATA_ERROR if the input data was corrupted.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
typedef voidp gzFile;
|
||||||
|
|
||||||
|
ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
|
||||||
|
/*
|
||||||
|
Opens a gzip (.gz) file for reading or writing. The mode parameter
|
||||||
|
is as in fopen ("rb" or "wb") but can also include a compression level
|
||||||
|
("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for
|
||||||
|
Huffman only compression as in "wb1h". (See the description
|
||||||
|
of deflateInit2 for more information about the strategy parameter.)
|
||||||
|
|
||||||
|
gzopen can be used to read a file which is not in gzip format; in this
|
||||||
|
case gzread will directly read from the file without decompression.
|
||||||
|
|
||||||
|
gzopen returns NULL if the file could not be opened or if there was
|
||||||
|
insufficient memory to allocate the (de)compression state; errno
|
||||||
|
can be checked to distinguish the two cases (if errno is zero, the
|
||||||
|
zlib error is Z_MEM_ERROR). */
|
||||||
|
|
||||||
|
ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode));
|
||||||
|
/*
|
||||||
|
gzdopen() associates a gzFile with the file descriptor fd. File
|
||||||
|
descriptors are obtained from calls like open, dup, creat, pipe or
|
||||||
|
fileno (in the file has been previously opened with fopen).
|
||||||
|
The mode parameter is as in gzopen.
|
||||||
|
The next call of gzclose on the returned gzFile will also close the
|
||||||
|
file descriptor fd, just like fclose(fdopen(fd), mode) closes the file
|
||||||
|
descriptor fd. If you want to keep fd open, use gzdopen(dup(fd), mode).
|
||||||
|
gzdopen returns NULL if there was insufficient memory to allocate
|
||||||
|
the (de)compression state.
|
||||||
|
*/
|
||||||
|
|
||||||
|
ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
|
||||||
|
/*
|
||||||
|
Dynamically update the compression level or strategy. See the description
|
||||||
|
of deflateInit2 for the meaning of these parameters.
|
||||||
|
gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not
|
||||||
|
opened for writing.
|
||||||
|
*/
|
||||||
|
|
||||||
|
ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
|
||||||
|
/*
|
||||||
|
Reads the given number of uncompressed bytes from the compressed file.
|
||||||
|
If the input file was not in gzip format, gzread copies the given number
|
||||||
|
of bytes into the buffer.
|
||||||
|
gzread returns the number of uncompressed bytes actually read (0 for
|
||||||
|
end of file, -1 for error). */
|
||||||
|
|
||||||
|
ZEXTERN int ZEXPORT gzwrite OF((gzFile file,
|
||||||
|
const voidp buf, unsigned len));
|
||||||
|
/*
|
||||||
|
Writes the given number of uncompressed bytes into the compressed file.
|
||||||
|
gzwrite returns the number of uncompressed bytes actually written
|
||||||
|
(0 in case of error).
|
||||||
|
*/
|
||||||
|
|
||||||
|
ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...));
|
||||||
|
/*
|
||||||
|
Converts, formats, and writes the args to the compressed file under
|
||||||
|
control of the format string, as in fprintf. gzprintf returns the number of
|
||||||
|
uncompressed bytes actually written (0 in case of error).
|
||||||
|
*/
|
||||||
|
|
||||||
|
ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));
|
||||||
|
/*
|
||||||
|
Writes the given null-terminated string to the compressed file, excluding
|
||||||
|
the terminating null character.
|
||||||
|
gzputs returns the number of characters written, or -1 in case of error.
|
||||||
|
*/
|
||||||
|
|
||||||
|
ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len));
|
||||||
|
/*
|
||||||
|
Reads bytes from the compressed file until len-1 characters are read, or
|
||||||
|
a newline character is read and transferred to buf, or an end-of-file
|
||||||
|
condition is encountered. The string is then terminated with a null
|
||||||
|
character.
|
||||||
|
gzgets returns buf, or Z_NULL in case of error.
|
||||||
|
*/
|
||||||
|
|
||||||
|
ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c));
|
||||||
|
/*
|
||||||
|
Writes c, converted to an unsigned char, into the compressed file.
|
||||||
|
gzputc returns the value that was written, or -1 in case of error.
|
||||||
|
*/
|
||||||
|
|
||||||
|
ZEXTERN int ZEXPORT gzgetc OF((gzFile file));
|
||||||
|
/*
|
||||||
|
Reads one byte from the compressed file. gzgetc returns this byte
|
||||||
|
or -1 in case of end of file or error.
|
||||||
|
*/
|
||||||
|
|
||||||
|
ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush));
|
||||||
|
/*
|
||||||
|
Flushes all pending output into the compressed file. The parameter
|
||||||
|
flush is as in the deflate() function. The return value is the zlib
|
||||||
|
error number (see function gzerror below). gzflush returns Z_OK if
|
||||||
|
the flush parameter is Z_FINISH and all output could be flushed.
|
||||||
|
gzflush should be called only when strictly necessary because it can
|
||||||
|
degrade compression.
|
||||||
|
*/
|
||||||
|
|
||||||
|
ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file,
|
||||||
|
z_off_t offset, int whence));
|
||||||
|
/*
|
||||||
|
Sets the starting position for the next gzread or gzwrite on the
|
||||||
|
given compressed file. The offset represents a number of bytes in the
|
||||||
|
uncompressed data stream. The whence parameter is defined as in lseek(2);
|
||||||
|
the value SEEK_END is not supported.
|
||||||
|
If the file is opened for reading, this function is emulated but can be
|
||||||
|
extremely slow. If the file is opened for writing, only forward seeks are
|
||||||
|
supported; gzseek then compresses a sequence of zeroes up to the new
|
||||||
|
starting position.
|
||||||
|
|
||||||
|
gzseek returns the resulting offset location as measured in bytes from
|
||||||
|
the beginning of the uncompressed stream, or -1 in case of error, in
|
||||||
|
particular if the file is opened for writing and the new starting position
|
||||||
|
would be before the current position.
|
||||||
|
*/
|
||||||
|
|
||||||
|
ZEXTERN int ZEXPORT gzrewind OF((gzFile file));
|
||||||
|
/*
|
||||||
|
Rewinds the given file. This function is supported only for reading.
|
||||||
|
|
||||||
|
gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET)
|
||||||
|
*/
|
||||||
|
|
||||||
|
ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file));
|
||||||
|
/*
|
||||||
|
Returns the starting position for the next gzread or gzwrite on the
|
||||||
|
given compressed file. This position represents a number of bytes in the
|
||||||
|
uncompressed data stream.
|
||||||
|
|
||||||
|
gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR)
|
||||||
|
*/
|
||||||
|
|
||||||
|
ZEXTERN int ZEXPORT gzeof OF((gzFile file));
|
||||||
|
/*
|
||||||
|
Returns 1 when EOF has previously been detected reading the given
|
||||||
|
input stream, otherwise zero.
|
||||||
|
*/
|
||||||
|
|
||||||
|
ZEXTERN int ZEXPORT gzclose OF((gzFile file));
|
||||||
|
/*
|
||||||
|
Flushes all pending output if necessary, closes the compressed file
|
||||||
|
and deallocates all the (de)compression state. The return value is the zlib
|
||||||
|
error number (see function gzerror below).
|
||||||
|
*/
|
||||||
|
|
||||||
|
ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum));
|
||||||
|
/*
|
||||||
|
Returns the error message for the last error which occurred on the
|
||||||
|
given compressed file. errnum is set to zlib error number. If an
|
||||||
|
error occurred in the file system and not in the compression library,
|
||||||
|
errnum is set to Z_ERRNO and the application may consult errno
|
||||||
|
to get the exact error code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* checksum functions */
|
||||||
|
|
||||||
|
/*
|
||||||
|
These functions are not related to compression but are exported
|
||||||
|
anyway because they might be useful in applications using the
|
||||||
|
compression library.
|
||||||
|
*/
|
||||||
|
|
||||||
|
ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
|
||||||
|
|
||||||
|
/*
|
||||||
|
Update a running Adler-32 checksum with the bytes buf[0..len-1] and
|
||||||
|
return the updated checksum. If buf is NULL, this function returns
|
||||||
|
the required initial value for the checksum.
|
||||||
|
An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
|
||||||
|
much faster. Usage example:
|
||||||
|
|
||||||
|
uLong adler = adler32(0L, Z_NULL, 0);
|
||||||
|
|
||||||
|
while (read_buffer(buffer, length) != EOF) {
|
||||||
|
adler = adler32(adler, buffer, length);
|
||||||
|
}
|
||||||
|
if (adler != original_adler) error();
|
||||||
|
*/
|
||||||
|
|
||||||
|
ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
|
||||||
|
/*
|
||||||
|
Update a running crc with the bytes buf[0..len-1] and return the updated
|
||||||
|
crc. If buf is NULL, this function returns the required initial value
|
||||||
|
for the crc. Pre- and post-conditioning (one's complement) is performed
|
||||||
|
within this function so it shouldn't be done by the application.
|
||||||
|
Usage example:
|
||||||
|
|
||||||
|
uLong crc = crc32(0L, Z_NULL, 0);
|
||||||
|
|
||||||
|
while (read_buffer(buffer, length) != EOF) {
|
||||||
|
crc = crc32(crc, buffer, length);
|
||||||
|
}
|
||||||
|
if (crc != original_crc) error();
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/* various hacks, don't look :) */
|
||||||
|
|
||||||
|
/* deflateInit and inflateInit are macros to allow checking the zlib version
|
||||||
|
* and the compiler's view of z_stream:
|
||||||
|
*/
|
||||||
|
ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level,
|
||||||
|
const char *version, int stream_size));
|
||||||
|
ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm,
|
||||||
|
const char *version, int stream_size));
|
||||||
|
ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method,
|
||||||
|
int windowBits, int memLevel,
|
||||||
|
int strategy, const char *version,
|
||||||
|
int stream_size));
|
||||||
|
ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits,
|
||||||
|
const char *version, int stream_size));
|
||||||
|
#define deflateInit(strm, level) deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream))
|
||||||
|
#define inflateInit(strm) inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream))
|
||||||
|
#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) deflateInit2_((strm),(level),(method),(windowBits),(memLevel), (strategy), ZLIB_VERSION, sizeof(z_stream))
|
||||||
|
#define inflateInit2(strm, windowBits) inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
|
||||||
|
|
||||||
|
|
||||||
|
#if !defined(_Z_UTIL_H) && !defined(NO_DUMMY_DECL)
|
||||||
|
struct internal_state {int dummy;}; /* hack for buggy compilers */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
ZEXTERN const char * ZEXPORT zError OF((int err));
|
||||||
|
ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp z));
|
||||||
|
ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void));
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* _ZLIB_H */
|
225
zlib/zutil.c
Normal file
225
zlib/zutil.c
Normal file
|
@ -0,0 +1,225 @@
|
||||||
|
/* zutil.c -- target dependent utility functions for the compression library
|
||||||
|
* Copyright (C) 1995-2002 Jean-loup Gailly.
|
||||||
|
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* @(#) $Id$ */
|
||||||
|
|
||||||
|
#include "zutil.h"
|
||||||
|
|
||||||
|
struct internal_state {int dummy;}; /* for buggy compilers */
|
||||||
|
|
||||||
|
#ifndef STDC
|
||||||
|
extern void exit OF((int));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
const char *z_errmsg[10] = {
|
||||||
|
"need dictionary", /* Z_NEED_DICT 2 */
|
||||||
|
"stream end", /* Z_STREAM_END 1 */
|
||||||
|
"", /* Z_OK 0 */
|
||||||
|
"file error", /* Z_ERRNO (-1) */
|
||||||
|
"stream error", /* Z_STREAM_ERROR (-2) */
|
||||||
|
"data error", /* Z_DATA_ERROR (-3) */
|
||||||
|
"insufficient memory", /* Z_MEM_ERROR (-4) */
|
||||||
|
"buffer error", /* Z_BUF_ERROR (-5) */
|
||||||
|
"incompatible version",/* Z_VERSION_ERROR (-6) */
|
||||||
|
""};
|
||||||
|
|
||||||
|
|
||||||
|
const char * ZEXPORT zlibVersion()
|
||||||
|
{
|
||||||
|
return ZLIB_VERSION;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
|
||||||
|
# ifndef verbose
|
||||||
|
# define verbose 0
|
||||||
|
# endif
|
||||||
|
int z_verbose = verbose;
|
||||||
|
|
||||||
|
void z_error (m)
|
||||||
|
char *m;
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s\n", m);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* exported to allow conversion of error code to string for compress() and
|
||||||
|
* uncompress()
|
||||||
|
*/
|
||||||
|
const char * ZEXPORT zError(err)
|
||||||
|
int err;
|
||||||
|
{
|
||||||
|
return ERR_MSG(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef HAVE_MEMCPY
|
||||||
|
|
||||||
|
void zmemcpy(dest, source, len)
|
||||||
|
Bytef* dest;
|
||||||
|
const Bytef* source;
|
||||||
|
uInt len;
|
||||||
|
{
|
||||||
|
if (len == 0) return;
|
||||||
|
do {
|
||||||
|
*dest++ = *source++; /* ??? to be unrolled */
|
||||||
|
} while (--len != 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int zmemcmp(s1, s2, len)
|
||||||
|
const Bytef* s1;
|
||||||
|
const Bytef* s2;
|
||||||
|
uInt len;
|
||||||
|
{
|
||||||
|
uInt j;
|
||||||
|
|
||||||
|
for (j = 0; j < len; j++) {
|
||||||
|
if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void zmemzero(dest, len)
|
||||||
|
Bytef* dest;
|
||||||
|
uInt len;
|
||||||
|
{
|
||||||
|
if (len == 0) return;
|
||||||
|
do {
|
||||||
|
*dest++ = 0; /* ??? to be unrolled */
|
||||||
|
} while (--len != 0);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __TURBOC__
|
||||||
|
#if (defined( __BORLANDC__) || !defined(SMALL_MEDIUM)) && !defined(__32BIT__)
|
||||||
|
/* Small and medium model in Turbo C are for now limited to near allocation
|
||||||
|
* with reduced MAX_WBITS and MAX_MEM_LEVEL
|
||||||
|
*/
|
||||||
|
# define MY_ZCALLOC
|
||||||
|
|
||||||
|
/* Turbo C malloc() does not allow dynamic allocation of 64K bytes
|
||||||
|
* and farmalloc(64K) returns a pointer with an offset of 8, so we
|
||||||
|
* must fix the pointer. Warning: the pointer must be put back to its
|
||||||
|
* original form in order to free it, use zcfree().
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define MAX_PTR 10
|
||||||
|
/* 10*64K = 640K */
|
||||||
|
|
||||||
|
local int next_ptr = 0;
|
||||||
|
|
||||||
|
typedef struct ptr_table_s {
|
||||||
|
voidpf org_ptr;
|
||||||
|
voidpf new_ptr;
|
||||||
|
} ptr_table;
|
||||||
|
|
||||||
|
local ptr_table table[MAX_PTR];
|
||||||
|
/* This table is used to remember the original form of pointers
|
||||||
|
* to large buffers (64K). Such pointers are normalized with a zero offset.
|
||||||
|
* Since MSDOS is not a preemptive multitasking OS, this table is not
|
||||||
|
* protected from concurrent access. This hack doesn't work anyway on
|
||||||
|
* a protected system like OS/2. Use Microsoft C instead.
|
||||||
|
*/
|
||||||
|
|
||||||
|
voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
|
||||||
|
{
|
||||||
|
voidpf buf = opaque; /* just to make some compilers happy */
|
||||||
|
ulg bsize = (ulg)items*size;
|
||||||
|
|
||||||
|
/* If we allocate less than 65520 bytes, we assume that farmalloc
|
||||||
|
* will return a usable pointer which doesn't have to be normalized.
|
||||||
|
*/
|
||||||
|
if (bsize < 65520L) {
|
||||||
|
buf = farmalloc(bsize);
|
||||||
|
if (*(ush*)&buf != 0) return buf;
|
||||||
|
} else {
|
||||||
|
buf = farmalloc(bsize + 16L);
|
||||||
|
}
|
||||||
|
if (buf == NULL || next_ptr >= MAX_PTR) return NULL;
|
||||||
|
table[next_ptr].org_ptr = buf;
|
||||||
|
|
||||||
|
/* Normalize the pointer to seg:0 */
|
||||||
|
*((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4;
|
||||||
|
*(ush*)&buf = 0;
|
||||||
|
table[next_ptr++].new_ptr = buf;
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
void zcfree (voidpf opaque, voidpf ptr)
|
||||||
|
{
|
||||||
|
int n;
|
||||||
|
if (*(ush*)&ptr != 0) { /* object < 64K */
|
||||||
|
farfree(ptr);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
/* Find the original pointer */
|
||||||
|
for (n = 0; n < next_ptr; n++) {
|
||||||
|
if (ptr != table[n].new_ptr) continue;
|
||||||
|
|
||||||
|
farfree(table[n].org_ptr);
|
||||||
|
while (++n < next_ptr) {
|
||||||
|
table[n-1] = table[n];
|
||||||
|
}
|
||||||
|
next_ptr--;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ptr = opaque; /* just to make some compilers happy */
|
||||||
|
Assert(0, "zcfree: ptr not found");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif /* __TURBOC__ */
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(M_I86) && !defined(__32BIT__)
|
||||||
|
/* Microsoft C in 16-bit mode */
|
||||||
|
|
||||||
|
# define MY_ZCALLOC
|
||||||
|
|
||||||
|
#if (!defined(_MSC_VER) || (_MSC_VER <= 600))
|
||||||
|
# define _halloc halloc
|
||||||
|
# define _hfree hfree
|
||||||
|
#endif
|
||||||
|
|
||||||
|
voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
|
||||||
|
{
|
||||||
|
if (opaque) opaque = 0; /* to make compiler happy */
|
||||||
|
return _halloc((long)items, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
void zcfree (voidpf opaque, voidpf ptr)
|
||||||
|
{
|
||||||
|
if (opaque) opaque = 0; /* to make compiler happy */
|
||||||
|
_hfree(ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* MSC */
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef MY_ZCALLOC /* Any system without a special alloc function */
|
||||||
|
|
||||||
|
#ifndef STDC
|
||||||
|
extern voidp calloc OF((uInt items, uInt size));
|
||||||
|
extern void free OF((voidpf ptr));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
voidpf zcalloc (opaque, items, size)
|
||||||
|
voidpf opaque;
|
||||||
|
unsigned items;
|
||||||
|
unsigned size;
|
||||||
|
{
|
||||||
|
if (opaque) items += size - size; /* make compiler happy */
|
||||||
|
return (voidpf)calloc(items, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
void zcfree (opaque, ptr)
|
||||||
|
voidpf opaque;
|
||||||
|
voidpf ptr;
|
||||||
|
{
|
||||||
|
free(ptr);
|
||||||
|
if (opaque) return; /* make compiler happy */
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* MY_ZCALLOC */
|
220
zlib/zutil.h
Normal file
220
zlib/zutil.h
Normal file
|
@ -0,0 +1,220 @@
|
||||||
|
/* zutil.h -- internal interface and configuration of the compression library
|
||||||
|
* Copyright (C) 1995-2002 Jean-loup Gailly.
|
||||||
|
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* WARNING: this file should *not* be used by applications. It is
|
||||||
|
part of the implementation of the compression library and is
|
||||||
|
subject to change. Applications should only use zlib.h.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* @(#) $Id$ */
|
||||||
|
|
||||||
|
#ifndef _Z_UTIL_H
|
||||||
|
#define _Z_UTIL_H
|
||||||
|
|
||||||
|
#include "zlib.h"
|
||||||
|
|
||||||
|
#ifdef STDC
|
||||||
|
# include <stddef.h>
|
||||||
|
# include <string.h>
|
||||||
|
# include <stdlib.h>
|
||||||
|
#endif
|
||||||
|
#ifdef NO_ERRNO_H
|
||||||
|
extern int errno;
|
||||||
|
#else
|
||||||
|
# include <errno.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef local
|
||||||
|
# define local static
|
||||||
|
#endif
|
||||||
|
/* compile with -Dlocal if your debugger can't find static symbols */
|
||||||
|
|
||||||
|
typedef unsigned char uch;
|
||||||
|
typedef uch FAR uchf;
|
||||||
|
typedef unsigned short ush;
|
||||||
|
typedef ush FAR ushf;
|
||||||
|
typedef unsigned long ulg;
|
||||||
|
|
||||||
|
extern const char *z_errmsg[10]; /* indexed by 2-zlib_error */
|
||||||
|
/* (size given to avoid silly warnings with Visual C++) */
|
||||||
|
|
||||||
|
#define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
|
||||||
|
|
||||||
|
#define ERR_RETURN(strm,err) \
|
||||||
|
return (strm->msg = (char*)ERR_MSG(err), (err))
|
||||||
|
/* To be used only when the state is known to be valid */
|
||||||
|
|
||||||
|
/* common constants */
|
||||||
|
|
||||||
|
#ifndef DEF_WBITS
|
||||||
|
# define DEF_WBITS MAX_WBITS
|
||||||
|
#endif
|
||||||
|
/* default windowBits for decompression. MAX_WBITS is for compression only */
|
||||||
|
|
||||||
|
#if MAX_MEM_LEVEL >= 8
|
||||||
|
# define DEF_MEM_LEVEL 8
|
||||||
|
#else
|
||||||
|
# define DEF_MEM_LEVEL MAX_MEM_LEVEL
|
||||||
|
#endif
|
||||||
|
/* default memLevel */
|
||||||
|
|
||||||
|
#define STORED_BLOCK 0
|
||||||
|
#define STATIC_TREES 1
|
||||||
|
#define DYN_TREES 2
|
||||||
|
/* The three kinds of block type */
|
||||||
|
|
||||||
|
#define MIN_MATCH 3
|
||||||
|
#define MAX_MATCH 258
|
||||||
|
/* The minimum and maximum match lengths */
|
||||||
|
|
||||||
|
#define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
|
||||||
|
|
||||||
|
/* target dependencies */
|
||||||
|
|
||||||
|
#ifdef MSDOS
|
||||||
|
# define OS_CODE 0x00
|
||||||
|
# if defined(__TURBOC__) || defined(__BORLANDC__)
|
||||||
|
# if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
|
||||||
|
/* Allow compilation with ANSI keywords only enabled */
|
||||||
|
void _Cdecl farfree( void *block );
|
||||||
|
void *_Cdecl farmalloc( unsigned long nbytes );
|
||||||
|
# else
|
||||||
|
# include <alloc.h>
|
||||||
|
# endif
|
||||||
|
# else /* MSC or DJGPP */
|
||||||
|
# include <malloc.h>
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef OS2
|
||||||
|
# define OS_CODE 0x06
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef WIN32 /* Window 95 & Windows NT */
|
||||||
|
# define OS_CODE 0x0b
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(VAXC) || defined(VMS)
|
||||||
|
# define OS_CODE 0x02
|
||||||
|
# define F_OPEN(name, mode) \
|
||||||
|
fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef AMIGA
|
||||||
|
# define OS_CODE 0x01
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(ATARI) || defined(atarist)
|
||||||
|
# define OS_CODE 0x05
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MACOS) || defined(TARGET_OS_MAC)
|
||||||
|
# define OS_CODE 0x07
|
||||||
|
# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
|
||||||
|
# include <unix.h> /* for fdopen */
|
||||||
|
# else
|
||||||
|
# ifndef fdopen
|
||||||
|
# define fdopen(fd,mode) NULL /* No fdopen() */
|
||||||
|
# endif
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __50SERIES /* Prime/PRIMOS */
|
||||||
|
# define OS_CODE 0x0F
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef TOPS20
|
||||||
|
# define OS_CODE 0x0a
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(_BEOS_) || defined(RISCOS)
|
||||||
|
# define fdopen(fd,mode) NULL /* No fdopen() */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if (defined(_MSC_VER) && (_MSC_VER > 600))
|
||||||
|
# define fdopen(fd,type) _fdopen(fd,type)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* Common defaults */
|
||||||
|
|
||||||
|
#ifndef OS_CODE
|
||||||
|
# define OS_CODE 0x03 /* assume Unix */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef F_OPEN
|
||||||
|
# define F_OPEN(name, mode) fopen((name), (mode))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* functions */
|
||||||
|
|
||||||
|
#ifdef HAVE_STRERROR
|
||||||
|
extern char *strerror OF((int));
|
||||||
|
# define zstrerror(errnum) strerror(errnum)
|
||||||
|
#else
|
||||||
|
# define zstrerror(errnum) ""
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(pyr)
|
||||||
|
# define NO_MEMCPY
|
||||||
|
#endif
|
||||||
|
#if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
|
||||||
|
/* Use our own functions for small and medium model with MSC <= 5.0.
|
||||||
|
* You may have to use the same strategy for Borland C (untested).
|
||||||
|
* The __SC__ check is for Symantec.
|
||||||
|
*/
|
||||||
|
# define NO_MEMCPY
|
||||||
|
#endif
|
||||||
|
#if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
|
||||||
|
# define HAVE_MEMCPY
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_MEMCPY
|
||||||
|
# ifdef SMALL_MEDIUM /* MSDOS small or medium model */
|
||||||
|
# define zmemcpy _fmemcpy
|
||||||
|
# define zmemcmp _fmemcmp
|
||||||
|
# define zmemzero(dest, len) _fmemset(dest, 0, len)
|
||||||
|
# else
|
||||||
|
# define zmemcpy memcpy
|
||||||
|
# define zmemcmp memcmp
|
||||||
|
# define zmemzero(dest, len) memset(dest, 0, len)
|
||||||
|
# endif
|
||||||
|
#else
|
||||||
|
extern void zmemcpy OF((Bytef* dest, const Bytef* source, uInt len));
|
||||||
|
extern int zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len));
|
||||||
|
extern void zmemzero OF((Bytef* dest, uInt len));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Diagnostic functions */
|
||||||
|
#ifdef DEBUG
|
||||||
|
# include <stdio.h>
|
||||||
|
extern int z_verbose;
|
||||||
|
extern void z_error OF((char *m));
|
||||||
|
# define Assert(cond,msg) {if(!(cond)) z_error(msg);}
|
||||||
|
# define Trace(x) {if (z_verbose>=0) fprintf x ;}
|
||||||
|
# define Tracev(x) {if (z_verbose>0) fprintf x ;}
|
||||||
|
# define Tracevv(x) {if (z_verbose>1) fprintf x ;}
|
||||||
|
# define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
|
||||||
|
# define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
|
||||||
|
#else
|
||||||
|
# define Assert(cond,msg)
|
||||||
|
# define Trace(x)
|
||||||
|
# define Tracev(x)
|
||||||
|
# define Tracevv(x)
|
||||||
|
# define Tracec(c,x)
|
||||||
|
# define Tracecv(c,x)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
typedef uLong (ZEXPORT *check_func) OF((uLong check, const Bytef *buf,
|
||||||
|
uInt len));
|
||||||
|
voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size));
|
||||||
|
void zcfree OF((voidpf opaque, voidpf ptr));
|
||||||
|
|
||||||
|
#define ZALLOC(strm, items, size) \
|
||||||
|
(*((strm)->zalloc))((strm)->opaque, (items), (size))
|
||||||
|
#define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
|
||||||
|
#define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
|
||||||
|
|
||||||
|
#endif /* _Z_UTIL_H */
|
Loading…
Add table
Reference in a new issue