This commit is contained in:
King_DuckZ 2020-05-05 20:22:42 +02:00
parent 0433a6bc0a
commit e5cd2e91e8
22 changed files with 5633 additions and 5315 deletions

View file

@ -1,6 +1,6 @@
CPP = g++ CPP = g++
CC = gcc CC = gcc
OBJ = main.o UnAlz.o UnAlzBz2decompress.o UnAlzBzip2.o UnAlzbzlib.o zlib/adler32.o zlib/crc32.o zlib/infback.o zlib/inffast.o zlib/inflate.o zlib/inftrees.o zlib/zutil.o bzip2/blocksort.o bzip2/compress.o bzip2/crctable.o bzip2/huffman.o bzip2/randtable.o OBJ = main.o UnAlz.o UnAlzUtils.o UnAlzBz2decompress.o UnAlzBzip2.o UnAlzbzlib.o zlib/adler32.o zlib/crc32.o zlib/infback.o zlib/inffast.o zlib/inflate.o zlib/inftrees.o zlib/zutil.o bzip2/blocksort.o bzip2/compress.o bzip2/crctable.o bzip2/huffman.o bzip2/randtable.o
BIN = unalz BIN = unalz
LDFLAGS = LDFLAGS =
CFLAGS = -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 CFLAGS = -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
@ -13,25 +13,33 @@ all:
@echo "TARGET_SYSTEM is one of" @echo "TARGET_SYSTEM is one of"
@echo "" @echo ""
@echo " posix : POSIX system (FreeBSD/linux/OSX/sparc)" @echo " posix : POSIX system (FreeBSD/linux/OSX/sparc)"
@echo " posix-utf8 : POSIX with utf8 filesystem(OSX)" @echo " posix-utf8 : POSIX with utf8 filesystem(e.g. OSX)"
@echo " posix-noiconv : POSIX without libiconv (Windows(MINGW32,CYGWIN)/CP949 only file system)" @echo " linux-utf8 : LINUX with utf8 filesystem(without -liconv option)"
@echo " posix-noiconv : POSIX without libiconv (Windows(MINGW32,CYGWIN) or EUC-KR file system)"
@echo "" @echo ""
@echo " and 'clean' for clean" @echo " 'install' for copy unalz to /usr/local/bin and "
@echo " 'clean' for clean"
@echo "" @echo ""
posix: unalz posix: unalz
$(CPP) -c UnAlz.cpp -c main.cpp -D_UNALZ_ICONV $(CFLAGS) $(CPP) -c UnAlz.cpp -c UnAlzUtils.cpp -c main.cpp -D_UNALZ_ICONV $(CFLAGS)
$(CPP) $(OBJ) $(LDFLAGS) -liconv -o $(BIN) $(CPP) $(OBJ) $(LDFLAGS) -liconv -o $(BIN)
posix-utf8: unalz posix-utf8: unalz
$(CPP) -c UnAlz.cpp -c main.cpp -D_UNALZ_ICONV -D_UNALZ_UTF8 $(CFLAGS) $(CPP) -c UnAlz.cpp -c UnAlzUtils.cpp -c main.cpp -D_UNALZ_ICONV -D_UNALZ_UTF8 $(CFLAGS)
$(CPP) $(OBJ) $(LDFLAGS) -liconv -o $(BIN) $(CPP) $(OBJ) $(LDFLAGS) -liconv -o $(BIN)
posix-noiconv: unalz posix-noiconv: unalz
$(CPP) -c UnAlz.cpp -c main.cpp $(CFLAGS) $(CPP) -c UnAlz.cpp -c UnAlzUtils.cpp -c main.cpp $(CFLAGS)
$(CPP) $(OBJ) $(LDFLAGS) -o $(BIN) $(CPP) $(OBJ) $(LDFLAGS) -o $(BIN)
linux-utf8: unalz
$(CPP) -c UnAlz.cpp -c UnAlzUtils.cpp -c main.cpp -D_UNALZ_ICONV -D_UNALZ_UTF8 $(CFLAGS)
$(CPP) $(OBJ) $(LDFLAGS) -o $(BIN)
install:
cp unalz /usr/local/bin/
clean: clean:
rm -f $(OBJ) $(BIN) rm -f $(OBJ) $(BIN)

View file

@ -2,8 +2,7 @@
PROG= unalz PROG= unalz
NOMAN= NOMAN=
SRCS= main.cpp UnAlz.cpp UnAlzBz2decompress.c UnAlzBzip2.cpp \ SRCS= main.cpp UnAlz.cpp UnAlzBz2decompress.c UnAlzBzip2.cpp UnAlzbzlib.c UnAlzUtils.cpp
UnAlzbzlib.c
LDADD+= -lz -lbz2 -liconv -lstdc++ LDADD+= -lz -lbz2 -liconv -lstdc++
.include <bsd.prog.mk> .include <bsd.prog.mk>

View file

@ -3,6 +3,18 @@
#include "bzip2/bzlib.h" #include "bzip2/bzlib.h"
#include "UnAlz.h" #include "UnAlz.h"
// utime 함수 처리
#if defined(_WIN32) || defined(__CYGWIN__)
# include <time.h>
# include <sys/utime.h>
#endif
#ifdef __GNUC__
# include <time.h>
# include <utime.h>
#endif
// mkdir // mkdir
#ifdef _WIN32 #ifdef _WIN32
# include <direct.h> # include <direct.h>
@ -27,7 +39,7 @@
//// byte-order : little to host //// //// byte-order : little to host ////
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
#if defined(_WIN32) ||defined(__CYGWIN__) // little to little #if defined(_WIN32) || defined(__CYGWIN__) // little to little
inline UINT16 unalz_le16toh(UINT16 a){return a;} inline UINT16 unalz_le16toh(UINT16 a){return a;}
inline UINT32 unalz_le32toh(UINT32 a){return a;} inline UINT32 unalz_le32toh(UINT32 a){return a;}
inline UINT64 unalz_le64toh(UINT64 a){return a;} inline UINT64 unalz_le64toh(UINT64 a){return a;}
@ -68,7 +80,7 @@
#ifndef MAX_PATH #ifndef MAX_PATH
# define MAX_PATH 260 # define MAX_PATH 260*6 // 그냥 .. 충분히..
#endif #endif
#ifdef _WIN32 #ifdef _WIN32
@ -79,6 +91,18 @@
# define PATHSEPC '/' # define PATHSEPC '/'
#endif #endif
static time_t dosTime2TimeT(UINT32 dostime) // from INFO-ZIP src
{
struct tm t;
t.tm_isdst = -1;
t.tm_sec = (((int)dostime) << 1) & 0x3e;
t.tm_min = (((int)dostime) >> 5) & 0x3f;
t.tm_hour = (((int)dostime) >> 11) & 0x1f;
t.tm_mday = (int)(dostime >> 16) & 0x1f;
t.tm_mon = ((int)(dostime >> 21) & 0x0f) - 1;
t.tm_year = ((int)(dostime >> 25) & 0x7f) + 80;
return mktime(&t);
}
// error string table <- CUnAlz::ERR 의 번역 // error string table <- CUnAlz::ERR 의 번역
@ -355,13 +379,13 @@ BOOL CUnAlz::ReadLocalFileheader()
FRead(&(zipHeader.compressionMethod), sizeof(zipHeader.compressionMethod)); FRead(&(zipHeader.compressionMethod), sizeof(zipHeader.compressionMethod));
FRead(&(zipHeader.unknown), sizeof(zipHeader.unknown)); FRead(&(zipHeader.unknown), sizeof(zipHeader.unknown));
FRead(&(zipHeader.fileCRC), sizeof(zipHeader.fileCRC)); FRead(&(zipHeader.fileCRC), sizeof(zipHeader.fileCRC));
// FRead(&(zipHeader.passwordCRC), sizeof(zipHeader.passwordCRC));
FRead(&(zipHeader.compressedSize), byteLen); FRead(&(zipHeader.compressedSize), byteLen);
FRead(&(zipHeader.uncompressedSize), byteLen); // 압축 사이즈가 없다. FRead(&(zipHeader.uncompressedSize), byteLen); // 압축 사이즈가 없다.
} }
// little to system // little to system
zipHeader.fileCRC = unalz_le32toh(zipHeader.fileCRC);
zipHeader.head.fileNameLength = unalz_le16toh(zipHeader.head.fileNameLength); zipHeader.head.fileNameLength = unalz_le16toh(zipHeader.head.fileNameLength);
zipHeader.compressedSize = unalz_le64toh(zipHeader.compressedSize); zipHeader.compressedSize = unalz_le64toh(zipHeader.compressedSize);
zipHeader.uncompressedSize = unalz_le64toh(zipHeader.uncompressedSize); zipHeader.uncompressedSize = unalz_le64toh(zipHeader.uncompressedSize);
@ -389,7 +413,7 @@ BOOL CUnAlz::ReadLocalFileheader()
size_t size; size_t size;
char inbuf[ICONV_BUF_SIZE]; char inbuf[ICONV_BUF_SIZE];
char outbuf[ICONV_BUF_SIZE]; char outbuf[ICONV_BUF_SIZE];
#if defined(__FreeBSD__) || defined(__CYGWIN__) #if defined(__FreeBSD__) || defined(__CYGWIN__) || defined(__APPLE__)
const char *inptr = inbuf; const char *inptr = inbuf;
#else #else
char *inptr = inbuf; char *inptr = inbuf;
@ -474,6 +498,7 @@ BOOL CUnAlz::ReadLocalFileheader()
} }
*/ */
/*
#ifdef _DEBUG #ifdef _DEBUG
printf("NAME:%s COMPRESSED SIZE:%d UNCOMPRESSED SIZE:%d COMP METHOD:%d\n", printf("NAME:%s COMPRESSED SIZE:%d UNCOMPRESSED SIZE:%d COMP METHOD:%d\n",
zipHeader.fileName, zipHeader.fileName,
@ -482,6 +507,7 @@ BOOL CUnAlz::ReadLocalFileheader()
zipHeader.compressionMethod zipHeader.compressionMethod
); );
#endif #endif
*/
// 파일을 목록에 추가한다.. // 파일을 목록에 추가한다..
m_fileList.push_back(zipHeader); m_fileList.push_back(zipHeader);
@ -691,7 +717,15 @@ BOOL CUnAlz::ExtractCurrentFile(const char* szDestPathName, const char* szDestFi
if(m_pFuncCallBack) m_pFuncCallBack(m_posCur->fileName, 0,m_posCur->uncompressedSize,m_pCallbackParam, NULL); if(m_pFuncCallBack) m_pFuncCallBack(m_posCur->fileName, 0,m_posCur->uncompressedSize,m_pCallbackParam, NULL);
ret = ExtractTo(&dest); ret = ExtractTo(&dest);
if(dest.fp!=NULL)fclose(dest.fp); if(dest.fp!=NULL)
{
fclose(dest.fp);
// file time setting - from unalz_wcx_01i.zip
utimbuf tmp;
tmp.actime = 0; // 마지막 엑세스 타임
tmp.modtime = dosTime2TimeT(m_posCur->head.fileTimeDate); // 마지막 수정일자만 변경(만든 날자는 어떻게 바꾸지?)
utime(m_posCur->fileName, &tmp);
}
return ret; return ret;
} }
@ -721,6 +755,7 @@ BOOL CUnAlz::ExtractTo(SExtractDest* dest)
{ {
// alzip 5.6 부터 추가된 포맷(5.5 에서는 풀지 못한다. 영문 5.51 은 푼다 ) // alzip 5.6 부터 추가된 포맷(5.5 에서는 풀지 못한다. 영문 5.51 은 푼다 )
// 하지만 어떤 버전에서 이 포맷을 만들어 내는지 정확히 알 수 없다. // 하지만 어떤 버전에서 이 포맷을 만들어 내는지 정확히 알 수 없다.
// 공식으로 릴리즈된 알집은 이 포맷을 만들어내지 않는다. 비공식(베타?)으로 배포된 버전에서만 이 포맷을 만들어낸다.
m_nErr = ERR_UNKNOWN_COMPRESSION_METHOD; m_nErr = ERR_UNKNOWN_COMPRESSION_METHOD;
ASSERT(0); ASSERT(0);
ret = FALSE; ret = FALSE;
@ -1418,6 +1453,7 @@ void CUnAlz::FClose()
m_nVirtualFilePos = 0; m_nVirtualFilePos = 0;
m_nCurFilePos = 0; m_nCurFilePos = 0;
m_bIsEOF = FALSE; m_bIsEOF = FALSE;
} }
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////

44
UnAlz.h
View file

