From 289acf3333cf76ffc689aff8a17340b299ce0686 Mon Sep 17 00:00:00 2001 From: Amaury Pouly Date: Mon, 11 Mar 2013 18:51:11 +0100 Subject: Fix libmspack to compile with rbutil The build system used by rbutil is not very robust: all the files are eventually compiled to the same directory so we cannot have two files with the same name (system.c would conflicts with system.cpp) so rename one file to avoid this. Also change all include directives to local ones because we don't have to expose the entire mspack source to inclusion. Change-Id: I3fe0638d69fdc30566eb9425abfe33c807678b28 Reviewed-on: http://gerrit.rockbox.org/417 Reviewed-by: Dominik Riebeling --- rbutil/rbutilqt/mspack/cab.h | 6 +- rbutil/rbutilqt/mspack/cabc.c | 4 +- rbutil/rbutilqt/mspack/cabd.c | 4 +- rbutil/rbutilqt/mspack/chm.h | 2 +- rbutil/rbutilqt/mspack/chmc.c | 4 +- rbutil/rbutilqt/mspack/chmd.c | 4 +- rbutil/rbutilqt/mspack/hlp.h | 2 +- rbutil/rbutilqt/mspack/hlpc.c | 4 +- rbutil/rbutilqt/mspack/hlpd.c | 4 +- rbutil/rbutilqt/mspack/kwaj.h | 2 +- rbutil/rbutilqt/mspack/kwajc.c | 4 +- rbutil/rbutilqt/mspack/kwajd.c | 8 +- rbutil/rbutilqt/mspack/lit.h | 6 +- rbutil/rbutilqt/mspack/litc.c | 4 +- rbutil/rbutilqt/mspack/litd.c | 4 +- rbutil/rbutilqt/mspack/lzssd.c | 4 +- rbutil/rbutilqt/mspack/lzxc.c | 4 +- rbutil/rbutilqt/mspack/lzxd.c | 8 +- rbutil/rbutilqt/mspack/mszipc.c | 4 +- rbutil/rbutilqt/mspack/mszipd.c | 8 +- rbutil/rbutilqt/mspack/qtmd.c | 6 +- rbutil/rbutilqt/mspack/system-mspack.c | 237 +++++++++++++++++++++++++++++++++ rbutil/rbutilqt/mspack/system-mspack.h | 124 +++++++++++++++++ rbutil/rbutilqt/mspack/system.c | 237 --------------------------------- rbutil/rbutilqt/mspack/system.h | 124 ----------------- rbutil/rbutilqt/mspack/szdd.h | 2 +- rbutil/rbutilqt/mspack/szddc.c | 4 +- rbutil/rbutilqt/mspack/szddd.c | 4 +- 28 files changed, 414 insertions(+), 414 deletions(-) create mode 100644 rbutil/rbutilqt/mspack/system-mspack.c create mode 100644 rbutil/rbutilqt/mspack/system-mspack.h delete mode 100644 rbutil/rbutilqt/mspack/system.c delete mode 100644 rbutil/rbutilqt/mspack/system.h diff --git a/rbutil/rbutilqt/mspack/cab.h b/rbutil/rbutilqt/mspack/cab.h index 9f449d1f29..78ec8e60db 100644 --- a/rbutil/rbutilqt/mspack/cab.h +++ b/rbutil/rbutilqt/mspack/cab.h @@ -10,9 +10,9 @@ #ifndef MSPACK_CAB_H #define MSPACK_CAB_H 1 -#include -#include -#include +#include "mszip.h" +#include "qtm.h" +#include "lzx.h" /* generic CAB definitions */ diff --git a/rbutil/rbutilqt/mspack/cabc.c b/rbutil/rbutilqt/mspack/cabc.c index 242e0347c3..eb85011056 100644 --- a/rbutil/rbutilqt/mspack/cabc.c +++ b/rbutil/rbutilqt/mspack/cabc.c @@ -9,8 +9,8 @@ /* CAB compression implementation */ -#include -#include +#include "system-mspack.h" +#include "cab.h" struct mscab_compressor * mspack_create_cab_compressor(struct mspack_system *sys) diff --git a/rbutil/rbutilqt/mspack/cabd.c b/rbutil/rbutilqt/mspack/cabd.c index 24ff2031f3..cf91cfb3b4 100644 --- a/rbutil/rbutilqt/mspack/cabd.c +++ b/rbutil/rbutilqt/mspack/cabd.c @@ -21,8 +21,8 @@ /* CAB decompression implementation */ -#include -#include +#include "system-mspack.h" +#include "cab.h" #include /* Notes on compliance with cabinet specification: diff --git a/rbutil/rbutilqt/mspack/chm.h b/rbutil/rbutilqt/mspack/chm.h index a85d2e1731..4b19f1505a 100644 --- a/rbutil/rbutilqt/mspack/chm.h +++ b/rbutil/rbutilqt/mspack/chm.h @@ -10,7 +10,7 @@ #ifndef MSPACK_CHM_H #define MSPACK_CHM_H 1 -#include +#include "lzx.h" /* generic CHM definitions */ diff --git a/rbutil/rbutilqt/mspack/chmc.c b/rbutil/rbutilqt/mspack/chmc.c index 72f6c5b389..b9a1d8856c 100644 --- a/rbutil/rbutilqt/mspack/chmc.c +++ b/rbutil/rbutilqt/mspack/chmc.c @@ -9,8 +9,8 @@ /* CHM compression implementation */ -#include -#include +#include "system-mspack.h" +#include "chm.h" struct mschm_compressor * mspack_create_chm_compressor(struct mspack_system *sys) diff --git a/rbutil/rbutilqt/mspack/chmd.c b/rbutil/rbutilqt/mspack/chmd.c index 6e4a1bf24f..416156e742 100644 --- a/rbutil/rbutilqt/mspack/chmd.c +++ b/rbutil/rbutilqt/mspack/chmd.c @@ -9,8 +9,8 @@ /* CHM decompression implementation */ -#include -#include +#include "system-mspack.h" +#include "chm.h" /* prototypes */ static struct mschmd_header * chmd_open( diff --git a/rbutil/rbutilqt/mspack/hlp.h b/rbutil/rbutilqt/mspack/hlp.h index b7486fa160..a6e3abc7ff 100644 --- a/rbutil/rbutilqt/mspack/hlp.h +++ b/rbutil/rbutilqt/mspack/hlp.h @@ -10,7 +10,7 @@ #ifndef MSPACK_HLP_H #define MSPACK_HLP_H 1 -#include +#include "lzss.h" /* generic HLP definitions */ diff --git a/rbutil/rbutilqt/mspack/hlpc.c b/rbutil/rbutilqt/mspack/hlpc.c index 60eabfe207..b33e499f65 100644 --- a/rbutil/rbutilqt/mspack/hlpc.c +++ b/rbutil/rbutilqt/mspack/hlpc.c @@ -9,8 +9,8 @@ /* HLP compression implementation */ -#include -#include +#include "system-mspack.h" +#include "hlp.h" struct mshlp_compressor * mspack_create_hlp_compressor(struct mspack_system *sys) diff --git a/rbutil/rbutilqt/mspack/hlpd.c b/rbutil/rbutilqt/mspack/hlpd.c index 43354f008f..ae1f2efba8 100644 --- a/rbutil/rbutilqt/mspack/hlpd.c +++ b/rbutil/rbutilqt/mspack/hlpd.c @@ -9,8 +9,8 @@ /* HLP decompression implementation */ -#include -#include +#include "system-mspack.h" +#include "hlp.h" struct mshlp_decompressor * mspack_create_hlp_decompressor(struct mspack_system *sys) diff --git a/rbutil/rbutilqt/mspack/kwaj.h b/rbutil/rbutilqt/mspack/kwaj.h index 09673c0779..75425d958a 100644 --- a/rbutil/rbutilqt/mspack/kwaj.h +++ b/rbutil/rbutilqt/mspack/kwaj.h @@ -10,7 +10,7 @@ #ifndef MSPACK_KWAJ_H #define MSPACK_KWAJ_H 1 -#include +#include "lzss.h" /* generic KWAJ definitions */ #define kwajh_Signature1 (0x00) diff --git a/rbutil/rbutilqt/mspack/kwajc.c b/rbutil/rbutilqt/mspack/kwajc.c index b88ed7690a..52ca29432a 100644 --- a/rbutil/rbutilqt/mspack/kwajc.c +++ b/rbutil/rbutilqt/mspack/kwajc.c @@ -9,8 +9,8 @@ /* KWAJ compression implementation */ -#include -#include +#include "system-mspack.h" +#include "kwaj.h" struct mskwaj_compressor * mspack_create_kwaj_compressor(struct mspack_system *sys) diff --git a/rbutil/rbutilqt/mspack/kwajd.c b/rbutil/rbutilqt/mspack/kwajd.c index d891b6a7e3..440f1dcfdd 100644 --- a/rbutil/rbutilqt/mspack/kwajd.c +++ b/rbutil/rbutilqt/mspack/kwajd.c @@ -12,8 +12,8 @@ /* KWAJ decompression implementation */ -#include -#include +#include "system-mspack.h" +#include "kwaj.h" /* prototypes */ static struct mskwajd_header *kwajd_open( @@ -361,7 +361,7 @@ static int kwajd_error(struct mskwaj_decompressor *base) } \ INJECT_BITS(*i_ptr++, 8); \ } while (0) -#include +#include "readbits.h" /* import huffman-reading macros and code */ #define TABLEBITS(tbl) KWAJ_TABLEBITS @@ -369,7 +369,7 @@ static int kwajd_error(struct mskwaj_decompressor *base) #define HUFF_TABLE(tbl,idx) lzh->tbl##_table[idx] #define HUFF_LEN(tbl,idx) lzh->tbl##_len[idx] #define HUFF_ERROR return MSPACK_ERR_DATAFORMAT -#include +#include "readhuff.h" /* In the KWAJ LZH format, there is no special 'eof' marker, it just * ends. Depending on how many bits are left in the final byte when diff --git a/rbutil/rbutilqt/mspack/lit.h b/rbutil/rbutilqt/mspack/lit.h index 79ba44d877..2ccc7dd7f3 100644 --- a/rbutil/rbutilqt/mspack/lit.h +++ b/rbutil/rbutilqt/mspack/lit.h @@ -10,9 +10,9 @@ #ifndef MSPACK_LIT_H #define MSPACK_LIT_H 1 -#include -#include -#include +#include "lzx.h" +#include "des.h" +#include "sha.h" /* generic LIT definitions */ diff --git a/rbutil/rbutilqt/mspack/litc.c b/rbutil/rbutilqt/mspack/litc.c index a8a709af07..4959a81d36 100644 --- a/rbutil/rbutilqt/mspack/litc.c +++ b/rbutil/rbutilqt/mspack/litc.c @@ -9,8 +9,8 @@ /* LIT compression implementation */ -#include -#include +#include "system-mspack.h" +#include "lit.h" struct mslit_compressor * mspack_create_lit_compressor(struct mspack_system *sys) diff --git a/rbutil/rbutilqt/mspack/litd.c b/rbutil/rbutilqt/mspack/litd.c index 6e0dc9af27..93cbf1765a 100644 --- a/rbutil/rbutilqt/mspack/litd.c +++ b/rbutil/rbutilqt/mspack/litd.c @@ -9,8 +9,8 @@ /* LIT decompression implementation */ -#include -#include +#include "system-mspack.h" +#include "lit.h" struct mslit_decompressor * mspack_create_lit_decompressor(struct mspack_system *sys) diff --git a/rbutil/rbutilqt/mspack/lzssd.c b/rbutil/rbutilqt/mspack/lzssd.c index df294bc132..f1a47c7a01 100644 --- a/rbutil/rbutilqt/mspack/lzssd.c +++ b/rbutil/rbutilqt/mspack/lzssd.c @@ -11,8 +11,8 @@ * For further details, see the file COPYING.LIB distributed with libmspack */ -#include -#include +#include "system-mspack.h" +#include "lzss.h" #define ENSURE_BYTES do { \ if (i_ptr >= i_end) { \ diff --git a/rbutil/rbutilqt/mspack/lzxc.c b/rbutil/rbutilqt/mspack/lzxc.c index 1207a0d747..89d8c610ea 100644 --- a/rbutil/rbutilqt/mspack/lzxc.c +++ b/rbutil/rbutilqt/mspack/lzxc.c @@ -12,7 +12,7 @@ /* LZX compression implementation */ -#include -#include +#include "system-mspack.h" +#include "lzx.h" /* todo */ diff --git a/rbutil/rbutilqt/mspack/lzxd.c b/rbutil/rbutilqt/mspack/lzxd.c index cebc4c23d3..9b26bac3e0 100644 --- a/rbutil/rbutilqt/mspack/lzxd.c +++ b/rbutil/rbutilqt/mspack/lzxd.c @@ -12,8 +12,8 @@ /* LZX decompression implementation */ -#include -#include +#include "system-mspack.h" +#include "lzx.h" /* Microsoft's LZX document (in cab-sdk.exe) and their implementation * of the com.ms.util.cab Java package do not concur. @@ -85,7 +85,7 @@ READ_IF_NEEDED; b1 = *i_ptr++; \ INJECT_BITS((b1 << 8) | b0, 16); \ } while (0) -#include +#include "readbits.h" /* import huffman-reading macros and code */ #define TABLEBITS(tbl) LZX_##tbl##_TABLEBITS @@ -93,7 +93,7 @@ #define HUFF_TABLE(tbl,idx) lzx->tbl##_table[idx] #define HUFF_LEN(tbl,idx) lzx->tbl##_len[idx] #define HUFF_ERROR return lzx->error = MSPACK_ERR_DECRUNCH -#include +#include "readhuff.h" /* BUILD_TABLE(tbl) builds a huffman lookup table from code lengths */ #define BUILD_TABLE(tbl) \ diff --git a/rbutil/rbutilqt/mspack/mszipc.c b/rbutil/rbutilqt/mspack/mszipc.c index 2f1ecb2e87..2f14b9ac83 100644 --- a/rbutil/rbutilqt/mspack/mszipc.c +++ b/rbutil/rbutilqt/mspack/mszipc.c @@ -12,7 +12,7 @@ /* MS-ZIP compression implementation */ -#include -#include +#include "system-mspack.h" +#include "mszip.h" /* todo */ diff --git a/rbutil/rbutilqt/mspack/mszipd.c b/rbutil/rbutilqt/mspack/mszipd.c index 5b7ef4ff4d..3c158fbd4d 100644 --- a/rbutil/rbutilqt/mspack/mszipd.c +++ b/rbutil/rbutilqt/mspack/mszipd.c @@ -12,8 +12,8 @@ /* MS-ZIP decompression implementation. */ -#include -#include +#include "system-mspack.h" +#include "mszip.h" /* import bit-reading macros and code */ #define BITS_TYPE struct mszipd_stream @@ -24,7 +24,7 @@ READ_IF_NEEDED; \ INJECT_BITS(*i_ptr++, 8); \ } while (0) -#include +#include "readbits.h" /* import huffman macros and code */ #define TABLEBITS(tbl) MSZIP_##tbl##_TABLEBITS @@ -32,7 +32,7 @@ #define HUFF_TABLE(tbl,idx) zip->tbl##_table[idx] #define HUFF_LEN(tbl,idx) zip->tbl##_len[idx] #define HUFF_ERROR return INF_ERR_HUFFSYM -#include +#include "readhuff.h" #define FLUSH_IF_NEEDED do { \ if (zip->window_posn == MSZIP_FRAME_SIZE) { \ diff --git a/rbutil/rbutilqt/mspack/qtmd.c b/rbutil/rbutilqt/mspack/qtmd.c index 12b27f5608..0fb20da167 100644 --- a/rbutil/rbutilqt/mspack/qtmd.c +++ b/rbutil/rbutilqt/mspack/qtmd.c @@ -20,8 +20,8 @@ * http://www.speakeasy.org/~russotto/quantumcomp.html */ -#include -#include +#include "system-mspack.h" +#include "qtm.h" /* import bit-reading macros and code */ #define BITS_TYPE struct qtmd_stream @@ -33,7 +33,7 @@ READ_IF_NEEDED; b1 = *i_ptr++; \ INJECT_BITS((b0 << 8) | b1, 16); \ } while (0) -#include +#include "readbits.h" /* Quantum static data tables: * diff --git a/rbutil/rbutilqt/mspack/system-mspack.c b/rbutil/rbutilqt/mspack/system-mspack.c new file mode 100644 index 0000000000..a7f4a5c218 --- /dev/null +++ b/rbutil/rbutilqt/mspack/system-mspack.c @@ -0,0 +1,237 @@ +/* This file is part of libmspack. + * (C) 2003-2004 Stuart Caie. + * + * libmspack is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License (LGPL) version 2.1 + * + * For further details, see the file COPYING.LIB distributed with libmspack + */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "system-mspack.h" + +#ifndef LARGEFILE_SUPPORT +const char *largefile_msg = "library not compiled to support large files."; +#endif + + +int mspack_version(int entity) { + switch (entity) { + /* CHM decoder version 1 -> 2 changes: + * - added mschmd_sec_mscompressed::spaninfo + * - added mschmd_header::first_pmgl + * - added mschmd_header::last_pmgl + * - added mschmd_header::chunk_cache; + */ + case MSPACK_VER_MSCHMD: + return 2; + case MSPACK_VER_LIBRARY: + case MSPACK_VER_SYSTEM: + case MSPACK_VER_MSCABD: + case MSPACK_VER_MSSZDDD: + case MSPACK_VER_MSKWAJD: + return 1; + case MSPACK_VER_MSCABC: + case MSPACK_VER_MSCHMC: + case MSPACK_VER_MSLITD: + case MSPACK_VER_MSLITC: + case MSPACK_VER_MSHLPD: + case MSPACK_VER_MSHLPC: + case MSPACK_VER_MSSZDDC: + case MSPACK_VER_MSKWAJC: + return 0; + } + return -1; +} + +int mspack_sys_selftest_internal(int offt_size) { + return (sizeof(off_t) == offt_size) ? MSPACK_ERR_OK : MSPACK_ERR_SEEK; +} + +/* validates a system structure */ +int mspack_valid_system(struct mspack_system *sys) { + return (sys != NULL) && (sys->open != NULL) && (sys->close != NULL) && + (sys->read != NULL) && (sys->write != NULL) && (sys->seek != NULL) && + (sys->tell != NULL) && (sys->message != NULL) && (sys->alloc != NULL) && + (sys->free != NULL) && (sys->copy != NULL) && (sys->null_ptr == NULL); +} + +/* returns the length of a file opened for reading */ +int mspack_sys_filelen(struct mspack_system *system, + struct mspack_file *file, off_t *length) +{ + off_t current; + + if (!system || !file || !length) return MSPACK_ERR_OPEN; + + /* get current offset */ + current = system->tell(file); + + /* seek to end of file */ + if (system->seek(file, (off_t) 0, MSPACK_SYS_SEEK_END)) { + return MSPACK_ERR_SEEK; + } + + /* get offset of end of file */ + *length = system->tell(file); + + /* seek back to original offset */ + if (system->seek(file, current, MSPACK_SYS_SEEK_START)) { + return MSPACK_ERR_SEEK; + } + + return MSPACK_ERR_OK; +} + + + +/* definition of mspack_default_system -- if the library is compiled with + * MSPACK_NO_DEFAULT_SYSTEM, no default system will be provided. Otherwise, + * an appropriate default system (e.g. the standard C library, or some native + * API calls) + */ + +#ifdef MSPACK_NO_DEFAULT_SYSTEM +struct mspack_system *mspack_default_system = NULL; +#else + +/* implementation of mspack_default_system for standard C library */ + +#include +#include +#include +#include + +struct mspack_file_p { + FILE *fh; + const char *name; +}; + +static struct mspack_file *msp_open(struct mspack_system *self, + const char *filename, int mode) +{ + struct mspack_file_p *fh; + const char *fmode; + + switch (mode) { + case MSPACK_SYS_OPEN_READ: fmode = "rb"; break; + case MSPACK_SYS_OPEN_WRITE: fmode = "wb"; break; + case MSPACK_SYS_OPEN_UPDATE: fmode = "r+b"; break; + case MSPACK_SYS_OPEN_APPEND: fmode = "ab"; break; + default: return NULL; + } + + if ((fh = (struct mspack_file_p *) malloc(sizeof(struct mspack_file_p)))) { + fh->name = filename; + if ((fh->fh = fopen(filename, fmode))) return (struct mspack_file *) fh; + free(fh); + } + return NULL; +} + +static void msp_close(struct mspack_file *file) { + struct mspack_file_p *self = (struct mspack_file_p *) file; + if (self) { + fclose(self->fh); + free(self); + } +} + +static int msp_read(struct mspack_file *file, void *buffer, int bytes) { + struct mspack_file_p *self = (struct mspack_file_p *) file; + if (self && buffer && bytes >= 0) { + size_t count = fread(buffer, 1, (size_t) bytes, self->fh); + if (!ferror(self->fh)) return (int) count; + } + return -1; +} + +static int msp_write(struct mspack_file *file, void *buffer, int bytes) { + struct mspack_file_p *self = (struct mspack_file_p *) file; + if (self && buffer && bytes >= 0) { + size_t count = fwrite(buffer, 1, (size_t) bytes, self->fh); + if (!ferror(self->fh)) return (int) count; + } + return -1; +} + +static int msp_seek(struct mspack_file *file, off_t offset, int mode) { + struct mspack_file_p *self = (struct mspack_file_p *) file; + if (self) { + switch (mode) { + case MSPACK_SYS_SEEK_START: mode = SEEK_SET; break; + case MSPACK_SYS_SEEK_CUR: mode = SEEK_CUR; break; + case MSPACK_SYS_SEEK_END: mode = SEEK_END; break; + default: return -1; + } +#ifdef HAVE_FSEEKO + return fseeko(self->fh, offset, mode); +#else + return fseek(self->fh, offset, mode); +#endif + } + return -1; +} + +static off_t msp_tell(struct mspack_file *file) { + struct mspack_file_p *self = (struct mspack_file_p *) file; +#ifdef HAVE_FSEEKO + return (self) ? (off_t) ftello(self->fh) : 0; +#else + return (self) ? (off_t) ftell(self->fh) : 0; +#endif +} + +static void msp_msg(struct mspack_file *file, const char *format, ...) { + va_list ap; + if (file) fprintf(stderr, "%s: ", ((struct mspack_file_p *) file)->name); + va_start(ap, format); + vfprintf(stderr, format, ap); + va_end(ap); + fputc((int) '\n', stderr); + fflush(stderr); +} + +static void *msp_alloc(struct mspack_system *self, size_t bytes) { +#ifdef DEBUG + /* make uninitialised data obvious */ + char *buf = malloc(bytes + 8); + if (buf) memset(buf, 0xDC, bytes); + *((size_t *)buf) = bytes; + return &buf[8]; +#else + return malloc(bytes); +#endif +} + +static void msp_free(void *buffer) { +#ifdef DEBUG + char *buf = buffer; + size_t bytes; + if (buf) { + buf -= 8; + bytes = *((size_t *)buf); + /* make freed data obvious */ + memset(buf, 0xED, bytes); + free(buf); + } +#else + free(buffer); +#endif +} + +static void msp_copy(void *src, void *dest, size_t bytes) { + memcpy(dest, src, bytes); +} + +static struct mspack_system msp_system = { + &msp_open, &msp_close, &msp_read, &msp_write, &msp_seek, + &msp_tell, &msp_msg, &msp_alloc, &msp_free, &msp_copy, NULL +}; + +struct mspack_system *mspack_default_system = &msp_system; + +#endif diff --git a/rbutil/rbutilqt/mspack/system-mspack.h b/rbutil/rbutilqt/mspack/system-mspack.h new file mode 100644 index 0000000000..dd3c325ffa --- /dev/null +++ b/rbutil/rbutilqt/mspack/system-mspack.h @@ -0,0 +1,124 @@ +/* This file is part of libmspack. + * (C) 2003-2004 Stuart Caie. + * + * libmspack is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License (LGPL) version 2.1 + * + * For further details, see the file COPYING.LIB distributed with libmspack + */ + +#ifndef MSPACK_SYSTEM_H +#define MSPACK_SYSTEM_H 1 + +#ifdef __cplusplus +extern "C" { +#endif + +/* ensure config.h is read before mspack.h */ +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "mspack.h" + +/* fix for problem with GCC 4 and glibc (thanks to Ville Skytta) + * http://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=150429 + */ +#ifdef read +# undef read +#endif + +#ifdef DEBUG +# include +/* Old GCCs don't have __func__, but __FUNCTION__: + * http://gcc.gnu.org/onlinedocs/gcc/Function-Names.html + */ +# if __STDC_VERSION__ < 199901L +# if __GNUC__ >= 2 +# define __func__ __FUNCTION__ +# else +# define __func__ "" +# endif +# endif +# define D(x) do { printf("%s:%d (%s) ",__FILE__, __LINE__, __func__); \ + printf x ; fputc('\n', stdout); fflush(stdout);} while (0); +#else +# define D(x) +#endif + +/* CAB supports searching through files over 4GB in size, and the CHM file + * format actively uses 64-bit offsets. These can only be fully supported + * if the system the code runs on supports large files. If not, the library + * will work as normal using only 32-bit arithmetic, but if an offset + * greater than 2GB is detected, an error message indicating the library + * can't support the file should be printed. + */ +#ifdef HAVE_LIMITS_H +# include +#endif + +#if ((defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS >= 64) || \ + (defined(FILESIZEBITS) && FILESIZEBITS >= 64) || \ + (defined(SIZEOF_OFF_T) && SIZEOF_OFF_T >= 8) || \ + defined(_LARGEFILE_SOURCE) || defined(_LARGEFILE64_SOURCE)) +# define LARGEFILE_SUPPORT +# define LD "lld" +# define LU "llu" +#else +extern const char *largefile_msg; +# define LD "ld" +# define LU "lu" +#endif + +/* endian-neutral reading of little-endian data */ +#define __egi32(a,n) ( ((((unsigned char *) a)[n+3]) << 24) | \ + ((((unsigned char *) a)[n+2]) << 16) | \ + ((((unsigned char *) a)[n+1]) << 8) | \ + ((((unsigned char *) a)[n+0]))) +#define EndGetI64(a) ((((unsigned long long int) __egi32(a,4)) << 32) | \ + ((unsigned int) __egi32(a,0))) +#define EndGetI32(a) __egi32(a,0) +#define EndGetI16(a) ((((a)[1])<<8)|((a)[0])) + +/* endian-neutral reading of big-endian data */ +#define EndGetM32(a) (((((unsigned char *) a)[0]) << 24) | \ + ((((unsigned char *) a)[1]) << 16) | \ + ((((unsigned char *) a)[2]) << 8) | \ + ((((unsigned char *) a)[3]))) +#define EndGetM16(a) ((((a)[0])<<8)|((a)[1])) + +extern struct mspack_system *mspack_default_system; + +/* returns the length of a file opened for reading */ +extern int mspack_sys_filelen(struct mspack_system *system, + struct mspack_file *file, off_t *length); + +/* validates a system structure */ +extern int mspack_valid_system(struct mspack_system *sys); + +#if HAVE_STRINGS_H +# include +#endif + +#if HAVE_STRING_H +# include +#endif + +#if HAVE_MEMCMP +# define mspack_memcmp memcmp +#else +/* inline memcmp() */ +static inline int mspack_memcmp(const void *s1, const void *s2, size_t n) { + unsigned char *c1 = (unsigned char *) s1; + unsigned char *c2 = (unsigned char *) s2; + if (n == 0) return 0; + while (--n && (*c1 == *c2)) c1++, c2++; + return *c1 - *c2; +} +#endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/rbutil/rbutilqt/mspack/system.c b/rbutil/rbutilqt/mspack/system.c deleted file mode 100644 index f3f0019f5e..0000000000 --- a/rbutil/rbutilqt/mspack/system.c +++ /dev/null @@ -1,237 +0,0 @@ -/* This file is part of libmspack. - * (C) 2003-2004 Stuart Caie. - * - * libmspack is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License (LGPL) version 2.1 - * - * For further details, see the file COPYING.LIB distributed with libmspack - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include - -#ifndef LARGEFILE_SUPPORT -const char *largefile_msg = "library not compiled to support large files."; -#endif - - -int mspack_version(int entity) { - switch (entity) { - /* CHM decoder version 1 -> 2 changes: - * - added mschmd_sec_mscompressed::spaninfo - * - added mschmd_header::first_pmgl - * - added mschmd_header::last_pmgl - * - added mschmd_header::chunk_cache; - */ - case MSPACK_VER_MSCHMD: - return 2; - case MSPACK_VER_LIBRARY: - case MSPACK_VER_SYSTEM: - case MSPACK_VER_MSCABD: - case MSPACK_VER_MSSZDDD: - case MSPACK_VER_MSKWAJD: - return 1; - case MSPACK_VER_MSCABC: - case MSPACK_VER_MSCHMC: - case MSPACK_VER_MSLITD: - case MSPACK_VER_MSLITC: - case MSPACK_VER_MSHLPD: - case MSPACK_VER_MSHLPC: - case MSPACK_VER_MSSZDDC: - case MSPACK_VER_MSKWAJC: - return 0; - } - return -1; -} - -int mspack_sys_selftest_internal(int offt_size) { - return (sizeof(off_t) == offt_size) ? MSPACK_ERR_OK : MSPACK_ERR_SEEK; -} - -/* validates a system structure */ -int mspack_valid_system(struct mspack_system *sys) { - return (sys != NULL) && (sys->open != NULL) && (sys->close != NULL) && - (sys->read != NULL) && (sys->write != NULL) && (sys->seek != NULL) && - (sys->tell != NULL) && (sys->message != NULL) && (sys->alloc != NULL) && - (sys->free != NULL) && (sys->copy != NULL) && (sys->null_ptr == NULL); -} - -/* returns the length of a file opened for reading */ -int mspack_sys_filelen(struct mspack_system *system, - struct mspack_file *file, off_t *length) -{ - off_t current; - - if (!system || !file || !length) return MSPACK_ERR_OPEN; - - /* get current offset */ - current = system->tell(file); - - /* seek to end of file */ - if (system->seek(file, (off_t) 0, MSPACK_SYS_SEEK_END)) { - return MSPACK_ERR_SEEK; - } - - /* get offset of end of file */ - *length = system->tell(file); - - /* seek back to original offset */ - if (system->seek(file, current, MSPACK_SYS_SEEK_START)) { - return MSPACK_ERR_SEEK; - } - - return MSPACK_ERR_OK; -} - - - -/* definition of mspack_default_system -- if the library is compiled with - * MSPACK_NO_DEFAULT_SYSTEM, no default system will be provided. Otherwise, - * an appropriate default system (e.g. the standard C library, or some native - * API calls) - */ - -#ifdef MSPACK_NO_DEFAULT_SYSTEM -struct mspack_system *mspack_default_system = NULL; -#else - -/* implementation of mspack_default_system for standard C library */ - -#include -#include -#include -#include - -struct mspack_file_p { - FILE *fh; - const char *name; -}; - -static struct mspack_file *msp_open(struct mspack_system *self, - const char *filename, int mode) -{ - struct mspack_file_p *fh; - const char *fmode; - - switch (mode) { - case MSPACK_SYS_OPEN_READ: fmode = "rb"; break; - case MSPACK_SYS_OPEN_WRITE: fmode = "wb"; break; - case MSPACK_SYS_OPEN_UPDATE: fmode = "r+b"; break; - case MSPACK_SYS_OPEN_APPEND: fmode = "ab"; break; - default: return NULL; - } - - if ((fh = (struct mspack_file_p *) malloc(sizeof(struct mspack_file_p)))) { - fh->name = filename; - if ((fh->fh = fopen(filename, fmode))) return (struct mspack_file *) fh; - free(fh); - } - return NULL; -} - -static void msp_close(struct mspack_file *file) { - struct mspack_file_p *self = (struct mspack_file_p *) file; - if (self) { - fclose(self->fh); - free(self); - } -} - -static int msp_read(struct mspack_file *file, void *buffer, int bytes) { - struct mspack_file_p *self = (struct mspack_file_p *) file; - if (self && buffer && bytes >= 0) { - size_t count = fread(buffer, 1, (size_t) bytes, self->fh); - if (!ferror(self->fh)) return (int) count; - } - return -1; -} - -static int msp_write(struct mspack_file *file, void *buffer, int bytes) { - struct mspack_file_p *self = (struct mspack_file_p *) file; - if (self && buffer && bytes >= 0) { - size_t count = fwrite(buffer, 1, (size_t) bytes, self->fh); - if (!ferror(self->fh)) return (int) count; - } - return -1; -} - -static int msp_seek(struct mspack_file *file, off_t offset, int mode) { - struct mspack_file_p *self = (struct mspack_file_p *) file; - if (self) { - switch (mode) { - case MSPACK_SYS_SEEK_START: mode = SEEK_SET; break; - case MSPACK_SYS_SEEK_CUR: mode = SEEK_CUR; break; - case MSPACK_SYS_SEEK_END: mode = SEEK_END; break; - default: return -1; - } -#ifdef HAVE_FSEEKO - return fseeko(self->fh, offset, mode); -#else - return fseek(self->fh, offset, mode); -#endif - } - return -1; -} - -static off_t msp_tell(struct mspack_file *file) { - struct mspack_file_p *self = (struct mspack_file_p *) file; -#ifdef HAVE_FSEEKO - return (self) ? (off_t) ftello(self->fh) : 0; -#else - return (self) ? (off_t) ftell(self->fh) : 0; -#endif -} - -static void msp_msg(struct mspack_file *file, const char *format, ...) { - va_list ap; - if (file) fprintf(stderr, "%s: ", ((struct mspack_file_p *) file)->name); - va_start(ap, format); - vfprintf(stderr, format, ap); - va_end(ap); - fputc((int) '\n', stderr); - fflush(stderr); -} - -static void *msp_alloc(struct mspack_system *self, size_t bytes) { -#ifdef DEBUG - /* make uninitialised data obvious */ - char *buf = malloc(bytes + 8); - if (buf) memset(buf, 0xDC, bytes); - *((size_t *)buf) = bytes; - return &buf[8]; -#else - return malloc(bytes); -#endif -} - -static void msp_free(void *buffer) { -#ifdef DEBUG - char *buf = buffer; - size_t bytes; - if (buf) { - buf -= 8; - bytes = *((size_t *)buf); - /* make freed data obvious */ - memset(buf, 0xED, bytes); - free(buf); - } -#else - free(buffer); -#endif -} - -static void msp_copy(void *src, void *dest, size_t bytes) { - memcpy(dest, src, bytes); -} - -static struct mspack_system msp_system = { - &msp_open, &msp_close, &msp_read, &msp_write, &msp_seek, - &msp_tell, &msp_msg, &msp_alloc, &msp_free, &msp_copy, NULL -}; - -struct mspack_system *mspack_default_system = &msp_system; - -#endif diff --git a/rbutil/rbutilqt/mspack/system.h b/rbutil/rbutilqt/mspack/system.h deleted file mode 100644 index 4a400850aa..0000000000 --- a/rbutil/rbutilqt/mspack/system.h +++ /dev/null @@ -1,124 +0,0 @@ -/* This file is part of libmspack. - * (C) 2003-2004 Stuart Caie. - * - * libmspack is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License (LGPL) version 2.1 - * - * For further details, see the file COPYING.LIB distributed with libmspack - */ - -#ifndef MSPACK_SYSTEM_H -#define MSPACK_SYSTEM_H 1 - -#ifdef __cplusplus -extern "C" { -#endif - -/* ensure config.h is read before mspack.h */ -#ifdef HAVE_CONFIG_H -# include -#endif - -#include - -/* fix for problem with GCC 4 and glibc (thanks to Ville Skytta) - * http://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=150429 - */ -#ifdef read -# undef read -#endif - -#ifdef DEBUG -# include -/* Old GCCs don't have __func__, but __FUNCTION__: - * http://gcc.gnu.org/onlinedocs/gcc/Function-Names.html - */ -# if __STDC_VERSION__ < 199901L -# if __GNUC__ >= 2 -# define __func__ __FUNCTION__ -# else -# define __func__ "" -# endif -# endif -# define D(x) do { printf("%s:%d (%s) ",__FILE__, __LINE__, __func__); \ - printf x ; fputc('\n', stdout); fflush(stdout);} while (0); -#else -# define D(x) -#endif - -/* CAB supports searching through files over 4GB in size, and the CHM file - * format actively uses 64-bit offsets. These can only be fully supported - * if the system the code runs on supports large files. If not, the library - * will work as normal using only 32-bit arithmetic, but if an offset - * greater than 2GB is detected, an error message indicating the library - * can't support the file should be printed. - */ -#ifdef HAVE_LIMITS_H -# include -#endif - -#if ((defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS >= 64) || \ - (defined(FILESIZEBITS) && FILESIZEBITS >= 64) || \ - (defined(SIZEOF_OFF_T) && SIZEOF_OFF_T >= 8) || \ - defined(_LARGEFILE_SOURCE) || defined(_LARGEFILE64_SOURCE)) -# define LARGEFILE_SUPPORT -# define LD "lld" -# define LU "llu" -#else -extern const char *largefile_msg; -# define LD "ld" -# define LU "lu" -#endif - -/* endian-neutral reading of little-endian data */ -#define __egi32(a,n) ( ((((unsigned char *) a)[n+3]) << 24) | \ - ((((unsigned char *) a)[n+2]) << 16) | \ - ((((unsigned char *) a)[n+1]) << 8) | \ - ((((unsigned char *) a)[n+0]))) -#define EndGetI64(a) ((((unsigned long long int) __egi32(a,4)) << 32) | \ - ((unsigned int) __egi32(a,0))) -#define EndGetI32(a) __egi32(a,0) -#define EndGetI16(a) ((((a)[1])<<8)|((a)[0])) - -/* endian-neutral reading of big-endian data */ -#define EndGetM32(a) (((((unsigned char *) a)[0]) << 24) | \ - ((((unsigned char *) a)[1]) << 16) | \ - ((((unsigned char *) a)[2]) << 8) | \ - ((((unsigned char *) a)[3]))) -#define EndGetM16(a) ((((a)[0])<<8)|((a)[1])) - -extern struct mspack_system *mspack_default_system; - -/* returns the length of a file opened for reading */ -extern int mspack_sys_filelen(struct mspack_system *system, - struct mspack_file *file, off_t *length); - -/* validates a system structure */ -extern int mspack_valid_system(struct mspack_system *sys); - -#if HAVE_STRINGS_H -# include -#endif - -#if HAVE_STRING_H -# include -#endif - -#if HAVE_MEMCMP -# define mspack_memcmp memcmp -#else -/* inline memcmp() */ -static inline int mspack_memcmp(const void *s1, const void *s2, size_t n) { - unsigned char *c1 = (unsigned char *) s1; - unsigned char *c2 = (unsigned char *) s2; - if (n == 0) return 0; - while (--n && (*c1 == *c2)) c1++, c2++; - return *c1 - *c2; -} -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/rbutil/rbutilqt/mspack/szdd.h b/rbutil/rbutilqt/mspack/szdd.h index e07c6b7c8e..b9936b42d1 100644 --- a/rbutil/rbutilqt/mspack/szdd.h +++ b/rbutil/rbutilqt/mspack/szdd.h @@ -10,7 +10,7 @@ #ifndef MSPACK_SZDD_H #define MSPACK_SZDD_H 1 -#include +#include "lzss.h" /* input buffer size during decompression - not worth parameterising IMHO */ #define SZDD_INPUT_SIZE (2048) diff --git a/rbutil/rbutilqt/mspack/szddc.c b/rbutil/rbutilqt/mspack/szddc.c index cdd39a6305..6ad6501217 100644 --- a/rbutil/rbutilqt/mspack/szddc.c +++ b/rbutil/rbutilqt/mspack/szddc.c @@ -9,8 +9,8 @@ /* SZDD compression implementation */ -#include -#include +#include "system-mspack.h" +#include "szdd.h" struct msszdd_compressor * mspack_create_szdd_compressor(struct mspack_system *sys) diff --git a/rbutil/rbutilqt/mspack/szddd.c b/rbutil/rbutilqt/mspack/szddd.c index 99c5aa4658..af77f15565 100644 --- a/rbutil/rbutilqt/mspack/szddd.c +++ b/rbutil/rbutilqt/mspack/szddd.c @@ -13,8 +13,8 @@ /* SZDD decompression implementation */ -#include -#include +#include "system-mspack.h" +#include "szdd.h" /* prototypes */ static struct msszddd_header *szddd_open( -- cgit v1.2.3