New plugin file format, new zlib libraries
This commit is contained in:
parent
65bd10c47b
commit
a776e832dd
@ -51,10 +51,6 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
typedef char mint8_t;
|
||||
typedef int16_t mint16_t;
|
||||
typedef int32_t mint32_t;
|
||||
|
||||
struct TableEntry
|
||||
{
|
||||
mint8_t cellSize PACKED;
|
||||
@ -76,6 +72,8 @@ struct TableEntry
|
||||
|
||||
CAmxxReader::CAmxxReader(const char *filename, int cellsize)
|
||||
{
|
||||
m_Bh.plugins = NULL;
|
||||
m_AmxxFile = false;
|
||||
if (!filename)
|
||||
{
|
||||
m_Status = Err_InvalidParam;
|
||||
@ -96,41 +94,55 @@ CAmxxReader::CAmxxReader(const char *filename, int cellsize)
|
||||
DATAREAD(&magic, sizeof(magic), 1);
|
||||
|
||||
m_OldFile = false;
|
||||
if (magic != 0x414D5842)
|
||||
{
|
||||
// check for old file
|
||||
AMX_HEADER hdr;
|
||||
rewind(m_pFile);
|
||||
fread(&hdr, sizeof(hdr), 1, m_pFile);
|
||||
amx_Align16(&hdr.magic);
|
||||
if (hdr.magic == AMX_MAGIC)
|
||||
{
|
||||
if (cellsize != 4)
|
||||
{
|
||||
m_Status = Err_SectionNotFound;
|
||||
fclose(m_pFile);
|
||||
m_pFile = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
m_OldFile = true;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
// no known file format
|
||||
m_Status = Err_FileInvalid;
|
||||
fclose(m_pFile);
|
||||
m_pFile = NULL;
|
||||
return;
|
||||
}
|
||||
} else if ( magic == 0x524C4542 ) {
|
||||
if ( magic == 0x524C4542 ) {
|
||||
//we have an invalid, old, RLEB file
|
||||
m_Status = Err_OldFile;
|
||||
fclose(m_pFile);
|
||||
m_pFile = NULL;
|
||||
return;
|
||||
} else {
|
||||
} else if ( magic == MAGIC_HEADER2 ) {
|
||||
DATAREAD(&m_Bh.version, sizeof(int16_t), 1);
|
||||
if (m_Bh.version != MAGIC_VERSION)
|
||||
{
|
||||
m_Status = Err_OldFile;
|
||||
fclose(m_pFile);
|
||||
m_pFile = NULL;
|
||||
return;
|
||||
}
|
||||
m_AmxxFile = true;
|
||||
DATAREAD(&m_Bh.numPlugins, sizeof(mint8_t), 1);
|
||||
m_Bh.plugins = new PluginEntry[m_Bh.numPlugins];
|
||||
PluginEntry *pe;
|
||||
m_SectionHdrOffset = 0;
|
||||
m_Entry = -1;
|
||||
for (mint8_t i=0; i<m_Bh.numPlugins; i++)
|
||||
{
|
||||
pe = &(m_Bh.plugins[i]);
|
||||
DATAREAD(&pe->cellsize, sizeof(mint8_t), 1);
|
||||
DATAREAD(&pe->disksize, sizeof(int32_t), 1);
|
||||
DATAREAD(&pe->imagesize, sizeof(int32_t), 1);
|
||||
DATAREAD(&pe->memsize, sizeof(int32_t), 1);
|
||||
DATAREAD(&pe->offs, sizeof(int32_t), 1);
|
||||
}
|
||||
for (mint8_t i=0; i<m_Bh.numPlugins; i++)
|
||||
{
|
||||
pe = &(m_Bh.plugins[i]);
|
||||
if (pe->cellsize == m_CellSize)
|
||||
{
|
||||
m_Entry = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (m_Entry == -1)
|
||||
{
|
||||
m_Status = Err_SectionNotFound;
|
||||
fclose(m_pFile);
|
||||
m_pFile = NULL;
|
||||
return;
|
||||
}
|
||||
pe = &(m_Bh.plugins[m_Entry]);
|
||||
m_SectionLength = pe->disksize;
|
||||
} else if (magic == MAGIC_HEADER) {
|
||||
|
||||
// try to find the section
|
||||
mint8_t numOfPlugins;
|
||||
@ -170,7 +182,34 @@ CAmxxReader::CAmxxReader(const char *filename, int cellsize)
|
||||
fseek(m_pFile, 0, SEEK_END);
|
||||
m_SectionLength = ftell(m_pFile) - (long)entry.offset;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// check for old file
|
||||
AMX_HEADER hdr;
|
||||
rewind(m_pFile);
|
||||
fread(&hdr, sizeof(hdr), 1, m_pFile);
|
||||
amx_Align16(&hdr.magic);
|
||||
if (hdr.magic == AMX_MAGIC)
|
||||
{
|
||||
if (cellsize != 4)
|
||||
{
|
||||
m_Status = Err_SectionNotFound;
|
||||
fclose(m_pFile);
|
||||
m_pFile = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
m_OldFile = true;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
// no known file format
|
||||
m_Status = Err_FileInvalid;
|
||||
fclose(m_pFile);
|
||||
m_pFile = NULL;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CAmxxReader::~CAmxxReader()
|
||||
@ -180,6 +219,11 @@ CAmxxReader::~CAmxxReader()
|
||||
fclose(m_pFile);
|
||||
m_pFile = NULL;
|
||||
}
|
||||
if (m_Bh.plugins)
|
||||
{
|
||||
delete m_Bh.plugins;
|
||||
m_Bh.plugins = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
CAmxxReader::Error CAmxxReader::GetStatus()
|
||||
@ -205,7 +249,6 @@ size_t CAmxxReader::GetBufferSize()
|
||||
if (!m_pFile)
|
||||
return 0;
|
||||
|
||||
|
||||
long save = ftell(m_pFile);
|
||||
|
||||
if (m_OldFile)
|
||||
@ -215,6 +258,11 @@ size_t CAmxxReader::GetBufferSize()
|
||||
DATAREAD(&hdr, sizeof(hdr), 1);
|
||||
fseek(m_pFile, save, SEEK_SET);
|
||||
return hdr.stp;
|
||||
} else if (m_AmxxFile) {
|
||||
PluginEntry *pe = &(m_Bh.plugins[m_Entry]);
|
||||
if (pe->imagesize > pe->memsize)
|
||||
return pe->imagesize + 1;
|
||||
return pe->memsize + 1;
|
||||
}
|
||||
|
||||
fseek(m_pFile, m_SectionHdrOffset, SEEK_SET);
|
||||
@ -252,27 +300,44 @@ CAmxxReader::Error CAmxxReader::GetSection(void *buffer)
|
||||
DATAREAD(buffer, 1, filesize);
|
||||
m_Status = Err_None;
|
||||
return m_Status;
|
||||
}
|
||||
|
||||
// new file type: go to the section table entry
|
||||
fseek(m_pFile, m_SectionHdrOffset, SEEK_SET);
|
||||
// go to the offset
|
||||
TableEntry entry;
|
||||
DATAREAD(&entry, sizeof(entry), 1);
|
||||
fseek(m_pFile, entry.offset, SEEK_SET);
|
||||
uLongf destLen = GetBufferSize();
|
||||
// read the data to a temporary buffer
|
||||
char *tempBuffer = new char[m_SectionLength + 1];
|
||||
//fread(tempBuffer, sizeof(char), m_SectionLength, m_pFile);
|
||||
DATAREAD((void*)tempBuffer, 1, m_SectionLength);
|
||||
// decompress
|
||||
int result = uncompress((Bytef *)buffer, &destLen,
|
||||
} else if (m_AmxxFile) {
|
||||
PluginEntry *pe = &(m_Bh.plugins[m_Entry]);
|
||||
char *tempBuffer = new char[m_SectionLength + 1];
|
||||
fseek(m_pFile, pe->offs, SEEK_SET);
|
||||
DATAREAD((void *)tempBuffer, 1, m_SectionLength);
|
||||
uLongf destLen = GetBufferSize();
|
||||
int result = uncompress((Bytef *)buffer, &destLen,
|
||||
(Bytef *)tempBuffer, m_SectionLength);
|
||||
delete [] tempBuffer;
|
||||
if (result != Z_OK)
|
||||
{
|
||||
m_Status = Err_Decompress;
|
||||
return Err_Decompress;
|
||||
delete [] tempBuffer;
|
||||
if (result != Z_OK)
|
||||
{
|
||||
AMXXLOG_Log("[AMXX] Zlib error encountered: %d(%d)", result, m_SectionLength);
|
||||
m_Status = Err_Decompress;
|
||||
return Err_Decompress;
|
||||
}
|
||||
return Err_None;
|
||||
} else {
|
||||
// new file type: go to the section table entry
|
||||
fseek(m_pFile, m_SectionHdrOffset, SEEK_SET);
|
||||
// go to the offset
|
||||
TableEntry entry;
|
||||
DATAREAD(&entry, sizeof(entry), 1);
|
||||
fseek(m_pFile, entry.offset, SEEK_SET);
|
||||
uLongf destLen = GetBufferSize();
|
||||
// read the data to a temporary buffer
|
||||
char *tempBuffer = new char[m_SectionLength + 1];
|
||||
//fread(tempBuffer, sizeof(char), m_SectionLength, m_pFile);
|
||||
DATAREAD((void*)tempBuffer, 1, m_SectionLength);
|
||||
// decompress
|
||||
int result = uncompress((Bytef *)buffer, &destLen,
|
||||
(Bytef *)tempBuffer, m_SectionLength);
|
||||
delete [] tempBuffer;
|
||||
if (result != Z_OK)
|
||||
{
|
||||
AMXXLOG_Log("[AMXX] Zlib error encountered: %d(%d)", result, m_SectionLength);
|
||||
m_Status = Err_Decompress;
|
||||
return Err_Decompress;
|
||||
}
|
||||
return Err_None;
|
||||
}
|
||||
return Err_None;
|
||||
}
|
||||
|
@ -32,6 +32,31 @@
|
||||
#ifndef __AMXXFILE_H__
|
||||
#define __AMXXFILE_H__
|
||||
|
||||
#define MAGIC_HEADER 0x414D5842
|
||||
#define MAGIC_HEADER2 0x414D5858
|
||||
#define MAGIC_VERSION 0x0300
|
||||
|
||||
typedef char mint8_t;
|
||||
typedef int16_t mint16_t;
|
||||
typedef int32_t mint32_t;
|
||||
|
||||
struct PluginEntry
|
||||
{
|
||||
mint8_t cellsize; //cell size
|
||||
int32_t imagesize; //uncompressed image size
|
||||
int32_t disksize; //compressed image size
|
||||
int32_t memsize; //memory image size
|
||||
int32_t offs; //file offset
|
||||
};
|
||||
|
||||
struct BinHeader
|
||||
{
|
||||
int32_t magic;
|
||||
mint16_t version;
|
||||
mint8_t numPlugins;
|
||||
PluginEntry *plugins;
|
||||
};
|
||||
|
||||
class CAmxxReader
|
||||
{
|
||||
public:
|
||||
@ -53,6 +78,9 @@ private:
|
||||
FILE *m_pFile;
|
||||
|
||||
bool m_OldFile; // old .amx file
|
||||
bool m_AmxxFile; // new 'AMXX' header format
|
||||
BinHeader m_Bh; // binary header
|
||||
int m_Entry; // entry #
|
||||
|
||||
int m_CellSize;
|
||||
int m_SectionHdrOffset; // offset to the table in the header that describes the required section
|
||||
@ -66,6 +94,5 @@ public:
|
||||
Error GetSection(void *buffer); // Copy the currently selected section to the buffer
|
||||
};
|
||||
|
||||
|
||||
#endif // __AMXXFILE_H__
|
||||
|
||||
|
@ -1482,7 +1482,7 @@ void LogError(AMX *amx, int err, const char *fmt, ...)
|
||||
//does this plugin have debug info?
|
||||
va_list arg;
|
||||
AMX_DBGINFO *pInfo = (AMX_DBGINFO *)(amx->userdata[2]);
|
||||
CPluginMngr::CPlugin *pPlugin = g_plugins.findPluginFast(amx);
|
||||
const char *name = get_amxscriptname(amx);
|
||||
static char buf[1024];
|
||||
static char vbuf[1024];
|
||||
*buf = 0;
|
||||
@ -1501,7 +1501,8 @@ void LogError(AMX *amx, int err, const char *fmt, ...)
|
||||
AMXXLOG_Log("[AMXX] %s", vbuf);
|
||||
if (!pInfo || !(amx->flags & AMX_FLAG_DEBUG) || !pInfo->pDebug)
|
||||
{
|
||||
AMXXLOG_Log("[AMXX] Debug is not enabled (plugin \"%s\")", pPlugin->getName());
|
||||
|
||||
AMXXLOG_Log("[AMXX] Debug is not enabled (plugin \"%s\")", name);
|
||||
invalidate = true;
|
||||
} else {
|
||||
long line;
|
||||
@ -1511,7 +1512,7 @@ void LogError(AMX *amx, int err, const char *fmt, ...)
|
||||
int i=0, iLine;
|
||||
cell frame;
|
||||
|
||||
AMXXLOG_Log("[AMXX] Displaying call trace (plugin \"%s\")", pPlugin->getName());
|
||||
AMXXLOG_Log("[AMXX] Displaying call trace (plugin \"%s\")", name);
|
||||
while (pTrace)
|
||||
{
|
||||
frame = pTrace->frm;
|
||||
@ -1671,6 +1672,7 @@ void Module_CacheFunctions()
|
||||
|
||||
// other amx stuff
|
||||
REGISTER_FUNC("amx_Exec", amx_Exec)
|
||||
REGISTER_FUNC("amx_Push", amx_Push);
|
||||
REGISTER_FUNC("amx_Execv", amx_Execv) //I HOPE NO ONE USES THIS!!!!
|
||||
REGISTER_FUNC("amx_Allot", amx_Allot)
|
||||
REGISTER_FUNC("amx_FindPublic", amx_FindPublic)
|
||||
|
@ -325,6 +325,7 @@
|
||||
LinkIncremental="1"
|
||||
SuppressStartupBanner="TRUE"
|
||||
AdditionalLibraryDirectories="..\extra\lib_win32"
|
||||
IgnoreDefaultLibraryNames="MSVCRT"
|
||||
ModuleDefinitionFile=""
|
||||
GenerateDebugInformation="TRUE"
|
||||
ProgramDatabaseFile=".\jitdebug/amxx_mm.pdb"
|
||||
@ -390,11 +391,12 @@
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalOptions="/MACHINE:I386"
|
||||
AdditionalDependencies="..\zlib\zlib.lib ..\JIT\amxjitsn.obj ..\JIT\amxexecn.obj"
|
||||
AdditionalDependencies="..\zlib\zlib.lib ..\JIT\amxjitsn.obj ..\JIT\amxexecn.obj ..\JIT\natives-x86.obj"
|
||||
OutputFile="jitrelease/amxmodx_mm.dll"
|
||||
LinkIncremental="1"
|
||||
SuppressStartupBanner="TRUE"
|
||||
AdditionalLibraryDirectories="..\extra\lib_win32"
|
||||
IgnoreDefaultLibraryNames="MSVCRT"
|
||||
ModuleDefinitionFile=""
|
||||
GenerateDebugInformation="TRUE"
|
||||
ProgramDatabaseFile=".\jitrelease/amxx_mm.pdb"
|
||||
@ -811,6 +813,12 @@
|
||||
<File
|
||||
RelativePath="..\resource.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\zlib\zconf.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\zlib\zlib.h">
|
||||
</File>
|
||||
<Filter
|
||||
Name="mmgr"
|
||||
Filter="">
|
||||
|
@ -1,7 +1,7 @@
|
||||
/* zlib.h -- interface of the 'zlib' general purpose compression library
|
||||
version 1.2.1, November 17th, 2003
|
||||
version 1.2.3, July 18th, 2005
|
||||
|
||||
Copyright (C) 1995-2003 Jean-loup Gailly and Mark Adler
|
||||
Copyright (C) 1995-2005 Jean-loup Gailly and Mark Adler
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
@ -37,8 +37,8 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define ZLIB_VERSION "1.2.1"
|
||||
#define ZLIB_VERNUM 0x1210
|
||||
#define ZLIB_VERSION "1.2.3"
|
||||
#define ZLIB_VERNUM 0x1230
|
||||
|
||||
/*
|
||||
The 'zlib' compression library provides in-memory compression and
|
||||
@ -53,24 +53,22 @@ extern "C" {
|
||||
application must provide more input and/or consume the output
|
||||
(providing more output space) before each call.
|
||||
|
||||
The compressed data format used by the in-memory functions is the zlib
|
||||
format, which is a zlib wrapper documented in RFC 1950, wrapped around a
|
||||
deflate stream, which is itself documented in RFC 1951.
|
||||
The compressed data format used by default by the in-memory functions is
|
||||
the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped
|
||||
around a deflate stream, which is itself documented in RFC 1951.
|
||||
|
||||
The library also supports reading and writing files in gzip (.gz) format
|
||||
with an interface similar to that of stdio using the functions that start
|
||||
with "gz". The gzip format is different from the zlib format. gzip is a
|
||||
gzip wrapper, documented in RFC 1952, wrapped around a deflate stream.
|
||||
|
||||
This library can optionally read and write gzip streams in memory as well.
|
||||
|
||||
The zlib format was designed to be compact and fast for use in memory
|
||||
and on communications channels. The gzip format was designed for single-
|
||||
file compression on file systems, has a larger header than zlib to maintain
|
||||
directory information, and uses a different, slower check method than zlib.
|
||||
|
||||
This library does not provide any functions to write gzip files in memory.
|
||||
However such functions could be easily written using zlib's deflate function,
|
||||
the documentation in the gzip RFC, and the examples in gzio.c.
|
||||
|
||||
The library does not install any signal handler. The decoder checks
|
||||
the consistency of the compressed data, so the library should never
|
||||
crash even in case of corrupted input.
|
||||
@ -97,13 +95,36 @@ typedef struct z_stream_s {
|
||||
free_func zfree; /* used to free the internal state */
|
||||
voidpf opaque; /* private data object passed to zalloc and zfree */
|
||||
|
||||
int data_type; /* best guess about the data type: ascii or binary */
|
||||
int data_type; /* best guess about the data type: binary or text */
|
||||
uLong adler; /* adler32 value of the uncompressed data */
|
||||
uLong reserved; /* reserved for future use */
|
||||
} z_stream;
|
||||
|
||||
typedef z_stream FAR *z_streamp;
|
||||
|
||||
/*
|
||||
gzip header information passed to and from zlib routines. See RFC 1952
|
||||
for more details on the meanings of these fields.
|
||||
*/
|
||||
typedef struct gz_header_s {
|
||||
int text; /* true if compressed data believed to be text */
|
||||
uLong time; /* modification time */
|
||||
int xflags; /* extra flags (not used when writing a gzip file) */
|
||||
int os; /* operating system */
|
||||
Bytef *extra; /* pointer to extra field or Z_NULL if none */
|
||||
uInt extra_len; /* extra field length (valid if extra != Z_NULL) */
|
||||
uInt extra_max; /* space at extra (only when reading header) */
|
||||
Bytef *name; /* pointer to zero-terminated file name or Z_NULL */
|
||||
uInt name_max; /* space at name (only when reading header) */
|
||||
Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */
|
||||
uInt comm_max; /* space at comment (only when reading header) */
|
||||
int hcrc; /* true if there was or will be a header crc */
|
||||
int done; /* true when done reading gzip header (not used
|
||||
when writing a gzip file) */
|
||||
} gz_header;
|
||||
|
||||
typedef gz_header FAR *gz_headerp;
|
||||
|
||||
/*
|
||||
The application must update next_in and avail_in when avail_in has
|
||||
dropped to zero. It must update next_out and avail_out when avail_out
|
||||
@ -168,11 +189,13 @@ typedef z_stream FAR *z_streamp;
|
||||
#define Z_FILTERED 1
|
||||
#define Z_HUFFMAN_ONLY 2
|
||||
#define Z_RLE 3
|
||||
#define Z_FIXED 4
|
||||
#define Z_DEFAULT_STRATEGY 0
|
||||
/* compression strategy; see deflateInit2() below for details */
|
||||
|
||||
#define Z_BINARY 0
|
||||
#define Z_ASCII 1
|
||||
#define Z_TEXT 1
|
||||
#define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */
|
||||
#define Z_UNKNOWN 2
|
||||
/* Possible values of the data_type field (though see inflate()) */
|
||||
|
||||
@ -246,6 +269,10 @@ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
|
||||
and with zero avail_out, it must be called again after making room in the
|
||||
output buffer because there might be more output pending.
|
||||
|
||||
Normally the parameter flush is set to Z_NO_FLUSH, which allows deflate to
|
||||
decide how much data to accumualte before producing output, in order to
|
||||
maximize compression.
|
||||
|
||||
If the parameter flush is set to Z_SYNC_FLUSH, all pending output is
|
||||
flushed to the output buffer and the output is aligned on a byte boundary, so
|
||||
that the decompressor can get all input data available so far. (In particular
|
||||
@ -257,7 +284,7 @@ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
|
||||
Z_SYNC_FLUSH, and the compression state is reset so that decompression can
|
||||
restart from this point if previous compressed data has been damaged or if
|
||||
random access is desired. Using Z_FULL_FLUSH too often can seriously degrade
|
||||
the compression.
|
||||
compression.
|
||||
|
||||
If deflate returns with avail_out == 0, this function must be called again
|
||||
with the same value of the flush parameter and more output space (updated
|
||||
@ -282,8 +309,8 @@ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
|
||||
deflate() sets strm->adler to the adler32 checksum of all input read
|
||||
so far (that is, total_in bytes).
|
||||
|
||||
deflate() may update data_type if it can make a good guess about
|
||||
the input data type (Z_ASCII or Z_BINARY). In doubt, the data is considered
|
||||
deflate() may update strm->data_type if it can make a good guess about
|
||||
the input data type (Z_BINARY or Z_TEXT). In doubt, the data is considered
|
||||
binary. This field is only for information purposes and does not affect
|
||||
the compression algorithm in any manner.
|
||||
|
||||
@ -365,11 +392,11 @@ ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
|
||||
The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH,
|
||||
Z_FINISH, or Z_BLOCK. Z_SYNC_FLUSH requests that inflate() flush as much
|
||||
output as possible to the output buffer. Z_BLOCK requests that inflate() stop
|
||||
if and when it get to the next deflate block boundary. When decoding the zlib
|
||||
or gzip format, this will cause inflate() to return immediately after the
|
||||
header and before the first block. When doing a raw inflate, inflate() will
|
||||
go ahead and process the first block, and will return when it gets to the end
|
||||
of that block, or when it runs out of data.
|
||||
if and when it gets to the next deflate block boundary. When decoding the
|
||||
zlib or gzip format, this will cause inflate() to return immediately after
|
||||
the header and before the first block. When doing a raw inflate, inflate()
|
||||
will go ahead and process the first block, and will return when it gets to
|
||||
the end of that block, or when it runs out of data.
|
||||
|
||||
The Z_BLOCK option assists in appending to or combining deflate streams.
|
||||
Also to assist in this, on return inflate() will set strm->data_type to the
|
||||
@ -401,7 +428,7 @@ ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
|
||||
because Z_BLOCK is used.
|
||||
|
||||
If a preset dictionary is needed after this call (see inflateSetDictionary
|
||||
below), inflate sets strm-adler to the adler32 checksum of the dictionary
|
||||
below), inflate sets strm->adler to the adler32 checksum of the dictionary
|
||||
chosen by the compressor and returns Z_NEED_DICT; otherwise it sets
|
||||
strm->adler to the adler32 checksum of all output produced so far (that is,
|
||||
total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described
|
||||
@ -478,7 +505,8 @@ ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm,
|
||||
16 to windowBits to write a simple gzip header and trailer around the
|
||||
compressed data instead of a zlib wrapper. The gzip header will have no
|
||||
file name, no extra data, no comment, no modification time (set to zero),
|
||||
no header crc, and the operating system will be set to 255 (unknown).
|
||||
no header crc, and the operating system will be set to 255 (unknown). If a
|
||||
gzip stream is being written, strm->adler is a crc32 instead of an adler32.
|
||||
|
||||
The memLevel parameter specifies how much memory should be allocated
|
||||
for the internal compression state. memLevel=1 uses minimum memory but
|
||||
@ -497,7 +525,9 @@ ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm,
|
||||
Z_DEFAULT and Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as fast as
|
||||
Z_HUFFMAN_ONLY, but give better compression for PNG image data. The strategy
|
||||
parameter only affects the compression ratio but not the correctness of the
|
||||
compressed output even if it is not set appropriately.
|
||||
compressed output even if it is not set appropriately. Z_FIXED prevents the
|
||||
use of dynamic Huffman codes, allowing for a simpler decoder for special
|
||||
applications.
|
||||
|
||||
deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
|
||||
memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid
|
||||
@ -526,7 +556,9 @@ ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
|
||||
deflateInit or deflateInit2, a part of the dictionary may in effect be
|
||||
discarded, for example if the dictionary is larger than the window size in
|
||||
deflate or deflate2. Thus the strings most likely to be useful should be
|
||||
put at the end of the dictionary, not at the front.
|
||||
put at the end of the dictionary, not at the front. In addition, the
|
||||
current implementation of deflate will use at most the window size minus
|
||||
262 bytes of the provided dictionary.
|
||||
|
||||
Upon return of this function, strm->adler is set to the adler32 value
|
||||
of the dictionary; the decompressor may later use this value to determine
|
||||
@ -592,6 +624,23 @@ ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
|
||||
if strm->avail_out was zero.
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm,
|
||||
int good_length,
|
||||
int max_lazy,
|
||||
int nice_length,
|
||||
int max_chain));
|
||||
/*
|
||||
Fine tune deflate's internal compression parameters. This should only be
|
||||
used by someone who understands the algorithm used by zlib's deflate for
|
||||
searching for the best matching string, and even then only by the most
|
||||
fanatic optimizer trying to squeeze out the last compressed bit for their
|
||||
specific input data. Read the deflate.c source code for the meaning of the
|
||||
max_lazy, good_length, nice_length, and max_chain parameters.
|
||||
|
||||
deflateTune() can be called after deflateInit() or deflateInit2(), and
|
||||
returns Z_OK on success, or Z_STREAM_ERROR for an invalid deflate stream.
|
||||
*/
|
||||
|
||||
ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm,
|
||||
uLong sourceLen));
|
||||
/*
|
||||
@ -617,6 +666,30 @@ ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm,
|
||||
stream state was inconsistent.
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm,
|
||||
gz_headerp head));
|
||||
/*
|
||||
deflateSetHeader() provides gzip header information for when a gzip
|
||||
stream is requested by deflateInit2(). deflateSetHeader() may be called
|
||||
after deflateInit2() or deflateReset() and before the first call of
|
||||
deflate(). The text, time, os, extra field, name, and comment information
|
||||
in the provided gz_header structure are written to the gzip header (xflag is
|
||||
ignored -- the extra flags are set according to the compression level). The
|
||||
caller must assure that, if not Z_NULL, name and comment are terminated with
|
||||
a zero byte, and that if extra is not Z_NULL, that extra_len bytes are
|
||||
available there. If hcrc is true, a gzip header crc is included. Note that
|
||||
the current versions of the command-line version of gzip (up through version
|
||||
1.3.x) do not support header crc's, and will report that it is a "multi-part
|
||||
gzip file" and give up.
|
||||
|
||||
If deflateSetHeader is not used, the default gzip header has text false,
|
||||
the time set to zero, and os set to 255, with no extra, name, or comment
|
||||
fields. The gzip header is returned to the default state by deflateReset().
|
||||
|
||||
deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source
|
||||
stream state was inconsistent.
|
||||
*/
|
||||
|
||||
/*
|
||||
ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm,
|
||||
int windowBits));
|
||||
@ -649,14 +722,15 @@ ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm,
|
||||
windowBits can also be greater than 15 for optional gzip decoding. Add
|
||||
32 to windowBits to enable zlib and gzip decoding with automatic header
|
||||
detection, or add 16 to decode only the gzip format (the zlib format will
|
||||
return a Z_DATA_ERROR).
|
||||
return a Z_DATA_ERROR). If a gzip stream is being decoded, strm->adler is
|
||||
a crc32 instead of an adler32.
|
||||
|
||||
inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
|
||||
memory, Z_STREAM_ERROR if a parameter is invalid (such as a negative
|
||||
memLevel). msg is set to null if there is no error message. inflateInit2
|
||||
does not perform any decompression apart from reading the zlib header if
|
||||
present: this will be done by inflate(). (So next_in and avail_in may be
|
||||
modified, but next_out and avail_out are unchanged.)
|
||||
memory, Z_STREAM_ERROR if a parameter is invalid (such as a null strm). msg
|
||||
is set to null if there is no error message. inflateInit2 does not perform
|
||||
any decompression apart from reading the zlib header if present: this will
|
||||
be done by inflate(). (So next_in and avail_in may be modified, but next_out
|
||||
and avail_out are unchanged.)
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
|
||||
@ -664,11 +738,14 @@ ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
|
||||
uInt dictLength));
|
||||
/*
|
||||
Initializes the decompression dictionary from the given uncompressed byte
|
||||
sequence. This function must be called immediately after a call of inflate
|
||||
if this call returned Z_NEED_DICT. The dictionary chosen by the compressor
|
||||
can be determined from the adler32 value returned by this call of
|
||||
inflate. The compressor and decompressor must use exactly the same
|
||||
dictionary (see deflateSetDictionary).
|
||||
sequence. This function must be called immediately after a call of inflate,
|
||||
if that call returned Z_NEED_DICT. The dictionary chosen by the compressor
|
||||
can be determined from the adler32 value returned by that call of inflate.
|
||||
The compressor and decompressor must use exactly the same dictionary (see
|
||||
deflateSetDictionary). For raw inflate, this function can be called
|
||||
immediately after inflateInit2() or inflateReset() and before any call of
|
||||
inflate() to set the dictionary. The application must insure that the
|
||||
dictionary that was used for compression is provided.
|
||||
|
||||
inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a
|
||||
parameter is invalid (such as NULL dictionary) or the stream state is
|
||||
@ -719,8 +796,64 @@ ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
|
||||
stream state was inconsistent (such as zalloc or state being NULL).
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm,
|
||||
int bits,
|
||||
int value));
|
||||
/*
|
||||
ZEXTERN int ZEXPORT inflateBackInit OF((z_stream FAR *strm, int windowBits,
|
||||
This function inserts bits in the inflate input stream. The intent is
|
||||
that this function is used to start inflating at a bit position in the
|
||||
middle of a byte. The provided bits will be used before any bytes are used
|
||||
from next_in. This function should only be used with raw inflate, and
|
||||
should be used before the first inflate() call after inflateInit2() or
|
||||
inflateReset(). bits must be less than or equal to 16, and that many of the
|
||||
least significant bits of value will be inserted in the input.
|
||||
|
||||
inflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source
|
||||
stream state was inconsistent.
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm,
|
||||
gz_headerp head));
|
||||
/*
|
||||
inflateGetHeader() requests that gzip header information be stored in the
|
||||
provided gz_header structure. inflateGetHeader() may be called after
|
||||
inflateInit2() or inflateReset(), and before the first call of inflate().
|
||||
As inflate() processes the gzip stream, head->done is zero until the header
|
||||
is completed, at which time head->done is set to one. If a zlib stream is
|
||||
being decoded, then head->done is set to -1 to indicate that there will be
|
||||
no gzip header information forthcoming. Note that Z_BLOCK can be used to
|
||||
force inflate() to return immediately after header processing is complete
|
||||
and before any actual data is decompressed.
|
||||
|
||||
The text, time, xflags, and os fields are filled in with the gzip header
|
||||
contents. hcrc is set to true if there is a header CRC. (The header CRC
|
||||
was valid if done is set to one.) If extra is not Z_NULL, then extra_max
|
||||
contains the maximum number of bytes to write to extra. Once done is true,
|
||||
extra_len contains the actual extra field length, and extra contains the
|
||||
extra field, or that field truncated if extra_max is less than extra_len.
|
||||
If name is not Z_NULL, then up to name_max characters are written there,
|
||||
terminated with a zero unless the length is greater than name_max. If
|
||||
comment is not Z_NULL, then up to comm_max characters are written there,
|
||||
terminated with a zero unless the length is greater than comm_max. When
|
||||
any of extra, name, or comment are not Z_NULL and the respective field is
|
||||
not present in the header, then that field is set to Z_NULL to signal its
|
||||
absence. This allows the use of deflateSetHeader() with the returned
|
||||
structure to duplicate the header. However if those fields are set to
|
||||
allocated memory, then the application will need to save those pointers
|
||||
elsewhere so that they can be eventually freed.
|
||||
|
||||
If inflateGetHeader is not used, then the header information is simply
|
||||
discarded. The header is always checked for validity, including the header
|
||||
CRC if present. inflateReset() will reset the process to discard the header
|
||||
information. The application would need to call inflateGetHeader() again to
|
||||
retrieve the header from the next gzip stream.
|
||||
|
||||
inflateGetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source
|
||||
stream state was inconsistent.
|
||||
*/
|
||||
|
||||
/*
|
||||
ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits,
|
||||
unsigned char FAR *window));
|
||||
|
||||
Initialize the internal stream state for decompression using inflateBack()
|
||||
@ -744,7 +877,7 @@ ZEXTERN int ZEXPORT inflateBackInit OF((z_stream FAR *strm, int windowBits,
|
||||
typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *));
|
||||
typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned));
|
||||
|
||||
ZEXTERN int ZEXPORT inflateBack OF((z_stream FAR *strm,
|
||||
ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
|
||||
in_func in, void FAR *in_desc,
|
||||
out_func out, void FAR *out_desc));
|
||||
/*
|
||||
@ -813,7 +946,7 @@ ZEXTERN int ZEXPORT inflateBack OF((z_stream FAR *strm,
|
||||
that inflateBack() cannot return Z_OK.
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT inflateBackEnd OF((z_stream FAR *strm));
|
||||
ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm));
|
||||
/*
|
||||
All memory allocated by inflateBackInit() is freed.
|
||||
|
||||
@ -1087,6 +1220,12 @@ ZEXTERN int ZEXPORT gzeof OF((gzFile file));
|
||||
input stream, otherwise zero.
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT gzdirect OF((gzFile file));
|
||||
/*
|
||||
Returns 1 if file is being read directly without decompression, otherwise
|
||||
zero.
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT gzclose OF((gzFile file));
|
||||
/*
|
||||
Flushes all pending output if necessary, closes the compressed file
|
||||
@ -1119,7 +1258,6 @@ ZEXTERN void ZEXPORT gzclearerr OF((gzFile file));
|
||||
*/
|
||||
|
||||
ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
|
||||
|
||||
/*
|
||||
Update a running Adler-32 checksum with the bytes buf[0..len-1] and
|
||||
return the updated checksum. If buf is NULL, this function returns
|
||||
@ -1135,12 +1273,21 @@ ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
|
||||
if (adler != original_adler) error();
|
||||
*/
|
||||
|
||||
ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2,
|
||||
z_off_t len2));
|
||||
/*
|
||||
Combine two Adler-32 checksums into one. For two sequences of bytes, seq1
|
||||
and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for
|
||||
each, adler1 and adler2. adler32_combine() returns the Adler-32 checksum of
|
||||
seq1 and seq2 concatenated, requiring only adler1, adler2, and len2.
|
||||
*/
|
||||
|
||||
ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
|
||||
/*
|
||||
Update a running crc with the bytes buf[0..len-1] and return the updated
|
||||
crc. If buf is NULL, this function returns the required initial value
|
||||
for the crc. Pre- and post-conditioning (one's complement) is performed
|
||||
within this function so it shouldn't be done by the application.
|
||||
Update a running CRC-32 with the bytes buf[0..len-1] and return the
|
||||
updated CRC-32. If buf is NULL, this function returns the required initial
|
||||
value for the for the crc. Pre- and post-conditioning (one's complement) is
|
||||
performed within this function so it shouldn't be done by the application.
|
||||
Usage example:
|
||||
|
||||
uLong crc = crc32(0L, Z_NULL, 0);
|
||||
@ -1151,6 +1298,16 @@ ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
|
||||
if (crc != original_crc) error();
|
||||
*/
|
||||
|
||||
ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2));
|
||||
|
||||
/*
|
||||
Combine two CRC-32 check values into one. For two sequences of bytes,
|
||||
seq1 and seq2 with lengths len1 and len2, CRC-32 check values were
|
||||
calculated for each, crc1 and crc2. crc32_combine() returns the CRC-32
|
||||
check value of seq1 and seq2 concatenated, requiring only crc1, crc2, and
|
||||
len2.
|
||||
*/
|
||||
|
||||
|
||||
/* various hacks, don't look :) */
|
||||
|
||||
@ -1167,7 +1324,7 @@ ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method,
|
||||
int stream_size));
|
||||
ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits,
|
||||
const char *version, int stream_size));
|
||||
ZEXTERN int ZEXPORT inflateBackInit_ OF((z_stream FAR *strm, int windowBits,
|
||||
ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
|
||||
unsigned char FAR *window,
|
||||
const char *version,
|
||||
int stream_size));
|
||||
@ -1189,7 +1346,7 @@ ZEXTERN int ZEXPORT inflateBackInit_ OF((z_stream FAR *strm, int windowBits,
|
||||
struct internal_state {int dummy;}; /* hack for buggy compilers */
|
||||
#endif
|
||||
|
||||
ZEXTERN const char * ZEXPORT zError OF((int err));
|
||||
ZEXTERN const char * ZEXPORT zError OF((int));
|
||||
ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp z));
|
||||
ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void));
|
||||
|
||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user