@ -42,7 +42,7 @@
- unalz 0.22 - unalz 0.22
2004/10/30 - & .. 2004/10/30 - & ..
- unalz 0.23 - unalz 0.23
2004/11/14 - by xxfre86 : 2004/11/14 - by xxfree86 :
- unalz 0.30 - unalz 0.30
2004/11/27 - cygwin에서 2004/11/27 - cygwin에서
- GPL CZipArchive "ZIP File Format Specification version 4.5" & - GPL CZipArchive "ZIP File Format Specification version 4.5" &
@ -56,7 +56,13 @@
2005/06/16 - GetFileList() ( ) 2005/06/16 - GetFileList() ( )
2005/06/18 - by goweol : utf-8 2005/06/18 - by goweol : utf-8
- unalz 0.4 - unalz 0.4
2005/06/22 - by goweol : -l
- UnAlzUtils.cpp/h
2005/06/29 - by xxfree86 : MacOSX 10.4.1 gcc 4.0 iconv
- CRC (?)
2005/07/02 - unalz , ..
- - from unalz_wcx_01i.zip
2005/07/09 - unalz 0.5
: :
- alz ( deflate/ bzip2/raw ) - alz ( deflate/ bzip2/raw )
@ -79,7 +85,6 @@
#define _UNALZ_H_ #define _UNALZ_H_
#include <vector> #include <vector>
#include <string>
using namespace std; using namespace std;
@ -129,7 +134,9 @@ using namespace std;
typedef unsigned long ULONG; // same as DWORD? i don't know. typedef unsigned long ULONG; // same as DWORD? i don't know.
#endif #endif
#ifndef BOOL #ifndef BOOL
# ifndef BOOL_DEFINED // 이미 BOOL 이 DEFINE 되어 있으면 BOOL_DEFINED 를 define 해서 컴파일 에러를 막을 수 있다.
typedef int BOOL; typedef int BOOL;
# endif
#endif #endif
#ifndef FALSE #ifndef FALSE
# define FALSE 0 # define FALSE 0
@ -147,7 +154,7 @@ using namespace std;
#ifndef ASSERT #ifndef ASSERT
# include <assert.h> # include <assert.h>
//# define ASSERT(x) assert(x) //# define ASSERT(x) assert(x)
# define ASSERT(x) {printf("assert at file:%s line:%d\n", __FILE__, __LINE__);} # define ASSERT(x) {printf("unalz assert at file:%s line:%d\n", __FILE__, __LINE__);}
#endif #endif
@ -162,7 +169,7 @@ namespace UNALZ
# pragma pack(1) # pragma pack(1)
#endif #endif
static const char UNALZ_VERSION[] = "CUnAlz0.4"; static const char UNALZ_VERSION[] = "CUnAlz0.5";
static const char UNALZ_COPYRIGHT[] = "Copyright(C) 2004-2005 by hardkoder ( http://www.kipple.pe.kr ) "; static const char UNALZ_COPYRIGHT[] = "Copyright(C) 2004-2005 by hardkoder ( http://www.kipple.pe.kr ) ";
enum {ENCR_HEADER_LEN=12}; // xf86 enum {ENCR_HEADER_LEN=12}; // xf86
@ -196,18 +203,28 @@ enum COMPRESSION_METHOD ///<
COMP_UNKNOWN = 3, // unknown! COMP_UNKNOWN = 3, // unknown!
}; };
enum FILE_ATTRIBUTE enum ALZ_FILE_ATTRIBUTE
{ {
FILEATTR_FILE = 0x1, ALZ_FILEATTR_READONLY = 0x1,
FILEATTR_FOLDER = 0x10, ALZ_FILEATTR_HIDDEN = 0x2,
FILEATTR_FILE2 = 0x20, /// FILEATTR_FILE 과 FILEATTR_FILE2 의 차이는 모르겠다.. ALZ_FILEATTR_DIRECTORY = 0x10,
ALZ_FILEATTR_FILE = 0x20,
};
enum ALZ_FILE_DESCRIPTOR
{
ALZ_FILE_DESCRIPTOR_ENCRYPTED = 0x01, // 암호 걸린 파일
ALZ_FILE_DESCRIPTOR_FILESIZEFIELD_1BYTE = 0x10, // 파일 크기 필드의 크기
ALZ_FILE_DESCRIPTOR_FILESIZEFIELD_2BYTE = 0x20,
ALZ_FILE_DESCRIPTOR_FILESIZEFIELD_4BYTE = 0x40,
ALZ_FILE_DESCRIPTOR_FILESIZEFIELD_8BYTE = 0x80,
}; };
struct _SLocalFileHeaderHead ///< 고정 헤더. struct _SLocalFileHeaderHead ///< 고정 헤더.
{ {
SHORT fileNameLength; SHORT fileNameLength;
BYTE fileAttribute; // from http://www.zap.pe.kr, FILE_ATTRIBUE 참고 BYTE fileAttribute; // from http://www.zap.pe.kr, enum FILE_ATTRIBUE 참고
UINT32 fileTimeDate; UINT32 fileTimeDate; // dos file time
BYTE fileDescriptor; ///< 파일 크기 필드의 크기 : 0x10, 0x20, 0x40, 0x80 각각 1byte, 2byte, 4byte, 8byte. BYTE fileDescriptor; ///< 파일 크기 필드의 크기 : 0x10, 0x20, 0x40, 0x80 각각 1byte, 2byte, 4byte, 8byte.
///< fileDescriptor & 1 == 암호걸렸는지 여부 ///< fileDescriptor & 1 == 암호걸렸는지 여부
@ -246,7 +263,6 @@ struct SLocalFileHeader
BYTE compressionMethod; ///< 압축 방법 : 2 - deflate, 1 - 변형 bzip2, 0 - 압축 안함. BYTE compressionMethod; ///< 압축 방법 : 2 - deflate, 1 - 변형 bzip2, 0 - 압축 안함.
BYTE unknown; BYTE unknown;
UINT32 fileCRC; ///< 파일의 CRC, 최상위 바이트는 암호 체크용으로도 사용된다. UINT32 fileCRC; ///< 파일의 CRC, 최상위 바이트는 암호 체크용으로도 사용된다.
//BYTE passwordCRC; ///< 암호 체크를 위한 1byte crc
INT64 compressedSize; INT64 compressedSize;
INT64 uncompressedSize; INT64 uncompressedSize;
@ -262,7 +278,7 @@ struct SLocalFileHeader
struct _SCentralDirectoryStructureHead struct _SCentralDirectoryStructureHead
{ {
UINT32 dwUnknown; ///< 항상 NULL 이던데.. UINT32 dwUnknown; ///< 항상 NULL 이던데..
UINT32 dwMaybeCRC; ///< 아마도 crc UINT32 dwUnknown2; ///< 아마도 crc
UINT32 dwCLZ03; ///< "CLZ0x03" - 0x035a4c43 끝을 표시하는듯. UINT32 dwCLZ03; ///< "CLZ0x03" - 0x035a4c43 끝을 표시하는듯.
/* /*
SHORT versionMadeBy; SHORT versionMadeBy;
@ -472,7 +488,7 @@ private : // bzip2
int BZ2_bzRead(int* bzerror, MYBZFILE* b, void* buf, int len); int BZ2_bzRead(int* bzerror, MYBZFILE* b, void* buf, int len);
void BZ2_bzReadClose( int *bzerror, MYBZFILE *b ); void BZ2_bzReadClose( int *bzerror, MYBZFILE *b );
private : // 분할 압축 파일 처리를 위한 래퍼(lapper?) 클래스 private : // 분할 압축 파일 처리를 위한 래퍼(lapper^^?) 클래스
BOOL FOpen(const char* szPathName); BOOL FOpen(const char* szPathName);
void FClose(); void FClose();
INT64 FTell(); INT64 FTell();

108
UnAlzUtils.cpp Executable file
View file

@ -0,0 +1,108 @@
#include <stdio.h>
#include <time.h>
#include "UnAlzUtils.h"
#ifdef _WIN32
# define I64FORM(x) "%"#x"I64d"
# define U64FORM(x) "%"#x"I64u"
#else
# define I64FORM(x) "%"#x"lld"
# define U64FORM(x) "%"#x"llu"
#endif
time_t dosTime2TimeT(UINT32 dostime) // from INFO-ZIP src
{
struct tm t;
t.tm_isdst = -1;
t.tm_sec = (((int)dostime) << 1) & 0x3e;
t.tm_min = (((int)dostime) >> 5) & 0x3f;
t.tm_hour = (((int)dostime) >> 11) & 0x1f;
t.tm_mday = (int)(dostime >> 16) & 0x1f;
t.tm_mon = ((int)(dostime >> 21) & 0x0f) - 1;
t.tm_year = ((int)(dostime >> 25) & 0x7f) + 80;
return mktime(&t);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
/// fileAttribute 를 스트링으로 바꿔준다.
/// @param buf - 5byte 이상
/// @param fileAttribute - ALZ_FILE_ATTRIBUTE 참조
/// @return
/// @date 2005-06-23 오후 10:12:35
////////////////////////////////////////////////////////////////////////////////////////////////////
void FileAttr2Str(char* buf, BYTE fileAttribute)
{
buf[0] = 0;
if(fileAttribute&ALZ_FILEATTR_FILE)
strcat(buf, "A");
else
strcat(buf, "_");
if(fileAttribute&ALZ_FILEATTR_DIRECTORY)
strcat(buf, "D");
else
strcat(buf, "_");
if(fileAttribute&ALZ_FILEATTR_READONLY)
strcat(buf, "R");
else
strcat(buf, "_");
if(fileAttribute&ALZ_FILEATTR_HIDDEN)
strcat(buf, "H");
else
strcat(buf, "_");
}
// alz 파일을 리스팅 한다 ( -l 옵션 )
int ListAlz(CUnAlz* pUnAlz, const char* src)
{
CUnAlz::FileList::iterator i;
CUnAlz::FileList* list;
list = pUnAlz->GetFileList();
printf("\nListing archive: %s\n"
"\n Date Time Attr Size Compressed Name\n",
src);
printf("------------------- ----- ------------ ------------ ------------\n");
char szDate[64];
char szTime[64];
char szAttr[6];
UINT64 totalUnCompressedSize = 0;
UINT64 totalCompressedSize = 0;
unsigned fileNum = 0;
time_t time;
struct tm* filetm;
for(i=list->begin(); i<list->end(); i++)
{
// time
time = dosTime2TimeT(i->head.fileTimeDate);
filetm = localtime(&time);
strftime(szTime, 64, "%H:%M:%S", filetm);
strftime(szDate, 64, "%Y:%m:%d", filetm);
// attributes
FileAttr2Str(szAttr, i->head.fileAttribute);
printf("%s %s %s " I64FORM(12) " " I64FORM(12) " %s%s\n",
szDate, szTime, szAttr, i->uncompressedSize,
i->compressedSize, i->fileName,
i->head.fileDescriptor & ALZ_FILE_DESCRIPTOR_ENCRYPTED ? "*" : "" );
++fileNum;
totalUnCompressedSize += i->uncompressedSize;
totalCompressedSize += i->compressedSize;
}
printf("------------------- ----- ------------ ------------ ------------\n");
printf(" " U64FORM(12) " " U64FORM(12) " %u file(s)\n",
totalUnCompressedSize, totalCompressedSize, fileNum);
return 0;
}

26
UnAlzUtils.h Executable file
View file

@ -0,0 +1,26 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
///
/// unalz 관련 유틸 모음
///
/// @author hardkoder
/// @date 2005-06-23 오후 9:55:34
///
////////////////////////////////////////////////////////////////////////////////////////////////////
#ifndef _UNALZ_UTILS_H_
#define _UNALZ_UTILS_H_
#include "UnAlz.h"
time_t dosTime2TimeT(UINT32 dostime);
int ListAlz(CUnAlz* pUnAlz, const char* src);
#endif // _UNALZ_UTILS_H_

View file

@ -1,321 +1,321 @@
/*-------------------------------------------------------------*/ /*-------------------------------------------------------------*/
/*--- Public header file for the library. ---*/ /*--- Public header file for the library. ---*/
/*--- bzlib.h ---*/ /*--- bzlib.h ---*/
/*-------------------------------------------------------------*/ /*-------------------------------------------------------------*/
/*-- /*--
This file is a part of bzip2 and/or libbzip2, a program and This file is a part of bzip2 and/or libbzip2, a program and
library for lossless, block-sorting data compression. library for lossless, block-sorting data compression.
Copyright (C) 1996-2002 Julian R Seward. All rights reserved. Copyright (C) 1996-2002 Julian R Seward. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
are met: are met:
1. Redistributions of source code must retain the above copyright 1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer. notice, this list of conditions and the following disclaimer.
2. The origin of this software must not be misrepresented; you must 2. The origin of this software must not be misrepresented; you must
not claim that you wrote the original software. If you use this not claim that you wrote the original software. If you use this
software in a product, an acknowledgment in the product software in a product, an acknowledgment in the product
documentation would be appreciated but is not required. documentation would be appreciated but is not required.
3. Altered source versions must be plainly marked as such, and must 3. Altered source versions must be plainly marked as such, and must
not be misrepresented as being the original software. not be misrepresented as being the original software.
4. The name of the author may not be used to endorse or promote 4. The name of the author may not be used to endorse or promote
products derived from this software without specific prior written products derived from this software without specific prior written
permission. permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Julian Seward, Cambridge, UK. Julian Seward, Cambridge, UK.
jseward@acm.org jseward@acm.org
bzip2/libbzip2 version 1.0 of 21 March 2000 bzip2/libbzip2 version 1.0 of 21 March 2000
This program is based on (at least) the work of: This program is based on (at least) the work of:
Mike Burrows Mike Burrows
David Wheeler David Wheeler
Peter Fenwick Peter Fenwick
Alistair Moffat Alistair Moffat
Radford Neal Radford Neal
Ian H. Witten Ian H. Witten
Robert Sedgewick Robert Sedgewick
Jon L. Bentley Jon L. Bentley
For more information on these sources, see the manual. For more information on these sources, see the manual.
--*/ --*/
#ifndef _BZLIB_H #ifndef _BZLIB_H
#define _BZLIB_H #define _BZLIB_H
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#define BZ_RUN 0 #define BZ_RUN 0
#define BZ_FLUSH 1 #define BZ_FLUSH 1
#define BZ_FINISH 2 #define BZ_FINISH 2
#define BZ_OK 0 #define BZ_OK 0
#define BZ_RUN_OK 1 #define BZ_RUN_OK 1
#define BZ_FLUSH_OK 2 #define BZ_FLUSH_OK 2
#define BZ_FINISH_OK 3 #define BZ_FINISH_OK 3
#define BZ_STREAM_END 4 #define BZ_STREAM_END 4
#define BZ_SEQUENCE_ERROR (-1) #define BZ_SEQUENCE_ERROR (-1)
#define BZ_PARAM_ERROR (-2) #define BZ_PARAM_ERROR (-2)
#define BZ_MEM_ERROR (-3) #define BZ_MEM_ERROR (-3)
#define BZ_DATA_ERROR (-4) #define BZ_DATA_ERROR (-4)
#define BZ_DATA_ERROR_MAGIC (-5) #define BZ_DATA_ERROR_MAGIC (-5)
#define BZ_IO_ERROR (-6) #define BZ_IO_ERROR (-6)
#define BZ_UNEXPECTED_EOF (-7) #define BZ_UNEXPECTED_EOF (-7)
#define BZ_OUTBUFF_FULL (-8) #define BZ_OUTBUFF_FULL (-8)
#define BZ_CONFIG_ERROR (-9) #define BZ_CONFIG_ERROR (-9)
typedef typedef
struct { struct {
char *next_in; char *next_in;
unsigned int avail_in; unsigned int avail_in;
unsigned int total_in_lo32; unsigned int total_in_lo32;
unsigned int total_in_hi32; unsigned int total_in_hi32;
char *next_out; char *next_out;
unsigned int avail_out; unsigned int avail_out;
unsigned int total_out_lo32; unsigned int total_out_lo32;
unsigned int total_out_hi32; unsigned int total_out_hi32;
void *state; void *state;
void *(*bzalloc)(void *,int,int); void *(*bzalloc)(void *,int,int);
void (*bzfree)(void *,void *); void (*bzfree)(void *,void *);
void *opaque; void *opaque;
} }
bz_stream; bz_stream;
#ifndef BZ_IMPORT #ifndef BZ_IMPORT
#define BZ_EXPORT #define BZ_EXPORT
#endif #endif
/* Need a definitition for FILE */ /* Need a definitition for FILE */
#include <stdio.h> #include <stdio.h>
#ifdef _WIN32 #ifdef _WIN32
# include <windows.h> # include <windows.h>
# ifdef small # ifdef small
/* windows.h define small to char */ /* windows.h define small to char */
# undef small # undef small
# endif # endif
# ifdef BZ_EXPORT # ifdef BZ_EXPORT
# define BZ_API(func) WINAPI func # define BZ_API(func) WINAPI func
# define BZ_EXTERN extern # define BZ_EXTERN extern
# else # else
/* import windows dll dynamically */ /* import windows dll dynamically */
# define BZ_API(func) (WINAPI * func) # define BZ_API(func) (WINAPI * func)
# define BZ_EXTERN # define BZ_EXTERN
# endif # endif
#else #else
# define BZ_API(func) func # define BZ_API(func) func
# define BZ_EXTERN extern # define BZ_EXTERN extern
#endif #endif
/*-- Core (low-level) library functions --*/ /*-- Core (low-level) library functions --*/
BZ_EXTERN int BZ_API(BZ2_bzCompressInit) ( BZ_EXTERN int BZ_API(BZ2_bzCompressInit) (
bz_stream* strm, bz_stream* strm,
int blockSize100k, int blockSize100k,
int verbosity, int verbosity,
int workFactor int workFactor
); );
BZ_EXTERN int BZ_API(BZ2_bzCompress) ( BZ_EXTERN int BZ_API(BZ2_bzCompress) (
bz_stream* strm, bz_stream* strm,
int action int action
); );
BZ_EXTERN int BZ_API(BZ2_bzCompressEnd) ( BZ_EXTERN int BZ_API(BZ2_bzCompressEnd) (
bz_stream* strm bz_stream* strm
); );
BZ_EXTERN int BZ_API(BZ2_bzDecompressInit) ( BZ_EXTERN int BZ_API(BZ2_bzDecompressInit) (
bz_stream *strm, bz_stream *strm,
int verbosity, int verbosity,
int small int small
); );
BZ_EXTERN int BZ_API(BZ2_bzDecompress) ( BZ_EXTERN int BZ_API(BZ2_bzDecompress) (
bz_stream* strm bz_stream* strm
); );
BZ_EXTERN int BZ_API(BZ2_bzDecompressEnd) ( BZ_EXTERN int BZ_API(BZ2_bzDecompressEnd) (
bz_stream *strm bz_stream *strm
); );
/*-- High(er) level library functions --*/ /*-- High(er) level library functions --*/
#ifndef BZ_NO_STDIO #ifndef BZ_NO_STDIO
#define BZ_MAX_UNUSED 5000 #define BZ_MAX_UNUSED 5000
typedef void BZFILE; typedef void BZFILE;
BZ_EXTERN BZFILE* BZ_API(BZ2_bzReadOpen) ( BZ_EXTERN BZFILE* BZ_API(BZ2_bzReadOpen) (
int* bzerror, int* bzerror,
FILE* f, FILE* f,
int verbosity, int verbosity,
int small, int small,
void* unused, void* unused,
int nUnused int nUnused
); );
BZ_EXTERN void BZ_API(BZ2_bzReadClose) ( BZ_EXTERN void BZ_API(BZ2_bzReadClose) (
int* bzerror, int* bzerror,
BZFILE* b BZFILE* b
); );
BZ_EXTERN void BZ_API(BZ2_bzReadGetUnused) ( BZ_EXTERN void BZ_API(BZ2_bzReadGetUnused) (
int* bzerror, int* bzerror,
BZFILE* b, BZFILE* b,
void** unused, void** unused,
int* nUnused int* nUnused
); );
BZ_EXTERN int BZ_API(BZ2_bzRead) ( BZ_EXTERN int BZ_API(BZ2_bzRead) (
int* bzerror, int* bzerror,
BZFILE* b, BZFILE* b,
void* buf, void* buf,
int len int len
); );
BZ_EXTERN BZFILE* BZ_API(BZ2_bzWriteOpen) ( BZ_EXTERN BZFILE* BZ_API(BZ2_bzWriteOpen) (
int* bzerror, int* bzerror,
FILE* f, FILE* f,
int blockSize100k, int blockSize100k,
int verbosity, int verbosity,
int workFactor int workFactor
); );
BZ_EXTERN void BZ_API(BZ2_bzWrite) ( BZ_EXTERN void BZ_API(BZ2_bzWrite) (
int* bzerror, int* bzerror,
BZFILE* b, BZFILE* b,
void* buf, void* buf,
int len int len
); );
BZ_EXTERN void BZ_API(BZ2_bzWriteClose) ( BZ_EXTERN void BZ_API(BZ2_bzWriteClose) (
int* bzerror, int* bzerror,
BZFILE* b, BZFILE* b,
int abandon, int abandon,
unsigned int* nbytes_in, unsigned int* nbytes_in,
unsigned int* nbytes_out unsigned int* nbytes_out
); );
BZ_EXTERN void BZ_API(BZ2_bzWriteClose64) ( BZ_EXTERN void BZ_API(BZ2_bzWriteClose64) (
int* bzerror, int* bzerror,
BZFILE* b, BZFILE* b,
int abandon, int abandon,
unsigned int* nbytes_in_lo32, unsigned int* nbytes_in_lo32,
unsigned int* nbytes_in_hi32, unsigned int* nbytes_in_hi32,
unsigned int* nbytes_out_lo32, unsigned int* nbytes_out_lo32,
unsigned int* nbytes_out_hi32 unsigned int* nbytes_out_hi32
); );
#endif #endif
/*-- Utility functions --*/ /*-- Utility functions --*/
BZ_EXTERN int BZ_API(BZ2_bzBuffToBuffCompress) ( BZ_EXTERN int BZ_API(BZ2_bzBuffToBuffCompress) (
char* dest, char* dest,
unsigned int* destLen, unsigned int* destLen,
char* source, char* source,
unsigned int sourceLen, unsigned int sourceLen,
int blockSize100k, int blockSize100k,
int verbosity, int verbosity,
int workFactor int workFactor
); );
BZ_EXTERN int BZ_API(BZ2_bzBuffToBuffDecompress) ( BZ_EXTERN int BZ_API(BZ2_bzBuffToBuffDecompress) (
char* dest, char* dest,
unsigned int* destLen, unsigned int* destLen,
char* source, char* source,
unsigned int sourceLen, unsigned int sourceLen,
int small, int small,
int verbosity int verbosity
); );
/*-- /*--
Code contributed by Yoshioka Tsuneo Code contributed by Yoshioka Tsuneo
(QWF00133@niftyserve.or.jp/tsuneo-y@is.aist-nara.ac.jp), (QWF00133@niftyserve.or.jp/tsuneo-y@is.aist-nara.ac.jp),
to support better zlib compatibility. to support better zlib compatibility.
This code is not _officially_ part of libbzip2 (yet); This code is not _officially_ part of libbzip2 (yet);
I haven't tested it, documented it, or considered the I haven't tested it, documented it, or considered the
threading-safeness of it. threading-safeness of it.
If this code breaks, please contact both Yoshioka and me. If this code breaks, please contact both Yoshioka and me.
--*/ --*/
BZ_EXTERN const char * BZ_API(BZ2_bzlibVersion) ( BZ_EXTERN const char * BZ_API(BZ2_bzlibVersion) (
void void
); );
#ifndef BZ_NO_STDIO #ifndef BZ_NO_STDIO
BZ_EXTERN BZFILE * BZ_API(BZ2_bzopen) ( BZ_EXTERN BZFILE * BZ_API(BZ2_bzopen) (
const char *path, const char *path,
const char *mode const char *mode
); );
BZ_EXTERN BZFILE * BZ_API(BZ2_bzdopen) ( BZ_EXTERN BZFILE * BZ_API(BZ2_bzdopen) (
int fd, int fd,
const char *mode const char *mode
); );
BZ_EXTERN int BZ_API(BZ2_bzread) ( BZ_EXTERN int BZ_API(BZ2_bzread) (
BZFILE* b, BZFILE* b,
void* buf, void* buf,
int len int len
); );
BZ_EXTERN int BZ_API(BZ2_bzwrite) ( BZ_EXTERN int BZ_API(BZ2_bzwrite) (
BZFILE* b, BZFILE* b,
void* buf, void* buf,
int len int len
); );
BZ_EXTERN int BZ_API(BZ2_bzflush) ( BZ_EXTERN int BZ_API(BZ2_bzflush) (
BZFILE* b BZFILE* b
); );
BZ_EXTERN void BZ_API(BZ2_bzclose) ( BZ_EXTERN void BZ_API(BZ2_bzclose) (
BZFILE* b BZFILE* b
); );
BZ_EXTERN const char * BZ_API(BZ2_bzerror) ( BZ_EXTERN const char * BZ_API(BZ2_bzerror) (
BZFILE *b, BZFILE *b,
int *errnum int *errnum
); );
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif #endif
/*-------------------------------------------------------------*/ /*-------------------------------------------------------------*/
/*--- end bzlib.h ---*/ /*--- end bzlib.h ---*/
/*-------------------------------------------------------------*/ /*-------------------------------------------------------------*/

View file

@ -1,144 +1,144 @@
/*-------------------------------------------------------------*/ /*-------------------------------------------------------------*/
/*--- Table for doing CRCs ---*/ /*--- Table for doing CRCs ---*/
/*--- crctable.c ---*/ /*--- crctable.c ---*/
/*-------------------------------------------------------------*/ /*-------------------------------------------------------------*/
/*-- /*--
This file is a part of bzip2 and/or libbzip2, a program and This file is a part of bzip2 and/or libbzip2, a program and
library for lossless, block-sorting data compression. library for lossless, block-sorting data compression.
Copyright (C) 1996-2002 Julian R Seward. All rights reserved. Copyright (C) 1996-2002 Julian R Seward. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
are met: are met:
1. Redistributions of source code must retain the above copyright 1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer. notice, this list of conditions and the following disclaimer.
2. The origin of this software must not be misrepresented; you must 2. The origin of this software must not be misrepresented; you must
not claim that you wrote the original software. If you use this not claim that you wrote the original software. If you use this
software in a product, an acknowledgment in the product software in a product, an acknowledgment in the product
documentation would be appreciated but is not required. documentation would be appreciated but is not required.
3. Altered source versions must be plainly marked as such, and must 3. Altered source versions must be plainly marked as such, and must
not be misrepresented as being the original software. not be misrepresented as being the original software.
4. The name of the author may not be used to endorse or promote 4. The name of the author may not be used to endorse or promote
products derived from this software without specific prior written products derived from this software without specific prior written
permission. permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Julian Seward, Cambridge, UK. Julian Seward, Cambridge, UK.
jseward@acm.org jseward@acm.org
bzip2/libbzip2 version 1.0 of 21 March 2000 bzip2/libbzip2 version 1.0 of 21 March 2000
This program is based on (at least) the work of: This program is based on (at least) the work of:
Mike Burrows Mike Burrows
David Wheeler David Wheeler
Peter Fenwick Peter Fenwick
Alistair Moffat Alistair Moffat
Radford Neal Radford Neal
Ian H. Witten Ian H. Witten
Robert Sedgewick Robert Sedgewick
Jon L. Bentley Jon L. Bentley
For more information on these sources, see the manual. For more information on these sources, see the manual.
--*/ --*/
#include "bzlib_private.h" #include "bzlib_private.h"
/*-- /*--
I think this is an implementation of the AUTODIN-II, I think this is an implementation of the AUTODIN-II,
Ethernet & FDDI 32-bit CRC standard. Vaguely derived Ethernet & FDDI 32-bit CRC standard. Vaguely derived
from code by Rob Warnock, in Section 51 of the from code by Rob Warnock, in Section 51 of the
comp.compression FAQ. comp.compression FAQ.
--*/ --*/
UInt32 BZ2_crc32Table[256] = { UInt32 BZ2_crc32Table[256] = {
/*-- Ugly, innit? --*/ /*-- Ugly, innit? --*/
0x00000000L, 0x04c11db7L, 0x09823b6eL, 0x0d4326d9L, 0x00000000L, 0x04c11db7L, 0x09823b6eL, 0x0d4326d9L,
0x130476dcL, 0x17c56b6bL, 0x1a864db2L, 0x1e475005L, 0x130476dcL, 0x17c56b6bL, 0x1a864db2L, 0x1e475005L,
0x2608edb8L, 0x22c9f00fL, 0x2f8ad6d6L, 0x2b4bcb61L, 0x2608edb8L, 0x22c9f00fL, 0x2f8ad6d6L, 0x2b4bcb61L,
0x350c9b64L, 0x31cd86d3L, 0x3c8ea00aL, 0x384fbdbdL, 0x350c9b64L, 0x31cd86d3L, 0x3c8ea00aL, 0x384fbdbdL,
0x4c11db70L, 0x48d0c6c7L, 0x4593e01eL, 0x4152fda9L, 0x4c11db70L, 0x48d0c6c7L, 0x4593e01eL, 0x4152fda9L,
0x5f15adacL, 0x5bd4b01bL, 0x569796c2L, 0x52568b75L, 0x5f15adacL, 0x5bd4b01bL, 0x569796c2L, 0x52568b75L,
0x6a1936c8L, 0x6ed82b7fL, 0x639b0da6L, 0x675a1011L, 0x6a1936c8L, 0x6ed82b7fL, 0x639b0da6L, 0x675a1011L,
0x791d4014L, 0x7ddc5da3L, 0x709f7b7aL, 0x745e66cdL, 0x791d4014L, 0x7ddc5da3L, 0x709f7b7aL, 0x745e66cdL,
0x9823b6e0L, 0x9ce2ab57L, 0x91a18d8eL, 0x95609039L, 0x9823b6e0L, 0x9ce2ab57L, 0x91a18d8eL, 0x95609039L,
0x8b27c03cL, 0x8fe6dd8bL, 0x82a5fb52L, 0x8664e6e5L, 0x8b27c03cL, 0x8fe6dd8bL, 0x82a5fb52L, 0x8664e6e5L,
0xbe2b5b58L, 0xbaea46efL, 0xb7a96036L, 0xb3687d81L, 0xbe2b5b58L, 0xbaea46efL, 0xb7a96036L, 0xb3687d81L,
0xad2f2d84L, 0xa9ee3033L, 0xa4ad16eaL, 0xa06c0b5dL, 0xad2f2d84L, 0xa9ee3033L, 0xa4ad16eaL, 0xa06c0b5dL,
0xd4326d90L, 0xd0f37027L, 0xddb056feL, 0xd9714b49L, 0xd4326d90L, 0xd0f37027L, 0xddb056feL, 0xd9714b49L,
0xc7361b4cL, 0xc3f706fbL, 0xceb42022L, 0xca753d95L, 0xc7361b4cL, 0xc3f706fbL, 0xceb42022L, 0xca753d95L,
0xf23a8028L, 0xf6fb9d9fL, 0xfbb8bb46L, 0xff79a6f1L, 0xf23a8028L, 0xf6fb9d9fL, 0xfbb8bb46L, 0xff79a6f1L,
0xe13ef6f4L, 0xe5ffeb43L, 0xe8bccd9aL, 0xec7dd02dL, 0xe13ef6f4L, 0xe5ffeb43L, 0xe8bccd9aL, 0xec7dd02dL,
0x34867077L, 0x30476dc0L, 0x3d044b19L, 0x39c556aeL, 0x34867077L, 0x30476dc0L, 0x3d044b19L, 0x39c556aeL,
0x278206abL, 0x23431b1cL, 0x2e003dc5L, 0x2ac12072L, 0x278206abL, 0x23431b1cL, 0x2e003dc5L, 0x2ac12072L,
0x128e9dcfL, 0x164f8078L, 0x1b0ca6a1L, 0x1fcdbb16L, 0x128e9dcfL, 0x164f8078L, 0x1b0ca6a1L, 0x1fcdbb16L,
0x018aeb13L, 0x054bf6a4L, 0x0808d07dL, 0x0cc9cdcaL, 0x018aeb13L, 0x054bf6a4L, 0x0808d07dL, 0x0cc9cdcaL,
0x7897ab07L, 0x7c56b6b0L, 0x71159069L, 0x75d48ddeL, 0x7897ab07L, 0x7c56b6b0L, 0x71159069L, 0x75d48ddeL,
0x6b93dddbL, 0x6f52c06cL, 0x6211e6b5L, 0x66d0fb02L, 0x6b93dddbL, 0x6f52c06cL, 0x6211e6b5L, 0x66d0fb02L,
0x5e9f46bfL, 0x5a5e5b08L, 0x571d7dd1L, 0x53dc6066L, 0x5e9f46bfL, 0x5a5e5b08L, 0x571d7dd1L, 0x53dc6066L,
0x4d9b3063L, 0x495a2dd4L, 0x44190b0dL, 0x40d816baL, 0x4d9b3063L, 0x495a2dd4L, 0x44190b0dL, 0x40d816baL,
0xaca5c697L, 0xa864db20L, 0xa527fdf9L, 0xa1e6e04eL, 0xaca5c697L, 0xa864db20L, 0xa527fdf9L, 0xa1e6e04eL,
0xbfa1b04bL, 0xbb60adfcL, 0xb6238b25L, 0xb2e29692L, 0xbfa1b04bL, 0xbb60adfcL, 0xb6238b25L, 0xb2e29692L,
0x8aad2b2fL, 0x8e6c3698L, 0x832f1041L, 0x87ee0df6L, 0x8aad2b2fL, 0x8e6c3698L, 0x832f1041L, 0x87ee0df6L,
0x99a95df3L, 0x9d684044L, 0x902b669dL, 0x94ea7b2aL, 0x99a95df3L, 0x9d684044L, 0x902b669dL, 0x94ea7b2aL,
0xe0b41de7L, 0xe4750050L, 0xe9362689L, 0xedf73b3eL, 0xe0b41de7L, 0xe4750050L, 0xe9362689L, 0xedf73b3eL,
0xf3b06b3bL, 0xf771768cL, 0xfa325055L, 0xfef34de2L, 0xf3b06b3bL, 0xf771768cL, 0xfa325055L, 0xfef34de2L,
0xc6bcf05fL, 0xc27dede8L, 0xcf3ecb31L, 0xcbffd686L, 0xc6bcf05fL, 0xc27dede8L, 0xcf3ecb31L, 0xcbffd686L,
0xd5b88683L, 0xd1799b34L, 0xdc3abdedL, 0xd8fba05aL, 0xd5b88683L, 0xd1799b34L, 0xdc3abdedL, 0xd8fba05aL,
0x690ce0eeL, 0x6dcdfd59L, 0x608edb80L, 0x644fc637L, 0x690ce0eeL, 0x6dcdfd59L, 0x608edb80L, 0x644fc637L,
0x7a089632L, 0x7ec98b85L, 0x738aad5cL, 0x774bb0ebL, 0x7a089632L, 0x7ec98b85L, 0x738aad5cL, 0x774bb0ebL,
0x4f040d56L, 0x4bc510e1L, 0x46863638L, 0x42472b8fL, 0x4f040d56L, 0x4bc510e1L, 0x46863638L, 0x42472b8fL,
0x5c007b8aL, 0x58c1663dL, 0x558240e4L, 0x51435d53L, 0x5c007b8aL, 0x58c1663dL, 0x558240e4L, 0x51435d53L,
0x251d3b9eL, 0x21dc2629L, 0x2c9f00f0L, 0x285e1d47L, 0x251d3b9eL, 0x21dc2629L, 0x2c9f00f0L, 0x285e1d47L,
0x36194d42L, 0x32d850f5L, 0x3f9b762cL, 0x3b5a6b9bL, 0x36194d42L, 0x32d850f5L, 0x3f9b762cL, 0x3b5a6b9bL,
0x0315d626L, 0x07d4cb91L, 0x0a97ed48L, 0x0e56f0ffL, 0x0315d626L, 0x07d4cb91L, 0x0a97ed48L, 0x0e56f0ffL,
0x1011a0faL, 0x14d0bd4dL, 0x19939b94L, 0x1d528623L, 0x1011a0faL, 0x14d0bd4dL, 0x19939b94L, 0x1d528623L,
0xf12f560eL, 0xf5ee4bb9L, 0xf8ad6d60L, 0xfc6c70d7L, 0xf12f560eL, 0xf5ee4bb9L, 0xf8ad6d60L, 0xfc6c70d7L,
0xe22b20d2L, 0xe6ea3d65L, 0xeba91bbcL, 0xef68060bL, 0xe22b20d2L, 0xe6ea3d65L, 0xeba91bbcL, 0xef68060bL,
0xd727bbb6L, 0xd3e6a601L, 0xdea580d8L, 0xda649d6fL, 0xd727bbb6L, 0xd3e6a601L, 0xdea580d8L, 0xda649d6fL,
0xc423cd6aL, 0xc0e2d0ddL, 0xcda1f604L, 0xc960ebb3L, 0xc423cd6aL, 0xc0e2d0ddL, 0xcda1f604L, 0xc960ebb3L,
0xbd3e8d7eL, 0xb9ff90c9L, 0xb4bcb610L, 0xb07daba7L, 0xbd3e8d7eL, 0xb9ff90c9L, 0xb4bcb610L, 0xb07daba7L,
0xae3afba2L, 0xaafbe615L, 0xa7b8c0ccL, 0xa379dd7bL, 0xae3afba2L, 0xaafbe615L, 0xa7b8c0ccL, 0xa379dd7bL,
0x9b3660c6L, 0x9ff77d71L, 0x92b45ba8L, 0x9675461fL, 0x9b3660c6L, 0x9ff77d71L, 0x92b45ba8L, 0x9675461fL,
0x8832161aL, 0x8cf30badL, 0x81b02d74L, 0x857130c3L, 0x8832161aL, 0x8cf30badL, 0x81b02d74L, 0x857130c3L,
0x5d8a9099L, 0x594b8d2eL, 0x5408abf7L, 0x50c9b640L, 0x5d8a9099L, 0x594b8d2eL, 0x5408abf7L, 0x50c9b640L,
0x4e8ee645L, 0x4a4ffbf2L, 0x470cdd2bL, 0x43cdc09cL, 0x4e8ee645L, 0x4a4ffbf2L, 0x470cdd2bL, 0x43cdc09cL,
0x7b827d21L, 0x7f436096L, 0x7200464fL, 0x76c15bf8L, 0x7b827d21L, 0x7f436096L, 0x7200464fL, 0x76c15bf8L,
0x68860bfdL, 0x6c47164aL, 0x61043093L, 0x65c52d24L, 0x68860bfdL, 0x6c47164aL, 0x61043093L, 0x65c52d24L,
0x119b4be9L, 0x155a565eL, 0x18197087L, 0x1cd86d30L, 0x119b4be9L, 0x155a565eL, 0x18197087L, 0x1cd86d30L,
0x029f3d35L, 0x065e2082L, 0x0b1d065bL, 0x0fdc1becL, 0x029f3d35L, 0x065e2082L, 0x0b1d065bL, 0x0fdc1becL,
0x3793a651L, 0x3352bbe6L, 0x3e119d3fL, 0x3ad08088L, 0x3793a651L, 0x3352bbe6L, 0x3e119d3fL, 0x3ad08088L,
0x2497d08dL, 0x2056cd3aL, 0x2d15ebe3L, 0x29d4f654L, 0x2497d08dL, 0x2056cd3aL, 0x2d15ebe3L, 0x29d4f654L,
0xc5a92679L, 0xc1683bceL, 0xcc2b1d17L, 0xc8ea00a0L, 0xc5a92679L, 0xc1683bceL, 0xcc2b1d17L, 0xc8ea00a0L,
0xd6ad50a5L, 0xd26c4d12L, 0xdf2f6bcbL, 0xdbee767cL, 0xd6ad50a5L, 0xd26c4d12L, 0xdf2f6bcbL, 0xdbee767cL,
0xe3a1cbc1L, 0xe760d676L, 0xea23f0afL, 0xeee2ed18L, 0xe3a1cbc1L, 0xe760d676L, 0xea23f0afL, 0xeee2ed18L,
0xf0a5bd1dL, 0xf464a0aaL, 0xf9278673L, 0xfde69bc4L, 0xf0a5bd1dL, 0xf464a0aaL, 0xf9278673L, 0xfde69bc4L,
0x89b8fd09L, 0x8d79e0beL, 0x803ac667L, 0x84fbdbd0L, 0x89b8fd09L, 0x8d79e0beL, 0x803ac667L, 0x84fbdbd0L,
0x9abc8bd5L, 0x9e7d9662L, 0x933eb0bbL, 0x97ffad0cL, 0x9abc8bd5L, 0x9e7d9662L, 0x933eb0bbL, 0x97ffad0cL,
0xafb010b1L, 0xab710d06L, 0xa6322bdfL, 0xa2f33668L, 0xafb010b1L, 0xab710d06L, 0xa6322bdfL, 0xa2f33668L,
0xbcb4666dL, 0xb8757bdaL, 0xb5365d03L, 0xb1f740b4L 0xbcb4666dL, 0xb8757bdaL, 0xb5365d03L, 0xb1f740b4L
}; };
/*-------------------------------------------------------------*/ /*-------------------------------------------------------------*/
/*--- end crctable.c ---*/ /*--- end crctable.c ---*/
/*-------------------------------------------------------------*/ /*-------------------------------------------------------------*/

View file

@ -1,124 +1,124 @@
/*-------------------------------------------------------------*/ /*-------------------------------------------------------------*/
/*--- Table for randomising repetitive blocks ---*/ /*--- Table for randomising repetitive blocks ---*/
/*--- randtable.c ---*/ /*--- randtable.c ---*/
/*-------------------------------------------------------------*/ /*-------------------------------------------------------------*/
/*-- /*--
This file is a part of bzip2 and/or libbzip2, a program and This file is a part of bzip2 and/or libbzip2, a program and
library for lossless, block-sorting data compression. library for lossless, block-sorting data compression.
Copyright (C) 1996-2002 Julian R Seward. All rights reserved. Copyright (C) 1996-2002 Julian R Seward. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
are met: are met:
1. Redistributions of source code must retain the above copyright 1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer. notice, this list of conditions and the following disclaimer.
2. The origin of this software must not be misrepresented; you must 2. The origin of this software must not be misrepresented; you must
not claim that you wrote the original software. If you use this not claim that you wrote the original software. If you use this
software in a product, an acknowledgment in the product software in a product, an acknowledgment in the product
documentation would be appreciated but is not required. documentation would be appreciated but is not required.
3. Altered source versions must be plainly marked as such, and must 3. Altered source versions must be plainly marked as such, and must
not be misrepresented as being the original software. not be misrepresented as being the original software.
4. The name of the author may not be used to endorse or promote 4. The name of the author may not be used to endorse or promote
products derived from this software without specific prior written products derived from this software without specific prior written
permission. permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Julian Seward, Cambridge, UK. Julian Seward, Cambridge, UK.
jseward@acm.org jseward@acm.org
bzip2/libbzip2 version 1.0 of 21 March 2000 bzip2/libbzip2 version 1.0 of 21 March 2000
This program is based on (at least) the work of: This program is based on (at least) the work of:
Mike Burrows Mike Burrows
David Wheeler David Wheeler
Peter Fenwick Peter Fenwick
Alistair Moffat Alistair Moffat
Radford Neal Radford Neal
Ian H. Witten Ian H. Witten
Robert Sedgewick Robert Sedgewick
Jon L. Bentley Jon L. Bentley
For more information on these sources, see the manual. For more information on these sources, see the manual.
--*/ --*/
#include "bzlib_private.h" #include "bzlib_private.h"
/*---------------------------------------------*/ /*---------------------------------------------*/
Int32 BZ2_rNums[512] = { Int32 BZ2_rNums[512] = {
619, 720, 127, 481, 931, 816, 813, 233, 566, 247, 619, 720, 127, 481, 931, 816, 813, 233, 566, 247,
985, 724, 205, 454, 863, 491, 741, 242, 949, 214, 985, 724, 205, 454, 863, 491, 741, 242, 949, 214,
733, 859, 335, 708, 621, 574, 73, 654, 730, 472, 733, 859, 335, 708, 621, 574, 73, 654, 730, 472,
419, 436, 278, 496, 867, 210, 399, 680, 480, 51, 419, 436, 278, 496, 867, 210, 399, 680, 480, 51,
878, 465, 811, 169, 869, 675, 611, 697, 867, 561, 878, 465, 811, 169, 869, 675, 611, 697, 867, 561,
862, 687, 507, 283, 482, 129, 807, 591, 733, 623, 862, 687, 507, 283, 482, 129, 807, 591, 733, 623,
150, 238, 59, 379, 684, 877, 625, 169, 643, 105, 150, 238, 59, 379, 684, 877, 625, 169, 643, 105,
170, 607, 520, 932, 727, 476, 693, 425, 174, 647, 170, 607, 520, 932, 727, 476, 693, 425, 174, 647,
73, 122, 335, 530, 442, 853, 695, 249, 445, 515, 73, 122, 335, 530, 442, 853, 695, 249, 445, 515,
909, 545, 703, 919, 874, 474, 882, 500, 594, 612, 909, 545, 703, 919, 874, 474, 882, 500, 594, 612,
641, 801, 220, 162, 819, 984, 589, 513, 495, 799, 641, 801, 220, 162, 819, 984, 589, 513, 495, 799,
161, 604, 958, 533, 221, 400, 386, 867, 600, 782, 161, 604, 958, 533, 221, 400, 386, 867, 600, 782,
382, 596, 414, 171, 516, 375, 682, 485, 911, 276, 382, 596, 414, 171, 516, 375, 682, 485, 911, 276,
98, 553, 163, 354, 666, 933, 424, 341, 533, 870, 98, 553, 163, 354, 666, 933, 424, 341, 533, 870,
227, 730, 475, 186, 263, 647, 537, 686, 600, 224, 227, 730, 475, 186, 263, 647, 537, 686, 600, 224,
469, 68, 770, 919, 190, 373, 294, 822, 808, 206, 469, 68, 770, 919, 190, 373, 294, 822, 808, 206,
184, 943, 795, 384, 383, 461, 404, 758, 839, 887, 184, 943, 795, 384, 383, 461, 404, 758, 839, 887,
715, 67, 618, 276, 204, 918, 873, 777, 604, 560, 715, 67, 618, 276, 204, 918, 873, 777, 604, 560,
951, 160, 578, 722, 79, 804, 96, 409, 713, 940, 951, 160, 578, 722, 79, 804, 96, 409, 713, 940,
652, 934, 970, 447, 318, 353, 859, 672, 112, 785, 652, 934, 970, 447, 318, 353, 859, 672, 112, 785,
645, 863, 803, 350, 139, 93, 354, 99, 820, 908, 645, 863, 803, 350, 139, 93, 354, 99, 820, 908,
609, 772, 154, 274, 580, 184, 79, 626, 630, 742, 609, 772, 154, 274, 580, 184, 79, 626, 630, 742,
653, 282, 762, 623, 680, 81, 927, 626, 789, 125, 653, 282, 762, 623, 680, 81, 927, 626, 789, 125,
411, 521, 938, 300, 821, 78, 343, 175, 128, 250, 411, 521, 938, 300, 821, 78, 343, 175, 128, 250,
170, 774, 972, 275, 999, 639, 495, 78, 352, 126, 170, 774, 972, 275, 999, 639, 495, 78, 352, 126,
857, 956, 358, 619, 580, 124, 737, 594, 701, 612, 857, 956, 358, 619, 580, 124, 737, 594, 701, 612,
669, 112, 134, 694, 363, 992, 809, 743, 168, 974, 669, 112, 134, 694, 363, 992, 809, 743, 168, 974,
944, 375, 748, 52, 600, 747, 642, 182, 862, 81, 944, 375, 748, 52, 600, 747, 642, 182, 862, 81,
344, 805, 988, 739, 511, 655, 814, 334, 249, 515, 344, 805, 988, 739, 511, 655, 814, 334, 249, 515,
897, 955, 664, 981, 649, 113, 974, 459, 893, 228, 897, 955, 664, 981, 649, 113, 974, 459, 893, 228,
433, 837, 553, 268, 926, 240, 102, 654, 459, 51, 433, 837, 553, 268, 926, 240, 102, 654, 459, 51,
686, 754, 806, 760, 493, 403, 415, 394, 687, 700, 686, 754, 806, 760, 493, 403, 415, 394, 687, 700,
946, 670, 656, 610, 738, 392, 760, 799, 887, 653, 946, 670, 656, 610, 738, 392, 760, 799, 887, 653,
978, 321, 576, 617, 626, 502, 894, 679, 243, 440, 978, 321, 576, 617, 626, 502, 894, 679, 243, 440,
680, 879, 194, 572, 640, 724, 926, 56, 204, 700, 680, 879, 194, 572, 640, 724, 926, 56, 204, 700,
707, 151, 457, 449, 797, 195, 791, 558, 945, 679, 707, 151, 457, 449, 797, 195, 791, 558, 945, 679,
297, 59, 87, 824, 713, 663, 412, 693, 342, 606, 297, 59, 87, 824, 713, 663, 412, 693, 342, 606,
134, 108, 571, 364, 631, 212, 174, 643, 304, 329, 134, 108, 571, 364, 631, 212, 174, 643, 304, 329,
343, 97, 430, 751, 497, 314, 983, 374, 822, 928, 343, 97, 430, 751, 497, 314, 983, 374, 822, 928,
140, 206, 73, 263, 980, 736, 876, 478, 430, 305, 140, 206, 73, 263, 980, 736, 876, 478, 430, 305,
170, 514, 364, 692, 829, 82, 855, 953, 676, 246, 170, 514, 364, 692, 829, 82, 855, 953, 676, 246,
369, 970, 294, 750, 807, 827, 150, 790, 288, 923, 369, 970, 294, 750, 807, 827, 150, 790, 288, 923,
804, 378, 215, 828, 592, 281, 565, 555, 710, 82, 804, 378, 215, 828, 592, 281, 565, 555, 710, 82,
896, 831, 547, 261, 524, 462, 293, 465, 502, 56, 896, 831, 547, 261, 524, 462, 293, 465, 502, 56,
661, 821, 976, 991, 658, 869, 905, 758, 745, 193, 661, 821, 976, 991, 658, 869, 905, 758, 745, 193,
768, 550, 608, 933, 378, 286, 215, 979, 792, 961, 768, 550, 608, 933, 378, 286, 215, 979, 792, 961,
61, 688, 793, 644, 986, 403, 106, 366, 905, 644, 61, 688, 793, 644, 986, 403, 106, 366, 905, 644,
372, 567, 466, 434, 645, 210, 389, 550, 919, 135, 372, 567, 466, 434, 645, 210, 389, 550, 919, 135,
780, 773, 635, 389, 707, 100, 626, 958, 165, 504, 780, 773, 635, 389, 707, 100, 626, 958, 165, 504,
920, 176, 193, 713, 857, 265, 203, 50, 668, 108, 920, 176, 193, 713, 857, 265, 203, 50, 668, 108,
645, 990, 626, 197, 510, 357, 358, 850, 858, 364, 645, 990, 626, 197, 510, 357, 358, 850, 858, 364,
936, 638 936, 638
}; };
/*-------------------------------------------------------------*/ /*-------------------------------------------------------------*/
/*--- end randtable.c ---*/ /*--- end randtable.c ---*/
/*-------------------------------------------------------------*/ /*-------------------------------------------------------------*/

View file

@ -1,4 +1,5 @@
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 *.scc /s 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 *.scc *.bak /s
del unalz.exe
rmdir bin rmdir bin
rmdir release rmdir release
rmdir debug rmdir debug

189
main.cpp
View file

@ -1,11 +1,20 @@
#ifdef _WIN32
# pragma warning( disable : 4786 ) // stl warning 없애기
#endif
#include <stdio.h> #include <stdio.h>
#include <iostream> #include <iostream>
#include <time.h>
#include <string>
#include <vector>
#include "UnAlz.h" #include "UnAlz.h"
#include "UnAlzUtils.h"
void Usage() void Usage()
{ {
printf("\n"); printf("\n");
/*
#ifdef _UNALZ_ICONV #ifdef _UNALZ_ICONV
printf("USAGE : unalz [ -utf8 | -cp949 | -euc-kr ] sourcefile.alz [dest path] \n"); printf("USAGE : unalz [ -utf8 | -cp949 | -euc-kr ] sourcefile.alz [dest path] \n");
# ifdef _UNALZ_UTF8 # ifdef _UNALZ_UTF8
@ -20,8 +29,32 @@ void Usage()
#else // no iconv #else // no iconv
printf("USAGE : unalz sourcefile.alz [dest path] \n"); printf("USAGE : unalz sourcefile.alz [dest path] \n");
#endif // _UNALZ_ICONV #endif // _UNALZ_ICONV
*/
printf("Usage : unalz [<switches>...] archive.alz [<file names to extract>...]\n");
printf("\n");
printf("<switches>\n");
#ifdef _UNALZ_ICONV
# ifdef _UNALZ_UTF8
printf(" -utf8 : convert filename's codepage to UTF-8 (default)\n");
printf(" -cp949 : convert filename's codepage to CP949\n");
printf(" -euc-kr : convert filename's codepage to EUC-KR\n");
# else
printf(" -utf8 : convert filename's codepage to UTF-8\n");
printf(" -cp949 : convert filename's codepage to CP949 (default)\n");
printf(" -euc-kr : convert filename's codepage to EUC-KR\n");
# endif // _UNALZ_UTF8
#endif // _UNALZ_ICONV
printf(" -l : list contents of archive\n");
printf(" -d directory : set output directory\n");
} }
void UnAlzCallback(const char* szMessage, INT64 nCurrent, INT64 nRange, void* param, BOOL* bHalt) void UnAlzCallback(const char* szMessage, INT64 nCurrent, INT64 nRange, void* param, BOOL* bHalt)
{ {
// progress // progress
@ -72,7 +105,8 @@ int main(int argc, char* argv[])
// printf("unalz v0.22 (2004/10/27) \n"); // printf("unalz v0.22 (2004/10/27) \n");
// printf("unalz v0.23 (2004/10/30) \n"); // printf("unalz v0.23 (2004/10/30) \n");
// printf("unalz v0.31 (2004/11/27) \n"); // printf("unalz v0.31 (2004/11/27) \n");
printf("unalz v0.4 (2005/06/18) \n"); // printf("unalz v0.4 (2005/06/18) \n");
printf("unalz v0.5 (2005/07/09) \n");
printf("Copyright(C) 2004-2005 by hardkoder (http://www.kipple.pe.kr) \n"); printf("Copyright(C) 2004-2005 by hardkoder (http://www.kipple.pe.kr) \n");
if(argc<2) if(argc<2)
@ -85,27 +119,37 @@ int main(int argc, char* argv[])
char* source=NULL; char* source=NULL;
char* destpath="."; char* destpath=".";
char* destcodepage=NULL; char* destcodepage=NULL;
int count=1; int count;
BOOL listMode = FALSE;
vector<string> filelist;
// utf8 옵션 처리 /* old method
for (count=1 ; count < argc && argv[count][0] == '-'; ++count)
{
#ifdef _UNALZ_ICONV #ifdef _UNALZ_ICONV
if(strcmp(argv[count], "-utf8")==0) // utf8 옵션 처리
{ if(strcmp(argv[count], "-utf8")==0)
destcodepage = "UTF-8"; // utf-8 support {
count++; destcodepage = "UTF-8"; // utf-8 support
}
else if(strcmp(argv[count], "-cp949")==0)
{
destcodepage = "CP949"; // cp949
}
else if(strcmp(argv[count], "-euc-kr")==0)
{
destcodepage = "EUC-KR"; // EUC-KR
}
else
#endif
if(strcmp(argv[count], "-l")==0 || strcmp(argv[count], "-list")==0)
{
listMode = TRUE;
}
} }
else if(strcmp(argv[count], "-cp949")==0)
{
destcodepage = "CP949"; // cp959
count++;
}
else if(strcmp(argv[count], "-euc-kr")==0)
{
destcodepage = "EUC-KR"; // EUC-KR
count++;
}
if(count>=argc) {Usage();return 0;} // 옵션만 쓰면 어쩌라고..
#ifdef _UNALZ_ICONV
if(count>=argc) {Usage();return 0;} // 옵션만 쓰면 어쩌라고..
if(destcodepage) unalz.SetDestCodepage(destcodepage); if(destcodepage) unalz.SetDestCodepage(destcodepage);
#endif #endif
@ -119,6 +163,54 @@ int main(int argc, char* argv[])
destpath = argv[count]; destpath = argv[count];
count++; count++;
} }
*/
for (count=1 ; count < argc; count++)
{
#ifdef _UNALZ_ICONV
// utf8 옵션 처리
if(strcmp(argv[count], "-utf8")==0)
{
destcodepage = "UTF-8"; // utf-8 support
}
else if(strcmp(argv[count], "-cp949")==0)
{
destcodepage = "CP949"; // cp949
}
else if(strcmp(argv[count], "-euc-kr")==0)
{
destcodepage = "EUC-KR"; // EUC-KR
}
else
#endif
if(strcmp(argv[count], "-l")==0 || strcmp(argv[count], "-list")==0)
{
listMode = TRUE;
}
else if(strcmp(argv[count], "-d")==0) // dest dir
{
count++;
if(count>=argc) {Usage();return 0;} // dest dir 이 정상 지정되지 않았다..
destpath = argv[count];
}
else // 옵션이 아닌 경우
{
if(source==NULL) // 소스 파일 경로
{
source=argv[count];
}
else // 압축풀 파일
{
filelist.push_back(argv[count]);
}
}
}
if(source==NULL) {Usage();return 0;} // 옵션만 쓰면 어쩌라고..
#ifdef _UNALZ_ICONV
if(destcodepage) unalz.SetDestCodepage(destcodepage);
#endif
// ÆÄÀÏ ¿­±â // ÆÄÀÏ ¿­±â
@ -126,7 +218,7 @@ int main(int argc, char* argv[])
{ {
if(unalz.GetLastErr()==CUnAlz::ERR_CORRUPTED_FILE) if(unalz.GetLastErr()==CUnAlz::ERR_CORRUPTED_FILE)
{ {
printf("It's corrupted file.\n", source); // 그냥 계속 풀기.. printf("It's corrupted file.\n"); // 그냥 계속 풀기..
} }
else else
{ {
@ -136,27 +228,50 @@ int main(int argc, char* argv[])
} }
} }
if (listMode)
if(unalz.IsEncrypted()){
char pwd[256];
cout << "Enter Password : ";
cin >> pwd;
unalz.setPassword(pwd);
}
printf("\nExtract %s to %s\n", source, destpath);
// callback 함수 세팅
unalz.SetCallback(UnAlzCallback, (void*)NULL);
if(unalz.ExtractAll(destpath)==FALSE)
{ {
printf("\n"); return ListAlz(&unalz, source);
printf("extract %s to %s failed.\n", source, destpath);
printf("err code(%d) (%s)\n", unalz.GetLastErr(), unalz.GetLastErrStr());
} }
printf("\ndone..\n"); else
{
if(unalz.IsEncrypted())
{
char pwd[256];
printf("Enter Password : ");
fgets(pwd,256,stdin);
unalz.setPassword(pwd);
}
printf("\nExtract %s to %s\n", source, destpath);
// callback 함수 세팅
unalz.SetCallback(UnAlzCallback, (void*)NULL);
if (filelist.empty()==false) // 파일 지정하기.
{
vector<string>::iterator i;
for(i=filelist.begin();i<filelist.end();i++)
{
if(unalz.SetCurrentFile(i->c_str())==FALSE)
{
printf("filename not matched : %s\n", i->c_str());
}
else
unalz.ExtractCurrentFile(destpath);
}
}
else // 모든 파일 다풀기.
{
if(unalz.ExtractAll(destpath)==FALSE)
{
printf("\n");
printf("extract %s to %s failed.\n", source, destpath);
printf("err code(%d) (%s)\n", unalz.GetLastErr(),
unalz.GetLastErrStr());
}
}
printf("\ndone..\n");
}
return 0; return 0;
} }

View file

@ -1,19 +1,14 @@
unalz v0.31 unalz v0.5
copyright(C) 2004 koder (http://www.kipple.pe.kr) Copyright(C) 2004-2005 by hardkoder (http://www.kipple.pe.kr)
- 최초 작성일 : v0.20 - 2004/10/22 - 최초 작성일 : v0.20 - 2004/10/22
- 최종 갱신일 : v0.31 - 2004/11/27
- 기능
. alz 파일 압축 해제 프로그램
. deflate/변형 bzip2/raw 포맷 지원
. 분할 압축 파일 지원
. WIN32(VC60/VC70/DEV-C++/CYGWIN/MINGW) , Free-BSD/LINUX(gcc/g++) 지원
- 라이선스 - 라이선스
. 자유로이 변형/배포 가능 (BSD-license) . 자유로이 변형/배포 가능 (BSD-license)

View file

@ -213,6 +213,14 @@ SOURCE=.\UnAlzBzip2.cpp
SOURCE=.\UnAlzbzlib.c SOURCE=.\UnAlzbzlib.c
# End Source File # End Source File
# Begin Source File
SOURCE=.\UnAlzUtils.cpp
# End Source File
# Begin Source File
SOURCE=.\UnAlzUtils.h
# End Source File
# End Group # End Group
# End Target # End Target
# End Project # End Project

View file

@ -384,6 +384,12 @@
PreprocessorDefinitions=""/> PreprocessorDefinitions=""/>
</FileConfiguration> </FileConfiguration>
</File> </File>
<File
RelativePath=".\UnAlzUtils.cpp">
</File>
<File
RelativePath=".\UnAlzUtils.h">
</File>
</Filter> </Filter>
</Files> </Files>
<Globals> <Globals>

View file

@ -1,333 +1,333 @@
/* crc32.c -- compute the CRC-32 of a data stream /* crc32.c -- compute the CRC-32 of a data stream
* Copyright (C) 1995-2003 Mark Adler * Copyright (C) 1995-2003 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
* *
* Thanks to Rodney Brown <rbrown64@csc.com.au> for his contribution of faster * Thanks to Rodney Brown <rbrown64@csc.com.au> for his contribution of faster
* CRC methods: exclusive-oring 32 bits of data at a time, and pre-computing * CRC methods: exclusive-oring 32 bits of data at a time, and pre-computing
* tables for updating the shift register in one step with three exclusive-ors * tables for updating the shift register in one step with three exclusive-ors
* instead of four steps with four exclusive-ors. This results about a factor * instead of four steps with four exclusive-ors. This results about a factor
* of two increase in speed on a Power PC G4 (PPC7455) using gcc -O3. * of two increase in speed on a Power PC G4 (PPC7455) using gcc -O3.
*/ */
/* @(#) $Id$ */ /* @(#) $Id$ */
/* /*
Note on the use of DYNAMIC_CRC_TABLE: there is no mutex or semaphore Note on the use of DYNAMIC_CRC_TABLE: there is no mutex or semaphore
protection on the static variables used to control the first-use generation protection on the static variables used to control the first-use generation
of the crc tables. Therefore, if you #define DYNAMIC_CRC_TABLE, you should of the crc tables. Therefore, if you #define DYNAMIC_CRC_TABLE, you should
first call get_crc_table() to initialize the tables before allowing more than first call get_crc_table() to initialize the tables before allowing more than
one thread to use crc32(). one thread to use crc32().
*/ */
#ifdef MAKECRCH #ifdef MAKECRCH
# include <stdio.h> # include <stdio.h>
# ifndef DYNAMIC_CRC_TABLE # ifndef DYNAMIC_CRC_TABLE
# define DYNAMIC_CRC_TABLE # define DYNAMIC_CRC_TABLE
# endif /* !DYNAMIC_CRC_TABLE */ # endif /* !DYNAMIC_CRC_TABLE */
#endif /* MAKECRCH */ #endif /* MAKECRCH */
#include "zutil.h" /* for STDC and FAR definitions */ #include "zutil.h" /* for STDC and FAR definitions */
#define local static #define local static
/* Find a four-byte integer type for crc32_little() and crc32_big(). */ /* Find a four-byte integer type for crc32_little() and crc32_big(). */
#ifndef NOBYFOUR #ifndef NOBYFOUR
# ifdef STDC /* need ANSI C limits.h to determine sizes */ # ifdef STDC /* need ANSI C limits.h to determine sizes */
# include <limits.h> # include <limits.h>
# define BYFOUR # define BYFOUR
# if (UINT_MAX == 0xffffffffUL) # if (UINT_MAX == 0xffffffffUL)
typedef unsigned int u4; typedef unsigned int u4;
# else # else
# if (ULONG_MAX == 0xffffffffUL) # if (ULONG_MAX == 0xffffffffUL)
typedef unsigned long u4; typedef unsigned long u4;
# else # else
# if (USHRT_MAX == 0xffffffffUL) # if (USHRT_MAX == 0xffffffffUL)
typedef unsigned short u4; typedef unsigned short u4;
# else # else
# undef BYFOUR /* can't find a four-byte integer type! */ # undef BYFOUR /* can't find a four-byte integer type! */
# endif # endif
# endif # endif
# endif # endif
# endif /* STDC */ # endif /* STDC */
#endif /* !NOBYFOUR */ #endif /* !NOBYFOUR */
/* Definitions for doing the crc four data bytes at a time. */ /* Definitions for doing the crc four data bytes at a time. */
#ifdef BYFOUR #ifdef BYFOUR
# define REV(w) (((w)>>24)+(((w)>>8)&0xff00)+ \ # define REV(w) (((w)>>24)+(((w)>>8)&0xff00)+ \
(((w)&0xff00)<<8)+(((w)&0xff)<<24)) (((w)&0xff00)<<8)+(((w)&0xff)<<24))
local unsigned long crc32_little OF((unsigned long, local unsigned long crc32_little OF((unsigned long,
const unsigned char FAR *, unsigned)); const unsigned char FAR *, unsigned));
local unsigned long crc32_big OF((unsigned long, local unsigned long crc32_big OF((unsigned long,
const unsigned char FAR *, unsigned)); const unsigned char FAR *, unsigned));
# define TBLS 8 # define TBLS 8
#else #else
# define TBLS 1 # define TBLS 1
#endif /* BYFOUR */ #endif /* BYFOUR */
#ifdef DYNAMIC_CRC_TABLE #ifdef DYNAMIC_CRC_TABLE
local volatile int crc_table_empty = 1; local volatile int crc_table_empty = 1;
local unsigned long FAR crc_table[TBLS][256]; local unsigned long FAR crc_table[TBLS][256];
local void make_crc_table OF((void)); local void make_crc_table OF((void));
#ifdef MAKECRCH #ifdef MAKECRCH
local void write_table OF((FILE *, const unsigned long FAR *)); local void write_table OF((FILE *, const unsigned long FAR *));
#endif /* MAKECRCH */ #endif /* MAKECRCH */
/* /*
Generate tables for a byte-wise 32-bit CRC calculation on the polynomial: Generate tables 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. 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, Polynomials over GF(2) are represented in binary, one bit per coefficient,
with the lowest powers in the most significant bit. Then adding polynomials 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 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 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 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, 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. where a mod b means the remainder after dividing a by b.
This calculation is done using the shift-register method of multiplying and This calculation is done using the shift-register method of multiplying and
taking the remainder. The register is initialized to zero, and for each 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 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^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 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 out is a one). We start with the highest power (least significant bit) of
q and repeat for all eight bits of q. q and repeat for all eight bits of q.
The first table is simply the CRC of all possible eight bit values. This is The first table is simply the CRC of all possible eight bit values. This is
all the information needed to generate CRCs on data a byte at a time for all all the information needed to generate CRCs on data a byte at a time for all
combinations of CRC register values and incoming bytes. The remaining tables combinations of CRC register values and incoming bytes. The remaining tables
allow for word-at-a-time CRC calculation for both big-endian and little- allow for word-at-a-time CRC calculation for both big-endian and little-
endian machines, where a word is four bytes. endian machines, where a word is four bytes.
*/ */
local void make_crc_table() local void make_crc_table()
{ {
unsigned long c; unsigned long c;
int n, k; int n, k;
unsigned long poly; /* polynomial exclusive-or pattern */ unsigned long poly; /* polynomial exclusive-or pattern */
/* terms of polynomial defining this crc (except x^32): */ /* terms of polynomial defining this crc (except x^32): */
static volatile int first = 1; /* flag to limit concurrent making */ static volatile int first = 1; /* flag to limit concurrent making */
static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26}; static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
/* See if another task is already doing this (not thread-safe, but better /* See if another task is already doing this (not thread-safe, but better
than nothing -- significantly reduces duration of vulnerability in than nothing -- significantly reduces duration of vulnerability in
case the advice about DYNAMIC_CRC_TABLE is ignored) */ case the advice about DYNAMIC_CRC_TABLE is ignored) */
if (first) { if (first) {
first = 0; first = 0;
/* make exclusive-or pattern from polynomial (0xedb88320UL) */ /* make exclusive-or pattern from polynomial (0xedb88320UL) */
poly = 0UL; poly = 0UL;
for (n = 0; n < sizeof(p)/sizeof(unsigned char); n++) for (n = 0; n < sizeof(p)/sizeof(unsigned char); n++)
poly |= 1UL << (31 - p[n]); poly |= 1UL << (31 - p[n]);
/* generate a crc for every 8-bit value */ /* generate a crc for every 8-bit value */
for (n = 0; n < 256; n++) { for (n = 0; n < 256; n++) {
c = (unsigned long)n; c = (unsigned long)n;
for (k = 0; k < 8; k++) for (k = 0; k < 8; k++)
c = c & 1 ? poly ^ (c >> 1) : c >> 1; c = c & 1 ? poly ^ (c >> 1) : c >> 1;
crc_table[0][n] = c; crc_table[0][n] = c;
} }
#ifdef BYFOUR #ifdef BYFOUR
/* generate crc for each value followed by one, two, and three zeros, /* generate crc for each value followed by one, two, and three zeros,
and then the byte reversal of those as well as the first table */ and then the byte reversal of those as well as the first table */
for (n = 0; n < 256; n++) { for (n = 0; n < 256; n++) {
c = crc_table[0][n]; c = crc_table[0][n];
crc_table[4][n] = REV(c); crc_table[4][n] = REV(c);
for (k = 1; k < 4; k++) { for (k = 1; k < 4; k++) {
c = crc_table[0][c & 0xff] ^ (c >> 8); c = crc_table[0][c & 0xff] ^ (c >> 8);
crc_table[k][n] = c; crc_table[k][n] = c;
crc_table[k + 4][n] = REV(c); crc_table[k + 4][n] = REV(c);
} }
} }
#endif /* BYFOUR */ #endif /* BYFOUR */
crc_table_empty = 0; crc_table_empty = 0;
} }
else { /* not first */ else { /* not first */
/* wait for the other guy to finish (not efficient, but rare) */ /* wait for the other guy to finish (not efficient, but rare) */
while (crc_table_empty) while (crc_table_empty)
; ;
} }
#ifdef MAKECRCH #ifdef MAKECRCH
/* write out CRC tables to crc32.h */ /* write out CRC tables to crc32.h */
{ {
FILE *out; FILE *out;
out = fopen("crc32.h", "w"); out = fopen("crc32.h", "w");
if (out == NULL) return; if (out == NULL) return;
fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n"); fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n");
fprintf(out, " * Generated automatically by crc32.c\n */\n\n"); fprintf(out, " * Generated automatically by crc32.c\n */\n\n");
fprintf(out, "local const unsigned long FAR "); fprintf(out, "local const unsigned long FAR ");
fprintf(out, "crc_table[TBLS][256] =\n{\n {\n"); fprintf(out, "crc_table[TBLS][256] =\n{\n {\n");
write_table(out, crc_table[0]); write_table(out, crc_table[0]);
# ifdef BYFOUR # ifdef BYFOUR
fprintf(out, "#ifdef BYFOUR\n"); fprintf(out, "#ifdef BYFOUR\n");
for (k = 1; k < 8; k++) { for (k = 1; k < 8; k++) {
fprintf(out, " },\n {\n"); fprintf(out, " },\n {\n");
write_table(out, crc_table[k]); write_table(out, crc_table[k]);
} }
fprintf(out, "#endif\n"); fprintf(out, "#endif\n");
# endif /* BYFOUR */ # endif /* BYFOUR */
fprintf(out, " }\n};\n"); fprintf(out, " }\n};\n");
fclose(out); fclose(out);
} }
#endif /* MAKECRCH */ #endif /* MAKECRCH */
} }
#ifdef MAKECRCH #ifdef MAKECRCH
local void write_table(out, table) local void write_table(out, table)
FILE *out; FILE *out;
const unsigned long FAR *table; const unsigned long FAR *table;
{ {
int n; int n;
for (n = 0; n < 256; n++) for (n = 0; n < 256; n++)
fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : " ", table[n], fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : " ", table[n],
n == 255 ? "\n" : (n % 5 == 4 ? ",\n" : ", ")); n == 255 ? "\n" : (n % 5 == 4 ? ",\n" : ", "));
} }
#endif /* MAKECRCH */ #endif /* MAKECRCH */
#else /* !DYNAMIC_CRC_TABLE */ #else /* !DYNAMIC_CRC_TABLE */
/* ======================================================================== /* ========================================================================
* Tables of CRC-32s of all single-byte values, made by make_crc_table(). * Tables of CRC-32s of all single-byte values, made by make_crc_table().
*/ */
#include "crc32.h" #include "crc32.h"
#endif /* DYNAMIC_CRC_TABLE */ #endif /* DYNAMIC_CRC_TABLE */
/* ========================================================================= /* =========================================================================
* This function can be used by asm versions of crc32() * This function can be used by asm versions of crc32()
*/ */
const unsigned long FAR * ZEXPORT get_crc_table() const unsigned long FAR * ZEXPORT get_crc_table()
{ {
#ifdef DYNAMIC_CRC_TABLE #ifdef DYNAMIC_CRC_TABLE
if (crc_table_empty) if (crc_table_empty)
make_crc_table(); make_crc_table();
#endif /* DYNAMIC_CRC_TABLE */ #endif /* DYNAMIC_CRC_TABLE */
return (const unsigned long FAR *)crc_table; return (const unsigned long FAR *)crc_table;
} }
/* ========================================================================= */ /* ========================================================================= */
#define DO1 crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8) #define DO1 crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8)
#define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1 #define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1
/* ========================================================================= */ /* ========================================================================= */
unsigned long ZEXPORT crc32(crc, buf, len) unsigned long ZEXPORT crc32(crc, buf, len)
unsigned long crc; unsigned long crc;
const unsigned char FAR *buf; const unsigned char FAR *buf;
unsigned len; unsigned len;
{ {
if (buf == Z_NULL) return 0UL; if (buf == Z_NULL) return 0UL;
#ifdef DYNAMIC_CRC_TABLE #ifdef DYNAMIC_CRC_TABLE
if (crc_table_empty) if (crc_table_empty)
make_crc_table(); make_crc_table();
#endif /* DYNAMIC_CRC_TABLE */ #endif /* DYNAMIC_CRC_TABLE */
#ifdef BYFOUR #ifdef BYFOUR
if (sizeof(void *) == sizeof(ptrdiff_t)) { if (sizeof(void *) == sizeof(ptrdiff_t)) {
u4 endian; u4 endian;
endian = 1; endian = 1;
if (*((unsigned char *)(&endian))) if (*((unsigned char *)(&endian)))
return crc32_little(crc, buf, len); return crc32_little(crc, buf, len);
else else
return crc32_big(crc, buf, len); return crc32_big(crc, buf, len);
} }
#endif /* BYFOUR */ #endif /* BYFOUR */
crc = crc ^ 0xffffffffUL; crc = crc ^ 0xffffffffUL;
while (len >= 8) { while (len >= 8) {
DO8; DO8;
len -= 8; len -= 8;
} }
if (len) do { if (len) do {
DO1; DO1;
} while (--len); } while (--len);
return crc ^ 0xffffffffUL; return crc ^ 0xffffffffUL;
} }
#ifdef BYFOUR #ifdef BYFOUR
/* ========================================================================= */ /* ========================================================================= */
#define DOLIT4 c ^= *buf4++; \ #define DOLIT4 c ^= *buf4++; \
c = crc_table[3][c & 0xff] ^ crc_table[2][(c >> 8) & 0xff] ^ \ c = crc_table[3][c & 0xff] ^ crc_table[2][(c >> 8) & 0xff] ^ \
crc_table[1][(c >> 16) & 0xff] ^ crc_table[0][c >> 24] crc_table[1][(c >> 16) & 0xff] ^ crc_table[0][c >> 24]
#define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4 #define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4
/* ========================================================================= */ /* ========================================================================= */
local unsigned long crc32_little(crc, buf, len) local unsigned long crc32_little(crc, buf, len)
unsigned long crc; unsigned long crc;
const unsigned char FAR *buf; const unsigned char FAR *buf;
unsigned len; unsigned len;
{ {
register u4 c; register u4 c;
register const u4 FAR *buf4; register const u4 FAR *buf4;
c = (u4)crc; c = (u4)crc;
c = ~c; c = ~c;
while (len && ((ptrdiff_t)buf & 3)) { while (len && ((ptrdiff_t)buf & 3)) {
c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8); c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
len--; len--;
} }
buf4 = (const u4 FAR *)buf; buf4 = (const u4 FAR *)buf;
while (len >= 32) { while (len >= 32) {
DOLIT32; DOLIT32;
len -= 32; len -= 32;
} }
while (len >= 4) { while (len >= 4) {
DOLIT4; DOLIT4;
len -= 4; len -= 4;
} }
buf = (const unsigned char FAR *)buf4; buf = (const unsigned char FAR *)buf4;
if (len) do { if (len) do {
c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8); c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
} while (--len); } while (--len);
c = ~c; c = ~c;
return (unsigned long)c; return (unsigned long)c;
} }
/* ========================================================================= */ /* ========================================================================= */
#define DOBIG4 c ^= *++buf4; \ #define DOBIG4 c ^= *++buf4; \
c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \ c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \
crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24] crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24]
#define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4 #define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4
/* ========================================================================= */ /* ========================================================================= */
local unsigned long crc32_big(crc, buf, len) local unsigned long crc32_big(crc, buf, len)
unsigned long crc; unsigned long crc;
const unsigned char FAR *buf; const unsigned char FAR *buf;
unsigned len; unsigned len;
{ {
register u4 c; register u4 c;
register const u4 FAR *buf4; register const u4 FAR *buf4;
c = REV((u4)crc); c = REV((u4)crc);
c = ~c; c = ~c;
while (len && ((ptrdiff_t)buf & 3)) { while (len && ((ptrdiff_t)buf & 3)) {
c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8); c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
len--; len--;
} }
buf4 = (const u4 FAR *)buf; buf4 = (const u4 FAR *)buf;
buf4--; buf4--;
while (len >= 32) { while (len >= 32) {
DOBIG32; DOBIG32;
len -= 32; len -= 32;
} }
while (len >= 4) { while (len >= 4) {
DOBIG4; DOBIG4;
len -= 4; len -= 4;
} }
buf4++; buf4++;
buf = (const unsigned char FAR *)buf4; buf = (const unsigned char FAR *)buf4;
if (len) do { if (len) do {
c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8); c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
} while (--len); } while (--len);
c = ~c; c = ~c;
return (unsigned long)(REV(c)); return (unsigned long)(REV(c));
} }
#endif /* BYFOUR */ #endif /* BYFOUR */

