From 978f8ee190f04646445f757f961963d5f2d036d4 Mon Sep 17 00:00:00 2001 From: Gabi Davar Date: Sat, 21 Jun 2014 15:26:00 +0300 Subject: [PATCH] add cmake build system * fix a few 64bit warnings * remove some really old stuff --- .gitignore | 2 + CMakeLists.txt | 165 ++++++++++++++++++++++++++++++++++++++++----- bzlib.c | 61 +++++++++-------- bzlib.h | 83 +++++++++-------------- bzlib_private.h | 30 --------- compress.c | 7 +- dlltest.dsp | 93 ------------------------- libbz2.def | 1 - libbz2.dsp | 130 ----------------------------------- makefile.msc | 63 ----------------- runtest.cmake | 19 ++++++ spewG.c | 16 ++++- version.rc.cmakein | 47 +++++++++++++ 13 files changed, 296 insertions(+), 421 deletions(-) delete mode 100644 dlltest.dsp delete mode 100644 libbz2.dsp delete mode 100644 makefile.msc create mode 100644 runtest.cmake create mode 100644 version.rc.cmakein diff --git a/.gitignore b/.gitignore index 6c7f32d..b1748f1 100644 --- a/.gitignore +++ b/.gitignore @@ -237,3 +237,5 @@ $RECYCLE.BIN/ *.x86_64 *.hex + +_b*/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 29b064b..3e1671b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,29 @@ cmake_minimum_required(VERSION 3.0) -project(bzip2) +project(bzip2 + VERSION 1.0.6 + LANGUAGES C +) + +set(local_lib_name bz2) + +option(BUILD_TESTING "Build the tests." ON) + +if (MSVC) + if (NOT DEFINED ARCH) + set (ARCH ${MSVC_C_ARCHITECTURE_ID}) + endif() + + # use boost convention - you cant' get the VC compiler without VS + if (NOT DEFINED MSVCVER) + math(EXPR MSVCVER "(${MSVC_VERSION} / 10) - 60") + endif() + + # add the runtiume version and target architecture into the DLL name per MS + # guidelines + set(MSVC_SHARED_SUFFIX_BASE "-${PROJECT_VERSION_MAJOR}-vc${MSVCVER}-mt-${ARCH}") + set(CMAKE_SHARED_LIBRARY_SUFFIX "${MSVC_SHARED_SUFFIX_BASE}.dll") +endif() set(bzip2_lib_SRCS blocksort.c @@ -12,6 +35,10 @@ set(bzip2_lib_SRCS bzlib.c ) +set(bzip2_lib_HDRS + bzlib.h + bzlib_private.h +) set(bzip2_scripts bzdiff bzgrep @@ -26,46 +53,148 @@ set(bzip2_html ) set(CMAKE_DEBUG_POSTFIX "d") + if(MSVC) - add_definitions(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE) - set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /GL") - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /GL") - set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /LTCG") - set(CMAKE_MODULE_LINKER_FLAGS_RELEASE "${CMAKE_MODULE_LINKER_FLAGS_RELEASE} /LTCG") - set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /LTCG") + add_definitions(-D_FILE_OFFSET_BITS=64) + add_definitions(-D_CRT_SECURE_NO_DEPRECATE) + add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE) + # set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /GL") + # set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /GL") + # set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /LTCG") + # set(CMAKE_MODULE_LINKER_FLAGS_RELEASE "${CMAKE_MODULE_LINKER_FLAGS_RELEASE} /LTCG") + # set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /LTCG") + + set(VER_PRODUCTNAME_STR "bzip2 - a freely available, patent free, high-quality data compressor.") + set(VER_LEGALCOPYRIGHT_STR "copyright (C) 1996-2010 Julian R Seward") + set(VER_STR "${PROJECT_VERSION}") + set(VER_NUM "${PROJECT_VERSION_MAJOR},${PROJECT_VERSION_MINOR},${PROJECT_VERSION_PATCH},0") + + + set(VER_ORIGINALFILENAME_STR "${local_lib_name}${CMAKE_SHARED_LIBRARY_SUFFIX}") + set(VER_INTERNALNAME_STR ${local_lib_name}) + set(VER_FILEDESCRIPTION_STR "${local_lib_name} Dynamic Link Library") + configure_file( + ${CMAKE_SOURCE_DIR}/version.rc.cmakein + ${CMAKE_CURRENT_BINARY_DIR}/version.rc + @ONLY + ) + set(bzip2_DLLSRCS + ${CMAKE_SOURCE_DIR}/libbz2.def + ${CMAKE_CURRENT_BINARY_DIR}/version.rc + ) endif(MSVC) -add_library(bz2 SHARED ${bzip2_lib_SRCS}) -if(WIN32) - set_target_properties(bz2 PROPERTIES PREFIX "") -endif(WIN32) +add_library(${local_lib_name} SHARED ${bzip2_lib_SRCS} ${bzip2_lib_HDRS} ${bzip2_DLLSRCS}) +set_target_properties(${local_lib_name} PROPERTIES + SOVERSION ${PROJECT_VERSION} + VERSION ${PROJECT_VERSION_MAJOR} + PUBLIC_HEADER bzlib.h +) + +if(MSVC) + set_target_properties(${local_lib_name} PROPERTIES PDB_NAME "${local_lib_name}${MSVC_SHARED_SUFFIX_BASE}") +endif() # bzip2recover add_executable(bzip2recover bzip2recover.c) target_link_libraries(bzip2recover bz2) # bzip2 -# disabled bin for wince because of problems with the file system - add_executable(bzip2_bin bzip2.c) target_link_libraries(bzip2_bin bz2) set_target_properties(bzip2_bin PROPERTIES OUTPUT_NAME bzip2) +install(TARGETS bz2 bzip2recover bzip2_bin + RUNTIME DESTINATION bin + ARCHIVE DESTINATION lib + LIBRARY DESTINATION lib + PUBLIC_HEADER DESTINATION include + ) + file(GLOB man1 ${bzip2_SOURCE_DIR}/*.1) -install_targets(/lib bz2) -install_targets(/bin bzip2recover) - -install_targets(/bin bzip2_bin) if(NOT WIN32) install(PROGRAMS ${bzip2_scripts} DESTINATION bin) endif(NOT WIN32) + install(FILES ${man1} DESTINATION share/man/man1) install(FILES ${bzip2_docs} DESTINATION doc) install(FILES ${bzip2_html} DESTINATION doc/html) -install(FILES bzlib.h DESTINATION include) + +if (BUILD_TESTING) + enable_testing() + + add_executable(spew spewG) + +add_test(NAME compress_block_size_1 + COMMAND ${CMAKE_COMMAND} + -DTEST_PROG=$ + -DARGUMENTS=-1 + -DINPUT=${CMAKE_SOURCE_DIR}/sample1.ref + -DEXPECTED=${CMAKE_SOURCE_DIR}/sample1.bz2 + -DOUTPUT=${CMAKE_CURRENT_BINARY_DIR}/sample1.rb2 + -DSOURCEDIR=${CMAKE_CURRENT_SOURCE_DIR} + -P ${CMAKE_CURRENT_SOURCE_DIR}/runtest.cmake + ) + +add_test(NAME compress_block_size_2 + COMMAND ${CMAKE_COMMAND} + -DTEST_PROG=$ + -DARGUMENTS=-2 + -DINPUT=${CMAKE_SOURCE_DIR}/sample2.ref + -DEXPECTED=${CMAKE_SOURCE_DIR}/sample2.bz2 + -DOUTPUT=${CMAKE_CURRENT_BINARY_DIR}/sample2.rb2 + -DSOURCEDIR=${CMAKE_CURRENT_SOURCE_DIR} + -P ${CMAKE_CURRENT_SOURCE_DIR}/runtest.cmake + ) + +add_test(NAME compress_block_size_3 + COMMAND ${CMAKE_COMMAND} + -DTEST_PROG=$ + -DARGUMENTS=-3 + -DINPUT=${CMAKE_SOURCE_DIR}/sample3.ref + -DEXPECTED=${CMAKE_SOURCE_DIR}/sample3.bz2 + -DOUTPUT=${CMAKE_CURRENT_BINARY_DIR}/sample3.rb2 + -DSOURCEDIR=${CMAKE_CURRENT_SOURCE_DIR} + -P ${CMAKE_CURRENT_SOURCE_DIR}/runtest.cmake + ) + +add_test(NAME decompress_block_size_1 + COMMAND ${CMAKE_COMMAND} + -DTEST_PROG=$ + -DARGUMENTS=-d + -DINPUT=${CMAKE_SOURCE_DIR}/sample1.bz2 + -DEXPECTED=${CMAKE_SOURCE_DIR}/sample1.ref + -DOUTPUT=${CMAKE_CURRENT_BINARY_DIR}/sample1.tst + -DSOURCEDIR=${CMAKE_CURRENT_SOURCE_DIR} + -P ${CMAKE_CURRENT_SOURCE_DIR}/runtest.cmake + ) + +add_test(NAME decompress_block_size_2 + COMMAND ${CMAKE_COMMAND} + -DTEST_PROG=$ + -DARGUMENTS=-d + -DINPUT=${CMAKE_SOURCE_DIR}/sample2.bz2 + -DEXPECTED=${CMAKE_SOURCE_DIR}/sample2.ref + -DOUTPUT=${CMAKE_CURRENT_BINARY_DIR}/sample2.tst + -DSOURCEDIR=${CMAKE_CURRENT_SOURCE_DIR} + -P ${CMAKE_CURRENT_SOURCE_DIR}/runtest.cmake + ) + +add_test(NAME decompress_block_size_3 + COMMAND ${CMAKE_COMMAND} + -DTEST_PROG=$ + -DARGUMENTS=-ds + -DINPUT=${CMAKE_SOURCE_DIR}/sample3.bz2 + -DEXPECTED=${CMAKE_SOURCE_DIR}/sample3.ref + -DOUTPUT=${CMAKE_CURRENT_BINARY_DIR}/sample3.tst + -DSOURCEDIR=${CMAKE_CURRENT_SOURCE_DIR} + -P ${CMAKE_CURRENT_SOURCE_DIR}/runtest.cmake + ) + +endif() # echo EXPORTS > bzip2.def # nm bzip2.dll | grep ' T _' | sed 's/.* T _//' >> bzip2.def diff --git a/bzlib.c b/bzlib.c index bd358a7..b58de17 100644 --- a/bzlib.c +++ b/bzlib.c @@ -145,7 +145,7 @@ Bool isempty_RL ( EState* s ) /*---------------------------------------------------*/ -int BZ_API(BZ2_bzCompressInit) +int BZ2_bzCompressInit ( bz_stream* strm, int blockSize100k, int verbosity, @@ -404,7 +404,7 @@ Bool handle_compress ( bz_stream* strm ) /*---------------------------------------------------*/ -int BZ_API(BZ2_bzCompress) ( bz_stream *strm, int action ) +int BZ2_bzCompress ( bz_stream *strm, int action ) { Bool progress; EState* s; @@ -465,7 +465,7 @@ int BZ_API(BZ2_bzCompress) ( bz_stream *strm, int action ) /*---------------------------------------------------*/ -int BZ_API(BZ2_bzCompressEnd) ( bz_stream *strm ) +int BZ2_bzCompressEnd ( bz_stream *strm ) { EState* s; if (strm == NULL) return BZ_PARAM_ERROR; @@ -489,7 +489,7 @@ int BZ_API(BZ2_bzCompressEnd) ( bz_stream *strm ) /*---------------------------------------------------*/ /*---------------------------------------------------*/ -int BZ_API(BZ2_bzDecompressInit) +int BZ2_bzDecompressInit ( bz_stream* strm, int verbosity, int small ) @@ -805,7 +805,7 @@ Bool unRLE_obuf_to_output_SMALL ( DState* s ) /*---------------------------------------------------*/ -int BZ_API(BZ2_bzDecompress) ( bz_stream *strm ) +int BZ2_bzDecompress ( bz_stream *strm ) { Bool corrupt; DState* s; @@ -859,7 +859,7 @@ int BZ_API(BZ2_bzDecompress) ( bz_stream *strm ) /*---------------------------------------------------*/ -int BZ_API(BZ2_bzDecompressEnd) ( bz_stream *strm ) +int BZ2_bzDecompressEnd ( bz_stream *strm ) { DState* s; if (strm == NULL) return BZ_PARAM_ERROR; @@ -913,7 +913,7 @@ static Bool myfeof ( FILE* f ) /*---------------------------------------------------*/ -BZFILE* BZ_API(BZ2_bzWriteOpen) +BZFILE* BZ2_bzWriteOpen ( int* bzerror, FILE* f, int blockSize100k, @@ -961,13 +961,15 @@ BZFILE* BZ_API(BZ2_bzWriteOpen) /*---------------------------------------------------*/ -void BZ_API(BZ2_bzWrite) +void BZ2_bzWrite ( int* bzerror, BZFILE* b, void* buf, int len ) { - Int32 n, n2, ret; + Int32 ret; + size_t n = 0; + size_t n2 = 0; bzFile* bzf = (bzFile*)b; BZ_SETERR(BZ_OK); @@ -1006,7 +1008,7 @@ void BZ_API(BZ2_bzWrite) /*---------------------------------------------------*/ -void BZ_API(BZ2_bzWriteClose) +void BZ2_bzWriteClose ( int* bzerror, BZFILE* b, int abandon, @@ -1018,7 +1020,7 @@ void BZ_API(BZ2_bzWriteClose) } -void BZ_API(BZ2_bzWriteClose64) +void BZ2_bzWriteClose64 ( int* bzerror, BZFILE* b, int abandon, @@ -1027,7 +1029,9 @@ void BZ_API(BZ2_bzWriteClose64) unsigned int* nbytes_out_lo32, unsigned int* nbytes_out_hi32 ) { - Int32 n, n2, ret; + Int32 ret; + size_t n = 0; + size_t n2 = 0; bzFile* bzf = (bzFile*)b; if (bzf == NULL) @@ -1084,7 +1088,7 @@ void BZ_API(BZ2_bzWriteClose64) /*---------------------------------------------------*/ -BZFILE* BZ_API(BZ2_bzReadOpen) +BZFILE* BZ2_bzReadOpen ( int* bzerror, FILE* f, int verbosity, @@ -1140,7 +1144,7 @@ BZFILE* BZ_API(BZ2_bzReadOpen) /*---------------------------------------------------*/ -void BZ_API(BZ2_bzReadClose) ( int *bzerror, BZFILE *b ) +void BZ2_bzReadClose ( int *bzerror, BZFILE *b ) { bzFile* bzf = (bzFile*)b; @@ -1158,13 +1162,14 @@ void BZ_API(BZ2_bzReadClose) ( int *bzerror, BZFILE *b ) /*---------------------------------------------------*/ -int BZ_API(BZ2_bzRead) +int BZ2_bzRead ( int* bzerror, BZFILE* b, void* buf, int len ) { - Int32 n, ret; + Int32 ret; + size_t n; bzFile* bzf = (bzFile*)b; BZ_SETERR(BZ_OK); @@ -1191,7 +1196,7 @@ int BZ_API(BZ2_bzRead) BZ_MAX_UNUSED, bzf->handle ); if (ferror(bzf->handle)) { BZ_SETERR(BZ_IO_ERROR); return 0; }; - bzf->bufN = n; + bzf->bufN = (Int32)n; bzf->strm.avail_in = bzf->bufN; bzf->strm.next_in = bzf->buf; } @@ -1218,7 +1223,7 @@ int BZ_API(BZ2_bzRead) /*---------------------------------------------------*/ -void BZ_API(BZ2_bzReadGetUnused) +void BZ2_bzReadGetUnused ( int* bzerror, BZFILE* b, void** unused, @@ -1244,7 +1249,7 @@ void BZ_API(BZ2_bzReadGetUnused) /*---------------------------------------------------*/ /*---------------------------------------------------*/ -int BZ_API(BZ2_bzBuffToBuffCompress) +int BZ2_bzBuffToBuffCompress ( char* dest, unsigned int* destLen, char* source, @@ -1296,7 +1301,7 @@ int BZ_API(BZ2_bzBuffToBuffCompress) /*---------------------------------------------------*/ -int BZ_API(BZ2_bzBuffToBuffDecompress) +int BZ2_bzBuffToBuffDecompress ( char* dest, unsigned int* destLen, char* source, @@ -1363,7 +1368,7 @@ int BZ_API(BZ2_bzBuffToBuffDecompress) /*-- return version like "0.9.5d, 4-Sept-1999". --*/ -const char * BZ_API(BZ2_bzlibVersion)(void) +const char * BZ2_bzlibVersion(void) { return BZ_VERSION; } @@ -1457,7 +1462,7 @@ BZFILE * bzopen_or_bzdopen ex) bzopen("file","w9") case path="" or NULL => use stdin or stdout. --*/ -BZFILE * BZ_API(BZ2_bzopen) +BZFILE * BZ2_bzopen ( const char *path, const char *mode ) { @@ -1466,7 +1471,7 @@ BZFILE * BZ_API(BZ2_bzopen) /*---------------------------------------------------*/ -BZFILE * BZ_API(BZ2_bzdopen) +BZFILE * BZ2_bzdopen ( int fd, const char *mode ) { @@ -1475,7 +1480,7 @@ BZFILE * BZ_API(BZ2_bzdopen) /*---------------------------------------------------*/ -int BZ_API(BZ2_bzread) (BZFILE* b, void* buf, int len ) +int BZ2_bzread (BZFILE* b, void* buf, int len ) { int bzerr, nread; if (((bzFile*)b)->lastErr == BZ_STREAM_END) return 0; @@ -1489,7 +1494,7 @@ int BZ_API(BZ2_bzread) (BZFILE* b, void* buf, int len ) /*---------------------------------------------------*/ -int BZ_API(BZ2_bzwrite) (BZFILE* b, void* buf, int len ) +int BZ2_bzwrite (BZFILE* b, void* buf, int len ) { int bzerr; @@ -1503,7 +1508,7 @@ int BZ_API(BZ2_bzwrite) (BZFILE* b, void* buf, int len ) /*---------------------------------------------------*/ -int BZ_API(BZ2_bzflush) (BZFILE *b) +int BZ2_bzflush (BZFILE *b) { /* do nothing now... */ return 0; @@ -1511,7 +1516,7 @@ int BZ_API(BZ2_bzflush) (BZFILE *b) /*---------------------------------------------------*/ -void BZ_API(BZ2_bzclose) (BZFILE* b) +void BZ2_bzclose (BZFILE* b) { int bzerr; FILE *fp; @@ -1556,7 +1561,7 @@ static const char *bzerrorstrings[] = { }; -const char * BZ_API(BZ2_bzerror) (BZFILE *b, int *errnum) +const char * BZ2_bzerror (BZFILE *b, int *errnum) { int err = ((bzFile *)b)->lastErr; diff --git a/bzlib.h b/bzlib.h index 698e28b..8904990 100644 --- a/bzlib.h +++ b/bzlib.h @@ -70,46 +70,29 @@ typedef #define BZ_EXPORT #endif -#ifndef BZ_NO_STDIO -/* Need a definitition for FILE */ +/* Need a definitions for FILE */ #include -#endif #ifdef _WIN32 +#define WIN32_LEAN_AND_MEAN # include -# ifdef small - /* windows.h define small to char */ -# undef small -# endif -//# ifdef BZ_EXPORT -//# define BZ_API(func) WINAPI func -//# define BZ_EXTERN extern -//# else -// /* import windows dll dynamically */ -//# define BZ_API(func) (WINAPI * func) -//# define BZ_EXTERN -//# endif -//#else -//# define BZ_API(func) func -//# define BZ_EXTERN extern -# include # include # include # define fdopen _fdopen # define isatty _isatty # define setmode _setmode # define utime _utime -# endif - +#endif #ifndef __GNUC__ # define __DLL_IMPORT__ __declspec(dllimport) # define __DLL_EXPORT__ __declspec(dllexport) # else # define __DLL_IMPORT__ __attribute__((dllimport)) extern # define __DLL_EXPORT__ __attribute__((dllexport)) extern -# endif +#endif -#if (defined __WIN32__) || (defined _WIN32) +//#if (defined __WIN32__) || (defined _WIN32) +#if 0 # if defined BUILD_BZIP2_DLL || defined BZ_EXPORT # define BZIP2_DLL_IMPEXP __DLL_EXPORT__ # elif defined(BZIP2_STATIC) @@ -125,39 +108,38 @@ typedef # define BZIP2_DLL_IMPEXP #endif -#define BZ_API(func) func #define BZ_EXTERN BZIP2_DLL_IMPEXP /*-- Core (low-level) library functions --*/ -BZ_EXTERN int BZ_API(BZ2_bzCompressInit) ( +BZ_EXTERN int BZ2_bzCompressInit ( bz_stream* strm, int blockSize100k, int verbosity, int workFactor ); -BZ_EXTERN int BZ_API(BZ2_bzCompress) ( +BZ_EXTERN int BZ2_bzCompress ( bz_stream* strm, int action ); -BZ_EXTERN int BZ_API(BZ2_bzCompressEnd) ( +BZ_EXTERN int BZ2_bzCompressEnd ( bz_stream* strm ); -BZ_EXTERN int BZ_API(BZ2_bzDecompressInit) ( +BZ_EXTERN int BZ2_bzDecompressInit ( bz_stream *strm, int verbosity, int small ); -BZ_EXTERN int BZ_API(BZ2_bzDecompress) ( +BZ_EXTERN int BZ2_bzDecompress ( bz_stream* strm ); -BZ_EXTERN int BZ_API(BZ2_bzDecompressEnd) ( +BZ_EXTERN int BZ2_bzDecompressEnd ( bz_stream *strm ); @@ -165,12 +147,11 @@ BZ_EXTERN int BZ_API(BZ2_bzDecompressEnd) ( /*-- High(er) level library functions --*/ -#ifndef BZ_NO_STDIO #define BZ_MAX_UNUSED 5000 typedef void BZFILE; -BZ_EXTERN BZFILE* BZ_API(BZ2_bzReadOpen) ( +BZ_EXTERN BZFILE* BZ2_bzReadOpen ( int* bzerror, FILE* f, int verbosity, @@ -179,26 +160,26 @@ BZ_EXTERN BZFILE* BZ_API(BZ2_bzReadOpen) ( int nUnused ); -BZ_EXTERN void BZ_API(BZ2_bzReadClose) ( +BZ_EXTERN void BZ2_bzReadClose ( int* bzerror, BZFILE* b ); -BZ_EXTERN void BZ_API(BZ2_bzReadGetUnused) ( +BZ_EXTERN void BZ2_bzReadGetUnused ( int* bzerror, BZFILE* b, void** unused, int* nUnused ); -BZ_EXTERN int BZ_API(BZ2_bzRead) ( +BZ_EXTERN int BZ2_bzRead ( int* bzerror, BZFILE* b, void* buf, int len ); -BZ_EXTERN BZFILE* BZ_API(BZ2_bzWriteOpen) ( +BZ_EXTERN BZFILE* BZ2_bzWriteOpen ( int* bzerror, FILE* f, int blockSize100k, @@ -206,14 +187,14 @@ BZ_EXTERN BZFILE* BZ_API(BZ2_bzWriteOpen) ( int workFactor ); -BZ_EXTERN void BZ_API(BZ2_bzWrite) ( +BZ_EXTERN void BZ2_bzWrite ( int* bzerror, BZFILE* b, void* buf, int len ); -BZ_EXTERN void BZ_API(BZ2_bzWriteClose) ( +BZ_EXTERN void BZ2_bzWriteClose ( int* bzerror, BZFILE* b, int abandon, @@ -221,7 +202,7 @@ BZ_EXTERN void BZ_API(BZ2_bzWriteClose) ( unsigned int* nbytes_out ); -BZ_EXTERN void BZ_API(BZ2_bzWriteClose64) ( +BZ_EXTERN void BZ2_bzWriteClose64 ( int* bzerror, BZFILE* b, int abandon, @@ -230,12 +211,10 @@ BZ_EXTERN void BZ_API(BZ2_bzWriteClose64) ( unsigned int* nbytes_out_lo32, unsigned int* nbytes_out_hi32 ); -#endif - /*-- Utility functions --*/ -BZ_EXTERN int BZ_API(BZ2_bzBuffToBuffCompress) ( +BZ_EXTERN int BZ2_bzBuffToBuffCompress ( char* dest, unsigned int* destLen, char* source, @@ -245,7 +224,7 @@ BZ_EXTERN int BZ_API(BZ2_bzBuffToBuffCompress) ( int workFactor ); -BZ_EXTERN int BZ_API(BZ2_bzBuffToBuffDecompress) ( +BZ_EXTERN int BZ2_bzBuffToBuffDecompress ( char* dest, unsigned int* destLen, char* source, @@ -264,46 +243,44 @@ BZ_EXTERN int BZ_API(BZ2_bzBuffToBuffDecompress) ( If this code breaks, please contact both Yoshioka and me. --*/ -BZ_EXTERN const char * BZ_API(BZ2_bzlibVersion) ( +BZ_EXTERN const char * BZ2_bzlibVersion ( void ); -#ifndef BZ_NO_STDIO -BZ_EXTERN BZFILE * BZ_API(BZ2_bzopen) ( +BZ_EXTERN BZFILE * BZ2_bzopen ( const char *path, const char *mode ); -BZ_EXTERN BZFILE * BZ_API(BZ2_bzdopen) ( +BZ_EXTERN BZFILE * BZ2_bzdopen ( int fd, const char *mode ); -BZ_EXTERN int BZ_API(BZ2_bzread) ( +BZ_EXTERN int BZ2_bzread ( BZFILE* b, void* buf, int len ); -BZ_EXTERN int BZ_API(BZ2_bzwrite) ( +BZ_EXTERN int BZ2_bzwrite ( BZFILE* b, void* buf, int len ); -BZ_EXTERN int BZ_API(BZ2_bzflush) ( +BZ_EXTERN int BZ2_bzflush ( BZFILE* b ); -BZ_EXTERN void BZ_API(BZ2_bzclose) ( +BZ_EXTERN void BZ2_bzclose ( BZFILE* b ); -BZ_EXTERN const char * BZ_API(BZ2_bzerror) ( +BZ_EXTERN const char * BZ2_bzerror ( BZFILE *b, int *errnum ); -#endif #ifdef __cplusplus } diff --git a/bzlib_private.h b/bzlib_private.h index 5d0217f..4b9ff1d 100644 --- a/bzlib_private.h +++ b/bzlib_private.h @@ -24,11 +24,9 @@ #include -#ifndef BZ_NO_STDIO #include #include #include -#endif #include "bzlib.h" @@ -53,8 +51,6 @@ typedef unsigned short UInt16; #define __inline__ /* */ #endif -#ifndef BZ_NO_STDIO - extern void BZ2_bz__AssertH__fail ( int errcode ); #define AssertH(cond,errcode) \ { if (!(cond)) BZ2_bz__AssertH__fail ( errcode ); } @@ -83,22 +79,6 @@ extern void BZ2_bz__AssertH__fail ( int errcode ); #define VPrintf5(zf,za1,za2,za3,za4,za5) \ fprintf(stderr,zf,za1,za2,za3,za4,za5) -#else - -extern void bz_internal_error ( int errcode ); -#define AssertH(cond,errcode) \ - { if (!(cond)) bz_internal_error ( errcode ); } -#define AssertD(cond,msg) do { } while (0) -#define VPrintf0(zf) do { } while (0) -#define VPrintf1(zf,za1) do { } while (0) -#define VPrintf2(zf,za1,za2) do { } while (0) -#define VPrintf3(zf,za1,za2,za3) do { } while (0) -#define VPrintf4(zf,za1,za2,za3,za4) do { } while (0) -#define VPrintf5(zf,za1,za2,za3,za4,za5) do { } while (0) - -#endif - - #define BZALLOC(nnn) (strm->bzalloc)(strm->opaque,(nnn),1) #define BZFREE(ppp) (strm->bzfree)(strm->opaque,(ppp)) @@ -494,16 +474,6 @@ BZ2_hbCreateDecodeTables ( Int32*, Int32*, Int32*, UChar*, #endif - -/*-- BZ_NO_STDIO seems to make NULL disappear on some platforms. --*/ - -#ifdef BZ_NO_STDIO -#ifndef NULL -#define NULL 0 -#endif -#endif - - /*-------------------------------------------------------------*/ /*--- end bzlib_private.h ---*/ /*-------------------------------------------------------------*/ diff --git a/compress.c b/compress.c index caf7696..f9d26a9 100644 --- a/compress.c +++ b/compress.c @@ -158,7 +158,8 @@ void generateMTFValues ( EState* s ) wr = 0; zPend = 0; - for (i = 0; i < s->nInUse; i++) yy[i] = (UChar) i; + for (i = 0; i < s->nInUse; i++) + yy[i] = (UChar) i; for (i = 0; i < s->nblock; i++) { UChar ll_i; @@ -203,7 +204,9 @@ void generateMTFValues ( EState* s ) }; yy[0] = rtmp; j = ryy_j - &(yy[0]); - mtfv[wr] = j+1; wr++; s->mtfFreq[j+1]++; + mtfv[wr] = j+1; + wr++; + s->mtfFreq[j+1]++; } } diff --git a/dlltest.dsp b/dlltest.dsp deleted file mode 100644 index 4b1615e..0000000 --- a/dlltest.dsp +++ /dev/null @@ -1,93 +0,0 @@ -# Microsoft Developer Studio Project File - Name="dlltest" - Package Owner=<4> -# Microsoft Developer Studio Generated Build File, Format Version 5.00 -# ** 編集しないでください ** - -# TARGTYPE "Win32 (x86) Console Application" 0x0103 - -CFG=dlltest - Win32 Debug -!MESSAGE これは有効なメイクファイルではありません。 このプロジェクトをビルドするためには NMAKE を使用してください。 -!MESSAGE [メイクファイルのエクスポート] コマンドを使用して実行してください -!MESSAGE -!MESSAGE NMAKE /f "dlltest.mak". -!MESSAGE -!MESSAGE NMAKE の実行時に構成を指定できます -!MESSAGE コマンド ライン上でマクロの設定を定義します。例: -!MESSAGE -!MESSAGE NMAKE /f "dlltest.mak" CFG="dlltest - Win32 Debug" -!MESSAGE -!MESSAGE 選択可能なビルド モード: -!MESSAGE -!MESSAGE "dlltest - Win32 Release" ("Win32 (x86) Console Application" 用) -!MESSAGE "dlltest - Win32 Debug" ("Win32 (x86) Console Application" 用) -!MESSAGE - -# Begin Project -# PROP Scc_ProjName "" -# PROP Scc_LocalPath "" -CPP=cl.exe -RSC=rc.exe - -!IF "$(CFG)" == "dlltest - Win32 Release" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir "Release" -# PROP BASE Intermediate_Dir "Release" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 0 -# PROP Output_Dir "Release" -# PROP Intermediate_Dir "Release" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c -# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c -# ADD BASE RSC /l 0x411 /d "NDEBUG" -# ADD RSC /l 0x411 /d "NDEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 -# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:"minibz2.exe" - -!ELSEIF "$(CFG)" == "dlltest - Win32 Debug" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 1 -# PROP BASE Output_Dir "dlltest_" -# PROP BASE Intermediate_Dir "dlltest_" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 1 -# PROP Output_Dir "dlltest_" -# PROP Intermediate_Dir "dlltest_" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c -# ADD CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c -# ADD BASE RSC /l 0x411 /d "_DEBUG" -# ADD RSC /l 0x411 /d "_DEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept -# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:"minibz2.exe" /pdbtype:sept - -!ENDIF - -# Begin Target - -# Name "dlltest - Win32 Release" -# Name "dlltest - Win32 Debug" -# Begin Source File - -SOURCE=.\bzlib.h -# End Source File -# Begin Source File - -SOURCE=.\dlltest.c -# End Source File -# End Target -# End Project diff --git a/libbz2.def b/libbz2.def index 8255b8d..9ec5a4d 100644 --- a/libbz2.def +++ b/libbz2.def @@ -1,5 +1,4 @@ LIBRARY -DESCRIPTION "libbzip2: library for data compression" EXPORTS BZ2_bzCompressInit BZ2_bzCompress diff --git a/libbz2.dsp b/libbz2.dsp deleted file mode 100644 index a21a20f..0000000 --- a/libbz2.dsp +++ /dev/null @@ -1,130 +0,0 @@ -# Microsoft Developer Studio Project File - Name="libbz2" - Package Owner=<4> -# Microsoft Developer Studio Generated Build File, Format Version 5.00 -# ** 編集しないでください ** - -# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 - -CFG=libbz2 - Win32 Debug -!MESSAGE これは有効なメイクファイルではありません。 このプロジェクトをビルドするためには NMAKE を使用してください。 -!MESSAGE [メイクファイルのエクスポート] コマンドを使用して実行してください -!MESSAGE -!MESSAGE NMAKE /f "libbz2.mak". -!MESSAGE -!MESSAGE NMAKE の実行時に構成を指定できます -!MESSAGE コマンド ライン上でマクロの設定を定義します。例: -!MESSAGE -!MESSAGE NMAKE /f "libbz2.mak" CFG="libbz2 - Win32 Debug" -!MESSAGE -!MESSAGE 選択可能なビルド モード: -!MESSAGE -!MESSAGE "libbz2 - Win32 Release" ("Win32 (x86) Dynamic-Link Library" 用) -!MESSAGE "libbz2 - Win32 Debug" ("Win32 (x86) Dynamic-Link Library" 用) -!MESSAGE - -# Begin Project -# PROP Scc_ProjName "" -# PROP Scc_LocalPath "" -CPP=cl.exe -MTL=midl.exe -RSC=rc.exe - -!IF "$(CFG)" == "libbz2 - Win32 Release" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir "Release" -# PROP BASE Intermediate_Dir "Release" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 0 -# PROP Output_Dir "Release" -# PROP Intermediate_Dir "Release" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c -# ADD CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c -# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o NUL /win32 -# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o NUL /win32 -# ADD BASE RSC /l 0x411 /d "NDEBUG" -# ADD RSC /l 0x411 /d "NDEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386 -# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386 /out:"libbz2.dll" - -!ELSEIF "$(CFG)" == "libbz2 - Win32 Debug" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 1 -# PROP BASE Output_Dir "Debug" -# PROP BASE Intermediate_Dir "Debug" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 1 -# PROP Output_Dir "Debug" -# PROP Intermediate_Dir "Debug" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c -# ADD CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c -# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o NUL /win32 -# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o NUL /win32 -# ADD BASE RSC /l 0x411 /d "_DEBUG" -# ADD RSC /l 0x411 /d "_DEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept -# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /out:"libbz2.dll" /pdbtype:sept - -!ENDIF - -# Begin Target - -# Name "libbz2 - Win32 Release" -# Name "libbz2 - Win32 Debug" -# Begin Source File - -SOURCE=.\blocksort.c -# End Source File -# Begin Source File - -SOURCE=.\bzlib.c -# End Source File -# Begin Source File - -SOURCE=.\bzlib.h -# End Source File -# Begin Source File - -SOURCE=.\bzlib_private.h -# End Source File -# Begin Source File - -SOURCE=.\compress.c -# End Source File -# Begin Source File - -SOURCE=.\crctable.c -# End Source File -# Begin Source File - -SOURCE=.\decompress.c -# End Source File -# Begin Source File - -SOURCE=.\huffman.c -# End Source File -# Begin Source File - -SOURCE=.\libbz2.def -# End Source File -# Begin Source File - -SOURCE=.\randtable.c -# End Source File -# End Target -# End Project diff --git a/makefile.msc b/makefile.msc deleted file mode 100644 index 799a18a..0000000 --- a/makefile.msc +++ /dev/null @@ -1,63 +0,0 @@ -# Makefile for Microsoft Visual C++ 6.0 -# usage: nmake -f makefile.msc -# K.M. Syring (syring@gsf.de) -# Fixed up by JRS for bzip2-0.9.5d release. - -CC=cl -CFLAGS= -DWIN32 -MD -Ox -D_FILE_OFFSET_BITS=64 -nologo - -OBJS= blocksort.obj \ - huffman.obj \ - crctable.obj \ - randtable.obj \ - compress.obj \ - decompress.obj \ - bzlib.obj - -all: lib bzip2 test - -bzip2: lib - $(CC) $(CFLAGS) -o bzip2 bzip2.c libbz2.lib setargv.obj - $(CC) $(CFLAGS) -o bzip2recover bzip2recover.c - -lib: $(OBJS) - lib /out:libbz2.lib $(OBJS) - -test: bzip2 - type words1 - .\\bzip2 -1 < sample1.ref > sample1.rb2 - .\\bzip2 -2 < sample2.ref > sample2.rb2 - .\\bzip2 -3 < sample3.ref > sample3.rb2 - .\\bzip2 -d < sample1.bz2 > sample1.tst - .\\bzip2 -d < sample2.bz2 > sample2.tst - .\\bzip2 -ds < sample3.bz2 > sample3.tst - @echo All six of the fc's should find no differences. - @echo If fc finds an error on sample3.bz2, this could be - @echo because WinZip's 'TAR file smart CR/LF conversion' - @echo is too clever for its own good. Disable this option. - @echo The correct size for sample3.ref is 120,244. If it - @echo is 150,251, WinZip has messed it up. - fc sample1.bz2 sample1.rb2 - fc sample2.bz2 sample2.rb2 - fc sample3.bz2 sample3.rb2 - fc sample1.tst sample1.ref - fc sample2.tst sample2.ref - fc sample3.tst sample3.ref - - - -clean: - del *.obj - del libbz2.lib - del bzip2.exe - del bzip2recover.exe - del sample1.rb2 - del sample2.rb2 - del sample3.rb2 - del sample1.tst - del sample2.tst - del sample3.tst - -.c.obj: - $(CC) $(CFLAGS) -c $*.c -o $*.obj - diff --git a/runtest.cmake b/runtest.cmake new file mode 100644 index 0000000..3c1120b --- /dev/null +++ b/runtest.cmake @@ -0,0 +1,19 @@ +message("TEST_PROG=${TEST_PROG}") +message("OUTPUT=${OUTPUT}") + +execute_process( + COMMAND ${TEST_PROG} ${ARGUMENTS} + RESULT_VARIABLE HAD_ERROR + INPUT_FILE ${INPUT} + OUTPUT_FILE ${OUTPUT} +) +if(HAD_ERROR) + message(FATAL_ERROR "Test failed - ERROR in execute process!!!") +endif() + +execute_process(COMMAND ${CMAKE_COMMAND} -E compare_files + ${OUTPUT} ${EXPECTED} + RESULT_VARIABLE DIFFERENT) +if(DIFFERENT) + message(FATAL_ERROR "Test failed - files differ") +endif() diff --git a/spewG.c b/spewG.c index 14a3649..0091ff3 100644 --- a/spewG.c +++ b/spewG.c @@ -26,9 +26,18 @@ #define _FILE_OFFSET_BITS 64 + #include #include +#if defined(_WIN32) +# include +# include +# define SET_BINARY_MODE(file) setmode(fileno(file),O_BINARY) +#else +# define SET_BINARY_MODE(file) +#endif + /* The number of megabytes of junk to spew out (roughly) */ #define MEGABYTES 5000 @@ -38,10 +47,11 @@ char buf[N_BUF]; int main ( int argc, char** argv ) { int ii, kk, p; - srandom(1); - setbuffer ( stdout, buf, N_BUF ); + srand(1); + SET_BINARY_MODE(stdout); + setvbuf ( stdout, buf, _IOFBF, N_BUF ); for (kk = 0; kk < MEGABYTES * 515; kk+=3) { - p = 25+random()%50; + p = 25+rand()%50; for (ii = 0; ii < p; ii++) printf ( "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" ); for (ii = 0; ii < p-1; ii++) diff --git a/version.rc.cmakein b/version.rc.cmakein new file mode 100644 index 0000000..b25e34f --- /dev/null +++ b/version.rc.cmakein @@ -0,0 +1,47 @@ +// +#include +///////////////////////////////////////////////////////////////////////////// +// +// Version +// + +#define VER_FILEVERSION @VER_NUM@ +#define VER_FILEVERSION_STR "@VER_STR@\0" + +#define VER_PRODUCTVERSION @VER_NUM@ +#define VER_PRODUCTVERSION_STR "@VER_STR@\0" + +#ifndef DEBUG +#define VER_DEBUG 0 +#else +#define VER_DEBUG VS_FF_DEBUG +#endif + +VS_VERSION_INFO VERSIONINFO +FILEVERSION VER_FILEVERSION +PRODUCTVERSION VER_PRODUCTVERSION +FILEFLAGSMASK VS_FFI_FILEFLAGSMASK +FILEFLAGS (VER_DEBUG) +FILEOS VOS__WINDOWS32 +FILETYPE VFT_DLL +FILESUBTYPE VFT2_UNKNOWN +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904E4" + BEGIN + VALUE "FileDescription", "@VER_FILEDESCRIPTION_STR@\0" + VALUE "FileVersion", VER_FILEVERSION_STR + VALUE "InternalName", "@VER_INTERNALNAME_STR@\0" + VALUE "LegalCopyright", "@VER_LEGALCOPYRIGHT_STR@\0" + VALUE "OriginalFilename", "@VER_ORIGINALFILENAME_STR@\0" + VALUE "ProductName", "@VER_PRODUCTNAME_STR@\0" + VALUE "ProductVersion", VER_PRODUCTVERSION_STR + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1252 + END +END +