mirror of
https://github.com/araxiaonline/TrinityCore2.git
synced 2026-06-18 22:09:40 -04:00
Replace tabs with spaces in more files.
--HG-- branch : trunk
This commit is contained in:
@@ -256,7 +256,7 @@ void LoadLocaleMPQFiles(int const locale)
|
||||
new MPQArchive(filename);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void LoadCommonMPQFiles()
|
||||
{
|
||||
char filename[512];
|
||||
@@ -291,7 +291,7 @@ int main(int argc, char * arg[])
|
||||
HandleArgs(argc, arg);
|
||||
|
||||
int FirstLocale = -1;
|
||||
|
||||
|
||||
for (int i = 0; i < LANG_COUNT; i++)
|
||||
{
|
||||
char tmp1[512];
|
||||
@@ -299,10 +299,10 @@ int main(int argc, char * arg[])
|
||||
if (FileExists(tmp1))
|
||||
{
|
||||
printf("Detected locale: %s\n", langs[i]);
|
||||
|
||||
|
||||
//Open MPQs
|
||||
LoadLocaleMPQFiles(i);
|
||||
|
||||
|
||||
if((extract & EXTRACT_DBC) == 0)
|
||||
{
|
||||
FirstLocale = i;
|
||||
@@ -328,15 +328,15 @@ int main(int argc, char * arg[])
|
||||
printf("No locales detected\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
if (extract & EXTRACT_MAP)
|
||||
{
|
||||
printf("Using locale: %s\n", langs[FirstLocale]);
|
||||
|
||||
|
||||
// Open MPQs
|
||||
LoadLocaleMPQFiles(FirstLocale);
|
||||
LoadCommonMPQFiles();
|
||||
|
||||
|
||||
// Extract maps
|
||||
ExtractMapsFromMpq();
|
||||
|
||||
|
||||
@@ -192,7 +192,7 @@ bool isHole(int holes, int i, int j)
|
||||
int testj = j/4;
|
||||
if(testi>3) testi = 3;
|
||||
if(testj>3) testj = 3;
|
||||
return (holes & holetab_h[testi] & holetab_v[testj])!=0;
|
||||
return (holes & holetab_h[testi] & holetab_v[testj])!=0;
|
||||
}
|
||||
|
||||
inline
|
||||
|
||||
+567
-567
File diff suppressed because it is too large
Load Diff
@@ -20,33 +20,33 @@
|
||||
* $Id: common.h,v 1.4 2004/02/12 00:41:55 mbroemme Exp $
|
||||
*/
|
||||
|
||||
#define LIBMPQ_CONF_FL_INCREMENT 512 /* i hope we did not need more :) */
|
||||
#define LIBMPQ_CONF_EXT ".conf" /* listdb file seems to be valid with this extension */
|
||||
#define LIBMPQ_CONF_HEADER "LIBMPQ_VERSION" /* listdb file must include this entry to be valid */
|
||||
#define LIBMPQ_CONF_BUFSIZE 4096 /* maximum number of bytes a line in the file could contain */
|
||||
#define LIBMPQ_CONF_FL_INCREMENT 512 /* i hope we did not need more :) */
|
||||
#define LIBMPQ_CONF_EXT ".conf" /* listdb file seems to be valid with this extension */
|
||||
#define LIBMPQ_CONF_HEADER "LIBMPQ_VERSION" /* listdb file must include this entry to be valid */
|
||||
#define LIBMPQ_CONF_BUFSIZE 4096 /* maximum number of bytes a line in the file could contain */
|
||||
|
||||
#define LIBMPQ_CONF_TYPE_CHAR 1 /* value in config file is from type char */
|
||||
#define LIBMPQ_CONF_TYPE_INT 2 /* value in config file is from type int */
|
||||
#define LIBMPQ_CONF_TYPE_CHAR 1 /* value in config file is from type char */
|
||||
#define LIBMPQ_CONF_TYPE_INT 2 /* value in config file is from type int */
|
||||
|
||||
#define LIBMPQ_CONF_EOPEN_DIR -1 /* error on open directory */
|
||||
#define LIBMPQ_CONF_EVALUE_NOT_FOUND -2 /* value for the option was not found */
|
||||
#define LIBMPQ_CONF_EOPEN_DIR -1 /* error on open directory */
|
||||
#define LIBMPQ_CONF_EVALUE_NOT_FOUND -2 /* value for the option was not found */
|
||||
|
||||
#if defined( __GNUC__ )
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define _lseek lseek
|
||||
#define _read read
|
||||
#define _open open
|
||||
#define _write write
|
||||
#define _close close
|
||||
#define _strdup strdup
|
||||
#define _lseek lseek
|
||||
#define _read read
|
||||
#define _open open
|
||||
#define _write write
|
||||
#define _close close
|
||||
#define _strdup strdup
|
||||
|
||||
#ifndef O_BINARY
|
||||
#define O_BINARY 0
|
||||
#endif
|
||||
#ifndef O_BINARY
|
||||
#define O_BINARY 0
|
||||
#endif
|
||||
#else
|
||||
#include <io.h>
|
||||
#include <io.h>
|
||||
#endif
|
||||
|
||||
#ifdef O_LARGEFILE
|
||||
@@ -56,7 +56,7 @@
|
||||
#endif
|
||||
|
||||
#ifndef min
|
||||
#define min(a, b) ((a < b) ? a : b)
|
||||
#define min(a, b) ((a < b) ? a : b)
|
||||
#endif
|
||||
|
||||
int libmpq_init_buffer(mpq_archive *mpq_a);
|
||||
|
||||
@@ -31,88 +31,88 @@
|
||||
|
||||
/* Tables */
|
||||
static unsigned char pkzip_dist_bits[] = {
|
||||
0x02, 0x04, 0x04, 0x05, 0x05, 0x05, 0x05, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
|
||||
0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
|
||||
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
|
||||
0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08
|
||||
0x02, 0x04, 0x04, 0x05, 0x05, 0x05, 0x05, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
|
||||
0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
|
||||
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
|
||||
0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08
|
||||
};
|
||||
|
||||
static unsigned char pkzip_dist_code[] = {
|
||||
0x03, 0x0D, 0x05, 0x19, 0x09, 0x11, 0x01, 0x3E, 0x1E, 0x2E, 0x0E, 0x36, 0x16, 0x26, 0x06, 0x3A,
|
||||
0x1A, 0x2A, 0x0A, 0x32, 0x12, 0x22, 0x42, 0x02, 0x7C, 0x3C, 0x5C, 0x1C, 0x6C, 0x2C, 0x4C, 0x0C,
|
||||
0x74, 0x34, 0x54, 0x14, 0x64, 0x24, 0x44, 0x04, 0x78, 0x38, 0x58, 0x18, 0x68, 0x28, 0x48, 0x08,
|
||||
0xF0, 0x70, 0xB0, 0x30, 0xD0, 0x50, 0x90, 0x10, 0xE0, 0x60, 0xA0, 0x20, 0xC0, 0x40, 0x80, 0x00
|
||||
0x03, 0x0D, 0x05, 0x19, 0x09, 0x11, 0x01, 0x3E, 0x1E, 0x2E, 0x0E, 0x36, 0x16, 0x26, 0x06, 0x3A,
|
||||
0x1A, 0x2A, 0x0A, 0x32, 0x12, 0x22, 0x42, 0x02, 0x7C, 0x3C, 0x5C, 0x1C, 0x6C, 0x2C, 0x4C, 0x0C,
|
||||
0x74, 0x34, 0x54, 0x14, 0x64, 0x24, 0x44, 0x04, 0x78, 0x38, 0x58, 0x18, 0x68, 0x28, 0x48, 0x08,
|
||||
0xF0, 0x70, 0xB0, 0x30, 0xD0, 0x50, 0x90, 0x10, 0xE0, 0x60, 0xA0, 0x20, 0xC0, 0x40, 0x80, 0x00
|
||||
};
|
||||
|
||||
static unsigned char pkzip_clen_bits[] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08
|
||||
};
|
||||
|
||||
static unsigned short pkzip_len_base[] = {
|
||||
0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007,
|
||||
0x0008, 0x000A, 0x000E, 0x0016, 0x0026, 0x0046, 0x0086, 0x0106
|
||||
0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007,
|
||||
0x0008, 0x000A, 0x000E, 0x0016, 0x0026, 0x0046, 0x0086, 0x0106
|
||||
};
|
||||
|
||||
static unsigned char pkzip_slen_bits[] = {
|
||||
0x03, 0x02, 0x03, 0x03, 0x04, 0x04, 0x04, 0x05, 0x05, 0x05, 0x05, 0x06, 0x06, 0x06, 0x07, 0x07
|
||||
0x03, 0x02, 0x03, 0x03, 0x04, 0x04, 0x04, 0x05, 0x05, 0x05, 0x05, 0x06, 0x06, 0x06, 0x07, 0x07
|
||||
};
|
||||
|
||||
static unsigned char pkzip_len_code[] = {
|
||||
0x05, 0x03, 0x01, 0x06, 0x0A, 0x02, 0x0C, 0x14, 0x04, 0x18, 0x08, 0x30, 0x10, 0x20, 0x40, 0x00
|
||||
0x05, 0x03, 0x01, 0x06, 0x0A, 0x02, 0x0C, 0x14, 0x04, 0x18, 0x08, 0x30, 0x10, 0x20, 0x40, 0x00
|
||||
};
|
||||
|
||||
static unsigned char pkzip_bits_asc[] = {
|
||||
0x0B, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x08, 0x07, 0x0C, 0x0C, 0x07, 0x0C, 0x0C,
|
||||
0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0D, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C,
|
||||
0x04, 0x0A, 0x08, 0x0C, 0x0A, 0x0C, 0x0A, 0x08, 0x07, 0x07, 0x08, 0x09, 0x07, 0x06, 0x07, 0x08,
|
||||
0x07, 0x06, 0x07, 0x07, 0x07, 0x07, 0x08, 0x07, 0x07, 0x08, 0x08, 0x0C, 0x0B, 0x07, 0x09, 0x0B,
|
||||
0x0C, 0x06, 0x07, 0x06, 0x06, 0x05, 0x07, 0x08, 0x08, 0x06, 0x0B, 0x09, 0x06, 0x07, 0x06, 0x06,
|
||||
0x07, 0x0B, 0x06, 0x06, 0x06, 0x07, 0x09, 0x08, 0x09, 0x09, 0x0B, 0x08, 0x0B, 0x09, 0x0C, 0x08,
|
||||
0x0C, 0x05, 0x06, 0x06, 0x06, 0x05, 0x06, 0x06, 0x06, 0x05, 0x0B, 0x07, 0x05, 0x06, 0x05, 0x05,
|
||||
0x06, 0x0A, 0x05, 0x05, 0x05, 0x05, 0x08, 0x07, 0x08, 0x08, 0x0A, 0x0B, 0x0B, 0x0C, 0x0C, 0x0C,
|
||||
0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D,
|
||||
0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D,
|
||||
0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D,
|
||||
0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C,
|
||||
0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C,
|
||||
0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C,
|
||||
0x0D, 0x0C, 0x0D, 0x0D, 0x0D, 0x0C, 0x0D, 0x0D, 0x0D, 0x0C, 0x0D, 0x0D, 0x0D, 0x0D, 0x0C, 0x0D,
|
||||
0x0D, 0x0D, 0x0C, 0x0C, 0x0C, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D
|
||||
0x0B, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x08, 0x07, 0x0C, 0x0C, 0x07, 0x0C, 0x0C,
|
||||
0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0D, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C,
|
||||
0x04, 0x0A, 0x08, 0x0C, 0x0A, 0x0C, 0x0A, 0x08, 0x07, 0x07, 0x08, 0x09, 0x07, 0x06, 0x07, 0x08,
|
||||
0x07, 0x06, 0x07, 0x07, 0x07, 0x07, 0x08, 0x07, 0x07, 0x08, 0x08, 0x0C, 0x0B, 0x07, 0x09, 0x0B,
|
||||
0x0C, 0x06, 0x07, 0x06, 0x06, 0x05, 0x07, 0x08, 0x08, 0x06, 0x0B, 0x09, 0x06, 0x07, 0x06, 0x06,
|
||||
0x07, 0x0B, 0x06, 0x06, 0x06, 0x07, 0x09, 0x08, 0x09, 0x09, 0x0B, 0x08, 0x0B, 0x09, 0x0C, 0x08,
|
||||
0x0C, 0x05, 0x06, 0x06, 0x06, 0x05, 0x06, 0x06, 0x06, 0x05, 0x0B, 0x07, 0x05, 0x06, 0x05, 0x05,
|
||||
0x06, 0x0A, 0x05, 0x05, 0x05, 0x05, 0x08, 0x07, 0x08, 0x08, 0x0A, 0x0B, 0x0B, 0x0C, 0x0C, 0x0C,
|
||||
0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D,
|
||||
0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D,
|
||||
0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D,
|
||||
0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C,
|
||||
0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C,
|
||||
0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C,
|
||||
0x0D, 0x0C, 0x0D, 0x0D, 0x0D, 0x0C, 0x0D, 0x0D, 0x0D, 0x0C, 0x0D, 0x0D, 0x0D, 0x0D, 0x0C, 0x0D,
|
||||
0x0D, 0x0D, 0x0C, 0x0C, 0x0C, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D
|
||||
};
|
||||
|
||||
static unsigned short pkzip_code_asc[] = {
|
||||
0x0490, 0x0FE0, 0x07E0, 0x0BE0, 0x03E0, 0x0DE0, 0x05E0, 0x09E0,
|
||||
0x01E0, 0x00B8, 0x0062, 0x0EE0, 0x06E0, 0x0022, 0x0AE0, 0x02E0,
|
||||
0x0CE0, 0x04E0, 0x08E0, 0x00E0, 0x0F60, 0x0760, 0x0B60, 0x0360,
|
||||
0x0D60, 0x0560, 0x1240, 0x0960, 0x0160, 0x0E60, 0x0660, 0x0A60,
|
||||
0x000F, 0x0250, 0x0038, 0x0260, 0x0050, 0x0C60, 0x0390, 0x00D8,
|
||||
0x0042, 0x0002, 0x0058, 0x01B0, 0x007C, 0x0029, 0x003C, 0x0098,
|
||||
0x005C, 0x0009, 0x001C, 0x006C, 0x002C, 0x004C, 0x0018, 0x000C,
|
||||
0x0074, 0x00E8, 0x0068, 0x0460, 0x0090, 0x0034, 0x00B0, 0x0710,
|
||||
0x0860, 0x0031, 0x0054, 0x0011, 0x0021, 0x0017, 0x0014, 0x00A8,
|
||||
0x0028, 0x0001, 0x0310, 0x0130, 0x003E, 0x0064, 0x001E, 0x002E,
|
||||
0x0024, 0x0510, 0x000E, 0x0036, 0x0016, 0x0044, 0x0030, 0x00C8,
|
||||
0x01D0, 0x00D0, 0x0110, 0x0048, 0x0610, 0x0150, 0x0060, 0x0088,
|
||||
0x0FA0, 0x0007, 0x0026, 0x0006, 0x003A, 0x001B, 0x001A, 0x002A,
|
||||
0x000A, 0x000B, 0x0210, 0x0004, 0x0013, 0x0032, 0x0003, 0x001D,
|
||||
0x0012, 0x0190, 0x000D, 0x0015, 0x0005, 0x0019, 0x0008, 0x0078,
|
||||
0x00F0, 0x0070, 0x0290, 0x0410, 0x0010, 0x07A0, 0x0BA0, 0x03A0,
|
||||
0x0240, 0x1C40, 0x0C40, 0x1440, 0x0440, 0x1840, 0x0840, 0x1040,
|
||||
0x0040, 0x1F80, 0x0F80, 0x1780, 0x0780, 0x1B80, 0x0B80, 0x1380,
|
||||
0x0380, 0x1D80, 0x0D80, 0x1580, 0x0580, 0x1980, 0x0980, 0x1180,
|
||||
0x0180, 0x1E80, 0x0E80, 0x1680, 0x0680, 0x1A80, 0x0A80, 0x1280,
|
||||
0x0280, 0x1C80, 0x0C80, 0x1480, 0x0480, 0x1880, 0x0880, 0x1080,
|
||||
0x0080, 0x1F00, 0x0F00, 0x1700, 0x0700, 0x1B00, 0x0B00, 0x1300,
|
||||
0x0DA0, 0x05A0, 0x09A0, 0x01A0, 0x0EA0, 0x06A0, 0x0AA0, 0x02A0,
|
||||
0x0CA0, 0x04A0, 0x08A0, 0x00A0, 0x0F20, 0x0720, 0x0B20, 0x0320,
|
||||
0x0D20, 0x0520, 0x0920, 0x0120, 0x0E20, 0x0620, 0x0A20, 0x0220,
|
||||
0x0C20, 0x0420, 0x0820, 0x0020, 0x0FC0, 0x07C0, 0x0BC0, 0x03C0,
|
||||
0x0DC0, 0x05C0, 0x09C0, 0x01C0, 0x0EC0, 0x06C0, 0x0AC0, 0x02C0,
|
||||
0x0CC0, 0x04C0, 0x08C0, 0x00C0, 0x0F40, 0x0740, 0x0B40, 0x0340,
|
||||
0x0300, 0x0D40, 0x1D00, 0x0D00, 0x1500, 0x0540, 0x0500, 0x1900,
|
||||
0x0900, 0x0940, 0x1100, 0x0100, 0x1E00, 0x0E00, 0x0140, 0x1600,
|
||||
0x0600, 0x1A00, 0x0E40, 0x0640, 0x0A40, 0x0A00, 0x1200, 0x0200,
|
||||
0x1C00, 0x0C00, 0x1400, 0x0400, 0x1800, 0x0800, 0x1000, 0x0000
|
||||
0x0490, 0x0FE0, 0x07E0, 0x0BE0, 0x03E0, 0x0DE0, 0x05E0, 0x09E0,
|
||||
0x01E0, 0x00B8, 0x0062, 0x0EE0, 0x06E0, 0x0022, 0x0AE0, 0x02E0,
|
||||
0x0CE0, 0x04E0, 0x08E0, 0x00E0, 0x0F60, 0x0760, 0x0B60, 0x0360,
|
||||
0x0D60, 0x0560, 0x1240, 0x0960, 0x0160, 0x0E60, 0x0660, 0x0A60,
|
||||
0x000F, 0x0250, 0x0038, 0x0260, 0x0050, 0x0C60, 0x0390, 0x00D8,
|
||||
0x0042, 0x0002, 0x0058, 0x01B0, 0x007C, 0x0029, 0x003C, 0x0098,
|
||||
0x005C, 0x0009, 0x001C, 0x006C, 0x002C, 0x004C, 0x0018, 0x000C,
|
||||
0x0074, 0x00E8, 0x0068, 0x0460, 0x0090, 0x0034, 0x00B0, 0x0710,
|
||||
0x0860, 0x0031, 0x0054, 0x0011, 0x0021, 0x0017, 0x0014, 0x00A8,
|
||||
0x0028, 0x0001, 0x0310, 0x0130, 0x003E, 0x0064, 0x001E, 0x002E,
|
||||
0x0024, 0x0510, 0x000E, 0x0036, 0x0016, 0x0044, 0x0030, 0x00C8,
|
||||
0x01D0, 0x00D0, 0x0110, 0x0048, 0x0610, 0x0150, 0x0060, 0x0088,
|
||||
0x0FA0, 0x0007, 0x0026, 0x0006, 0x003A, 0x001B, 0x001A, 0x002A,
|
||||
0x000A, 0x000B, 0x0210, 0x0004, 0x0013, 0x0032, 0x0003, 0x001D,
|
||||
0x0012, 0x0190, 0x000D, 0x0015, 0x0005, 0x0019, 0x0008, 0x0078,
|
||||
0x00F0, 0x0070, 0x0290, 0x0410, 0x0010, 0x07A0, 0x0BA0, 0x03A0,
|
||||
0x0240, 0x1C40, 0x0C40, 0x1440, 0x0440, 0x1840, 0x0840, 0x1040,
|
||||
0x0040, 0x1F80, 0x0F80, 0x1780, 0x0780, 0x1B80, 0x0B80, 0x1380,
|
||||
0x0380, 0x1D80, 0x0D80, 0x1580, 0x0580, 0x1980, 0x0980, 0x1180,
|
||||
0x0180, 0x1E80, 0x0E80, 0x1680, 0x0680, 0x1A80, 0x0A80, 0x1280,
|
||||
0x0280, 0x1C80, 0x0C80, 0x1480, 0x0480, 0x1880, 0x0880, 0x1080,
|
||||
0x0080, 0x1F00, 0x0F00, 0x1700, 0x0700, 0x1B00, 0x0B00, 0x1300,
|
||||
0x0DA0, 0x05A0, 0x09A0, 0x01A0, 0x0EA0, 0x06A0, 0x0AA0, 0x02A0,
|
||||
0x0CA0, 0x04A0, 0x08A0, 0x00A0, 0x0F20, 0x0720, 0x0B20, 0x0320,
|
||||
0x0D20, 0x0520, 0x0920, 0x0120, 0x0E20, 0x0620, 0x0A20, 0x0220,
|
||||
0x0C20, 0x0420, 0x0820, 0x0020, 0x0FC0, 0x07C0, 0x0BC0, 0x03C0,
|
||||
0x0DC0, 0x05C0, 0x09C0, 0x01C0, 0x0EC0, 0x06C0, 0x0AC0, 0x02C0,
|
||||
0x0CC0, 0x04C0, 0x08C0, 0x00C0, 0x0F40, 0x0740, 0x0B40, 0x0340,
|
||||
0x0300, 0x0D40, 0x1D00, 0x0D00, 0x1500, 0x0540, 0x0500, 0x1900,
|
||||
0x0900, 0x0940, 0x1100, 0x0100, 0x1E00, 0x0E00, 0x0140, 0x1600,
|
||||
0x0600, 0x1A00, 0x0E40, 0x0640, 0x0A40, 0x0A00, 0x1200, 0x0200,
|
||||
0x1C00, 0x0C00, 0x1400, 0x0400, 0x1800, 0x0800, 0x1000, 0x0000
|
||||
};
|
||||
|
||||
/* Local variables */
|
||||
@@ -124,68 +124,68 @@ static char copyright[] = "PKWARE Data Compression Library for Win32\r\n"
|
||||
|
||||
/* Local functions */
|
||||
static void libmpq_pkzip_gen_decode_tabs(long count, unsigned char *bits, unsigned char *code, unsigned char *buf2) {
|
||||
long i;
|
||||
long i;
|
||||
|
||||
for (i = count-1; i >= 0; i--) { /* EBX - count */
|
||||
unsigned long idx1 = code[i];
|
||||
unsigned long idx2 = 1 << bits[i];
|
||||
do {
|
||||
buf2[idx1] = (unsigned char)i;
|
||||
idx1 += idx2;
|
||||
} while (idx1 < 0x100);
|
||||
}
|
||||
for (i = count-1; i >= 0; i--) { /* EBX - count */
|
||||
unsigned long idx1 = code[i];
|
||||
unsigned long idx2 = 1 << bits[i];
|
||||
do {
|
||||
buf2[idx1] = (unsigned char)i;
|
||||
idx1 += idx2;
|
||||
} while (idx1 < 0x100);
|
||||
}
|
||||
}
|
||||
|
||||
static void libmpq_pkzip_gen_asc_tabs(pkzip_data_cmp *mpq_pkzip) {
|
||||
unsigned short *code_asc = &pkzip_code_asc[0xFF];
|
||||
unsigned long acc, add;
|
||||
unsigned short count;
|
||||
unsigned short *code_asc = &pkzip_code_asc[0xFF];
|
||||
unsigned long acc, add;
|
||||
unsigned short count;
|
||||
|
||||
for (count = 0x00FF; code_asc >= pkzip_code_asc; code_asc--, count--) {
|
||||
unsigned char *bits_asc = mpq_pkzip->bits_asc + count;
|
||||
unsigned char bits_tmp = *bits_asc;
|
||||
for (count = 0x00FF; code_asc >= pkzip_code_asc; code_asc--, count--) {
|
||||
unsigned char *bits_asc = mpq_pkzip->bits_asc + count;
|
||||
unsigned char bits_tmp = *bits_asc;
|
||||
|
||||
if (bits_tmp <= 8) {
|
||||
add = (1 << bits_tmp);
|
||||
acc = *code_asc;
|
||||
do {
|
||||
mpq_pkzip->offs_2c34[acc] = (unsigned char)count;
|
||||
acc += add;
|
||||
} while (acc < 0x100);
|
||||
} else {
|
||||
if ((acc = (*code_asc & 0xFF)) != 0) {
|
||||
mpq_pkzip->offs_2c34[acc] = 0xFF;
|
||||
if (*code_asc & 0x3F) {
|
||||
bits_tmp -= 4;
|
||||
*bits_asc = bits_tmp;
|
||||
add = (1 << bits_tmp);
|
||||
acc = *code_asc >> 4;
|
||||
do {
|
||||
mpq_pkzip->offs_2d34[acc] = (unsigned char)count;
|
||||
acc += add;
|
||||
} while (acc < 0x100);
|
||||
} else {
|
||||
bits_tmp -= 6;
|
||||
*bits_asc = bits_tmp;
|
||||
add = (1 << bits_tmp);
|
||||
acc = *code_asc >> 6;
|
||||
do {
|
||||
mpq_pkzip->offs_2e34[acc] = (unsigned char)count;
|
||||
acc += add;
|
||||
} while (acc < 0x80);
|
||||
}
|
||||
} else {
|
||||
bits_tmp -= 8;
|
||||
*bits_asc = bits_tmp;
|
||||
add = (1 << bits_tmp);
|
||||
acc = *code_asc >> 8;
|
||||
do {
|
||||
mpq_pkzip->offs_2eb4[acc] = (unsigned char)count;
|
||||
acc += add;
|
||||
} while (acc < 0x100);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (bits_tmp <= 8) {
|
||||
add = (1 << bits_tmp);
|
||||
acc = *code_asc;
|
||||
do {
|
||||
mpq_pkzip->offs_2c34[acc] = (unsigned char)count;
|
||||
acc += add;
|
||||
} while (acc < 0x100);
|
||||
} else {
|
||||
if ((acc = (*code_asc & 0xFF)) != 0) {
|
||||
mpq_pkzip->offs_2c34[acc] = 0xFF;
|
||||
if (*code_asc & 0x3F) {
|
||||
bits_tmp -= 4;
|
||||
*bits_asc = bits_tmp;
|
||||
add = (1 << bits_tmp);
|
||||
acc = *code_asc >> 4;
|
||||
do {
|
||||
mpq_pkzip->offs_2d34[acc] = (unsigned char)count;
|
||||
acc += add;
|
||||
} while (acc < 0x100);
|
||||
} else {
|
||||
bits_tmp -= 6;
|
||||
*bits_asc = bits_tmp;
|
||||
add = (1 << bits_tmp);
|
||||
acc = *code_asc >> 6;
|
||||
do {
|
||||
mpq_pkzip->offs_2e34[acc] = (unsigned char)count;
|
||||
acc += add;
|
||||
} while (acc < 0x80);
|
||||
}
|
||||
} else {
|
||||
bits_tmp -= 8;
|
||||
*bits_asc = bits_tmp;
|
||||
add = (1 << bits_tmp);
|
||||
acc = *code_asc >> 8;
|
||||
do {
|
||||
mpq_pkzip->offs_2eb4[acc] = (unsigned char)count;
|
||||
acc += add;
|
||||
} while (acc < 0x100);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -193,28 +193,28 @@ static void libmpq_pkzip_gen_asc_tabs(pkzip_data_cmp *mpq_pkzip) {
|
||||
* If no data in input buffer, returns true
|
||||
*/
|
||||
static int libmpq_pkzip_skip_bits(pkzip_data_cmp *mpq_pkzip, unsigned long bits) {
|
||||
/* If number of bits required is less than number of (bits in the buffer) ? */
|
||||
if (bits <= mpq_pkzip->extra_bits) {
|
||||
mpq_pkzip->extra_bits -= bits;
|
||||
mpq_pkzip->bit_buf >>= bits;
|
||||
return 0;
|
||||
}
|
||||
/* If number of bits required is less than number of (bits in the buffer) ? */
|
||||
if (bits <= mpq_pkzip->extra_bits) {
|
||||
mpq_pkzip->extra_bits -= bits;
|
||||
mpq_pkzip->bit_buf >>= bits;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Load input buffer if necessary */
|
||||
mpq_pkzip->bit_buf >>= mpq_pkzip->extra_bits;
|
||||
if (mpq_pkzip->in_pos == mpq_pkzip->in_bytes) {
|
||||
mpq_pkzip->in_pos = sizeof(mpq_pkzip->in_buf);
|
||||
if ((mpq_pkzip->in_bytes = mpq_pkzip->read_buf((char *)mpq_pkzip->in_buf, &mpq_pkzip->in_pos, mpq_pkzip->param)) == 0) {
|
||||
return 1;
|
||||
}
|
||||
mpq_pkzip->in_pos = 0;
|
||||
}
|
||||
/* Load input buffer if necessary */
|
||||
mpq_pkzip->bit_buf >>= mpq_pkzip->extra_bits;
|
||||
if (mpq_pkzip->in_pos == mpq_pkzip->in_bytes) {
|
||||
mpq_pkzip->in_pos = sizeof(mpq_pkzip->in_buf);
|
||||
if ((mpq_pkzip->in_bytes = mpq_pkzip->read_buf((char *)mpq_pkzip->in_buf, &mpq_pkzip->in_pos, mpq_pkzip->param)) == 0) {
|
||||
return 1;
|
||||
}
|
||||
mpq_pkzip->in_pos = 0;
|
||||
}
|
||||
|
||||
/* Update bit buffer */
|
||||
mpq_pkzip->bit_buf |= (mpq_pkzip->in_buf[mpq_pkzip->in_pos++] << 8);
|
||||
mpq_pkzip->bit_buf >>= (bits - mpq_pkzip->extra_bits);
|
||||
mpq_pkzip->extra_bits = (mpq_pkzip->extra_bits - bits) + 8;
|
||||
return 0;
|
||||
/* Update bit buffer */
|
||||
mpq_pkzip->bit_buf |= (mpq_pkzip->in_buf[mpq_pkzip->in_pos++] << 8);
|
||||
mpq_pkzip->bit_buf >>= (bits - mpq_pkzip->extra_bits);
|
||||
mpq_pkzip->extra_bits = (mpq_pkzip->extra_bits - bits) + 8;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -224,205 +224,205 @@ static int libmpq_pkzip_skip_bits(pkzip_data_cmp *mpq_pkzip, unsigned long bits)
|
||||
* 0x306 : Out of buffer (?)
|
||||
*/
|
||||
static unsigned long libmpq_pkzip_explode_lit(pkzip_data_cmp *mpq_pkzip) {
|
||||
unsigned long bits; /* Number of bits to skip */
|
||||
unsigned long value; /* Position in buffers */
|
||||
unsigned long bits; /* Number of bits to skip */
|
||||
unsigned long value; /* Position in buffers */
|
||||
|
||||
/* Test the current bit in byte buffer. If is not set, simply return the next byte. */
|
||||
if (mpq_pkzip->bit_buf & 1) {
|
||||
/* Test the current bit in byte buffer. If is not set, simply return the next byte. */
|
||||
if (mpq_pkzip->bit_buf & 1) {
|
||||
|
||||
/* Skip current bit in the buffer. */
|
||||
if (libmpq_pkzip_skip_bits(mpq_pkzip, 1)) {
|
||||
return 0x306;
|
||||
}
|
||||
/* Skip current bit in the buffer. */
|
||||
if (libmpq_pkzip_skip_bits(mpq_pkzip, 1)) {
|
||||
return 0x306;
|
||||
}
|
||||
|
||||
/* The next bits are position in buffers. */
|
||||
value = mpq_pkzip->pos2[(mpq_pkzip->bit_buf & 0xFF)];
|
||||
/* The next bits are position in buffers. */
|
||||
value = mpq_pkzip->pos2[(mpq_pkzip->bit_buf & 0xFF)];
|
||||
|
||||
/* Get number of bits to skip */
|
||||
if (libmpq_pkzip_skip_bits(mpq_pkzip, mpq_pkzip->slen_bits[value])) {
|
||||
return 0x306;
|
||||
}
|
||||
if ((bits = mpq_pkzip->clen_bits[value]) != 0) {
|
||||
unsigned long val2 = mpq_pkzip->bit_buf & ((1 << bits) - 1);
|
||||
if (libmpq_pkzip_skip_bits(mpq_pkzip, bits)) {
|
||||
if ((value + val2) != 0x10E) {
|
||||
return 0x306;
|
||||
}
|
||||
}
|
||||
value = mpq_pkzip->len_base[value] + val2;
|
||||
}
|
||||
return value + 0x100; /* Return number of bytes to repeat */
|
||||
}
|
||||
/* Get number of bits to skip */
|
||||
if (libmpq_pkzip_skip_bits(mpq_pkzip, mpq_pkzip->slen_bits[value])) {
|
||||
return 0x306;
|
||||
}
|
||||
if ((bits = mpq_pkzip->clen_bits[value]) != 0) {
|
||||
unsigned long val2 = mpq_pkzip->bit_buf & ((1 << bits) - 1);
|
||||
if (libmpq_pkzip_skip_bits(mpq_pkzip, bits)) {
|
||||
if ((value + val2) != 0x10E) {
|
||||
return 0x306;
|
||||
}
|
||||
}
|
||||
value = mpq_pkzip->len_base[value] + val2;
|
||||
}
|
||||
return value + 0x100; /* Return number of bytes to repeat */
|
||||
}
|
||||
|
||||
/* Skip one bit */
|
||||
if (libmpq_pkzip_skip_bits(mpq_pkzip, 1)) {
|
||||
return 0x306;
|
||||
}
|
||||
/* Skip one bit */
|
||||
if (libmpq_pkzip_skip_bits(mpq_pkzip, 1)) {
|
||||
return 0x306;
|
||||
}
|
||||
|
||||
/* If the binary compression type, read 8 bits and return them as one byte. */
|
||||
if (mpq_pkzip->cmp_type == LIBMPQ_PKZIP_CMP_BINARY) {
|
||||
value = mpq_pkzip->bit_buf & 0xFF;
|
||||
if (libmpq_pkzip_skip_bits(mpq_pkzip, 8)) {
|
||||
return 0x306;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
/* If the binary compression type, read 8 bits and return them as one byte. */
|
||||
if (mpq_pkzip->cmp_type == LIBMPQ_PKZIP_CMP_BINARY) {
|
||||
value = mpq_pkzip->bit_buf & 0xFF;
|
||||
if (libmpq_pkzip_skip_bits(mpq_pkzip, 8)) {
|
||||
return 0x306;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/* When ASCII compression ... */
|
||||
if (mpq_pkzip->bit_buf & 0xFF) {
|
||||
value = mpq_pkzip->offs_2c34[mpq_pkzip->bit_buf & 0xFF];
|
||||
if (value == 0xFF) {
|
||||
if (mpq_pkzip->bit_buf & 0x3F) {
|
||||
if (libmpq_pkzip_skip_bits(mpq_pkzip, 4)) {
|
||||
return 0x306;
|
||||
}
|
||||
value = mpq_pkzip->offs_2d34[mpq_pkzip->bit_buf & 0xFF];
|
||||
} else {
|
||||
if (libmpq_pkzip_skip_bits(mpq_pkzip, 6)) {
|
||||
return 0x306;
|
||||
}
|
||||
value = mpq_pkzip->offs_2e34[mpq_pkzip->bit_buf & 0x7F];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (libmpq_pkzip_skip_bits(mpq_pkzip, 8)) {
|
||||
return 0x306;
|
||||
}
|
||||
value = mpq_pkzip->offs_2eb4[mpq_pkzip->bit_buf & 0xFF];
|
||||
}
|
||||
return libmpq_pkzip_skip_bits(mpq_pkzip, mpq_pkzip->bits_asc[value]) ? 0x306 : value;
|
||||
/* When ASCII compression ... */
|
||||
if (mpq_pkzip->bit_buf & 0xFF) {
|
||||
value = mpq_pkzip->offs_2c34[mpq_pkzip->bit_buf & 0xFF];
|
||||
if (value == 0xFF) {
|
||||
if (mpq_pkzip->bit_buf & 0x3F) {
|
||||
if (libmpq_pkzip_skip_bits(mpq_pkzip, 4)) {
|
||||
return 0x306;
|
||||
}
|
||||
value = mpq_pkzip->offs_2d34[mpq_pkzip->bit_buf & 0xFF];
|
||||
} else {
|
||||
if (libmpq_pkzip_skip_bits(mpq_pkzip, 6)) {
|
||||
return 0x306;
|
||||
}
|
||||
value = mpq_pkzip->offs_2e34[mpq_pkzip->bit_buf & 0x7F];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (libmpq_pkzip_skip_bits(mpq_pkzip, 8)) {
|
||||
return 0x306;
|
||||
}
|
||||
value = mpq_pkzip->offs_2eb4[mpq_pkzip->bit_buf & 0xFF];
|
||||
}
|
||||
return libmpq_pkzip_skip_bits(mpq_pkzip, mpq_pkzip->bits_asc[value]) ? 0x306 : value;
|
||||
}
|
||||
|
||||
/*
|
||||
* Retrieves the number of bytes to move back.
|
||||
*/
|
||||
static unsigned long libmpq_pkzip_explode_dist(pkzip_data_cmp *mpq_pkzip, unsigned long length) {
|
||||
unsigned long pos = mpq_pkzip->pos1[(mpq_pkzip->bit_buf & 0xFF)];
|
||||
unsigned long skip = mpq_pkzip->dist_bits[pos]; /* Number of bits to skip */
|
||||
unsigned long pos = mpq_pkzip->pos1[(mpq_pkzip->bit_buf & 0xFF)];
|
||||
unsigned long skip = mpq_pkzip->dist_bits[pos]; /* Number of bits to skip */
|
||||
|
||||
/* Skip the appropriate number of bits */
|
||||
if (libmpq_pkzip_skip_bits(mpq_pkzip, skip) == 1) {
|
||||
return 0;
|
||||
}
|
||||
if (length == 2) {
|
||||
pos = (pos << 2) | (mpq_pkzip->bit_buf & 0x03);
|
||||
if (libmpq_pkzip_skip_bits(mpq_pkzip, 2) == 1) {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
pos = (pos << mpq_pkzip->dsize_bits) | (mpq_pkzip->bit_buf & mpq_pkzip->dsize_mask);
|
||||
/* Skip the appropriate number of bits */
|
||||
if (libmpq_pkzip_skip_bits(mpq_pkzip, skip) == 1) {
|
||||
return 0;
|
||||
}
|
||||
if (length == 2) {
|
||||
pos = (pos << 2) | (mpq_pkzip->bit_buf & 0x03);
|
||||
if (libmpq_pkzip_skip_bits(mpq_pkzip, 2) == 1) {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
pos = (pos << mpq_pkzip->dsize_bits) | (mpq_pkzip->bit_buf & mpq_pkzip->dsize_mask);
|
||||
|
||||
/* Skip the bits */
|
||||
if (libmpq_pkzip_skip_bits(mpq_pkzip, mpq_pkzip->dsize_bits) == 1) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return pos + 1;
|
||||
/* Skip the bits */
|
||||
if (libmpq_pkzip_skip_bits(mpq_pkzip, mpq_pkzip->dsize_bits) == 1) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return pos + 1;
|
||||
}
|
||||
|
||||
static unsigned long libmpq_pkzip_expand(pkzip_data_cmp *mpq_pkzip) {
|
||||
unsigned int copy_bytes; /* Number of bytes to copy */
|
||||
unsigned long one_byte; /* One byte from compressed file */
|
||||
unsigned long result;
|
||||
unsigned int copy_bytes; /* Number of bytes to copy */
|
||||
unsigned long one_byte; /* One byte from compressed file */
|
||||
unsigned long result;
|
||||
|
||||
mpq_pkzip->out_pos = 0x1000; /* Initialize output buffer position */
|
||||
mpq_pkzip->out_pos = 0x1000; /* Initialize output buffer position */
|
||||
|
||||
/* If end of data or error, terminate decompress */
|
||||
while ((result = one_byte = libmpq_pkzip_explode_lit(mpq_pkzip)) < 0x305) {
|
||||
/* If end of data or error, terminate decompress */
|
||||
while ((result = one_byte = libmpq_pkzip_explode_lit(mpq_pkzip)) < 0x305) {
|
||||
|
||||
/* If one byte is greater than 0x100, means "Repeat n - 0xFE bytes" */
|
||||
if (one_byte >= 0x100) {
|
||||
unsigned char *source; /* ECX */
|
||||
unsigned char *target; /* EDX */
|
||||
unsigned long copy_length = one_byte - 0xFE;
|
||||
unsigned long move_back;
|
||||
/* If one byte is greater than 0x100, means "Repeat n - 0xFE bytes" */
|
||||
if (one_byte >= 0x100) {
|
||||
unsigned char *source; /* ECX */
|
||||
unsigned char *target; /* EDX */
|
||||
unsigned long copy_length = one_byte - 0xFE;
|
||||
unsigned long move_back;
|
||||
|
||||
/* Get length of data to copy */
|
||||
if ((move_back = libmpq_pkzip_explode_dist(mpq_pkzip, copy_length)) == 0) {
|
||||
result = 0x306;
|
||||
break;
|
||||
}
|
||||
/* Get length of data to copy */
|
||||
if ((move_back = libmpq_pkzip_explode_dist(mpq_pkzip, copy_length)) == 0) {
|
||||
result = 0x306;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Target and source pointer */
|
||||
target = &mpq_pkzip->out_buf[mpq_pkzip->out_pos];
|
||||
source = target - move_back;
|
||||
mpq_pkzip->out_pos += copy_length;
|
||||
while (copy_length-- > 0) {
|
||||
*target++ = *source++;
|
||||
}
|
||||
} else {
|
||||
mpq_pkzip->out_buf[mpq_pkzip->out_pos++] = (unsigned char)one_byte;
|
||||
}
|
||||
/* Target and source pointer */
|
||||
target = &mpq_pkzip->out_buf[mpq_pkzip->out_pos];
|
||||
source = target - move_back;
|
||||
mpq_pkzip->out_pos += copy_length;
|
||||
while (copy_length-- > 0) {
|
||||
*target++ = *source++;
|
||||
}
|
||||
} else {
|
||||
mpq_pkzip->out_buf[mpq_pkzip->out_pos++] = (unsigned char)one_byte;
|
||||
}
|
||||
|
||||
/*
|
||||
* If number of extracted bytes has reached 1/2 of output buffer,
|
||||
* flush output buffer.
|
||||
*/
|
||||
if (mpq_pkzip->out_pos >= 0x2000) {
|
||||
/*
|
||||
* If number of extracted bytes has reached 1/2 of output buffer,
|
||||
* flush output buffer.
|
||||
*/
|
||||
if (mpq_pkzip->out_pos >= 0x2000) {
|
||||
|
||||
/* Copy decompressed data into user buffer. */
|
||||
copy_bytes = 0x1000;
|
||||
mpq_pkzip->write_buf((char *)&mpq_pkzip->out_buf[0x1000], ©_bytes, mpq_pkzip->param);
|
||||
/* Copy decompressed data into user buffer. */
|
||||
copy_bytes = 0x1000;
|
||||
mpq_pkzip->write_buf((char *)&mpq_pkzip->out_buf[0x1000], ©_bytes, mpq_pkzip->param);
|
||||
|
||||
/* If there are some data left, keep them alive */
|
||||
memcpy(mpq_pkzip->out_buf, &mpq_pkzip->out_buf[0x1000], mpq_pkzip->out_pos - 0x1000);
|
||||
mpq_pkzip->out_pos -= 0x1000;
|
||||
}
|
||||
}
|
||||
copy_bytes = mpq_pkzip->out_pos - 0x1000;
|
||||
mpq_pkzip->write_buf((char *)&mpq_pkzip->out_buf[0x1000], ©_bytes, mpq_pkzip->param);
|
||||
return result;
|
||||
/* If there are some data left, keep them alive */
|
||||
memcpy(mpq_pkzip->out_buf, &mpq_pkzip->out_buf[0x1000], mpq_pkzip->out_pos - 0x1000);
|
||||
mpq_pkzip->out_pos -= 0x1000;
|
||||
}
|
||||
}
|
||||
copy_bytes = mpq_pkzip->out_pos - 0x1000;
|
||||
mpq_pkzip->write_buf((char *)&mpq_pkzip->out_buf[0x1000], ©_bytes, mpq_pkzip->param);
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* Main exploding function.
|
||||
*/
|
||||
unsigned int libmpq_pkzip_explode(
|
||||
unsigned int (*read_buf)(char *buf, unsigned int *size, void *param),
|
||||
void (*write_buf)(char *buf, unsigned int *size, void *param),
|
||||
char *work_buf,
|
||||
void *param) {
|
||||
unsigned int (*read_buf)(char *buf, unsigned int *size, void *param),
|
||||
void (*write_buf)(char *buf, unsigned int *size, void *param),
|
||||
char *work_buf,
|
||||
void *param) {
|
||||
|
||||
pkzip_data_cmp *mpq_pkzip = (pkzip_data_cmp *)work_buf;
|
||||
pkzip_data_cmp *mpq_pkzip = (pkzip_data_cmp *)work_buf;
|
||||
|
||||
/* Set the whole work buffer to zeros */
|
||||
memset(mpq_pkzip, 0, sizeof(pkzip_data_cmp));
|
||||
/* Set the whole work buffer to zeros */
|
||||
memset(mpq_pkzip, 0, sizeof(pkzip_data_cmp));
|
||||
|
||||
/* Initialize work struct and load compressed data */
|
||||
mpq_pkzip->read_buf = read_buf;
|
||||
mpq_pkzip->write_buf = write_buf;
|
||||
mpq_pkzip->param = param;
|
||||
mpq_pkzip->in_pos = sizeof(mpq_pkzip->in_buf);
|
||||
mpq_pkzip->in_bytes = mpq_pkzip->read_buf((char *)mpq_pkzip->in_buf, &mpq_pkzip->in_pos, mpq_pkzip->param);
|
||||
if (mpq_pkzip->in_bytes <= 4) {
|
||||
return LIBMPQ_PKZIP_CMP_BAD_DATA;
|
||||
}
|
||||
mpq_pkzip->cmp_type = mpq_pkzip->in_buf[0]; /* Get the compression type */
|
||||
mpq_pkzip->dsize_bits = mpq_pkzip->in_buf[1]; /* Get the dictionary size */
|
||||
mpq_pkzip->bit_buf = mpq_pkzip->in_buf[2]; /* Initialize 16-bit bit buffer */
|
||||
mpq_pkzip->extra_bits = 0; /* Extra (over 8) bits */
|
||||
mpq_pkzip->in_pos = 3; /* Position in input buffer */
|
||||
/* Initialize work struct and load compressed data */
|
||||
mpq_pkzip->read_buf = read_buf;
|
||||
mpq_pkzip->write_buf = write_buf;
|
||||
mpq_pkzip->param = param;
|
||||
mpq_pkzip->in_pos = sizeof(mpq_pkzip->in_buf);
|
||||
mpq_pkzip->in_bytes = mpq_pkzip->read_buf((char *)mpq_pkzip->in_buf, &mpq_pkzip->in_pos, mpq_pkzip->param);
|
||||
if (mpq_pkzip->in_bytes <= 4) {
|
||||
return LIBMPQ_PKZIP_CMP_BAD_DATA;
|
||||
}
|
||||
mpq_pkzip->cmp_type = mpq_pkzip->in_buf[0]; /* Get the compression type */
|
||||
mpq_pkzip->dsize_bits = mpq_pkzip->in_buf[1]; /* Get the dictionary size */
|
||||
mpq_pkzip->bit_buf = mpq_pkzip->in_buf[2]; /* Initialize 16-bit bit buffer */
|
||||
mpq_pkzip->extra_bits = 0; /* Extra (over 8) bits */
|
||||
mpq_pkzip->in_pos = 3; /* Position in input buffer */
|
||||
|
||||
/* Test for the valid dictionary size */
|
||||
if (4 > mpq_pkzip->dsize_bits || mpq_pkzip->dsize_bits > 6) {
|
||||
return LIBMPQ_PKZIP_CMP_INV_DICTSIZE;
|
||||
}
|
||||
mpq_pkzip->dsize_mask = 0xFFFF >> (0x10 - mpq_pkzip->dsize_bits); /* Shifted by 'sar' instruction */
|
||||
if (mpq_pkzip->cmp_type != LIBMPQ_PKZIP_CMP_BINARY) {
|
||||
if (mpq_pkzip->cmp_type != LIBMPQ_PKZIP_CMP_ASCII) {
|
||||
return LIBMPQ_PKZIP_CMP_INV_MODE;
|
||||
}
|
||||
memcpy(mpq_pkzip->bits_asc, pkzip_bits_asc, sizeof(mpq_pkzip->bits_asc));
|
||||
libmpq_pkzip_gen_asc_tabs(mpq_pkzip);
|
||||
}
|
||||
memcpy(mpq_pkzip->slen_bits, pkzip_slen_bits, sizeof(mpq_pkzip->slen_bits));
|
||||
libmpq_pkzip_gen_decode_tabs(0x10, mpq_pkzip->slen_bits, pkzip_len_code, mpq_pkzip->pos2);
|
||||
memcpy(mpq_pkzip->clen_bits, pkzip_clen_bits, sizeof(mpq_pkzip->clen_bits));
|
||||
memcpy(mpq_pkzip->len_base, pkzip_len_base, sizeof(mpq_pkzip->len_base));
|
||||
memcpy(mpq_pkzip->dist_bits, pkzip_dist_bits, sizeof(mpq_pkzip->dist_bits));
|
||||
libmpq_pkzip_gen_decode_tabs(0x40, mpq_pkzip->dist_bits, pkzip_dist_code, mpq_pkzip->pos1);
|
||||
if (libmpq_pkzip_expand(mpq_pkzip) != 0x306) {
|
||||
return LIBMPQ_PKZIP_CMP_NO_ERROR;
|
||||
}
|
||||
return LIBMPQ_PKZIP_CMP_ABORT;
|
||||
/* Test for the valid dictionary size */
|
||||
if (4 > mpq_pkzip->dsize_bits || mpq_pkzip->dsize_bits > 6) {
|
||||
return LIBMPQ_PKZIP_CMP_INV_DICTSIZE;
|
||||
}
|
||||
mpq_pkzip->dsize_mask = 0xFFFF >> (0x10 - mpq_pkzip->dsize_bits); /* Shifted by 'sar' instruction */
|
||||
if (mpq_pkzip->cmp_type != LIBMPQ_PKZIP_CMP_BINARY) {
|
||||
if (mpq_pkzip->cmp_type != LIBMPQ_PKZIP_CMP_ASCII) {
|
||||
return LIBMPQ_PKZIP_CMP_INV_MODE;
|
||||
}
|
||||
memcpy(mpq_pkzip->bits_asc, pkzip_bits_asc, sizeof(mpq_pkzip->bits_asc));
|
||||
libmpq_pkzip_gen_asc_tabs(mpq_pkzip);
|
||||
}
|
||||
memcpy(mpq_pkzip->slen_bits, pkzip_slen_bits, sizeof(mpq_pkzip->slen_bits));
|
||||
libmpq_pkzip_gen_decode_tabs(0x10, mpq_pkzip->slen_bits, pkzip_len_code, mpq_pkzip->pos2);
|
||||
memcpy(mpq_pkzip->clen_bits, pkzip_clen_bits, sizeof(mpq_pkzip->clen_bits));
|
||||
memcpy(mpq_pkzip->len_base, pkzip_len_base, sizeof(mpq_pkzip->len_base));
|
||||
memcpy(mpq_pkzip->dist_bits, pkzip_dist_bits, sizeof(mpq_pkzip->dist_bits));
|
||||
libmpq_pkzip_gen_decode_tabs(0x40, mpq_pkzip->dist_bits, pkzip_dist_code, mpq_pkzip->pos1);
|
||||
if (libmpq_pkzip_expand(mpq_pkzip) != 0x306) {
|
||||
return LIBMPQ_PKZIP_CMP_NO_ERROR;
|
||||
}
|
||||
return LIBMPQ_PKZIP_CMP_ABORT;
|
||||
}
|
||||
|
||||
@@ -27,60 +27,60 @@
|
||||
#ifndef _EXPLODE_H
|
||||
#define _EXPLODE_H
|
||||
|
||||
#define LIBMPQ_PKZIP_EXP_BUFFER_SIZE 12596 /* Size of decompress buffer */
|
||||
#define LIBMPQ_PKZIP_CMP_BINARY 0 /* Binary compression */
|
||||
#define LIBMPQ_PKZIP_CMP_ASCII 1 /* Ascii compression */
|
||||
#define LIBMPQ_PKZIP_CMP_NO_ERROR 0
|
||||
#define LIBMPQ_PKZIP_CMP_INV_DICTSIZE 1
|
||||
#define LIBMPQ_PKZIP_CMP_INV_MODE 2
|
||||
#define LIBMPQ_PKZIP_CMP_BAD_DATA 3
|
||||
#define LIBMPQ_PKZIP_CMP_ABORT 4
|
||||
#define LIBMPQ_PKZIP_EXP_BUFFER_SIZE 12596 /* Size of decompress buffer */
|
||||
#define LIBMPQ_PKZIP_CMP_BINARY 0 /* Binary compression */
|
||||
#define LIBMPQ_PKZIP_CMP_ASCII 1 /* Ascii compression */
|
||||
#define LIBMPQ_PKZIP_CMP_NO_ERROR 0
|
||||
#define LIBMPQ_PKZIP_CMP_INV_DICTSIZE 1
|
||||
#define LIBMPQ_PKZIP_CMP_INV_MODE 2
|
||||
#define LIBMPQ_PKZIP_CMP_BAD_DATA 3
|
||||
#define LIBMPQ_PKZIP_CMP_ABORT 4
|
||||
|
||||
/* Compression structure (size: 12596 bytes on x86-32) */
|
||||
typedef struct {
|
||||
unsigned long offs0000; /* 0000 */
|
||||
unsigned long cmp_type; /* 0004 - Compression type (LIBMPQ_PZIP_CMP_BINARY or LIBMPQ_PKZIP_CMP_ASCII) */
|
||||
unsigned long out_pos; /* 0008 - Position in output buffer */
|
||||
unsigned long dsize_bits; /* 000C - Dict size (4, 5, 6 for 0x400, 0x800, 0x1000) */
|
||||
unsigned long dsize_mask; /* 0010 - Dict size bitmask (0x0F, 0x1F, 0x3F for 0x400, 0x800, 0x1000) */
|
||||
unsigned long bit_buf; /* 0014 - 16-bit buffer for processing input data */
|
||||
unsigned long extra_bits; /* 0018 - Number of extra (above 8) bits in bit buffer */
|
||||
unsigned int in_pos; /* 001C - Position in in_buf */
|
||||
unsigned long in_bytes; /* 0020 - Number of bytes in input buffer */
|
||||
void *param; /* 0024 - Custom parameter */
|
||||
unsigned int (*read_buf)(char *buf, unsigned int *size, void *param); /* 0028 */
|
||||
void (*write_buf)(char *buf, unsigned int *size, void *param); /* 002C */
|
||||
unsigned char out_buf[0x2000]; /* 0030 - Output circle buffer. Starting position is 0x1000 */
|
||||
unsigned char offs_2030[0x204]; /* 2030 - ??? */
|
||||
unsigned char in_buf[0x800]; /* 2234 - Buffer for data to be decompressed */
|
||||
unsigned char pos1[0x100]; /* 2A34 - Positions in buffers */
|
||||
unsigned char pos2[0x100]; /* 2B34 - Positions in buffers */
|
||||
unsigned char offs_2c34[0x100]; /* 2C34 - Buffer for */
|
||||
unsigned char offs_2d34[0x100]; /* 2D34 - Buffer for */
|
||||
unsigned char offs_2e34[0x80]; /* 2EB4 - Buffer for */
|
||||
unsigned char offs_2eb4[0x100]; /* 2EB4 - Buffer for */
|
||||
unsigned char bits_asc[0x100]; /* 2FB4 - Buffer for */
|
||||
unsigned char dist_bits[0x40]; /* 30B4 - Numbers of bytes to skip copied block length */
|
||||
unsigned char slen_bits[0x10]; /* 30F4 - Numbers of bits for skip copied block length */
|
||||
unsigned char clen_bits[0x10]; /* 3104 - Number of valid bits for copied block */
|
||||
unsigned short len_base[0x10]; /* 3114 - Buffer for */
|
||||
unsigned long offs0000; /* 0000 */
|
||||
unsigned long cmp_type; /* 0004 - Compression type (LIBMPQ_PZIP_CMP_BINARY or LIBMPQ_PKZIP_CMP_ASCII) */
|
||||
unsigned long out_pos; /* 0008 - Position in output buffer */
|
||||
unsigned long dsize_bits; /* 000C - Dict size (4, 5, 6 for 0x400, 0x800, 0x1000) */
|
||||
unsigned long dsize_mask; /* 0010 - Dict size bitmask (0x0F, 0x1F, 0x3F for 0x400, 0x800, 0x1000) */
|
||||
unsigned long bit_buf; /* 0014 - 16-bit buffer for processing input data */
|
||||
unsigned long extra_bits; /* 0018 - Number of extra (above 8) bits in bit buffer */
|
||||
unsigned int in_pos; /* 001C - Position in in_buf */
|
||||
unsigned long in_bytes; /* 0020 - Number of bytes in input buffer */
|
||||
void *param; /* 0024 - Custom parameter */
|
||||
unsigned int (*read_buf)(char *buf, unsigned int *size, void *param); /* 0028 */
|
||||
void (*write_buf)(char *buf, unsigned int *size, void *param); /* 002C */
|
||||
unsigned char out_buf[0x2000]; /* 0030 - Output circle buffer. Starting position is 0x1000 */
|
||||
unsigned char offs_2030[0x204]; /* 2030 - ??? */
|
||||
unsigned char in_buf[0x800]; /* 2234 - Buffer for data to be decompressed */
|
||||
unsigned char pos1[0x100]; /* 2A34 - Positions in buffers */
|
||||
unsigned char pos2[0x100]; /* 2B34 - Positions in buffers */
|
||||
unsigned char offs_2c34[0x100]; /* 2C34 - Buffer for */
|
||||
unsigned char offs_2d34[0x100]; /* 2D34 - Buffer for */
|
||||
unsigned char offs_2e34[0x80]; /* 2EB4 - Buffer for */
|
||||
unsigned char offs_2eb4[0x100]; /* 2EB4 - Buffer for */
|
||||
unsigned char bits_asc[0x100]; /* 2FB4 - Buffer for */
|
||||
unsigned char dist_bits[0x40]; /* 30B4 - Numbers of bytes to skip copied block length */
|
||||
unsigned char slen_bits[0x10]; /* 30F4 - Numbers of bits for skip copied block length */
|
||||
unsigned char clen_bits[0x10]; /* 3104 - Number of valid bits for copied block */
|
||||
unsigned short len_base[0x10]; /* 3114 - Buffer for */
|
||||
} pkzip_data_cmp;
|
||||
// __attribute__ ((packed)) pkzip_data_cmp;
|
||||
|
||||
typedef struct {
|
||||
char *in_buf; /* Pointer to input data buffer */
|
||||
unsigned int in_pos; /* Current offset in input data buffer */
|
||||
int in_bytes; /* Number of bytes in the input buffer */
|
||||
char *out_buf; /* Pointer to output data buffer */
|
||||
unsigned int out_pos; /* Position in the output buffer */
|
||||
int max_out; /* Maximum number of bytes in the output buffer */
|
||||
char *in_buf; /* Pointer to input data buffer */
|
||||
unsigned int in_pos; /* Current offset in input data buffer */
|
||||
int in_bytes; /* Number of bytes in the input buffer */
|
||||
char *out_buf; /* Pointer to output data buffer */
|
||||
unsigned int out_pos; /* Position in the output buffer */
|
||||
int max_out; /* Maximum number of bytes in the output buffer */
|
||||
} pkzip_data;
|
||||
|
||||
extern unsigned int libmpq_pkzip_explode(
|
||||
unsigned int (*read_buf)(char *buf, unsigned int *size, void *param),
|
||||
void (*write_buf)(char *buf, unsigned int *size, void *param),
|
||||
char *work_buf,
|
||||
void *param
|
||||
unsigned int (*read_buf)(char *buf, unsigned int *size, void *param),
|
||||
void (*write_buf)(char *buf, unsigned int *size, void *param),
|
||||
char *work_buf,
|
||||
void *param
|
||||
);
|
||||
|
||||
#endif /* _EXPLODE_H */
|
||||
#endif /* _EXPLODE_H */
|
||||
|
||||
@@ -50,20 +50,20 @@
|
||||
* void * param - Custom pointer, parameter of implode/explode
|
||||
*/
|
||||
static unsigned int libmpq_pkzip_read_input_data(char *buf, unsigned int *size, void *param) {
|
||||
pkzip_data *info = (pkzip_data *)param;
|
||||
unsigned int max_avail = (info->in_bytes - info->in_pos);
|
||||
unsigned int to_read = *size;
|
||||
pkzip_data *info = (pkzip_data *)param;
|
||||
unsigned int max_avail = (info->in_bytes - info->in_pos);
|
||||
unsigned int to_read = *size;
|
||||
|
||||
/* Check the case when not enough data available */
|
||||
if (to_read > max_avail) {
|
||||
to_read = max_avail;
|
||||
}
|
||||
/* Check the case when not enough data available */
|
||||
if (to_read > max_avail) {
|
||||
to_read = max_avail;
|
||||
}
|
||||
|
||||
/* Load data and increment offsets */
|
||||
memcpy(buf, info->in_buf + info->in_pos, to_read);
|
||||
info->in_pos += to_read;
|
||||
/* Load data and increment offsets */
|
||||
memcpy(buf, info->in_buf + info->in_pos, to_read);
|
||||
info->in_pos += to_read;
|
||||
|
||||
return to_read;
|
||||
return to_read;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -77,76 +77,76 @@ static unsigned int libmpq_pkzip_read_input_data(char *buf, unsigned int *size,
|
||||
* void * param - Custom pointer, parameter of implode/explode
|
||||
*/
|
||||
static void libmpq_pkzip_write_output_data(char *buf, unsigned int *size, void *param) {
|
||||
pkzip_data *info = (pkzip_data *)param;
|
||||
unsigned int max_write = (info->max_out - info->out_pos);
|
||||
unsigned int to_write = *size;
|
||||
pkzip_data *info = (pkzip_data *)param;
|
||||
unsigned int max_write = (info->max_out - info->out_pos);
|
||||
unsigned int to_write = *size;
|
||||
|
||||
/* Check the case when not enough space in the output buffer */
|
||||
if (to_write > max_write) {
|
||||
to_write = max_write;
|
||||
}
|
||||
/* Check the case when not enough space in the output buffer */
|
||||
if (to_write > max_write) {
|
||||
to_write = max_write;
|
||||
}
|
||||
|
||||
/* Write output data and increments offsets */
|
||||
memcpy(info->out_buf + info->out_pos, buf, to_write);
|
||||
info->out_pos += to_write;
|
||||
/* Write output data and increments offsets */
|
||||
memcpy(info->out_buf + info->out_pos, buf, to_write);
|
||||
info->out_pos += to_write;
|
||||
}
|
||||
|
||||
int libmpq_pkzip_decompress(char *out_buf, int *out_length, char *in_buf, int in_length) {
|
||||
pkzip_data info; /* Data information */
|
||||
char *work_buf = (char *)malloc(LIBMPQ_PKZIP_EXP_BUFFER_SIZE); /* mpq_pkzip work buffer */
|
||||
pkzip_data info; /* Data information */
|
||||
char *work_buf = (char *)malloc(LIBMPQ_PKZIP_EXP_BUFFER_SIZE); /* mpq_pkzip work buffer */
|
||||
|
||||
/* Fill data information structure */
|
||||
info.in_buf = in_buf;
|
||||
info.in_pos = 0;
|
||||
info.in_bytes = in_length;
|
||||
info.out_buf = out_buf;
|
||||
info.out_pos = 0;
|
||||
info.max_out = *out_length;
|
||||
/* Fill data information structure */
|
||||
info.in_buf = in_buf;
|
||||
info.in_pos = 0;
|
||||
info.in_bytes = in_length;
|
||||
info.out_buf = out_buf;
|
||||
info.out_pos = 0;
|
||||
info.max_out = *out_length;
|
||||
|
||||
/* Do the decompression */
|
||||
libmpq_pkzip_explode(libmpq_pkzip_read_input_data, libmpq_pkzip_write_output_data, work_buf, &info);
|
||||
*out_length = info.out_pos;
|
||||
free(work_buf);
|
||||
return 0;
|
||||
/* Do the decompression */
|
||||
libmpq_pkzip_explode(libmpq_pkzip_read_input_data, libmpq_pkzip_write_output_data, work_buf, &info);
|
||||
*out_length = info.out_pos;
|
||||
free(work_buf);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int libmpq_wave_decompress_mono(char *out_buf, int *out_length, char *in_buf, int in_length) {
|
||||
*out_length = libmpq_wave_decompress((unsigned char *)out_buf, *out_length, (unsigned char *)in_buf, in_length, 1);
|
||||
return 1;
|
||||
*out_length = libmpq_wave_decompress((unsigned char *)out_buf, *out_length, (unsigned char *)in_buf, in_length, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int libmpq_wave_decompress_stereo(char *out_buf, int *out_length, char *in_buf, int in_length) {
|
||||
*out_length = libmpq_wave_decompress((unsigned char *)out_buf, *out_length, (unsigned char *)in_buf, in_length, 2);
|
||||
return 1;
|
||||
*out_length = libmpq_wave_decompress((unsigned char *)out_buf, *out_length, (unsigned char *)in_buf, in_length, 2);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int libmpq_zlib_decompress(char *out_buf, int *out_length, char *in_buf, int in_length) {
|
||||
#ifdef HAVE_LIBZ
|
||||
z_stream z; /* Stream information for zlib */
|
||||
int result;
|
||||
z_stream z; /* Stream information for zlib */
|
||||
int result;
|
||||
|
||||
/* Fill the stream structure for zlib */
|
||||
z.next_in = (Bytef *)in_buf;
|
||||
z.avail_in = (uInt)in_length;
|
||||
z.total_in = in_length;
|
||||
z.next_out = (Bytef *)out_buf;
|
||||
z.avail_out = *out_length;
|
||||
z.total_out = 0;
|
||||
z.zalloc = NULL;
|
||||
z.zfree = NULL;
|
||||
/* Fill the stream structure for zlib */
|
||||
z.next_in = (Bytef *)in_buf;
|
||||
z.avail_in = (uInt)in_length;
|
||||
z.total_in = in_length;
|
||||
z.next_out = (Bytef *)out_buf;
|
||||
z.avail_out = *out_length;
|
||||
z.total_out = 0;
|
||||
z.zalloc = NULL;
|
||||
z.zfree = NULL;
|
||||
|
||||
/* Initialize the decompression structure. Storm.dll uses zlib version 1.1.3 */
|
||||
if ((result = inflateInit(&z)) == 0) {
|
||||
/* Initialize the decompression structure. Storm.dll uses zlib version 1.1.3 */
|
||||
if ((result = inflateInit(&z)) == 0) {
|
||||
|
||||
/* Call zlib to decompress the data */
|
||||
result = inflate(&z, Z_FINISH);
|
||||
*out_length = z.total_out;
|
||||
inflateEnd(&z);
|
||||
}
|
||||
return result;
|
||||
/* Call zlib to decompress the data */
|
||||
result = inflate(&z, Z_FINISH);
|
||||
*out_length = z.total_out;
|
||||
inflateEnd(&z);
|
||||
}
|
||||
return result;
|
||||
#else
|
||||
memset(out_buf, '0', *out_length);
|
||||
return 0;
|
||||
memset(out_buf, '0', *out_length);
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -157,106 +157,106 @@ int libmpq_zlib_decompress(char *out_buf, int *out_length, char *in_buf, int in_
|
||||
* 1500F5F0
|
||||
*/
|
||||
int libmpq_huff_decompress(char *out_buf, int *out_length, char *in_buf, int in_length) {
|
||||
struct huffman_tree *ht = (huffman_tree *)malloc(sizeof(struct huffman_tree));
|
||||
struct huffman_input_stream *is = (huffman_input_stream *)malloc(sizeof(struct huffman_input_stream));
|
||||
struct huffman_tree_item *hi = (huffman_tree_item *)malloc(sizeof(struct huffman_tree_item));
|
||||
memset(ht, 0, sizeof(struct huffman_tree));
|
||||
memset(is, 0, sizeof(struct huffman_input_stream));
|
||||
memset(hi, 0, sizeof(struct huffman_tree_item));
|
||||
struct huffman_tree *ht = (huffman_tree *)malloc(sizeof(struct huffman_tree));
|
||||
struct huffman_input_stream *is = (huffman_input_stream *)malloc(sizeof(struct huffman_input_stream));
|
||||
struct huffman_tree_item *hi = (huffman_tree_item *)malloc(sizeof(struct huffman_tree_item));
|
||||
memset(ht, 0, sizeof(struct huffman_tree));
|
||||
memset(is, 0, sizeof(struct huffman_input_stream));
|
||||
memset(hi, 0, sizeof(struct huffman_tree_item));
|
||||
|
||||
/* Initialize input stream */
|
||||
is->bit_buf = *(unsigned long *)in_buf;
|
||||
in_buf += sizeof(unsigned long);
|
||||
is->in_buf = (unsigned char *)in_buf;
|
||||
is->bits = 32;
|
||||
/* Initialize input stream */
|
||||
is->bit_buf = *(unsigned long *)in_buf;
|
||||
in_buf += sizeof(unsigned long);
|
||||
is->in_buf = (unsigned char *)in_buf;
|
||||
is->bits = 32;
|
||||
|
||||
/* Initialize the Huffmann tree for decompression */
|
||||
libmpq_huff_init_tree(ht, hi, LIBMPQ_HUFF_DECOMPRESS);
|
||||
/* Initialize the Huffmann tree for decompression */
|
||||
libmpq_huff_init_tree(ht, hi, LIBMPQ_HUFF_DECOMPRESS);
|
||||
|
||||
*out_length = libmpq_huff_do_decompress(ht, is, (unsigned char *)out_buf, *out_length);
|
||||
*out_length = libmpq_huff_do_decompress(ht, is, (unsigned char *)out_buf, *out_length);
|
||||
|
||||
free(hi);
|
||||
free(is);
|
||||
free(ht);
|
||||
return 0;
|
||||
free(hi);
|
||||
free(is);
|
||||
free(ht);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int libmpq_multi_decompress(char *out_buf, int *pout_length, char *in_buf, int in_length) {
|
||||
char *temp_buf = NULL; /* Temporary storage for decompressed data */
|
||||
char *work_buf = NULL; /* Where to store decompressed data */
|
||||
int out_length = *pout_length; /* For storage number of output bytes */
|
||||
unsigned fDecompressions1; /* Decompressions applied to the block */
|
||||
unsigned fDecompressions2; /* Just another copy of decompressions applied to the block */
|
||||
int count = 0; /* Counter for every use */
|
||||
int entries = (sizeof(dcmp_table) / sizeof(decompress_table));
|
||||
int i;
|
||||
char *temp_buf = NULL; /* Temporary storage for decompressed data */
|
||||
char *work_buf = NULL; /* Where to store decompressed data */
|
||||
int out_length = *pout_length; /* For storage number of output bytes */
|
||||
unsigned fDecompressions1; /* Decompressions applied to the block */
|
||||
unsigned fDecompressions2; /* Just another copy of decompressions applied to the block */
|
||||
int count = 0; /* Counter for every use */
|
||||
int entries = (sizeof(dcmp_table) / sizeof(decompress_table));
|
||||
int i;
|
||||
|
||||
/* If the input length is the same as output, do nothing. */
|
||||
if (in_length == out_length) {
|
||||
if (in_buf == out_buf) {
|
||||
return 1;
|
||||
}
|
||||
memcpy(out_buf, in_buf, in_length);
|
||||
return 1;
|
||||
}
|
||||
/* If the input length is the same as output, do nothing. */
|
||||
if (in_length == out_length) {
|
||||
if (in_buf == out_buf) {
|
||||
return 1;
|
||||
}
|
||||
memcpy(out_buf, in_buf, in_length);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Get applied compression types and decrement data length */
|
||||
fDecompressions1 = fDecompressions2 = (unsigned char)*in_buf++;
|
||||
in_length--;
|
||||
/* Get applied compression types and decrement data length */
|
||||
fDecompressions1 = fDecompressions2 = (unsigned char)*in_buf++;
|
||||
in_length--;
|
||||
|
||||
/* Search decompression table type and get all types of compression */
|
||||
for (i = 0; i < entries; i++) {
|
||||
/* We have to apply this decompression? */
|
||||
if (fDecompressions1 & dcmp_table[i].mask) {
|
||||
count++;
|
||||
}
|
||||
/* Search decompression table type and get all types of compression */
|
||||
for (i = 0; i < entries; i++) {
|
||||
/* We have to apply this decompression? */
|
||||
if (fDecompressions1 & dcmp_table[i].mask) {
|
||||
count++;
|
||||
}
|
||||
|
||||
/* Clear this flag from temporary variable. */
|
||||
fDecompressions2 &= ~dcmp_table[i].mask;
|
||||
}
|
||||
/* Clear this flag from temporary variable. */
|
||||
fDecompressions2 &= ~dcmp_table[i].mask;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check if there is some method unhandled
|
||||
* (E.g. compressed by future versions)
|
||||
*/
|
||||
if (fDecompressions2 != 0) {
|
||||
printf("Unknown Compression\n");
|
||||
return 0;
|
||||
}
|
||||
/*
|
||||
* Check if there is some method unhandled
|
||||
* (E.g. compressed by future versions)
|
||||
*/
|
||||
if (fDecompressions2 != 0) {
|
||||
printf("Unknown Compression\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* If there is more than only one compression, we have to allocate extra buffer */
|
||||
if (count >= 2) {
|
||||
temp_buf = (char *)malloc(out_length);
|
||||
}
|
||||
/* If there is more than only one compression, we have to allocate extra buffer */
|
||||
if (count >= 2) {
|
||||
temp_buf = (char *)malloc(out_length);
|
||||
}
|
||||
|
||||
/* Apply all decompressions */
|
||||
for (i = 0, count = 0; i < entries; i++) {
|
||||
/* Apply all decompressions */
|
||||
for (i = 0, count = 0; i < entries; i++) {
|
||||
|
||||
/* If not used this kind of compression, skip the loop */
|
||||
if (fDecompressions1 & dcmp_table[i].mask) {
|
||||
/* If not used this kind of compression, skip the loop */
|
||||
if (fDecompressions1 & dcmp_table[i].mask) {
|
||||
|
||||
/* If odd case, use target buffer for output, otherwise use allocated tempbuf */
|
||||
work_buf = (count++ & 1) ? temp_buf : out_buf;
|
||||
out_length = *pout_length;
|
||||
/* If odd case, use target buffer for output, otherwise use allocated tempbuf */
|
||||
work_buf = (count++ & 1) ? temp_buf : out_buf;
|
||||
out_length = *pout_length;
|
||||
|
||||
/* Decompress buffer using corresponding function */
|
||||
dcmp_table[i].decompress(work_buf, &out_length, in_buf, in_length);
|
||||
/* Decompress buffer using corresponding function */
|
||||
dcmp_table[i].decompress(work_buf, &out_length, in_buf, in_length);
|
||||
|
||||
/* Move output length to src length for next compression */
|
||||
in_length = out_length;
|
||||
in_buf = work_buf;
|
||||
}
|
||||
}
|
||||
/* Move output length to src length for next compression */
|
||||
in_length = out_length;
|
||||
in_buf = work_buf;
|
||||
}
|
||||
}
|
||||
|
||||
/* If output buffer is not the same like target buffer, we have to copy data */
|
||||
if (work_buf != out_buf) {
|
||||
memcpy(out_buf, in_buf, out_length);
|
||||
}
|
||||
*pout_length = out_length;
|
||||
/* If output buffer is not the same like target buffer, we have to copy data */
|
||||
if (work_buf != out_buf) {
|
||||
memcpy(out_buf, in_buf, out_length);
|
||||
}
|
||||
*pout_length = out_length;
|
||||
|
||||
/* Delete temporary buffer, if necessary */
|
||||
if (temp_buf != NULL) {
|
||||
free(temp_buf);
|
||||
}
|
||||
return 1;
|
||||
/* Delete temporary buffer, if necessary */
|
||||
if (temp_buf != NULL) {
|
||||
free(temp_buf);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -27,32 +27,32 @@
|
||||
#ifndef _HUFFMAN_H
|
||||
#define _HUFFMAN_H
|
||||
|
||||
#define PTR_NOT(ptr) (struct huffman_tree_item *)(~(unsigned long)(ptr))
|
||||
#define PTR_PTR(ptr) ((struct huffman_tree_item *)(ptr))
|
||||
#define PTR_INT(ptr) (long)(ptr)
|
||||
#define PTR_NOT(ptr) (struct huffman_tree_item *)(~(unsigned long)(ptr))
|
||||
#define PTR_PTR(ptr) ((struct huffman_tree_item *)(ptr))
|
||||
#define PTR_INT(ptr) (long)(ptr)
|
||||
|
||||
#define INSERT_ITEM 1
|
||||
#define SWITCH_ITEMS 2 /* Switch the item1 and item2 */
|
||||
#define INSERT_ITEM 1
|
||||
#define SWITCH_ITEMS 2 /* Switch the item1 and item2 */
|
||||
|
||||
/*
|
||||
* Input stream for Huffmann decompression
|
||||
*/
|
||||
struct huffman_input_stream {
|
||||
unsigned char *in_buf; /* 00 - Input data */
|
||||
unsigned long bit_buf; /* 04 - Input bit buffer */
|
||||
unsigned int bits; /* 08 - Number of bits remaining in 'byte' */
|
||||
unsigned char *in_buf; /* 00 - Input data */
|
||||
unsigned long bit_buf; /* 04 - Input bit buffer */
|
||||
unsigned int bits; /* 08 - Number of bits remaining in 'byte' */
|
||||
};
|
||||
|
||||
/*
|
||||
* Huffmann tree item.
|
||||
*/
|
||||
struct huffman_tree_item {
|
||||
struct huffman_tree_item *next; /* 00 - Pointer to next huffman_tree_item */
|
||||
struct huffman_tree_item *prev; /* 04 - Pointer to prev huffman_tree_item (< 0 if none) */
|
||||
unsigned long dcmp_byte; /* 08 - Index of this item in item pointer array, decompressed byte value */
|
||||
unsigned long byte_value; /* 0C - Some byte value */
|
||||
struct huffman_tree_item *parent; /* 10 - Pointer to parent huffman_tree_item (NULL if none) */
|
||||
struct huffman_tree_item *child; /* 14 - Pointer to child huffman_tree_item */
|
||||
struct huffman_tree_item *next; /* 00 - Pointer to next huffman_tree_item */
|
||||
struct huffman_tree_item *prev; /* 04 - Pointer to prev huffman_tree_item (< 0 if none) */
|
||||
unsigned long dcmp_byte; /* 08 - Index of this item in item pointer array, decompressed byte value */
|
||||
unsigned long byte_value; /* 0C - Some byte value */
|
||||
struct huffman_tree_item *parent; /* 10 - Pointer to parent huffman_tree_item (NULL if none) */
|
||||
struct huffman_tree_item *child; /* 14 - Pointer to child huffman_tree_item */
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -66,40 +66,40 @@ struct huffman_tree_item {
|
||||
* directly stores output byte to output stream.
|
||||
*/
|
||||
struct huffman_decompress {
|
||||
unsigned long offs00; /* 00 - 1 if resolved */
|
||||
unsigned long bits; /* 04 - Bit count */
|
||||
union {
|
||||
unsigned long dcmp_byte; /* 08 - Byte value for decompress (if bitCount <= 7) */
|
||||
struct huffman_tree_item *p_item; /* 08 - THTreeItem (if number of bits is greater than 7 */
|
||||
};
|
||||
unsigned long offs00; /* 00 - 1 if resolved */
|
||||
unsigned long bits; /* 04 - Bit count */
|
||||
union {
|
||||
unsigned long dcmp_byte; /* 08 - Byte value for decompress (if bitCount <= 7) */
|
||||
struct huffman_tree_item *p_item; /* 08 - THTreeItem (if number of bits is greater than 7 */
|
||||
};
|
||||
};
|
||||
|
||||
/*
|
||||
* Structure for Huffman tree.
|
||||
*/
|
||||
struct huffman_tree {
|
||||
unsigned long cmp0; /* 0000 - 1 if compression type 0 */
|
||||
unsigned long offs0004; /* 0004 - Some flag */
|
||||
unsigned long cmp0; /* 0000 - 1 if compression type 0 */
|
||||
unsigned long offs0004; /* 0004 - Some flag */
|
||||
|
||||
struct huffman_tree_item items0008[0x203]; /* 0008 - huffman tree items */
|
||||
struct huffman_tree_item items0008[0x203]; /* 0008 - huffman tree items */
|
||||
|
||||
/* Sometimes used as huffman tree item */
|
||||
struct huffman_tree_item *item3050; /* 3050 - Always NULL (?) */
|
||||
struct huffman_tree_item *item3054; /* 3054 - Pointer to huffman_tree_item */
|
||||
struct huffman_tree_item *item3058; /* 3058 - Pointer to huffman_tree_item (< 0 if invalid) */
|
||||
/* Sometimes used as huffman tree item */
|
||||
struct huffman_tree_item *item3050; /* 3050 - Always NULL (?) */
|
||||
struct huffman_tree_item *item3054; /* 3054 - Pointer to huffman_tree_item */
|
||||
struct huffman_tree_item *item3058; /* 3058 - Pointer to huffman_tree_item (< 0 if invalid) */
|
||||
|
||||
/* Sometimes used as huffman tree item */
|
||||
struct huffman_tree_item *item305C; /* 305C - Usually NULL */
|
||||
struct huffman_tree_item *first; /* 3060 - Pointer to top (first) Huffman tree item */
|
||||
struct huffman_tree_item *last; /* 3064 - Pointer to bottom (last) Huffman tree item (< 0 if invalid) */
|
||||
unsigned long items; /* 3068 - Number of used huffman tree items */
|
||||
/* Sometimes used as huffman tree item */
|
||||
struct huffman_tree_item *item305C; /* 305C - Usually NULL */
|
||||
struct huffman_tree_item *first; /* 3060 - Pointer to top (first) Huffman tree item */
|
||||
struct huffman_tree_item *last; /* 3064 - Pointer to bottom (last) Huffman tree item (< 0 if invalid) */
|
||||
unsigned long items; /* 3068 - Number of used huffman tree items */
|
||||
|
||||
struct huffman_tree_item *items306C[0x102]; /* 306C - huffman_tree_item pointer array */
|
||||
struct huffman_decompress qd3474[0x80]; /* 3474 - Array for quick decompression */
|
||||
struct huffman_tree_item *items306C[0x102]; /* 306C - huffman_tree_item pointer array */
|
||||
struct huffman_decompress qd3474[0x80]; /* 3474 - Array for quick decompression */
|
||||
|
||||
//unsigned char table1502A630[]; /* Some table to make struct size flexible */
|
||||
//unsigned char table1502A630[]; /* Some table to make struct size flexible */
|
||||
};
|
||||
|
||||
int libmpq_huff_init_tree(struct huffman_tree *ht, struct huffman_tree_item *hi, unsigned int cmp);
|
||||
int libmpq_huff_do_decompress(struct huffman_tree *ht, struct huffman_input_stream *is, unsigned char *out_buf, unsigned int out_length);
|
||||
#endif /* _HUFFMAN_H */
|
||||
#endif /* _HUFFMAN_H */
|
||||
|
||||
+422
-422
@@ -36,9 +36,9 @@
|
||||
* format: MAJOR.MINOR.PATCH
|
||||
*/
|
||||
char *libmpq_version() {
|
||||
static char version[10];
|
||||
sprintf(version, "%i.%i.%i", LIBMPQ_MAJOR_VERSION, LIBMPQ_MINOR_VERSION, LIBMPQ_PATCH_VERSION);
|
||||
return version;
|
||||
static char version[10];
|
||||
sprintf(version, "%i.%i.%i", LIBMPQ_MAJOR_VERSION, LIBMPQ_MINOR_VERSION, LIBMPQ_PATCH_VERSION);
|
||||
return version;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -47,94 +47,94 @@ char *libmpq_version() {
|
||||
* table.
|
||||
*/
|
||||
int libmpq_archive_open(mpq_archive *mpq_a, unsigned char *mpq_filename) {
|
||||
int fd = 0;
|
||||
int rb = 0;
|
||||
int ncnt = FALSE;
|
||||
struct stat fileinfo;
|
||||
int fd = 0;
|
||||
int rb = 0;
|
||||
int ncnt = FALSE;
|
||||
struct stat fileinfo;
|
||||
|
||||
/* allocate memory */
|
||||
mpq_a->mpq_l = (mpq_list *)malloc(sizeof(mpq_list));
|
||||
memset(mpq_a->mpq_l, 0, sizeof(mpq_list));
|
||||
mpq_a->header = (mpq_header *)malloc(sizeof(mpq_header));
|
||||
memset(mpq_a->header, 0, sizeof(mpq_header));
|
||||
/* allocate memory */
|
||||
mpq_a->mpq_l = (mpq_list *)malloc(sizeof(mpq_list));
|
||||
memset(mpq_a->mpq_l, 0, sizeof(mpq_list));
|
||||
mpq_a->header = (mpq_header *)malloc(sizeof(mpq_header));
|
||||
memset(mpq_a->header, 0, sizeof(mpq_header));
|
||||
|
||||
/* Check if file exists and is readable */
|
||||
fd = _open((char *)mpq_filename, MPQ_FILE_OPEN_FLAGS);
|
||||
if (fd == LIBMPQ_EFILE) {
|
||||
return LIBMPQ_EFILE;
|
||||
}
|
||||
/* Check if file exists and is readable */
|
||||
fd = _open((char *)mpq_filename, MPQ_FILE_OPEN_FLAGS);
|
||||
if (fd == LIBMPQ_EFILE) {
|
||||
return LIBMPQ_EFILE;
|
||||
}
|
||||
|
||||
/* fill the structures with informations */
|
||||
strcpy((char *)mpq_a->filename, (char *)mpq_filename);
|
||||
libmpq_init_buffer(mpq_a);
|
||||
mpq_a->fd = fd;
|
||||
mpq_a->header->id = 0;
|
||||
mpq_a->maxblockindex = 0;
|
||||
mpq_a->mpq_l->mpq_files = NULL;
|
||||
/* fill the structures with informations */
|
||||
strcpy((char *)mpq_a->filename, (char *)mpq_filename);
|
||||
libmpq_init_buffer(mpq_a);
|
||||
mpq_a->fd = fd;
|
||||
mpq_a->header->id = 0;
|
||||
mpq_a->maxblockindex = 0;
|
||||
mpq_a->mpq_l->mpq_files = NULL;
|
||||
|
||||
mpq_a->mpqpos = 0; //k
|
||||
|
||||
while (!ncnt) {
|
||||
mpq_a->header->id = 0;
|
||||
#ifdef WIN32
|
||||
_lseeki64(mpq_a->fd, mpq_a->mpqpos, SEEK_SET);
|
||||
#else
|
||||
lseek64(mpq_a->fd, mpq_a->mpqpos, SEEK_SET);
|
||||
#endif
|
||||
rb = _read(mpq_a->fd, mpq_a->header, sizeof(mpq_header));
|
||||
while (!ncnt) {
|
||||
mpq_a->header->id = 0;
|
||||
#ifdef WIN32
|
||||
_lseeki64(mpq_a->fd, mpq_a->mpqpos, SEEK_SET);
|
||||
#else
|
||||
lseek64(mpq_a->fd, mpq_a->mpqpos, SEEK_SET);
|
||||
#endif
|
||||
rb = _read(mpq_a->fd, mpq_a->header, sizeof(mpq_header));
|
||||
|
||||
/* if different number of bytes read, break the loop */
|
||||
if (rb != sizeof(mpq_header)) {
|
||||
return LIBMPQ_EFILE_FORMAT;
|
||||
}
|
||||
/* if different number of bytes read, break the loop */
|
||||
if (rb != sizeof(mpq_header)) {
|
||||
return LIBMPQ_EFILE_FORMAT;
|
||||
}
|
||||
|
||||
/* special offset for protected MPQs */
|
||||
if (mpq_a->header->offset == LIBMPQ_HEADER_W3M) {
|
||||
mpq_a->flags |= LIBMPQ_FLAG_PROTECTED;
|
||||
mpq_a->header->offset = sizeof(mpq_header);
|
||||
}
|
||||
/* special offset for protected MPQs */
|
||||
if (mpq_a->header->offset == LIBMPQ_HEADER_W3M) {
|
||||
mpq_a->flags |= LIBMPQ_FLAG_PROTECTED;
|
||||
mpq_a->header->offset = sizeof(mpq_header);
|
||||
}
|
||||
|
||||
/* if valid signature has been found, break the loop */
|
||||
/* if valid signature has been found, break the loop */
|
||||
if (mpq_a->header->id == LIBMPQ_ID_MPQ) {
|
||||
ncnt = true;
|
||||
}
|
||||
/*if (mpq_a->header->id == LIBMPQ_ID_MPQ &&
|
||||
mpq_a->header->offset == sizeof(mpq_header) &&
|
||||
mpq_a->header->hashtablepos < mpq_a->header->archivesize &&
|
||||
mpq_a->header->blocktablepos < mpq_a->header->archivesize) {
|
||||
ncnt = TRUE;
|
||||
}*/
|
||||
mpq_a->header->offset == sizeof(mpq_header) &&
|
||||
mpq_a->header->hashtablepos < mpq_a->header->archivesize &&
|
||||
mpq_a->header->blocktablepos < mpq_a->header->archivesize) {
|
||||
ncnt = TRUE;
|
||||
}*/
|
||||
|
||||
/* move to the next possible offset */
|
||||
if (!ncnt) {
|
||||
mpq_a->mpqpos += 0x200;
|
||||
}
|
||||
}
|
||||
/* move to the next possible offset */
|
||||
if (!ncnt) {
|
||||
mpq_a->mpqpos += 0x200;
|
||||
}
|
||||
}
|
||||
|
||||
/* get the right positions of the hash table and the block table. */
|
||||
mpq_a->blocksize = (0x200 << mpq_a->header->blocksize);
|
||||
fstat(mpq_a->fd, &fileinfo);
|
||||
/* get the right positions of the hash table and the block table. */
|
||||
mpq_a->blocksize = (0x200 << mpq_a->header->blocksize);
|
||||
fstat(mpq_a->fd, &fileinfo);
|
||||
|
||||
/* Normal MPQs must have position of */
|
||||
/*if (mpq_a->header->hashtablepos + mpq_a->mpqpos < fileinfo.st_size &&
|
||||
mpq_a->header->blocktablepos + mpq_a->mpqpos < fileinfo.st_size) {
|
||||
mpq_a->header->hashtablepos += mpq_a->mpqpos;
|
||||
mpq_a->header->blocktablepos += mpq_a->mpqpos;
|
||||
} else {
|
||||
return LIBMPQ_EFILE_FORMAT;
|
||||
}*/
|
||||
/* Normal MPQs must have position of */
|
||||
/*if (mpq_a->header->hashtablepos + mpq_a->mpqpos < fileinfo.st_size &&
|
||||
mpq_a->header->blocktablepos + mpq_a->mpqpos < fileinfo.st_size) {
|
||||
mpq_a->header->hashtablepos += mpq_a->mpqpos;
|
||||
mpq_a->header->blocktablepos += mpq_a->mpqpos;
|
||||
} else {
|
||||
return LIBMPQ_EFILE_FORMAT;
|
||||
}*/
|
||||
|
||||
/* Try to read and decrypt the hashtable */
|
||||
if (libmpq_read_hashtable(mpq_a) != 0) {
|
||||
return LIBMPQ_EHASHTABLE;
|
||||
}
|
||||
/* Try to read and decrypt the hashtable */
|
||||
if (libmpq_read_hashtable(mpq_a) != 0) {
|
||||
return LIBMPQ_EHASHTABLE;
|
||||
}
|
||||
|
||||
/* Try to read and decrypt the blocktable */
|
||||
if (libmpq_read_blocktable(mpq_a) != 0) {
|
||||
return LIBMPQ_EBLOCKTABLE;
|
||||
}
|
||||
/* Try to read and decrypt the blocktable */
|
||||
if (libmpq_read_blocktable(mpq_a) != 0) {
|
||||
return LIBMPQ_EBLOCKTABLE;
|
||||
}
|
||||
|
||||
return LIBMPQ_TOOLS_SUCCESS;
|
||||
return LIBMPQ_TOOLS_SUCCESS;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -142,18 +142,18 @@ int libmpq_archive_open(mpq_archive *mpq_a, unsigned char *mpq_filename) {
|
||||
* mpq_open_archive(); and frees the decryption buffer.
|
||||
*/
|
||||
int libmpq_archive_close(mpq_archive *mpq_a) {
|
||||
memset(mpq_a->buf, 0, sizeof(mpq_a->buf));
|
||||
memset(mpq_a->buf, 0, sizeof(mpq_a->buf));
|
||||
|
||||
/* free the allocated memory. */
|
||||
free(mpq_a->header);
|
||||
free(mpq_a->mpq_l);
|
||||
/* free the allocated memory. */
|
||||
free(mpq_a->header);
|
||||
free(mpq_a->mpq_l);
|
||||
|
||||
/* Check if file descriptor is valid. */
|
||||
if ((_close(mpq_a->fd)) == LIBMPQ_EFILE) {
|
||||
return LIBMPQ_EFILE;
|
||||
}
|
||||
/* Check if file descriptor is valid. */
|
||||
if ((_close(mpq_a->fd)) == LIBMPQ_EFILE) {
|
||||
return LIBMPQ_EFILE;
|
||||
}
|
||||
|
||||
return LIBMPQ_TOOLS_SUCCESS;
|
||||
return LIBMPQ_TOOLS_SUCCESS;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -161,95 +161,95 @@ int libmpq_archive_close(mpq_archive *mpq_a) {
|
||||
* If an error occurs something < 0 is returned.
|
||||
*/
|
||||
int libmpq_archive_info(mpq_archive *mpq_a, unsigned int infotype) {
|
||||
unsigned int filecount = 0;
|
||||
unsigned int fsize = 0;
|
||||
unsigned int csize = 0;
|
||||
mpq_block *mpq_b_end = mpq_a->blocktable + mpq_a->header->blocktablesize;
|
||||
mpq_block *mpq_b = NULL;
|
||||
unsigned int filecount = 0;
|
||||
unsigned int fsize = 0;
|
||||
unsigned int csize = 0;
|
||||
mpq_block *mpq_b_end = mpq_a->blocktable + mpq_a->header->blocktablesize;
|
||||
mpq_block *mpq_b = NULL;
|
||||
|
||||
switch (infotype) {
|
||||
case LIBMPQ_MPQ_ARCHIVE_SIZE:
|
||||
return mpq_a->header->archivesize;
|
||||
case LIBMPQ_MPQ_HASHTABLE_SIZE:
|
||||
return mpq_a->header->hashtablesize;
|
||||
case LIBMPQ_MPQ_BLOCKTABLE_SIZE:
|
||||
return mpq_a->header->blocktablesize;
|
||||
case LIBMPQ_MPQ_BLOCKSIZE:
|
||||
return mpq_a->blocksize;
|
||||
case LIBMPQ_MPQ_NUMFILES:
|
||||
for (mpq_b = mpq_a->blocktable; mpq_b < mpq_b_end; mpq_b++) {
|
||||
filecount++;
|
||||
}
|
||||
return filecount;
|
||||
case LIBMPQ_MPQ_COMPRESSED_SIZE:
|
||||
for (mpq_b = mpq_a->blocktable; mpq_b < mpq_b_end; mpq_b++) {
|
||||
csize += mpq_b->csize;
|
||||
}
|
||||
return csize;
|
||||
case LIBMPQ_MPQ_UNCOMPRESSED_SIZE:
|
||||
for (mpq_b = mpq_a->blocktable; mpq_b < mpq_b_end; mpq_b++) {
|
||||
fsize += mpq_b->fsize;
|
||||
}
|
||||
return fsize;
|
||||
default:
|
||||
return LIBMPQ_TOOLS_SUCCESS;
|
||||
}
|
||||
switch (infotype) {
|
||||
case LIBMPQ_MPQ_ARCHIVE_SIZE:
|
||||
return mpq_a->header->archivesize;
|
||||
case LIBMPQ_MPQ_HASHTABLE_SIZE:
|
||||
return mpq_a->header->hashtablesize;
|
||||
case LIBMPQ_MPQ_BLOCKTABLE_SIZE:
|
||||
return mpq_a->header->blocktablesize;
|
||||
case LIBMPQ_MPQ_BLOCKSIZE:
|
||||
return mpq_a->blocksize;
|
||||
case LIBMPQ_MPQ_NUMFILES:
|
||||
for (mpq_b = mpq_a->blocktable; mpq_b < mpq_b_end; mpq_b++) {
|
||||
filecount++;
|
||||
}
|
||||
return filecount;
|
||||
case LIBMPQ_MPQ_COMPRESSED_SIZE:
|
||||
for (mpq_b = mpq_a->blocktable; mpq_b < mpq_b_end; mpq_b++) {
|
||||
csize += mpq_b->csize;
|
||||
}
|
||||
return csize;
|
||||
case LIBMPQ_MPQ_UNCOMPRESSED_SIZE:
|
||||
for (mpq_b = mpq_a->blocktable; mpq_b < mpq_b_end; mpq_b++) {
|
||||
fsize += mpq_b->fsize;
|
||||
}
|
||||
return fsize;
|
||||
default:
|
||||
return LIBMPQ_TOOLS_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* This function returns some useful file information.
|
||||
*/
|
||||
int libmpq_file_info(mpq_archive *mpq_a, unsigned int infotype, const int unsigned number) {
|
||||
int blockindex = number; //-1;
|
||||
int i = 0;
|
||||
mpq_block *mpq_b = NULL;
|
||||
mpq_hash *mpq_h = NULL;
|
||||
int blockindex = number; //-1;
|
||||
int i = 0;
|
||||
mpq_block *mpq_b = NULL;
|
||||
mpq_hash *mpq_h = NULL;
|
||||
|
||||
/* check if given number is not out of range */
|
||||
if (number < 1 || number > mpq_a->header->blocktablesize) {
|
||||
return LIBMPQ_EINV_RANGE;
|
||||
}
|
||||
/* check if given number is not out of range */
|
||||
if (number < 1 || number > mpq_a->header->blocktablesize) {
|
||||
return LIBMPQ_EINV_RANGE;
|
||||
}
|
||||
|
||||
/* search for correct hashtable */
|
||||
/*for (i = 0; i < mpq_a->header->hashtablesize; i++) {
|
||||
if ((number - 1) == (mpq_a->hashtable[i]).blockindex) {
|
||||
blockindex = (mpq_a->hashtable[i]).blockindex;
|
||||
mpq_h = &(mpq_a->hashtable[i]);
|
||||
break;
|
||||
}
|
||||
}*/
|
||||
/* search for correct hashtable */
|
||||
/*for (i = 0; i < mpq_a->header->hashtablesize; i++) {
|
||||
if ((number - 1) == (mpq_a->hashtable[i]).blockindex) {
|
||||
blockindex = (mpq_a->hashtable[i]).blockindex;
|
||||
mpq_h = &(mpq_a->hashtable[i]);
|
||||
break;
|
||||
}
|
||||
}*/
|
||||
|
||||
/* check if file was found */
|
||||
/*if (blockindex == -1 || blockindex > mpq_a->header->blocktablesize) {
|
||||
return LIBMPQ_EFILE_NOT_FOUND;
|
||||
}*/
|
||||
/* check if file was found */
|
||||
/*if (blockindex == -1 || blockindex > mpq_a->header->blocktablesize) {
|
||||
return LIBMPQ_EFILE_NOT_FOUND;
|
||||
}*/
|
||||
|
||||
/* check if sizes are correct */
|
||||
mpq_b = mpq_a->blocktable + blockindex;
|
||||
if (mpq_b->filepos > (mpq_a->header->archivesize + mpq_a->mpqpos) || mpq_b->csize > mpq_a->header->archivesize) {
|
||||
return LIBMPQ_EFILE_CORRUPT;
|
||||
}
|
||||
/* check if sizes are correct */
|
||||
mpq_b = mpq_a->blocktable + blockindex;
|
||||
if (mpq_b->filepos > (mpq_a->header->archivesize + mpq_a->mpqpos) || mpq_b->csize > mpq_a->header->archivesize) {
|
||||
return LIBMPQ_EFILE_CORRUPT;
|
||||
}
|
||||
|
||||
/* check if file exists */
|
||||
if ((mpq_b->flags & LIBMPQ_FILE_EXISTS) == 0) {
|
||||
return LIBMPQ_EFILE_NOT_FOUND;
|
||||
}
|
||||
/* check if file exists */
|
||||
if ((mpq_b->flags & LIBMPQ_FILE_EXISTS) == 0) {
|
||||
return LIBMPQ_EFILE_NOT_FOUND;
|
||||
}
|
||||
|
||||
switch (infotype) {
|
||||
case LIBMPQ_FILE_COMPRESSED_SIZE:
|
||||
return mpq_b->csize;
|
||||
case LIBMPQ_FILE_UNCOMPRESSED_SIZE:
|
||||
return mpq_b->fsize;
|
||||
case LIBMPQ_FILE_COMPRESSION_TYPE:
|
||||
if (mpq_b->flags & LIBMPQ_FILE_COMPRESS_PKWARE) {
|
||||
return LIBMPQ_FILE_COMPRESS_PKWARE;
|
||||
}
|
||||
if (mpq_b->flags & LIBMPQ_FILE_COMPRESS_MULTI) {
|
||||
return LIBMPQ_FILE_COMPRESS_MULTI;
|
||||
}
|
||||
default:
|
||||
return LIBMPQ_TOOLS_SUCCESS;
|
||||
}
|
||||
switch (infotype) {
|
||||
case LIBMPQ_FILE_COMPRESSED_SIZE:
|
||||
return mpq_b->csize;
|
||||
case LIBMPQ_FILE_UNCOMPRESSED_SIZE:
|
||||
return mpq_b->fsize;
|
||||
case LIBMPQ_FILE_COMPRESSION_TYPE:
|
||||
if (mpq_b->flags & LIBMPQ_FILE_COMPRESS_PKWARE) {
|
||||
return LIBMPQ_FILE_COMPRESS_PKWARE;
|
||||
}
|
||||
if (mpq_b->flags & LIBMPQ_FILE_COMPRESS_MULTI) {
|
||||
return LIBMPQ_FILE_COMPRESS_MULTI;
|
||||
}
|
||||
default:
|
||||
return LIBMPQ_TOOLS_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -259,17 +259,17 @@ int libmpq_file_info(mpq_archive *mpq_a, unsigned int infotype, const int unsign
|
||||
* returns NULL.
|
||||
*/
|
||||
char *libmpq_file_name(mpq_archive *mpq_a, const int number) {
|
||||
static char tempfile[PATH_MAX];
|
||||
static char tempfile[PATH_MAX];
|
||||
|
||||
/* check if we are in the range of available files. */
|
||||
if (number > libmpq_archive_info(mpq_a, LIBMPQ_MPQ_NUMFILES) || number < 1) {
|
||||
return NULL;
|
||||
}
|
||||
/* check if we are in the range of available files. */
|
||||
if (number > libmpq_archive_info(mpq_a, LIBMPQ_MPQ_NUMFILES) || number < 1) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* this is safe because we built a fallback filelist, if something was wrong. */
|
||||
sprintf(tempfile, (char *)mpq_a->mpq_l->mpq_files[number - 1], number);
|
||||
/* this is safe because we built a fallback filelist, if something was wrong. */
|
||||
sprintf(tempfile, (char *)mpq_a->mpq_l->mpq_files[number - 1], number);
|
||||
|
||||
return tempfile;
|
||||
return tempfile;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -277,20 +277,20 @@ char *libmpq_file_name(mpq_archive *mpq_a, const int number) {
|
||||
* filename.
|
||||
*/
|
||||
int libmpq_file_number(mpq_archive *mpq_a, const char *name) {
|
||||
int i;
|
||||
char tempfile[PATH_MAX];
|
||||
int i;
|
||||
char tempfile[PATH_MAX];
|
||||
|
||||
for (i = 0; mpq_a->mpq_l->mpq_files[i]; i++) {
|
||||
sprintf(tempfile, (char *)mpq_a->mpq_l->mpq_files[i], i + 1);
|
||||
if (strncmp(tempfile, name, strlen(name)) == 0) {
|
||||
for (i = 0; mpq_a->mpq_l->mpq_files[i]; i++) {
|
||||
sprintf(tempfile, (char *)mpq_a->mpq_l->mpq_files[i], i + 1);
|
||||
if (strncmp(tempfile, name, strlen(name)) == 0) {
|
||||
|
||||
/* if file found return the number */
|
||||
return i + 1;
|
||||
}
|
||||
}
|
||||
/* if file found return the number */
|
||||
return i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* if no matching entry found return LIBMPQ_EFILE_NOT_FOUND */
|
||||
return LIBMPQ_EFILE_NOT_FOUND;
|
||||
/* if no matching entry found return LIBMPQ_EFILE_NOT_FOUND */
|
||||
return LIBMPQ_EFILE_NOT_FOUND;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -299,39 +299,39 @@ int libmpq_file_number(mpq_archive *mpq_a, const char *name) {
|
||||
* it returns 0, otherwise LIBMPQ_EFILE_NOT_FOUND.
|
||||
*/
|
||||
int libmpq_file_check(mpq_archive *mpq_a, void *file, int type) {
|
||||
int found = 0;
|
||||
int i;
|
||||
char tempfile[PATH_MAX];
|
||||
int found = 0;
|
||||
int i;
|
||||
char tempfile[PATH_MAX];
|
||||
|
||||
switch (type) {
|
||||
case LIBMPQ_FILE_TYPE_INT:
|
||||
switch (type) {
|
||||
case LIBMPQ_FILE_TYPE_INT:
|
||||
|
||||
/* check if we are in the range of available files. */
|
||||
if (*(int *)file > libmpq_archive_info(mpq_a, LIBMPQ_MPQ_NUMFILES) || *(int *)file < 1) {
|
||||
return LIBMPQ_EFILE_NOT_FOUND;
|
||||
} else {
|
||||
return LIBMPQ_TOOLS_SUCCESS;
|
||||
}
|
||||
case LIBMPQ_FILE_TYPE_CHAR:
|
||||
for (i = 0; mpq_a->mpq_l->mpq_files[i]; i++) {
|
||||
sprintf(tempfile, (char *)mpq_a->mpq_l->mpq_files[i], i);
|
||||
if (strncmp(tempfile, (char *)file, strlen((char *)file)) == 0) {
|
||||
/* check if we are in the range of available files. */
|
||||
if (*(int *)file > libmpq_archive_info(mpq_a, LIBMPQ_MPQ_NUMFILES) || *(int *)file < 1) {
|
||||
return LIBMPQ_EFILE_NOT_FOUND;
|
||||
} else {
|
||||
return LIBMPQ_TOOLS_SUCCESS;
|
||||
}
|
||||
case LIBMPQ_FILE_TYPE_CHAR:
|
||||
for (i = 0; mpq_a->mpq_l->mpq_files[i]; i++) {
|
||||
sprintf(tempfile, (char *)mpq_a->mpq_l->mpq_files[i], i);
|
||||
if (strncmp(tempfile, (char *)file, strlen((char *)file)) == 0) {
|
||||
|
||||
/* if file found break */
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* if file found break */
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* if a file was found return 0 */
|
||||
if (found == 1) {
|
||||
return LIBMPQ_TOOLS_SUCCESS;
|
||||
} else {
|
||||
return LIBMPQ_EFILE_NOT_FOUND;
|
||||
}
|
||||
default:
|
||||
return LIBMPQ_TOOLS_SUCCESS;
|
||||
}
|
||||
/* if a file was found return 0 */
|
||||
if (found == 1) {
|
||||
return LIBMPQ_TOOLS_SUCCESS;
|
||||
} else {
|
||||
return LIBMPQ_EFILE_NOT_FOUND;
|
||||
}
|
||||
default:
|
||||
return LIBMPQ_TOOLS_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -339,102 +339,102 @@ int libmpq_file_check(mpq_archive *mpq_a, void *file, int type) {
|
||||
* by the given number.
|
||||
*/
|
||||
int libmpq_file_extract(mpq_archive *mpq_a, const int number, const char *filename) {
|
||||
int blockindex = number; //-1;
|
||||
int fd = 0;
|
||||
int i = 0;
|
||||
char buffer[0x1000];
|
||||
//char tempfile[PATH_MAX];
|
||||
unsigned int transferred = 1;
|
||||
mpq_file *mpq_f = NULL;
|
||||
mpq_block *mpq_b = NULL;
|
||||
mpq_hash *mpq_h = NULL;
|
||||
int blockindex = number; //-1;
|
||||
int fd = 0;
|
||||
int i = 0;
|
||||
char buffer[0x1000];
|
||||
//char tempfile[PATH_MAX];
|
||||
unsigned int transferred = 1;
|
||||
mpq_file *mpq_f = NULL;
|
||||
mpq_block *mpq_b = NULL;
|
||||
mpq_hash *mpq_h = NULL;
|
||||
|
||||
/* if (number < 1 || number > mpq_a->header->blocktablesize) {
|
||||
return LIBMPQ_EINV_RANGE;
|
||||
}*/
|
||||
/* if (number < 1 || number > mpq_a->header->blocktablesize) {
|
||||
return LIBMPQ_EINV_RANGE;
|
||||
}*/
|
||||
/*
|
||||
sprintf(tempfile, libmpq_file_name(mpq_a, number));
|
||||
sprintf(tempfile, libmpq_file_name(mpq_a, number));
|
||||
*/
|
||||
/* check if mpq_f->filename could be written here. */
|
||||
fd = _open(filename, O_RDWR|O_CREAT|O_TRUNC, 0644);
|
||||
if (fd == LIBMPQ_EFILE) {
|
||||
return LIBMPQ_EFILE;
|
||||
}
|
||||
/* check if mpq_f->filename could be written here. */
|
||||
fd = _open(filename, O_RDWR|O_CREAT|O_TRUNC, 0644);
|
||||
if (fd == LIBMPQ_EFILE) {
|
||||
return LIBMPQ_EFILE;
|
||||
}
|
||||
|
||||
/* search for correct hashtable */
|
||||
/*for (i = 0; i < mpq_a->header->hashtablesize; i++) {
|
||||
if ((number - 1) == (mpq_a->hashtable[i]).blockindex) {
|
||||
blockindex = (mpq_a->hashtable[i]).blockindex;
|
||||
mpq_h = &(mpq_a->hashtable[i]);
|
||||
break;
|
||||
}
|
||||
}*/
|
||||
/* search for correct hashtable */
|
||||
/*for (i = 0; i < mpq_a->header->hashtablesize; i++) {
|
||||
if ((number - 1) == (mpq_a->hashtable[i]).blockindex) {
|
||||
blockindex = (mpq_a->hashtable[i]).blockindex;
|
||||
mpq_h = &(mpq_a->hashtable[i]);
|
||||
break;
|
||||
}
|
||||
}*/
|
||||
|
||||
/* check if file was found */
|
||||
if (blockindex == -1 || blockindex > mpq_a->header->blocktablesize) {
|
||||
return LIBMPQ_EFILE_NOT_FOUND;
|
||||
}
|
||||
/* check if file was found */
|
||||
if (blockindex == -1 || blockindex > mpq_a->header->blocktablesize) {
|
||||
return LIBMPQ_EFILE_NOT_FOUND;
|
||||
}
|
||||
|
||||
/* check if sizes are correct */
|
||||
mpq_b = mpq_a->blocktable + blockindex;
|
||||
if (mpq_b->filepos > (mpq_a->header->archivesize + mpq_a->mpqpos) || mpq_b->csize > mpq_a->header->archivesize) {
|
||||
return LIBMPQ_EFILE_CORRUPT;
|
||||
}
|
||||
/* check if sizes are correct */
|
||||
mpq_b = mpq_a->blocktable + blockindex;
|
||||
if (mpq_b->filepos > (mpq_a->header->archivesize + mpq_a->mpqpos) || mpq_b->csize > mpq_a->header->archivesize) {
|
||||
return LIBMPQ_EFILE_CORRUPT;
|
||||
}
|
||||
|
||||
/* check if file exists */
|
||||
if ((mpq_b->flags & LIBMPQ_FILE_EXISTS) == 0) {
|
||||
return LIBMPQ_EFILE_NOT_FOUND;
|
||||
}
|
||||
/* check if file exists */
|
||||
if ((mpq_b->flags & LIBMPQ_FILE_EXISTS) == 0) {
|
||||
return LIBMPQ_EFILE_NOT_FOUND;
|
||||
}
|
||||
|
||||
/* allocate memory for file structure */
|
||||
mpq_f = (mpq_file *)malloc(sizeof(mpq_file));
|
||||
if (!mpq_f) {
|
||||
return LIBMPQ_EALLOCMEM;
|
||||
}
|
||||
/* allocate memory for file structure */
|
||||
mpq_f = (mpq_file *)malloc(sizeof(mpq_file));
|
||||
if (!mpq_f) {
|
||||
return LIBMPQ_EALLOCMEM;
|
||||
}
|
||||
|
||||
/* initialize file structure */
|
||||
memset(mpq_f, 0, sizeof(mpq_file));
|
||||
mpq_f->fd = fd;
|
||||
mpq_f->mpq_b = mpq_b;
|
||||
mpq_f->nblocks = (mpq_f->mpq_b->fsize + mpq_a->blocksize - 1) / mpq_a->blocksize;
|
||||
mpq_f->mpq_h = mpq_h;
|
||||
mpq_f->accessed = FALSE;
|
||||
mpq_f->blockposloaded = FALSE;
|
||||
sprintf((char *)mpq_f->filename, filename);
|
||||
/* initialize file structure */
|
||||
memset(mpq_f, 0, sizeof(mpq_file));
|
||||
mpq_f->fd = fd;
|
||||
mpq_f->mpq_b = mpq_b;
|
||||
mpq_f->nblocks = (mpq_f->mpq_b->fsize + mpq_a->blocksize - 1) / mpq_a->blocksize;
|
||||
mpq_f->mpq_h = mpq_h;
|
||||
mpq_f->accessed = FALSE;
|
||||
mpq_f->blockposloaded = FALSE;
|
||||
sprintf((char *)mpq_f->filename, filename);
|
||||
|
||||
/* allocate buffers for decompression. */
|
||||
if (mpq_f->mpq_b->flags & LIBMPQ_FILE_COMPRESSED) {
|
||||
/* allocate buffers for decompression. */
|
||||
if (mpq_f->mpq_b->flags & LIBMPQ_FILE_COMPRESSED) {
|
||||
|
||||
/*
|
||||
* Allocate buffer for block positions. At the begin of file are stored
|
||||
* unsigned ints holding positions of each block relative from begin of
|
||||
* file in the archive.
|
||||
*/
|
||||
if ((mpq_f->blockpos = (unsigned int *)malloc(sizeof(int) * mpq_f->nblocks + 1)) == NULL) {
|
||||
return LIBMPQ_EALLOCMEM;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Allocate buffer for block positions. At the begin of file are stored
|
||||
* unsigned ints holding positions of each block relative from begin of
|
||||
* file in the archive.
|
||||
*/
|
||||
if ((mpq_f->blockpos = (unsigned int *)malloc(sizeof(int) * mpq_f->nblocks + 1)) == NULL) {
|
||||
return LIBMPQ_EALLOCMEM;
|
||||
}
|
||||
}
|
||||
|
||||
while (transferred > 0) {
|
||||
transferred = libmpq_file_read_file(mpq_a, mpq_f, mpq_f->filepos, buffer, sizeof(buffer));
|
||||
if (transferred == 0) {
|
||||
break;
|
||||
} else {
|
||||
mpq_f->accessed = TRUE;
|
||||
mpq_f->filepos += transferred;
|
||||
}
|
||||
while (transferred > 0) {
|
||||
transferred = libmpq_file_read_file(mpq_a, mpq_f, mpq_f->filepos, buffer, sizeof(buffer));
|
||||
if (transferred == 0) {
|
||||
break;
|
||||
} else {
|
||||
mpq_f->accessed = TRUE;
|
||||
mpq_f->filepos += transferred;
|
||||
}
|
||||
|
||||
transferred = _write(mpq_f->fd, buffer, transferred);
|
||||
if (transferred == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
transferred = _write(mpq_f->fd, buffer, transferred);
|
||||
if (transferred == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
_close(fd);
|
||||
_close(fd);
|
||||
|
||||
/* freeing the file structure */
|
||||
free(mpq_f);
|
||||
return LIBMPQ_TOOLS_SUCCESS;
|
||||
/* freeing the file structure */
|
||||
free(mpq_f);
|
||||
return LIBMPQ_TOOLS_SUCCESS;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -444,183 +444,183 @@ int libmpq_file_extract(mpq_archive *mpq_a, const int number, const char *filena
|
||||
*/
|
||||
|
||||
int libmpq_listfile_open(mpq_archive *mpq_a, char file[PATH_MAX]) {
|
||||
FILE *fp;
|
||||
//char **filelist;
|
||||
int i = 0;
|
||||
//int fl_count;
|
||||
//int fl_size;
|
||||
int fl_count_fb;
|
||||
int fl_size_fb;
|
||||
int result = LIBMPQ_TOOLS_SUCCESS;
|
||||
struct stat statbuf;
|
||||
FILE *fp;
|
||||
//char **filelist;
|
||||
int i = 0;
|
||||
//int fl_count;
|
||||
//int fl_size;
|
||||
int fl_count_fb;
|
||||
int fl_size_fb;
|
||||
int result = LIBMPQ_TOOLS_SUCCESS;
|
||||
struct stat statbuf;
|
||||
|
||||
/* get file status */
|
||||
if (stat(file, &statbuf) < 0) {
|
||||
result = LIBMPQ_CONF_EFILE_NOT_FOUND;
|
||||
}
|
||||
/* get file status */
|
||||
if (stat(file, &statbuf) < 0) {
|
||||
result = LIBMPQ_CONF_EFILE_NOT_FOUND;
|
||||
}
|
||||
|
||||
/* check if file is a filename or directory */
|
||||
/*if (S_ISDIR(statbuf.st_mode)) {
|
||||
/* check if file is a filename or directory */
|
||||
/*if (S_ISDIR(statbuf.st_mode)) {
|
||||
|
||||
// allocate memory for the file list
|
||||
filelist = (char **)malloc(LIBMPQ_CONF_FL_INCREMENT * sizeof(char *));
|
||||
fl_count = 0;
|
||||
fl_size = LIBMPQ_CONF_FL_INCREMENT;
|
||||
// allocate memory for the file list
|
||||
filelist = (char **)malloc(LIBMPQ_CONF_FL_INCREMENT * sizeof(char *));
|
||||
fl_count = 0;
|
||||
fl_size = LIBMPQ_CONF_FL_INCREMENT;
|
||||
|
||||
// check if it is a valid listfile
|
||||
if (libmpq_detect_listfile_rec(file, &filelist, &fl_count, &fl_size)) {
|
||||
filelist == NULL;
|
||||
}
|
||||
// check if it is a valid listfile
|
||||
if (libmpq_detect_listfile_rec(file, &filelist, &fl_count, &fl_size)) {
|
||||
filelist == NULL;
|
||||
}
|
||||
|
||||
filelist[fl_count] = NULL;
|
||||
filelist[fl_count] = NULL;
|
||||
|
||||
// return if no listfile was found
|
||||
if (filelist == NULL) {
|
||||
result = LIBMPQ_CONF_EFILE_NOT_FOUND;
|
||||
}
|
||||
// return if no listfile was found
|
||||
if (filelist == NULL) {
|
||||
result = LIBMPQ_CONF_EFILE_NOT_FOUND;
|
||||
}
|
||||
|
||||
for (i = 0; filelist[i]; i++) {
|
||||
if ((fp = fopen(filelist[i], "r")) != NULL ) {
|
||||
result = libmpq_read_listfile(mpq_a, fp);
|
||||
fclose(fp);
|
||||
}
|
||||
}
|
||||
for (i = 0; filelist[i]; i++) {
|
||||
if ((fp = fopen(filelist[i], "r")) != NULL ) {
|
||||
result = libmpq_read_listfile(mpq_a, fp);
|
||||
fclose(fp);
|
||||
}
|
||||
}
|
||||
|
||||
// freeing the listfile struct
|
||||
libmpq_free_listfile(filelist);
|
||||
}*/
|
||||
// freeing the listfile struct
|
||||
libmpq_free_listfile(filelist);
|
||||
}*/
|
||||
|
||||
/* if file is a regular file use it */
|
||||
//if (S_ISREG(statbuf.st_mode)) {
|
||||
/* if file is a regular file use it */
|
||||
//if (S_ISREG(statbuf.st_mode)) {
|
||||
|
||||
/* if specific listfile was forced. */
|
||||
if ((fp = fopen(file, "r")) != NULL ) {
|
||||
result = libmpq_read_listfile(mpq_a, fp);
|
||||
fclose(fp);
|
||||
} else {
|
||||
result = LIBMPQ_CONF_EFILE_OPEN;
|
||||
}
|
||||
//}
|
||||
/* if specific listfile was forced. */
|
||||
if ((fp = fopen(file, "r")) != NULL ) {
|
||||
result = libmpq_read_listfile(mpq_a, fp);
|
||||
fclose(fp);
|
||||
} else {
|
||||
result = LIBMPQ_CONF_EFILE_OPEN;
|
||||
}
|
||||
//}
|
||||
|
||||
/* if error occured we need to create a fallback filelist. */
|
||||
if (mpq_a->mpq_l->mpq_files == NULL) {
|
||||
/* if error occured we need to create a fallback filelist. */
|
||||
if (mpq_a->mpq_l->mpq_files == NULL) {
|
||||
|
||||
/* allocate memory for the file list */
|
||||
mpq_a->mpq_l->mpq_files = (unsigned char **)malloc(LIBMPQ_CONF_FL_INCREMENT * sizeof(char *));
|
||||
fl_count_fb = 0;
|
||||
fl_size_fb = LIBMPQ_CONF_FL_INCREMENT;
|
||||
/* allocate memory for the file list */
|
||||
mpq_a->mpq_l->mpq_files = (unsigned char **)malloc(LIBMPQ_CONF_FL_INCREMENT * sizeof(char *));
|
||||
fl_count_fb = 0;
|
||||
fl_size_fb = LIBMPQ_CONF_FL_INCREMENT;
|
||||
|
||||
for (i = 0; i < libmpq_archive_info(mpq_a, LIBMPQ_MPQ_NUMFILES); i++) {
|
||||
for (i = 0; i < libmpq_archive_info(mpq_a, LIBMPQ_MPQ_NUMFILES); i++) {
|
||||
|
||||
/* set the next filelist entry to a copy of the file */
|
||||
mpq_a->mpq_l->mpq_files[fl_count_fb++] = (unsigned char *)_strdup("file%06lu.xxx");
|
||||
/* set the next filelist entry to a copy of the file */
|
||||
mpq_a->mpq_l->mpq_files[fl_count_fb++] = (unsigned char *)_strdup("file%06lu.xxx");
|
||||
|
||||
/* increase the array size */
|
||||
if (fl_count_fb == fl_size_fb) {
|
||||
mpq_a->mpq_l->mpq_files = (unsigned char **)realloc(mpq_a->mpq_l->mpq_files, (fl_size_fb + LIBMPQ_CONF_FL_INCREMENT) * sizeof(char *));
|
||||
fl_size_fb += LIBMPQ_CONF_FL_INCREMENT;
|
||||
}
|
||||
}
|
||||
mpq_a->mpq_l->mpq_files[fl_count_fb] = NULL;
|
||||
/* increase the array size */
|
||||
if (fl_count_fb == fl_size_fb) {
|
||||
mpq_a->mpq_l->mpq_files = (unsigned char **)realloc(mpq_a->mpq_l->mpq_files, (fl_size_fb + LIBMPQ_CONF_FL_INCREMENT) * sizeof(char *));
|
||||
fl_size_fb += LIBMPQ_CONF_FL_INCREMENT;
|
||||
}
|
||||
}
|
||||
mpq_a->mpq_l->mpq_files[fl_count_fb] = NULL;
|
||||
|
||||
/* if no error occurs and no listfile was assigned, we think there was no matching listfile. */
|
||||
if (result == 0) {
|
||||
result = LIBMPQ_CONF_EFILE_NOT_FOUND;
|
||||
}
|
||||
}
|
||||
/* if no error occurs and no listfile was assigned, we think there was no matching listfile. */
|
||||
if (result == 0) {
|
||||
result = LIBMPQ_CONF_EFILE_NOT_FOUND;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* This function frees the allocated memory for the listfile.
|
||||
*/
|
||||
int libmpq_listfile_close(mpq_archive *mpq_a) {
|
||||
int i = 0;
|
||||
int i = 0;
|
||||
|
||||
/* safety check if we really have a filelist. */
|
||||
if (mpq_a->mpq_l->mpq_files != NULL) {
|
||||
/* freeing the filelist */
|
||||
while (mpq_a->mpq_l->mpq_files[i]) {
|
||||
free(mpq_a->mpq_l->mpq_files[i++]);
|
||||
}
|
||||
free(mpq_a->mpq_l->mpq_files);
|
||||
}
|
||||
/* safety check if we really have a filelist. */
|
||||
if (mpq_a->mpq_l->mpq_files != NULL) {
|
||||
/* freeing the filelist */
|
||||
while (mpq_a->mpq_l->mpq_files[i]) {
|
||||
free(mpq_a->mpq_l->mpq_files[i++]);
|
||||
}
|
||||
free(mpq_a->mpq_l->mpq_files);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int libmpq_file_getdata(mpq_archive *mpq_a, mpq_hash mpq_h, const int number, unsigned char *dest) {
|
||||
int blockindex = number; //-1;
|
||||
int i = 0;
|
||||
mpq_file *mpq_f = NULL;
|
||||
mpq_block *mpq_b = NULL;
|
||||
int success = 0;
|
||||
int blockindex = number; //-1;
|
||||
int i = 0;
|
||||
mpq_file *mpq_f = NULL;
|
||||
mpq_block *mpq_b = NULL;
|
||||
int success = 0;
|
||||
|
||||
/*if (number < 1 || number > mpq_a->header->blocktablesize) {
|
||||
return LIBMPQ_EINV_RANGE;
|
||||
}*/
|
||||
/*if (number < 1 || number > mpq_a->header->blocktablesize) {
|
||||
return LIBMPQ_EINV_RANGE;
|
||||
}*/
|
||||
|
||||
/* search for correct hashtable */
|
||||
/*for (i = 0; i < mpq_a->header->hashtablesize; i++) {
|
||||
if ((number - 1) == (mpq_a->hashtable[i]).blockindex) {
|
||||
blockindex = (mpq_a->hashtable[i]).blockindex;
|
||||
mpq_h = &(mpq_a->hashtable[i]);
|
||||
break;
|
||||
}
|
||||
}*/
|
||||
/* search for correct hashtable */
|
||||
/*for (i = 0; i < mpq_a->header->hashtablesize; i++) {
|
||||
if ((number - 1) == (mpq_a->hashtable[i]).blockindex) {
|
||||
blockindex = (mpq_a->hashtable[i]).blockindex;
|
||||
mpq_h = &(mpq_a->hashtable[i]);
|
||||
break;
|
||||
}
|
||||
}*/
|
||||
|
||||
/* check if file was found */
|
||||
if (blockindex == -1 || blockindex > mpq_a->header->blocktablesize) {
|
||||
return LIBMPQ_EFILE_NOT_FOUND;
|
||||
}
|
||||
/* check if file was found */
|
||||
if (blockindex == -1 || blockindex > mpq_a->header->blocktablesize) {
|
||||
return LIBMPQ_EFILE_NOT_FOUND;
|
||||
}
|
||||
|
||||
/* check if sizes are correct */
|
||||
mpq_b = mpq_a->blocktable + blockindex;
|
||||
if (mpq_b->filepos > (mpq_a->header->archivesize + mpq_a->mpqpos) || mpq_b->csize > mpq_a->header->archivesize) {
|
||||
return LIBMPQ_EFILE_CORRUPT;
|
||||
}
|
||||
/* check if sizes are correct */
|
||||
mpq_b = mpq_a->blocktable + blockindex;
|
||||
if (mpq_b->filepos > (mpq_a->header->archivesize + mpq_a->mpqpos) || mpq_b->csize > mpq_a->header->archivesize) {
|
||||
return LIBMPQ_EFILE_CORRUPT;
|
||||
}
|
||||
|
||||
/* check if file exists */
|
||||
if ((mpq_b->flags & LIBMPQ_FILE_EXISTS) == 0) {
|
||||
return LIBMPQ_EFILE_NOT_FOUND;
|
||||
}
|
||||
/* check if file exists */
|
||||
if ((mpq_b->flags & LIBMPQ_FILE_EXISTS) == 0) {
|
||||
return LIBMPQ_EFILE_NOT_FOUND;
|
||||
}
|
||||
|
||||
/* allocate memory for file structure */
|
||||
mpq_f = (mpq_file*)malloc(sizeof(mpq_file));
|
||||
if (!mpq_f) {
|
||||
return LIBMPQ_EALLOCMEM;
|
||||
}
|
||||
/* allocate memory for file structure */
|
||||
mpq_f = (mpq_file*)malloc(sizeof(mpq_file));
|
||||
if (!mpq_f) {
|
||||
return LIBMPQ_EALLOCMEM;
|
||||
}
|
||||
|
||||
/* initialize file structure */
|
||||
memset(mpq_f, 0, sizeof(mpq_file));
|
||||
mpq_f->mpq_b = mpq_b;
|
||||
mpq_f->nblocks = (mpq_f->mpq_b->fsize + mpq_a->blocksize - 1) / mpq_a->blocksize;
|
||||
mpq_f->mpq_h = &mpq_h;
|
||||
mpq_f->accessed = FALSE;
|
||||
mpq_f->blockposloaded = FALSE;
|
||||
/* initialize file structure */
|
||||
memset(mpq_f, 0, sizeof(mpq_file));
|
||||
mpq_f->mpq_b = mpq_b;
|
||||
mpq_f->nblocks = (mpq_f->mpq_b->fsize + mpq_a->blocksize - 1) / mpq_a->blocksize;
|
||||
mpq_f->mpq_h = &mpq_h;
|
||||
mpq_f->accessed = FALSE;
|
||||
mpq_f->blockposloaded = FALSE;
|
||||
|
||||
/* allocate buffers for decompression. */
|
||||
if (mpq_f->mpq_b->flags & LIBMPQ_FILE_COMPRESSED) {
|
||||
/* allocate buffers for decompression. */
|
||||
if (mpq_f->mpq_b->flags & LIBMPQ_FILE_COMPRESSED) {
|
||||
|
||||
/*
|
||||
* Allocate buffer for block positions. At the begin of file are stored
|
||||
* unsigned ints holding positions of each block relative from begin of
|
||||
* file in the archive.
|
||||
*/
|
||||
if ((mpq_f->blockpos = (unsigned int*)malloc(sizeof(int) * (mpq_f->nblocks + 1))) == NULL) {
|
||||
return LIBMPQ_EALLOCMEM;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Allocate buffer for block positions. At the begin of file are stored
|
||||
* unsigned ints holding positions of each block relative from begin of
|
||||
* file in the archive.
|
||||
*/
|
||||
if ((mpq_f->blockpos = (unsigned int*)malloc(sizeof(int) * (mpq_f->nblocks + 1))) == NULL) {
|
||||
return LIBMPQ_EALLOCMEM;
|
||||
}
|
||||
}
|
||||
|
||||
if(libmpq_file_read_file(mpq_a, mpq_f, 0, (char*)dest, mpq_b->fsize) == mpq_b->fsize)
|
||||
success = 1;
|
||||
|
||||
if (mpq_f->mpq_b->flags & LIBMPQ_FILE_COMPRESSED) {
|
||||
// Free buffer for block positions
|
||||
|
||||
free(mpq_f->blockpos);
|
||||
}
|
||||
/* freeing the file structure */
|
||||
free(mpq_f);
|
||||
return success?LIBMPQ_TOOLS_SUCCESS:LIBMPQ_EFILE_CORRUPT;
|
||||
|
||||
free(mpq_f->blockpos);
|
||||
}
|
||||
/* freeing the file structure */
|
||||
free(mpq_f);
|
||||
return success?LIBMPQ_TOOLS_SUCCESS:LIBMPQ_EFILE_CORRUPT;
|
||||
}
|
||||
|
||||
+106
-106
@@ -33,61 +33,61 @@
|
||||
#include <limits.h>
|
||||
|
||||
#ifndef PATH_MAX
|
||||
#define PATH_MAX 260
|
||||
#define PATH_MAX 260
|
||||
#endif
|
||||
|
||||
|
||||
#define LIBMPQ_MAJOR_VERSION 0 /* Major version number... maybe sometimes we reach version 1 :) */
|
||||
#define LIBMPQ_MINOR_VERSION 3 /* Minor version number - increased only for small changes */
|
||||
#define LIBMPQ_PATCH_VERSION 0 /* Patchlevel - changed on bugfixes etc... */
|
||||
#define LIBMPQ_MAJOR_VERSION 0 /* Major version number... maybe sometimes we reach version 1 :) */
|
||||
#define LIBMPQ_MINOR_VERSION 3 /* Minor version number - increased only for small changes */
|
||||
#define LIBMPQ_PATCH_VERSION 0 /* Patchlevel - changed on bugfixes etc... */
|
||||
|
||||
#define LIBMPQ_TOOLS_SUCCESS 0 /* return value for all functions which success */
|
||||
#define LIBMPQ_TOOLS_BUFSIZE 0x500 /* buffer size for the decryption engine */
|
||||
#define LIBMPQ_TOOLS_SUCCESS 0 /* return value for all functions which success */
|
||||
#define LIBMPQ_TOOLS_BUFSIZE 0x500 /* buffer size for the decryption engine */
|
||||
|
||||
#define LIBMPQ_EFILE -1 /* error on file operation */
|
||||
#define LIBMPQ_EFILE_FORMAT -2 /* bad file format */
|
||||
#define LIBMPQ_EFILE_CORRUPT -3 /* file corrupt */
|
||||
#define LIBMPQ_EFILE_NOT_FOUND -4 /* file in archive not found */
|
||||
#define LIBMPQ_EFILE_READ -5 /* Read error in archive */
|
||||
#define LIBMPQ_EALLOCMEM -6 /* maybe not enough memory? :) */
|
||||
#define LIBMPQ_EFREEMEM -7 /* can not free memory */
|
||||
#define LIBMPQ_EINV_RANGE -8 /* Given filenumber is out of range */
|
||||
#define LIBMPQ_EHASHTABLE -9 /* error in reading hashtable */
|
||||
#define LIBMPQ_EBLOCKTABLE -10 /* error in reading blocktable */
|
||||
#define LIBMPQ_EFILE -1 /* error on file operation */
|
||||
#define LIBMPQ_EFILE_FORMAT -2 /* bad file format */
|
||||
#define LIBMPQ_EFILE_CORRUPT -3 /* file corrupt */
|
||||
#define LIBMPQ_EFILE_NOT_FOUND -4 /* file in archive not found */
|
||||
#define LIBMPQ_EFILE_READ -5 /* Read error in archive */
|
||||
#define LIBMPQ_EALLOCMEM -6 /* maybe not enough memory? :) */
|
||||
#define LIBMPQ_EFREEMEM -7 /* can not free memory */
|
||||
#define LIBMPQ_EINV_RANGE -8 /* Given filenumber is out of range */
|
||||
#define LIBMPQ_EHASHTABLE -9 /* error in reading hashtable */
|
||||
#define LIBMPQ_EBLOCKTABLE -10 /* error in reading blocktable */
|
||||
|
||||
#define LIBMPQ_ID_MPQ 0x1A51504D /* MPQ archive header ID ('MPQ\x1A') */
|
||||
#define LIBMPQ_HEADER_W3M 0x6D9E4B86 /* special value used by W3M Map Protector */
|
||||
#define LIBMPQ_FLAG_PROTECTED 0x00000002 /* Set on protected MPQs (like W3M maps) */
|
||||
#define LIBMPQ_HASH_ENTRY_DELETED 0xFFFFFFFE /* Block index for deleted hash entry */
|
||||
#define LIBMPQ_ID_MPQ 0x1A51504D /* MPQ archive header ID ('MPQ\x1A') */
|
||||
#define LIBMPQ_HEADER_W3M 0x6D9E4B86 /* special value used by W3M Map Protector */
|
||||
#define LIBMPQ_FLAG_PROTECTED 0x00000002 /* Set on protected MPQs (like W3M maps) */
|
||||
#define LIBMPQ_HASH_ENTRY_DELETED 0xFFFFFFFE /* Block index for deleted hash entry */
|
||||
|
||||
#define LIBMPQ_FILE_COMPRESS_PKWARE 0x00000100 /* Compression made by PKWARE Data Compression Library */
|
||||
#define LIBMPQ_FILE_COMPRESS_MULTI 0x00000200 /* Multiple compressions */
|
||||
#define LIBMPQ_FILE_COMPRESSED 0x0000FF00 /* File is compressed */
|
||||
#define LIBMPQ_FILE_EXISTS 0x80000000 /* Set if file exists, reset when the file was deleted */
|
||||
#define LIBMPQ_FILE_ENCRYPTED 0x00010000 /* Indicates whether file is encrypted */
|
||||
#define LIBMPQ_FILE_COMPRESS_PKWARE 0x00000100 /* Compression made by PKWARE Data Compression Library */
|
||||
#define LIBMPQ_FILE_COMPRESS_MULTI 0x00000200 /* Multiple compressions */
|
||||
#define LIBMPQ_FILE_COMPRESSED 0x0000FF00 /* File is compressed */
|
||||
#define LIBMPQ_FILE_EXISTS 0x80000000 /* Set if file exists, reset when the file was deleted */
|
||||
#define LIBMPQ_FILE_ENCRYPTED 0x00010000 /* Indicates whether file is encrypted */
|
||||
#define LIBMPQ_FILE_HAS_METADATA 0x04000000
|
||||
|
||||
#define LIBMPQ_FILE_COMPRESSED_SIZE 1 /* MPQ compressed filesize of given file */
|
||||
#define LIBMPQ_FILE_UNCOMPRESSED_SIZE 2 /* MPQ uncompressed filesize of given file */
|
||||
#define LIBMPQ_FILE_COMPRESSION_TYPE 3 /* MPQ compression type of given file */
|
||||
#define LIBMPQ_FILE_TYPE_INT 4 /* file is given by number */
|
||||
#define LIBMPQ_FILE_TYPE_CHAR 5 /* file is given by name */
|
||||
#define LIBMPQ_FILE_COMPRESSED_SIZE 1 /* MPQ compressed filesize of given file */
|
||||
#define LIBMPQ_FILE_UNCOMPRESSED_SIZE 2 /* MPQ uncompressed filesize of given file */
|
||||
#define LIBMPQ_FILE_COMPRESSION_TYPE 3 /* MPQ compression type of given file */
|
||||
#define LIBMPQ_FILE_TYPE_INT 4 /* file is given by number */
|
||||
#define LIBMPQ_FILE_TYPE_CHAR 5 /* file is given by name */
|
||||
|
||||
#define LIBMPQ_MPQ_ARCHIVE_SIZE 1 /* MPQ archive size */
|
||||
#define LIBMPQ_MPQ_HASHTABLE_SIZE 2 /* MPQ archive hashtable size */
|
||||
#define LIBMPQ_MPQ_BLOCKTABLE_SIZE 3 /* MPQ archive blocktable size */
|
||||
#define LIBMPQ_MPQ_BLOCKSIZE 4 /* MPQ archive blocksize */
|
||||
#define LIBMPQ_MPQ_NUMFILES 5 /* Number of files in the MPQ archive */
|
||||
#define LIBMPQ_MPQ_COMPRESSED_SIZE 6 /* Compressed archive size */
|
||||
#define LIBMPQ_MPQ_UNCOMPRESSED_SIZE 7 /* Uncompressed archive size */
|
||||
#define LIBMPQ_MPQ_ARCHIVE_SIZE 1 /* MPQ archive size */
|
||||
#define LIBMPQ_MPQ_HASHTABLE_SIZE 2 /* MPQ archive hashtable size */
|
||||
#define LIBMPQ_MPQ_BLOCKTABLE_SIZE 3 /* MPQ archive blocktable size */
|
||||
#define LIBMPQ_MPQ_BLOCKSIZE 4 /* MPQ archive blocksize */
|
||||
#define LIBMPQ_MPQ_NUMFILES 5 /* Number of files in the MPQ archive */
|
||||
#define LIBMPQ_MPQ_COMPRESSED_SIZE 6 /* Compressed archive size */
|
||||
#define LIBMPQ_MPQ_UNCOMPRESSED_SIZE 7 /* Uncompressed archive size */
|
||||
|
||||
#define LIBMPQ_HUFF_DECOMPRESS 0 /* Defines that we want to decompress using huffman trees. */
|
||||
#define LIBMPQ_HUFF_DECOMPRESS 0 /* Defines that we want to decompress using huffman trees. */
|
||||
|
||||
#define LIBMPQ_CONF_EFILE_OPEN -1 /* error if a specific listfile was forced and could not be opened. */
|
||||
#define LIBMPQ_CONF_EFILE_CORRUPT -2 /* listfile seems to be corrupt */
|
||||
#define LIBMPQ_CONF_EFILE_LIST_CORRUPT -3 /* listfile seems correct, but filelist is broken */
|
||||
#define LIBMPQ_CONF_EFILE_NOT_FOUND -4 /* error if no matching listfile found */
|
||||
#define LIBMPQ_CONF_EFILE_VERSION -5 /* libmpq version does not match required listfile version */
|
||||
#define LIBMPQ_CONF_EFILE_OPEN -1 /* error if a specific listfile was forced and could not be opened. */
|
||||
#define LIBMPQ_CONF_EFILE_CORRUPT -2 /* listfile seems to be corrupt */
|
||||
#define LIBMPQ_CONF_EFILE_LIST_CORRUPT -3 /* listfile seems correct, but filelist is broken */
|
||||
#define LIBMPQ_CONF_EFILE_NOT_FOUND -4 /* error if no matching listfile found */
|
||||
#define LIBMPQ_CONF_EFILE_VERSION -5 /* libmpq version does not match required listfile version */
|
||||
|
||||
#ifndef FALSE
|
||||
#define FALSE 0
|
||||
@@ -102,95 +102,95 @@
|
||||
#endif
|
||||
*/
|
||||
|
||||
typedef unsigned int mpq_buffer[LIBMPQ_TOOLS_BUFSIZE];
|
||||
typedef int (*DECOMPRESS)(char *, int *, char *, int);
|
||||
typedef unsigned int mpq_buffer[LIBMPQ_TOOLS_BUFSIZE];
|
||||
typedef int (*DECOMPRESS)(char *, int *, char *, int);
|
||||
typedef struct {
|
||||
unsigned long mask; /* Decompression bit */
|
||||
DECOMPRESS decompress; /* Decompression function */
|
||||
unsigned long mask; /* Decompression bit */
|
||||
DECOMPRESS decompress; /* Decompression function */
|
||||
} decompress_table;
|
||||
|
||||
/* MPQ file header */
|
||||
typedef struct {
|
||||
unsigned int id; /* The 0x1A51504D ('MPQ\x1A') signature */
|
||||
unsigned int offset; /* Offset of the first file (Relative to MPQ start) */
|
||||
unsigned int archivesize; /* Size of MPQ archive */
|
||||
unsigned short offsetsc; /* 0000 for SC and BW */
|
||||
unsigned short blocksize; /* Size of file block is (0x200 << blockSize) */
|
||||
unsigned int hashtablepos; /* File position of hashTable */
|
||||
unsigned int blocktablepos; /* File position of blockTable. Each entry has 16 bytes */
|
||||
unsigned int hashtablesize; /* Number of entries in hash table */
|
||||
unsigned int blocktablesize; /* Number of entries in the block table */
|
||||
unsigned int id; /* The 0x1A51504D ('MPQ\x1A') signature */
|
||||
unsigned int offset; /* Offset of the first file (Relative to MPQ start) */
|
||||
unsigned int archivesize; /* Size of MPQ archive */
|
||||
unsigned short offsetsc; /* 0000 for SC and BW */
|
||||
unsigned short blocksize; /* Size of file block is (0x200 << blockSize) */
|
||||
unsigned int hashtablepos; /* File position of hashTable */
|
||||
unsigned int blocktablepos; /* File position of blockTable. Each entry has 16 bytes */
|
||||
unsigned int hashtablesize; /* Number of entries in hash table */
|
||||
unsigned int blocktablesize; /* Number of entries in the block table */
|
||||
} mpq_header;
|
||||
//} __attribute__ ((packed)) mpq_header;
|
||||
|
||||
|
||||
/* Hash entry. All files in the archive are searched by their hashes. */
|
||||
typedef struct {
|
||||
unsigned int name1; /* The first two unsigned ints */
|
||||
unsigned int name2; /* are the encrypted file name */
|
||||
unsigned int locale; /* Locale information. */
|
||||
unsigned int blockindex; /* Index to file description block */
|
||||
unsigned int name1; /* The first two unsigned ints */
|
||||
unsigned int name2; /* are the encrypted file name */
|
||||
unsigned int locale; /* Locale information. */
|
||||
unsigned int blockindex; /* Index to file description block */
|
||||
} mpq_hash;
|
||||
|
||||
/* File description block contains informations about the file */
|
||||
typedef struct {
|
||||
unsigned int filepos; /* Block file starting position in the archive */
|
||||
unsigned int csize; /* Compressed file size */
|
||||
unsigned int fsize; /* Uncompressed file size */
|
||||
unsigned int flags; /* Flags */
|
||||
unsigned int filepos; /* Block file starting position in the archive */
|
||||
unsigned int csize; /* Compressed file size */
|
||||
unsigned int fsize; /* Uncompressed file size */
|
||||
unsigned int flags; /* Flags */
|
||||
} mpq_block;
|
||||
|
||||
/* File handle structure used since Diablo 1.00 (0x38 bytes) */
|
||||
typedef struct {
|
||||
unsigned char filename[PATH_MAX]; /* filename of the actual file in the archive */
|
||||
int fd; /* File handle */
|
||||
unsigned int seed; /* Seed used for file decrypt */
|
||||
unsigned int filepos; /* Current file position */
|
||||
unsigned int offset;
|
||||
unsigned int nblocks; /* Number of blocks in the file (incl. the last noncomplete one) */
|
||||
unsigned int *blockpos; /* Position of each file block (only for compressed files) */
|
||||
int blockposloaded; /* TRUE if block positions loaded */
|
||||
unsigned int offset2; /* (Number of bytes somewhere ?) */
|
||||
mpq_hash *mpq_h; /* Hash table entry */
|
||||
mpq_block *mpq_b; /* File block pointer */
|
||||
unsigned char filename[PATH_MAX]; /* filename of the actual file in the archive */
|
||||
int fd; /* File handle */
|
||||
unsigned int seed; /* Seed used for file decrypt */
|
||||
unsigned int filepos; /* Current file position */
|
||||
unsigned int offset;
|
||||
unsigned int nblocks; /* Number of blocks in the file (incl. the last noncomplete one) */
|
||||
unsigned int *blockpos; /* Position of each file block (only for compressed files) */
|
||||
int blockposloaded; /* TRUE if block positions loaded */
|
||||
unsigned int offset2; /* (Number of bytes somewhere ?) */
|
||||
mpq_hash *mpq_h; /* Hash table entry */
|
||||
mpq_block *mpq_b; /* File block pointer */
|
||||
|
||||
/* Non-Storm.dll members */
|
||||
/* Non-Storm.dll members */
|
||||
|
||||
unsigned int accessed; /* Was something from the file already read? */
|
||||
unsigned int accessed; /* Was something from the file already read? */
|
||||
} mpq_file;
|
||||
|
||||
/* List handle structure */
|
||||
typedef struct {
|
||||
unsigned char mpq_version[10]; /* libmpq version required by the listfile */
|
||||
unsigned char mpq_name[PATH_MAX]; /* mpq archive name without full path */
|
||||
unsigned char mpq_type[20]; /* mpq archive type */
|
||||
unsigned char mpq_game[40]; /* blizzard title the file matches */
|
||||
unsigned char mpq_game_version[10]; /* game version */
|
||||
unsigned char **mpq_files; /* filelist */
|
||||
unsigned char mpq_version[10]; /* libmpq version required by the listfile */
|
||||
unsigned char mpq_name[PATH_MAX]; /* mpq archive name without full path */
|
||||
unsigned char mpq_type[20]; /* mpq archive type */
|
||||
unsigned char mpq_game[40]; /* blizzard title the file matches */
|
||||
unsigned char mpq_game_version[10]; /* game version */
|
||||
unsigned char **mpq_files; /* filelist */
|
||||
} mpq_list;
|
||||
|
||||
/* Archive handle structure used since Diablo 1.00 */
|
||||
typedef struct {
|
||||
unsigned char filename[PATH_MAX]; /* Opened archive file name */
|
||||
int fd; /* File handle */
|
||||
unsigned int blockpos; /* Position of loaded block in the file */
|
||||
unsigned int blocksize; /* Size of file block */
|
||||
unsigned char *blockbuf; /* Buffer (cache) for file block */
|
||||
unsigned int bufpos; /* Position in block buffer */
|
||||
unsigned int mpqpos; /* MPQ archive position in the file */
|
||||
unsigned int filepos; /* Current file pointer */
|
||||
unsigned int openfiles; /* Number of open files + 1 */
|
||||
mpq_buffer buf; /* MPQ buffer */
|
||||
mpq_header *header; /* MPQ file header */
|
||||
mpq_hash *hashtable; /* Hash table */
|
||||
mpq_block *blocktable; /* Block table */
|
||||
unsigned char filename[PATH_MAX]; /* Opened archive file name */
|
||||
int fd; /* File handle */
|
||||
unsigned int blockpos; /* Position of loaded block in the file */
|
||||
unsigned int blocksize; /* Size of file block */
|
||||
unsigned char *blockbuf; /* Buffer (cache) for file block */
|
||||
unsigned int bufpos; /* Position in block buffer */
|
||||
unsigned int mpqpos; /* MPQ archive position in the file */
|
||||
unsigned int filepos; /* Current file pointer */
|
||||
unsigned int openfiles; /* Number of open files + 1 */
|
||||
mpq_buffer buf; /* MPQ buffer */
|
||||
mpq_header *header; /* MPQ file header */
|
||||
mpq_hash *hashtable; /* Hash table */
|
||||
mpq_block *blocktable; /* Block table */
|
||||
|
||||
/* Non-Storm.dll members */
|
||||
/* Non-Storm.dll members */
|
||||
|
||||
mpq_list *mpq_l; /* Handle to file list from database */
|
||||
mpq_list *mpq_l; /* Handle to file list from database */
|
||||
|
||||
unsigned int flags; /* See LIBMPQ_TOOLS_FLAG_XXXXX */
|
||||
unsigned int maxblockindex; /* The highest block table entry */
|
||||
unsigned int flags; /* See LIBMPQ_TOOLS_FLAG_XXXXX */
|
||||
unsigned int maxblockindex; /* The highest block table entry */
|
||||
} mpq_archive;
|
||||
|
||||
extern char *libmpq_version();
|
||||
@@ -213,13 +213,13 @@ extern int libmpq_wave_decompress_mono(char *out_buf, int *out_length, char *in_
|
||||
extern int libmpq_multi_decompress(char *out_buf, int *pout_length, char *in_buf, int in_length);
|
||||
|
||||
static decompress_table dcmp_table[] = {
|
||||
{0x08, libmpq_pkzip_decompress}, /* Decompression with Pkware Data Compression Library */
|
||||
{0x02, libmpq_zlib_decompress}, /* Decompression with the "zlib" library */
|
||||
{0x01, libmpq_huff_decompress}, /* Huffmann decompression */
|
||||
{0x80, libmpq_wave_decompress_stereo}, /* WAVE decompression for stereo waves */
|
||||
{0x40, libmpq_wave_decompress_mono} /* WAVE decompression for mono waves */
|
||||
{0x08, libmpq_pkzip_decompress}, /* Decompression with Pkware Data Compression Library */
|
||||
{0x02, libmpq_zlib_decompress}, /* Decompression with the "zlib" library */
|
||||
{0x01, libmpq_huff_decompress}, /* Huffmann decompression */
|
||||
{0x80, libmpq_wave_decompress_stereo}, /* WAVE decompression for stereo waves */
|
||||
{0x40, libmpq_wave_decompress_mono} /* WAVE decompression for mono waves */
|
||||
};
|
||||
|
||||
int libmpq_file_extract(mpq_archive *mpq_a, const int number, const char *filename);
|
||||
int libmpq_file_getdata(mpq_archive *mpq_a, mpq_hash mpq_h, const int number, unsigned char *dest);
|
||||
#endif /* _MPQ_H */
|
||||
#endif /* _MPQ_H */
|
||||
|
||||
+188
-188
@@ -34,21 +34,21 @@
|
||||
* deleted but \" would not.
|
||||
*/
|
||||
char *libmpq_conf_delete_char(char *buf, char *chars) {
|
||||
static char *temp;
|
||||
char ch;
|
||||
static char *temp;
|
||||
char ch;
|
||||
|
||||
temp = buf;
|
||||
temp = buf;
|
||||
|
||||
/* strip out special chars like " */
|
||||
while (temp = strpbrk(temp, chars)) {
|
||||
ch = temp[0];
|
||||
memmove(&temp[0], &temp[1], strlen(temp));
|
||||
if (ch == '\\') {
|
||||
temp++;
|
||||
}
|
||||
}
|
||||
/* strip out special chars like " */
|
||||
while (temp = strpbrk(temp, chars)) {
|
||||
ch = temp[0];
|
||||
memmove(&temp[0], &temp[1], strlen(temp));
|
||||
if (ch == '\\') {
|
||||
temp++;
|
||||
}
|
||||
}
|
||||
|
||||
return buf;
|
||||
return buf;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -56,65 +56,65 @@ char *libmpq_conf_delete_char(char *buf, char *chars) {
|
||||
* return 1 on success and the byte array or 0 and null.
|
||||
*/
|
||||
int libmpq_conf_parse_line(char *line, char *search_value, char *return_value, int size) {
|
||||
int level = 0;
|
||||
int found = 0;
|
||||
int i = 0;
|
||||
int pos = 0;
|
||||
int level = 0;
|
||||
int found = 0;
|
||||
int i = 0;
|
||||
int pos = 0;
|
||||
|
||||
/* search value */
|
||||
while (*(++line)) {
|
||||
/* search value */
|
||||
while (*(++line)) {
|
||||
|
||||
/* check for spaces */
|
||||
if (!isspace(*line) && level == 1) {
|
||||
/* check for spaces */
|
||||
if (!isspace(*line) && level == 1) {
|
||||
|
||||
/* we found our value so break */
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
/* we found our value so break */
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
/* check for '=' so the value follows as next parameter */
|
||||
if (*line == '=' && level == 0) {
|
||||
level = 1;
|
||||
}
|
||||
}
|
||||
/* check for '=' so the value follows as next parameter */
|
||||
if (*line == '=' && level == 0) {
|
||||
level = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* now search for comment in this line */
|
||||
for (i = 0; i < int(strlen(line)); i++) {
|
||||
if (line[i] == '#') {
|
||||
pos = i - 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* now search for comment in this line */
|
||||
for (i = 0; i < int(strlen(line)); i++) {
|
||||
if (line[i] == '#') {
|
||||
pos = i - 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* now set end of byte array behind value, but only if comment was found */
|
||||
if (pos != 0) {
|
||||
for (i = pos; i >= 0; i--) {
|
||||
if (line[i] != ' ' && line[i] != '\t') {
|
||||
line[i + 1] = '\0';
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* now set end of byte array behind value, but only if comment was found */
|
||||
if (pos != 0) {
|
||||
for (i = pos; i >= 0; i--) {
|
||||
if (line[i] != ' ' && line[i] != '\t') {
|
||||
line[i + 1] = '\0';
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* now check if line has trailing spaces */
|
||||
for (i = strlen(line); i >= 0; i--) {
|
||||
if (line[i] != ' ' && line[i] != '\t') {
|
||||
line[i + 1] = '\0';
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* now check if line has trailing spaces */
|
||||
for (i = strlen(line); i >= 0; i--) {
|
||||
if (line[i] != ' ' && line[i] != '\t') {
|
||||
line[i + 1] = '\0';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* now check if value is quoted with "" and if there is a char behind. */
|
||||
for (i = strlen(line); i >= 0; i--) {
|
||||
if (line[i] == '"') {
|
||||
line[i + 1] = '\0';
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* now check if value is quoted with "" and if there is a char behind. */
|
||||
for (i = strlen(line); i >= 0; i--) {
|
||||
if (line[i] == '"') {
|
||||
line[i + 1] = '\0';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* return the values */
|
||||
strncpy(return_value, line, size);
|
||||
return found;
|
||||
/* return the values */
|
||||
strncpy(return_value, line, size);
|
||||
return found;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -122,70 +122,70 @@ int libmpq_conf_parse_line(char *line, char *search_value, char *return_value, i
|
||||
* listdb or config file. On success it returns 1, otherwise 0.
|
||||
*/
|
||||
int libmpq_conf_get_value(FILE *fp, char *search_value, void *return_value, int type, int size) {
|
||||
char buf[LIBMPQ_CONF_BUFSIZE];
|
||||
int found = 0;
|
||||
int result = LIBMPQ_TOOLS_SUCCESS;
|
||||
char buf[LIBMPQ_CONF_BUFSIZE];
|
||||
int found = 0;
|
||||
int result = LIBMPQ_TOOLS_SUCCESS;
|
||||
|
||||
while (fgets(buf, LIBMPQ_CONF_BUFSIZE, fp) != NULL) {
|
||||
char *line;
|
||||
while (fgets(buf, LIBMPQ_CONF_BUFSIZE, fp) != NULL) {
|
||||
char *line;
|
||||
|
||||
buf[strlen(buf) - 1] = '\0';
|
||||
buf[strlen(buf) - 1] = '\0';
|
||||
|
||||
/* skip whitespace */
|
||||
for (line = buf; isspace(*line); line++) {
|
||||
continue;
|
||||
}
|
||||
/* skip whitespace */
|
||||
for (line = buf; isspace(*line); line++) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* skip empty line */
|
||||
if (line[0] == '\0') {
|
||||
continue;
|
||||
}
|
||||
/* skip empty line */
|
||||
if (line[0] == '\0') {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* skip comments */
|
||||
if (line[0] == '#') {
|
||||
continue;
|
||||
}
|
||||
/* skip comments */
|
||||
if (line[0] == '#') {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* process the line */
|
||||
//if (!strncasecmp(line, search_value, strlen(search_value))) {
|
||||
/* process the line */
|
||||
//if (!strncasecmp(line, search_value, strlen(search_value))) {
|
||||
if (!strcmp(line, search_value)) {
|
||||
found = libmpq_conf_parse_line(line, search_value, line, LIBMPQ_CONF_BUFSIZE);
|
||||
if (found == 1) {
|
||||
libmpq_conf_delete_char(line, "\"\\");
|
||||
found = libmpq_conf_parse_line(line, search_value, line, LIBMPQ_CONF_BUFSIZE);
|
||||
if (found == 1) {
|
||||
libmpq_conf_delete_char(line, "\"\\");
|
||||
|
||||
switch (type) {
|
||||
case LIBMPQ_CONF_TYPE_INT:
|
||||
switch (type) {
|
||||
case LIBMPQ_CONF_TYPE_INT:
|
||||
|
||||
/* if it is no valid number it is safe to return 0 */
|
||||
*(int *)return_value = atoi(line);
|
||||
break;
|
||||
default:
|
||||
strncpy((char *)return_value, line, size);
|
||||
break;
|
||||
}
|
||||
/* if it is no valid number it is safe to return 0 */
|
||||
*(int *)return_value = atoi(line);
|
||||
break;
|
||||
default:
|
||||
strncpy((char *)return_value, line, size);
|
||||
break;
|
||||
}
|
||||
|
||||
/* value found, so rewind stream */
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* value found, so rewind stream */
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* if value was not found */
|
||||
if (found == 0) {
|
||||
switch (type) {
|
||||
case LIBMPQ_CONF_TYPE_INT:
|
||||
*(int *)return_value = 0;
|
||||
result = LIBMPQ_CONF_EVALUE_NOT_FOUND;
|
||||
break;
|
||||
default:
|
||||
strncpy((char *)return_value, "", size);
|
||||
result = LIBMPQ_CONF_EVALUE_NOT_FOUND;
|
||||
break;
|
||||
}
|
||||
}
|
||||
fseek(fp, 0L, SEEK_SET);
|
||||
/* if value was not found */
|
||||
if (found == 0) {
|
||||
switch (type) {
|
||||
case LIBMPQ_CONF_TYPE_INT:
|
||||
*(int *)return_value = 0;
|
||||
result = LIBMPQ_CONF_EVALUE_NOT_FOUND;
|
||||
break;
|
||||
default:
|
||||
strncpy((char *)return_value, "", size);
|
||||
result = LIBMPQ_CONF_EVALUE_NOT_FOUND;
|
||||
break;
|
||||
}
|
||||
}
|
||||
fseek(fp, 0L, SEEK_SET);
|
||||
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -194,101 +194,101 @@ int libmpq_conf_get_value(FILE *fp, char *search_value, void *return_value, int
|
||||
* entries in the byte array. On success it returns 1, otherwise 0.
|
||||
*/
|
||||
int libmpq_conf_get_array(FILE *fp, char *search_value, char ***filelist, int *entries) {
|
||||
char buf[LIBMPQ_CONF_BUFSIZE];
|
||||
char temp[LIBMPQ_CONF_BUFSIZE];
|
||||
int level = 0;
|
||||
int array_start = 0;
|
||||
int array_end = 0;
|
||||
int fl_count;
|
||||
int fl_size;
|
||||
int found = 0;
|
||||
int i = 0;
|
||||
char buf[LIBMPQ_CONF_BUFSIZE];
|
||||
char temp[LIBMPQ_CONF_BUFSIZE];
|
||||
int level = 0;
|
||||
int array_start = 0;
|
||||
int array_end = 0;
|
||||
int fl_count;
|
||||
int fl_size;
|
||||
int found = 0;
|
||||
int i = 0;
|
||||
|
||||
*entries = 0;
|
||||
*entries = 0;
|
||||
|
||||
/* allocate memory for the file list */
|
||||
(*filelist) = (char **)malloc(LIBMPQ_CONF_FL_INCREMENT * sizeof(char *));
|
||||
fl_count = 0;
|
||||
fl_size = LIBMPQ_CONF_FL_INCREMENT;
|
||||
/* allocate memory for the file list */
|
||||
(*filelist) = (char **)malloc(LIBMPQ_CONF_FL_INCREMENT * sizeof(char *));
|
||||
fl_count = 0;
|
||||
fl_size = LIBMPQ_CONF_FL_INCREMENT;
|
||||
|
||||
while (fgets(buf, LIBMPQ_CONF_BUFSIZE, fp) != NULL) {
|
||||
char *line;
|
||||
while (fgets(buf, LIBMPQ_CONF_BUFSIZE, fp) != NULL) {
|
||||
char *line;
|
||||
|
||||
buf[strlen(buf) - 1] = '\0';
|
||||
buf[strlen(buf) - 1] = '\0';
|
||||
|
||||
/* skip whitespace */
|
||||
for (line = buf; isspace(*line); line++) {
|
||||
continue;
|
||||
}
|
||||
/* skip whitespace */
|
||||
for (line = buf; isspace(*line); line++) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* skip empty line */
|
||||
if (line[0] == '\0') {
|
||||
continue;
|
||||
}
|
||||
/* skip empty line */
|
||||
if (line[0] == '\0') {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* skip comments */
|
||||
if (line[0] == '#') {
|
||||
continue;
|
||||
}
|
||||
/* skip comments */
|
||||
if (line[0] == '#') {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* check for array end ) */
|
||||
if (*line == ')') {
|
||||
array_end = 1;
|
||||
break;
|
||||
}
|
||||
/* check for array end ) */
|
||||
if (*line == ')') {
|
||||
array_end = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
/* process entries between () */
|
||||
if (array_start == 1 && array_end == 0) {
|
||||
/* process entries between () */
|
||||
if (array_start == 1 && array_end == 0) {
|
||||
|
||||
/* add dummy option to use with libmpq_conf_parse_line() */
|
||||
strncpy(temp, "MPQ_BUFFER = ", LIBMPQ_CONF_BUFSIZE);
|
||||
strncat(temp, line, LIBMPQ_CONF_BUFSIZE);
|
||||
found = libmpq_conf_parse_line(temp, "MPQ_BUFFER", temp, LIBMPQ_CONF_BUFSIZE);
|
||||
/* add dummy option to use with libmpq_conf_parse_line() */
|
||||
strncpy(temp, "MPQ_BUFFER = ", LIBMPQ_CONF_BUFSIZE);
|
||||
strncat(temp, line, LIBMPQ_CONF_BUFSIZE);
|
||||
found = libmpq_conf_parse_line(temp, "MPQ_BUFFER", temp, LIBMPQ_CONF_BUFSIZE);
|
||||
|
||||
if (found == 1) {
|
||||
libmpq_conf_delete_char(temp, "\"\\");
|
||||
if (found == 1) {
|
||||
libmpq_conf_delete_char(temp, "\"\\");
|
||||
|
||||
/* set the next filelist entry to a copy of the file */
|
||||
(*filelist)[fl_count++] = _strdup(temp);
|
||||
/* set the next filelist entry to a copy of the file */
|
||||
(*filelist)[fl_count++] = _strdup(temp);
|
||||
|
||||
/* increase the array size */
|
||||
if (fl_count == fl_size) {
|
||||
(*filelist) = (char **)realloc((*filelist), (fl_size + LIBMPQ_CONF_FL_INCREMENT) * sizeof(char *));
|
||||
fl_size += LIBMPQ_CONF_FL_INCREMENT;
|
||||
}
|
||||
/* increase the array size */
|
||||
if (fl_count == fl_size) {
|
||||
(*filelist) = (char **)realloc((*filelist), (fl_size + LIBMPQ_CONF_FL_INCREMENT) * sizeof(char *));
|
||||
fl_size += LIBMPQ_CONF_FL_INCREMENT;
|
||||
}
|
||||
|
||||
/* increase number of entries */
|
||||
(*entries)++;
|
||||
}
|
||||
}
|
||||
/* increase number of entries */
|
||||
(*entries)++;
|
||||
}
|
||||
}
|
||||
|
||||
/* process the line and search array start */
|
||||
//if (!strncasecmp(line, search_value, strlen(search_value))) {
|
||||
/* process the line and search array start */
|
||||
//if (!strncasecmp(line, search_value, strlen(search_value))) {
|
||||
if (!strcmp(line, search_value)) {
|
||||
|
||||
/* search value */
|
||||
while (*(++line)) {
|
||||
/* search value */
|
||||
while (*(++line)) {
|
||||
|
||||
/* check for array start ( */
|
||||
if (*line == '(' && level == 1) {
|
||||
/* check for array start ( */
|
||||
if (*line == '(' && level == 1) {
|
||||
|
||||
/* we found our value so break */
|
||||
array_start = 1;
|
||||
break;
|
||||
}
|
||||
/* we found our value so break */
|
||||
array_start = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
/* check for '=' so the value follows as next parameter */
|
||||
if (*line == '=' && level == 0) {
|
||||
level = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/* check for '=' so the value follows as next parameter */
|
||||
if (*line == '=' && level == 0) {
|
||||
level = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* we got all files, so rewind stream */
|
||||
fseek(fp, 0L, SEEK_SET);
|
||||
/* we got all files, so rewind stream */
|
||||
fseek(fp, 0L, SEEK_SET);
|
||||
|
||||
(*filelist)[fl_count] = NULL;
|
||||
(*filelist)[fl_count] = NULL;
|
||||
|
||||
return found;
|
||||
return found;
|
||||
}
|
||||
|
||||
+137
-137
@@ -29,25 +29,25 @@
|
||||
|
||||
/* Tables necessary dor decompression */
|
||||
static unsigned long wave_table_1503f120[] = {
|
||||
0xFFFFFFFF, 0x00000000, 0xFFFFFFFF, 0x00000004, 0xFFFFFFFF, 0x00000002, 0xFFFFFFFF, 0x00000006,
|
||||
0xFFFFFFFF, 0x00000001, 0xFFFFFFFF, 0x00000005, 0xFFFFFFFF, 0x00000003, 0xFFFFFFFF, 0x00000007,
|
||||
0xFFFFFFFF, 0x00000001, 0xFFFFFFFF, 0x00000005, 0xFFFFFFFF, 0x00000003, 0xFFFFFFFF, 0x00000007,
|
||||
0xFFFFFFFF, 0x00000002, 0xFFFFFFFF, 0x00000004, 0xFFFFFFFF, 0x00000006, 0xFFFFFFFF, 0x00000008
|
||||
0xFFFFFFFF, 0x00000000, 0xFFFFFFFF, 0x00000004, 0xFFFFFFFF, 0x00000002, 0xFFFFFFFF, 0x00000006,
|
||||
0xFFFFFFFF, 0x00000001, 0xFFFFFFFF, 0x00000005, 0xFFFFFFFF, 0x00000003, 0xFFFFFFFF, 0x00000007,
|
||||
0xFFFFFFFF, 0x00000001, 0xFFFFFFFF, 0x00000005, 0xFFFFFFFF, 0x00000003, 0xFFFFFFFF, 0x00000007,
|
||||
0xFFFFFFFF, 0x00000002, 0xFFFFFFFF, 0x00000004, 0xFFFFFFFF, 0x00000006, 0xFFFFFFFF, 0x00000008
|
||||
};
|
||||
|
||||
static unsigned long wave_table_1503f1a0[] = {
|
||||
0x00000007, 0x00000008, 0x00000009, 0x0000000A, 0x0000000B, 0x0000000C, 0x0000000D, 0x0000000E,
|
||||
0x00000010, 0x00000011, 0x00000013, 0x00000015, 0x00000017, 0x00000019, 0x0000001C, 0x0000001F,
|
||||
0x00000022, 0x00000025, 0x00000029, 0x0000002D, 0x00000032, 0x00000037, 0x0000003C, 0x00000042,
|
||||
0x00000049, 0x00000050, 0x00000058, 0x00000061, 0x0000006B, 0x00000076, 0x00000082, 0x0000008F,
|
||||
0x0000009D, 0x000000AD, 0x000000BE, 0x000000D1, 0x000000E6, 0x000000FD, 0x00000117, 0x00000133,
|
||||
0x00000151, 0x00000173, 0x00000198, 0x000001C1, 0x000001EE, 0x00000220, 0x00000256, 0x00000292,
|
||||
0x000002D4, 0x0000031C, 0x0000036C, 0x000003C3, 0x00000424, 0x0000048E, 0x00000502, 0x00000583,
|
||||
0x00000610, 0x000006AB, 0x00000756, 0x00000812, 0x000008E0, 0x000009C3, 0x00000ABD, 0x00000BD0,
|
||||
0x00000CFF, 0x00000E4C, 0x00000FBA, 0x0000114C, 0x00001307, 0x000014EE, 0x00001706, 0x00001954,
|
||||
0x00001BDC, 0x00001EA5, 0x000021B6, 0x00002515, 0x000028CA, 0x00002CDF, 0x0000315B, 0x0000364B,
|
||||
0x00003BB9, 0x000041B2, 0x00004844, 0x00004F7E, 0x00005771, 0x0000602F, 0x000069CE, 0x00007462,
|
||||
0x00007FFF
|
||||
0x00000007, 0x00000008, 0x00000009, 0x0000000A, 0x0000000B, 0x0000000C, 0x0000000D, 0x0000000E,
|
||||
0x00000010, 0x00000011, 0x00000013, 0x00000015, 0x00000017, 0x00000019, 0x0000001C, 0x0000001F,
|
||||
0x00000022, 0x00000025, 0x00000029, 0x0000002D, 0x00000032, 0x00000037, 0x0000003C, 0x00000042,
|
||||
0x00000049, 0x00000050, 0x00000058, 0x00000061, 0x0000006B, 0x00000076, 0x00000082, 0x0000008F,
|
||||
0x0000009D, 0x000000AD, 0x000000BE, 0x000000D1, 0x000000E6, 0x000000FD, 0x00000117, 0x00000133,
|
||||
0x00000151, 0x00000173, 0x00000198, 0x000001C1, 0x000001EE, 0x00000220, 0x00000256, 0x00000292,
|
||||
0x000002D4, 0x0000031C, 0x0000036C, 0x000003C3, 0x00000424, 0x0000048E, 0x00000502, 0x00000583,
|
||||
0x00000610, 0x000006AB, 0x00000756, 0x00000812, 0x000008E0, 0x000009C3, 0x00000ABD, 0x00000BD0,
|
||||
0x00000CFF, 0x00000E4C, 0x00000FBA, 0x0000114C, 0x00001307, 0x000014EE, 0x00001706, 0x00001954,
|
||||
0x00001BDC, 0x00001EA5, 0x000021B6, 0x00002515, 0x000028CA, 0x00002CDF, 0x0000315B, 0x0000364B,
|
||||
0x00003BB9, 0x000041B2, 0x00004844, 0x00004F7E, 0x00005771, 0x0000602F, 0x000069CE, 0x00007462,
|
||||
0x00007FFF
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -56,130 +56,130 @@ static unsigned long wave_table_1503f1a0[] = {
|
||||
* Offset: 1500F230
|
||||
*/
|
||||
int libmpq_wave_decompress(unsigned char *out_buf, int out_length, unsigned char *in_buf, int in_length, int channels) {
|
||||
byte_and_short out;
|
||||
byte_and_short in;
|
||||
unsigned char *in_end = in_buf + in_length; /* End on input buffer */
|
||||
unsigned long index;
|
||||
long nr_array1[2];
|
||||
long nr_array2[2];
|
||||
int count = 0;
|
||||
byte_and_short out;
|
||||
byte_and_short in;
|
||||
unsigned char *in_end = in_buf + in_length; /* End on input buffer */
|
||||
unsigned long index;
|
||||
long nr_array1[2];
|
||||
long nr_array2[2];
|
||||
int count = 0;
|
||||
|
||||
out.pb = out_buf;
|
||||
in.pb = in_buf;
|
||||
nr_array1[0] = 0x2C;
|
||||
nr_array1[1] = 0x2C;
|
||||
in.pw++;
|
||||
out.pb = out_buf;
|
||||
in.pb = in_buf;
|
||||
nr_array1[0] = 0x2C;
|
||||
nr_array1[1] = 0x2C;
|
||||
in.pw++;
|
||||
|
||||
/* 15007AD7 */
|
||||
for (count = 0; count < channels; count++) {
|
||||
long temp;
|
||||
temp = *(short *)in.pw++;
|
||||
nr_array2[count] = temp;
|
||||
if (out_length < 2) {
|
||||
return out.pb - out_buf;
|
||||
}
|
||||
*out.pw++ = (unsigned short)temp;
|
||||
out_length -= 2;
|
||||
}
|
||||
index = channels - 1;
|
||||
while (in.pb < in_end) {
|
||||
unsigned char one_byte = *in.pb++;
|
||||
if (channels == 2) {
|
||||
index = (index == 0) ? 1 : 0;
|
||||
}
|
||||
/* 15007AD7 */
|
||||
for (count = 0; count < channels; count++) {
|
||||
long temp;
|
||||
temp = *(short *)in.pw++;
|
||||
nr_array2[count] = temp;
|
||||
if (out_length < 2) {
|
||||
return out.pb - out_buf;
|
||||
}
|
||||
*out.pw++ = (unsigned short)temp;
|
||||
out_length -= 2;
|
||||
}
|
||||
index = channels - 1;
|
||||
while (in.pb < in_end) {
|
||||
unsigned char one_byte = *in.pb++;
|
||||
if (channels == 2) {
|
||||
index = (index == 0) ? 1 : 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get one byte from input buffer
|
||||
* 15007B25
|
||||
*/
|
||||
if (one_byte & 0x80) {
|
||||
/* 15007B32 */
|
||||
switch(one_byte & 0x7F) {
|
||||
case 0: /* 15007B8E */
|
||||
if (nr_array1[index] != 0) {
|
||||
nr_array1[index]--;
|
||||
}
|
||||
if (out_length < 2) {
|
||||
break;
|
||||
}
|
||||
*out.pw++ = (unsigned short)nr_array2[index];
|
||||
out_length -= 2;
|
||||
continue;
|
||||
case 1: /* 15007B72 */
|
||||
nr_array1[index] += 8; /* EBX also */
|
||||
if (nr_array1[index] > 0x58) {
|
||||
nr_array1[index] = 0x58;
|
||||
}
|
||||
if (channels == 2) {
|
||||
index = (index == 0) ? 1 : 0;
|
||||
}
|
||||
continue;
|
||||
case 2:
|
||||
continue;
|
||||
default:
|
||||
nr_array1[index] -= 8;
|
||||
if (nr_array1[index] < 0) {
|
||||
nr_array1[index] = 0;
|
||||
}
|
||||
if (channels != 2) {
|
||||
continue;
|
||||
}
|
||||
index = (index == 0) ? 1 : 0;
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
unsigned long temp1 = wave_table_1503f1a0[nr_array1[index]]; /* EDI */
|
||||
unsigned long temp2 = temp1 >> in_buf[1]; /* ESI */
|
||||
long temp3 = nr_array2[index]; /* ECX */
|
||||
if (one_byte & 0x01) { /* EBX = one_byte */
|
||||
temp2 += (temp1 >> 0);
|
||||
}
|
||||
if (one_byte & 0x02) {
|
||||
temp2 += (temp1 >> 1);
|
||||
}
|
||||
if (one_byte & 0x04) {
|
||||
temp2 += (temp1 >> 2);
|
||||
}
|
||||
if (one_byte & 0x08) {
|
||||
temp2 += (temp1 >> 3);
|
||||
}
|
||||
if (one_byte & 0x10) {
|
||||
temp2 += (temp1 >> 4);
|
||||
}
|
||||
if (one_byte & 0x20) {
|
||||
temp2 += (temp1 >> 5);
|
||||
}
|
||||
if(one_byte & 0x40) {
|
||||
temp3 -= temp2;
|
||||
if (temp3 <= (long)0xFFFF8000) {
|
||||
temp3 = (long)0xFFFF8000;
|
||||
}
|
||||
} else {
|
||||
temp3 += temp2;
|
||||
if (temp3 >= 0x7FFF) {
|
||||
temp3 = 0x7FFF;
|
||||
}
|
||||
}
|
||||
nr_array2[index] = temp3;
|
||||
if (out_length < 2) {
|
||||
break;
|
||||
}
|
||||
/*
|
||||
* Get one byte from input buffer
|
||||
* 15007B25
|
||||
*/
|
||||
if (one_byte & 0x80) {
|
||||
/* 15007B32 */
|
||||
switch(one_byte & 0x7F) {
|
||||
case 0: /* 15007B8E */
|
||||
if (nr_array1[index] != 0) {
|
||||
nr_array1[index]--;
|
||||
}
|
||||
if (out_length < 2) {
|
||||
break;
|
||||
}
|
||||
*out.pw++ = (unsigned short)nr_array2[index];
|
||||
out_length -= 2;
|
||||
continue;
|
||||
case 1: /* 15007B72 */
|
||||
nr_array1[index] += 8; /* EBX also */
|
||||
if (nr_array1[index] > 0x58) {
|
||||
nr_array1[index] = 0x58;
|
||||
}
|
||||
if (channels == 2) {
|
||||
index = (index == 0) ? 1 : 0;
|
||||
}
|
||||
continue;
|
||||
case 2:
|
||||
continue;
|
||||
default:
|
||||
nr_array1[index] -= 8;
|
||||
if (nr_array1[index] < 0) {
|
||||
nr_array1[index] = 0;
|
||||
}
|
||||
if (channels != 2) {
|
||||
continue;
|
||||
}
|
||||
index = (index == 0) ? 1 : 0;
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
unsigned long temp1 = wave_table_1503f1a0[nr_array1[index]]; /* EDI */
|
||||
unsigned long temp2 = temp1 >> in_buf[1]; /* ESI */
|
||||
long temp3 = nr_array2[index]; /* ECX */
|
||||
if (one_byte & 0x01) { /* EBX = one_byte */
|
||||
temp2 += (temp1 >> 0);
|
||||
}
|
||||
if (one_byte & 0x02) {
|
||||
temp2 += (temp1 >> 1);
|
||||
}
|
||||
if (one_byte & 0x04) {
|
||||
temp2 += (temp1 >> 2);
|
||||
}
|
||||
if (one_byte & 0x08) {
|
||||
temp2 += (temp1 >> 3);
|
||||
}
|
||||
if (one_byte & 0x10) {
|
||||
temp2 += (temp1 >> 4);
|
||||
}
|
||||
if (one_byte & 0x20) {
|
||||
temp2 += (temp1 >> 5);
|
||||
}
|
||||
if(one_byte & 0x40) {
|
||||
temp3 -= temp2;
|
||||
if (temp3 <= (long)0xFFFF8000) {
|
||||
temp3 = (long)0xFFFF8000;
|
||||
}
|
||||
} else {
|
||||
temp3 += temp2;
|
||||
if (temp3 >= 0x7FFF) {
|
||||
temp3 = 0x7FFF;
|
||||
}
|
||||
}
|
||||
nr_array2[index] = temp3;
|
||||
if (out_length < 2) {
|
||||
break;
|
||||
}
|
||||
|
||||
temp2 = nr_array1[index];
|
||||
one_byte &= 0x1F;
|
||||
*out.pw++ = (unsigned short)temp3;
|
||||
out_length -= 2;
|
||||
temp2 += wave_table_1503f120[one_byte];
|
||||
nr_array1[index] = temp2;
|
||||
temp2 = nr_array1[index];
|
||||
one_byte &= 0x1F;
|
||||
*out.pw++ = (unsigned short)temp3;
|
||||
out_length -= 2;
|
||||
temp2 += wave_table_1503f120[one_byte];
|
||||
nr_array1[index] = temp2;
|
||||
|
||||
if (nr_array1[index] < 0) {
|
||||
nr_array1[index] = 0;
|
||||
} else {
|
||||
if (nr_array1[index] > 0x58) {
|
||||
nr_array1[index] = 0x58;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return (out.pb - out_buf);
|
||||
if (nr_array1[index] < 0) {
|
||||
nr_array1[index] = 0;
|
||||
} else {
|
||||
if (nr_array1[index] > 0x58) {
|
||||
nr_array1[index] = 0x58;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return (out.pb - out_buf);
|
||||
}
|
||||
|
||||
@@ -22,16 +22,16 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
*/
|
||||
|
||||
#ifndef _WAVE_H
|
||||
#define _WAVE_H
|
||||
|
||||
typedef union {
|
||||
unsigned short *pw;
|
||||
unsigned char *pb;
|
||||
unsigned short *pw;
|
||||
unsigned char *pb;
|
||||
} byte_and_short;
|
||||
|
||||
int libmpq_wave_decompress(unsigned char *out_buf, int out_length, unsigned char *in_buf, int in_length, int channels);
|
||||
|
||||
#endif /* _WAVE_H */
|
||||
#endif /* _WAVE_H */
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
/**
|
||||
@file AABSPTree.h
|
||||
|
||||
|
||||
@maintainer Morgan McGuire, matrix@graphics3d.com
|
||||
|
||||
|
||||
@created 2004-01-11
|
||||
@edited 2007-02-16
|
||||
|
||||
Copyright 2000-2007, Morgan McGuire.
|
||||
All rights reserved.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#ifndef G3D_AABSPTREE_H
|
||||
@@ -89,7 +89,7 @@ namespace G3D {
|
||||
|
||||
/**
|
||||
Wraps a pointer value so that it can be treated as the instance itself;
|
||||
convenient for inserting pointers into a Table but using the
|
||||
convenient for inserting pointers into a Table but using the
|
||||
object equality instead of pointer equality.
|
||||
*/
|
||||
template<class Type>
|
||||
@@ -136,9 +136,9 @@ namespace G3D {
|
||||
AABSPTree is as powerful as but more general than a Quad Tree, Oct
|
||||
Tree, or KD Tree, but less general than an unconstrained BSP tree
|
||||
(which is much slower to create).
|
||||
|
||||
|
||||
Internally, objects
|
||||
are arranged into an axis-aligned BSP-tree according to their
|
||||
are arranged into an axis-aligned BSP-tree according to their
|
||||
axis-aligned bounds. This increases the cost of insertion to
|
||||
O(log n) but allows fast overlap queries.
|
||||
|
||||
@@ -158,13 +158,13 @@ namespace G3D {
|
||||
<B>Moving %Set Members</B>
|
||||
<DT>It is important that objects do not move without updating the
|
||||
AABSPTree. If the axis-aligned bounds of an object are about
|
||||
to change, AABSPTree::remove it before they change and
|
||||
to change, AABSPTree::remove it before they change and
|
||||
AABSPTree::insert it again afterward. For objects
|
||||
where the hashCode and == operator are invariant with respect
|
||||
where the hashCode and == operator are invariant with respect
|
||||
to the 3D position,
|
||||
you can use the AABSPTree::update method as a shortcut to
|
||||
insert/remove an object in one step after it has moved.
|
||||
|
||||
|
||||
|
||||
Note: Do not mutate any value once it has been inserted into AABSPTree. Values
|
||||
are copied interally. All AABSPTree iterators convert to pointers to constant
|
||||
@@ -185,9 +185,9 @@ namespace G3D {
|
||||
*/
|
||||
namespace _AABSPTree {
|
||||
|
||||
/** Wrapper for a value that includes a cache of its bounds.
|
||||
/** Wrapper for a value that includes a cache of its bounds.
|
||||
Except for the test value used in a set-query operation, there
|
||||
is only ever one instance of the handle associated with any
|
||||
is only ever one instance of the handle associated with any
|
||||
value and the memberTable and Nodes maintain pointers to that
|
||||
heap-allocated value.
|
||||
*/
|
||||
@@ -201,7 +201,7 @@ namespace _AABSPTree {
|
||||
during the median sort, and because MSVC 6 std::sort goes into
|
||||
an infinite loop if we compute the midpoint on the fly (possibly
|
||||
a floating point roundoff issue, where B<A and A<B both are true).*/
|
||||
Vector3 center;
|
||||
Vector3 center;
|
||||
|
||||
TValue value;
|
||||
|
||||
@@ -261,10 +261,10 @@ public:
|
||||
|
||||
/** Returns the bounds of the sub array. Used by makeNode. */
|
||||
static AABox computeBounds(
|
||||
const Array<_AABSPTree::Handle<T>*>& point,
|
||||
const Array<_AABSPTree::Handle<T>*>& point,
|
||||
int beginIndex,
|
||||
int endIndex) {
|
||||
|
||||
|
||||
Vector3 lo = Vector3::inf();
|
||||
Vector3 hi = -lo;
|
||||
|
||||
@@ -279,11 +279,11 @@ public:
|
||||
/** Compares centers */
|
||||
class CenterComparator {
|
||||
public:
|
||||
Vector3::Axis sortAxis;
|
||||
Vector3::Axis sortAxis;
|
||||
|
||||
CenterComparator(Vector3::Axis a) : sortAxis(a) {}
|
||||
CenterComparator(Vector3::Axis a) : sortAxis(a) {}
|
||||
|
||||
inline int operator()(_AABSPTree::Handle<T>* A, const _AABSPTree::Handle<T>* B) const {
|
||||
inline int operator()(_AABSPTree::Handle<T>* A, const _AABSPTree::Handle<T>* B) const {
|
||||
float a = A->center[sortAxis];
|
||||
float b = B->center[sortAxis];
|
||||
|
||||
@@ -294,18 +294,18 @@ public:
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/** Compares bounds for strict >, <, or overlap*/
|
||||
class BoundsComparator {
|
||||
public:
|
||||
Vector3::Axis sortAxis;
|
||||
Vector3::Axis sortAxis;
|
||||
|
||||
BoundsComparator(Vector3::Axis a) : sortAxis(a) {}
|
||||
BoundsComparator(Vector3::Axis a) : sortAxis(a) {}
|
||||
|
||||
inline int operator()(_AABSPTree::Handle<T>* A, const _AABSPTree::Handle<T>* B) const {
|
||||
inline int operator()(_AABSPTree::Handle<T>* A, const _AABSPTree::Handle<T>* B) const {
|
||||
const AABox& a = A->bounds;
|
||||
const AABox& b = B->bounds;
|
||||
|
||||
@@ -316,33 +316,33 @@ public:
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/** Compares bounds to the sort location */
|
||||
class Comparator {
|
||||
public:
|
||||
Vector3::Axis sortAxis;
|
||||
float sortLocation;
|
||||
Vector3::Axis sortAxis;
|
||||
float sortLocation;
|
||||
|
||||
Comparator(Vector3::Axis a, float l) : sortAxis(a), sortLocation(l) {}
|
||||
Comparator(Vector3::Axis a, float l) : sortAxis(a), sortLocation(l) {}
|
||||
|
||||
inline int operator()(_AABSPTree::Handle<T>* ignore, const _AABSPTree::Handle<T>* handle) const {
|
||||
inline int operator()(_AABSPTree::Handle<T>* ignore, const _AABSPTree::Handle<T>* handle) const {
|
||||
const AABox& box = handle->bounds;
|
||||
debugAssert(ignore == NULL);
|
||||
|
||||
if (box.high()[sortAxis] < sortLocation) {
|
||||
if (box.high()[sortAxis] < sortLocation) {
|
||||
// Box is strictly below the sort location
|
||||
return -1;
|
||||
} else if (box.low()[sortAxis] > sortLocation) {
|
||||
} else if (box.low()[sortAxis] > sortLocation) {
|
||||
// Box is strictly above the sort location
|
||||
return 1;
|
||||
} else {
|
||||
return 1;
|
||||
} else {
|
||||
// Box overlaps the sort location
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Using System::malloc with this class provided no speed improvement.
|
||||
@@ -357,8 +357,8 @@ public:
|
||||
|
||||
/** Location along the specified axis */
|
||||
float splitLocation;
|
||||
|
||||
/** child[0] contains all values strictly
|
||||
|
||||
/** child[0] contains all values strictly
|
||||
smaller than splitLocation along splitAxis.
|
||||
|
||||
child[1] contains all values strictly
|
||||
@@ -371,15 +371,15 @@ public:
|
||||
|
||||
/** Array of values at this node (i.e., values
|
||||
straddling the split plane + all values if
|
||||
this is a leaf node).
|
||||
this is a leaf node).
|
||||
|
||||
This is an array of pointers because that minimizes
|
||||
data movement during tree building, which accounts
|
||||
data movement during tree building, which accounts
|
||||
for about 15% of the time cost of tree building.
|
||||
*/
|
||||
Array<_AABSPTree::Handle<T> * > valueArray;
|
||||
|
||||
/** For each object in the value array, a copy of its bounds.
|
||||
/** For each object in the value array, a copy of its bounds.
|
||||
Packing these into an array at the node level
|
||||
instead putting them in the valueArray improves
|
||||
cache coherence, which is about a 3x performance
|
||||
@@ -403,7 +403,7 @@ public:
|
||||
Node(const Node& other) : valueArray(other.valueArray), boundsArray(other.boundsArray) {
|
||||
splitAxis = other.splitAxis;
|
||||
splitLocation = other.splitLocation;
|
||||
splitBounds = other.splitBounds;
|
||||
splitBounds = other.splitBounds;
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
child[i] = NULL;
|
||||
}
|
||||
@@ -450,47 +450,47 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void verifyNode(const Vector3& lo, const Vector3& hi) {
|
||||
// debugPrintf("Verifying: split %d @ %f [%f, %f, %f], [%f, %f, %f]\n",
|
||||
// splitAxis, splitLocation, lo.x, lo.y, lo.z, hi.x, hi.y, hi.z);
|
||||
void verifyNode(const Vector3& lo, const Vector3& hi) {
|
||||
// debugPrintf("Verifying: split %d @ %f [%f, %f, %f], [%f, %f, %f]\n",
|
||||
// splitAxis, splitLocation, lo.x, lo.y, lo.z, hi.x, hi.y, hi.z);
|
||||
|
||||
debugAssert(lo == splitBounds.low());
|
||||
debugAssert(hi == splitBounds.high());
|
||||
|
||||
for (int i = 0; i < valueArray.length(); ++i) {
|
||||
const AABox& b = valueArray[i]->bounds;
|
||||
for (int i = 0; i < valueArray.length(); ++i) {
|
||||
const AABox& b = valueArray[i]->bounds;
|
||||
debugAssert(b == boundsArray[i]);
|
||||
|
||||
for(int axis = 0; axis < 3; ++axis) {
|
||||
debugAssert(b.low()[axis] <= b.high()[axis]);
|
||||
debugAssert(b.low()[axis] >= lo[axis]);
|
||||
debugAssert(b.high()[axis] <= hi[axis]);
|
||||
}
|
||||
}
|
||||
for(int axis = 0; axis < 3; ++axis) {
|
||||
debugAssert(b.low()[axis] <= b.high()[axis]);
|
||||
debugAssert(b.low()[axis] >= lo[axis]);
|
||||
debugAssert(b.high()[axis] <= hi[axis]);
|
||||
}
|
||||
}
|
||||
|
||||
if (child[0] || child[1]) {
|
||||
debugAssert(lo[splitAxis] < splitLocation);
|
||||
debugAssert(hi[splitAxis] > splitLocation);
|
||||
}
|
||||
if (child[0] || child[1]) {
|
||||
debugAssert(lo[splitAxis] < splitLocation);
|
||||
debugAssert(hi[splitAxis] > splitLocation);
|
||||
}
|
||||
|
||||
Vector3 newLo = lo;
|
||||
newLo[splitAxis] = splitLocation;
|
||||
Vector3 newHi = hi;
|
||||
newHi[splitAxis] = splitLocation;
|
||||
Vector3 newLo = lo;
|
||||
newLo[splitAxis] = splitLocation;
|
||||
Vector3 newHi = hi;
|
||||
newHi[splitAxis] = splitLocation;
|
||||
|
||||
if (child[0] != NULL) {
|
||||
child[0]->verifyNode(lo, newHi);
|
||||
}
|
||||
if (child[0] != NULL) {
|
||||
child[0]->verifyNode(lo, newHi);
|
||||
}
|
||||
|
||||
if (child[1] != NULL) {
|
||||
child[1]->verifyNode(newLo, hi);
|
||||
}
|
||||
}
|
||||
if (child[1] != NULL) {
|
||||
child[1]->verifyNode(newLo, hi);
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
/**
|
||||
Stores the locations of the splitting planes (the structure but not the content)
|
||||
so that the tree can be quickly rebuilt from a previous configuration without
|
||||
so that the tree can be quickly rebuilt from a previous configuration without
|
||||
calling balance.
|
||||
*/
|
||||
static void serializeStructure(const Node* n, BinaryOutput& bo) {
|
||||
@@ -546,7 +546,7 @@ public:
|
||||
}
|
||||
|
||||
|
||||
/** Appends all members that intersect the box.
|
||||
/** Appends all members that intersect the box.
|
||||
If useSphere is true, members that pass the box test
|
||||
face a second test against the sphere. */
|
||||
void getIntersectingMembers(
|
||||
@@ -604,11 +604,11 @@ public:
|
||||
// See if the ray will ever hit this node or its children
|
||||
Vector3 location;
|
||||
bool alreadyInsideBounds = false;
|
||||
bool rayWillHitBounds =
|
||||
bool rayWillHitBounds =
|
||||
VMAP::MyCollisionDetection::collisionLocationForMovingPointFixedAABox(
|
||||
ray.origin, ray.direction, splitBounds, location, alreadyInsideBounds);
|
||||
|
||||
bool canHitThisNode = (alreadyInsideBounds ||
|
||||
|
||||
bool canHitThisNode = (alreadyInsideBounds ||
|
||||
(rayWillHitBounds && ((location - ray.origin).squaredLength() < square(distance))));
|
||||
|
||||
return canHitThisNode;
|
||||
@@ -616,20 +616,20 @@ public:
|
||||
|
||||
template<typename RayCallback>
|
||||
void intersectRay(
|
||||
const Ray& ray,
|
||||
RayCallback& intersectCallback,
|
||||
const Ray& ray,
|
||||
RayCallback& intersectCallback,
|
||||
float& distance,
|
||||
bool pStopAtFirstHit,
|
||||
bool intersectCallbackIsFast) const {
|
||||
float enterDistance = distance;
|
||||
|
||||
|
||||
if (! intersects(ray, distance)) {
|
||||
// The ray doesn't hit this node, so it can't hit the children of the node.
|
||||
return;
|
||||
}
|
||||
|
||||
// Test for intersection against every object at this node.
|
||||
for (int v = 0; v < valueArray.size(); ++v) {
|
||||
for (int v = 0; v < valueArray.size(); ++v) {
|
||||
bool canHitThisObject = true;
|
||||
|
||||
if (! intersectCallbackIsFast) {
|
||||
@@ -637,11 +637,11 @@ public:
|
||||
Vector3 location;
|
||||
const AABox& bounds = boundsArray[v];
|
||||
bool alreadyInsideBounds = false;
|
||||
bool rayWillHitBounds =
|
||||
bool rayWillHitBounds =
|
||||
VMAP::MyCollisionDetection::collisionLocationForMovingPointFixedAABox(
|
||||
ray.origin, ray.direction, bounds, location, alreadyInsideBounds);
|
||||
|
||||
canHitThisObject = (alreadyInsideBounds ||
|
||||
canHitThisObject = (alreadyInsideBounds ||
|
||||
(rayWillHitBounds && ((location - ray.origin).squaredLength() < square(distance))));
|
||||
}
|
||||
|
||||
@@ -656,7 +656,7 @@ public:
|
||||
}
|
||||
|
||||
// There are three cases to consider next:
|
||||
//
|
||||
//
|
||||
// 1. the ray can start on one side of the splitting plane and never enter the other,
|
||||
// 2. the ray can start on one side and enter the other, and
|
||||
// 3. the ray can travel exactly down the splitting plane
|
||||
@@ -666,7 +666,7 @@ public:
|
||||
int secondChild = NONE;
|
||||
|
||||
if (ray.origin[splitAxis] < splitLocation) {
|
||||
|
||||
|
||||
// The ray starts on the small side
|
||||
firstChild = 0;
|
||||
|
||||
@@ -702,7 +702,7 @@ public:
|
||||
}
|
||||
|
||||
if (ray.direction[splitAxis] != 0) {
|
||||
// See if there was an intersection before hitting the splitting plane.
|
||||
// See if there was an intersection before hitting the splitting plane.
|
||||
// If so, there is no need to look on the far side and recursion terminates.
|
||||
float distanceToSplittingPlane = (splitLocation - ray.origin[splitAxis]) / ray.direction[splitAxis];
|
||||
if (distanceToSplittingPlane > distance) {
|
||||
@@ -724,43 +724,43 @@ public:
|
||||
|
||||
/**
|
||||
Recursively subdivides the subarray.
|
||||
|
||||
|
||||
Clears the source array as soon as it is no longer needed.
|
||||
|
||||
Call assignSplitBounds() on the root node after making a tree.
|
||||
*/
|
||||
Node* makeNode(
|
||||
Array<_AABSPTree::Handle<T> * >& source,
|
||||
int valuesPerNode,
|
||||
Array<_AABSPTree::Handle<T> * >& source,
|
||||
int valuesPerNode,
|
||||
int numMeanSplits,
|
||||
Array<_AABSPTree::Handle<T> * >& temp) {
|
||||
|
||||
Node* node = NULL;
|
||||
|
||||
if (source.size() <= valuesPerNode) {
|
||||
// Make a new leaf node
|
||||
node = new Node(source);
|
||||
|
||||
// Set the pointers in the memberTable
|
||||
for (int i = 0; i < source.size(); ++i) {
|
||||
memberTable.set(Member(source[i]), node);
|
||||
}
|
||||
Node* node = NULL;
|
||||
|
||||
if (source.size() <= valuesPerNode) {
|
||||
// Make a new leaf node
|
||||
node = new Node(source);
|
||||
|
||||
// Set the pointers in the memberTable
|
||||
for (int i = 0; i < source.size(); ++i) {
|
||||
memberTable.set(Member(source[i]), node);
|
||||
}
|
||||
source.clear();
|
||||
|
||||
|
||||
} else {
|
||||
// Make a new internal node
|
||||
node = new Node();
|
||||
|
||||
// Make a new internal node
|
||||
node = new Node();
|
||||
|
||||
const AABox bounds = computeBounds(source, 0, source.size() - 1);
|
||||
const Vector3 extent = bounds.high() - bounds.low();
|
||||
|
||||
Vector3::Axis splitAxis = extent.primaryAxis();
|
||||
|
||||
const Vector3 extent = bounds.high() - bounds.low();
|
||||
|
||||
Vector3::Axis splitAxis = extent.primaryAxis();
|
||||
|
||||
float splitLocation;
|
||||
|
||||
// Arrays for holding the children
|
||||
Array<_AABSPTree::Handle<T> * > lt, gt;
|
||||
|
||||
|
||||
if (numMeanSplits <= 0) {
|
||||
|
||||
source.medianPartition(lt, node->valueArray, gt, temp, CenterComparator(splitAxis));
|
||||
@@ -788,13 +788,13 @@ public:
|
||||
// is swapped in in its place.
|
||||
gt.fastRemove(i); --i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((node->valueArray.size() > (source.size() / 2)) &&
|
||||
(source.size() > 6)) {
|
||||
// This was a bad partition; we ended up putting the splitting plane right in the middle of most of the
|
||||
// objects. We could try to split on a different axis, or use a different partition (e.g., the extents mean,
|
||||
// or geometric mean). This implementation falls back on the extents mean, since that case is already handled
|
||||
// This was a bad partition; we ended up putting the splitting plane right in the middle of most of the
|
||||
// objects. We could try to split on a different axis, or use a different partition (e.g., the extents mean,
|
||||
// or geometric mean). This implementation falls back on the extents mean, since that case is already handled
|
||||
// below.
|
||||
numMeanSplits = 1;
|
||||
}
|
||||
@@ -805,9 +805,9 @@ public:
|
||||
|
||||
if (numMeanSplits > 0) {
|
||||
// Split along the mean
|
||||
splitLocation = (bounds.high()[splitAxis] +
|
||||
splitLocation = (bounds.high()[splitAxis] +
|
||||
bounds.low()[splitAxis]) / 2.0;
|
||||
|
||||
|
||||
source.partition(NULL, lt, node->valueArray, gt, Comparator(splitAxis, splitLocation));
|
||||
|
||||
// The Comparator ensures that elements are strictly on the correct side of the split
|
||||
@@ -817,7 +817,7 @@ public:
|
||||
# if defined(G3D_DEBUG) && defined(VERIFY_TREE)
|
||||
debugAssert(lt.size() + node->valueArray.size() + gt.size() == source.size());
|
||||
// Verify that all objects ended up on the correct side of the split.
|
||||
// (i.e., make sure that the Array partition was correct)
|
||||
// (i.e., make sure that the Array partition was correct)
|
||||
for (int i = 0; i < lt.size(); ++i) {
|
||||
const AABox& bounds = lt[i]->bounds;
|
||||
debugAssert(bounds.high()[splitAxis] < splitLocation);
|
||||
@@ -846,20 +846,20 @@ public:
|
||||
for (int i = 0; i < node->valueArray.size(); ++i) {
|
||||
_AABSPTree::Handle<T> * v = node->valueArray[i];
|
||||
node->boundsArray[i] = v->bounds;
|
||||
memberTable.set(Member(v), node);
|
||||
memberTable.set(Member(v), node);
|
||||
}
|
||||
|
||||
if (lt.size() > 0) {
|
||||
node->child[0] = makeNode(lt, valuesPerNode, numMeanSplits - 1, temp);
|
||||
}
|
||||
|
||||
if (gt.size() > 0) {
|
||||
node->child[1] = makeNode(gt, valuesPerNode, numMeanSplits - 1, temp);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return node;
|
||||
if (lt.size() > 0) {
|
||||
node->child[0] = makeNode(lt, valuesPerNode, numMeanSplits - 1, temp);
|
||||
}
|
||||
|
||||
if (gt.size() > 0) {
|
||||
node->child[1] = makeNode(gt, valuesPerNode, numMeanSplits - 1, temp);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -927,7 +927,7 @@ public:
|
||||
*/
|
||||
void clear() {
|
||||
typedef typename Table<_internal::Indirector<_AABSPTree::Handle<T> >, Node* >::Iterator It;
|
||||
|
||||
|
||||
// Delete all handles stored in the member table
|
||||
It cur = memberTable.begin();
|
||||
It end = memberTable.end();
|
||||
@@ -970,7 +970,7 @@ public:
|
||||
// Insert into the node
|
||||
node->valueArray.append(h);
|
||||
node->boundsArray.append(h->bounds);
|
||||
|
||||
|
||||
// Insert into the node table
|
||||
Member m(h);
|
||||
memberTable.set(m, node);
|
||||
@@ -1022,8 +1022,8 @@ public:
|
||||
/**
|
||||
Removes an object from the set in O(1) time.
|
||||
It is an error to remove members that are not already
|
||||
present. May unbalance the tree.
|
||||
|
||||
present. May unbalance the tree.
|
||||
|
||||
Removing an element never causes a node (split plane) to be removed...
|
||||
nodes are only changed when the tree is rebalanced. This behavior
|
||||
is desirable because it allows the split planes to be serialized,
|
||||
@@ -1075,7 +1075,7 @@ public:
|
||||
on <I>T</I> are independent of the bounds. In
|
||||
that case, you may call update(v) to insert an
|
||||
element for the first time and call update(v)
|
||||
again every time it moves to keep the tree
|
||||
again every time it moves to keep the tree
|
||||
up to date.
|
||||
*/
|
||||
void update(const T& value) {
|
||||
@@ -1091,15 +1091,15 @@ public:
|
||||
have moved substantially from their original positions
|
||||
(which unbalances the tree and causes the spatial
|
||||
queries to be slow).
|
||||
|
||||
|
||||
@param valuesPerNode Maximum number of elements to put at
|
||||
a node.
|
||||
|
||||
@param numMeanSplits numMeanSplits = 0 gives a
|
||||
@param numMeanSplits numMeanSplits = 0 gives a
|
||||
fully axis aligned BSP-tree, where the balance operation attempts to balance
|
||||
the tree so that every splitting plane has an equal number of left
|
||||
and right children (i.e. it is a <B>median</B> split along that axis).
|
||||
This tends to maximize average performance.
|
||||
and right children (i.e. it is a <B>median</B> split along that axis).
|
||||
This tends to maximize average performance.
|
||||
|
||||
You can override this behavior by
|
||||
setting a number of <B>mean</B> (average) splits. numMeanSplits = MAX_INT
|
||||
@@ -1126,7 +1126,7 @@ public:
|
||||
}
|
||||
|
||||
Array<_AABSPTree::Handle<T> * > temp;
|
||||
// Make a new root. Work with a copy of the value array because
|
||||
// Make a new root. Work with a copy of the value array because
|
||||
// makeNode clears the source array as it progresses
|
||||
Array<_AABSPTree::Handle<T> * > copy(oldRoot->valueArray);
|
||||
root = makeNode(copy, valuesPerNode, numMeanSplits, temp);
|
||||
@@ -1195,7 +1195,7 @@ protected:
|
||||
public:
|
||||
|
||||
/**
|
||||
Returns all members inside the set of planes.
|
||||
Returns all members inside the set of planes.
|
||||
@param members The results are appended to this array.
|
||||
*/
|
||||
void getIntersectingMembers(const Array<Plane>& plane, Array<T>& members) const {
|
||||
@@ -1221,7 +1221,7 @@ public:
|
||||
*/
|
||||
void getIntersectingMembers(const GCamera::Frustum& frustum, Array<T>& members) const {
|
||||
Array<Plane> plane;
|
||||
|
||||
|
||||
for (int i = 0; i < frustum.faceArray.size(); ++i) {
|
||||
plane.append(frustum.faceArray[i].plane);
|
||||
}
|
||||
@@ -1260,14 +1260,14 @@ public:
|
||||
// caller uses post increment (which they shouldn't!).
|
||||
Array<Node*> stack;
|
||||
|
||||
/** The next index of current->valueArray to return.
|
||||
/** The next index of current->valueArray to return.
|
||||
Undefined when isEnd is true.*/
|
||||
int nextValueArrayIndex;
|
||||
|
||||
BoxIntersectionIterator() : isEnd(true) {}
|
||||
|
||||
BoxIntersectionIterator(const AABox& b, const Node* root) :
|
||||
isEnd(root == NULL), box(b),
|
||||
|
||||
BoxIntersectionIterator(const AABox& b, const Node* root) :
|
||||
isEnd(root == NULL), box(b),
|
||||
node(const_cast<Node*>(root)), nextValueArrayIndex(-1) {
|
||||
|
||||
// We intentionally start at the "-1" index of the current
|
||||
@@ -1290,10 +1290,10 @@ public:
|
||||
} else if (other.isEnd) {
|
||||
return false;
|
||||
} else {
|
||||
// Two non-end iterators; see if they match. This is kind of
|
||||
// Two non-end iterators; see if they match. This is kind of
|
||||
// silly; users shouldn't call == on iterators in general unless
|
||||
// one of them is the end iterator.
|
||||
if ((box != other.box) || (node != other.node) ||
|
||||
if ((box != other.box) || (node != other.node) ||
|
||||
(nextValueArrayIndex != other.nextValueArrayIndex) ||
|
||||
(stack.length() != other.stack.length())) {
|
||||
return false;
|
||||
@@ -1317,51 +1317,51 @@ public:
|
||||
BoxIntersectionIterator& operator++() {
|
||||
++nextValueArrayIndex;
|
||||
|
||||
bool foundIntersection = false;
|
||||
bool foundIntersection = false;
|
||||
while (! isEnd && ! foundIntersection) {
|
||||
|
||||
// Search for the next node if we've exhausted this one
|
||||
// Search for the next node if we've exhausted this one
|
||||
while ((! isEnd) && (nextValueArrayIndex >= node->valueArray.length())) {
|
||||
// If we entered this loop, then the iterator has exhausted the elements at
|
||||
// node (possibly because it just switched to a child node with no members).
|
||||
// This loop continues until it finds a node with members or reaches
|
||||
// the end of the whole intersection search.
|
||||
// If we entered this loop, then the iterator has exhausted the elements at
|
||||
// node (possibly because it just switched to a child node with no members).
|
||||
// This loop continues until it finds a node with members or reaches
|
||||
// the end of the whole intersection search.
|
||||
|
||||
// If the right child overlaps the box, push it onto the stack for
|
||||
// processing.
|
||||
if ((node->child[1] != NULL) &&
|
||||
(box.high()[node->splitAxis] > node->splitLocation)) {
|
||||
stack.push(node->child[1]);
|
||||
}
|
||||
|
||||
// If the left child overlaps the box, push it onto the stack for
|
||||
// processing.
|
||||
if ((node->child[0] != NULL) &&
|
||||
(box.low()[node->splitAxis] < node->splitLocation)) {
|
||||
stack.push(node->child[0]);
|
||||
}
|
||||
// If the right child overlaps the box, push it onto the stack for
|
||||
// processing.
|
||||
if ((node->child[1] != NULL) &&
|
||||
(box.high()[node->splitAxis] > node->splitLocation)) {
|
||||
stack.push(node->child[1]);
|
||||
}
|
||||
|
||||
if (stack.length() > 0) {
|
||||
// Go on to the next node (which may be either one of the ones we
|
||||
// just pushed, or one from farther back the tree).
|
||||
node = stack.pop();
|
||||
nextValueArrayIndex = 0;
|
||||
} else {
|
||||
// That was the last node; we're done iterating
|
||||
isEnd = true;
|
||||
}
|
||||
}
|
||||
// If the left child overlaps the box, push it onto the stack for
|
||||
// processing.
|
||||
if ((node->child[0] != NULL) &&
|
||||
(box.low()[node->splitAxis] < node->splitLocation)) {
|
||||
stack.push(node->child[0]);
|
||||
}
|
||||
|
||||
// Search for the next intersection at this node until we run out of children
|
||||
while (! isEnd && ! foundIntersection && (nextValueArrayIndex < node->valueArray.length())) {
|
||||
if (box.intersects(node->boundsArray[nextValueArrayIndex])) {
|
||||
foundIntersection = true;
|
||||
} else {
|
||||
++nextValueArrayIndex;
|
||||
// If we exhaust this node, we'll loop around the master loop
|
||||
// to find a new node.
|
||||
}
|
||||
}
|
||||
if (stack.length() > 0) {
|
||||
// Go on to the next node (which may be either one of the ones we
|
||||
// just pushed, or one from farther back the tree).
|
||||
node = stack.pop();
|
||||
nextValueArrayIndex = 0;
|
||||
} else {
|
||||
// That was the last node; we're done iterating
|
||||
isEnd = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Search for the next intersection at this node until we run out of children
|
||||
while (! isEnd && ! foundIntersection && (nextValueArrayIndex < node->valueArray.length())) {
|
||||
if (box.intersects(node->boundsArray[nextValueArrayIndex])) {
|
||||
foundIntersection = true;
|
||||
} else {
|
||||
++nextValueArrayIndex;
|
||||
// If we exhaust this node, we'll loop around the master loop
|
||||
// to find a new node.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return *this;
|
||||
@@ -1431,7 +1431,7 @@ public:
|
||||
Invoke a callback for every member along a ray until the closest intersection is found.
|
||||
|
||||
@param callback either a function or an instance of a class with an overloaded operator() of the form:
|
||||
|
||||
|
||||
<code>void callback(const Ray& ray, const T& object, float& distance)</code>. If the ray hits the object
|
||||
before travelling distance <code>distance</code>, updates <code>distance</code> with the new distance to
|
||||
the intersection, otherwise leaves it unmodified. A common example is:
|
||||
@@ -1482,12 +1482,12 @@ public:
|
||||
*/
|
||||
template<typename RayCallback>
|
||||
void intersectRay(
|
||||
const Ray& ray,
|
||||
RayCallback& intersectCallback,
|
||||
const Ray& ray,
|
||||
RayCallback& intersectCallback,
|
||||
float& distance,
|
||||
bool pStopAtFirstHit,
|
||||
bool intersectCallbackIsFast = false) const {
|
||||
|
||||
|
||||
root->intersectRay(ray, intersectCallback, distance, pStopAtFirstHit, intersectCallbackIsFast);
|
||||
|
||||
}
|
||||
@@ -1509,7 +1509,7 @@ public:
|
||||
#if 0
|
||||
/**
|
||||
Stores the locations of the splitting planes (the structure but not the content)
|
||||
so that the tree can be quickly rebuilt from a previous configuration without
|
||||
so that the tree can be quickly rebuilt from a previous configuration without
|
||||
calling balance.
|
||||
*/
|
||||
void serializeStructure(BinaryOutput& bo) const {
|
||||
@@ -1593,9 +1593,9 @@ public:
|
||||
|
||||
|
||||
/**
|
||||
C++ STL style iterator method. Returns the first member.
|
||||
C++ STL style iterator method. Returns the first member.
|
||||
Use preincrement (++entry) to get to the next element (iteration
|
||||
order is arbitrary).
|
||||
order is arbitrary).
|
||||
Do not modify the set while iterating.
|
||||
*/
|
||||
Iterator begin() const {
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace VMAP
|
||||
Vector3 lo = Vector3(inf(), inf(), inf());
|
||||
Vector3 hi = Vector3(-inf(), -inf(), -inf());
|
||||
|
||||
for(int i=0; i< root->getNValues(); i++) {
|
||||
for(int i=0; i< root->getNValues(); i++) {
|
||||
SubModel sm = pModelContainer->getSubModel(root->getStartPosition() + i);
|
||||
lo = lo.min(sm.getAABoxBounds().low());
|
||||
hi = hi.max(sm.getAABoxBounds().high());
|
||||
@@ -502,7 +502,7 @@ namespace VMAP
|
||||
|
||||
if(ui->keyPressed(GKey::fromString("2"))) { //dec count1
|
||||
gCount1--;
|
||||
if(gCount1 < 0)
|
||||
if(gCount1 < 0)
|
||||
gCount1 = 0;
|
||||
}
|
||||
|
||||
@@ -529,7 +529,7 @@ namespace VMAP
|
||||
|
||||
|
||||
if(ui->keyPressed(GKey::LEFT_MOUSE)) {
|
||||
if( iCurrCmdIndex>0) {
|
||||
if( iCurrCmdIndex>0) {
|
||||
--iCurrCmdIndex;
|
||||
printf("restart last command\n");
|
||||
processCommand();
|
||||
|
||||
@@ -12,78 +12,78 @@
|
||||
|
||||
namespace VMAP
|
||||
{
|
||||
//==========================================
|
||||
//==========================================
|
||||
|
||||
|
||||
//==========================================
|
||||
//==========================================
|
||||
|
||||
class ModelContainerView :
|
||||
public G3D::GApp
|
||||
{
|
||||
private:
|
||||
class ModelContainerView :
|
||||
public G3D::GApp
|
||||
{
|
||||
private:
|
||||
SkyRef iSky;
|
||||
LightingRef iLighting;
|
||||
SkyParameters iSkyParameters;
|
||||
|
||||
VARAreaRef iVARAreaRef;
|
||||
Table<std::string , VAR*> iTriVarTable;
|
||||
Table<std::string , Array<int> > iTriIndexTable;
|
||||
VARAreaRef iVARAreaRef;
|
||||
Table<std::string , VAR*> iTriVarTable;
|
||||
Table<std::string , Array<int> > iTriIndexTable;
|
||||
|
||||
VARAreaRef iVARAreaRef2;
|
||||
VARAreaRef iVARAreaRef2;
|
||||
VAR iTriDebugVar;
|
||||
Array<Vector3> iVTriDebugArray;
|
||||
Array<int> iTriDebugArray;
|
||||
|
||||
//Array<int> iLineIndexArray;
|
||||
|
||||
GApp* i_App;
|
||||
CommandFileRW iCommandFileRW;
|
||||
Array<Command> iCmdArray;
|
||||
int iCurrCmdIndex;
|
||||
GApp* i_App;
|
||||
CommandFileRW iCommandFileRW;
|
||||
Array<Command> iCmdArray;
|
||||
int iCurrCmdIndex;
|
||||
|
||||
VMapManager* iVMapManager;
|
||||
VMapManager* iVMapManager;
|
||||
|
||||
Vector3 iPos1;
|
||||
Vector3 iPos2;
|
||||
Color3 iColor;
|
||||
bool iDrawLine;
|
||||
int iInstanceId;
|
||||
Vector3 iPos1;
|
||||
Vector3 iPos2;
|
||||
Color3 iColor;
|
||||
bool iDrawLine;
|
||||
int iInstanceId;
|
||||
bool iPosSent;
|
||||
Array<Command> iPrevLoadCommands;
|
||||
private:
|
||||
Vector3 convertPositionToTrinityRep(float x, float y, float z) const;
|
||||
private:
|
||||
Vector3 convertPositionToTrinityRep(float x, float y, float z) const;
|
||||
|
||||
public:
|
||||
ModelContainerView(const G3D::GApp::Settings& settings);
|
||||
public:
|
||||
ModelContainerView(const G3D::GApp::Settings& settings);
|
||||
|
||||
~ModelContainerView(void);
|
||||
~ModelContainerView(void);
|
||||
|
||||
void addModelContainer(const std::string& pName,const ModelContainer* pModelContainer);
|
||||
void removeModelContainer(const std::string& pName, const ModelContainer* pModelContainer);
|
||||
void setViewPosition(const Vector3& pPosition);
|
||||
void addModelContainer(const std::string& pName,const ModelContainer* pModelContainer);
|
||||
void removeModelContainer(const std::string& pName, const ModelContainer* pModelContainer);
|
||||
void setViewPosition(const Vector3& pPosition);
|
||||
|
||||
void onGraphics(RenderDevice* rd, Array<PosedModelRef> &posed3D, Array<PosedModel2DRef> &posed2D);
|
||||
void onGraphics(RenderDevice* rd, Array<PosedModelRef> &posed3D, Array<PosedModel2DRef> &posed2D);
|
||||
virtual void onInit();
|
||||
void init();
|
||||
void cleanup();
|
||||
void onUserInput(UserInput* ui);
|
||||
void cleanup();
|
||||
void onUserInput(UserInput* ui);
|
||||
|
||||
void fillRenderArray(const SubModel& pSm,Array<TriangleBox> &pArray, const TreeNode* pTreeNode);
|
||||
void fillVertexAndIndexArrays(const SubModel& pSm, Array<Vector3>& vArray, Array<int>& iArray);
|
||||
void fillRenderArray(const SubModel& pSm,Array<TriangleBox> &pArray, const TreeNode* pTreeNode);
|
||||
void fillVertexAndIndexArrays(const SubModel& pSm, Array<Vector3>& vArray, Array<int>& iArray);
|
||||
|
||||
bool loadAndShowTile(int pMapId, int x, int y);
|
||||
void showMap(int pMapId, int x, int y);
|
||||
bool loadAndShowTile(int pMapId, int x, int y);
|
||||
void showMap(int pMapId, int x, int y);
|
||||
|
||||
void showMap(MapTree* mt, std::string dirFileName);
|
||||
bool loadAndShowTile(int pMapId);
|
||||
void showMap(MapTree* mt, std::string dirFileName);
|
||||
bool loadAndShowTile(int pMapId);
|
||||
|
||||
|
||||
void processCommand();
|
||||
void processCommand();
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
//==========================================
|
||||
//==========================================
|
||||
//==========================================
|
||||
//==========================================
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
* Description: GfxDecode -- functions for reading Diablo's GFX files
|
||||
* Author: Marko Friedemann <marko.friedemann@bmx-chemnitz.de>
|
||||
* Created at: Son Jan 27 15:20:43 CET 2002
|
||||
* Computer: hangloose.flachland-chemnitz.de
|
||||
* Computer: hangloose.flachland-chemnitz.de
|
||||
* System: Linux 2.4.16 on i686
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2002 BMX-Chemnitz.DE All rights reserved.
|
||||
*
|
||||
* ---------------------------------------------------------------------
|
||||
@@ -60,12 +60,12 @@ static const uint16_t c_RampOffsetRight[17] = {
|
||||
2, // __ before this, there are 2 Pixels
|
||||
14, // + 12 --__ 4^2 - 2
|
||||
34, // + 20 --__ 6^2 - 2
|
||||
62, // + 28 this area --__ 8^2 - 2
|
||||
62, // + 28 this area --__ 8^2 - 2
|
||||
98, // + 36 is always --__ 10^2 - 2 pattern anyone? ;)
|
||||
142, // + 44 colored --__
|
||||
142, // + 44 colored --__
|
||||
194, // + 52 --__
|
||||
254, // + 60 lower ramp ends here --__ (-30 == 224)
|
||||
318, // + 64 upper ramp might be missing __--
|
||||
318, // + 64 upper ramp might be missing __--
|
||||
374, // + 56 __-- |
|
||||
422, // + 48 this area __-- | note that this
|
||||
462, // + 40 is always __-- | "drawing"
|
||||
@@ -133,7 +133,7 @@ class FrameBuf
|
||||
cerr << "\n +++ at (" << uCols << "," << uRows << "), see for yourself *** \n\n";
|
||||
uColorNum = TRANS_COL; // sane setting to avoid segfaults
|
||||
}
|
||||
|
||||
|
||||
memcpy(pCurrRow + 4*uCols, pPalette + 4*uColorNum, 4*sizeof(uint8_t));
|
||||
if (++uCols == uXSize)
|
||||
addLine();
|
||||
@@ -147,18 +147,18 @@ class FrameBuf
|
||||
vector <uint8_t *>::reverse_iterator vri;
|
||||
// allocate a buffer to hold the actual image size
|
||||
uint8_t *tmp = new uint8_t[4*uXSize*uRows];
|
||||
|
||||
|
||||
// the lines are upside down inside the vector, use reverse iterator
|
||||
for (i=0, vri=vecData.rbegin(); vri!=vecData.rend(); vri++, i++)
|
||||
memcpy(tmp+4*uXSize*i, *vri, 4*uXSize*sizeof(uint8_t));
|
||||
|
||||
|
||||
*upYSize = uRows; // set height
|
||||
|
||||
|
||||
if (uCols > 0) {
|
||||
cerr << "\n*** there seemed to be an error (last line does not match boundary, " << uCols << " pixels left)";
|
||||
cerr << "\n +++ this is often caused by specifying an invalid width, see for yourself *** \n\n";
|
||||
}
|
||||
|
||||
|
||||
return tmp;
|
||||
}
|
||||
};
|
||||
@@ -183,17 +183,17 @@ uint8_t *celDecodeBlocks(uint8_t *pFileBuf, FrameBuf *pFrame, uint32_t *framesta
|
||||
|
||||
if (!pFrame->bHasBlocks) // sanity check
|
||||
return NULL;
|
||||
|
||||
|
||||
while (uFilePos < framestart[pFrame->uFrameNum+1]) {
|
||||
cRead = pFileBuf[uFilePos++];
|
||||
|
||||
|
||||
if ((uFilePos == framestart[pFrame->uFrameNum]+1))
|
||||
// TODO: what is this 0x0A 0x00 stuff all about?
|
||||
if ((cRead == 0x0A) && (pFileBuf[uFilePos] == 0x00)) {
|
||||
uFilePos += 9;
|
||||
cRead = pFileBuf[uFilePos++];
|
||||
}
|
||||
|
||||
|
||||
if (cRead > 0x7F)
|
||||
// transparent block (complement, 256-val)
|
||||
for (i=0; i<256-cRead; i++)
|
||||
@@ -220,10 +220,10 @@ uint8_t *celDecodeRamps(uint8_t *pFileBuf, FrameBuf *pFrame, uint32_t *framestar
|
||||
uint32_t uFilePos=0;
|
||||
uint16_t uBlockLen=0, i=0, j=0;
|
||||
bool bFirstLonger=false;
|
||||
|
||||
|
||||
if (!pFrame->bHasRamps) // sanity check
|
||||
return NULL;
|
||||
|
||||
|
||||
if (pFrame->uXSize != 32) // only used in that case
|
||||
return NULL;
|
||||
|
||||
@@ -265,7 +265,7 @@ uint8_t *celDecodeRamps(uint8_t *pFileBuf, FrameBuf *pFrame, uint32_t *framestar
|
||||
pFrame->addPixel(pFileBuf[uFilePos++]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// now read the last 0x00 pair and fill up
|
||||
uBlockLen = (uFrameLen == c_2RampSize ? 30 : 2); // one or two ramps?
|
||||
uFilePos = framestart[pFrame->uFrameNum] + (bLeft ? c_RampOffsetLeft[i] : c_RampOffsetRight[i]) + 2;
|
||||
@@ -276,16 +276,16 @@ uint8_t *celDecodeRamps(uint8_t *pFileBuf, FrameBuf *pFrame, uint32_t *framestar
|
||||
for (j=0; j<pFrame->uXSize - uBlockLen; j++)
|
||||
pFrame->addPixel(pFileBuf[uFilePos++]);
|
||||
}
|
||||
|
||||
|
||||
// now the rest of the file (plain)
|
||||
while (uFilePos < framestart[pFrame->uFrameNum+1])
|
||||
pFrame->addPixel(pFileBuf[uFilePos++]);
|
||||
|
||||
|
||||
// the uppermost line is emtpy when 2 ramps are used
|
||||
if (uFrameLen == c_2RampSize)
|
||||
for (j=0; j<pFrame->uXSize; j++)
|
||||
pFrame->addPixel(TRANS_COL);
|
||||
|
||||
|
||||
return pFrame->getData();
|
||||
}
|
||||
|
||||
@@ -308,17 +308,17 @@ uint8_t *celDecodeRamps(uint8_t *pFileBuf, FrameBuf *pFrame, uint32_t *framestar
|
||||
* Comments: dirty hack, started from scratch @ 2000-10-11
|
||||
* cleanly rewritten during incorporation into ladiks StormLib
|
||||
* status: structured hack ;)
|
||||
*
|
||||
*
|
||||
* It took me approx. 6 days to understand the format basics (hex viewer)
|
||||
* For this I had a little help from a dos tool ("ddecode", from
|
||||
* www.cowlevel.com, binary only, no sources) which, however, gave
|
||||
* www.cowlevel.com, binary only, no sources) which, however, gave
|
||||
* me the general idea what the pictures are actually supposed to look like.
|
||||
*
|
||||
*
|
||||
* The fine adjustments, however, took quite some time and a little luck.
|
||||
* After I had written to various people (mickyk and ladik), which could
|
||||
* not help me, but wished best luck (thanks, btw, it helped ;)), I tried
|
||||
* some reverse engineering which was not succesful in the end.
|
||||
*
|
||||
*
|
||||
* I then had incidentally a new idea of what could be going on @ 2002-01-23.
|
||||
* It just came to my mind that I could retry some actual painting in
|
||||
* reverse order (had done that before to no avail) and when looking closer
|
||||
@@ -334,48 +334,48 @@ uint8_t * WINAPI celGetFrameData(uint8_t *pFileBuf, uint8_t *palette, uint16_t u
|
||||
uint32_t *framestart=NULL, frames=0, uFilePos=0;
|
||||
uint16_t i, tmpWord=0;
|
||||
uint8_t cRead=0, *data;
|
||||
|
||||
|
||||
memcpy(&frames, pFileBuf, sizeof(uint32_t));
|
||||
uFilePos += sizeof(uint32_t);
|
||||
|
||||
|
||||
if (pFileBuf == NULL) {
|
||||
SetLastError(ERROR_INVALID_PARAMETER);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
if (palette == NULL) {
|
||||
SetLastError(ERROR_INVALID_PARAMETER);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
if (uFrameNum > frames-1) {
|
||||
SetLastError(ERROR_INVALID_PARAMETER);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
if (uYSize == NULL) {
|
||||
SetLastError(ERROR_INVALID_PARAMETER);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
// in case we want to know the rightmost pixels column (usable eg. for fonts)
|
||||
if (uMaxX != NULL)
|
||||
*uMaxX = 0;
|
||||
|
||||
|
||||
// get the frame offsets
|
||||
framestart = new uint32_t[frames+1];
|
||||
for (i=0; i<frames+1; i++) {
|
||||
memcpy(&framestart[i], pFileBuf+uFilePos, sizeof(uint32_t));
|
||||
uFilePos += sizeof(uint32_t);
|
||||
}
|
||||
|
||||
|
||||
/****** block size *************************************************
|
||||
* depends on the image width
|
||||
******************************/
|
||||
|
||||
|
||||
double erg = rint(sqrt(pow(2, rint(log((double)(framestart[uFrameNum+1] - framestart[uFrameNum])) / log(2.0)))));
|
||||
pFrame = new FrameBuf(palette, uFrameNum, uXSize, uYSize, uMaxX, max((uint16_t)min((int)erg, 0x7F), uXSize));
|
||||
|
||||
|
||||
/****** ramp detection -- AFAIK only needed for 32x32 tiles ********
|
||||
* here I use hard coded constants because this is the only simple
|
||||
* way to get the detection done; plus this stuff is only to be
|
||||
@@ -385,7 +385,7 @@ uint8_t * WINAPI celGetFrameData(uint8_t *pFileBuf, uint8_t *palette, uint16_t u
|
||||
uint32_t uFrameLen = framestart[uFrameNum+1] - framestart[uFrameNum];
|
||||
if ((uXSize == 32) && ((uFrameLen == c_2RampSize) || (uFrameLen == c_1RampSize))) {
|
||||
|
||||
// use the static arrays for the check
|
||||
// use the static arrays for the check
|
||||
for (i=0; i<(uFrameLen == c_2RampSize ? 16 : 8); i++) {
|
||||
memcpy(&tmpWord, pFileBuf+framestart[uFrameNum]+c_RampOffsetLeft[i], sizeof(uint16_t));
|
||||
if (tmpWord != 0)
|
||||
@@ -400,7 +400,7 @@ uint8_t * WINAPI celGetFrameData(uint8_t *pFileBuf, uint8_t *palette, uint16_t u
|
||||
}
|
||||
pFrame->bHasRamps = (i==(uFrameLen == c_2RampSize ? 16 : 8)); // bRampsLeft stays false in this case
|
||||
}
|
||||
|
||||
|
||||
if (pFrame->bHasRamps) { // decode ramps and be off (if appropriate)
|
||||
data = celDecodeRamps(pFileBuf, pFrame, framestart, bRampsLeft);
|
||||
delete pFrame;
|
||||
@@ -408,25 +408,25 @@ uint8_t * WINAPI celGetFrameData(uint8_t *pFileBuf, uint8_t *palette, uint16_t u
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*********** block detection ***************************************
|
||||
* 0x0A as start byte seems to be sufficient (though I still dunno
|
||||
* what the trailing 10 bytes mean); in any other case we act as if
|
||||
* blocks were to be used and check afterwards if the image looks
|
||||
* OK (that is, the last line has no pixels in it)
|
||||
******************************************************************/
|
||||
|
||||
|
||||
cRead = pFileBuf[framestart[uFrameNum]];
|
||||
if (cRead == 0x0A) // sufficient
|
||||
pFrame->bHasBlocks = true;
|
||||
// if width == 32 && framelen == 32*32, assume plain
|
||||
else if ((uXSize != 32) || (uFrameLen != 32*32)) { // check needed
|
||||
uFilePos=framestart[uFrameNum];
|
||||
uFilePos=framestart[uFrameNum];
|
||||
i=0;
|
||||
// rush through the frame
|
||||
while (uFilePos < framestart[uFrameNum+1]) {
|
||||
cRead = pFileBuf[uFilePos++];
|
||||
|
||||
|
||||
// transparency blocks
|
||||
while (cRead > 0x7F) {
|
||||
i += 256-cRead;
|
||||
@@ -436,7 +436,7 @@ uint8_t * WINAPI celGetFrameData(uint8_t *pFileBuf, uint8_t *palette, uint16_t u
|
||||
else
|
||||
cRead = 0;
|
||||
}
|
||||
|
||||
|
||||
// colored pixel block
|
||||
if (uFilePos < framestart[uFrameNum+1]) {
|
||||
if (cRead < pFrame->uMaxBlock + 1) {
|
||||
@@ -453,19 +453,19 @@ uint8_t * WINAPI celGetFrameData(uint8_t *pFileBuf, uint8_t *palette, uint16_t u
|
||||
if (i%uXSize == 0) // looks as if we got it right
|
||||
pFrame->bHasBlocks=true;
|
||||
}
|
||||
|
||||
|
||||
if (pFrame->bHasBlocks) { // use block decoder if appropriate
|
||||
data = celDecodeBlocks(pFileBuf, pFrame, framestart);
|
||||
delete pFrame;
|
||||
delete[] framestart;
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
// plain mode (#3), read each color index and write the pixel
|
||||
uFilePos=framestart[uFrameNum];
|
||||
while (uFilePos < framestart[uFrameNum+1])
|
||||
pFrame->addPixel(pFileBuf[uFilePos++]);
|
||||
|
||||
|
||||
// cleanup, return image data and height
|
||||
data = pFrame->getData();
|
||||
delete pFrame;
|
||||
@@ -496,7 +496,7 @@ uint16_t WINAPI cl2GetFrameCount(uint8_t *pFileBuf)
|
||||
*
|
||||
* ---------------------------------------------------------------
|
||||
* Comments: dirty hack, started from scratch @ 2000-10-12
|
||||
*
|
||||
*
|
||||
* The format basics are similar to .cel, with the main difference
|
||||
* that the values read have reverse interpretation. In .cel a value
|
||||
* greater than 0x7F means transparency, while in .cl2 this means
|
||||
@@ -507,7 +507,7 @@ uint16_t WINAPI cl2GetFrameCount(uint8_t *pFileBuf)
|
||||
* .cl2 only uses the block scheme, so there is no detection
|
||||
* necessary in order to get it right. The only thing still unknown
|
||||
* is that 0x0A 0x00 stuff...
|
||||
*
|
||||
*
|
||||
* TODO: learn what 0x0A 0x00 means
|
||||
***********************************************************************/
|
||||
BYTE ** WINAPI cl2GetDirData(BYTE *pFileBuf, BYTE *palette, WORD uXSize, WORD uDirNum, WORD *uYSize)
|
||||
@@ -516,27 +516,27 @@ BYTE ** WINAPI cl2GetDirData(BYTE *pFileBuf, BYTE *palette, WORD uXSize, WORD uD
|
||||
uint32_t frames=0, *framestart=NULL, uFilePos=0;
|
||||
uint16_t i, fc;
|
||||
uint8_t cRead=0, **data=NULL;
|
||||
|
||||
|
||||
if (pFileBuf == NULL) {
|
||||
SetLastError(ERROR_INVALID_PARAMETER);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
if (palette == NULL) {
|
||||
SetLastError(ERROR_INVALID_PARAMETER);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
if (uDirNum > 7) {
|
||||
SetLastError(ERROR_INVALID_PARAMETER);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
if (uYSize == NULL) {
|
||||
SetLastError(ERROR_INVALID_PARAMETER);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
// get direction offsets
|
||||
uint32_t dirstart[8];
|
||||
for (i=0; i<8; i++) {
|
||||
@@ -545,23 +545,23 @@ BYTE ** WINAPI cl2GetDirData(BYTE *pFileBuf, BYTE *palette, WORD uXSize, WORD uD
|
||||
}
|
||||
|
||||
uFilePos = dirstart[uDirNum];
|
||||
|
||||
|
||||
memcpy(&frames, pFileBuf+uFilePos, sizeof(uint32_t));
|
||||
uFilePos += sizeof(uint32_t);
|
||||
|
||||
|
||||
data = new uint8_t*[frames];
|
||||
|
||||
|
||||
// get frame offsets
|
||||
framestart = new uint32_t[frames+1];
|
||||
for (i=0; i<frames+1; i++) {
|
||||
memcpy(&framestart[i], pFileBuf+uFilePos, sizeof(uint32_t));
|
||||
uFilePos += sizeof(uint32_t);
|
||||
}
|
||||
|
||||
// get frame data
|
||||
|
||||
// get frame data
|
||||
for (fc=0; fc<frames; fc++) {
|
||||
pFrame = new FrameBuf(palette, 0, uXSize, uYSize, NULL, 0);
|
||||
|
||||
|
||||
uFilePos = dirstart[uDirNum] + framestart[fc];
|
||||
while (uFilePos < dirstart[uDirNum] + framestart[fc+1]) {
|
||||
|
||||
@@ -583,12 +583,12 @@ BYTE ** WINAPI cl2GetDirData(BYTE *pFileBuf, BYTE *palette, WORD uXSize, WORD uD
|
||||
for (i=0; i < 256-cRead; i++)
|
||||
pFrame->addPixel(pFileBuf[uFilePos++]);
|
||||
}
|
||||
|
||||
|
||||
// got the frame data, save it
|
||||
data[fc] = pFrame->getData();
|
||||
delete pFrame;
|
||||
}
|
||||
|
||||
|
||||
delete[] framestart;
|
||||
return data;
|
||||
}
|
||||
@@ -616,7 +616,7 @@ BYTE * WINAPI pcxGetData(BYTE *pFileBuf, DWORD uFileSize, BYTE uTransColor, WORD
|
||||
uint16_t i=0;
|
||||
uint8_t *data, *palette;
|
||||
uint8_t uColorNum=0, uCount=0;
|
||||
|
||||
|
||||
struct pcx_header_t {
|
||||
uint8_t id;
|
||||
uint8_t version;
|
||||
@@ -635,17 +635,17 @@ BYTE * WINAPI pcxGetData(BYTE *pFileBuf, DWORD uFileSize, BYTE uTransColor, WORD
|
||||
uint16_t colortype;
|
||||
uint8_t pad[58];
|
||||
} pcxHeader;
|
||||
|
||||
|
||||
if (pFileBuf == NULL) {
|
||||
SetLastError(ERROR_INVALID_PARAMETER);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
if (uXSize == NULL) {
|
||||
SetLastError(ERROR_INVALID_PARAMETER);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
if (uYSize == NULL) {
|
||||
SetLastError(ERROR_INVALID_PARAMETER);
|
||||
return NULL;
|
||||
@@ -655,12 +655,12 @@ BYTE * WINAPI pcxGetData(BYTE *pFileBuf, DWORD uFileSize, BYTE uTransColor, WORD
|
||||
memcpy(&pcxHeader, pFileBuf, sizeof(struct pcx_header_t));
|
||||
*uXSize = (pcxHeader.x1 - pcxHeader.x0 + 1);
|
||||
*uYSize = (pcxHeader.y1 - pcxHeader.y0 + 1);
|
||||
|
||||
|
||||
if ((pcxHeader.version != 2) && (pcxHeader.version != 5)) {
|
||||
cerr << "cannot handle pcx v" << pcxHeader.version << "\n";
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
// get palette
|
||||
palette = new uint8_t[256*4];
|
||||
if (pFileBuf[uFileSize - 768 - 1] != 0x0C) {
|
||||
@@ -672,7 +672,7 @@ BYTE * WINAPI pcxGetData(BYTE *pFileBuf, DWORD uFileSize, BYTE uTransColor, WORD
|
||||
palette[i*4+3] = 0xFF;
|
||||
}
|
||||
memset(palette+uTransColor*4, 0, 4*sizeof(uint8_t)); // transparent black
|
||||
|
||||
|
||||
// start right after the header
|
||||
uFilePos = sizeof(struct pcx_header_t);
|
||||
data = new uint8_t[*uXSize * *uYSize * 4];
|
||||
@@ -684,14 +684,14 @@ BYTE * WINAPI pcxGetData(BYTE *pFileBuf, DWORD uFileSize, BYTE uTransColor, WORD
|
||||
uColorNum = pFileBuf[uFilePos++];
|
||||
} else
|
||||
uCount = 1;
|
||||
|
||||
|
||||
// draw count pixels with color val
|
||||
for (i=0; i<uCount; i++)
|
||||
memcpy(data+(uDataRead++)*4, palette+uColorNum*4, 4*sizeof(uint8_t));
|
||||
}
|
||||
|
||||
|
||||
// cleanup
|
||||
delete[] palette;
|
||||
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ USHORT wPlatform = 0; // File platform
|
||||
//-----------------------------------------------------------------------------
|
||||
// Compression types
|
||||
|
||||
//
|
||||
//
|
||||
// Data compressions
|
||||
//
|
||||
// Can be combination of MPQ_COMPRESSION_PKWARE, MPQ_COMPRESSION_BZIP2
|
||||
@@ -261,16 +261,16 @@ DWORD DetectFileSeed2(DWORD * pdwBlock, UINT nDwords, ...)
|
||||
DWORD saveSeed1;
|
||||
DWORD dwTemp;
|
||||
DWORD i, j;
|
||||
|
||||
|
||||
// We need at least two DWORDS to detect the seed
|
||||
if(nDwords < 0x02 || nDwords > 0x10)
|
||||
return 0;
|
||||
|
||||
|
||||
va_start(argList, nDwords);
|
||||
for(i = 0; i < nDwords; i++)
|
||||
dwDecrypted[i] = va_arg(argList, DWORD);
|
||||
va_end(argList);
|
||||
|
||||
|
||||
dwTemp = (*pdwBlock ^ dwDecrypted[0]) - 0xEEEEEEEE;
|
||||
for(i = 0; i < 0x100; i++) // Try all 255 possibilities
|
||||
{
|
||||
@@ -427,7 +427,7 @@ TMPQHash * GetHashEntry(TMPQArchive * ha, const char * szFileName)
|
||||
// If filename is given by index, we have to search all hash entries for the right index.
|
||||
if(dwIndex <= ha->pHeader->dwBlockTableSize)
|
||||
{
|
||||
// Pass all the hash entries and find the
|
||||
// Pass all the hash entries and find the
|
||||
for(pHash = ha->pHashTable; pHash < pHashEnd; pHash++)
|
||||
{
|
||||
if(pHash->dwBlockIndex == dwIndex)
|
||||
@@ -441,7 +441,7 @@ TMPQHash * GetHashEntry(TMPQArchive * ha, const char * szFileName)
|
||||
dwName1 = DecryptName1(szFileName);
|
||||
dwName2 = DecryptName2(szFileName);
|
||||
pHash = pHash0 = ha->pHashTable + dwIndex;
|
||||
|
||||
|
||||
// Look for hash index
|
||||
while(pHash->dwBlockIndex != HASH_ENTRY_FREE)
|
||||
{
|
||||
@@ -562,7 +562,7 @@ BOOL IsValidMpqHandle(TMPQArchive * ha)
|
||||
return FALSE;
|
||||
if(ha->pHeader == NULL || IsBadReadPtr(ha->pHeader, sizeof(TMPQHeader)))
|
||||
return FALSE;
|
||||
|
||||
|
||||
return (ha->pHeader->dwID == ID_MPQ);
|
||||
}
|
||||
|
||||
@@ -620,7 +620,7 @@ int AddFileToArchive(
|
||||
{
|
||||
if(nFileType == SFILE_TYPE_DATA)
|
||||
nCmpFirst = nCmpNext = nDataCmp;
|
||||
|
||||
|
||||
if(nFileType == SFILE_TYPE_WAVE)
|
||||
{
|
||||
nCmpNext = uWaveCmpType[dwQuality];
|
||||
@@ -721,7 +721,7 @@ int AddFileToArchive(
|
||||
// Get pointers to both block entries of the file
|
||||
pBlockEx = ha->pExtBlockTable + pHash->dwBlockIndex;
|
||||
pBlock = ha->pBlockTable + pHash->dwBlockIndex;
|
||||
|
||||
|
||||
// Save the file size info
|
||||
pBlockEx->wFilePosHigh = (USHORT)RelativePos.HighPart;
|
||||
pBlock->dwFilePos = RelativePos.LowPart;
|
||||
@@ -735,7 +735,7 @@ int AddFileToArchive(
|
||||
if(dwFlags & MPQ_FILE_ENCRYPTED)
|
||||
{
|
||||
dwSeed1 = DecryptFileSeed(szArchivedName);
|
||||
|
||||
|
||||
if(dwFlags & MPQ_FILE_FIXSEED)
|
||||
dwSeed1 = (dwSeed1 + pBlock->dwFilePos) ^ pBlock->dwFSize;
|
||||
}
|
||||
@@ -785,7 +785,7 @@ int AddFileToArchive(
|
||||
|
||||
memset(pdwBlockPos, 0, dwBlockPosLen);
|
||||
pdwBlockPos[0] = dwBlockPosLen;
|
||||
|
||||
|
||||
// Write the block positions
|
||||
BSWAP_ARRAY32_UNSIGNED((DWORD *)pdwBlockPos, nBlocks);
|
||||
WriteFile(ha->hFile, pdwBlockPos, dwBlockPosLen, &dwTransferred, NULL);
|
||||
@@ -852,7 +852,7 @@ int AddFileToArchive(
|
||||
EncryptMPQBlock((DWORD *)pbToWrite, dwOutLength, dwSeed1 + nBlock);
|
||||
BSWAP_ARRAY32_UNSIGNED((DWORD *)pbToWrite, dwOutLength / sizeof(DWORD));
|
||||
}
|
||||
|
||||
|
||||
// Write the block
|
||||
WriteFile(ha->hFile, pbToWrite, dwOutLength, &dwTransferred, NULL);
|
||||
if(dwTransferred != dwOutLength)
|
||||
@@ -876,10 +876,10 @@ int AddFileToArchive(
|
||||
// If file is encrypted, block positions are also encrypted
|
||||
if(dwFlags & MPQ_FILE_ENCRYPTED)
|
||||
EncryptMPQBlock(pdwBlockPos, dwBlockPosLen, dwSeed1 - 1);
|
||||
|
||||
|
||||
// Set the position back to the block table
|
||||
SetFilePointer(ha->hFile, FilePos.LowPart, &FilePos.HighPart, FILE_BEGIN);
|
||||
|
||||
|
||||
// Write block positions to the archive
|
||||
BSWAP_ARRAY32_UNSIGNED((DWORD *)pdwBlockPos, nBlocks);
|
||||
WriteFile(ha->hFile, pdwBlockPos, dwBlockPosLen, &dwTransferred, NULL);
|
||||
@@ -1015,7 +1015,7 @@ int SaveMPQTables(TMPQArchive * ha)
|
||||
|
||||
// Encrypt the block table and write it to the file
|
||||
EncryptBlockTable((DWORD *)pbBuffer, (BYTE *)"(block table)", dwBytes >> 2);
|
||||
|
||||
|
||||
// Convert to little endian for file save
|
||||
BSWAP_ARRAY32_UNSIGNED((DWORD *)pbBuffer, dwBytes / sizeof(DWORD));
|
||||
WriteFile(ha->hFile, pbBuffer, dwBytes, &dwWritten, NULL);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
/* SCompression.cpp Copyright (c) Ladislav Zezula 2003 */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* This module serves as a bridge between StormLib code and (de)compression */
|
||||
/* functions. All (de)compression calls go (and should only go) through this */
|
||||
/* functions. All (de)compression calls go (and should only go) through this */
|
||||
/* module. No system headers should be included in this module to prevent */
|
||||
/* compile-time problems. */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
@@ -19,7 +19,7 @@
|
||||
#include <string.h>
|
||||
|
||||
// Include functions from Pkware Data Compression Library
|
||||
#include "pklib/pklib.h"
|
||||
#include "pklib/pklib.h"
|
||||
|
||||
// Include functions from zlib
|
||||
#ifndef __SYS_ZLIB
|
||||
@@ -29,10 +29,10 @@
|
||||
#endif
|
||||
|
||||
// Include functions from Huffmann compression
|
||||
#include "huffman/huff.h"
|
||||
#include "huffman/huff.h"
|
||||
|
||||
// Include functions from WAVe compression
|
||||
#include "wave/wave.h"
|
||||
#include "wave/wave.h"
|
||||
|
||||
// Include functions from BZip2 compression library
|
||||
#ifndef __SYS_BZLIB
|
||||
@@ -57,7 +57,7 @@ typedef struct
|
||||
|
||||
// Table of compression functions
|
||||
typedef int (*COMPRESS)(char *, int *, char *, int, int *, int);
|
||||
typedef struct
|
||||
typedef struct
|
||||
{
|
||||
unsigned long dwMask; // Compression mask
|
||||
COMPRESS Compress; // Compression function
|
||||
@@ -81,7 +81,7 @@ typedef struct
|
||||
// Function loads data from the input buffer. Used by Pklib's "implode"
|
||||
// and "explode" function as user-defined callback
|
||||
// Returns number of bytes loaded
|
||||
//
|
||||
//
|
||||
// char * buf - Pointer to a buffer where to store loaded data
|
||||
// unsigned int * size - Max. number of bytes to read
|
||||
// void * param - Custom pointer, parameter of implode/explode
|
||||
@@ -95,7 +95,7 @@ static unsigned int ReadInputData(char * buf, unsigned int * size, void * param)
|
||||
// Check the case when not enough data available
|
||||
if(nToRead > nMaxAvail)
|
||||
nToRead = nMaxAvail;
|
||||
|
||||
|
||||
// Load data and increment offsets
|
||||
memcpy(buf, pInfo->pInBuff + pInfo->nInPos, nToRead);
|
||||
pInfo->nInPos += nToRead;
|
||||
@@ -105,7 +105,7 @@ static unsigned int ReadInputData(char * buf, unsigned int * size, void * param)
|
||||
|
||||
// Function for store output data. Used by Pklib's "implode" and "explode"
|
||||
// as user-defined callback
|
||||
//
|
||||
//
|
||||
// char * buf - Pointer to data to be written
|
||||
// unsigned int * size - Number of bytes to write
|
||||
// void * param - Custom pointer, parameter of implode/explode
|
||||
@@ -272,7 +272,7 @@ int Compress_zlib(char * pbOutBuffer, int * pdwOutLength, char * pbInBuffer, int
|
||||
{
|
||||
// Call zlib to compress the data
|
||||
nResult = deflate(&z, Z_FINISH);
|
||||
|
||||
|
||||
if(nResult == Z_OK || nResult == Z_STREAM_END)
|
||||
*pdwOutLength = z.total_out;
|
||||
|
||||
@@ -359,7 +359,7 @@ int Decompress_pklib(char * pbOutBuffer, int * pdwOutLength, char * pbInBuffer,
|
||||
|
||||
// Do the decompression
|
||||
explode(ReadInputData, WriteOutputData, work_buf, &Info);
|
||||
|
||||
|
||||
// Fix: If PKLIB is unable to decompress the data, they are uncompressed
|
||||
if(Info.nOutPos == 0)
|
||||
{
|
||||
@@ -487,7 +487,7 @@ int WINAPI SCompCompress(char * pbCompressed, int * pdwOutLength, char * pbUncom
|
||||
int dwInSize = dwInLength;
|
||||
int dwEntries = (sizeof(cmp_table) / sizeof(TCompressTable));
|
||||
int nResult = 1;
|
||||
int i;
|
||||
int i;
|
||||
|
||||
// Check for valid parameters
|
||||
if(!pdwOutLength || *pdwOutLength < dwInLength || !pbCompressed || !pbUncompressed)
|
||||
@@ -523,7 +523,7 @@ int WINAPI SCompCompress(char * pbCompressed, int * pdwOutLength, char * pbUncom
|
||||
{
|
||||
if(uCompressions2 & cmp_table[i].dwMask)
|
||||
{
|
||||
// Set the right output buffer
|
||||
// Set the right output buffer
|
||||
dwCompressCount--;
|
||||
pbOutput = (dwCompressCount & 1) ? pbTempBuff : pbCompressed;
|
||||
|
||||
@@ -611,7 +611,7 @@ int WINAPI SCompDecompress(char * pbOutBuffer, int * pdwOutLength, char * pbInBu
|
||||
int dwCount = 0; // Counter for every use
|
||||
int dwEntries = (sizeof(dcmp_table) / sizeof(TDecompressTable));
|
||||
int nResult = 1;
|
||||
int i;
|
||||
int i;
|
||||
|
||||
// If the input length is the same as output, do nothing.
|
||||
if(dwInLength == dwOutLength)
|
||||
@@ -623,11 +623,11 @@ int WINAPI SCompDecompress(char * pbOutBuffer, int * pdwOutLength, char * pbInBu
|
||||
*pdwOutLength = dwInLength;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
// Get applied compression types and decrement data length
|
||||
fDecompressions1 = fDecompressions2 = (unsigned char)*pbInBuffer++;
|
||||
fDecompressions1 = fDecompressions2 = (unsigned char)*pbInBuffer++;
|
||||
dwInLength--;
|
||||
|
||||
|
||||
// Search decompression table type and get all types of compression
|
||||
for(i = 0; i < dwEntries; i++)
|
||||
{
|
||||
@@ -681,13 +681,13 @@ int WINAPI SCompDecompress(char * pbOutBuffer, int * pdwOutLength, char * pbInBu
|
||||
{
|
||||
if(pbWorkBuff != pbOutBuffer)
|
||||
memcpy(pbOutBuffer, pbInBuffer, dwOutLength);
|
||||
|
||||
|
||||
}
|
||||
|
||||
// Delete temporary buffer, if necessary
|
||||
if(pbTempBuff != NULL)
|
||||
FREEMEM(pbTempBuff);
|
||||
|
||||
|
||||
*pdwOutLength = dwOutLength;
|
||||
return nResult;
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ static int CheckIfAllFilesKnown(TMPQArchive * ha, const char * szListFile, DWORD
|
||||
SFileCloseFile(hFile);
|
||||
}
|
||||
|
||||
// If the file is encrypted, we have to check
|
||||
// If the file is encrypted, we have to check
|
||||
// If we can apply the file decryption seed
|
||||
if(dwFlags & MPQ_FILE_ENCRYPTED && dwSeed == 0)
|
||||
{
|
||||
@@ -269,7 +269,7 @@ static int CopyMpqFileBlocks(
|
||||
DecryptMPQBlock(pdwBlockPos, dwBytes, dwSeed1 - 1);
|
||||
if(pdwBlockPos[0] != dwBytes)
|
||||
nError = ERROR_FILE_CORRUPT;
|
||||
|
||||
|
||||
memcpy(pdwBlockPos2, pdwBlockPos, dwBytes);
|
||||
EncryptMPQBlock(pdwBlockPos2, dwBytes, dwSeed2 - 1);
|
||||
}
|
||||
@@ -315,7 +315,7 @@ static int CopyMpqFileBlocks(
|
||||
}
|
||||
|
||||
// If necessary, re-encrypt the block
|
||||
// Note: Recompression is not necessary here. Unlike encryption,
|
||||
// Note: Recompression is not necessary here. Unlike encryption,
|
||||
// the compression does not depend on the position of the file in MPQ.
|
||||
if((pBlock->dwFlags & MPQ_FILE_ENCRYPTED) && dwSeed1 != dwSeed2)
|
||||
{
|
||||
@@ -583,7 +583,7 @@ BOOL WINAPI SFileCompactArchive(HANDLE hMPQ, const char * szListFile, BOOL /* bR
|
||||
TempPos.LowPart = pBlock->dwFilePos;
|
||||
if(TempPos.QuadPart < FirstFilePos.QuadPart)
|
||||
FirstFilePos = TempPos;
|
||||
|
||||
|
||||
pBlockEx++;
|
||||
pBlock++;
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Local tables
|
||||
|
||||
static DWORD PowersOfTwo[] =
|
||||
static DWORD PowersOfTwo[] =
|
||||
{
|
||||
0x0000002, 0x0000004, 0x0000008,
|
||||
0x0000010, 0x0000020, 0x0000040, 0x0000080,
|
||||
@@ -52,7 +52,7 @@ static DWORD PowersOfTwo[] =
|
||||
//
|
||||
// MPQ_CREATE_ARCHIVE_V1 - Creates MPQ archive version 1
|
||||
// MPQ_CREATE_ARCHIVE_V2 - Creates MPQ archive version 2
|
||||
//
|
||||
//
|
||||
// dwHashTableSize - Size of the hash table (only if creating a new archive).
|
||||
// Must be between 2^4 (= 16) and 2^18 (= 262 144)
|
||||
//
|
||||
@@ -118,7 +118,7 @@ BOOL WINAPI SFileCreateArchiveEx(const char * szMpqName, DWORD dwCreationDisposi
|
||||
dwHashTableSize = HASH_TABLE_SIZE_MIN;
|
||||
if(dwHashTableSize > HASH_TABLE_SIZE_MAX)
|
||||
dwHashTableSize = HASH_TABLE_SIZE_MAX;
|
||||
|
||||
|
||||
// Round the hash table size up to the nearest power of two
|
||||
for(nIndex = 0; PowersOfTwo[nIndex] != 0; nIndex++)
|
||||
{
|
||||
@@ -249,7 +249,7 @@ BOOL WINAPI SFileCreateArchiveEx(const char * szMpqName, DWORD dwCreationDisposi
|
||||
BSWAP_TMPQHEADER(ha->pHeader);
|
||||
WriteFile(ha->hFile, ha->pHeader, dwHeaderSize, &dwTransferred, NULL);
|
||||
BSWAP_TMPQHEADER(ha->pHeader);
|
||||
|
||||
|
||||
if(dwTransferred != ha->pHeader->dwHeaderSize)
|
||||
nError = ERROR_DISK_FULL;
|
||||
|
||||
@@ -273,7 +273,7 @@ BOOL WINAPI SFileCreateArchiveEx(const char * szMpqName, DWORD dwCreationDisposi
|
||||
CloseHandle(hFile);
|
||||
SetLastError(nError);
|
||||
}
|
||||
|
||||
|
||||
// Return the values
|
||||
*phMPQ = (HANDLE)ha;
|
||||
return (nError == ERROR_SUCCESS);
|
||||
@@ -355,7 +355,7 @@ BOOL WINAPI SFileAddFileEx(HANDLE hMPQ, const char * szFileName, const char * sz
|
||||
SetLastError(nError);
|
||||
return (nError == ERROR_SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
// Adds a data file into the archive
|
||||
// TODO: Test for archives > 4GB
|
||||
BOOL WINAPI SFileAddFile(HANDLE hMPQ, const char * szFileName, const char * szArchivedName, DWORD dwFlags)
|
||||
@@ -375,7 +375,7 @@ BOOL WINAPI SFileAddWave(HANDLE hMPQ, const char * szFileName, const char * szAr
|
||||
//
|
||||
// This function removes a file from the archive. The file content
|
||||
// remains there, only the entries in the hash table and in the block
|
||||
// table are updated.
|
||||
// table are updated.
|
||||
|
||||
// TODO: Test for archives > 4GB
|
||||
BOOL WINAPI SFileRemoveFile(HANDLE hMPQ, const char * szFileName, DWORD dwSearchScope)
|
||||
|
||||
@@ -67,7 +67,7 @@ BOOL CheckWildCard(const char * szString, const char * szWildCard)
|
||||
// The next N characters must not agree
|
||||
nMustNotMatch |= 0x70000000;
|
||||
break;
|
||||
|
||||
|
||||
case '?': // Means "One or no character"
|
||||
while(*szWildCard == '?')
|
||||
{
|
||||
@@ -111,7 +111,7 @@ BOOL CheckWildCard(const char * szString, const char * szWildCard)
|
||||
{
|
||||
if((nResult = _strnicmp(szString, szWildCard, nMustMatch)) == 0)
|
||||
break;
|
||||
|
||||
|
||||
szString++;
|
||||
nMustNotMatch--;
|
||||
}
|
||||
@@ -207,7 +207,7 @@ HANDLE WINAPI SFileFindFirstFile(HANDLE hMPQ, const char * szMask, SFILE_FIND_DA
|
||||
{
|
||||
if(!IsValidMpqHandle(ha))
|
||||
nError = ERROR_INVALID_PARAMETER;
|
||||
|
||||
|
||||
if(szMask == NULL || lpFindFileData == NULL)
|
||||
nError = ERROR_INVALID_PARAMETER;
|
||||
|
||||
@@ -245,7 +245,7 @@ HANDLE WINAPI SFileFindFirstFile(HANDLE hMPQ, const char * szMask, SFILE_FIND_DA
|
||||
FreeMPQSearch(hs);
|
||||
SetLastError(nError);
|
||||
}
|
||||
|
||||
|
||||
// Return the result value
|
||||
return (HANDLE)hs;
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ static int RelocateMpqTablePositions(TMPQArchive * ha)
|
||||
TempSize.QuadPart = ha->ExtBlockTablePos.QuadPart + (pHeader->dwBlockTableSize * sizeof(TMPQBlockEx));
|
||||
if(TempSize.QuadPart > ha->MpqSize.QuadPart)
|
||||
ha->MpqSize = TempSize;
|
||||
|
||||
|
||||
// MPQ size does not include the bytes before MPQ header
|
||||
ha->MpqSize.QuadPart -= ha->MpqPos.QuadPart;
|
||||
return ERROR_SUCCESS;
|
||||
@@ -122,7 +122,7 @@ BOOL SFileOpenArchiveEx(
|
||||
DWORD dwBlockTableSize = 0; // Block table size.
|
||||
DWORD dwTransferred; // Number of bytes read
|
||||
DWORD dwBytes = 0; // Number of bytes to read
|
||||
int nError = ERROR_SUCCESS;
|
||||
int nError = ERROR_SUCCESS;
|
||||
|
||||
// Check the right parameters
|
||||
if(nError == ERROR_SUCCESS)
|
||||
@@ -142,7 +142,7 @@ BOOL SFileOpenArchiveEx(
|
||||
if(hFile == INVALID_HANDLE_VALUE)
|
||||
nError = GetLastError();
|
||||
}
|
||||
|
||||
|
||||
// Allocate the MPQhandle
|
||||
if(nError == ERROR_SUCCESS)
|
||||
{
|
||||
@@ -241,7 +241,7 @@ BOOL SFileOpenArchiveEx(
|
||||
break;
|
||||
}
|
||||
|
||||
// If a MPQ shunt already has been found,
|
||||
// If a MPQ shunt already has been found,
|
||||
// and no MPQ header was at potision pointed by the shunt,
|
||||
// then the archive is corrupt
|
||||
if(ha->pShunt != NULL)
|
||||
@@ -327,7 +327,7 @@ BOOL SFileOpenArchiveEx(
|
||||
nError = ERROR_BAD_FORMAT;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
// Remember the highest block table entry
|
||||
if(pHash->dwBlockIndex > dwMaxBlockIndex)
|
||||
dwMaxBlockIndex = pHash->dwBlockIndex;
|
||||
@@ -437,7 +437,7 @@ BOOL SFileOpenArchiveEx(
|
||||
}
|
||||
}
|
||||
|
||||
// If the user didn't specified otherwise,
|
||||
// If the user didn't specified otherwise,
|
||||
// include the internal listfile to the TMPQArchive structure
|
||||
if((dwFlags & MPQ_OPEN_NO_LISTFILE) == 0)
|
||||
{
|
||||
@@ -479,7 +479,7 @@ BOOL WINAPI SFileOpenArchive(const char * szMpqName, DWORD dwPriority, DWORD dwF
|
||||
BOOL WINAPI SFileCloseArchive(HANDLE hMPQ)
|
||||
{
|
||||
TMPQArchive * ha = (TMPQArchive *)hMPQ;
|
||||
|
||||
|
||||
if(!IsValidMpqHandle(ha))
|
||||
{
|
||||
SetLastError(ERROR_INVALID_PARAMETER);
|
||||
|
||||
@@ -25,7 +25,7 @@ static BOOL OpenLocalFile(const char * szFileName, HANDLE * phFile)
|
||||
if(hFile != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
// Allocate and initialize file handle
|
||||
size_t nHandleSize = sizeof(TMPQFile) + strlen(szFileName);
|
||||
size_t nHandleSize = sizeof(TMPQFile) + strlen(szFileName);
|
||||
if((hf = (TMPQFile *)ALLOCMEM(char, nHandleSize)) != NULL)
|
||||
{
|
||||
memset(hf, 0, nHandleSize);
|
||||
@@ -62,7 +62,7 @@ static void FreeMPQFile(TMPQFile *& hf)
|
||||
/*****************************************************************************/
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// SFileEnumLocales enums all locale versions within MPQ.
|
||||
// SFileEnumLocales enums all locale versions within MPQ.
|
||||
// Functions fills all available language identifiers on a file into the buffer
|
||||
// pointed by plcLocales. There must be enough entries to copy the localed,
|
||||
// otherwise the function returns ERROR_INSUFFICIENT_BUFFER.
|
||||
@@ -220,7 +220,7 @@ BOOL WINAPI SFileOpenFileEx(HANDLE hMPQ, const char * szFileName, DWORD dwSearch
|
||||
size_t nHandleSize = 0; // Memory space necessary to allocate TMPQHandle
|
||||
int nError = ERROR_SUCCESS;
|
||||
|
||||
#ifdef _DEBUG
|
||||
#ifdef _DEBUG
|
||||
// Due to increasing numbers of files in MPQs, I had to change the behavior
|
||||
// of opening by file index. Now, the SFILE_OPEN_BY_INDEX value of dwSearchScope
|
||||
// must be entered. This check will allow to find code places that are incompatible
|
||||
@@ -321,13 +321,13 @@ BOOL WINAPI SFileOpenFileEx(HANDLE hMPQ, const char * szFileName, DWORD dwSearch
|
||||
hf->pBlock = pBlock;
|
||||
hf->nBlocks = (hf->pBlock->dwFSize + ha->dwBlockSize - 1) / ha->dwBlockSize;
|
||||
hf->pHash = pHash;
|
||||
|
||||
|
||||
hf->MpqFilePos.HighPart = pBlockEx->wFilePosHigh;
|
||||
hf->MpqFilePos.LowPart = pBlock->dwFilePos;
|
||||
hf->MpqFilePos.QuadPart += ha->MpqPos.QuadPart;
|
||||
|
||||
hf->dwHashIndex = dwHashIndex;
|
||||
hf->dwFileIndex = dwBlockIndex;
|
||||
hf->dwFileIndex = dwBlockIndex;
|
||||
|
||||
// Allocate buffers for decompression.
|
||||
if(hf->pBlock->dwFlags & MPQ_FILE_COMPRESSED)
|
||||
@@ -337,11 +337,11 @@ BOOL WINAPI SFileOpenFileEx(HANDLE hMPQ, const char * szFileName, DWORD dwSearch
|
||||
// As for newer MPQs, there may be one additional entry in the block table
|
||||
// (if the MPQ_FILE_HAS_EXTRA flag is set).
|
||||
// Allocate the buffer to include this DWORD as well
|
||||
|
||||
|
||||
if((hf->pdwBlockPos = ALLOCMEM(DWORD, hf->nBlocks + 2)) == NULL)
|
||||
nError = ERROR_NOT_ENOUGH_MEMORY;
|
||||
}
|
||||
|
||||
|
||||
// Decrypt file seed. Cannot be used if the file is given by index
|
||||
if(dwSearchScope != SFILE_OPEN_BY_INDEX)
|
||||
{
|
||||
@@ -386,7 +386,7 @@ BOOL WINAPI SFileOpenFileEx(HANDLE hMPQ, const char * szFileName, DWORD dwSearch
|
||||
BOOL WINAPI SFileCloseFile(HANDLE hFile)
|
||||
{
|
||||
TMPQFile * hf = (TMPQFile *)hFile;
|
||||
|
||||
|
||||
if(!IsValidFileHandle(hf))
|
||||
{
|
||||
SetLastError(ERROR_INVALID_PARAMETER);
|
||||
|
||||
@@ -154,8 +154,8 @@ static DWORD WINAPI ReadMPQBlocks(TMPQFile * hf, DWORD dwBlockPos, BYTE * buffer
|
||||
}
|
||||
}
|
||||
|
||||
// Set file pointer, if necessary
|
||||
if(ha->FilePointer.QuadPart != FilePos.QuadPart)
|
||||
// Set file pointer, if necessary
|
||||
if(ha->FilePointer.QuadPart != FilePos.QuadPart)
|
||||
{
|
||||
SetFilePointer(ha->hFile, FilePos.LowPart, &FilePos.HighPart, FILE_BEGIN);
|
||||
}
|
||||
@@ -245,7 +245,7 @@ static DWORD WINAPI ReadMPQBlocks(TMPQFile * hf, DWORD dwBlockPos, BYTE * buffer
|
||||
// TODO: Test for archives > 4GB
|
||||
static DWORD WINAPI ReadMPQFileSingleUnit(TMPQFile * hf, DWORD dwFilePos, BYTE * pbBuffer, DWORD dwToRead)
|
||||
{
|
||||
TMPQArchive * ha = hf->ha;
|
||||
TMPQArchive * ha = hf->ha;
|
||||
DWORD dwBytesRead = 0;
|
||||
|
||||
if(ha->FilePointer.QuadPart != hf->MpqFilePos.QuadPart)
|
||||
@@ -311,7 +311,7 @@ static DWORD WINAPI ReadMPQFileSingleUnit(TMPQFile * hf, DWORD dwFilePos, BYTE *
|
||||
// TODO: Test for archives > 4GB
|
||||
static DWORD WINAPI ReadMPQFile(TMPQFile * hf, DWORD dwFilePos, BYTE * pbBuffer, DWORD dwToRead)
|
||||
{
|
||||
TMPQArchive * ha = hf->ha;
|
||||
TMPQArchive * ha = hf->ha;
|
||||
TMPQBlock * pBlock = hf->pBlock; // Pointer to file block
|
||||
DWORD dwBytesRead = 0; // Number of bytes read from the file
|
||||
DWORD dwBlockPos; // Position in the file aligned to the whole blocks
|
||||
@@ -359,7 +359,7 @@ static DWORD WINAPI ReadMPQFile(TMPQFile * hf, DWORD dwFilePos, BYTE * pbBuffer,
|
||||
|
||||
// Copy data from block buffer into target buffer
|
||||
memcpy(pbBuffer, ha->pbBlockBuffer + ha->dwBuffPos, dwToCopy);
|
||||
|
||||
|
||||
// Update pointers
|
||||
dwToRead -= dwToCopy;
|
||||
dwBytesRead += dwToCopy;
|
||||
@@ -374,7 +374,7 @@ static DWORD WINAPI ReadMPQFile(TMPQFile * hf, DWORD dwFilePos, BYTE * pbBuffer,
|
||||
|
||||
// Load the whole ("middle") blocks only if there are more or equal one block
|
||||
if(dwToRead > ha->dwBlockSize)
|
||||
{
|
||||
{
|
||||
DWORD dwBlockBytes = dwToRead & ~(ha->dwBlockSize - 1);
|
||||
|
||||
dwLoaded = ReadMPQBlocks(hf, dwBlockPos, pbBuffer, dwBlockBytes);
|
||||
@@ -419,7 +419,7 @@ static DWORD WINAPI ReadMPQFile(TMPQFile * hf, DWORD dwFilePos, BYTE * pbBuffer,
|
||||
dwBytesRead += dwToCopy;
|
||||
ha->dwBuffPos = dwToCopy;
|
||||
}
|
||||
|
||||
|
||||
// Return what we've read
|
||||
return dwBytesRead;
|
||||
}
|
||||
@@ -456,7 +456,7 @@ BOOL WINAPI SFileReadFile(HANDLE hFile, VOID * lpBuffer, DWORD dwToRead, DWORD *
|
||||
SetLastError(ERROR_HANDLE_EOF);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
if(pdwRead != NULL)
|
||||
*pdwRead = dwTransferred;
|
||||
return TRUE;
|
||||
@@ -498,7 +498,7 @@ BOOL WINAPI SFileReadFile(HANDLE hFile, VOID * lpBuffer, DWORD dwToRead, DWORD *
|
||||
DWORD WINAPI SFileGetFilePos(HANDLE hFile, DWORD * pdwFilePosHigh)
|
||||
{
|
||||
TMPQFile * hf = (TMPQFile *)hFile;
|
||||
|
||||
|
||||
if(pdwFilePosHigh != NULL)
|
||||
*pdwFilePosHigh = 0;
|
||||
|
||||
@@ -525,7 +525,7 @@ DWORD WINAPI SFileGetFilePos(HANDLE hFile, DWORD * pdwFilePosHigh)
|
||||
DWORD WINAPI SFileGetFileSize(HANDLE hFile, DWORD * pdwFileSizeHigh)
|
||||
{
|
||||
TMPQFile * hf = (TMPQFile *)hFile;
|
||||
|
||||
|
||||
if(pdwFileSizeHigh != NULL)
|
||||
*pdwFileSizeHigh = 0;
|
||||
|
||||
@@ -604,7 +604,7 @@ DWORD WINAPI SFileSetFilePointer(HANDLE hFile, LONG lFilePos, LONG * pdwFilePosH
|
||||
//-----------------------------------------------------------------------------
|
||||
// Tries to retrieve the file name
|
||||
|
||||
static TID2Ext id2ext[] =
|
||||
static TID2Ext id2ext[] =
|
||||
{
|
||||
{0x1A51504D, "mpq"}, // MPQ archive header ID ('MPQ\x1A')
|
||||
{0x46464952, "wav"}, // WAVE header 'RIFF'
|
||||
@@ -623,7 +623,7 @@ static TID2Ext id2ext[] =
|
||||
{0x3032444D, "m2"}, // WoW ??? .m2
|
||||
{0x43424457, "dbc"}, // ??? .dbc
|
||||
{0x47585053, "bls"}, // WoW pixel shaders
|
||||
{0, NULL} // Terminator
|
||||
{0, NULL} // Terminator
|
||||
};
|
||||
|
||||
// TODO: Test for archives > 4GB
|
||||
@@ -646,7 +646,7 @@ BOOL WINAPI SFileGetFileName(HANDLE hFile, char * szFileName)
|
||||
if(hf == NULL || szFileName == NULL)
|
||||
nError = ERROR_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
|
||||
// If the file name is already filled, return it.
|
||||
if(nError == ERROR_SUCCESS && *hf->szFileName != 0)
|
||||
{
|
||||
@@ -665,7 +665,7 @@ BOOL WINAPI SFileGetFileName(HANDLE hFile, char * szFileName)
|
||||
if(nError == ERROR_SUCCESS)
|
||||
{
|
||||
dwFirstBytes[0] = dwFirstBytes[1] = 0;
|
||||
dwFilePos = SFileSetFilePointer(hf, 0, NULL, FILE_CURRENT);
|
||||
dwFilePos = SFileSetFilePointer(hf, 0, NULL, FILE_CURRENT);
|
||||
if(!SFileReadFile(hFile, &dwFirstBytes, sizeof(dwFirstBytes), NULL))
|
||||
nError = GetLastError();
|
||||
BSWAP_ARRAY32_UNSIGNED(dwFirstBytes, sizeof(dwFirstBytes) / sizeof(DWORD));
|
||||
|
||||
@@ -71,7 +71,7 @@ static size_t ReadLine(TListFileCache * pCache, char * szLine, int nMaxChars)
|
||||
{
|
||||
char * szLineBegin = szLine;
|
||||
char * szLineEnd = szLine + nMaxChars - 1;
|
||||
|
||||
|
||||
__BeginLoading:
|
||||
|
||||
// Skip newlines, spaces, tabs and another non-printable stuff
|
||||
@@ -156,7 +156,7 @@ int SListFileAddNode(TMPQArchive * ha, const char * szFileName)
|
||||
dwName2 = pHash->dwName2;
|
||||
if((DWORD_PTR)ha->pListFile[dwHashIndex] <= LISTFILE_ENTRY_DELETED)
|
||||
return ERROR_SUCCESS;
|
||||
|
||||
|
||||
// Create the listfile node and insert it into the listfile table
|
||||
nLength = strlen(szFileName);
|
||||
pNode = (TFileNode *)ALLOCMEM(char, sizeof(TFileNode) + nLength);
|
||||
@@ -310,8 +310,8 @@ int SListFileSaveToMpq(TMPQArchive * ha)
|
||||
szBuffer[nLength + 0] = 0x0D;
|
||||
szBuffer[nLength + 1] = 0x0A;
|
||||
WriteFile(hFile, szBuffer, (DWORD)(nLength + 2), &dwTransferred, NULL);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Add the listfile into the archive.
|
||||
SFileSetLocale(LANG_NEUTRAL);
|
||||
nError = AddFileToArchive(ha, hFile, LISTFILE_NAME, MPQ_FILE_COMPRESS_PKWARE | MPQ_FILE_ENCRYPTED | MPQ_FILE_REPLACEEXISTING, 0, SFILE_TYPE_DATA, NULL);
|
||||
@@ -329,7 +329,7 @@ int SListFileSaveToMpq(TMPQArchive * ha)
|
||||
// File functions
|
||||
|
||||
// Adds a listfile into the MPQ archive.
|
||||
// Note that the function does not remove the
|
||||
// Note that the function does not remove the
|
||||
// TODO: Test for archives > 4GB
|
||||
int WINAPI SFileAddListFile(HANDLE hMpq, const char * szListFile)
|
||||
{
|
||||
@@ -359,7 +359,7 @@ int WINAPI SFileAddListFile(HANDLE hMpq, const char * szListFile)
|
||||
|
||||
if(nError == ERROR_SUCCESS)
|
||||
{
|
||||
dwCacheSize =
|
||||
dwCacheSize =
|
||||
dwFileSize = SFileGetFileSize(hListFile, NULL);
|
||||
|
||||
// Try to allocate memory for the complete file. If it fails,
|
||||
@@ -443,7 +443,7 @@ HANDLE SListFileFindFirstFile(HANDLE hMpq, const char * szListFile, const char *
|
||||
|
||||
if(nError == ERROR_SUCCESS)
|
||||
{
|
||||
dwCacheSize =
|
||||
dwCacheSize =
|
||||
dwFileSize = SFileGetFileSize(hListFile, NULL);
|
||||
|
||||
// Try to allocate memory for the complete file. If it fails,
|
||||
@@ -493,7 +493,7 @@ HANDLE SListFileFindFirstFile(HANDLE hMpq, const char * szListFile, const char *
|
||||
|
||||
// If some mask entered, check it
|
||||
if(CheckWildCard(lpFindFileData->cFileName, pCache->szMask))
|
||||
break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@
|
||||
//
|
||||
// The library type is encoded in the library name as the following
|
||||
// StormLibXYZ.lib
|
||||
//
|
||||
//
|
||||
// X - D for Debug version, R for Release version
|
||||
// Y - A for ANSI version, U for Unicode version (Unicode version does not exist yet)
|
||||
// Z - S for static C library, D for multithreaded DLL C-library
|
||||
@@ -63,15 +63,15 @@
|
||||
|
||||
#if defined(_MSC_VER) && !defined (__STORMLIB_SELF__)
|
||||
#ifdef _DEBUG // DEBUG VERSIONS
|
||||
#ifdef _DLL
|
||||
#ifdef _DLL
|
||||
#pragma comment(lib, "StormLibDAD.lib") // Debug Ansi Dynamic version
|
||||
#else
|
||||
#else
|
||||
#pragma comment(lib, "StormLibDAS.lib") // Debug Ansi Static version
|
||||
#endif
|
||||
#else // RELEASE VERSIONS
|
||||
#ifdef _DLL
|
||||
#pragma comment(lib, "StormLibRAD.lib") // Release Ansi Dynamic version
|
||||
#else
|
||||
#else
|
||||
#pragma comment(lib, "StormLibRAS.lib") // Release Ansi Static version
|
||||
#endif
|
||||
#endif
|
||||
@@ -109,7 +109,7 @@
|
||||
#define MPQ_FILE_COMPRESS_PKWARE 0x00000100 // Compression made by PKWARE Data Compression Library
|
||||
#define MPQ_FILE_COMPRESS_MULTI 0x00000200 // Multiple compressions
|
||||
#define MPQ_FILE_COMPRESSED 0x0000FF00 // File is compressed
|
||||
#define MPQ_FILE_ENCRYPTED 0x00010000 // Indicates whether file is encrypted
|
||||
#define MPQ_FILE_ENCRYPTED 0x00010000 // Indicates whether file is encrypted
|
||||
#define MPQ_FILE_FIXSEED 0x00020000 // File decrypt seed has to be fixed
|
||||
#define MPQ_FILE_SINGLE_UNIT 0x01000000 // File is stored as a single unit, rather than split into sectors (Thx, Quantam)
|
||||
#define MPQ_FILE_DUMMY_FILE 0x02000000 // The file is only 1 byte long and its name is a hash
|
||||
@@ -132,8 +132,8 @@
|
||||
#define MPQ_COMPRESSION_ZLIB 0x02 // ZLIB compression
|
||||
#define MPQ_COMPRESSION_PKWARE 0x08 // PKWARE DCL compression
|
||||
#define MPQ_COMPRESSION_BZIP2 0x10 // BZIP2 compression
|
||||
#define MPQ_COMPRESSION_WAVE_MONO 0x40 //
|
||||
#define MPQ_COMPRESSION_WAVE_STEREO 0x80 //
|
||||
#define MPQ_COMPRESSION_WAVE_MONO 0x40 //
|
||||
#define MPQ_COMPRESSION_WAVE_STEREO 0x80 //
|
||||
|
||||
|
||||
// Constants for SFileAddWave
|
||||
@@ -168,7 +168,7 @@
|
||||
#define CCB_COPYING_NON_MPQ_DATA 3 // Copying non-MPQ data: No params used
|
||||
#define CCB_COMPACTING_FILES 4 // Compacting archive (dwParam1 = current, dwParam2 = total)
|
||||
#define CCB_CLOSING_ARCHIVE 5 // Closing archive: No params used
|
||||
|
||||
|
||||
#define LISTFILE_NAME "(listfile)" // Name of internal listfile
|
||||
#define SIGNATURE_NAME "(signature)" // Name of internal signature
|
||||
#define ATTRIBUTES_NAME "(attributes)" // Name of internal attributes file
|
||||
@@ -213,10 +213,10 @@ struct TMPQShunt
|
||||
struct TMPQHeader
|
||||
{
|
||||
// The ID_MPQ ('MPQ\x1A') signature
|
||||
DWORD dwID;
|
||||
DWORD dwID;
|
||||
|
||||
// Size of the archive header
|
||||
DWORD dwHeaderSize;
|
||||
DWORD dwHeaderSize;
|
||||
|
||||
// Size of MPQ archive
|
||||
// This field is deprecated in the Burning Crusade MoPaQ format, and the size of the archive
|
||||
@@ -235,14 +235,14 @@ struct TMPQHeader
|
||||
|
||||
// Offset to the beginning of the hash table, relative to the beginning of the archive.
|
||||
DWORD dwHashTablePos;
|
||||
|
||||
|
||||
// Offset to the beginning of the block table, relative to the beginning of the archive.
|
||||
DWORD dwBlockTablePos;
|
||||
|
||||
|
||||
// Number of entries in the hash table. Must be a power of two, and must be less than 2^16 for
|
||||
// the original MoPaQ format, or less than 2^20 for the Burning Crusade format.
|
||||
DWORD dwHashTableSize;
|
||||
|
||||
|
||||
// Number of entries in the block table
|
||||
DWORD dwBlockTableSize;
|
||||
};
|
||||
@@ -267,7 +267,7 @@ struct TMPQHash
|
||||
{
|
||||
// The hash of the file path, using method A.
|
||||
DWORD dwName1;
|
||||
|
||||
|
||||
// The hash of the file path, using method B.
|
||||
DWORD dwName2;
|
||||
|
||||
@@ -303,16 +303,16 @@ struct TMPQBlock
|
||||
{
|
||||
// Offset of the beginning of the block, relative to the beginning of the archive.
|
||||
DWORD dwFilePos;
|
||||
|
||||
|
||||
// Compressed file size
|
||||
DWORD dwCSize;
|
||||
|
||||
|
||||
// Only valid if the block is a file; otherwise meaningless, and should be 0.
|
||||
// If the file is compressed, this is the size of the uncompressed file data.
|
||||
DWORD dwFSize;
|
||||
|
||||
DWORD dwFSize;
|
||||
|
||||
// Flags for the file. See MPQ_FILE_XXXX constants
|
||||
DWORD dwFlags;
|
||||
DWORD dwFlags;
|
||||
};
|
||||
|
||||
|
||||
@@ -333,7 +333,7 @@ struct TFileNode
|
||||
// There can be more files that have the same name.
|
||||
// (e.g. multiple language files). We don't want to
|
||||
// have an entry for each of them, so the entries will be referenced.
|
||||
// When a number of node references reaches zero,
|
||||
// When a number of node references reaches zero,
|
||||
// the node will be deleted
|
||||
|
||||
size_t nLength; // File name length
|
||||
@@ -372,7 +372,7 @@ struct TMPQArchive
|
||||
TMPQHash * pHashTable; // Hash table
|
||||
TMPQBlock * pBlockTable; // Block table
|
||||
TMPQBlockEx * pExtBlockTable; // Extended block table
|
||||
|
||||
|
||||
TMPQShunt Shunt; // MPQ shunt. Valid only when ID_MPQ_SHUNT has been found
|
||||
TMPQHeader2 Header; // MPQ header
|
||||
|
||||
@@ -520,8 +520,8 @@ int WINAPI SFileAddListFile(HANDLE hMpq, const char * szListFile);
|
||||
|
||||
// Archive creating and editing
|
||||
BOOL WINAPI SFileCreateArchiveEx(const char * szMpqName, DWORD dwCreationDisposition, DWORD dwHashTableSize, HANDLE * phMPQ);
|
||||
BOOL WINAPI SFileAddFile(HANDLE hMPQ, const char * szFileName, const char * szArchivedName, DWORD dwFlags);
|
||||
BOOL WINAPI SFileAddWave(HANDLE hMPQ, const char * szFileName, const char * szArchivedName, DWORD dwFlags, DWORD dwQuality);
|
||||
BOOL WINAPI SFileAddFile(HANDLE hMPQ, const char * szFileName, const char * szArchivedName, DWORD dwFlags);
|
||||
BOOL WINAPI SFileAddWave(HANDLE hMPQ, const char * szFileName, const char * szArchivedName, DWORD dwFlags, DWORD dwQuality);
|
||||
BOOL WINAPI SFileRemoveFile(HANDLE hMPQ, const char * szFileName, DWORD dwSearchScope = SFILE_OPEN_BY_INDEX);
|
||||
BOOL WINAPI SFileRenameFile(HANDLE hMPQ, const char * szOldFileName, const char * szNewFileName);
|
||||
BOOL WINAPI SFileSetFileLocale(HANDLE hFile, LCID lcNewLocale);
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
/* 12.11.03 1.02 Dan Macintosh compatibility */
|
||||
/* 24.07.04 1.03 Sam Mac OS X compatibility */
|
||||
/* 22.11.06 1.04 Sam Mac OS X compatibility (for StormLib 6.0) */
|
||||
/* 31.12.06 1.05 XPinguin Full GNU/Linux compatibility */
|
||||
/* 31.12.06 1.05 XPinguin Full GNU/Linux compatibility */
|
||||
/*****************************************************************************/
|
||||
|
||||
#ifndef __STORMPORT_H__
|
||||
@@ -35,9 +35,9 @@
|
||||
#define _CRT_NON_CONFORMING_SWPRINTFS
|
||||
#endif
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <windows.h>
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <windows.h>
|
||||
#define PLATFORM_LITTLE_ENDIAN 1
|
||||
|
||||
#ifdef WIN64
|
||||
@@ -50,20 +50,20 @@
|
||||
|
||||
#endif
|
||||
|
||||
// Defines for Mac Carbon
|
||||
// Defines for Mac Carbon
|
||||
#if !defined(PLATFORM_DEFINED) && defined(__APPLE__) // Mac Carbon API
|
||||
|
||||
// Macintosh using Carbon
|
||||
#include <Carbon/Carbon.h> // Mac OS X
|
||||
#define _stricmp strcasecmp // Case insensitive strcmp has a different name on this platform.
|
||||
#define _strnicmp strncasecmp
|
||||
|
||||
|
||||
typedef void * LPCSTR;
|
||||
typedef unsigned long * LPDWORD;
|
||||
typedef long * PLONG;
|
||||
typedef void * LPVOID;
|
||||
typedef unsigned int UINT;
|
||||
|
||||
|
||||
#define PKEXPORT
|
||||
#define __SYS_ZLIB
|
||||
#define __SYS_BZLIB
|
||||
@@ -120,17 +120,17 @@
|
||||
typedef void * LPOVERLAPPED; // Unsupported on Linux
|
||||
typedef char TCHAR;
|
||||
typedef unsigned long LCID;
|
||||
|
||||
|
||||
typedef void * LPCSTR;
|
||||
typedef unsigned long * LPDWORD;
|
||||
typedef long * PLONG;
|
||||
typedef void * LPVOID;
|
||||
typedef unsigned int UINT;
|
||||
|
||||
|
||||
typedef struct _FILETIME
|
||||
{
|
||||
DWORD dwLowDateTime;
|
||||
DWORD dwHighDateTime;
|
||||
{
|
||||
DWORD dwLowDateTime;
|
||||
DWORD dwHighDateTime;
|
||||
}
|
||||
FILETIME, *PFILETIME;
|
||||
|
||||
@@ -152,7 +152,7 @@
|
||||
LONGLONG QuadPart;
|
||||
}
|
||||
LARGE_INTEGER, *PLARGE_INTEGER;
|
||||
|
||||
|
||||
// Some Windows-specific defines
|
||||
#ifndef MAX_PATH
|
||||
#define MAX_PATH 1024
|
||||
@@ -167,24 +167,24 @@
|
||||
#endif
|
||||
|
||||
#define VOID void
|
||||
#define WINAPI
|
||||
#define WINAPI
|
||||
|
||||
#define FILE_BEGIN SEEK_SET
|
||||
#define FILE_CURRENT SEEK_CUR
|
||||
#define FILE_END SEEK_END
|
||||
|
||||
|
||||
#define CREATE_NEW 1
|
||||
#define CREATE_ALWAYS 2
|
||||
#define OPEN_EXISTING 3
|
||||
#define OPEN_ALWAYS 4
|
||||
|
||||
|
||||
#define FILE_SHARE_READ 0x00000001L
|
||||
#define GENERIC_WRITE 0x40000000
|
||||
#define GENERIC_READ 0x80000000
|
||||
|
||||
|
||||
#define FILE_FLAG_DELETE_ON_CLOSE 1 // Sam: Added these two defines so it would compile.
|
||||
#define FILE_FLAG_SEQUENTIAL_SCAN 2
|
||||
|
||||
|
||||
#define ERROR_SUCCESS 0
|
||||
#define ERROR_INVALID_FUNCTION 1
|
||||
#define ERROR_FILE_NOT_FOUND 2
|
||||
@@ -204,22 +204,22 @@
|
||||
#define ERROR_PARAMETER_QUOTA_EXCEEDED 1283
|
||||
#define ERROR_FILE_CORRUPT 1392
|
||||
#define ERROR_INSUFFICIENT_BUFFER 4999
|
||||
|
||||
|
||||
#define INVALID_HANDLE_VALUE ((HANDLE) -1)
|
||||
|
||||
|
||||
#ifndef min
|
||||
#define min(a, b) ((a < b) ? a : b)
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef max
|
||||
#define max(a, b) ((a > b) ? a : b)
|
||||
#endif
|
||||
|
||||
|
||||
#define _stricmp strcasecmp
|
||||
#define _strnicmp strncasecmp
|
||||
|
||||
|
||||
extern int globalerr;
|
||||
|
||||
|
||||
void SetLastError(int err);
|
||||
int GetLastError();
|
||||
char *ErrString(int err);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
*
|
||||
* Description: implementation for StormLib - linux port
|
||||
* intended to be used in GLdiablo
|
||||
*
|
||||
*
|
||||
* ----> StormLib was originally developed for Windows by
|
||||
* Ladislav Zezula (www.zezula.net), and he did
|
||||
* a _great_ job! Thanks Ladislav!
|
||||
@@ -17,9 +17,9 @@
|
||||
*
|
||||
* Author: Marko Friedemann <marko.friedemann@bmx-chemnitz.de>
|
||||
* Created at: Mon Jan 29 19:01:37 CEST 2001
|
||||
* Computer: whiplash.flachland-chemnitz.de
|
||||
* Computer: whiplash.flachland-chemnitz.de
|
||||
* System: Linux 2.4.0 on i686
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2001 BMX-Chemnitz.DE All rights reserved.
|
||||
*
|
||||
********************************************************************/
|
||||
@@ -97,7 +97,7 @@ DWORD GetFileSize(HANDLE hFile, DWORD *ulOffSetHigh)
|
||||
|
||||
struct stat fileinfo;
|
||||
fstat((int)hFile, &fileinfo);
|
||||
|
||||
|
||||
return fileinfo.st_size;
|
||||
}
|
||||
|
||||
@@ -163,6 +163,6 @@ BOOL DeleteFile(const char *lpFileName)
|
||||
BOOL MoveFile(const char *lpExistingFileName, const char *lpNewFileName)
|
||||
{
|
||||
return rename(lpExistingFileName, lpNewFileName);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/********************************************************************
|
||||
*
|
||||
* Description: implementation for StormLib - Macintosh port
|
||||
*
|
||||
*
|
||||
* these are function wraps to execute Windows API calls
|
||||
* as native Macintosh file calls (open/close/read/write/...)
|
||||
* requires Mac OS X
|
||||
@@ -45,14 +45,14 @@ static OSErr FSGetFullPath(const FSRef *ref, UInt8 *fullPath, UInt32 fullPathLen
|
||||
OSErr result;
|
||||
|
||||
result = FSRefMakePath(ref, fullPath, fullPathLength);
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static OSErr FSLocationFromFullPath(const void *fullPath, FSRef *ref)
|
||||
{
|
||||
OSErr result;
|
||||
|
||||
|
||||
result = FSPathMakeRef((UInt8 *)fullPath, ref, NULL); // Create an FSRef from the path
|
||||
return result;
|
||||
}
|
||||
@@ -61,7 +61,7 @@ static OSErr FSLocationFromFullPath(const void *fullPath, FSRef *ref)
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static OSErr FSCreateCompat(const FSRef *parentRef, OSType creator, OSType fileType, const UniChar *fileName,
|
||||
static OSErr FSCreateCompat(const FSRef *parentRef, OSType creator, OSType fileType, const UniChar *fileName,
|
||||
UniCharCount nameLength, FSRef *ref)
|
||||
{
|
||||
FSCatalogInfo theCatInfo;
|
||||
@@ -71,7 +71,7 @@ static OSErr FSCreateCompat(const FSRef *parentRef, OSType creator, OSType fileT
|
||||
((FileInfo *)&theCatInfo.finderInfo)->finderFlags = 0;
|
||||
SetPt(&((FileInfo *)&theCatInfo.finderInfo)->location, 0, 0);
|
||||
((FileInfo *)&theCatInfo.finderInfo)->reservedField = 0;
|
||||
|
||||
|
||||
theErr = FSCreateFileUnicode(parentRef, nameLength, fileName, kFSCatInfoFinderInfo, &theCatInfo, ref, NULL);
|
||||
return theErr;
|
||||
}
|
||||
@@ -84,11 +84,11 @@ static OSErr FSOpenDFCompat(FSRef *ref, char permission, short *refNum)
|
||||
HFSUniStr255 forkName;
|
||||
OSErr theErr;
|
||||
Boolean isFolder, wasChanged;
|
||||
|
||||
|
||||
theErr = FSResolveAliasFile(ref, TRUE, &isFolder, &wasChanged);
|
||||
if (theErr != noErr)
|
||||
return theErr;
|
||||
|
||||
|
||||
FSGetDataForkName(&forkName);
|
||||
theErr = FSOpenFork(ref, forkName.length, forkName.unicode, permission, refNum);
|
||||
return theErr;
|
||||
@@ -209,7 +209,7 @@ void ConvertTMPQShunt(void *shunt)
|
||||
void ConvertTMPQHeader(void *header)
|
||||
{
|
||||
TMPQHeader2 * theHeader = (TMPQHeader2 *)header;
|
||||
|
||||
|
||||
theHeader->dwID = SwapULong(theHeader->dwID);
|
||||
theHeader->dwHeaderSize = SwapULong(theHeader->dwHeaderSize);
|
||||
theHeader->dwArchiveSize = SwapULong(theHeader->dwArchiveSize);
|
||||
@@ -271,7 +271,7 @@ int GetLastError()
|
||||
********************************************************************/
|
||||
char *ErrString(int err)
|
||||
{
|
||||
switch (err)
|
||||
switch (err)
|
||||
{
|
||||
case ERROR_INVALID_FUNCTION:
|
||||
return "function not implemented";
|
||||
@@ -324,7 +324,7 @@ void GetTempPath(DWORD szTempLength, char * szTemp) // I think I'll change this
|
||||
else
|
||||
szTemp[0] = '\0';
|
||||
strcat(szTemp, "/");
|
||||
|
||||
|
||||
SetLastError(theErr);
|
||||
}
|
||||
|
||||
@@ -347,7 +347,7 @@ void GetTempFileName(const char * lpTempFolderPath, const char * lpFileName, DWO
|
||||
strcpy(szLFName, lpTempFolderPath);
|
||||
strcat(szLFName, lpFileName);
|
||||
strcat(szLFName, tmp);
|
||||
|
||||
|
||||
if ((fHandle = CreateFile(szLFName, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, 0)) == INVALID_HANDLE_VALUE)
|
||||
// OK we found it!
|
||||
break;
|
||||
@@ -364,16 +364,16 @@ BOOL DeleteFile(const char * lpFileName)
|
||||
{
|
||||
OSErr theErr;
|
||||
FSRef theFileRef;
|
||||
|
||||
|
||||
theErr = FSLocationFromFullPath(lpFileName, &theFileRef);
|
||||
if (theErr != noErr)
|
||||
{
|
||||
SetLastError(theErr);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
theErr = FSDeleteObject(&theFileRef);
|
||||
|
||||
|
||||
SetLastError(theErr);
|
||||
|
||||
return theErr == noErr;
|
||||
@@ -390,7 +390,7 @@ BOOL MoveFile(const char * lpFromFileName, const char * lpToFileName)
|
||||
FSRef fromFileRef;
|
||||
FSRef toFileRef;
|
||||
FSRef parentFolderRef;
|
||||
|
||||
|
||||
// Get the path to the old file
|
||||
theErr = FSLocationFromFullPath(lpFromFileName, &fromFileRef);
|
||||
if (theErr != noErr)
|
||||
@@ -398,7 +398,7 @@ BOOL MoveFile(const char * lpFromFileName, const char * lpToFileName)
|
||||
SetLastError(theErr);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Get the path to the new folder for the file
|
||||
char folderName[strlen(lpToFileName)];
|
||||
CFStringRef folderPathCFString = CFStringCreateWithCString(NULL, lpToFileName, kCFStringEncodingUTF8);
|
||||
@@ -409,7 +409,7 @@ BOOL MoveFile(const char * lpFromFileName, const char * lpToFileName)
|
||||
CFRelease(fileURL);
|
||||
CFRelease(folderURL);
|
||||
CFRelease(folderPathCFString);
|
||||
|
||||
|
||||
// Move the old file
|
||||
theErr = FSMoveObject(&fromFileRef, &parentFolderRef, &toFileRef);
|
||||
if (theErr != noErr)
|
||||
@@ -417,19 +417,19 @@ BOOL MoveFile(const char * lpFromFileName, const char * lpToFileName)
|
||||
SetLastError(theErr);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Get a CFString for the new file name
|
||||
CFStringRef newFileNameCFString = CFStringCreateWithCString(NULL, lpToFileName, kCFStringEncodingUTF8);
|
||||
fileURL = CFURLCreateWithFileSystemPath(NULL, newFileNameCFString, kCFURLPOSIXPathStyle, FALSE);
|
||||
CFRelease(newFileNameCFString);
|
||||
newFileNameCFString = CFURLCopyLastPathComponent(fileURL);
|
||||
CFRelease(fileURL);
|
||||
|
||||
|
||||
// Convert CFString to Unicode and rename the file
|
||||
UniChar unicodeFileName[256];
|
||||
CFStringGetCharacters(newFileNameCFString, CFRangeMake(0, CFStringGetLength(newFileNameCFString)),
|
||||
UniChar unicodeFileName[256];
|
||||
CFStringGetCharacters(newFileNameCFString, CFRangeMake(0, CFStringGetLength(newFileNameCFString)),
|
||||
unicodeFileName);
|
||||
theErr = FSRenameUnicode(&toFileRef, CFStringGetLength(newFileNameCFString), unicodeFileName,
|
||||
theErr = FSRenameUnicode(&toFileRef, CFStringGetLength(newFileNameCFString), unicodeFileName,
|
||||
kTextEncodingUnknown, NULL);
|
||||
if (theErr != noErr)
|
||||
{
|
||||
@@ -437,9 +437,9 @@ BOOL MoveFile(const char * lpFromFileName, const char * lpToFileName)
|
||||
CFRelease(newFileNameCFString);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
CFRelease(newFileNameCFString);
|
||||
|
||||
|
||||
SetLastError(theErr);
|
||||
return true;
|
||||
}
|
||||
@@ -470,7 +470,7 @@ HANDLE CreateFile( const char *sFileName, /* file name */
|
||||
char permission;
|
||||
static OSType gCreator;
|
||||
static OSType gType;
|
||||
|
||||
|
||||
theErr = FSLocationFromFullPath(sFileName, &theFileRef);
|
||||
if (theErr == fnfErr)
|
||||
{ // Create the FSRef for the parent directory.
|
||||
@@ -484,23 +484,23 @@ HANDLE CreateFile( const char *sFileName, /* file name */
|
||||
CFRelease(fileURL);
|
||||
CFRelease(folderURL);
|
||||
CFRelease(folderPathCFString);
|
||||
}
|
||||
}
|
||||
if (theErr != noErr)
|
||||
{
|
||||
SetLastError(theErr);
|
||||
if (ulCreation == OPEN_EXISTING || theErr != fnfErr)
|
||||
return INVALID_HANDLE_VALUE;
|
||||
}
|
||||
|
||||
|
||||
if (ulCreation != OPEN_EXISTING)
|
||||
{ /* We create the file */
|
||||
UniChar unicodeFileName[256];
|
||||
CFStringRef filePathCFString = CFStringCreateWithCString(NULL, sFileName, kCFStringEncodingUTF8);
|
||||
CFURLRef fileURL = CFURLCreateWithFileSystemPath(NULL, filePathCFString, kCFURLPOSIXPathStyle, FALSE);
|
||||
CFStringRef fileNameCFString = CFURLCopyLastPathComponent(fileURL);
|
||||
CFStringGetCharacters(fileNameCFString, CFRangeMake(0, CFStringGetLength(fileNameCFString)),
|
||||
CFStringGetCharacters(fileNameCFString, CFRangeMake(0, CFStringGetLength(fileNameCFString)),
|
||||
unicodeFileName);
|
||||
theErr = FSCreateCompat(&theParentRef, gCreator, gType, unicodeFileName,
|
||||
theErr = FSCreateCompat(&theParentRef, gCreator, gType, unicodeFileName,
|
||||
CFStringGetLength(fileNameCFString), &theFileRef);
|
||||
CFRelease(fileNameCFString);
|
||||
CFRelease(filePathCFString);
|
||||
@@ -522,7 +522,7 @@ HANDLE CreateFile( const char *sFileName, /* file name */
|
||||
permission = fsRdWrPerm;
|
||||
}
|
||||
theErr = FSOpenDFCompat(&theFileRef, permission, &fileRef);
|
||||
|
||||
|
||||
SetLastError(theErr);
|
||||
|
||||
if (theErr == noErr)
|
||||
@@ -537,14 +537,14 @@ HANDLE CreateFile( const char *sFileName, /* file name */
|
||||
BOOL CloseHandle( HANDLE hFile ) /* handle to object */
|
||||
{
|
||||
OSErr theErr;
|
||||
|
||||
|
||||
if ((hFile == NULL) || (hFile == INVALID_HANDLE_VALUE))
|
||||
return FALSE;
|
||||
|
||||
theErr = FSCloseFork((short)(int)hFile);
|
||||
|
||||
|
||||
SetLastError(theErr);
|
||||
|
||||
|
||||
return theErr != noErr;
|
||||
}
|
||||
|
||||
@@ -562,19 +562,19 @@ DWORD GetFileSize( HANDLE hFile, /* handle to file */
|
||||
SetLastError(theErr);
|
||||
return -1u;
|
||||
}
|
||||
|
||||
|
||||
theErr = FSGetForkSize((short)(int)hFile, &fileLength);
|
||||
if (theErr != noErr)
|
||||
{
|
||||
SetLastError(theErr);
|
||||
return -1u;
|
||||
}
|
||||
|
||||
|
||||
if (ulOffSetHigh != NULL)
|
||||
*ulOffSetHigh = fileLength >> 32;
|
||||
|
||||
SetLastError(theErr);
|
||||
|
||||
|
||||
return fileLength;
|
||||
}
|
||||
|
||||
@@ -593,81 +593,81 @@ DWORD SetFilePointer( HANDLE hFile, /* handle to file */
|
||||
if (ulMethod == FILE_CURRENT)
|
||||
{
|
||||
SInt64 bytesToMove;
|
||||
|
||||
|
||||
if (pOffSetHigh != NULL)
|
||||
bytesToMove = ((SInt64)*pOffSetHigh << 32) + lOffSetLow;
|
||||
else
|
||||
bytesToMove = lOffSetLow;
|
||||
|
||||
|
||||
SInt64 newPos;
|
||||
|
||||
|
||||
theErr = FSSetForkPosition((short)(int)hFile, fsFromMark, bytesToMove);
|
||||
if (theErr != noErr)
|
||||
{
|
||||
SetLastError(theErr);
|
||||
return -1u;
|
||||
}
|
||||
|
||||
|
||||
theErr = FSGetForkPosition((short)(int)hFile, &newPos);
|
||||
if (theErr != noErr)
|
||||
{
|
||||
SetLastError(theErr);
|
||||
return -1u;
|
||||
}
|
||||
|
||||
|
||||
if (pOffSetHigh != NULL)
|
||||
*pOffSetHigh = newPos >> 32;
|
||||
|
||||
|
||||
SetLastError(theErr);
|
||||
return newPos;
|
||||
}
|
||||
else if (ulMethod == FILE_BEGIN)
|
||||
{
|
||||
SInt64 bytesToMove;
|
||||
|
||||
|
||||
if (pOffSetHigh != NULL)
|
||||
bytesToMove = ((SInt64)*pOffSetHigh << 32) + lOffSetLow;
|
||||
else
|
||||
bytesToMove = lOffSetLow;
|
||||
|
||||
|
||||
theErr = FSSetForkPosition((short)(int)hFile, fsFromStart, bytesToMove);
|
||||
if (theErr != noErr)
|
||||
{
|
||||
SetLastError(theErr);
|
||||
return -1u;
|
||||
}
|
||||
|
||||
|
||||
SetLastError(theErr);
|
||||
return lOffSetLow;
|
||||
}
|
||||
else
|
||||
{
|
||||
SInt64 bytesToMove;
|
||||
|
||||
|
||||
if (pOffSetHigh != NULL)
|
||||
bytesToMove = ((SInt64)*pOffSetHigh << 32) + lOffSetLow;
|
||||
else
|
||||
bytesToMove = lOffSetLow;
|
||||
|
||||
|
||||
SInt64 newPos;
|
||||
|
||||
|
||||
theErr = FSSetForkPosition((short)(int)hFile, fsFromLEOF, bytesToMove);
|
||||
if (theErr != noErr)
|
||||
{
|
||||
SetLastError(theErr);
|
||||
return -1u;
|
||||
}
|
||||
|
||||
|
||||
theErr = FSGetForkPosition((short)(int)hFile, &newPos);
|
||||
if (theErr != noErr)
|
||||
{
|
||||
SetLastError(theErr);
|
||||
return -1u;
|
||||
}
|
||||
|
||||
|
||||
if (pOffSetHigh != NULL)
|
||||
*pOffSetHigh = newPos >> 32;
|
||||
|
||||
|
||||
SetLastError(theErr);
|
||||
return newPos;
|
||||
}
|
||||
@@ -679,11 +679,11 @@ DWORD SetFilePointer( HANDLE hFile, /* handle to file */
|
||||
BOOL SetEndOfFile( HANDLE hFile ) /* handle to file */
|
||||
{
|
||||
OSErr theErr;
|
||||
|
||||
|
||||
theErr = FSSetForkSize((short)(int)hFile, fsAtMark, 0);
|
||||
|
||||
|
||||
SetLastError(theErr);
|
||||
|
||||
|
||||
return theErr == noErr;
|
||||
}
|
||||
|
||||
@@ -701,13 +701,13 @@ BOOL ReadFile( HANDLE hFile, /* handle to file */
|
||||
|
||||
ByteCount nbCharsRead;
|
||||
OSErr theErr;
|
||||
|
||||
|
||||
nbCharsRead = ulLen;
|
||||
theErr = FSReadFork((short)(int)hFile, fsAtMark, 0, nbCharsRead, pBuffer, &nbCharsRead);
|
||||
*ulRead = nbCharsRead;
|
||||
|
||||
|
||||
SetLastError(theErr);
|
||||
|
||||
|
||||
return theErr == noErr;
|
||||
}
|
||||
|
||||
@@ -725,13 +725,13 @@ BOOL WriteFile( HANDLE hFile, /* handle to file */
|
||||
|
||||
ByteCount nbCharsToWrite;
|
||||
OSErr theErr;
|
||||
|
||||
nbCharsToWrite = ulLen;
|
||||
|
||||
nbCharsToWrite = ulLen;
|
||||
theErr = FSWriteFork((short)(int)hFile, fsAtMark, 0, nbCharsToWrite, pBuffer, &nbCharsToWrite);
|
||||
*ulWritten = nbCharsToWrite;
|
||||
|
||||
|
||||
SetLastError(theErr);
|
||||
|
||||
|
||||
return theErr == noErr;
|
||||
}
|
||||
|
||||
@@ -744,15 +744,15 @@ BOOL IsBadReadPtr(const void * ptr, int size)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Returns attributes of a file. Actually, it doesn't, it just checks if
|
||||
// Returns attributes of a file. Actually, it doesn't, it just checks if
|
||||
// the file exists, since that's all StormLib uses it for
|
||||
DWORD GetFileAttributes(const char * szFileName)
|
||||
{
|
||||
FSRef theRef;
|
||||
OSErr theErr;
|
||||
|
||||
|
||||
theErr = FSLocationFromFullPath(szFileName, &theRef);
|
||||
|
||||
|
||||
if (theErr != noErr)
|
||||
return -1u;
|
||||
else
|
||||
|
||||
@@ -17,16 +17,16 @@
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. The origin of this software must not be misrepresented; you must
|
||||
not claim that you wrote the original software. If you use this
|
||||
software in a product, an acknowledgment in the product
|
||||
2. The origin of this software must not be misrepresented; you must
|
||||
not claim that you wrote the original software. If you use this
|
||||
software in a product, an acknowledgment in the product
|
||||
documentation would be appreciated but is not required.
|
||||
|
||||
3. Altered source versions must be plainly marked as such, and must
|
||||
not be misrepresented as being the original software.
|
||||
|
||||
4. The name of the author may not be used to endorse or promote
|
||||
products derived from this software without specific prior written
|
||||
4. The name of the author may not be used to endorse or promote
|
||||
products derived from this software without specific prior written
|
||||
permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
|
||||
@@ -57,8 +57,8 @@
|
||||
|
||||
For more information on these sources, see the manual.
|
||||
|
||||
To get some idea how the block sorting algorithms in this file
|
||||
work, read my paper
|
||||
To get some idea how the block sorting algorithms in this file
|
||||
work, read my paper
|
||||
On the Performance of BWT Sorting Algorithms
|
||||
in Proceedings of the IEEE Data Compression Conference 2000,
|
||||
Snowbird, Utah, USA, 27-30 March 2000. The main sort in this
|
||||
@@ -74,11 +74,11 @@
|
||||
/*---------------------------------------------*/
|
||||
|
||||
/*---------------------------------------------*/
|
||||
static
|
||||
static
|
||||
__inline__
|
||||
void fallbackSimpleSort ( UInt32* fmap,
|
||||
UInt32* eclass,
|
||||
Int32 lo,
|
||||
void fallbackSimpleSort ( UInt32* fmap,
|
||||
UInt32* eclass,
|
||||
Int32 lo,
|
||||
Int32 hi )
|
||||
{
|
||||
Int32 i, j, tmp;
|
||||
@@ -137,9 +137,9 @@ void fallbackSimpleSort ( UInt32* fmap,
|
||||
|
||||
|
||||
static
|
||||
void fallbackQSort3 ( UInt32* fmap,
|
||||
void fallbackQSort3 ( UInt32* fmap,
|
||||
UInt32* eclass,
|
||||
Int32 loSt,
|
||||
Int32 loSt,
|
||||
Int32 hiSt )
|
||||
{
|
||||
Int32 unLo, unHi, ltLo, gtHi, n, m;
|
||||
@@ -164,9 +164,9 @@ void fallbackQSort3 ( UInt32* fmap,
|
||||
}
|
||||
|
||||
/* Random partitioning. Median of 3 sometimes fails to
|
||||
avoid bad cases. Median of 9 seems to help but
|
||||
avoid bad cases. Median of 9 seems to help but
|
||||
looks rather expensive. This too seems to work but
|
||||
is cheaper. Guidance for the magic constants
|
||||
is cheaper. Guidance for the magic constants
|
||||
7621 and 32768 is taken from Sedgewick's algorithms
|
||||
book, chapter 35.
|
||||
*/
|
||||
@@ -183,10 +183,10 @@ void fallbackQSort3 ( UInt32* fmap,
|
||||
while (1) {
|
||||
if (unLo > unHi) break;
|
||||
n = (Int32)eclass[fmap[unLo]] - (Int32)med;
|
||||
if (n == 0) {
|
||||
fswap(fmap[unLo], fmap[ltLo]);
|
||||
ltLo++; unLo++;
|
||||
continue;
|
||||
if (n == 0) {
|
||||
fswap(fmap[unLo], fmap[ltLo]);
|
||||
ltLo++; unLo++;
|
||||
continue;
|
||||
};
|
||||
if (n > 0) break;
|
||||
unLo++;
|
||||
@@ -194,10 +194,10 @@ void fallbackQSort3 ( UInt32* fmap,
|
||||
while (1) {
|
||||
if (unLo > unHi) break;
|
||||
n = (Int32)eclass[fmap[unHi]] - (Int32)med;
|
||||
if (n == 0) {
|
||||
fswap(fmap[unHi], fmap[gtHi]);
|
||||
gtHi--; unHi--;
|
||||
continue;
|
||||
if (n == 0) {
|
||||
fswap(fmap[unHi], fmap[gtHi]);
|
||||
gtHi--; unHi--;
|
||||
continue;
|
||||
};
|
||||
if (n < 0) break;
|
||||
unHi--;
|
||||
@@ -256,8 +256,8 @@ void fallbackQSort3 ( UInt32* fmap,
|
||||
#define UNALIGNED_BH(zz) ((zz) & 0x01f)
|
||||
|
||||
static
|
||||
void fallbackSort ( UInt32* fmap,
|
||||
UInt32* eclass,
|
||||
void fallbackSort ( UInt32* fmap,
|
||||
UInt32* eclass,
|
||||
UInt32* bhtab,
|
||||
Int32 nblock,
|
||||
Int32 verb )
|
||||
@@ -298,7 +298,7 @@ void fallbackSort ( UInt32* fmap,
|
||||
--*/
|
||||
|
||||
/*-- set sentinel bits for block-end detection --*/
|
||||
for (i = 0; i < 32; i++) {
|
||||
for (i = 0; i < 32; i++) {
|
||||
SET_BH(nblock + 2*i);
|
||||
CLEAR_BH(nblock + 2*i + 1);
|
||||
}
|
||||
@@ -307,7 +307,7 @@ void fallbackSort ( UInt32* fmap,
|
||||
H = 1;
|
||||
while (1) {
|
||||
|
||||
if (verb >= 4)
|
||||
if (verb >= 4)
|
||||
VPrintf1 ( " depth %6d has ", H );
|
||||
|
||||
j = 0;
|
||||
@@ -321,7 +321,7 @@ void fallbackSort ( UInt32* fmap,
|
||||
r = -1;
|
||||
while (1) {
|
||||
|
||||
/*-- find the next non-singleton bucket --*/
|
||||
/*-- find the next non-singleton bucket --*/
|
||||
k = r + 1;
|
||||
while (ISSET_BH(k) && UNALIGNED_BH(k)) k++;
|
||||
if (ISSET_BH(k)) {
|
||||
@@ -352,14 +352,14 @@ void fallbackSort ( UInt32* fmap,
|
||||
}
|
||||
}
|
||||
|
||||
if (verb >= 4)
|
||||
if (verb >= 4)
|
||||
VPrintf1 ( "%6d unresolved strings\n", nNotDone );
|
||||
|
||||
H *= 2;
|
||||
if (H > nblock || nNotDone == 0) break;
|
||||
}
|
||||
|
||||
/*--
|
||||
/*--
|
||||
Reconstruct the original block in
|
||||
eclass8 [0 .. nblock-1], since the
|
||||
previous phase destroyed it.
|
||||
@@ -391,9 +391,9 @@ void fallbackSort ( UInt32* fmap,
|
||||
/*---------------------------------------------*/
|
||||
static
|
||||
__inline__
|
||||
Bool mainGtU ( UInt32 i1,
|
||||
Bool mainGtU ( UInt32 i1,
|
||||
UInt32 i2,
|
||||
UChar* block,
|
||||
UChar* block,
|
||||
UInt16* quadrant,
|
||||
UInt32 nblock,
|
||||
Int32* budget )
|
||||
@@ -533,8 +533,8 @@ void mainSimpleSort ( UInt32* ptr,
|
||||
UChar* block,
|
||||
UInt16* quadrant,
|
||||
Int32 nblock,
|
||||
Int32 lo,
|
||||
Int32 hi,
|
||||
Int32 lo,
|
||||
Int32 hi,
|
||||
Int32 d,
|
||||
Int32* budget )
|
||||
{
|
||||
@@ -558,8 +558,8 @@ void mainSimpleSort ( UInt32* ptr,
|
||||
if (i > hi) break;
|
||||
v = ptr[i];
|
||||
j = i;
|
||||
while ( mainGtU (
|
||||
ptr[j-h]+d, v+d, block, quadrant, nblock, budget
|
||||
while ( mainGtU (
|
||||
ptr[j-h]+d, v+d, block, quadrant, nblock, budget
|
||||
) ) {
|
||||
ptr[j] = ptr[j-h];
|
||||
j = j - h;
|
||||
@@ -572,8 +572,8 @@ void mainSimpleSort ( UInt32* ptr,
|
||||
if (i > hi) break;
|
||||
v = ptr[i];
|
||||
j = i;
|
||||
while ( mainGtU (
|
||||
ptr[j-h]+d, v+d, block, quadrant, nblock, budget
|
||||
while ( mainGtU (
|
||||
ptr[j-h]+d, v+d, block, quadrant, nblock, budget
|
||||
) ) {
|
||||
ptr[j] = ptr[j-h];
|
||||
j = j - h;
|
||||
@@ -586,8 +586,8 @@ void mainSimpleSort ( UInt32* ptr,
|
||||
if (i > hi) break;
|
||||
v = ptr[i];
|
||||
j = i;
|
||||
while ( mainGtU (
|
||||
ptr[j-h]+d, v+d, block, quadrant, nblock, budget
|
||||
while ( mainGtU (
|
||||
ptr[j-h]+d, v+d, block, quadrant, nblock, budget
|
||||
) ) {
|
||||
ptr[j] = ptr[j-h];
|
||||
j = j - h;
|
||||
@@ -625,13 +625,13 @@ void mainSimpleSort ( UInt32* ptr,
|
||||
} \
|
||||
}
|
||||
|
||||
static
|
||||
static
|
||||
__inline__
|
||||
UChar mmed3 ( UChar a, UChar b, UChar c )
|
||||
{
|
||||
UChar t;
|
||||
if (a > b) { t = a; a = b; b = t; };
|
||||
if (b > c) {
|
||||
if (b > c) {
|
||||
b = c;
|
||||
if (a > b) b = a;
|
||||
}
|
||||
@@ -669,8 +669,8 @@ void mainQSort3 ( UInt32* ptr,
|
||||
UChar* block,
|
||||
UInt16* quadrant,
|
||||
Int32 nblock,
|
||||
Int32 loSt,
|
||||
Int32 hiSt,
|
||||
Int32 loSt,
|
||||
Int32 hiSt,
|
||||
Int32 dSt,
|
||||
Int32* budget )
|
||||
{
|
||||
@@ -693,14 +693,14 @@ void mainQSort3 ( UInt32* ptr,
|
||||
AssertH ( sp < MAIN_QSORT_STACK_SIZE, 1001 );
|
||||
|
||||
mpop ( lo, hi, d );
|
||||
if (hi - lo < MAIN_QSORT_SMALL_THRESH ||
|
||||
if (hi - lo < MAIN_QSORT_SMALL_THRESH ||
|
||||
d > MAIN_QSORT_DEPTH_THRESH) {
|
||||
mainSimpleSort ( ptr, block, quadrant, nblock, lo, hi, d, budget );
|
||||
if (*budget < 0) return;
|
||||
continue;
|
||||
}
|
||||
|
||||
med = (Int32)
|
||||
med = (Int32)
|
||||
mmed3 ( block[ptr[ lo ]+d],
|
||||
block[ptr[ hi ]+d],
|
||||
block[ptr[ (lo+hi)>>1 ]+d] );
|
||||
@@ -712,9 +712,9 @@ void mainQSort3 ( UInt32* ptr,
|
||||
while (True) {
|
||||
if (unLo > unHi) break;
|
||||
n = ((Int32)block[ptr[unLo]+d]) - med;
|
||||
if (n == 0) {
|
||||
mswap(ptr[unLo], ptr[ltLo]);
|
||||
ltLo++; unLo++; continue;
|
||||
if (n == 0) {
|
||||
mswap(ptr[unLo], ptr[ltLo]);
|
||||
ltLo++; unLo++; continue;
|
||||
};
|
||||
if (n > 0) break;
|
||||
unLo++;
|
||||
@@ -722,9 +722,9 @@ void mainQSort3 ( UInt32* ptr,
|
||||
while (True) {
|
||||
if (unLo > unHi) break;
|
||||
n = ((Int32)block[ptr[unHi]+d]) - med;
|
||||
if (n == 0) {
|
||||
mswap(ptr[unHi], ptr[gtHi]);
|
||||
gtHi--; unHi--; continue;
|
||||
if (n == 0) {
|
||||
mswap(ptr[unHi], ptr[gtHi]);
|
||||
gtHi--; unHi--; continue;
|
||||
};
|
||||
if (n < 0) break;
|
||||
unHi--;
|
||||
@@ -795,9 +795,9 @@ void mainQSort3 ( UInt32* ptr,
|
||||
#define CLEARMASK (~(SETMASK))
|
||||
|
||||
static
|
||||
void mainSort ( UInt32* ptr,
|
||||
void mainSort ( UInt32* ptr,
|
||||
UChar* block,
|
||||
UInt16* quadrant,
|
||||
UInt16* quadrant,
|
||||
UInt32* ftab,
|
||||
Int32 nblock,
|
||||
Int32 verb,
|
||||
@@ -925,7 +925,7 @@ void mainSort ( UInt32* ptr,
|
||||
/*--
|
||||
Step 1:
|
||||
Complete the big bucket [ss] by quicksorting
|
||||
any unsorted small buckets [ss, j], for j != ss.
|
||||
any unsorted small buckets [ss, j], for j != ss.
|
||||
Hopefully previous pointer-scanning phases have already
|
||||
completed many of the small buckets [ss, j], so
|
||||
we don't have to sort them at all.
|
||||
@@ -941,10 +941,10 @@ void mainSort ( UInt32* ptr,
|
||||
VPrintf4 ( " qsort [0x%x, 0x%x] "
|
||||
"done %d this %d\n",
|
||||
ss, j, numQSorted, hi - lo + 1 );
|
||||
mainQSort3 (
|
||||
ptr, block, quadrant, nblock,
|
||||
lo, hi, BZ_N_RADIX, budget
|
||||
);
|
||||
mainQSort3 (
|
||||
ptr, block, quadrant, nblock,
|
||||
lo, hi, BZ_N_RADIX, budget
|
||||
);
|
||||
numQSorted += (hi - lo + 1);
|
||||
if (*budget < 0) return;
|
||||
}
|
||||
@@ -976,16 +976,16 @@ void mainSort ( UInt32* ptr,
|
||||
for (j = (ftab[(ss+1) << 8] & CLEARMASK) - 1; j > copyEnd[ss]; j--) {
|
||||
k = ptr[j]-1; if (k < 0) k += nblock;
|
||||
c1 = block[k];
|
||||
if (!bigDone[c1])
|
||||
if (!bigDone[c1])
|
||||
ptr[ copyEnd[c1]-- ] = k;
|
||||
}
|
||||
}
|
||||
|
||||
AssertH ( (copyStart[ss]-1 == copyEnd[ss])
|
||||
||
|
||||
||
|
||||
/* Extremely rare case missing in bzip2-1.0.0 and 1.0.1.
|
||||
Necessity for this case is demonstrated by compressing
|
||||
a sequence of approximately 48.5 million of character
|
||||
Necessity for this case is demonstrated by compressing
|
||||
a sequence of approximately 48.5 million of character
|
||||
251; 1.0.0/1.0.1 will then die here. */
|
||||
(copyStart[ss] == 0 && copyEnd[ss] == nblock-1),
|
||||
1007 )
|
||||
@@ -1002,7 +1002,7 @@ void mainSort ( UInt32* ptr,
|
||||
updating for the last bucket is pointless.
|
||||
|
||||
The quadrant array provides a way to incrementally
|
||||
cache sort orderings, as they appear, so as to
|
||||
cache sort orderings, as they appear, so as to
|
||||
make subsequent comparisons in fullGtU() complete
|
||||
faster. For repetitive blocks this makes a big
|
||||
difference (but not big enough to be able to avoid
|
||||
@@ -1012,9 +1012,9 @@ void mainSort ( UInt32* ptr,
|
||||
|
||||
for 0 <= i < nblock and 0 <= j <= nblock
|
||||
|
||||
if block[i] != block[j],
|
||||
if block[i] != block[j],
|
||||
|
||||
then the relative values of quadrant[i] and
|
||||
then the relative values of quadrant[i] and
|
||||
quadrant[j] are meaningless.
|
||||
|
||||
else {
|
||||
@@ -1077,7 +1077,7 @@ void mainSort ( UInt32* ptr,
|
||||
*/
|
||||
void BZ2_blockSort ( EState* s )
|
||||
{
|
||||
UInt32* ptr = s->ptr;
|
||||
UInt32* ptr = s->ptr;
|
||||
UChar* block = s->block;
|
||||
UInt32* ftab = s->ftab;
|
||||
Int32 nblock = s->nblock;
|
||||
@@ -1101,8 +1101,8 @@ void BZ2_blockSort ( EState* s )
|
||||
quadrant = (UInt16*)(&(block[i]));
|
||||
|
||||
/* (wfact-1) / 3 puts the default-factor-30
|
||||
transition point at very roughly the same place as
|
||||
with v0.1 and v0.9.0.
|
||||
transition point at very roughly the same place as
|
||||
with v0.1 and v0.9.0.
|
||||
Not that it particularly matters any more, since the
|
||||
resulting compressed stream is now the same regardless
|
||||
of whether or not we use the main sort or fallback sort.
|
||||
@@ -1113,14 +1113,14 @@ void BZ2_blockSort ( EState* s )
|
||||
budget = budgetInit;
|
||||
|
||||
mainSort ( ptr, block, quadrant, ftab, nblock, verb, &budget );
|
||||
if (verb >= 3)
|
||||
if (verb >= 3)
|
||||
VPrintf3 ( " %d work, %d block, ratio %5.2f\n",
|
||||
budgetInit - budget,
|
||||
nblock,
|
||||
nblock,
|
||||
(float)(budgetInit - budget) /
|
||||
(float)(nblock==0 ? 1 : nblock) );
|
||||
(float)(nblock==0 ? 1 : nblock) );
|
||||
if (budget < 0) {
|
||||
if (verb >= 2)
|
||||
if (verb >= 2)
|
||||
VPrintf0 ( " too repetitive; using fallback"
|
||||
" sorting algorithm\n" );
|
||||
fallbackSort ( s->arr1, s->arr2, ftab, nblock, verb );
|
||||
|
||||
@@ -16,16 +16,16 @@
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. The origin of this software must not be misrepresented; you must
|
||||
not claim that you wrote the original software. If you use this
|
||||
software in a product, an acknowledgment in the product
|
||||
2. The origin of this software must not be misrepresented; you must
|
||||
not claim that you wrote the original software. If you use this
|
||||
software in a product, an acknowledgment in the product
|
||||
documentation would be appreciated but is not required.
|
||||
|
||||
3. Altered source versions must be plainly marked as such, and must
|
||||
not be misrepresented as being the original software.
|
||||
|
||||
4. The name of the author may not be used to endorse or promote
|
||||
products derived from this software without specific prior written
|
||||
4. The name of the author may not be used to endorse or promote
|
||||
products derived from this software without specific prior written
|
||||
permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
|
||||
@@ -64,12 +64,12 @@
|
||||
|
||||
/*--
|
||||
WARNING:
|
||||
This program and library (attempts to) compress data by
|
||||
performing several non-trivial transformations on it.
|
||||
Unless you are 100% familiar with *all* the algorithms
|
||||
contained herein, and with the consequences of modifying them,
|
||||
you should NOT meddle with the compression or decompression
|
||||
machinery. Incorrect changes can and very likely *will*
|
||||
This program and library (attempts to) compress data by
|
||||
performing several non-trivial transformations on it.
|
||||
Unless you are 100% familiar with *all* the algorithms
|
||||
contained herein, and with the consequences of modifying them,
|
||||
you should NOT meddle with the compression or decompression
|
||||
machinery. Incorrect changes can and very likely *will*
|
||||
lead to disasterous loss of data.
|
||||
|
||||
DISCLAIMER:
|
||||
@@ -84,8 +84,8 @@
|
||||
of various special cases in the code which occur with very low
|
||||
but non-zero probability make it impossible to rule out the
|
||||
possibility of bugs remaining in the program. DO NOT COMPRESS
|
||||
ANY DATA WITH THIS PROGRAM AND/OR LIBRARY UNLESS YOU ARE PREPARED
|
||||
TO ACCEPT THE POSSIBILITY, HOWEVER SMALL, THAT THE DATA WILL
|
||||
ANY DATA WITH THIS PROGRAM AND/OR LIBRARY UNLESS YOU ARE PREPARED
|
||||
TO ACCEPT THE POSSIBILITY, HOWEVER SMALL, THAT THE DATA WILL
|
||||
NOT BE RECOVERABLE.
|
||||
|
||||
That is not to say this program is inherently unreliable.
|
||||
@@ -93,9 +93,9 @@
|
||||
has been carefully constructed and extensively tested.
|
||||
|
||||
PATENTS:
|
||||
To the best of my knowledge, bzip2/libbzip2 does not use any
|
||||
patented algorithms. However, I do not have the resources
|
||||
available to carry out a full patent search. Therefore I cannot
|
||||
To the best of my knowledge, bzip2/libbzip2 does not use any
|
||||
patented algorithms. However, I do not have the resources
|
||||
available to carry out a full patent search. Therefore I cannot
|
||||
give any guarantee of the above statement.
|
||||
--*/
|
||||
|
||||
@@ -257,7 +257,7 @@ typedef int Int32;
|
||||
typedef unsigned int UInt32;
|
||||
typedef short Int16;
|
||||
typedef unsigned short UInt16;
|
||||
|
||||
|
||||
#define True ((Bool)1)
|
||||
#define False ((Bool)0)
|
||||
|
||||
@@ -321,7 +321,7 @@ static void* myMalloc ( Int32 );
|
||||
/*---------------------------------------------------*/
|
||||
|
||||
typedef
|
||||
struct { UChar b[8]; }
|
||||
struct { UChar b[8]; }
|
||||
UInt64;
|
||||
|
||||
|
||||
@@ -364,7 +364,7 @@ Bool uInt64_isZero ( UInt64* n )
|
||||
|
||||
|
||||
/* Divide *n by 10, and return the remainder. */
|
||||
static
|
||||
static
|
||||
Int32 uInt64_qrm10 ( UInt64* n )
|
||||
{
|
||||
UInt32 rem, tmp;
|
||||
@@ -395,7 +395,7 @@ void uInt64_toAscii ( char* outbuf, UInt64* n )
|
||||
nBuf++;
|
||||
} while (!uInt64_isZero(&n_copy));
|
||||
outbuf[nBuf] = 0;
|
||||
for (i = 0; i < nBuf; i++)
|
||||
for (i = 0; i < nBuf; i++)
|
||||
outbuf[i] = buf[nBuf-i-1];
|
||||
}
|
||||
|
||||
@@ -405,7 +405,7 @@ void uInt64_toAscii ( char* outbuf, UInt64* n )
|
||||
/*---------------------------------------------------*/
|
||||
|
||||
/*---------------------------------------------*/
|
||||
static
|
||||
static
|
||||
Bool myfeof ( FILE* f )
|
||||
{
|
||||
Int32 c = fgetc ( f );
|
||||
@@ -416,7 +416,7 @@ Bool myfeof ( FILE* f )
|
||||
|
||||
|
||||
/*---------------------------------------------*/
|
||||
static
|
||||
static
|
||||
void compressStream ( FILE *stream, FILE *zStream )
|
||||
{
|
||||
BZFILE* bzf = NULL;
|
||||
@@ -432,8 +432,8 @@ void compressStream ( FILE *stream, FILE *zStream )
|
||||
if (ferror(stream)) goto errhandler_io;
|
||||
if (ferror(zStream)) goto errhandler_io;
|
||||
|
||||
bzf = BZ2_bzWriteOpen ( &bzerr, zStream,
|
||||
blockSize100k, verbosity, workFactor );
|
||||
bzf = BZ2_bzWriteOpen ( &bzerr, zStream,
|
||||
blockSize100k, verbosity, workFactor );
|
||||
if (bzerr != BZ_OK) goto errhandler;
|
||||
|
||||
if (verbosity >= 2) fprintf ( stderr, "\n" );
|
||||
@@ -448,7 +448,7 @@ void compressStream ( FILE *stream, FILE *zStream )
|
||||
|
||||
}
|
||||
|
||||
BZ2_bzWriteClose64 ( &bzerr, bzf, 0,
|
||||
BZ2_bzWriteClose64 ( &bzerr, bzf, 0,
|
||||
&nbytes_in_lo32, &nbytes_in_hi32,
|
||||
&nbytes_out_lo32, &nbytes_out_hi32 );
|
||||
if (bzerr != BZ_OK) goto errhandler;
|
||||
@@ -468,34 +468,34 @@ void compressStream ( FILE *stream, FILE *zStream )
|
||||
|
||||
if (verbosity >= 1) {
|
||||
if (nbytes_in_lo32 == 0 && nbytes_in_hi32 == 0) {
|
||||
fprintf ( stderr, " no data compressed.\n");
|
||||
fprintf ( stderr, " no data compressed.\n");
|
||||
} else {
|
||||
Char buf_nin[32], buf_nout[32];
|
||||
UInt64 nbytes_in, nbytes_out;
|
||||
double nbytes_in_d, nbytes_out_d;
|
||||
uInt64_from_UInt32s ( &nbytes_in,
|
||||
nbytes_in_lo32, nbytes_in_hi32 );
|
||||
uInt64_from_UInt32s ( &nbytes_out,
|
||||
nbytes_out_lo32, nbytes_out_hi32 );
|
||||
nbytes_in_d = uInt64_to_double ( &nbytes_in );
|
||||
nbytes_out_d = uInt64_to_double ( &nbytes_out );
|
||||
uInt64_toAscii ( buf_nin, &nbytes_in );
|
||||
uInt64_toAscii ( buf_nout, &nbytes_out );
|
||||
fprintf ( stderr, "%6.3f:1, %6.3f bits/byte, "
|
||||
"%5.2f%% saved, %s in, %s out.\n",
|
||||
nbytes_in_d / nbytes_out_d,
|
||||
(8.0 * nbytes_out_d) / nbytes_in_d,
|
||||
100.0 * (1.0 - nbytes_out_d / nbytes_in_d),
|
||||
buf_nin,
|
||||
buf_nout
|
||||
);
|
||||
Char buf_nin[32], buf_nout[32];
|
||||
UInt64 nbytes_in, nbytes_out;
|
||||
double nbytes_in_d, nbytes_out_d;
|
||||
uInt64_from_UInt32s ( &nbytes_in,
|
||||
nbytes_in_lo32, nbytes_in_hi32 );
|
||||
uInt64_from_UInt32s ( &nbytes_out,
|
||||
nbytes_out_lo32, nbytes_out_hi32 );
|
||||
nbytes_in_d = uInt64_to_double ( &nbytes_in );
|
||||
nbytes_out_d = uInt64_to_double ( &nbytes_out );
|
||||
uInt64_toAscii ( buf_nin, &nbytes_in );
|
||||
uInt64_toAscii ( buf_nout, &nbytes_out );
|
||||
fprintf ( stderr, "%6.3f:1, %6.3f bits/byte, "
|
||||
"%5.2f%% saved, %s in, %s out.\n",
|
||||
nbytes_in_d / nbytes_out_d,
|
||||
(8.0 * nbytes_out_d) / nbytes_in_d,
|
||||
100.0 * (1.0 - nbytes_out_d / nbytes_in_d),
|
||||
buf_nin,
|
||||
buf_nout
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
errhandler:
|
||||
BZ2_bzWriteClose64 ( &bzerr_dummy, bzf, 1,
|
||||
BZ2_bzWriteClose64 ( &bzerr_dummy, bzf, 1,
|
||||
&nbytes_in_lo32, &nbytes_in_hi32,
|
||||
&nbytes_out_lo32, &nbytes_out_hi32 );
|
||||
switch (bzerr) {
|
||||
@@ -517,7 +517,7 @@ void compressStream ( FILE *stream, FILE *zStream )
|
||||
|
||||
|
||||
/*---------------------------------------------*/
|
||||
static
|
||||
static
|
||||
Bool uncompressStream ( FILE *zStream, FILE *stream )
|
||||
{
|
||||
BZFILE* bzf = NULL;
|
||||
@@ -539,8 +539,8 @@ Bool uncompressStream ( FILE *zStream, FILE *stream )
|
||||
|
||||
while (True) {
|
||||
|
||||
bzf = BZ2_bzReadOpen (
|
||||
&bzerr, zStream, verbosity,
|
||||
bzf = BZ2_bzReadOpen (
|
||||
&bzerr, zStream, verbosity,
|
||||
(int)smallMode, unused, nUnused
|
||||
);
|
||||
if (bzf == NULL || bzerr != BZ_OK) goto errhandler;
|
||||
@@ -584,19 +584,19 @@ Bool uncompressStream ( FILE *zStream, FILE *stream )
|
||||
if (verbosity >= 2) fprintf ( stderr, "\n " );
|
||||
return True;
|
||||
|
||||
trycat:
|
||||
trycat:
|
||||
if (forceOverwrite) {
|
||||
rewind(zStream);
|
||||
while (True) {
|
||||
if (myfeof(zStream)) break;
|
||||
nread = fread ( obuf, sizeof(UChar), 5000, zStream );
|
||||
if (ferror(zStream)) goto errhandler_io;
|
||||
if (nread > 0) fwrite ( obuf, sizeof(UChar), nread, stream );
|
||||
if (ferror(stream)) goto errhandler_io;
|
||||
if (myfeof(zStream)) break;
|
||||
nread = fread ( obuf, sizeof(UChar), 5000, zStream );
|
||||
if (ferror(zStream)) goto errhandler_io;
|
||||
if (nread > 0) fwrite ( obuf, sizeof(UChar), nread, stream );
|
||||
if (ferror(stream)) goto errhandler_io;
|
||||
}
|
||||
goto closeok;
|
||||
}
|
||||
|
||||
|
||||
errhandler:
|
||||
BZ2_bzReadClose ( &bzerr_dummy, bzf );
|
||||
switch (bzerr) {
|
||||
@@ -618,10 +618,10 @@ Bool uncompressStream ( FILE *zStream, FILE *stream )
|
||||
return False;
|
||||
} else {
|
||||
if (noisy)
|
||||
fprintf ( stderr,
|
||||
fprintf ( stderr,
|
||||
"\n%s: %s: trailing garbage after EOF ignored\n",
|
||||
progName, inName );
|
||||
return True;
|
||||
return True;
|
||||
}
|
||||
default:
|
||||
panic ( "decompress:unexpected error" );
|
||||
@@ -633,7 +633,7 @@ Bool uncompressStream ( FILE *zStream, FILE *stream )
|
||||
|
||||
|
||||
/*---------------------------------------------*/
|
||||
static
|
||||
static
|
||||
Bool testStream ( FILE *zStream )
|
||||
{
|
||||
BZFILE* bzf = NULL;
|
||||
@@ -652,8 +652,8 @@ Bool testStream ( FILE *zStream )
|
||||
|
||||
while (True) {
|
||||
|
||||
bzf = BZ2_bzReadOpen (
|
||||
&bzerr, zStream, verbosity,
|
||||
bzf = BZ2_bzReadOpen (
|
||||
&bzerr, zStream, verbosity,
|
||||
(int)smallMode, unused, nUnused
|
||||
);
|
||||
if (bzf == NULL || bzerr != BZ_OK) goto errhandler;
|
||||
@@ -686,7 +686,7 @@ Bool testStream ( FILE *zStream )
|
||||
|
||||
errhandler:
|
||||
BZ2_bzReadClose ( &bzerr_dummy, bzf );
|
||||
if (verbosity == 0)
|
||||
if (verbosity == 0)
|
||||
fprintf ( stderr, "%s: %s: ", progName, inName );
|
||||
switch (bzerr) {
|
||||
case BZ_CONFIG_ERROR:
|
||||
@@ -707,14 +707,14 @@ Bool testStream ( FILE *zStream )
|
||||
case BZ_DATA_ERROR_MAGIC:
|
||||
if (zStream != stdin) fclose(zStream);
|
||||
if (streamNo == 1) {
|
||||
fprintf ( stderr,
|
||||
fprintf ( stderr,
|
||||
"bad magic number (file not created by bzip2)\n" );
|
||||
return False;
|
||||
} else {
|
||||
if (noisy)
|
||||
fprintf ( stderr,
|
||||
fprintf ( stderr,
|
||||
"trailing garbage after EOF ignored\n" );
|
||||
return True;
|
||||
return True;
|
||||
}
|
||||
default:
|
||||
panic ( "test:unexpected error" );
|
||||
@@ -738,7 +738,7 @@ void setExit ( Int32 v )
|
||||
|
||||
|
||||
/*---------------------------------------------*/
|
||||
static
|
||||
static
|
||||
void cadvise ( void )
|
||||
{
|
||||
if (noisy)
|
||||
@@ -753,26 +753,26 @@ void cadvise ( void )
|
||||
|
||||
|
||||
/*---------------------------------------------*/
|
||||
static
|
||||
static
|
||||
void showFileNames ( void )
|
||||
{
|
||||
if (noisy)
|
||||
fprintf (
|
||||
stderr,
|
||||
"\tInput file = %s, output file = %s\n",
|
||||
inName, outName
|
||||
inName, outName
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------*/
|
||||
static
|
||||
static
|
||||
void cleanUpAndFail ( Int32 ec )
|
||||
{
|
||||
IntNative retVal;
|
||||
struct MY_STAT statBuf;
|
||||
|
||||
if ( srcMode == SM_F2F
|
||||
if ( srcMode == SM_F2F
|
||||
&& opMode != OM_TEST
|
||||
&& deleteOutputOnInterrupt ) {
|
||||
|
||||
@@ -784,7 +784,7 @@ void cleanUpAndFail ( Int32 ec )
|
||||
retVal = MY_STAT ( inName, &statBuf );
|
||||
if (retVal == 0) {
|
||||
if (noisy)
|
||||
fprintf ( stderr,
|
||||
fprintf ( stderr,
|
||||
"%s: Deleting output file %s, if it exists.\n",
|
||||
progName, outName );
|
||||
if (outputHandleJustInCase != NULL)
|
||||
@@ -805,7 +805,7 @@ void cleanUpAndFail ( Int32 ec )
|
||||
fprintf ( stderr,
|
||||
"%s: `%s' may be incomplete.\n",
|
||||
progName, outName );
|
||||
fprintf ( stderr,
|
||||
fprintf ( stderr,
|
||||
"%s: I suggest doing an integrity test (bzip2 -tv)"
|
||||
" of it.\n",
|
||||
progName );
|
||||
@@ -813,7 +813,7 @@ void cleanUpAndFail ( Int32 ec )
|
||||
}
|
||||
|
||||
if (noisy && numFileNames > 0 && numFilesProcessed < numFileNames) {
|
||||
fprintf ( stderr,
|
||||
fprintf ( stderr,
|
||||
"%s: WARNING: some files have not been processed:\n"
|
||||
"%s: %d specified on command line, %d not processed yet.\n\n",
|
||||
progName, progName,
|
||||
@@ -825,7 +825,7 @@ void cleanUpAndFail ( Int32 ec )
|
||||
|
||||
|
||||
/*---------------------------------------------*/
|
||||
static
|
||||
static
|
||||
void panic ( Char* s )
|
||||
{
|
||||
fprintf ( stderr,
|
||||
@@ -840,7 +840,7 @@ void panic ( Char* s )
|
||||
|
||||
|
||||
/*---------------------------------------------*/
|
||||
static
|
||||
static
|
||||
void crcError ( void )
|
||||
{
|
||||
fprintf ( stderr,
|
||||
@@ -853,14 +853,14 @@ void crcError ( void )
|
||||
|
||||
|
||||
/*---------------------------------------------*/
|
||||
static
|
||||
static
|
||||
void compressedStreamEOF ( void )
|
||||
{
|
||||
if (noisy) {
|
||||
fprintf ( stderr,
|
||||
"\n%s: Compressed file ends unexpectedly;\n\t"
|
||||
"perhaps it is corrupted? *Possible* reason follows.\n",
|
||||
progName );
|
||||
"\n%s: Compressed file ends unexpectedly;\n\t"
|
||||
"perhaps it is corrupted? *Possible* reason follows.\n",
|
||||
progName );
|
||||
perror ( progName );
|
||||
showFileNames();
|
||||
cadvise();
|
||||
@@ -870,7 +870,7 @@ void compressedStreamEOF ( void )
|
||||
|
||||
|
||||
/*---------------------------------------------*/
|
||||
static
|
||||
static
|
||||
void ioError ( void )
|
||||
{
|
||||
fprintf ( stderr,
|
||||
@@ -884,7 +884,7 @@ void ioError ( void )
|
||||
|
||||
|
||||
/*---------------------------------------------*/
|
||||
static
|
||||
static
|
||||
void mySignalCatcher ( IntNative n )
|
||||
{
|
||||
fprintf ( stderr,
|
||||
@@ -895,11 +895,11 @@ void mySignalCatcher ( IntNative n )
|
||||
|
||||
|
||||
/*---------------------------------------------*/
|
||||
static
|
||||
static
|
||||
void mySIGSEGVorSIGBUScatcher ( IntNative n )
|
||||
{
|
||||
if (opMode == OM_Z)
|
||||
fprintf (
|
||||
fprintf (
|
||||
stderr,
|
||||
"\n%s: Caught a SIGSEGV or SIGBUS whilst compressing.\n"
|
||||
"\n"
|
||||
@@ -920,7 +920,7 @@ void mySIGSEGVorSIGBUScatcher ( IntNative n )
|
||||
"\n",
|
||||
progName );
|
||||
else
|
||||
fprintf (
|
||||
fprintf (
|
||||
stderr,
|
||||
"\n%s: Caught a SIGSEGV or SIGBUS whilst decompressing.\n"
|
||||
"\n"
|
||||
@@ -951,7 +951,7 @@ void mySIGSEGVorSIGBUScatcher ( IntNative n )
|
||||
|
||||
|
||||
/*---------------------------------------------*/
|
||||
static
|
||||
static
|
||||
void outOfMemory ( void )
|
||||
{
|
||||
fprintf ( stderr,
|
||||
@@ -963,7 +963,7 @@ void outOfMemory ( void )
|
||||
|
||||
|
||||
/*---------------------------------------------*/
|
||||
static
|
||||
static
|
||||
void configError ( void )
|
||||
{
|
||||
fprintf ( stderr,
|
||||
@@ -983,11 +983,11 @@ void configError ( void )
|
||||
|
||||
/* All rather crufty. The main problem is that input files
|
||||
are stat()d multiple times before use. This should be
|
||||
cleaned up.
|
||||
cleaned up.
|
||||
*/
|
||||
|
||||
/*---------------------------------------------*/
|
||||
static
|
||||
static
|
||||
void pad ( Char *s )
|
||||
{
|
||||
Int32 i;
|
||||
@@ -998,8 +998,8 @@ void pad ( Char *s )
|
||||
|
||||
|
||||
/*---------------------------------------------*/
|
||||
static
|
||||
void copyFileName ( Char* to, Char* from )
|
||||
static
|
||||
void copyFileName ( Char* to, Char* from )
|
||||
{
|
||||
if ( strlen(from) > FILE_NAME_LEN-10 ) {
|
||||
fprintf (
|
||||
@@ -1019,7 +1019,7 @@ void copyFileName ( Char* to, Char* from )
|
||||
|
||||
|
||||
/*---------------------------------------------*/
|
||||
static
|
||||
static
|
||||
Bool fileExists ( Char* name )
|
||||
{
|
||||
FILE *tmp = fopen ( name, "rb" );
|
||||
@@ -1059,7 +1059,7 @@ FILE* fopen_output_safely ( Char* name, const char* mode )
|
||||
/*--
|
||||
if in doubt, return True
|
||||
--*/
|
||||
static
|
||||
static
|
||||
Bool notAStandardFile ( Char* name )
|
||||
{
|
||||
IntNative i;
|
||||
@@ -1076,9 +1076,9 @@ Bool notAStandardFile ( Char* name )
|
||||
/*--
|
||||
rac 11/21/98 see if file has hard links to it
|
||||
--*/
|
||||
static
|
||||
static
|
||||
Int32 countHardLinks ( Char* name )
|
||||
{
|
||||
{
|
||||
IntNative i;
|
||||
struct MY_STAT statBuf;
|
||||
|
||||
@@ -1109,14 +1109,14 @@ Int32 countHardLinks ( Char* name )
|
||||
|
||||
It sounds pretty fragile to me. Whether this carries across
|
||||
robustly to arbitrary Unix-like platforms (or even works robustly
|
||||
on this one, RedHat 7.2) is unknown to me. Nevertheless ...
|
||||
on this one, RedHat 7.2) is unknown to me. Nevertheless ...
|
||||
*/
|
||||
#if BZ_UNIX
|
||||
static
|
||||
static
|
||||
struct MY_STAT fileMetaInfo;
|
||||
#endif
|
||||
|
||||
static
|
||||
static
|
||||
void saveInputFileMetaInfo ( Char *srcName )
|
||||
{
|
||||
# if BZ_UNIX
|
||||
@@ -1128,7 +1128,7 @@ void saveInputFileMetaInfo ( Char *srcName )
|
||||
}
|
||||
|
||||
|
||||
static
|
||||
static
|
||||
void applySavedMetaInfoToOutputFile ( Char *dstName )
|
||||
{
|
||||
# if BZ_UNIX
|
||||
@@ -1153,7 +1153,7 @@ void applySavedMetaInfoToOutputFile ( Char *dstName )
|
||||
|
||||
|
||||
/*---------------------------------------------*/
|
||||
static
|
||||
static
|
||||
Bool containsDubiousChars ( Char* name )
|
||||
{
|
||||
# if BZ_UNIX
|
||||
@@ -1162,7 +1162,7 @@ Bool containsDubiousChars ( Char* name )
|
||||
*/
|
||||
return False;
|
||||
# else /* ! BZ_UNIX */
|
||||
/* On non-unix (Win* platforms), wildcard characters are not allowed in
|
||||
/* On non-unix (Win* platforms), wildcard characters are not allowed in
|
||||
* filenames.
|
||||
*/
|
||||
for (; *name != '\0'; name++)
|
||||
@@ -1175,12 +1175,12 @@ Bool containsDubiousChars ( Char* name )
|
||||
/*---------------------------------------------*/
|
||||
#define BZ_N_SUFFIX_PAIRS 4
|
||||
|
||||
Char* zSuffix[BZ_N_SUFFIX_PAIRS]
|
||||
Char* zSuffix[BZ_N_SUFFIX_PAIRS]
|
||||
= { ".bz2", ".bz", ".tbz2", ".tbz" };
|
||||
Char* unzSuffix[BZ_N_SUFFIX_PAIRS]
|
||||
Char* unzSuffix[BZ_N_SUFFIX_PAIRS]
|
||||
= { "", "", ".tar", ".tar" };
|
||||
|
||||
static
|
||||
static
|
||||
Bool hasSuffix ( Char* s, Char* suffix )
|
||||
{
|
||||
Int32 ns = strlen(s);
|
||||
@@ -1190,8 +1190,8 @@ Bool hasSuffix ( Char* s, Char* suffix )
|
||||
return False;
|
||||
}
|
||||
|
||||
static
|
||||
Bool mapSuffix ( Char* name,
|
||||
static
|
||||
Bool mapSuffix ( Char* name,
|
||||
Char* oldSuffix, Char* newSuffix )
|
||||
{
|
||||
if (!hasSuffix(name,oldSuffix)) return False;
|
||||
@@ -1202,7 +1202,7 @@ Bool mapSuffix ( Char* name,
|
||||
|
||||
|
||||
/*---------------------------------------------*/
|
||||
static
|
||||
static
|
||||
void compress ( Char *name )
|
||||
{
|
||||
FILE *inStr;
|
||||
@@ -1216,18 +1216,18 @@ void compress ( Char *name )
|
||||
panic ( "compress: bad modes\n" );
|
||||
|
||||
switch (srcMode) {
|
||||
case SM_I2O:
|
||||
case SM_I2O:
|
||||
copyFileName ( inName, "(stdin)" );
|
||||
copyFileName ( outName, "(stdout)" );
|
||||
copyFileName ( outName, "(stdout)" );
|
||||
break;
|
||||
case SM_F2F:
|
||||
case SM_F2F:
|
||||
copyFileName ( inName, name );
|
||||
copyFileName ( outName, name );
|
||||
strcat ( outName, ".bz2" );
|
||||
strcat ( outName, ".bz2" );
|
||||
break;
|
||||
case SM_F2O:
|
||||
case SM_F2O:
|
||||
copyFileName ( inName, name );
|
||||
copyFileName ( outName, "(stdout)" );
|
||||
copyFileName ( outName, "(stdout)" );
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1247,7 +1247,7 @@ void compress ( Char *name )
|
||||
for (i = 0; i < BZ_N_SUFFIX_PAIRS; i++) {
|
||||
if (hasSuffix(inName, zSuffix[i])) {
|
||||
if (noisy)
|
||||
fprintf ( stderr,
|
||||
fprintf ( stderr,
|
||||
"%s: Input file %s already has %s suffix.\n",
|
||||
progName, inName, zSuffix[i] );
|
||||
setExit(1);
|
||||
@@ -1273,12 +1273,12 @@ void compress ( Char *name )
|
||||
}
|
||||
if ( srcMode == SM_F2F && fileExists ( outName ) ) {
|
||||
if (forceOverwrite) {
|
||||
remove(outName);
|
||||
remove(outName);
|
||||
} else {
|
||||
fprintf ( stderr, "%s: Output file %s already exists.\n",
|
||||
progName, outName );
|
||||
setExit(1);
|
||||
return;
|
||||
fprintf ( stderr, "%s: Output file %s already exists.\n",
|
||||
progName, outName );
|
||||
setExit(1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if ( srcMode == SM_F2F && !forceOverwrite &&
|
||||
@@ -1383,7 +1383,7 @@ void compress ( Char *name )
|
||||
|
||||
|
||||
/*---------------------------------------------*/
|
||||
static
|
||||
static
|
||||
void uncompress ( Char *name )
|
||||
{
|
||||
FILE *inStr;
|
||||
@@ -1400,22 +1400,22 @@ void uncompress ( Char *name )
|
||||
|
||||
cantGuess = False;
|
||||
switch (srcMode) {
|
||||
case SM_I2O:
|
||||
case SM_I2O:
|
||||
copyFileName ( inName, "(stdin)" );
|
||||
copyFileName ( outName, "(stdout)" );
|
||||
copyFileName ( outName, "(stdout)" );
|
||||
break;
|
||||
case SM_F2F:
|
||||
case SM_F2F:
|
||||
copyFileName ( inName, name );
|
||||
copyFileName ( outName, name );
|
||||
for (i = 0; i < BZ_N_SUFFIX_PAIRS; i++)
|
||||
if (mapSuffix(outName,zSuffix[i],unzSuffix[i]))
|
||||
goto zzz;
|
||||
goto zzz;
|
||||
cantGuess = True;
|
||||
strcat ( outName, ".out" );
|
||||
break;
|
||||
case SM_F2O:
|
||||
case SM_F2O:
|
||||
copyFileName ( inName, name );
|
||||
copyFileName ( outName, "(stdout)" );
|
||||
copyFileName ( outName, "(stdout)" );
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1452,14 +1452,14 @@ void uncompress ( Char *name )
|
||||
}
|
||||
if ( /* srcMode == SM_F2F implied && */ cantGuess ) {
|
||||
if (noisy)
|
||||
fprintf ( stderr,
|
||||
fprintf ( stderr,
|
||||
"%s: Can't guess original name for %s -- using %s\n",
|
||||
progName, inName, outName );
|
||||
/* just a warning, no return */
|
||||
}
|
||||
}
|
||||
if ( srcMode == SM_F2F && fileExists ( outName ) ) {
|
||||
if (forceOverwrite) {
|
||||
remove(outName);
|
||||
remove(outName);
|
||||
} else {
|
||||
fprintf ( stderr, "%s: Output file %s already exists.\n",
|
||||
progName, outName );
|
||||
@@ -1581,7 +1581,7 @@ void uncompress ( Char *name )
|
||||
|
||||
|
||||
/*---------------------------------------------*/
|
||||
static
|
||||
static
|
||||
void testf ( Char *name )
|
||||
{
|
||||
FILE *inStr;
|
||||
@@ -1670,7 +1670,7 @@ void testf ( Char *name )
|
||||
|
||||
|
||||
/*---------------------------------------------*/
|
||||
static
|
||||
static
|
||||
void license ( void )
|
||||
{
|
||||
fprintf ( stderr,
|
||||
@@ -1695,7 +1695,7 @@ void license ( void )
|
||||
|
||||
|
||||
/*---------------------------------------------*/
|
||||
static
|
||||
static
|
||||
void usage ( Char *fullProgName )
|
||||
{
|
||||
fprintf (
|
||||
@@ -1739,11 +1739,11 @@ void usage ( Char *fullProgName )
|
||||
|
||||
|
||||
/*---------------------------------------------*/
|
||||
static
|
||||
static
|
||||
void redundant ( Char* flag )
|
||||
{
|
||||
fprintf (
|
||||
stderr,
|
||||
fprintf (
|
||||
stderr,
|
||||
"%s: %s is redundant in versions 0.9.5 and above\n",
|
||||
progName, flag );
|
||||
}
|
||||
@@ -1755,8 +1755,8 @@ void redundant ( Char* flag )
|
||||
implement a linked list of command-line arguments,
|
||||
into which main() copies argv[1 .. argc-1].
|
||||
|
||||
The purpose of this exercise is to facilitate
|
||||
the expansion of wildcard characters * and ? in
|
||||
The purpose of this exercise is to facilitate
|
||||
the expansion of wildcard characters * and ? in
|
||||
filenames for OSs which don't know how to do it
|
||||
themselves, like MSDOS, Windows 95 and NT.
|
||||
|
||||
@@ -1773,7 +1773,7 @@ typedef
|
||||
|
||||
|
||||
/*---------------------------------------------*/
|
||||
static
|
||||
static
|
||||
void *myMalloc ( Int32 n )
|
||||
{
|
||||
void* p;
|
||||
@@ -1785,7 +1785,7 @@ void *myMalloc ( Int32 n )
|
||||
|
||||
|
||||
/*---------------------------------------------*/
|
||||
static
|
||||
static
|
||||
Cell *mkCell ( void )
|
||||
{
|
||||
Cell *c;
|
||||
@@ -1798,7 +1798,7 @@ Cell *mkCell ( void )
|
||||
|
||||
|
||||
/*---------------------------------------------*/
|
||||
static
|
||||
static
|
||||
Cell *snocString ( Cell *root, Char *name )
|
||||
{
|
||||
if (root == NULL) {
|
||||
@@ -1816,8 +1816,8 @@ Cell *snocString ( Cell *root, Char *name )
|
||||
|
||||
|
||||
/*---------------------------------------------*/
|
||||
static
|
||||
void addFlagsFromEnvVar ( Cell** argList, Char* varName )
|
||||
static
|
||||
void addFlagsFromEnvVar ( Cell** argList, Char* varName )
|
||||
{
|
||||
Int32 i, j, k;
|
||||
Char *envbase, *p;
|
||||
@@ -1894,7 +1894,7 @@ IntNative main ( IntNative argc, Char *argv[] )
|
||||
if (*tmp == PATH_SEP) progName = tmp + 1;
|
||||
|
||||
|
||||
/*-- Copy flags from env var BZIP2, and
|
||||
/*-- Copy flags from env var BZIP2, and
|
||||
expand filename wildcards in arg list.
|
||||
--*/
|
||||
argList = NULL;
|
||||
@@ -1977,7 +1977,7 @@ IntNative main ( IntNative argc, Char *argv[] )
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*-- And again ... --*/
|
||||
for (aa = argList; aa != NULL; aa = aa->link) {
|
||||
if (ISFLAG("--")) break;
|
||||
@@ -1991,7 +1991,7 @@ IntNative main ( IntNative argc, Char *argv[] )
|
||||
if (ISFLAG("--quiet")) noisy = False; else
|
||||
if (ISFLAG("--version")) license(); else
|
||||
if (ISFLAG("--license")) license(); else
|
||||
if (ISFLAG("--exponential")) workFactor = 1; else
|
||||
if (ISFLAG("--exponential")) workFactor = 1; else
|
||||
if (ISFLAG("--repetitive-best")) redundant(aa->name); else
|
||||
if (ISFLAG("--repetitive-fast")) redundant(aa->name); else
|
||||
if (ISFLAG("--fast")) blockSize100k = 1; else
|
||||
@@ -2007,7 +2007,7 @@ IntNative main ( IntNative argc, Char *argv[] )
|
||||
}
|
||||
|
||||
if (verbosity > 4) verbosity = 4;
|
||||
if (opMode == OM_Z && smallMode && blockSize100k > 2)
|
||||
if (opMode == OM_Z && smallMode && blockSize100k > 2)
|
||||
blockSize100k = 2;
|
||||
|
||||
if (opMode == OM_TEST && srcMode == SM_F2O) {
|
||||
@@ -2041,7 +2041,7 @@ IntNative main ( IntNative argc, Char *argv[] )
|
||||
compress ( aa->name );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
if (opMode == OM_UNZ) {
|
||||
@@ -2055,13 +2055,13 @@ IntNative main ( IntNative argc, Char *argv[] )
|
||||
if (aa->name[0] == '-' && decode) continue;
|
||||
numFilesProcessed++;
|
||||
uncompress ( aa->name );
|
||||
}
|
||||
}
|
||||
}
|
||||
if (unzFailsExist) {
|
||||
setExit(2);
|
||||
if (unzFailsExist) {
|
||||
setExit(2);
|
||||
exit(exitValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
testFailsExist = False;
|
||||
@@ -2070,11 +2070,11 @@ IntNative main ( IntNative argc, Char *argv[] )
|
||||
} else {
|
||||
decode = True;
|
||||
for (aa = argList; aa != NULL; aa = aa->link) {
|
||||
if (ISFLAG("--")) { decode = False; continue; }
|
||||
if (ISFLAG("--")) { decode = False; continue; }
|
||||
if (aa->name[0] == '-' && decode) continue;
|
||||
numFilesProcessed++;
|
||||
testf ( aa->name );
|
||||
}
|
||||
}
|
||||
}
|
||||
if (testFailsExist && noisy) {
|
||||
fprintf ( stderr,
|
||||
@@ -2087,7 +2087,7 @@ IntNative main ( IntNative argc, Char *argv[] )
|
||||
}
|
||||
}
|
||||
|
||||
/* Free the argument list memory to mollify leak detectors
|
||||
/* Free the argument list memory to mollify leak detectors
|
||||
(eg) Purify, Checker. Serves no other useful purpose.
|
||||
*/
|
||||
aa = argList;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/*--
|
||||
This program is bzip2recover, a program to attempt data
|
||||
This program is bzip2recover, a program to attempt data
|
||||
salvage from damaged files created by the accompanying
|
||||
bzip2-1.0.3 program.
|
||||
|
||||
@@ -18,16 +18,16 @@
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. The origin of this software must not be misrepresented; you must
|
||||
not claim that you wrote the original software. If you use this
|
||||
software in a product, an acknowledgment in the product
|
||||
2. The origin of this software must not be misrepresented; you must
|
||||
not claim that you wrote the original software. If you use this
|
||||
software in a product, an acknowledgment in the product
|
||||
documentation would be appreciated but is not required.
|
||||
|
||||
3. Altered source versions must be plainly marked as such, and must
|
||||
not be misrepresented as being the original software.
|
||||
|
||||
4. The name of the author may not be used to endorse or promote
|
||||
products derived from this software without specific prior written
|
||||
4. The name of the author may not be used to endorse or promote
|
||||
products derived from this software without specific prior written
|
||||
permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
|
||||
@@ -107,7 +107,7 @@ MaybeUInt64 bytesIn = 0;
|
||||
#define BZ_HDR_Z 0x5a /* 'Z' */
|
||||
#define BZ_HDR_h 0x68 /* 'h' */
|
||||
#define BZ_HDR_0 0x30 /* '0' */
|
||||
|
||||
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
/*--- I/O errors ---*/
|
||||
@@ -160,7 +160,7 @@ void tooManyBlocks ( Int32 max_handled_blocks )
|
||||
fprintf ( stderr,
|
||||
"%s: and cannot be handled. To fix, increase\n",
|
||||
progName );
|
||||
fprintf ( stderr,
|
||||
fprintf ( stderr,
|
||||
"%s: BZ_MAX_HANDLED_BLOCKS in bzip2recover.c, and recompile.\n",
|
||||
progName );
|
||||
exit ( 1 );
|
||||
@@ -344,7 +344,7 @@ Int32 main ( Int32 argc, Char** argv )
|
||||
strcpy ( progName, argv[0] );
|
||||
inFileName[0] = outFileName[0] = 0;
|
||||
|
||||
fprintf ( stderr,
|
||||
fprintf ( stderr,
|
||||
"bzip2recover 1.0.3: extracts blocks from damaged .bz2 files.\n" );
|
||||
|
||||
if (argc != 2) {
|
||||
@@ -352,18 +352,18 @@ Int32 main ( Int32 argc, Char** argv )
|
||||
progName, progName );
|
||||
switch (sizeof(MaybeUInt64)) {
|
||||
case 8:
|
||||
fprintf(stderr,
|
||||
fprintf(stderr,
|
||||
"\trestrictions on size of recovered file: None\n");
|
||||
break;
|
||||
case 4:
|
||||
fprintf(stderr,
|
||||
fprintf(stderr,
|
||||
"\trestrictions on size of recovered file: 512 MB\n");
|
||||
fprintf(stderr,
|
||||
fprintf(stderr,
|
||||
"\tto circumvent, recompile with MaybeUInt64 as an\n"
|
||||
"\tunsigned 64-bit int.\n");
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr,
|
||||
fprintf(stderr,
|
||||
"\tsizeof(MaybeUInt64) is not 4 or 8 -- "
|
||||
"configuration error.\n");
|
||||
break;
|
||||
@@ -372,7 +372,7 @@ Int32 main ( Int32 argc, Char** argv )
|
||||
}
|
||||
|
||||
if (strlen(argv[1]) >= BZ_MAX_FILENAME-20) {
|
||||
fprintf ( stderr,
|
||||
fprintf ( stderr,
|
||||
"%s: supplied filename is suspiciously (>= %d chars) long. Bye!\n",
|
||||
progName, (int)strlen(argv[1]) );
|
||||
exit(1);
|
||||
@@ -404,7 +404,7 @@ Int32 main ( Int32 argc, Char** argv )
|
||||
(bitsRead - bStart[currBlock]) >= 40) {
|
||||
bEnd[currBlock] = bitsRead-1;
|
||||
if (currBlock > 0)
|
||||
fprintf ( stderr, " block %d runs from " MaybeUInt64_FMT
|
||||
fprintf ( stderr, " block %d runs from " MaybeUInt64_FMT
|
||||
" to " MaybeUInt64_FMT " (incomplete)\n",
|
||||
currBlock, bStart[currBlock], bEnd[currBlock] );
|
||||
} else
|
||||
@@ -413,10 +413,10 @@ Int32 main ( Int32 argc, Char** argv )
|
||||
}
|
||||
buffHi = (buffHi << 1) | (buffLo >> 31);
|
||||
buffLo = (buffLo << 1) | (b & 1);
|
||||
if ( ( (buffHi & 0x0000ffff) == BLOCK_HEADER_HI
|
||||
if ( ( (buffHi & 0x0000ffff) == BLOCK_HEADER_HI
|
||||
&& buffLo == BLOCK_HEADER_LO)
|
||||
||
|
||||
( (buffHi & 0x0000ffff) == BLOCK_ENDMARK_HI
|
||||
||
|
||||
( (buffHi & 0x0000ffff) == BLOCK_ENDMARK_HI
|
||||
&& buffLo == BLOCK_ENDMARK_LO)
|
||||
) {
|
||||
if (bitsRead > 49) {
|
||||
@@ -425,8 +425,8 @@ Int32 main ( Int32 argc, Char** argv )
|
||||
bEnd[currBlock] = 0;
|
||||
}
|
||||
if (currBlock > 0 &&
|
||||
(bEnd[currBlock] - bStart[currBlock]) >= 130) {
|
||||
fprintf ( stderr, " block %d runs from " MaybeUInt64_FMT
|
||||
(bEnd[currBlock] - bStart[currBlock]) >= 130) {
|
||||
fprintf ( stderr, " block %d runs from " MaybeUInt64_FMT
|
||||
" to " MaybeUInt64_FMT "\n",
|
||||
rbCtr+1, bStart[currBlock], bEnd[currBlock] );
|
||||
rbStart[rbCtr] = bStart[currBlock];
|
||||
@@ -472,7 +472,7 @@ Int32 main ( Int32 argc, Char** argv )
|
||||
if (b == 2) break;
|
||||
buffHi = (buffHi << 1) | (buffLo >> 31);
|
||||
buffLo = (buffLo << 1) | (b & 1);
|
||||
if (bitsRead == 47+rbStart[wrBlock])
|
||||
if (bitsRead == 47+rbStart[wrBlock])
|
||||
blockCRC = (buffHi << 16) | (buffLo >> 16);
|
||||
|
||||
if (outFile != NULL && bitsRead >= rbStart[wrBlock]
|
||||
@@ -494,11 +494,11 @@ Int32 main ( Int32 argc, Char** argv )
|
||||
wrBlock++;
|
||||
} else
|
||||
if (bitsRead == rbStart[wrBlock]) {
|
||||
/* Create the output file name, correctly handling leading paths.
|
||||
/* Create the output file name, correctly handling leading paths.
|
||||
(31.10.2001 by Sergey E. Kusikov) */
|
||||
Char* split;
|
||||
Int32 ofs, k;
|
||||
for (k = 0; k < BZ_MAX_FILENAME; k++)
|
||||
for (k = 0; k < BZ_MAX_FILENAME; k++)
|
||||
outFileName[k] = 0;
|
||||
strcpy (outFileName, inFileName);
|
||||
split = strrchr (outFileName, BZ_SPLIT_SYM);
|
||||
@@ -506,8 +506,8 @@ Int32 main ( Int32 argc, Char** argv )
|
||||
split = outFileName;
|
||||
} else {
|
||||
++split;
|
||||
}
|
||||
/* Now split points to the start of the basename. */
|
||||
}
|
||||
/* Now split points to the start of the basename. */
|
||||
ofs = split - outFileName;
|
||||
sprintf (split, "rec%5d", wrBlock+1);
|
||||
for (p = split; *p != 0; p++) if (*p == ' ') *p = '0';
|
||||
@@ -525,9 +525,9 @@ Int32 main ( Int32 argc, Char** argv )
|
||||
exit(1);
|
||||
}
|
||||
bsWr = bsOpenWriteStream ( outFile );
|
||||
bsPutUChar ( bsWr, BZ_HDR_B );
|
||||
bsPutUChar ( bsWr, BZ_HDR_Z );
|
||||
bsPutUChar ( bsWr, BZ_HDR_h );
|
||||
bsPutUChar ( bsWr, BZ_HDR_B );
|
||||
bsPutUChar ( bsWr, BZ_HDR_Z );
|
||||
bsPutUChar ( bsWr, BZ_HDR_h );
|
||||
bsPutUChar ( bsWr, BZ_HDR_0 + 9 );
|
||||
bsPutUChar ( bsWr, 0x31 ); bsPutUChar ( bsWr, 0x41 );
|
||||
bsPutUChar ( bsWr, 0x59 ); bsPutUChar ( bsWr, 0x26 );
|
||||
|
||||
@@ -17,16 +17,16 @@
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. The origin of this software must not be misrepresented; you must
|
||||
not claim that you wrote the original software. If you use this
|
||||
software in a product, an acknowledgment in the product
|
||||
2. The origin of this software must not be misrepresented; you must
|
||||
not claim that you wrote the original software. If you use this
|
||||
software in a product, an acknowledgment in the product
|
||||
documentation would be appreciated but is not required.
|
||||
|
||||
3. Altered source versions must be plainly marked as such, and must
|
||||
not be misrepresented as being the original software.
|
||||
|
||||
4. The name of the author may not be used to endorse or promote
|
||||
products derived from this software without specific prior written
|
||||
4. The name of the author may not be used to endorse or promote
|
||||
products derived from this software without specific prior written
|
||||
permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
|
||||
@@ -86,7 +86,7 @@
|
||||
#ifndef BZ_NO_STDIO
|
||||
void BZ2_bz__AssertH__fail ( int errcode )
|
||||
{
|
||||
fprintf(stderr,
|
||||
fprintf(stderr,
|
||||
"\n\nbzip2/libbzip2: internal error number %d.\n"
|
||||
"This is a bug in bzip2/libbzip2, %s.\n"
|
||||
"Please report it to me at: jseward@bzip.org. If this happened\n"
|
||||
@@ -191,8 +191,8 @@ Bool isempty_RL ( EState* s )
|
||||
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
int BZ_API(BZ2_bzCompressInit)
|
||||
( bz_stream* strm,
|
||||
int BZ_API(BZ2_bzCompressInit)
|
||||
( bz_stream* strm,
|
||||
int blockSize100k,
|
||||
int verbosity,
|
||||
int workFactor )
|
||||
@@ -202,7 +202,7 @@ int BZ_API(BZ2_bzCompressInit)
|
||||
|
||||
if (!bz_config_ok()) return BZ_CONFIG_ERROR;
|
||||
|
||||
if (strm == NULL ||
|
||||
if (strm == NULL ||
|
||||
blockSize100k < 1 || blockSize100k > 9 ||
|
||||
workFactor < 0 || workFactor > 250)
|
||||
return BZ_PARAM_ERROR;
|
||||
@@ -345,7 +345,7 @@ Bool copy_input_until_stop ( EState* s )
|
||||
/*-- no input? --*/
|
||||
if (s->strm->avail_in == 0) break;
|
||||
progress_in = True;
|
||||
ADD_CHAR_TO_BLOCK ( s, (UInt32)(*((UChar*)(s->strm->next_in))) );
|
||||
ADD_CHAR_TO_BLOCK ( s, (UInt32)(*((UChar*)(s->strm->next_in))) );
|
||||
s->strm->next_in++;
|
||||
s->strm->avail_in--;
|
||||
s->strm->total_in_lo32++;
|
||||
@@ -363,7 +363,7 @@ Bool copy_input_until_stop ( EState* s )
|
||||
/*-- flush/finish end? --*/
|
||||
if (s->avail_in_expect == 0) break;
|
||||
progress_in = True;
|
||||
ADD_CHAR_TO_BLOCK ( s, (UInt32)(*((UChar*)(s->strm->next_in))) );
|
||||
ADD_CHAR_TO_BLOCK ( s, (UInt32)(*((UChar*)(s->strm->next_in))) );
|
||||
s->strm->next_in++;
|
||||
s->strm->avail_in--;
|
||||
s->strm->total_in_lo32++;
|
||||
@@ -409,18 +409,18 @@ Bool handle_compress ( bz_stream* strm )
|
||||
Bool progress_in = False;
|
||||
Bool progress_out = False;
|
||||
EState* s = strm->state;
|
||||
|
||||
|
||||
while (True) {
|
||||
|
||||
if (s->state == BZ_S_OUTPUT) {
|
||||
progress_out |= copy_output_until_stop ( s );
|
||||
if (s->state_out_pos < s->numZ) break;
|
||||
if (s->mode == BZ_M_FINISHING &&
|
||||
if (s->mode == BZ_M_FINISHING &&
|
||||
s->avail_in_expect == 0 &&
|
||||
isempty_RL(s)) break;
|
||||
prepare_new_block ( s );
|
||||
s->state = BZ_S_INPUT;
|
||||
if (s->mode == BZ_M_FLUSHING &&
|
||||
if (s->mode == BZ_M_FLUSHING &&
|
||||
s->avail_in_expect == 0 &&
|
||||
isempty_RL(s)) break;
|
||||
}
|
||||
@@ -469,9 +469,9 @@ int BZ_API(BZ2_bzCompress) ( bz_stream *strm, int action )
|
||||
if (action == BZ_RUN) {
|
||||
progress = handle_compress ( strm );
|
||||
return progress ? BZ_RUN_OK : BZ_PARAM_ERROR;
|
||||
}
|
||||
}
|
||||
else
|
||||
if (action == BZ_FLUSH) {
|
||||
if (action == BZ_FLUSH) {
|
||||
s->avail_in_expect = strm->avail_in;
|
||||
s->mode = BZ_M_FLUSHING;
|
||||
goto preswitch;
|
||||
@@ -482,12 +482,12 @@ int BZ_API(BZ2_bzCompress) ( bz_stream *strm, int action )
|
||||
s->mode = BZ_M_FINISHING;
|
||||
goto preswitch;
|
||||
}
|
||||
else
|
||||
else
|
||||
return BZ_PARAM_ERROR;
|
||||
|
||||
case BZ_M_FLUSHING:
|
||||
if (action != BZ_FLUSH) return BZ_SEQUENCE_ERROR;
|
||||
if (s->avail_in_expect != s->strm->avail_in)
|
||||
if (s->avail_in_expect != s->strm->avail_in)
|
||||
return BZ_SEQUENCE_ERROR;
|
||||
progress = handle_compress ( strm );
|
||||
if (s->avail_in_expect > 0 || !isempty_RL(s) ||
|
||||
@@ -497,7 +497,7 @@ int BZ_API(BZ2_bzCompress) ( bz_stream *strm, int action )
|
||||
|
||||
case BZ_M_FINISHING:
|
||||
if (action != BZ_FINISH) return BZ_SEQUENCE_ERROR;
|
||||
if (s->avail_in_expect != s->strm->avail_in)
|
||||
if (s->avail_in_expect != s->strm->avail_in)
|
||||
return BZ_SEQUENCE_ERROR;
|
||||
progress = handle_compress ( strm );
|
||||
if (!progress) return BZ_SEQUENCE_ERROR;
|
||||
@@ -524,7 +524,7 @@ int BZ_API(BZ2_bzCompressEnd) ( bz_stream *strm )
|
||||
if (s->ftab != NULL) BZFREE(s->ftab);
|
||||
BZFREE(strm->state);
|
||||
|
||||
strm->state = NULL;
|
||||
strm->state = NULL;
|
||||
|
||||
return BZ_OK;
|
||||
}
|
||||
@@ -535,8 +535,8 @@ int BZ_API(BZ2_bzCompressEnd) ( bz_stream *strm )
|
||||
/*---------------------------------------------------*/
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
int BZ_API(BZ2_bzDecompressInit)
|
||||
( bz_stream* strm,
|
||||
int BZ_API(BZ2_bzDecompressInit)
|
||||
( bz_stream* strm,
|
||||
int verbosity,
|
||||
int small )
|
||||
{
|
||||
@@ -601,34 +601,34 @@ Bool unRLE_obuf_to_output_FAST ( DState* s )
|
||||
|
||||
/* can a new run be started? */
|
||||
if (s->nblock_used == s->save_nblock+1) return False;
|
||||
|
||||
|
||||
/* Only caused by corrupt data stream? */
|
||||
if (s->nblock_used > s->save_nblock+1)
|
||||
return True;
|
||||
|
||||
|
||||
s->state_out_len = 1;
|
||||
s->state_out_ch = s->k0;
|
||||
BZ_GET_FAST(k1); BZ_RAND_UPD_MASK;
|
||||
BZ_GET_FAST(k1); BZ_RAND_UPD_MASK;
|
||||
k1 ^= BZ_RAND_MASK; s->nblock_used++;
|
||||
if (s->nblock_used == s->save_nblock+1) continue;
|
||||
if (k1 != s->k0) { s->k0 = k1; continue; };
|
||||
|
||||
|
||||
s->state_out_len = 2;
|
||||
BZ_GET_FAST(k1); BZ_RAND_UPD_MASK;
|
||||
BZ_GET_FAST(k1); BZ_RAND_UPD_MASK;
|
||||
k1 ^= BZ_RAND_MASK; s->nblock_used++;
|
||||
if (s->nblock_used == s->save_nblock+1) continue;
|
||||
if (k1 != s->k0) { s->k0 = k1; continue; };
|
||||
|
||||
|
||||
s->state_out_len = 3;
|
||||
BZ_GET_FAST(k1); BZ_RAND_UPD_MASK;
|
||||
BZ_GET_FAST(k1); BZ_RAND_UPD_MASK;
|
||||
k1 ^= BZ_RAND_MASK; s->nblock_used++;
|
||||
if (s->nblock_used == s->save_nblock+1) continue;
|
||||
if (k1 != s->k0) { s->k0 = k1; continue; };
|
||||
|
||||
BZ_GET_FAST(k1); BZ_RAND_UPD_MASK;
|
||||
|
||||
BZ_GET_FAST(k1); BZ_RAND_UPD_MASK;
|
||||
k1 ^= BZ_RAND_MASK; s->nblock_used++;
|
||||
s->state_out_len = ((Int32)k1) + 4;
|
||||
BZ_GET_FAST(s->k0); BZ_RAND_UPD_MASK;
|
||||
BZ_GET_FAST(s->k0); BZ_RAND_UPD_MASK;
|
||||
s->k0 ^= BZ_RAND_MASK; s->nblock_used++;
|
||||
}
|
||||
|
||||
@@ -665,7 +665,7 @@ Bool unRLE_obuf_to_output_FAST ( DState* s )
|
||||
}
|
||||
s_state_out_len_eq_one:
|
||||
{
|
||||
if (cs_avail_out == 0) {
|
||||
if (cs_avail_out == 0) {
|
||||
c_state_out_len = 1; goto return_notr;
|
||||
};
|
||||
*( (UChar*)(cs_next_out) ) = c_state_out_ch;
|
||||
@@ -673,7 +673,7 @@ Bool unRLE_obuf_to_output_FAST ( DState* s )
|
||||
cs_next_out++;
|
||||
cs_avail_out--;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Only caused by corrupt data stream? */
|
||||
if (c_nblock_used > s_save_nblockPP)
|
||||
return True;
|
||||
@@ -681,25 +681,25 @@ Bool unRLE_obuf_to_output_FAST ( DState* s )
|
||||
/* can a new run be started? */
|
||||
if (c_nblock_used == s_save_nblockPP) {
|
||||
c_state_out_len = 0; goto return_notr;
|
||||
};
|
||||
};
|
||||
c_state_out_ch = c_k0;
|
||||
BZ_GET_FAST_C(k1); c_nblock_used++;
|
||||
if (k1 != c_k0) {
|
||||
c_k0 = k1; goto s_state_out_len_eq_one;
|
||||
if (k1 != c_k0) {
|
||||
c_k0 = k1; goto s_state_out_len_eq_one;
|
||||
};
|
||||
if (c_nblock_used == s_save_nblockPP)
|
||||
if (c_nblock_used == s_save_nblockPP)
|
||||
goto s_state_out_len_eq_one;
|
||||
|
||||
|
||||
c_state_out_len = 2;
|
||||
BZ_GET_FAST_C(k1); c_nblock_used++;
|
||||
if (c_nblock_used == s_save_nblockPP) continue;
|
||||
if (k1 != c_k0) { c_k0 = k1; continue; };
|
||||
|
||||
|
||||
c_state_out_len = 3;
|
||||
BZ_GET_FAST_C(k1); c_nblock_used++;
|
||||
if (c_nblock_used == s_save_nblockPP) continue;
|
||||
if (k1 != c_k0) { c_k0 = k1; continue; };
|
||||
|
||||
|
||||
BZ_GET_FAST_C(k1); c_nblock_used++;
|
||||
c_state_out_len = ((Int32)k1) + 4;
|
||||
BZ_GET_FAST_C(c_k0); c_nblock_used++;
|
||||
@@ -767,37 +767,37 @@ Bool unRLE_obuf_to_output_SMALL ( DState* s )
|
||||
s->strm->total_out_lo32++;
|
||||
if (s->strm->total_out_lo32 == 0) s->strm->total_out_hi32++;
|
||||
}
|
||||
|
||||
|
||||
/* can a new run be started? */
|
||||
if (s->nblock_used == s->save_nblock+1) return False;
|
||||
|
||||
/* Only caused by corrupt data stream? */
|
||||
if (s->nblock_used > s->save_nblock+1)
|
||||
return True;
|
||||
|
||||
|
||||
s->state_out_len = 1;
|
||||
s->state_out_ch = s->k0;
|
||||
BZ_GET_SMALL(k1); BZ_RAND_UPD_MASK;
|
||||
BZ_GET_SMALL(k1); BZ_RAND_UPD_MASK;
|
||||
k1 ^= BZ_RAND_MASK; s->nblock_used++;
|
||||
if (s->nblock_used == s->save_nblock+1) continue;
|
||||
if (k1 != s->k0) { s->k0 = k1; continue; };
|
||||
|
||||
|
||||
s->state_out_len = 2;
|
||||
BZ_GET_SMALL(k1); BZ_RAND_UPD_MASK;
|
||||
BZ_GET_SMALL(k1); BZ_RAND_UPD_MASK;
|
||||
k1 ^= BZ_RAND_MASK; s->nblock_used++;
|
||||
if (s->nblock_used == s->save_nblock+1) continue;
|
||||
if (k1 != s->k0) { s->k0 = k1; continue; };
|
||||
|
||||
|
||||
s->state_out_len = 3;
|
||||
BZ_GET_SMALL(k1); BZ_RAND_UPD_MASK;
|
||||
BZ_GET_SMALL(k1); BZ_RAND_UPD_MASK;
|
||||
k1 ^= BZ_RAND_MASK; s->nblock_used++;
|
||||
if (s->nblock_used == s->save_nblock+1) continue;
|
||||
if (k1 != s->k0) { s->k0 = k1; continue; };
|
||||
|
||||
BZ_GET_SMALL(k1); BZ_RAND_UPD_MASK;
|
||||
|
||||
BZ_GET_SMALL(k1); BZ_RAND_UPD_MASK;
|
||||
k1 ^= BZ_RAND_MASK; s->nblock_used++;
|
||||
s->state_out_len = ((Int32)k1) + 4;
|
||||
BZ_GET_SMALL(s->k0); BZ_RAND_UPD_MASK;
|
||||
BZ_GET_SMALL(s->k0); BZ_RAND_UPD_MASK;
|
||||
s->k0 ^= BZ_RAND_MASK; s->nblock_used++;
|
||||
}
|
||||
|
||||
@@ -816,30 +816,30 @@ Bool unRLE_obuf_to_output_SMALL ( DState* s )
|
||||
s->strm->total_out_lo32++;
|
||||
if (s->strm->total_out_lo32 == 0) s->strm->total_out_hi32++;
|
||||
}
|
||||
|
||||
|
||||
/* can a new run be started? */
|
||||
if (s->nblock_used == s->save_nblock+1) return False;
|
||||
|
||||
/* Only caused by corrupt data stream? */
|
||||
if (s->nblock_used > s->save_nblock+1)
|
||||
return True;
|
||||
|
||||
|
||||
s->state_out_len = 1;
|
||||
s->state_out_ch = s->k0;
|
||||
BZ_GET_SMALL(k1); s->nblock_used++;
|
||||
if (s->nblock_used == s->save_nblock+1) continue;
|
||||
if (k1 != s->k0) { s->k0 = k1; continue; };
|
||||
|
||||
|
||||
s->state_out_len = 2;
|
||||
BZ_GET_SMALL(k1); s->nblock_used++;
|
||||
if (s->nblock_used == s->save_nblock+1) continue;
|
||||
if (k1 != s->k0) { s->k0 = k1; continue; };
|
||||
|
||||
|
||||
s->state_out_len = 3;
|
||||
BZ_GET_SMALL(k1); s->nblock_used++;
|
||||
if (s->nblock_used == s->save_nblock+1) continue;
|
||||
if (k1 != s->k0) { s->k0 = k1; continue; };
|
||||
|
||||
|
||||
BZ_GET_SMALL(k1); s->nblock_used++;
|
||||
s->state_out_len = ((Int32)k1) + 4;
|
||||
BZ_GET_SMALL(s->k0); s->nblock_used++;
|
||||
@@ -868,14 +868,14 @@ int BZ_API(BZ2_bzDecompress) ( bz_stream *strm )
|
||||
if (corrupt) return BZ_DATA_ERROR;
|
||||
if (s->nblock_used == s->save_nblock+1 && s->state_out_len == 0) {
|
||||
BZ_FINALISE_CRC ( s->calculatedBlockCRC );
|
||||
if (s->verbosity >= 3)
|
||||
VPrintf2 ( " {0x%08x, 0x%08x}", s->storedBlockCRC,
|
||||
if (s->verbosity >= 3)
|
||||
VPrintf2 ( " {0x%08x, 0x%08x}", s->storedBlockCRC,
|
||||
s->calculatedBlockCRC );
|
||||
if (s->verbosity >= 2) VPrintf0 ( "]" );
|
||||
if (s->calculatedBlockCRC != s->storedBlockCRC)
|
||||
return BZ_DATA_ERROR;
|
||||
s->calculatedCombinedCRC
|
||||
= (s->calculatedCombinedCRC << 1) |
|
||||
s->calculatedCombinedCRC
|
||||
= (s->calculatedCombinedCRC << 1) |
|
||||
(s->calculatedCombinedCRC >> 31);
|
||||
s->calculatedCombinedCRC ^= s->calculatedBlockCRC;
|
||||
s->state = BZ_X_BLKHDR_1;
|
||||
@@ -887,7 +887,7 @@ int BZ_API(BZ2_bzDecompress) ( bz_stream *strm )
|
||||
Int32 r = BZ2_decompress ( s );
|
||||
if (r == BZ_STREAM_END) {
|
||||
if (s->verbosity >= 3)
|
||||
VPrintf2 ( "\n combined CRCs: stored = 0x%08x, computed = 0x%08x",
|
||||
VPrintf2 ( "\n combined CRCs: stored = 0x%08x, computed = 0x%08x",
|
||||
s->storedCombinedCRC, s->calculatedCombinedCRC );
|
||||
if (s->calculatedCombinedCRC != s->storedCombinedCRC)
|
||||
return BZ_DATA_ERROR;
|
||||
@@ -934,7 +934,7 @@ int BZ_API(BZ2_bzDecompressEnd) ( bz_stream *strm )
|
||||
if (bzf != NULL) bzf->lastErr = eee; \
|
||||
}
|
||||
|
||||
typedef
|
||||
typedef
|
||||
struct {
|
||||
FILE* handle;
|
||||
Char buf[BZ_MAX_UNUSED];
|
||||
@@ -958,10 +958,10 @@ static Bool myfeof ( FILE* f )
|
||||
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
BZFILE* BZ_API(BZ2_bzWriteOpen)
|
||||
( int* bzerror,
|
||||
FILE* f,
|
||||
int blockSize100k,
|
||||
BZFILE* BZ_API(BZ2_bzWriteOpen)
|
||||
( int* bzerror,
|
||||
FILE* f,
|
||||
int blockSize100k,
|
||||
int verbosity,
|
||||
int workFactor )
|
||||
{
|
||||
@@ -993,23 +993,23 @@ BZFILE* BZ_API(BZ2_bzWriteOpen)
|
||||
bzf->strm.opaque = NULL;
|
||||
|
||||
if (workFactor == 0) workFactor = 30;
|
||||
ret = BZ2_bzCompressInit ( &(bzf->strm), blockSize100k,
|
||||
ret = BZ2_bzCompressInit ( &(bzf->strm), blockSize100k,
|
||||
verbosity, workFactor );
|
||||
if (ret != BZ_OK)
|
||||
{ BZ_SETERR(ret); free(bzf); return NULL; };
|
||||
|
||||
bzf->strm.avail_in = 0;
|
||||
bzf->initialisedOk = True;
|
||||
return bzf;
|
||||
return bzf;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
void BZ_API(BZ2_bzWrite)
|
||||
( int* bzerror,
|
||||
BZFILE* b,
|
||||
void* buf,
|
||||
( int* bzerror,
|
||||
BZFILE* b,
|
||||
void* buf,
|
||||
int len )
|
||||
{
|
||||
Int32 n, n2, ret;
|
||||
@@ -1038,7 +1038,7 @@ void BZ_API(BZ2_bzWrite)
|
||||
|
||||
if (bzf->strm.avail_out < BZ_MAX_UNUSED) {
|
||||
n = BZ_MAX_UNUSED - bzf->strm.avail_out;
|
||||
n2 = fwrite ( (void*)(bzf->buf), sizeof(UChar),
|
||||
n2 = fwrite ( (void*)(bzf->buf), sizeof(UChar),
|
||||
n, bzf->handle );
|
||||
if (n != n2 || ferror(bzf->handle))
|
||||
{ BZ_SETERR(BZ_IO_ERROR); return; };
|
||||
@@ -1052,20 +1052,20 @@ void BZ_API(BZ2_bzWrite)
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
void BZ_API(BZ2_bzWriteClose)
|
||||
( int* bzerror,
|
||||
BZFILE* b,
|
||||
( int* bzerror,
|
||||
BZFILE* b,
|
||||
int abandon,
|
||||
unsigned int* nbytes_in,
|
||||
unsigned int* nbytes_out )
|
||||
{
|
||||
BZ2_bzWriteClose64 ( bzerror, b, abandon,
|
||||
BZ2_bzWriteClose64 ( bzerror, b, abandon,
|
||||
nbytes_in, NULL, nbytes_out, NULL );
|
||||
}
|
||||
|
||||
|
||||
void BZ_API(BZ2_bzWriteClose64)
|
||||
( int* bzerror,
|
||||
BZFILE* b,
|
||||
( int* bzerror,
|
||||
BZFILE* b,
|
||||
int abandon,
|
||||
unsigned int* nbytes_in_lo32,
|
||||
unsigned int* nbytes_in_hi32,
|
||||
@@ -1097,7 +1097,7 @@ void BZ_API(BZ2_bzWriteClose64)
|
||||
|
||||
if (bzf->strm.avail_out < BZ_MAX_UNUSED) {
|
||||
n = BZ_MAX_UNUSED - bzf->strm.avail_out;
|
||||
n2 = fwrite ( (void*)(bzf->buf), sizeof(UChar),
|
||||
n2 = fwrite ( (void*)(bzf->buf), sizeof(UChar),
|
||||
n, bzf->handle );
|
||||
if (n != n2 || ferror(bzf->handle))
|
||||
{ BZ_SETERR(BZ_IO_ERROR); return; };
|
||||
@@ -1129,9 +1129,9 @@ void BZ_API(BZ2_bzWriteClose64)
|
||||
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
BZFILE* BZ_API(BZ2_bzReadOpen)
|
||||
( int* bzerror,
|
||||
FILE* f,
|
||||
BZFILE* BZ_API(BZ2_bzReadOpen)
|
||||
( int* bzerror,
|
||||
FILE* f,
|
||||
int verbosity,
|
||||
int small,
|
||||
void* unused,
|
||||
@@ -1142,7 +1142,7 @@ BZFILE* BZ_API(BZ2_bzReadOpen)
|
||||
|
||||
BZ_SETERR(BZ_OK);
|
||||
|
||||
if (f == NULL ||
|
||||
if (f == NULL ||
|
||||
(small != 0 && small != 1) ||
|
||||
(verbosity < 0 || verbosity > 4) ||
|
||||
(unused == NULL && nUnused != 0) ||
|
||||
@@ -1153,7 +1153,7 @@ BZFILE* BZ_API(BZ2_bzReadOpen)
|
||||
{ BZ_SETERR(BZ_IO_ERROR); return NULL; };
|
||||
|
||||
bzf = malloc ( sizeof(bzFile) );
|
||||
if (bzf == NULL)
|
||||
if (bzf == NULL)
|
||||
{ BZ_SETERR(BZ_MEM_ERROR); return NULL; };
|
||||
|
||||
BZ_SETERR(BZ_OK);
|
||||
@@ -1165,7 +1165,7 @@ BZFILE* BZ_API(BZ2_bzReadOpen)
|
||||
bzf->strm.bzalloc = NULL;
|
||||
bzf->strm.bzfree = NULL;
|
||||
bzf->strm.opaque = NULL;
|
||||
|
||||
|
||||
while (nUnused > 0) {
|
||||
bzf->buf[bzf->bufN] = *((UChar*)(unused)); bzf->bufN++;
|
||||
unused = ((void*)( 1 + ((UChar*)(unused)) ));
|
||||
@@ -1180,7 +1180,7 @@ BZFILE* BZ_API(BZ2_bzReadOpen)
|
||||
bzf->strm.next_in = bzf->buf;
|
||||
|
||||
bzf->initialisedOk = True;
|
||||
return bzf;
|
||||
return bzf;
|
||||
}
|
||||
|
||||
|
||||
@@ -1203,10 +1203,10 @@ void BZ_API(BZ2_bzReadClose) ( int *bzerror, BZFILE *b )
|
||||
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
int BZ_API(BZ2_bzRead)
|
||||
( int* bzerror,
|
||||
BZFILE* b,
|
||||
void* buf,
|
||||
int BZ_API(BZ2_bzRead)
|
||||
( int* bzerror,
|
||||
BZFILE* b,
|
||||
void* buf,
|
||||
int len )
|
||||
{
|
||||
Int32 n, ret;
|
||||
@@ -1228,11 +1228,11 @@ int BZ_API(BZ2_bzRead)
|
||||
|
||||
while (True) {
|
||||
|
||||
if (ferror(bzf->handle))
|
||||
if (ferror(bzf->handle))
|
||||
{ BZ_SETERR(BZ_IO_ERROR); return 0; };
|
||||
|
||||
if (bzf->strm.avail_in == 0 && !myfeof(bzf->handle)) {
|
||||
n = fread ( bzf->buf, sizeof(UChar),
|
||||
n = fread ( bzf->buf, sizeof(UChar),
|
||||
BZ_MAX_UNUSED, bzf->handle );
|
||||
if (ferror(bzf->handle))
|
||||
{ BZ_SETERR(BZ_IO_ERROR); return 0; };
|
||||
@@ -1246,7 +1246,7 @@ int BZ_API(BZ2_bzRead)
|
||||
if (ret != BZ_OK && ret != BZ_STREAM_END)
|
||||
{ BZ_SETERR(ret); return 0; };
|
||||
|
||||
if (ret == BZ_OK && myfeof(bzf->handle) &&
|
||||
if (ret == BZ_OK && myfeof(bzf->handle) &&
|
||||
bzf->strm.avail_in == 0 && bzf->strm.avail_out > 0)
|
||||
{ BZ_SETERR(BZ_UNEXPECTED_EOF); return 0; };
|
||||
|
||||
@@ -1255,7 +1255,7 @@ int BZ_API(BZ2_bzRead)
|
||||
return len - bzf->strm.avail_out; };
|
||||
if (bzf->strm.avail_out == 0)
|
||||
{ BZ_SETERR(BZ_OK); return len; };
|
||||
|
||||
|
||||
}
|
||||
|
||||
return 0; /*not reached*/
|
||||
@@ -1263,10 +1263,10 @@ int BZ_API(BZ2_bzRead)
|
||||
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
void BZ_API(BZ2_bzReadGetUnused)
|
||||
( int* bzerror,
|
||||
BZFILE* b,
|
||||
void** unused,
|
||||
void BZ_API(BZ2_bzReadGetUnused)
|
||||
( int* bzerror,
|
||||
BZFILE* b,
|
||||
void** unused,
|
||||
int* nUnused )
|
||||
{
|
||||
bzFile* bzf = (bzFile*)b;
|
||||
@@ -1289,30 +1289,30 @@ void BZ_API(BZ2_bzReadGetUnused)
|
||||
/*---------------------------------------------------*/
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
int BZ_API(BZ2_bzBuffToBuffCompress)
|
||||
( char* dest,
|
||||
int BZ_API(BZ2_bzBuffToBuffCompress)
|
||||
( char* dest,
|
||||
unsigned int* destLen,
|
||||
char* source,
|
||||
char* source,
|
||||
unsigned int sourceLen,
|
||||
int blockSize100k,
|
||||
int verbosity,
|
||||
int blockSize100k,
|
||||
int verbosity,
|
||||
int workFactor )
|
||||
{
|
||||
bz_stream strm;
|
||||
int ret;
|
||||
|
||||
if (dest == NULL || destLen == NULL ||
|
||||
if (dest == NULL || destLen == NULL ||
|
||||
source == NULL ||
|
||||
blockSize100k < 1 || blockSize100k > 9 ||
|
||||
verbosity < 0 || verbosity > 4 ||
|
||||
workFactor < 0 || workFactor > 250)
|
||||
workFactor < 0 || workFactor > 250)
|
||||
return BZ_PARAM_ERROR;
|
||||
|
||||
if (workFactor == 0) workFactor = 30;
|
||||
strm.bzalloc = NULL;
|
||||
strm.bzfree = NULL;
|
||||
strm.opaque = NULL;
|
||||
ret = BZ2_bzCompressInit ( &strm, blockSize100k,
|
||||
ret = BZ2_bzCompressInit ( &strm, blockSize100k,
|
||||
verbosity, workFactor );
|
||||
if (ret != BZ_OK) return ret;
|
||||
|
||||
@@ -1326,7 +1326,7 @@ int BZ_API(BZ2_bzBuffToBuffCompress)
|
||||
if (ret != BZ_STREAM_END) goto errhandler;
|
||||
|
||||
/* normal termination */
|
||||
*destLen -= strm.avail_out;
|
||||
*destLen -= strm.avail_out;
|
||||
BZ2_bzCompressEnd ( &strm );
|
||||
return BZ_OK;
|
||||
|
||||
@@ -1341,10 +1341,10 @@ int BZ_API(BZ2_bzBuffToBuffCompress)
|
||||
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
int BZ_API(BZ2_bzBuffToBuffDecompress)
|
||||
( char* dest,
|
||||
int BZ_API(BZ2_bzBuffToBuffDecompress)
|
||||
( char* dest,
|
||||
unsigned int* destLen,
|
||||
char* source,
|
||||
char* source,
|
||||
unsigned int sourceLen,
|
||||
int small,
|
||||
int verbosity )
|
||||
@@ -1352,10 +1352,10 @@ int BZ_API(BZ2_bzBuffToBuffDecompress)
|
||||
bz_stream strm;
|
||||
int ret;
|
||||
|
||||
if (dest == NULL || destLen == NULL ||
|
||||
if (dest == NULL || destLen == NULL ||
|
||||
source == NULL ||
|
||||
(small != 0 && small != 1) ||
|
||||
verbosity < 0 || verbosity > 4)
|
||||
verbosity < 0 || verbosity > 4)
|
||||
return BZ_PARAM_ERROR;
|
||||
|
||||
strm.bzalloc = NULL;
|
||||
@@ -1385,11 +1385,11 @@ int BZ_API(BZ2_bzBuffToBuffDecompress)
|
||||
} else {
|
||||
BZ2_bzDecompressEnd ( &strm );
|
||||
return BZ_OUTBUFF_FULL;
|
||||
};
|
||||
};
|
||||
|
||||
errhandler:
|
||||
BZ2_bzDecompressEnd ( &strm );
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -1442,7 +1442,7 @@ BZFILE * bzopen_or_bzdopen
|
||||
int verbosity = 0;
|
||||
int workFactor = 30;
|
||||
int smallMode = 0;
|
||||
int nUnused = 0;
|
||||
int nUnused = 0;
|
||||
|
||||
if (mode == NULL) return NULL;
|
||||
while (*mode) {
|
||||
@@ -1482,7 +1482,7 @@ BZFILE * bzopen_or_bzdopen
|
||||
if (writing) {
|
||||
/* Guard against total chaos and anarchy -- JRS */
|
||||
if (blockSize100k < 1) blockSize100k = 1;
|
||||
if (blockSize100k > 9) blockSize100k = 9;
|
||||
if (blockSize100k > 9) blockSize100k = 9;
|
||||
bzfp = BZ2_bzWriteOpen(&bzerr,fp,blockSize100k,
|
||||
verbosity,workFactor);
|
||||
} else {
|
||||
@@ -1561,7 +1561,7 @@ void BZ_API(BZ2_bzclose) (BZFILE* b)
|
||||
{
|
||||
int bzerr;
|
||||
FILE *fp = ((bzFile *)b)->handle;
|
||||
|
||||
|
||||
if (b==NULL) {return;}
|
||||
if(((bzFile*)b)->writing){
|
||||
BZ2_bzWriteClose(&bzerr,b,0,NULL,NULL);
|
||||
@@ -1579,7 +1579,7 @@ void BZ_API(BZ2_bzclose) (BZFILE* b)
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
/*--
|
||||
return last error code
|
||||
return last error code
|
||||
--*/
|
||||
static char *bzerrorstrings[] = {
|
||||
"OK"
|
||||
|
||||
@@ -17,16 +17,16 @@
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. The origin of this software must not be misrepresented; you must
|
||||
not claim that you wrote the original software. If you use this
|
||||
software in a product, an acknowledgment in the product
|
||||
2. The origin of this software must not be misrepresented; you must
|
||||
not claim that you wrote the original software. If you use this
|
||||
software in a product, an acknowledgment in the product
|
||||
documentation would be appreciated but is not required.
|
||||
|
||||
3. Altered source versions must be plainly marked as such, and must
|
||||
not be misrepresented as being the original software.
|
||||
|
||||
4. The name of the author may not be used to endorse or promote
|
||||
products derived from this software without specific prior written
|
||||
4. The name of the author may not be used to endorse or promote
|
||||
products derived from this software without specific prior written
|
||||
permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
|
||||
@@ -85,7 +85,7 @@ extern "C" {
|
||||
#define BZ_OUTBUFF_FULL (-8)
|
||||
#define BZ_CONFIG_ERROR (-9)
|
||||
|
||||
typedef
|
||||
typedef
|
||||
struct {
|
||||
char *next_in;
|
||||
unsigned int avail_in;
|
||||
@@ -102,7 +102,7 @@ typedef
|
||||
void *(*bzalloc)(void *,int,int);
|
||||
void (*bzfree)(void *,void *);
|
||||
void *opaque;
|
||||
}
|
||||
}
|
||||
bz_stream;
|
||||
|
||||
|
||||
@@ -137,34 +137,34 @@ typedef
|
||||
|
||||
/*-- Core (low-level) library functions --*/
|
||||
|
||||
BZ_EXTERN int BZ_API(BZ2_bzCompressInit) (
|
||||
bz_stream* strm,
|
||||
int blockSize100k,
|
||||
int verbosity,
|
||||
int workFactor
|
||||
BZ_EXTERN int BZ_API(BZ2_bzCompressInit) (
|
||||
bz_stream* strm,
|
||||
int blockSize100k,
|
||||
int verbosity,
|
||||
int workFactor
|
||||
);
|
||||
|
||||
BZ_EXTERN int BZ_API(BZ2_bzCompress) (
|
||||
bz_stream* strm,
|
||||
int action
|
||||
BZ_EXTERN int BZ_API(BZ2_bzCompress) (
|
||||
bz_stream* strm,
|
||||
int action
|
||||
);
|
||||
|
||||
BZ_EXTERN int BZ_API(BZ2_bzCompressEnd) (
|
||||
bz_stream* strm
|
||||
BZ_EXTERN int BZ_API(BZ2_bzCompressEnd) (
|
||||
bz_stream* strm
|
||||
);
|
||||
|
||||
BZ_EXTERN int BZ_API(BZ2_bzDecompressInit) (
|
||||
bz_stream *strm,
|
||||
int verbosity,
|
||||
BZ_EXTERN int BZ_API(BZ2_bzDecompressInit) (
|
||||
bz_stream *strm,
|
||||
int verbosity,
|
||||
int small
|
||||
);
|
||||
|
||||
BZ_EXTERN int BZ_API(BZ2_bzDecompress) (
|
||||
bz_stream* strm
|
||||
BZ_EXTERN int BZ_API(BZ2_bzDecompress) (
|
||||
bz_stream* strm
|
||||
);
|
||||
|
||||
BZ_EXTERN int BZ_API(BZ2_bzDecompressEnd) (
|
||||
bz_stream *strm
|
||||
BZ_EXTERN int BZ_API(BZ2_bzDecompressEnd) (
|
||||
bz_stream *strm
|
||||
);
|
||||
|
||||
|
||||
@@ -176,64 +176,64 @@ BZ_EXTERN int BZ_API(BZ2_bzDecompressEnd) (
|
||||
|
||||
typedef void BZFILE;
|
||||
|
||||
BZ_EXTERN BZFILE* BZ_API(BZ2_bzReadOpen) (
|
||||
int* bzerror,
|
||||
FILE* f,
|
||||
int verbosity,
|
||||
BZ_EXTERN BZFILE* BZ_API(BZ2_bzReadOpen) (
|
||||
int* bzerror,
|
||||
FILE* f,
|
||||
int verbosity,
|
||||
int small,
|
||||
void* unused,
|
||||
int nUnused
|
||||
void* unused,
|
||||
int nUnused
|
||||
);
|
||||
|
||||
BZ_EXTERN void BZ_API(BZ2_bzReadClose) (
|
||||
int* bzerror,
|
||||
BZFILE* b
|
||||
BZ_EXTERN void BZ_API(BZ2_bzReadClose) (
|
||||
int* bzerror,
|
||||
BZFILE* b
|
||||
);
|
||||
|
||||
BZ_EXTERN void BZ_API(BZ2_bzReadGetUnused) (
|
||||
int* bzerror,
|
||||
BZFILE* b,
|
||||
void** unused,
|
||||
int* nUnused
|
||||
BZ_EXTERN void BZ_API(BZ2_bzReadGetUnused) (
|
||||
int* bzerror,
|
||||
BZFILE* b,
|
||||
void** unused,
|
||||
int* nUnused
|
||||
);
|
||||
|
||||
BZ_EXTERN int BZ_API(BZ2_bzRead) (
|
||||
int* bzerror,
|
||||
BZFILE* b,
|
||||
void* buf,
|
||||
int len
|
||||
BZ_EXTERN int BZ_API(BZ2_bzRead) (
|
||||
int* bzerror,
|
||||
BZFILE* b,
|
||||
void* buf,
|
||||
int len
|
||||
);
|
||||
|
||||
BZ_EXTERN BZFILE* BZ_API(BZ2_bzWriteOpen) (
|
||||
int* bzerror,
|
||||
FILE* f,
|
||||
int blockSize100k,
|
||||
int verbosity,
|
||||
int workFactor
|
||||
BZ_EXTERN BZFILE* BZ_API(BZ2_bzWriteOpen) (
|
||||
int* bzerror,
|
||||
FILE* f,
|
||||
int blockSize100k,
|
||||
int verbosity,
|
||||
int workFactor
|
||||
);
|
||||
|
||||
BZ_EXTERN void BZ_API(BZ2_bzWrite) (
|
||||
int* bzerror,
|
||||
BZFILE* b,
|
||||
void* buf,
|
||||
int len
|
||||
BZ_EXTERN void BZ_API(BZ2_bzWrite) (
|
||||
int* bzerror,
|
||||
BZFILE* b,
|
||||
void* buf,
|
||||
int len
|
||||
);
|
||||
|
||||
BZ_EXTERN void BZ_API(BZ2_bzWriteClose) (
|
||||
int* bzerror,
|
||||
BZFILE* b,
|
||||
int abandon,
|
||||
unsigned int* nbytes_in,
|
||||
unsigned int* nbytes_out
|
||||
BZ_EXTERN void BZ_API(BZ2_bzWriteClose) (
|
||||
int* bzerror,
|
||||
BZFILE* b,
|
||||
int abandon,
|
||||
unsigned int* nbytes_in,
|
||||
unsigned int* nbytes_out
|
||||
);
|
||||
|
||||
BZ_EXTERN void BZ_API(BZ2_bzWriteClose64) (
|
||||
int* bzerror,
|
||||
BZFILE* b,
|
||||
int abandon,
|
||||
unsigned int* nbytes_in_lo32,
|
||||
unsigned int* nbytes_in_hi32,
|
||||
unsigned int* nbytes_out_lo32,
|
||||
BZ_EXTERN void BZ_API(BZ2_bzWriteClose64) (
|
||||
int* bzerror,
|
||||
BZFILE* b,
|
||||
int abandon,
|
||||
unsigned int* nbytes_in_lo32,
|
||||
unsigned int* nbytes_in_hi32,
|
||||
unsigned int* nbytes_out_lo32,
|
||||
unsigned int* nbytes_out_hi32
|
||||
);
|
||||
#endif
|
||||
@@ -241,23 +241,23 @@ BZ_EXTERN void BZ_API(BZ2_bzWriteClose64) (
|
||||
|
||||
/*-- Utility functions --*/
|
||||
|
||||
BZ_EXTERN int BZ_API(BZ2_bzBuffToBuffCompress) (
|
||||
char* dest,
|
||||
BZ_EXTERN int BZ_API(BZ2_bzBuffToBuffCompress) (
|
||||
char* dest,
|
||||
unsigned int* destLen,
|
||||
char* source,
|
||||
char* source,
|
||||
unsigned int sourceLen,
|
||||
int blockSize100k,
|
||||
int verbosity,
|
||||
int workFactor
|
||||
int blockSize100k,
|
||||
int verbosity,
|
||||
int workFactor
|
||||
);
|
||||
|
||||
BZ_EXTERN int BZ_API(BZ2_bzBuffToBuffDecompress) (
|
||||
char* dest,
|
||||
BZ_EXTERN int BZ_API(BZ2_bzBuffToBuffDecompress) (
|
||||
char* dest,
|
||||
unsigned int* destLen,
|
||||
char* source,
|
||||
char* source,
|
||||
unsigned int sourceLen,
|
||||
int small,
|
||||
int verbosity
|
||||
int small,
|
||||
int verbosity
|
||||
);
|
||||
|
||||
|
||||
@@ -285,17 +285,17 @@ BZ_EXTERN BZFILE * BZ_API(BZ2_bzdopen) (
|
||||
int fd,
|
||||
const char *mode
|
||||
);
|
||||
|
||||
|
||||
BZ_EXTERN int BZ_API(BZ2_bzread) (
|
||||
BZFILE* b,
|
||||
void* buf,
|
||||
int len
|
||||
BZFILE* b,
|
||||
void* buf,
|
||||
int len
|
||||
);
|
||||
|
||||
BZ_EXTERN int BZ_API(BZ2_bzwrite) (
|
||||
BZFILE* b,
|
||||
void* buf,
|
||||
int len
|
||||
BZFILE* b,
|
||||
void* buf,
|
||||
int len
|
||||
);
|
||||
|
||||
BZ_EXTERN int BZ_API(BZ2_bzflush) (
|
||||
@@ -307,7 +307,7 @@ BZ_EXTERN void BZ_API(BZ2_bzclose) (
|
||||
);
|
||||
|
||||
BZ_EXTERN const char * BZ_API(BZ2_bzerror) (
|
||||
BZFILE *b,
|
||||
BZFILE *b,
|
||||
int *errnum
|
||||
);
|
||||
#endif
|
||||
|
||||
@@ -17,16 +17,16 @@
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. The origin of this software must not be misrepresented; you must
|
||||
not claim that you wrote the original software. If you use this
|
||||
software in a product, an acknowledgment in the product
|
||||
2. The origin of this software must not be misrepresented; you must
|
||||
not claim that you wrote the original software. If you use this
|
||||
software in a product, an acknowledgment in the product
|
||||
documentation would be appreciated but is not required.
|
||||
|
||||
3. Altered source versions must be plainly marked as such, and must
|
||||
not be misrepresented as being the original software.
|
||||
|
||||
4. The name of the author may not be used to endorse or promote
|
||||
products derived from this software without specific prior written
|
||||
4. The name of the author may not be used to endorse or promote
|
||||
products derived from this software without specific prior written
|
||||
permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
|
||||
@@ -91,7 +91,7 @@ typedef unsigned short UInt16;
|
||||
|
||||
#ifndef __GNUC__
|
||||
#define __inline__ /* */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef BZ_NO_STDIO
|
||||
extern void BZ2_bz__AssertH__fail ( int errcode );
|
||||
@@ -143,7 +143,7 @@ extern void bz_internal_error ( int errcode );
|
||||
#define BZ_HDR_Z 0x5a /* 'Z' */
|
||||
#define BZ_HDR_h 0x68 /* 'h' */
|
||||
#define BZ_HDR_0 0x30 /* '0' */
|
||||
|
||||
|
||||
/*-- Constants for the back end. --*/
|
||||
|
||||
#define BZ_MAX_ALPHA_SIZE 258
|
||||
@@ -303,19 +303,19 @@ typedef
|
||||
|
||||
/*-- externs for compression. --*/
|
||||
|
||||
extern void
|
||||
extern void
|
||||
BZ2_blockSort ( EState* );
|
||||
|
||||
extern void
|
||||
extern void
|
||||
BZ2_compressBlock ( EState*, Bool );
|
||||
|
||||
extern void
|
||||
extern void
|
||||
BZ2_bsInitWrite ( EState* );
|
||||
|
||||
extern void
|
||||
extern void
|
||||
BZ2_hbAssignCodes ( Int32*, UChar*, Int32, Int32, Int32 );
|
||||
|
||||
extern void
|
||||
extern void
|
||||
BZ2_hbMakeCodeLengths ( UChar*, Int32*, Int32, Int32 );
|
||||
|
||||
|
||||
@@ -459,7 +459,7 @@ typedef
|
||||
Int32 save_N;
|
||||
Int32 save_curr;
|
||||
Int32 save_zt;
|
||||
Int32 save_zn;
|
||||
Int32 save_zn;
|
||||
Int32 save_zvec;
|
||||
Int32 save_zj;
|
||||
Int32 save_gSel;
|
||||
@@ -509,13 +509,13 @@ typedef
|
||||
|
||||
/*-- externs for decompression. --*/
|
||||
|
||||
extern Int32
|
||||
extern Int32
|
||||
BZ2_indexIntoF ( Int32, Int32* );
|
||||
|
||||
extern Int32
|
||||
extern Int32
|
||||
BZ2_decompress ( DState* );
|
||||
|
||||
extern void
|
||||
extern void
|
||||
BZ2_hbCreateDecodeTables ( Int32*, Int32*, Int32*, UChar*,
|
||||
Int32, Int32, Int32 );
|
||||
|
||||
|
||||
@@ -17,16 +17,16 @@
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. The origin of this software must not be misrepresented; you must
|
||||
not claim that you wrote the original software. If you use this
|
||||
software in a product, an acknowledgment in the product
|
||||
2. The origin of this software must not be misrepresented; you must
|
||||
not claim that you wrote the original software. If you use this
|
||||
software in a product, an acknowledgment in the product
|
||||
documentation would be appreciated but is not required.
|
||||
|
||||
3. Altered source versions must be plainly marked as such, and must
|
||||
not be misrepresented as being the original software.
|
||||
|
||||
4. The name of the author may not be used to endorse or promote
|
||||
products derived from this software without specific prior written
|
||||
4. The name of the author may not be used to endorse or promote
|
||||
products derived from this software without specific prior written
|
||||
permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
|
||||
@@ -66,7 +66,7 @@
|
||||
0.9.0a/b -- no changes in this file.
|
||||
|
||||
0.9.0c
|
||||
* changed setting of nGroups in sendMTFValues() so as to
|
||||
* changed setting of nGroups in sendMTFValues() so as to
|
||||
do a bit better on small files
|
||||
--*/
|
||||
|
||||
@@ -169,11 +169,11 @@ void generateMTFValues ( EState* s )
|
||||
Int32 wr;
|
||||
Int32 EOB;
|
||||
|
||||
/*
|
||||
/*
|
||||
After sorting (eg, here),
|
||||
s->arr1 [ 0 .. s->nblock-1 ] holds sorted order,
|
||||
and
|
||||
((UChar*)s->arr2) [ 0 .. s->nblock-1 ]
|
||||
((UChar*)s->arr2) [ 0 .. s->nblock-1 ]
|
||||
holds the original block data.
|
||||
|
||||
The first thing to do is generate the MTF values,
|
||||
@@ -188,7 +188,7 @@ void generateMTFValues ( EState* s )
|
||||
(UChar*) (&((UChar*)s->arr2)[s->nblock])
|
||||
|
||||
These storage aliases are set up in bzCompressInit(),
|
||||
except for the last one, which is arranged in
|
||||
except for the last one, which is arranged in
|
||||
compressBlock().
|
||||
*/
|
||||
UInt32* ptr = s->ptr;
|
||||
@@ -211,7 +211,7 @@ void generateMTFValues ( EState* s )
|
||||
ll_i = s->unseqToSeq[block[j]];
|
||||
AssertD ( ll_i < s->nInUse, "generateMTFValues(2a)" );
|
||||
|
||||
if (yy[0] == ll_i) {
|
||||
if (yy[0] == ll_i) {
|
||||
zPend++;
|
||||
} else {
|
||||
|
||||
@@ -219,11 +219,11 @@ void generateMTFValues ( EState* s )
|
||||
zPend--;
|
||||
while (True) {
|
||||
if (zPend & 1) {
|
||||
mtfv[wr] = BZ_RUNB; wr++;
|
||||
s->mtfFreq[BZ_RUNB]++;
|
||||
mtfv[wr] = BZ_RUNB; wr++;
|
||||
s->mtfFreq[BZ_RUNB]++;
|
||||
} else {
|
||||
mtfv[wr] = BZ_RUNA; wr++;
|
||||
s->mtfFreq[BZ_RUNA]++;
|
||||
mtfv[wr] = BZ_RUNA; wr++;
|
||||
s->mtfFreq[BZ_RUNA]++;
|
||||
}
|
||||
if (zPend < 2) break;
|
||||
zPend = (zPend - 2) / 2;
|
||||
@@ -257,11 +257,11 @@ void generateMTFValues ( EState* s )
|
||||
zPend--;
|
||||
while (True) {
|
||||
if (zPend & 1) {
|
||||
mtfv[wr] = BZ_RUNB; wr++;
|
||||
s->mtfFreq[BZ_RUNB]++;
|
||||
mtfv[wr] = BZ_RUNB; wr++;
|
||||
s->mtfFreq[BZ_RUNB]++;
|
||||
} else {
|
||||
mtfv[wr] = BZ_RUNA; wr++;
|
||||
s->mtfFreq[BZ_RUNA]++;
|
||||
mtfv[wr] = BZ_RUNA; wr++;
|
||||
s->mtfFreq[BZ_RUNA]++;
|
||||
}
|
||||
if (zPend < 2) break;
|
||||
zPend = (zPend - 2) / 2;
|
||||
@@ -304,7 +304,7 @@ void sendMTFValues ( EState* s )
|
||||
|
||||
if (s->verbosity >= 3)
|
||||
VPrintf3( " %d in block, %d after MTF & 1-2 coding, "
|
||||
"%d+2 syms in use\n",
|
||||
"%d+2 syms in use\n",
|
||||
s->nblock, s->nMTF, s->nInUse );
|
||||
|
||||
alphaSize = s->nInUse+2;
|
||||
@@ -321,7 +321,7 @@ void sendMTFValues ( EState* s )
|
||||
nGroups = 6;
|
||||
|
||||
/*--- Generate an initial set of coding tables ---*/
|
||||
{
|
||||
{
|
||||
Int32 nPart, remF, tFreq, aFreq;
|
||||
|
||||
nPart = nGroups;
|
||||
@@ -336,8 +336,8 @@ void sendMTFValues ( EState* s )
|
||||
aFreq += s->mtfFreq[ge];
|
||||
}
|
||||
|
||||
if (ge > gs
|
||||
&& nPart != nGroups && nPart != 1
|
||||
if (ge > gs
|
||||
&& nPart != nGroups && nPart != 1
|
||||
&& ((nGroups-nPart) % 2 == 1)) {
|
||||
aFreq -= s->mtfFreq[ge];
|
||||
ge--;
|
||||
@@ -346,21 +346,21 @@ void sendMTFValues ( EState* s )
|
||||
if (s->verbosity >= 3)
|
||||
VPrintf5( " initial group %d, [%d .. %d], "
|
||||
"has %d syms (%4.1f%%)\n",
|
||||
nPart, gs, ge, aFreq,
|
||||
nPart, gs, ge, aFreq,
|
||||
(100.0 * (float)aFreq) / (float)(s->nMTF) );
|
||||
|
||||
|
||||
for (v = 0; v < alphaSize; v++)
|
||||
if (v >= gs && v <= ge)
|
||||
if (v >= gs && v <= ge)
|
||||
s->len[nPart-1][v] = BZ_LESSER_ICOST; else
|
||||
s->len[nPart-1][v] = BZ_GREATER_ICOST;
|
||||
|
||||
|
||||
nPart--;
|
||||
gs = ge+1;
|
||||
remF -= aFreq;
|
||||
}
|
||||
}
|
||||
|
||||
/*---
|
||||
/*---
|
||||
Iterate up to BZ_N_ITERS times to improve the tables.
|
||||
---*/
|
||||
for (iter = 0; iter < BZ_N_ITERS; iter++) {
|
||||
@@ -373,14 +373,14 @@ void sendMTFValues ( EState* s )
|
||||
|
||||
/*---
|
||||
Set up an auxiliary length table which is used to fast-track
|
||||
the common case (nGroups == 6).
|
||||
the common case (nGroups == 6).
|
||||
---*/
|
||||
if (nGroups == 6) {
|
||||
for (v = 0; v < alphaSize; v++) {
|
||||
s->len_pack[v][0] = (s->len[1][v] << 16) | s->len[0][v];
|
||||
s->len_pack[v][1] = (s->len[3][v] << 16) | s->len[2][v];
|
||||
s->len_pack[v][2] = (s->len[5][v] << 16) | s->len[4][v];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nSelectors = 0;
|
||||
@@ -390,10 +390,10 @@ void sendMTFValues ( EState* s )
|
||||
|
||||
/*--- Set group start & end marks. --*/
|
||||
if (gs >= s->nMTF) break;
|
||||
ge = gs + BZ_G_SIZE - 1;
|
||||
ge = gs + BZ_G_SIZE - 1;
|
||||
if (ge >= s->nMTF) ge = s->nMTF-1;
|
||||
|
||||
/*--
|
||||
/*--
|
||||
Calculate the cost of this group as coded
|
||||
by each of the coding tables.
|
||||
--*/
|
||||
@@ -429,14 +429,14 @@ void sendMTFValues ( EState* s )
|
||||
cost[4] = cost45 & 0xffff; cost[5] = cost45 >> 16;
|
||||
|
||||
} else {
|
||||
/*--- slow version which correctly handles all situations ---*/
|
||||
for (i = gs; i <= ge; i++) {
|
||||
/*--- slow version which correctly handles all situations ---*/
|
||||
for (i = gs; i <= ge; i++) {
|
||||
UInt16 icv = mtfv[i];
|
||||
for (t = 0; t < nGroups; t++) cost[t] += s->len[t][icv];
|
||||
}
|
||||
}
|
||||
|
||||
/*--
|
||||
|
||||
/*--
|
||||
Find the coding table which is best for this group,
|
||||
and record its identity in the selector table.
|
||||
--*/
|
||||
@@ -448,7 +448,7 @@ void sendMTFValues ( EState* s )
|
||||
s->selector[nSelectors] = bt;
|
||||
nSelectors++;
|
||||
|
||||
/*--
|
||||
/*--
|
||||
Increment the symbol frequencies for the selected table.
|
||||
--*/
|
||||
if (nGroups == 6 && 50 == ge-gs+1) {
|
||||
@@ -470,7 +470,7 @@ void sendMTFValues ( EState* s )
|
||||
# undef BZ_ITUR
|
||||
|
||||
} else {
|
||||
/*--- slow version which correctly handles all situations ---*/
|
||||
/*--- slow version which correctly handles all situations ---*/
|
||||
for (i = gs; i <= ge; i++)
|
||||
s->rfreq[bt][ mtfv[i] ]++;
|
||||
}
|
||||
@@ -478,7 +478,7 @@ void sendMTFValues ( EState* s )
|
||||
gs = ge+1;
|
||||
}
|
||||
if (s->verbosity >= 3) {
|
||||
VPrintf2 ( " pass %d: size is %d, grp uses are ",
|
||||
VPrintf2 ( " pass %d: size is %d, grp uses are ",
|
||||
iter+1, totc/8 );
|
||||
for (t = 0; t < nGroups; t++)
|
||||
VPrintf1 ( "%d ", fave[t] );
|
||||
@@ -488,10 +488,10 @@ void sendMTFValues ( EState* s )
|
||||
/*--
|
||||
Recompute the tables based on the accumulated frequencies.
|
||||
--*/
|
||||
/* maxLen was changed from 20 to 17 in bzip2-1.0.3. See
|
||||
/* maxLen was changed from 20 to 17 in bzip2-1.0.3. See
|
||||
comment in huffman.c for details. */
|
||||
for (t = 0; t < nGroups; t++)
|
||||
BZ2_hbMakeCodeLengths ( &(s->len[t][0]), &(s->rfreq[t][0]),
|
||||
BZ2_hbMakeCodeLengths ( &(s->len[t][0]), &(s->rfreq[t][0]),
|
||||
alphaSize, 17 /*20*/ );
|
||||
}
|
||||
|
||||
@@ -531,19 +531,19 @@ void sendMTFValues ( EState* s )
|
||||
}
|
||||
AssertH ( !(maxLen > 17 /*20*/ ), 3004 );
|
||||
AssertH ( !(minLen < 1), 3005 );
|
||||
BZ2_hbAssignCodes ( &(s->code[t][0]), &(s->len[t][0]),
|
||||
BZ2_hbAssignCodes ( &(s->code[t][0]), &(s->len[t][0]),
|
||||
minLen, maxLen, alphaSize );
|
||||
}
|
||||
|
||||
/*--- Transmit the mapping table. ---*/
|
||||
{
|
||||
{
|
||||
Bool inUse16[16];
|
||||
for (i = 0; i < 16; i++) {
|
||||
inUse16[i] = False;
|
||||
for (j = 0; j < 16; j++)
|
||||
if (s->inUse[i * 16 + j]) inUse16[i] = True;
|
||||
}
|
||||
|
||||
|
||||
nBytes = s->numZ;
|
||||
for (i = 0; i < 16; i++)
|
||||
if (inUse16[i]) bsW(s,1,1); else bsW(s,1,0);
|
||||
@@ -554,7 +554,7 @@ void sendMTFValues ( EState* s )
|
||||
if (s->inUse[i * 16 + j]) bsW(s,1,1); else bsW(s,1,0);
|
||||
}
|
||||
|
||||
if (s->verbosity >= 3)
|
||||
if (s->verbosity >= 3)
|
||||
VPrintf1( " bytes: mapping %d, ", s->numZ-nBytes );
|
||||
}
|
||||
|
||||
@@ -562,7 +562,7 @@ void sendMTFValues ( EState* s )
|
||||
nBytes = s->numZ;
|
||||
bsW ( s, 3, nGroups );
|
||||
bsW ( s, 15, nSelectors );
|
||||
for (i = 0; i < nSelectors; i++) {
|
||||
for (i = 0; i < nSelectors; i++) {
|
||||
for (j = 0; j < s->selectorMtf[i]; j++) bsW(s,1,1);
|
||||
bsW(s,1,0);
|
||||
}
|
||||
@@ -591,14 +591,14 @@ void sendMTFValues ( EState* s )
|
||||
gs = 0;
|
||||
while (True) {
|
||||
if (gs >= s->nMTF) break;
|
||||
ge = gs + BZ_G_SIZE - 1;
|
||||
ge = gs + BZ_G_SIZE - 1;
|
||||
if (ge >= s->nMTF) ge = s->nMTF-1;
|
||||
AssertH ( s->selector[selCtr] < nGroups, 3006 );
|
||||
|
||||
if (nGroups == 6 && 50 == ge-gs+1) {
|
||||
/*--- fast track the common case ---*/
|
||||
UInt16 mtfv_i;
|
||||
UChar* s_len_sel_selCtr
|
||||
UChar* s_len_sel_selCtr
|
||||
= &(s->len[s->selector[selCtr]][0]);
|
||||
Int32* s_code_sel_selCtr
|
||||
= &(s->code[s->selector[selCtr]][0]);
|
||||
@@ -623,9 +623,9 @@ void sendMTFValues ( EState* s )
|
||||
# undef BZ_ITAH
|
||||
|
||||
} else {
|
||||
/*--- slow version which correctly handles all situations ---*/
|
||||
/*--- slow version which correctly handles all situations ---*/
|
||||
for (i = gs; i <= ge; i++) {
|
||||
bsW ( s,
|
||||
bsW ( s,
|
||||
s->len [s->selector[selCtr]] [mtfv[i]],
|
||||
s->code [s->selector[selCtr]] [mtfv[i]] );
|
||||
}
|
||||
@@ -680,8 +680,8 @@ void BZ2_compressBlock ( EState* s, Bool is_last_block )
|
||||
/*-- Now the block's CRC, so it is in a known place. --*/
|
||||
bsPutUInt32 ( s, s->blockCRC );
|
||||
|
||||
/*--
|
||||
Now a single bit indicating (non-)randomisation.
|
||||
/*--
|
||||
Now a single bit indicating (non-)randomisation.
|
||||
As of version 0.9.5, we use a better sorting algorithm
|
||||
which makes randomisation unnecessary. So always set
|
||||
the randomised bit to 'no'. Of course, the decoder
|
||||
|
||||
@@ -17,16 +17,16 @@
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. The origin of this software must not be misrepresented; you must
|
||||
not claim that you wrote the original software. If you use this
|
||||
software in a product, an acknowledgment in the product
|
||||
2. The origin of this software must not be misrepresented; you must
|
||||
not claim that you wrote the original software. If you use this
|
||||
software in a product, an acknowledgment in the product
|
||||
documentation would be appreciated but is not required.
|
||||
|
||||
3. Altered source versions must be plainly marked as such, and must
|
||||
not be misrepresented as being the original software.
|
||||
|
||||
4. The name of the author may not be used to endorse or promote
|
||||
products derived from this software without specific prior written
|
||||
4. The name of the author may not be used to endorse or promote
|
||||
products derived from this software without specific prior written
|
||||
permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
|
||||
|
||||
@@ -17,16 +17,16 @@
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. The origin of this software must not be misrepresented; you must
|
||||
not claim that you wrote the original software. If you use this
|
||||
software in a product, an acknowledgment in the product
|
||||
2. The origin of this software must not be misrepresented; you must
|
||||
not claim that you wrote the original software. If you use this
|
||||
software in a product, an acknowledgment in the product
|
||||
documentation would be appreciated but is not required.
|
||||
|
||||
3. Altered source versions must be plainly marked as such, and must
|
||||
not be misrepresented as being the original software.
|
||||
|
||||
4. The name of the author may not be used to endorse or promote
|
||||
products derived from this software without specific prior written
|
||||
4. The name of the author may not be used to endorse or promote
|
||||
products derived from this software without specific prior written
|
||||
permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
|
||||
@@ -167,7 +167,7 @@ Int32 BZ2_decompress ( DState* s )
|
||||
Int32 N;
|
||||
Int32 curr;
|
||||
Int32 zt;
|
||||
Int32 zn;
|
||||
Int32 zn;
|
||||
Int32 zvec;
|
||||
Int32 zj;
|
||||
Int32 gSel;
|
||||
@@ -221,7 +221,7 @@ Int32 BZ2_decompress ( DState* s )
|
||||
N = s->save_N;
|
||||
curr = s->save_curr;
|
||||
zt = s->save_zt;
|
||||
zn = s->save_zn;
|
||||
zn = s->save_zn;
|
||||
zvec = s->save_zvec;
|
||||
zj = s->save_zj;
|
||||
gSel = s->save_gSel;
|
||||
@@ -244,14 +244,14 @@ Int32 BZ2_decompress ( DState* s )
|
||||
if (uc != BZ_HDR_h) RETURN(BZ_DATA_ERROR_MAGIC);
|
||||
|
||||
GET_BITS(BZ_X_MAGIC_4, s->blockSize100k, 8)
|
||||
if (s->blockSize100k < (BZ_HDR_0 + 1) ||
|
||||
if (s->blockSize100k < (BZ_HDR_0 + 1) ||
|
||||
s->blockSize100k > (BZ_HDR_0 + 9)) RETURN(BZ_DATA_ERROR_MAGIC);
|
||||
s->blockSize100k -= BZ_HDR_0;
|
||||
|
||||
if (s->smallDecompress) {
|
||||
s->ll16 = BZALLOC( s->blockSize100k * 100000 * sizeof(UInt16) );
|
||||
s->ll4 = BZALLOC(
|
||||
((1 + s->blockSize100k * 100000) >> 1) * sizeof(UChar)
|
||||
s->ll4 = BZALLOC(
|
||||
((1 + s->blockSize100k * 100000) >> 1) * sizeof(UChar)
|
||||
);
|
||||
if (s->ll16 == NULL || s->ll4 == NULL) RETURN(BZ_MEM_ERROR);
|
||||
} else {
|
||||
@@ -277,7 +277,7 @@ Int32 BZ2_decompress ( DState* s )
|
||||
s->currBlockNo++;
|
||||
if (s->verbosity >= 2)
|
||||
VPrintf1 ( "\n [%d: huff+mtf ", s->currBlockNo );
|
||||
|
||||
|
||||
s->storedBlockCRC = 0;
|
||||
GET_UCHAR(BZ_X_BCRC_1, uc);
|
||||
s->storedBlockCRC = (s->storedBlockCRC << 8) | ((UInt32)uc);
|
||||
@@ -300,14 +300,14 @@ Int32 BZ2_decompress ( DState* s )
|
||||
|
||||
if (s->origPtr < 0)
|
||||
RETURN(BZ_DATA_ERROR);
|
||||
if (s->origPtr > 10 + 100000*s->blockSize100k)
|
||||
if (s->origPtr > 10 + 100000*s->blockSize100k)
|
||||
RETURN(BZ_DATA_ERROR);
|
||||
|
||||
/*--- Receive the mapping table ---*/
|
||||
for (i = 0; i < 16; i++) {
|
||||
GET_BIT(BZ_X_MAPPING_1, uc);
|
||||
if (uc == 1)
|
||||
s->inUse16[i] = True; else
|
||||
if (uc == 1)
|
||||
s->inUse16[i] = True; else
|
||||
s->inUse16[i] = False;
|
||||
}
|
||||
|
||||
@@ -343,7 +343,7 @@ Int32 BZ2_decompress ( DState* s )
|
||||
{
|
||||
UChar pos[BZ_N_GROUPS], tmp, v;
|
||||
for (v = 0; v < nGroups; v++) pos[v] = v;
|
||||
|
||||
|
||||
for (i = 0; i < nSelectors; i++) {
|
||||
v = s->selectorMtf[i];
|
||||
tmp = pos[v];
|
||||
@@ -376,10 +376,10 @@ Int32 BZ2_decompress ( DState* s )
|
||||
if (s->len[t][i] > maxLen) maxLen = s->len[t][i];
|
||||
if (s->len[t][i] < minLen) minLen = s->len[t][i];
|
||||
}
|
||||
BZ2_hbCreateDecodeTables (
|
||||
&(s->limit[t][0]),
|
||||
&(s->base[t][0]),
|
||||
&(s->perm[t][0]),
|
||||
BZ2_hbCreateDecodeTables (
|
||||
&(s->limit[t][0]),
|
||||
&(s->base[t][0]),
|
||||
&(s->perm[t][0]),
|
||||
&(s->len[t][0]),
|
||||
minLen, maxLen, alphaSize
|
||||
);
|
||||
@@ -471,23 +471,23 @@ Int32 BZ2_decompress ( DState* s )
|
||||
s->mtfa[(z)-3] = s->mtfa[(z)-4];
|
||||
nn -= 4;
|
||||
}
|
||||
while (nn > 0) {
|
||||
s->mtfa[(pp+nn)] = s->mtfa[(pp+nn)-1]; nn--;
|
||||
while (nn > 0) {
|
||||
s->mtfa[(pp+nn)] = s->mtfa[(pp+nn)-1]; nn--;
|
||||
};
|
||||
s->mtfa[pp] = uc;
|
||||
} else {
|
||||
} else {
|
||||
/* general case */
|
||||
lno = nn / MTFL_SIZE;
|
||||
off = nn % MTFL_SIZE;
|
||||
pp = s->mtfbase[lno] + off;
|
||||
uc = s->mtfa[pp];
|
||||
while (pp > s->mtfbase[lno]) {
|
||||
s->mtfa[pp] = s->mtfa[pp-1]; pp--;
|
||||
while (pp > s->mtfbase[lno]) {
|
||||
s->mtfa[pp] = s->mtfa[pp-1]; pp--;
|
||||
};
|
||||
s->mtfbase[lno]++;
|
||||
while (lno > 0) {
|
||||
s->mtfbase[lno]--;
|
||||
s->mtfa[s->mtfbase[lno]]
|
||||
s->mtfa[s->mtfbase[lno]]
|
||||
= s->mtfa[s->mtfbase[lno-1] + MTFL_SIZE - 1];
|
||||
lno--;
|
||||
}
|
||||
@@ -569,7 +569,7 @@ Int32 BZ2_decompress ( DState* s )
|
||||
if (s->blockRandomised) {
|
||||
BZ_RAND_INIT_MASK;
|
||||
BZ_GET_SMALL(s->k0); s->nblock_used++;
|
||||
BZ_RAND_UPD_MASK; s->k0 ^= BZ_RAND_MASK;
|
||||
BZ_RAND_UPD_MASK; s->k0 ^= BZ_RAND_MASK;
|
||||
} else {
|
||||
BZ_GET_SMALL(s->k0); s->nblock_used++;
|
||||
}
|
||||
@@ -588,7 +588,7 @@ Int32 BZ2_decompress ( DState* s )
|
||||
if (s->blockRandomised) {
|
||||
BZ_RAND_INIT_MASK;
|
||||
BZ_GET_FAST(s->k0); s->nblock_used++;
|
||||
BZ_RAND_UPD_MASK; s->k0 ^= BZ_RAND_MASK;
|
||||
BZ_RAND_UPD_MASK; s->k0 ^= BZ_RAND_MASK;
|
||||
} else {
|
||||
BZ_GET_FAST(s->k0); s->nblock_used++;
|
||||
}
|
||||
@@ -657,7 +657,7 @@ Int32 BZ2_decompress ( DState* s )
|
||||
s->save_gBase = gBase;
|
||||
s->save_gPerm = gPerm;
|
||||
|
||||
return retVal;
|
||||
return retVal;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
#define BZ2_LIBNAME "libbz2-1.0.2.DLL"
|
||||
#define BZ2_LIBNAME "libbz2-1.0.2.DLL"
|
||||
|
||||
#include <windows.h>
|
||||
static int BZ2DLLLoaded = 0;
|
||||
|
||||
@@ -17,16 +17,16 @@
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. The origin of this software must not be misrepresented; you must
|
||||
not claim that you wrote the original software. If you use this
|
||||
software in a product, an acknowledgment in the product
|
||||
2. The origin of this software must not be misrepresented; you must
|
||||
not claim that you wrote the original software. If you use this
|
||||
software in a product, an acknowledgment in the product
|
||||
documentation would be appreciated but is not required.
|
||||
|
||||
3. Altered source versions must be plainly marked as such, and must
|
||||
not be misrepresented as being the original software.
|
||||
|
||||
4. The name of the author may not be used to endorse or promote
|
||||
products derived from this software without specific prior written
|
||||
4. The name of the author may not be used to endorse or promote
|
||||
products derived from this software without specific prior written
|
||||
permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
|
||||
@@ -100,7 +100,7 @@
|
||||
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
void BZ2_hbMakeCodeLengths ( UChar *len,
|
||||
void BZ2_hbMakeCodeLengths ( UChar *len,
|
||||
Int32 *freq,
|
||||
Int32 alphaSize,
|
||||
Int32 maxLen )
|
||||
@@ -114,7 +114,7 @@ void BZ2_hbMakeCodeLengths ( UChar *len,
|
||||
|
||||
Int32 heap [ BZ_MAX_ALPHA_SIZE + 2 ];
|
||||
Int32 weight [ BZ_MAX_ALPHA_SIZE * 2 ];
|
||||
Int32 parent [ BZ_MAX_ALPHA_SIZE * 2 ];
|
||||
Int32 parent [ BZ_MAX_ALPHA_SIZE * 2 ];
|
||||
|
||||
for (i = 0; i < alphaSize; i++)
|
||||
weight[i+1] = (freq[i] == 0 ? 1 : freq[i]) << 8;
|
||||
@@ -136,7 +136,7 @@ void BZ2_hbMakeCodeLengths ( UChar *len,
|
||||
}
|
||||
|
||||
AssertH( nHeap < (BZ_MAX_ALPHA_SIZE+2), 2001 );
|
||||
|
||||
|
||||
while (nHeap > 1) {
|
||||
n1 = heap[1]; heap[1] = heap[nHeap]; nHeap--; DOWNHEAP(1);
|
||||
n2 = heap[1]; heap[1] = heap[nHeap]; nHeap--; DOWNHEAP(1);
|
||||
@@ -159,7 +159,7 @@ void BZ2_hbMakeCodeLengths ( UChar *len,
|
||||
len[i-1] = j;
|
||||
if (j > maxLen) tooLong = True;
|
||||
}
|
||||
|
||||
|
||||
if (! tooLong) break;
|
||||
|
||||
/* 17 Oct 04: keep-going condition for the following loop used
|
||||
|
||||
@@ -17,16 +17,16 @@
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. The origin of this software must not be misrepresented; you must
|
||||
not claim that you wrote the original software. If you use this
|
||||
software in a product, an acknowledgment in the product
|
||||
2. The origin of this software must not be misrepresented; you must
|
||||
not claim that you wrote the original software. If you use this
|
||||
software in a product, an acknowledgment in the product
|
||||
documentation would be appreciated but is not required.
|
||||
|
||||
3. Altered source versions must be plainly marked as such, and must
|
||||
not be misrepresented as being the original software.
|
||||
|
||||
4. The name of the author may not be used to endorse or promote
|
||||
products derived from this software without specific prior written
|
||||
4. The name of the author may not be used to endorse or promote
|
||||
products derived from this software without specific prior written
|
||||
permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
|
||||
@@ -63,58 +63,58 @@
|
||||
|
||||
|
||||
/*---------------------------------------------*/
|
||||
Int32 BZ2_rNums[512] = {
|
||||
619, 720, 127, 481, 931, 816, 813, 233, 566, 247,
|
||||
985, 724, 205, 454, 863, 491, 741, 242, 949, 214,
|
||||
733, 859, 335, 708, 621, 574, 73, 654, 730, 472,
|
||||
419, 436, 278, 496, 867, 210, 399, 680, 480, 51,
|
||||
878, 465, 811, 169, 869, 675, 611, 697, 867, 561,
|
||||
862, 687, 507, 283, 482, 129, 807, 591, 733, 623,
|
||||
150, 238, 59, 379, 684, 877, 625, 169, 643, 105,
|
||||
170, 607, 520, 932, 727, 476, 693, 425, 174, 647,
|
||||
73, 122, 335, 530, 442, 853, 695, 249, 445, 515,
|
||||
909, 545, 703, 919, 874, 474, 882, 500, 594, 612,
|
||||
641, 801, 220, 162, 819, 984, 589, 513, 495, 799,
|
||||
161, 604, 958, 533, 221, 400, 386, 867, 600, 782,
|
||||
382, 596, 414, 171, 516, 375, 682, 485, 911, 276,
|
||||
98, 553, 163, 354, 666, 933, 424, 341, 533, 870,
|
||||
227, 730, 475, 186, 263, 647, 537, 686, 600, 224,
|
||||
469, 68, 770, 919, 190, 373, 294, 822, 808, 206,
|
||||
184, 943, 795, 384, 383, 461, 404, 758, 839, 887,
|
||||
715, 67, 618, 276, 204, 918, 873, 777, 604, 560,
|
||||
951, 160, 578, 722, 79, 804, 96, 409, 713, 940,
|
||||
652, 934, 970, 447, 318, 353, 859, 672, 112, 785,
|
||||
645, 863, 803, 350, 139, 93, 354, 99, 820, 908,
|
||||
609, 772, 154, 274, 580, 184, 79, 626, 630, 742,
|
||||
653, 282, 762, 623, 680, 81, 927, 626, 789, 125,
|
||||
411, 521, 938, 300, 821, 78, 343, 175, 128, 250,
|
||||
170, 774, 972, 275, 999, 639, 495, 78, 352, 126,
|
||||
857, 956, 358, 619, 580, 124, 737, 594, 701, 612,
|
||||
669, 112, 134, 694, 363, 992, 809, 743, 168, 974,
|
||||
944, 375, 748, 52, 600, 747, 642, 182, 862, 81,
|
||||
344, 805, 988, 739, 511, 655, 814, 334, 249, 515,
|
||||
897, 955, 664, 981, 649, 113, 974, 459, 893, 228,
|
||||
433, 837, 553, 268, 926, 240, 102, 654, 459, 51,
|
||||
686, 754, 806, 760, 493, 403, 415, 394, 687, 700,
|
||||
946, 670, 656, 610, 738, 392, 760, 799, 887, 653,
|
||||
978, 321, 576, 617, 626, 502, 894, 679, 243, 440,
|
||||
680, 879, 194, 572, 640, 724, 926, 56, 204, 700,
|
||||
707, 151, 457, 449, 797, 195, 791, 558, 945, 679,
|
||||
297, 59, 87, 824, 713, 663, 412, 693, 342, 606,
|
||||
134, 108, 571, 364, 631, 212, 174, 643, 304, 329,
|
||||
343, 97, 430, 751, 497, 314, 983, 374, 822, 928,
|
||||
140, 206, 73, 263, 980, 736, 876, 478, 430, 305,
|
||||
170, 514, 364, 692, 829, 82, 855, 953, 676, 246,
|
||||
369, 970, 294, 750, 807, 827, 150, 790, 288, 923,
|
||||
804, 378, 215, 828, 592, 281, 565, 555, 710, 82,
|
||||
896, 831, 547, 261, 524, 462, 293, 465, 502, 56,
|
||||
661, 821, 976, 991, 658, 869, 905, 758, 745, 193,
|
||||
768, 550, 608, 933, 378, 286, 215, 979, 792, 961,
|
||||
61, 688, 793, 644, 986, 403, 106, 366, 905, 644,
|
||||
372, 567, 466, 434, 645, 210, 389, 550, 919, 135,
|
||||
780, 773, 635, 389, 707, 100, 626, 958, 165, 504,
|
||||
920, 176, 193, 713, 857, 265, 203, 50, 668, 108,
|
||||
645, 990, 626, 197, 510, 357, 358, 850, 858, 364,
|
||||
Int32 BZ2_rNums[512] = {
|
||||
619, 720, 127, 481, 931, 816, 813, 233, 566, 247,
|
||||
985, 724, 205, 454, 863, 491, 741, 242, 949, 214,
|
||||
733, 859, 335, 708, 621, 574, 73, 654, 730, 472,
|
||||
419, 436, 278, 496, 867, 210, 399, 680, 480, 51,
|
||||
878, 465, 811, 169, 869, 675, 611, 697, 867, 561,
|
||||
862, 687, 507, 283, 482, 129, 807, 591, 733, 623,
|
||||
150, 238, 59, 379, 684, 877, 625, 169, 643, 105,
|
||||
170, 607, 520, 932, 727, 476, 693, 425, 174, 647,
|
||||
73, 122, 335, 530, 442, 853, 695, 249, 445, 515,
|
||||
909, 545, 703, 919, 874, 474, 882, 500, 594, 612,
|
||||
641, 801, 220, 162, 819, 984, 589, 513, 495, 799,
|
||||
161, 604, 958, 533, 221, 400, 386, 867, 600, 782,
|
||||
382, 596, 414, 171, 516, 375, 682, 485, 911, 276,
|
||||
98, 553, 163, 354, 666, 933, 424, 341, 533, 870,
|
||||
227, 730, 475, 186, 263, 647, 537, 686, 600, 224,
|
||||
469, 68, 770, 919, 190, 373, 294, 822, 808, 206,
|
||||
184, 943, 795, 384, 383, 461, 404, 758, 839, 887,
|
||||
715, 67, 618, 276, 204, 918, 873, 777, 604, 560,
|
||||
951, 160, 578, 722, 79, 804, 96, 409, 713, 940,
|
||||
652, 934, 970, 447, 318, 353, 859, 672, 112, 785,
|
||||
645, 863, 803, 350, 139, 93, 354, 99, 820, 908,
|
||||
609, 772, 154, 274, 580, 184, 79, 626, 630, 742,
|
||||
653, 282, 762, 623, 680, 81, 927, 626, 789, 125,
|
||||
411, 521, 938, 300, 821, 78, 343, 175, 128, 250,
|
||||
170, 774, 972, 275, 999, 639, 495, 78, 352, 126,
|
||||
857, 956, 358, 619, 580, 124, 737, 594, 701, 612,
|
||||
669, 112, 134, 694, 363, 992, 809, 743, 168, 974,
|
||||
944, 375, 748, 52, 600, 747, 642, 182, 862, 81,
|
||||
344, 805, 988, 739, 511, 655, 814, 334, 249, 515,
|
||||
897, 955, 664, 981, 649, 113, 974, 459, 893, 228,
|
||||
433, 837, 553, 268, 926, 240, 102, 654, 459, 51,
|
||||
686, 754, 806, 760, 493, 403, 415, 394, 687, 700,
|
||||
946, 670, 656, 610, 738, 392, 760, 799, 887, 653,
|
||||
978, 321, 576, 617, 626, 502, 894, 679, 243, 440,
|
||||
680, 879, 194, 572, 640, 724, 926, 56, 204, 700,
|
||||
707, 151, 457, 449, 797, 195, 791, 558, 945, 679,
|
||||
297, 59, 87, 824, 713, 663, 412, 693, 342, 606,
|
||||
134, 108, 571, 364, 631, 212, 174, 643, 304, 329,
|
||||
343, 97, 430, 751, 497, 314, 983, 374, 822, 928,
|
||||
140, 206, 73, 263, 980, 736, 876, 478, 430, 305,
|
||||
170, 514, 364, 692, 829, 82, 855, 953, 676, 246,
|
||||
369, 970, 294, 750, 807, 827, 150, 790, 288, 923,
|
||||
804, 378, 215, 828, 592, 281, 565, 555, 710, 82,
|
||||
896, 831, 547, 261, 524, 462, 293, 465, 502, 56,
|
||||
661, 821, 976, 991, 658, 869, 905, 758, 745, 193,
|
||||
768, 550, 608, 933, 378, 286, 215, 979, 792, 961,
|
||||
61, 688, 793, 644, 986, 403, 106, 366, 905, 644,
|
||||
372, 567, 466, 434, 645, 210, 389, 550, 919, 135,
|
||||
780, 773, 635, 389, 707, 100, 626, 958, 165, 504,
|
||||
920, 176, 193, 713, 857, 265, 203, 50, 668, 108,
|
||||
645, 990, 626, 197, 510, 357, 358, 850, 858, 364,
|
||||
936, 638
|
||||
};
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
support for large files (> 2GB) in a reasonable amount of time.
|
||||
I suggest you use the undocumented --exponential option to
|
||||
bzip2 when compressing the resulting file; this saves a bit of
|
||||
time. Note: *don't* bother with --exponential when compressing
|
||||
time. Note: *don't* bother with --exponential when compressing
|
||||
Real Files; it'll just waste a lot of CPU time :-)
|
||||
(but is otherwise harmless).
|
||||
*/
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
|
||||
/* A test program written to test robustness to decompression of
|
||||
corrupted data. Usage is
|
||||
corrupted data. Usage is
|
||||
unzcrash filename
|
||||
and the program will read the specified file, compress it (in memory),
|
||||
and then repeatedly decompress it, each time with a different bit of
|
||||
the compressed data inverted, so as to test all possible one-bit errors.
|
||||
This should not cause any invalid memory accesses. If it does,
|
||||
This should not cause any invalid memory accesses. If it does,
|
||||
I want to know about it!
|
||||
|
||||
p.s. As you can see from the above description, the process is
|
||||
@@ -100,9 +100,9 @@ int main ( int argc, char** argv )
|
||||
return 1;
|
||||
} else {
|
||||
for (i = 0; i < nOut; i++)
|
||||
if (inbuf[i] != outbuf[i]) {
|
||||
fprintf(stderr, "mismatch at %d\n", i );
|
||||
return 1;
|
||||
if (inbuf[i] != outbuf[i]) {
|
||||
fprintf(stderr, "mismatch at %d\n", i );
|
||||
return 1;
|
||||
}
|
||||
if (i == nOut) fprintf(stderr, "really ok!\n" );
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -9,67 +9,67 @@
|
||||
/* 03.05.03 2.00 Lad Added compression */
|
||||
/* 08.12.03 2.01 Dan High-memory handling (> 0x80000000) */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
#ifndef __HUFFMAN_H__
|
||||
#define __HUFFMAN_H__
|
||||
|
||||
#include "../StormPort.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Defines
|
||||
|
||||
#define INSERT_ITEM 1
|
||||
|
||||
#define INSERT_ITEM 1
|
||||
#define SWITCH_ITEMS 2 // Switch the item1 and item2
|
||||
|
||||
|
||||
#define PTR_NOT(ptr) (THTreeItem *)(~(DWORD_PTR)(ptr))
|
||||
#define PTR_PTR(ptr) ((THTreeItem *)(ptr))
|
||||
#define PTR_INT(ptr) (LONG_PTR)(ptr)
|
||||
|
||||
|
||||
#ifndef NULL
|
||||
#define NULL 0
|
||||
#endif
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Structures and classes
|
||||
|
||||
|
||||
// Input stream for Huffmann decompression
|
||||
class TInputStream
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
unsigned long GetBit();
|
||||
unsigned long Get7Bits();
|
||||
unsigned long Get8Bits();
|
||||
|
||||
|
||||
unsigned char * pbInBuffer; // 00 - Input data
|
||||
unsigned long dwBitBuff; // 04 - Input bit buffer
|
||||
unsigned int nBits; // 08 - Number of bits remaining in 'dwValue'
|
||||
};
|
||||
|
||||
|
||||
// Output stream for Huffmann compression
|
||||
class TOutputStream
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
void PutBits(unsigned long dwBuff, unsigned int nPutBits);
|
||||
|
||||
|
||||
unsigned char * pbOutBuffer; // 00 : Output buffer
|
||||
unsigned long dwOutSize; // 04 : Size of output buffer
|
||||
unsigned char * pbOutPos; // 08 : Current output position
|
||||
unsigned long dwBitBuff; // 0C : Bit buffer
|
||||
unsigned long nBits; // 10 : Number of bits in the bit buffer
|
||||
};
|
||||
|
||||
|
||||
// Huffmann tree item (?)
|
||||
struct THTreeItem
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
THTreeItem * Call1501DB70(THTreeItem * pLast);
|
||||
THTreeItem * GetPrevItem(LONG_PTR value);
|
||||
void ClearItemLinks();
|
||||
void RemoveItem();
|
||||
|
||||
|
||||
THTreeItem * next; // 00 - Pointer to next THTreeItem
|
||||
THTreeItem * prev; // 04 - Pointer to prev THTreeItem (< 0 if none)
|
||||
unsigned long dcmpByte; // 08 - Index of this item in item pointer array, decompressed byte value
|
||||
@@ -78,7 +78,7 @@ struct THTreeItem
|
||||
THTreeItem * child; // 14 - Pointer to child THTreeItem
|
||||
int addressMultiplier; // -1 if object on negative address (>0x80000000), +1 if positive
|
||||
};
|
||||
|
||||
|
||||
// Structure used for quick decompress. The 'bitCount' contains number of bits
|
||||
// and byte value contains result decompressed byte value.
|
||||
// After each walk through Huffman tree are filled all entries which are
|
||||
@@ -96,47 +96,47 @@ struct TQDecompress
|
||||
THTreeItem * pItem; // 08 - THTreeItem (if number of bits is greater than 7
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
// Structure for Huffman tree (Size 0x3674 bytes). Because I'm not expert
|
||||
// for the decompression, I do not know actually if the class is really a Hufmann
|
||||
// tree. If someone knows the decompression details, please let me know
|
||||
class THuffmannTree
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
THuffmannTree();
|
||||
void InitTree(bool bCompression);
|
||||
void BuildTree(unsigned int nCmpType);
|
||||
// void ModifyTree(unsigned long dwIndex);
|
||||
// void UninitTree();
|
||||
|
||||
|
||||
// void Call15007010(Bit32 dwInLength, THTreeItem * item);
|
||||
THTreeItem * Call1500E740(unsigned int nValue);
|
||||
void Call1500E820(THTreeItem * pItem);
|
||||
unsigned int DoCompression(TOutputStream * os, unsigned char * pbInBuffer, int nInLength, int nCmpType);
|
||||
unsigned int DoDecompression(unsigned char * pbOutBuffer, unsigned int dwOutLength, TInputStream * is);
|
||||
|
||||
|
||||
unsigned long bIsCmp0; // 0000 - 1 if compression type 0
|
||||
unsigned long offs0004; // 0004 - Some flag
|
||||
THTreeItem items0008[0x203]; // 0008 - HTree items
|
||||
|
||||
|
||||
//- Sometimes used as HTree item -----------
|
||||
THTreeItem * pItem3050; // 3050 - Always NULL (?)
|
||||
THTreeItem * pItem3054; // 3054 - Pointer to Huffman tree item
|
||||
THTreeItem * pItem3058; // 3058 - Pointer to Huffman tree item (< 0 if invalid)
|
||||
|
||||
|
||||
//- Sometimes used as HTree item -----------
|
||||
THTreeItem * pItem305C; // 305C - Usually NULL
|
||||
THTreeItem * pFirst; // 3060 - Pointer to top (first) Huffman tree item
|
||||
THTreeItem * pLast; // 3064 - Pointer to bottom (last) Huffman tree item (< 0 if invalid)
|
||||
unsigned long nItems; // 3068 - Number of used HTree items
|
||||
|
||||
|
||||
//-------------------------------------------
|
||||
THTreeItem * items306C[0x102]; // 306C - THTreeItem pointer array
|
||||
TQDecompress qd3474[0x80]; // 3474 - Array for quick decompression
|
||||
int addressMultiplier; // -1 if object on negative address (>0x80000000), +1 if positive
|
||||
|
||||
|
||||
static unsigned char Table1502A630[];// Some table
|
||||
};
|
||||
|
||||
|
||||
#endif // __HUFFMAN_H__
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Tables
|
||||
|
||||
static unsigned char DistBits[] =
|
||||
static unsigned char DistBits[] =
|
||||
{
|
||||
0x02, 0x04, 0x04, 0x05, 0x05, 0x05, 0x05, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
|
||||
0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
|
||||
@@ -26,7 +26,7 @@ static unsigned char DistBits[] =
|
||||
0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08
|
||||
};
|
||||
|
||||
static unsigned char DistCode[] =
|
||||
static unsigned char DistCode[] =
|
||||
{
|
||||
0x03, 0x0D, 0x05, 0x19, 0x09, 0x11, 0x01, 0x3E, 0x1E, 0x2E, 0x0E, 0x36, 0x16, 0x26, 0x06, 0x3A,
|
||||
0x1A, 0x2A, 0x0A, 0x32, 0x12, 0x22, 0x42, 0x02, 0x7C, 0x3C, 0x5C, 0x1C, 0x6C, 0x2C, 0x4C, 0x0C,
|
||||
@@ -75,7 +75,7 @@ static unsigned char ChBitsAsc[] =
|
||||
0x0D, 0x0D, 0x0C, 0x0C, 0x0C, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D
|
||||
};
|
||||
|
||||
static unsigned short ChCodeAsc[] =
|
||||
static unsigned short ChCodeAsc[] =
|
||||
{
|
||||
0x0490, 0x0FE0, 0x07E0, 0x0BE0, 0x03E0, 0x0DE0, 0x05E0, 0x09E0,
|
||||
0x01E0, 0x00B8, 0x0062, 0x0EE0, 0x06E0, 0x0022, 0x0AE0, 0x02E0,
|
||||
@@ -108,7 +108,7 @@ static unsigned short ChCodeAsc[] =
|
||||
0x0300, 0x0D40, 0x1D00, 0x0D00, 0x1500, 0x0540, 0x0500, 0x1900,
|
||||
0x0900, 0x0940, 0x1100, 0x0100, 0x1E00, 0x0E00, 0x0140, 0x1600,
|
||||
0x0600, 0x1A00, 0x0E40, 0x0640, 0x0A40, 0x0A00, 0x1200, 0x0200,
|
||||
0x1C00, 0x0C00, 0x1400, 0x0400, 0x1800, 0x0800, 0x1000, 0x0000
|
||||
0x1C00, 0x0C00, 0x1400, 0x0400, 0x1800, 0x0800, 0x1000, 0x0000
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -266,11 +266,11 @@ static unsigned long DecodeLit(TDcmpStruct * pWork)
|
||||
{
|
||||
// Skip current bit in the buffer
|
||||
if(WasteBits(pWork, 1))
|
||||
return 0x306;
|
||||
return 0x306;
|
||||
|
||||
// The next bits are position in buffers
|
||||
value = pWork->position2[(pWork->bit_buff & 0xFF)];
|
||||
|
||||
|
||||
// Get number of bits to skip
|
||||
if(WasteBits(pWork, pWork->LenBits[value]))
|
||||
return 0x306;
|
||||
@@ -337,7 +337,7 @@ static unsigned long DecodeLit(TDcmpStruct * pWork)
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Retrieves the number of bytes to move back
|
||||
// Retrieves the number of bytes to move back
|
||||
|
||||
static unsigned long DecodeDist(TDcmpStruct * pWork, unsigned long dwLength)
|
||||
{
|
||||
@@ -402,7 +402,7 @@ static unsigned long Expand(TDcmpStruct * pWork)
|
||||
}
|
||||
else
|
||||
pWork->out_buff[pWork->outputPos++] = (unsigned char)oneByte;
|
||||
|
||||
|
||||
// If number of extracted bytes has reached 1/2 of output buffer,
|
||||
// flush output buffer.
|
||||
if(pWork->outputPos >= 0x2000)
|
||||
@@ -453,7 +453,7 @@ unsigned int explode(
|
||||
pWork->in_pos = 3; // Position in input buffer
|
||||
|
||||
// Test for the valid dictionary size
|
||||
if(4 > pWork->dsize_bits || pWork->dsize_bits > 6)
|
||||
if(4 > pWork->dsize_bits || pWork->dsize_bits > 6)
|
||||
return CMP_INVALID_DICTSIZE;
|
||||
|
||||
pWork->dsize_mask = 0xFFFF >> (0x10 - pWork->dsize_bits); // Shifted by 'sar' instruction
|
||||
@@ -475,6 +475,6 @@ unsigned int explode(
|
||||
GenDecodeTabs(0x40, pWork->DistBits, DistCode, pWork->position1);
|
||||
if(Expand(pWork) != 0x306)
|
||||
return CMP_NO_ERROR;
|
||||
|
||||
|
||||
return CMP_ABORT;
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Tables
|
||||
|
||||
static unsigned char DistBits[] =
|
||||
static unsigned char DistBits[] =
|
||||
{
|
||||
0x02, 0x04, 0x04, 0x05, 0x05, 0x05, 0x05, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
|
||||
0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
|
||||
@@ -36,7 +36,7 @@ static unsigned char DistBits[] =
|
||||
0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08
|
||||
};
|
||||
|
||||
static unsigned char DistCode[] =
|
||||
static unsigned char DistCode[] =
|
||||
{
|
||||
0x03, 0x0D, 0x05, 0x19, 0x09, 0x11, 0x01, 0x3E, 0x1E, 0x2E, 0x0E, 0x36, 0x16, 0x26, 0x06, 0x3A,
|
||||
0x1A, 0x2A, 0x0A, 0x32, 0x12, 0x22, 0x42, 0x02, 0x7C, 0x3C, 0x5C, 0x1C, 0x6C, 0x2C, 0x4C, 0x0C,
|
||||
@@ -79,7 +79,7 @@ static unsigned char ChBitsAsc[] =
|
||||
0x0D, 0x0D, 0x0C, 0x0C, 0x0C, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D
|
||||
};
|
||||
|
||||
static unsigned short ChCodeAsc[] =
|
||||
static unsigned short ChCodeAsc[] =
|
||||
{
|
||||
0x0490, 0x0FE0, 0x07E0, 0x0BE0, 0x03E0, 0x0DE0, 0x05E0, 0x09E0,
|
||||
0x01E0, 0x00B8, 0x0062, 0x0EE0, 0x06E0, 0x0022, 0x0AE0, 0x02E0,
|
||||
@@ -112,7 +112,7 @@ static unsigned short ChCodeAsc[] =
|
||||
0x0300, 0x0D40, 0x1D00, 0x0D00, 0x1500, 0x0540, 0x0500, 0x1900,
|
||||
0x0900, 0x0940, 0x1100, 0x0100, 0x1E00, 0x0E00, 0x0140, 0x1600,
|
||||
0x0600, 0x1A00, 0x0E40, 0x0640, 0x0A40, 0x0A00, 0x1200, 0x0200,
|
||||
0x1C00, 0x0C00, 0x1400, 0x0400, 0x1800, 0x0800, 0x1000, 0x0000
|
||||
0x1C00, 0x0C00, 0x1400, 0x0400, 0x1800, 0x0800, 0x1000, 0x0000
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -215,7 +215,7 @@ static void OutputBits(TCmpStruct * pWork, unsigned int nbits, unsigned long bit
|
||||
{
|
||||
pWork->out_bytes++;
|
||||
bit_buff >>= (8 - out_bits);
|
||||
|
||||
|
||||
pWork->out_buff[pWork->out_bytes] = (unsigned char)bit_buff;
|
||||
pWork->out_bits &= 7;
|
||||
}
|
||||
@@ -341,7 +341,7 @@ static unsigned long FindRep(TCmpStruct * pWork, unsigned char * srcbuff)
|
||||
esi = nreps;
|
||||
pin27CC = pWork->work_buff + pin49D0[0] + nreps;
|
||||
esp14 = pin27CC;
|
||||
|
||||
|
||||
for(;;) // 0040268B
|
||||
{
|
||||
esi = pWork->offs09BC[esi];
|
||||
@@ -473,7 +473,7 @@ static void WriteCmpData(TCmpStruct * pWork)
|
||||
//
|
||||
switch(esp20)
|
||||
{
|
||||
case 0:
|
||||
case 0:
|
||||
SortBuffer(pWork, uncmp_begin, uncmp_end + 1);
|
||||
esp20++;
|
||||
if(pWork->dsize_bytes != 0x1000)
|
||||
@@ -590,7 +590,7 @@ unsigned int PKEXPORT implode(
|
||||
// Initialize the work buffer. This is not in the Pklib,
|
||||
// but it seems to be a bug. Storm always pre-fills the data with zeros,
|
||||
// and always compresses one block only. So the bug will not appear.
|
||||
// But when a larger data block (size > 0x1000) is compressed,
|
||||
// But when a larger data block (size > 0x1000) is compressed,
|
||||
// it may fail.
|
||||
memset(pWork, 0, sizeof(TCmpStruct));
|
||||
|
||||
@@ -650,7 +650,7 @@ unsigned int PKEXPORT implode(
|
||||
|
||||
for(i = 0; i < 0x10; i++)
|
||||
{
|
||||
int nCount2 = 0; // EBX
|
||||
int nCount2 = 0; // EBX
|
||||
|
||||
if((1 << ExLenBits[i]) == 0)
|
||||
continue;
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
// Define calling convention
|
||||
|
||||
#ifndef PKEXPORT
|
||||
#define PKEXPORT //__cdecl // Use for normal __cdecl calling
|
||||
#define PKEXPORT //__cdecl // Use for normal __cdecl calling
|
||||
#endif
|
||||
//#define PKEXPORT __stdcall
|
||||
//#define PKEXPORT __fastcall
|
||||
@@ -40,8 +40,8 @@
|
||||
// Compression structure
|
||||
typedef struct
|
||||
{
|
||||
unsigned int offs0000; // 0000 :
|
||||
unsigned int out_bytes; // 0004 : # bytes available in out_buff
|
||||
unsigned int offs0000; // 0000 :
|
||||
unsigned int out_bytes; // 0004 : # bytes available in out_buff
|
||||
unsigned int out_bits; // 0008 : # of bits available in the last out byte
|
||||
unsigned int dsize_bits; // 000C : Dict size : 4=0x400, 5=0x800, 6=0x1000
|
||||
unsigned int dsize_mask; // 0010 : Dict size : 0x0F=0x400, 0x1F=0x800, 0x3F=0x1000
|
||||
@@ -49,23 +49,23 @@ typedef struct
|
||||
unsigned int dsize_bytes; // 0018 : Dictionary size in bytes
|
||||
unsigned char dist_bits[0x40]; // 001C : Distance bits
|
||||
unsigned char dist_codes[0x40]; // 005C : Distance codes
|
||||
unsigned char nChBits[0x306]; // 009C :
|
||||
unsigned short nChCodes[0x306]; // 03A2 :
|
||||
unsigned short offs09AE; // 09AE :
|
||||
unsigned char nChBits[0x306]; // 009C :
|
||||
unsigned short nChCodes[0x306]; // 03A2 :
|
||||
unsigned short offs09AE; // 09AE :
|
||||
|
||||
void * param; // 09B0 : User parameter
|
||||
unsigned int (*read_buf)(char *buf, unsigned int *size, void *param); // 9B4
|
||||
void (*write_buf)(char *buf, unsigned int *size, void *param); // 9B8
|
||||
|
||||
unsigned short offs09BC[0x204]; // 09BC :
|
||||
unsigned long offs0DC4; // 0DC4 :
|
||||
unsigned long offs0DC4; // 0DC4 :
|
||||
unsigned short offs0DC8[0x900]; // 0DC8 :
|
||||
unsigned short offs1FC8; // 1FC8 :
|
||||
unsigned short offs1FC8; // 1FC8 :
|
||||
char out_buff[0x802]; // 1FCA : Output (compressed) data
|
||||
unsigned char work_buff[0x2204]; // 27CC : Work buffer
|
||||
// + DICT_OFFSET => Dictionary
|
||||
// + UNCMP_OFFSET => Uncompressed data
|
||||
unsigned short offs49D0[0x2000]; // 49D0 :
|
||||
unsigned short offs49D0[0x2000]; // 49D0 :
|
||||
} TCmpStruct;
|
||||
|
||||
#define CMP_BUFFER_SIZE sizeof(TCmpStruct) // Size of compression buffer
|
||||
@@ -91,15 +91,15 @@ typedef struct
|
||||
unsigned char in_buff[0x800]; // 2234 - Buffer for data to be decompressed
|
||||
unsigned char position1[0x100]; // 2A34 - Positions in buffers
|
||||
unsigned char position2[0x100]; // 2B34 - Positions in buffers
|
||||
unsigned char offs2C34[0x100]; // 2C34 - Buffer for
|
||||
unsigned char offs2D34[0x100]; // 2D34 - Buffer for
|
||||
unsigned char offs2E34[0x80]; // 2EB4 - Buffer for
|
||||
unsigned char offs2EB4[0x100]; // 2EB4 - Buffer for
|
||||
unsigned char ChBitsAsc[0x100]; // 2FB4 - Buffer for
|
||||
unsigned char offs2C34[0x100]; // 2C34 - Buffer for
|
||||
unsigned char offs2D34[0x100]; // 2D34 - Buffer for
|
||||
unsigned char offs2E34[0x80]; // 2EB4 - Buffer for
|
||||
unsigned char offs2EB4[0x100]; // 2EB4 - Buffer for
|
||||
unsigned char ChBitsAsc[0x100]; // 2FB4 - Buffer for
|
||||
unsigned char DistBits[0x40]; // 30B4 - Numbers of bytes to skip copied block length
|
||||
unsigned char LenBits[0x10]; // 30F4 - Numbers of bits for skip copied block length
|
||||
unsigned char ExLenBits[0x10]; // 3104 - Number of valid bits for copied block
|
||||
unsigned short LenBase[0x10]; // 3114 - Buffer for
|
||||
unsigned short LenBase[0x10]; // 3114 - Buffer for
|
||||
} TDcmpStruct;
|
||||
|
||||
#define EXP_BUFFER_SIZE sizeof(TDcmpStruct) // Size of decompress buffer
|
||||
|
||||
@@ -35,8 +35,8 @@ static long Table1503F120[] =
|
||||
{
|
||||
0xFFFFFFFF, 0x00000000, 0xFFFFFFFF, 0x00000004, 0xFFFFFFFF, 0x00000002, 0xFFFFFFFF, 0x00000006,
|
||||
0xFFFFFFFF, 0x00000001, 0xFFFFFFFF, 0x00000005, 0xFFFFFFFF, 0x00000003, 0xFFFFFFFF, 0x00000007,
|
||||
0xFFFFFFFF, 0x00000001, 0xFFFFFFFF, 0x00000005, 0xFFFFFFFF, 0x00000003, 0xFFFFFFFF, 0x00000007,
|
||||
0xFFFFFFFF, 0x00000002, 0xFFFFFFFF, 0x00000004, 0xFFFFFFFF, 0x00000006, 0xFFFFFFFF, 0x00000008
|
||||
0xFFFFFFFF, 0x00000001, 0xFFFFFFFF, 0x00000005, 0xFFFFFFFF, 0x00000003, 0xFFFFFFFF, 0x00000007,
|
||||
0xFFFFFFFF, 0x00000002, 0xFFFFFFFF, 0x00000004, 0xFFFFFFFF, 0x00000006, 0xFFFFFFFF, 0x00000008
|
||||
};
|
||||
|
||||
static long Table1503F1A0[] =
|
||||
@@ -112,10 +112,10 @@ int CompressWave(unsigned char * pbOutBuffer, int dwOutLength, short * pwInBuffe
|
||||
|
||||
nLength = (nLength / 2) - (int)(out.pb - pbOutBuffer);
|
||||
nLength = (nLength < 0) ? 0 : nLength;
|
||||
|
||||
|
||||
nIndex = nChannels - 1; // edi
|
||||
nWordsRemains = dwInLength / 2; // eax
|
||||
|
||||
|
||||
// ebx - nChannels
|
||||
// ecx - pwOutPos
|
||||
for(int chnl = nChannels; chnl < nWordsRemains; chnl++)
|
||||
@@ -184,7 +184,7 @@ int CompressWave(unsigned char * pbOutBuffer, int dwOutLength, short * pwInBuffe
|
||||
}
|
||||
if(dwBit == dwStopBit)
|
||||
break;
|
||||
|
||||
|
||||
nTableValue >>= 1;
|
||||
}
|
||||
|
||||
@@ -205,7 +205,7 @@ int CompressWave(unsigned char * pbOutBuffer, int dwOutLength, short * pwInBuffe
|
||||
SInt32Array2[nIndex] = nValue;
|
||||
*out.pb++ = (unsigned char)(dwBitBuff | ebx);
|
||||
nTableValue = Table1503F120[dwBitBuff & 0x1F];
|
||||
SInt32Array1[nIndex] = SInt32Array1[nIndex] + nTableValue;
|
||||
SInt32Array1[nIndex] = SInt32Array1[nIndex] + nTableValue;
|
||||
if(SInt32Array1[nIndex] < 0)
|
||||
SInt32Array1[nIndex] = 0;
|
||||
else if(SInt32Array1[nIndex] > 0x58)
|
||||
@@ -280,7 +280,7 @@ int DecompressWave(unsigned char * pbOutBuffer, int dwOutLength, unsigned char *
|
||||
SInt32Array1[nIndex] += 8;
|
||||
if(SInt32Array1[nIndex] > 0x58)
|
||||
SInt32Array1[nIndex] = 0x58;
|
||||
|
||||
|
||||
if(nChannels == 2)
|
||||
nIndex = (nIndex == 0) ? 1 : 0;
|
||||
break;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* adler32.c -- compute the Adler-32 checksum of a data stream
|
||||
* Copyright (C) 1995-2002 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* @(#) $Id$ */
|
||||
@@ -34,12 +34,12 @@ uLong ZEXPORT adler32(adler, buf, len)
|
||||
len -= k;
|
||||
while (k >= 16) {
|
||||
DO16(buf);
|
||||
buf += 16;
|
||||
buf += 16;
|
||||
k -= 16;
|
||||
}
|
||||
if (k != 0) do {
|
||||
s1 += *buf++;
|
||||
s2 += s1;
|
||||
s2 += s1;
|
||||
} while (--k);
|
||||
s1 %= BASE;
|
||||
s2 %= BASE;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* compress.c -- compress a memory buffer
|
||||
* Copyright (C) 1995-2002 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$ */
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
|
||||
/* if your C compiler don't add underline before function name,
|
||||
define ADD_UNDERLINE_ASMFUNC */
|
||||
define ADD_UNDERLINE_ASMFUNC */
|
||||
#ifdef ADD_UNDERLINE_ASMFUNC
|
||||
#define longest_match_7fff _longest_match_7fff
|
||||
#endif
|
||||
@@ -46,15 +46,15 @@ uInt longest_match(
|
||||
deflate_state *s,
|
||||
IPos cur_match) /* current match */
|
||||
{
|
||||
static uInt iIsPPro=2;
|
||||
static uInt iIsPPro=2;
|
||||
|
||||
if ((s->w_mask == 0x7fff) && (iIsPPro==0))
|
||||
return longest_match_7fff(s,cur_match);
|
||||
|
||||
if (iIsPPro==2)
|
||||
iIsPPro = (((cpudetect32()/0x100)&0xf)>=6) ? 1 : 0;
|
||||
if (iIsPPro==2)
|
||||
iIsPPro = (((cpudetect32()/0x100)&0xf)>=6) ? 1 : 0;
|
||||
|
||||
return longest_match_c(s,cur_match);
|
||||
return longest_match_c(s,cur_match);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ gzfilebuf::~gzfilebuf() {
|
||||
}
|
||||
|
||||
gzfilebuf *gzfilebuf::open( const char *name,
|
||||
int io_mode ) {
|
||||
int io_mode ) {
|
||||
|
||||
if ( is_open() )
|
||||
return NULL;
|
||||
@@ -58,7 +58,7 @@ gzfilebuf *gzfilebuf::open( const char *name,
|
||||
}
|
||||
|
||||
gzfilebuf *gzfilebuf::attach( int file_descriptor,
|
||||
int io_mode ) {
|
||||
int io_mode ) {
|
||||
|
||||
if ( is_open() )
|
||||
return NULL;
|
||||
@@ -151,7 +151,7 @@ int gzfilebuf::underflow() {
|
||||
|
||||
if ( out_waiting() ) {
|
||||
if ( flushbuf() == EOF )
|
||||
return EOF;
|
||||
return EOF;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -180,11 +180,11 @@ int gzfilebuf::overflow( int c ) {
|
||||
setg(0,0,0);
|
||||
} else {
|
||||
if (in_avail()) {
|
||||
return EOF;
|
||||
return EOF;
|
||||
}
|
||||
if (out_waiting()) {
|
||||
if (flushbuf() == EOF)
|
||||
return EOF;
|
||||
return EOF;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -287,7 +287,7 @@ gzfilebuf *gzfilestream_common::rdbuf() {
|
||||
return &buffer;
|
||||
|
||||
}
|
||||
|
||||
|
||||
gzifstream::gzifstream() :
|
||||
ios( gzfilestream_common::rdbuf() )
|
||||
{
|
||||
|
||||
@@ -99,9 +99,9 @@ private:
|
||||
};
|
||||
|
||||
template<class T> gzofstream &operator<<(gzofstream &s,
|
||||
const gzomanip<T> &m) {
|
||||
const gzomanip<T> &m) {
|
||||
return (*m.func)(s, m.val);
|
||||
|
||||
|
||||
}
|
||||
|
||||
inline gzofstream &setcompressionlevel( gzofstream &s, int l ) {
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
#include <iomanip.h>
|
||||
|
||||
void main() {
|
||||
char h[256] = "Hello";
|
||||
char* g = "Goodbye";
|
||||
ozstream out("temp.gz");
|
||||
char h[256] = "Hello";
|
||||
char* g = "Goodbye";
|
||||
ozstream out("temp.gz");
|
||||
out < "This works well" < h < g;
|
||||
out.close();
|
||||
|
||||
|
||||
@@ -34,9 +34,9 @@
|
||||
dosdate : the new date at the MSDos format (4 bytes)
|
||||
tmu_date : the SAME new date at the tm_unz format */
|
||||
void change_file_date(filename,dosdate,tmu_date)
|
||||
const char *filename;
|
||||
uLong dosdate;
|
||||
tm_unz tmu_date;
|
||||
const char *filename;
|
||||
uLong dosdate;
|
||||
tm_unz tmu_date;
|
||||
{
|
||||
#ifdef WIN32
|
||||
HANDLE hFile;
|
||||
@@ -75,17 +75,17 @@ void change_file_date(filename,dosdate,tmu_date)
|
||||
As I don't know well Unix, I wait feedback for the unix portion */
|
||||
|
||||
int mymkdir(dirname)
|
||||
const char* dirname;
|
||||
const char* dirname;
|
||||
{
|
||||
int ret=0;
|
||||
#ifdef WIN32
|
||||
ret = mkdir(dirname);
|
||||
ret = mkdir(dirname);
|
||||
#else
|
||||
#ifdef unix
|
||||
ret = mkdir (dirname,0775);
|
||||
ret = mkdir (dirname,0775);
|
||||
#endif
|
||||
#endif
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int makedir (newdir)
|
||||
@@ -93,14 +93,14 @@ int makedir (newdir)
|
||||
{
|
||||
char *buffer ;
|
||||
char *p;
|
||||
int len = strlen(newdir);
|
||||
int len = strlen(newdir);
|
||||
|
||||
if (len <= 0)
|
||||
if (len <= 0)
|
||||
return 0;
|
||||
|
||||
buffer = (char*)malloc(len+1);
|
||||
strcpy(buffer,newdir);
|
||||
|
||||
|
||||
if (buffer[len-1] == '/') {
|
||||
buffer[len-1] = '\0';
|
||||
}
|
||||
@@ -135,104 +135,104 @@ int makedir (newdir)
|
||||
|
||||
void do_banner()
|
||||
{
|
||||
printf("MiniUnz 0.15, demo of zLib + Unz package written by Gilles Vollant\n");
|
||||
printf("more info at http://wwww.winimage/zLibDll/unzip.htm\n\n");
|
||||
printf("MiniUnz 0.15, demo of zLib + Unz package written by Gilles Vollant\n");
|
||||
printf("more info at http://wwww.winimage/zLibDll/unzip.htm\n\n");
|
||||
}
|
||||
|
||||
void do_help()
|
||||
{
|
||||
printf("Usage : miniunz [-exvlo] file.zip [file_to_extract]\n\n") ;
|
||||
{
|
||||
printf("Usage : miniunz [-exvlo] file.zip [file_to_extract]\n\n") ;
|
||||
}
|
||||
|
||||
|
||||
int do_list(uf)
|
||||
unzFile uf;
|
||||
unzFile uf;
|
||||
{
|
||||
uLong i;
|
||||
unz_global_info gi;
|
||||
int err;
|
||||
uLong i;
|
||||
unz_global_info gi;
|
||||
int err;
|
||||
|
||||
err = unzGetGlobalInfo (uf,&gi);
|
||||
if (err!=UNZ_OK)
|
||||
printf("error %d with zipfile in unzGetGlobalInfo \n",err);
|
||||
err = unzGetGlobalInfo (uf,&gi);
|
||||
if (err!=UNZ_OK)
|
||||
printf("error %d with zipfile in unzGetGlobalInfo \n",err);
|
||||
printf(" Length Method Size Ratio Date Time CRC-32 Name\n");
|
||||
printf(" ------ ------ ---- ----- ---- ---- ------ ----\n");
|
||||
for (i=0;i<gi.number_entry;i++)
|
||||
{
|
||||
char filename_inzip[256];
|
||||
unz_file_info file_info;
|
||||
uLong ratio=0;
|
||||
const char *string_method;
|
||||
err = unzGetCurrentFileInfo(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0);
|
||||
if (err!=UNZ_OK)
|
||||
{
|
||||
printf("error %d with zipfile in unzGetCurrentFileInfo\n",err);
|
||||
break;
|
||||
}
|
||||
if (file_info.uncompressed_size>0)
|
||||
ratio = (file_info.compressed_size*100)/file_info.uncompressed_size;
|
||||
for (i=0;i<gi.number_entry;i++)
|
||||
{
|
||||
char filename_inzip[256];
|
||||
unz_file_info file_info;
|
||||
uLong ratio=0;
|
||||
const char *string_method;
|
||||
err = unzGetCurrentFileInfo(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0);
|
||||
if (err!=UNZ_OK)
|
||||
{
|
||||
printf("error %d with zipfile in unzGetCurrentFileInfo\n",err);
|
||||
break;
|
||||
}
|
||||
if (file_info.uncompressed_size>0)
|
||||
ratio = (file_info.compressed_size*100)/file_info.uncompressed_size;
|
||||
|
||||
if (file_info.compression_method==0)
|
||||
string_method="Stored";
|
||||
else
|
||||
if (file_info.compression_method==Z_DEFLATED)
|
||||
{
|
||||
uInt iLevel=(uInt)((file_info.flag & 0x6)/2);
|
||||
if (iLevel==0)
|
||||
string_method="Defl:N";
|
||||
else if (iLevel==1)
|
||||
string_method="Defl:X";
|
||||
else if ((iLevel==2) || (iLevel==3))
|
||||
string_method="Defl:F"; /* 2:fast , 3 : extra fast*/
|
||||
}
|
||||
else
|
||||
string_method="Unkn. ";
|
||||
if (file_info.compression_method==0)
|
||||
string_method="Stored";
|
||||
else
|
||||
if (file_info.compression_method==Z_DEFLATED)
|
||||
{
|
||||
uInt iLevel=(uInt)((file_info.flag & 0x6)/2);
|
||||
if (iLevel==0)
|
||||
string_method="Defl:N";
|
||||
else if (iLevel==1)
|
||||
string_method="Defl:X";
|
||||
else if ((iLevel==2) || (iLevel==3))
|
||||
string_method="Defl:F"; /* 2:fast , 3 : extra fast*/
|
||||
}
|
||||
else
|
||||
string_method="Unkn. ";
|
||||
|
||||
printf("%7lu %6s %7lu %3lu%% %2.2lu-%2.2lu-%2.2lu %2.2lu:%2.2lu %8.8lx %s\n",
|
||||
file_info.uncompressed_size,string_method,file_info.compressed_size,
|
||||
ratio,
|
||||
(uLong)file_info.tmu_date.tm_mon + 1,
|
||||
printf("%7lu %6s %7lu %3lu%% %2.2lu-%2.2lu-%2.2lu %2.2lu:%2.2lu %8.8lx %s\n",
|
||||
file_info.uncompressed_size,string_method,file_info.compressed_size,
|
||||
ratio,
|
||||
(uLong)file_info.tmu_date.tm_mon + 1,
|
||||
(uLong)file_info.tmu_date.tm_mday,
|
||||
(uLong)file_info.tmu_date.tm_year % 100,
|
||||
(uLong)file_info.tmu_date.tm_hour,(uLong)file_info.tmu_date.tm_min,
|
||||
(uLong)file_info.crc,filename_inzip);
|
||||
if ((i+1)<gi.number_entry)
|
||||
{
|
||||
err = unzGoToNextFile(uf);
|
||||
if (err!=UNZ_OK)
|
||||
{
|
||||
printf("error %d with zipfile in unzGoToNextFile\n",err);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
(uLong)file_info.tmu_date.tm_year % 100,
|
||||
(uLong)file_info.tmu_date.tm_hour,(uLong)file_info.tmu_date.tm_min,
|
||||
(uLong)file_info.crc,filename_inzip);
|
||||
if ((i+1)<gi.number_entry)
|
||||
{
|
||||
err = unzGoToNextFile(uf);
|
||||
if (err!=UNZ_OK)
|
||||
{
|
||||
printf("error %d with zipfile in unzGoToNextFile\n",err);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int do_extract_currentfile(uf,popt_extract_without_path,popt_overwrite)
|
||||
unzFile uf;
|
||||
const int* popt_extract_without_path;
|
||||
unzFile uf;
|
||||
const int* popt_extract_without_path;
|
||||
int* popt_overwrite;
|
||||
{
|
||||
char filename_inzip[256];
|
||||
char* filename_withoutpath;
|
||||
char* p;
|
||||
char filename_inzip[256];
|
||||
char* filename_withoutpath;
|
||||
char* p;
|
||||
int err=UNZ_OK;
|
||||
FILE *fout=NULL;
|
||||
void* buf;
|
||||
uInt size_buf;
|
||||
|
||||
unz_file_info file_info;
|
||||
uLong ratio=0;
|
||||
err = unzGetCurrentFileInfo(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0);
|
||||
|
||||
if (err!=UNZ_OK)
|
||||
{
|
||||
printf("error %d with zipfile in unzGetCurrentFileInfo\n",err);
|
||||
return err;
|
||||
}
|
||||
unz_file_info file_info;
|
||||
uLong ratio=0;
|
||||
err = unzGetCurrentFileInfo(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0);
|
||||
|
||||
if (err!=UNZ_OK)
|
||||
{
|
||||
printf("error %d with zipfile in unzGetCurrentFileInfo\n",err);
|
||||
return err;
|
||||
}
|
||||
|
||||
size_buf = WRITEBUFFERSIZE;
|
||||
buf = (void*)malloc(size_buf);
|
||||
@@ -242,71 +242,71 @@ int do_extract_currentfile(uf,popt_extract_without_path,popt_overwrite)
|
||||
return UNZ_INTERNALERROR;
|
||||
}
|
||||
|
||||
p = filename_withoutpath = filename_inzip;
|
||||
while ((*p) != '\0')
|
||||
{
|
||||
if (((*p)=='/') || ((*p)=='\\'))
|
||||
filename_withoutpath = p+1;
|
||||
p++;
|
||||
}
|
||||
p = filename_withoutpath = filename_inzip;
|
||||
while ((*p) != '\0')
|
||||
{
|
||||
if (((*p)=='/') || ((*p)=='\\'))
|
||||
filename_withoutpath = p+1;
|
||||
p++;
|
||||
}
|
||||
|
||||
if ((*filename_withoutpath)=='\0')
|
||||
{
|
||||
if ((*popt_extract_without_path)==0)
|
||||
{
|
||||
printf("creating directory: %s\n",filename_inzip);
|
||||
mymkdir(filename_inzip);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
const char* write_filename;
|
||||
int skip=0;
|
||||
if ((*filename_withoutpath)=='\0')
|
||||
{
|
||||
if ((*popt_extract_without_path)==0)
|
||||
{
|
||||
printf("creating directory: %s\n",filename_inzip);
|
||||
mymkdir(filename_inzip);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
const char* write_filename;
|
||||
int skip=0;
|
||||
|
||||
if ((*popt_extract_without_path)==0)
|
||||
write_filename = filename_inzip;
|
||||
else
|
||||
write_filename = filename_withoutpath;
|
||||
if ((*popt_extract_without_path)==0)
|
||||
write_filename = filename_inzip;
|
||||
else
|
||||
write_filename = filename_withoutpath;
|
||||
|
||||
err = unzOpenCurrentFile(uf);
|
||||
if (err!=UNZ_OK)
|
||||
{
|
||||
printf("error %d with zipfile in unzOpenCurrentFile\n",err);
|
||||
}
|
||||
err = unzOpenCurrentFile(uf);
|
||||
if (err!=UNZ_OK)
|
||||
{
|
||||
printf("error %d with zipfile in unzOpenCurrentFile\n",err);
|
||||
}
|
||||
|
||||
if (((*popt_overwrite)==0) && (err==UNZ_OK))
|
||||
{
|
||||
char rep;
|
||||
FILE* ftestexist;
|
||||
ftestexist = fopen(write_filename,"rb");
|
||||
if (ftestexist!=NULL)
|
||||
{
|
||||
fclose(ftestexist);
|
||||
do
|
||||
{
|
||||
char answer[128];
|
||||
printf("The file %s exist. Overwrite ? [y]es, [n]o, [A]ll: ",write_filename);
|
||||
scanf("%1s",answer);
|
||||
rep = answer[0] ;
|
||||
if ((rep>='a') && (rep<='z'))
|
||||
rep -= 0x20;
|
||||
}
|
||||
while ((rep!='Y') && (rep!='N') && (rep!='A'));
|
||||
}
|
||||
if (((*popt_overwrite)==0) && (err==UNZ_OK))
|
||||
{
|
||||
char rep;
|
||||
FILE* ftestexist;
|
||||
ftestexist = fopen(write_filename,"rb");
|
||||
if (ftestexist!=NULL)
|
||||
{
|
||||
fclose(ftestexist);
|
||||
do
|
||||
{
|
||||
char answer[128];
|
||||
printf("The file %s exist. Overwrite ? [y]es, [n]o, [A]ll: ",write_filename);
|
||||
scanf("%1s",answer);
|
||||
rep = answer[0] ;
|
||||
if ((rep>='a') && (rep<='z'))
|
||||
rep -= 0x20;
|
||||
}
|
||||
while ((rep!='Y') && (rep!='N') && (rep!='A'));
|
||||
}
|
||||
|
||||
if (rep == 'N')
|
||||
skip = 1;
|
||||
if (rep == 'N')
|
||||
skip = 1;
|
||||
|
||||
if (rep == 'A')
|
||||
*popt_overwrite=1;
|
||||
}
|
||||
if (rep == 'A')
|
||||
*popt_overwrite=1;
|
||||
}
|
||||
|
||||
if ((skip==0) && (err==UNZ_OK))
|
||||
{
|
||||
fout=fopen(write_filename,"wb");
|
||||
if ((skip==0) && (err==UNZ_OK))
|
||||
{
|
||||
fout=fopen(write_filename,"wb");
|
||||
|
||||
/* some zipfile don't contain directory alone before file */
|
||||
if ((fout==NULL) && ((*popt_extract_without_path)==0) &&
|
||||
if ((fout==NULL) && ((*popt_extract_without_path)==0) &&
|
||||
(filename_withoutpath!=(char*)filename_inzip))
|
||||
{
|
||||
char c=*(filename_withoutpath-1);
|
||||
@@ -316,94 +316,94 @@ int do_extract_currentfile(uf,popt_extract_without_path,popt_overwrite)
|
||||
fout=fopen(write_filename,"wb");
|
||||
}
|
||||
|
||||
if (fout==NULL)
|
||||
{
|
||||
printf("error opening %s\n",write_filename);
|
||||
}
|
||||
}
|
||||
if (fout==NULL)
|
||||
{
|
||||
printf("error opening %s\n",write_filename);
|
||||
}
|
||||
}
|
||||
|
||||
if (fout!=NULL)
|
||||
{
|
||||
printf(" extracting: %s\n",write_filename);
|
||||
if (fout!=NULL)
|
||||
{
|
||||
printf(" extracting: %s\n",write_filename);
|
||||
|
||||
do
|
||||
{
|
||||
err = unzReadCurrentFile(uf,buf,size_buf);
|
||||
if (err<0)
|
||||
{
|
||||
printf("error %d with zipfile in unzReadCurrentFile\n",err);
|
||||
break;
|
||||
}
|
||||
if (err>0)
|
||||
if (fwrite(buf,err,1,fout)!=1)
|
||||
{
|
||||
printf("error in writing extracted file\n");
|
||||
do
|
||||
{
|
||||
err = unzReadCurrentFile(uf,buf,size_buf);
|
||||
if (err<0)
|
||||
{
|
||||
printf("error %d with zipfile in unzReadCurrentFile\n",err);
|
||||
break;
|
||||
}
|
||||
if (err>0)
|
||||
if (fwrite(buf,err,1,fout)!=1)
|
||||
{
|
||||
printf("error in writing extracted file\n");
|
||||
err=UNZ_ERRNO;
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (err>0);
|
||||
fclose(fout);
|
||||
if (err==0)
|
||||
change_file_date(write_filename,file_info.dosDate,
|
||||
file_info.tmu_date);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (err>0);
|
||||
fclose(fout);
|
||||
if (err==0)
|
||||
change_file_date(write_filename,file_info.dosDate,
|
||||
file_info.tmu_date);
|
||||
}
|
||||
|
||||
if (err==UNZ_OK)
|
||||
{
|
||||
err = unzCloseCurrentFile (uf);
|
||||
if (err!=UNZ_OK)
|
||||
{
|
||||
printf("error %d with zipfile in unzCloseCurrentFile\n",err);
|
||||
}
|
||||
err = unzCloseCurrentFile (uf);
|
||||
if (err!=UNZ_OK)
|
||||
{
|
||||
printf("error %d with zipfile in unzCloseCurrentFile\n",err);
|
||||
}
|
||||
}
|
||||
else
|
||||
unzCloseCurrentFile(uf); /* don't lose the error */
|
||||
}
|
||||
unzCloseCurrentFile(uf); /* don't lose the error */
|
||||
}
|
||||
|
||||
free(buf);
|
||||
free(buf);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
int do_extract(uf,opt_extract_without_path,opt_overwrite)
|
||||
unzFile uf;
|
||||
int opt_extract_without_path;
|
||||
unzFile uf;
|
||||
int opt_extract_without_path;
|
||||
int opt_overwrite;
|
||||
{
|
||||
uLong i;
|
||||
unz_global_info gi;
|
||||
int err;
|
||||
FILE* fout=NULL;
|
||||
uLong i;
|
||||
unz_global_info gi;
|
||||
int err;
|
||||
FILE* fout=NULL;
|
||||
|
||||
err = unzGetGlobalInfo (uf,&gi);
|
||||
if (err!=UNZ_OK)
|
||||
printf("error %d with zipfile in unzGetGlobalInfo \n",err);
|
||||
err = unzGetGlobalInfo (uf,&gi);
|
||||
if (err!=UNZ_OK)
|
||||
printf("error %d with zipfile in unzGetGlobalInfo \n",err);
|
||||
|
||||
for (i=0;i<gi.number_entry;i++)
|
||||
{
|
||||
for (i=0;i<gi.number_entry;i++)
|
||||
{
|
||||
if (do_extract_currentfile(uf,&opt_extract_without_path,
|
||||
&opt_overwrite) != UNZ_OK)
|
||||
break;
|
||||
|
||||
if ((i+1)<gi.number_entry)
|
||||
{
|
||||
err = unzGoToNextFile(uf);
|
||||
if (err!=UNZ_OK)
|
||||
{
|
||||
printf("error %d with zipfile in unzGoToNextFile\n",err);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((i+1)<gi.number_entry)
|
||||
{
|
||||
err = unzGoToNextFile(uf);
|
||||
if (err!=UNZ_OK)
|
||||
{
|
||||
printf("error %d with zipfile in unzGoToNextFile\n",err);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int do_extract_onefile(uf,filename,opt_extract_without_path,opt_overwrite)
|
||||
unzFile uf;
|
||||
const char* filename;
|
||||
int opt_extract_without_path;
|
||||
unzFile uf;
|
||||
const char* filename;
|
||||
int opt_extract_without_path;
|
||||
int opt_overwrite;
|
||||
{
|
||||
int err = UNZ_OK;
|
||||
@@ -422,87 +422,87 @@ int do_extract_onefile(uf,filename,opt_extract_without_path,opt_overwrite)
|
||||
|
||||
|
||||
int main(argc,argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
const char *zipfilename=NULL;
|
||||
const char *zipfilename=NULL;
|
||||
const char *filename_to_extract=NULL;
|
||||
int i;
|
||||
int opt_do_list=0;
|
||||
int opt_do_extract=1;
|
||||
int opt_do_extract_withoutpath=0;
|
||||
int opt_overwrite=0;
|
||||
char filename_try[512];
|
||||
unzFile uf=NULL;
|
||||
int i;
|
||||
int opt_do_list=0;
|
||||
int opt_do_extract=1;
|
||||
int opt_do_extract_withoutpath=0;
|
||||
int opt_overwrite=0;
|
||||
char filename_try[512];
|
||||
unzFile uf=NULL;
|
||||
|
||||
do_banner();
|
||||
if (argc==1)
|
||||
{
|
||||
do_help();
|
||||
exit(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i=1;i<argc;i++)
|
||||
{
|
||||
if ((*argv[i])=='-')
|
||||
{
|
||||
const char *p=argv[i]+1;
|
||||
|
||||
while ((*p)!='\0')
|
||||
{
|
||||
char c=*(p++);;
|
||||
if ((c=='l') || (c=='L'))
|
||||
opt_do_list = 1;
|
||||
if ((c=='v') || (c=='V'))
|
||||
opt_do_list = 1;
|
||||
if ((c=='x') || (c=='X'))
|
||||
opt_do_extract = 1;
|
||||
if ((c=='e') || (c=='E'))
|
||||
opt_do_extract = opt_do_extract_withoutpath = 1;
|
||||
if ((c=='o') || (c=='O'))
|
||||
opt_overwrite=1;
|
||||
}
|
||||
}
|
||||
else
|
||||
do_banner();
|
||||
if (argc==1)
|
||||
{
|
||||
do_help();
|
||||
exit(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i=1;i<argc;i++)
|
||||
{
|
||||
if ((*argv[i])=='-')
|
||||
{
|
||||
if (zipfilename == NULL)
|
||||
zipfilename = argv[i];
|
||||
const char *p=argv[i]+1;
|
||||
|
||||
while ((*p)!='\0')
|
||||
{
|
||||
char c=*(p++);;
|
||||
if ((c=='l') || (c=='L'))
|
||||
opt_do_list = 1;
|
||||
if ((c=='v') || (c=='V'))
|
||||
opt_do_list = 1;
|
||||
if ((c=='x') || (c=='X'))
|
||||
opt_do_extract = 1;
|
||||
if ((c=='e') || (c=='E'))
|
||||
opt_do_extract = opt_do_extract_withoutpath = 1;
|
||||
if ((c=='o') || (c=='O'))
|
||||
opt_overwrite=1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (zipfilename == NULL)
|
||||
zipfilename = argv[i];
|
||||
else if (filename_to_extract==NULL)
|
||||
filename_to_extract = argv[i] ;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (zipfilename!=NULL)
|
||||
{
|
||||
strcpy(filename_try,zipfilename);
|
||||
uf = unzOpen(zipfilename);
|
||||
if (uf==NULL)
|
||||
{
|
||||
strcat(filename_try,".zip");
|
||||
uf = unzOpen(filename_try);
|
||||
}
|
||||
}
|
||||
if (zipfilename!=NULL)
|
||||
{
|
||||
strcpy(filename_try,zipfilename);
|
||||
uf = unzOpen(zipfilename);
|
||||
if (uf==NULL)
|
||||
{
|
||||
strcat(filename_try,".zip");
|
||||
uf = unzOpen(filename_try);
|
||||
}
|
||||
}
|
||||
|
||||
if (uf==NULL)
|
||||
{
|
||||
printf("Cannot open %s or %s.zip\n",zipfilename,zipfilename);
|
||||
exit (1);
|
||||
}
|
||||
if (uf==NULL)
|
||||
{
|
||||
printf("Cannot open %s or %s.zip\n",zipfilename,zipfilename);
|
||||
exit (1);
|
||||
}
|
||||
printf("%s opened\n",filename_try);
|
||||
|
||||
if (opt_do_list==1)
|
||||
return do_list(uf);
|
||||
else if (opt_do_extract==1)
|
||||
if (opt_do_list==1)
|
||||
return do_list(uf);
|
||||
else if (opt_do_extract==1)
|
||||
{
|
||||
if (filename_to_extract == NULL)
|
||||
return do_extract(uf,opt_do_extract_withoutpath,opt_overwrite);
|
||||
return do_extract(uf,opt_do_extract_withoutpath,opt_overwrite);
|
||||
else
|
||||
return do_extract_onefile(uf,filename_to_extract,
|
||||
opt_do_extract_withoutpath,opt_overwrite);
|
||||
}
|
||||
unzCloseCurrentFile(uf);
|
||||
unzCloseCurrentFile(uf);
|
||||
|
||||
return 0; /* to avoid warning */
|
||||
return 0; /* to avoid warning */
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ uLong filetime(f, tmzip, dt)
|
||||
struct stat s; /* results of stat() */
|
||||
struct tm* filedate;
|
||||
time_t tm_t=0;
|
||||
|
||||
|
||||
if (strcmp(f,"-")!=0)
|
||||
{
|
||||
char name[MAXFILENAME];
|
||||
@@ -98,10 +98,10 @@ uLong filetime(f, tmzip, dt)
|
||||
int check_exist_file(filename)
|
||||
const char* filename;
|
||||
{
|
||||
FILE* ftestexist;
|
||||
FILE* ftestexist;
|
||||
int ret = 1;
|
||||
ftestexist = fopen(filename,"rb");
|
||||
if (ftestexist==NULL)
|
||||
ftestexist = fopen(filename,"rb");
|
||||
if (ftestexist==NULL)
|
||||
ret = 0;
|
||||
else
|
||||
fclose(ftestexist);
|
||||
@@ -110,59 +110,59 @@ int check_exist_file(filename)
|
||||
|
||||
void do_banner()
|
||||
{
|
||||
printf("MiniZip 0.15, demo of zLib + Zip package written by Gilles Vollant\n");
|
||||
printf("more info at http://wwww.winimage/zLibDll/unzip.htm\n\n");
|
||||
printf("MiniZip 0.15, demo of zLib + Zip package written by Gilles Vollant\n");
|
||||
printf("more info at http://wwww.winimage/zLibDll/unzip.htm\n\n");
|
||||
}
|
||||
|
||||
void do_help()
|
||||
{
|
||||
printf("Usage : minizip [-o] file.zip [files_to_add]\n\n") ;
|
||||
{
|
||||
printf("Usage : minizip [-o] file.zip [files_to_add]\n\n") ;
|
||||
}
|
||||
|
||||
int main(argc,argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
int i;
|
||||
int opt_overwrite=0;
|
||||
int i;
|
||||
int opt_overwrite=0;
|
||||
int opt_compress_level=Z_DEFAULT_COMPRESSION;
|
||||
int zipfilenamearg = 0;
|
||||
char filename_try[MAXFILENAME];
|
||||
char filename_try[MAXFILENAME];
|
||||
int zipok;
|
||||
int err=0;
|
||||
int size_buf=0;
|
||||
void* buf=NULL,
|
||||
|
||||
|
||||
do_banner();
|
||||
if (argc==1)
|
||||
{
|
||||
do_help();
|
||||
exit(0);
|
||||
do_banner();
|
||||
if (argc==1)
|
||||
{
|
||||
do_help();
|
||||
exit(0);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i=1;i<argc;i++)
|
||||
{
|
||||
if ((*argv[i])=='-')
|
||||
{
|
||||
const char *p=argv[i]+1;
|
||||
|
||||
while ((*p)!='\0')
|
||||
{
|
||||
char c=*(p++);;
|
||||
if ((c=='o') || (c=='O'))
|
||||
opt_overwrite = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i=1;i<argc;i++)
|
||||
{
|
||||
if ((*argv[i])=='-')
|
||||
{
|
||||
const char *p=argv[i]+1;
|
||||
|
||||
while ((*p)!='\0')
|
||||
{
|
||||
char c=*(p++);;
|
||||
if ((c=='o') || (c=='O'))
|
||||
opt_overwrite = 1;
|
||||
if ((c>='0') && (c<='9'))
|
||||
opt_compress_level = c-'0';
|
||||
}
|
||||
}
|
||||
else
|
||||
if (zipfilenamearg == 0)
|
||||
}
|
||||
}
|
||||
else
|
||||
if (zipfilenamearg == 0)
|
||||
zipfilenamearg = i ;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
size_buf = WRITEBUFFERSIZE;
|
||||
buf = (void*)malloc(size_buf);
|
||||
@@ -172,15 +172,15 @@ int main(argc,argv)
|
||||
return ZIP_INTERNALERROR;
|
||||
}
|
||||
|
||||
if (zipfilenamearg==0)
|
||||
if (zipfilenamearg==0)
|
||||
zipok=0;
|
||||
else
|
||||
{
|
||||
{
|
||||
int i,len;
|
||||
int dot_found=0;
|
||||
|
||||
zipok = 1 ;
|
||||
strcpy(filename_try,argv[zipfilenamearg]);
|
||||
strcpy(filename_try,argv[zipfilenamearg]);
|
||||
len=strlen(filename_try);
|
||||
for (i=0;i<len;i++)
|
||||
if (filename_try[i]=='.')
|
||||
@@ -191,21 +191,21 @@ int main(argc,argv)
|
||||
|
||||
if (opt_overwrite==0)
|
||||
if (check_exist_file(filename_try)!=0)
|
||||
{
|
||||
{
|
||||
char rep;
|
||||
do
|
||||
{
|
||||
char answer[128];
|
||||
printf("The file %s exist. Overwrite ? [y]es, [n]o : ",filename_try);
|
||||
scanf("%1s",answer);
|
||||
rep = answer[0] ;
|
||||
if ((rep>='a') && (rep<='z'))
|
||||
rep -= 0x20;
|
||||
}
|
||||
while ((rep!='Y') && (rep!='N'));
|
||||
do
|
||||
{
|
||||
char answer[128];
|
||||
printf("The file %s exist. Overwrite ? [y]es, [n]o : ",filename_try);
|
||||
scanf("%1s",answer);
|
||||
rep = answer[0] ;
|
||||
if ((rep>='a') && (rep<='z'))
|
||||
rep -= 0x20;
|
||||
}
|
||||
while ((rep!='Y') && (rep!='N'));
|
||||
if (rep=='N')
|
||||
zipok = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (zipok==1)
|
||||
@@ -218,7 +218,7 @@ int main(argc,argv)
|
||||
printf("error opening %s\n",filename_try);
|
||||
err= ZIP_ERRNO;
|
||||
}
|
||||
else
|
||||
else
|
||||
printf("creating %s\n",filename_try);
|
||||
|
||||
for (i=zipfilenamearg+1;(i<argc) && (err==ZIP_OK);i++)
|
||||
@@ -230,7 +230,7 @@ int main(argc,argv)
|
||||
const char* filenameinzip = argv[i];
|
||||
zip_fileinfo zi;
|
||||
|
||||
zi.tmz_date.tm_sec = zi.tmz_date.tm_min = zi.tmz_date.tm_hour =
|
||||
zi.tmz_date.tm_sec = zi.tmz_date.tm_min = zi.tmz_date.tm_hour =
|
||||
zi.tmz_date.tm_mday = zi.tmz_date.tm_min = zi.tmz_date.tm_year = 0;
|
||||
zi.dosDate = 0;
|
||||
zi.internal_fa = 0;
|
||||
@@ -275,7 +275,7 @@ int main(argc,argv)
|
||||
printf("error in writing %s in the zipfile\n",
|
||||
filenameinzip);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
} while ((err == ZIP_OK) && (size_read>0));
|
||||
|
||||
@@ -283,7 +283,7 @@ int main(argc,argv)
|
||||
if (err<0)
|
||||
err=ZIP_ERRNO;
|
||||
else
|
||||
{
|
||||
{
|
||||
err = zipCloseFileInZip(zf);
|
||||
if (err!=ZIP_OK)
|
||||
printf("error in closing %s in the zipfile\n",
|
||||
@@ -298,5 +298,5 @@ int main(argc,argv)
|
||||
|
||||
free(buf);
|
||||
exit(0);
|
||||
return 0; /* to avoid warning */
|
||||
return 0; /* to avoid warning */
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,4 @@
|
||||
/* unzip.h -- IO for uncompress .zip files using zlib
|
||||
/* unzip.h -- IO for uncompress .zip files using zlib
|
||||
Version 0.15 beta, Mar 19th, 1998,
|
||||
|
||||
Copyright (C) 1998 Gilles Vollant
|
||||
@@ -33,7 +33,7 @@
|
||||
|
||||
|
||||
*/
|
||||
/* for more info about .ZIP format, see
|
||||
/* for more info about .ZIP format, see
|
||||
ftp://ftp.cdrom.com/pub/infozip/doc/appnote-970311-iz.zip
|
||||
PkWare has also a specification at :
|
||||
ftp://ftp.pkware.com/probdesc.zip */
|
||||
@@ -52,7 +52,7 @@ extern "C" {
|
||||
#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
|
||||
/* like the STRICT of WIN32, we define a pointer that cannot be converted
|
||||
from (void*) without cast */
|
||||
typedef struct TagunzFile__ { int unused; } unzFile__;
|
||||
typedef struct TagunzFile__ { int unused; } unzFile__;
|
||||
typedef unzFile__ *unzFile;
|
||||
#else
|
||||
typedef voidp unzFile;
|
||||
@@ -69,23 +69,23 @@ typedef voidp unzFile;
|
||||
#define UNZ_CRCERROR (-105)
|
||||
|
||||
/* tm_unz contain date/time info */
|
||||
typedef struct tm_unz_s
|
||||
typedef struct tm_unz_s
|
||||
{
|
||||
uInt tm_sec; /* seconds after the minute - [0,59] */
|
||||
uInt tm_min; /* minutes after the hour - [0,59] */
|
||||
uInt tm_hour; /* hours since midnight - [0,23] */
|
||||
uInt tm_mday; /* day of the month - [1,31] */
|
||||
uInt tm_mon; /* months since January - [0,11] */
|
||||
uInt tm_year; /* years - [1980..2044] */
|
||||
uInt tm_sec; /* seconds after the minute - [0,59] */
|
||||
uInt tm_min; /* minutes after the hour - [0,59] */
|
||||
uInt tm_hour; /* hours since midnight - [0,23] */
|
||||
uInt tm_mday; /* day of the month - [1,31] */
|
||||
uInt tm_mon; /* months since January - [0,11] */
|
||||
uInt tm_year; /* years - [1980..2044] */
|
||||
} tm_unz;
|
||||
|
||||
/* unz_global_info structure contain global data about the ZIPfile
|
||||
These data comes from the end of central dir */
|
||||
typedef struct unz_global_info_s
|
||||
{
|
||||
uLong number_entry; /* total number of entries in
|
||||
the central dir on this disk */
|
||||
uLong size_comment; /* size of the global comment of the zipfile */
|
||||
uLong number_entry; /* total number of entries in
|
||||
the central dir on this disk */
|
||||
uLong size_comment; /* size of the global comment of the zipfile */
|
||||
} unz_global_info;
|
||||
|
||||
|
||||
@@ -98,8 +98,8 @@ typedef struct unz_file_info_s
|
||||
uLong compression_method; /* compression method 2 bytes */
|
||||
uLong dosDate; /* last mod file date in Dos fmt 4 bytes */
|
||||
uLong crc; /* crc-32 4 bytes */
|
||||
uLong compressed_size; /* compressed size 4 bytes */
|
||||
uLong uncompressed_size; /* uncompressed size 4 bytes */
|
||||
uLong compressed_size; /* compressed size 4 bytes */
|
||||
uLong uncompressed_size; /* uncompressed size 4 bytes */
|
||||
uLong size_filename; /* filename length 2 bytes */
|
||||
uLong size_file_extra; /* extra field length 2 bytes */
|
||||
uLong size_file_comment; /* file comment length 2 bytes */
|
||||
@@ -112,15 +112,15 @@ typedef struct unz_file_info_s
|
||||
} unz_file_info;
|
||||
|
||||
extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1,
|
||||
const char* fileName2,
|
||||
int iCaseSensitivity));
|
||||
const char* fileName2,
|
||||
int iCaseSensitivity));
|
||||
/*
|
||||
Compare two filename (fileName1,fileName2).
|
||||
If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
|
||||
If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
|
||||
or strcasecmp)
|
||||
or strcasecmp)
|
||||
If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
|
||||
(like 1 on Unix, 2 on Windows)
|
||||
(like 1 on Unix, 2 on Windows)
|
||||
*/
|
||||
|
||||
|
||||
@@ -128,11 +128,11 @@ extern unzFile ZEXPORT unzOpen OF((const char *path));
|
||||
/*
|
||||
Open a Zip file. path contain the full pathname (by example,
|
||||
on a Windows NT computer "c:\\zlib\\zlib111.zip" or on an Unix computer
|
||||
"zlib/zlib111.zip".
|
||||
If the zipfile cannot be opened (file don't exist or in not valid), the
|
||||
return value is NULL.
|
||||
"zlib/zlib111.zip".
|
||||
If the zipfile cannot be opened (file don't exist or in not valid), the
|
||||
return value is NULL.
|
||||
Else, the return value is a unzFile Handle, usable with other function
|
||||
of this unzip package.
|
||||
of this unzip package.
|
||||
*/
|
||||
|
||||
extern int ZEXPORT unzClose OF((unzFile file));
|
||||
@@ -143,7 +143,7 @@ extern int ZEXPORT unzClose OF((unzFile file));
|
||||
return UNZ_OK if there is no problem. */
|
||||
|
||||
extern int ZEXPORT unzGetGlobalInfo OF((unzFile file,
|
||||
unz_global_info *pglobal_info));
|
||||
unz_global_info *pglobal_info));
|
||||
/*
|
||||
Write info about the ZipFile in the *pglobal_info structure.
|
||||
No preparation of the structure is needed
|
||||
@@ -151,8 +151,8 @@ extern int ZEXPORT unzGetGlobalInfo OF((unzFile file,
|
||||
|
||||
|
||||
extern int ZEXPORT unzGetGlobalComment OF((unzFile file,
|
||||
char *szComment,
|
||||
uLong uSizeBuf));
|
||||
char *szComment,
|
||||
uLong uSizeBuf));
|
||||
/*
|
||||
Get the global comment string of the ZipFile, in the szComment buffer.
|
||||
uSizeBuf is the size of the szComment buffer.
|
||||
@@ -176,9 +176,9 @@ extern int ZEXPORT unzGoToNextFile OF((unzFile file));
|
||||
return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
|
||||
*/
|
||||
|
||||
extern int ZEXPORT unzLocateFile OF((unzFile file,
|
||||
const char *szFileName,
|
||||
int iCaseSensitivity));
|
||||
extern int ZEXPORT unzLocateFile OF((unzFile file,
|
||||
const char *szFileName,
|
||||
int iCaseSensitivity));
|
||||
/*
|
||||
Try locate the file szFileName in the zipfile.
|
||||
For the iCaseSensitivity signification, see unzStringFileNameCompare
|
||||
@@ -190,24 +190,24 @@ extern int ZEXPORT unzLocateFile OF((unzFile file,
|
||||
|
||||
|
||||
extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file,
|
||||
unz_file_info *pfile_info,
|
||||
char *szFileName,
|
||||
uLong fileNameBufferSize,
|
||||
void *extraField,
|
||||
uLong extraFieldBufferSize,
|
||||
char *szComment,
|
||||
uLong commentBufferSize));
|
||||
unz_file_info *pfile_info,
|
||||
char *szFileName,
|
||||
uLong fileNameBufferSize,
|
||||
void *extraField,
|
||||
uLong extraFieldBufferSize,
|
||||
char *szComment,
|
||||
uLong commentBufferSize));
|
||||
/*
|
||||
Get Info about the current file
|
||||
if pfile_info!=NULL, the *pfile_info structure will contain somes info about
|
||||
the current file
|
||||
the current file
|
||||
if szFileName!=NULL, the filemane string will be copied in szFileName
|
||||
(fileNameBufferSize is the size of the buffer)
|
||||
(fileNameBufferSize is the size of the buffer)
|
||||
if extraField!=NULL, the extra field information will be copied in extraField
|
||||
(extraFieldBufferSize is the size of the buffer).
|
||||
This is the Central-header version of the extra field
|
||||
(extraFieldBufferSize is the size of the buffer).
|
||||
This is the Central-header version of the extra field
|
||||
if szComment!=NULL, the comment string of the file will be copied in szComment
|
||||
(commentBufferSize is the size of the buffer)
|
||||
(commentBufferSize is the size of the buffer)
|
||||
*/
|
||||
|
||||
/***************************************************************************/
|
||||
@@ -227,10 +227,10 @@ extern int ZEXPORT unzCloseCurrentFile OF((unzFile file));
|
||||
Return UNZ_CRCERROR if all the file was read but the CRC is not good
|
||||
*/
|
||||
|
||||
|
||||
extern int ZEXPORT unzReadCurrentFile OF((unzFile file,
|
||||
voidp buf,
|
||||
unsigned len));
|
||||
|
||||
extern int ZEXPORT unzReadCurrentFile OF((unzFile file,
|
||||
voidp buf,
|
||||
unsigned len));
|
||||
/*
|
||||
Read bytes from the current file (opened by unzOpenCurrentFile)
|
||||
buf contain buffer where data must be copied
|
||||
@@ -249,12 +249,12 @@ extern z_off_t ZEXPORT unztell OF((unzFile file));
|
||||
|
||||
extern int ZEXPORT unzeof OF((unzFile file));
|
||||
/*
|
||||
return 1 if the end of file was reached, 0 elsewhere
|
||||
return 1 if the end of file was reached, 0 elsewhere
|
||||
*/
|
||||
|
||||
extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file,
|
||||
voidp buf,
|
||||
unsigned len));
|
||||
voidp buf,
|
||||
unsigned len));
|
||||
/*
|
||||
Read extra field from the current file (opened by unzOpenCurrentFile)
|
||||
This is the local-header version of the extra field (sometimes, there is
|
||||
@@ -263,9 +263,9 @@ extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file,
|
||||
if buf==NULL, it return the size of the local extra field
|
||||
|
||||
if buf!=NULL, len is the size of the buffer, the extra header is copied in
|
||||
buf.
|
||||
the return value is the number of bytes copied in buf, or (if <0)
|
||||
the error code
|
||||
buf.
|
||||
the return value is the number of bytes copied in buf, or (if <0)
|
||||
the error code
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* zip.c -- IO on .zip files using zlib
|
||||
/* zip.c -- IO on .zip files using zlib
|
||||
Version 0.15 beta, Mar 19th, 1998,
|
||||
|
||||
Read zip.h for more info
|
||||
@@ -99,11 +99,11 @@ typedef struct linkedlist_data_s
|
||||
|
||||
typedef struct
|
||||
{
|
||||
z_stream stream; /* zLib stream structure for inflate */
|
||||
z_stream stream; /* zLib stream structure for inflate */
|
||||
int stream_initialised; /* 1 is stream is initialised */
|
||||
uInt pos_in_buffered_data; /* last written byte in buffered_data */
|
||||
|
||||
uLong pos_local_header; /* offset of the local header of the file
|
||||
uLong pos_local_header; /* offset of the local header of the file
|
||||
currenty writing */
|
||||
char* central_header; /* central header data for the current file */
|
||||
uLong size_centralheader; /* size of the central header for cur file */
|
||||
@@ -166,7 +166,7 @@ local void free_linkedlist(ll)
|
||||
|
||||
|
||||
local int add_data_in_datablock(ll,buf,len)
|
||||
linkedlist_data* ll;
|
||||
linkedlist_data* ll;
|
||||
const void* buf;
|
||||
uLong len;
|
||||
{
|
||||
@@ -222,7 +222,7 @@ local int add_data_in_datablock(ll,buf,len)
|
||||
|
||||
local int write_datablock(fout,ll)
|
||||
FILE * fout;
|
||||
linkedlist_data* ll;
|
||||
linkedlist_data* ll;
|
||||
{
|
||||
linkedlist_datablock_internal* ldi;
|
||||
ldi = ll->first_block;
|
||||
@@ -322,7 +322,7 @@ extern zipFile ZEXPORT zipOpen (pathname, append)
|
||||
return (zipFile)zi;
|
||||
}
|
||||
|
||||
extern int ZEXPORT zipOpenNewFileInZip (file, filename, zipfi,
|
||||
extern int ZEXPORT zipOpenNewFileInZip (file, filename, zipfi,
|
||||
extrafield_local, size_extrafield_local,
|
||||
extrafield_global, size_extrafield_global,
|
||||
comment, method, level)
|
||||
@@ -390,7 +390,7 @@ extern int ZEXPORT zipOpenNewFileInZip (file, filename, zipfi,
|
||||
zi->ci.stream_initialised = 0;
|
||||
zi->ci.pos_in_buffered_data = 0;
|
||||
zi->ci.pos_local_header = ftell(zi->filezip);
|
||||
zi->ci.size_centralheader = SIZECENTRALHEADER + size_filename +
|
||||
zi->ci.size_centralheader = SIZECENTRALHEADER + size_filename +
|
||||
size_extrafield_global + size_comment;
|
||||
zi->ci.central_header = (char*)ALLOC((uInt)zi->ci.size_centralheader);
|
||||
|
||||
@@ -410,12 +410,12 @@ extern int ZEXPORT zipOpenNewFileInZip (file, filename, zipfi,
|
||||
ziplocal_putValue_inmemory(zi->ci.central_header+34,(uLong)0,2); /*disk nm start*/
|
||||
|
||||
if (zipfi==NULL)
|
||||
ziplocal_putValue_inmemory(zi->ci.central_header+36,(uLong)0,2);
|
||||
ziplocal_putValue_inmemory(zi->ci.central_header+36,(uLong)0,2);
|
||||
else
|
||||
ziplocal_putValue_inmemory(zi->ci.central_header+36,(uLong)zipfi->internal_fa,2);
|
||||
ziplocal_putValue_inmemory(zi->ci.central_header+36,(uLong)zipfi->internal_fa,2);
|
||||
|
||||
if (zipfi==NULL)
|
||||
ziplocal_putValue_inmemory(zi->ci.central_header+38,(uLong)0,4);
|
||||
ziplocal_putValue_inmemory(zi->ci.central_header+38,(uLong)0,4);
|
||||
else
|
||||
ziplocal_putValue_inmemory(zi->ci.central_header+38,(uLong)zipfi->external_fa,4);
|
||||
|
||||
@@ -568,10 +568,10 @@ extern int ZEXPORT zipCloseFileInZip (file)
|
||||
return ZIP_PARAMERROR;
|
||||
zi = (zip_internal*)file;
|
||||
|
||||
if (zi->in_opened_file_inzip == 0)
|
||||
if (zi->in_opened_file_inzip == 0)
|
||||
return ZIP_PARAMERROR;
|
||||
zi->ci.stream.avail_in = 0;
|
||||
|
||||
|
||||
if (zi->ci.method == Z_DEFLATED)
|
||||
while (err==ZIP_OK)
|
||||
{
|
||||
@@ -618,22 +618,22 @@ extern int ZEXPORT zipCloseFileInZip (file)
|
||||
if (err==ZIP_OK)
|
||||
{
|
||||
long cur_pos_inzip = ftell(zi->filezip);
|
||||
if (fseek(zi->filezip,
|
||||
if (fseek(zi->filezip,
|
||||
zi->ci.pos_local_header + 14,SEEK_SET)!=0)
|
||||
err = ZIP_ERRNO;
|
||||
err = ZIP_ERRNO;
|
||||
|
||||
if (err==ZIP_OK)
|
||||
err = ziplocal_putValue(zi->filezip,(uLong)zi->ci.crc32,4); /* crc 32, unknown */
|
||||
|
||||
if (err==ZIP_OK) /* compressed size, unknown */
|
||||
err = ziplocal_putValue(zi->filezip,(uLong)zi->ci.stream.total_out,4);
|
||||
err = ziplocal_putValue(zi->filezip,(uLong)zi->ci.stream.total_out,4);
|
||||
|
||||
if (err==ZIP_OK) /* uncompressed size, unknown */
|
||||
err = ziplocal_putValue(zi->filezip,(uLong)zi->ci.stream.total_in,4);
|
||||
|
||||
if (fseek(zi->filezip,
|
||||
if (fseek(zi->filezip,
|
||||
cur_pos_inzip,SEEK_SET)!=0)
|
||||
err = ZIP_ERRNO;
|
||||
err = ZIP_ERRNO;
|
||||
}
|
||||
|
||||
zi->number_entry ++;
|
||||
@@ -701,8 +701,8 @@ extern int ZEXPORT zipClose (file, global_comment)
|
||||
if (err==ZIP_OK) /* size of the central directory */
|
||||
err = ziplocal_putValue(zi->filezip,(uLong)size_centraldir,4);
|
||||
|
||||
if (err==ZIP_OK) /* offset of start of central directory with respect to the
|
||||
starting disk number */
|
||||
if (err==ZIP_OK) /* offset of start of central directory with respect to the
|
||||
starting disk number */
|
||||
err = ziplocal_putValue(zi->filezip,(uLong)centraldir_pos_inzip ,4);
|
||||
|
||||
if (err==ZIP_OK) /* zipfile comment length */
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* zip.h -- IO for compress .zip files using zlib
|
||||
/* zip.h -- IO for compress .zip files using zlib
|
||||
Version 0.15 alpha, Mar 19th, 1998,
|
||||
|
||||
Copyright (C) 1998 Gilles Vollant
|
||||
@@ -36,7 +36,7 @@
|
||||
|
||||
*/
|
||||
|
||||
/* for more info about .ZIP format, see
|
||||
/* for more info about .ZIP format, see
|
||||
ftp://ftp.cdrom.com/pub/infozip/doc/appnote-970311-iz.zip
|
||||
PkWare has also a specification at :
|
||||
ftp://ftp.pkware.com/probdesc.zip
|
||||
@@ -56,7 +56,7 @@ extern "C" {
|
||||
#if defined(STRICTZIP) || defined(STRICTZIPUNZIP)
|
||||
/* like the STRICT of WIN32, we define a pointer that cannot be converted
|
||||
from (void*) without cast */
|
||||
typedef struct TagzipFile__ { int unused; } zipFile__;
|
||||
typedef struct TagzipFile__ { int unused; } zipFile__;
|
||||
typedef zipFile__ *zipFile;
|
||||
#else
|
||||
typedef voidp zipFile;
|
||||
@@ -68,19 +68,19 @@ typedef voidp zipFile;
|
||||
#define ZIP_INTERNALERROR (-104)
|
||||
|
||||
/* tm_zip contain date/time info */
|
||||
typedef struct tm_zip_s
|
||||
typedef struct tm_zip_s
|
||||
{
|
||||
uInt tm_sec; /* seconds after the minute - [0,59] */
|
||||
uInt tm_min; /* minutes after the hour - [0,59] */
|
||||
uInt tm_hour; /* hours since midnight - [0,23] */
|
||||
uInt tm_mday; /* day of the month - [1,31] */
|
||||
uInt tm_mon; /* months since January - [0,11] */
|
||||
uInt tm_year; /* years - [1980..2044] */
|
||||
uInt tm_sec; /* seconds after the minute - [0,59] */
|
||||
uInt tm_min; /* minutes after the hour - [0,59] */
|
||||
uInt tm_hour; /* hours since midnight - [0,23] */
|
||||
uInt tm_mday; /* day of the month - [1,31] */
|
||||
uInt tm_mon; /* months since January - [0,11] */
|
||||
uInt tm_year; /* years - [1980..2044] */
|
||||
} tm_zip;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
tm_zip tmz_date; /* date in understandable format */
|
||||
tm_zip tmz_date; /* date in understandable format */
|
||||
uLong dosDate; /* if dos_date == 0, tmu_date is used */
|
||||
/* uLong flag; */ /* general purpose bit flag 2 bytes */
|
||||
|
||||
@@ -91,27 +91,27 @@ typedef struct
|
||||
extern zipFile ZEXPORT zipOpen OF((const char *pathname, int append));
|
||||
/*
|
||||
Create a zipfile.
|
||||
pathname contain on Windows NT a filename like "c:\\zlib\\zlib111.zip" or on
|
||||
an Unix computer "zlib/zlib111.zip".
|
||||
if the file pathname exist and append=1, the zip will be created at the end
|
||||
of the file. (useful if the file contain a self extractor code)
|
||||
If the zipfile cannot be opened, the return value is NULL.
|
||||
pathname contain on Windows NT a filename like "c:\\zlib\\zlib111.zip" or on
|
||||
an Unix computer "zlib/zlib111.zip".
|
||||
if the file pathname exist and append=1, the zip will be created at the end
|
||||
of the file. (useful if the file contain a self extractor code)
|
||||
If the zipfile cannot be opened, the return value is NULL.
|
||||
Else, the return value is a zipFile Handle, usable with other function
|
||||
of this zip package.
|
||||
of this zip package.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file,
|
||||
const char* filename,
|
||||
const zip_fileinfo* zipfi,
|
||||
const void* extrafield_local,
|
||||
uInt size_extrafield_local,
|
||||
const void* extrafield_global,
|
||||
uInt size_extrafield_global,
|
||||
const char* comment,
|
||||
int method,
|
||||
int level));
|
||||
const char* filename,
|
||||
const zip_fileinfo* zipfi,
|
||||
const void* extrafield_local,
|
||||
uInt size_extrafield_local,
|
||||
const void* extrafield_global,
|
||||
uInt size_extrafield_global,
|
||||
const char* comment,
|
||||
int method,
|
||||
int level));
|
||||
/*
|
||||
Open a file in the ZIP for writing.
|
||||
filename : the filename in zip (if NULL, '-' without quote will be used
|
||||
@@ -126,8 +126,8 @@ extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file,
|
||||
*/
|
||||
|
||||
extern int ZEXPORT zipWriteInFileInZip OF((zipFile file,
|
||||
const voidp buf,
|
||||
unsigned len));
|
||||
const voidp buf,
|
||||
unsigned len));
|
||||
/*
|
||||
Write data in the zipfile
|
||||
*/
|
||||
@@ -138,7 +138,7 @@ extern int ZEXPORT zipCloseFileInZip OF((zipFile file));
|
||||
*/
|
||||
|
||||
extern int ZEXPORT zipClose OF((zipFile file,
|
||||
const char* global_comment));
|
||||
const char* global_comment));
|
||||
/*
|
||||
Close the zipfile
|
||||
*/
|
||||
|
||||
@@ -39,37 +39,37 @@
|
||||
|
||||
/* Values used in typeflag field. */
|
||||
|
||||
#define REGTYPE '0' /* regular file */
|
||||
#define AREGTYPE '\0' /* regular file */
|
||||
#define LNKTYPE '1' /* link */
|
||||
#define SYMTYPE '2' /* reserved */
|
||||
#define CHRTYPE '3' /* character special */
|
||||
#define BLKTYPE '4' /* block special */
|
||||
#define DIRTYPE '5' /* directory */
|
||||
#define FIFOTYPE '6' /* FIFO special */
|
||||
#define CONTTYPE '7' /* reserved */
|
||||
#define REGTYPE '0' /* regular file */
|
||||
#define AREGTYPE '\0' /* regular file */
|
||||
#define LNKTYPE '1' /* link */
|
||||
#define SYMTYPE '2' /* reserved */
|
||||
#define CHRTYPE '3' /* character special */
|
||||
#define BLKTYPE '4' /* block special */
|
||||
#define DIRTYPE '5' /* directory */
|
||||
#define FIFOTYPE '6' /* FIFO special */
|
||||
#define CONTTYPE '7' /* reserved */
|
||||
|
||||
#define BLOCKSIZE 512
|
||||
|
||||
struct tar_header
|
||||
{ /* byte offset */
|
||||
char name[100]; /* 0 */
|
||||
char mode[8]; /* 100 */
|
||||
char uid[8]; /* 108 */
|
||||
char gid[8]; /* 116 */
|
||||
char size[12]; /* 124 */
|
||||
char mtime[12]; /* 136 */
|
||||
char chksum[8]; /* 148 */
|
||||
char typeflag; /* 156 */
|
||||
char linkname[100]; /* 157 */
|
||||
char magic[6]; /* 257 */
|
||||
char version[2]; /* 263 */
|
||||
char uname[32]; /* 265 */
|
||||
char gname[32]; /* 297 */
|
||||
char devmajor[8]; /* 329 */
|
||||
char devminor[8]; /* 337 */
|
||||
char prefix[155]; /* 345 */
|
||||
/* 500 */
|
||||
{ /* byte offset */
|
||||
char name[100]; /* 0 */
|
||||
char mode[8]; /* 100 */
|
||||
char uid[8]; /* 108 */
|
||||
char gid[8]; /* 116 */
|
||||
char size[12]; /* 124 */
|
||||
char mtime[12]; /* 136 */
|
||||
char chksum[8]; /* 148 */
|
||||
char typeflag; /* 156 */
|
||||
char linkname[100]; /* 157 */
|
||||
char magic[6]; /* 257 */
|
||||
char version[2]; /* 263 */
|
||||
char uname[32]; /* 265 */
|
||||
char gname[32]; /* 297 */
|
||||
char devmajor[8]; /* 329 */
|
||||
char devminor[8]; /* 337 */
|
||||
char prefix[155]; /* 345 */
|
||||
/* 500 */
|
||||
};
|
||||
|
||||
union tar_buffer {
|
||||
@@ -79,21 +79,21 @@ union tar_buffer {
|
||||
|
||||
enum { TGZ_EXTRACT = 0, TGZ_LIST };
|
||||
|
||||
static char *TGZfname OF((const char *));
|
||||
void TGZnotfound OF((const char *));
|
||||
static char *TGZfname OF((const char *));
|
||||
void TGZnotfound OF((const char *));
|
||||
|
||||
int getoct OF((char *, int));
|
||||
char *strtime OF((time_t *));
|
||||
int ExprMatch OF((char *,char *));
|
||||
int getoct OF((char *, int));
|
||||
char *strtime OF((time_t *));
|
||||
int ExprMatch OF((char *,char *));
|
||||
|
||||
int makedir OF((char *));
|
||||
int matchname OF((int,int,char **,char *));
|
||||
int makedir OF((char *));
|
||||
int matchname OF((int,int,char **,char *));
|
||||
|
||||
void error OF((const char *));
|
||||
int tar OF((gzFile, int, int, int, char **));
|
||||
void error OF((const char *));
|
||||
int tar OF((gzFile, int, int, int, char **));
|
||||
|
||||
void help OF((int));
|
||||
int main OF((int, char **));
|
||||
void help OF((int));
|
||||
int main OF((int, char **));
|
||||
|
||||
char *prog;
|
||||
|
||||
@@ -108,7 +108,7 @@ static char *TGZfname OF((const char *fname))
|
||||
{
|
||||
static char buffer[1024];
|
||||
int origlen,i;
|
||||
|
||||
|
||||
strcpy(buffer,fname);
|
||||
origlen = strlen(buffer);
|
||||
|
||||
@@ -142,14 +142,14 @@ int getoct(char *p,int width)
|
||||
{
|
||||
int result = 0;
|
||||
char c;
|
||||
|
||||
|
||||
while (width --)
|
||||
{
|
||||
c = *p++;
|
||||
if (c == ' ')
|
||||
continue;
|
||||
continue;
|
||||
if (c == 0)
|
||||
break;
|
||||
break;
|
||||
result = result * 8 + (c - '0');
|
||||
}
|
||||
return result;
|
||||
@@ -162,8 +162,8 @@ char *strtime (time_t *t)
|
||||
|
||||
local = localtime(t);
|
||||
sprintf(result,"%2d/%02d/%4d %02d:%02d:%02d",
|
||||
local->tm_mday, local->tm_mon+1, local->tm_year+1900,
|
||||
local->tm_hour, local->tm_min, local->tm_sec);
|
||||
local->tm_mday, local->tm_mon+1, local->tm_year+1900,
|
||||
local->tm_hour, local->tm_min, local->tm_sec);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -177,30 +177,30 @@ int ExprMatch(char *string,char *expr)
|
||||
while (1)
|
||||
{
|
||||
if (ISSPECIAL(*expr))
|
||||
{
|
||||
if (*expr == '/')
|
||||
{
|
||||
if (*string != '\\' && *string != '/')
|
||||
return 0;
|
||||
string ++; expr++;
|
||||
}
|
||||
else if (*expr == '*')
|
||||
{
|
||||
if (*expr ++ == 0)
|
||||
return 1;
|
||||
while (*++string != *expr)
|
||||
if (*string == 0)
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
{
|
||||
if (*expr == '/')
|
||||
{
|
||||
if (*string != '\\' && *string != '/')
|
||||
return 0;
|
||||
string ++; expr++;
|
||||
}
|
||||
else if (*expr == '*')
|
||||
{
|
||||
if (*expr ++ == 0)
|
||||
return 1;
|
||||
while (*++string != *expr)
|
||||
if (*string == 0)
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (*string != *expr)
|
||||
return 0;
|
||||
if (*expr++ == 0)
|
||||
return 1;
|
||||
string++;
|
||||
}
|
||||
{
|
||||
if (*string != *expr)
|
||||
return 0;
|
||||
if (*expr++ == 0)
|
||||
return 1;
|
||||
string++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -216,7 +216,7 @@ int makedir (char *newdir)
|
||||
char *buffer = strdup(newdir);
|
||||
char *p;
|
||||
int len = strlen(buffer);
|
||||
|
||||
|
||||
if (len <= 0) {
|
||||
free(buffer);
|
||||
return 0;
|
||||
@@ -234,19 +234,19 @@ int makedir (char *newdir)
|
||||
while (1)
|
||||
{
|
||||
char hold;
|
||||
|
||||
|
||||
while(*p && *p != '\\' && *p != '/')
|
||||
p++;
|
||||
p++;
|
||||
hold = *p;
|
||||
*p = 0;
|
||||
if ((mkdir(buffer, 0775) == -1) && (errno == ENOENT))
|
||||
{
|
||||
fprintf(stderr,"%s: couldn't create directory %s\n",prog,buffer);
|
||||
free(buffer);
|
||||
return 0;
|
||||
}
|
||||
{
|
||||
fprintf(stderr,"%s: couldn't create directory %s\n",prog,buffer);
|
||||
free(buffer);
|
||||
return 0;
|
||||
}
|
||||
if (hold == 0)
|
||||
break;
|
||||
break;
|
||||
*p++ = hold;
|
||||
}
|
||||
free(buffer);
|
||||
@@ -255,7 +255,7 @@ int makedir (char *newdir)
|
||||
|
||||
int matchname (int arg,int argc,char **argv,char *fname)
|
||||
{
|
||||
if (arg == argc) /* no arguments given (untgz tgzarchive) */
|
||||
if (arg == argc) /* no arguments given (untgz tgzarchive) */
|
||||
return 1;
|
||||
|
||||
while (arg < argc)
|
||||
@@ -278,144 +278,144 @@ int tar (gzFile in,int action,int arg,int argc,char **argv)
|
||||
FILE *outfile = NULL;
|
||||
char fname[BLOCKSIZE];
|
||||
time_t tartime;
|
||||
|
||||
|
||||
if (action == TGZ_LIST)
|
||||
printf(" day time size file\n"
|
||||
" ---------- -------- --------- -------------------------------------\n");
|
||||
" ---------- -------- --------- -------------------------------------\n");
|
||||
while (1)
|
||||
{
|
||||
len = gzread(in, &buffer, BLOCKSIZE);
|
||||
if (len < 0)
|
||||
error (gzerror(in, &err));
|
||||
error (gzerror(in, &err));
|
||||
/*
|
||||
* Always expect complete blocks to process
|
||||
* the tar information.
|
||||
*/
|
||||
if (len != BLOCKSIZE)
|
||||
error("gzread: incomplete block read");
|
||||
|
||||
error("gzread: incomplete block read");
|
||||
|
||||
/*
|
||||
* If we have to get a tar header
|
||||
*/
|
||||
if (getheader == 1)
|
||||
{
|
||||
/*
|
||||
* if we met the end of the tar
|
||||
* or the end-of-tar block,
|
||||
* we are done
|
||||
*/
|
||||
if ((len == 0) || (buffer.header.name[0]== 0)) break;
|
||||
{
|
||||
/*
|
||||
* if we met the end of the tar
|
||||
* or the end-of-tar block,
|
||||
* we are done
|
||||
*/
|
||||
if ((len == 0) || (buffer.header.name[0]== 0)) break;
|
||||
|
||||
tartime = (time_t)getoct(buffer.header.mtime,12);
|
||||
strcpy(fname,buffer.header.name);
|
||||
|
||||
switch (buffer.header.typeflag)
|
||||
{
|
||||
case DIRTYPE:
|
||||
if (action == TGZ_LIST)
|
||||
printf(" %s <dir> %s\n",strtime(&tartime),fname);
|
||||
if (action == TGZ_EXTRACT)
|
||||
makedir(fname);
|
||||
break;
|
||||
case REGTYPE:
|
||||
case AREGTYPE:
|
||||
remaining = getoct(buffer.header.size,12);
|
||||
if (action == TGZ_LIST)
|
||||
printf(" %s %9d %s\n",strtime(&tartime),remaining,fname);
|
||||
if (action == TGZ_EXTRACT)
|
||||
{
|
||||
if ((remaining) && (matchname(arg,argc,argv,fname)))
|
||||
{
|
||||
outfile = fopen(fname,"wb");
|
||||
if (outfile == NULL) {
|
||||
/* try creating directory */
|
||||
char *p = strrchr(fname, '/');
|
||||
if (p != NULL) {
|
||||
*p = '\0';
|
||||
makedir(fname);
|
||||
*p = '/';
|
||||
outfile = fopen(fname,"wb");
|
||||
}
|
||||
}
|
||||
fprintf(stderr,
|
||||
"%s %s\n",
|
||||
(outfile) ? "Extracting" : "Couldn't create",
|
||||
fname);
|
||||
}
|
||||
else
|
||||
outfile = NULL;
|
||||
}
|
||||
/*
|
||||
* could have no contents
|
||||
*/
|
||||
getheader = (remaining) ? 0 : 1;
|
||||
break;
|
||||
default:
|
||||
if (action == TGZ_LIST)
|
||||
printf(" %s <---> %s\n",strtime(&tartime),fname);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned int bytes = (remaining > BLOCKSIZE) ? BLOCKSIZE : remaining;
|
||||
tartime = (time_t)getoct(buffer.header.mtime,12);
|
||||
strcpy(fname,buffer.header.name);
|
||||
|
||||
if ((action == TGZ_EXTRACT) && (outfile != NULL))
|
||||
{
|
||||
if (fwrite(&buffer,sizeof(char),bytes,outfile) != bytes)
|
||||
{
|
||||
fprintf(stderr,"%s : error writing %s skipping...\n",prog,fname);
|
||||
fclose(outfile);
|
||||
unlink(fname);
|
||||
}
|
||||
}
|
||||
remaining -= bytes;
|
||||
if (remaining == 0)
|
||||
{
|
||||
getheader = 1;
|
||||
if ((action == TGZ_EXTRACT) && (outfile != NULL))
|
||||
{
|
||||
#ifdef WIN32
|
||||
HANDLE hFile;
|
||||
FILETIME ftm,ftLocal;
|
||||
SYSTEMTIME st;
|
||||
struct tm localt;
|
||||
|
||||
fclose(outfile);
|
||||
|
||||
localt = *localtime(&tartime);
|
||||
|
||||
hFile = CreateFile(fname, GENERIC_READ | GENERIC_WRITE,
|
||||
0, NULL, OPEN_EXISTING, 0, NULL);
|
||||
|
||||
st.wYear = (WORD)localt.tm_year+1900;
|
||||
st.wMonth = (WORD)localt.tm_mon;
|
||||
st.wDayOfWeek = (WORD)localt.tm_wday;
|
||||
st.wDay = (WORD)localt.tm_mday;
|
||||
st.wHour = (WORD)localt.tm_hour;
|
||||
st.wMinute = (WORD)localt.tm_min;
|
||||
st.wSecond = (WORD)localt.tm_sec;
|
||||
st.wMilliseconds = 0;
|
||||
SystemTimeToFileTime(&st,&ftLocal);
|
||||
LocalFileTimeToFileTime(&ftLocal,&ftm);
|
||||
SetFileTime(hFile,&ftm,NULL,&ftm);
|
||||
CloseHandle(hFile);
|
||||
|
||||
outfile = NULL;
|
||||
#else
|
||||
struct utimbuf settime;
|
||||
|
||||
settime.actime = settime.modtime = tartime;
|
||||
|
||||
fclose(outfile);
|
||||
outfile = NULL;
|
||||
utime(fname,&settime);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
switch (buffer.header.typeflag)
|
||||
{
|
||||
case DIRTYPE:
|
||||
if (action == TGZ_LIST)
|
||||
printf(" %s <dir> %s\n",strtime(&tartime),fname);
|
||||
if (action == TGZ_EXTRACT)
|
||||
makedir(fname);
|
||||
break;
|
||||
case REGTYPE:
|
||||
case AREGTYPE:
|
||||
remaining = getoct(buffer.header.size,12);
|
||||
if (action == TGZ_LIST)
|
||||
printf(" %s %9d %s\n",strtime(&tartime),remaining,fname);
|
||||
if (action == TGZ_EXTRACT)
|
||||
{
|
||||
if ((remaining) && (matchname(arg,argc,argv,fname)))
|
||||
{
|
||||
outfile = fopen(fname,"wb");
|
||||
if (outfile == NULL) {
|
||||
/* try creating directory */
|
||||
char *p = strrchr(fname, '/');
|
||||
if (p != NULL) {
|
||||
*p = '\0';
|
||||
makedir(fname);
|
||||
*p = '/';
|
||||
outfile = fopen(fname,"wb");
|
||||
}
|
||||
}
|
||||
fprintf(stderr,
|
||||
"%s %s\n",
|
||||
(outfile) ? "Extracting" : "Couldn't create",
|
||||
fname);
|
||||
}
|
||||
else
|
||||
outfile = NULL;
|
||||
}
|
||||
/*
|
||||
* could have no contents
|
||||
*/
|
||||
getheader = (remaining) ? 0 : 1;
|
||||
break;
|
||||
default:
|
||||
if (action == TGZ_LIST)
|
||||
printf(" %s <---> %s\n",strtime(&tartime),fname);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
unsigned int bytes = (remaining > BLOCKSIZE) ? BLOCKSIZE : remaining;
|
||||
|
||||
if ((action == TGZ_EXTRACT) && (outfile != NULL))
|
||||
{
|
||||
if (fwrite(&buffer,sizeof(char),bytes,outfile) != bytes)
|
||||
{
|
||||
fprintf(stderr,"%s : error writing %s skipping...\n",prog,fname);
|
||||
fclose(outfile);
|
||||
unlink(fname);
|
||||
}
|
||||
}
|
||||
remaining -= bytes;
|
||||
if (remaining == 0)
|
||||
{
|
||||
getheader = 1;
|
||||
if ((action == TGZ_EXTRACT) && (outfile != NULL))
|
||||
{
|
||||
#ifdef WIN32
|
||||
HANDLE hFile;
|
||||
FILETIME ftm,ftLocal;
|
||||
SYSTEMTIME st;
|
||||
struct tm localt;
|
||||
|
||||
fclose(outfile);
|
||||
|
||||
localt = *localtime(&tartime);
|
||||
|
||||
hFile = CreateFile(fname, GENERIC_READ | GENERIC_WRITE,
|
||||
0, NULL, OPEN_EXISTING, 0, NULL);
|
||||
|
||||
st.wYear = (WORD)localt.tm_year+1900;
|
||||
st.wMonth = (WORD)localt.tm_mon;
|
||||
st.wDayOfWeek = (WORD)localt.tm_wday;
|
||||
st.wDay = (WORD)localt.tm_mday;
|
||||
st.wHour = (WORD)localt.tm_hour;
|
||||
st.wMinute = (WORD)localt.tm_min;
|
||||
st.wSecond = (WORD)localt.tm_sec;
|
||||
st.wMilliseconds = 0;
|
||||
SystemTimeToFileTime(&st,&ftLocal);
|
||||
LocalFileTimeToFileTime(&ftLocal,&ftm);
|
||||
SetFileTime(hFile,&ftm,NULL,&ftm);
|
||||
CloseHandle(hFile);
|
||||
|
||||
outfile = NULL;
|
||||
#else
|
||||
struct utimbuf settime;
|
||||
|
||||
settime.actime = settime.modtime = tartime;
|
||||
|
||||
fclose(outfile);
|
||||
outfile = NULL;
|
||||
utime(fname,&settime);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (gzclose(in) != Z_OK)
|
||||
error("failed gzclose");
|
||||
|
||||
@@ -428,8 +428,8 @@ int tar (gzFile in,int action,int arg,int argc,char **argv)
|
||||
void help(int exitval)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"untgz v 0.1\n"
|
||||
" an sample application of zlib 1.0.4\n\n"
|
||||
"untgz v 0.1\n"
|
||||
" an sample application of zlib 1.0.4\n\n"
|
||||
"Usage : untgz TGZfile to extract all files\n"
|
||||
" untgz TGZfile fname ... to extract selected files\n"
|
||||
" untgz -l TGZfile to list archive contents\n"
|
||||
@@ -446,50 +446,50 @@ void error(const char *msg)
|
||||
|
||||
/* ====================================================================== */
|
||||
|
||||
int _CRT_glob = 0; /* disable globbing of the arguments */
|
||||
int _CRT_glob = 0; /* disable globbing of the arguments */
|
||||
|
||||
int main(int argc,char **argv)
|
||||
{
|
||||
int action = TGZ_EXTRACT;
|
||||
int arg = 1;
|
||||
char *TGZfile;
|
||||
gzFile *f;
|
||||
|
||||
int action = TGZ_EXTRACT;
|
||||
int arg = 1;
|
||||
char *TGZfile;
|
||||
gzFile *f;
|
||||
|
||||
|
||||
prog = strrchr(argv[0],'\\');
|
||||
if (prog == NULL)
|
||||
{
|
||||
prog = strrchr(argv[0],'/');
|
||||
if (prog == NULL)
|
||||
{
|
||||
prog = strrchr(argv[0],':');
|
||||
if (prog == NULL)
|
||||
prog = argv[0];
|
||||
else
|
||||
prog++;
|
||||
}
|
||||
else
|
||||
prog++;
|
||||
prog = strrchr(argv[0],'/');
|
||||
if (prog == NULL)
|
||||
{
|
||||
prog = strrchr(argv[0],':');
|
||||
if (prog == NULL)
|
||||
prog = argv[0];
|
||||
else
|
||||
prog++;
|
||||
}
|
||||
else
|
||||
prog++;
|
||||
|
||||
}
|
||||
else
|
||||
prog++;
|
||||
|
||||
if (argc == 1)
|
||||
help(0);
|
||||
|
||||
if (strcmp(argv[arg],"-l") == 0)
|
||||
{
|
||||
action = TGZ_LIST;
|
||||
if (argc == ++arg)
|
||||
help(0);
|
||||
action = TGZ_LIST;
|
||||
if (argc == ++arg)
|
||||
help(0);
|
||||
}
|
||||
else if (strcmp(argv[arg],"-h") == 0)
|
||||
{
|
||||
help(0);
|
||||
help(0);
|
||||
}
|
||||
|
||||
if ((TGZfile = TGZfname(argv[arg])) == NULL)
|
||||
TGZnotfound(argv[arg]);
|
||||
TGZnotfound(argv[arg]);
|
||||
|
||||
++arg;
|
||||
if ((action == TGZ_LIST) && (arg != argc))
|
||||
@@ -502,20 +502,20 @@ int main(int argc,char **argv)
|
||||
{
|
||||
case TGZ_LIST:
|
||||
case TGZ_EXTRACT:
|
||||
f = gzopen(TGZfile,"rb");
|
||||
if (f == NULL)
|
||||
{
|
||||
fprintf(stderr,"%s: Couldn't gzopen %s\n",
|
||||
prog,
|
||||
TGZfile);
|
||||
return 1;
|
||||
}
|
||||
exit(tar(f, action, arg, argc, argv));
|
||||
f = gzopen(TGZfile,"rb");
|
||||
if (f == NULL)
|
||||
{
|
||||
fprintf(stderr,"%s: Couldn't gzopen %s\n",
|
||||
prog,
|
||||
TGZfile);
|
||||
return 1;
|
||||
}
|
||||
exit(tar(f, action, arg, argc, argv));
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
error("Unknown option!");
|
||||
exit(1);
|
||||
error("Unknown option!");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* crc32.c -- compute the CRC-32 of a data stream
|
||||
* Copyright (C) 1995-2002 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* @(#) $Id$ */
|
||||
@@ -51,7 +51,7 @@ local void make_crc_table()
|
||||
poly = 0L;
|
||||
for (n = 0; n < sizeof(p)/sizeof(Byte); n++)
|
||||
poly |= 1L << (31 - p[n]);
|
||||
|
||||
|
||||
for (n = 0; n < 256; n++)
|
||||
{
|
||||
c = (uLong)n;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* deflate.c -- compress data using the deflation algorithm
|
||||
* Copyright (C) 1995-2002 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
|
||||
*/
|
||||
|
||||
/*
|
||||
@@ -194,13 +194,13 @@ int ZEXPORT deflateInit_(strm, level, version, stream_size)
|
||||
int stream_size;
|
||||
{
|
||||
return deflateInit2_(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL,
|
||||
Z_DEFAULT_STRATEGY, version, stream_size);
|
||||
Z_DEFAULT_STRATEGY, version, stream_size);
|
||||
/* To do: ignore strm->next_in if we use it as window */
|
||||
}
|
||||
|
||||
/* ========================================================================= */
|
||||
int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
|
||||
version, stream_size)
|
||||
version, stream_size)
|
||||
z_streamp strm;
|
||||
int level;
|
||||
int method;
|
||||
@@ -221,14 +221,14 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
|
||||
|
||||
if (version == Z_NULL || version[0] != my_version[0] ||
|
||||
stream_size != sizeof(z_stream)) {
|
||||
return Z_VERSION_ERROR;
|
||||
return Z_VERSION_ERROR;
|
||||
}
|
||||
if (strm == Z_NULL) return Z_STREAM_ERROR;
|
||||
|
||||
strm->msg = Z_NULL;
|
||||
if (strm->zalloc == Z_NULL) {
|
||||
strm->zalloc = zcalloc;
|
||||
strm->opaque = (voidpf)0;
|
||||
strm->zalloc = zcalloc;
|
||||
strm->opaque = (voidpf)0;
|
||||
}
|
||||
if (strm->zfree == Z_NULL) strm->zfree = zcfree;
|
||||
|
||||
@@ -243,7 +243,7 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
|
||||
}
|
||||
if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED ||
|
||||
windowBits < 9 || windowBits > 15 || level < 0 || level > 9 ||
|
||||
strategy < 0 || strategy > Z_HUFFMAN_ONLY) {
|
||||
strategy < 0 || strategy > Z_HUFFMAN_ONLY) {
|
||||
return Z_STREAM_ERROR;
|
||||
}
|
||||
s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state));
|
||||
@@ -306,9 +306,9 @@ int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength)
|
||||
|
||||
if (length < MIN_MATCH) return Z_OK;
|
||||
if (length > MAX_DIST(s)) {
|
||||
length = MAX_DIST(s);
|
||||
length = MAX_DIST(s);
|
||||
#ifndef USE_DICT_HEAD
|
||||
dictionary += dictLength - length; /* use the tail of the dictionary */
|
||||
dictionary += dictLength - length; /* use the tail of the dictionary */
|
||||
#endif
|
||||
}
|
||||
zmemcpy(s->window, dictionary, length);
|
||||
@@ -322,7 +322,7 @@ int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength)
|
||||
s->ins_h = s->window[0];
|
||||
UPDATE_HASH(s, s->ins_h, s->window[1]);
|
||||
for (n = 0; n <= length - MIN_MATCH; n++) {
|
||||
INSERT_STRING(s, n, hash_head);
|
||||
INSERT_STRING(s, n, hash_head);
|
||||
}
|
||||
if (hash_head) hash_head = 0; /* to make compiler happy */
|
||||
return Z_OK;
|
||||
@@ -333,7 +333,7 @@ int ZEXPORT deflateReset (strm)
|
||||
z_streamp strm;
|
||||
{
|
||||
deflate_state *s;
|
||||
|
||||
|
||||
if (strm == Z_NULL || strm->state == Z_NULL ||
|
||||
strm->zalloc == Z_NULL || strm->zfree == Z_NULL) return Z_STREAM_ERROR;
|
||||
|
||||
@@ -372,23 +372,23 @@ int ZEXPORT deflateParams(strm, level, strategy)
|
||||
s = strm->state;
|
||||
|
||||
if (level == Z_DEFAULT_COMPRESSION) {
|
||||
level = 6;
|
||||
level = 6;
|
||||
}
|
||||
if (level < 0 || level > 9 || strategy < 0 || strategy > Z_HUFFMAN_ONLY) {
|
||||
return Z_STREAM_ERROR;
|
||||
return Z_STREAM_ERROR;
|
||||
}
|
||||
func = configuration_table[s->level].func;
|
||||
|
||||
if (func != configuration_table[level].func && strm->total_in != 0) {
|
||||
/* Flush the last buffer: */
|
||||
err = deflate(strm, Z_PARTIAL_FLUSH);
|
||||
/* Flush the last buffer: */
|
||||
err = deflate(strm, Z_PARTIAL_FLUSH);
|
||||
}
|
||||
if (s->level != level) {
|
||||
s->level = level;
|
||||
s->max_lazy_match = configuration_table[level].max_lazy;
|
||||
s->good_match = configuration_table[level].good_length;
|
||||
s->nice_match = configuration_table[level].nice_length;
|
||||
s->max_chain_length = configuration_table[level].max_chain;
|
||||
s->level = level;
|
||||
s->max_lazy_match = configuration_table[level].max_lazy;
|
||||
s->good_match = configuration_table[level].good_length;
|
||||
s->nice_match = configuration_table[level].nice_length;
|
||||
s->max_chain_length = configuration_table[level].max_chain;
|
||||
}
|
||||
s->strategy = strategy;
|
||||
return err;
|
||||
@@ -405,7 +405,7 @@ local void putShortMSB (s, b)
|
||||
{
|
||||
put_byte(s, (Byte)(b >> 8));
|
||||
put_byte(s, (Byte)(b & 0xff));
|
||||
}
|
||||
}
|
||||
|
||||
/* =========================================================================
|
||||
* Flush as much pending output as possible. All deflate() output goes
|
||||
@@ -441,14 +441,14 @@ int ZEXPORT deflate (strm, flush)
|
||||
deflate_state *s;
|
||||
|
||||
if (strm == Z_NULL || strm->state == Z_NULL ||
|
||||
flush > Z_FINISH || flush < 0) {
|
||||
flush > Z_FINISH || flush < 0) {
|
||||
return Z_STREAM_ERROR;
|
||||
}
|
||||
s = strm->state;
|
||||
|
||||
if (strm->next_out == Z_NULL ||
|
||||
(strm->next_in == Z_NULL && strm->avail_in != 0) ||
|
||||
(s->status == FINISH_STATE && flush != Z_FINISH)) {
|
||||
(s->status == FINISH_STATE && flush != Z_FINISH)) {
|
||||
ERR_RETURN(strm, Z_STREAM_ERROR);
|
||||
}
|
||||
if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR);
|
||||
@@ -465,40 +465,40 @@ int ZEXPORT deflate (strm, flush)
|
||||
|
||||
if (level_flags > 3) level_flags = 3;
|
||||
header |= (level_flags << 6);
|
||||
if (s->strstart != 0) header |= PRESET_DICT;
|
||||
if (s->strstart != 0) header |= PRESET_DICT;
|
||||
header += 31 - (header % 31);
|
||||
|
||||
s->status = BUSY_STATE;
|
||||
putShortMSB(s, header);
|
||||
|
||||
/* Save the adler32 of the preset dictionary: */
|
||||
if (s->strstart != 0) {
|
||||
putShortMSB(s, (uInt)(strm->adler >> 16));
|
||||
putShortMSB(s, (uInt)(strm->adler & 0xffff));
|
||||
}
|
||||
strm->adler = 1L;
|
||||
/* Save the adler32 of the preset dictionary: */
|
||||
if (s->strstart != 0) {
|
||||
putShortMSB(s, (uInt)(strm->adler >> 16));
|
||||
putShortMSB(s, (uInt)(strm->adler & 0xffff));
|
||||
}
|
||||
strm->adler = 1L;
|
||||
}
|
||||
|
||||
/* Flush as much pending output as possible */
|
||||
if (s->pending != 0) {
|
||||
flush_pending(strm);
|
||||
if (strm->avail_out == 0) {
|
||||
/* Since avail_out is 0, deflate will be called again with
|
||||
* more output space, but possibly with both pending and
|
||||
* avail_in equal to zero. There won't be anything to do,
|
||||
* but this is not an error situation so make sure we
|
||||
* return OK instead of BUF_ERROR at next call of deflate:
|
||||
/* Since avail_out is 0, deflate will be called again with
|
||||
* more output space, but possibly with both pending and
|
||||
* avail_in equal to zero. There won't be anything to do,
|
||||
* but this is not an error situation so make sure we
|
||||
* return OK instead of BUF_ERROR at next call of deflate:
|
||||
*/
|
||||
s->last_flush = -1;
|
||||
return Z_OK;
|
||||
}
|
||||
s->last_flush = -1;
|
||||
return Z_OK;
|
||||
}
|
||||
|
||||
/* Make sure there is something to do and avoid duplicate consecutive
|
||||
* flushes. For repeated and useless calls with Z_FINISH, we keep
|
||||
* returning Z_STREAM_END instead of Z_BUFF_ERROR.
|
||||
*/
|
||||
} else if (strm->avail_in == 0 && flush <= old_flush &&
|
||||
flush != Z_FINISH) {
|
||||
flush != Z_FINISH) {
|
||||
ERR_RETURN(strm, Z_BUF_ERROR);
|
||||
}
|
||||
|
||||
@@ -513,24 +513,24 @@ int ZEXPORT deflate (strm, flush)
|
||||
(flush != Z_NO_FLUSH && s->status != FINISH_STATE)) {
|
||||
block_state bstate;
|
||||
|
||||
bstate = (*(configuration_table[s->level].func))(s, flush);
|
||||
bstate = (*(configuration_table[s->level].func))(s, flush);
|
||||
|
||||
if (bstate == finish_started || bstate == finish_done) {
|
||||
s->status = FINISH_STATE;
|
||||
}
|
||||
if (bstate == need_more || bstate == finish_started) {
|
||||
if (strm->avail_out == 0) {
|
||||
s->last_flush = -1; /* avoid BUF_ERROR next call, see above */
|
||||
}
|
||||
return Z_OK;
|
||||
/* If flush != Z_NO_FLUSH && avail_out == 0, the next call
|
||||
* of deflate should use the same flush parameter to make sure
|
||||
* that the flush is complete. So we don't have to output an
|
||||
* empty block here, this will be done at next call. This also
|
||||
* ensures that for a very small output buffer, we emit at most
|
||||
* one empty block.
|
||||
*/
|
||||
}
|
||||
if (strm->avail_out == 0) {
|
||||
s->last_flush = -1; /* avoid BUF_ERROR next call, see above */
|
||||
}
|
||||
return Z_OK;
|
||||
/* If flush != Z_NO_FLUSH && avail_out == 0, the next call
|
||||
* of deflate should use the same flush parameter to make sure
|
||||
* that the flush is complete. So we don't have to output an
|
||||
* empty block here, this will be done at next call. This also
|
||||
* ensures that for a very small output buffer, we emit at most
|
||||
* one empty block.
|
||||
*/
|
||||
}
|
||||
if (bstate == block_done) {
|
||||
if (flush == Z_PARTIAL_FLUSH) {
|
||||
_tr_align(s);
|
||||
@@ -544,10 +544,10 @@ int ZEXPORT deflate (strm, flush)
|
||||
}
|
||||
}
|
||||
flush_pending(strm);
|
||||
if (strm->avail_out == 0) {
|
||||
s->last_flush = -1; /* avoid BUF_ERROR at next call, see above */
|
||||
return Z_OK;
|
||||
}
|
||||
if (strm->avail_out == 0) {
|
||||
s->last_flush = -1; /* avoid BUF_ERROR at next call, see above */
|
||||
return Z_OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
Assert(strm->avail_out > 0, "bug2");
|
||||
@@ -576,7 +576,7 @@ int ZEXPORT deflateEnd (strm)
|
||||
|
||||
status = strm->state->status;
|
||||
if (status != INIT_STATE && status != BUSY_STATE &&
|
||||
status != FINISH_STATE) {
|
||||
status != FINISH_STATE) {
|
||||
return Z_STREAM_ERROR;
|
||||
}
|
||||
|
||||
@@ -903,10 +903,10 @@ local uInt longest_match(s, cur_match)
|
||||
*/
|
||||
do {
|
||||
} while (*++scan == *++match && *++scan == *++match &&
|
||||
*++scan == *++match && *++scan == *++match &&
|
||||
*++scan == *++match && *++scan == *++match &&
|
||||
*++scan == *++match && *++scan == *++match &&
|
||||
scan < strend);
|
||||
*++scan == *++match && *++scan == *++match &&
|
||||
*++scan == *++match && *++scan == *++match &&
|
||||
*++scan == *++match && *++scan == *++match &&
|
||||
scan < strend);
|
||||
|
||||
Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
|
||||
|
||||
@@ -933,10 +933,10 @@ local void check_match(s, start, match, length)
|
||||
if (zmemcmp(s->window + match,
|
||||
s->window + start, length) != EQUAL) {
|
||||
fprintf(stderr, " start %u, match %u, length %d\n",
|
||||
start, match, length);
|
||||
start, match, length);
|
||||
do {
|
||||
fprintf(stderr, "%c%c", s->window[match++], s->window[start++]);
|
||||
} while (--length != 0);
|
||||
fprintf(stderr, "%c%c", s->window[match++], s->window[start++]);
|
||||
} while (--length != 0);
|
||||
z_error("invalid match");
|
||||
}
|
||||
if (z_verbose > 1) {
|
||||
@@ -995,23 +995,23 @@ local void fill_window(s)
|
||||
later. (Using level 0 permanently is not an optimal usage of
|
||||
zlib, so we don't care about this pathological case.)
|
||||
*/
|
||||
n = s->hash_size;
|
||||
p = &s->head[n];
|
||||
do {
|
||||
m = *--p;
|
||||
*p = (Pos)(m >= wsize ? m-wsize : NIL);
|
||||
} while (--n);
|
||||
n = s->hash_size;
|
||||
p = &s->head[n];
|
||||
do {
|
||||
m = *--p;
|
||||
*p = (Pos)(m >= wsize ? m-wsize : NIL);
|
||||
} while (--n);
|
||||
|
||||
n = wsize;
|
||||
n = wsize;
|
||||
#ifndef FASTEST
|
||||
p = &s->prev[n];
|
||||
do {
|
||||
m = *--p;
|
||||
*p = (Pos)(m >= wsize ? m-wsize : NIL);
|
||||
/* If n is not on any hash chain, prev[n] is garbage but
|
||||
* its value will never be used.
|
||||
*/
|
||||
} while (--n);
|
||||
p = &s->prev[n];
|
||||
do {
|
||||
m = *--p;
|
||||
*p = (Pos)(m >= wsize ? m-wsize : NIL);
|
||||
/* If n is not on any hash chain, prev[n] is garbage but
|
||||
* its value will never be used.
|
||||
*/
|
||||
} while (--n);
|
||||
#endif
|
||||
more += wsize;
|
||||
}
|
||||
@@ -1056,8 +1056,8 @@ local void fill_window(s)
|
||||
_tr_flush_block(s, (s->block_start >= 0L ? \
|
||||
(charf *)&s->window[(unsigned)s->block_start] : \
|
||||
(charf *)Z_NULL), \
|
||||
(ulg)((long)s->strstart - s->block_start), \
|
||||
(eof)); \
|
||||
(ulg)((long)s->strstart - s->block_start), \
|
||||
(eof)); \
|
||||
s->block_start = s->strstart; \
|
||||
flush_pending(s->strm); \
|
||||
Tracev((stderr,"[FLUSH]")); \
|
||||
@@ -1098,32 +1098,32 @@ local block_state deflate_stored(s, flush)
|
||||
if (s->lookahead <= 1) {
|
||||
|
||||
Assert(s->strstart < s->w_size+MAX_DIST(s) ||
|
||||
s->block_start >= (long)s->w_size, "slide too late");
|
||||
s->block_start >= (long)s->w_size, "slide too late");
|
||||
|
||||
fill_window(s);
|
||||
if (s->lookahead == 0 && flush == Z_NO_FLUSH) return need_more;
|
||||
|
||||
if (s->lookahead == 0) break; /* flush the current block */
|
||||
}
|
||||
Assert(s->block_start >= 0L, "block gone");
|
||||
Assert(s->block_start >= 0L, "block gone");
|
||||
|
||||
s->strstart += s->lookahead;
|
||||
s->lookahead = 0;
|
||||
s->strstart += s->lookahead;
|
||||
s->lookahead = 0;
|
||||
|
||||
/* Emit a stored block if pending_buf will be full: */
|
||||
max_start = s->block_start + max_block_size;
|
||||
/* Emit a stored block if pending_buf will be full: */
|
||||
max_start = s->block_start + max_block_size;
|
||||
if (s->strstart == 0 || (ulg)s->strstart >= max_start) {
|
||||
/* strstart == 0 is possible when wraparound on 16-bit machine */
|
||||
s->lookahead = (uInt)(s->strstart - max_start);
|
||||
s->strstart = (uInt)max_start;
|
||||
/* strstart == 0 is possible when wraparound on 16-bit machine */
|
||||
s->lookahead = (uInt)(s->strstart - max_start);
|
||||
s->strstart = (uInt)max_start;
|
||||
FLUSH_BLOCK(s, 0);
|
||||
}
|
||||
/* Flush if we may have to slide, otherwise block_start may become
|
||||
}
|
||||
/* Flush if we may have to slide, otherwise block_start may become
|
||||
* negative and the data will be gone:
|
||||
*/
|
||||
if (s->strstart - (uInt)s->block_start >= MAX_DIST(s)) {
|
||||
FLUSH_BLOCK(s, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
FLUSH_BLOCK(s, flush == Z_FINISH);
|
||||
return flush == Z_FINISH ? finish_done : block_done;
|
||||
@@ -1152,8 +1152,8 @@ local block_state deflate_fast(s, flush)
|
||||
if (s->lookahead < MIN_LOOKAHEAD) {
|
||||
fill_window(s);
|
||||
if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
|
||||
return need_more;
|
||||
}
|
||||
return need_more;
|
||||
}
|
||||
if (s->lookahead == 0) break; /* flush the current block */
|
||||
}
|
||||
|
||||
@@ -1199,10 +1199,10 @@ local block_state deflate_fast(s, flush)
|
||||
* always MIN_MATCH bytes ahead.
|
||||
*/
|
||||
} while (--s->match_length != 0);
|
||||
s->strstart++;
|
||||
s->strstart++;
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
{
|
||||
s->strstart += s->match_length;
|
||||
s->match_length = 0;
|
||||
s->ins_h = s->window[s->strstart];
|
||||
@@ -1219,7 +1219,7 @@ local block_state deflate_fast(s, flush)
|
||||
Tracevv((stderr,"%c", s->window[s->strstart]));
|
||||
_tr_tally_lit (s, s->window[s->strstart], bflush);
|
||||
s->lookahead--;
|
||||
s->strstart++;
|
||||
s->strstart++;
|
||||
}
|
||||
if (bflush) FLUSH_BLOCK(s, 0);
|
||||
}
|
||||
@@ -1249,8 +1249,8 @@ local block_state deflate_slow(s, flush)
|
||||
if (s->lookahead < MIN_LOOKAHEAD) {
|
||||
fill_window(s);
|
||||
if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
|
||||
return need_more;
|
||||
}
|
||||
return need_more;
|
||||
}
|
||||
if (s->lookahead == 0) break; /* flush the current block */
|
||||
}
|
||||
|
||||
@@ -1297,7 +1297,7 @@ local block_state deflate_slow(s, flush)
|
||||
check_match(s, s->strstart-1, s->prev_match, s->prev_length);
|
||||
|
||||
_tr_tally_dist(s, s->strstart -1 - s->prev_match,
|
||||
s->prev_length - MIN_MATCH, bflush);
|
||||
s->prev_length - MIN_MATCH, bflush);
|
||||
|
||||
/* Insert in hash table all strings up to the end of the match.
|
||||
* strstart-1 and strstart are already inserted. If there is not
|
||||
@@ -1323,8 +1323,8 @@ local block_state deflate_slow(s, flush)
|
||||
* is longer, truncate the previous match to a single literal.
|
||||
*/
|
||||
Tracevv((stderr,"%c", s->window[s->strstart-1]));
|
||||
_tr_tally_lit(s, s->window[s->strstart-1], bflush);
|
||||
if (bflush) {
|
||||
_tr_tally_lit(s, s->window[s->strstart-1], bflush);
|
||||
if (bflush) {
|
||||
FLUSH_BLOCK_ONLY(s, 0);
|
||||
}
|
||||
s->strstart++;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* deflate.h -- internal compression state
|
||||
* Copyright (C) 1995-2002 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
|
||||
@@ -269,7 +269,7 @@ typedef struct internal_state {
|
||||
void _tr_init OF((deflate_state *s));
|
||||
int _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc));
|
||||
void _tr_flush_block OF((deflate_state *s, charf *buf, ulg stored_len,
|
||||
int eof));
|
||||
int eof));
|
||||
void _tr_align OF((deflate_state *s));
|
||||
void _tr_stored_block OF((deflate_state *s, charf *buf, ulg stored_len,
|
||||
int eof));
|
||||
@@ -312,7 +312,7 @@ void _tr_stored_block OF((deflate_state *s, charf *buf, ulg stored_len,
|
||||
#else
|
||||
# define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c)
|
||||
# define _tr_tally_dist(s, distance, length, flush) \
|
||||
flush = _tr_tally(s, distance, length)
|
||||
flush = _tr_tally(s, distance, length)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* example.c -- usage example of the zlib compression library
|
||||
* Copyright (C) 1995-2002 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$ */
|
||||
@@ -37,22 +37,22 @@ const char dictionary[] = "hello";
|
||||
uLong dictId; /* Adler32 value of the dictionary */
|
||||
|
||||
void test_compress OF((Byte *compr, uLong comprLen,
|
||||
Byte *uncompr, uLong uncomprLen));
|
||||
void test_gzio OF((const char *out, const char *in,
|
||||
Byte *uncompr, int uncomprLen));
|
||||
Byte *uncompr, uLong uncomprLen));
|
||||
void test_gzio OF((const char *out, const char *in,
|
||||
Byte *uncompr, int uncomprLen));
|
||||
void test_deflate OF((Byte *compr, uLong comprLen));
|
||||
void test_inflate OF((Byte *compr, uLong comprLen,
|
||||
Byte *uncompr, uLong uncomprLen));
|
||||
Byte *uncompr, uLong uncomprLen));
|
||||
void test_large_deflate OF((Byte *compr, uLong comprLen,
|
||||
Byte *uncompr, uLong uncomprLen));
|
||||
Byte *uncompr, uLong uncomprLen));
|
||||
void test_large_inflate OF((Byte *compr, uLong comprLen,
|
||||
Byte *uncompr, uLong uncomprLen));
|
||||
Byte *uncompr, uLong uncomprLen));
|
||||
void test_flush OF((Byte *compr, uLong *comprLen));
|
||||
void test_sync OF((Byte *compr, uLong comprLen,
|
||||
Byte *uncompr, uLong uncomprLen));
|
||||
Byte *uncompr, uLong uncomprLen));
|
||||
void test_dict_deflate OF((Byte *compr, uLong comprLen));
|
||||
void test_dict_inflate OF((Byte *compr, uLong comprLen,
|
||||
Byte *uncompr, uLong uncomprLen));
|
||||
Byte *uncompr, uLong uncomprLen));
|
||||
int main OF((int argc, char *argv[]));
|
||||
|
||||
/* ===========================================================================
|
||||
@@ -75,7 +75,7 @@ void test_compress(compr, comprLen, uncompr, uncomprLen)
|
||||
|
||||
if (strcmp((char*)uncompr, hello)) {
|
||||
fprintf(stderr, "bad uncompress\n");
|
||||
exit(1);
|
||||
exit(1);
|
||||
} else {
|
||||
printf("uncompress(): %s\n", (char *)uncompr);
|
||||
}
|
||||
@@ -103,11 +103,11 @@ void test_gzio(out, in, uncompr, uncomprLen)
|
||||
gzputc(file, 'h');
|
||||
if (gzputs(file, "ello") != 4) {
|
||||
fprintf(stderr, "gzputs err: %s\n", gzerror(file, &err));
|
||||
exit(1);
|
||||
exit(1);
|
||||
}
|
||||
if (gzprintf(file, ", %s!", "hello") != 8) {
|
||||
fprintf(stderr, "gzprintf err: %s\n", gzerror(file, &err));
|
||||
exit(1);
|
||||
exit(1);
|
||||
}
|
||||
gzseek(file, 1L, SEEK_CUR); /* add one zero byte */
|
||||
gzclose(file);
|
||||
@@ -121,36 +121,36 @@ void test_gzio(out, in, uncompr, uncomprLen)
|
||||
uncomprLen = gzread(file, uncompr, (unsigned)uncomprLen);
|
||||
if (uncomprLen != len) {
|
||||
fprintf(stderr, "gzread err: %s\n", gzerror(file, &err));
|
||||
exit(1);
|
||||
exit(1);
|
||||
}
|
||||
if (strcmp((char*)uncompr, hello)) {
|
||||
fprintf(stderr, "bad gzread: %s\n", (char*)uncompr);
|
||||
exit(1);
|
||||
exit(1);
|
||||
} else {
|
||||
printf("gzread(): %s\n", (char *)uncompr);
|
||||
}
|
||||
|
||||
pos = gzseek(file, -8L, SEEK_CUR);
|
||||
if (pos != 6 || gztell(file) != pos) {
|
||||
fprintf(stderr, "gzseek error, pos=%ld, gztell=%ld\n",
|
||||
(long)pos, (long)gztell(file));
|
||||
exit(1);
|
||||
fprintf(stderr, "gzseek error, pos=%ld, gztell=%ld\n",
|
||||
(long)pos, (long)gztell(file));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (gzgetc(file) != ' ') {
|
||||
fprintf(stderr, "gzgetc error\n");
|
||||
exit(1);
|
||||
fprintf(stderr, "gzgetc error\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
gzgets(file, (char*)uncompr, uncomprLen);
|
||||
uncomprLen = strlen((char*)uncompr);
|
||||
if (uncomprLen != 6) { /* "hello!" */
|
||||
fprintf(stderr, "gzgets err after gzseek: %s\n", gzerror(file, &err));
|
||||
exit(1);
|
||||
exit(1);
|
||||
}
|
||||
if (strcmp((char*)uncompr, hello+7)) {
|
||||
fprintf(stderr, "bad gzgets after gzseek\n");
|
||||
exit(1);
|
||||
exit(1);
|
||||
} else {
|
||||
printf("gzgets() after gzseek: %s\n", (char *)uncompr);
|
||||
}
|
||||
@@ -231,7 +231,7 @@ void test_inflate(compr, comprLen, uncompr, uncomprLen)
|
||||
|
||||
if (strcmp((char*)uncompr, hello)) {
|
||||
fprintf(stderr, "bad inflate\n");
|
||||
exit(1);
|
||||
exit(1);
|
||||
} else {
|
||||
printf("inflate(): %s\n", (char *)uncompr);
|
||||
}
|
||||
@@ -266,7 +266,7 @@ void test_large_deflate(compr, comprLen, uncompr, uncomprLen)
|
||||
CHECK_ERR(err, "deflate");
|
||||
if (c_stream.avail_in != 0) {
|
||||
fprintf(stderr, "deflate not greedy\n");
|
||||
exit(1);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* Feed in already compressed data and switch to no compression: */
|
||||
@@ -286,7 +286,7 @@ void test_large_deflate(compr, comprLen, uncompr, uncomprLen)
|
||||
err = deflate(&c_stream, Z_FINISH);
|
||||
if (err != Z_STREAM_END) {
|
||||
fprintf(stderr, "deflate should report Z_STREAM_END\n");
|
||||
exit(1);
|
||||
exit(1);
|
||||
}
|
||||
err = deflateEnd(&c_stream);
|
||||
CHECK_ERR(err, "deflateEnd");
|
||||
@@ -316,7 +316,7 @@ void test_large_inflate(compr, comprLen, uncompr, uncomprLen)
|
||||
|
||||
for (;;) {
|
||||
d_stream.next_out = uncompr; /* discard the output */
|
||||
d_stream.avail_out = (uInt)uncomprLen;
|
||||
d_stream.avail_out = (uInt)uncomprLen;
|
||||
err = inflate(&d_stream, Z_NO_FLUSH);
|
||||
if (err == Z_STREAM_END) break;
|
||||
CHECK_ERR(err, "large inflate");
|
||||
@@ -327,7 +327,7 @@ void test_large_inflate(compr, comprLen, uncompr, uncomprLen)
|
||||
|
||||
if (d_stream.total_out != 2*uncomprLen + comprLen/2) {
|
||||
fprintf(stderr, "bad large inflate: %ld\n", d_stream.total_out);
|
||||
exit(1);
|
||||
exit(1);
|
||||
} else {
|
||||
printf("large_inflate(): OK\n");
|
||||
}
|
||||
@@ -407,7 +407,7 @@ void test_sync(compr, comprLen, uncompr, uncomprLen)
|
||||
if (err != Z_DATA_ERROR) {
|
||||
fprintf(stderr, "inflate should report DATA_ERROR\n");
|
||||
/* Because of incorrect adler32 */
|
||||
exit(1);
|
||||
exit(1);
|
||||
}
|
||||
err = inflateEnd(&d_stream);
|
||||
CHECK_ERR(err, "inflateEnd");
|
||||
@@ -433,7 +433,7 @@ void test_dict_deflate(compr, comprLen)
|
||||
CHECK_ERR(err, "deflateInit");
|
||||
|
||||
err = deflateSetDictionary(&c_stream,
|
||||
(const Bytef*)dictionary, sizeof(dictionary));
|
||||
(const Bytef*)dictionary, sizeof(dictionary));
|
||||
CHECK_ERR(err, "deflateSetDictionary");
|
||||
|
||||
dictId = c_stream.adler;
|
||||
@@ -446,7 +446,7 @@ void test_dict_deflate(compr, comprLen)
|
||||
err = deflate(&c_stream, Z_FINISH);
|
||||
if (err != Z_STREAM_END) {
|
||||
fprintf(stderr, "deflate should report Z_STREAM_END\n");
|
||||
exit(1);
|
||||
exit(1);
|
||||
}
|
||||
err = deflateEnd(&c_stream);
|
||||
CHECK_ERR(err, "deflateEnd");
|
||||
@@ -480,14 +480,14 @@ void test_dict_inflate(compr, comprLen, uncompr, uncomprLen)
|
||||
for (;;) {
|
||||
err = inflate(&d_stream, Z_NO_FLUSH);
|
||||
if (err == Z_STREAM_END) break;
|
||||
if (err == Z_NEED_DICT) {
|
||||
if (d_stream.adler != dictId) {
|
||||
fprintf(stderr, "unexpected dictionary");
|
||||
exit(1);
|
||||
}
|
||||
err = inflateSetDictionary(&d_stream, (const Bytef*)dictionary,
|
||||
sizeof(dictionary));
|
||||
}
|
||||
if (err == Z_NEED_DICT) {
|
||||
if (d_stream.adler != dictId) {
|
||||
fprintf(stderr, "unexpected dictionary");
|
||||
exit(1);
|
||||
}
|
||||
err = inflateSetDictionary(&d_stream, (const Bytef*)dictionary,
|
||||
sizeof(dictionary));
|
||||
}
|
||||
CHECK_ERR(err, "inflate with dict");
|
||||
}
|
||||
|
||||
@@ -496,7 +496,7 @@ void test_dict_inflate(compr, comprLen, uncompr, uncomprLen)
|
||||
|
||||
if (strcmp((char*)uncompr, hello)) {
|
||||
fprintf(stderr, "bad inflate with dict\n");
|
||||
exit(1);
|
||||
exit(1);
|
||||
} else {
|
||||
printf("inflate with dictionary: %s\n", (char *)uncompr);
|
||||
}
|
||||
@@ -530,13 +530,13 @@ int main(argc, argv)
|
||||
*/
|
||||
if (compr == Z_NULL || uncompr == Z_NULL) {
|
||||
printf("out of memory\n");
|
||||
exit(1);
|
||||
exit(1);
|
||||
}
|
||||
test_compress(compr, comprLen, uncompr, uncomprLen);
|
||||
|
||||
test_gzio((argc > 1 ? argv[1] : TESTFILE),
|
||||
(argc > 2 ? argv[2] : TESTFILE),
|
||||
uncompr, (int)uncomprLen);
|
||||
uncompr, (int)uncomprLen);
|
||||
|
||||
test_deflate(compr, comprLen);
|
||||
test_inflate(compr, comprLen, uncompr, uncomprLen);
|
||||
|
||||
@@ -112,17 +112,17 @@ local gzFile gz_open (path, mode, fd)
|
||||
if (*p == 'r') s->mode = 'r';
|
||||
if (*p == 'w' || *p == 'a') s->mode = 'w';
|
||||
if (*p >= '0' && *p <= '9') {
|
||||
level = *p - '0';
|
||||
} else if (*p == 'f') {
|
||||
strategy = Z_FILTERED;
|
||||
} else if (*p == 'h') {
|
||||
strategy = Z_HUFFMAN_ONLY;
|
||||
} else {
|
||||
*m++ = *p; /* copy the mode */
|
||||
}
|
||||
level = *p - '0';
|
||||
} else if (*p == 'f') {
|
||||
strategy = Z_FILTERED;
|
||||
} else if (*p == 'h') {
|
||||
strategy = Z_HUFFMAN_ONLY;
|
||||
} else {
|
||||
*m++ = *p; /* copy the mode */
|
||||
}
|
||||
} while (*p++ && m != fmode + sizeof(fmode));
|
||||
if (s->mode == '\0') return destroy(s), (gzFile)Z_NULL;
|
||||
|
||||
|
||||
if (s->mode == 'w') {
|
||||
#ifdef NO_DEFLATE
|
||||
err = Z_STREAM_ERROR;
|
||||
@@ -163,17 +163,17 @@ local gzFile gz_open (path, mode, fd)
|
||||
*/
|
||||
fprintf(s->file, "%c%c%c%c%c%c%c%c%c%c", gz_magic[0], gz_magic[1],
|
||||
Z_DEFLATED, 0 /*flags*/, 0,0,0,0 /*time*/, 0 /*xflags*/, OS_CODE);
|
||||
s->startpos = 10L;
|
||||
/* We use 10L instead of ftell(s->file) to because ftell causes an
|
||||
s->startpos = 10L;
|
||||
/* We use 10L instead of ftell(s->file) to because ftell causes an
|
||||
* fflush on some systems. This version of the library doesn't use
|
||||
* startpos anyway in write mode, so this initialization is not
|
||||
* necessary.
|
||||
*/
|
||||
} else {
|
||||
check_header(s); /* skip the .gz header */
|
||||
s->startpos = (ftell(s->file) - s->stream.avail_in);
|
||||
check_header(s); /* skip the .gz header */
|
||||
s->startpos = (ftell(s->file) - s->stream.avail_in);
|
||||
}
|
||||
|
||||
|
||||
return (gzFile)s;
|
||||
}
|
||||
|
||||
@@ -218,11 +218,11 @@ int ZEXPORT gzsetparams (file, level, strategy)
|
||||
/* Make room to allow flushing */
|
||||
if (s->stream.avail_out == 0) {
|
||||
|
||||
s->stream.next_out = s->outbuf;
|
||||
if (fwrite(s->outbuf, 1, Z_BUFSIZE, s->file) != Z_BUFSIZE) {
|
||||
s->z_err = Z_ERRNO;
|
||||
}
|
||||
s->stream.avail_out = Z_BUFSIZE;
|
||||
s->stream.next_out = s->outbuf;
|
||||
if (fwrite(s->outbuf, 1, Z_BUFSIZE, s->file) != Z_BUFSIZE) {
|
||||
s->z_err = Z_ERRNO;
|
||||
}
|
||||
s->stream.avail_out = Z_BUFSIZE;
|
||||
}
|
||||
|
||||
return deflateParams (&(s->stream), level, strategy);
|
||||
@@ -238,14 +238,14 @@ local int get_byte(s)
|
||||
{
|
||||
if (s->z_eof) return EOF;
|
||||
if (s->stream.avail_in == 0) {
|
||||
errno = 0;
|
||||
s->stream.avail_in = fread(s->inbuf, 1, Z_BUFSIZE, s->file);
|
||||
if (s->stream.avail_in == 0) {
|
||||
s->z_eof = 1;
|
||||
if (ferror(s->file)) s->z_err = Z_ERRNO;
|
||||
return EOF;
|
||||
}
|
||||
s->stream.next_in = s->inbuf;
|
||||
errno = 0;
|
||||
s->stream.avail_in = fread(s->inbuf, 1, Z_BUFSIZE, s->file);
|
||||
if (s->stream.avail_in == 0) {
|
||||
s->z_eof = 1;
|
||||
if (ferror(s->file)) s->z_err = Z_ERRNO;
|
||||
return EOF;
|
||||
}
|
||||
s->stream.next_in = s->inbuf;
|
||||
}
|
||||
s->stream.avail_in--;
|
||||
return *(s->stream.next_in)++;
|
||||
@@ -270,41 +270,41 @@ local void check_header(s)
|
||||
|
||||
/* Check the gzip magic header */
|
||||
for (len = 0; len < 2; len++) {
|
||||
c = get_byte(s);
|
||||
if (c != gz_magic[len]) {
|
||||
if (len != 0) s->stream.avail_in++, s->stream.next_in--;
|
||||
if (c != EOF) {
|
||||
s->stream.avail_in++, s->stream.next_in--;
|
||||
s->transparent = 1;
|
||||
}
|
||||
s->z_err = s->stream.avail_in != 0 ? Z_OK : Z_STREAM_END;
|
||||
return;
|
||||
}
|
||||
c = get_byte(s);
|
||||
if (c != gz_magic[len]) {
|
||||
if (len != 0) s->stream.avail_in++, s->stream.next_in--;
|
||||
if (c != EOF) {
|
||||
s->stream.avail_in++, s->stream.next_in--;
|
||||
s->transparent = 1;
|
||||
}
|
||||
s->z_err = s->stream.avail_in != 0 ? Z_OK : Z_STREAM_END;
|
||||
return;
|
||||
}
|
||||
}
|
||||
method = get_byte(s);
|
||||
flags = get_byte(s);
|
||||
if (method != Z_DEFLATED || (flags & RESERVED) != 0) {
|
||||
s->z_err = Z_DATA_ERROR;
|
||||
return;
|
||||
s->z_err = Z_DATA_ERROR;
|
||||
return;
|
||||
}
|
||||
|
||||
/* Discard time, xflags and OS code: */
|
||||
for (len = 0; len < 6; len++) (void)get_byte(s);
|
||||
|
||||
if ((flags & EXTRA_FIELD) != 0) { /* skip the extra field */
|
||||
len = (uInt)get_byte(s);
|
||||
len += ((uInt)get_byte(s))<<8;
|
||||
/* len is garbage if EOF but the loop below will quit anyway */
|
||||
while (len-- != 0 && get_byte(s) != EOF) ;
|
||||
len = (uInt)get_byte(s);
|
||||
len += ((uInt)get_byte(s))<<8;
|
||||
/* len is garbage if EOF but the loop below will quit anyway */
|
||||
while (len-- != 0 && get_byte(s) != EOF) ;
|
||||
}
|
||||
if ((flags & ORIG_NAME) != 0) { /* skip the original file name */
|
||||
while ((c = get_byte(s)) != 0 && c != EOF) ;
|
||||
while ((c = get_byte(s)) != 0 && c != EOF) ;
|
||||
}
|
||||
if ((flags & COMMENT) != 0) { /* skip the .gz file comment */
|
||||
while ((c = get_byte(s)) != 0 && c != EOF) ;
|
||||
while ((c = get_byte(s)) != 0 && c != EOF) ;
|
||||
}
|
||||
if ((flags & HEAD_CRC) != 0) { /* skip the header crc */
|
||||
for (len = 0; len < 2; len++) (void)get_byte(s);
|
||||
for (len = 0; len < 2; len++) (void)get_byte(s);
|
||||
}
|
||||
s->z_err = s->z_eof ? Z_DATA_ERROR : Z_OK;
|
||||
}
|
||||
@@ -323,21 +323,21 @@ local int destroy (s)
|
||||
TRYFREE(s->msg);
|
||||
|
||||
if (s->stream.state != NULL) {
|
||||
if (s->mode == 'w') {
|
||||
if (s->mode == 'w') {
|
||||
#ifdef NO_DEFLATE
|
||||
err = Z_STREAM_ERROR;
|
||||
err = Z_STREAM_ERROR;
|
||||
#else
|
||||
err = deflateEnd(&(s->stream));
|
||||
err = deflateEnd(&(s->stream));
|
||||
#endif
|
||||
} else if (s->mode == 'r') {
|
||||
err = inflateEnd(&(s->stream));
|
||||
}
|
||||
} else if (s->mode == 'r') {
|
||||
err = inflateEnd(&(s->stream));
|
||||
}
|
||||
}
|
||||
if (s->file != NULL && fclose(s->file)) {
|
||||
#ifdef ESPIPE
|
||||
if (errno != ESPIPE) /* fclose is broken for pipes in HP/UX */
|
||||
if (errno != ESPIPE) /* fclose is broken for pipes in HP/UX */
|
||||
#endif
|
||||
err = Z_ERRNO;
|
||||
err = Z_ERRNO;
|
||||
}
|
||||
if (s->z_err < 0) err = s->z_err;
|
||||
|
||||
@@ -372,69 +372,69 @@ int ZEXPORT gzread (file, buf, len)
|
||||
|
||||
while (s->stream.avail_out != 0) {
|
||||
|
||||
if (s->transparent) {
|
||||
/* Copy first the lookahead bytes: */
|
||||
uInt n = s->stream.avail_in;
|
||||
if (n > s->stream.avail_out) n = s->stream.avail_out;
|
||||
if (n > 0) {
|
||||
zmemcpy(s->stream.next_out, s->stream.next_in, n);
|
||||
next_out += n;
|
||||
s->stream.next_out = next_out;
|
||||
s->stream.next_in += n;
|
||||
s->stream.avail_out -= n;
|
||||
s->stream.avail_in -= n;
|
||||
}
|
||||
if (s->stream.avail_out > 0) {
|
||||
s->stream.avail_out -= fread(next_out, 1, s->stream.avail_out,
|
||||
s->file);
|
||||
}
|
||||
len -= s->stream.avail_out;
|
||||
s->stream.total_in += (uLong)len;
|
||||
s->stream.total_out += (uLong)len;
|
||||
if (s->transparent) {
|
||||
/* Copy first the lookahead bytes: */
|
||||
uInt n = s->stream.avail_in;
|
||||
if (n > s->stream.avail_out) n = s->stream.avail_out;
|
||||
if (n > 0) {
|
||||
zmemcpy(s->stream.next_out, s->stream.next_in, n);
|
||||
next_out += n;
|
||||
s->stream.next_out = next_out;
|
||||
s->stream.next_in += n;
|
||||
s->stream.avail_out -= n;
|
||||
s->stream.avail_in -= n;
|
||||
}
|
||||
if (s->stream.avail_out > 0) {
|
||||
s->stream.avail_out -= fread(next_out, 1, s->stream.avail_out,
|
||||
s->file);
|
||||
}
|
||||
len -= s->stream.avail_out;
|
||||
s->stream.total_in += (uLong)len;
|
||||
s->stream.total_out += (uLong)len;
|
||||
if (len == 0) s->z_eof = 1;
|
||||
return (int)len;
|
||||
}
|
||||
return (int)len;
|
||||
}
|
||||
if (s->stream.avail_in == 0 && !s->z_eof) {
|
||||
|
||||
errno = 0;
|
||||
s->stream.avail_in = fread(s->inbuf, 1, Z_BUFSIZE, s->file);
|
||||
if (s->stream.avail_in == 0) {
|
||||
s->z_eof = 1;
|
||||
if (ferror(s->file)) {
|
||||
s->z_err = Z_ERRNO;
|
||||
break;
|
||||
}
|
||||
if (ferror(s->file)) {
|
||||
s->z_err = Z_ERRNO;
|
||||
break;
|
||||
}
|
||||
}
|
||||
s->stream.next_in = s->inbuf;
|
||||
}
|
||||
s->z_err = inflate(&(s->stream), Z_NO_FLUSH);
|
||||
|
||||
if (s->z_err == Z_STREAM_END) {
|
||||
/* Check CRC and original size */
|
||||
s->crc = crc32(s->crc, start, (uInt)(s->stream.next_out - start));
|
||||
start = s->stream.next_out;
|
||||
if (s->z_err == Z_STREAM_END) {
|
||||
/* Check CRC and original size */
|
||||
s->crc = crc32(s->crc, start, (uInt)(s->stream.next_out - start));
|
||||
start = s->stream.next_out;
|
||||
|
||||
if (getLong(s) != s->crc) {
|
||||
s->z_err = Z_DATA_ERROR;
|
||||
} else {
|
||||
(void)getLong(s);
|
||||
if (getLong(s) != s->crc) {
|
||||
s->z_err = Z_DATA_ERROR;
|
||||
} else {
|
||||
(void)getLong(s);
|
||||
/* The uncompressed length returned by above getlong() may
|
||||
* be different from s->stream.total_out) in case of
|
||||
* concatenated .gz files. Check for such files:
|
||||
*/
|
||||
check_header(s);
|
||||
if (s->z_err == Z_OK) {
|
||||
uLong total_in = s->stream.total_in;
|
||||
uLong total_out = s->stream.total_out;
|
||||
* concatenated .gz files. Check for such files:
|
||||
*/
|
||||
check_header(s);
|
||||
if (s->z_err == Z_OK) {
|
||||
uLong total_in = s->stream.total_in;
|
||||
uLong total_out = s->stream.total_out;
|
||||
|
||||
inflateReset(&(s->stream));
|
||||
s->stream.total_in = total_in;
|
||||
s->stream.total_out = total_out;
|
||||
s->crc = crc32(0L, Z_NULL, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (s->z_err != Z_OK || s->z_eof) break;
|
||||
inflateReset(&(s->stream));
|
||||
s->stream.total_in = total_in;
|
||||
s->stream.total_out = total_out;
|
||||
s->crc = crc32(0L, Z_NULL, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (s->z_err != Z_OK || s->z_eof) break;
|
||||
}
|
||||
s->crc = crc32(s->crc, start, (uInt)(s->stream.next_out - start));
|
||||
|
||||
@@ -543,21 +543,21 @@ int ZEXPORTVA gzprintf (gzFile file, const char *format, /* args */ ...)
|
||||
#else /* not ANSI C */
|
||||
|
||||
int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
|
||||
a11, a12, a13, a14, a15, a16, a17, a18, a19, a20)
|
||||
a11, a12, a13, a14, a15, a16, a17, a18, a19, a20)
|
||||
gzFile file;
|
||||
const char *format;
|
||||
int a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
|
||||
a11, a12, a13, a14, a15, a16, a17, a18, a19, a20;
|
||||
a11, a12, a13, a14, a15, a16, a17, a18, a19, a20;
|
||||
{
|
||||
char buf[Z_PRINTF_BUFSIZE];
|
||||
int len;
|
||||
|
||||
#ifdef HAS_snprintf
|
||||
snprintf(buf, sizeof(buf), format, a1, a2, a3, a4, a5, a6, a7, a8,
|
||||
a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
|
||||
a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
|
||||
#else
|
||||
sprintf(buf, format, a1, a2, a3, a4, a5, a6, a7, a8,
|
||||
a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
|
||||
a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
|
||||
#endif
|
||||
len = strlen(buf); /* old sprintf doesn't return the nb of bytes written */
|
||||
if (len <= 0) return 0;
|
||||
@@ -623,14 +623,14 @@ local int do_flush (file, flush)
|
||||
if (done) break;
|
||||
s->z_err = deflate(&(s->stream), flush);
|
||||
|
||||
/* Ignore the second of two consecutive flushes: */
|
||||
if (len == 0 && s->z_err == Z_BUF_ERROR) s->z_err = Z_OK;
|
||||
/* Ignore the second of two consecutive flushes: */
|
||||
if (len == 0 && s->z_err == Z_BUF_ERROR) s->z_err = Z_OK;
|
||||
|
||||
/* deflate has finished flushing only when it hasn't used up
|
||||
* all the available space in the output buffer:
|
||||
* all the available space in the output buffer:
|
||||
*/
|
||||
done = (s->stream.avail_out != 0 || s->z_err == Z_STREAM_END);
|
||||
|
||||
|
||||
if (s->z_err != Z_OK && s->z_err != Z_STREAM_END) break;
|
||||
}
|
||||
return s->z_err == Z_STREAM_END ? Z_OK : s->z_err;
|
||||
@@ -665,84 +665,84 @@ z_off_t ZEXPORT gzseek (file, offset, whence)
|
||||
gz_stream *s = (gz_stream*)file;
|
||||
|
||||
if (s == NULL || whence == SEEK_END ||
|
||||
s->z_err == Z_ERRNO || s->z_err == Z_DATA_ERROR) {
|
||||
return -1L;
|
||||
s->z_err == Z_ERRNO || s->z_err == Z_DATA_ERROR) {
|
||||
return -1L;
|
||||
}
|
||||
|
||||
|
||||
if (s->mode == 'w') {
|
||||
#ifdef NO_DEFLATE
|
||||
return -1L;
|
||||
return -1L;
|
||||
#else
|
||||
if (whence == SEEK_SET) {
|
||||
offset -= s->stream.total_in;
|
||||
}
|
||||
if (offset < 0) return -1L;
|
||||
if (whence == SEEK_SET) {
|
||||
offset -= s->stream.total_in;
|
||||
}
|
||||
if (offset < 0) return -1L;
|
||||
|
||||
/* At this point, offset is the number of zero bytes to write. */
|
||||
if (s->inbuf == Z_NULL) {
|
||||
s->inbuf = (Byte*)ALLOC(Z_BUFSIZE); /* for seeking */
|
||||
zmemzero(s->inbuf, Z_BUFSIZE);
|
||||
}
|
||||
while (offset > 0) {
|
||||
uInt size = Z_BUFSIZE;
|
||||
if (offset < Z_BUFSIZE) size = (uInt)offset;
|
||||
/* At this point, offset is the number of zero bytes to write. */
|
||||
if (s->inbuf == Z_NULL) {
|
||||
s->inbuf = (Byte*)ALLOC(Z_BUFSIZE); /* for seeking */
|
||||
zmemzero(s->inbuf, Z_BUFSIZE);
|
||||
}
|
||||
while (offset > 0) {
|
||||
uInt size = Z_BUFSIZE;
|
||||
if (offset < Z_BUFSIZE) size = (uInt)offset;
|
||||
|
||||
size = gzwrite(file, s->inbuf, size);
|
||||
if (size == 0) return -1L;
|
||||
size = gzwrite(file, s->inbuf, size);
|
||||
if (size == 0) return -1L;
|
||||
|
||||
offset -= size;
|
||||
}
|
||||
return (z_off_t)s->stream.total_in;
|
||||
offset -= size;
|
||||
}
|
||||
return (z_off_t)s->stream.total_in;
|
||||
#endif
|
||||
}
|
||||
/* Rest of function is for reading only */
|
||||
|
||||
/* compute absolute position */
|
||||
if (whence == SEEK_CUR) {
|
||||
offset += s->stream.total_out;
|
||||
offset += s->stream.total_out;
|
||||
}
|
||||
if (offset < 0) return -1L;
|
||||
|
||||
if (s->transparent) {
|
||||
/* map to fseek */
|
||||
s->stream.avail_in = 0;
|
||||
s->stream.next_in = s->inbuf;
|
||||
/* map to fseek */
|
||||
s->stream.avail_in = 0;
|
||||
s->stream.next_in = s->inbuf;
|
||||
if (fseek(s->file, offset, SEEK_SET) < 0) return -1L;
|
||||
|
||||
s->stream.total_in = s->stream.total_out = (uLong)offset;
|
||||
return offset;
|
||||
s->stream.total_in = s->stream.total_out = (uLong)offset;
|
||||
return offset;
|
||||
}
|
||||
|
||||
/* For a negative seek, rewind and use positive seek */
|
||||
if ((uLong)offset >= s->stream.total_out) {
|
||||
offset -= s->stream.total_out;
|
||||
offset -= s->stream.total_out;
|
||||
} else if (gzrewind(file) < 0) {
|
||||
return -1L;
|
||||
return -1L;
|
||||
}
|
||||
/* offset is now the number of bytes to skip. */
|
||||
|
||||
if (offset != 0 && s->outbuf == Z_NULL) {
|
||||
s->outbuf = (Byte*)ALLOC(Z_BUFSIZE);
|
||||
s->outbuf = (Byte*)ALLOC(Z_BUFSIZE);
|
||||
}
|
||||
while (offset > 0) {
|
||||
int size = Z_BUFSIZE;
|
||||
if (offset < Z_BUFSIZE) size = (int)offset;
|
||||
int size = Z_BUFSIZE;
|
||||
if (offset < Z_BUFSIZE) size = (int)offset;
|
||||
|
||||
size = gzread(file, s->outbuf, (uInt)size);
|
||||
if (size <= 0) return -1L;
|
||||
offset -= size;
|
||||
size = gzread(file, s->outbuf, (uInt)size);
|
||||
if (size <= 0) return -1L;
|
||||
offset -= size;
|
||||
}
|
||||
return (z_off_t)s->stream.total_out;
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
Rewinds input file.
|
||||
Rewinds input file.
|
||||
*/
|
||||
int ZEXPORT gzrewind (file)
|
||||
gzFile file;
|
||||
{
|
||||
gz_stream *s = (gz_stream*)file;
|
||||
|
||||
|
||||
if (s == NULL || s->mode != 'r') return -1;
|
||||
|
||||
s->z_err = Z_OK;
|
||||
@@ -750,10 +750,10 @@ int ZEXPORT gzrewind (file)
|
||||
s->stream.avail_in = 0;
|
||||
s->stream.next_in = s->inbuf;
|
||||
s->crc = crc32(0L, Z_NULL, 0);
|
||||
|
||||
|
||||
if (s->startpos == 0) { /* not a compressed file */
|
||||
rewind(s->file);
|
||||
return 0;
|
||||
rewind(s->file);
|
||||
return 0;
|
||||
}
|
||||
|
||||
(void) inflateReset(&s->stream);
|
||||
@@ -779,7 +779,7 @@ int ZEXPORT gzeof (file)
|
||||
gzFile file;
|
||||
{
|
||||
gz_stream *s = (gz_stream*)file;
|
||||
|
||||
|
||||
return (s == NULL || s->mode != 'r') ? 0 : s->z_eof;
|
||||
}
|
||||
|
||||
@@ -829,7 +829,7 @@ int ZEXPORT gzclose (file)
|
||||
|
||||
if (s->mode == 'w') {
|
||||
#ifdef NO_DEFLATE
|
||||
return Z_STREAM_ERROR;
|
||||
return Z_STREAM_ERROR;
|
||||
#else
|
||||
err = do_flush (file, Z_FINISH);
|
||||
if (err != Z_OK) return destroy((gz_stream*)file);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* infblock.c -- interpret and process block types to last block
|
||||
* Copyright (C) 1995-2002 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
#include "zutil.h"
|
||||
@@ -393,7 +393,7 @@ uInt n;
|
||||
|
||||
|
||||
/* Returns true if inflate is currently at the end of a block generated
|
||||
* by Z_SYNC_FLUSH or Z_FULL_FLUSH.
|
||||
* by Z_SYNC_FLUSH or Z_FULL_FLUSH.
|
||||
* IN assertion: s != Z_NULL
|
||||
*/
|
||||
int inflate_blocks_sync_point(s)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* infblock.h -- header to use infblock.c
|
||||
* Copyright (C) 1995-2002 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* WARNING: this file should *not* be used by applications. It is
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* infcodes.c -- process literals and length/distance pairs
|
||||
* Copyright (C) 1995-2002 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
#include "zutil.h"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* infcodes.h -- header to use infcodes.c
|
||||
* Copyright (C) 1995-2002 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* WARNING: this file should *not* be used by applications. It is
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* inffast.c -- process literals and length/distance pairs fast
|
||||
* Copyright (C) 1995-2002 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
#include "zutil.h"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* inffast.h -- header to use inffast.c
|
||||
* Copyright (C) 1995-2002 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* WARNING: this file should *not* be used by applications. It is
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* inflate.c -- zlib interface to inflate modules
|
||||
* Copyright (C) 1995-2002 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
#include "zutil.h"
|
||||
@@ -44,7 +44,7 @@ struct internal_state {
|
||||
/* mode independent information */
|
||||
int nowrap; /* flag for no wrapper */
|
||||
uInt wbits; /* log2(window size) (8..15, defaults to 15) */
|
||||
inflate_blocks_statef
|
||||
inflate_blocks_statef
|
||||
*blocks; /* current inflate_blocks state */
|
||||
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* inftrees.c -- generate Huffman trees for efficient decoding
|
||||
* Copyright (C) 1995-2002 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
#include "zutil.h"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* inftrees.h -- header to use inftrees.c
|
||||
* Copyright (C) 1995-2002 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* WARNING: this file should *not* be used by applications. It is
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* inflate_util.c -- data and routines common to blocks and codes
|
||||
* Copyright (C) 1995-2002 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
#include "zutil.h"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* infutil.h -- types and macros common to blocks and codes
|
||||
* Copyright (C) 1995-2002 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* WARNING: this file should *not* be used by applications. It is
|
||||
@@ -41,7 +41,7 @@ struct inflate_blocks_state {
|
||||
inflate_huft *tb; /* bit length decoding tree */
|
||||
} trees; /* if DTREE, decoding info for trees */
|
||||
struct {
|
||||
inflate_codes_statef
|
||||
inflate_codes_statef
|
||||
*codes;
|
||||
} decode; /* if CODES, current state */
|
||||
} sub; /* submode */
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* maketree.c -- make inffixed.h table for decoding fixed codes
|
||||
* Copyright (C) 1995-2002 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
|
||||
*/
|
||||
|
||||
/* WARNING: this file should *not* be used by applications. It is
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* minigzip.c -- simulate gzip using the zlib compression library
|
||||
* Copyright (C) 1995-2002 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
|
||||
*/
|
||||
|
||||
/*
|
||||
@@ -147,7 +147,7 @@ int gz_compress_mmap(in, out)
|
||||
if (buf_len <= 0) return Z_ERRNO;
|
||||
|
||||
/* Now do the actual mmap: */
|
||||
buf = mmap((caddr_t) 0, buf_len, PROT_READ, MAP_SHARED, ifd, (off_t)0);
|
||||
buf = mmap((caddr_t) 0, buf_len, PROT_READ, MAP_SHARED, ifd, (off_t)0);
|
||||
if (buf == (caddr_t)(-1)) return Z_ERRNO;
|
||||
|
||||
/* Compress the whole file at once: */
|
||||
@@ -179,8 +179,8 @@ void gz_uncompress(in, out)
|
||||
if (len == 0) break;
|
||||
|
||||
if ((int)fwrite(buf, 1, (unsigned)len, out) != len) {
|
||||
error("failed fwrite");
|
||||
}
|
||||
error("failed fwrite");
|
||||
}
|
||||
}
|
||||
if (fclose(out)) error("failed fclose");
|
||||
|
||||
@@ -282,16 +282,16 @@ int main(argc, argv)
|
||||
|
||||
while (argc > 0) {
|
||||
if (strcmp(*argv, "-d") == 0)
|
||||
uncompr = 1;
|
||||
uncompr = 1;
|
||||
else if (strcmp(*argv, "-f") == 0)
|
||||
outmode[3] = 'f';
|
||||
outmode[3] = 'f';
|
||||
else if (strcmp(*argv, "-h") == 0)
|
||||
outmode[3] = 'h';
|
||||
outmode[3] = 'h';
|
||||
else if ((*argv)[0] == '-' && (*argv)[1] >= '1' && (*argv)[1] <= '9' &&
|
||||
(*argv)[2] == 0)
|
||||
outmode[2] = (*argv)[1];
|
||||
(*argv)[2] == 0)
|
||||
outmode[2] = (*argv)[1];
|
||||
else
|
||||
break;
|
||||
break;
|
||||
argc--, argv++;
|
||||
}
|
||||
if (argc == 0) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* trees.c -- output deflated data using Huffman coding
|
||||
* Copyright (C) 1995-2002 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
|
||||
*/
|
||||
|
||||
/*
|
||||
@@ -335,42 +335,42 @@ void gen_trees_header()
|
||||
|
||||
Assert (header != NULL, "Can't open trees.h");
|
||||
fprintf(header,
|
||||
"/* header created automatically with -DGEN_TREES_H */\n\n");
|
||||
"/* header created automatically with -DGEN_TREES_H */\n\n");
|
||||
|
||||
fprintf(header, "local const ct_data static_ltree[L_CODES+2] = {\n");
|
||||
for (i = 0; i < L_CODES+2; i++) {
|
||||
fprintf(header, "{{%3u},{%3u}}%s", static_ltree[i].Code,
|
||||
static_ltree[i].Len, SEPARATOR(i, L_CODES+1, 5));
|
||||
fprintf(header, "{{%3u},{%3u}}%s", static_ltree[i].Code,
|
||||
static_ltree[i].Len, SEPARATOR(i, L_CODES+1, 5));
|
||||
}
|
||||
|
||||
fprintf(header, "local const ct_data static_dtree[D_CODES] = {\n");
|
||||
for (i = 0; i < D_CODES; i++) {
|
||||
fprintf(header, "{{%2u},{%2u}}%s", static_dtree[i].Code,
|
||||
static_dtree[i].Len, SEPARATOR(i, D_CODES-1, 5));
|
||||
fprintf(header, "{{%2u},{%2u}}%s", static_dtree[i].Code,
|
||||
static_dtree[i].Len, SEPARATOR(i, D_CODES-1, 5));
|
||||
}
|
||||
|
||||
fprintf(header, "const uch _dist_code[DIST_CODE_LEN] = {\n");
|
||||
for (i = 0; i < DIST_CODE_LEN; i++) {
|
||||
fprintf(header, "%2u%s", _dist_code[i],
|
||||
SEPARATOR(i, DIST_CODE_LEN-1, 20));
|
||||
fprintf(header, "%2u%s", _dist_code[i],
|
||||
SEPARATOR(i, DIST_CODE_LEN-1, 20));
|
||||
}
|
||||
|
||||
fprintf(header, "const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {\n");
|
||||
for (i = 0; i < MAX_MATCH-MIN_MATCH+1; i++) {
|
||||
fprintf(header, "%2u%s", _length_code[i],
|
||||
SEPARATOR(i, MAX_MATCH-MIN_MATCH, 20));
|
||||
fprintf(header, "%2u%s", _length_code[i],
|
||||
SEPARATOR(i, MAX_MATCH-MIN_MATCH, 20));
|
||||
}
|
||||
|
||||
fprintf(header, "local const int base_length[LENGTH_CODES] = {\n");
|
||||
for (i = 0; i < LENGTH_CODES; i++) {
|
||||
fprintf(header, "%1u%s", base_length[i],
|
||||
SEPARATOR(i, LENGTH_CODES-1, 20));
|
||||
fprintf(header, "%1u%s", base_length[i],
|
||||
SEPARATOR(i, LENGTH_CODES-1, 20));
|
||||
}
|
||||
|
||||
fprintf(header, "local const int base_dist[D_CODES] = {\n");
|
||||
for (i = 0; i < D_CODES; i++) {
|
||||
fprintf(header, "%5u%s", base_dist[i],
|
||||
SEPARATOR(i, D_CODES-1, 10));
|
||||
fprintf(header, "%5u%s", base_dist[i],
|
||||
SEPARATOR(i, D_CODES-1, 10));
|
||||
}
|
||||
|
||||
fclose(header);
|
||||
@@ -930,39 +930,39 @@ void _tr_flush_block(s, buf, stored_len, eof)
|
||||
/* Build the Huffman trees unless a stored block is forced */
|
||||
if (s->level > 0) {
|
||||
|
||||
/* Check if the file is ascii or binary */
|
||||
if (s->data_type == Z_UNKNOWN) set_data_type(s);
|
||||
/* Check if the file is ascii or binary */
|
||||
if (s->data_type == Z_UNKNOWN) set_data_type(s);
|
||||
|
||||
/* Construct the literal and distance trees */
|
||||
build_tree(s, (tree_desc *)(&(s->l_desc)));
|
||||
Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len,
|
||||
s->static_len));
|
||||
/* Construct the literal and distance trees */
|
||||
build_tree(s, (tree_desc *)(&(s->l_desc)));
|
||||
Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len,
|
||||
s->static_len));
|
||||
|
||||
build_tree(s, (tree_desc *)(&(s->d_desc)));
|
||||
Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len,
|
||||
s->static_len));
|
||||
/* At this point, opt_len and static_len are the total bit lengths of
|
||||
* the compressed block data, excluding the tree representations.
|
||||
*/
|
||||
build_tree(s, (tree_desc *)(&(s->d_desc)));
|
||||
Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len,
|
||||
s->static_len));
|
||||
/* At this point, opt_len and static_len are the total bit lengths of
|
||||
* the compressed block data, excluding the tree representations.
|
||||
*/
|
||||
|
||||
/* Build the bit length tree for the above two trees, and get the index
|
||||
* in bl_order of the last bit length code to send.
|
||||
*/
|
||||
max_blindex = build_bl_tree(s);
|
||||
/* Build the bit length tree for the above two trees, and get the index
|
||||
* in bl_order of the last bit length code to send.
|
||||
*/
|
||||
max_blindex = build_bl_tree(s);
|
||||
|
||||
/* Determine the best encoding. Compute first the block length in bytes*/
|
||||
opt_lenb = (s->opt_len+3+7)>>3;
|
||||
static_lenb = (s->static_len+3+7)>>3;
|
||||
/* Determine the best encoding. Compute first the block length in bytes*/
|
||||
opt_lenb = (s->opt_len+3+7)>>3;
|
||||
static_lenb = (s->static_len+3+7)>>3;
|
||||
|
||||
Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ",
|
||||
opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,
|
||||
s->last_lit));
|
||||
Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ",
|
||||
opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,
|
||||
s->last_lit));
|
||||
|
||||
if (static_lenb <= opt_lenb) opt_lenb = static_lenb;
|
||||
if (static_lenb <= opt_lenb) opt_lenb = static_lenb;
|
||||
|
||||
} else {
|
||||
Assert(buf != (char*)0, "lost buf");
|
||||
opt_lenb = static_lenb = stored_len + 5; /* force a stored block */
|
||||
opt_lenb = static_lenb = stored_len + 5; /* force a stored block */
|
||||
}
|
||||
|
||||
#ifdef FORCE_STORED
|
||||
@@ -1199,7 +1199,7 @@ local void copy_block(s, buf, len, header)
|
||||
s->last_eob_len = 8; /* enough lookahead for inflate */
|
||||
|
||||
if (header) {
|
||||
put_short(s, (ush)len);
|
||||
put_short(s, (ush)len);
|
||||
put_short(s, (ush)~len);
|
||||
#ifdef DEBUG
|
||||
s->bits_sent += 2*16;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* uncompr.c -- decompress a memory buffer
|
||||
* Copyright (C) 1995-2002 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$ */
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* zconf.h -- configuration of the zlib compression library
|
||||
* Copyright (C) 1995-2002 Jean-loup Gailly.
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* @(#) $Id$ */
|
||||
@@ -13,39 +13,39 @@
|
||||
* compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
|
||||
*/
|
||||
#ifdef Z_PREFIX
|
||||
# define deflateInit_ z_deflateInit_
|
||||
# define deflate z_deflate
|
||||
# define deflateEnd z_deflateEnd
|
||||
# define inflateInit_ z_inflateInit_
|
||||
# define inflate z_inflate
|
||||
# define inflateEnd z_inflateEnd
|
||||
# define deflateInit2_ z_deflateInit2_
|
||||
# define deflateInit_ z_deflateInit_
|
||||
# define deflate z_deflate
|
||||
# define deflateEnd z_deflateEnd
|
||||
# define inflateInit_ z_inflateInit_
|
||||
# define inflate z_inflate
|
||||
# define inflateEnd z_inflateEnd
|
||||
# define deflateInit2_ z_deflateInit2_
|
||||
# define deflateSetDictionary z_deflateSetDictionary
|
||||
# define deflateCopy z_deflateCopy
|
||||
# define deflateReset z_deflateReset
|
||||
# define deflateParams z_deflateParams
|
||||
# define inflateInit2_ z_inflateInit2_
|
||||
# define deflateCopy z_deflateCopy
|
||||
# define deflateReset z_deflateReset
|
||||
# define deflateParams z_deflateParams
|
||||
# define inflateInit2_ z_inflateInit2_
|
||||
# define inflateSetDictionary z_inflateSetDictionary
|
||||
# define inflateSync z_inflateSync
|
||||
# define inflateSync z_inflateSync
|
||||
# define inflateSyncPoint z_inflateSyncPoint
|
||||
# define inflateReset z_inflateReset
|
||||
# define compress z_compress
|
||||
# define compress2 z_compress2
|
||||
# define uncompress z_uncompress
|
||||
# define adler32 z_adler32
|
||||
# define crc32 z_crc32
|
||||
# define inflateReset z_inflateReset
|
||||
# define compress z_compress
|
||||
# define compress2 z_compress2
|
||||
# define uncompress z_uncompress
|
||||
# define adler32 z_adler32
|
||||
# define crc32 z_crc32
|
||||
# define get_crc_table z_get_crc_table
|
||||
|
||||
# define Byte z_Byte
|
||||
# define uInt z_uInt
|
||||
# define uLong z_uLong
|
||||
# define Bytef z_Bytef
|
||||
# define charf z_charf
|
||||
# define intf z_intf
|
||||
# define uIntf z_uIntf
|
||||
# define uLongf z_uLongf
|
||||
# define voidpf z_voidpf
|
||||
# define voidp z_voidp
|
||||
# define Byte z_Byte
|
||||
# define uInt z_uInt
|
||||
# define uLong z_uLong
|
||||
# define Bytef z_Bytef
|
||||
# define charf z_charf
|
||||
# define intf z_intf
|
||||
# define uIntf z_uIntf
|
||||
# define uLongf z_uLongf
|
||||
# define voidpf z_voidpf
|
||||
# define voidp z_voidp
|
||||
#endif
|
||||
|
||||
#if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32)
|
||||
|
||||
@@ -39,7 +39,7 @@ extern "C" {
|
||||
|
||||
#define ZLIB_VERSION "1.1.4"
|
||||
|
||||
/*
|
||||
/*
|
||||
The 'zlib' compression library provides in-memory compression and
|
||||
decompression functions, including integrity checks of the uncompressed
|
||||
data. This version of the library supports only one compression method
|
||||
@@ -175,7 +175,7 @@ ZEXTERN const char * ZEXPORT zlibVersion OF((void));
|
||||
This check is automatically made by deflateInit and inflateInit.
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level));
|
||||
|
||||
Initializes the internal stream state for compression. The fields
|
||||
@@ -253,7 +253,7 @@ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
|
||||
more input data, until it returns with Z_STREAM_END or an error. After
|
||||
deflate has returned Z_STREAM_END, the only possible operations on the
|
||||
stream are deflateReset or deflateEnd.
|
||||
|
||||
|
||||
Z_FINISH can be used immediately after deflateInit if all the compression
|
||||
is to be done in a single step. In this case, avail_out must be at least
|
||||
0.1% larger than avail_in plus 12 bytes. If deflate does not return
|
||||
@@ -290,7 +290,7 @@ ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
/*
|
||||
ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm));
|
||||
|
||||
Initializes the internal stream state for decompression. The fields
|
||||
@@ -359,7 +359,7 @@ ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
|
||||
|
||||
If a preset dictionary is needed at this point (see inflateSetDictionary
|
||||
below), inflate sets strm-adler to the adler32 checksum of the
|
||||
dictionary chosen by the compressor and returns Z_NEED_DICT; otherwise
|
||||
dictionary chosen by the compressor and returns Z_NEED_DICT; otherwise
|
||||
it sets strm->adler to the adler32 checksum of all output produced
|
||||
so far (that is, total_out bytes) and returns Z_OK, Z_STREAM_END or
|
||||
an error code as described below. At the end of the stream, inflate()
|
||||
@@ -397,7 +397,7 @@ ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
|
||||
The following functions are needed only in some special applications.
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm,
|
||||
int level,
|
||||
int method,
|
||||
@@ -440,7 +440,7 @@ ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm,
|
||||
method). msg is set to null if there is no error message. deflateInit2 does
|
||||
not perform any compression: this will be done by deflate().
|
||||
*/
|
||||
|
||||
|
||||
ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
|
||||
const Bytef *dictionary,
|
||||
uInt dictLength));
|
||||
@@ -507,8 +507,8 @@ ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm));
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
|
||||
int level,
|
||||
int strategy));
|
||||
int level,
|
||||
int strategy));
|
||||
/*
|
||||
Dynamically update the compression level and compression strategy. The
|
||||
interpretation of level and strategy is as in deflateInit2. This can be
|
||||
@@ -527,7 +527,7 @@ ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
|
||||
if strm->avail_out was zero.
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm,
|
||||
int windowBits));
|
||||
|
||||
@@ -570,7 +570,7 @@ ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));
|
||||
/*
|
||||
/*
|
||||
Skips invalid compressed data until a full flush point (see above the
|
||||
description of deflate with Z_FULL_FLUSH) can be found, or until all
|
||||
available input is skipped. No output is provided.
|
||||
@@ -701,8 +701,8 @@ ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
|
||||
gzread returns the number of uncompressed bytes actually read (0 for
|
||||
end of file, -1 for error). */
|
||||
|
||||
ZEXTERN int ZEXPORT gzwrite OF((gzFile file,
|
||||
const voidp buf, unsigned len));
|
||||
ZEXTERN int ZEXPORT gzwrite OF((gzFile file,
|
||||
const voidp buf, unsigned len));
|
||||
/*
|
||||
Writes the given number of uncompressed bytes into the compressed file.
|
||||
gzwrite returns the number of uncompressed bytes actually written
|
||||
@@ -755,8 +755,8 @@ ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush));
|
||||
*/
|
||||
|
||||
ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file,
|
||||
z_off_t offset, int whence));
|
||||
/*
|
||||
z_off_t offset, int whence));
|
||||
/*
|
||||
Sets the starting position for the next gzread or gzwrite on the
|
||||
given compressed file. The offset represents a number of bytes in the
|
||||
uncompressed data stream. The whence parameter is defined as in lseek(2);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* inflate_util.c -- data and routines common to blocks and codes
|
||||
* Copyright (C) 1995-2002 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
#include "zutil.h"
|
||||
|
||||
@@ -208,7 +208,7 @@ extern const char *z_errmsg[10]; /* indexed by 2-zlib_error */
|
||||
|
||||
|
||||
typedef uLong (ZEXPORT *check_func) OF((uLong check, const Bytef *buf,
|
||||
uInt len));
|
||||
uInt len));
|
||||
voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size));
|
||||
void zcfree OF((voidpf opaque, voidpf ptr));
|
||||
|
||||
|
||||
@@ -20,5 +20,5 @@ DWORD WINAPI DllMain(HINSTANCE hInst, DWORD dwReason, LPVOID lpReserved)
|
||||
UNREFERENCED_PARAMETER(dwReason);
|
||||
UNREFERENCED_PARAMETER(lpReserved);
|
||||
|
||||
return TRUE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -12,151 +12,151 @@ char * GetPlainName(char * FileName)
|
||||
|
||||
void fixnamen(char *name, size_t len)
|
||||
{
|
||||
for (size_t i=0; i<len-3; i++) {
|
||||
if (i>0 && name[i]>='A' && name[i]<='Z' && isalpha(name[i-1]))
|
||||
{
|
||||
name[i] |= 0x20;
|
||||
} else if ((i==0 || !isalpha(name[i-1])) && name[i]>='a' && name[i]<='z')
|
||||
{
|
||||
name[i] &= ~0x20;
|
||||
}
|
||||
}
|
||||
for (size_t i=0; i<len-3; i++) {
|
||||
if (i>0 && name[i]>='A' && name[i]<='Z' && isalpha(name[i-1]))
|
||||
{
|
||||
name[i] |= 0x20;
|
||||
} else if ((i==0 || !isalpha(name[i-1])) && name[i]>='a' && name[i]<='z')
|
||||
{
|
||||
name[i] &= ~0x20;
|
||||
}
|
||||
}
|
||||
}
|
||||
void fixname2(char *name, size_t len)
|
||||
{
|
||||
for (size_t i=0; i<len-3; i++)
|
||||
{
|
||||
if(name[i] == ' ')
|
||||
name[i] = '_';
|
||||
}
|
||||
for (size_t i=0; i<len-3; i++)
|
||||
{
|
||||
if(name[i] == ' ')
|
||||
name[i] = '_';
|
||||
}
|
||||
}
|
||||
|
||||
ADTFile::ADTFile(char* filename): ADT(filename)
|
||||
{
|
||||
Adtfilename.append(filename);
|
||||
Adtfilename.append(filename);
|
||||
}
|
||||
|
||||
bool ADTFile::init(char *map_id)
|
||||
{
|
||||
|
||||
if(ADT.isEof ())
|
||||
return false;
|
||||
if(ADT.isEof ())
|
||||
return false;
|
||||
|
||||
size_t size;
|
||||
|
||||
string xMap;
|
||||
string yMap;
|
||||
|
||||
Adtfilename.erase(Adtfilename.find(".adt"),4);
|
||||
string TempMapNumber;
|
||||
TempMapNumber = Adtfilename.substr(Adtfilename.length()-6,6);
|
||||
size_t size;
|
||||
|
||||
string xMap;
|
||||
string yMap;
|
||||
|
||||
Adtfilename.erase(Adtfilename.find(".adt"),4);
|
||||
string TempMapNumber;
|
||||
TempMapNumber = Adtfilename.substr(Adtfilename.length()-6,6);
|
||||
xMap = TempMapNumber.substr(TempMapNumber.find("_")+1,(TempMapNumber.find_last_of("_")-1) - (TempMapNumber.find("_")));
|
||||
yMap = TempMapNumber.substr(TempMapNumber.find_last_of("_")+1,(TempMapNumber.length()) - (TempMapNumber.find_last_of("_")));
|
||||
Adtfilename.erase((Adtfilename.length()-xMap.length()-yMap.length()-2), (xMap.length()+yMap.length()+2));
|
||||
string AdtMapNumber = xMap + ' ' + yMap + ' ' + GetPlainName((char*)Adtfilename.c_str());
|
||||
printf("Processing map %s...\n", AdtMapNumber.c_str());
|
||||
//printf("MapNumber = %s\n", TempMapNumber.c_str());
|
||||
Adtfilename.erase((Adtfilename.length()-xMap.length()-yMap.length()-2), (xMap.length()+yMap.length()+2));
|
||||
string AdtMapNumber = xMap + ' ' + yMap + ' ' + GetPlainName((char*)Adtfilename.c_str());
|
||||
printf("Processing map %s...\n", AdtMapNumber.c_str());
|
||||
//printf("MapNumber = %s\n", TempMapNumber.c_str());
|
||||
//printf("xMap = %s\n", xMap.c_str());
|
||||
//printf("yMap = %s\n", yMap.c_str());
|
||||
|
||||
const char dirname[] = "buildings\\dir";
|
||||
FILE *dirfile;
|
||||
const char dirname[] = "buildings\\dir";
|
||||
FILE *dirfile;
|
||||
dirfile = fopen(dirname, "ab");
|
||||
if(!dirfile)
|
||||
{
|
||||
printf("Can't open dirfile!'%s'\n");
|
||||
return false;
|
||||
}
|
||||
if(!dirfile)
|
||||
{
|
||||
printf("Can't open dirfile!'%s'\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
while (!ADT.isEof ())
|
||||
{
|
||||
char fourcc[5];
|
||||
ADT.read(&fourcc,4);
|
||||
ADT.read(&size, 4);
|
||||
flipcc(fourcc);
|
||||
fourcc[4] = 0;
|
||||
while (!ADT.isEof ())
|
||||
{
|
||||
char fourcc[5];
|
||||
ADT.read(&fourcc,4);
|
||||
ADT.read(&size, 4);
|
||||
flipcc(fourcc);
|
||||
fourcc[4] = 0;
|
||||
|
||||
size_t nextpos = ADT.getPos () + size;
|
||||
|
||||
if (!strcmp(fourcc,"MCIN"))//MCIN
|
||||
{
|
||||
|
||||
}
|
||||
else if (!strcmp(fourcc,"MTEX"))
|
||||
{
|
||||
}
|
||||
else if (!strcmp(fourcc,"MMDX"))
|
||||
{
|
||||
|
||||
if (size)
|
||||
{
|
||||
char *buf = new char[size];
|
||||
ADT.read(buf, size);
|
||||
char *p=buf;
|
||||
int t=0;
|
||||
ModelInstansName = new string[size];
|
||||
while (p<buf+size)
|
||||
{
|
||||
fixnamen(p,strlen(p));
|
||||
string path(p);
|
||||
char* s=GetPlainName(p);
|
||||
fixname2(s,strlen(s));
|
||||
p=p+strlen(p)+1;
|
||||
ModelInstansName[t++] = s;
|
||||
path.erase(path.length()-2,2);
|
||||
path.append("2");
|
||||
char* szLocalFile[512];
|
||||
sprintf((char*)szLocalFile, ".\\buildings\\%s", s);
|
||||
FILE * output = fopen((char*)szLocalFile,"rb");
|
||||
if(!output)
|
||||
{
|
||||
|
||||
Model * m2 = new Model(path);
|
||||
if(m2->open())
|
||||
{
|
||||
m2->ConvertToVMAPModel((char*)szLocalFile);
|
||||
}
|
||||
delete m2;
|
||||
size_t nextpos = ADT.getPos () + size;
|
||||
|
||||
}
|
||||
else
|
||||
fclose(output);
|
||||
}
|
||||
|
||||
delete[] buf;
|
||||
}
|
||||
|
||||
}
|
||||
else if (!strcmp(fourcc,"MWMO"))
|
||||
{
|
||||
if (size)
|
||||
{
|
||||
|
||||
char *buf = new char[size];
|
||||
ADT.read(buf, size);
|
||||
char *p=buf;
|
||||
int q = 0;
|
||||
WmoInstansName = new string[size];
|
||||
while (p<buf+size)
|
||||
{
|
||||
string path(p);
|
||||
if (!strcmp(fourcc,"MCIN"))//MCIN
|
||||
{
|
||||
|
||||
}
|
||||
else if (!strcmp(fourcc,"MTEX"))
|
||||
{
|
||||
}
|
||||
else if (!strcmp(fourcc,"MMDX"))
|
||||
{
|
||||
|
||||
if (size)
|
||||
{
|
||||
char *buf = new char[size];
|
||||
ADT.read(buf, size);
|
||||
char *p=buf;
|
||||
int t=0;
|
||||
ModelInstansName = new string[size];
|
||||
while (p<buf+size)
|
||||
{
|
||||
fixnamen(p,strlen(p));
|
||||
string path(p);
|
||||
char* s=GetPlainName(p);
|
||||
fixnamen(s,strlen(s));
|
||||
fixname2(s,strlen(s));
|
||||
p=p+strlen(p)+1;
|
||||
WmoInstansName[q++] = s;
|
||||
}
|
||||
delete[] buf;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
fixname2(s,strlen(s));
|
||||
p=p+strlen(p)+1;
|
||||
ModelInstansName[t++] = s;
|
||||
path.erase(path.length()-2,2);
|
||||
path.append("2");
|
||||
char* szLocalFile[512];
|
||||
sprintf((char*)szLocalFile, ".\\buildings\\%s", s);
|
||||
FILE * output = fopen((char*)szLocalFile,"rb");
|
||||
if(!output)
|
||||
{
|
||||
|
||||
Model * m2 = new Model(path);
|
||||
if(m2->open())
|
||||
{
|
||||
m2->ConvertToVMAPModel((char*)szLocalFile);
|
||||
}
|
||||
delete m2;
|
||||
|
||||
}
|
||||
else
|
||||
fclose(output);
|
||||
}
|
||||
|
||||
delete[] buf;
|
||||
}
|
||||
|
||||
}
|
||||
else if (!strcmp(fourcc,"MWMO"))
|
||||
{
|
||||
if (size)
|
||||
{
|
||||
|
||||
char *buf = new char[size];
|
||||
ADT.read(buf, size);
|
||||
char *p=buf;
|
||||
int q = 0;
|
||||
WmoInstansName = new string[size];
|
||||
while (p<buf+size)
|
||||
{
|
||||
string path(p);
|
||||
char* s=GetPlainName(p);
|
||||
fixnamen(s,strlen(s));
|
||||
fixname2(s,strlen(s));
|
||||
p=p+strlen(p)+1;
|
||||
WmoInstansName[q++] = s;
|
||||
}
|
||||
delete[] buf;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
//======================
|
||||
else if (!strcmp(fourcc,"MDDF"))
|
||||
{
|
||||
if (size)
|
||||
{
|
||||
{
|
||||
nMDX = (int)size / 36;
|
||||
for (int i=0; i<nMDX; i++)
|
||||
{
|
||||
@@ -179,49 +179,49 @@ bool ADTFile::init(char *map_id)
|
||||
WMOInstance inst(ADT,WmoInstansName[id].c_str(),map_id, dirfile);//!!!!!!!!!!!!!
|
||||
}
|
||||
delete[] WmoInstansName;
|
||||
}
|
||||
}
|
||||
}
|
||||
//======================
|
||||
#if 0
|
||||
else if (!strcmp(fourcc,"MDDF"))
|
||||
{
|
||||
if (size)
|
||||
{
|
||||
nMDX = (int)size / 36;
|
||||
for (int i=0; i<nMDX; i++)
|
||||
{
|
||||
int id;
|
||||
ADT.read(&id, 4);
|
||||
ModelInstance inst(ADT,ModelInstansName[id].c_str(),AdtMapNumber.c_str(), dirfile);
|
||||
}
|
||||
delete[] ModelInstansName;
|
||||
}
|
||||
}
|
||||
else if (!strcmp(fourcc,"MODF"))
|
||||
{
|
||||
if (size)
|
||||
#if 0
|
||||
else if (!strcmp(fourcc,"MDDF"))
|
||||
{
|
||||
if (size)
|
||||
{
|
||||
nWMO = (int)size / 64;
|
||||
for (int i=0; i<nWMO; i++)
|
||||
{
|
||||
int id;
|
||||
ADT.read(&id, 4);
|
||||
WMOInstance inst(ADT,WmoInstansName[id].c_str(),AdtMapNumber.c_str(), dirfile);
|
||||
}
|
||||
nMDX = (int)size / 36;
|
||||
for (int i=0; i<nMDX; i++)
|
||||
{
|
||||
int id;
|
||||
ADT.read(&id, 4);
|
||||
ModelInstance inst(ADT,ModelInstansName[id].c_str(),AdtMapNumber.c_str(), dirfile);
|
||||
}
|
||||
delete[] ModelInstansName;
|
||||
}
|
||||
}
|
||||
else if (!strcmp(fourcc,"MODF"))
|
||||
{
|
||||
if (size)
|
||||
{
|
||||
nWMO = (int)size / 64;
|
||||
for (int i=0; i<nWMO; i++)
|
||||
{
|
||||
int id;
|
||||
ADT.read(&id, 4);
|
||||
WMOInstance inst(ADT,WmoInstansName[id].c_str(),AdtMapNumber.c_str(), dirfile);
|
||||
}
|
||||
delete[] WmoInstansName;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
ADT.seek(nextpos);
|
||||
}
|
||||
ADT.close();
|
||||
ADT.seek(nextpos);
|
||||
}
|
||||
ADT.close();
|
||||
fclose(dirfile);
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
ADTFile::~ADTFile()
|
||||
{
|
||||
ADT.close();
|
||||
ADT.close();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include "wmo.h"
|
||||
#include "model.h"
|
||||
|
||||
#define __STORMLIB_SELF__
|
||||
#define __STORMLIB_SELF__
|
||||
|
||||
#define TILESIZE (533.33333f)
|
||||
#define CHUNKSIZE ((TILESIZE) / 16.0f)
|
||||
@@ -30,9 +30,9 @@ double z;
|
||||
}vec;
|
||||
|
||||
typedef struct{
|
||||
vec v[3];
|
||||
vec v[3];
|
||||
|
||||
}triangle;
|
||||
}triangle;
|
||||
|
||||
typedef struct{
|
||||
float v9[16*8+1][16*8+1];
|
||||
@@ -54,66 +54,66 @@ chunk ch[16][16];
|
||||
}mcell;
|
||||
|
||||
struct MapChunkHeader {
|
||||
uint32 flags;
|
||||
uint32 ix;
|
||||
uint32 iy;
|
||||
uint32 nLayers;
|
||||
uint32 nDoodadRefs;
|
||||
uint32 ofsHeight;
|
||||
uint32 ofsNormal;
|
||||
uint32 ofsLayer;
|
||||
uint32 ofsRefs;
|
||||
uint32 ofsAlpha;
|
||||
uint32 sizeAlpha;
|
||||
uint32 ofsShadow;
|
||||
uint32 sizeShadow;
|
||||
uint32 areaid;
|
||||
uint32 nMapObjRefs;
|
||||
uint32 holes;
|
||||
uint16 s1;
|
||||
uint16 s2;
|
||||
uint32 d1;
|
||||
uint32 d2;
|
||||
uint32 d3;
|
||||
uint32 predTex;
|
||||
uint32 nEffectDoodad;
|
||||
uint32 ofsSndEmitters;
|
||||
uint32 nSndEmitters;
|
||||
uint32 ofsLiquid;
|
||||
uint32 sizeLiquid;
|
||||
float zpos;
|
||||
float xpos;
|
||||
float ypos;
|
||||
uint32 textureId;
|
||||
uint32 props;
|
||||
uint32 effectId;
|
||||
uint32 flags;
|
||||
uint32 ix;
|
||||
uint32 iy;
|
||||
uint32 nLayers;
|
||||
uint32 nDoodadRefs;
|
||||
uint32 ofsHeight;
|
||||
uint32 ofsNormal;
|
||||
uint32 ofsLayer;
|
||||
uint32 ofsRefs;
|
||||
uint32 ofsAlpha;
|
||||
uint32 sizeAlpha;
|
||||
uint32 ofsShadow;
|
||||
uint32 sizeShadow;
|
||||
uint32 areaid;
|
||||
uint32 nMapObjRefs;
|
||||
uint32 holes;
|
||||
uint16 s1;
|
||||
uint16 s2;
|
||||
uint32 d1;
|
||||
uint32 d2;
|
||||
uint32 d3;
|
||||
uint32 predTex;
|
||||
uint32 nEffectDoodad;
|
||||
uint32 ofsSndEmitters;
|
||||
uint32 nSndEmitters;
|
||||
uint32 ofsLiquid;
|
||||
uint32 sizeLiquid;
|
||||
float zpos;
|
||||
float xpos;
|
||||
float ypos;
|
||||
uint32 textureId;
|
||||
uint32 props;
|
||||
uint32 effectId;
|
||||
};
|
||||
|
||||
|
||||
class ADTFile
|
||||
{
|
||||
public:
|
||||
ADTFile(char* filename);
|
||||
~ADTFile();
|
||||
int nWMO;
|
||||
int nMDX;
|
||||
string* WmoInstansName;
|
||||
string* ModelInstansName;
|
||||
bool init(char *map_id);
|
||||
//void LoadMapChunks();
|
||||
ADTFile(char* filename);
|
||||
~ADTFile();
|
||||
int nWMO;
|
||||
int nMDX;
|
||||
string* WmoInstansName;
|
||||
string* ModelInstansName;
|
||||
bool init(char *map_id);
|
||||
//void LoadMapChunks();
|
||||
|
||||
//uint32 wmo_count;
|
||||
//uint32 wmo_count;
|
||||
/*
|
||||
const mcell& Getmcell() const
|
||||
{
|
||||
return Mcell;
|
||||
}
|
||||
const mcell& Getmcell() const
|
||||
{
|
||||
return Mcell;
|
||||
}
|
||||
*/
|
||||
private:
|
||||
//size_t mcnk_offsets[256], mcnk_sizes[256];
|
||||
MPQFile ADT;
|
||||
//mcell Mcell;
|
||||
string Adtfilename;
|
||||
//size_t mcnk_offsets[256], mcnk_sizes[256];
|
||||
MPQFile ADT;
|
||||
//mcell Mcell;
|
||||
string Adtfilename;
|
||||
};
|
||||
|
||||
void fixnamen(char *name, size_t len);
|
||||
|
||||
@@ -5,71 +5,71 @@
|
||||
|
||||
DBCFile::DBCFile(const std::string &filename) : filename(filename)
|
||||
{
|
||||
data = NULL;
|
||||
data = NULL;
|
||||
}
|
||||
|
||||
bool DBCFile::open()
|
||||
{
|
||||
MPQFile f(filename.c_str());
|
||||
MPQFile f(filename.c_str());
|
||||
|
||||
// Need some error checking, otherwise an unhandled exception error occurs
|
||||
// if people screw with the data path.
|
||||
if (f.isEof() == true)
|
||||
return false;
|
||||
// Need some error checking, otherwise an unhandled exception error occurs
|
||||
// if people screw with the data path.
|
||||
if (f.isEof() == true)
|
||||
return false;
|
||||
|
||||
unsigned char header[4];
|
||||
unsigned int na,nb,es,ss;
|
||||
unsigned char header[4];
|
||||
unsigned int na,nb,es,ss;
|
||||
|
||||
f.read(header,4); // File Header
|
||||
f.read(header,4); // File Header
|
||||
|
||||
if (header[0]!='W' || header[1]!='D' || header[2]!='B' || header[3] != 'C') {
|
||||
if (header[0]!='W' || header[1]!='D' || header[2]!='B' || header[3] != 'C') {
|
||||
|
||||
f.close();
|
||||
data = NULL;
|
||||
printf("Critical Error: An error occured while trying to read the DBCFile %s.", filename.c_str());
|
||||
return false;
|
||||
}
|
||||
f.close();
|
||||
data = NULL;
|
||||
printf("Critical Error: An error occured while trying to read the DBCFile %s.", filename.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
//assert(header[0]=='W' && header[1]=='D' && header[2]=='B' && header[3] == 'C');
|
||||
//assert(header[0]=='W' && header[1]=='D' && header[2]=='B' && header[3] == 'C');
|
||||
|
||||
f.read(&na,4); // Number of records
|
||||
f.read(&nb,4); // Number of fields
|
||||
f.read(&es,4); // Size of a record
|
||||
f.read(&ss,4); // String size
|
||||
|
||||
recordSize = es;
|
||||
recordCount = na;
|
||||
fieldCount = nb;
|
||||
stringSize = ss;
|
||||
//assert(fieldCount*4 == recordSize);
|
||||
assert(fieldCount*4 >= recordSize);
|
||||
f.read(&na,4); // Number of records
|
||||
f.read(&nb,4); // Number of fields
|
||||
f.read(&es,4); // Size of a record
|
||||
f.read(&ss,4); // String size
|
||||
|
||||
data = new unsigned char[recordSize*recordCount+stringSize];
|
||||
stringTable = data + recordSize*recordCount;
|
||||
f.read(data,recordSize*recordCount+stringSize);
|
||||
f.close();
|
||||
return true;
|
||||
recordSize = es;
|
||||
recordCount = na;
|
||||
fieldCount = nb;
|
||||
stringSize = ss;
|
||||
//assert(fieldCount*4 == recordSize);
|
||||
assert(fieldCount*4 >= recordSize);
|
||||
|
||||
data = new unsigned char[recordSize*recordCount+stringSize];
|
||||
stringTable = data + recordSize*recordCount;
|
||||
f.read(data,recordSize*recordCount+stringSize);
|
||||
f.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
DBCFile::~DBCFile()
|
||||
{
|
||||
delete [] data;
|
||||
delete [] data;
|
||||
}
|
||||
|
||||
DBCFile::Record DBCFile::getRecord(size_t id)
|
||||
{
|
||||
assert(data);
|
||||
return Record(*this, data + id*recordSize);
|
||||
assert(data);
|
||||
return Record(*this, data + id*recordSize);
|
||||
}
|
||||
|
||||
DBCFile::Iterator DBCFile::begin()
|
||||
{
|
||||
assert(data);
|
||||
return Iterator(*this, data);
|
||||
assert(data);
|
||||
return Iterator(*this, data);
|
||||
}
|
||||
DBCFile::Iterator DBCFile::end()
|
||||
{
|
||||
assert(data);
|
||||
return Iterator(*this, stringTable);
|
||||
assert(data);
|
||||
return Iterator(*this, stringTable);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,131 +9,131 @@
|
||||
class DBCFile
|
||||
{
|
||||
public:
|
||||
DBCFile(const std::string &filename);
|
||||
~DBCFile();
|
||||
DBCFile(const std::string &filename);
|
||||
~DBCFile();
|
||||
|
||||
// Open database. It must be openened before it can be used.
|
||||
bool open();
|
||||
// Open database. It must be openened before it can be used.
|
||||
bool open();
|
||||
|
||||
// TODO: Add a close function?
|
||||
// TODO: Add a close function?
|
||||
|
||||
// Database exceptions
|
||||
class Exception
|
||||
{
|
||||
public:
|
||||
Exception(const std::string &message): message(message)
|
||||
{ }
|
||||
virtual ~Exception()
|
||||
{ }
|
||||
const std::string &getMessage() {return message;}
|
||||
private:
|
||||
std::string message;
|
||||
};
|
||||
// Database exceptions
|
||||
class Exception
|
||||
{
|
||||
public:
|
||||
Exception(const std::string &message): message(message)
|
||||
{ }
|
||||
virtual ~Exception()
|
||||
{ }
|
||||
const std::string &getMessage() {return message;}
|
||||
private:
|
||||
std::string message;
|
||||
};
|
||||
|
||||
//
|
||||
class NotFound: public Exception
|
||||
{
|
||||
public:
|
||||
NotFound(): Exception("Key was not found")
|
||||
{ }
|
||||
};
|
||||
//
|
||||
class NotFound: public Exception
|
||||
{
|
||||
public:
|
||||
NotFound(): Exception("Key was not found")
|
||||
{ }
|
||||
};
|
||||
|
||||
// Iteration over database
|
||||
class Iterator;
|
||||
class Record
|
||||
{
|
||||
public:
|
||||
Record& operator= (const Record& r)
|
||||
{
|
||||
// Iteration over database
|
||||
class Iterator;
|
||||
class Record
|
||||
{
|
||||
public:
|
||||
Record& operator= (const Record& r)
|
||||
{
|
||||
file = r.file;
|
||||
offset = r.offset;
|
||||
return *this;
|
||||
}
|
||||
float getFloat(size_t field) const
|
||||
{
|
||||
assert(field < file.fieldCount);
|
||||
return *reinterpret_cast<float*>(offset+field*4);
|
||||
}
|
||||
unsigned int getUInt(size_t field) const
|
||||
{
|
||||
assert(field < file.fieldCount);
|
||||
return *reinterpret_cast<unsigned int*>(offset+(field*4));
|
||||
}
|
||||
int getInt(size_t field) const
|
||||
{
|
||||
assert(field < file.fieldCount);
|
||||
return *reinterpret_cast<int*>(offset+field*4);
|
||||
}
|
||||
unsigned char getByte(size_t ofs) const
|
||||
{
|
||||
assert(ofs < file.recordSize);
|
||||
return *reinterpret_cast<unsigned char*>(offset+ofs);
|
||||
}
|
||||
const char *getString(size_t field) const
|
||||
{
|
||||
assert(field < file.fieldCount);
|
||||
size_t stringOffset = getUInt(field);
|
||||
assert(stringOffset < file.stringSize);
|
||||
//char * tmp = (char*)file.stringTable + stringOffset;
|
||||
//unsigned char * tmp2 = file.stringTable + stringOffset;
|
||||
return reinterpret_cast<char*>(file.stringTable + stringOffset);
|
||||
}
|
||||
private:
|
||||
Record(DBCFile &file, unsigned char *offset): file(file), offset(offset) {}
|
||||
unsigned char *offset;
|
||||
DBCFile &file;
|
||||
offset = r.offset;
|
||||
return *this;
|
||||
}
|
||||
float getFloat(size_t field) const
|
||||
{
|
||||
assert(field < file.fieldCount);
|
||||
return *reinterpret_cast<float*>(offset+field*4);
|
||||
}
|
||||
unsigned int getUInt(size_t field) const
|
||||
{
|
||||
assert(field < file.fieldCount);
|
||||
return *reinterpret_cast<unsigned int*>(offset+(field*4));
|
||||
}
|
||||
int getInt(size_t field) const
|
||||
{
|
||||
assert(field < file.fieldCount);
|
||||
return *reinterpret_cast<int*>(offset+field*4);
|
||||
}
|
||||
unsigned char getByte(size_t ofs) const
|
||||
{
|
||||
assert(ofs < file.recordSize);
|
||||
return *reinterpret_cast<unsigned char*>(offset+ofs);
|
||||
}
|
||||
const char *getString(size_t field) const
|
||||
{
|
||||
assert(field < file.fieldCount);
|
||||
size_t stringOffset = getUInt(field);
|
||||
assert(stringOffset < file.stringSize);
|
||||
//char * tmp = (char*)file.stringTable + stringOffset;
|
||||
//unsigned char * tmp2 = file.stringTable + stringOffset;
|
||||
return reinterpret_cast<char*>(file.stringTable + stringOffset);
|
||||
}
|
||||
private:
|
||||
Record(DBCFile &file, unsigned char *offset): file(file), offset(offset) {}
|
||||
unsigned char *offset;
|
||||
DBCFile &file;
|
||||
|
||||
friend class DBCFile;
|
||||
friend class Iterator;
|
||||
};
|
||||
friend class DBCFile;
|
||||
friend class Iterator;
|
||||
};
|
||||
|
||||
/* Iterator that iterates over records */
|
||||
class Iterator
|
||||
{
|
||||
public:
|
||||
Iterator(DBCFile &file, unsigned char *offset):
|
||||
record(file, offset) {}
|
||||
/// Advance (prefix only)
|
||||
Iterator & operator++() {
|
||||
record.offset += record.file.recordSize;
|
||||
return *this;
|
||||
}
|
||||
/// Return address of current instance
|
||||
Record const & operator*() const { return record; }
|
||||
const Record* operator->() const {
|
||||
return &record;
|
||||
}
|
||||
/// Comparison
|
||||
bool operator==(const Iterator &b) const
|
||||
{
|
||||
return record.offset == b.record.offset;
|
||||
}
|
||||
bool operator!=(const Iterator &b) const
|
||||
{
|
||||
return record.offset != b.record.offset;
|
||||
}
|
||||
private:
|
||||
Record record;
|
||||
};
|
||||
/* Iterator that iterates over records */
|
||||
class Iterator
|
||||
{
|
||||
public:
|
||||
Iterator(DBCFile &file, unsigned char *offset):
|
||||
record(file, offset) {}
|
||||
/// Advance (prefix only)
|
||||
Iterator & operator++() {
|
||||
record.offset += record.file.recordSize;
|
||||
return *this;
|
||||
}
|
||||
/// Return address of current instance
|
||||
Record const & operator*() const { return record; }
|
||||
const Record* operator->() const {
|
||||
return &record;
|
||||
}
|
||||
/// Comparison
|
||||
bool operator==(const Iterator &b) const
|
||||
{
|
||||
return record.offset == b.record.offset;
|
||||
}
|
||||
bool operator!=(const Iterator &b) const
|
||||
{
|
||||
return record.offset != b.record.offset;
|
||||
}
|
||||
private:
|
||||
Record record;
|
||||
};
|
||||
|
||||
// Get record by id
|
||||
Record getRecord(size_t id);
|
||||
/// Get begin iterator over records
|
||||
Iterator begin();
|
||||
/// Get begin iterator over records
|
||||
Iterator end();
|
||||
/// Trivial
|
||||
size_t getRecordCount() const { return recordCount;}
|
||||
size_t getFieldCount() const { return fieldCount; }
|
||||
// Get record by id
|
||||
Record getRecord(size_t id);
|
||||
/// Get begin iterator over records
|
||||
Iterator begin();
|
||||
/// Get begin iterator over records
|
||||
Iterator end();
|
||||
/// Trivial
|
||||
size_t getRecordCount() const { return recordCount;}
|
||||
size_t getFieldCount() const { return fieldCount; }
|
||||
|
||||
private:
|
||||
std::string filename;
|
||||
size_t recordSize;
|
||||
size_t recordCount;
|
||||
size_t fieldCount;
|
||||
size_t stringSize;
|
||||
unsigned char *data;
|
||||
unsigned char *stringTable;
|
||||
std::string filename;
|
||||
size_t recordSize;
|
||||
size_t recordCount;
|
||||
size_t fieldCount;
|
||||
size_t stringSize;
|
||||
unsigned char *data;
|
||||
unsigned char *stringTable;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -16,7 +16,7 @@ bool Model::open()
|
||||
|
||||
ok = !f.isEof();
|
||||
|
||||
if (!ok)
|
||||
if (!ok)
|
||||
{
|
||||
f.close();
|
||||
printf("Error loading model %s\n", filename.c_str());
|
||||
@@ -40,12 +40,12 @@ bool Model::open()
|
||||
vertices = new Vec3D[header.nVertices];
|
||||
normals = new Vec3D[header.nVertices];
|
||||
|
||||
for (size_t i=0; i<header.nVertices; i++)
|
||||
for (size_t i=0; i<header.nVertices; i++)
|
||||
{
|
||||
origVertices[i].pos = fixCoordSystem(origVertices[i].pos);
|
||||
origVertices[i].normal = fixCoordSystem(origVertices[i].normal);
|
||||
vertices[i] = origVertices[i].pos;
|
||||
normals[i] = origVertices[i].normal.normalize();
|
||||
normals[i] = origVertices[i].normal.normalize();
|
||||
}
|
||||
|
||||
ModelView *view = (ModelView*)(f.getBuffer() + header.ofsViews);
|
||||
@@ -55,7 +55,7 @@ bool Model::open()
|
||||
|
||||
nIndices = view->nTris;
|
||||
indices = new uint16[nIndices];
|
||||
for (size_t i = 0; i<nIndices; i++)
|
||||
for (size_t i = 0; i<nIndices; i++)
|
||||
{
|
||||
indices[i] = indexLookup[triangles[i]];
|
||||
}
|
||||
@@ -168,7 +168,7 @@ bool Model::ConvertToVMAPModel(char * outfilename)
|
||||
wsize = sizeof(uint32) + sizeof(unsigned short) * nIdexes;
|
||||
fwrite(&wsize, sizeof(int), 1, output);
|
||||
fwrite(&nIdexes, sizeof(uint32), 1, output);
|
||||
if(nIdexes >0)
|
||||
if(nIdexes >0)
|
||||
{
|
||||
fwrite(indices, sizeof(unsigned short), nIdexes, output);
|
||||
}
|
||||
@@ -176,9 +176,9 @@ bool Model::ConvertToVMAPModel(char * outfilename)
|
||||
wsize = sizeof(int) + sizeof(float) * 3 * nVertices;
|
||||
fwrite(&wsize, sizeof(int), 1, output);
|
||||
fwrite(&nVertices, sizeof(int), 1, output);
|
||||
if(nVertices >0)
|
||||
if(nVertices >0)
|
||||
{
|
||||
for(int vpos=0; vpos <nVertices; ++vpos)
|
||||
for(int vpos=0; vpos <nVertices; ++vpos)
|
||||
{
|
||||
float sy = vertices[vpos].y;
|
||||
vertices[vpos].y = vertices[vpos].z;
|
||||
@@ -231,15 +231,15 @@ ModelInstance::ModelInstance(MPQFile &f,const char* ModelInstName,const char*Map
|
||||
return;
|
||||
}
|
||||
fseek(input, 8, SEEK_SET); // get the correct no of vertices
|
||||
int nVertices;
|
||||
fread(&nVertices, sizeof (int), 1, input);
|
||||
fclose(input);
|
||||
int nVertices;
|
||||
fread(&nVertices, sizeof (int), 1, input);
|
||||
fclose(input);
|
||||
if(nVertices == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(pDirfile)
|
||||
if(pDirfile)
|
||||
{
|
||||
int realx1 = (int) ((float) pos.x / 533.333333f);
|
||||
int realy1 = (int) ((float) pos.z / 533.333333f);
|
||||
@@ -256,6 +256,6 @@ ModelInstance::ModelInstance(MPQFile &f,const char* ModelInstName,const char*Map
|
||||
nVertices,
|
||||
realx1, realy1,
|
||||
realx2, realy2
|
||||
);
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,61 +16,61 @@ Vec3D fixCoordSystem(Vec3D v);
|
||||
|
||||
|
||||
class Model
|
||||
{
|
||||
public:
|
||||
ModelHeader header;
|
||||
ModelAnimation *anims;
|
||||
int *globalSequences;
|
||||
|
||||
public:
|
||||
bool animGeometry,animTextures,animBones;
|
||||
bool animated;
|
||||
|
||||
bool isAnimated(MPQFile &f);
|
||||
ModelVertex *origVertices;
|
||||
Vec3D *vertices, *normals;
|
||||
uint16 *indices;
|
||||
size_t nIndices;
|
||||
|
||||
bool open();
|
||||
bool ConvertToVMAPModel(char * outfilename);
|
||||
|
||||
public:
|
||||
|
||||
bool ok;
|
||||
bool ind;
|
||||
|
||||
float rad;
|
||||
float trans;
|
||||
bool animcalc;
|
||||
int anim, animtime;
|
||||
|
||||
Model(std::string &filename);
|
||||
~Model();
|
||||
|
||||
private:
|
||||
std::string filename;
|
||||
char outfilename;
|
||||
};
|
||||
|
||||
class ModelInstance
|
||||
{
|
||||
public:
|
||||
Model *model;
|
||||
ModelHeader header;
|
||||
ModelAnimation *anims;
|
||||
int *globalSequences;
|
||||
|
||||
int id;
|
||||
public:
|
||||
bool animGeometry,animTextures,animBones;
|
||||
bool animated;
|
||||
|
||||
Vec3D pos, rot;
|
||||
unsigned int d1, scale;
|
||||
bool isAnimated(MPQFile &f);
|
||||
ModelVertex *origVertices;
|
||||
Vec3D *vertices, *normals;
|
||||
uint16 *indices;
|
||||
size_t nIndices;
|
||||
|
||||
float frot,w,sc;
|
||||
bool open();
|
||||
bool ConvertToVMAPModel(char * outfilename);
|
||||
|
||||
int light;
|
||||
Vec3D ldir;
|
||||
Vec3D lcol;
|
||||
public:
|
||||
|
||||
ModelInstance() {}
|
||||
ModelInstance(MPQFile &f,const char* ModelInstName,const char*MapName, FILE *pDirfile);
|
||||
bool ok;
|
||||
bool ind;
|
||||
|
||||
float rad;
|
||||
float trans;
|
||||
bool animcalc;
|
||||
int anim, animtime;
|
||||
|
||||
Model(std::string &filename);
|
||||
~Model();
|
||||
|
||||
private:
|
||||
std::string filename;
|
||||
char outfilename;
|
||||
};
|
||||
|
||||
class ModelInstance
|
||||
{
|
||||
public:
|
||||
Model *model;
|
||||
|
||||
int id;
|
||||
|
||||
Vec3D pos, rot;
|
||||
unsigned int d1, scale;
|
||||
|
||||
float frot,w,sc;
|
||||
|
||||
int light;
|
||||
Vec3D ldir;
|
||||
Vec3D lcol;
|
||||
|
||||
ModelInstance() {}
|
||||
ModelInstance(MPQFile &f,const char* ModelInstName,const char*MapName, FILE *pDirfile);
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -11,290 +11,290 @@ typedef int int32;
|
||||
#pragma pack(push,1)
|
||||
|
||||
struct ModelHeader {
|
||||
char id[4];
|
||||
uint8 version[4];
|
||||
uint32 nameLength;
|
||||
uint32 nameOfs;
|
||||
uint32 type;
|
||||
char id[4];
|
||||
uint8 version[4];
|
||||
uint32 nameLength;
|
||||
uint32 nameOfs;
|
||||
uint32 type;
|
||||
|
||||
uint32 nGlobalSequences;
|
||||
uint32 ofsGlobalSequences;
|
||||
uint32 nAnimations;
|
||||
uint32 ofsAnimations;
|
||||
uint32 nC;
|
||||
uint32 ofsC;
|
||||
uint32 nD;
|
||||
uint32 ofsD;
|
||||
uint32 nBones;
|
||||
uint32 ofsBones;
|
||||
uint32 nF;
|
||||
uint32 ofsF;
|
||||
uint32 nGlobalSequences;
|
||||
uint32 ofsGlobalSequences;
|
||||
uint32 nAnimations;
|
||||
uint32 ofsAnimations;
|
||||
uint32 nC;
|
||||
uint32 ofsC;
|
||||
uint32 nD;
|
||||
uint32 ofsD;
|
||||
uint32 nBones;
|
||||
uint32 ofsBones;
|
||||
uint32 nF;
|
||||
uint32 ofsF;
|
||||
|
||||
uint32 nVertices;
|
||||
uint32 ofsVertices;
|
||||
uint32 nViews;
|
||||
uint32 ofsViews;
|
||||
uint32 nVertices;
|
||||
uint32 ofsVertices;
|
||||
uint32 nViews;
|
||||
uint32 ofsViews;
|
||||
|
||||
uint32 nColors;
|
||||
uint32 ofsColors;
|
||||
uint32 nColors;
|
||||
uint32 ofsColors;
|
||||
|
||||
uint32 nTextures;
|
||||
uint32 ofsTextures;
|
||||
uint32 nTextures;
|
||||
uint32 ofsTextures;
|
||||
|
||||
uint32 nTransparency; // H
|
||||
uint32 ofsTransparency;
|
||||
uint32 nI; // always unused ?
|
||||
uint32 ofsI;
|
||||
uint32 nTexAnims; // J
|
||||
uint32 ofsTexAnims;
|
||||
uint32 nK;
|
||||
uint32 ofsK;
|
||||
uint32 nTransparency; // H
|
||||
uint32 ofsTransparency;
|
||||
uint32 nI; // always unused ?
|
||||
uint32 ofsI;
|
||||
uint32 nTexAnims; // J
|
||||
uint32 ofsTexAnims;
|
||||
uint32 nK;
|
||||
uint32 ofsK;
|
||||
|
||||
uint32 nTexFlags;
|
||||
uint32 ofsTexFlags;
|
||||
uint32 nY;
|
||||
uint32 ofsY;
|
||||
uint32 nTexFlags;
|
||||
uint32 ofsTexFlags;
|
||||
uint32 nY;
|
||||
uint32 ofsY;
|
||||
|
||||
uint32 nTexLookup;
|
||||
uint32 ofsTexLookup;
|
||||
uint32 nTexLookup;
|
||||
uint32 ofsTexLookup;
|
||||
|
||||
uint32 nTexUnitLookup; // L
|
||||
uint32 ofsTexUnitLookup;
|
||||
uint32 nTransparencyLookup; // M
|
||||
uint32 ofsTransparencyLookup;
|
||||
uint32 nTexAnimLookup;
|
||||
uint32 ofsTexAnimLookup;
|
||||
uint32 nTexUnitLookup; // L
|
||||
uint32 ofsTexUnitLookup;
|
||||
uint32 nTransparencyLookup; // M
|
||||
uint32 ofsTransparencyLookup;
|
||||
uint32 nTexAnimLookup;
|
||||
uint32 ofsTexAnimLookup;
|
||||
|
||||
float floats[14];
|
||||
float floats[14];
|
||||
|
||||
uint32 nBoundingTriangles;
|
||||
uint32 ofsBoundingTriangles;
|
||||
uint32 nBoundingVertices;
|
||||
uint32 ofsBoundingVertices;
|
||||
uint32 nBoundingNormals;
|
||||
uint32 ofsBoundingNormals;
|
||||
uint32 nBoundingTriangles;
|
||||
uint32 ofsBoundingTriangles;
|
||||
uint32 nBoundingVertices;
|
||||
uint32 ofsBoundingVertices;
|
||||
uint32 nBoundingNormals;
|
||||
uint32 ofsBoundingNormals;
|
||||
|
||||
uint32 nO;
|
||||
uint32 ofsO;
|
||||
uint32 nP;
|
||||
uint32 ofsP;
|
||||
uint32 nQ;
|
||||
uint32 ofsQ;
|
||||
uint32 nLights; // R
|
||||
uint32 ofsLights;
|
||||
uint32 nCameras; // S
|
||||
uint32 ofsCameras;
|
||||
uint32 nT;
|
||||
uint32 ofsT;
|
||||
uint32 nRibbonEmitters; // U
|
||||
uint32 ofsRibbonEmitters;
|
||||
uint32 nParticleEmitters; // V
|
||||
uint32 ofsParticleEmitters;
|
||||
uint32 nO;
|
||||
uint32 ofsO;
|
||||
uint32 nP;
|
||||
uint32 ofsP;
|
||||
uint32 nQ;
|
||||
uint32 ofsQ;
|
||||
uint32 nLights; // R
|
||||
uint32 ofsLights;
|
||||
uint32 nCameras; // S
|
||||
uint32 ofsCameras;
|
||||
uint32 nT;
|
||||
uint32 ofsT;
|
||||
uint32 nRibbonEmitters; // U
|
||||
uint32 ofsRibbonEmitters;
|
||||
uint32 nParticleEmitters; // V
|
||||
uint32 ofsParticleEmitters;
|
||||
|
||||
};
|
||||
|
||||
// block B - animations
|
||||
struct ModelAnimation {
|
||||
uint32 animID;
|
||||
uint32 timeStart;
|
||||
uint32 timeEnd;
|
||||
uint32 animID;
|
||||
uint32 timeStart;
|
||||
uint32 timeEnd;
|
||||
|
||||
float moveSpeed;
|
||||
float moveSpeed;
|
||||
|
||||
uint32 loopType;
|
||||
uint32 flags;
|
||||
uint32 d1;
|
||||
uint32 d2;
|
||||
uint32 playSpeed; // note: this can't be play speed because it's 0 for some models
|
||||
uint32 loopType;
|
||||
uint32 flags;
|
||||
uint32 d1;
|
||||
uint32 d2;
|
||||
uint32 playSpeed; // note: this can't be play speed because it's 0 for some models
|
||||
|
||||
Vec3D boxA, boxB;
|
||||
float rad;
|
||||
Vec3D boxA, boxB;
|
||||
float rad;
|
||||
|
||||
int16 s[2];
|
||||
int16 s[2];
|
||||
};
|
||||
|
||||
|
||||
// sub-block in block E - animation data
|
||||
struct AnimationBlock {
|
||||
int16 type; // interpolation type (0=none, 1=linear, 2=hermite)
|
||||
int16 seq; // global sequence id or -1
|
||||
uint32 nRanges;
|
||||
uint32 ofsRanges;
|
||||
uint32 nTimes;
|
||||
uint32 ofsTimes;
|
||||
uint32 nKeys;
|
||||
uint32 ofsKeys;
|
||||
int16 type; // interpolation type (0=none, 1=linear, 2=hermite)
|
||||
int16 seq; // global sequence id or -1
|
||||
uint32 nRanges;
|
||||
uint32 ofsRanges;
|
||||
uint32 nTimes;
|
||||
uint32 ofsTimes;
|
||||
uint32 nKeys;
|
||||
uint32 ofsKeys;
|
||||
};
|
||||
|
||||
// block E - bones
|
||||
struct ModelBoneDef {
|
||||
int32 animid;
|
||||
int32 flags;
|
||||
int16 parent; // parent bone index
|
||||
int16 geoid;
|
||||
// new int added to the bone definitions. Added in WoW 2.0
|
||||
int32 unknown;
|
||||
AnimationBlock translation;
|
||||
AnimationBlock rotation;
|
||||
AnimationBlock scaling;
|
||||
Vec3D pivot;
|
||||
int32 animid;
|
||||
int32 flags;
|
||||
int16 parent; // parent bone index
|
||||
int16 geoid;
|
||||
// new int added to the bone definitions. Added in WoW 2.0
|
||||
int32 unknown;
|
||||
AnimationBlock translation;
|
||||
AnimationBlock rotation;
|
||||
AnimationBlock scaling;
|
||||
Vec3D pivot;
|
||||
};
|
||||
|
||||
struct ModelTexAnimDef {
|
||||
AnimationBlock trans, rot, scale;
|
||||
AnimationBlock trans, rot, scale;
|
||||
};
|
||||
|
||||
struct ModelVertex {
|
||||
Vec3D pos;
|
||||
uint8 weights[4];
|
||||
uint8 bones[4];
|
||||
Vec3D normal;
|
||||
Vec2D texcoords;
|
||||
int unk1, unk2; // always 0,0 so this is probably unused
|
||||
Vec3D pos;
|
||||
uint8 weights[4];
|
||||
uint8 bones[4];
|
||||
Vec3D normal;
|
||||
Vec2D texcoords;
|
||||
int unk1, unk2; // always 0,0 so this is probably unused
|
||||
};
|
||||
|
||||
struct ModelView {
|
||||
uint32 nIndex, ofsIndex; // Vertices in this model (index into vertices[])
|
||||
uint32 nTris, ofsTris; // indices
|
||||
uint32 nTris, ofsTris; // indices
|
||||
uint32 nProps, ofsProps; // additional vtx properties
|
||||
uint32 nSub, ofsSub; // materials/renderops/submeshes
|
||||
uint32 nTex, ofsTex; // material properties/textures
|
||||
int32 lod; // LOD bias?
|
||||
uint32 nSub, ofsSub; // materials/renderops/submeshes
|
||||
uint32 nTex, ofsTex; // material properties/textures
|
||||
int32 lod; // LOD bias?
|
||||
};
|
||||
|
||||
|
||||
/// One material + render operation
|
||||
struct ModelGeoset {
|
||||
uint16 d1; // mesh part id?
|
||||
uint16 d2; // ?
|
||||
uint16 vstart; // first vertex
|
||||
uint16 vcount; // num vertices
|
||||
uint16 istart; // first index
|
||||
uint16 icount; // num indices
|
||||
uint16 d3; // number of bone indices
|
||||
uint16 d4; // offset into bone index list
|
||||
uint16 d5; // ?
|
||||
uint16 d6; // root bone?
|
||||
Vec3D v;
|
||||
float unknown[4]; // Added in WoW 2.0?
|
||||
uint16 d1; // mesh part id?
|
||||
uint16 d2; // ?
|
||||
uint16 vstart; // first vertex
|
||||
uint16 vcount; // num vertices
|
||||
uint16 istart; // first index
|
||||
uint16 icount; // num indices
|
||||
uint16 d3; // number of bone indices
|
||||
uint16 d4; // offset into bone index list
|
||||
uint16 d5; // ?
|
||||
uint16 d6; // root bone?
|
||||
Vec3D v;
|
||||
float unknown[4]; // Added in WoW 2.0?
|
||||
};
|
||||
|
||||
/// A texture unit (sub of material)
|
||||
struct ModelTexUnit{
|
||||
// probably the texture units
|
||||
// size always >=number of materials it seems
|
||||
uint16 flags; // Flags
|
||||
uint16 order; // ?
|
||||
uint16 op; // Material this texture is part of (index into mat)
|
||||
uint16 op2; // Always same as above?
|
||||
int16 colorIndex; // color or -1
|
||||
uint16 flagsIndex; // more flags...
|
||||
uint16 texunit; // Texture unit (0 or 1)
|
||||
uint16 d4; // ? (seems to be always 1)
|
||||
uint16 textureid; // Texture id (index into global texture list)
|
||||
uint16 texunit2; // copy of texture unit value?
|
||||
uint16 transid; // transparency id (index into transparency list)
|
||||
uint16 texanimid; // texture animation id
|
||||
// probably the texture units
|
||||
// size always >=number of materials it seems
|
||||
uint16 flags; // Flags
|
||||
uint16 order; // ?
|
||||
uint16 op; // Material this texture is part of (index into mat)
|
||||
uint16 op2; // Always same as above?
|
||||
int16 colorIndex; // color or -1
|
||||
uint16 flagsIndex; // more flags...
|
||||
uint16 texunit; // Texture unit (0 or 1)
|
||||
uint16 d4; // ? (seems to be always 1)
|
||||
uint16 textureid; // Texture id (index into global texture list)
|
||||
uint16 texunit2; // copy of texture unit value?
|
||||
uint16 transid; // transparency id (index into transparency list)
|
||||
uint16 texanimid; // texture animation id
|
||||
};
|
||||
|
||||
// block X - render flags
|
||||
struct ModelRenderFlags {
|
||||
uint16 flags;
|
||||
uint16 blend;
|
||||
uint16 flags;
|
||||
uint16 blend;
|
||||
};
|
||||
|
||||
// block G - color defs
|
||||
struct ModelColorDef {
|
||||
AnimationBlock color;
|
||||
AnimationBlock opacity;
|
||||
AnimationBlock color;
|
||||
AnimationBlock opacity;
|
||||
};
|
||||
|
||||
// block H - transp defs
|
||||
struct ModelTransDef {
|
||||
AnimationBlock trans;
|
||||
AnimationBlock trans;
|
||||
};
|
||||
|
||||
struct ModelTextureDef {
|
||||
uint32 type;
|
||||
uint32 flags;
|
||||
uint32 nameLen;
|
||||
uint32 nameOfs;
|
||||
uint32 type;
|
||||
uint32 flags;
|
||||
uint32 nameLen;
|
||||
uint32 nameOfs;
|
||||
};
|
||||
|
||||
struct ModelLightDef {
|
||||
int16 type;
|
||||
int16 bone;
|
||||
Vec3D pos;
|
||||
AnimationBlock ambColor;
|
||||
AnimationBlock ambIntensity;
|
||||
AnimationBlock color;
|
||||
AnimationBlock intensity;
|
||||
AnimationBlock attStart;
|
||||
AnimationBlock attEnd;
|
||||
AnimationBlock unk1;
|
||||
int16 type;
|
||||
int16 bone;
|
||||
Vec3D pos;
|
||||
AnimationBlock ambColor;
|
||||
AnimationBlock ambIntensity;
|
||||
AnimationBlock color;
|
||||
AnimationBlock intensity;
|
||||
AnimationBlock attStart;
|
||||
AnimationBlock attEnd;
|
||||
AnimationBlock unk1;
|
||||
};
|
||||
|
||||
struct ModelCameraDef {
|
||||
int32 id;
|
||||
float fov, farclip, nearclip;
|
||||
AnimationBlock transPos;
|
||||
Vec3D pos;
|
||||
AnimationBlock transTarget;
|
||||
Vec3D target;
|
||||
AnimationBlock rot;
|
||||
int32 id;
|
||||
float fov, farclip, nearclip;
|
||||
AnimationBlock transPos;
|
||||
Vec3D pos;
|
||||
AnimationBlock transTarget;
|
||||
Vec3D target;
|
||||
AnimationBlock rot;
|
||||
};
|
||||
|
||||
|
||||
struct ModelParticleParams {
|
||||
float mid;
|
||||
uint32 colors[3];
|
||||
float sizes[3];
|
||||
int16 d[10];
|
||||
float unk[3];
|
||||
float scales[3];
|
||||
float slowdown;
|
||||
float rotation;
|
||||
float f2[16];
|
||||
float mid;
|
||||
uint32 colors[3];
|
||||
float sizes[3];
|
||||
int16 d[10];
|
||||
float unk[3];
|
||||
float scales[3];
|
||||
float slowdown;
|
||||
float rotation;
|
||||
float f2[16];
|
||||
};
|
||||
|
||||
struct ModelParticleEmitterDef {
|
||||
int32 id;
|
||||
int32 flags;
|
||||
Vec3D pos;
|
||||
int16 bone;
|
||||
int16 texture;
|
||||
int32 nZero1;
|
||||
int32 ofsZero1;
|
||||
int32 nZero2;
|
||||
int32 ofsZero2;
|
||||
int16 blend;
|
||||
int16 type;
|
||||
int16 s1;
|
||||
int16 s2;
|
||||
int16 cols;
|
||||
int16 rows;
|
||||
AnimationBlock params[10];
|
||||
ModelParticleParams p;
|
||||
AnimationBlock unk;
|
||||
int32 flags;
|
||||
Vec3D pos;
|
||||
int16 bone;
|
||||
int16 texture;
|
||||
int32 nZero1;
|
||||
int32 ofsZero1;
|
||||
int32 nZero2;
|
||||
int32 ofsZero2;
|
||||
int16 blend;
|
||||
int16 type;
|
||||
int16 s1;
|
||||
int16 s2;
|
||||
int16 cols;
|
||||
int16 rows;
|
||||
AnimationBlock params[10];
|
||||
ModelParticleParams p;
|
||||
AnimationBlock unk;
|
||||
};
|
||||
|
||||
|
||||
struct ModelRibbonEmitterDef {
|
||||
int32 id;
|
||||
int32 bone;
|
||||
Vec3D pos;
|
||||
int32 nTextures;
|
||||
int32 ofsTextures;
|
||||
int32 nUnknown;
|
||||
int32 ofsUnknown;
|
||||
AnimationBlock color;
|
||||
AnimationBlock opacity;
|
||||
AnimationBlock above;
|
||||
AnimationBlock below;
|
||||
float res, length, unk;
|
||||
int16 s1, s2;
|
||||
AnimationBlock unk1;
|
||||
AnimationBlock unk2;
|
||||
int32 id;
|
||||
int32 bone;
|
||||
Vec3D pos;
|
||||
int32 nTextures;
|
||||
int32 ofsTextures;
|
||||
int32 nUnknown;
|
||||
int32 ofsUnknown;
|
||||
AnimationBlock color;
|
||||
AnimationBlock opacity;
|
||||
AnimationBlock above;
|
||||
AnimationBlock below;
|
||||
float res, length, unk;
|
||||
int16 s1, s2;
|
||||
AnimationBlock unk1;
|
||||
AnimationBlock unk2;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -8,85 +8,85 @@ ArchiveSet gOpenArchives;
|
||||
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||
MPQArchive::MPQArchive(const char* filename)
|
||||
{
|
||||
BOOL succ = SFileOpenArchive(filename, 0, 0,&hMPQ);
|
||||
if (succ)
|
||||
{
|
||||
MPQArchive*ar = (MPQArchive*)(hMPQ);
|
||||
printf("Opening %s\n", filename);
|
||||
gOpenArchives.push_back(ar);
|
||||
BOOL succ = SFileOpenArchive(filename, 0, 0,&hMPQ);
|
||||
if (succ)
|
||||
{
|
||||
MPQArchive*ar = (MPQArchive*)(hMPQ);
|
||||
printf("Opening %s\n", filename);
|
||||
gOpenArchives.push_back(ar);
|
||||
succ = true;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Error!!!Not open archive %s\n", filename);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Error!!!Not open archive %s\n", filename);
|
||||
}
|
||||
}
|
||||
|
||||
void MPQArchive::close()
|
||||
{
|
||||
SFileCloseArchive(hMPQ);
|
||||
SFileCloseArchive(hMPQ);
|
||||
}
|
||||
|
||||
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||
MPQFile::MPQFile(const char* filename):
|
||||
eof(false),
|
||||
buffer(0),
|
||||
pointer(0),
|
||||
size(0)
|
||||
eof(false),
|
||||
buffer(0),
|
||||
pointer(0),
|
||||
size(0)
|
||||
{
|
||||
for(ArchiveSet::iterator i=gOpenArchives.begin(); i!=gOpenArchives.end();++i)
|
||||
{
|
||||
|
||||
HANDLE hFile = "";
|
||||
MPQArchive*(hMPQ) = *i;
|
||||
BOOL succ = SFileOpenFileEx(hMPQ,filename,0, &hFile);
|
||||
if (succ)
|
||||
{
|
||||
DWORD s = SFileGetFileSize(hFile, 0);
|
||||
if (!s)
|
||||
{
|
||||
eof = true;
|
||||
buffer = 0;
|
||||
return;
|
||||
}
|
||||
for(ArchiveSet::iterator i=gOpenArchives.begin(); i!=gOpenArchives.end();++i)
|
||||
{
|
||||
|
||||
HANDLE hFile = "";
|
||||
MPQArchive*(hMPQ) = *i;
|
||||
BOOL succ = SFileOpenFileEx(hMPQ,filename,0, &hFile);
|
||||
if (succ)
|
||||
{
|
||||
DWORD s = SFileGetFileSize(hFile, 0);
|
||||
if (!s)
|
||||
{
|
||||
eof = true;
|
||||
buffer = 0;
|
||||
return;
|
||||
}
|
||||
size = (size_t)s;
|
||||
buffer = new char[s];
|
||||
SFileReadFile(hFile, buffer, s, 0, 0);
|
||||
SFileCloseFile(hFile);
|
||||
|
||||
eof = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
eof = true;
|
||||
buffer = 0;
|
||||
|
||||
buffer = new char[s];
|
||||
SFileReadFile(hFile, buffer, s, 0, 0);
|
||||
SFileCloseFile(hFile);
|
||||
|
||||
eof = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
eof = true;
|
||||
buffer = 0;
|
||||
|
||||
}
|
||||
|
||||
MPQFile::~MPQFile()
|
||||
{
|
||||
close();
|
||||
close();
|
||||
}
|
||||
|
||||
size_t MPQFile::read(void* dest, size_t bytes)
|
||||
{
|
||||
if (eof)
|
||||
return 0;
|
||||
if (eof)
|
||||
return 0;
|
||||
|
||||
size_t rpos = pointer + bytes;
|
||||
if (rpos > size)
|
||||
{
|
||||
bytes = size - pointer;
|
||||
eof = true;
|
||||
}
|
||||
size_t rpos = pointer + bytes;
|
||||
if (rpos > size)
|
||||
{
|
||||
bytes = size - pointer;
|
||||
eof = true;
|
||||
}
|
||||
|
||||
memcpy(dest, &(buffer[pointer]), bytes);
|
||||
memcpy(dest, &(buffer[pointer]), bytes);
|
||||
|
||||
pointer = rpos;
|
||||
pointer = rpos;
|
||||
|
||||
return bytes;
|
||||
return bytes;
|
||||
}
|
||||
|
||||
bool MPQFile::isEof()
|
||||
@@ -96,41 +96,41 @@ bool MPQFile::isEof()
|
||||
|
||||
void MPQFile::seek(int offset)
|
||||
{
|
||||
pointer = offset;
|
||||
eof = (pointer >= size);
|
||||
pointer = offset;
|
||||
eof = (pointer >= size);
|
||||
}
|
||||
|
||||
void MPQFile::seekRelative(int offset)
|
||||
{
|
||||
pointer += offset;
|
||||
eof = (pointer >= size);
|
||||
pointer += offset;
|
||||
eof = (pointer >= size);
|
||||
}
|
||||
|
||||
void MPQFile::close()
|
||||
{
|
||||
if (buffer)
|
||||
delete[] buffer;
|
||||
buffer = 0;
|
||||
eof = true;
|
||||
if (buffer)
|
||||
delete[] buffer;
|
||||
buffer = 0;
|
||||
eof = true;
|
||||
}
|
||||
|
||||
size_t MPQFile::getSize()
|
||||
{
|
||||
return size;
|
||||
return size;
|
||||
}
|
||||
|
||||
size_t MPQFile::getPos()
|
||||
{
|
||||
return pointer;
|
||||
return pointer;
|
||||
}
|
||||
|
||||
char* MPQFile::getBuffer()
|
||||
{
|
||||
return buffer;
|
||||
return buffer;
|
||||
}
|
||||
|
||||
char* MPQFile::getPointer()
|
||||
{
|
||||
return buffer + pointer;
|
||||
return buffer + pointer;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#ifndef MPQ_H
|
||||
#define MPQ_H
|
||||
|
||||
#define __STORMLIB_SELF__
|
||||
#define __STORMLIB_SELF__
|
||||
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
@@ -18,49 +18,49 @@ typedef unsigned int uint32;
|
||||
|
||||
class MPQArchive
|
||||
{
|
||||
|
||||
|
||||
public:
|
||||
HANDLE hMPQ;
|
||||
MPQArchive(const char* filename);
|
||||
void close();
|
||||
HANDLE hMPQ;
|
||||
MPQArchive(const char* filename);
|
||||
void close();
|
||||
};
|
||||
|
||||
|
||||
class MPQFile
|
||||
{
|
||||
HANDLE hFile;
|
||||
HANDLE hFile;
|
||||
HANDLE hMPQ;
|
||||
bool eof;
|
||||
char *buffer;
|
||||
size_t pointer,
|
||||
size;
|
||||
bool eof;
|
||||
char *buffer;
|
||||
size_t pointer,
|
||||
size;
|
||||
|
||||
// disable copying
|
||||
//MPQFile(const MPQFile &f) {}
|
||||
//void operator=(const MPQFile &f) {}
|
||||
// disable copying
|
||||
//MPQFile(const MPQFile &f) {}
|
||||
//void operator=(const MPQFile &f) {}
|
||||
|
||||
public:
|
||||
MPQFile(const char* filename);
|
||||
~MPQFile();
|
||||
size_t read(void* dest, size_t bytes);
|
||||
size_t getSize();
|
||||
size_t getPos();
|
||||
char* getBuffer();
|
||||
char* getPointer();
|
||||
bool isEof();
|
||||
void seek(int offset);
|
||||
void seekRelative(int offset);
|
||||
void close();
|
||||
MPQFile(const char* filename);
|
||||
~MPQFile();
|
||||
size_t read(void* dest, size_t bytes);
|
||||
size_t getSize();
|
||||
size_t getPos();
|
||||
char* getBuffer();
|
||||
char* getPointer();
|
||||
bool isEof();
|
||||
void seek(int offset);
|
||||
void seekRelative(int offset);
|
||||
void close();
|
||||
};
|
||||
|
||||
inline void flipcc(char *fcc)
|
||||
{
|
||||
char t;
|
||||
t=fcc[0];
|
||||
fcc[0]=fcc[3];
|
||||
fcc[3]=t;
|
||||
t=fcc[1];
|
||||
fcc[1]=fcc[2];
|
||||
fcc[2]=t;
|
||||
char t;
|
||||
t=fcc[0];
|
||||
fcc[0]=fcc[3];
|
||||
fcc[3]=t;
|
||||
t=fcc[1];
|
||||
fcc[1]=fcc[2];
|
||||
fcc[2]=t;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -8,220 +8,220 @@
|
||||
|
||||
class Vec3D {
|
||||
public:
|
||||
float x,y,z;
|
||||
float x,y,z;
|
||||
|
||||
Vec3D(float x0 = 0.0f, float y0 = 0.0f, float z0 = 0.0f) : x(x0), y(y0), z(z0) {}
|
||||
Vec3D(float x0 = 0.0f, float y0 = 0.0f, float z0 = 0.0f) : x(x0), y(y0), z(z0) {}
|
||||
|
||||
Vec3D(const Vec3D& v) : x(v.x), y(v.y), z(v.z) {}
|
||||
Vec3D(const Vec3D& v) : x(v.x), y(v.y), z(v.z) {}
|
||||
|
||||
Vec3D& operator= (const Vec3D &v) {
|
||||
Vec3D& operator= (const Vec3D &v) {
|
||||
x = v.x;
|
||||
y = v.y;
|
||||
z = v.z;
|
||||
return *this;
|
||||
}
|
||||
y = v.y;
|
||||
z = v.z;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vec3D operator+ (const Vec3D &v) const
|
||||
{
|
||||
Vec3D r(x+v.x,y+v.y,z+v.z);
|
||||
Vec3D operator+ (const Vec3D &v) const
|
||||
{
|
||||
Vec3D r(x+v.x,y+v.y,z+v.z);
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
Vec3D operator- (const Vec3D &v) const
|
||||
{
|
||||
Vec3D r(x-v.x,y-v.y,z-v.z);
|
||||
return r;
|
||||
}
|
||||
Vec3D operator- (const Vec3D &v) const
|
||||
{
|
||||
Vec3D r(x-v.x,y-v.y,z-v.z);
|
||||
return r;
|
||||
}
|
||||
|
||||
float operator* (const Vec3D &v) const
|
||||
{
|
||||
float operator* (const Vec3D &v) const
|
||||
{
|
||||
return x*v.x + y*v.y + z*v.z;
|
||||
}
|
||||
}
|
||||
|
||||
Vec3D operator* (float d) const
|
||||
{
|
||||
Vec3D r(x*d,y*d,z*d);
|
||||
Vec3D operator* (float d) const
|
||||
{
|
||||
Vec3D r(x*d,y*d,z*d);
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
friend Vec3D operator* (float d, const Vec3D& v)
|
||||
{
|
||||
return v * d;
|
||||
}
|
||||
friend Vec3D operator* (float d, const Vec3D& v)
|
||||
{
|
||||
return v * d;
|
||||
}
|
||||
|
||||
Vec3D operator% (const Vec3D &v) const
|
||||
{
|
||||
Vec3D operator% (const Vec3D &v) const
|
||||
{
|
||||
Vec3D r(y*v.z-z*v.y, z*v.x-x*v.z, x*v.y-y*v.x);
|
||||
return r;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
Vec3D& operator+= (const Vec3D &v)
|
||||
{
|
||||
x += v.x;
|
||||
y += v.y;
|
||||
z += v.z;
|
||||
return *this;
|
||||
}
|
||||
Vec3D& operator+= (const Vec3D &v)
|
||||
{
|
||||
x += v.x;
|
||||
y += v.y;
|
||||
z += v.z;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vec3D& operator-= (const Vec3D &v)
|
||||
{
|
||||
x -= v.x;
|
||||
y -= v.y;
|
||||
z -= v.z;
|
||||
return *this;
|
||||
}
|
||||
Vec3D& operator-= (const Vec3D &v)
|
||||
{
|
||||
x -= v.x;
|
||||
y -= v.y;
|
||||
z -= v.z;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vec3D& operator*= (float d)
|
||||
{
|
||||
x *= d;
|
||||
y *= d;
|
||||
z *= d;
|
||||
return *this;
|
||||
}
|
||||
Vec3D& operator*= (float d)
|
||||
{
|
||||
x *= d;
|
||||
y *= d;
|
||||
z *= d;
|
||||
return *this;
|
||||
}
|
||||
|
||||
float lengthSquared() const
|
||||
{
|
||||
return x*x+y*y+z*z;
|
||||
}
|
||||
float lengthSquared() const
|
||||
{
|
||||
return x*x+y*y+z*z;
|
||||
}
|
||||
|
||||
float length() const
|
||||
{
|
||||
float length() const
|
||||
{
|
||||
return sqrt(x*x+y*y+z*z);
|
||||
}
|
||||
}
|
||||
|
||||
Vec3D& normalize()
|
||||
{
|
||||
this->operator*= (1.0f/length());
|
||||
return *this;
|
||||
}
|
||||
Vec3D& normalize()
|
||||
{
|
||||
this->operator*= (1.0f/length());
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vec3D operator~ () const
|
||||
{
|
||||
Vec3D r(*this);
|
||||
Vec3D operator~ () const
|
||||
{
|
||||
Vec3D r(*this);
|
||||
r.normalize();
|
||||
return r;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
friend std::istream& operator>>(std::istream& in, Vec3D& v)
|
||||
{
|
||||
in >> v.x >> v.y >> v.z;
|
||||
return in;
|
||||
}
|
||||
friend std::istream& operator>>(std::istream& in, Vec3D& v)
|
||||
{
|
||||
in >> v.x >> v.y >> v.z;
|
||||
return in;
|
||||
}
|
||||
|
||||
operator float*()
|
||||
{
|
||||
return (float*)this;
|
||||
}
|
||||
operator float*()
|
||||
{
|
||||
return (float*)this;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
class Vec2D {
|
||||
public:
|
||||
float x,y;
|
||||
|
||||
Vec2D(float x0 = 0.0f, float y0 = 0.0f) : x(x0), y(y0) {}
|
||||
float x,y;
|
||||
|
||||
Vec2D(const Vec2D& v) : x(v.x), y(v.y) {}
|
||||
Vec2D(float x0 = 0.0f, float y0 = 0.0f) : x(x0), y(y0) {}
|
||||
|
||||
Vec2D& operator= (const Vec2D &v) {
|
||||
Vec2D(const Vec2D& v) : x(v.x), y(v.y) {}
|
||||
|
||||
Vec2D& operator= (const Vec2D &v) {
|
||||
x = v.x;
|
||||
y = v.y;
|
||||
return *this;
|
||||
}
|
||||
y = v.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vec2D operator+ (const Vec2D &v) const
|
||||
{
|
||||
Vec2D r(x+v.x,y+v.y);
|
||||
Vec2D operator+ (const Vec2D &v) const
|
||||
{
|
||||
Vec2D r(x+v.x,y+v.y);
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
Vec2D operator- (const Vec2D &v) const
|
||||
{
|
||||
Vec2D r(x-v.x,y-v.y);
|
||||
return r;
|
||||
}
|
||||
Vec2D operator- (const Vec2D &v) const
|
||||
{
|
||||
Vec2D r(x-v.x,y-v.y);
|
||||
return r;
|
||||
}
|
||||
|
||||
float operator* (const Vec2D &v) const
|
||||
{
|
||||
float operator* (const Vec2D &v) const
|
||||
{
|
||||
return x*v.x + y*v.y;
|
||||
}
|
||||
}
|
||||
|
||||
Vec2D operator* (float d) const
|
||||
{
|
||||
Vec2D r(x*d,y*d);
|
||||
Vec2D operator* (float d) const
|
||||
{
|
||||
Vec2D r(x*d,y*d);
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
friend Vec2D operator* (float d, const Vec2D& v)
|
||||
{
|
||||
return v * d;
|
||||
}
|
||||
friend Vec2D operator* (float d, const Vec2D& v)
|
||||
{
|
||||
return v * d;
|
||||
}
|
||||
|
||||
Vec2D& operator+= (const Vec2D &v)
|
||||
{
|
||||
x += v.x;
|
||||
y += v.y;
|
||||
return *this;
|
||||
}
|
||||
Vec2D& operator+= (const Vec2D &v)
|
||||
{
|
||||
x += v.x;
|
||||
y += v.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vec2D& operator-= (const Vec2D &v)
|
||||
{
|
||||
x -= v.x;
|
||||
y -= v.y;
|
||||
return *this;
|
||||
}
|
||||
Vec2D& operator-= (const Vec2D &v)
|
||||
{
|
||||
x -= v.x;
|
||||
y -= v.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vec2D& operator*= (float d)
|
||||
{
|
||||
x *= d;
|
||||
y *= d;
|
||||
return *this;
|
||||
}
|
||||
Vec2D& operator*= (float d)
|
||||
{
|
||||
x *= d;
|
||||
y *= d;
|
||||
return *this;
|
||||
}
|
||||
|
||||
float lengthSquared() const
|
||||
{
|
||||
return x*x+y*y;
|
||||
}
|
||||
float lengthSquared() const
|
||||
{
|
||||
return x*x+y*y;
|
||||
}
|
||||
|
||||
float length() const
|
||||
{
|
||||
float length() const
|
||||
{
|
||||
return sqrt(x*x+y*y);
|
||||
}
|
||||
}
|
||||
|
||||
Vec2D& normalize()
|
||||
{
|
||||
this->operator*= (1.0f/length());
|
||||
return *this;
|
||||
}
|
||||
Vec2D& normalize()
|
||||
{
|
||||
this->operator*= (1.0f/length());
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vec2D operator~ () const
|
||||
{
|
||||
Vec2D r(*this);
|
||||
Vec2D operator~ () const
|
||||
{
|
||||
Vec2D r(*this);
|
||||
r.normalize();
|
||||
return r;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
friend std::istream& operator>>(std::istream& in, Vec2D& v)
|
||||
{
|
||||
friend std::istream& operator>>(std::istream& in, Vec2D& v)
|
||||
{
|
||||
in >> v.x >> v.y;
|
||||
return in;
|
||||
}
|
||||
return in;
|
||||
}
|
||||
|
||||
operator float*()
|
||||
{
|
||||
return (float*)this;
|
||||
}
|
||||
operator float*()
|
||||
{
|
||||
return (float*)this;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
inline void rotate(float x0, float y0, float *x, float *y, float angle)
|
||||
{
|
||||
float xa = *x - x0, ya = *y - y0;
|
||||
*x = xa*cosf(angle) - ya*sinf(angle) + x0;
|
||||
*y = xa*sinf(angle) + ya*cosf(angle) + y0;
|
||||
float xa = *x - x0, ya = *y - y0;
|
||||
*x = xa*cosf(angle) - ya*sinf(angle) + x0;
|
||||
*y = xa*sinf(angle) + ya*cosf(angle) + y0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
#define __STORMLIB_SELF__ // Don't use StormLib.lib
|
||||
#include "StormLib.h"
|
||||
|
||||
#pragma warning(disable : 4505)
|
||||
#pragma warning(disable : 4505)
|
||||
#pragma comment(lib, "Winmm.lib")
|
||||
|
||||
//From Extractor
|
||||
@@ -58,7 +58,7 @@ char input_path[1024]=".";
|
||||
bool hasInputPathParam = false;
|
||||
char tmp[512];
|
||||
bool preciseVectorData = false;
|
||||
//char gamepath[1024];
|
||||
//char gamepath[1024];
|
||||
|
||||
//Convert function
|
||||
//bool ConvertADT(char*,char*);
|
||||
@@ -106,9 +106,9 @@ static void ShowProcessedFile(const char * szFileName)
|
||||
int ExtractWmo(const std::vector<std::string>& pArchiveNames)
|
||||
{
|
||||
|
||||
char* szListFile = "";
|
||||
char* szListFile = "";
|
||||
char szLocalFile[MAX_PATH] = "";
|
||||
HANDLE hMpq = "";
|
||||
HANDLE hMpq = "";
|
||||
BOOL bResult = FALSE;
|
||||
|
||||
//const char* ParsArchiveNames[] = {"patch-2.MPQ", "patch.MPQ", "common.MPQ", "expansion.MPQ"};
|
||||
@@ -128,7 +128,7 @@ int ExtractWmo(const std::vector<std::string>& pArchiveNames)
|
||||
|
||||
// Copy files from archive
|
||||
if(nError == ERROR_SUCCESS)
|
||||
{
|
||||
{
|
||||
SFILE_FIND_DATA wf;
|
||||
HANDLE hFind = SFileFindFirstFile(hMpq,"*.wmo*", &wf, szListFile);
|
||||
bResult = TRUE;
|
||||
@@ -153,7 +153,7 @@ int ExtractWmo(const std::vector<std::string>& pArchiveNames)
|
||||
{
|
||||
int m = cpy[i];
|
||||
if(isdigit(m))
|
||||
p++;
|
||||
p++;
|
||||
}
|
||||
}
|
||||
if(p != 3)
|
||||
@@ -189,12 +189,12 @@ int ExtractWmo(const std::vector<std::string>& pArchiveNames)
|
||||
bResult = SFileFindNextFile(hFind, &wf);
|
||||
break;
|
||||
}
|
||||
Wmo_nVertices += fgroup->ConvertToVMAPGroupWmo(output, preciseVectorData);
|
||||
Wmo_nVertices += fgroup->ConvertToVMAPGroupWmo(output, preciseVectorData);
|
||||
}
|
||||
}
|
||||
fseek(output, 8, SEEK_SET); // store the correct no of vertices
|
||||
fwrite(&Wmo_nVertices,sizeof(int),1,output);
|
||||
fclose(output);
|
||||
fclose(output);
|
||||
}
|
||||
} else {
|
||||
fclose(n);
|
||||
@@ -269,7 +269,7 @@ void ParsMapFiles()
|
||||
{
|
||||
for (int x=0; x<64; x++)
|
||||
{
|
||||
for (int y=0; y<64; y++)
|
||||
for (int y=0; y<64; y++)
|
||||
{
|
||||
if (ADTFile*ADT = WDT.GetMap(x,y))
|
||||
{
|
||||
@@ -297,10 +297,10 @@ void getGamePath()
|
||||
//l = RegOpenKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\\Blizzard Entertainment\\Burning Crusade Closed Beta",0,KEY_QUERY_VALUE,&key);
|
||||
l = RegQueryValueEx(key,"InstallPath",0,&t,(LPBYTE)input_path,&s);
|
||||
RegCloseKey(key);
|
||||
if (strlen(input_path) > 0)
|
||||
{
|
||||
if (input_path[strlen(input_path) - 1] != '\\') strcat(input_path, "\\");
|
||||
}
|
||||
if (strlen(input_path) > 0)
|
||||
{
|
||||
if (input_path[strlen(input_path) - 1] != '\\') strcat(input_path, "\\");
|
||||
}
|
||||
strcat(input_path,"Data\\");
|
||||
#else
|
||||
strcpy(input_path,"data/");
|
||||
@@ -450,9 +450,9 @@ bool processArgv(int argc, char ** argv, char*versionString)
|
||||
bool preciseVectorData = false;
|
||||
|
||||
for(int i=1; i< argc; ++i) {
|
||||
if(strcmp("-s",argv[i]) == 0) {
|
||||
preciseVectorData = false;
|
||||
} else if(strcmp("-d",argv[i]) == 0) {
|
||||
if(strcmp("-s",argv[i]) == 0) {
|
||||
preciseVectorData = false;
|
||||
} else if(strcmp("-d",argv[i]) == 0) {
|
||||
if((i+1)<argc) {
|
||||
hasInputPathParam = true;
|
||||
strcpy(input_path, argv[i+1]);
|
||||
@@ -462,10 +462,10 @@ bool processArgv(int argc, char ** argv, char*versionString)
|
||||
} else {
|
||||
result = false;
|
||||
}
|
||||
} else if(strcmp("-?",argv[1]) == 0) {
|
||||
} else if(strcmp("-?",argv[1]) == 0) {
|
||||
result = false;
|
||||
} else if(strcmp("-l",argv[i]) == 0) {
|
||||
preciseVectorData = true;
|
||||
} else if(strcmp("-l",argv[i]) == 0) {
|
||||
preciseVectorData = true;
|
||||
} else {
|
||||
result = false;
|
||||
break;
|
||||
@@ -484,7 +484,7 @@ bool processArgv(int argc, char ** argv, char*versionString)
|
||||
|
||||
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||
// Main
|
||||
//
|
||||
//
|
||||
// The program must be run with two command line arguments
|
||||
//
|
||||
// Arg1 - The source MPQ name (for testing reading and file find)
|
||||
@@ -506,9 +506,9 @@ int main(int argc, char ** argv)
|
||||
char *versionString = "V2.4 2007_07_12";
|
||||
|
||||
// Use command line arguments, when some
|
||||
if(!processArgv(argc, argv, versionString))
|
||||
if(!processArgv(argc, argv, versionString))
|
||||
return 1;
|
||||
|
||||
|
||||
printf("Extract %s. Beginning work ....\n",versionString);
|
||||
// Set the lowest priority to allow running in the background
|
||||
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_BELOW_NORMAL);
|
||||
@@ -522,7 +522,7 @@ int main(int argc, char ** argv)
|
||||
nError = GetLastError();
|
||||
if(nError == ERROR_ALREADY_EXISTS)
|
||||
nError = ERROR_SUCCESS;
|
||||
}
|
||||
}
|
||||
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||
// patch goes first -> fake priority handling
|
||||
std::vector<MPQArchive*> archives;
|
||||
@@ -548,7 +548,7 @@ int main(int argc, char ** argv)
|
||||
{
|
||||
map_ids[x].id=dbc->getRecord (x).getUInt(0);
|
||||
strcpy(map_ids[x].name,dbc->getRecord(x).getString(1));
|
||||
printf("Map - %s\n",map_ids[x].name);
|
||||
printf("Map - %s\n",map_ids[x].name);
|
||||
}
|
||||
|
||||
delete dbc;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user