File diff suppressed because it is too large Load diff

View file

@ -1,305 +1,305 @@
/* inffast.c -- fast decoding /* inffast.c -- fast decoding
* Copyright (C) 1995-2004 Mark Adler * Copyright (C) 1995-2004 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
#include "zutil.h" #include "zutil.h"
#include "inftrees.h" #include "inftrees.h"
#include "inflate.h" #include "inflate.h"
#include "inffast.h" #include "inffast.h"
#ifndef ASMINF #ifndef ASMINF
/* Allow machine dependent optimization for post-increment or pre-increment. /* Allow machine dependent optimization for post-increment or pre-increment.
Based on testing to date, Based on testing to date,
Pre-increment preferred for: Pre-increment preferred for:
- PowerPC G3 (Adler) - PowerPC G3 (Adler)
- MIPS R5000 (Randers-Pehrson) - MIPS R5000 (Randers-Pehrson)
Post-increment preferred for: Post-increment preferred for:
- none - none
No measurable difference: No measurable difference:
- Pentium III (Anderson) - Pentium III (Anderson)
- M68060 (Nikl) - M68060 (Nikl)
*/ */
#ifdef POSTINC #ifdef POSTINC
# define OFF 0 # define OFF 0
# define PUP(a) *(a)++ # define PUP(a) *(a)++
#else #else
# define OFF 1 # define OFF 1
# define PUP(a) *++(a) # define PUP(a) *++(a)
#endif #endif
/* /*
Decode literal, length, and distance codes and write out the resulting Decode literal, length, and distance codes and write out the resulting
literal and match bytes until either not enough input or output is literal and match bytes until either not enough input or output is
available, an end-of-block is encountered, or a data error is encountered. available, an end-of-block is encountered, or a data error is encountered.
When large enough input and output buffers are supplied to inflate(), for When large enough input and output buffers are supplied to inflate(), for
example, a 16K input buffer and a 64K output buffer, more than 95% of the example, a 16K input buffer and a 64K output buffer, more than 95% of the
inflate execution time is spent in this routine. inflate execution time is spent in this routine.
Entry assumptions: Entry assumptions:
state->mode == LEN state->mode == LEN
strm->avail_in >= 6 strm->avail_in >= 6
strm->avail_out >= 258 strm->avail_out >= 258
start >= strm->avail_out start >= strm->avail_out
state->bits < 8 state->bits < 8
On return, state->mode is one of: On return, state->mode is one of:
LEN -- ran out of enough output space or enough available input LEN -- ran out of enough output space or enough available input
TYPE -- reached end of block code, inflate() to interpret next block TYPE -- reached end of block code, inflate() to interpret next block
BAD -- error in block data BAD -- error in block data
Notes: Notes:
- The maximum input bits used by a length/distance pair is 15 bits for the - The maximum input bits used by a length/distance pair is 15 bits for the
length code, 5 bits for the length extra, 15 bits for the distance code, length code, 5 bits for the length extra, 15 bits for the distance code,
and 13 bits for the distance extra. This totals 48 bits, or six bytes. and 13 bits for the distance extra. This totals 48 bits, or six bytes.
Therefore if strm->avail_in >= 6, then there is enough input to avoid Therefore if strm->avail_in >= 6, then there is enough input to avoid
checking for available input while decoding. checking for available input while decoding.
- The maximum bytes that a single length/distance pair can output is 258 - The maximum bytes that a single length/distance pair can output is 258
bytes, which is the maximum length that can be coded. inflate_fast() bytes, which is the maximum length that can be coded. inflate_fast()
requires strm->avail_out >= 258 for each loop to avoid checking for requires strm->avail_out >= 258 for each loop to avoid checking for
output space. output space.
*/ */
void inflate_fast(strm, start) void inflate_fast(strm, start)
z_streamp strm; z_streamp strm;
unsigned start; /* inflate()'s starting value for strm->avail_out */ unsigned start; /* inflate()'s starting value for strm->avail_out */
{ {
struct inflate_state FAR *state; struct inflate_state FAR *state;
unsigned char FAR *in; /* local strm->next_in */ unsigned char FAR *in; /* local strm->next_in */
unsigned char FAR *last; /* while in < last, enough input available */ unsigned char FAR *last; /* while in < last, enough input available */
unsigned char FAR *out; /* local strm->next_out */ unsigned char FAR *out; /* local strm->next_out */
unsigned char FAR *beg; /* inflate()'s initial strm->next_out */ unsigned char FAR *beg; /* inflate()'s initial strm->next_out */
unsigned char FAR *end; /* while out < end, enough space available */ unsigned char FAR *end; /* while out < end, enough space available */
unsigned wsize; /* window size or zero if not using window */ unsigned wsize; /* window size or zero if not using window */
unsigned whave; /* valid bytes in the window */ unsigned whave; /* valid bytes in the window */
unsigned write; /* window write index */ unsigned write; /* window write index */
unsigned char FAR *window; /* allocated sliding window, if wsize != 0 */ unsigned char FAR *window; /* allocated sliding window, if wsize != 0 */
unsigned long hold; /* local strm->hold */ unsigned long hold; /* local strm->hold */
unsigned bits; /* local strm->bits */ unsigned bits; /* local strm->bits */
code const FAR *lcode; /* local strm->lencode */ code const FAR *lcode; /* local strm->lencode */
code const FAR *dcode; /* local strm->distcode */ code const FAR *dcode; /* local strm->distcode */
unsigned lmask; /* mask for first level of length codes */ unsigned lmask; /* mask for first level of length codes */
unsigned dmask; /* mask for first level of distance codes */ unsigned dmask; /* mask for first level of distance codes */
code this; /* retrieved table entry */ code this; /* retrieved table entry */
unsigned op; /* code bits, operation, extra bits, or */ unsigned op; /* code bits, operation, extra bits, or */
/* window position, window bytes to copy */ /* window position, window bytes to copy */
unsigned len; /* match length, unused bytes */ unsigned len; /* match length, unused bytes */
unsigned dist; /* match distance */ unsigned dist; /* match distance */
unsigned char FAR *from; /* where to copy match from */ unsigned char FAR *from; /* where to copy match from */
/* copy state to local variables */ /* copy state to local variables */
state = (struct inflate_state FAR *)strm->state; state = (struct inflate_state FAR *)strm->state;
in = strm->next_in - OFF; in = strm->next_in - OFF;
last = in + (strm->avail_in - 5); last = in + (strm->avail_in - 5);
out = strm->next_out - OFF; out = strm->next_out - OFF;
beg = out - (start - strm->avail_out); beg = out - (start - strm->avail_out);
end = out + (strm->avail_out - 257); end = out + (strm->avail_out - 257);
wsize = state->wsize; wsize = state->wsize;
whave = state->whave; whave = state->whave;
write = state->write; write = state->write;
window = state->window; window = state->window;
hold = state->hold; hold = state->hold;
bits = state->bits; bits = state->bits;
lcode = state->lencode; lcode = state->lencode;
dcode = state->distcode; dcode = state->distcode;
lmask = (1U << state->lenbits) - 1; lmask = (1U << state->lenbits) - 1;
dmask = (1U << state->distbits) - 1; dmask = (1U << state->distbits) - 1;
/* decode literals and length/distances until end-of-block or not enough /* decode literals and length/distances until end-of-block or not enough
input data or output space */ input data or output space */
do { do {
if (bits < 15) { if (bits < 15) {
hold += (unsigned long)(PUP(in)) << bits; hold += (unsigned long)(PUP(in)) << bits;
bits += 8; bits += 8;
hold += (unsigned long)(PUP(in)) << bits; hold += (unsigned long)(PUP(in)) << bits;
bits += 8; bits += 8;
} }
this = lcode[hold & lmask]; this = lcode[hold & lmask];
dolen: dolen:
op = (unsigned)(this.bits); op = (unsigned)(this.bits);
hold >>= op; hold >>= op;
bits -= op; bits -= op;
op = (unsigned)(this.op); op = (unsigned)(this.op);
if (op == 0) { /* literal */ if (op == 0) { /* literal */
Tracevv((stderr, this.val >= 0x20 && this.val < 0x7f ? Tracevv((stderr, this.val >= 0x20 && this.val < 0x7f ?
"inflate: literal '%c'\n" : "inflate: literal '%c'\n" :
"inflate: literal 0x%02x\n", this.val)); "inflate: literal 0x%02x\n", this.val));
PUP(out) = (unsigned char)(this.val); PUP(out) = (unsigned char)(this.val);
} }
else if (op & 16) { /* length base */ else if (op & 16) { /* length base */
len = (unsigned)(this.val); len = (unsigned)(this.val);
op &= 15; /* number of extra bits */ op &= 15; /* number of extra bits */
if (op) { if (op) {
if (bits < op) { if (bits < op) {
hold += (unsigned long)(PUP(in)) << bits; hold += (unsigned long)(PUP(in)) << bits;
bits += 8; bits += 8;
} }
len += (unsigned)hold & ((1U << op) - 1); len += (unsigned)hold & ((1U << op) - 1);
hold >>= op; hold >>= op;
bits -= op; bits -= op;
} }
Tracevv((stderr, "inflate: length %u\n", len)); Tracevv((stderr, "inflate: length %u\n", len));
if (bits < 15) { if (bits < 15) {
hold += (unsigned long)(PUP(in)) << bits; hold += (unsigned long)(PUP(in)) << bits;
bits += 8; bits += 8;
hold += (unsigned long)(PUP(in)) << bits; hold += (unsigned long)(PUP(in)) << bits;
bits += 8; bits += 8;
} }
this = dcode[hold & dmask]; this = dcode[hold & dmask];
dodist: dodist:
op = (unsigned)(this.bits); op = (unsigned)(this.bits);
hold >>= op; hold >>= op;
bits -= op; bits -= op;
op = (unsigned)(this.op); op = (unsigned)(this.op);
if (op & 16) { /* distance base */ if (op & 16) { /* distance base */
dist = (unsigned)(this.val); dist = (unsigned)(this.val);
op &= 15; /* number of extra bits */ op &= 15; /* number of extra bits */
if (bits < op) { if (bits < op) {
hold += (unsigned long)(PUP(in)) << bits; hold += (unsigned long)(PUP(in)) << bits;
bits += 8; bits += 8;
if (bits < op) { if (bits < op) {
hold += (unsigned long)(PUP(in)) << bits; hold += (unsigned long)(PUP(in)) << bits;
bits += 8; bits += 8;
} }
} }
dist += (unsigned)hold & ((1U << op) - 1); dist += (unsigned)hold & ((1U << op) - 1);
hold >>= op; hold >>= op;
bits -= op; bits -= op;
Tracevv((stderr, "inflate: distance %u\n", dist)); Tracevv((stderr, "inflate: distance %u\n", dist));
op = (unsigned)(out - beg); /* max distance in output */ op = (unsigned)(out - beg); /* max distance in output */
if (dist > op) { /* see if copy from window */ if (dist > op) { /* see if copy from window */
op = dist - op; /* distance back in window */ op = dist - op; /* distance back in window */
if (op > whave) { if (op > whave) {
strm->msg = (char *)"invalid distance too far back"; strm->msg = (char *)"invalid distance too far back";
state->mode = BAD; state->mode = BAD;
break; break;
} }
from = window - OFF; from = window - OFF;
if (write == 0) { /* very common case */ if (write == 0) { /* very common case */
from += wsize - op; from += wsize - op;
if (op < len) { /* some from window */ if (op < len) { /* some from window */
len -= op; len -= op;
do { do {
PUP(out) = PUP(from); PUP(out) = PUP(from);
} while (--op); } while (--op);
from = out - dist; /* rest from output */ from = out - dist; /* rest from output */
} }
} }
else if (write < op) { /* wrap around window */ else if (write < op) { /* wrap around window */
from += wsize + write - op; from += wsize + write - op;
op -= write; op -= write;
if (op < len) { /* some from end of window */ if (op < len) { /* some from end of window */
len -= op; len -= op;
do { do {
PUP(out) = PUP(from); PUP(out) = PUP(from);
} while (--op); } while (--op);
from = window - OFF; from = window - OFF;
if (write < len) { /* some from start of window */ if (write < len) { /* some from start of window */
op = write; op = write;
len -= op; len -= op;
do { do {
PUP(out) = PUP(from); PUP(out) = PUP(from);
} while (--op); } while (--op);
from = out - dist; /* rest from output */ from = out - dist; /* rest from output */
} }
} }
} }
else { /* contiguous in window */ else { /* contiguous in window */
from += write - op; from += write - op;
if (op < len) { /* some from window */ if (op < len) { /* some from window */
len -= op; len -= op;
do { do {
PUP(out) = PUP(from); PUP(out) = PUP(from);
} while (--op); } while (--op);
from = out - dist; /* rest from output */ from = out - dist; /* rest from output */
} }
} }
while (len > 2) { while (len > 2) {
PUP(out) = PUP(from); PUP(out) = PUP(from);
PUP(out) = PUP(from); PUP(out) = PUP(from);
PUP(out) = PUP(from); PUP(out) = PUP(from);
len -= 3; len -= 3;
} }
if (len) { if (len) {
PUP(out) = PUP(from); PUP(out) = PUP(from);
if (len > 1) if (len > 1)
PUP(out) = PUP(from); PUP(out) = PUP(from);
} }
} }
else { else {
from = out - dist; /* copy direct from output */ from = out - dist; /* copy direct from output */
do { /* minimum length is three */ do { /* minimum length is three */
PUP(out) = PUP(from); PUP(out) = PUP(from);
PUP(out) = PUP(from); PUP(out) = PUP(from);
PUP(out) = PUP(from); PUP(out) = PUP(from);
len -= 3; len -= 3;
} while (len > 2); } while (len > 2);
if (len) { if (len) {
PUP(out) = PUP(from); PUP(out) = PUP(from);
if (len > 1) if (len > 1)
PUP(out) = PUP(from); PUP(out) = PUP(from);
} }
} }
} }
else if ((op & 64) == 0) { /* 2nd level distance code */ else if ((op & 64) == 0) { /* 2nd level distance code */
this = dcode[this.val + (hold & ((1U << op) - 1))]; this = dcode[this.val + (hold & ((1U << op) - 1))];
goto dodist; goto dodist;
} }
else { else {
strm->msg = (char *)"invalid distance code"; strm->msg = (char *)"invalid distance code";
state->mode = BAD; state->mode = BAD;
break; break;
} }
} }
else if ((op & 64) == 0) { /* 2nd level length code */ else if ((op & 64) == 0) { /* 2nd level length code */
this = lcode[this.val + (hold & ((1U << op) - 1))]; this = lcode[this.val + (hold & ((1U << op) - 1))];
goto dolen; goto dolen;
} }
else if (op & 32) { /* end-of-block */ else if (op & 32) { /* end-of-block */
Tracevv((stderr, "inflate: end of block\n")); Tracevv((stderr, "inflate: end of block\n"));
state->mode = TYPE; state->mode = TYPE;
break; break;
} }
else { else {
strm->msg = (char *)"invalid literal/length code"; strm->msg = (char *)"invalid literal/length code";
state->mode = BAD; state->mode = BAD;
break; break;
} }
} while (in < last && out < end); } while (in < last && out < end);
/* return unused bytes (on entry, bits < 8, so in won't go too far back) */ /* return unused bytes (on entry, bits < 8, so in won't go too far back) */
len = bits >> 3; len = bits >> 3;
in -= len; in -= len;
bits -= len << 3; bits -= len << 3;
hold &= (1U << bits) - 1; hold &= (1U << bits) - 1;
/* update state and return */ /* update state and return */
strm->next_in = in + OFF; strm->next_in = in + OFF;
strm->next_out = out + OFF; strm->next_out = out + OFF;
strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last)); strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last));
strm->avail_out = (unsigned)(out < end ? strm->avail_out = (unsigned)(out < end ?
257 + (end - out) : 257 - (out - end)); 257 + (end - out) : 257 - (out - end));
state->hold = hold; state->hold = hold;
state->bits = bits; state->bits = bits;
return; return;
} }
/* /*
inflate_fast() speedups that turned out slower (on a PowerPC G3 750CXe): inflate_fast() speedups that turned out slower (on a PowerPC G3 750CXe):
- Using bit fields for code structure - Using bit fields for code structure
- Different op definition to avoid & for extra bits (do & for table bits) - Different op definition to avoid & for extra bits (do & for table bits)
- Three separate decoding do-loops for direct, window, and write == 0 - Three separate decoding do-loops for direct, window, and write == 0
- Special case for distance > 1 copies to do overlapped load and store copy - Special case for distance > 1 copies to do overlapped load and store copy
- Explicit branch predictions (based on measured branch probabilities) - Explicit branch predictions (based on measured branch probabilities)
- Deferring match copy and interspersed it with decoding subsequent codes - Deferring match copy and interspersed it with decoding subsequent codes
- Swapping literal/length else - Swapping literal/length else
- Swapping window/direct else - Swapping window/direct else
- Larger unrolled copy loops (three is about right) - Larger unrolled copy loops (three is about right)
- Moving len -= 3 statement into middle of loop - Moving len -= 3 statement into middle of loop
*/ */
#endif /* !ASMINF */ #endif /* !ASMINF */

File diff suppressed because it is too large Load diff

View file

@ -1,328 +1,328 @@
/* inftrees.c -- generate Huffman trees for efficient decoding /* inftrees.c -- generate Huffman trees for efficient decoding
* Copyright (C) 1995-2004 Mark Adler * Copyright (C) 1995-2004 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
#include "zutil.h" #include "zutil.h"
#include "inftrees.h" #include "inftrees.h"
#define MAXBITS 15 #define MAXBITS 15
const char inflate_copyright[] = const char inflate_copyright[] =
" inflate 1.2.2 Copyright 1995-2004 Mark Adler "; " inflate 1.2.2 Copyright 1995-2004 Mark Adler ";
/* /*
If you use the zlib library in a product, an acknowledgment is welcome 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 in the documentation of your product. If for some reason you cannot
include such an acknowledgment, I would appreciate that you keep this include such an acknowledgment, I would appreciate that you keep this
copyright string in the executable of your product. copyright string in the executable of your product.
*/ */
/* /*
Build a set of tables to decode the provided canonical Huffman code. Build a set of tables to decode the provided canonical Huffman code.
The code lengths are lens[0..codes-1]. The result starts at *table, The code lengths are lens[0..codes-1]. The result starts at *table,
whose indices are 0..2^bits-1. work is a writable array of at least whose indices are 0..2^bits-1. work is a writable array of at least
lens shorts, which is used as a work area. type is the type of code lens shorts, which is used as a work area. type is the type of code
to be generated, CODES, LENS, or DISTS. On return, zero is success, to be generated, CODES, LENS, or DISTS. On return, zero is success,
-1 is an invalid code, and +1 means that ENOUGH isn't enough. table -1 is an invalid code, and +1 means that ENOUGH isn't enough. table
on return points to the next available entry's address. bits is the on return points to the next available entry's address. bits is the
requested root table index bits, and on return it is the actual root requested root table index bits, and on return it is the actual root
table index bits. It will differ if the request is greater than the table index bits. It will differ if the request is greater than the
longest code or if it is less than the shortest code. longest code or if it is less than the shortest code.
*/ */
int inflate_table(type, lens, codes, table, bits, work) int inflate_table(type, lens, codes, table, bits, work)
codetype type; codetype type;
unsigned short FAR *lens; unsigned short FAR *lens;
unsigned codes; unsigned codes;
code FAR * FAR *table; code FAR * FAR *table;
unsigned FAR *bits; unsigned FAR *bits;
unsigned short FAR *work; unsigned short FAR *work;
{ {
unsigned len; /* a code's length in bits */ unsigned len; /* a code's length in bits */
unsigned sym; /* index of code symbols */ unsigned sym; /* index of code symbols */
unsigned min, max; /* minimum and maximum code lengths */ unsigned min, max; /* minimum and maximum code lengths */
unsigned root; /* number of index bits for root table */ unsigned root; /* number of index bits for root table */
unsigned curr; /* number of index bits for current table */ unsigned curr; /* number of index bits for current table */
unsigned drop; /* code bits to drop for sub-table */ unsigned drop; /* code bits to drop for sub-table */
int left; /* number of prefix codes available */ int left; /* number of prefix codes available */
unsigned used; /* code entries in table used */ unsigned used; /* code entries in table used */
unsigned huff; /* Huffman code */ unsigned huff; /* Huffman code */
unsigned incr; /* for incrementing code, index */ unsigned incr; /* for incrementing code, index */
unsigned fill; /* index for replicating entries */ unsigned fill; /* index for replicating entries */
unsigned low; /* low bits for current root entry */ unsigned low; /* low bits for current root entry */
unsigned mask; /* mask for low root bits */ unsigned mask; /* mask for low root bits */
code this; /* table entry for duplication */ code this; /* table entry for duplication */
code FAR *next; /* next available space in table */ code FAR *next; /* next available space in table */
const unsigned short FAR *base; /* base value table to use */ const unsigned short FAR *base; /* base value table to use */
const unsigned short FAR *extra; /* extra bits table to use */ const unsigned short FAR *extra; /* extra bits table to use */
int end; /* use base and extra for symbol > end */ int end; /* use base and extra for symbol > end */
unsigned short count[MAXBITS+1]; /* number of codes of each length */ unsigned short count[MAXBITS+1]; /* number of codes of each length */
unsigned short offs[MAXBITS+1]; /* offsets in table for each length */ unsigned short offs[MAXBITS+1]; /* offsets in table for each length */
static const unsigned short lbase[31] = { /* Length codes 257..285 base */ static const unsigned short lbase[31] = { /* Length codes 257..285 base */
3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 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}; 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
static const unsigned short lext[31] = { /* Length codes 257..285 extra */ static const unsigned short lext[31] = { /* Length codes 257..285 extra */
16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 199, 198}; 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 199, 198};
static const unsigned short dbase[32] = { /* Distance codes 0..29 base */ static const unsigned short dbase[32] = { /* Distance codes 0..29 base */
1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 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, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
8193, 12289, 16385, 24577, 0, 0}; 8193, 12289, 16385, 24577, 0, 0};
static const unsigned short dext[32] = { /* Distance codes 0..29 extra */ static const unsigned short dext[32] = { /* Distance codes 0..29 extra */
16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22,
23, 23, 24, 24, 25, 25, 26, 26, 27, 27, 23, 23, 24, 24, 25, 25, 26, 26, 27, 27,
28, 28, 29, 29, 64, 64}; 28, 28, 29, 29, 64, 64};
/* /*
Process a set of code lengths to create a canonical Huffman code. The Process a set of code lengths to create a canonical Huffman code. The
code lengths are lens[0..codes-1]. Each length corresponds to the code lengths are lens[0..codes-1]. Each length corresponds to the
symbols 0..codes-1. The Huffman code is generated by first sorting the symbols 0..codes-1. The Huffman code is generated by first sorting the
symbols by length from short to long, and retaining the symbol order symbols by length from short to long, and retaining the symbol order
for codes with equal lengths. Then the code starts with all zero bits for codes with equal lengths. Then the code starts with all zero bits
for the first code of the shortest length, and the codes are integer for the first code of the shortest length, and the codes are integer
increments for the same length, and zeros are appended as the length increments for the same length, and zeros are appended as the length
increases. For the deflate format, these bits are stored backwards increases. For the deflate format, these bits are stored backwards
from their more natural integer increment ordering, and so when the from their more natural integer increment ordering, and so when the
decoding tables are built in the large loop below, the integer codes decoding tables are built in the large loop below, the integer codes
are incremented backwards. are incremented backwards.
This routine assumes, but does not check, that all of the entries in This routine assumes, but does not check, that all of the entries in
lens[] are in the range 0..MAXBITS. The caller must assure this. lens[] are in the range 0..MAXBITS. The caller must assure this.
1..MAXBITS is interpreted as that code length. zero means that that 1..MAXBITS is interpreted as that code length. zero means that that
symbol does not occur in this code. symbol does not occur in this code.
The codes are sorted by computing a count of codes for each length, The codes are sorted by computing a count of codes for each length,
creating from that a table of starting indices for each length in the creating from that a table of starting indices for each length in the
sorted table, and then entering the symbols in order in the sorted sorted table, and then entering the symbols in order in the sorted
table. The sorted table is work[], with that space being provided by table. The sorted table is work[], with that space being provided by
the caller. the caller.
The length counts are used for other purposes as well, i.e. finding The length counts are used for other purposes as well, i.e. finding
the minimum and maximum length codes, determining if there are any the minimum and maximum length codes, determining if there are any
codes at all, checking for a valid set of lengths, and looking ahead codes at all, checking for a valid set of lengths, and looking ahead
at length counts to determine sub-table sizes when building the at length counts to determine sub-table sizes when building the
decoding tables. decoding tables.
*/ */
/* accumulate lengths for codes (assumes lens[] all in 0..MAXBITS) */ /* accumulate lengths for codes (assumes lens[] all in 0..MAXBITS) */
for (len = 0; len <= MAXBITS; len++) for (len = 0; len <= MAXBITS; len++)
count[len] = 0; count[len] = 0;
for (sym = 0; sym < codes; sym++) for (sym = 0; sym < codes; sym++)
count[lens[sym]]++; count[lens[sym]]++;
/* bound code lengths, force root to be within code lengths */ /* bound code lengths, force root to be within code lengths */
root = *bits; root = *bits;
for (max = MAXBITS; max >= 1; max--) for (max = MAXBITS; max >= 1; max--)
if (count[max] != 0) break; if (count[max] != 0) break;
if (root > max) root = max; if (root > max) root = max;
if (max == 0) { /* no symbols to code at all */ if (max == 0) { /* no symbols to code at all */
this.op = (unsigned char)64; /* invalid code marker */ this.op = (unsigned char)64; /* invalid code marker */
this.bits = (unsigned char)1; this.bits = (unsigned char)1;
this.val = (unsigned short)0; this.val = (unsigned short)0;
*(*table)++ = this; /* make a table to force an error */ *(*table)++ = this; /* make a table to force an error */
*(*table)++ = this; *(*table)++ = this;
*bits = 1; *bits = 1;
return 0; /* no symbols, but wait for decoding to report error */ return 0; /* no symbols, but wait for decoding to report error */
} }
for (min = 1; min <= MAXBITS; min++) for (min = 1; min <= MAXBITS; min++)
if (count[min] != 0) break; if (count[min] != 0) break;
if (root < min) root = min; if (root < min) root = min;
/* check for an over-subscribed or incomplete set of lengths */ /* check for an over-subscribed or incomplete set of lengths */
left = 1; left = 1;
for (len = 1; len <= MAXBITS; len++) { for (len = 1; len <= MAXBITS; len++) {
left <<= 1; left <<= 1;
left -= count[len]; left -= count[len];
if (left < 0) return -1; /* over-subscribed */ if (left < 0) return -1; /* over-subscribed */
} }
if (left > 0 && (type == CODES || (codes - count[0] != 1))) if (left > 0 && (type == CODES || (codes - count[0] != 1)))
return -1; /* incomplete set */ return -1; /* incomplete set */
/* generate offsets into symbol table for each length for sorting */ /* generate offsets into symbol table for each length for sorting */
offs[1] = 0; offs[1] = 0;
for (len = 1; len < MAXBITS; len++) for (len = 1; len < MAXBITS; len++)
offs[len + 1] = offs[len] + count[len]; offs[len + 1] = offs[len] + count[len];
/* sort symbols by length, by symbol order within each length */ /* sort symbols by length, by symbol order within each length */
for (sym = 0; sym < codes; sym++) for (sym = 0; sym < codes; sym++)
if (lens[sym] != 0) work[offs[lens[sym]]++] = (unsigned short)sym; if (lens[sym] != 0) work[offs[lens[sym]]++] = (unsigned short)sym;
/* /*
Create and fill in decoding tables. In this loop, the table being Create and fill in decoding tables. In this loop, the table being
filled is at next and has curr index bits. The code being used is huff filled is at next and has curr index bits. The code being used is huff
with length len. That code is converted to an index by dropping drop with length len. That code is converted to an index by dropping drop
bits off of the bottom. For codes where len is less than drop + curr, bits off of the bottom. For codes where len is less than drop + curr,
those top drop + curr - len bits are incremented through all values to those top drop + curr - len bits are incremented through all values to
fill the table with replicated entries. fill the table with replicated entries.
root is the number of index bits for the root table. When len exceeds root is the number of index bits for the root table. When len exceeds
root, sub-tables are created pointed to by the root entry with an index root, sub-tables are created pointed to by the root entry with an index
of the low root bits of huff. This is saved in low to check for when a of the low root bits of huff. This is saved in low to check for when a
new sub-table should be started. drop is zero when the root table is new sub-table should be started. drop is zero when the root table is
being filled, and drop is root when sub-tables are being filled. being filled, and drop is root when sub-tables are being filled.
When a new sub-table is needed, it is necessary to look ahead in the When a new sub-table is needed, it is necessary to look ahead in the
code lengths to determine what size sub-table is needed. The length code lengths to determine what size sub-table is needed. The length
counts are used for this, and so count[] is decremented as codes are counts are used for this, and so count[] is decremented as codes are
entered in the tables. entered in the tables.
used keeps track of how many table entries have been allocated from the used keeps track of how many table entries have been allocated from the
provided *table space. It is checked when a LENS table is being made provided *table space. It is checked when a LENS table is being made
against the space in *table, ENOUGH, minus the maximum space needed by against the space in *table, ENOUGH, minus the maximum space needed by
the worst case distance code, MAXD. This should never happen, but the the worst case distance code, MAXD. This should never happen, but the
sufficiency of ENOUGH has not been proven exhaustively, hence the check. sufficiency of ENOUGH has not been proven exhaustively, hence the check.
This assumes that when type == LENS, bits == 9. This assumes that when type == LENS, bits == 9.
sym increments through all symbols, and the loop terminates when sym increments through all symbols, and the loop terminates when
all codes of length max, i.e. all codes, have been processed. This all codes of length max, i.e. all codes, have been processed. This
routine permits incomplete codes, so another loop after this one fills routine permits incomplete codes, so another loop after this one fills
in the rest of the decoding tables with invalid code markers. in the rest of the decoding tables with invalid code markers.
*/ */
/* set up for code type */ /* set up for code type */
switch (type) { switch (type) {
case CODES: case CODES:
base = extra = work; /* dummy value--not used */ base = extra = work; /* dummy value--not used */
end = 19; end = 19;
break; break;
case LENS: case LENS:
base = lbase; base = lbase;
base -= 257; base -= 257;
extra = lext; extra = lext;
extra -= 257; extra -= 257;
end = 256; end = 256;
break; break;
default: /* DISTS */ default: /* DISTS */
base = dbase; base = dbase;
extra = dext; extra = dext;
end = -1; end = -1;
} }
/* initialize state for loop */ /* initialize state for loop */
huff = 0; /* starting code */ huff = 0; /* starting code */
sym = 0; /* starting code symbol */ sym = 0; /* starting code symbol */
len = min; /* starting code length */ len = min; /* starting code length */
next = *table; /* current table to fill in */ next = *table; /* current table to fill in */
curr = root; /* current table index bits */ curr = root; /* current table index bits */
drop = 0; /* current bits to drop from code for index */ drop = 0; /* current bits to drop from code for index */
low = (unsigned)(-1); /* trigger new sub-table when len > root */ low = (unsigned)(-1); /* trigger new sub-table when len > root */
used = 1U << root; /* use root table entries */ used = 1U << root; /* use root table entries */
mask = used - 1; /* mask for comparing low */ mask = used - 1; /* mask for comparing low */
/* check available table space */ /* check available table space */
if (type == LENS && used >= ENOUGH - MAXD) if (type == LENS && used >= ENOUGH - MAXD)
return 1; return 1;
/* process all codes and make table entries */ /* process all codes and make table entries */
for (;;) { for (;;) {
/* create table entry */ /* create table entry */
this.bits = (unsigned char)(len - drop); this.bits = (unsigned char)(len - drop);
if ((int)(work[sym]) < end) { if ((int)(work[sym]) < end) {
this.op = (unsigned char)0; this.op = (unsigned char)0;
this.val = work[sym]; this.val = work[sym];
} }
else if ((int)(work[sym]) > end) { else if ((int)(work[sym]) > end) {
this.op = (unsigned char)(extra[work[sym]]); this.op = (unsigned char)(extra[work[sym]]);
this.val = base[work[sym]]; this.val = base[work[sym]];
} }
else { else {
this.op = (unsigned char)(32 + 64); /* end of block */ this.op = (unsigned char)(32 + 64); /* end of block */
this.val = 0; this.val = 0;
} }
/* replicate for those indices with low len bits equal to huff */ /* replicate for those indices with low len bits equal to huff */
incr = 1U << (len - drop); incr = 1U << (len - drop);
fill = 1U << curr; fill = 1U << curr;
do { do {
fill -= incr; fill -= incr;
next[(huff >> drop) + fill] = this; next[(huff >> drop) + fill] = this;
} while (fill != 0); } while (fill != 0);
/* backwards increment the len-bit code huff */ /* backwards increment the len-bit code huff */
incr = 1U << (len - 1); incr = 1U << (len - 1);
while (huff & incr) while (huff & incr)
incr >>= 1; incr >>= 1;
if (incr != 0) { if (incr != 0) {
huff &= incr - 1; huff &= incr - 1;
huff += incr; huff += incr;
} }
else else
huff = 0; huff = 0;
/* go to next symbol, update count, len */ /* go to next symbol, update count, len */
sym++; sym++;
if (--(count[len]) == 0) { if (--(count[len]) == 0) {
if (len == max) break; if (len == max) break;
len = lens[work[sym]]; len = lens[work[sym]];
} }
/* create new sub-table if needed */ /* create new sub-table if needed */
if (len > root && (huff & mask) != low) { if (len > root && (huff & mask) != low) {
/* if first time, transition to sub-tables */ /* if first time, transition to sub-tables */
if (drop == 0) if (drop == 0)
drop = root; drop = root;
/* increment past last table */ /* increment past last table */
next += 1U << curr; next += 1U << curr;
/* determine length of next table */ /* determine length of next table */
curr = len - drop; curr = len - drop;
left = (int)(1 << curr); left = (int)(1 << curr);
while (curr + drop < max) { while (curr + drop < max) {
left -= count[curr + drop]; left -= count[curr + drop];
if (left <= 0) break; if (left <= 0) break;
curr++; curr++;
left <<= 1; left <<= 1;
} }
/* check for enough space */ /* check for enough space */
used += 1U << curr; used += 1U << curr;
if (type == LENS && used >= ENOUGH - MAXD) if (type == LENS && used >= ENOUGH - MAXD)
return 1; return 1;
/* point entry in root table to sub-table */ /* point entry in root table to sub-table */
low = huff & mask; low = huff & mask;
(*table)[low].op = (unsigned char)curr; (*table)[low].op = (unsigned char)curr;
(*table)[low].bits = (unsigned char)root; (*table)[low].bits = (unsigned char)root;
(*table)[low].val = (unsigned short)(next - *table); (*table)[low].val = (unsigned short)(next - *table);
} }
} }
/* /*
Fill in rest of table for incomplete codes. This loop is similar to the Fill in rest of table for incomplete codes. This loop is similar to the
loop above in incrementing huff for table indices. It is assumed that loop above in incrementing huff for table indices. It is assumed that
len is equal to curr + drop, so there is no loop needed to increment len is equal to curr + drop, so there is no loop needed to increment
through high index bits. When the current sub-table is filled, the loop through high index bits. When the current sub-table is filled, the loop
drops back to the root table to fill in any remaining entries there. drops back to the root table to fill in any remaining entries there.
*/ */
this.op = (unsigned char)64; /* invalid code marker */ this.op = (unsigned char)64; /* invalid code marker */
this.bits = (unsigned char)(len - drop); this.bits = (unsigned char)(len - drop);
this.val = (unsigned short)0; this.val = (unsigned short)0;
while (huff != 0) { while (huff != 0) {
/* when done with sub-table, drop back to root table */ /* when done with sub-table, drop back to root table */
if (drop != 0 && (huff & mask) != low) { if (drop != 0 && (huff & mask) != low) {
drop = 0; drop = 0;
len = root; len = root;
next = *table; next = *table;
this.bits = (unsigned char)len; this.bits = (unsigned char)len;
} }
/* put invalid code marker in table */ /* put invalid code marker in table */
next[huff >> drop] = this; next[huff >> drop] = this;
/* backwards increment the len-bit code huff */ /* backwards increment the len-bit code huff */
incr = 1U << (len - 1); incr = 1U << (len - 1);
while (huff & incr) while (huff & incr)
incr >>= 1; incr >>= 1;
if (incr != 0) { if (incr != 0) {
huff &= incr - 1; huff &= incr - 1;
huff += incr; huff += incr;
} }
else else
huff = 0; huff = 0;
} }
/* set return parameters */ /* set return parameters */
*table += used; *table += used;
*bits = root; *bits = root;
return 0; return 0;
} }

View file

@ -1,326 +1,326 @@
/* zconf.h -- configuration of the zlib compression library /* zconf.h -- configuration of the zlib compression library
* Copyright (C) 1995-2004 Jean-loup Gailly. * Copyright (C) 1995-2004 Jean-loup Gailly.
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
/* @(#) $Id$ */ /* @(#) $Id$ */
#ifndef ZCONF_H #ifndef ZCONF_H
#define ZCONF_H #define ZCONF_H
/* /*
* If you *really* need a unique prefix for all types and library functions, * 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. * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
*/ */
#ifdef Z_PREFIX #ifdef Z_PREFIX
# define deflateInit_ z_deflateInit_ # define deflateInit_ z_deflateInit_
# define deflate z_deflate # define deflate z_deflate
# define deflateEnd z_deflateEnd # define deflateEnd z_deflateEnd
# define inflateInit_ z_inflateInit_ # define inflateInit_ z_inflateInit_
# define inflate z_inflate # define inflate z_inflate
# define inflateEnd z_inflateEnd # define inflateEnd z_inflateEnd
# define deflateInit2_ z_deflateInit2_ # define deflateInit2_ z_deflateInit2_
# define deflateSetDictionary z_deflateSetDictionary # define deflateSetDictionary z_deflateSetDictionary
# define deflateCopy z_deflateCopy # define deflateCopy z_deflateCopy
# define deflateReset z_deflateReset # define deflateReset z_deflateReset
# define deflateParams z_deflateParams # define deflateParams z_deflateParams
# define deflateBound z_deflateBound # define deflateBound z_deflateBound
# define deflatePrime z_deflatePrime # define deflatePrime z_deflatePrime
# define inflateInit2_ z_inflateInit2_ # define inflateInit2_ z_inflateInit2_
# define inflateSetDictionary z_inflateSetDictionary # define inflateSetDictionary z_inflateSetDictionary
# define inflateSync z_inflateSync # define inflateSync z_inflateSync
# define inflateSyncPoint z_inflateSyncPoint # define inflateSyncPoint z_inflateSyncPoint
# define inflateCopy z_inflateCopy # define inflateCopy z_inflateCopy
# define inflateReset z_inflateReset # define inflateReset z_inflateReset
# define inflateBack z_inflateBack # define inflateBack z_inflateBack
# define inflateBackEnd z_inflateBackEnd # define inflateBackEnd z_inflateBackEnd
# define compress z_compress # define compress z_compress
# define compress2 z_compress2 # define compress2 z_compress2
# define compressBound z_compressBound # define compressBound z_compressBound
# define uncompress z_uncompress # define uncompress z_uncompress
# define adler32 z_adler32 # define adler32 z_adler32
# define crc32 z_crc32 # define crc32 z_crc32
# define get_crc_table z_get_crc_table # define get_crc_table z_get_crc_table
# define zError z_zError # define zError z_zError
# define Byte z_Byte # define Byte z_Byte
# define uInt z_uInt # define uInt z_uInt
# define uLong z_uLong # define uLong z_uLong
# define Bytef z_Bytef # define Bytef z_Bytef
# define charf z_charf # define charf z_charf
# define intf z_intf # define intf z_intf
# define uIntf z_uIntf # define uIntf z_uIntf
# define uLongf z_uLongf # define uLongf z_uLongf
# define voidpf z_voidpf # define voidpf z_voidpf
# define voidp z_voidp # define voidp z_voidp
#endif #endif
#if defined(__MSDOS__) && !defined(MSDOS) #if defined(__MSDOS__) && !defined(MSDOS)
# define MSDOS # define MSDOS
#endif #endif
#if (defined(OS_2) || defined(__OS2__)) && !defined(OS2) #if (defined(OS_2) || defined(__OS2__)) && !defined(OS2)
# define OS2 # define OS2
#endif #endif
#if defined(_WINDOWS) && !defined(WINDOWS) #if defined(_WINDOWS) && !defined(WINDOWS)
# define WINDOWS # define WINDOWS
#endif #endif
#if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32) #if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32)
# define WIN32 # define WIN32
#endif #endif
#if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32) #if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32)
# if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__) # if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__)
# ifndef SYS16BIT # ifndef SYS16BIT
# define SYS16BIT # define SYS16BIT
# endif # endif
# endif # endif
#endif #endif
/* /*
* Compile with -DMAXSEG_64K if the alloc function cannot allocate more * Compile with -DMAXSEG_64K if the alloc function cannot allocate more
* than 64k bytes at a time (needed on systems with 16-bit int). * than 64k bytes at a time (needed on systems with 16-bit int).
*/ */
#ifdef SYS16BIT #ifdef SYS16BIT
# define MAXSEG_64K # define MAXSEG_64K
#endif #endif
#ifdef MSDOS #ifdef MSDOS
# define UNALIGNED_OK # define UNALIGNED_OK
#endif #endif
#ifdef __STDC_VERSION__ #ifdef __STDC_VERSION__
# ifndef STDC # ifndef STDC
# define STDC # define STDC
# endif # endif
# if __STDC_VERSION__ >= 199901L # if __STDC_VERSION__ >= 199901L
# ifndef STDC99 # ifndef STDC99
# define STDC99 # define STDC99
# endif # endif
# endif # endif
#endif #endif
#if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus)) #if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus))
# define STDC # define STDC
#endif #endif
#if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__)) #if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__))
# define STDC # define STDC
#endif #endif
#if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32)) #if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32))
# define STDC # define STDC
#endif #endif
#if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__)) #if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__))
# define STDC # define STDC
#endif #endif
#if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */ #if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */
# define STDC # define STDC
#endif #endif
#ifndef STDC #ifndef STDC
# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */ # ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
# define const /* note: need a more gentle solution here */ # define const /* note: need a more gentle solution here */
# endif # endif
#endif #endif
/* Some Mac compilers merge all .h files incorrectly: */ /* Some Mac compilers merge all .h files incorrectly: */
#if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__) #if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__)
# define NO_DUMMY_DECL # define NO_DUMMY_DECL
#endif #endif
/* Maximum value for memLevel in deflateInit2 */ /* Maximum value for memLevel in deflateInit2 */
#ifndef MAX_MEM_LEVEL #ifndef MAX_MEM_LEVEL
# ifdef MAXSEG_64K # ifdef MAXSEG_64K
# define MAX_MEM_LEVEL 8 # define MAX_MEM_LEVEL 8
# else # else
# define MAX_MEM_LEVEL 9 # define MAX_MEM_LEVEL 9
# endif # endif
#endif #endif
/* Maximum value for windowBits in deflateInit2 and inflateInit2. /* Maximum value for windowBits in deflateInit2 and inflateInit2.
* WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files
* created by gzip. (Files created by minigzip can still be extracted by * created by gzip. (Files created by minigzip can still be extracted by
* gzip.) * gzip.)
*/ */
#ifndef MAX_WBITS #ifndef MAX_WBITS
# define MAX_WBITS 15 /* 32K LZ77 window */ # define MAX_WBITS 15 /* 32K LZ77 window */
#endif #endif
/* The memory requirements for deflate are (in bytes): /* The memory requirements for deflate are (in bytes):
(1 << (windowBits+2)) + (1 << (memLevel+9)) (1 << (windowBits+2)) + (1 << (memLevel+9))
that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values) 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 plus a few kilobytes for small objects. For example, if you want to reduce
the default memory requirements from 256K to 128K, compile with the default memory requirements from 256K to 128K, compile with
make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7" make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
Of course this will generally degrade compression (there's no free lunch). Of course this will generally degrade compression (there's no free lunch).
The memory requirements for inflate are (in bytes) 1 << windowBits The memory requirements for inflate are (in bytes) 1 << windowBits
that is, 32K for windowBits=15 (default value) plus a few kilobytes that is, 32K for windowBits=15 (default value) plus a few kilobytes
for small objects. for small objects.
*/ */
/* Type declarations */ /* Type declarations */
#ifndef OF /* function prototypes */ #ifndef OF /* function prototypes */
# ifdef STDC # ifdef STDC
# define OF(args) args # define OF(args) args
# else # else
# define OF(args) () # define OF(args) ()
# endif # endif
#endif #endif
/* The following definitions for FAR are needed only for MSDOS mixed /* The following definitions for FAR are needed only for MSDOS mixed
* model programming (small or medium model with some far allocations). * model programming (small or medium model with some far allocations).
* This was tested only with MSC; for other MSDOS compilers you may have * 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, * to define NO_MEMCPY in zutil.h. If you don't need the mixed model,
* just define FAR to be empty. * just define FAR to be empty.
*/ */
#ifdef SYS16BIT #ifdef SYS16BIT
# if defined(M_I86SM) || defined(M_I86MM) # if defined(M_I86SM) || defined(M_I86MM)
/* MSC small or medium model */ /* MSC small or medium model */
# define SMALL_MEDIUM # define SMALL_MEDIUM
# ifdef _MSC_VER # ifdef _MSC_VER
# define FAR _far # define FAR _far
# else # else
# define FAR far # define FAR far
# endif # endif
# endif # endif
# if (defined(__SMALL__) || defined(__MEDIUM__)) # if (defined(__SMALL__) || defined(__MEDIUM__))
/* Turbo C small or medium model */ /* Turbo C small or medium model */
# define SMALL_MEDIUM # define SMALL_MEDIUM
# ifdef __BORLANDC__ # ifdef __BORLANDC__
# define FAR _far # define FAR _far
# else # else
# define FAR far # define FAR far
# endif # endif
# endif # endif
#endif #endif
#if defined(WINDOWS) || defined(WIN32) #if defined(WINDOWS) || defined(WIN32)
/* If building or using zlib as a DLL, define ZLIB_DLL. /* If building or using zlib as a DLL, define ZLIB_DLL.
* This is not mandatory, but it offers a little performance increase. * This is not mandatory, but it offers a little performance increase.
*/ */
# ifdef ZLIB_DLL # ifdef ZLIB_DLL
# if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500)) # if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500))
# ifdef ZLIB_INTERNAL # ifdef ZLIB_INTERNAL
# define ZEXTERN extern __declspec(dllexport) # define ZEXTERN extern __declspec(dllexport)
# else # else
# define ZEXTERN extern __declspec(dllimport) # define ZEXTERN extern __declspec(dllimport)
# endif # endif
# endif # endif
# endif /* ZLIB_DLL */ # endif /* ZLIB_DLL */
/* If building or using zlib with the WINAPI/WINAPIV calling convention, /* If building or using zlib with the WINAPI/WINAPIV calling convention,
* define ZLIB_WINAPI. * define ZLIB_WINAPI.
* Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI. * Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI.
*/ */
# ifdef ZLIB_WINAPI # ifdef ZLIB_WINAPI
# ifdef FAR # ifdef FAR
# undef FAR # undef FAR
# endif # endif
# include <windows.h> # include <windows.h>
/* No need for _export, use ZLIB.DEF instead. */ /* No need for _export, use ZLIB.DEF instead. */
/* For complete Windows compatibility, use WINAPI, not __stdcall. */ /* For complete Windows compatibility, use WINAPI, not __stdcall. */
# define ZEXPORT WINAPI # define ZEXPORT WINAPI
# ifdef WIN32 # ifdef WIN32
# define ZEXPORTVA WINAPIV # define ZEXPORTVA WINAPIV
# else # else
# define ZEXPORTVA FAR CDECL # define ZEXPORTVA FAR CDECL
# endif # endif
# endif # endif
#endif #endif
#if defined (__BEOS__) #if defined (__BEOS__)
# ifdef ZLIB_DLL # ifdef ZLIB_DLL
# ifdef ZLIB_INTERNAL # ifdef ZLIB_INTERNAL
# define ZEXPORT __declspec(dllexport) # define ZEXPORT __declspec(dllexport)
# define ZEXPORTVA __declspec(dllexport) # define ZEXPORTVA __declspec(dllexport)
# else # else
# define ZEXPORT __declspec(dllimport) # define ZEXPORT __declspec(dllimport)
# define ZEXPORTVA __declspec(dllimport) # define ZEXPORTVA __declspec(dllimport)
# endif # endif
# endif # endif
#endif #endif
#ifndef ZEXTERN #ifndef ZEXTERN
# define ZEXTERN extern # define ZEXTERN extern
#endif #endif
#ifndef ZEXPORT #ifndef ZEXPORT
# define ZEXPORT # define ZEXPORT
#endif #endif
#ifndef ZEXPORTVA #ifndef ZEXPORTVA
# define ZEXPORTVA # define ZEXPORTVA
#endif #endif
#ifndef FAR #ifndef FAR
# define FAR # define FAR
#endif #endif
#if !defined(__MACTYPES__) #if !defined(__MACTYPES__)
typedef unsigned char Byte; /* 8 bits */ typedef unsigned char Byte; /* 8 bits */
#endif #endif
typedef unsigned int uInt; /* 16 bits or more */ typedef unsigned int uInt; /* 16 bits or more */
typedef unsigned long uLong; /* 32 bits or more */ typedef unsigned long uLong; /* 32 bits or more */
#ifdef SMALL_MEDIUM #ifdef SMALL_MEDIUM
/* Borland C/C++ and some old MSC versions ignore FAR inside typedef */ /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */
# define Bytef Byte FAR # define Bytef Byte FAR
#else #else
typedef Byte FAR Bytef; typedef Byte FAR Bytef;
#endif #endif
typedef char FAR charf; typedef char FAR charf;
typedef int FAR intf; typedef int FAR intf;
typedef uInt FAR uIntf; typedef uInt FAR uIntf;
typedef uLong FAR uLongf; typedef uLong FAR uLongf;
#ifdef STDC #ifdef STDC
typedef void const *voidpc; typedef void const *voidpc;
typedef void FAR *voidpf; typedef void FAR *voidpf;
typedef void *voidp; typedef void *voidp;
#else #else
typedef Byte const *voidpc; typedef Byte const *voidpc;
typedef Byte FAR *voidpf; typedef Byte FAR *voidpf;
typedef Byte *voidp; typedef Byte *voidp;
#endif #endif
#if 0 /* HAVE_UNISTD_H -- this line is updated by ./configure */ #if 0 /* HAVE_UNISTD_H -- this line is updated by ./configure */
# include <sys/types.h> /* for off_t */ # include <sys/types.h> /* for off_t */
# include <unistd.h> /* for SEEK_* and off_t */ # include <unistd.h> /* for SEEK_* and off_t */
# ifdef VMS # ifdef VMS
# include <unixio.h> /* for off_t */ # include <unixio.h> /* for off_t */
# endif # endif
# define z_off_t off_t # define z_off_t off_t
#endif #endif
#ifndef SEEK_SET #ifndef SEEK_SET
# define SEEK_SET 0 /* Seek from beginning of file. */ # define SEEK_SET 0 /* Seek from beginning of file. */
# define SEEK_CUR 1 /* Seek from current position. */ # define SEEK_CUR 1 /* Seek from current position. */
# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */ # define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
#endif #endif
#ifndef z_off_t #ifndef z_off_t
# define z_off_t long # define z_off_t long
#endif #endif
#if defined(__OS400__) #if defined(__OS400__)
# define NO_vsnprintf # define NO_vsnprintf
#endif #endif
#if defined(__MVS__) #if defined(__MVS__)
# define NO_vsnprintf # define NO_vsnprintf
# ifdef FAR # ifdef FAR
# undef FAR # undef FAR
# endif # endif
#endif #endif
/* MVS linker does not support external names larger than 8 bytes */ /* MVS linker does not support external names larger than 8 bytes */
#if defined(__MVS__) #if defined(__MVS__)
# pragma map(deflateInit_,"DEIN") # pragma map(deflateInit_,"DEIN")
# pragma map(deflateInit2_,"DEIN2") # pragma map(deflateInit2_,"DEIN2")
# pragma map(deflateEnd,"DEEND") # pragma map(deflateEnd,"DEEND")
# pragma map(deflateBound,"DEBND") # pragma map(deflateBound,"DEBND")
# pragma map(inflateInit_,"ININ") # pragma map(inflateInit_,"ININ")
# pragma map(inflateInit2_,"ININ2") # pragma map(inflateInit2_,"ININ2")
# pragma map(inflateEnd,"INEND") # pragma map(inflateEnd,"INEND")
# pragma map(inflateSync,"INSY") # pragma map(inflateSync,"INSY")
# pragma map(inflateSetDictionary,"INSEDI") # pragma map(inflateSetDictionary,"INSEDI")
# pragma map(compressBound,"CMBND") # pragma map(compressBound,"CMBND")
# pragma map(inflate_table,"INTABL") # pragma map(inflate_table,"INTABL")
# pragma map(inflate_fast,"INFA") # pragma map(inflate_fast,"INFA")
# pragma map(inflate_copyright,"INCOPY") # pragma map(inflate_copyright,"INCOPY")
#endif #endif
#endif /* ZCONF_H */ #endif /* ZCONF_H */

File diff suppressed because it is too large Load diff

View file

@ -1,263 +1,263 @@
/* zutil.h -- internal interface and configuration of the compression library /* zutil.h -- internal interface and configuration of the compression library
* Copyright (C) 1995-2003 Jean-loup Gailly. * Copyright (C) 1995-2003 Jean-loup Gailly.
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
/* WARNING: this file should *not* be used by applications. It is /* WARNING: this file should *not* be used by applications. It is
part of the implementation of the compression library and is part of the implementation of the compression library and is
subject to change. Applications should only use zlib.h. subject to change. Applications should only use zlib.h.
*/ */
/* @(#) $Id$ */ /* @(#) $Id$ */
#ifndef ZUTIL_H #ifndef ZUTIL_H
#define ZUTIL_H #define ZUTIL_H
#define ZLIB_INTERNAL #define ZLIB_INTERNAL
#include "zlib.h" #include "zlib.h"
#ifdef STDC #ifdef STDC
# include <stddef.h> # include <stddef.h>
# include <string.h> # include <string.h>
# include <stdlib.h> # include <stdlib.h>
#endif #endif
#ifdef NO_ERRNO_H #ifdef NO_ERRNO_H
extern int errno; extern int errno;
#else #else
# include <errno.h> # include <errno.h>
#endif #endif
#ifndef local #ifndef local
# define local static # define local static
#endif #endif
/* compile with -Dlocal if your debugger can't find static symbols */ /* compile with -Dlocal if your debugger can't find static symbols */
typedef unsigned char uch; typedef unsigned char uch;
typedef uch FAR uchf; typedef uch FAR uchf;
typedef unsigned short ush; typedef unsigned short ush;
typedef ush FAR ushf; typedef ush FAR ushf;
typedef unsigned long ulg; typedef unsigned long ulg;
extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
/* (size given to avoid silly warnings with Visual C++) */ /* (size given to avoid silly warnings with Visual C++) */
#define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)] #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
#define ERR_RETURN(strm,err) \ #define ERR_RETURN(strm,err) \
return (strm->msg = (char*)ERR_MSG(err), (err)) return (strm->msg = (char*)ERR_MSG(err), (err))
/* To be used only when the state is known to be valid */ /* To be used only when the state is known to be valid */
/* common constants */ /* common constants */
#ifndef DEF_WBITS #ifndef DEF_WBITS
# define DEF_WBITS MAX_WBITS # define DEF_WBITS MAX_WBITS
#endif #endif
/* default windowBits for decompression. MAX_WBITS is for compression only */ /* default windowBits for decompression. MAX_WBITS is for compression only */
#if MAX_MEM_LEVEL >= 8 #if MAX_MEM_LEVEL >= 8
# define DEF_MEM_LEVEL 8 # define DEF_MEM_LEVEL 8
#else #else
# define DEF_MEM_LEVEL MAX_MEM_LEVEL # define DEF_MEM_LEVEL MAX_MEM_LEVEL
#endif #endif
/* default memLevel */ /* default memLevel */
#define STORED_BLOCK 0 #define STORED_BLOCK 0
#define STATIC_TREES 1 #define STATIC_TREES 1
#define DYN_TREES 2 #define DYN_TREES 2
/* The three kinds of block type */ /* The three kinds of block type */
#define MIN_MATCH 3 #define MIN_MATCH 3
#define MAX_MATCH 258 #define MAX_MATCH 258
/* The minimum and maximum match lengths */ /* The minimum and maximum match lengths */
#define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */ #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
/* target dependencies */ /* target dependencies */
#if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32)) #if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))
# define OS_CODE 0x00 # define OS_CODE 0x00
# if defined(__TURBOC__) || defined(__BORLANDC__) # if defined(__TURBOC__) || defined(__BORLANDC__)
# if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__)) # if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
/* Allow compilation with ANSI keywords only enabled */ /* Allow compilation with ANSI keywords only enabled */
void _Cdecl farfree( void *block ); void _Cdecl farfree( void *block );
void *_Cdecl farmalloc( unsigned long nbytes ); void *_Cdecl farmalloc( unsigned long nbytes );
# else # else
# include <alloc.h> # include <alloc.h>
# endif # endif
# else /* MSC or DJGPP */ # else /* MSC or DJGPP */
# include <malloc.h> # include <malloc.h>
# endif # endif
#endif #endif
#ifdef AMIGA #ifdef AMIGA
# define OS_CODE 0x01 # define OS_CODE 0x01
#endif #endif
#if defined(VAXC) || defined(VMS) #if defined(VAXC) || defined(VMS)
# define OS_CODE 0x02 # define OS_CODE 0x02
# define F_OPEN(name, mode) \ # define F_OPEN(name, mode) \
fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512") fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
#endif #endif
#if defined(ATARI) || defined(atarist) #if defined(ATARI) || defined(atarist)
# define OS_CODE 0x05 # define OS_CODE 0x05
#endif #endif
#ifdef OS2 #ifdef OS2
# define OS_CODE 0x06 # define OS_CODE 0x06
#endif #endif
#if defined(MACOS) || defined(TARGET_OS_MAC) #if defined(MACOS) || defined(TARGET_OS_MAC)
# define OS_CODE 0x07 # define OS_CODE 0x07
# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os # if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
# include <unix.h> /* for fdopen */ # include <unix.h> /* for fdopen */
# else # else
# ifndef fdopen # ifndef fdopen
# define fdopen(fd,mode) NULL /* No fdopen() */ # define fdopen(fd,mode) NULL /* No fdopen() */
# endif # endif
# endif # endif
#endif #endif
#ifdef TOPS20 #ifdef TOPS20
# define OS_CODE 0x0a # define OS_CODE 0x0a
#endif #endif
#ifdef WIN32 #ifdef WIN32
# ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */ # ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */
# define OS_CODE 0x0b # define OS_CODE 0x0b
# endif # endif
#endif #endif
#ifdef __50SERIES /* Prime/PRIMOS */ #ifdef __50SERIES /* Prime/PRIMOS */
# define OS_CODE 0x0f # define OS_CODE 0x0f
#endif #endif
#if defined(_BEOS_) || defined(RISCOS) #if defined(_BEOS_) || defined(RISCOS)
# define fdopen(fd,mode) NULL /* No fdopen() */ # define fdopen(fd,mode) NULL /* No fdopen() */
#endif #endif
#if (defined(_MSC_VER) && (_MSC_VER > 600)) #if (defined(_MSC_VER) && (_MSC_VER > 600))
# if defined(_WIN32_WCE) # if defined(_WIN32_WCE)
# define fdopen(fd,mode) NULL /* No fdopen() */ # define fdopen(fd,mode) NULL /* No fdopen() */
# ifndef _PTRDIFF_T_DEFINED # ifndef _PTRDIFF_T_DEFINED
typedef int ptrdiff_t; typedef int ptrdiff_t;
# define _PTRDIFF_T_DEFINED # define _PTRDIFF_T_DEFINED
# endif # endif
# else # else
# define fdopen(fd,type) _fdopen(fd,type) # define fdopen(fd,type) _fdopen(fd,type)
# endif # endif
#endif #endif
/* common defaults */ /* common defaults */
#ifndef OS_CODE #ifndef OS_CODE
# define OS_CODE 0x03 /* assume Unix */ # define OS_CODE 0x03 /* assume Unix */
#endif #endif
#ifndef F_OPEN #ifndef F_OPEN
# define F_OPEN(name, mode) fopen((name), (mode)) # define F_OPEN(name, mode) fopen((name), (mode))
#endif #endif
/* functions */ /* functions */
#if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550) #if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)
# ifndef HAVE_VSNPRINTF # ifndef HAVE_VSNPRINTF
# define HAVE_VSNPRINTF # define HAVE_VSNPRINTF
# endif # endif
#endif #endif
#if defined(__CYGWIN__) #if defined(__CYGWIN__)
# ifndef HAVE_VSNPRINTF # ifndef HAVE_VSNPRINTF
# define HAVE_VSNPRINTF # define HAVE_VSNPRINTF
# endif # endif
#endif #endif
#ifndef HAVE_VSNPRINTF #ifndef HAVE_VSNPRINTF
# ifdef MSDOS # ifdef MSDOS
/* vsnprintf may exist on some MS-DOS compilers (DJGPP?), /* vsnprintf may exist on some MS-DOS compilers (DJGPP?),
but for now we just assume it doesn't. */ but for now we just assume it doesn't. */
# define NO_vsnprintf # define NO_vsnprintf
# endif # endif
# ifdef __TURBOC__ # ifdef __TURBOC__
# define NO_vsnprintf # define NO_vsnprintf
# endif # endif
# ifdef WIN32 # ifdef WIN32
/* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */ /* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */
# if !defined(vsnprintf) && !defined(NO_vsnprintf) # if !defined(vsnprintf) && !defined(NO_vsnprintf)
# define vsnprintf _vsnprintf # define vsnprintf _vsnprintf
# endif # endif
# endif # endif
# ifdef __SASC # ifdef __SASC
# define NO_vsnprintf # define NO_vsnprintf
# endif # endif
#endif #endif
#ifdef VMS #ifdef VMS
# define NO_vsnprintf # define NO_vsnprintf
#endif #endif
#ifdef HAVE_STRERROR #ifdef HAVE_STRERROR
# ifndef VMS # ifndef VMS
extern char *strerror OF((int)); extern char *strerror OF((int));
# endif # endif
# define zstrerror(errnum) strerror(errnum) # define zstrerror(errnum) strerror(errnum)
#else #else
# define zstrerror(errnum) "" # define zstrerror(errnum) ""
#endif #endif
#if defined(pyr) #if defined(pyr)
# define NO_MEMCPY # define NO_MEMCPY
#endif #endif
#if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__) #if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
/* Use our own functions for small and medium model with MSC <= 5.0. /* 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). * You may have to use the same strategy for Borland C (untested).
* The __SC__ check is for Symantec. * The __SC__ check is for Symantec.
*/ */
# define NO_MEMCPY # define NO_MEMCPY
#endif #endif
#if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY) #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
# define HAVE_MEMCPY # define HAVE_MEMCPY
#endif #endif
#ifdef HAVE_MEMCPY #ifdef HAVE_MEMCPY
# ifdef SMALL_MEDIUM /* MSDOS small or medium model */ # ifdef SMALL_MEDIUM /* MSDOS small or medium model */
# define zmemcpy _fmemcpy # define zmemcpy _fmemcpy
# define zmemcmp _fmemcmp # define zmemcmp _fmemcmp
# define zmemzero(dest, len) _fmemset(dest, 0, len) # define zmemzero(dest, len) _fmemset(dest, 0, len)
# else # else
# define zmemcpy memcpy # define zmemcpy memcpy
# define zmemcmp memcmp # define zmemcmp memcmp
# define zmemzero(dest, len) memset(dest, 0, len) # define zmemzero(dest, len) memset(dest, 0, len)
# endif # endif
#else #else
extern void zmemcpy OF((Bytef* dest, const Bytef* source, uInt len)); extern void zmemcpy OF((Bytef* dest, const Bytef* source, uInt len));
extern int zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len)); extern int zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len));
extern void zmemzero OF((Bytef* dest, uInt len)); extern void zmemzero OF((Bytef* dest, uInt len));
#endif #endif
/* Diagnostic functions */ /* Diagnostic functions */
#ifdef DEBUG #ifdef DEBUG
# include <stdio.h> # include <stdio.h>
extern int z_verbose; extern int z_verbose;
extern void z_error OF((char *m)); extern void z_error OF((char *m));
# define Assert(cond,msg) {if(!(cond)) z_error(msg);} # define Assert(cond,msg) {if(!(cond)) z_error(msg);}
# define Trace(x) {if (z_verbose>=0) fprintf x ;} # define Trace(x) {if (z_verbose>=0) fprintf x ;}
# define Tracev(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 Tracevv(x) {if (z_verbose>1) fprintf x ;}
# define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;} # define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
# define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;} # define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
#else #else
# define Assert(cond,msg) # define Assert(cond,msg)
# define Trace(x) # define Trace(x)
# define Tracev(x) # define Tracev(x)
# define Tracevv(x) # define Tracevv(x)
# define Tracec(c,x) # define Tracec(c,x)
# define Tracecv(c,x) # define Tracecv(c,x)
#endif #endif
voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size)); voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size));
void zcfree OF((voidpf opaque, voidpf ptr)); void zcfree OF((voidpf opaque, voidpf ptr));
#define ZALLOC(strm, items, size) \ #define ZALLOC(strm, items, size) \
(*((strm)->zalloc))((strm)->opaque, (items), (size)) (*((strm)->zalloc))((strm)->opaque, (items), (size))
#define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr)) #define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
#define TRY_FREE(s, p) {if (p) ZFREE(s, p);} #define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
#endif /* ZUTIL_H */ #endif /* ZUTIL_H */