Fossil

Changes On Branch zlib
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Changes In Branch zlib Excluding Merge-Ins

This is equivalent to a diff from 77cd6e0d to 36734cfc

2012-11-27
13:21
Add zlib sources to the tree in the compat/zlib subdirectory and use them to build Fossil on windows systems that lack a zlib library. (check-in: 7ef7284d user: drh tags: trunk)
09:42
blob_to_utf8_no_bom(): the starts_with_utf16(le|be)_bom calls were swapped. (check-in: d27cddf1 user: jan.nijtmans tags: trunk)
09:10
merge trunk (check-in: 43caa737 user: jan.nijtmans tags: convert_before_commit_v2)
07:03
Modify the MinGW makefile to support building with zlib in the compat directory. (Closed-Leaf check-in: 36734cfc user: mistachkin tags: zlib)
06:31
Support building with zlib in the compat directory, phase 1. (check-in: d17f4473 user: mistachkin tags: zlib)
00:23
Assume that the NetSurf browser is operated by a human. (check-in: 77cd6e0d user: drh tags: trunk)
2012-11-26
22:51
Merge byte-order-mark handling enhancements to trunk. (check-in: 9b800ee4 user: mistachkin tags: trunk)

Added compat/zlib/CMakeLists.txt.

            1  +cmake_minimum_required(VERSION 2.4.4)
            2  +set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS ON)
            3  +
            4  +project(zlib C)
            5  +
            6  +set(VERSION "1.2.7")
            7  +
            8  +set(INSTALL_BIN_DIR "${CMAKE_INSTALL_PREFIX}/bin" CACHE PATH "Installation directory for executables")
            9  +set(INSTALL_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE PATH "Installation directory for libraries")
           10  +set(INSTALL_INC_DIR "${CMAKE_INSTALL_PREFIX}/include" CACHE PATH "Installation directory for headers")
           11  +set(INSTALL_MAN_DIR "${CMAKE_INSTALL_PREFIX}/share/man" CACHE PATH "Installation directory for manual pages")
           12  +set(INSTALL_PKGCONFIG_DIR "${CMAKE_INSTALL_PREFIX}/share/pkgconfig" CACHE PATH "Installation directory for pkgconfig (.pc) files")
           13  +
           14  +include(CheckTypeSize)
           15  +include(CheckFunctionExists)
           16  +include(CheckIncludeFile)
           17  +include(CheckCSourceCompiles)
           18  +enable_testing()
           19  +
           20  +check_include_file(sys/types.h HAVE_SYS_TYPES_H)
           21  +check_include_file(stdint.h    HAVE_STDINT_H)
           22  +check_include_file(stddef.h    HAVE_STDDEF_H)
           23  +
           24  +#
           25  +# Check to see if we have large file support
           26  +#
           27  +set(CMAKE_REQUIRED_DEFINITIONS -D_LARGEFILE64_SOURCE=1)
           28  +# We add these other definitions here because CheckTypeSize.cmake
           29  +# in CMake 2.4.x does not automatically do so and we want
           30  +# compatibility with CMake 2.4.x.
           31  +if(HAVE_SYS_TYPES_H)
           32  +    list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_SYS_TYPES_H)
           33  +endif()
           34  +if(HAVE_STDINT_H)
           35  +    list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_STDINT_H)
           36  +endif()
           37  +if(HAVE_STDDEF_H)
           38  +    list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_STDDEF_H)
           39  +endif()
           40  +check_type_size(off64_t OFF64_T)
           41  +if(HAVE_OFF64_T)
           42  +   add_definitions(-D_LARGEFILE64_SOURCE=1)
           43  +endif()
           44  +set(CMAKE_REQUIRED_DEFINITIONS) # clear variable
           45  +
           46  +#
           47  +# Check for fseeko
           48  +#
           49  +check_function_exists(fseeko HAVE_FSEEKO)
           50  +if(NOT HAVE_FSEEKO)
           51  +    add_definitions(-DNO_FSEEKO)
           52  +endif()
           53  +
           54  +#
           55  +# Check for unistd.h
           56  +#
           57  +check_include_file(unistd.h Z_HAVE_UNISTD_H)
           58  +
           59  +if(MSVC)
           60  +    set(CMAKE_DEBUG_POSTFIX "d")
           61  +    add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
           62  +    add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE)
           63  +    include_directories(${CMAKE_CURRENT_SOURCE_DIR})
           64  +endif()
           65  +
           66  +if(NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR)
           67  +    # If we're doing an out of source build and the user has a zconf.h
           68  +    # in their source tree...
           69  +    if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h)
           70  +        message(STATUS "Renaming")
           71  +        message(STATUS "    ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h")
           72  +        message(STATUS "to 'zconf.h.included' because this file is included with zlib")
           73  +        message(STATUS "but CMake generates it automatically in the build directory.")
           74  +        file(RENAME ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h.included)
           75  +  endif()
           76  +endif()
           77  +
           78  +set(ZLIB_PC ${CMAKE_CURRENT_BINARY_DIR}/zlib.pc)
           79  +configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/zlib.pc.cmakein
           80  +		${ZLIB_PC} @ONLY)
           81  +configure_file(	${CMAKE_CURRENT_SOURCE_DIR}/zconf.h.cmakein
           82  +		${CMAKE_CURRENT_BINARY_DIR}/zconf.h @ONLY)
           83  +include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR})
           84  +
           85  +
           86  +#============================================================================
           87  +# zlib
           88  +#============================================================================
           89  +
           90  +set(ZLIB_PUBLIC_HDRS
           91  +    ${CMAKE_CURRENT_BINARY_DIR}/zconf.h
           92  +    zlib.h
           93  +)
           94  +set(ZLIB_PRIVATE_HDRS
           95  +    crc32.h
           96  +    deflate.h
           97  +    gzguts.h
           98  +    inffast.h
           99  +    inffixed.h
          100  +    inflate.h
          101  +    inftrees.h
          102  +    trees.h
          103  +    zutil.h
          104  +)
          105  +set(ZLIB_SRCS
          106  +    adler32.c
          107  +    compress.c
          108  +    crc32.c
          109  +    deflate.c
          110  +    gzclose.c
          111  +    gzlib.c
          112  +    gzread.c
          113  +    gzwrite.c
          114  +    inflate.c
          115  +    infback.c
          116  +    inftrees.c
          117  +    inffast.c
          118  +    trees.c
          119  +    uncompr.c
          120  +    zutil.c
          121  +)
          122  +
          123  +if(NOT MINGW)
          124  +    set(ZLIB_SRCS ${ZLIB_SRCS}
          125  +        win32/zlib1.rc # If present will override custom build rule below.
          126  +    )
          127  +endif()
          128  +
          129  +# parse the full version number from zlib.h and include in ZLIB_FULL_VERSION
          130  +file(READ ${CMAKE_CURRENT_SOURCE_DIR}/zlib.h _zlib_h_contents)
          131  +string(REGEX REPLACE ".*#define[ \t]+ZLIB_VERSION[ \t]+\"([-0-9A-Za-z.]+)\".*"
          132  +    "\\1" ZLIB_FULL_VERSION ${_zlib_h_contents})
          133  +
          134  +if(MINGW)
          135  +    # This gets us DLL resource information when compiling on MinGW.
          136  +    if(NOT CMAKE_RC_COMPILER)
          137  +        SET(CMAKE_RC_COMPILER windres.exe)
          138  +    endif()
          139  +
          140  +    add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj
          141  +                       COMMAND ${CMAKE_RC_COMPILER}
          142  +                            -D GCC_WINDRES
          143  +                            -I ${CMAKE_CURRENT_SOURCE_DIR}
          144  +                            -I ${CMAKE_CURRENT_BINARY_DIR}
          145  +                            -o ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj
          146  +                            -i ${CMAKE_CURRENT_SOURCE_DIR}/win32/zlib1.rc)
          147  +    set(ZLIB_SRCS ${ZLIB_SRCS} ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj)
          148  +endif(MINGW)
          149  +
          150  +add_library(zlib SHARED ${ZLIB_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})
          151  +add_library(zlibstatic STATIC ${ZLIB_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})
          152  +set_target_properties(zlib PROPERTIES DEFINE_SYMBOL ZLIB_DLL)
          153  +set_target_properties(zlib PROPERTIES SOVERSION 1)
          154  +
          155  +if(NOT CYGWIN)
          156  +    # This property causes shared libraries on Linux to have the full version
          157  +    # encoded into their final filename.  We disable this on Cygwin because
          158  +    # it causes cygz-${ZLIB_FULL_VERSION}.dll to be created when cygz.dll
          159  +    # seems to be the default.
          160  +    #
          161  +    # This has no effect with MSVC, on that platform the version info for
          162  +    # the DLL comes from the resource file win32/zlib1.rc
          163  +    set_target_properties(zlib PROPERTIES VERSION ${ZLIB_FULL_VERSION})
          164  +endif()
          165  +
          166  +if(UNIX)
          167  +    # On unix-like platforms the library is almost always called libz
          168  +   set_target_properties(zlib zlibstatic PROPERTIES OUTPUT_NAME z)
          169  +   set_target_properties(zlib PROPERTIES LINK_FLAGS "-Wl,--version-script,${CMAKE_CURRENT_SOURCE_DIR}/zlib.map")
          170  +elseif(BUILD_SHARED_LIBS AND WIN32)
          171  +    # Creates zlib1.dll when building shared library version
          172  +    set_target_properties(zlib PROPERTIES SUFFIX "1.dll")
          173  +endif()
          174  +
          175  +if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL )
          176  +    install(TARGETS zlib zlibstatic
          177  +        RUNTIME DESTINATION "${INSTALL_BIN_DIR}"
          178  +        ARCHIVE DESTINATION "${INSTALL_LIB_DIR}"
          179  +        LIBRARY DESTINATION "${INSTALL_LIB_DIR}" )
          180  +endif()
          181  +if(NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL )
          182  +    install(FILES ${ZLIB_PUBLIC_HDRS} DESTINATION "${INSTALL_INC_DIR}")
          183  +endif()
          184  +if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL )
          185  +    install(FILES zlib.3 DESTINATION "${INSTALL_MAN_DIR}/man3")
          186  +endif()
          187  +if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL )
          188  +    install(FILES ${ZLIB_PC} DESTINATION "${INSTALL_PKGCONFIG_DIR}")
          189  +endif()
          190  +
          191  +#============================================================================
          192  +# Example binaries
          193  +#============================================================================
          194  +
          195  +add_executable(example test/example.c)
          196  +target_link_libraries(example zlib)
          197  +add_test(example example)
          198  +
          199  +add_executable(minigzip test/minigzip.c)
          200  +target_link_libraries(minigzip zlib)
          201  +
          202  +if(HAVE_OFF64_T)
          203  +    add_executable(example64 test/example.c)
          204  +    target_link_libraries(example64 zlib)
          205  +    set_target_properties(example64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64")
          206  +    add_test(example64 example64)
          207  +
          208  +    add_executable(minigzip64 test/minigzip.c)
          209  +    target_link_libraries(minigzip64 zlib)
          210  +    set_target_properties(minigzip64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64")
          211  +endif()

Added compat/zlib/ChangeLog.

            1  +
            2  +                ChangeLog file for zlib
            3  +
            4  +Changes in 1.2.7 (2 May 2012)
            5  +- Replace use of memmove() with a simple copy for portability
            6  +- Test for existence of strerror
            7  +- Restore gzgetc_ for backward compatibility with 1.2.6
            8  +- Fix build with non-GNU make on Solaris
            9  +- Require gcc 4.0 or later on Mac OS X to use the hidden attribute
           10  +- Include unistd.h for Watcom C
           11  +- Use __WATCOMC__ instead of __WATCOM__
           12  +- Do not use the visibility attribute if NO_VIZ defined
           13  +- Improve the detection of no hidden visibility attribute
           14  +- Avoid using __int64 for gcc or solo compilation
           15  +- Cast to char * in gzprintf to avoid warnings [Zinser]
           16  +- Fix make_vms.com for VAX [Zinser]
           17  +- Don't use library or built-in byte swaps
           18  +- Simplify test and use of gcc hidden attribute
           19  +- Fix bug in gzclose_w() when gzwrite() fails to allocate memory
           20  +- Add "x" (O_EXCL) and "e" (O_CLOEXEC) modes support to gzopen()
           21  +- Fix bug in test/minigzip.c for configure --solo
           22  +- Fix contrib/vstudio project link errors [Mohanathas]
           23  +- Add ability to choose the builder in make_vms.com [Schweda]
           24  +- Add DESTDIR support to mingw32 win32/Makefile.gcc
           25  +- Fix comments in win32/Makefile.gcc for proper usage
           26  +- Allow overriding the default install locations for cmake
           27  +- Generate and install the pkg-config file with cmake
           28  +- Build both a static and a shared version of zlib with cmake
           29  +- Include version symbols for cmake builds
           30  +- If using cmake with MSVC, add the source directory to the includes
           31  +- Remove unneeded EXTRA_CFLAGS from win32/Makefile.gcc [Truta]
           32  +- Move obsolete emx makefile to old [Truta]
           33  +- Allow the use of -Wundef when compiling or using zlib
           34  +- Avoid the use of the -u option with mktemp
           35  +- Improve inflate() documentation on the use of Z_FINISH
           36  +- Recognize clang as gcc
           37  +- Add gzopen_w() in Windows for wide character path names
           38  +- Rename zconf.h in CMakeLists.txt to move it out of the way
           39  +- Add source directory in CMakeLists.txt for building examples
           40  +- Look in build directory for zlib.pc in CMakeLists.txt
           41  +- Remove gzflags from zlibvc.def in vc9 and vc10
           42  +- Fix contrib/minizip compilation in the MinGW environment
           43  +- Update ./configure for Solaris, support --64 [Mooney]
           44  +- Remove -R. from Solaris shared build (possible security issue)
           45  +- Avoid race condition for parallel make (-j) running example
           46  +- Fix type mismatch between get_crc_table() and crc_table
           47  +- Fix parsing of version with "-" in CMakeLists.txt [Snider, Ziegler]
           48  +- Fix the path to zlib.map in CMakeLists.txt
           49  +- Force the native libtool in Mac OS X to avoid GNU libtool [Beebe]
           50  +- Add instructions to win32/Makefile.gcc for shared install [Torri]
           51  +
           52  +Changes in 1.2.6.1 (12 Feb 2012)
           53  +- Avoid the use of the Objective-C reserved name "id"
           54  +- Include io.h in gzguts.h for Microsoft compilers
           55  +- Fix problem with ./configure --prefix and gzgetc macro
           56  +- Include gz_header definition when compiling zlib solo
           57  +- Put gzflags() functionality back in zutil.c
           58  +- Avoid library header include in crc32.c for Z_SOLO
           59  +- Use name in GCC_CLASSIC as C compiler for coverage testing, if set
           60  +- Minor cleanup in contrib/minizip/zip.c [Vollant]
           61  +- Update make_vms.com [Zinser]
           62  +- Remove unnecessary gzgetc_ function
           63  +- Use optimized byte swap operations for Microsoft and GNU [Snyder]
           64  +- Fix minor typo in zlib.h comments [Rzesniowiecki]
           65  +
           66  +Changes in 1.2.6 (29 Jan 2012)
           67  +- Update the Pascal interface in contrib/pascal
           68  +- Fix function numbers for gzgetc_ in zlibvc.def files
           69  +- Fix configure.ac for contrib/minizip [Schiffer]
           70  +- Fix large-entry detection in minizip on 64-bit systems [Schiffer]
           71  +- Have ./configure use the compiler return code for error indication
           72  +- Fix CMakeLists.txt for cross compilation [McClure]
           73  +- Fix contrib/minizip/zip.c for 64-bit architectures [Dalsnes]
           74  +- Fix compilation of contrib/minizip on FreeBSD [Marquez]
           75  +- Correct suggested usages in win32/Makefile.msc [Shachar, Horvath]
           76  +- Include io.h for Turbo C / Borland C on all platforms [Truta]
           77  +- Make version explicit in contrib/minizip/configure.ac [Bosmans]
           78  +- Avoid warning for no encryption in contrib/minizip/zip.c [Vollant]
           79  +- Minor cleanup up contrib/minizip/unzip.c [Vollant]
           80  +- Fix bug when compiling minizip with C++ [Vollant]
           81  +- Protect for long name and extra fields in contrib/minizip [Vollant]
           82  +- Avoid some warnings in contrib/minizip [Vollant]
           83  +- Add -I../.. -L../.. to CFLAGS for minizip and miniunzip
           84  +- Add missing libs to minizip linker command
           85  +- Add support for VPATH builds in contrib/minizip
           86  +- Add an --enable-demos option to contrib/minizip/configure
           87  +- Add the generation of configure.log by ./configure
           88  +- Exit when required parameters not provided to win32/Makefile.gcc
           89  +- Have gzputc return the character written instead of the argument
           90  +- Use the -m option on ldconfig for BSD systems [Tobias]
           91  +- Correct in zlib.map when deflateResetKeep was added
           92  +
           93  +Changes in 1.2.5.3 (15 Jan 2012)
           94  +- Restore gzgetc function for binary compatibility
           95  +- Do not use _lseeki64 under Borland C++ [Truta]
           96  +- Update win32/Makefile.msc to build test/*.c [Truta]
           97  +- Remove old/visualc6 given CMakefile and other alternatives
           98  +- Update AS400 build files and documentation [Monnerat]
           99  +- Update win32/Makefile.gcc to build test/*.c [Truta]
          100  +- Permit stronger flushes after Z_BLOCK flushes
          101  +- Avoid extraneous empty blocks when doing empty flushes
          102  +- Permit Z_NULL arguments to deflatePending
          103  +- Allow deflatePrime() to insert bits in the middle of a stream
          104  +- Remove second empty static block for Z_PARTIAL_FLUSH
          105  +- Write out all of the available bits when using Z_BLOCK
          106  +- Insert the first two strings in the hash table after a flush
          107  +
          108  +Changes in 1.2.5.2 (17 Dec 2011)
          109  +- fix ld error: unable to find version dependency 'ZLIB_1.2.5'
          110  +- use relative symlinks for shared libs
          111  +- Avoid searching past window for Z_RLE strategy
          112  +- Assure that high-water mark initialization is always applied in deflate
          113  +- Add assertions to fill_window() in deflate.c to match comments
          114  +- Update python link in README
          115  +- Correct spelling error in gzread.c
          116  +- Fix bug in gzgets() for a concatenated empty gzip stream
          117  +- Correct error in comment for gz_make()
          118  +- Change gzread() and related to ignore junk after gzip streams
          119  +- Allow gzread() and related to continue after gzclearerr()
          120  +- Allow gzrewind() and gzseek() after a premature end-of-file
          121  +- Simplify gzseek() now that raw after gzip is ignored
          122  +- Change gzgetc() to a macro for speed (~40% speedup in testing)
          123  +- Fix gzclose() to return the actual error last encountered
          124  +- Always add large file support for windows
          125  +- Include zconf.h for windows large file support
          126  +- Include zconf.h.cmakein for windows large file support
          127  +- Update zconf.h.cmakein on make distclean
          128  +- Merge vestigial vsnprintf determination from zutil.h to gzguts.h
          129  +- Clarify how gzopen() appends in zlib.h comments
          130  +- Correct documentation of gzdirect() since junk at end now ignored
          131  +- Add a transparent write mode to gzopen() when 'T' is in the mode
          132  +- Update python link in zlib man page
          133  +- Get inffixed.h and MAKEFIXED result to match
          134  +- Add a ./config --solo option to make zlib subset with no libary use
          135  +- Add undocumented inflateResetKeep() function for CAB file decoding
          136  +- Add --cover option to ./configure for gcc coverage testing
          137  +- Add #define ZLIB_CONST option to use const in the z_stream interface
          138  +- Add comment to gzdopen() in zlib.h to use dup() when using fileno()
          139  +- Note behavior of uncompress() to provide as much data as it can
          140  +- Add files in contrib/minizip to aid in building libminizip
          141  +- Split off AR options in Makefile.in and configure
          142  +- Change ON macro to Z_ARG to avoid application conflicts
          143  +- Facilitate compilation with Borland C++ for pragmas and vsnprintf
          144  +- Include io.h for Turbo C / Borland C++
          145  +- Move example.c and minigzip.c to test/
          146  +- Simplify incomplete code table filling in inflate_table()
          147  +- Remove code from inflate.c and infback.c that is impossible to execute
          148  +- Test the inflate code with full coverage
          149  +- Allow deflateSetDictionary, inflateSetDictionary at any time (in raw)
          150  +- Add deflateResetKeep and fix inflateResetKeep to retain dictionary
          151  +- Fix gzwrite.c to accommodate reduced memory zlib compilation
          152  +- Have inflate() with Z_FINISH avoid the allocation of a window
          153  +- Do not set strm->adler when doing raw inflate
          154  +- Fix gzeof() to behave just like feof() when read is not past end of file
          155  +- Fix bug in gzread.c when end-of-file is reached
          156  +- Avoid use of Z_BUF_ERROR in gz* functions except for premature EOF
          157  +- Document gzread() capability to read concurrently written files
          158  +- Remove hard-coding of resource compiler in CMakeLists.txt [Blammo]
          159  +
          160  +Changes in 1.2.5.1 (10 Sep 2011)
          161  +- Update FAQ entry on shared builds (#13)
          162  +- Avoid symbolic argument to chmod in Makefile.in
          163  +- Fix bug and add consts in contrib/puff [Oberhumer]
          164  +- Update contrib/puff/zeros.raw test file to have all block types
          165  +- Add full coverage test for puff in contrib/puff/Makefile
          166  +- Fix static-only-build install in Makefile.in
          167  +- Fix bug in unzGetCurrentFileInfo() in contrib/minizip [Kuno]
          168  +- Add libz.a dependency to shared in Makefile.in for parallel builds
          169  +- Spell out "number" (instead of "nb") in zlib.h for total_in, total_out
          170  +- Replace $(...) with `...` in configure for non-bash sh [Bowler]
          171  +- Add darwin* to Darwin* and solaris* to SunOS\ 5* in configure [Groffen]
          172  +- Add solaris* to Linux* in configure to allow gcc use [Groffen]
          173  +- Add *bsd* to Linux* case in configure [Bar-Lev]
          174  +- Add inffast.obj to dependencies in win32/Makefile.msc
          175  +- Correct spelling error in deflate.h [Kohler]
          176  +- Change libzdll.a again to libz.dll.a (!) in win32/Makefile.gcc
          177  +- Add test to configure for GNU C looking for gcc in output of $cc -v
          178  +- Add zlib.pc generation to win32/Makefile.gcc [Weigelt]
          179  +- Fix bug in zlib.h for _FILE_OFFSET_BITS set and _LARGEFILE64_SOURCE not
          180  +- Add comment in zlib.h that adler32_combine with len2 < 0 makes no sense
          181  +- Make NO_DIVIDE option in adler32.c much faster (thanks to John Reiser)
          182  +- Make stronger test in zconf.h to include unistd.h for LFS
          183  +- Apply Darwin patches for 64-bit file offsets to contrib/minizip [Slack]
          184  +- Fix zlib.h LFS support when Z_PREFIX used
          185  +- Add updated as400 support (removed from old) [Monnerat]
          186  +- Avoid deflate sensitivity to volatile input data
          187  +- Avoid division in adler32_combine for NO_DIVIDE
          188  +- Clarify the use of Z_FINISH with deflateBound() amount of space
          189  +- Set binary for output file in puff.c
          190  +- Use u4 type for crc_table to avoid conversion warnings
          191  +- Apply casts in zlib.h to avoid conversion warnings
          192  +- Add OF to prototypes for adler32_combine_ and crc32_combine_ [Miller]
          193  +- Improve inflateSync() documentation to note indeterminancy
          194  +- Add deflatePending() function to return the amount of pending output
          195  +- Correct the spelling of "specification" in FAQ [Randers-Pehrson]
          196  +- Add a check in configure for stdarg.h, use for gzprintf()
          197  +- Check that pointers fit in ints when gzprint() compiled old style
          198  +- Add dummy name before $(SHAREDLIBV) in Makefile [Bar-Lev, Bowler]
          199  +- Delete line in configure that adds -L. libz.a to LDFLAGS [Weigelt]
          200  +- Add debug records in assmebler code [Londer]
          201  +- Update RFC references to use http://tools.ietf.org/html/... [Li]
          202  +- Add --archs option, use of libtool to configure for Mac OS X [Borstel]
          203  +
          204  +Changes in 1.2.5 (19 Apr 2010)
          205  +- Disable visibility attribute in win32/Makefile.gcc [Bar-Lev]
          206  +- Default to libdir as sharedlibdir in configure [Nieder]
          207  +- Update copyright dates on modified source files
          208  +- Update trees.c to be able to generate modified trees.h
          209  +- Exit configure for MinGW, suggesting win32/Makefile.gcc
          210  +- Check for NULL path in gz_open [Homurlu]
          211  +
          212  +Changes in 1.2.4.5 (18 Apr 2010)
          213  +- Set sharedlibdir in configure [Torok]
          214  +- Set LDFLAGS in Makefile.in [Bar-Lev]
          215  +- Avoid mkdir objs race condition in Makefile.in [Bowler]
          216  +- Add ZLIB_INTERNAL in front of internal inter-module functions and arrays
          217  +- Define ZLIB_INTERNAL to hide internal functions and arrays for GNU C
          218  +- Don't use hidden attribute when it is a warning generator (e.g. Solaris)
          219  +
          220  +Changes in 1.2.4.4 (18 Apr 2010)
          221  +- Fix CROSS_PREFIX executable testing, CHOST extract, mingw* [Torok]
          222  +- Undefine _LARGEFILE64_SOURCE in zconf.h if it is zero, but not if empty
          223  +- Try to use bash or ksh regardless of functionality of /bin/sh
          224  +- Fix configure incompatibility with NetBSD sh
          225  +- Remove attempt to run under bash or ksh since have better NetBSD fix
          226  +- Fix win32/Makefile.gcc for MinGW [Bar-Lev]
          227  +- Add diagnostic messages when using CROSS_PREFIX in configure
          228  +- Added --sharedlibdir option to configure [Weigelt]
          229  +- Use hidden visibility attribute when available [Frysinger]
          230  +
          231  +Changes in 1.2.4.3 (10 Apr 2010)
          232  +- Only use CROSS_PREFIX in configure for ar and ranlib if they exist
          233  +- Use CROSS_PREFIX for nm [Bar-Lev]
          234  +- Assume _LARGEFILE64_SOURCE defined is equivalent to true
          235  +- Avoid use of undefined symbols in #if with && and ||
          236  +- Make *64 prototypes in gzguts.h consistent with functions
          237  +- Add -shared load option for MinGW in configure [Bowler]
          238  +- Move z_off64_t to public interface, use instead of off64_t
          239  +- Remove ! from shell test in configure (not portable to Solaris)
          240  +- Change +0 macro tests to -0 for possibly increased portability
          241  +
          242  +Changes in 1.2.4.2 (9 Apr 2010)
          243  +- Add consistent carriage returns to readme.txt's in masmx86 and masmx64
          244  +- Really provide prototypes for *64 functions when building without LFS
          245  +- Only define unlink() in minigzip.c if unistd.h not included
          246  +- Update README to point to contrib/vstudio project files
          247  +- Move projects/vc6 to old/ and remove projects/
          248  +- Include stdlib.h in minigzip.c for setmode() definition under WinCE
          249  +- Clean up assembler builds in win32/Makefile.msc [Rowe]
          250  +- Include sys/types.h for Microsoft for off_t definition
          251  +- Fix memory leak on error in gz_open()
          252  +- Symbolize nm as $NM in configure [Weigelt]
          253  +- Use TEST_LDSHARED instead of LDSHARED to link test programs [Weigelt]
          254  +- Add +0 to _FILE_OFFSET_BITS and _LFS64_LARGEFILE in case not defined
          255  +- Fix bug in gzeof() to take into account unused input data
          256  +- Avoid initialization of structures with variables in puff.c
          257  +- Updated win32/README-WIN32.txt [Rowe]
          258  +
          259  +Changes in 1.2.4.1 (28 Mar 2010)
          260  +- Remove the use of [a-z] constructs for sed in configure [gentoo 310225]
          261  +- Remove $(SHAREDLIB) from LIBS in Makefile.in [Creech]
          262  +- Restore "for debugging" comment on sprintf() in gzlib.c
          263  +- Remove fdopen for MVS from gzguts.h
          264  +- Put new README-WIN32.txt in win32 [Rowe]
          265  +- Add check for shell to configure and invoke another shell if needed
          266  +- Fix big fat stinking bug in gzseek() on uncompressed files
          267  +- Remove vestigial F_OPEN64 define in zutil.h
          268  +- Set and check the value of _LARGEFILE_SOURCE and _LARGEFILE64_SOURCE
          269  +- Avoid errors on non-LFS systems when applications define LFS macros
          270  +- Set EXE to ".exe" in configure for MINGW [Kahle]
          271  +- Match crc32() in crc32.c exactly to the prototype in zlib.h [Sherrill]
          272  +- Add prefix for cross-compilation in win32/makefile.gcc [Bar-Lev]
          273  +- Add DLL install in win32/makefile.gcc [Bar-Lev]
          274  +- Allow Linux* or linux* from uname in configure [Bar-Lev]
          275  +- Allow ldconfig to be redefined in configure and Makefile.in [Bar-Lev]
          276  +- Add cross-compilation prefixes to configure [Bar-Lev]
          277  +- Match type exactly in gz_load() invocation in gzread.c
          278  +- Match type exactly of zcalloc() in zutil.c to zlib.h alloc_func
          279  +- Provide prototypes for *64 functions when building zlib without LFS
          280  +- Don't use -lc when linking shared library on MinGW
          281  +- Remove errno.h check in configure and vestigial errno code in zutil.h
          282  +
          283  +Changes in 1.2.4 (14 Mar 2010)
          284  +- Fix VER3 extraction in configure for no fourth subversion
          285  +- Update zlib.3, add docs to Makefile.in to make .pdf out of it
          286  +- Add zlib.3.pdf to distribution
          287  +- Don't set error code in gzerror() if passed pointer is NULL
          288  +- Apply destination directory fixes to CMakeLists.txt [Lowman]
          289  +- Move #cmakedefine's to a new zconf.in.cmakein
          290  +- Restore zconf.h for builds that don't use configure or cmake
          291  +- Add distclean to dummy Makefile for convenience
          292  +- Update and improve INDEX, README, and FAQ
          293  +- Update CMakeLists.txt for the return of zconf.h [Lowman]
          294  +- Update contrib/vstudio/vc9 and vc10 [Vollant]
          295  +- Change libz.dll.a back to libzdll.a in win32/Makefile.gcc
          296  +- Apply license and readme changes to contrib/asm686 [Raiter]
          297  +- Check file name lengths and add -c option in minigzip.c [Li]
          298  +- Update contrib/amd64 and contrib/masmx86/ [Vollant]
          299  +- Avoid use of "eof" parameter in trees.c to not shadow library variable
          300  +- Update make_vms.com for removal of zlibdefs.h [Zinser]
          301  +- Update assembler code and vstudio projects in contrib [Vollant]
          302  +- Remove outdated assembler code contrib/masm686 and contrib/asm586
          303  +- Remove old vc7 and vc8 from contrib/vstudio
          304  +- Update win32/Makefile.msc, add ZLIB_VER_SUBREVISION [Rowe]
          305  +- Fix memory leaks in gzclose_r() and gzclose_w(), file leak in gz_open()
          306  +- Add contrib/gcc_gvmat64 for longest_match and inflate_fast [Vollant]
          307  +- Remove *64 functions from win32/zlib.def (they're not 64-bit yet)
          308  +- Fix bug in void-returning vsprintf() case in gzwrite.c
          309  +- Fix name change from inflate.h in contrib/inflate86/inffas86.c
          310  +- Check if temporary file exists before removing in make_vms.com [Zinser]
          311  +- Fix make install and uninstall for --static option
          312  +- Fix usage of _MSC_VER in gzguts.h and zutil.h [Truta]
          313  +- Update readme.txt in contrib/masmx64 and masmx86 to assemble
          314  +
          315  +Changes in 1.2.3.9 (21 Feb 2010)
          316  +- Expunge gzio.c
          317  +- Move as400 build information to old
          318  +- Fix updates in contrib/minizip and contrib/vstudio
          319  +- Add const to vsnprintf test in configure to avoid warnings [Weigelt]
          320  +- Delete zconf.h (made by configure) [Weigelt]
          321  +- Change zconf.in.h to zconf.h.in per convention [Weigelt]
          322  +- Check for NULL buf in gzgets()
          323  +- Return empty string for gzgets() with len == 1 (like fgets())
          324  +- Fix description of gzgets() in zlib.h for end-of-file, NULL return
          325  +- Update minizip to 1.1 [Vollant]
          326  +- Avoid MSVC loss of data warnings in gzread.c, gzwrite.c
          327  +- Note in zlib.h that gzerror() should be used to distinguish from EOF
          328  +- Remove use of snprintf() from gzlib.c
          329  +- Fix bug in gzseek()
          330  +- Update contrib/vstudio, adding vc9 and vc10 [Kuno, Vollant]
          331  +- Fix zconf.h generation in CMakeLists.txt [Lowman]
          332  +- Improve comments in zconf.h where modified by configure
          333  +
          334  +Changes in 1.2.3.8 (13 Feb 2010)
          335  +- Clean up text files (tabs, trailing whitespace, etc.) [Oberhumer]
          336  +- Use z_off64_t in gz_zero() and gz_skip() to match state->skip
          337  +- Avoid comparison problem when sizeof(int) == sizeof(z_off64_t)
          338  +- Revert to Makefile.in from 1.2.3.6 (live with the clutter)
          339  +- Fix missing error return in gzflush(), add zlib.h note
          340  +- Add *64 functions to zlib.map [Levin]
          341  +- Fix signed/unsigned comparison in gz_comp()
          342  +- Use SFLAGS when testing shared linking in configure
          343  +- Add --64 option to ./configure to use -m64 with gcc
          344  +- Fix ./configure --help to correctly name options
          345  +- Have make fail if a test fails [Levin]
          346  +- Avoid buffer overrun in contrib/masmx64/gvmat64.asm [Simpson]
          347  +- Remove assembler object files from contrib
          348  +
          349  +Changes in 1.2.3.7 (24 Jan 2010)
          350  +- Always gzopen() with O_LARGEFILE if available
          351  +- Fix gzdirect() to work immediately after gzopen() or gzdopen()
          352  +- Make gzdirect() more precise when the state changes while reading
          353  +- Improve zlib.h documentation in many places
          354  +- Catch memory allocation failure in gz_open()
          355  +- Complete close operation if seek forward in gzclose_w() fails
          356  +- Return Z_ERRNO from gzclose_r() if close() fails
          357  +- Return Z_STREAM_ERROR instead of EOF for gzclose() being passed NULL
          358  +- Return zero for gzwrite() errors to match zlib.h description
          359  +- Return -1 on gzputs() error to match zlib.h description
          360  +- Add zconf.in.h to allow recovery from configure modification [Weigelt]
          361  +- Fix static library permissions in Makefile.in [Weigelt]
          362  +- Avoid warnings in configure tests that hide functionality [Weigelt]
          363  +- Add *BSD and DragonFly to Linux case in configure [gentoo 123571]
          364  +- Change libzdll.a to libz.dll.a in win32/Makefile.gcc [gentoo 288212]
          365  +- Avoid access of uninitialized data for first inflateReset2 call [Gomes]
          366  +- Keep object files in subdirectories to reduce the clutter somewhat
          367  +- Remove default Makefile and zlibdefs.h, add dummy Makefile
          368  +- Add new external functions to Z_PREFIX, remove duplicates, z_z_ -> z_
          369  +- Remove zlibdefs.h completely -- modify zconf.h instead
          370  +
          371  +Changes in 1.2.3.6 (17 Jan 2010)
          372  +- Avoid void * arithmetic in gzread.c and gzwrite.c
          373  +- Make compilers happier with const char * for gz_error message
          374  +- Avoid unused parameter warning in inflate.c
          375  +- Avoid signed-unsigned comparison warning in inflate.c
          376  +- Indent #pragma's for traditional C
          377  +- Fix usage of strwinerror() in glib.c, change to gz_strwinerror()
          378  +- Correct email address in configure for system options
          379  +- Update make_vms.com and add make_vms.com to contrib/minizip [Zinser]
          380  +- Update zlib.map [Brown]
          381  +- Fix Makefile.in for Solaris 10 make of example64 and minizip64 [Torok]
          382  +- Apply various fixes to CMakeLists.txt [Lowman]
          383  +- Add checks on len in gzread() and gzwrite()
          384  +- Add error message for no more room for gzungetc()
          385  +- Remove zlib version check in gzwrite()
          386  +- Defer compression of gzprintf() result until need to
          387  +- Use snprintf() in gzdopen() if available
          388  +- Remove USE_MMAP configuration determination (only used by minigzip)
          389  +- Remove examples/pigz.c (available separately)
          390  +- Update examples/gun.c to 1.6
          391  +
          392  +Changes in 1.2.3.5 (8 Jan 2010)
          393  +- Add space after #if in zutil.h for some compilers
          394  +- Fix relatively harmless bug in deflate_fast() [Exarevsky]
          395  +- Fix same problem in deflate_slow()
          396  +- Add $(SHAREDLIBV) to LIBS in Makefile.in [Brown]
          397  +- Add deflate_rle() for faster Z_RLE strategy run-length encoding
          398  +- Add deflate_huff() for faster Z_HUFFMAN_ONLY encoding
          399  +- Change name of "write" variable in inffast.c to avoid library collisions
          400  +- Fix premature EOF from gzread() in gzio.c [Brown]
          401  +- Use zlib header window size if windowBits is 0 in inflateInit2()
          402  +- Remove compressBound() call in deflate.c to avoid linking compress.o
          403  +- Replace use of errno in gz* with functions, support WinCE [Alves]
          404  +- Provide alternative to perror() in minigzip.c for WinCE [Alves]
          405  +- Don't use _vsnprintf on later versions of MSVC [Lowman]
          406  +- Add CMake build script and input file [Lowman]
          407  +- Update contrib/minizip to 1.1 [Svensson, Vollant]
          408  +- Moved nintendods directory from contrib to .
          409  +- Replace gzio.c with a new set of routines with the same functionality
          410  +- Add gzbuffer(), gzoffset(), gzclose_r(), gzclose_w() as part of above
          411  +- Update contrib/minizip to 1.1b
          412  +- Change gzeof() to return 0 on error instead of -1 to agree with zlib.h
          413  +
          414  +Changes in 1.2.3.4 (21 Dec 2009)
          415  +- Use old school .SUFFIXES in Makefile.in for FreeBSD compatibility
          416  +- Update comments in configure and Makefile.in for default --shared
          417  +- Fix test -z's in configure [Marquess]
          418  +- Build examplesh and minigzipsh when not testing
          419  +- Change NULL's to Z_NULL's in deflate.c and in comments in zlib.h
          420  +- Import LDFLAGS from the environment in configure
          421  +- Fix configure to populate SFLAGS with discovered CFLAGS options
          422  +- Adapt make_vms.com to the new Makefile.in [Zinser]
          423  +- Add zlib2ansi script for C++ compilation [Marquess]
          424  +- Add _FILE_OFFSET_BITS=64 test to make test (when applicable)
          425  +- Add AMD64 assembler code for longest match to contrib [Teterin]
          426  +- Include options from $SFLAGS when doing $LDSHARED
          427  +- Simplify 64-bit file support by introducing z_off64_t type
          428  +- Make shared object files in objs directory to work around old Sun cc
          429  +- Use only three-part version number for Darwin shared compiles
          430  +- Add rc option to ar in Makefile.in for when ./configure not run
          431  +- Add -WI,-rpath,. to LDFLAGS for OSF 1 V4*
          432  +- Set LD_LIBRARYN32_PATH for SGI IRIX shared compile
          433  +- Protect against _FILE_OFFSET_BITS being defined when compiling zlib
          434  +- Rename Makefile.in targets allstatic to static and allshared to shared
          435  +- Fix static and shared Makefile.in targets to be independent
          436  +- Correct error return bug in gz_open() by setting state [Brown]
          437  +- Put spaces before ;;'s in configure for better sh compatibility
          438  +- Add pigz.c (parallel implementation of gzip) to examples/
          439  +- Correct constant in crc32.c to UL [Leventhal]
          440  +- Reject negative lengths in crc32_combine()
          441  +- Add inflateReset2() function to work like inflateEnd()/inflateInit2()
          442  +- Include sys/types.h for _LARGEFILE64_SOURCE [Brown]
          443  +- Correct typo in doc/algorithm.txt [Janik]
          444  +- Fix bug in adler32_combine() [Zhu]
          445  +- Catch missing-end-of-block-code error in all inflates and in puff
          446  +    Assures that random input to inflate eventually results in an error
          447  +- Added enough.c (calculation of ENOUGH for inftrees.h) to examples/
          448  +- Update ENOUGH and its usage to reflect discovered bounds
          449  +- Fix gzerror() error report on empty input file [Brown]
          450  +- Add ush casts in trees.c to avoid pedantic runtime errors
          451  +- Fix typo in zlib.h uncompress() description [Reiss]
          452  +- Correct inflate() comments with regard to automatic header detection
          453  +- Remove deprecation comment on Z_PARTIAL_FLUSH (it stays)
          454  +- Put new version of gzlog (2.0) in examples with interruption recovery
          455  +- Add puff compile option to permit invalid distance-too-far streams
          456  +- Add puff TEST command options, ability to read piped input
          457  +- Prototype the *64 functions in zlib.h when _FILE_OFFSET_BITS == 64, but
          458  +  _LARGEFILE64_SOURCE not defined
          459  +- Fix Z_FULL_FLUSH to truly erase the past by resetting s->strstart
          460  +- Fix deflateSetDictionary() to use all 32K for output consistency
          461  +- Remove extraneous #define MIN_LOOKAHEAD in deflate.c (in deflate.h)
          462  +- Clear bytes after deflate lookahead to avoid use of uninitialized data
          463  +- Change a limit in inftrees.c to be more transparent to Coverity Prevent
          464  +- Update win32/zlib.def with exported symbols from zlib.h
          465  +- Correct spelling errors in zlib.h [Willem, Sobrado]
          466  +- Allow Z_BLOCK for deflate() to force a new block
          467  +- Allow negative bits in inflatePrime() to delete existing bit buffer
          468  +- Add Z_TREES flush option to inflate() to return at end of trees
          469  +- Add inflateMark() to return current state information for random access
          470  +- Add Makefile for NintendoDS to contrib [Costa]
          471  +- Add -w in configure compile tests to avoid spurious warnings [Beucler]
          472  +- Fix typos in zlib.h comments for deflateSetDictionary()
          473  +- Fix EOF detection in transparent gzread() [Maier]
          474  +
          475  +Changes in 1.2.3.3 (2 October 2006)
          476  +- Make --shared the default for configure, add a --static option
          477  +- Add compile option to permit invalid distance-too-far streams
          478  +- Add inflateUndermine() function which is required to enable above
          479  +- Remove use of "this" variable name for C++ compatibility [Marquess]
          480  +- Add testing of shared library in make test, if shared library built
          481  +- Use ftello() and fseeko() if available instead of ftell() and fseek()
          482  +- Provide two versions of all functions that use the z_off_t type for
          483  +  binary compatibility -- a normal version and a 64-bit offset version,
          484  +  per the Large File Support Extension when _LARGEFILE64_SOURCE is
          485  +  defined; use the 64-bit versions by default when _FILE_OFFSET_BITS
          486  +  is defined to be 64
          487  +- Add a --uname= option to configure to perhaps help with cross-compiling
          488  +
          489  +Changes in 1.2.3.2 (3 September 2006)
          490  +- Turn off silly Borland warnings [Hay]
          491  +- Use off64_t and define _LARGEFILE64_SOURCE when present
          492  +- Fix missing dependency on inffixed.h in Makefile.in
          493  +- Rig configure --shared to build both shared and static [Teredesai, Truta]
          494  +- Remove zconf.in.h and instead create a new zlibdefs.h file
          495  +- Fix contrib/minizip/unzip.c non-encrypted after encrypted [Vollant]
          496  +- Add treebuild.xml (see http://treebuild.metux.de/) [Weigelt]
          497  +
          498  +Changes in 1.2.3.1 (16 August 2006)
          499  +- Add watcom directory with OpenWatcom make files [Daniel]
          500  +- Remove #undef of FAR in zconf.in.h for MVS [Fedtke]
          501  +- Update make_vms.com [Zinser]
          502  +- Use -fPIC for shared build in configure [Teredesai, Nicholson]
          503  +- Use only major version number for libz.so on IRIX and OSF1 [Reinholdtsen]
          504  +- Use fdopen() (not _fdopen()) for Interix in zutil.h [BŠck]
          505  +- Add some FAQ entries about the contrib directory
          506  +- Update the MVS question in the FAQ
          507  +- Avoid extraneous reads after EOF in gzio.c [Brown]
          508  +- Correct spelling of "successfully" in gzio.c [Randers-Pehrson]
          509  +- Add comments to zlib.h about gzerror() usage [Brown]
          510  +- Set extra flags in gzip header in gzopen() like deflate() does
          511  +- Make configure options more compatible with double-dash conventions
          512  +  [Weigelt]
          513  +- Clean up compilation under Solaris SunStudio cc [Rowe, Reinholdtsen]
          514  +- Fix uninstall target in Makefile.in [Truta]
          515  +- Add pkgconfig support [Weigelt]
          516  +- Use $(DESTDIR) macro in Makefile.in [Reinholdtsen, Weigelt]
          517  +- Replace set_data_type() with a more accurate detect_data_type() in
          518  +  trees.c, according to the txtvsbin.txt document [Truta]
          519  +- Swap the order of #include <stdio.h> and #include "zlib.h" in
          520  +  gzio.c, example.c and minigzip.c [Truta]
          521  +- Shut up annoying VS2005 warnings about standard C deprecation [Rowe,
          522  +  Truta] (where?)
          523  +- Fix target "clean" from win32/Makefile.bor [Truta]
          524  +- Create .pdb and .manifest files in win32/makefile.msc [Ziegler, Rowe]
          525  +- Update zlib www home address in win32/DLL_FAQ.txt [Truta]
          526  +- Update contrib/masmx86/inffas32.asm for VS2005 [Vollant, Van Wassenhove]
          527  +- Enable browse info in the "Debug" and "ASM Debug" configurations in
          528  +  the Visual C++ 6 project, and set (non-ASM) "Debug" as default [Truta]
          529  +- Add pkgconfig support [Weigelt]
          530  +- Add ZLIB_VER_MAJOR, ZLIB_VER_MINOR and ZLIB_VER_REVISION in zlib.h,
          531  +  for use in win32/zlib1.rc [Polushin, Rowe, Truta]
          532  +- Add a document that explains the new text detection scheme to
          533  +  doc/txtvsbin.txt [Truta]
          534  +- Add rfc1950.txt, rfc1951.txt and rfc1952.txt to doc/ [Truta]
          535  +- Move algorithm.txt into doc/ [Truta]
          536  +- Synchronize FAQ with website
          537  +- Fix compressBound(), was low for some pathological cases [Fearnley]
          538  +- Take into account wrapper variations in deflateBound()
          539  +- Set examples/zpipe.c input and output to binary mode for Windows
          540  +- Update examples/zlib_how.html with new zpipe.c (also web site)
          541  +- Fix some warnings in examples/gzlog.c and examples/zran.c (it seems
          542  +  that gcc became pickier in 4.0)
          543  +- Add zlib.map for Linux: "All symbols from zlib-1.1.4 remain
          544  +  un-versioned, the patch adds versioning only for symbols introduced in
          545  +  zlib-1.2.0 or later.  It also declares as local those symbols which are
          546  +  not designed to be exported." [Levin]
          547  +- Update Z_PREFIX list in zconf.in.h, add --zprefix option to configure
          548  +- Do not initialize global static by default in trees.c, add a response
          549  +  NO_INIT_GLOBAL_POINTERS to initialize them if needed [Marquess]
          550  +- Don't use strerror() in gzio.c under WinCE [Yakimov]
          551  +- Don't use errno.h in zutil.h under WinCE [Yakimov]
          552  +- Move arguments for AR to its usage to allow replacing ar [Marot]
          553  +- Add HAVE_VISIBILITY_PRAGMA in zconf.in.h for Mozilla [Randers-Pehrson]
          554  +- Improve inflateInit() and inflateInit2() documentation
          555  +- Fix structure size comment in inflate.h
          556  +- Change configure help option from --h* to --help [Santos]
          557  +
          558  +Changes in 1.2.3 (18 July 2005)
          559  +- Apply security vulnerability fixes to contrib/infback9 as well
          560  +- Clean up some text files (carriage returns, trailing space)
          561  +- Update testzlib, vstudio, masmx64, and masmx86 in contrib [Vollant]
          562  +
          563  +Changes in 1.2.2.4 (11 July 2005)
          564  +- Add inflatePrime() function for starting inflation at bit boundary
          565  +- Avoid some Visual C warnings in deflate.c
          566  +- Avoid more silly Visual C warnings in inflate.c and inftrees.c for 64-bit
          567  +  compile
          568  +- Fix some spelling errors in comments [Betts]
          569  +- Correct inflateInit2() error return documentation in zlib.h
          570  +- Add zran.c example of compressed data random access to examples
          571  +  directory, shows use of inflatePrime()
          572  +- Fix cast for assignments to strm->state in inflate.c and infback.c
          573  +- Fix zlibCompileFlags() in zutil.c to use 1L for long shifts [Oberhumer]
          574  +- Move declarations of gf2 functions to right place in crc32.c [Oberhumer]
          575  +- Add cast in trees.c t avoid a warning [Oberhumer]
          576  +- Avoid some warnings in fitblk.c, gun.c, gzjoin.c in examples [Oberhumer]
          577  +- Update make_vms.com [Zinser]
          578  +- Initialize state->write in inflateReset() since copied in inflate_fast()
          579  +- Be more strict on incomplete code sets in inflate_table() and increase
          580  +  ENOUGH and MAXD -- this repairs a possible security vulnerability for
          581  +  invalid inflate input.  Thanks to Tavis Ormandy and Markus Oberhumer for
          582  +  discovering the vulnerability and providing test cases.
          583  +- Add ia64 support to configure for HP-UX [Smith]
          584  +- Add error return to gzread() for format or i/o error [Levin]
          585  +- Use malloc.h for OS/2 [Necasek]
          586  +
          587  +Changes in 1.2.2.3 (27 May 2005)
          588  +- Replace 1U constants in inflate.c and inftrees.c for 64-bit compile
          589  +- Typecast fread() return values in gzio.c [Vollant]
          590  +- Remove trailing space in minigzip.c outmode (VC++ can't deal with it)
          591  +- Fix crc check bug in gzread() after gzungetc() [Heiner]
          592  +- Add the deflateTune() function to adjust internal compression parameters
          593  +- Add a fast gzip decompressor, gun.c, to examples (use of inflateBack)
          594  +- Remove an incorrect assertion in examples/zpipe.c
          595  +- Add C++ wrapper in infback9.h [Donais]
          596  +- Fix bug in inflateCopy() when decoding fixed codes
          597  +- Note in zlib.h how much deflateSetDictionary() actually uses
          598  +- Remove USE_DICT_HEAD in deflate.c (would mess up inflate if used)
          599  +- Add _WIN32_WCE to define WIN32 in zconf.in.h [Spencer]
          600  +- Don't include stderr.h or errno.h for _WIN32_WCE in zutil.h [Spencer]
          601  +- Add gzdirect() function to indicate transparent reads
          602  +- Update contrib/minizip [Vollant]
          603  +- Fix compilation of deflate.c when both ASMV and FASTEST [Oberhumer]
          604  +- Add casts in crc32.c to avoid warnings [Oberhumer]
          605  +- Add contrib/masmx64 [Vollant]
          606  +- Update contrib/asm586, asm686, masmx86, testzlib, vstudio [Vollant]
          607  +
          608  +Changes in 1.2.2.2 (30 December 2004)
          609  +- Replace structure assignments in deflate.c and inflate.c with zmemcpy to
          610  +  avoid implicit memcpy calls (portability for no-library compilation)
          611  +- Increase sprintf() buffer size in gzdopen() to allow for large numbers
          612  +- Add INFLATE_STRICT to check distances against zlib header
          613  +- Improve WinCE errno handling and comments [Chang]
          614  +- Remove comment about no gzip header processing in FAQ
          615  +- Add Z_FIXED strategy option to deflateInit2() to force fixed trees
          616  +- Add updated make_vms.com [Coghlan], update README
          617  +- Create a new "examples" directory, move gzappend.c there, add zpipe.c,
          618  +  fitblk.c, gzlog.[ch], gzjoin.c, and zlib_how.html.
          619  +- Add FAQ entry and comments in deflate.c on uninitialized memory access
          620  +- Add Solaris 9 make options in configure [Gilbert]
          621  +- Allow strerror() usage in gzio.c for STDC
          622  +- Fix DecompressBuf in contrib/delphi/ZLib.pas [ManChesTer]
          623  +- Update contrib/masmx86/inffas32.asm and gvmat32.asm [Vollant]
          624  +- Use z_off_t for adler32_combine() and crc32_combine() lengths
          625  +- Make adler32() much faster for small len
          626  +- Use OS_CODE in deflate() default gzip header
          627  +
          628  +Changes in 1.2.2.1 (31 October 2004)
          629  +- Allow inflateSetDictionary() call for raw inflate
          630  +- Fix inflate header crc check bug for file names and comments
          631  +- Add deflateSetHeader() and gz_header structure for custom gzip headers
          632  +- Add inflateGetheader() to retrieve gzip headers
          633  +- Add crc32_combine() and adler32_combine() functions
          634  +- Add alloc_func, free_func, in_func, out_func to Z_PREFIX list
          635  +- Use zstreamp consistently in zlib.h (inflate_back functions)
          636  +- Remove GUNZIP condition from definition of inflate_mode in inflate.h
          637  +  and in contrib/inflate86/inffast.S [Truta, Anderson]
          638  +- Add support for AMD64 in contrib/inflate86/inffas86.c [Anderson]
          639  +- Update projects/README.projects and projects/visualc6 [Truta]
          640  +- Update win32/DLL_FAQ.txt [Truta]
          641  +- Avoid warning under NO_GZCOMPRESS in gzio.c; fix typo [Truta]
          642  +- Deprecate Z_ASCII; use Z_TEXT instead [Truta]
          643  +- Use a new algorithm for setting strm->data_type in trees.c [Truta]
          644  +- Do not define an exit() prototype in zutil.c unless DEBUG defined
          645  +- Remove prototype of exit() from zutil.c, example.c, minigzip.c [Truta]
          646  +- Add comment in zlib.h for Z_NO_FLUSH parameter to deflate()
          647  +- Fix Darwin build version identification [Peterson]
          648  +
          649  +Changes in 1.2.2 (3 October 2004)
          650  +- Update zlib.h comments on gzip in-memory processing
          651  +- Set adler to 1 in inflateReset() to support Java test suite [Walles]
          652  +- Add contrib/dotzlib [Ravn]
          653  +- Update win32/DLL_FAQ.txt [Truta]
          654  +- Update contrib/minizip [Vollant]
          655  +- Move contrib/visual-basic.txt to old/ [Truta]
          656  +- Fix assembler builds in projects/visualc6/ [Truta]
          657  +
          658  +Changes in 1.2.1.2 (9 September 2004)
          659  +- Update INDEX file
          660  +- Fix trees.c to update strm->data_type (no one ever noticed!)
          661  +- Fix bug in error case in inflate.c, infback.c, and infback9.c [Brown]
          662  +- Add "volatile" to crc table flag declaration (for DYNAMIC_CRC_TABLE)
          663  +- Add limited multitasking protection to DYNAMIC_CRC_TABLE
          664  +- Add NO_vsnprintf for VMS in zutil.h [Mozilla]
          665  +- Don't declare strerror() under VMS [Mozilla]
          666  +- Add comment to DYNAMIC_CRC_TABLE to use get_crc_table() to initialize
          667  +- Update contrib/ada [Anisimkov]
          668  +- Update contrib/minizip [Vollant]
          669  +- Fix configure to not hardcode directories for Darwin [Peterson]
          670  +- Fix gzio.c to not return error on empty files [Brown]
          671  +- Fix indentation; update version in contrib/delphi/ZLib.pas and
          672  +  contrib/pascal/zlibpas.pas [Truta]
          673  +- Update mkasm.bat in contrib/masmx86 [Truta]
          674  +- Update contrib/untgz [Truta]
          675  +- Add projects/README.projects [Truta]
          676  +- Add project for MS Visual C++ 6.0 in projects/visualc6 [Cadieux, Truta]
          677  +- Update win32/DLL_FAQ.txt [Truta]
          678  +- Update list of Z_PREFIX symbols in zconf.h [Randers-Pehrson, Truta]
          679  +- Remove an unnecessary assignment to curr in inftrees.c [Truta]
          680  +- Add OS/2 to exe builds in configure [Poltorak]
          681  +- Remove err dummy parameter in zlib.h [Kientzle]
          682  +
          683  +Changes in 1.2.1.1 (9 January 2004)
          684  +- Update email address in README
          685  +- Several FAQ updates
          686  +- Fix a big fat bug in inftrees.c that prevented decoding valid
          687  +  dynamic blocks with only literals and no distance codes --
          688  +  Thanks to "Hot Emu" for the bug report and sample file
          689  +- Add a note to puff.c on no distance codes case.
          690  +
          691  +Changes in 1.2.1 (17 November 2003)
          692  +- Remove a tab in contrib/gzappend/gzappend.c
          693  +- Update some interfaces in contrib for new zlib functions
          694  +- Update zlib version number in some contrib entries
          695  +- Add Windows CE definition for ptrdiff_t in zutil.h [Mai, Truta]
          696  +- Support shared libraries on Hurd and KFreeBSD [Brown]
          697  +- Fix error in NO_DIVIDE option of adler32.c
          698  +
          699  +Changes in 1.2.0.8 (4 November 2003)
          700  +- Update version in contrib/delphi/ZLib.pas and contrib/pascal/zlibpas.pas
          701  +- Add experimental NO_DIVIDE #define in adler32.c
          702  +    - Possibly faster on some processors (let me know if it is)
          703  +- Correct Z_BLOCK to not return on first inflate call if no wrap
          704  +- Fix strm->data_type on inflate() return to correctly indicate EOB
          705  +- Add deflatePrime() function for appending in the middle of a byte
          706  +- Add contrib/gzappend for an example of appending to a stream
          707  +- Update win32/DLL_FAQ.txt [Truta]
          708  +- Delete Turbo C comment in README [Truta]
          709  +- Improve some indentation in zconf.h [Truta]
          710  +- Fix infinite loop on bad input in configure script [Church]
          711  +- Fix gzeof() for concatenated gzip files [Johnson]
          712  +- Add example to contrib/visual-basic.txt [Michael B.]
          713  +- Add -p to mkdir's in Makefile.in [vda]
          714  +- Fix configure to properly detect presence or lack of printf functions
          715  +- Add AS400 support [Monnerat]
          716  +- Add a little Cygwin support [Wilson]
          717  +
          718  +Changes in 1.2.0.7 (21 September 2003)
          719  +- Correct some debug formats in contrib/infback9
          720  +- Cast a type in a debug statement in trees.c
          721  +- Change search and replace delimiter in configure from % to # [Beebe]
          722  +- Update contrib/untgz to 0.2 with various fixes [Truta]
          723  +- Add build support for Amiga [Nikl]
          724  +- Remove some directories in old that have been updated to 1.2
          725  +- Add dylib building for Mac OS X in configure and Makefile.in
          726  +- Remove old distribution stuff from Makefile
          727  +- Update README to point to DLL_FAQ.txt, and add comment on Mac OS X
          728  +- Update links in README
          729  +
          730  +Changes in 1.2.0.6 (13 September 2003)
          731  +- Minor FAQ updates
          732  +- Update contrib/minizip to 1.00 [Vollant]
          733  +- Remove test of gz functions in example.c when GZ_COMPRESS defined [Truta]
          734  +- Update POSTINC comment for 68060 [Nikl]
          735  +- Add contrib/infback9 with deflate64 decoding (unsupported)
          736  +- For MVS define NO_vsnprintf and undefine FAR [van Burik]
          737  +- Add pragma for fdopen on MVS [van Burik]
          738  +
          739  +Changes in 1.2.0.5 (8 September 2003)
          740  +- Add OF to inflateBackEnd() declaration in zlib.h
          741  +- Remember start when using gzdopen in the middle of a file
          742  +- Use internal off_t counters in gz* functions to properly handle seeks
          743  +- Perform more rigorous check for distance-too-far in inffast.c
          744  +- Add Z_BLOCK flush option to return from inflate at block boundary
          745  +- Set strm->data_type on return from inflate
          746  +    - Indicate bits unused, if at block boundary, and if in last block
          747  +- Replace size_t with ptrdiff_t in crc32.c, and check for correct size
          748  +- Add condition so old NO_DEFLATE define still works for compatibility
          749  +- FAQ update regarding the Windows DLL [Truta]
          750  +- INDEX update: add qnx entry, remove aix entry [Truta]
          751  +- Install zlib.3 into mandir [Wilson]
          752  +- Move contrib/zlib_dll_FAQ.txt to win32/DLL_FAQ.txt; update [Truta]
          753  +- Adapt the zlib interface to the new DLL convention guidelines [Truta]
          754  +- Introduce ZLIB_WINAPI macro to allow the export of functions using
          755  +  the WINAPI calling convention, for Visual Basic [Vollant, Truta]
          756  +- Update msdos and win32 scripts and makefiles [Truta]
          757  +- Export symbols by name, not by ordinal, in win32/zlib.def [Truta]
          758  +- Add contrib/ada [Anisimkov]
          759  +- Move asm files from contrib/vstudio/vc70_32 to contrib/asm386 [Truta]
          760  +- Rename contrib/asm386 to contrib/masmx86 [Truta, Vollant]
          761  +- Add contrib/masm686 [Truta]
          762  +- Fix offsets in contrib/inflate86 and contrib/masmx86/inffas32.asm
          763  +  [Truta, Vollant]
          764  +- Update contrib/delphi; rename to contrib/pascal; add example [Truta]
          765  +- Remove contrib/delphi2; add a new contrib/delphi [Truta]
          766  +- Avoid inclusion of the nonstandard <memory.h> in contrib/iostream,
          767  +  and fix some method prototypes [Truta]
          768  +- Fix the ZCR_SEED2 constant to avoid warnings in contrib/minizip
          769  +  [Truta]
          770  +- Avoid the use of backslash (\) in contrib/minizip [Vollant]
          771  +- Fix file time handling in contrib/untgz; update makefiles [Truta]
          772  +- Update contrib/vstudio/vc70_32 to comply with the new DLL guidelines
          773  +  [Vollant]
          774  +- Remove contrib/vstudio/vc15_16 [Vollant]
          775  +- Rename contrib/vstudio/vc70_32 to contrib/vstudio/vc7 [Truta]
          776  +- Update README.contrib [Truta]
          777  +- Invert the assignment order of match_head and s->prev[...] in
          778  +  INSERT_STRING [Truta]
          779  +- Compare TOO_FAR with 32767 instead of 32768, to avoid 16-bit warnings
          780  +  [Truta]
          781  +- Compare function pointers with 0, not with NULL or Z_NULL [Truta]
          782  +- Fix prototype of syncsearch in inflate.c [Truta]
          783  +- Introduce ASMINF macro to be enabled when using an ASM implementation
          784  +  of inflate_fast [Truta]
          785  +- Change NO_DEFLATE to NO_GZCOMPRESS [Truta]
          786  +- Modify test_gzio in example.c to take a single file name as a
          787  +  parameter [Truta]
          788  +- Exit the example.c program if gzopen fails [Truta]
          789  +- Add type casts around strlen in example.c [Truta]
          790  +- Remove casting to sizeof in minigzip.c; give a proper type
          791  +  to the variable compared with SUFFIX_LEN [Truta]
          792  +- Update definitions of STDC and STDC99 in zconf.h [Truta]
          793  +- Synchronize zconf.h with the new Windows DLL interface [Truta]
          794  +- Use SYS16BIT instead of __32BIT__ to distinguish between
          795  +  16- and 32-bit platforms [Truta]
          796  +- Use far memory allocators in small 16-bit memory models for
          797  +  Turbo C [Truta]
          798  +- Add info about the use of ASMV, ASMINF and ZLIB_WINAPI in
          799  +  zlibCompileFlags [Truta]
          800  +- Cygwin has vsnprintf [Wilson]
          801  +- In Windows16, OS_CODE is 0, as in MSDOS [Truta]
          802  +- In Cygwin, OS_CODE is 3 (Unix), not 11 (Windows32) [Wilson]
          803  +
          804  +Changes in 1.2.0.4 (10 August 2003)
          805  +- Minor FAQ updates
          806  +- Be more strict when checking inflateInit2's windowBits parameter
          807  +- Change NO_GUNZIP compile option to NO_GZIP to cover deflate as well
          808  +- Add gzip wrapper option to deflateInit2 using windowBits
          809  +- Add updated QNX rule in configure and qnx directory [Bonnefoy]
          810  +- Make inflate distance-too-far checks more rigorous
          811  +- Clean up FAR usage in inflate
          812  +- Add casting to sizeof() in gzio.c and minigzip.c
          813  +
          814  +Changes in 1.2.0.3 (19 July 2003)
          815  +- Fix silly error in gzungetc() implementation [Vollant]
          816  +- Update contrib/minizip and contrib/vstudio [Vollant]
          817  +- Fix printf format in example.c
          818  +- Correct cdecl support in zconf.in.h [Anisimkov]
          819  +- Minor FAQ updates
          820  +
          821  +Changes in 1.2.0.2 (13 July 2003)
          822  +- Add ZLIB_VERNUM in zlib.h for numerical preprocessor comparisons
          823  +- Attempt to avoid warnings in crc32.c for pointer-int conversion
          824  +- Add AIX to configure, remove aix directory [Bakker]
          825  +- Add some casts to minigzip.c
          826  +- Improve checking after insecure sprintf() or vsprintf() calls
          827  +- Remove #elif's from crc32.c
          828  +- Change leave label to inf_leave in inflate.c and infback.c to avoid
          829  +  library conflicts
          830  +- Remove inflate gzip decoding by default--only enable gzip decoding by
          831  +  special request for stricter backward compatibility
          832  +- Add zlibCompileFlags() function to return compilation information
          833  +- More typecasting in deflate.c to avoid warnings
          834  +- Remove leading underscore from _Capital #defines [Truta]
          835  +- Fix configure to link shared library when testing
          836  +- Add some Windows CE target adjustments [Mai]
          837  +- Remove #define ZLIB_DLL in zconf.h [Vollant]
          838  +- Add zlib.3 [Rodgers]
          839  +- Update RFC URL in deflate.c and algorithm.txt [Mai]
          840  +- Add zlib_dll_FAQ.txt to contrib [Truta]
          841  +- Add UL to some constants [Truta]
          842  +- Update minizip and vstudio [Vollant]
          843  +- Remove vestigial NEED_DUMMY_RETURN from zconf.in.h
          844  +- Expand use of NO_DUMMY_DECL to avoid all dummy structures
          845  +- Added iostream3 to contrib [Schwardt]
          846  +- Replace rewind() with fseek() for WinCE [Truta]
          847  +- Improve setting of zlib format compression level flags
          848  +    - Report 0 for huffman and rle strategies and for level == 0 or 1
          849  +    - Report 2 only for level == 6
          850  +- Only deal with 64K limit when necessary at compile time [Truta]
          851  +- Allow TOO_FAR check to be turned off at compile time [Truta]
          852  +- Add gzclearerr() function [Souza]
          853  +- Add gzungetc() function
          854  +
          855  +Changes in 1.2.0.1 (17 March 2003)
          856  +- Add Z_RLE strategy for run-length encoding [Truta]
          857  +    - When Z_RLE requested, restrict matches to distance one
          858  +    - Update zlib.h, minigzip.c, gzopen(), gzdopen() for Z_RLE
          859  +- Correct FASTEST compilation to allow level == 0
          860  +- Clean up what gets compiled for FASTEST
          861  +- Incorporate changes to zconf.in.h [Vollant]
          862  +    - Refine detection of Turbo C need for dummy returns
          863  +    - Refine ZLIB_DLL compilation
          864  +    - Include additional header file on VMS for off_t typedef
          865  +- Try to use _vsnprintf where it supplants vsprintf [Vollant]
          866  +- Add some casts in inffast.c
          867  +- Enchance comments in zlib.h on what happens if gzprintf() tries to
          868  +  write more than 4095 bytes before compression
          869  +- Remove unused state from inflateBackEnd()
          870  +- Remove exit(0) from minigzip.c, example.c
          871  +- Get rid of all those darn tabs
          872  +- Add "check" target to Makefile.in that does the same thing as "test"
          873  +- Add "mostlyclean" and "maintainer-clean" targets to Makefile.in
          874  +- Update contrib/inflate86 [Anderson]
          875  +- Update contrib/testzlib, contrib/vstudio, contrib/minizip [Vollant]
          876  +- Add msdos and win32 directories with makefiles [Truta]
          877  +- More additions and improvements to the FAQ
          878  +
          879  +Changes in 1.2.0 (9 March 2003)
          880  +- New and improved inflate code
          881  +    - About 20% faster
          882  +    - Does not allocate 32K window unless and until needed
          883  +    - Automatically detects and decompresses gzip streams
          884  +    - Raw inflate no longer needs an extra dummy byte at end
          885  +    - Added inflateBack functions using a callback interface--even faster
          886  +      than inflate, useful for file utilities (gzip, zip)
          887  +    - Added inflateCopy() function to record state for random access on
          888  +      externally generated deflate streams (e.g. in gzip files)
          889  +    - More readable code (I hope)
          890  +- New and improved crc32()
          891  +    - About 50% faster, thanks to suggestions from Rodney Brown
          892  +- Add deflateBound() and compressBound() functions
          893  +- Fix memory leak in deflateInit2()
          894  +- Permit setting dictionary for raw deflate (for parallel deflate)
          895  +- Fix const declaration for gzwrite()
          896  +- Check for some malloc() failures in gzio.c
          897  +- Fix bug in gzopen() on single-byte file 0x1f
          898  +- Fix bug in gzread() on concatenated file with 0x1f at end of buffer
          899  +  and next buffer doesn't start with 0x8b
          900  +- Fix uncompress() to return Z_DATA_ERROR on truncated input
          901  +- Free memory at end of example.c
          902  +- Remove MAX #define in trees.c (conflicted with some libraries)
          903  +- Fix static const's in deflate.c, gzio.c, and zutil.[ch]
          904  +- Declare malloc() and free() in gzio.c if STDC not defined
          905  +- Use malloc() instead of calloc() in zutil.c if int big enough
          906  +- Define STDC for AIX
          907  +- Add aix/ with approach for compiling shared library on AIX
          908  +- Add HP-UX support for shared libraries in configure
          909  +- Add OpenUNIX support for shared libraries in configure
          910  +- Use $cc instead of gcc to build shared library
          911  +- Make prefix directory if needed when installing
          912  +- Correct Macintosh avoidance of typedef Byte in zconf.h
          913  +- Correct Turbo C memory allocation when under Linux
          914  +- Use libz.a instead of -lz in Makefile (assure use of compiled library)
          915  +- Update configure to check for snprintf or vsnprintf functions and their
          916  +  return value, warn during make if using an insecure function
          917  +- Fix configure problem with compile-time knowledge of HAVE_UNISTD_H that
          918  +  is lost when library is used--resolution is to build new zconf.h
          919  +- Documentation improvements (in zlib.h):
          920  +    - Document raw deflate and inflate
          921  +    - Update RFCs URL
          922  +    - Point out that zlib and gzip formats are different
          923  +    - Note that Z_BUF_ERROR is not fatal
          924  +    - Document string limit for gzprintf() and possible buffer overflow
          925  +    - Note requirement on avail_out when flushing
          926  +    - Note permitted values of flush parameter of inflate()
          927  +- Add some FAQs (and even answers) to the FAQ
          928  +- Add contrib/inflate86/ for x86 faster inflate
          929  +- Add contrib/blast/ for PKWare Data Compression Library decompression
          930  +- Add contrib/puff/ simple inflate for deflate format description
          931  +
          932  +Changes in 1.1.4 (11 March 2002)
          933  +- ZFREE was repeated on same allocation on some error conditions.
          934  +  This creates a security problem described in
          935  +  http://www.zlib.org/advisory-2002-03-11.txt
          936  +- Returned incorrect error (Z_MEM_ERROR) on some invalid data
          937  +- Avoid accesses before window for invalid distances with inflate window
          938  +  less than 32K.
          939  +- force windowBits > 8 to avoid a bug in the encoder for a window size
          940  +  of 256 bytes. (A complete fix will be available in 1.1.5).
          941  +
          942  +Changes in 1.1.3 (9 July 1998)
          943  +- fix "an inflate input buffer bug that shows up on rare but persistent
          944  +  occasions" (Mark)
          945  +- fix gzread and gztell for concatenated .gz files (Didier Le Botlan)
          946  +- fix gzseek(..., SEEK_SET) in write mode
          947  +- fix crc check after a gzeek (Frank Faubert)
          948  +- fix miniunzip when the last entry in a zip file is itself a zip file
          949  +  (J Lillge)
          950  +- add contrib/asm586 and contrib/asm686 (Brian Raiter)
          951  +  See http://www.muppetlabs.com/~breadbox/software/assembly.html
          952  +- add support for Delphi 3 in contrib/delphi (Bob Dellaca)
          953  +- add support for C++Builder 3 and Delphi 3 in contrib/delphi2 (Davide Moretti)
          954  +- do not exit prematurely in untgz if 0 at start of block (Magnus Holmgren)
          955  +- use macro EXTERN instead of extern to support DLL for BeOS (Sander Stoks)
          956  +- added a FAQ file
          957  +
          958  +- Support gzdopen on Mac with Metrowerks (Jason Linhart)
          959  +- Do not redefine Byte on Mac (Brad Pettit & Jason Linhart)
          960  +- define SEEK_END too if SEEK_SET is not defined (Albert Chin-A-Young)
          961  +- avoid some warnings with Borland C (Tom Tanner)
          962  +- fix a problem in contrib/minizip/zip.c for 16-bit MSDOS (Gilles Vollant)
          963  +- emulate utime() for WIN32 in contrib/untgz  (Gilles Vollant)
          964  +- allow several arguments to configure (Tim Mooney, Frodo Looijaard)
          965  +- use libdir and includedir in Makefile.in (Tim Mooney)
          966  +- support shared libraries on OSF1 V4 (Tim Mooney)
          967  +- remove so_locations in "make clean"  (Tim Mooney)
          968  +- fix maketree.c compilation error (Glenn, Mark)
          969  +- Python interface to zlib now in Python 1.5 (Jeremy Hylton)
          970  +- new Makefile.riscos (Rich Walker)
          971  +- initialize static descriptors in trees.c for embedded targets (Nick Smith)
          972  +- use "foo-gz" in example.c for RISCOS and VMS (Nick Smith)
          973  +- add the OS/2 files in Makefile.in too (Andrew Zabolotny)
          974  +- fix fdopen and halloc macros for Microsoft C 6.0 (Tom Lane)
          975  +- fix maketree.c to allow clean compilation of inffixed.h (Mark)
          976  +- fix parameter check in deflateCopy (Gunther Nikl)
          977  +- cleanup trees.c, use compressed_len only in debug mode (Christian Spieler)
          978  +- Many portability patches by Christian Spieler:
          979  +  . zutil.c, zutil.h: added "const" for zmem*
          980  +  . Make_vms.com: fixed some typos
          981  +  . Make_vms.com: msdos/Makefile.*: removed zutil.h from some dependency lists
          982  +  . msdos/Makefile.msc: remove "default rtl link library" info from obj files
          983  +  . msdos/Makefile.*: use model-dependent name for the built zlib library
          984  +  . msdos/Makefile.emx, nt/Makefile.emx, nt/Makefile.gcc:
          985  +     new makefiles, for emx (DOS/OS2), emx&rsxnt and mingw32 (Windows 9x / NT)
          986  +- use define instead of typedef for Bytef also for MSC small/medium (Tom Lane)
          987  +- replace __far with _far for better portability (Christian Spieler, Tom Lane)
          988  +- fix test for errno.h in configure (Tim Newsham)
          989  +
          990  +Changes in 1.1.2 (19 March 98)
          991  +- added contrib/minzip, mini zip and unzip based on zlib (Gilles Vollant)
          992  +  See http://www.winimage.com/zLibDll/unzip.html
          993  +- preinitialize the inflate tables for fixed codes, to make the code
          994  +  completely thread safe (Mark)
          995  +- some simplifications and slight speed-up to the inflate code (Mark)
          996  +- fix gzeof on non-compressed files (Allan Schrum)
          997  +- add -std1 option in configure for OSF1 to fix gzprintf (Martin Mokrejs)
          998  +- use default value of 4K for Z_BUFSIZE for 16-bit MSDOS (Tim Wegner + Glenn)
          999  +- added os2/Makefile.def and os2/zlib.def (Andrew Zabolotny)
         1000  +- add shared lib support for UNIX_SV4.2MP (MATSUURA Takanori)
         1001  +- do not wrap extern "C" around system includes (Tom Lane)
         1002  +- mention zlib binding for TCL in README (Andreas Kupries)
         1003  +- added amiga/Makefile.pup for Amiga powerUP SAS/C PPC (Andreas Kleinert)
         1004  +- allow "make install prefix=..." even after configure (Glenn Randers-Pehrson)
         1005  +- allow "configure --prefix $HOME" (Tim Mooney)
         1006  +- remove warnings in example.c and gzio.c (Glenn Randers-Pehrson)
         1007  +- move Makefile.sas to amiga/Makefile.sas
         1008  +
         1009  +Changes in 1.1.1 (27 Feb 98)
         1010  +- fix macros _tr_tally_* in deflate.h for debug mode  (Glenn Randers-Pehrson)
         1011  +- remove block truncation heuristic which had very marginal effect for zlib
         1012  +  (smaller lit_bufsize than in gzip 1.2.4) and degraded a little the
         1013  +  compression ratio on some files. This also allows inlining _tr_tally for
         1014  +  matches in deflate_slow.
         1015  +- added msdos/Makefile.w32 for WIN32 Microsoft Visual C++ (Bob Frazier)
         1016  +
         1017  +Changes in 1.1.0 (24 Feb 98)
         1018  +- do not return STREAM_END prematurely in inflate (John Bowler)
         1019  +- revert to the zlib 1.0.8 inflate to avoid the gcc 2.8.0 bug (Jeremy Buhler)
         1020  +- compile with -DFASTEST to get compression code optimized for speed only
         1021  +- in minigzip, try mmap'ing the input file first (Miguel Albrecht)
         1022  +- increase size of I/O buffers in minigzip.c and gzio.c (not a big gain
         1023  +  on Sun but significant on HP)
         1024  +
         1025  +- add a pointer to experimental unzip library in README (Gilles Vollant)
         1026  +- initialize variable gcc in configure (Chris Herborth)
         1027  +
         1028  +Changes in 1.0.9 (17 Feb 1998)
         1029  +- added gzputs and gzgets functions
         1030  +- do not clear eof flag in gzseek (Mark Diekhans)
         1031  +- fix gzseek for files in transparent mode (Mark Diekhans)
         1032  +- do not assume that vsprintf returns the number of bytes written (Jens Krinke)
         1033  +- replace EXPORT with ZEXPORT to avoid conflict with other programs
         1034  +- added compress2 in zconf.h, zlib.def, zlib.dnt
         1035  +- new asm code from Gilles Vollant in contrib/asm386
         1036  +- simplify the inflate code (Mark):
         1037  + . Replace ZALLOC's in huft_build() with single ZALLOC in inflate_blocks_new()
         1038  + . ZALLOC the length list in inflate_trees_fixed() instead of using stack
         1039  + . ZALLOC the value area for huft_build() instead of using stack
         1040  + . Simplify Z_FINISH check in inflate()
         1041  +
         1042  +- Avoid gcc 2.8.0 comparison bug a little differently than zlib 1.0.8
         1043  +- in inftrees.c, avoid cc -O bug on HP (Farshid Elahi)
         1044  +- in zconf.h move the ZLIB_DLL stuff earlier to avoid problems with
         1045  +  the declaration of FAR (Gilles VOllant)
         1046  +- install libz.so* with mode 755 (executable) instead of 644 (Marc Lehmann)
         1047  +- read_buf buf parameter of type Bytef* instead of charf*
         1048  +- zmemcpy parameters are of type Bytef*, not charf* (Joseph Strout)
         1049  +- do not redeclare unlink in minigzip.c for WIN32 (John Bowler)
         1050  +- fix check for presence of directories in "make install" (Ian Willis)
         1051  +
         1052  +Changes in 1.0.8 (27 Jan 1998)
         1053  +- fixed offsets in contrib/asm386/gvmat32.asm (Gilles Vollant)
         1054  +- fix gzgetc and gzputc for big endian systems (Markus Oberhumer)
         1055  +- added compress2() to allow setting the compression level
         1056  +- include sys/types.h to get off_t on some systems (Marc Lehmann & QingLong)
         1057  +- use constant arrays for the static trees in trees.c instead of computing
         1058  +  them at run time (thanks to Ken Raeburn for this suggestion). To create
         1059  +  trees.h, compile with GEN_TREES_H and run "make test".
         1060  +- check return code of example in "make test" and display result
         1061  +- pass minigzip command line options to file_compress
         1062  +- simplifying code of inflateSync to avoid gcc 2.8 bug
         1063  +
         1064  +- support CC="gcc -Wall" in configure -s (QingLong)
         1065  +- avoid a flush caused by ftell in gzopen for write mode (Ken Raeburn)
         1066  +- fix test for shared library support to avoid compiler warnings
         1067  +- zlib.lib -> zlib.dll in msdos/zlib.rc (Gilles Vollant)
         1068  +- check for TARGET_OS_MAC in addition to MACOS (Brad Pettit)
         1069  +- do not use fdopen for Metrowerks on Mac (Brad Pettit))
         1070  +- add checks for gzputc and gzputc in example.c
         1071  +- avoid warnings in gzio.c and deflate.c (Andreas Kleinert)
         1072  +- use const for the CRC table (Ken Raeburn)
         1073  +- fixed "make uninstall" for shared libraries
         1074  +- use Tracev instead of Trace in infblock.c
         1075  +- in example.c use correct compressed length for test_sync
         1076  +- suppress +vnocompatwarnings in configure for HPUX (not always supported)
         1077  +
         1078  +Changes in 1.0.7 (20 Jan 1998)
         1079  +- fix gzseek which was broken in write mode
         1080  +- return error for gzseek to negative absolute position
         1081  +- fix configure for Linux (Chun-Chung Chen)
         1082  +- increase stack space for MSC (Tim Wegner)
         1083  +- get_crc_table and inflateSyncPoint are EXPORTed (Gilles Vollant)
         1084  +- define EXPORTVA for gzprintf (Gilles Vollant)
         1085  +- added man page zlib.3 (Rick Rodgers)
         1086  +- for contrib/untgz, fix makedir() and improve Makefile
         1087  +
         1088  +- check gzseek in write mode in example.c
         1089  +- allocate extra buffer for seeks only if gzseek is actually called
         1090  +- avoid signed/unsigned comparisons (Tim Wegner, Gilles Vollant)
         1091  +- add inflateSyncPoint in zconf.h
         1092  +- fix list of exported functions in nt/zlib.dnt and mdsos/zlib.def
         1093  +
         1094  +Changes in 1.0.6 (19 Jan 1998)
         1095  +- add functions gzprintf, gzputc, gzgetc, gztell, gzeof, gzseek, gzrewind and
         1096  +  gzsetparams (thanks to Roland Giersig and Kevin Ruland for some of this code)
         1097  +- Fix a deflate bug occurring only with compression level 0 (thanks to
         1098  +  Andy Buckler for finding this one).
         1099  +- In minigzip, pass transparently also the first byte for .Z files.
         1100  +- return Z_BUF_ERROR instead of Z_OK if output buffer full in uncompress()
         1101  +- check Z_FINISH in inflate (thanks to Marc Schluper)
         1102  +- Implement deflateCopy (thanks to Adam Costello)
         1103  +- make static libraries by default in configure, add --shared option.
         1104  +- move MSDOS or Windows specific files to directory msdos
         1105  +- suppress the notion of partial flush to simplify the interface
         1106  +  (but the symbol Z_PARTIAL_FLUSH is kept for compatibility with 1.0.4)
         1107  +- suppress history buffer provided by application to simplify the interface
         1108  +  (this feature was not implemented anyway in 1.0.4)
         1109  +- next_in and avail_in must be initialized before calling inflateInit or
         1110  +  inflateInit2
         1111  +- add EXPORT in all exported functions (for Windows DLL)
         1112  +- added Makefile.nt (thanks to Stephen Williams)
         1113  +- added the unsupported "contrib" directory:
         1114  +   contrib/asm386/ by Gilles Vollant <info@winimage.com>
         1115  +        386 asm code replacing longest_match().
         1116  +   contrib/iostream/ by Kevin Ruland <kevin@rodin.wustl.edu>
         1117  +        A C++ I/O streams interface to the zlib gz* functions
         1118  +   contrib/iostream2/  by Tyge Løvset <Tyge.Lovset@cmr.no>
         1119  +        Another C++ I/O streams interface
         1120  +   contrib/untgz/  by "Pedro A. Aranda Guti\irrez" <paag@tid.es>
         1121  +        A very simple tar.gz file extractor using zlib
         1122  +   contrib/visual-basic.txt by Carlos Rios <c_rios@sonda.cl>
         1123  +        How to use compress(), uncompress() and the gz* functions from VB.
         1124  +- pass params -f (filtered data), -h (huffman only), -1 to -9 (compression
         1125  +  level) in minigzip (thanks to Tom Lane)
         1126  +
         1127  +- use const for rommable constants in deflate
         1128  +- added test for gzseek and gztell in example.c
         1129  +- add undocumented function inflateSyncPoint() (hack for Paul Mackerras)
         1130  +- add undocumented function zError to convert error code to string
         1131  +  (for Tim Smithers)
         1132  +- Allow compilation of gzio with -DNO_DEFLATE to avoid the compression code.
         1133  +- Use default memcpy for Symantec MSDOS compiler.
         1134  +- Add EXPORT keyword for check_func (needed for Windows DLL)
         1135  +- add current directory to LD_LIBRARY_PATH for "make test"
         1136  +- create also a link for libz.so.1
         1137  +- added support for FUJITSU UXP/DS (thanks to Toshiaki Nomura)
         1138  +- use $(SHAREDLIB) instead of libz.so in Makefile.in (for HPUX)
         1139  +- added -soname for Linux in configure (Chun-Chung Chen,
         1140  +- assign numbers to the exported functions in zlib.def (for Windows DLL)
         1141  +- add advice in zlib.h for best usage of deflateSetDictionary
         1142  +- work around compiler bug on Atari (cast Z_NULL in call of s->checkfn)
         1143  +- allow compilation with ANSI keywords only enabled for TurboC in large model
         1144  +- avoid "versionString"[0] (Borland bug)
         1145  +- add NEED_DUMMY_RETURN for Borland
         1146  +- use variable z_verbose for tracing in debug mode (L. Peter Deutsch).
         1147  +- allow compilation with CC
         1148  +- defined STDC for OS/2 (David Charlap)
         1149  +- limit external names to 8 chars for MVS (Thomas Lund)
         1150  +- in minigzip.c, use static buffers only for 16-bit systems
         1151  +- fix suffix check for "minigzip -d foo.gz"
         1152  +- do not return an error for the 2nd of two consecutive gzflush() (Felix Lee)
         1153  +- use _fdopen instead of fdopen for MSC >= 6.0 (Thomas Fanslau)
         1154  +- added makelcc.bat for lcc-win32 (Tom St Denis)
         1155  +- in Makefile.dj2, use copy and del instead of install and rm (Frank Donahoe)
         1156  +- Avoid expanded $Id$. Use "rcs -kb" or "cvs admin -kb" to avoid Id expansion.
         1157  +- check for unistd.h in configure (for off_t)
         1158  +- remove useless check parameter in inflate_blocks_free
         1159  +- avoid useless assignment of s->check to itself in inflate_blocks_new
         1160  +- do not flush twice in gzclose (thanks to Ken Raeburn)
         1161  +- rename FOPEN as F_OPEN to avoid clash with /usr/include/sys/file.h
         1162  +- use NO_ERRNO_H instead of enumeration of operating systems with errno.h
         1163  +- work around buggy fclose on pipes for HP/UX
         1164  +- support zlib DLL with BORLAND C++ 5.0 (thanks to Glenn Randers-Pehrson)
         1165  +- fix configure if CC is already equal to gcc
         1166  +
         1167  +Changes in 1.0.5 (3 Jan 98)
         1168  +- Fix inflate to terminate gracefully when fed corrupted or invalid data
         1169  +- Use const for rommable constants in inflate
         1170  +- Eliminate memory leaks on error conditions in inflate
         1171  +- Removed some vestigial code in inflate
         1172  +- Update web address in README
         1173  +
         1174  +Changes in 1.0.4 (24 Jul 96)
         1175  +- In very rare conditions, deflate(s, Z_FINISH) could fail to produce an EOF
         1176  +  bit, so the decompressor could decompress all the correct data but went
         1177  +  on to attempt decompressing extra garbage data. This affected minigzip too.
         1178  +- zlibVersion and gzerror return const char* (needed for DLL)
         1179  +- port to RISCOS (no fdopen, no multiple dots, no unlink, no fileno)
         1180  +- use z_error only for DEBUG (avoid problem with DLLs)
         1181  +
         1182  +Changes in 1.0.3 (2 Jul 96)
         1183  +- use z_streamp instead of z_stream *, which is now a far pointer in MSDOS
         1184  +  small and medium models; this makes the library incompatible with previous
         1185  +  versions for these models. (No effect in large model or on other systems.)
         1186  +- return OK instead of BUF_ERROR if previous deflate call returned with
         1187  +  avail_out as zero but there is nothing to do
         1188  +- added memcmp for non STDC compilers
         1189  +- define NO_DUMMY_DECL for more Mac compilers (.h files merged incorrectly)
         1190  +- define __32BIT__ if __386__ or i386 is defined (pb. with Watcom and SCO)
         1191  +- better check for 16-bit mode MSC (avoids problem with Symantec)
         1192  +
         1193  +Changes in 1.0.2 (23 May 96)
         1194  +- added Windows DLL support
         1195  +- added a function zlibVersion (for the DLL support)
         1196  +- fixed declarations using Bytef in infutil.c (pb with MSDOS medium model)
         1197  +- Bytef is define's instead of typedef'd only for Borland C
         1198  +- avoid reading uninitialized memory in example.c
         1199  +- mention in README that the zlib format is now RFC1950
         1200  +- updated Makefile.dj2
         1201  +- added algorithm.doc
         1202  +
         1203  +Changes in 1.0.1 (20 May 96) [1.0 skipped to avoid confusion]
         1204  +- fix array overlay in deflate.c which sometimes caused bad compressed data
         1205  +- fix inflate bug with empty stored block
         1206  +- fix MSDOS medium model which was broken in 0.99
         1207  +- fix deflateParams() which could generated bad compressed data.
         1208  +- Bytef is define'd instead of typedef'ed (work around Borland bug)
         1209  +- added an INDEX file
         1210  +- new makefiles for DJGPP (Makefile.dj2), 32-bit Borland (Makefile.b32),
         1211  +  Watcom (Makefile.wat), Amiga SAS/C (Makefile.sas)
         1212  +- speed up adler32 for modern machines without auto-increment
         1213  +- added -ansi for IRIX in configure
         1214  +- static_init_done in trees.c is an int
         1215  +- define unlink as delete for VMS
         1216  +- fix configure for QNX
         1217  +- add configure branch for SCO and HPUX
         1218  +- avoid many warnings (unused variables, dead assignments, etc...)
         1219  +- no fdopen for BeOS
         1220  +- fix the Watcom fix for 32 bit mode (define FAR as empty)
         1221  +- removed redefinition of Byte for MKWERKS
         1222  +- work around an MWKERKS bug (incorrect merge of all .h files)
         1223  +
         1224  +Changes in 0.99 (27 Jan 96)
         1225  +- allow preset dictionary shared between compressor and decompressor
         1226  +- allow compression level 0 (no compression)
         1227  +- add deflateParams in zlib.h: allow dynamic change of compression level
         1228  +  and compression strategy.
         1229  +- test large buffers and deflateParams in example.c
         1230  +- add optional "configure" to build zlib as a shared library
         1231  +- suppress Makefile.qnx, use configure instead
         1232  +- fixed deflate for 64-bit systems (detected on Cray)
         1233  +- fixed inflate_blocks for 64-bit systems (detected on Alpha)
         1234  +- declare Z_DEFLATED in zlib.h (possible parameter for deflateInit2)
         1235  +- always return Z_BUF_ERROR when deflate() has nothing to do
         1236  +- deflateInit and inflateInit are now macros to allow version checking
         1237  +- prefix all global functions and types with z_ with -DZ_PREFIX
         1238  +- make falloc completely reentrant (inftrees.c)
         1239  +- fixed very unlikely race condition in ct_static_init
         1240  +- free in reverse order of allocation to help memory manager
         1241  +- use zlib-1.0/* instead of zlib/* inside the tar.gz
         1242  +- make zlib warning-free with "gcc -O3 -Wall -Wwrite-strings -Wpointer-arith
         1243  +  -Wconversion -Wstrict-prototypes -Wmissing-prototypes"
         1244  +- allow gzread on concatenated .gz files
         1245  +- deflateEnd now returns Z_DATA_ERROR if it was premature
         1246  +- deflate is finally (?) fully deterministic (no matches beyond end of input)
         1247  +- Document Z_SYNC_FLUSH
         1248  +- add uninstall in Makefile
         1249  +- Check for __cpluplus in zlib.h
         1250  +- Better test in ct_align for partial flush
         1251  +- avoid harmless warnings for Borland C++
         1252  +- initialize hash_head in deflate.c
         1253  +- avoid warning on fdopen (gzio.c) for HP cc -Aa
         1254  +- include stdlib.h for STDC compilers
         1255  +- include errno.h for Cray
         1256  +- ignore error if ranlib doesn't exist
         1257  +- call ranlib twice for NeXTSTEP
         1258  +- use exec_prefix instead of prefix for libz.a
         1259  +- renamed ct_* as _tr_* to avoid conflict with applications
         1260  +- clear z->msg in inflateInit2 before any error return
         1261  +- initialize opaque in example.c, gzio.c, deflate.c and inflate.c
         1262  +- fixed typo in zconf.h (_GNUC__ => __GNUC__)
         1263  +- check for WIN32 in zconf.h and zutil.c (avoid farmalloc in 32-bit mode)
         1264  +- fix typo in Make_vms.com (f$trnlnm -> f$getsyi)
         1265  +- in fcalloc, normalize pointer if size > 65520 bytes
         1266  +- don't use special fcalloc for 32 bit Borland C++
         1267  +- use STDC instead of __GO32__ to avoid redeclaring exit, calloc, etc...
         1268  +- use Z_BINARY instead of BINARY
         1269  +- document that gzclose after gzdopen will close the file
         1270  +- allow "a" as mode in gzopen.
         1271  +- fix error checking in gzread
         1272  +- allow skipping .gz extra-field on pipes
         1273  +- added reference to Perl interface in README
         1274  +- put the crc table in FAR data (I dislike more and more the medium model :)
         1275  +- added get_crc_table
         1276  +- added a dimension to all arrays (Borland C can't count).
         1277  +- workaround Borland C bug in declaration of inflate_codes_new & inflate_fast
         1278  +- guard against multiple inclusion of *.h (for precompiled header on Mac)
         1279  +- Watcom C pretends to be Microsoft C small model even in 32 bit mode.
         1280  +- don't use unsized arrays to avoid silly warnings by Visual C++:
         1281  +     warning C4746: 'inflate_mask' : unsized array treated as  '__far'
         1282  +     (what's wrong with far data in far model?).
         1283  +- define enum out of inflate_blocks_state to allow compilation with C++
         1284  +
         1285  +Changes in 0.95 (16 Aug 95)
         1286  +- fix MSDOS small and medium model (now easier to adapt to any compiler)
         1287  +- inlined send_bits
         1288  +- fix the final (:-) bug for deflate with flush (output was correct but
         1289  +  not completely flushed in rare occasions).
         1290  +- default window size is same for compression and decompression
         1291  +  (it's now sufficient to set MAX_WBITS in zconf.h).
         1292  +- voidp -> voidpf and voidnp -> voidp (for consistency with other
         1293  +  typedefs and because voidnp was not near in large model).
         1294  +
         1295  +Changes in 0.94 (13 Aug 95)
         1296  +- support MSDOS medium model
         1297  +- fix deflate with flush (could sometimes generate bad output)
         1298  +- fix deflateReset (zlib header was incorrectly suppressed)
         1299  +- added support for VMS
         1300  +- allow a compression level in gzopen()
         1301  +- gzflush now calls fflush
         1302  +- For deflate with flush, flush even if no more input is provided.
         1303  +- rename libgz.a as libz.a
         1304  +- avoid complex expression in infcodes.c triggering Turbo C bug
         1305  +- work around a problem with gcc on Alpha (in INSERT_STRING)
         1306  +- don't use inline functions (problem with some gcc versions)
         1307  +- allow renaming of Byte, uInt, etc... with #define.
         1308  +- avoid warning about (unused) pointer before start of array in deflate.c
         1309  +- avoid various warnings in gzio.c, example.c, infblock.c, adler32.c, zutil.c
         1310  +- avoid reserved word 'new' in trees.c
         1311  +
         1312  +Changes in 0.93 (25 June 95)
         1313  +- temporarily disable inline functions
         1314  +- make deflate deterministic
         1315  +- give enough lookahead for PARTIAL_FLUSH
         1316  +- Set binary mode for stdin/stdout in minigzip.c for OS/2
         1317  +- don't even use signed char in inflate (not portable enough)
         1318  +- fix inflate memory leak for segmented architectures
         1319  +
         1320  +Changes in 0.92 (3 May 95)
         1321  +- don't assume that char is signed (problem on SGI)
         1322  +- Clear bit buffer when starting a stored block
         1323  +- no memcpy on Pyramid
         1324  +- suppressed inftest.c
         1325  +- optimized fill_window, put longest_match inline for gcc
         1326  +- optimized inflate on stored blocks.
         1327  +- untabify all sources to simplify patches
         1328  +
         1329  +Changes in 0.91 (2 May 95)
         1330  +- Default MEM_LEVEL is 8 (not 9 for Unix) as documented in zlib.h
         1331  +- Document the memory requirements in zconf.h
         1332  +- added "make install"
         1333  +- fix sync search logic in inflateSync
         1334  +- deflate(Z_FULL_FLUSH) now works even if output buffer too short
         1335  +- after inflateSync, don't scare people with just "lo world"
         1336  +- added support for DJGPP
         1337  +
         1338  +Changes in 0.9 (1 May 95)
         1339  +- don't assume that zalloc clears the allocated memory (the TurboC bug
         1340  +  was Mark's bug after all :)
         1341  +- let again gzread copy uncompressed data unchanged (was working in 0.71)
         1342  +- deflate(Z_FULL_FLUSH), inflateReset and inflateSync are now fully implemented
         1343  +- added a test of inflateSync in example.c
         1344  +- moved MAX_WBITS to zconf.h because users might want to change that.
         1345  +- document explicitly that zalloc(64K) on MSDOS must return a normalized
         1346  +  pointer (zero offset)
         1347  +- added Makefiles for Microsoft C, Turbo C, Borland C++
         1348  +- faster crc32()
         1349  +
         1350  +Changes in 0.8 (29 April 95)
         1351  +- added fast inflate (inffast.c)
         1352  +- deflate(Z_FINISH) now returns Z_STREAM_END when done. Warning: this
         1353  +  is incompatible with previous versions of zlib which returned Z_OK.
         1354  +- work around a TurboC compiler bug (bad code for b << 0, see infutil.h)
         1355  +  (actually that was not a compiler bug, see 0.81 above)
         1356  +- gzread no longer reads one extra byte in certain cases
         1357  +- In gzio destroy(), don't reference a freed structure
         1358  +- avoid many warnings for MSDOS
         1359  +- avoid the ERROR symbol which is used by MS Windows
         1360  +
         1361  +Changes in 0.71 (14 April 95)
         1362  +- Fixed more MSDOS compilation problems :( There is still a bug with
         1363  +  TurboC large model.
         1364  +
         1365  +Changes in 0.7 (14 April 95)
         1366  +- Added full inflate support.
         1367  +- Simplified the crc32() interface. The pre- and post-conditioning
         1368  +  (one's complement) is now done inside crc32(). WARNING: this is
         1369  +  incompatible with previous versions; see zlib.h for the new usage.
         1370  +
         1371  +Changes in 0.61 (12 April 95)
         1372  +- workaround for a bug in TurboC. example and minigzip now work on MSDOS.
         1373  +
         1374  +Changes in 0.6 (11 April 95)
         1375  +- added minigzip.c
         1376  +- added gzdopen to reopen a file descriptor as gzFile
         1377  +- added transparent reading of non-gziped files in gzread.
         1378  +- fixed bug in gzread (don't read crc as data)
         1379  +- fixed bug in destroy (gzio.c) (don't return Z_STREAM_END for gzclose).
         1380  +- don't allocate big arrays in the stack (for MSDOS)
         1381  +- fix some MSDOS compilation problems
         1382  +
         1383  +Changes in 0.5:
         1384  +- do real compression in deflate.c. Z_PARTIAL_FLUSH is supported but
         1385  +  not yet Z_FULL_FLUSH.
         1386  +- support decompression but only in a single step (forced Z_FINISH)
         1387  +- added opaque object for zalloc and zfree.
         1388  +- added deflateReset and inflateReset
         1389  +- added a variable zlib_version for consistency checking.
         1390  +- renamed the 'filter' parameter of deflateInit2 as 'strategy'.
         1391  +  Added Z_FILTERED and Z_HUFFMAN_ONLY constants.
         1392  +
         1393  +Changes in 0.4:
         1394  +- avoid "zip" everywhere, use zlib instead of ziplib.
         1395  +- suppress Z_BLOCK_FLUSH, interpret Z_PARTIAL_FLUSH as block flush
         1396  +  if compression method == 8.
         1397  +- added adler32 and crc32
         1398  +- renamed deflateOptions as deflateInit2, call one or the other but not both
         1399  +- added the method parameter for deflateInit2.
         1400  +- added inflateInit2
         1401  +- simplied considerably deflateInit and inflateInit by not supporting
         1402  +  user-provided history buffer. This is supported only in deflateInit2
         1403  +  and inflateInit2.
         1404  +
         1405  +Changes in 0.3:
         1406  +- prefix all macro names with Z_
         1407  +- use Z_FINISH instead of deflateEnd to finish compression.
         1408  +- added Z_HUFFMAN_ONLY
         1409  +- added gzerror()

Added compat/zlib/FAQ.

            1  +
            2  +                Frequently Asked Questions about zlib
            3  +
            4  +
            5  +If your question is not there, please check the zlib home page
            6  +http://zlib.net/ which may have more recent information.
            7  +The lastest zlib FAQ is at http://zlib.net/zlib_faq.html
            8  +
            9  +
           10  + 1. Is zlib Y2K-compliant?
           11  +
           12  +    Yes. zlib doesn't handle dates.
           13  +
           14  + 2. Where can I get a Windows DLL version?
           15  +
           16  +    The zlib sources can be compiled without change to produce a DLL.  See the
           17  +    file win32/DLL_FAQ.txt in the zlib distribution.  Pointers to the
           18  +    precompiled DLL are found in the zlib web site at http://zlib.net/ .
           19  +
           20  + 3. Where can I get a Visual Basic interface to zlib?
           21  +
           22  +    See
           23  +        * http://marknelson.us/1997/01/01/zlib-engine/
           24  +        * win32/DLL_FAQ.txt in the zlib distribution
           25  +
           26  + 4. compress() returns Z_BUF_ERROR.
           27  +
           28  +    Make sure that before the call of compress(), the length of the compressed
           29  +    buffer is equal to the available size of the compressed buffer and not
           30  +    zero.  For Visual Basic, check that this parameter is passed by reference
           31  +    ("as any"), not by value ("as long").
           32  +
           33  + 5. deflate() or inflate() returns Z_BUF_ERROR.
           34  +
           35  +    Before making the call, make sure that avail_in and avail_out are not zero.
           36  +    When setting the parameter flush equal to Z_FINISH, also make sure that
           37  +    avail_out is big enough to allow processing all pending input.  Note that a
           38  +    Z_BUF_ERROR is not fatal--another call to deflate() or inflate() can be
           39  +    made with more input or output space.  A Z_BUF_ERROR may in fact be
           40  +    unavoidable depending on how the functions are used, since it is not
           41  +    possible to tell whether or not there is more output pending when
           42  +    strm.avail_out returns with zero.  See http://zlib.net/zlib_how.html for a
           43  +    heavily annotated example.
           44  +
           45  + 6. Where's the zlib documentation (man pages, etc.)?
           46  +
           47  +    It's in zlib.h .  Examples of zlib usage are in the files test/example.c
           48  +    and test/minigzip.c, with more in examples/ .
           49  +
           50  + 7. Why don't you use GNU autoconf or libtool or ...?
           51  +
           52  +    Because we would like to keep zlib as a very small and simple package.
           53  +    zlib is rather portable and doesn't need much configuration.
           54  +
           55  + 8. I found a bug in zlib.
           56  +
           57  +    Most of the time, such problems are due to an incorrect usage of zlib.
           58  +    Please try to reproduce the problem with a small program and send the
           59  +    corresponding source to us at zlib@gzip.org .  Do not send multi-megabyte
           60  +    data files without prior agreement.
           61  +
           62  + 9. Why do I get "undefined reference to gzputc"?
           63  +
           64  +    If "make test" produces something like
           65  +
           66  +       example.o(.text+0x154): undefined reference to `gzputc'
           67  +
           68  +    check that you don't have old files libz.* in /usr/lib, /usr/local/lib or
           69  +    /usr/X11R6/lib. Remove any old versions, then do "make install".
           70  +
           71  +10. I need a Delphi interface to zlib.
           72  +
           73  +    See the contrib/delphi directory in the zlib distribution.
           74  +
           75  +11. Can zlib handle .zip archives?
           76  +
           77  +    Not by itself, no.  See the directory contrib/minizip in the zlib
           78  +    distribution.
           79  +
           80  +12. Can zlib handle .Z files?
           81  +
           82  +    No, sorry.  You have to spawn an uncompress or gunzip subprocess, or adapt
           83  +    the code of uncompress on your own.
           84  +
           85  +13. How can I make a Unix shared library?
           86  +
           87  +    By default a shared (and a static) library is built for Unix.  So:
           88  +
           89  +    make distclean
           90  +    ./configure
           91  +    make
           92  +
           93  +14. How do I install a shared zlib library on Unix?
           94  +
           95  +    After the above, then:
           96  +
           97  +    make install
           98  +
           99  +    However, many flavors of Unix come with a shared zlib already installed.
          100  +    Before going to the trouble of compiling a shared version of zlib and
          101  +    trying to install it, you may want to check if it's already there!  If you
          102  +    can #include <zlib.h>, it's there.  The -lz option will probably link to
          103  +    it.  You can check the version at the top of zlib.h or with the
          104  +    ZLIB_VERSION symbol defined in zlib.h .
          105  +
          106  +15. I have a question about OttoPDF.
          107  +
          108  +    We are not the authors of OttoPDF. The real author is on the OttoPDF web
          109  +    site: Joel Hainley, jhainley@myndkryme.com.
          110  +
          111  +16. Can zlib decode Flate data in an Adobe PDF file?
          112  +
          113  +    Yes. See http://www.pdflib.com/ . To modify PDF forms, see
          114  +    http://sourceforge.net/projects/acroformtool/ .
          115  +
          116  +17. Why am I getting this "register_frame_info not found" error on Solaris?
          117  +
          118  +    After installing zlib 1.1.4 on Solaris 2.6, running applications using zlib
          119  +    generates an error such as:
          120  +
          121  +        ld.so.1: rpm: fatal: relocation error: file /usr/local/lib/libz.so:
          122  +        symbol __register_frame_info: referenced symbol not found
          123  +
          124  +    The symbol __register_frame_info is not part of zlib, it is generated by
          125  +    the C compiler (cc or gcc).  You must recompile applications using zlib
          126  +    which have this problem.  This problem is specific to Solaris.  See
          127  +    http://www.sunfreeware.com for Solaris versions of zlib and applications
          128  +    using zlib.
          129  +
          130  +18. Why does gzip give an error on a file I make with compress/deflate?
          131  +
          132  +    The compress and deflate functions produce data in the zlib format, which
          133  +    is different and incompatible with the gzip format.  The gz* functions in
          134  +    zlib on the other hand use the gzip format.  Both the zlib and gzip formats
          135  +    use the same compressed data format internally, but have different headers
          136  +    and trailers around the compressed data.
          137  +
          138  +19. Ok, so why are there two different formats?
          139  +
          140  +    The gzip format was designed to retain the directory information about a
          141  +    single file, such as the name and last modification date.  The zlib format
          142  +    on the other hand was designed for in-memory and communication channel
          143  +    applications, and has a much more compact header and trailer and uses a
          144  +    faster integrity check than gzip.
          145  +
          146  +20. Well that's nice, but how do I make a gzip file in memory?
          147  +
          148  +    You can request that deflate write the gzip format instead of the zlib
          149  +    format using deflateInit2().  You can also request that inflate decode the
          150  +    gzip format using inflateInit2().  Read zlib.h for more details.
          151  +
          152  +21. Is zlib thread-safe?
          153  +
          154  +    Yes.  However any library routines that zlib uses and any application-
          155  +    provided memory allocation routines must also be thread-safe.  zlib's gz*
          156  +    functions use stdio library routines, and most of zlib's functions use the
          157  +    library memory allocation routines by default.  zlib's *Init* functions
          158  +    allow for the application to provide custom memory allocation routines.
          159  +
          160  +    Of course, you should only operate on any given zlib or gzip stream from a
          161  +    single thread at a time.
          162  +
          163  +22. Can I use zlib in my commercial application?
          164  +
          165  +    Yes.  Please read the license in zlib.h.
          166  +
          167  +23. Is zlib under the GNU license?
          168  +
          169  +    No.  Please read the license in zlib.h.
          170  +
          171  +24. The license says that altered source versions must be "plainly marked". So
          172  +    what exactly do I need to do to meet that requirement?
          173  +
          174  +    You need to change the ZLIB_VERSION and ZLIB_VERNUM #defines in zlib.h.  In
          175  +    particular, the final version number needs to be changed to "f", and an
          176  +    identification string should be appended to ZLIB_VERSION.  Version numbers
          177  +    x.x.x.f are reserved for modifications to zlib by others than the zlib
          178  +    maintainers.  For example, if the version of the base zlib you are altering
          179  +    is "1.2.3.4", then in zlib.h you should change ZLIB_VERNUM to 0x123f, and
          180  +    ZLIB_VERSION to something like "1.2.3.f-zachary-mods-v3".  You can also
          181  +    update the version strings in deflate.c and inftrees.c.
          182  +
          183  +    For altered source distributions, you should also note the origin and
          184  +    nature of the changes in zlib.h, as well as in ChangeLog and README, along
          185  +    with the dates of the alterations.  The origin should include at least your
          186  +    name (or your company's name), and an email address to contact for help or
          187  +    issues with the library.
          188  +
          189  +    Note that distributing a compiled zlib library along with zlib.h and
          190  +    zconf.h is also a source distribution, and so you should change
          191  +    ZLIB_VERSION and ZLIB_VERNUM and note the origin and nature of the changes
          192  +    in zlib.h as you would for a full source distribution.
          193  +
          194  +25. Will zlib work on a big-endian or little-endian architecture, and can I
          195  +    exchange compressed data between them?
          196  +
          197  +    Yes and yes.
          198  +
          199  +26. Will zlib work on a 64-bit machine?
          200  +
          201  +    Yes.  It has been tested on 64-bit machines, and has no dependence on any
          202  +    data types being limited to 32-bits in length.  If you have any
          203  +    difficulties, please provide a complete problem report to zlib@gzip.org
          204  +
          205  +27. Will zlib decompress data from the PKWare Data Compression Library?
          206  +
          207  +    No.  The PKWare DCL uses a completely different compressed data format than
          208  +    does PKZIP and zlib.  However, you can look in zlib's contrib/blast
          209  +    directory for a possible solution to your problem.
          210  +
          211  +28. Can I access data randomly in a compressed stream?
          212  +
          213  +    No, not without some preparation.  If when compressing you periodically use
          214  +    Z_FULL_FLUSH, carefully write all the pending data at those points, and
          215  +    keep an index of those locations, then you can start decompression at those
          216  +    points.  You have to be careful to not use Z_FULL_FLUSH too often, since it
          217  +    can significantly degrade compression.  Alternatively, you can scan a
          218  +    deflate stream once to generate an index, and then use that index for
          219  +    random access.  See examples/zran.c .
          220  +
          221  +29. Does zlib work on MVS, OS/390, CICS, etc.?
          222  +
          223  +    It has in the past, but we have not heard of any recent evidence.  There
          224  +    were working ports of zlib 1.1.4 to MVS, but those links no longer work.
          225  +    If you know of recent, successful applications of zlib on these operating
          226  +    systems, please let us know.  Thanks.
          227  +
          228  +30. Is there some simpler, easier to read version of inflate I can look at to
          229  +    understand the deflate format?
          230  +
          231  +    First off, you should read RFC 1951.  Second, yes.  Look in zlib's
          232  +    contrib/puff directory.
          233  +
          234  +31. Does zlib infringe on any patents?
          235  +
          236  +    As far as we know, no.  In fact, that was originally the whole point behind
          237  +    zlib.  Look here for some more information:
          238  +
          239  +    http://www.gzip.org/#faq11
          240  +
          241  +32. Can zlib work with greater than 4 GB of data?
          242  +
          243  +    Yes.  inflate() and deflate() will process any amount of data correctly.
          244  +    Each call of inflate() or deflate() is limited to input and output chunks
          245  +    of the maximum value that can be stored in the compiler's "unsigned int"
          246  +    type, but there is no limit to the number of chunks.  Note however that the
          247  +    strm.total_in and strm_total_out counters may be limited to 4 GB.  These
          248  +    counters are provided as a convenience and are not used internally by
          249  +    inflate() or deflate().  The application can easily set up its own counters
          250  +    updated after each call of inflate() or deflate() to count beyond 4 GB.
          251  +    compress() and uncompress() may be limited to 4 GB, since they operate in a
          252  +    single call.  gzseek() and gztell() may be limited to 4 GB depending on how
          253  +    zlib is compiled.  See the zlibCompileFlags() function in zlib.h.
          254  +
          255  +    The word "may" appears several times above since there is a 4 GB limit only
          256  +    if the compiler's "long" type is 32 bits.  If the compiler's "long" type is
          257  +    64 bits, then the limit is 16 exabytes.
          258  +
          259  +33. Does zlib have any security vulnerabilities?
          260  +
          261  +    The only one that we are aware of is potentially in gzprintf().  If zlib is
          262  +    compiled to use sprintf() or vsprintf(), then there is no protection
          263  +    against a buffer overflow of an 8K string space (or other value as set by
          264  +    gzbuffer()), other than the caller of gzprintf() assuring that the output
          265  +    will not exceed 8K.  On the other hand, if zlib is compiled to use
          266  +    snprintf() or vsnprintf(), which should normally be the case, then there is
          267  +    no vulnerability.  The ./configure script will display warnings if an
          268  +    insecure variation of sprintf() will be used by gzprintf().  Also the
          269  +    zlibCompileFlags() function will return information on what variant of
          270  +    sprintf() is used by gzprintf().
          271  +
          272  +    If you don't have snprintf() or vsnprintf() and would like one, you can
          273  +    find a portable implementation here:
          274  +
          275  +        http://www.ijs.si/software/snprintf/
          276  +
          277  +    Note that you should be using the most recent version of zlib.  Versions
          278  +    1.1.3 and before were subject to a double-free vulnerability, and versions
          279  +    1.2.1 and 1.2.2 were subject to an access exception when decompressing
          280  +    invalid compressed data.
          281  +
          282  +34. Is there a Java version of zlib?
          283  +
          284  +    Probably what you want is to use zlib in Java. zlib is already included
          285  +    as part of the Java SDK in the java.util.zip package. If you really want
          286  +    a version of zlib written in the Java language, look on the zlib home
          287  +    page for links: http://zlib.net/ .
          288  +
          289  +35. I get this or that compiler or source-code scanner warning when I crank it
          290  +    up to maximally-pedantic. Can't you guys write proper code?
          291  +
          292  +    Many years ago, we gave up attempting to avoid warnings on every compiler
          293  +    in the universe.  It just got to be a waste of time, and some compilers
          294  +    were downright silly as well as contradicted each other.  So now, we simply
          295  +    make sure that the code always works.
          296  +
          297  +36. Valgrind (or some similar memory access checker) says that deflate is
          298  +    performing a conditional jump that depends on an uninitialized value.
          299  +    Isn't that a bug?
          300  +
          301  +    No.  That is intentional for performance reasons, and the output of deflate
          302  +    is not affected.  This only started showing up recently since zlib 1.2.x
          303  +    uses malloc() by default for allocations, whereas earlier versions used
          304  +    calloc(), which zeros out the allocated memory.  Even though the code was
          305  +    correct, versions 1.2.4 and later was changed to not stimulate these
          306  +    checkers.
          307  +
          308  +37. Will zlib read the (insert any ancient or arcane format here) compressed
          309  +    data format?
          310  +
          311  +    Probably not. Look in the comp.compression FAQ for pointers to various
          312  +    formats and associated software.
          313  +
          314  +38. How can I encrypt/decrypt zip files with zlib?
          315  +
          316  +    zlib doesn't support encryption.  The original PKZIP encryption is very
          317  +    weak and can be broken with freely available programs.  To get strong
          318  +    encryption, use GnuPG, http://www.gnupg.org/ , which already includes zlib
          319  +    compression.  For PKZIP compatible "encryption", look at
          320  +    http://www.info-zip.org/
          321  +
          322  +39. What's the difference between the "gzip" and "deflate" HTTP 1.1 encodings?
          323  +
          324  +    "gzip" is the gzip format, and "deflate" is the zlib format.  They should
          325  +    probably have called the second one "zlib" instead to avoid confusion with
          326  +    the raw deflate compressed data format.  While the HTTP 1.1 RFC 2616
          327  +    correctly points to the zlib specification in RFC 1950 for the "deflate"
          328  +    transfer encoding, there have been reports of servers and browsers that
          329  +    incorrectly produce or expect raw deflate data per the deflate
          330  +    specification in RFC 1951, most notably Microsoft.  So even though the
          331  +    "deflate" transfer encoding using the zlib format would be the more
          332  +    efficient approach (and in fact exactly what the zlib format was designed
          333  +    for), using the "gzip" transfer encoding is probably more reliable due to
          334  +    an unfortunate choice of name on the part of the HTTP 1.1 authors.
          335  +
          336  +    Bottom line: use the gzip format for HTTP 1.1 encoding.
          337  +
          338  +40. Does zlib support the new "Deflate64" format introduced by PKWare?
          339  +
          340  +    No.  PKWare has apparently decided to keep that format proprietary, since
          341  +    they have not documented it as they have previous compression formats.  In
          342  +    any case, the compression improvements are so modest compared to other more
          343  +    modern approaches, that it's not worth the effort to implement.
          344  +
          345  +41. I'm having a problem with the zip functions in zlib, can you help?
          346  +
          347  +    There are no zip functions in zlib.  You are probably using minizip by
          348  +    Giles Vollant, which is found in the contrib directory of zlib.  It is not
          349  +    part of zlib.  In fact none of the stuff in contrib is part of zlib.  The
          350  +    files in there are not supported by the zlib authors.  You need to contact
          351  +    the authors of the respective contribution for help.
          352  +
          353  +42. The match.asm code in contrib is under the GNU General Public License.
          354  +    Since it's part of zlib, doesn't that mean that all of zlib falls under the
          355  +    GNU GPL?
          356  +
          357  +    No.  The files in contrib are not part of zlib.  They were contributed by
          358  +    other authors and are provided as a convenience to the user within the zlib
          359  +    distribution.  Each item in contrib has its own license.
          360  +
          361  +43. Is zlib subject to export controls?  What is its ECCN?
          362  +
          363  +    zlib is not subject to export controls, and so is classified as EAR99.
          364  +
          365  +44. Can you please sign these lengthy legal documents and fax them back to us
          366  +    so that we can use your software in our product?
          367  +
          368  +    No. Go away. Shoo.

Added compat/zlib/INDEX.

            1  +CMakeLists.txt  cmake build file
            2  +ChangeLog       history of changes
            3  +FAQ             Frequently Asked Questions about zlib
            4  +INDEX           this file
            5  +Makefile        dummy Makefile that tells you to ./configure
            6  +Makefile.in     template for Unix Makefile
            7  +README          guess what
            8  +configure       configure script for Unix
            9  +make_vms.com    makefile for VMS
           10  +test/example.c  zlib usages examples for build testing
           11  +test/minigzip.c minimal gzip-like functionality for build testing
           12  +test/infcover.c inf*.c code coverage for build coverage testing
           13  +treebuild.xml   XML description of source file dependencies
           14  +zconf.h.cmakein zconf.h template for cmake
           15  +zconf.h.in      zconf.h template for configure
           16  +zlib.3          Man page for zlib
           17  +zlib.3.pdf      Man page in PDF format
           18  +zlib.map        Linux symbol information
           19  +zlib.pc.in      Template for pkg-config descriptor
           20  +zlib.pc.cmakein zlib.pc template for cmake
           21  +zlib2ansi       perl script to convert source files for C++ compilation
           22  +
           23  +amiga/          makefiles for Amiga SAS C
           24  +as400/          makefiles for AS/400
           25  +doc/            documentation for formats and algorithms
           26  +msdos/          makefiles for MSDOS
           27  +nintendods/     makefile for Nintendo DS
           28  +old/            makefiles for various architectures and zlib documentation
           29  +                files that have not yet been updated for zlib 1.2.x
           30  +qnx/            makefiles for QNX
           31  +watcom/         makefiles for OpenWatcom
           32  +win32/          makefiles for Windows
           33  +
           34  +                zlib public header files (required for library use):
           35  +zconf.h
           36  +zlib.h
           37  +
           38  +                private source files used to build the zlib library:
           39  +adler32.c
           40  +compress.c
           41  +crc32.c
           42  +crc32.h
           43  +deflate.c
           44  +deflate.h
           45  +gzclose.c
           46  +gzguts.h
           47  +gzlib.c
           48  +gzread.c
           49  +gzwrite.c
           50  +infback.c
           51  +inffast.c
           52  +inffast.h
           53  +inffixed.h
           54  +inflate.c
           55  +inflate.h
           56  +inftrees.c
           57  +inftrees.h
           58  +trees.c
           59  +trees.h
           60  +uncompr.c
           61  +zutil.c
           62  +zutil.h
           63  +
           64  +                source files for sample programs
           65  +See examples/README.examples
           66  +
           67  +                unsupported contributions by third parties
           68  +See contrib/README.contrib

Added compat/zlib/Makefile.

            1  +all:
            2  +	-@echo "Please use ./configure first.  Thank you."
            3  +
            4  +distclean:
            5  +	make -f Makefile.in distclean

Added compat/zlib/Makefile.in.

            1  +# Makefile for zlib
            2  +# Copyright (C) 1995-2011 Jean-loup Gailly.
            3  +# For conditions of distribution and use, see copyright notice in zlib.h
            4  +
            5  +# To compile and test, type:
            6  +#    ./configure; make test
            7  +# Normally configure builds both a static and a shared library.
            8  +# If you want to build just a static library, use: ./configure --static
            9  +
           10  +# To use the asm code, type:
           11  +#    cp contrib/asm?86/match.S ./match.S
           12  +#    make LOC=-DASMV OBJA=match.o
           13  +
           14  +# To install /usr/local/lib/libz.* and /usr/local/include/zlib.h, type:
           15  +#    make install
           16  +# To install in $HOME instead of /usr/local, use:
           17  +#    make install prefix=$HOME
           18  +
           19  +CC=cc
           20  +
           21  +CFLAGS=-O
           22  +#CFLAGS=-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7
           23  +#CFLAGS=-g -DDEBUG
           24  +#CFLAGS=-O3 -Wall -Wwrite-strings -Wpointer-arith -Wconversion \
           25  +#           -Wstrict-prototypes -Wmissing-prototypes
           26  +
           27  +SFLAGS=-O
           28  +LDFLAGS=
           29  +TEST_LDFLAGS=-L. libz.a
           30  +LDSHARED=$(CC)
           31  +CPP=$(CC) -E
           32  +
           33  +STATICLIB=libz.a
           34  +SHAREDLIB=libz.so
           35  +SHAREDLIBV=libz.so.1.2.7
           36  +SHAREDLIBM=libz.so.1
           37  +LIBS=$(STATICLIB) $(SHAREDLIBV)
           38  +
           39  +AR=ar
           40  +ARFLAGS=rc
           41  +RANLIB=ranlib
           42  +LDCONFIG=ldconfig
           43  +LDSHAREDLIBC=-lc
           44  +TAR=tar
           45  +SHELL=/bin/sh
           46  +EXE=
           47  +
           48  +prefix = /usr/local
           49  +exec_prefix = ${prefix}
           50  +libdir = ${exec_prefix}/lib
           51  +sharedlibdir = ${libdir}
           52  +includedir = ${prefix}/include
           53  +mandir = ${prefix}/share/man
           54  +man3dir = ${mandir}/man3
           55  +pkgconfigdir = ${libdir}/pkgconfig
           56  +
           57  +OBJZ = adler32.o crc32.o deflate.o infback.o inffast.o inflate.o inftrees.o trees.o zutil.o
           58  +OBJG = compress.o uncompr.o gzclose.o gzlib.o gzread.o gzwrite.o
           59  +OBJC = $(OBJZ) $(OBJG)
           60  +
           61  +PIC_OBJZ = adler32.lo crc32.lo deflate.lo infback.lo inffast.lo inflate.lo inftrees.lo trees.lo zutil.lo
           62  +PIC_OBJG = compress.lo uncompr.lo gzclose.lo gzlib.lo gzread.lo gzwrite.lo
           63  +PIC_OBJC = $(PIC_OBJZ) $(PIC_OBJG)
           64  +
           65  +# to use the asm code: make OBJA=match.o, PIC_OBJA=match.lo
           66  +OBJA =
           67  +PIC_OBJA =
           68  +
           69  +OBJS = $(OBJC) $(OBJA)
           70  +
           71  +PIC_OBJS = $(PIC_OBJC) $(PIC_OBJA)
           72  +
           73  +all: static shared
           74  +
           75  +static: example$(EXE) minigzip$(EXE)
           76  +
           77  +shared: examplesh$(EXE) minigzipsh$(EXE)
           78  +
           79  +all64: example64$(EXE) minigzip64$(EXE)
           80  +
           81  +check: test
           82  +
           83  +test: all teststatic testshared
           84  +
           85  +teststatic: static
           86  +	@TMPST=`mktemp fooXXXXXX`; \
           87  +	if echo hello world | ./minigzip | ./minigzip -d && ./example $$TMPST ; then \
           88  +	  echo '		*** zlib test OK ***'; \
           89  +	else \
           90  +	  echo '		*** zlib test FAILED ***'; false; \
           91  +	fi; \
           92  +	rm -f $$TMPST
           93  +
           94  +testshared: shared
           95  +	@LD_LIBRARY_PATH=`pwd`:$(LD_LIBRARY_PATH) ; export LD_LIBRARY_PATH; \
           96  +	LD_LIBRARYN32_PATH=`pwd`:$(LD_LIBRARYN32_PATH) ; export LD_LIBRARYN32_PATH; \
           97  +	DYLD_LIBRARY_PATH=`pwd`:$(DYLD_LIBRARY_PATH) ; export DYLD_LIBRARY_PATH; \
           98  +	SHLIB_PATH=`pwd`:$(SHLIB_PATH) ; export SHLIB_PATH; \
           99  +	TMPSH=`mktemp fooXXXXXX`; \
          100  +	if echo hello world | ./minigzipsh | ./minigzipsh -d && ./examplesh $$TMPSH; then \
          101  +	  echo '		*** zlib shared test OK ***'; \
          102  +	else \
          103  +	  echo '		*** zlib shared test FAILED ***'; false; \
          104  +	fi; \
          105  +	rm -f $$TMPSH
          106  +
          107  +test64: all64
          108  +	@TMP64=`mktemp fooXXXXXX`; \
          109  +	if echo hello world | ./minigzip64 | ./minigzip64 -d && ./example64 $$TMP64; then \
          110  +	  echo '		*** zlib 64-bit test OK ***'; \
          111  +	else \
          112  +	  echo '		*** zlib 64-bit test FAILED ***'; false; \
          113  +	fi; \
          114  +	rm -f $$TMP64
          115  +
          116  +infcover.o: test/infcover.c zlib.h zconf.h
          117  +	$(CC) $(CFLAGS) -I. -c -o $@ test/infcover.c
          118  +
          119  +infcover: infcover.o libz.a
          120  +	$(CC) $(CFLAGS) -o $@ infcover.o libz.a
          121  +
          122  +cover: infcover
          123  +	rm -f *.gcda
          124  +	./infcover
          125  +	gcov inf*.c
          126  +
          127  +libz.a: $(OBJS)
          128  +	$(AR) $(ARFLAGS) $@ $(OBJS)
          129  +	-@ ($(RANLIB) $@ || true) >/dev/null 2>&1
          130  +
          131  +match.o: match.S
          132  +	$(CPP) match.S > _match.s
          133  +	$(CC) -c _match.s
          134  +	mv _match.o match.o
          135  +	rm -f _match.s
          136  +
          137  +match.lo: match.S
          138  +	$(CPP) match.S > _match.s
          139  +	$(CC) -c -fPIC _match.s
          140  +	mv _match.o match.lo
          141  +	rm -f _match.s
          142  +
          143  +example.o: test/example.c zlib.h zconf.h
          144  +	$(CC) $(CFLAGS) -I. -c -o $@ test/example.c
          145  +
          146  +minigzip.o: test/minigzip.c zlib.h zconf.h
          147  +	$(CC) $(CFLAGS) -I. -c -o $@ test/minigzip.c
          148  +
          149  +example64.o: test/example.c zlib.h zconf.h
          150  +	$(CC) $(CFLAGS) -I. -D_FILE_OFFSET_BITS=64 -c -o $@ test/example.c
          151  +
          152  +minigzip64.o: test/minigzip.c zlib.h zconf.h
          153  +	$(CC) $(CFLAGS) -I. -D_FILE_OFFSET_BITS=64 -c -o $@ test/minigzip.c
          154  +
          155  +.SUFFIXES: .lo
          156  +
          157  +.c.lo:
          158  +	-@mkdir objs 2>/dev/null || test -d objs
          159  +	$(CC) $(SFLAGS) -DPIC -c -o objs/$*.o $<
          160  +	-@mv objs/$*.o $@
          161  +
          162  +placebo $(SHAREDLIBV): $(PIC_OBJS) libz.a
          163  +	$(LDSHARED) $(SFLAGS) -o $@ $(PIC_OBJS) $(LDSHAREDLIBC) $(LDFLAGS)
          164  +	rm -f $(SHAREDLIB) $(SHAREDLIBM)
          165  +	ln -s $@ $(SHAREDLIB)
          166  +	ln -s $@ $(SHAREDLIBM)
          167  +	-@rmdir objs
          168  +
          169  +example$(EXE): example.o $(STATICLIB)
          170  +	$(CC) $(CFLAGS) -o $@ example.o $(TEST_LDFLAGS)
          171  +
          172  +minigzip$(EXE): minigzip.o $(STATICLIB)
          173  +	$(CC) $(CFLAGS) -o $@ minigzip.o $(TEST_LDFLAGS)
          174  +
          175  +examplesh$(EXE): example.o $(SHAREDLIBV)
          176  +	$(CC) $(CFLAGS) -o $@ example.o -L. $(SHAREDLIBV)
          177  +
          178  +minigzipsh$(EXE): minigzip.o $(SHAREDLIBV)
          179  +	$(CC) $(CFLAGS) -o $@ minigzip.o -L. $(SHAREDLIBV)
          180  +
          181  +example64$(EXE): example64.o $(STATICLIB)
          182  +	$(CC) $(CFLAGS) -o $@ example64.o $(TEST_LDFLAGS)
          183  +
          184  +minigzip64$(EXE): minigzip64.o $(STATICLIB)
          185  +	$(CC) $(CFLAGS) -o $@ minigzip64.o $(TEST_LDFLAGS)
          186  +
          187  +install-libs: $(LIBS)
          188  +	-@if [ ! -d $(DESTDIR)$(exec_prefix)  ]; then mkdir -p $(DESTDIR)$(exec_prefix); fi
          189  +	-@if [ ! -d $(DESTDIR)$(libdir)       ]; then mkdir -p $(DESTDIR)$(libdir); fi
          190  +	-@if [ ! -d $(DESTDIR)$(sharedlibdir) ]; then mkdir -p $(DESTDIR)$(sharedlibdir); fi
          191  +	-@if [ ! -d $(DESTDIR)$(man3dir)      ]; then mkdir -p $(DESTDIR)$(man3dir); fi
          192  +	-@if [ ! -d $(DESTDIR)$(pkgconfigdir) ]; then mkdir -p $(DESTDIR)$(pkgconfigdir); fi
          193  +	cp $(STATICLIB) $(DESTDIR)$(libdir)
          194  +	chmod 644 $(DESTDIR)$(libdir)/$(STATICLIB)
          195  +	-@($(RANLIB) $(DESTDIR)$(libdir)/libz.a || true) >/dev/null 2>&1
          196  +	-@if test -n "$(SHAREDLIBV)"; then \
          197  +	  cp $(SHAREDLIBV) $(DESTDIR)$(sharedlibdir); \
          198  +	  echo "cp $(SHAREDLIBV) $(DESTDIR)$(sharedlibdir)"; \
          199  +	  chmod 755 $(DESTDIR)$(sharedlibdir)/$(SHAREDLIBV); \
          200  +	  echo "chmod 755 $(DESTDIR)$(sharedlibdir)/$(SHAREDLIBV)"; \
          201  +	  rm -f $(DESTDIR)$(sharedlibdir)/$(SHAREDLIB) $(DESTDIR)$(sharedlibdir)/$(SHAREDLIBM); \
          202  +	  ln -s $(SHAREDLIBV) $(DESTDIR)$(sharedlibdir)/$(SHAREDLIB); \
          203  +	  ln -s $(SHAREDLIBV) $(DESTDIR)$(sharedlibdir)/$(SHAREDLIBM); \
          204  +	  ($(LDCONFIG) || true)  >/dev/null 2>&1; \
          205  +	fi
          206  +	cp zlib.3 $(DESTDIR)$(man3dir)
          207  +	chmod 644 $(DESTDIR)$(man3dir)/zlib.3
          208  +	cp zlib.pc $(DESTDIR)$(pkgconfigdir)
          209  +	chmod 644 $(DESTDIR)$(pkgconfigdir)/zlib.pc
          210  +# The ranlib in install is needed on NeXTSTEP which checks file times
          211  +# ldconfig is for Linux
          212  +
          213  +install: install-libs
          214  +	-@if [ ! -d $(DESTDIR)$(includedir)   ]; then mkdir -p $(DESTDIR)$(includedir); fi
          215  +	cp zlib.h zconf.h $(DESTDIR)$(includedir)
          216  +	chmod 644 $(DESTDIR)$(includedir)/zlib.h $(DESTDIR)$(includedir)/zconf.h
          217  +
          218  +uninstall:
          219  +	cd $(DESTDIR)$(includedir); rm -f zlib.h zconf.h
          220  +	cd $(DESTDIR)$(libdir); rm -f libz.a; \
          221  +	if test -n "$(SHAREDLIBV)" -a -f $(SHAREDLIBV); then \
          222  +	  rm -f $(SHAREDLIBV) $(SHAREDLIB) $(SHAREDLIBM); \
          223  +	fi
          224  +	cd $(DESTDIR)$(man3dir); rm -f zlib.3
          225  +	cd $(DESTDIR)$(pkgconfigdir); rm -f zlib.pc
          226  +
          227  +docs: zlib.3.pdf
          228  +
          229  +zlib.3.pdf: zlib.3
          230  +	groff -mandoc -f H -T ps zlib.3 | ps2pdf - zlib.3.pdf
          231  +
          232  +zconf.h.cmakein: zconf.h.in
          233  +	-@ TEMPFILE=`mktemp __XXXXXX`; \
          234  +	echo "/#define ZCONF_H/ a\\\\\n#cmakedefine Z_PREFIX\\\\\n#cmakedefine Z_HAVE_UNISTD_H\n" >> $$TEMPFILE &&\
          235  +	sed -f $$TEMPFILE zconf.h.in > zconf.h.cmakein &&\
          236  +	touch -r zconf.h.in zconf.h.cmakein &&\
          237  +	rm $$TEMPFILE
          238  +
          239  +zconf: zconf.h.in
          240  +	cp -p zconf.h.in zconf.h
          241  +
          242  +mostlyclean: clean
          243  +clean:
          244  +	rm -f *.o *.lo *~ \
          245  +	   example$(EXE) minigzip$(EXE) examplesh$(EXE) minigzipsh$(EXE) \
          246  +	   example64$(EXE) minigzip64$(EXE) \
          247  +	   infcover \
          248  +	   libz.* foo.gz so_locations \
          249  +	   _match.s maketree contrib/infback9/*.o
          250  +	rm -rf objs
          251  +	rm -f *.gcda *.gcno *.gcov
          252  +	rm -f contrib/infback9/*.gcda contrib/infback9/*.gcno contrib/infback9/*.gcov
          253  +
          254  +maintainer-clean: distclean
          255  +distclean: clean zconf zconf.h.cmakein docs
          256  +	rm -f Makefile zlib.pc configure.log
          257  +	-@rm -f .DS_Store
          258  +	-@printf 'all:\n\t-@echo "Please use ./configure first.  Thank you."\n' > Makefile
          259  +	-@printf '\ndistclean:\n\tmake -f Makefile.in distclean\n' >> Makefile
          260  +	-@touch -r Makefile.in Makefile
          261  +
          262  +tags:
          263  +	etags *.[ch]
          264  +
          265  +depend:
          266  +	makedepend -- $(CFLAGS) -- *.[ch]
          267  +
          268  +# DO NOT DELETE THIS LINE -- make depend depends on it.
          269  +
          270  +adler32.o zutil.o: zutil.h zlib.h zconf.h
          271  +gzclose.o gzlib.o gzread.o gzwrite.o: zlib.h zconf.h gzguts.h
          272  +compress.o example.o minigzip.o uncompr.o: zlib.h zconf.h
          273  +crc32.o: zutil.h zlib.h zconf.h crc32.h
          274  +deflate.o: deflate.h zutil.h zlib.h zconf.h
          275  +infback.o inflate.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h inffixed.h
          276  +inffast.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h
          277  +inftrees.o: zutil.h zlib.h zconf.h inftrees.h
          278  +trees.o: deflate.h zutil.h zlib.h zconf.h trees.h
          279  +
          280  +adler32.lo zutil.lo: zutil.h zlib.h zconf.h
          281  +gzclose.lo gzlib.lo gzread.lo gzwrite.lo: zlib.h zconf.h gzguts.h
          282  +compress.lo example.lo minigzip.lo uncompr.lo: zlib.h zconf.h
          283  +crc32.lo: zutil.h zlib.h zconf.h crc32.h
          284  +deflate.lo: deflate.h zutil.h zlib.h zconf.h
          285  +infback.lo inflate.lo: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h inffixed.h
          286  +inffast.lo: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h
          287  +inftrees.lo: zutil.h zlib.h zconf.h inftrees.h
          288  +trees.lo: deflate.h zutil.h zlib.h zconf.h trees.h

Added compat/zlib/README.

            1  +ZLIB DATA COMPRESSION LIBRARY
            2  +
            3  +zlib 1.2.7 is a general purpose data compression library.  All the code is
            4  +thread safe.  The data format used by the zlib library is described by RFCs
            5  +(Request for Comments) 1950 to 1952 in the files
            6  +http://tools.ietf.org/html/rfc1950 (zlib format), rfc1951 (deflate format) and
            7  +rfc1952 (gzip format).
            8  +
            9  +All functions of the compression library are documented in the file zlib.h
           10  +(volunteer to write man pages welcome, contact zlib@gzip.org).  A usage example
           11  +of the library is given in the file test/example.c which also tests that
           12  +the library is working correctly.  Another example is given in the file
           13  +test/minigzip.c.  The compression library itself is composed of all source
           14  +files in the root directory.
           15  +
           16  +To compile all files and run the test program, follow the instructions given at
           17  +the top of Makefile.in.  In short "./configure; make test", and if that goes
           18  +well, "make install" should work for most flavors of Unix.  For Windows, use
           19  +one of the special makefiles in win32/ or contrib/vstudio/ .  For VMS, use
           20  +make_vms.com.
           21  +
           22  +Questions about zlib should be sent to <zlib@gzip.org>, or to Gilles Vollant
           23  +<info@winimage.com> for the Windows DLL version.  The zlib home page is
           24  +http://zlib.net/ .  Before reporting a problem, please check this site to
           25  +verify that you have the latest version of zlib; otherwise get the latest
           26  +version and check whether the problem still exists or not.
           27  +
           28  +PLEASE read the zlib FAQ http://zlib.net/zlib_faq.html before asking for help.
           29  +
           30  +Mark Nelson <markn@ieee.org> wrote an article about zlib for the Jan.  1997
           31  +issue of Dr.  Dobb's Journal; a copy of the article is available at
           32  +http://marknelson.us/1997/01/01/zlib-engine/ .
           33  +
           34  +The changes made in version 1.2.7 are documented in the file ChangeLog.
           35  +
           36  +Unsupported third party contributions are provided in directory contrib/ .
           37  +
           38  +zlib is available in Java using the java.util.zip package, documented at
           39  +http://java.sun.com/developer/technicalArticles/Programming/compression/ .
           40  +
           41  +A Perl interface to zlib written by Paul Marquess <pmqs@cpan.org> is available
           42  +at CPAN (Comprehensive Perl Archive Network) sites, including
           43  +http://search.cpan.org/~pmqs/IO-Compress-Zlib/ .
           44  +
           45  +A Python interface to zlib written by A.M. Kuchling <amk@amk.ca> is
           46  +available in Python 1.5 and later versions, see
           47  +http://docs.python.org/library/zlib.html .
           48  +
           49  +zlib is built into tcl: http://wiki.tcl.tk/4610 .
           50  +
           51  +An experimental package to read and write files in .zip format, written on top
           52  +of zlib by Gilles Vollant <info@winimage.com>, is available in the
           53  +contrib/minizip directory of zlib.
           54  +
           55  +
           56  +Notes for some targets:
           57  +
           58  +- For Windows DLL versions, please see win32/DLL_FAQ.txt
           59  +
           60  +- For 64-bit Irix, deflate.c must be compiled without any optimization. With
           61  +  -O, one libpng test fails. The test works in 32 bit mode (with the -n32
           62  +  compiler flag). The compiler bug has been reported to SGI.
           63  +
           64  +- zlib doesn't work with gcc 2.6.3 on a DEC 3000/300LX under OSF/1 2.1 it works
           65  +  when compiled with cc.
           66  +
           67  +- On Digital Unix 4.0D (formely OSF/1) on AlphaServer, the cc option -std1 is
           68  +  necessary to get gzprintf working correctly. This is done by configure.
           69  +
           70  +- zlib doesn't work on HP-UX 9.05 with some versions of /bin/cc. It works with
           71  +  other compilers. Use "make test" to check your compiler.
           72  +
           73  +- gzdopen is not supported on RISCOS or BEOS.
           74  +
           75  +- For PalmOs, see http://palmzlib.sourceforge.net/
           76  +
           77  +
           78  +Acknowledgments:
           79  +
           80  +  The deflate format used by zlib was defined by Phil Katz.  The deflate and
           81  +  zlib specifications were written by L.  Peter Deutsch.  Thanks to all the
           82  +  people who reported problems and suggested various improvements in zlib; they
           83  +  are too numerous to cite here.
           84  +
           85  +Copyright notice:
           86  +
           87  + (C) 1995-2012 Jean-loup Gailly and Mark Adler
           88  +
           89  +  This software is provided 'as-is', without any express or implied
           90  +  warranty.  In no event will the authors be held liable for any damages
           91  +  arising from the use of this software.
           92  +
           93  +  Permission is granted to anyone to use this software for any purpose,
           94  +  including commercial applications, and to alter it and redistribute it
           95  +  freely, subject to the following restrictions:
           96  +
           97  +  1. The origin of this software must not be misrepresented; you must not
           98  +     claim that you wrote the original software. If you use this software
           99  +     in a product, an acknowledgment in the product documentation would be
          100  +     appreciated but is not required.
          101  +  2. Altered source versions must be plainly marked as such, and must not be
          102  +     misrepresented as being the original software.
          103  +  3. This notice may not be removed or altered from any source distribution.
          104  +
          105  +  Jean-loup Gailly        Mark Adler
          106  +  jloup@gzip.org          madler@alumni.caltech.edu
          107  +
          108  +If you use the zlib library in a product, we would appreciate *not* receiving
          109  +lengthy legal documents to sign.  The sources are provided for free but without
          110  +warranty of any kind.  The library has been entirely written by Jean-loup
          111  +Gailly and Mark Adler; it does not include third-party code.
          112  +
          113  +If you redistribute modified sources, we would appreciate that you include in
          114  +the file ChangeLog history information documenting your changes.  Please read
          115  +the FAQ for more information on the distribution of modified source versions.

Added compat/zlib/adler32.c.

            1  +/* adler32.c -- compute the Adler-32 checksum of a data stream
            2  + * Copyright (C) 1995-2011 Mark Adler
            3  + * For conditions of distribution and use, see copyright notice in zlib.h
            4  + */
            5  +
            6  +/* @(#) $Id$ */
            7  +
            8  +#include "zutil.h"
            9  +
           10  +#define local static
           11  +
           12  +local uLong adler32_combine_ OF((uLong adler1, uLong adler2, z_off64_t len2));
           13  +
           14  +#define BASE 65521      /* largest prime smaller than 65536 */
           15  +#define NMAX 5552
           16  +/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
           17  +
           18  +#define DO1(buf,i)  {adler += (buf)[i]; sum2 += adler;}
           19  +#define DO2(buf,i)  DO1(buf,i); DO1(buf,i+1);
           20  +#define DO4(buf,i)  DO2(buf,i); DO2(buf,i+2);
           21  +#define DO8(buf,i)  DO4(buf,i); DO4(buf,i+4);
           22  +#define DO16(buf)   DO8(buf,0); DO8(buf,8);
           23  +
           24  +/* use NO_DIVIDE if your processor does not do division in hardware --
           25  +   try it both ways to see which is faster */
           26  +#ifdef NO_DIVIDE
           27  +/* note that this assumes BASE is 65521, where 65536 % 65521 == 15
           28  +   (thank you to John Reiser for pointing this out) */
           29  +#  define CHOP(a) \
           30  +    do { \
           31  +        unsigned long tmp = a >> 16; \
           32  +        a &= 0xffffUL; \
           33  +        a += (tmp << 4) - tmp; \
           34  +    } while (0)
           35  +#  define MOD28(a) \
           36  +    do { \
           37  +        CHOP(a); \
           38  +        if (a >= BASE) a -= BASE; \
           39  +    } while (0)
           40  +#  define MOD(a) \
           41  +    do { \
           42  +        CHOP(a); \
           43  +        MOD28(a); \
           44  +    } while (0)
           45  +#  define MOD63(a) \
           46  +    do { /* this assumes a is not negative */ \
           47  +        z_off64_t tmp = a >> 32; \
           48  +        a &= 0xffffffffL; \
           49  +        a += (tmp << 8) - (tmp << 5) + tmp; \
           50  +        tmp = a >> 16; \
           51  +        a &= 0xffffL; \
           52  +        a += (tmp << 4) - tmp; \
           53  +        tmp = a >> 16; \
           54  +        a &= 0xffffL; \
           55  +        a += (tmp << 4) - tmp; \
           56  +        if (a >= BASE) a -= BASE; \
           57  +    } while (0)
           58  +#else
           59  +#  define MOD(a) a %= BASE
           60  +#  define MOD28(a) a %= BASE
           61  +#  define MOD63(a) a %= BASE
           62  +#endif
           63  +
           64  +/* ========================================================================= */
           65  +uLong ZEXPORT adler32(adler, buf, len)
           66  +    uLong adler;
           67  +    const Bytef *buf;
           68  +    uInt len;
           69  +{
           70  +    unsigned long sum2;
           71  +    unsigned n;
           72  +
           73  +    /* split Adler-32 into component sums */
           74  +    sum2 = (adler >> 16) & 0xffff;
           75  +    adler &= 0xffff;
           76  +
           77  +    /* in case user likes doing a byte at a time, keep it fast */
           78  +    if (len == 1) {
           79  +        adler += buf[0];
           80  +        if (adler >= BASE)
           81  +            adler -= BASE;
           82  +        sum2 += adler;
           83  +        if (sum2 >= BASE)
           84  +            sum2 -= BASE;
           85  +        return adler | (sum2 << 16);
           86  +    }
           87  +
           88  +    /* initial Adler-32 value (deferred check for len == 1 speed) */
           89  +    if (buf == Z_NULL)
           90  +        return 1L;
           91  +
           92  +    /* in case short lengths are provided, keep it somewhat fast */
           93  +    if (len < 16) {
           94  +        while (len--) {
           95  +            adler += *buf++;
           96  +            sum2 += adler;
           97  +        }
           98  +        if (adler >= BASE)
           99  +            adler -= BASE;
          100  +        MOD28(sum2);            /* only added so many BASE's */
          101  +        return adler | (sum2 << 16);
          102  +    }
          103  +
          104  +    /* do length NMAX blocks -- requires just one modulo operation */
          105  +    while (len >= NMAX) {
          106  +        len -= NMAX;
          107  +        n = NMAX / 16;          /* NMAX is divisible by 16 */
          108  +        do {
          109  +            DO16(buf);          /* 16 sums unrolled */
          110  +            buf += 16;
          111  +        } while (--n);
          112  +        MOD(adler);
          113  +        MOD(sum2);
          114  +    }
          115  +
          116  +    /* do remaining bytes (less than NMAX, still just one modulo) */
          117  +    if (len) {                  /* avoid modulos if none remaining */
          118  +        while (len >= 16) {
          119  +            len -= 16;
          120  +            DO16(buf);
          121  +            buf += 16;
          122  +        }
          123  +        while (len--) {
          124  +            adler += *buf++;
          125  +            sum2 += adler;
          126  +        }
          127  +        MOD(adler);
          128  +        MOD(sum2);
          129  +    }
          130  +
          131  +    /* return recombined sums */
          132  +    return adler | (sum2 << 16);
          133  +}
          134  +
          135  +/* ========================================================================= */
          136  +local uLong adler32_combine_(adler1, adler2, len2)
          137  +    uLong adler1;
          138  +    uLong adler2;
          139  +    z_off64_t len2;
          140  +{
          141  +    unsigned long sum1;
          142  +    unsigned long sum2;
          143  +    unsigned rem;
          144  +
          145  +    /* for negative len, return invalid adler32 as a clue for debugging */
          146  +    if (len2 < 0)
          147  +        return 0xffffffffUL;
          148  +
          149  +    /* the derivation of this formula is left as an exercise for the reader */
          150  +    MOD63(len2);                /* assumes len2 >= 0 */
          151  +    rem = (unsigned)len2;
          152  +    sum1 = adler1 & 0xffff;
          153  +    sum2 = rem * sum1;
          154  +    MOD(sum2);
          155  +    sum1 += (adler2 & 0xffff) + BASE - 1;
          156  +    sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;
          157  +    if (sum1 >= BASE) sum1 -= BASE;
          158  +    if (sum1 >= BASE) sum1 -= BASE;
          159  +    if (sum2 >= (BASE << 1)) sum2 -= (BASE << 1);
          160  +    if (sum2 >= BASE) sum2 -= BASE;
          161  +    return sum1 | (sum2 << 16);
          162  +}
          163  +
          164  +/* ========================================================================= */
          165  +uLong ZEXPORT adler32_combine(adler1, adler2, len2)
          166  +    uLong adler1;
          167  +    uLong adler2;
          168  +    z_off_t len2;
          169  +{
          170  +    return adler32_combine_(adler1, adler2, len2);
          171  +}
          172  +
          173  +uLong ZEXPORT adler32_combine64(adler1, adler2, len2)
          174  +    uLong adler1;
          175  +    uLong adler2;
          176  +    z_off64_t len2;
          177  +{
          178  +    return adler32_combine_(adler1, adler2, len2);
          179  +}

Added compat/zlib/amiga/Makefile.pup.

            1  +# Amiga powerUP (TM) Makefile
            2  +# makefile for libpng and SAS C V6.58/7.00 PPC compiler
            3  +# Copyright (C) 1998 by Andreas R. Kleinert
            4  +
            5  +LIBNAME	= libzip.a
            6  +
            7  +CC	= scppc
            8  +CFLAGS	= NOSTKCHK NOSINT OPTIMIZE OPTGO OPTPEEP OPTINLOCAL OPTINL \
            9  +	  OPTLOOP OPTRDEP=8 OPTDEP=8 OPTCOMP=8 NOVER
           10  +AR	= ppc-amigaos-ar cr
           11  +RANLIB	= ppc-amigaos-ranlib
           12  +LD	= ppc-amigaos-ld -r
           13  +LDFLAGS	= -o
           14  +LDLIBS	= LIB:scppc.a LIB:end.o
           15  +RM	= delete quiet
           16  +
           17  +OBJS = adler32.o compress.o crc32.o gzclose.o gzlib.o gzread.o gzwrite.o \
           18  +       uncompr.o deflate.o trees.o zutil.o inflate.o infback.o inftrees.o inffast.o
           19  +
           20  +TEST_OBJS = example.o minigzip.o
           21  +
           22  +all: example minigzip
           23  +
           24  +check: test
           25  +test: all
           26  +	example
           27  +	echo hello world | minigzip | minigzip -d
           28  +
           29  +$(LIBNAME): $(OBJS)
           30  +	$(AR) $@ $(OBJS)
           31  +	-$(RANLIB) $@
           32  +
           33  +example: example.o $(LIBNAME)
           34  +	$(LD) $(LDFLAGS) $@ LIB:c_ppc.o $@.o $(LIBNAME) $(LDLIBS)
           35  +
           36  +minigzip: minigzip.o $(LIBNAME)
           37  +	$(LD) $(LDFLAGS) $@ LIB:c_ppc.o $@.o $(LIBNAME) $(LDLIBS)
           38  +
           39  +mostlyclean: clean
           40  +clean:
           41  +	$(RM) *.o example minigzip $(LIBNAME) foo.gz
           42  +
           43  +zip:
           44  +	zip -ul9 zlib README ChangeLog Makefile Make????.??? Makefile.?? \
           45  +	  descrip.mms *.[ch]
           46  +
           47  +tgz:
           48  +	cd ..; tar cfz zlib/zlib.tgz zlib/README zlib/ChangeLog zlib/Makefile \
           49  +	  zlib/Make????.??? zlib/Makefile.?? zlib/descrip.mms zlib/*.[ch]
           50  +
           51  +# DO NOT DELETE THIS LINE -- make depend depends on it.
           52  +
           53  +adler32.o: zlib.h zconf.h
           54  +compress.o: zlib.h zconf.h
           55  +crc32.o: crc32.h zlib.h zconf.h
           56  +deflate.o: deflate.h zutil.h zlib.h zconf.h
           57  +example.o: zlib.h zconf.h
           58  +gzclose.o: zlib.h zconf.h gzguts.h
           59  +gzlib.o: zlib.h zconf.h gzguts.h
           60  +gzread.o: zlib.h zconf.h gzguts.h
           61  +gzwrite.o: zlib.h zconf.h gzguts.h
           62  +inffast.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h
           63  +inflate.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h
           64  +infback.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h
           65  +inftrees.o: zutil.h zlib.h zconf.h inftrees.h
           66  +minigzip.o: zlib.h zconf.h
           67  +trees.o: deflate.h zutil.h zlib.h zconf.h trees.h
           68  +uncompr.o: zlib.h zconf.h
           69  +zutil.o: zutil.h zlib.h zconf.h

Added compat/zlib/amiga/Makefile.sas.

            1  +# SMakefile for zlib
            2  +# Modified from the standard UNIX Makefile Copyright Jean-loup Gailly
            3  +# Osma Ahvenlampi <Osma.Ahvenlampi@hut.fi>
            4  +# Amiga, SAS/C 6.56 & Smake
            5  +
            6  +CC=sc
            7  +CFLAGS=OPT
            8  +#CFLAGS=OPT CPU=68030
            9  +#CFLAGS=DEBUG=LINE
           10  +LDFLAGS=LIB z.lib
           11  +
           12  +SCOPTIONS=OPTSCHED OPTINLINE OPTALIAS OPTTIME OPTINLOCAL STRMERGE \
           13  +       NOICONS PARMS=BOTH NOSTACKCHECK UTILLIB NOVERSION ERRORREXX \
           14  +       DEF=POSTINC
           15  +
           16  +OBJS = adler32.o compress.o crc32.o gzclose.o gzlib.o gzread.o gzwrite.o \
           17  +       uncompr.o deflate.o trees.o zutil.o inflate.o infback.o inftrees.o inffast.o
           18  +
           19  +TEST_OBJS = example.o minigzip.o
           20  +
           21  +all: SCOPTIONS example minigzip
           22  +
           23  +check: test
           24  +test: all
           25  +	example
           26  +	echo hello world | minigzip | minigzip -d
           27  +
           28  +install: z.lib
           29  +	copy clone zlib.h zconf.h INCLUDE:
           30  +	copy clone z.lib LIB:
           31  +
           32  +z.lib: $(OBJS)
           33  +	oml z.lib r $(OBJS)
           34  +
           35  +example: example.o z.lib
           36  +	$(CC) $(CFLAGS) LINK TO $@ example.o $(LDFLAGS)
           37  +
           38  +minigzip: minigzip.o z.lib
           39  +	$(CC) $(CFLAGS) LINK TO $@ minigzip.o $(LDFLAGS)
           40  +
           41  +mostlyclean: clean
           42  +clean:
           43  +	-delete force quiet example minigzip *.o z.lib foo.gz *.lnk SCOPTIONS
           44  +
           45  +SCOPTIONS: Makefile.sas
           46  +	copy to $@ <from <
           47  +$(SCOPTIONS)
           48  +<
           49  +
           50  +# DO NOT DELETE THIS LINE -- make depend depends on it.
           51  +
           52  +adler32.o: zlib.h zconf.h
           53  +compress.o: zlib.h zconf.h
           54  +crc32.o: crc32.h zlib.h zconf.h
           55  +deflate.o: deflate.h zutil.h zlib.h zconf.h
           56  +example.o: zlib.h zconf.h
           57  +gzclose.o: zlib.h zconf.h gzguts.h
           58  +gzlib.o: zlib.h zconf.h gzguts.h
           59  +gzread.o: zlib.h zconf.h gzguts.h
           60  +gzwrite.o: zlib.h zconf.h gzguts.h
           61  +inffast.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h
           62  +inflate.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h
           63  +infback.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h
           64  +inftrees.o: zutil.h zlib.h zconf.h inftrees.h
           65  +minigzip.o: zlib.h zconf.h
           66  +trees.o: deflate.h zutil.h zlib.h zconf.h trees.h
           67  +uncompr.o: zlib.h zconf.h
           68  +zutil.o: zutil.h zlib.h zconf.h

Added compat/zlib/as400/bndsrc.

            1  +STRPGMEXP PGMLVL(*CURRENT) SIGNATURE('ZLIB')
            2  +
            3  +/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/
            4  +/*   Version 1.1.3 entry points.                                    */
            5  +/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/
            6  +
            7  +/********************************************************************/
            8  +/*   *MODULE      ADLER32      ZLIB         01/02/01  00:15:09      */
            9  +/********************************************************************/
           10  +
           11  +  EXPORT SYMBOL("adler32")
           12  +
           13  +/********************************************************************/
           14  +/*   *MODULE      COMPRESS     ZLIB         01/02/01  00:15:09      */
           15  +/********************************************************************/
           16  +
           17  +  EXPORT SYMBOL("compress")
           18  +  EXPORT SYMBOL("compress2")
           19  +
           20  +/********************************************************************/
           21  +/*   *MODULE      CRC32        ZLIB         01/02/01  00:15:09      */
           22  +/********************************************************************/
           23  +
           24  +  EXPORT SYMBOL("crc32")
           25  +  EXPORT SYMBOL("get_crc_table")
           26  +
           27  +/********************************************************************/
           28  +/*   *MODULE      DEFLATE      ZLIB         01/02/01  00:15:09      */
           29  +/********************************************************************/
           30  +
           31  +  EXPORT SYMBOL("deflate")
           32  +  EXPORT SYMBOL("deflateEnd")
           33  +  EXPORT SYMBOL("deflateSetDictionary")
           34  +  EXPORT SYMBOL("deflateCopy")
           35  +  EXPORT SYMBOL("deflateReset")
           36  +  EXPORT SYMBOL("deflateParams")
           37  +  EXPORT SYMBOL("deflatePrime")
           38  +  EXPORT SYMBOL("deflateInit_")
           39  +  EXPORT SYMBOL("deflateInit2_")
           40  +
           41  +/********************************************************************/
           42  +/*   *MODULE      GZIO         ZLIB         01/02/01  00:15:09      */
           43  +/********************************************************************/
           44  +
           45  +  EXPORT SYMBOL("gzopen")
           46  +  EXPORT SYMBOL("gzdopen")
           47  +  EXPORT SYMBOL("gzsetparams")
           48  +  EXPORT SYMBOL("gzread")
           49  +  EXPORT SYMBOL("gzwrite")
           50  +  EXPORT SYMBOL("gzprintf")
           51  +  EXPORT SYMBOL("gzputs")
           52  +  EXPORT SYMBOL("gzgets")
           53  +  EXPORT SYMBOL("gzputc")
           54  +  EXPORT SYMBOL("gzgetc")
           55  +  EXPORT SYMBOL("gzflush")
           56  +  EXPORT SYMBOL("gzseek")
           57  +  EXPORT SYMBOL("gzrewind")
           58  +  EXPORT SYMBOL("gztell")
           59  +  EXPORT SYMBOL("gzeof")
           60  +  EXPORT SYMBOL("gzclose")
           61  +  EXPORT SYMBOL("gzerror")
           62  +
           63  +/********************************************************************/
           64  +/*   *MODULE      INFLATE      ZLIB         01/02/01  00:15:09      */
           65  +/********************************************************************/
           66  +
           67  +  EXPORT SYMBOL("inflate")
           68  +  EXPORT SYMBOL("inflateEnd")
           69  +  EXPORT SYMBOL("inflateSetDictionary")
           70  +  EXPORT SYMBOL("inflateSync")
           71  +  EXPORT SYMBOL("inflateReset")
           72  +  EXPORT SYMBOL("inflateInit_")
           73  +  EXPORT SYMBOL("inflateInit2_")
           74  +  EXPORT SYMBOL("inflateSyncPoint")
           75  +
           76  +/********************************************************************/
           77  +/*   *MODULE      UNCOMPR      ZLIB         01/02/01  00:15:09      */
           78  +/********************************************************************/
           79  +
           80  +  EXPORT SYMBOL("uncompress")
           81  +
           82  +/********************************************************************/
           83  +/*   *MODULE      ZUTIL        ZLIB         01/02/01  00:15:09      */
           84  +/********************************************************************/
           85  +
           86  +  EXPORT SYMBOL("zlibVersion")
           87  +  EXPORT SYMBOL("zError")
           88  +
           89  +/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/
           90  +/*   Version 1.2.1 additional entry points.                         */
           91  +/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/
           92  +
           93  +/********************************************************************/
           94  +/*   *MODULE      COMPRESS     ZLIB         01/02/01  00:15:09      */
           95  +/********************************************************************/
           96  +
           97  +  EXPORT SYMBOL("compressBound")
           98  +
           99  +/********************************************************************/
          100  +/*   *MODULE      DEFLATE      ZLIB         01/02/01  00:15:09      */
          101  +/********************************************************************/
          102  +
          103  +  EXPORT SYMBOL("deflateBound")
          104  +
          105  +/********************************************************************/
          106  +/*   *MODULE      GZIO         ZLIB         01/02/01  00:15:09      */
          107  +/********************************************************************/
          108  +
          109  +  EXPORT SYMBOL("gzungetc")
          110  +  EXPORT SYMBOL("gzclearerr")
          111  +
          112  +/********************************************************************/
          113  +/*   *MODULE      INFBACK      ZLIB         01/02/01  00:15:09      */
          114  +/********************************************************************/
          115  +
          116  +  EXPORT SYMBOL("inflateBack")
          117  +  EXPORT SYMBOL("inflateBackEnd")
          118  +  EXPORT SYMBOL("inflateBackInit_")
          119  +
          120  +/********************************************************************/
          121  +/*   *MODULE      INFLATE      ZLIB         01/02/01  00:15:09      */
          122  +/********************************************************************/
          123  +
          124  +  EXPORT SYMBOL("inflateCopy")
          125  +
          126  +/********************************************************************/
          127  +/*   *MODULE      ZUTIL        ZLIB         01/02/01  00:15:09      */
          128  +/********************************************************************/
          129  +
          130  +  EXPORT SYMBOL("zlibCompileFlags")
          131  +
          132  +/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/
          133  +/*   Version 1.2.5 additional entry points.                         */
          134  +/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/
          135  +
          136  +/********************************************************************/
          137  +/*   *MODULE      ADLER32      ZLIB         01/02/01  00:15:09      */
          138  +/********************************************************************/
          139  +
          140  +  EXPORT SYMBOL("adler32_combine")
          141  +  EXPORT SYMBOL("adler32_combine64")
          142  +
          143  +/********************************************************************/
          144  +/*   *MODULE      CRC32        ZLIB         01/02/01  00:15:09      */
          145  +/********************************************************************/
          146  +
          147  +  EXPORT SYMBOL("crc32_combine")
          148  +  EXPORT SYMBOL("crc32_combine64")
          149  +
          150  +/********************************************************************/
          151  +/*   *MODULE      GZLIB        ZLIB         01/02/01  00:15:09      */
          152  +/********************************************************************/
          153  +
          154  +  EXPORT SYMBOL("gzbuffer")
          155  +  EXPORT SYMBOL("gzoffset")
          156  +  EXPORT SYMBOL("gzoffset64")
          157  +  EXPORT SYMBOL("gzopen64")
          158  +  EXPORT SYMBOL("gzseek64")
          159  +  EXPORT SYMBOL("gztell64")
          160  +
          161  +/********************************************************************/
          162  +/*   *MODULE      GZREAD       ZLIB         01/02/01  00:15:09      */
          163  +/********************************************************************/
          164  +
          165  +  EXPORT SYMBOL("gzclose_r")
          166  +
          167  +/********************************************************************/
          168  +/*   *MODULE      GZWRITE      ZLIB         01/02/01  00:15:09      */
          169  +/********************************************************************/
          170  +
          171  +  EXPORT SYMBOL("gzclose_w")
          172  +
          173  +/********************************************************************/
          174  +/*   *MODULE      INFLATE      ZLIB         01/02/01  00:15:09      */
          175  +/********************************************************************/
          176  +
          177  +  EXPORT SYMBOL("inflateMark")
          178  +  EXPORT SYMBOL("inflatePrime")
          179  +  EXPORT SYMBOL("inflateReset2")
          180  +  EXPORT SYMBOL("inflateUndermine")
          181  +
          182  +/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/
          183  +/*   Version 1.2.6 additional entry points.                         */
          184  +/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/
          185  +
          186  +/********************************************************************/
          187  +/*   *MODULE      DEFLATE      ZLIB         01/02/01  00:15:09      */
          188  +/********************************************************************/
          189  +
          190  +  EXPORT SYMBOL("deflateResetKeep")
          191  +  EXPORT SYMBOL("deflatePending")
          192  +
          193  +/********************************************************************/
          194  +/*   *MODULE      GZWRITE      ZLIB         01/02/01  00:15:09      */
          195  +/********************************************************************/
          196  +
          197  +  EXPORT SYMBOL("gzgetc_")
          198  +
          199  +/********************************************************************/
          200  +/*   *MODULE      INFLATE      ZLIB         01/02/01  00:15:09      */
          201  +/********************************************************************/
          202  +
          203  +  EXPORT SYMBOL("inflateResetKeep")
          204  +
          205  +ENDPGMEXP

Added compat/zlib/as400/compile.clp.

            1  +/******************************************************************************/
            2  +/*                                                                            */
            3  +/*  ZLIB                                                                      */
            4  +/*                                                                            */
            5  +/*    Compile sources into modules and link them into a service program.      */
            6  +/*                                                                            */
            7  +/******************************************************************************/
            8  +
            9  +             PGM
           10  +
           11  +/*      Configuration adjustable parameters.                                  */
           12  +
           13  +             DCL        VAR(&SRCLIB) TYPE(*CHAR) LEN(10) +
           14  +                          VALUE('ZLIB')                         /* Source library. */
           15  +             DCL        VAR(&SRCFILE) TYPE(*CHAR) LEN(10) +
           16  +                          VALUE('SOURCES')                      /* Source member file. */
           17  +             DCL        VAR(&CTLFILE) TYPE(*CHAR) LEN(10) +
           18  +                          VALUE('TOOLS')                        /* Control member file. */
           19  +
           20  +             DCL        VAR(&MODLIB) TYPE(*CHAR) LEN(10) +
           21  +                          VALUE('ZLIB')                         /* Module library. */
           22  +
           23  +             DCL        VAR(&SRVLIB) TYPE(*CHAR) LEN(10) +
           24  +                          VALUE('LGPL')                         /* Service program library. */
           25  +
           26  +             DCL        VAR(&CFLAGS) TYPE(*CHAR) +
           27  +                          VALUE('OPTIMIZE(40)')                 /* Compile options. */
           28  +
           29  +             DCL        VAR(&TGTRLS) TYPE(*CHAR) +
           30  +                          VALUE('V5R3M0')                       /* Target release. */
           31  +
           32  +
           33  +/*      Working storage.                                                      */
           34  +
           35  +             DCL        VAR(&CMDLEN) TYPE(*DEC) LEN(15 5) VALUE(300)    /* Command length. */
           36  +             DCL        VAR(&CMD) TYPE(*CHAR) LEN(512)
           37  +             DCL        VAR(&FIXDCMD) TYPE(*CHAR) LEN(512)
           38  +
           39  +
           40  +/*      Compile sources into modules.                                         */
           41  +
           42  +             CHGVAR     VAR(&FIXDCMD) VALUE('CRTCMOD' *BCAT &CFLAGS *BCAT      +
           43  +                        'SYSIFCOPT(*IFS64IO)' *BCAT                            +
           44  +                        'DEFINE(''_LARGEFILE64_SOURCE''' *BCAT                 +
           45  +                        '''_LFS64_LARGEFILE=1'') TGTRLS(' *TCAT &TGTRLS *TCAT  +
           46  +                        ') SRCFILE(' *TCAT &SRCLIB *TCAT '/' *TCAT             +
           47  +                        &SRCFILE *TCAT ') MODULE(' *TCAT &MODLIB *TCAT '/')
           48  +
           49  +
           50  +             CHGVAR     VAR(&CMD) VALUE(&FIXDCMD *TCAT 'ADLER32)')
           51  +             CALL       PGM(QCMDEXC) PARM(&CMD &CMDLEN)
           52  +
           53  +             CHGVAR     VAR(&CMD) VALUE(&FIXDCMD *TCAT 'COMPRESS)')
           54  +             CALL       PGM(QCMDEXC) PARM(&CMD &CMDLEN)
           55  +
           56  +             CHGVAR     VAR(&CMD) VALUE(&FIXDCMD *TCAT 'CRC32)')
           57  +             CALL       PGM(QCMDEXC) PARM(&CMD &CMDLEN)
           58  +
           59  +             CHGVAR     VAR(&CMD) VALUE(&FIXDCMD *TCAT 'DEFLATE)')
           60  +             CALL       PGM(QCMDEXC) PARM(&CMD &CMDLEN)
           61  +
           62  +             CHGVAR     VAR(&CMD) VALUE(&FIXDCMD *TCAT 'GZCLOSE)')
           63  +             CALL       PGM(QCMDEXC) PARM(&CMD &CMDLEN)
           64  +
           65  +             CHGVAR     VAR(&CMD) VALUE(&FIXDCMD *TCAT 'GZLIB)')
           66  +             CALL       PGM(QCMDEXC) PARM(&CMD &CMDLEN)
           67  +
           68  +             CHGVAR     VAR(&CMD) VALUE(&FIXDCMD *TCAT 'GZREAD)')
           69  +             CALL       PGM(QCMDEXC) PARM(&CMD &CMDLEN)
           70  +
           71  +             CHGVAR     VAR(&CMD) VALUE(&FIXDCMD *TCAT 'GZWRITE)')
           72  +             CALL       PGM(QCMDEXC) PARM(&CMD &CMDLEN)
           73  +
           74  +             CHGVAR     VAR(&CMD) VALUE(&FIXDCMD *TCAT 'INFBACK)')
           75  +             CALL       PGM(QCMDEXC) PARM(&CMD &CMDLEN)
           76  +
           77  +             CHGVAR     VAR(&CMD) VALUE(&FIXDCMD *TCAT 'INFFAST)')
           78  +             CALL       PGM(QCMDEXC) PARM(&CMD &CMDLEN)
           79  +
           80  +             CHGVAR     VAR(&CMD) VALUE(&FIXDCMD *TCAT 'INFLATE)')
           81  +             CALL       PGM(QCMDEXC) PARM(&CMD &CMDLEN)
           82  +
           83  +             CHGVAR     VAR(&CMD) VALUE(&FIXDCMD *TCAT 'INFTREES)')
           84  +             CALL       PGM(QCMDEXC) PARM(&CMD &CMDLEN)
           85  +
           86  +             CHGVAR     VAR(&CMD) VALUE(&FIXDCMD *TCAT 'TREES)')
           87  +             CALL       PGM(QCMDEXC) PARM(&CMD &CMDLEN)
           88  +
           89  +             CHGVAR     VAR(&CMD) VALUE(&FIXDCMD *TCAT 'UNCOMPR)')
           90  +             CALL       PGM(QCMDEXC) PARM(&CMD &CMDLEN)
           91  +
           92  +             CHGVAR     VAR(&CMD) VALUE(&FIXDCMD *TCAT 'ZUTIL)')
           93  +             CALL       PGM(QCMDEXC) PARM(&CMD &CMDLEN)
           94  +
           95  +
           96  +/*      Link modules into a service program.                                  */
           97  +
           98  +             CRTSRVPGM  SRVPGM(&SRVLIB/ZLIB) +
           99  +                          MODULE(&MODLIB/ADLER32     &MODLIB/COMPRESS    +
          100  +                                 &MODLIB/CRC32       &MODLIB/DEFLATE     +
          101  +                                 &MODLIB/GZCLOSE     &MODLIB/GZLIB       +
          102  +                                 &MODLIB/GZREAD      &MODLIB/GZWRITE     +
          103  +                                 &MODLIB/INFBACK     &MODLIB/INFFAST     +
          104  +                                 &MODLIB/INFLATE     &MODLIB/INFTREES    +
          105  +                                 &MODLIB/TREES       &MODLIB/UNCOMPR     +
          106  +                                 &MODLIB/ZUTIL)                          +
          107  +                          SRCFILE(&SRCLIB/&CTLFILE) SRCMBR(BNDSRC)       +
          108  +                          TEXT('ZLIB 1.2.7') TGTRLS(&TGTRLS)
          109  +
          110  +             ENDPGM

Added compat/zlib/as400/readme.txt.

            1  +        ZLIB version 1.2.7 for AS400 installation instructions
            2  +
            3  +I) From an AS400 *SAVF file:
            4  +
            5  +1)      Unpacking archive to an AS400 save file
            6  +
            7  +On the AS400:
            8  +
            9  +_       Create the ZLIB AS400 library:
           10  +
           11  +        CRTLIB LIB(ZLIB) TYPE(*PROD) TEXT('ZLIB compression API library')
           12  +
           13  +_       Create a work save file, for example:
           14  +
           15  +                CRTSAVF FILE(ZLIB/ZLIBSAVF)
           16  +
           17  +On a PC connected to the target AS400:
           18  +
           19  +_       Unpack the save file image to a PC file "ZLIBSAVF"
           20  +_       Upload this file into the save file on the AS400, for example
           21  +                using ftp in BINARY mode.
           22  +
           23  +
           24  +2)      Populating the ZLIB AS400 source library
           25  +
           26  +On the AS400:
           27  +
           28  +_       Extract the saved objects into the ZLIB AS400 library using:
           29  +
           30  +RSTOBJ OBJ(*ALL) SAVLIB(ZLIB) DEV(*SAVF) SAVF(ZLIB/ZLIBSAVF) RSTLIB(ZLIB)
           31  +
           32  +
           33  +3)      Customize installation:
           34  +
           35  +_       Edit CL member ZLIB/TOOLS(COMPILE) and change parameters if needed,
           36  +                according to the comments.
           37  +
           38  +_       Compile this member with:
           39  +
           40  +        CRTCLPGM PGM(ZLIB/COMPILE) SRCFILE(ZLIB/TOOLS) SRCMBR(COMPILE)
           41  +
           42  +
           43  +4)      Compile and generate the service program:
           44  +
           45  +_       This can now be done by executing:
           46  +
           47  +        CALL PGM(ZLIB/COMPILE)
           48  +
           49  +
           50  +
           51  +II) From the original source distribution:
           52  +
           53  +1)      On the AS400, create the source library:
           54  +
           55  +        CRTLIB LIB(ZLIB) TYPE(*PROD) TEXT('ZLIB compression API library')
           56  +
           57  +2)      Create the source files:
           58  +
           59  +        CRTSRCPF FILE(ZLIB/SOURCES) RCDLEN(112) TEXT('ZLIB library modules')
           60  +        CRTSRCPF FILE(ZLIB/H)       RCDLEN(112) TEXT('ZLIB library includes')
           61  +        CRTSRCPF FILE(ZLIB/TOOLS)   RCDLEN(112) TEXT('ZLIB library control utilities')
           62  +
           63  +3)      From the machine hosting the distribution files, upload them (with
           64  +                FTP in text mode, for example) according to the following table:
           65  +
           66  +    Original    AS400   AS400    AS400 AS400
           67  +    file        file    member   type  description
           68  +                SOURCES                Original ZLIB C subprogram sources
           69  +    adler32.c           ADLER32  C     ZLIB - Compute the Adler-32 checksum of a dta strm
           70  +    compress.c          COMPRESS C     ZLIB - Compress a memory buffer
           71  +    crc32.c             CRC32    C     ZLIB - Compute the CRC-32 of a data stream
           72  +    deflate.c           DEFLATE  C     ZLIB - Compress data using the deflation algorithm
           73  +    gzclose.c           GZCLOSE  C     ZLIB - Close .gz files
           74  +    gzlib.c             GZLIB    C     ZLIB - Miscellaneous .gz files IO support
           75  +    gzread.c            GZREAD   C     ZLIB - Read .gz files
           76  +    gzwrite.c           GZWRITE  C     ZLIB - Write .gz files
           77  +    infback.c           INFBACK  C     ZLIB - Inflate using a callback interface
           78  +    inffast.c           INFFAST  C     ZLIB - Fast proc. literals & length/distance pairs
           79  +    inflate.c           INFLATE  C     ZLIB - Interface to inflate modules
           80  +    inftrees.c          INFTREES C     ZLIB - Generate Huffman trees for efficient decode
           81  +    trees.c             TREES    C     ZLIB - Output deflated data using Huffman coding
           82  +    uncompr.c           UNCOMPR  C     ZLIB - Decompress a memory buffer
           83  +    zutil.c             ZUTIL    C     ZLIB - Target dependent utility functions
           84  +                H                      Original ZLIB C and ILE/RPG include files
           85  +    crc32.h             CRC32    C     ZLIB - CRC32 tables
           86  +    deflate.h           DEFLATE  C     ZLIB - Internal compression state
           87  +    gzguts.h            GZGUTS   C     ZLIB - Definitions for the gzclose module
           88  +    inffast.h           INFFAST  C     ZLIB - Header to use inffast.c
           89  +    inffixed.h          INFFIXED C     ZLIB - Table for decoding fixed codes
           90  +    inflate.h           INFLATE  C     ZLIB - Internal inflate state definitions
           91  +    inftrees.h          INFTREES C     ZLIB - Header to use inftrees.c
           92  +    trees.h             TREES    C     ZLIB - Created automatically with -DGEN_TREES_H
           93  +    zconf.h             ZCONF    C     ZLIB - Compression library configuration
           94  +    zlib.h              ZLIB     C     ZLIB - Compression library C user interface
           95  +    as400/zlib.inc      ZLIB.INC RPGLE ZLIB - Compression library ILE RPG user interface
           96  +    zutil.h             ZUTIL    C     ZLIB - Internal interface and configuration
           97  +                TOOLS                  Building source software & AS/400 README
           98  +    as400/bndsrc        BNDSRC         Entry point exportation list
           99  +    as400/compile.clp   COMPILE  CLP   Compile sources & generate service program
          100  +    as400/readme.txt    README   TXT   Installation instructions
          101  +
          102  +4)      Continue as in I)3).
          103  +
          104  +
          105  +
          106  +
          107  +Notes:  For AS400 ILE RPG programmers, a /copy member defining the ZLIB
          108  +                API prototypes for ILE RPG can be found in ZLIB/H(ZLIB.INC).
          109  +                Please read comments in this member for more information.
          110  +
          111  +        Remember that most foreign textual data are ASCII coded: this
          112  +                implementation does not handle conversion from/to ASCII, so
          113  +                text data code conversions must be done explicitely.
          114  +
          115  +        Mainly for the reason above, always open zipped files in binary mode.

Added compat/zlib/as400/zlib.inc.

            1  +      *  ZLIB.INC - Interface to the general purpose compression library
            2  +      *
            3  +      *  ILE RPG400 version by Patrick Monnerat, DATASPHERE.
            4  +      *  Version 1.2.7
            5  +      *
            6  +      *
            7  +      *  WARNING:
            8  +      *     Procedures inflateInit(), inflateInit2(), deflateInit(),
            9  +      *         deflateInit2() and inflateBackInit() need to be called with
           10  +      *         two additional arguments:
           11  +      *         the package version string and the stream control structure.
           12  +      *         size. This is needed because RPG lacks some macro feature.
           13  +      *         Call these procedures as:
           14  +      *             inflateInit(...: ZLIB_VERSION: %size(z_stream))
           15  +      *
           16  +      /if not defined(ZLIB_H_)
           17  +      /define ZLIB_H_
           18  +      *
           19  +      **************************************************************************
           20  +      *                               Constants
           21  +      **************************************************************************
           22  +      *
           23  +      *  Versioning information.
           24  +      *
           25  +     D ZLIB_VERSION    C                   '1.2.7'
           26  +     D ZLIB_VERNUM     C                   X'1270'
           27  +     D ZLIB_VER_MAJOR  C                   1
           28  +     D ZLIB_VER_MINOR  C                   2
           29  +     D ZLIB_VER_REVISION...
           30  +     D                 C                   7
           31  +     D ZLIB_VER_SUBREVISION...
           32  +     D                 C                   0
           33  +      *
           34  +      *  Other equates.
           35  +      *
           36  +     D Z_NO_FLUSH      C                   0
           37  +     D Z_PARTIAL_FLUSH...
           38  +     D                 C                   1
           39  +     D Z_SYNC_FLUSH    C                   2
           40  +     D Z_FULL_FLUSH    C                   3
           41  +     D Z_FINISH        C                   4
           42  +     D Z_BLOCK         C                   5
           43  +     D Z_TREES         C                   6
           44  +      *
           45  +     D Z_OK            C                   0
           46  +     D Z_STREAM_END    C                   1
           47  +     D Z_NEED_DICT     C                   2
           48  +     D Z_ERRNO         C                   -1
           49  +     D Z_STREAM_ERROR  C                   -2
           50  +     D Z_DATA_ERROR    C                   -3
           51  +     D Z_MEM_ERROR     C                   -4
           52  +     D Z_BUF_ERROR     C                   -5
           53  +     DZ_VERSION_ERROR  C                   -6
           54  +      *
           55  +     D Z_NO_COMPRESSION...
           56  +     D                 C                   0
           57  +     D Z_BEST_SPEED    C                   1
           58  +     D Z_BEST_COMPRESSION...
           59  +     D                 C                   9
           60  +     D Z_DEFAULT_COMPRESSION...
           61  +     D                 C                   -1
           62  +      *
           63  +     D Z_FILTERED      C                   1
           64  +     D Z_HUFFMAN_ONLY  C                   2
           65  +     D Z_RLE           C                   3
           66  +     D Z_DEFAULT_STRATEGY...
           67  +     D                 C                   0
           68  +      *
           69  +     D Z_BINARY        C                   0
           70  +     D Z_ASCII         C                   1
           71  +     D Z_UNKNOWN       C                   2
           72  +      *
           73  +     D Z_DEFLATED      C                   8
           74  +      *
           75  +     D Z_NULL          C                   0
           76  +      *
           77  +      **************************************************************************
           78  +      *                                 Types
           79  +      **************************************************************************
           80  +      *
           81  +     D z_streamp       S               *                                        Stream struct ptr
           82  +     D gzFile          S               *                                        File pointer
           83  +     D z_off_t         S             10i 0                                      Stream offsets
           84  +     D z_off64_t       S             20i 0                                      Stream offsets
           85  +      *
           86  +      **************************************************************************
           87  +      *                               Structures
           88  +      **************************************************************************
           89  +      *
           90  +      *  The GZIP encode/decode stream support structure.
           91  +      *
           92  +     D z_stream        DS                  align based(z_streamp)
           93  +     D  zs_next_in                     *                                        Next input byte
           94  +     D  zs_avail_in                  10U 0                                      Byte cnt at next_in
           95  +     D  zs_total_in                  10U 0                                      Total bytes read
           96  +     D  zs_next_out                    *                                        Output buffer ptr
           97  +     D  zs_avail_out                 10U 0                                      Room left @ next_out
           98  +     D  zs_total_out                 10U 0                                      Total bytes written
           99  +     D  zs_msg                         *                                        Last errmsg or null
          100  +     D  zs_state                       *                                        Internal state
          101  +     D  zs_zalloc                      *   procptr                              Int. state allocator
          102  +     D  zs_free                        *   procptr                              Int. state dealloc.
          103  +     D  zs_opaque                      *                                        Private alloc. data
          104  +     D  zs_data_type                 10i 0                                      ASC/BIN best guess
          105  +     D  zs_adler                     10u 0                                      Uncompr. adler32 val
          106  +     D                               10U 0                                      Reserved
          107  +     D                               10U 0                                      Ptr. alignment
          108  +      *
          109  +      **************************************************************************
          110  +      *                     Utility function prototypes
          111  +      **************************************************************************
          112  +      *
          113  +     D compress        PR            10I 0 extproc('compress')
          114  +     D  dest                      65535    options(*varsize)                    Destination buffer
          115  +     D  destLen                      10U 0                                      Destination length
          116  +     D  source                    65535    const options(*varsize)              Source buffer
          117  +     D  sourceLen                    10u 0 value                                Source length
          118  +      *
          119  +     D compress2       PR            10I 0 extproc('compress2')
          120  +     D  dest                      65535    options(*varsize)                    Destination buffer
          121  +     D  destLen                      10U 0                                      Destination length
          122  +     D  source                    65535    const options(*varsize)              Source buffer
          123  +     D  sourceLen                    10U 0 value                                Source length
          124  +     D  level                        10I 0 value                                Compression level
          125  +      *
          126  +     D compressBound   PR            10U 0 extproc('compressBound')
          127  +     D  sourceLen                    10U 0 value
          128  +      *
          129  +     D uncompress      PR            10I 0 extproc('uncompress')
          130  +     D  dest                      65535    options(*varsize)                    Destination buffer
          131  +     D  destLen                      10U 0                                      Destination length
          132  +     D  source                    65535    const options(*varsize)              Source buffer
          133  +     D  sourceLen                    10U 0 value                                Source length
          134  +      *
          135  +      /if not defined(LARGE_FILES)
          136  +     D gzopen          PR                  extproc('gzopen')
          137  +     D                                     like(gzFile)
          138  +     D  path                           *   value options(*string)               File pathname
          139  +     D  mode                           *   value options(*string)               Open mode
          140  +      /else
          141  +     D gzopen          PR                  extproc('gzopen64')
          142  +     D                                     like(gzFile)
          143  +     D  path                           *   value options(*string)               File pathname
          144  +     D  mode                           *   value options(*string)               Open mode
          145  +      *
          146  +     D gzopen64        PR                  extproc('gzopen64')
          147  +     D                                     like(gzFile)
          148  +     D  path                           *   value options(*string)               File pathname
          149  +     D  mode                           *   value options(*string)               Open mode
          150  +      /endif
          151  +      *
          152  +     D gzdopen         PR                  extproc('gzdopen')
          153  +     D                                     like(gzFile)
          154  +     D  fd                           10I 0 value                                File descriptor
          155  +     D  mode                           *   value options(*string)               Open mode
          156  +      *
          157  +     D gzbuffer        PR            10I 0 extproc('gzbuffer')
          158  +     D  file                               value like(gzFile)                   File pointer
          159  +     D  size                         10U 0 value
          160  +      *
          161  +     D gzsetparams     PR            10I 0 extproc('gzsetparams')
          162  +     D  file                               value like(gzFile)                   File pointer
          163  +     D  level                        10I 0 value
          164  +     D  strategy                     10I 0 value
          165  +      *
          166  +     D gzread          PR            10I 0 extproc('gzread')
          167  +     D  file                               value like(gzFile)                   File pointer
          168  +     D  buf                       65535    options(*varsize)                    Buffer
          169  +     D  len                          10u 0 value                                Buffer length
          170  +      *
          171  +     D gzwrite         PR            10I 0 extproc('gzwrite')
          172  +     D  file                               value like(gzFile)                   File pointer
          173  +     D  buf                       65535    const options(*varsize)              Buffer
          174  +     D  len                          10u 0 value                                Buffer length
          175  +      *
          176  +     D gzputs          PR            10I 0 extproc('gzputs')
          177  +     D  file                               value like(gzFile)                   File pointer
          178  +     D  s                              *   value options(*string)               String to output
          179  +      *
          180  +     D gzgets          PR              *   extproc('gzgets')
          181  +     D  file                               value like(gzFile)                   File pointer
          182  +     D  buf                       65535    options(*varsize)                    Read buffer
          183  +     D  len                          10i 0 value                                Buffer length
          184  +      *
          185  +     D gzputc          PR            10i 0 extproc('gzputc')
          186  +     D  file                               value like(gzFile)                   File pointer
          187  +     D  c                            10I 0 value                                Character to write
          188  +      *
          189  +     D gzgetc          PR            10i 0 extproc('gzgetc')
          190  +     D  file                               value like(gzFile)                   File pointer
          191  +      *
          192  +     D gzgetc_         PR            10i 0 extproc('gzgetc_')
          193  +     D  file                               value like(gzFile)                   File pointer
          194  +      *
          195  +     D gzungetc        PR            10i 0 extproc('gzungetc')
          196  +     D  c                            10I 0 value                                Character to push
          197  +     D  file                               value like(gzFile)                   File pointer
          198  +      *
          199  +     D gzflush         PR            10i 0 extproc('gzflush')
          200  +     D  file                               value like(gzFile)                   File pointer
          201  +     D  flush                        10I 0 value                                Type of flush
          202  +      *
          203  +      /if not defined(LARGE_FILES)
          204  +     D gzseek          PR                  extproc('gzseek')
          205  +     D                                     like(z_off_t)
          206  +     D  file                               value like(gzFile)                   File pointer
          207  +     D  offset                             value like(z_off_t)                  Offset
          208  +     D  whence                       10i 0 value                                Origin
          209  +      /else
          210  +     D gzseek          PR                  extproc('gzseek64')
          211  +     D                                     like(z_off_t)
          212  +     D  file                               value like(gzFile)                   File pointer
          213  +     D  offset                             value like(z_off_t)                  Offset
          214  +     D  whence                       10i 0 value                                Origin
          215  +      *
          216  +     D gzseek64        PR                  extproc('gzseek64')
          217  +     D                                     like(z_off64_t)
          218  +     D  file                               value like(gzFile)                   File pointer
          219  +     D  offset                             value like(z_off64_t)                Offset
          220  +     D  whence                       10i 0 value                                Origin
          221  +      /endif
          222  +      *
          223  +     D gzrewind        PR            10i 0 extproc('gzrewind')
          224  +     D  file                               value like(gzFile)                   File pointer
          225  +      *
          226  +      /if not defined(LARGE_FILES)
          227  +     D gztell          PR                  extproc('gztell')
          228  +     D                                     like(z_off_t)
          229  +     D  file                               value like(gzFile)                   File pointer
          230  +      /else
          231  +     D gztell          PR                  extproc('gztell64')
          232  +     D                                     like(z_off_t)
          233  +     D  file                               value like(gzFile)                   File pointer
          234  +      *
          235  +     D gztell64        PR                  extproc('gztell64')
          236  +     D                                     like(z_off64_t)
          237  +     D  file                               value like(gzFile)                   File pointer
          238  +      /endif
          239  +      *
          240  +      /if not defined(LARGE_FILES)
          241  +     D gzoffset        PR                  extproc('gzoffset')
          242  +     D                                     like(z_off_t)
          243  +     D  file                               value like(gzFile)                   File pointer
          244  +      /else
          245  +     D gzoffset        PR                  extproc('gzoffset64')
          246  +     D                                     like(z_off_t)
          247  +     D  file                               value like(gzFile)                   File pointer
          248  +      *
          249  +     D gzoffset64      PR                  extproc('gzoffset64')
          250  +     D                                     like(z_off64_t)
          251  +     D  file                               value like(gzFile)                   File pointer
          252  +      /endif
          253  +      *
          254  +     D gzeof           PR            10i 0 extproc('gzeof')
          255  +     D  file                               value like(gzFile)                   File pointer
          256  +      *
          257  +     D gzclose_r       PR            10i 0 extproc('gzclose_r')
          258  +     D  file                               value like(gzFile)                   File pointer
          259  +      *
          260  +     D gzclose_w       PR            10i 0 extproc('gzclose_w')
          261  +     D  file                               value like(gzFile)                   File pointer
          262  +      *
          263  +     D gzclose         PR            10i 0 extproc('gzclose')
          264  +     D  file                               value like(gzFile)                   File pointer
          265  +      *
          266  +     D gzerror         PR              *   extproc('gzerror')                   Error string
          267  +     D  file                               value like(gzFile)                   File pointer
          268  +     D  errnum                       10I 0                                      Error code
          269  +      *
          270  +     D gzclearerr      PR                  extproc('gzclearerr')
          271  +     D  file                               value like(gzFile)                   File pointer
          272  +      *
          273  +      **************************************************************************
          274  +      *                        Basic function prototypes
          275  +      **************************************************************************
          276  +      *
          277  +     D zlibVersion     PR              *   extproc('zlibVersion')               Version string
          278  +      *
          279  +     D deflateInit     PR            10I 0 extproc('deflateInit_')              Init. compression
          280  +     D  strm                               like(z_stream)                       Compression stream
          281  +     D  level                        10I 0 value                                Compression level
          282  +     D  version                        *   value options(*string)               Version string
          283  +     D  stream_size                  10i 0 value                                Stream struct. size
          284  +      *
          285  +     D deflate         PR            10I 0 extproc('deflate')                   Compress data
          286  +     D  strm                               like(z_stream)                       Compression stream
          287  +     D  flush                        10I 0 value                                Flush type required
          288  +      *
          289  +     D deflateEnd      PR            10I 0 extproc('deflateEnd')                Termin. compression
          290  +     D  strm                               like(z_stream)                       Compression stream
          291  +      *
          292  +     D inflateInit     PR            10I 0 extproc('inflateInit_')              Init. expansion
          293  +     D  strm                               like(z_stream)                       Expansion stream
          294  +     D  version                        *   value options(*string)               Version string
          295  +     D  stream_size                  10i 0 value                                Stream struct. size
          296  +      *
          297  +     D inflate         PR            10I 0 extproc('inflate')                   Expand data
          298  +     D  strm                               like(z_stream)                       Expansion stream
          299  +     D  flush                        10I 0 value                                Flush type required
          300  +      *
          301  +     D inflateEnd      PR            10I 0 extproc('inflateEnd')                Termin. expansion
          302  +     D  strm                               like(z_stream)                       Expansion stream
          303  +      *
          304  +      **************************************************************************
          305  +      *                        Advanced function prototypes
          306  +      **************************************************************************
          307  +      *
          308  +     D deflateInit2    PR            10I 0 extproc('deflateInit2_')             Init. compression
          309  +     D  strm                               like(z_stream)                       Compression stream
          310  +     D  level                        10I 0 value                                Compression level
          311  +     D  method                       10I 0 value                                Compression method
          312  +     D  windowBits                   10I 0 value                                log2(window size)
          313  +     D  memLevel                     10I 0 value                                Mem/cmpress tradeoff
          314  +     D  strategy                     10I 0 value                                Compression stategy
          315  +     D  version                        *   value options(*string)               Version string
          316  +     D  stream_size                  10i 0 value                                Stream struct. size
          317  +      *
          318  +     D deflateSetDictionary...
          319  +     D                 PR            10I 0 extproc('deflateSetDictionary')      Init. dictionary
          320  +     D  strm                               like(z_stream)                       Compression stream
          321  +     D  dictionary                65535    const options(*varsize)              Dictionary bytes
          322  +     D  dictLength                   10U 0 value                                Dictionary length
          323  +      *
          324  +     D deflateCopy     PR            10I 0 extproc('deflateCopy')               Compress strm 2 strm
          325  +     D  dest                               like(z_stream)                       Destination stream
          326  +     D  source                             like(z_stream)                       Source stream
          327  +      *
          328  +     D deflateReset    PR            10I 0 extproc('deflateReset')              End and init. stream
          329  +     D  strm                               like(z_stream)                       Compression stream
          330  +      *
          331  +     D deflateParams   PR            10I 0 extproc('deflateParams')             Change level & strat
          332  +     D  strm                               like(z_stream)                       Compression stream
          333  +     D  level                        10I 0 value                                Compression level
          334  +     D  strategy                     10I 0 value                                Compression stategy
          335  +      *
          336  +     D deflateBound    PR            10U 0 extproc('deflateBound')              Change level & strat
          337  +     D  strm                               like(z_stream)                       Compression stream
          338  +     D  sourcelen                    10U 0 value                                Compression level
          339  +      *
          340  +     D deflatePending  PR            10I 0 extproc('deflatePending')            Change level & strat
          341  +     D  strm                               like(z_stream)                       Compression stream
          342  +     D  pending                      10U 0                                      Pending bytes
          343  +     D  bits                         10I 0                                      Pending bits
          344  +      *
          345  +     D deflatePrime    PR            10I 0 extproc('deflatePrime')              Change level & strat
          346  +     D  strm                               like(z_stream)                       Compression stream
          347  +     D  bits                         10I 0 value                                # of bits to insert
          348  +     D  value                        10I 0 value                                Bits to insert
          349  +      *
          350  +     D inflateInit2    PR            10I 0 extproc('inflateInit2_')             Init. expansion
          351  +     D  strm                               like(z_stream)                       Expansion stream
          352  +     D  windowBits                   10I 0 value                                log2(window size)
          353  +     D  version                        *   value options(*string)               Version string
          354  +     D  stream_size                  10i 0 value                                Stream struct. size
          355  +      *
          356  +     D inflateSetDictionary...
          357  +     D                 PR            10I 0 extproc('inflateSetDictionary')      Init. dictionary
          358  +     D  strm                               like(z_stream)                       Expansion stream
          359  +     D  dictionary                65535    const options(*varsize)              Dictionary bytes
          360  +     D  dictLength                   10U 0 value                                Dictionary length
          361  +      *
          362  +     D inflateSync     PR            10I 0 extproc('inflateSync')               Sync. expansion
          363  +     D  strm                               like(z_stream)                       Expansion stream
          364  +      *
          365  +     D inflateCopy     PR            10I 0 extproc('inflateCopy')
          366  +     D  dest                               like(z_stream)                       Destination stream
          367  +     D  source                             like(z_stream)                       Source stream
          368  +      *
          369  +     D inflateReset    PR            10I 0 extproc('inflateReset')              End and init. stream
          370  +     D  strm                               like(z_stream)                       Expansion stream
          371  +      *
          372  +     D inflateReset2   PR            10I 0 extproc('inflateReset2')             End and init. stream
          373  +     D  strm                               like(z_stream)                       Expansion stream
          374  +     D  windowBits                   10I 0 value                                Log2(buffer size)
          375  +      *
          376  +     D inflatePrime    PR            10I 0 extproc('inflatePrime')              Insert bits
          377  +     D  strm                               like(z_stream)                       Expansion stream
          378  +     D  bits                         10I 0 value                                Bit count
          379  +     D  value                        10I 0 value                                Bits to insert
          380  +      *
          381  +     D inflateMark     PR            10I 0 extproc('inflateMark')               Get inflate info
          382  +     D  strm                               like(z_stream)                       Expansion stream
          383  +      *
          384  +     D inflateBackInit...
          385  +     D                 PR            10I 0 extproc('inflateBackInit_')
          386  +     D  strm                               like(z_stream)                       Expansion stream
          387  +     D  windowBits                   10I 0 value                                Log2(buffer size)
          388  +     D  window                    65535    options(*varsize)                    Buffer
          389  +     D  version                        *   value options(*string)               Version string
          390  +     D  stream_size                  10i 0 value                                Stream struct. size
          391  +      *
          392  +     D inflateBack     PR            10I 0 extproc('inflateBack')
          393  +     D  strm                               like(z_stream)                       Expansion stream
          394  +     D  in                             *   value procptr                        Input function
          395  +     D  in_desc                        *   value                                Input descriptor
          396  +     D  out                            *   value procptr                        Output function
          397  +     D  out_desc                       *   value                                Output descriptor
          398  +      *
          399  +     D inflateBackEnd  PR            10I 0 extproc('inflateBackEnd')
          400  +     D  strm                               like(z_stream)                       Expansion stream
          401  +      *
          402  +     D zlibCompileFlags...
          403  +     D                 PR            10U 0 extproc('zlibCompileFlags')
          404  +      *
          405  +      **************************************************************************
          406  +      *                        Checksum function prototypes
          407  +      **************************************************************************
          408  +      *
          409  +     D adler32         PR            10U 0 extproc('adler32')                   New checksum
          410  +     D  adler                        10U 0 value                                Old checksum
          411  +     D  buf                       65535    const options(*varsize)              Bytes to accumulate
          412  +     D  len                          10U 0 value                                Buffer length
          413  +      *
          414  +     D crc32           PR            10U 0 extproc('crc32')                     New checksum
          415  +     D  crc                          10U 0 value                                Old checksum
          416  +     D  buf                       65535    const options(*varsize)              Bytes to accumulate
          417  +     D  len                          10U 0 value                                Buffer length
          418  +      *
          419  +      **************************************************************************
          420  +      *                     Miscellaneous function prototypes
          421  +      **************************************************************************
          422  +      *
          423  +     D zError          PR              *   extproc('zError')                    Error string
          424  +     D  err                          10I 0 value                                Error code
          425  +      *
          426  +     D inflateSyncPoint...
          427  +     D                 PR            10I 0 extproc('inflateSyncPoint')
          428  +     D  strm                               like(z_stream)                       Expansion stream
          429  +      *
          430  +     D get_crc_table   PR              *   extproc('get_crc_table')             Ptr to ulongs
          431  +      *
          432  +     D inflateUndermine...
          433  +     D                 PR            10I 0 extproc('inflateUndermine')
          434  +     D  strm                               like(z_stream)                       Expansion stream
          435  +     D  arg                          10I 0 value                                Error code
          436  +      *
          437  +     D inflateResetKeep...
          438  +     D                 PR            10I 0 extproc('inflateResetKeep')          End and init. stream
          439  +     D  strm                               like(z_stream)                       Expansion stream
          440  +      *
          441  +     D deflateResetKeep...
          442  +     D                 PR            10I 0 extproc('deflateResetKeep')          End and init. stream
          443  +     D  strm                               like(z_stream)                       Expansion stream
          444  +      *
          445  +      /endif

Added compat/zlib/compress.c.

            1  +/* compress.c -- compress a memory buffer
            2  + * Copyright (C) 1995-2005 Jean-loup Gailly.
            3  + * For conditions of distribution and use, see copyright notice in zlib.h
            4  + */
            5  +
            6  +/* @(#) $Id$ */
            7  +
            8  +#define ZLIB_INTERNAL
            9  +#include "zlib.h"
           10  +
           11  +/* ===========================================================================
           12  +     Compresses the source buffer into the destination buffer. The level
           13  +   parameter has the same meaning as in deflateInit.  sourceLen is the byte
           14  +   length of the source buffer. Upon entry, destLen is the total size of the
           15  +   destination buffer, which must be at least 0.1% larger than sourceLen plus
           16  +   12 bytes. Upon exit, destLen is the actual size of the compressed buffer.
           17  +
           18  +     compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
           19  +   memory, Z_BUF_ERROR if there was not enough room in the output buffer,
           20  +   Z_STREAM_ERROR if the level parameter is invalid.
           21  +*/
           22  +int ZEXPORT compress2 (dest, destLen, source, sourceLen, level)
           23  +    Bytef *dest;
           24  +    uLongf *destLen;
           25  +    const Bytef *source;
           26  +    uLong sourceLen;
           27  +    int level;
           28  +{
           29  +    z_stream stream;
           30  +    int err;
           31  +
           32  +    stream.next_in = (Bytef*)source;
           33  +    stream.avail_in = (uInt)sourceLen;
           34  +#ifdef MAXSEG_64K
           35  +    /* Check for source > 64K on 16-bit machine: */
           36  +    if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
           37  +#endif
           38  +    stream.next_out = dest;
           39  +    stream.avail_out = (uInt)*destLen;
           40  +    if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
           41  +
           42  +    stream.zalloc = (alloc_func)0;
           43  +    stream.zfree = (free_func)0;
           44  +    stream.opaque = (voidpf)0;
           45  +
           46  +    err = deflateInit(&stream, level);
           47  +    if (err != Z_OK) return err;
           48  +
           49  +    err = deflate(&stream, Z_FINISH);
           50  +    if (err != Z_STREAM_END) {
           51  +        deflateEnd(&stream);
           52  +        return err == Z_OK ? Z_BUF_ERROR : err;
           53  +    }
           54  +    *destLen = stream.total_out;
           55  +
           56  +    err = deflateEnd(&stream);
           57  +    return err;
           58  +}
           59  +
           60  +/* ===========================================================================
           61  + */
           62  +int ZEXPORT compress (dest, destLen, source, sourceLen)
           63  +    Bytef *dest;
           64  +    uLongf *destLen;
           65  +    const Bytef *source;
           66  +    uLong sourceLen;
           67  +{
           68  +    return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
           69  +}
           70  +
           71  +/* ===========================================================================
           72  +     If the default memLevel or windowBits for deflateInit() is changed, then
           73  +   this function needs to be updated.
           74  + */
           75  +uLong ZEXPORT compressBound (sourceLen)
           76  +    uLong sourceLen;
           77  +{
           78  +    return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) +
           79  +           (sourceLen >> 25) + 13;
           80  +}

Added compat/zlib/configure.

            1  +#!/bin/sh
            2  +# configure script for zlib.
            3  +#
            4  +# Normally configure builds both a static and a shared library.
            5  +# If you want to build just a static library, use: ./configure --static
            6  +#
            7  +# To impose specific compiler or flags or install directory, use for example:
            8  +#    prefix=$HOME CC=cc CFLAGS="-O4" ./configure
            9  +# or for csh/tcsh users:
           10  +#    (setenv prefix $HOME; setenv CC cc; setenv CFLAGS "-O4"; ./configure)
           11  +
           12  +# Incorrect settings of CC or CFLAGS may prevent creating a shared library.
           13  +# If you have problems, try without defining CC and CFLAGS before reporting
           14  +# an error.
           15  +
           16  +# start off configure.log
           17  +echo -------------------- >> configure.log
           18  +echo $0 $* >> configure.log
           19  +date >> configure.log
           20  +
           21  +# set command prefix for cross-compilation
           22  +if [ -n "${CHOST}" ]; then
           23  +    uname="`echo "${CHOST}" | sed -e 's/^[^-]*-\([^-]*\)$/\1/' -e 's/^[^-]*-[^-]*-\([^-]*\)$/\1/' -e 's/^[^-]*-[^-]*-\([^-]*\)-.*$/\1/'`"
           24  +    CROSS_PREFIX="${CHOST}-"
           25  +fi
           26  +
           27  +# destination name for static library
           28  +STATICLIB=libz.a
           29  +
           30  +# extract zlib version numbers from zlib.h
           31  +VER=`sed -n -e '/VERSION "/s/.*"\(.*\)".*/\1/p' < zlib.h`
           32  +VER3=`sed -n -e '/VERSION "/s/.*"\([0-9]*\\.[0-9]*\\.[0-9]*\).*/\1/p' < zlib.h`
           33  +VER2=`sed -n -e '/VERSION "/s/.*"\([0-9]*\\.[0-9]*\)\\..*/\1/p' < zlib.h`
           34  +VER1=`sed -n -e '/VERSION "/s/.*"\([0-9]*\)\\..*/\1/p' < zlib.h`
           35  +
           36  +# establish commands for library building
           37  +if "${CROSS_PREFIX}ar" --version >/dev/null 2>/dev/null || test $? -lt 126; then
           38  +    AR=${AR-"${CROSS_PREFIX}ar"}
           39  +    test -n "${CROSS_PREFIX}" && echo Using ${AR} | tee -a configure.log
           40  +else
           41  +    AR=${AR-"ar"}
           42  +    test -n "${CROSS_PREFIX}" && echo Using ${AR} | tee -a configure.log
           43  +fi
           44  +ARFLAGS=${ARFLAGS-"rc"}
           45  +if "${CROSS_PREFIX}ranlib" --version >/dev/null 2>/dev/null || test $? -lt 126; then
           46  +    RANLIB=${RANLIB-"${CROSS_PREFIX}ranlib"}
           47  +    test -n "${CROSS_PREFIX}" && echo Using ${RANLIB} | tee -a configure.log
           48  +else
           49  +    RANLIB=${RANLIB-"ranlib"}
           50  +fi
           51  +if "${CROSS_PREFIX}nm" --version >/dev/null 2>/dev/null || test $? -lt 126; then
           52  +    NM=${NM-"${CROSS_PREFIX}nm"}
           53  +    test -n "${CROSS_PREFIX}" && echo Using ${NM} | tee -a configure.log
           54  +else
           55  +    NM=${NM-"nm"}
           56  +fi
           57  +
           58  +# set defaults before processing command line options
           59  +LDCONFIG=${LDCONFIG-"ldconfig"}
           60  +LDSHAREDLIBC="${LDSHAREDLIBC--lc}"
           61  +ARCHS=
           62  +prefix=${prefix-/usr/local}
           63  +exec_prefix=${exec_prefix-'${prefix}'}
           64  +libdir=${libdir-'${exec_prefix}/lib'}
           65  +sharedlibdir=${sharedlibdir-'${libdir}'}
           66  +includedir=${includedir-'${prefix}/include'}
           67  +mandir=${mandir-'${prefix}/share/man'}
           68  +shared_ext='.so'
           69  +shared=1
           70  +solo=0
           71  +cover=0
           72  +zprefix=0
           73  +build64=0
           74  +gcc=0
           75  +old_cc="$CC"
           76  +old_cflags="$CFLAGS"
           77  +OBJC='$(OBJZ) $(OBJG)'
           78  +PIC_OBJC='$(PIC_OBJZ) $(PIC_OBJG)'
           79  +
           80  +# process command line options
           81  +while test $# -ge 1
           82  +do
           83  +case "$1" in
           84  +    -h* | --help)
           85  +      echo 'usage:' | tee -a configure.log
           86  +      echo '  configure [--zprefix] [--prefix=PREFIX]  [--eprefix=EXPREFIX]' | tee -a configure.log
           87  +      echo '    [--static] [--64] [--libdir=LIBDIR] [--sharedlibdir=LIBDIR]' | tee -a configure.log
           88  +      echo '    [--includedir=INCLUDEDIR] [--archs="-arch i386 -arch x86_64"]' | tee -a configure.log
           89  +        exit 0 ;;
           90  +    -p*=* | --prefix=*) prefix=`echo $1 | sed 's/.*=//'`; shift ;;
           91  +    -e*=* | --eprefix=*) exec_prefix=`echo $1 | sed 's/.*=//'`; shift ;;
           92  +    -l*=* | --libdir=*) libdir=`echo $1 | sed 's/.*=//'`; shift ;;
           93  +    --sharedlibdir=*) sharedlibdir=`echo $1 | sed 's/.*=//'`; shift ;;
           94  +    -i*=* | --includedir=*) includedir=`echo $1 | sed 's/.*=//'`;shift ;;
           95  +    -u*=* | --uname=*) uname=`echo $1 | sed 's/.*=//'`;shift ;;
           96  +    -p* | --prefix) prefix="$2"; shift; shift ;;
           97  +    -e* | --eprefix) exec_prefix="$2"; shift; shift ;;
           98  +    -l* | --libdir) libdir="$2"; shift; shift ;;
           99  +    -i* | --includedir) includedir="$2"; shift; shift ;;
          100  +    -s* | --shared | --enable-shared) shared=1; shift ;;
          101  +    -t | --static) shared=0; shift ;;
          102  +    --solo) solo=1; shift ;;
          103  +    --cover) cover=1; shift ;;
          104  +    -z* | --zprefix) zprefix=1; shift ;;
          105  +    -6* | --64) build64=1; shift ;;
          106  +    -a*=* | --archs=*) ARCHS=`echo $1 | sed 's/.*=//'`; shift ;;
          107  +    --sysconfdir=*) echo "ignored option: --sysconfdir" | tee -a configure.log; shift ;;
          108  +    --localstatedir=*) echo "ignored option: --localstatedir" | tee -a configure.log; shift ;;
          109  +    *) echo "unknown option: $1"; echo "$0 --help for help" | tee -a configure.log; exit 1 ;;
          110  +    esac
          111  +done
          112  +
          113  +# define functions for testing compiler and library characteristics and logging the results
          114  +test=ztest$$
          115  +
          116  +show()
          117  +{
          118  +  case "$*" in
          119  +    *$test.c*)
          120  +      echo === $test.c === >> configure.log
          121  +      cat $test.c >> configure.log
          122  +      echo === >> configure.log;;
          123  +  esac
          124  +  echo $* >> configure.log
          125  +}
          126  +
          127  +cat > $test.c <<EOF
          128  +#error error
          129  +EOF
          130  +if ($CC -c $CFLAGS $test.c) 2>/dev/null; then
          131  +  try()
          132  +  {
          133  +    show $*
          134  +    test "`( $* ) 2>&1 | tee -a configure.log`" = ""
          135  +  }
          136  +  echo - using any output from compiler to indicate an error >> configure.log
          137  +else
          138  +  try()
          139  +  {
          140  +    show $*
          141  +    ( $* ) >> configure.log 2>&1
          142  +    ret=$?
          143  +    if test $ret -ne 0; then
          144  +      echo "(exit code "$ret")" >> configure.log
          145  +    fi
          146  +    return $ret
          147  +  }
          148  +fi
          149  +
          150  +tryboth()
          151  +{
          152  +  show $*
          153  +  got=`( $* ) 2>&1`
          154  +  ret=$?
          155  +  printf %s "$got" >> configure.log
          156  +  if test $ret -ne 0; then
          157  +    return $ret
          158  +  fi
          159  +  test "$got" = ""
          160  +}
          161  +
          162  +echo >> configure.log
          163  +
          164  +# check for gcc vs. cc and set compile and link flags based on the system identified by uname
          165  +cat > $test.c <<EOF
          166  +extern int getchar();
          167  +int hello() {return getchar();}
          168  +EOF
          169  +
          170  +test -z "$CC" && echo Checking for ${CROSS_PREFIX}gcc... | tee -a configure.log
          171  +cc=${CC-${CROSS_PREFIX}gcc}
          172  +cflags=${CFLAGS-"-O3"}
          173  +# to force the asm version use: CFLAGS="-O3 -DASMV" ./configure
          174  +case "$cc" in
          175  +  *gcc*) gcc=1 ;;
          176  +  *clang*) gcc=1 ;;
          177  +esac
          178  +case `$cc -v 2>&1` in
          179  +  *gcc*) gcc=1 ;;
          180  +esac
          181  +
          182  +show $cc -c $cflags $test.c
          183  +if test "$gcc" -eq 1 && ($cc -c $cflags $test.c) >> configure.log 2>&1; then
          184  +  echo ... using gcc >> configure.log
          185  +  CC="$cc"
          186  +  CFLAGS="${CFLAGS--O3} ${ARCHS}"
          187  +  SFLAGS="${CFLAGS--O3} -fPIC"
          188  +  LDFLAGS="${LDFLAGS} ${ARCHS}"
          189  +  if test $build64 -eq 1; then
          190  +    CFLAGS="${CFLAGS} -m64"
          191  +    SFLAGS="${SFLAGS} -m64"
          192  +  fi
          193  +  if test "${ZLIBGCCWARN}" = "YES"; then
          194  +    CFLAGS="${CFLAGS} -Wall -Wextra -pedantic"
          195  +  fi
          196  +  if test -z "$uname"; then
          197  +    uname=`(uname -s || echo unknown) 2>/dev/null`
          198  +  fi
          199  +  case "$uname" in
          200  +  Linux* | linux* | GNU | GNU/* | solaris*)
          201  +        LDSHARED=${LDSHARED-"$cc -shared -Wl,-soname,libz.so.1,--version-script,zlib.map"} ;;
          202  +  *BSD | *bsd* | DragonFly)
          203  +        LDSHARED=${LDSHARED-"$cc -shared -Wl,-soname,libz.so.1,--version-script,zlib.map"}
          204  +        LDCONFIG="ldconfig -m" ;;
          205  +  CYGWIN* | Cygwin* | cygwin* | OS/2*)
          206  +        EXE='.exe' ;;
          207  +  MINGW* | mingw*)
          208  +# temporary bypass
          209  +        rm -f $test.[co] $test $test$shared_ext
          210  +        echo "Please use win32/Makefile.gcc instead." | tee -a configure.log
          211  +        exit 1
          212  +        LDSHARED=${LDSHARED-"$cc -shared"}
          213  +        LDSHAREDLIBC=""
          214  +        EXE='.exe' ;;
          215  +  QNX*)  # This is for QNX6. I suppose that the QNX rule below is for QNX2,QNX4
          216  +         # (alain.bonnefoy@icbt.com)
          217  +                 LDSHARED=${LDSHARED-"$cc -shared -Wl,-hlibz.so.1"} ;;
          218  +  HP-UX*)
          219  +         LDSHARED=${LDSHARED-"$cc -shared $SFLAGS"}
          220  +         case `(uname -m || echo unknown) 2>/dev/null` in
          221  +         ia64)
          222  +                 shared_ext='.so'
          223  +                 SHAREDLIB='libz.so' ;;
          224  +         *)
          225  +                 shared_ext='.sl'
          226  +                 SHAREDLIB='libz.sl' ;;
          227  +         esac ;;
          228  +  Darwin* | darwin*)
          229  +             shared_ext='.dylib'
          230  +             SHAREDLIB=libz$shared_ext
          231  +             SHAREDLIBV=libz.$VER$shared_ext
          232  +             SHAREDLIBM=libz.$VER1$shared_ext
          233  +             LDSHARED=${LDSHARED-"$cc -dynamiclib -install_name $libdir/$SHAREDLIBM -compatibility_version $VER1 -current_version $VER3"}
          234  +             AR="/usr/bin/libtool"
          235  +             ARFLAGS="-o" ;;
          236  +  *)             LDSHARED=${LDSHARED-"$cc -shared"} ;;
          237  +  esac
          238  +else
          239  +  # find system name and corresponding cc options
          240  +  CC=${CC-cc}
          241  +  gcc=0
          242  +  echo ... using $CC >> configure.log
          243  +  if test -z "$uname"; then
          244  +    uname=`(uname -sr || echo unknown) 2>/dev/null`
          245  +  fi
          246  +  case "$uname" in
          247  +  HP-UX*)    SFLAGS=${CFLAGS-"-O +z"}
          248  +             CFLAGS=${CFLAGS-"-O"}
          249  +#            LDSHARED=${LDSHARED-"ld -b +vnocompatwarnings"}
          250  +             LDSHARED=${LDSHARED-"ld -b"}
          251  +         case `(uname -m || echo unknown) 2>/dev/null` in
          252  +         ia64)
          253  +             shared_ext='.so'
          254  +             SHAREDLIB='libz.so' ;;
          255  +         *)
          256  +             shared_ext='.sl'
          257  +             SHAREDLIB='libz.sl' ;;
          258  +         esac ;;
          259  +  IRIX*)     SFLAGS=${CFLAGS-"-ansi -O2 -rpath ."}
          260  +             CFLAGS=${CFLAGS-"-ansi -O2"}
          261  +             LDSHARED=${LDSHARED-"cc -shared -Wl,-soname,libz.so.1"} ;;
          262  +  OSF1\ V4*) SFLAGS=${CFLAGS-"-O -std1"}
          263  +             CFLAGS=${CFLAGS-"-O -std1"}
          264  +             LDFLAGS="${LDFLAGS} -Wl,-rpath,."
          265  +             LDSHARED=${LDSHARED-"cc -shared  -Wl,-soname,libz.so -Wl,-msym -Wl,-rpath,$(libdir) -Wl,-set_version,${VER}:1.0"} ;;
          266  +  OSF1*)     SFLAGS=${CFLAGS-"-O -std1"}
          267  +             CFLAGS=${CFLAGS-"-O -std1"}
          268  +             LDSHARED=${LDSHARED-"cc -shared -Wl,-soname,libz.so.1"} ;;
          269  +  QNX*)      SFLAGS=${CFLAGS-"-4 -O"}
          270  +             CFLAGS=${CFLAGS-"-4 -O"}
          271  +             LDSHARED=${LDSHARED-"cc"}
          272  +             RANLIB=${RANLIB-"true"}
          273  +             AR="cc"
          274  +             ARFLAGS="-A" ;;
          275  +  SCO_SV\ 3.2*) SFLAGS=${CFLAGS-"-O3 -dy -KPIC "}
          276  +             CFLAGS=${CFLAGS-"-O3"}
          277  +             LDSHARED=${LDSHARED-"cc -dy -KPIC -G"} ;;
          278  +  SunOS\ 5* | solaris*)
          279  +         LDSHARED=${LDSHARED-"cc -G -h libz$shared_ext.$VER1"}
          280  +         SFLAGS=${CFLAGS-"-fast -KPIC"}
          281  +         CFLAGS=${CFLAGS-"-fast"}
          282  +         if test $build64 -eq 1; then
          283  +             # old versions of SunPRO/Workshop/Studio don't support -m64,
          284  +             # but newer ones do.  Check for it.
          285  +             flag64=`$CC -flags | egrep -- '^-m64'`
          286  +             if test x"$flag64" != x"" ; then
          287  +                 CFLAGS="${CFLAGS} -m64"
          288  +                 SFLAGS="${SFLAGS} -m64"
          289  +             else
          290  +                 case `(uname -m || echo unknown) 2>/dev/null` in
          291  +                   i86*)
          292  +                     SFLAGS="$SFLAGS -xarch=amd64"
          293  +                     CFLAGS="$CFLAGS -xarch=amd64" ;;
          294  +                   *)
          295  +                     SFLAGS="$SFLAGS -xarch=v9"
          296  +                     CFLAGS="$CFLAGS -xarch=v9" ;;
          297  +                 esac
          298  +             fi
          299  +         fi
          300  +         ;;
          301  +  SunOS\ 4*) SFLAGS=${CFLAGS-"-O2 -PIC"}
          302  +             CFLAGS=${CFLAGS-"-O2"}
          303  +             LDSHARED=${LDSHARED-"ld"} ;;
          304  +  SunStudio\ 9*) SFLAGS=${CFLAGS-"-fast -xcode=pic32 -xtarget=ultra3 -xarch=v9b"}
          305  +             CFLAGS=${CFLAGS-"-fast -xtarget=ultra3 -xarch=v9b"}
          306  +             LDSHARED=${LDSHARED-"cc -xarch=v9b"} ;;
          307  +  UNIX_System_V\ 4.2.0)
          308  +             SFLAGS=${CFLAGS-"-KPIC -O"}
          309  +             CFLAGS=${CFLAGS-"-O"}
          310  +             LDSHARED=${LDSHARED-"cc -G"} ;;
          311  +  UNIX_SV\ 4.2MP)
          312  +             SFLAGS=${CFLAGS-"-Kconform_pic -O"}
          313  +             CFLAGS=${CFLAGS-"-O"}
          314  +             LDSHARED=${LDSHARED-"cc -G"} ;;
          315  +  OpenUNIX\ 5)
          316  +             SFLAGS=${CFLAGS-"-KPIC -O"}
          317  +             CFLAGS=${CFLAGS-"-O"}
          318  +             LDSHARED=${LDSHARED-"cc -G"} ;;
          319  +  AIX*)  # Courtesy of dbakker@arrayasolutions.com
          320  +             SFLAGS=${CFLAGS-"-O -qmaxmem=8192"}
          321  +             CFLAGS=${CFLAGS-"-O -qmaxmem=8192"}
          322  +             LDSHARED=${LDSHARED-"xlc -G"} ;;
          323  +  # send working options for other systems to zlib@gzip.org
          324  +  *)         SFLAGS=${CFLAGS-"-O"}
          325  +             CFLAGS=${CFLAGS-"-O"}
          326  +             LDSHARED=${LDSHARED-"cc -shared"} ;;
          327  +  esac
          328  +fi
          329  +
          330  +# destination names for shared library if not defined above
          331  +SHAREDLIB=${SHAREDLIB-"libz$shared_ext"}
          332  +SHAREDLIBV=${SHAREDLIBV-"libz$shared_ext.$VER"}
          333  +SHAREDLIBM=${SHAREDLIBM-"libz$shared_ext.$VER1"}
          334  +
          335  +echo >> configure.log
          336  +
          337  +# see if shared library build supported
          338  +if test $shared -eq 1; then
          339  +  echo Checking for shared library support... | tee -a configure.log
          340  +  # we must test in two steps (cc then ld), required at least on SunOS 4.x
          341  +  if try $CC -w -c $SFLAGS $test.c &&
          342  +     try $LDSHARED $SFLAGS -o $test$shared_ext $test.o; then
          343  +    echo Building shared library $SHAREDLIBV with $CC. | tee -a configure.log
          344  +  elif test -z "$old_cc" -a -z "$old_cflags"; then
          345  +    echo No shared library support. | tee -a configure.log
          346  +    shared=0;
          347  +  else
          348  +    echo 'No shared library support; try without defining CC and CFLAGS' | tee -a configure.log
          349  +    shared=0;
          350  +  fi
          351  +fi
          352  +if test $shared -eq 0; then
          353  +  LDSHARED="$CC"
          354  +  ALL="static"
          355  +  TEST="all teststatic"
          356  +  SHAREDLIB=""
          357  +  SHAREDLIBV=""
          358  +  SHAREDLIBM=""
          359  +  echo Building static library $STATICLIB version $VER with $CC. | tee -a configure.log
          360  +else
          361  +  ALL="static shared"
          362  +  TEST="all teststatic testshared"
          363  +fi
          364  +
          365  +echo >> configure.log
          366  +
          367  +# check for underscores in external names for use by assembler code
          368  +CPP=${CPP-"$CC -E"}
          369  +case $CFLAGS in
          370  +  *ASMV*)
          371  +    echo >> configure.log
          372  +    show "$NM $test.o | grep _hello"
          373  +    if test "`$NM $test.o | grep _hello | tee -a configure.log`" = ""; then
          374  +      CPP="$CPP -DNO_UNDERLINE"
          375  +      echo Checking for underline in external names... No. | tee -a configure.log
          376  +    else
          377  +      echo Checking for underline in external names... Yes. | tee -a configure.log
          378  +    fi ;;
          379  +esac
          380  +
          381  +echo >> configure.log
          382  +
          383  +# check for large file support, and if none, check for fseeko()
          384  +cat > $test.c <<EOF
          385  +#include <sys/types.h>
          386  +off64_t dummy = 0;
          387  +EOF
          388  +if try $CC -c $CFLAGS -D_LARGEFILE64_SOURCE=1 $test.c; then
          389  +  CFLAGS="${CFLAGS} -D_LARGEFILE64_SOURCE=1"
          390  +  SFLAGS="${SFLAGS} -D_LARGEFILE64_SOURCE=1"
          391  +  ALL="${ALL} all64"
          392  +  TEST="${TEST} test64"
          393  +  echo "Checking for off64_t... Yes." | tee -a configure.log
          394  +  echo "Checking for fseeko... Yes." | tee -a configure.log
          395  +else
          396  +  echo "Checking for off64_t... No." | tee -a configure.log
          397  +  echo >> configure.log
          398  +  cat > $test.c <<EOF
          399  +#include <stdio.h>
          400  +int main(void) {
          401  +  fseeko(NULL, 0, 0);
          402  +  return 0;
          403  +}
          404  +EOF
          405  +  if try $CC $CFLAGS -o $test $test.c; then
          406  +    echo "Checking for fseeko... Yes." | tee -a configure.log
          407  +  else
          408  +    CFLAGS="${CFLAGS} -DNO_FSEEKO"
          409  +    SFLAGS="${SFLAGS} -DNO_FSEEKO"
          410  +    echo "Checking for fseeko... No." | tee -a configure.log
          411  +  fi
          412  +fi
          413  +
          414  +echo >> configure.log
          415  +
          416  +# check for strerror() for use by gz* functions
          417  +cat > $test.c <<EOF
          418  +#include <string.h>
          419  +#include <errno.h>
          420  +int main() { return strlen(strerror(errno)); }
          421  +EOF
          422  +if try $CC $CFLAGS -o $test $test.c; then
          423  +  echo "Checking for strerror... Yes." | tee -a configure.log
          424  +else
          425  +  CFLAGS="${CFLAGS} -DNO_STRERROR"
          426  +  SFLAGS="${SFLAGS} -DNO_STRERROR"
          427  +  echo "Checking for strerror... No." | tee -a configure.log
          428  +fi
          429  +
          430  +# copy clean zconf.h for subsequent edits
          431  +cp -p zconf.h.in zconf.h
          432  +
          433  +echo >> configure.log
          434  +
          435  +# check for unistd.h and save result in zconf.h
          436  +cat > $test.c <<EOF
          437  +#include <unistd.h>
          438  +int main() { return 0; }
          439  +EOF
          440  +if try $CC -c $CFLAGS $test.c; then
          441  +  sed < zconf.h "/^#ifdef HAVE_UNISTD_H.* may be/s/def HAVE_UNISTD_H\(.*\) may be/ 1\1 was/" > zconf.temp.h
          442  +  mv zconf.temp.h zconf.h
          443  +  echo "Checking for unistd.h... Yes." | tee -a configure.log
          444  +else
          445  +  echo "Checking for unistd.h... No." | tee -a configure.log
          446  +fi
          447  +
          448  +echo >> configure.log
          449  +
          450  +# check for stdarg.h and save result in zconf.h
          451  +cat > $test.c <<EOF
          452  +#include <stdarg.h>
          453  +int main() { return 0; }
          454  +EOF
          455  +if try $CC -c $CFLAGS $test.c; then
          456  +  sed < zconf.h "/^#ifdef HAVE_STDARG_H.* may be/s/def HAVE_STDARG_H\(.*\) may be/ 1\1 was/" > zconf.temp.h
          457  +  mv zconf.temp.h zconf.h
          458  +  echo "Checking for stdarg.h... Yes." | tee -a configure.log
          459  +else
          460  +  echo "Checking for stdarg.h... No." | tee -a configure.log
          461  +fi
          462  +
          463  +# if the z_ prefix was requested, save that in zconf.h
          464  +if test $zprefix -eq 1; then
          465  +  sed < zconf.h "/#ifdef Z_PREFIX.* may be/s/def Z_PREFIX\(.*\) may be/ 1\1 was/" > zconf.temp.h
          466  +  mv zconf.temp.h zconf.h
          467  +  echo >> configure.log
          468  +  echo "Using z_ prefix on all symbols." | tee -a configure.log
          469  +fi
          470  +
          471  +# if --solo compilation was requested, save that in zconf.h and remove gz stuff from object lists
          472  +if test $solo -eq 1; then
          473  +  sed '/#define ZCONF_H/a\
          474  +#define Z_SOLO
          475  +
          476  +' < zconf.h > zconf.temp.h
          477  +  mv zconf.temp.h zconf.h
          478  +OBJC='$(OBJZ)'
          479  +PIC_OBJC='$(PIC_OBJZ)'
          480  +fi
          481  +
          482  +# if code coverage testing was requested, use older gcc if defined, e.g. "gcc-4.2" on Mac OS X
          483  +if test $cover -eq 1; then
          484  +  CFLAGS="${CFLAGS} -fprofile-arcs -ftest-coverage"
          485  +  if test -n "$GCC_CLASSIC"; then
          486  +    CC=$GCC_CLASSIC
          487  +  fi
          488  +fi
          489  +
          490  +echo >> configure.log
          491  +
          492  +# conduct a series of tests to resolve eight possible cases of using "vs" or "s" printf functions
          493  +# (using stdarg or not), with or without "n" (proving size of buffer), and with or without a
          494  +# return value.  The most secure result is vsnprintf() with a return value.  snprintf() with a
          495  +# return value is secure as well, but then gzprintf() will be limited to 20 arguments.
          496  +cat > $test.c <<EOF
          497  +#include <stdio.h>
          498  +#include <stdarg.h>
          499  +#include "zconf.h"
          500  +int main()
          501  +{
          502  +#ifndef STDC
          503  +  choke me
          504  +#endif
          505  +  return 0;
          506  +}
          507  +EOF
          508  +if try $CC -c $CFLAGS $test.c; then
          509  +  echo "Checking whether to use vs[n]printf() or s[n]printf()... using vs[n]printf()." | tee -a configure.log
          510  +
          511  +  echo >> configure.log
          512  +  cat > $test.c <<EOF
          513  +#include <stdio.h>
          514  +#include <stdarg.h>
          515  +int mytest(const char *fmt, ...)
          516  +{
          517  +  char buf[20];
          518  +  va_list ap;
          519  +  va_start(ap, fmt);
          520  +  vsnprintf(buf, sizeof(buf), fmt, ap);
          521  +  va_end(ap);
          522  +  return 0;
          523  +}
          524  +int main()
          525  +{
          526  +  return (mytest("Hello%d\n", 1));
          527  +}
          528  +EOF
          529  +  if try $CC $CFLAGS -o $test $test.c; then
          530  +    echo "Checking for vsnprintf() in stdio.h... Yes." | tee -a configure.log
          531  +
          532  +    echo >> configure.log
          533  +    cat >$test.c <<EOF
          534  +#include <stdio.h>
          535  +#include <stdarg.h>
          536  +int mytest(const char *fmt, ...)
          537  +{
          538  +  int n;
          539  +  char buf[20];
          540  +  va_list ap;
          541  +  va_start(ap, fmt);
          542  +  n = vsnprintf(buf, sizeof(buf), fmt, ap);
          543  +  va_end(ap);
          544  +  return n;
          545  +}
          546  +int main()
          547  +{
          548  +  return (mytest("Hello%d\n", 1));
          549  +}
          550  +EOF
          551  +
          552  +    if try $CC -c $CFLAGS $test.c; then
          553  +      echo "Checking for return value of vsnprintf()... Yes." | tee -a configure.log
          554  +    else
          555  +      CFLAGS="$CFLAGS -DHAS_vsnprintf_void"
          556  +      SFLAGS="$SFLAGS -DHAS_vsnprintf_void"
          557  +      echo "Checking for return value of vsnprintf()... No." | tee -a configure.log
          558  +      echo "  WARNING: apparently vsnprintf() does not return a value. zlib" | tee -a configure.log
          559  +      echo "  can build but will be open to possible string-format security" | tee -a configure.log
          560  +      echo "  vulnerabilities." | tee -a configure.log
          561  +    fi
          562  +  else
          563  +    CFLAGS="$CFLAGS -DNO_vsnprintf"
          564  +    SFLAGS="$SFLAGS -DNO_vsnprintf"
          565  +    echo "Checking for vsnprintf() in stdio.h... No." | tee -a configure.log
          566  +    echo "  WARNING: vsnprintf() not found, falling back to vsprintf(). zlib" | tee -a configure.log
          567  +    echo "  can build but will be open to possible buffer-overflow security" | tee -a configure.log
          568  +    echo "  vulnerabilities." | tee -a configure.log
          569  +
          570  +    echo >> configure.log
          571  +    cat >$test.c <<EOF
          572  +#include <stdio.h>
          573  +#include <stdarg.h>
          574  +int mytest(const char *fmt, ...)
          575  +{
          576  +  int n;
          577  +  char buf[20];
          578  +  va_list ap;
          579  +  va_start(ap, fmt);
          580  +  n = vsprintf(buf, fmt, ap);
          581  +  va_end(ap);
          582  +  return n;
          583  +}
          584  +int main()
          585  +{
          586  +  return (mytest("Hello%d\n", 1));
          587  +}
          588  +EOF
          589  +
          590  +    if try $CC -c $CFLAGS $test.c; then
          591  +      echo "Checking for return value of vsprintf()... Yes." | tee -a configure.log
          592  +    else
          593  +      CFLAGS="$CFLAGS -DHAS_vsprintf_void"
          594  +      SFLAGS="$SFLAGS -DHAS_vsprintf_void"
          595  +      echo "Checking for return value of vsprintf()... No." | tee -a configure.log
          596  +      echo "  WARNING: apparently vsprintf() does not return a value. zlib" | tee -a configure.log
          597  +      echo "  can build but will be open to possible string-format security" | tee -a configure.log
          598  +      echo "  vulnerabilities." | tee -a configure.log
          599  +    fi
          600  +  fi
          601  +else
          602  +  echo "Checking whether to use vs[n]printf() or s[n]printf()... using s[n]printf()." | tee -a configure.log
          603  +
          604  +  echo >> configure.log
          605  +  cat >$test.c <<EOF
          606  +#include <stdio.h>
          607  +int mytest()
          608  +{
          609  +  char buf[20];
          610  +  snprintf(buf, sizeof(buf), "%s", "foo");
          611  +  return 0;
          612  +}
          613  +int main()
          614  +{
          615  +  return (mytest());
          616  +}
          617  +EOF
          618  +
          619  +  if try $CC $CFLAGS -o $test $test.c; then
          620  +    echo "Checking for snprintf() in stdio.h... Yes." | tee -a configure.log
          621  +
          622  +    echo >> configure.log
          623  +    cat >$test.c <<EOF
          624  +#include <stdio.h>
          625  +int mytest()
          626  +{
          627  +  char buf[20];
          628  +  return snprintf(buf, sizeof(buf), "%s", "foo");
          629  +}
          630  +int main()
          631  +{
          632  +  return (mytest());
          633  +}
          634  +EOF
          635  +
          636  +    if try $CC -c $CFLAGS $test.c; then
          637  +      echo "Checking for return value of snprintf()... Yes." | tee -a configure.log
          638  +    else
          639  +      CFLAGS="$CFLAGS -DHAS_snprintf_void"
          640  +      SFLAGS="$SFLAGS -DHAS_snprintf_void"
          641  +      echo "Checking for return value of snprintf()... No." | tee -a configure.log
          642  +      echo "  WARNING: apparently snprintf() does not return a value. zlib" | tee -a configure.log
          643  +      echo "  can build but will be open to possible string-format security" | tee -a configure.log
          644  +      echo "  vulnerabilities." | tee -a configure.log
          645  +    fi
          646  +  else
          647  +    CFLAGS="$CFLAGS -DNO_snprintf"
          648  +    SFLAGS="$SFLAGS -DNO_snprintf"
          649  +    echo "Checking for snprintf() in stdio.h... No." | tee -a configure.log
          650  +    echo "  WARNING: snprintf() not found, falling back to sprintf(). zlib" | tee -a configure.log
          651  +    echo "  can build but will be open to possible buffer-overflow security" | tee -a configure.log
          652  +    echo "  vulnerabilities." | tee -a configure.log
          653  +
          654  +    echo >> configure.log
          655  +    cat >$test.c <<EOF
          656  +#include <stdio.h>
          657  +int mytest()
          658  +{
          659  +  char buf[20];
          660  +  return sprintf(buf, "%s", "foo");
          661  +}
          662  +int main()
          663  +{
          664  +  return (mytest());
          665  +}
          666  +EOF
          667  +
          668  +    if try $CC -c $CFLAGS $test.c; then
          669  +      echo "Checking for return value of sprintf()... Yes." | tee -a configure.log
          670  +    else
          671  +      CFLAGS="$CFLAGS -DHAS_sprintf_void"
          672  +      SFLAGS="$SFLAGS -DHAS_sprintf_void"
          673  +      echo "Checking for return value of sprintf()... No." | tee -a configure.log
          674  +      echo "  WARNING: apparently sprintf() does not return a value. zlib" | tee -a configure.log
          675  +      echo "  can build but will be open to possible string-format security" | tee -a configure.log
          676  +      echo "  vulnerabilities." | tee -a configure.log
          677  +    fi
          678  +  fi
          679  +fi
          680  +
          681  +# see if we can hide zlib internal symbols that are linked between separate source files
          682  +if test "$gcc" -eq 1; then
          683  +  echo >> configure.log
          684  +  cat > $test.c <<EOF
          685  +#define ZLIB_INTERNAL __attribute__((visibility ("hidden")))
          686  +int ZLIB_INTERNAL foo;
          687  +int main()
          688  +{
          689  +  return 0;
          690  +}
          691  +EOF
          692  +  if tryboth $CC -c $CFLAGS $test.c; then
          693  +    CFLAGS="$CFLAGS -DHAVE_HIDDEN"
          694  +    SFLAGS="$SFLAGS -DHAVE_HIDDEN"
          695  +    echo "Checking for attribute(visibility) support... Yes." | tee -a configure.log
          696  +  else
          697  +    echo "Checking for attribute(visibility) support... No." | tee -a configure.log
          698  +  fi
          699  +fi
          700  +
          701  +echo >> configure.log
          702  +
          703  +# find a four-byte unsiged integer type for crc calculations
          704  +cat > $test.c <<EOF
          705  +#include <stdio.h>
          706  +#define is32(n,t) for(n=1,k=0;n;n<<=1,k++);if(k==32){puts(t);return 0;}
          707  +int main() {
          708  +    int k;
          709  +    unsigned i;
          710  +    unsigned long l;
          711  +    unsigned short s;
          712  +    is32(i, "unsigned")
          713  +    is32(l, "unsigned long")
          714  +    is32(s, "unsigned short")
          715  +    return 1;
          716  +}
          717  +EOF
          718  +Z_U4=""
          719  +if try $CC $CFLAGS $test.c -o $test && Z_U4=`./$test` && test -n "$Z_U4"; then
          720  +  sed < zconf.h "/#define Z_U4/s/\/\* \.\/configure may/#define Z_U4 $Z_U4   \/* .\/configure put the/" > zconf.temp.h
          721  +  mv zconf.temp.h zconf.h
          722  +  echo "Looking for a four-byte integer type... Found." | tee -a configure.log
          723  +else
          724  +  echo "Looking for a four-byte integer type... Not found." | tee -a configure.log
          725  +fi
          726  +
          727  +# clean up files produced by running the compiler and linker
          728  +rm -f $test.[co] $test $test$shared_ext $test.gcno
          729  +
          730  +# show the results in the log
          731  +echo >> configure.log
          732  +echo ALL = $ALL >> configure.log
          733  +echo AR = $AR >> configure.log
          734  +echo ARFLAGS = $ARFLAGS >> configure.log
          735  +echo CC = $CC >> configure.log
          736  +echo CFLAGS = $CFLAGS >> configure.log
          737  +echo CPP = $CPP >> configure.log
          738  +echo EXE = $EXE >> configure.log
          739  +echo LDCONFIG = $LDCONFIG >> configure.log
          740  +echo LDFLAGS = $LDFLAGS >> configure.log
          741  +echo LDSHARED = $LDSHARED >> configure.log
          742  +echo LDSHAREDLIBC = $LDSHAREDLIBC >> configure.log
          743  +echo OBJC = $OBJC >> configure.log
          744  +echo PIC_OBJC = $PIC_OBJC >> configure.log
          745  +echo RANLIB = $RANLIB >> configure.log
          746  +echo SFLAGS = $SFLAGS >> configure.log
          747  +echo SHAREDLIB = $SHAREDLIB >> configure.log
          748  +echo SHAREDLIBM = $SHAREDLIBM >> configure.log
          749  +echo SHAREDLIBV = $SHAREDLIBV >> configure.log
          750  +echo STATICLIB = $STATICLIB >> configure.log
          751  +echo TEST = $TEST >> configure.log
          752  +echo VER = $VER >> configure.log
          753  +echo Z_U4 = $Z_U4 >> configure.log
          754  +echo exec_prefix = $exec_prefix >> configure.log
          755  +echo includedir = $includedir >> configure.log
          756  +echo libdir = $libdir >> configure.log
          757  +echo mandir = $mandir >> configure.log
          758  +echo prefix = $prefix >> configure.log
          759  +echo sharedlibdir = $sharedlibdir >> configure.log
          760  +echo uname = $uname >> configure.log
          761  +echo -------------------- >> configure.log
          762  +echo >> configure.log
          763  +echo >> configure.log
          764  +
          765  +# udpate Makefile with the configure results
          766  +sed < Makefile.in "
          767  +/^CC *=/s#=.*#=$CC#
          768  +/^CFLAGS *=/s#=.*#=$CFLAGS#
          769  +/^SFLAGS *=/s#=.*#=$SFLAGS#
          770  +/^LDFLAGS *=/s#=.*#=$LDFLAGS#
          771  +/^LDSHARED *=/s#=.*#=$LDSHARED#
          772  +/^CPP *=/s#=.*#=$CPP#
          773  +/^STATICLIB *=/s#=.*#=$STATICLIB#
          774  +/^SHAREDLIB *=/s#=.*#=$SHAREDLIB#
          775  +/^SHAREDLIBV *=/s#=.*#=$SHAREDLIBV#
          776  +/^SHAREDLIBM *=/s#=.*#=$SHAREDLIBM#
          777  +/^AR *=/s#=.*#=$AR#
          778  +/^ARFLAGS *=/s#=.*#=$ARFLAGS#
          779  +/^RANLIB *=/s#=.*#=$RANLIB#
          780  +/^LDCONFIG *=/s#=.*#=$LDCONFIG#
          781  +/^LDSHAREDLIBC *=/s#=.*#=$LDSHAREDLIBC#
          782  +/^EXE *=/s#=.*#=$EXE#
          783  +/^prefix *=/s#=.*#=$prefix#
          784  +/^exec_prefix *=/s#=.*#=$exec_prefix#
          785  +/^libdir *=/s#=.*#=$libdir#
          786  +/^sharedlibdir *=/s#=.*#=$sharedlibdir#
          787  +/^includedir *=/s#=.*#=$includedir#
          788  +/^mandir *=/s#=.*#=$mandir#
          789  +/^OBJC *=/s#=.*#= $OBJC#
          790  +/^PIC_OBJC *=/s#=.*#= $PIC_OBJC#
          791  +/^all: */s#:.*#: $ALL#
          792  +/^test: */s#:.*#: $TEST#
          793  +" > Makefile
          794  +
          795  +# create zlib.pc with the configure results
          796  +sed < zlib.pc.in "
          797  +/^CC *=/s#=.*#=$CC#
          798  +/^CFLAGS *=/s#=.*#=$CFLAGS#
          799  +/^CPP *=/s#=.*#=$CPP#
          800  +/^LDSHARED *=/s#=.*#=$LDSHARED#
          801  +/^STATICLIB *=/s#=.*#=$STATICLIB#
          802  +/^SHAREDLIB *=/s#=.*#=$SHAREDLIB#
          803  +/^SHAREDLIBV *=/s#=.*#=$SHAREDLIBV#
          804  +/^SHAREDLIBM *=/s#=.*#=$SHAREDLIBM#
          805  +/^AR *=/s#=.*#=$AR#
          806  +/^ARFLAGS *=/s#=.*#=$ARFLAGS#
          807  +/^RANLIB *=/s#=.*#=$RANLIB#
          808  +/^EXE *=/s#=.*#=$EXE#
          809  +/^prefix *=/s#=.*#=$prefix#
          810  +/^exec_prefix *=/s#=.*#=$exec_prefix#
          811  +/^libdir *=/s#=.*#=$libdir#
          812  +/^sharedlibdir *=/s#=.*#=$sharedlibdir#
          813  +/^includedir *=/s#=.*#=$includedir#
          814  +/^mandir *=/s#=.*#=$mandir#
          815  +/^LDFLAGS *=/s#=.*#=$LDFLAGS#
          816  +" | sed -e "
          817  +s/\@VERSION\@/$VER/g;
          818  +" > zlib.pc

Added compat/zlib/contrib/README.contrib.

            1  +All files under this contrib directory are UNSUPPORTED. There were
            2  +provided by users of zlib and were not tested by the authors of zlib.
            3  +Use at your own risk. Please contact the authors of the contributions
            4  +for help about these, not the zlib authors. Thanks.
            5  +
            6  +
            7  +ada/        by Dmitriy Anisimkov <anisimkov@yahoo.com>
            8  +        Support for Ada
            9  +        See http://zlib-ada.sourceforge.net/
           10  +
           11  +amd64/      by Mikhail Teterin <mi@ALDAN.algebra.com>
           12  +        asm code for AMD64
           13  +        See patch at http://www.freebsd.org/cgi/query-pr.cgi?pr=bin/96393
           14  +
           15  +asm686/     by Brian Raiter <breadbox@muppetlabs.com>
           16  +        asm code for Pentium and PPro/PII, using the AT&T (GNU as) syntax
           17  +        See http://www.muppetlabs.com/~breadbox/software/assembly.html
           18  +
           19  +blast/      by Mark Adler <madler@alumni.caltech.edu>
           20  +        Decompressor for output of PKWare Data Compression Library (DCL)
           21  +
           22  +delphi/     by Cosmin Truta <cosmint@cs.ubbcluj.ro>
           23  +        Support for Delphi and C++ Builder
           24  +
           25  +dotzlib/    by Henrik Ravn <henrik@ravn.com>
           26  +        Support for Microsoft .Net and Visual C++ .Net
           27  +
           28  +gcc_gvmat64/by Gilles Vollant <info@winimage.com>
           29  +        GCC Version of x86 64-bit (AMD64 and Intel EM64t) code for x64
           30  +        assembler to replace longest_match() and inflate_fast()
           31  +
           32  +infback9/   by Mark Adler <madler@alumni.caltech.edu>
           33  +        Unsupported diffs to infback to decode the deflate64 format
           34  +
           35  +inflate86/  by Chris Anderson <christop@charm.net>
           36  +        Tuned x86 gcc asm code to replace inflate_fast()
           37  +
           38  +iostream/   by Kevin Ruland <kevin@rodin.wustl.edu>
           39  +        A C++ I/O streams interface to the zlib gz* functions
           40  +
           41  +iostream2/  by Tyge Løvset <Tyge.Lovset@cmr.no>
           42  +        Another C++ I/O streams interface
           43  +
           44  +iostream3/  by Ludwig Schwardt <schwardt@sun.ac.za>
           45  +            and Kevin Ruland <kevin@rodin.wustl.edu>
           46  +        Yet another C++ I/O streams interface
           47  +
           48  +masmx64/    by Gilles Vollant <info@winimage.com>
           49  +        x86 64-bit (AMD64 and Intel EM64t) code for x64 assembler to
           50  +        replace longest_match() and inflate_fast(),  also masm x86
           51  +        64-bits translation of Chris Anderson inflate_fast()
           52  +
           53  +masmx86/    by Gilles Vollant <info@winimage.com>
           54  +        x86 asm code to replace longest_match() and inflate_fast(),
           55  +        for Visual C++ and MASM (32 bits).
           56  +        Based on Brian Raiter (asm686) and Chris Anderson (inflate86)
           57  +
           58  +minizip/    by Gilles Vollant <info@winimage.com>
           59  +        Mini zip and unzip based on zlib
           60  +        Includes Zip64 support by Mathias Svensson <mathias@result42.com>
           61  +        See http://www.winimage.com/zLibDll/unzip.html
           62  +
           63  +pascal/     by Bob Dellaca <bobdl@xtra.co.nz> et al.
           64  +        Support for Pascal
           65  +
           66  +puff/       by Mark Adler <madler@alumni.caltech.edu>
           67  +        Small, low memory usage inflate.  Also serves to provide an
           68  +        unambiguous description of the deflate format.
           69  +
           70  +testzlib/   by Gilles Vollant <info@winimage.com>
           71  +        Example of the use of zlib
           72  +
           73  +untgz/      by Pedro A. Aranda Gutierrez <paag@tid.es>
           74  +        A very simple tar.gz file extractor using zlib
           75  +
           76  +vstudio/    by Gilles Vollant <info@winimage.com>
           77  +        Building a minizip-enhanced zlib with Microsoft Visual Studio

Added compat/zlib/contrib/ada/buffer_demo.adb.

            1  +----------------------------------------------------------------
            2  +--  ZLib for Ada thick binding.                               --
            3  +--                                                            --
            4  +--  Copyright (C) 2002-2004 Dmitriy Anisimkov                 --
            5  +--                                                            --
            6  +--  Open source license information is in the zlib.ads file.  --
            7  +----------------------------------------------------------------
            8  +--
            9  +--  $Id: buffer_demo.adb,v 1.3 2004/09/06 06:55:35 vagul Exp $
           10  +
           11  +--  This demo program provided by Dr Steve Sangwine <sjs@essex.ac.uk>
           12  +--
           13  +--  Demonstration of a problem with Zlib-Ada (already fixed) when a buffer
           14  +--  of exactly the correct size is used for decompressed data, and the last
           15  +--  few bytes passed in to Zlib are checksum bytes.
           16  +
           17  +--  This program compresses a string of text, and then decompresses the
           18  +--  compressed text into a buffer of the same size as the original text.
           19  +
           20  +with Ada.Streams; use Ada.Streams;
           21  +with Ada.Text_IO;
           22  +
           23  +with ZLib; use ZLib;
           24  +
           25  +procedure Buffer_Demo is
           26  +   EOL  : Character renames ASCII.LF;
           27  +   Text : constant String
           28  +     := "Four score and seven years ago our fathers brought forth," & EOL &
           29  +        "upon this continent, a new nation, conceived in liberty," & EOL &
           30  +        "and dedicated to the proposition that `all men are created equal'.";
           31  +
           32  +   Source : Stream_Element_Array (1 .. Text'Length);
           33  +   for Source'Address use Text'Address;
           34  +
           35  +begin
           36  +   Ada.Text_IO.Put (Text);
           37  +   Ada.Text_IO.New_Line;
           38  +   Ada.Text_IO.Put_Line
           39  +     ("Uncompressed size : " & Positive'Image (Text'Length) & " bytes");
           40  +
           41  +   declare
           42  +      Compressed_Data : Stream_Element_Array (1 .. Text'Length);
           43  +      L               : Stream_Element_Offset;
           44  +   begin
           45  +      Compress : declare
           46  +         Compressor : Filter_Type;
           47  +         I : Stream_Element_Offset;
           48  +      begin
           49  +         Deflate_Init (Compressor);
           50  +
           51  +         --  Compress the whole of T at once.
           52  +
           53  +         Translate (Compressor, Source, I, Compressed_Data, L, Finish);
           54  +         pragma Assert (I = Source'Last);
           55  +
           56  +         Close (Compressor);
           57  +
           58  +         Ada.Text_IO.Put_Line
           59  +           ("Compressed size :   "
           60  +            & Stream_Element_Offset'Image (L) & " bytes");
           61  +      end Compress;
           62  +
           63  +      --  Now we decompress the data, passing short blocks of data to Zlib
           64  +      --  (because this demonstrates the problem - the last block passed will
           65  +      --  contain checksum information and there will be no output, only a
           66  +      --  check inside Zlib that the checksum is correct).
           67  +
           68  +      Decompress : declare
           69  +         Decompressor : Filter_Type;
           70  +
           71  +         Uncompressed_Data : Stream_Element_Array (1 .. Text'Length);
           72  +
           73  +         Block_Size : constant := 4;
           74  +         --  This makes sure that the last block contains
           75  +         --  only Adler checksum data.
           76  +
           77  +         P : Stream_Element_Offset := Compressed_Data'First - 1;
           78  +         O : Stream_Element_Offset;
           79  +      begin
           80  +         Inflate_Init (Decompressor);
           81  +
           82  +         loop
           83  +            Translate
           84  +              (Decompressor,
           85  +               Compressed_Data
           86  +                 (P + 1 .. Stream_Element_Offset'Min (P + Block_Size, L)),
           87  +               P,
           88  +               Uncompressed_Data
           89  +                 (Total_Out (Decompressor) + 1 .. Uncompressed_Data'Last),
           90  +               O,
           91  +               No_Flush);
           92  +
           93  +               Ada.Text_IO.Put_Line
           94  +                 ("Total in : " & Count'Image (Total_In (Decompressor)) &
           95  +                  ", out : " & Count'Image (Total_Out (Decompressor)));
           96  +
           97  +               exit when P = L;
           98  +         end loop;
           99  +
          100  +         Ada.Text_IO.New_Line;
          101  +         Ada.Text_IO.Put_Line
          102  +           ("Decompressed text matches original text : "
          103  +             & Boolean'Image (Uncompressed_Data = Source));
          104  +      end Decompress;
          105  +   end;
          106  +end Buffer_Demo;

Added compat/zlib/contrib/ada/mtest.adb.

            1  +----------------------------------------------------------------
            2  +--  ZLib for Ada thick binding.                               --
            3  +--                                                            --
            4  +--  Copyright (C) 2002-2003 Dmitriy Anisimkov                 --
            5  +--                                                            --
            6  +--  Open source license information is in the zlib.ads file.  --
            7  +----------------------------------------------------------------
            8  +--  Continuous test for ZLib multithreading. If the test would fail
            9  +--  we should provide thread safe allocation routines for the Z_Stream.
           10  +--
           11  +--  $Id: mtest.adb,v 1.4 2004/07/23 07:49:54 vagul Exp $
           12  +
           13  +with ZLib;
           14  +with Ada.Streams;
           15  +with Ada.Numerics.Discrete_Random;
           16  +with Ada.Text_IO;
           17  +with Ada.Exceptions;
           18  +with Ada.Task_Identification;
           19  +
           20  +procedure MTest is
           21  +   use Ada.Streams;
           22  +   use ZLib;
           23  +
           24  +   Stop : Boolean := False;
           25  +
           26  +   pragma Atomic (Stop);
           27  +
           28  +   subtype Visible_Symbols is Stream_Element range 16#20# .. 16#7E#;
           29  +
           30  +   package Random_Elements is
           31  +      new Ada.Numerics.Discrete_Random (Visible_Symbols);
           32  +
           33  +   task type Test_Task;
           34  +
           35  +   task body Test_Task is
           36  +      Buffer : Stream_Element_Array (1 .. 100_000);
           37  +      Gen : Random_Elements.Generator;
           38  +
           39  +      Buffer_First  : Stream_Element_Offset;
           40  +      Compare_First : Stream_Element_Offset;
           41  +
           42  +      Deflate : Filter_Type;
           43  +      Inflate : Filter_Type;
           44  +
           45  +      procedure Further (Item : in Stream_Element_Array);
           46  +
           47  +      procedure Read_Buffer
           48  +        (Item : out Ada.Streams.Stream_Element_Array;
           49  +         Last : out Ada.Streams.Stream_Element_Offset);
           50  +
           51  +      -------------
           52  +      -- Further --
           53  +      -------------
           54  +
           55  +      procedure Further (Item : in Stream_Element_Array) is
           56  +
           57  +         procedure Compare (Item : in Stream_Element_Array);
           58  +
           59  +         -------------
           60  +         -- Compare --
           61  +         -------------
           62  +
           63  +         procedure Compare (Item : in Stream_Element_Array) is
           64  +            Next_First : Stream_Element_Offset := Compare_First + Item'Length;
           65  +         begin
           66  +            if Buffer (Compare_First .. Next_First - 1) /= Item then
           67  +               raise Program_Error;
           68  +            end if;
           69  +
           70  +            Compare_First := Next_First;
           71  +         end Compare;
           72  +
           73  +         procedure Compare_Write is new ZLib.Write (Write => Compare);
           74  +      begin
           75  +         Compare_Write (Inflate, Item, No_Flush);
           76  +      end Further;
           77  +
           78  +      -----------------
           79  +      -- Read_Buffer --
           80  +      -----------------
           81  +
           82  +      procedure Read_Buffer
           83  +        (Item : out Ada.Streams.Stream_Element_Array;
           84  +         Last : out Ada.Streams.Stream_Element_Offset)
           85  +      is
           86  +         Buff_Diff   : Stream_Element_Offset := Buffer'Last - Buffer_First;
           87  +         Next_First : Stream_Element_Offset;
           88  +      begin
           89  +         if Item'Length <= Buff_Diff then
           90  +            Last := Item'Last;
           91  +
           92  +            Next_First := Buffer_First + Item'Length;
           93  +
           94  +            Item := Buffer (Buffer_First .. Next_First - 1);
           95  +
           96  +            Buffer_First := Next_First;
           97  +         else
           98  +            Last := Item'First + Buff_Diff;
           99  +            Item (Item'First .. Last) := Buffer (Buffer_First .. Buffer'Last);
          100  +            Buffer_First := Buffer'Last + 1;
          101  +         end if;
          102  +      end Read_Buffer;
          103  +
          104  +      procedure Translate is new Generic_Translate
          105  +                                   (Data_In  => Read_Buffer,
          106  +                                    Data_Out => Further);
          107  +
          108  +   begin
          109  +      Random_Elements.Reset (Gen);
          110  +
          111  +      Buffer := (others => 20);
          112  +
          113  +      Main : loop
          114  +         for J in Buffer'Range loop
          115  +            Buffer (J) := Random_Elements.Random (Gen);
          116  +
          117  +            Deflate_Init (Deflate);
          118  +            Inflate_Init (Inflate);
          119  +
          120  +            Buffer_First  := Buffer'First;
          121  +            Compare_First := Buffer'First;
          122  +
          123  +            Translate (Deflate);
          124  +
          125  +            if Compare_First /= Buffer'Last + 1 then
          126  +               raise Program_Error;
          127  +            end if;
          128  +
          129  +            Ada.Text_IO.Put_Line
          130  +              (Ada.Task_Identification.Image
          131  +                 (Ada.Task_Identification.Current_Task)
          132  +               & Stream_Element_Offset'Image (J)
          133  +               & ZLib.Count'Image (Total_Out (Deflate)));
          134  +
          135  +            Close (Deflate);
          136  +            Close (Inflate);
          137  +
          138  +            exit Main when Stop;
          139  +         end loop;
          140  +      end loop Main;
          141  +   exception
          142  +      when E : others =>
          143  +         Ada.Text_IO.Put_Line (Ada.Exceptions.Exception_Information (E));
          144  +         Stop := True;
          145  +   end Test_Task;
          146  +
          147  +   Test : array (1 .. 4) of Test_Task;
          148  +
          149  +   pragma Unreferenced (Test);
          150  +
          151  +   Dummy : Character;
          152  +
          153  +begin
          154  +   Ada.Text_IO.Get_Immediate (Dummy);
          155  +   Stop := True;
          156  +end MTest;

Added compat/zlib/contrib/ada/read.adb.

            1  +----------------------------------------------------------------
            2  +--  ZLib for Ada thick binding.                               --
            3  +--                                                            --
            4  +--  Copyright (C) 2002-2003 Dmitriy Anisimkov                 --
            5  +--                                                            --
            6  +--  Open source license information is in the zlib.ads file.  --
            7  +----------------------------------------------------------------
            8  +
            9  +--  $Id: read.adb,v 1.8 2004/05/31 10:53:40 vagul Exp $
           10  +
           11  +--  Test/demo program for the generic read interface.
           12  +
           13  +with Ada.Numerics.Discrete_Random;
           14  +with Ada.Streams;
           15  +with Ada.Text_IO;
           16  +
           17  +with ZLib;
           18  +
           19  +procedure Read is
           20  +
           21  +   use Ada.Streams;
           22  +
           23  +   ------------------------------------
           24  +   --  Test configuration parameters --
           25  +   ------------------------------------
           26  +
           27  +   File_Size   : Stream_Element_Offset := 100_000;
           28  +
           29  +   Continuous  : constant Boolean          := False;
           30  +   --  If this constant is True, the test would be repeated again and again,
           31  +   --  with increment File_Size for every iteration.
           32  +
           33  +   Header      : constant ZLib.Header_Type := ZLib.Default;
           34  +   --  Do not use Header other than Default in ZLib versions 1.1.4 and older.
           35  +
           36  +   Init_Random : constant := 8;
           37  +   --  We are using the same random sequence, in case of we catch bug,
           38  +   --  so we would be able to reproduce it.
           39  +
           40  +   -- End --
           41  +
           42  +   Pack_Size : Stream_Element_Offset;
           43  +   Offset    : Stream_Element_Offset;
           44  +
           45  +   Filter     : ZLib.Filter_Type;
           46  +
           47  +   subtype Visible_Symbols
           48  +      is Stream_Element range 16#20# .. 16#7E#;
           49  +
           50  +   package Random_Elements is new
           51  +      Ada.Numerics.Discrete_Random (Visible_Symbols);
           52  +
           53  +   Gen : Random_Elements.Generator;
           54  +   Period  : constant Stream_Element_Offset := 200;
           55  +   --  Period constant variable for random generator not to be very random.
           56  +   --  Bigger period, harder random.
           57  +
           58  +   Read_Buffer : Stream_Element_Array (1 .. 2048);
           59  +   Read_First  : Stream_Element_Offset;
           60  +   Read_Last   : Stream_Element_Offset;
           61  +
           62  +   procedure Reset;
           63  +
           64  +   procedure Read
           65  +     (Item : out Stream_Element_Array;
           66  +      Last : out Stream_Element_Offset);
           67  +   --  this procedure is for generic instantiation of
           68  +   --  ZLib.Read
           69  +   --  reading data from the File_In.
           70  +
           71  +   procedure Read is new ZLib.Read
           72  +                           (Read,
           73  +                            Read_Buffer,
           74  +                            Rest_First => Read_First,
           75  +                            Rest_Last  => Read_Last);
           76  +
           77  +   ----------
           78  +   -- Read --
           79  +   ----------
           80  +
           81  +   procedure Read
           82  +     (Item : out Stream_Element_Array;
           83  +      Last : out Stream_Element_Offset) is
           84  +   begin
           85  +      Last := Stream_Element_Offset'Min
           86  +               (Item'Last,
           87  +                Item'First + File_Size - Offset);
           88  +
           89  +      for J in Item'First .. Last loop
           90  +         if J < Item'First + Period then
           91  +            Item (J) := Random_Elements.Random (Gen);
           92  +         else
           93  +            Item (J) := Item (J - Period);
           94  +         end if;
           95  +
           96  +         Offset   := Offset + 1;
           97  +      end loop;
           98  +   end Read;
           99  +
          100  +   -----------
          101  +   -- Reset --
          102  +   -----------
          103  +
          104  +   procedure Reset is
          105  +   begin
          106  +      Random_Elements.Reset (Gen, Init_Random);
          107  +      Pack_Size := 0;
          108  +      Offset := 1;
          109  +      Read_First := Read_Buffer'Last + 1;
          110  +      Read_Last  := Read_Buffer'Last;
          111  +   end Reset;
          112  +
          113  +begin
          114  +   Ada.Text_IO.Put_Line ("ZLib " & ZLib.Version);
          115  +
          116  +   loop
          117  +      for Level in ZLib.Compression_Level'Range loop
          118  +
          119  +         Ada.Text_IO.Put ("Level ="
          120  +            & ZLib.Compression_Level'Image (Level));
          121  +
          122  +         --  Deflate using generic instantiation.
          123  +
          124  +         ZLib.Deflate_Init
          125  +               (Filter,
          126  +                Level,
          127  +                Header => Header);
          128  +
          129  +         Reset;
          130  +
          131  +         Ada.Text_IO.Put
          132  +           (Stream_Element_Offset'Image (File_Size) & " ->");
          133  +
          134  +         loop
          135  +            declare
          136  +               Buffer : Stream_Element_Array (1 .. 1024);
          137  +               Last   : Stream_Element_Offset;
          138  +            begin
          139  +               Read (Filter, Buffer, Last);
          140  +
          141  +               Pack_Size := Pack_Size + Last - Buffer'First + 1;
          142  +
          143  +               exit when Last < Buffer'Last;
          144  +            end;
          145  +         end loop;
          146  +
          147  +         Ada.Text_IO.Put_Line (Stream_Element_Offset'Image (Pack_Size));
          148  +
          149  +         ZLib.Close (Filter);
          150  +      end loop;
          151  +
          152  +      exit when not Continuous;
          153  +
          154  +      File_Size := File_Size + 1;
          155  +   end loop;
          156  +end Read;

Added compat/zlib/contrib/ada/readme.txt.

            1  +                        ZLib for Ada thick binding (ZLib.Ada)
            2  +                        Release 1.3
            3  +
            4  +ZLib.Ada is a thick binding interface to the popular ZLib data
            5  +compression library, available at http://www.gzip.org/zlib/.
            6  +It provides Ada-style access to the ZLib C library.
            7  +
            8  +
            9  +        Here are the main changes since ZLib.Ada 1.2:
           10  +
           11  +- Attension: ZLib.Read generic routine have a initialization requirement
           12  +  for Read_Last parameter now. It is a bit incompartible with previous version,
           13  +  but extends functionality, we could use new parameters Allow_Read_Some and
           14  +  Flush now.
           15  +
           16  +- Added Is_Open routines to ZLib and ZLib.Streams packages.
           17  +
           18  +- Add pragma Assert to check Stream_Element is 8 bit.
           19  +
           20  +- Fix extraction to buffer with exact known decompressed size. Error reported by
           21  +  Steve Sangwine.
           22  +
           23  +- Fix definition of ULong (changed to unsigned_long), fix regression on 64 bits
           24  +  computers. Patch provided by Pascal Obry.
           25  +
           26  +- Add Status_Error exception definition.
           27  +
           28  +- Add pragma Assertion that Ada.Streams.Stream_Element size is 8 bit.
           29  +
           30  +
           31  +        How to build ZLib.Ada under GNAT
           32  +
           33  +You should have the ZLib library already build on your computer, before
           34  +building ZLib.Ada. Make the directory of ZLib.Ada sources current and
           35  +issue the command:
           36  +
           37  +  gnatmake test -largs -L<directory where libz.a is> -lz
           38  +
           39  +Or use the GNAT project file build for GNAT 3.15 or later:
           40  +
           41  +  gnatmake -Pzlib.gpr -L<directory where libz.a is>
           42  +
           43  +
           44  +        How to build ZLib.Ada under Aonix ObjectAda for Win32 7.2.2
           45  +
           46  +1. Make a project with all *.ads and *.adb files from the distribution.
           47  +2. Build the libz.a library from the ZLib C sources.
           48  +3. Rename libz.a to z.lib.
           49  +4. Add the library z.lib to the project.
           50  +5. Add the libc.lib library from the ObjectAda distribution to the project.
           51  +6. Build the executable using test.adb as a main procedure.
           52  +
           53  +
           54  +        How to use ZLib.Ada
           55  +
           56  +The source files test.adb and read.adb are small demo programs that show
           57  +the main functionality of ZLib.Ada.
           58  +
           59  +The routines from the package specifications are commented.
           60  +
           61  +
           62  +Homepage: http://zlib-ada.sourceforge.net/
           63  +Author: Dmitriy Anisimkov <anisimkov@yahoo.com>
           64  +
           65  +Contributors: Pascal Obry <pascal@obry.org>, Steve Sangwine <sjs@essex.ac.uk>

Added compat/zlib/contrib/ada/test.adb.

            1  +----------------------------------------------------------------
            2  +--  ZLib for Ada thick binding.                               --
            3  +--                                                            --
            4  +--  Copyright (C) 2002-2003 Dmitriy Anisimkov                 --
            5  +--                                                            --
            6  +--  Open source license information is in the zlib.ads file.  --
            7  +----------------------------------------------------------------
            8  +
            9  +--  $Id: test.adb,v 1.17 2003/08/12 12:13:30 vagul Exp $
           10  +
           11  +--  The program has a few aims.
           12  +--  1. Test ZLib.Ada95 thick binding functionality.
           13  +--  2. Show the example of use main functionality of the ZLib.Ada95 binding.
           14  +--  3. Build this program automatically compile all ZLib.Ada95 packages under
           15  +--     GNAT Ada95 compiler.
           16  +
           17  +with ZLib.Streams;
           18  +with Ada.Streams.Stream_IO;
           19  +with Ada.Numerics.Discrete_Random;
           20  +
           21  +with Ada.Text_IO;
           22  +
           23  +with Ada.Calendar;
           24  +
           25  +procedure Test is
           26  +
           27  +   use Ada.Streams;
           28  +   use Stream_IO;
           29  +
           30  +   ------------------------------------
           31  +   --  Test configuration parameters --
           32  +   ------------------------------------
           33  +
           34  +   File_Size   : Count   := 100_000;
           35  +   Continuous  : constant Boolean := False;
           36  +
           37  +   Header      : constant ZLib.Header_Type := ZLib.Default;
           38  +                                              --  ZLib.None;
           39  +                                              --  ZLib.Auto;
           40  +                                              --  ZLib.GZip;
           41  +   --  Do not use Header other then Default in ZLib versions 1.1.4
           42  +   --  and older.
           43  +
           44  +   Strategy    : constant ZLib.Strategy_Type := ZLib.Default_Strategy;
           45  +   Init_Random : constant := 10;
           46  +
           47  +   -- End --
           48  +
           49  +   In_File_Name  : constant String := "testzlib.in";
           50  +   --  Name of the input file
           51  +
           52  +   Z_File_Name   : constant String := "testzlib.zlb";
           53  +   --  Name of the compressed file.
           54  +
           55  +   Out_File_Name : constant String := "testzlib.out";
           56  +   --  Name of the decompressed file.
           57  +
           58  +   File_In   : File_Type;
           59  +   File_Out  : File_Type;
           60  +   File_Back : File_Type;
           61  +   File_Z    : ZLib.Streams.Stream_Type;
           62  +
           63  +   Filter : ZLib.Filter_Type;
           64  +
           65  +   Time_Stamp : Ada.Calendar.Time;
           66  +
           67  +   procedure Generate_File;
           68  +   --  Generate file of spetsified size with some random data.
           69  +   --  The random data is repeatable, for the good compression.
           70  +
           71  +   procedure Compare_Streams
           72  +     (Left, Right : in out Root_Stream_Type'Class);
           73  +   --  The procedure compearing data in 2 streams.
           74  +   --  It is for compare data before and after compression/decompression.
           75  +
           76  +   procedure Compare_Files (Left, Right : String);
           77  +   --  Compare files. Based on the Compare_Streams.
           78  +
           79  +   procedure Copy_Streams
           80  +     (Source, Target : in out Root_Stream_Type'Class;
           81  +      Buffer_Size    : in     Stream_Element_Offset := 1024);
           82  +   --  Copying data from one stream to another. It is for test stream
           83  +   --  interface of the library.
           84  +
           85  +   procedure Data_In
           86  +     (Item : out Stream_Element_Array;
           87  +      Last : out Stream_Element_Offset);
           88  +   --  this procedure is for generic instantiation of
           89  +   --  ZLib.Generic_Translate.
           90  +   --  reading data from the File_In.
           91  +
           92  +   procedure Data_Out (Item : in Stream_Element_Array);
           93  +   --  this procedure is for generic instantiation of
           94  +   --  ZLib.Generic_Translate.
           95  +   --  writing data to the File_Out.
           96  +
           97  +   procedure Stamp;
           98  +   --  Store the timestamp to the local variable.
           99  +
          100  +   procedure Print_Statistic (Msg : String; Data_Size : ZLib.Count);
          101  +   --  Print the time statistic with the message.
          102  +
          103  +   procedure Translate is new ZLib.Generic_Translate
          104  +                                (Data_In  => Data_In,
          105  +                                 Data_Out => Data_Out);
          106  +   --  This procedure is moving data from File_In to File_Out
          107  +   --  with compression or decompression, depend on initialization of
          108  +   --  Filter parameter.
          109  +
          110  +   -------------------
          111  +   -- Compare_Files --
          112  +   -------------------
          113  +
          114  +   procedure Compare_Files (Left, Right : String) is
          115  +      Left_File, Right_File : File_Type;
          116  +   begin
          117  +      Open (Left_File, In_File, Left);
          118  +      Open (Right_File, In_File, Right);
          119  +      Compare_Streams (Stream (Left_File).all, Stream (Right_File).all);
          120  +      Close (Left_File);
          121  +      Close (Right_File);
          122  +   end Compare_Files;
          123  +
          124  +   ---------------------
          125  +   -- Compare_Streams --
          126  +   ---------------------
          127  +
          128  +   procedure Compare_Streams
          129  +     (Left, Right : in out Ada.Streams.Root_Stream_Type'Class)
          130  +   is
          131  +      Left_Buffer, Right_Buffer : Stream_Element_Array (0 .. 16#FFF#);
          132  +      Left_Last, Right_Last : Stream_Element_Offset;
          133  +   begin
          134  +      loop
          135  +         Read (Left, Left_Buffer, Left_Last);
          136  +         Read (Right, Right_Buffer, Right_Last);
          137  +
          138  +         if Left_Last /= Right_Last then
          139  +            Ada.Text_IO.Put_Line ("Compare error :"
          140  +              & Stream_Element_Offset'Image (Left_Last)
          141  +              & " /= "
          142  +              & Stream_Element_Offset'Image (Right_Last));
          143  +
          144  +            raise Constraint_Error;
          145  +
          146  +         elsif Left_Buffer (0 .. Left_Last)
          147  +               /= Right_Buffer (0 .. Right_Last)
          148  +         then
          149  +            Ada.Text_IO.Put_Line ("ERROR: IN and OUT files is not equal.");
          150  +            raise Constraint_Error;
          151  +
          152  +         end if;
          153  +
          154  +         exit when Left_Last < Left_Buffer'Last;
          155  +      end loop;
          156  +   end Compare_Streams;
          157  +
          158  +   ------------------
          159  +   -- Copy_Streams --
          160  +   ------------------
          161  +
          162  +   procedure Copy_Streams
          163  +     (Source, Target : in out Ada.Streams.Root_Stream_Type'Class;
          164  +      Buffer_Size    : in     Stream_Element_Offset := 1024)
          165  +   is
          166  +      Buffer : Stream_Element_Array (1 .. Buffer_Size);
          167  +      Last   : Stream_Element_Offset;
          168  +   begin
          169  +      loop
          170  +         Read  (Source, Buffer, Last);
          171  +         Write (Target, Buffer (1 .. Last));
          172  +
          173  +         exit when Last < Buffer'Last;
          174  +      end loop;
          175  +   end Copy_Streams;
          176  +
          177  +   -------------
          178  +   -- Data_In --
          179  +   -------------
          180  +
          181  +   procedure Data_In
          182  +     (Item : out Stream_Element_Array;
          183  +      Last : out Stream_Element_Offset) is
          184  +   begin
          185  +      Read (File_In, Item, Last);
          186  +   end Data_In;
          187  +
          188  +   --------------
          189  +   -- Data_Out --
          190  +   --------------
          191  +
          192  +   procedure Data_Out (Item : in Stream_Element_Array) is
          193  +   begin
          194  +      Write (File_Out, Item);
          195  +   end Data_Out;
          196  +
          197  +   -------------------
          198  +   -- Generate_File --
          199  +   -------------------
          200  +
          201  +   procedure Generate_File is
          202  +      subtype Visible_Symbols is Stream_Element range 16#20# .. 16#7E#;
          203  +
          204  +      package Random_Elements is
          205  +         new Ada.Numerics.Discrete_Random (Visible_Symbols);
          206  +
          207  +      Gen    : Random_Elements.Generator;
          208  +      Buffer : Stream_Element_Array := (1 .. 77 => 16#20#) & 10;
          209  +
          210  +      Buffer_Count : constant Count := File_Size / Buffer'Length;
          211  +      --  Number of same buffers in the packet.
          212  +
          213  +      Density : constant Count := 30; --  from 0 to Buffer'Length - 2;
          214  +
          215  +      procedure Fill_Buffer (J, D : in Count);
          216  +      --  Change the part of the buffer.
          217  +
          218  +      -----------------
          219  +      -- Fill_Buffer --
          220  +      -----------------
          221  +
          222  +      procedure Fill_Buffer (J, D : in Count) is
          223  +      begin
          224  +         for K in 0 .. D loop
          225  +            Buffer
          226  +              (Stream_Element_Offset ((J + K) mod (Buffer'Length - 1) + 1))
          227  +             := Random_Elements.Random (Gen);
          228  +
          229  +         end loop;
          230  +      end Fill_Buffer;
          231  +
          232  +   begin
          233  +      Random_Elements.Reset (Gen, Init_Random);
          234  +
          235  +      Create (File_In, Out_File, In_File_Name);
          236  +
          237  +      Fill_Buffer (1, Buffer'Length - 2);
          238  +
          239  +      for J in 1 .. Buffer_Count loop
          240  +         Write (File_In, Buffer);
          241  +
          242  +         Fill_Buffer (J, Density);
          243  +      end loop;
          244  +
          245  +      --  fill remain size.
          246  +
          247  +      Write
          248  +        (File_In,
          249  +         Buffer
          250  +           (1 .. Stream_Element_Offset
          251  +                   (File_Size - Buffer'Length * Buffer_Count)));
          252  +
          253  +      Flush (File_In);
          254  +      Close (File_In);
          255  +   end Generate_File;
          256  +
          257  +   ---------------------
          258  +   -- Print_Statistic --
          259  +   ---------------------
          260  +
          261  +   procedure Print_Statistic (Msg : String; Data_Size : ZLib.Count) is
          262  +      use Ada.Calendar;
          263  +      use Ada.Text_IO;
          264  +
          265  +      package Count_IO is new Integer_IO (ZLib.Count);
          266  +
          267  +      Curr_Dur : Duration := Clock - Time_Stamp;
          268  +   begin
          269  +      Put (Msg);
          270  +
          271  +      Set_Col (20);
          272  +      Ada.Text_IO.Put ("size =");
          273  +
          274  +      Count_IO.Put
          275  +        (Data_Size,
          276  +         Width => Stream_IO.Count'Image (File_Size)'Length);
          277  +
          278  +      Put_Line (" duration =" & Duration'Image (Curr_Dur));
          279  +   end Print_Statistic;
          280  +
          281  +   -----------
          282  +   -- Stamp --
          283  +   -----------
          284  +
          285  +   procedure Stamp is
          286  +   begin
          287  +      Time_Stamp := Ada.Calendar.Clock;
          288  +   end Stamp;
          289  +
          290  +begin
          291  +   Ada.Text_IO.Put_Line ("ZLib " & ZLib.Version);
          292  +
          293  +   loop
          294  +      Generate_File;
          295  +
          296  +      for Level in ZLib.Compression_Level'Range loop
          297  +
          298  +         Ada.Text_IO.Put_Line ("Level ="
          299  +            & ZLib.Compression_Level'Image (Level));
          300  +
          301  +         --  Test generic interface.
          302  +         Open   (File_In, In_File, In_File_Name);
          303  +         Create (File_Out, Out_File, Z_File_Name);
          304  +
          305  +         Stamp;
          306  +
          307  +         --  Deflate using generic instantiation.
          308  +
          309  +         ZLib.Deflate_Init
          310  +               (Filter   => Filter,
          311  +                Level    => Level,
          312  +                Strategy => Strategy,
          313  +                Header   => Header);
          314  +
          315  +         Translate (Filter);
          316  +         Print_Statistic ("Generic compress", ZLib.Total_Out (Filter));
          317  +         ZLib.Close (Filter);
          318  +
          319  +         Close (File_In);
          320  +         Close (File_Out);
          321  +
          322  +         Open   (File_In, In_File, Z_File_Name);
          323  +         Create (File_Out, Out_File, Out_File_Name);
          324  +
          325  +         Stamp;
          326  +
          327  +         --  Inflate using generic instantiation.
          328  +
          329  +         ZLib.Inflate_Init (Filter, Header => Header);
          330  +
          331  +         Translate (Filter);
          332  +         Print_Statistic ("Generic decompress", ZLib.Total_Out (Filter));
          333  +
          334  +         ZLib.Close (Filter);
          335  +
          336  +         Close (File_In);
          337  +         Close (File_Out);
          338  +
          339  +         Compare_Files (In_File_Name, Out_File_Name);
          340  +
          341  +         --  Test stream interface.
          342  +
          343  +         --  Compress to the back stream.
          344  +
          345  +         Open   (File_In, In_File, In_File_Name);
          346  +         Create (File_Back, Out_File, Z_File_Name);
          347  +
          348  +         Stamp;
          349  +
          350  +         ZLib.Streams.Create
          351  +           (Stream          => File_Z,
          352  +            Mode            => ZLib.Streams.Out_Stream,
          353  +            Back            => ZLib.Streams.Stream_Access
          354  +                                 (Stream (File_Back)),
          355  +            Back_Compressed => True,
          356  +            Level           => Level,
          357  +            Strategy        => Strategy,
          358  +            Header          => Header);
          359  +
          360  +         Copy_Streams
          361  +           (Source => Stream (File_In).all,
          362  +            Target => File_Z);
          363  +
          364  +         --  Flushing internal buffers to the back stream.
          365  +
          366  +         ZLib.Streams.Flush (File_Z, ZLib.Finish);
          367  +
          368  +         Print_Statistic ("Write compress",
          369  +                          ZLib.Streams.Write_Total_Out (File_Z));
          370  +
          371  +         ZLib.Streams.Close (File_Z);
          372  +
          373  +         Close (File_In);
          374  +         Close (File_Back);
          375  +
          376  +         --  Compare reading from original file and from
          377  +         --  decompression stream.
          378  +
          379  +         Open (File_In,   In_File, In_File_Name);
          380  +         Open (File_Back, In_File, Z_File_Name);
          381  +
          382  +         ZLib.Streams.Create
          383  +           (Stream          => File_Z,
          384  +            Mode            => ZLib.Streams.In_Stream,
          385  +            Back            => ZLib.Streams.Stream_Access
          386  +                                 (Stream (File_Back)),
          387  +            Back_Compressed => True,
          388  +            Header          => Header);
          389  +
          390  +         Stamp;
          391  +         Compare_Streams (Stream (File_In).all, File_Z);
          392  +
          393  +         Print_Statistic ("Read decompress",
          394  +                          ZLib.Streams.Read_Total_Out (File_Z));
          395  +
          396  +         ZLib.Streams.Close (File_Z);
          397  +         Close (File_In);
          398  +         Close (File_Back);
          399  +
          400  +         --  Compress by reading from compression stream.
          401  +
          402  +         Open (File_Back, In_File, In_File_Name);
          403  +         Create (File_Out, Out_File, Z_File_Name);
          404  +
          405  +         ZLib.Streams.Create
          406  +           (Stream          => File_Z,
          407  +            Mode            => ZLib.Streams.In_Stream,
          408  +            Back            => ZLib.Streams.Stream_Access
          409  +                                 (Stream (File_Back)),
          410  +            Back_Compressed => False,
          411  +            Level           => Level,
          412  +            Strategy        => Strategy,
          413  +            Header          => Header);
          414  +
          415  +         Stamp;
          416  +         Copy_Streams
          417  +           (Source => File_Z,
          418  +            Target => Stream (File_Out).all);
          419  +
          420  +         Print_Statistic ("Read compress",
          421  +                          ZLib.Streams.Read_Total_Out (File_Z));
          422  +
          423  +         ZLib.Streams.Close (File_Z);
          424  +
          425  +         Close (File_Out);
          426  +         Close (File_Back);
          427  +
          428  +         --  Decompress to decompression stream.
          429  +
          430  +         Open   (File_In,   In_File, Z_File_Name);
          431  +         Create (File_Back, Out_File, Out_File_Name);
          432  +
          433  +         ZLib.Streams.Create
          434  +           (Stream          => File_Z,
          435  +            Mode            => ZLib.Streams.Out_Stream,
          436  +            Back            => ZLib.Streams.Stream_Access
          437  +                                 (Stream (File_Back)),
          438  +            Back_Compressed => False,
          439  +            Header          => Header);
          440  +
          441  +         Stamp;
          442  +
          443  +         Copy_Streams
          444  +           (Source => Stream (File_In).all,
          445  +            Target => File_Z);
          446  +
          447  +         Print_Statistic ("Write decompress",
          448  +                          ZLib.Streams.Write_Total_Out (File_Z));
          449  +
          450  +         ZLib.Streams.Close (File_Z);
          451  +         Close (File_In);
          452  +         Close (File_Back);
          453  +
          454  +         Compare_Files (In_File_Name, Out_File_Name);
          455  +      end loop;
          456  +
          457  +      Ada.Text_IO.Put_Line (Count'Image (File_Size) & " Ok.");
          458  +
          459  +      exit when not Continuous;
          460  +
          461  +      File_Size := File_Size + 1;
          462  +   end loop;
          463  +end Test;

Added compat/zlib/contrib/ada/zlib-streams.adb.

            1  +----------------------------------------------------------------
            2  +--  ZLib for Ada thick binding.                               --
            3  +--                                                            --
            4  +--  Copyright (C) 2002-2003 Dmitriy Anisimkov                 --
            5  +--                                                            --
            6  +--  Open source license information is in the zlib.ads file.  --
            7  +----------------------------------------------------------------
            8  +
            9  +--  $Id: zlib-streams.adb,v 1.10 2004/05/31 10:53:40 vagul Exp $
           10  +
           11  +with Ada.Unchecked_Deallocation;
           12  +
           13  +package body ZLib.Streams is
           14  +
           15  +   -----------
           16  +   -- Close --
           17  +   -----------
           18  +
           19  +   procedure Close (Stream : in out Stream_Type) is
           20  +      procedure Free is new Ada.Unchecked_Deallocation
           21  +         (Stream_Element_Array, Buffer_Access);
           22  +   begin
           23  +      if Stream.Mode = Out_Stream or Stream.Mode = Duplex then
           24  +         --  We should flush the data written by the writer.
           25  +
           26  +         Flush (Stream, Finish);
           27  +
           28  +         Close (Stream.Writer);
           29  +      end if;
           30  +
           31  +      if Stream.Mode = In_Stream or Stream.Mode = Duplex then
           32  +         Close (Stream.Reader);
           33  +         Free (Stream.Buffer);
           34  +      end if;
           35  +   end Close;
           36  +
           37  +   ------------
           38  +   -- Create --
           39  +   ------------
           40  +
           41  +   procedure Create
           42  +     (Stream            :    out Stream_Type;
           43  +      Mode              : in     Stream_Mode;
           44  +      Back              : in     Stream_Access;
           45  +      Back_Compressed   : in     Boolean;
           46  +      Level             : in     Compression_Level := Default_Compression;
           47  +      Strategy          : in     Strategy_Type     := Default_Strategy;
           48  +      Header            : in     Header_Type       := Default;
           49  +      Read_Buffer_Size  : in     Ada.Streams.Stream_Element_Offset
           50  +                                    := Default_Buffer_Size;
           51  +      Write_Buffer_Size : in     Ada.Streams.Stream_Element_Offset
           52  +                                    := Default_Buffer_Size)
           53  +   is
           54  +
           55  +      subtype Buffer_Subtype is Stream_Element_Array (1 .. Read_Buffer_Size);
           56  +
           57  +      procedure Init_Filter
           58  +         (Filter   : in out Filter_Type;
           59  +          Compress : in     Boolean);
           60  +
           61  +      -----------------
           62  +      -- Init_Filter --
           63  +      -----------------
           64  +
           65  +      procedure Init_Filter
           66  +         (Filter   : in out Filter_Type;
           67  +          Compress : in     Boolean) is
           68  +      begin
           69  +         if Compress then
           70  +            Deflate_Init
           71  +              (Filter, Level, Strategy, Header => Header);
           72  +         else
           73  +            Inflate_Init (Filter, Header => Header);
           74  +         end if;
           75  +      end Init_Filter;
           76  +
           77  +   begin
           78  +      Stream.Back := Back;
           79  +      Stream.Mode := Mode;
           80  +
           81  +      if Mode = Out_Stream or Mode = Duplex then
           82  +         Init_Filter (Stream.Writer, Back_Compressed);
           83  +         Stream.Buffer_Size := Write_Buffer_Size;
           84  +      else
           85  +         Stream.Buffer_Size := 0;
           86  +      end if;
           87  +
           88  +      if Mode = In_Stream or Mode = Duplex then
           89  +         Init_Filter (Stream.Reader, not Back_Compressed);
           90  +
           91  +         Stream.Buffer     := new Buffer_Subtype;
           92  +         Stream.Rest_First := Stream.Buffer'Last + 1;
           93  +         Stream.Rest_Last  := Stream.Buffer'Last;
           94  +      end if;
           95  +   end Create;
           96  +
           97  +   -----------
           98  +   -- Flush --
           99  +   -----------
          100  +
          101  +   procedure Flush
          102  +     (Stream : in out Stream_Type;
          103  +      Mode   : in     Flush_Mode := Sync_Flush)
          104  +   is
          105  +      Buffer : Stream_Element_Array (1 .. Stream.Buffer_Size);
          106  +      Last   : Stream_Element_Offset;
          107  +   begin
          108  +      loop
          109  +         Flush (Stream.Writer, Buffer, Last, Mode);
          110  +
          111  +         Ada.Streams.Write (Stream.Back.all, Buffer (1 .. Last));
          112  +
          113  +         exit when Last < Buffer'Last;
          114  +      end loop;
          115  +   end Flush;
          116  +
          117  +   -------------
          118  +   -- Is_Open --
          119  +   -------------
          120  +
          121  +   function Is_Open (Stream : Stream_Type) return Boolean is
          122  +   begin
          123  +      return Is_Open (Stream.Reader) or else Is_Open (Stream.Writer);
          124  +   end Is_Open;
          125  +
          126  +   ----------
          127  +   -- Read --
          128  +   ----------
          129  +
          130  +   procedure Read
          131  +     (Stream : in out Stream_Type;
          132  +      Item   :    out Stream_Element_Array;
          133  +      Last   :    out Stream_Element_Offset)
          134  +   is
          135  +
          136  +      procedure Read
          137  +        (Item : out Stream_Element_Array;
          138  +         Last : out Stream_Element_Offset);
          139  +
          140  +      ----------
          141  +      -- Read --
          142  +      ----------
          143  +
          144  +      procedure Read
          145  +        (Item : out Stream_Element_Array;
          146  +         Last : out Stream_Element_Offset) is
          147  +      begin
          148  +         Ada.Streams.Read (Stream.Back.all, Item, Last);
          149  +      end Read;
          150  +
          151  +      procedure Read is new ZLib.Read
          152  +         (Read       => Read,
          153  +          Buffer     => Stream.Buffer.all,
          154  +          Rest_First => Stream.Rest_First,
          155  +          Rest_Last  => Stream.Rest_Last);
          156  +
          157  +   begin
          158  +      Read (Stream.Reader, Item, Last);
          159  +   end Read;
          160  +
          161  +   -------------------
          162  +   -- Read_Total_In --
          163  +   -------------------
          164  +
          165  +   function Read_Total_In (Stream : in Stream_Type) return Count is
          166  +   begin
          167  +      return Total_In (Stream.Reader);
          168  +   end Read_Total_In;
          169  +
          170  +   --------------------
          171  +   -- Read_Total_Out --
          172  +   --------------------
          173  +
          174  +   function Read_Total_Out (Stream : in Stream_Type) return Count is
          175  +   begin
          176  +      return Total_Out (Stream.Reader);
          177  +   end Read_Total_Out;
          178  +
          179  +   -----------
          180  +   -- Write --
          181  +   -----------
          182  +
          183  +   procedure Write
          184  +     (Stream : in out Stream_Type;
          185  +      Item   : in     Stream_Element_Array)
          186  +   is
          187  +
          188  +      procedure Write (Item : in Stream_Element_Array);
          189  +
          190  +      -----------
          191  +      -- Write --
          192  +      -----------
          193  +
          194  +      procedure Write (Item : in Stream_Element_Array) is
          195  +      begin
          196  +         Ada.Streams.Write (Stream.Back.all, Item);
          197  +      end Write;
          198  +
          199  +      procedure Write is new ZLib.Write
          200  +         (Write       => Write,
          201  +          Buffer_Size => Stream.Buffer_Size);
          202  +
          203  +   begin
          204  +      Write (Stream.Writer, Item, No_Flush);
          205  +   end Write;
          206  +
          207  +   --------------------
          208  +   -- Write_Total_In --
          209  +   --------------------
          210  +
          211  +   function Write_Total_In (Stream : in Stream_Type) return Count is
          212  +   begin
          213  +      return Total_In (Stream.Writer);
          214  +   end Write_Total_In;
          215  +
          216  +   ---------------------
          217  +   -- Write_Total_Out --
          218  +   ---------------------
          219  +
          220  +   function Write_Total_Out (Stream : in Stream_Type) return Count is
          221  +   begin
          222  +      return Total_Out (Stream.Writer);
          223  +   end Write_Total_Out;
          224  +
          225  +end ZLib.Streams;

Added compat/zlib/contrib/ada/zlib-streams.ads.

            1  +----------------------------------------------------------------
            2  +--  ZLib for Ada thick binding.                               --
            3  +--                                                            --
            4  +--  Copyright (C) 2002-2003 Dmitriy Anisimkov                 --
            5  +--                                                            --
            6  +--  Open source license information is in the zlib.ads file.  --
            7  +----------------------------------------------------------------
            8  +
            9  +--  $Id: zlib-streams.ads,v 1.12 2004/05/31 10:53:40 vagul Exp $
           10  +
           11  +package ZLib.Streams is
           12  +
           13  +   type Stream_Mode is (In_Stream, Out_Stream, Duplex);
           14  +
           15  +   type Stream_Access is access all Ada.Streams.Root_Stream_Type'Class;
           16  +
           17  +   type Stream_Type is
           18  +      new Ada.Streams.Root_Stream_Type with private;
           19  +
           20  +   procedure Read
           21  +     (Stream : in out Stream_Type;
           22  +      Item   :    out Ada.Streams.Stream_Element_Array;
           23  +      Last   :    out Ada.Streams.Stream_Element_Offset);
           24  +
           25  +   procedure Write
           26  +     (Stream : in out Stream_Type;
           27  +      Item   : in     Ada.Streams.Stream_Element_Array);
           28  +
           29  +   procedure Flush
           30  +     (Stream : in out Stream_Type;
           31  +      Mode   : in     Flush_Mode := Sync_Flush);
           32  +   --  Flush the written data to the back stream,
           33  +   --  all data placed to the compressor is flushing to the Back stream.
           34  +   --  Should not be used untill necessary, becouse it is decreasing
           35  +   --  compression.
           36  +
           37  +   function Read_Total_In (Stream : in Stream_Type) return Count;
           38  +   pragma Inline (Read_Total_In);
           39  +   --  Return total number of bytes read from back stream so far.
           40  +
           41  +   function Read_Total_Out (Stream : in Stream_Type) return Count;
           42  +   pragma Inline (Read_Total_Out);
           43  +   --  Return total number of bytes read so far.
           44  +
           45  +   function Write_Total_In (Stream : in Stream_Type) return Count;
           46  +   pragma Inline (Write_Total_In);
           47  +   --  Return total number of bytes written so far.
           48  +
           49  +   function Write_Total_Out (Stream : in Stream_Type) return Count;
           50  +   pragma Inline (Write_Total_Out);
           51  +   --  Return total number of bytes written to the back stream.
           52  +
           53  +   procedure Create
           54  +     (Stream            :    out Stream_Type;
           55  +      Mode              : in     Stream_Mode;
           56  +      Back              : in     Stream_Access;
           57  +      Back_Compressed   : in     Boolean;
           58  +      Level             : in     Compression_Level := Default_Compression;
           59  +      Strategy          : in     Strategy_Type     := Default_Strategy;
           60  +      Header            : in     Header_Type       := Default;
           61  +      Read_Buffer_Size  : in     Ada.Streams.Stream_Element_Offset
           62  +                                    := Default_Buffer_Size;
           63  +      Write_Buffer_Size : in     Ada.Streams.Stream_Element_Offset
           64  +                                    := Default_Buffer_Size);
           65  +   --  Create the Comression/Decompression stream.
           66  +   --  If mode is In_Stream then Write operation is disabled.
           67  +   --  If mode is Out_Stream then Read operation is disabled.
           68  +
           69  +   --  If Back_Compressed is true then
           70  +   --  Data written to the Stream is compressing to the Back stream
           71  +   --  and data read from the Stream is decompressed data from the Back stream.
           72  +
           73  +   --  If Back_Compressed is false then
           74  +   --  Data written to the Stream is decompressing to the Back stream
           75  +   --  and data read from the Stream is compressed data from the Back stream.
           76  +
           77  +   --  !!! When the Need_Header is False ZLib-Ada is using undocumented
           78  +   --  ZLib 1.1.4 functionality to do not create/wait for ZLib headers.
           79  +
           80  +   function Is_Open (Stream : Stream_Type) return Boolean;
           81  +
           82  +   procedure Close (Stream : in out Stream_Type);
           83  +
           84  +private
           85  +
           86  +   use Ada.Streams;
           87  +
           88  +   type Buffer_Access is access all Stream_Element_Array;
           89  +
           90  +   type Stream_Type
           91  +     is new Root_Stream_Type with
           92  +   record
           93  +      Mode       : Stream_Mode;
           94  +
           95  +      Buffer     : Buffer_Access;
           96  +      Rest_First : Stream_Element_Offset;
           97  +      Rest_Last  : Stream_Element_Offset;
           98  +      --  Buffer for Read operation.
           99  +      --  We need to have this buffer in the record
          100  +      --  becouse not all read data from back stream
          101  +      --  could be processed during the read operation.
          102  +
          103  +      Buffer_Size : Stream_Element_Offset;
          104  +      --  Buffer size for write operation.
          105  +      --  We do not need to have this buffer
          106  +      --  in the record becouse all data could be
          107  +      --  processed in the write operation.
          108  +
          109  +      Back       : Stream_Access;
          110  +      Reader     : Filter_Type;
          111  +      Writer     : Filter_Type;
          112  +   end record;
          113  +
          114  +end ZLib.Streams;

Added compat/zlib/contrib/ada/zlib-thin.adb.

            1  +----------------------------------------------------------------
            2  +--  ZLib for Ada thick binding.                               --
            3  +--                                                            --
            4  +--  Copyright (C) 2002-2003 Dmitriy Anisimkov                 --
            5  +--                                                            --
            6  +--  Open source license information is in the zlib.ads file.  --
            7  +----------------------------------------------------------------
            8  +
            9  +--  $Id: zlib-thin.adb,v 1.8 2003/12/14 18:27:31 vagul Exp $
           10  +
           11  +package body ZLib.Thin is
           12  +
           13  +   ZLIB_VERSION  : constant Chars_Ptr := zlibVersion;
           14  +
           15  +   Z_Stream_Size : constant Int := Z_Stream'Size / System.Storage_Unit;
           16  +
           17  +   --------------
           18  +   -- Avail_In --
           19  +   --------------
           20  +
           21  +   function Avail_In (Strm : in Z_Stream) return UInt is
           22  +   begin
           23  +      return Strm.Avail_In;
           24  +   end Avail_In;
           25  +
           26  +   ---------------
           27  +   -- Avail_Out --
           28  +   ---------------
           29  +
           30  +   function Avail_Out (Strm : in Z_Stream) return UInt is
           31  +   begin
           32  +      return Strm.Avail_Out;
           33  +   end Avail_Out;
           34  +
           35  +   ------------------
           36  +   -- Deflate_Init --
           37  +   ------------------
           38  +
           39  +   function Deflate_Init
           40  +     (strm       : Z_Streamp;
           41  +      level      : Int;
           42  +      method     : Int;
           43  +      windowBits : Int;
           44  +      memLevel   : Int;
           45  +      strategy   : Int)
           46  +      return       Int is
           47  +   begin
           48  +      return deflateInit2
           49  +               (strm,
           50  +                level,
           51  +                method,
           52  +                windowBits,
           53  +                memLevel,
           54  +                strategy,
           55  +                ZLIB_VERSION,
           56  +                Z_Stream_Size);
           57  +   end Deflate_Init;
           58  +
           59  +   ------------------
           60  +   -- Inflate_Init --
           61  +   ------------------
           62  +
           63  +   function Inflate_Init (strm : Z_Streamp; windowBits : Int) return Int is
           64  +   begin
           65  +      return inflateInit2 (strm, windowBits, ZLIB_VERSION, Z_Stream_Size);
           66  +   end Inflate_Init;
           67  +
           68  +   ------------------------
           69  +   -- Last_Error_Message --
           70  +   ------------------------
           71  +
           72  +   function Last_Error_Message (Strm : in Z_Stream) return String is
           73  +      use Interfaces.C.Strings;
           74  +   begin
           75  +      if Strm.msg = Null_Ptr then
           76  +         return "";
           77  +      else
           78  +         return Value (Strm.msg);
           79  +      end if;
           80  +   end Last_Error_Message;
           81  +
           82  +   ------------
           83  +   -- Set_In --
           84  +   ------------
           85  +
           86  +   procedure Set_In
           87  +     (Strm   : in out Z_Stream;
           88  +      Buffer : in     Voidp;
           89  +      Size   : in     UInt) is
           90  +   begin
           91  +      Strm.Next_In  := Buffer;
           92  +      Strm.Avail_In := Size;
           93  +   end Set_In;
           94  +
           95  +   ------------------
           96  +   -- Set_Mem_Func --
           97  +   ------------------
           98  +
           99  +   procedure Set_Mem_Func
          100  +     (Strm   : in out Z_Stream;
          101  +      Opaque : in     Voidp;
          102  +      Alloc  : in     alloc_func;
          103  +      Free   : in     free_func) is
          104  +   begin
          105  +      Strm.opaque := Opaque;
          106  +      Strm.zalloc := Alloc;
          107  +      Strm.zfree  := Free;
          108  +   end Set_Mem_Func;
          109  +
          110  +   -------------
          111  +   -- Set_Out --
          112  +   -------------
          113  +
          114  +   procedure Set_Out
          115  +     (Strm   : in out Z_Stream;
          116  +      Buffer : in     Voidp;
          117  +      Size   : in     UInt) is
          118  +   begin
          119  +      Strm.Next_Out  := Buffer;
          120  +      Strm.Avail_Out := Size;
          121  +   end Set_Out;
          122  +
          123  +   --------------
          124  +   -- Total_In --
          125  +   --------------
          126  +
          127  +   function Total_In (Strm : in Z_Stream) return ULong is
          128  +   begin
          129  +      return Strm.Total_In;
          130  +   end Total_In;
          131  +
          132  +   ---------------
          133  +   -- Total_Out --
          134  +   ---------------
          135  +
          136  +   function Total_Out (Strm : in Z_Stream) return ULong is
          137  +   begin
          138  +      return Strm.Total_Out;
          139  +   end Total_Out;
          140  +
          141  +end ZLib.Thin;

Added compat/zlib/contrib/ada/zlib-thin.ads.

            1  +----------------------------------------------------------------
            2  +--  ZLib for Ada thick binding.                               --
            3  +--                                                            --
            4  +--  Copyright (C) 2002-2003 Dmitriy Anisimkov                 --
            5  +--                                                            --
            6  +--  Open source license information is in the zlib.ads file.  --
            7  +----------------------------------------------------------------
            8  +
            9  +--  $Id: zlib-thin.ads,v 1.11 2004/07/23 06:33:11 vagul Exp $
           10  +
           11  +with Interfaces.C.Strings;
           12  +
           13  +with System;
           14  +
           15  +private package ZLib.Thin is
           16  +
           17  +   --  From zconf.h
           18  +
           19  +   MAX_MEM_LEVEL : constant := 9;         --  zconf.h:105
           20  +                                          --  zconf.h:105
           21  +   MAX_WBITS : constant := 15;      --  zconf.h:115
           22  +                                    --  32K LZ77 window
           23  +                                    --  zconf.h:115
           24  +   SEEK_SET : constant := 8#0000#;  --  zconf.h:244
           25  +                                    --  Seek from beginning of file.
           26  +                                    --  zconf.h:244
           27  +   SEEK_CUR : constant := 1;        --  zconf.h:245
           28  +                                    --  Seek from current position.
           29  +                                    --  zconf.h:245
           30  +   SEEK_END : constant := 2;        --  zconf.h:246
           31  +                                    --  Set file pointer to EOF plus "offset"
           32  +                                    --  zconf.h:246
           33  +
           34  +   type Byte is new Interfaces.C.unsigned_char; --  8 bits
           35  +                                                --  zconf.h:214
           36  +   type UInt is new Interfaces.C.unsigned;      --  16 bits or more
           37  +                                                --  zconf.h:216
           38  +   type Int is new Interfaces.C.int;
           39  +
           40  +   type ULong is new Interfaces.C.unsigned_long;     --  32 bits or more
           41  +                                                     --  zconf.h:217
           42  +   subtype Chars_Ptr is Interfaces.C.Strings.chars_ptr;
           43  +
           44  +   type ULong_Access is access ULong;
           45  +   type Int_Access is access Int;
           46  +
           47  +   subtype Voidp is System.Address;            --  zconf.h:232
           48  +
           49  +   subtype Byte_Access is Voidp;
           50  +
           51  +   Nul : constant Voidp := System.Null_Address;
           52  +   --  end from zconf
           53  +
           54  +   Z_NO_FLUSH : constant := 8#0000#;   --  zlib.h:125
           55  +                                       --  zlib.h:125
           56  +   Z_PARTIAL_FLUSH : constant := 1;       --  zlib.h:126
           57  +                                          --  will be removed, use
           58  +                                          --  Z_SYNC_FLUSH instead
           59  +                                          --  zlib.h:126
           60  +   Z_SYNC_FLUSH : constant := 2;       --  zlib.h:127
           61  +                                       --  zlib.h:127
           62  +   Z_FULL_FLUSH : constant := 3;       --  zlib.h:128
           63  +                                       --  zlib.h:128
           64  +   Z_FINISH : constant := 4;        --  zlib.h:129
           65  +                                    --  zlib.h:129
           66  +   Z_OK : constant := 8#0000#;   --  zlib.h:132
           67  +                                 --  zlib.h:132
           68  +   Z_STREAM_END : constant := 1;       --  zlib.h:133
           69  +                                       --  zlib.h:133
           70  +   Z_NEED_DICT : constant := 2;        --  zlib.h:134
           71  +                                       --  zlib.h:134
           72  +   Z_ERRNO : constant := -1;        --  zlib.h:135
           73  +                                    --  zlib.h:135
           74  +   Z_STREAM_ERROR : constant := -2;       --  zlib.h:136
           75  +                                          --  zlib.h:136
           76  +   Z_DATA_ERROR : constant := -3;      --  zlib.h:137
           77  +                                       --  zlib.h:137
           78  +   Z_MEM_ERROR : constant := -4;       --  zlib.h:138
           79  +                                       --  zlib.h:138
           80  +   Z_BUF_ERROR : constant := -5;       --  zlib.h:139
           81  +                                       --  zlib.h:139
           82  +   Z_VERSION_ERROR : constant := -6;      --  zlib.h:140
           83  +                                          --  zlib.h:140
           84  +   Z_NO_COMPRESSION : constant := 8#0000#;   --  zlib.h:145
           85  +                                             --  zlib.h:145
           86  +   Z_BEST_SPEED : constant := 1;       --  zlib.h:146
           87  +                                       --  zlib.h:146
           88  +   Z_BEST_COMPRESSION : constant := 9;       --  zlib.h:147
           89  +                                             --  zlib.h:147
           90  +   Z_DEFAULT_COMPRESSION : constant := -1;      --  zlib.h:148
           91  +                                                --  zlib.h:148
           92  +   Z_FILTERED : constant := 1;      --  zlib.h:151
           93  +                                    --  zlib.h:151
           94  +   Z_HUFFMAN_ONLY : constant := 2;        --  zlib.h:152
           95  +                                          --  zlib.h:152
           96  +   Z_DEFAULT_STRATEGY : constant := 8#0000#; --  zlib.h:153
           97  +                                             --  zlib.h:153
           98  +   Z_BINARY : constant := 8#0000#;  --  zlib.h:156
           99  +                                    --  zlib.h:156
          100  +   Z_ASCII : constant := 1;      --  zlib.h:157
          101  +                                 --  zlib.h:157
          102  +   Z_UNKNOWN : constant := 2;       --  zlib.h:158
          103  +                                    --  zlib.h:158
          104  +   Z_DEFLATED : constant := 8;      --  zlib.h:161
          105  +                                    --  zlib.h:161
          106  +   Z_NULL : constant := 8#0000#; --  zlib.h:164
          107  +                                 --  for initializing zalloc, zfree, opaque
          108  +                                 --  zlib.h:164
          109  +   type gzFile is new Voidp;                  --  zlib.h:646
          110  +
          111  +   type Z_Stream is private;
          112  +
          113  +   type Z_Streamp is access all Z_Stream;     --  zlib.h:89
          114  +
          115  +   type alloc_func is access function
          116  +     (Opaque : Voidp;
          117  +      Items  : UInt;
          118  +      Size   : UInt)
          119  +      return Voidp; --  zlib.h:63
          120  +
          121  +   type free_func is access procedure (opaque : Voidp; address : Voidp);
          122  +
          123  +   function zlibVersion return Chars_Ptr;
          124  +
          125  +   function Deflate (strm : Z_Streamp; flush : Int) return Int;
          126  +
          127  +   function DeflateEnd (strm : Z_Streamp) return Int;
          128  +
          129  +   function Inflate (strm : Z_Streamp; flush : Int) return Int;
          130  +
          131  +   function InflateEnd (strm : Z_Streamp) return Int;
          132  +
          133  +   function deflateSetDictionary
          134  +     (strm       : Z_Streamp;
          135  +      dictionary : Byte_Access;
          136  +      dictLength : UInt)
          137  +      return       Int;
          138  +
          139  +   function deflateCopy (dest : Z_Streamp; source : Z_Streamp) return Int;
          140  +   --  zlib.h:478
          141  +
          142  +   function deflateReset (strm : Z_Streamp) return Int; -- zlib.h:495
          143  +
          144  +   function deflateParams
          145  +     (strm     : Z_Streamp;
          146  +      level    : Int;
          147  +      strategy : Int)
          148  +      return     Int;       -- zlib.h:506
          149  +
          150  +   function inflateSetDictionary
          151  +     (strm       : Z_Streamp;
          152  +      dictionary : Byte_Access;
          153  +      dictLength : UInt)
          154  +      return       Int; --  zlib.h:548
          155  +
          156  +   function inflateSync (strm : Z_Streamp) return Int;  --  zlib.h:565
          157  +
          158  +   function inflateReset (strm : Z_Streamp) return Int; --  zlib.h:580
          159  +
          160  +   function compress
          161  +     (dest      : Byte_Access;
          162  +      destLen   : ULong_Access;
          163  +      source    : Byte_Access;
          164  +      sourceLen : ULong)
          165  +      return      Int;           -- zlib.h:601
          166  +
          167  +   function compress2
          168  +     (dest      : Byte_Access;
          169  +      destLen   : ULong_Access;
          170  +      source    : Byte_Access;
          171  +      sourceLen : ULong;
          172  +      level     : Int)
          173  +      return      Int;          -- zlib.h:615
          174  +
          175  +   function uncompress
          176  +     (dest      : Byte_Access;
          177  +      destLen   : ULong_Access;
          178  +      source    : Byte_Access;
          179  +      sourceLen : ULong)
          180  +      return      Int;
          181  +
          182  +   function gzopen (path : Chars_Ptr; mode : Chars_Ptr) return gzFile;
          183  +
          184  +   function gzdopen (fd : Int; mode : Chars_Ptr) return gzFile;
          185  +
          186  +   function gzsetparams
          187  +     (file     : gzFile;
          188  +      level    : Int;
          189  +      strategy : Int)
          190  +      return     Int;
          191  +
          192  +   function gzread
          193  +     (file : gzFile;
          194  +      buf  : Voidp;
          195  +      len  : UInt)
          196  +      return Int;
          197  +
          198  +   function gzwrite
          199  +     (file : in gzFile;
          200  +      buf  : in Voidp;
          201  +      len  : in UInt)
          202  +      return Int;
          203  +
          204  +   function gzprintf (file : in gzFile; format : in Chars_Ptr) return Int;
          205  +
          206  +   function gzputs (file : in gzFile; s : in Chars_Ptr) return Int;
          207  +
          208  +   function gzgets
          209  +     (file : gzFile;
          210  +      buf  : Chars_Ptr;
          211  +      len  : Int)
          212  +      return Chars_Ptr;
          213  +
          214  +   function gzputc (file : gzFile; char : Int) return Int;
          215  +
          216  +   function gzgetc (file : gzFile) return Int;
          217  +
          218  +   function gzflush (file : gzFile; flush : Int) return Int;
          219  +
          220  +   function gzseek
          221  +     (file   : gzFile;
          222  +      offset : Int;
          223  +      whence : Int)
          224  +      return   Int;
          225  +
          226  +   function gzrewind (file : gzFile) return Int;
          227  +
          228  +   function gztell (file : gzFile) return Int;
          229  +
          230  +   function gzeof (file : gzFile) return Int;
          231  +
          232  +   function gzclose (file : gzFile) return Int;
          233  +
          234  +   function gzerror (file : gzFile; errnum : Int_Access) return Chars_Ptr;
          235  +
          236  +   function adler32
          237  +     (adler : ULong;
          238  +      buf   : Byte_Access;
          239  +      len   : UInt)
          240  +      return  ULong;
          241  +
          242  +   function crc32
          243  +     (crc  : ULong;
          244  +      buf  : Byte_Access;
          245  +      len  : UInt)
          246  +      return ULong;
          247  +
          248  +   function deflateInit
          249  +     (strm        : Z_Streamp;
          250  +      level       : Int;
          251  +      version     : Chars_Ptr;
          252  +      stream_size : Int)
          253  +      return        Int;
          254  +
          255  +   function deflateInit2
          256  +     (strm        : Z_Streamp;
          257  +      level       : Int;
          258  +      method      : Int;
          259  +      windowBits  : Int;
          260  +      memLevel    : Int;
          261  +      strategy    : Int;
          262  +      version     : Chars_Ptr;
          263  +      stream_size : Int)
          264  +      return        Int;
          265  +
          266  +   function Deflate_Init
          267  +     (strm       : Z_Streamp;
          268  +      level      : Int;
          269  +      method     : Int;
          270  +      windowBits : Int;
          271  +      memLevel   : Int;
          272  +      strategy   : Int)
          273  +      return       Int;
          274  +   pragma Inline (Deflate_Init);
          275  +
          276  +   function inflateInit
          277  +     (strm        : Z_Streamp;
          278  +      version     : Chars_Ptr;
          279  +      stream_size : Int)
          280  +      return        Int;
          281  +
          282  +   function inflateInit2
          283  +     (strm        : in Z_Streamp;
          284  +      windowBits  : in Int;
          285  +      version     : in Chars_Ptr;
          286  +      stream_size : in Int)
          287  +      return      Int;
          288  +
          289  +   function inflateBackInit
          290  +     (strm        : in Z_Streamp;
          291  +      windowBits  : in Int;
          292  +      window      : in Byte_Access;
          293  +      version     : in Chars_Ptr;
          294  +      stream_size : in Int)
          295  +      return      Int;
          296  +   --  Size of window have to be 2**windowBits.
          297  +
          298  +   function Inflate_Init (strm : Z_Streamp; windowBits : Int) return Int;
          299  +   pragma Inline (Inflate_Init);
          300  +
          301  +   function zError (err : Int) return Chars_Ptr;
          302  +
          303  +   function inflateSyncPoint (z : Z_Streamp) return Int;
          304  +
          305  +   function get_crc_table return ULong_Access;
          306  +
          307  +   --  Interface to the available fields of the z_stream structure.
          308  +   --  The application must update next_in and avail_in when avail_in has
          309  +   --  dropped to zero. It must update next_out and avail_out when avail_out
          310  +   --  has dropped to zero. The application must initialize zalloc, zfree and
          311  +   --  opaque before calling the init function.
          312  +
          313  +   procedure Set_In
          314  +     (Strm   : in out Z_Stream;
          315  +      Buffer : in Voidp;
          316  +      Size   : in UInt);
          317  +   pragma Inline (Set_In);
          318  +
          319  +   procedure Set_Out
          320  +     (Strm   : in out Z_Stream;
          321  +      Buffer : in Voidp;
          322  +      Size   : in UInt);
          323  +   pragma Inline (Set_Out);
          324  +
          325  +   procedure Set_Mem_Func
          326  +     (Strm   : in out Z_Stream;
          327  +      Opaque : in Voidp;
          328  +      Alloc  : in alloc_func;
          329  +      Free   : in free_func);
          330  +   pragma Inline (Set_Mem_Func);
          331  +
          332  +   function Last_Error_Message (Strm : in Z_Stream) return String;
          333  +   pragma Inline (Last_Error_Message);
          334  +
          335  +   function Avail_Out (Strm : in Z_Stream) return UInt;
          336  +   pragma Inline (Avail_Out);
          337  +
          338  +   function Avail_In (Strm : in Z_Stream) return UInt;
          339  +   pragma Inline (Avail_In);
          340  +
          341  +   function Total_In (Strm : in Z_Stream) return ULong;
          342  +   pragma Inline (Total_In);
          343  +
          344  +   function Total_Out (Strm : in Z_Stream) return ULong;
          345  +   pragma Inline (Total_Out);
          346  +
          347  +   function inflateCopy
          348  +     (dest   : in Z_Streamp;
          349  +      Source : in Z_Streamp)
          350  +      return Int;
          351  +
          352  +   function compressBound (Source_Len : in ULong) return ULong;
          353  +
          354  +   function deflateBound
          355  +     (Strm       : in Z_Streamp;
          356  +      Source_Len : in ULong)
          357  +      return     ULong;
          358  +
          359  +   function gzungetc (C : in Int; File : in  gzFile) return Int;
          360  +
          361  +   function zlibCompileFlags return ULong;
          362  +
          363  +private
          364  +
          365  +   type Z_Stream is record            -- zlib.h:68
          366  +      Next_In   : Voidp      := Nul;  -- next input byte
          367  +      Avail_In  : UInt       := 0;    -- number of bytes available at next_in
          368  +      Total_In  : ULong      := 0;    -- total nb of input bytes read so far
          369  +      Next_Out  : Voidp      := Nul;  -- next output byte should be put there
          370  +      Avail_Out : UInt       := 0;    -- remaining free space at next_out
          371  +      Total_Out : ULong      := 0;    -- total nb of bytes output so far
          372  +      msg       : Chars_Ptr;          -- last error message, NULL if no error
          373  +      state     : Voidp;              -- not visible by applications
          374  +      zalloc    : alloc_func := null; -- used to allocate the internal state
          375  +      zfree     : free_func  := null; -- used to free the internal state
          376  +      opaque    : Voidp;              -- private data object passed to
          377  +                                      --  zalloc and zfree
          378  +      data_type : Int;                -- best guess about the data type:
          379  +                                      --  ascii or binary
          380  +      adler     : ULong;              -- adler32 value of the uncompressed
          381  +                                      --  data
          382  +      reserved  : ULong;              -- reserved for future use
          383  +   end record;
          384  +
          385  +   pragma Convention (C, Z_Stream);
          386  +
          387  +   pragma Import (C, zlibVersion, "zlibVersion");
          388  +   pragma Import (C, Deflate, "deflate");
          389  +   pragma Import (C, DeflateEnd, "deflateEnd");
          390  +   pragma Import (C, Inflate, "inflate");
          391  +   pragma Import (C, InflateEnd, "inflateEnd");
          392  +   pragma Import (C, deflateSetDictionary, "deflateSetDictionary");
          393  +   pragma Import (C, deflateCopy, "deflateCopy");
          394  +   pragma Import (C, deflateReset, "deflateReset");
          395  +   pragma Import (C, deflateParams, "deflateParams");
          396  +   pragma Import (C, inflateSetDictionary, "inflateSetDictionary");
          397  +   pragma Import (C, inflateSync, "inflateSync");
          398  +   pragma Import (C, inflateReset, "inflateReset");
          399  +   pragma Import (C, compress, "compress");
          400  +   pragma Import (C, compress2, "compress2");
          401  +   pragma Import (C, uncompress, "uncompress");
          402  +   pragma Import (C, gzopen, "gzopen");
          403  +   pragma Import (C, gzdopen, "gzdopen");
          404  +   pragma Import (C, gzsetparams, "gzsetparams");
          405  +   pragma Import (C, gzread, "gzread");
          406  +   pragma Import (C, gzwrite, "gzwrite");
          407  +   pragma Import (C, gzprintf, "gzprintf");
          408  +   pragma Import (C, gzputs, "gzputs");
          409  +   pragma Import (C, gzgets, "gzgets");
          410  +   pragma Import (C, gzputc, "gzputc");
          411  +   pragma Import (C, gzgetc, "gzgetc");
          412  +   pragma Import (C, gzflush, "gzflush");
          413  +   pragma Import (C, gzseek, "gzseek");
          414  +   pragma Import (C, gzrewind, "gzrewind");
          415  +   pragma Import (C, gztell, "gztell");
          416  +   pragma Import (C, gzeof, "gzeof");
          417  +   pragma Import (C, gzclose, "gzclose");
          418  +   pragma Import (C, gzerror, "gzerror");
          419  +   pragma Import (C, adler32, "adler32");
          420  +   pragma Import (C, crc32, "crc32");
          421  +   pragma Import (C, deflateInit, "deflateInit_");
          422  +   pragma Import (C, inflateInit, "inflateInit_");
          423  +   pragma Import (C, deflateInit2, "deflateInit2_");
          424  +   pragma Import (C, inflateInit2, "inflateInit2_");
          425  +   pragma Import (C, zError, "zError");
          426  +   pragma Import (C, inflateSyncPoint, "inflateSyncPoint");
          427  +   pragma Import (C, get_crc_table, "get_crc_table");
          428  +
          429  +   --  since zlib 1.2.0:
          430  +
          431  +   pragma Import (C, inflateCopy, "inflateCopy");
          432  +   pragma Import (C, compressBound, "compressBound");
          433  +   pragma Import (C, deflateBound, "deflateBound");
          434  +   pragma Import (C, gzungetc, "gzungetc");
          435  +   pragma Import (C, zlibCompileFlags, "zlibCompileFlags");
          436  +
          437  +   pragma Import (C, inflateBackInit, "inflateBackInit_");
          438  +
          439  +   --  I stopped binding the inflateBack routines, becouse realize that
          440  +   --  it does not support zlib and gzip headers for now, and have no
          441  +   --  symmetric deflateBack routines.
          442  +   --  ZLib-Ada is symmetric regarding deflate/inflate data transformation
          443  +   --  and has a similar generic callback interface for the
          444  +   --  deflate/inflate transformation based on the regular Deflate/Inflate
          445  +   --  routines.
          446  +
          447  +   --  pragma Import (C, inflateBack, "inflateBack");
          448  +   --  pragma Import (C, inflateBackEnd, "inflateBackEnd");
          449  +
          450  +end ZLib.Thin;

Added compat/zlib/contrib/ada/zlib.adb.

            1  +----------------------------------------------------------------
            2  +--  ZLib for Ada thick binding.                               --
            3  +--                                                            --
            4  +--  Copyright (C) 2002-2004 Dmitriy Anisimkov                 --
            5  +--                                                            --
            6  +--  Open source license information is in the zlib.ads file.  --
            7  +----------------------------------------------------------------
            8  +
            9  +--  $Id: zlib.adb,v 1.31 2004/09/06 06:53:19 vagul Exp $
           10  +
           11  +with Ada.Exceptions;
           12  +with Ada.Unchecked_Conversion;
           13  +with Ada.Unchecked_Deallocation;
           14  +
           15  +with Interfaces.C.Strings;
           16  +
           17  +with ZLib.Thin;
           18  +
           19  +package body ZLib is
           20  +
           21  +   use type Thin.Int;
           22  +
           23  +   type Z_Stream is new Thin.Z_Stream;
           24  +
           25  +   type Return_Code_Enum is
           26  +      (OK,
           27  +       STREAM_END,
           28  +       NEED_DICT,
           29  +       ERRNO,
           30  +       STREAM_ERROR,
           31  +       DATA_ERROR,
           32  +       MEM_ERROR,
           33  +       BUF_ERROR,
           34  +       VERSION_ERROR);
           35  +
           36  +   type Flate_Step_Function is access
           37  +     function (Strm : in Thin.Z_Streamp; Flush : in Thin.Int) return Thin.Int;
           38  +   pragma Convention (C, Flate_Step_Function);
           39  +
           40  +   type Flate_End_Function is access
           41  +      function (Ctrm : in Thin.Z_Streamp) return Thin.Int;
           42  +   pragma Convention (C, Flate_End_Function);
           43  +
           44  +   type Flate_Type is record
           45  +      Step : Flate_Step_Function;
           46  +      Done : Flate_End_Function;
           47  +   end record;
           48  +
           49  +   subtype Footer_Array is Stream_Element_Array (1 .. 8);
           50  +
           51  +   Simple_GZip_Header : constant Stream_Element_Array (1 .. 10)
           52  +     := (16#1f#, 16#8b#,                 --  Magic header
           53  +         16#08#,                         --  Z_DEFLATED
           54  +         16#00#,                         --  Flags
           55  +         16#00#, 16#00#, 16#00#, 16#00#, --  Time
           56  +         16#00#,                         --  XFlags
           57  +         16#03#                          --  OS code
           58  +        );
           59  +   --  The simplest gzip header is not for informational, but just for
           60  +   --  gzip format compatibility.
           61  +   --  Note that some code below is using assumption
           62  +   --  Simple_GZip_Header'Last > Footer_Array'Last, so do not make
           63  +   --  Simple_GZip_Header'Last <= Footer_Array'Last.
           64  +
           65  +   Return_Code : constant array (Thin.Int range <>) of Return_Code_Enum
           66  +     := (0 => OK,
           67  +         1 => STREAM_END,
           68  +         2 => NEED_DICT,
           69  +        -1 => ERRNO,
           70  +        -2 => STREAM_ERROR,
           71  +        -3 => DATA_ERROR,
           72  +        -4 => MEM_ERROR,
           73  +        -5 => BUF_ERROR,
           74  +        -6 => VERSION_ERROR);
           75  +
           76  +   Flate : constant array (Boolean) of Flate_Type
           77  +     := (True  => (Step => Thin.Deflate'Access,
           78  +                   Done => Thin.DeflateEnd'Access),
           79  +         False => (Step => Thin.Inflate'Access,
           80  +                   Done => Thin.InflateEnd'Access));
           81  +
           82  +   Flush_Finish : constant array (Boolean) of Flush_Mode
           83  +     := (True => Finish, False => No_Flush);
           84  +
           85  +   procedure Raise_Error (Stream : in Z_Stream);
           86  +   pragma Inline (Raise_Error);
           87  +
           88  +   procedure Raise_Error (Message : in String);
           89  +   pragma Inline (Raise_Error);
           90  +
           91  +   procedure Check_Error (Stream : in Z_Stream; Code : in Thin.Int);
           92  +
           93  +   procedure Free is new Ada.Unchecked_Deallocation
           94  +      (Z_Stream, Z_Stream_Access);
           95  +
           96  +   function To_Thin_Access is new Ada.Unchecked_Conversion
           97  +     (Z_Stream_Access, Thin.Z_Streamp);
           98  +
           99  +   procedure Translate_GZip
          100  +     (Filter    : in out Filter_Type;
          101  +      In_Data   : in     Ada.Streams.Stream_Element_Array;
          102  +      In_Last   :    out Ada.Streams.Stream_Element_Offset;
          103  +      Out_Data  :    out Ada.Streams.Stream_Element_Array;
          104  +      Out_Last  :    out Ada.Streams.Stream_Element_Offset;
          105  +      Flush     : in     Flush_Mode);
          106  +   --  Separate translate routine for make gzip header.
          107  +
          108  +   procedure Translate_Auto
          109  +     (Filter    : in out Filter_Type;
          110  +      In_Data   : in     Ada.Streams.Stream_Element_Array;
          111  +      In_Last   :    out Ada.Streams.Stream_Element_Offset;
          112  +      Out_Data  :    out Ada.Streams.Stream_Element_Array;
          113  +      Out_Last  :    out Ada.Streams.Stream_Element_Offset;
          114  +      Flush     : in     Flush_Mode);
          115  +   --  translate routine without additional headers.
          116  +
          117  +   -----------------
          118  +   -- Check_Error --
          119  +   -----------------
          120  +
          121  +   procedure Check_Error (Stream : in Z_Stream; Code : in Thin.Int) is
          122  +      use type Thin.Int;
          123  +   begin
          124  +      if Code /= Thin.Z_OK then
          125  +         Raise_Error
          126  +            (Return_Code_Enum'Image (Return_Code (Code))
          127  +              & ": " & Last_Error_Message (Stream));
          128  +      end if;
          129  +   end Check_Error;
          130  +
          131  +   -----------
          132  +   -- Close --
          133  +   -----------
          134  +
          135  +   procedure Close
          136  +     (Filter       : in out Filter_Type;
          137  +      Ignore_Error : in     Boolean := False)
          138  +   is
          139  +      Code : Thin.Int;
          140  +   begin
          141  +      if not Ignore_Error and then not Is_Open (Filter) then
          142  +         raise Status_Error;
          143  +      end if;
          144  +
          145  +      Code := Flate (Filter.Compression).Done (To_Thin_Access (Filter.Strm));
          146  +
          147  +      if Ignore_Error or else Code = Thin.Z_OK then
          148  +         Free (Filter.Strm);
          149  +      else
          150  +         declare
          151  +            Error_Message : constant String
          152  +              := Last_Error_Message (Filter.Strm.all);
          153  +         begin
          154  +            Free (Filter.Strm);
          155  +            Ada.Exceptions.Raise_Exception
          156  +               (ZLib_Error'Identity,
          157  +                Return_Code_Enum'Image (Return_Code (Code))
          158  +                  & ": " & Error_Message);
          159  +         end;
          160  +      end if;
          161  +   end Close;
          162  +
          163  +   -----------
          164  +   -- CRC32 --
          165  +   -----------
          166  +
          167  +   function CRC32
          168  +     (CRC  : in Unsigned_32;
          169  +      Data : in Ada.Streams.Stream_Element_Array)
          170  +      return Unsigned_32
          171  +   is
          172  +      use Thin;
          173  +   begin
          174  +      return Unsigned_32 (crc32 (ULong (CRC),
          175  +                                 Data'Address,
          176  +                                 Data'Length));
          177  +   end CRC32;
          178  +
          179  +   procedure CRC32
          180  +     (CRC  : in out Unsigned_32;
          181  +      Data : in     Ada.Streams.Stream_Element_Array) is
          182  +   begin
          183  +      CRC := CRC32 (CRC, Data);
          184  +   end CRC32;
          185  +
          186  +   ------------------
          187  +   -- Deflate_Init --
          188  +   ------------------
          189  +
          190  +   procedure Deflate_Init
          191  +     (Filter       : in out Filter_Type;
          192  +      Level        : in     Compression_Level  := Default_Compression;
          193  +      Strategy     : in     Strategy_Type      := Default_Strategy;
          194  +      Method       : in     Compression_Method := Deflated;
          195  +      Window_Bits  : in     Window_Bits_Type   := Default_Window_Bits;
          196  +      Memory_Level : in     Memory_Level_Type  := Default_Memory_Level;
          197  +      Header       : in     Header_Type        := Default)
          198  +   is
          199  +      use type Thin.Int;
          200  +      Win_Bits : Thin.Int := Thin.Int (Window_Bits);
          201  +   begin
          202  +      if Is_Open (Filter) then
          203  +         raise Status_Error;
          204  +      end if;
          205  +
          206  +      --  We allow ZLib to make header only in case of default header type.
          207  +      --  Otherwise we would either do header by ourselfs, or do not do
          208  +      --  header at all.
          209  +
          210  +      if Header = None or else Header = GZip then
          211  +         Win_Bits := -Win_Bits;
          212  +      end if;
          213  +
          214  +      --  For the GZip CRC calculation and make headers.
          215  +
          216  +      if Header = GZip then
          217  +         Filter.CRC    := 0;
          218  +         Filter.Offset := Simple_GZip_Header'First;
          219  +      else
          220  +         Filter.Offset := Simple_GZip_Header'Last + 1;
          221  +      end if;
          222  +
          223  +      Filter.Strm        := new Z_Stream;
          224  +      Filter.Compression := True;
          225  +      Filter.Stream_End  := False;
          226  +      Filter.Header      := Header;
          227  +
          228  +      if Thin.Deflate_Init
          229  +           (To_Thin_Access (Filter.Strm),
          230  +            Level      => Thin.Int (Level),
          231  +            method     => Thin.Int (Method),
          232  +            windowBits => Win_Bits,
          233  +            memLevel   => Thin.Int (Memory_Level),
          234  +            strategy   => Thin.Int (Strategy)) /= Thin.Z_OK
          235  +      then
          236  +         Raise_Error (Filter.Strm.all);
          237  +      end if;
          238  +   end Deflate_Init;
          239  +
          240  +   -----------
          241  +   -- Flush --
          242  +   -----------
          243  +
          244  +   procedure Flush
          245  +     (Filter    : in out Filter_Type;
          246  +      Out_Data  :    out Ada.Streams.Stream_Element_Array;
          247  +      Out_Last  :    out Ada.Streams.Stream_Element_Offset;
          248  +      Flush     : in     Flush_Mode)
          249  +   is
          250  +      No_Data : Stream_Element_Array := (1 .. 0 => 0);
          251  +      Last    : Stream_Element_Offset;
          252  +   begin
          253  +      Translate (Filter, No_Data, Last, Out_Data, Out_Last, Flush);
          254  +   end Flush;
          255  +
          256  +   -----------------------
          257  +   -- Generic_Translate --
          258  +   -----------------------
          259  +
          260  +   procedure Generic_Translate
          261  +     (Filter          : in out ZLib.Filter_Type;
          262  +      In_Buffer_Size  : in     Integer := Default_Buffer_Size;
          263  +      Out_Buffer_Size : in     Integer := Default_Buffer_Size)
          264  +   is
          265  +      In_Buffer  : Stream_Element_Array
          266  +                     (1 .. Stream_Element_Offset (In_Buffer_Size));
          267  +      Out_Buffer : Stream_Element_Array
          268  +                     (1 .. Stream_Element_Offset (Out_Buffer_Size));
          269  +      Last       : Stream_Element_Offset;
          270  +      In_Last    : Stream_Element_Offset;
          271  +      In_First   : Stream_Element_Offset;
          272  +      Out_Last   : Stream_Element_Offset;
          273  +   begin
          274  +      Main : loop
          275  +         Data_In (In_Buffer, Last);
          276  +
          277  +         In_First := In_Buffer'First;
          278  +
          279  +         loop
          280  +            Translate
          281  +              (Filter   => Filter,
          282  +               In_Data  => In_Buffer (In_First .. Last),
          283  +               In_Last  => In_Last,
          284  +               Out_Data => Out_Buffer,
          285  +               Out_Last => Out_Last,
          286  +               Flush    => Flush_Finish (Last < In_Buffer'First));
          287  +
          288  +            if Out_Buffer'First <= Out_Last then
          289  +               Data_Out (Out_Buffer (Out_Buffer'First .. Out_Last));
          290  +            end if;
          291  +
          292  +            exit Main when Stream_End (Filter);
          293  +
          294  +            --  The end of in buffer.
          295  +
          296  +            exit when In_Last = Last;
          297  +
          298  +            In_First := In_Last + 1;
          299  +         end loop;
          300  +      end loop Main;
          301  +
          302  +   end Generic_Translate;
          303  +
          304  +   ------------------
          305  +   -- Inflate_Init --
          306  +   ------------------
          307  +
          308  +   procedure Inflate_Init
          309  +     (Filter      : in out Filter_Type;
          310  +      Window_Bits : in     Window_Bits_Type := Default_Window_Bits;
          311  +      Header      : in     Header_Type      := Default)
          312  +   is
          313  +      use type Thin.Int;
          314  +      Win_Bits : Thin.Int := Thin.Int (Window_Bits);
          315  +
          316  +      procedure Check_Version;
          317  +      --  Check the latest header types compatibility.
          318  +
          319  +      procedure Check_Version is
          320  +      begin
          321  +         if Version <= "1.1.4" then
          322  +            Raise_Error
          323  +              ("Inflate header type " & Header_Type'Image (Header)
          324  +               & " incompatible with ZLib version " & Version);
          325  +         end if;
          326  +      end Check_Version;
          327  +
          328  +   begin
          329  +      if Is_Open (Filter) then
          330  +         raise Status_Error;
          331  +      end if;
          332  +
          333  +      case Header is
          334  +         when None =>
          335  +            Check_Version;
          336  +
          337  +            --  Inflate data without headers determined
          338  +            --  by negative Win_Bits.
          339  +
          340  +            Win_Bits := -Win_Bits;
          341  +         when GZip =>
          342  +            Check_Version;
          343  +
          344  +            --  Inflate gzip data defined by flag 16.
          345  +
          346  +            Win_Bits := Win_Bits + 16;
          347  +         when Auto =>
          348  +            Check_Version;
          349  +
          350  +            --  Inflate with automatic detection
          351  +            --  of gzip or native header defined by flag 32.
          352  +
          353  +            Win_Bits := Win_Bits + 32;
          354  +         when Default => null;
          355  +      end case;
          356  +
          357  +      Filter.Strm        := new Z_Stream;
          358  +      Filter.Compression := False;
          359  +      Filter.Stream_End  := False;
          360  +      Filter.Header      := Header;
          361  +
          362  +      if Thin.Inflate_Init
          363  +         (To_Thin_Access (Filter.Strm), Win_Bits) /= Thin.Z_OK
          364  +      then
          365  +         Raise_Error (Filter.Strm.all);
          366  +      end if;
          367  +   end Inflate_Init;
          368  +
          369  +   -------------
          370  +   -- Is_Open --
          371  +   -------------
          372  +
          373  +   function Is_Open (Filter : in Filter_Type) return Boolean is
          374  +   begin
          375  +      return Filter.Strm /= null;
          376  +   end Is_Open;
          377  +
          378  +   -----------------
          379  +   -- Raise_Error --
          380  +   -----------------
          381  +
          382  +   procedure Raise_Error (Message : in String) is
          383  +   begin
          384  +      Ada.Exceptions.Raise_Exception (ZLib_Error'Identity, Message);
          385  +   end Raise_Error;
          386  +
          387  +   procedure Raise_Error (Stream : in Z_Stream) is
          388  +   begin
          389  +      Raise_Error (Last_Error_Message (Stream));
          390  +   end Raise_Error;
          391  +
          392  +   ----------
          393  +   -- Read --
          394  +   ----------
          395  +
          396  +   procedure Read
          397  +     (Filter : in out Filter_Type;
          398  +      Item   :    out Ada.Streams.Stream_Element_Array;
          399  +      Last   :    out Ada.Streams.Stream_Element_Offset;
          400  +      Flush  : in     Flush_Mode := No_Flush)
          401  +   is
          402  +      In_Last    : Stream_Element_Offset;
          403  +      Item_First : Ada.Streams.Stream_Element_Offset := Item'First;
          404  +      V_Flush    : Flush_Mode := Flush;
          405  +
          406  +   begin
          407  +      pragma Assert (Rest_First in Buffer'First .. Buffer'Last + 1);
          408  +      pragma Assert (Rest_Last in Buffer'First - 1 .. Buffer'Last);
          409  +
          410  +      loop
          411  +         if Rest_Last = Buffer'First - 1 then
          412  +            V_Flush := Finish;
          413  +
          414  +         elsif Rest_First > Rest_Last then
          415  +            Read (Buffer, Rest_Last);
          416  +            Rest_First := Buffer'First;
          417  +
          418  +            if Rest_Last < Buffer'First then
          419  +               V_Flush := Finish;
          420  +            end if;
          421  +         end if;
          422  +
          423  +         Translate
          424  +           (Filter   => Filter,
          425  +            In_Data  => Buffer (Rest_First .. Rest_Last),
          426  +            In_Last  => In_Last,
          427  +            Out_Data => Item (Item_First .. Item'Last),
          428  +            Out_Last => Last,
          429  +            Flush    => V_Flush);
          430  +
          431  +         Rest_First := In_Last + 1;
          432  +
          433  +         exit when Stream_End (Filter)
          434  +           or else Last = Item'Last
          435  +           or else (Last >= Item'First and then Allow_Read_Some);
          436  +
          437  +         Item_First := Last + 1;
          438  +      end loop;
          439  +   end Read;
          440  +
          441  +   ----------------
          442  +   -- Stream_End --
          443  +   ----------------
          444  +
          445  +   function Stream_End (Filter : in Filter_Type) return Boolean is
          446  +   begin
          447  +      if Filter.Header = GZip and Filter.Compression then
          448  +         return Filter.Stream_End
          449  +            and then Filter.Offset = Footer_Array'Last + 1;
          450  +      else
          451  +         return Filter.Stream_End;
          452  +      end if;
          453  +   end Stream_End;
          454  +
          455  +   --------------
          456  +   -- Total_In --
          457  +   --------------
          458  +
          459  +   function Total_In (Filter : in Filter_Type) return Count is
          460  +   begin
          461  +      return Count (Thin.Total_In (To_Thin_Access (Filter.Strm).all));
          462  +   end Total_In;
          463  +
          464  +   ---------------
          465  +   -- Total_Out --
          466  +   ---------------
          467  +
          468  +   function Total_Out (Filter : in Filter_Type) return Count is
          469  +   begin
          470  +      return Count (Thin.Total_Out (To_Thin_Access (Filter.Strm).all));
          471  +   end Total_Out;
          472  +
          473  +   ---------------
          474  +   -- Translate --
          475  +   ---------------
          476  +
          477  +   procedure Translate
          478  +     (Filter    : in out Filter_Type;
          479  +      In_Data   : in     Ada.Streams.Stream_Element_Array;
          480  +      In_Last   :    out Ada.Streams.Stream_Element_Offset;
          481  +      Out_Data  :    out Ada.Streams.Stream_Element_Array;
          482  +      Out_Last  :    out Ada.Streams.Stream_Element_Offset;
          483  +      Flush     : in     Flush_Mode) is
          484  +   begin
          485  +      if Filter.Header = GZip and then Filter.Compression then
          486  +         Translate_GZip
          487  +           (Filter   => Filter,
          488  +            In_Data  => In_Data,
          489  +            In_Last  => In_Last,
          490  +            Out_Data => Out_Data,
          491  +            Out_Last => Out_Last,
          492  +            Flush    => Flush);
          493  +      else
          494  +         Translate_Auto
          495  +           (Filter   => Filter,
          496  +            In_Data  => In_Data,
          497  +            In_Last  => In_Last,
          498  +            Out_Data => Out_Data,
          499  +            Out_Last => Out_Last,
          500  +            Flush    => Flush);
          501  +      end if;
          502  +   end Translate;
          503  +
          504  +   --------------------
          505  +   -- Translate_Auto --
          506  +   --------------------
          507  +
          508  +   procedure Translate_Auto
          509  +     (Filter    : in out Filter_Type;
          510  +      In_Data   : in     Ada.Streams.Stream_Element_Array;
          511  +      In_Last   :    out Ada.Streams.Stream_Element_Offset;
          512  +      Out_Data  :    out Ada.Streams.Stream_Element_Array;
          513  +      Out_Last  :    out Ada.Streams.Stream_Element_Offset;
          514  +      Flush     : in     Flush_Mode)
          515  +   is
          516  +      use type Thin.Int;
          517  +      Code : Thin.Int;
          518  +
          519  +   begin
          520  +      if not Is_Open (Filter) then
          521  +         raise Status_Error;
          522  +      end if;
          523  +
          524  +      if Out_Data'Length = 0 and then In_Data'Length = 0 then
          525  +         raise Constraint_Error;
          526  +      end if;
          527  +
          528  +      Set_Out (Filter.Strm.all, Out_Data'Address, Out_Data'Length);
          529  +      Set_In  (Filter.Strm.all, In_Data'Address, In_Data'Length);
          530  +
          531  +      Code := Flate (Filter.Compression).Step
          532  +        (To_Thin_Access (Filter.Strm),
          533  +         Thin.Int (Flush));
          534  +
          535  +      if Code = Thin.Z_STREAM_END then
          536  +         Filter.Stream_End := True;
          537  +      else
          538  +         Check_Error (Filter.Strm.all, Code);
          539  +      end if;
          540  +
          541  +      In_Last  := In_Data'Last
          542  +         - Stream_Element_Offset (Avail_In (Filter.Strm.all));
          543  +      Out_Last := Out_Data'Last
          544  +         - Stream_Element_Offset (Avail_Out (Filter.Strm.all));
          545  +   end Translate_Auto;
          546  +
          547  +   --------------------
          548  +   -- Translate_GZip --
          549  +   --------------------
          550  +
          551  +   procedure Translate_GZip
          552  +     (Filter    : in out Filter_Type;
          553  +      In_Data   : in     Ada.Streams.Stream_Element_Array;
          554  +      In_Last   :    out Ada.Streams.Stream_Element_Offset;
          555  +      Out_Data  :    out Ada.Streams.Stream_Element_Array;
          556  +      Out_Last  :    out Ada.Streams.Stream_Element_Offset;
          557  +      Flush     : in     Flush_Mode)
          558  +   is
          559  +      Out_First : Stream_Element_Offset;
          560  +
          561  +      procedure Add_Data (Data : in Stream_Element_Array);
          562  +      --  Add data to stream from the Filter.Offset till necessary,
          563  +      --  used for add gzip headr/footer.
          564  +
          565  +      procedure Put_32
          566  +        (Item : in out Stream_Element_Array;
          567  +         Data : in     Unsigned_32);
          568  +      pragma Inline (Put_32);
          569  +
          570  +      --------------
          571  +      -- Add_Data --
          572  +      --------------
          573  +
          574  +      procedure Add_Data (Data : in Stream_Element_Array) is
          575  +         Data_First : Stream_Element_Offset renames Filter.Offset;
          576  +         Data_Last  : Stream_Element_Offset;
          577  +         Data_Len   : Stream_Element_Offset; --  -1
          578  +         Out_Len    : Stream_Element_Offset; --  -1
          579  +      begin
          580  +         Out_First := Out_Last + 1;
          581  +
          582  +         if Data_First > Data'Last then
          583  +            return;
          584  +         end if;
          585  +
          586  +         Data_Len  := Data'Last     - Data_First;
          587  +         Out_Len   := Out_Data'Last - Out_First;
          588  +
          589  +         if Data_Len <= Out_Len then
          590  +            Out_Last  := Out_First  + Data_Len;
          591  +            Data_Last := Data'Last;
          592  +         else
          593  +            Out_Last  := Out_Data'Last;
          594  +            Data_Last := Data_First + Out_Len;
          595  +         end if;
          596  +
          597  +         Out_Data (Out_First .. Out_Last) := Data (Data_First .. Data_Last);
          598  +
          599  +         Data_First := Data_Last + 1;
          600  +         Out_First  := Out_Last + 1;
          601  +      end Add_Data;
          602  +
          603  +      ------------
          604  +      -- Put_32 --
          605  +      ------------
          606  +
          607  +      procedure Put_32
          608  +        (Item : in out Stream_Element_Array;
          609  +         Data : in     Unsigned_32)
          610  +      is
          611  +         D : Unsigned_32 := Data;
          612  +      begin
          613  +         for J in Item'First .. Item'First + 3 loop
          614  +            Item (J) := Stream_Element (D and 16#FF#);
          615  +            D := Shift_Right (D, 8);
          616  +         end loop;
          617  +      end Put_32;
          618  +
          619  +   begin
          620  +      Out_Last := Out_Data'First - 1;
          621  +
          622  +      if not Filter.Stream_End then
          623  +         Add_Data (Simple_GZip_Header);
          624  +
          625  +         Translate_Auto
          626  +           (Filter   => Filter,
          627  +            In_Data  => In_Data,
          628  +            In_Last  => In_Last,
          629  +            Out_Data => Out_Data (Out_First .. Out_Data'Last),
          630  +            Out_Last => Out_Last,
          631  +            Flush    => Flush);
          632  +
          633  +         CRC32 (Filter.CRC, In_Data (In_Data'First .. In_Last));
          634  +      end if;
          635  +
          636  +      if Filter.Stream_End and then Out_Last <= Out_Data'Last then
          637  +         --  This detection method would work only when
          638  +         --  Simple_GZip_Header'Last > Footer_Array'Last
          639  +
          640  +         if Filter.Offset = Simple_GZip_Header'Last + 1 then
          641  +            Filter.Offset := Footer_Array'First;
          642  +         end if;
          643  +
          644  +         declare
          645  +            Footer : Footer_Array;
          646  +         begin
          647  +            Put_32 (Footer, Filter.CRC);
          648  +            Put_32 (Footer (Footer'First + 4 .. Footer'Last),
          649  +                    Unsigned_32 (Total_In (Filter)));
          650  +            Add_Data (Footer);
          651  +         end;
          652  +      end if;
          653  +   end Translate_GZip;
          654  +
          655  +   -------------
          656  +   -- Version --
          657  +   -------------
          658  +
          659  +   function Version return String is
          660  +   begin
          661  +      return Interfaces.C.Strings.Value (Thin.zlibVersion);
          662  +   end Version;
          663  +
          664  +   -----------
          665  +   -- Write --
          666  +   -----------
          667  +
          668  +   procedure Write
          669  +     (Filter : in out Filter_Type;
          670  +      Item   : in     Ada.Streams.Stream_Element_Array;
          671  +      Flush  : in     Flush_Mode := No_Flush)
          672  +   is
          673  +      Buffer   : Stream_Element_Array (1 .. Buffer_Size);
          674  +      In_Last  : Stream_Element_Offset;
          675  +      Out_Last : Stream_Element_Offset;
          676  +      In_First : Stream_Element_Offset := Item'First;
          677  +   begin
          678  +      if Item'Length = 0 and Flush = No_Flush then
          679  +         return;
          680  +      end if;
          681  +
          682  +      loop
          683  +         Translate
          684  +           (Filter   => Filter,
          685  +            In_Data  => Item (In_First .. Item'Last),
          686  +            In_Last  => In_Last,
          687  +            Out_Data => Buffer,
          688  +            Out_Last => Out_Last,
          689  +            Flush    => Flush);
          690  +
          691  +         if Out_Last >= Buffer'First then
          692  +            Write (Buffer (1 .. Out_Last));
          693  +         end if;
          694  +
          695  +         exit when In_Last = Item'Last or Stream_End (Filter);
          696  +
          697  +         In_First := In_Last + 1;
          698  +      end loop;
          699  +   end Write;
          700  +
          701  +end ZLib;

Added compat/zlib/contrib/ada/zlib.ads.

            1  +------------------------------------------------------------------------------
            2  +--                      ZLib for Ada thick binding.                         --
            3  +--                                                                          --
            4  +--              Copyright (C) 2002-2004 Dmitriy Anisimkov                   --
            5  +--                                                                          --
            6  +--  This library is free software; you can redistribute it and/or modify    --
            7  +--  it under the terms of the GNU General Public License as published by    --
            8  +--  the Free Software Foundation; either version 2 of the License, or (at   --
            9  +--  your option) any later version.                                         --
           10  +--                                                                          --
           11  +--  This library is distributed in the hope that it will be useful, but     --
           12  +--  WITHOUT ANY WARRANTY; without even the implied warranty of              --
           13  +--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU       --
           14  +--  General Public License for more details.                                --
           15  +--                                                                          --
           16  +--  You should have received a copy of the GNU General Public License       --
           17  +--  along with this library; if not, write to the Free Software Foundation, --
           18  +--  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.          --
           19  +--                                                                          --
           20  +--  As a special exception, if other files instantiate generics from this   --
           21  +--  unit, or you link this unit with other files to produce an executable,  --
           22  +--  this  unit  does not  by itself cause  the resulting executable to be   --
           23  +--  covered by the GNU General Public License. This exception does not      --
           24  +--  however invalidate any other reasons why the executable file  might be  --
           25  +--  covered by the  GNU Public License.                                     --
           26  +------------------------------------------------------------------------------
           27  +
           28  +--  $Id: zlib.ads,v 1.26 2004/09/06 06:53:19 vagul Exp $
           29  +
           30  +with Ada.Streams;
           31  +
           32  +with Interfaces;
           33  +
           34  +package ZLib is
           35  +
           36  +   ZLib_Error   : exception;
           37  +   Status_Error : exception;
           38  +
           39  +   type Compression_Level is new Integer range -1 .. 9;
           40  +
           41  +   type Flush_Mode is private;
           42  +
           43  +   type Compression_Method is private;
           44  +
           45  +   type Window_Bits_Type is new Integer range 8 .. 15;
           46  +
           47  +   type Memory_Level_Type is new Integer range 1 .. 9;
           48  +
           49  +   type Unsigned_32 is new Interfaces.Unsigned_32;
           50  +
           51  +   type Strategy_Type is private;
           52  +
           53  +   type Header_Type is (None, Auto, Default, GZip);
           54  +   --  Header type usage have a some limitation for inflate.
           55  +   --  See comment for Inflate_Init.
           56  +
           57  +   subtype Count is Ada.Streams.Stream_Element_Count;
           58  +
           59  +   Default_Memory_Level : constant Memory_Level_Type := 8;
           60  +   Default_Window_Bits  : constant Window_Bits_Type  := 15;
           61  +
           62  +   ----------------------------------
           63  +   -- Compression method constants --
           64  +   ----------------------------------
           65  +
           66  +   Deflated : constant Compression_Method;
           67  +   --  Only one method allowed in this ZLib version
           68  +
           69  +   ---------------------------------
           70  +   -- Compression level constants --
           71  +   ---------------------------------
           72  +
           73  +   No_Compression      : constant Compression_Level := 0;
           74  +   Best_Speed          : constant Compression_Level := 1;
           75  +   Best_Compression    : constant Compression_Level := 9;
           76  +   Default_Compression : constant Compression_Level := -1;
           77  +
           78  +   --------------------------
           79  +   -- Flush mode constants --
           80  +   --------------------------
           81  +
           82  +   No_Flush      : constant Flush_Mode;
           83  +   --  Regular way for compression, no flush
           84  +
           85  +   Partial_Flush : constant Flush_Mode;
           86  +   --  Will be removed, use Z_SYNC_FLUSH instead
           87  +
           88  +   Sync_Flush    : constant Flush_Mode;
           89  +   --  All pending output is flushed to the output buffer and the output
           90  +   --  is aligned on a byte boundary, so that the decompressor can get all
           91  +   --  input data available so far. (In particular avail_in is zero after the
           92  +   --  call if enough output space has been provided  before the call.)
           93  +   --  Flushing may degrade compression for some compression algorithms and so
           94  +   --  it should be used only when necessary.
           95  +
           96  +   Block_Flush   : constant Flush_Mode;
           97  +   --  Z_BLOCK requests that inflate() stop
           98  +   --  if and when it get to the next deflate block boundary. When decoding the
           99  +   --  zlib or gzip format, this will cause inflate() to return immediately
          100  +   --  after the header and before the first block. When doing a raw inflate,
          101  +   --  inflate() will go ahead and process the first block, and will return
          102  +   --  when it gets to the end of that block, or when it runs out of data.
          103  +
          104  +   Full_Flush    : constant Flush_Mode;
          105  +   --  All output is flushed as with SYNC_FLUSH, and the compression state
          106  +   --  is reset so that decompression can restart from this point if previous
          107  +   --  compressed data has been damaged or if random access is desired. Using
          108  +   --  Full_Flush too often can seriously degrade the compression.
          109  +
          110  +   Finish        : constant Flush_Mode;
          111  +   --  Just for tell the compressor that input data is complete.
          112  +
          113  +   ------------------------------------
          114  +   -- Compression strategy constants --
          115  +   ------------------------------------
          116  +
          117  +   --  RLE stategy could be used only in version 1.2.0 and later.
          118  +
          119  +   Filtered         : constant Strategy_Type;
          120  +   Huffman_Only     : constant Strategy_Type;
          121  +   RLE              : constant Strategy_Type;
          122  +   Default_Strategy : constant Strategy_Type;
          123  +
          124  +   Default_Buffer_Size : constant := 4096;
          125  +
          126  +   type Filter_Type is tagged limited private;
          127  +   --  The filter is for compression and for decompression.
          128  +   --  The usage of the type is depend of its initialization.
          129  +
          130  +   function Version return String;
          131  +   pragma Inline (Version);
          132  +   --  Return string representation of the ZLib version.
          133  +
          134  +   procedure Deflate_Init
          135  +     (Filter       : in out Filter_Type;
          136  +      Level        : in     Compression_Level  := Default_Compression;
          137  +      Strategy     : in     Strategy_Type      := Default_Strategy;
          138  +      Method       : in     Compression_Method := Deflated;
          139  +      Window_Bits  : in     Window_Bits_Type   := Default_Window_Bits;
          140  +      Memory_Level : in     Memory_Level_Type  := Default_Memory_Level;
          141  +      Header       : in     Header_Type        := Default);
          142  +   --  Compressor initialization.
          143  +   --  When Header parameter is Auto or Default, then default zlib header
          144  +   --  would be provided for compressed data.
          145  +   --  When Header is GZip, then gzip header would be set instead of
          146  +   --  default header.
          147  +   --  When Header is None, no header would be set for compressed data.
          148  +
          149  +   procedure Inflate_Init
          150  +     (Filter      : in out Filter_Type;
          151  +      Window_Bits : in     Window_Bits_Type := Default_Window_Bits;
          152  +      Header      : in     Header_Type      := Default);
          153  +   --  Decompressor initialization.
          154  +   --  Default header type mean that ZLib default header is expecting in the
          155  +   --  input compressed stream.
          156  +   --  Header type None mean that no header is expecting in the input stream.
          157  +   --  GZip header type mean that GZip header is expecting in the
          158  +   --  input compressed stream.
          159  +   --  Auto header type mean that header type (GZip or Native) would be
          160  +   --  detected automatically in the input stream.
          161  +   --  Note that header types parameter values None, GZip and Auto are
          162  +   --  supported for inflate routine only in ZLib versions 1.2.0.2 and later.
          163  +   --  Deflate_Init is supporting all header types.
          164  +
          165  +   function Is_Open (Filter : in Filter_Type) return Boolean;
          166  +   pragma Inline (Is_Open);
          167  +   --  Is the filter opened for compression or decompression.
          168  +
          169  +   procedure Close
          170  +     (Filter       : in out Filter_Type;
          171  +      Ignore_Error : in     Boolean := False);
          172  +   --  Closing the compression or decompressor.
          173  +   --  If stream is closing before the complete and Ignore_Error is False,
          174  +   --  The exception would be raised.
          175  +
          176  +   generic
          177  +      with procedure Data_In
          178  +        (Item : out Ada.Streams.Stream_Element_Array;
          179  +         Last : out Ada.Streams.Stream_Element_Offset);
          180  +      with procedure Data_Out
          181  +        (Item : in Ada.Streams.Stream_Element_Array);
          182  +   procedure Generic_Translate
          183  +     (Filter          : in out Filter_Type;
          184  +      In_Buffer_Size  : in     Integer := Default_Buffer_Size;
          185  +      Out_Buffer_Size : in     Integer := Default_Buffer_Size);
          186  +   --  Compress/decompress data fetch from Data_In routine and pass the result
          187  +   --  to the Data_Out routine. User should provide Data_In and Data_Out
          188  +   --  for compression/decompression data flow.
          189  +   --  Compression or decompression depend on Filter initialization.
          190  +
          191  +   function Total_In (Filter : in Filter_Type) return Count;
          192  +   pragma Inline (Total_In);
          193  +   --  Returns total number of input bytes read so far
          194  +
          195  +   function Total_Out (Filter : in Filter_Type) return Count;
          196  +   pragma Inline (Total_Out);
          197  +   --  Returns total number of bytes output so far
          198  +
          199  +   function CRC32
          200  +     (CRC    : in Unsigned_32;
          201  +      Data   : in Ada.Streams.Stream_Element_Array)
          202  +      return Unsigned_32;
          203  +   pragma Inline (CRC32);
          204  +   --  Compute CRC32, it could be necessary for make gzip format
          205  +
          206  +   procedure CRC32
          207  +     (CRC  : in out Unsigned_32;
          208  +      Data : in     Ada.Streams.Stream_Element_Array);
          209  +   pragma Inline (CRC32);
          210  +   --  Compute CRC32, it could be necessary for make gzip format
          211  +
          212  +   -------------------------------------------------
          213  +   --  Below is more complex low level routines.  --
          214  +   -------------------------------------------------
          215  +
          216  +   procedure Translate
          217  +     (Filter    : in out Filter_Type;
          218  +      In_Data   : in     Ada.Streams.Stream_Element_Array;
          219  +      In_Last   :    out Ada.Streams.Stream_Element_Offset;
          220  +      Out_Data  :    out Ada.Streams.Stream_Element_Array;
          221  +      Out_Last  :    out Ada.Streams.Stream_Element_Offset;
          222  +      Flush     : in     Flush_Mode);
          223  +   --  Compress/decompress the In_Data buffer and place the result into
          224  +   --  Out_Data. In_Last is the index of last element from In_Data accepted by
          225  +   --  the Filter. Out_Last is the last element of the received data from
          226  +   --  Filter. To tell the filter that incoming data are complete put the
          227  +   --  Flush parameter to Finish.
          228  +
          229  +   function Stream_End (Filter : in Filter_Type) return Boolean;
          230  +   pragma Inline (Stream_End);
          231  +   --  Return the true when the stream is complete.
          232  +
          233  +   procedure Flush
          234  +     (Filter    : in out Filter_Type;
          235  +      Out_Data  :    out Ada.Streams.Stream_Element_Array;
          236  +      Out_Last  :    out Ada.Streams.Stream_Element_Offset;
          237  +      Flush     : in     Flush_Mode);
          238  +   pragma Inline (Flush);
          239  +   --  Flushing the data from the compressor.
          240  +
          241  +   generic
          242  +      with procedure Write
          243  +        (Item : in Ada.Streams.Stream_Element_Array);
          244  +      --  User should provide this routine for accept
          245  +      --  compressed/decompressed data.
          246  +
          247  +      Buffer_Size : in Ada.Streams.Stream_Element_Offset
          248  +         := Default_Buffer_Size;
          249  +      --  Buffer size for Write user routine.
          250  +
          251  +   procedure Write
          252  +     (Filter  : in out Filter_Type;
          253  +      Item    : in     Ada.Streams.Stream_Element_Array;
          254  +      Flush   : in     Flush_Mode := No_Flush);
          255  +   --  Compress/Decompress data from Item to the generic parameter procedure
          256  +   --  Write. Output buffer size could be set in Buffer_Size generic parameter.
          257  +
          258  +   generic
          259  +      with procedure Read
          260  +        (Item : out Ada.Streams.Stream_Element_Array;
          261  +         Last : out Ada.Streams.Stream_Element_Offset);
          262  +      --  User should provide data for compression/decompression
          263  +      --  thru this routine.
          264  +
          265  +      Buffer : in out Ada.Streams.Stream_Element_Array;
          266  +      --  Buffer for keep remaining data from the previous
          267  +      --  back read.
          268  +
          269  +      Rest_First, Rest_Last : in out Ada.Streams.Stream_Element_Offset;
          270  +      --  Rest_First have to be initialized to Buffer'Last + 1
          271  +      --  Rest_Last have to be initialized to Buffer'Last
          272  +      --  before usage.
          273  +
          274  +      Allow_Read_Some : in Boolean := False;
          275  +      --  Is it allowed to return Last < Item'Last before end of data.
          276  +
          277  +   procedure Read
          278  +     (Filter : in out Filter_Type;
          279  +      Item   :    out Ada.Streams.Stream_Element_Array;
          280  +      Last   :    out Ada.Streams.Stream_Element_Offset;
          281  +      Flush  : in     Flush_Mode := No_Flush);
          282  +   --  Compress/Decompress data from generic parameter procedure Read to the
          283  +   --  Item. User should provide Buffer and initialized Rest_First, Rest_Last
          284  +   --  indicators. If Allow_Read_Some is True, Read routines could return
          285  +   --  Last < Item'Last only at end of stream.
          286  +
          287  +private
          288  +
          289  +   use Ada.Streams;
          290  +
          291  +   pragma Assert (Ada.Streams.Stream_Element'Size    =    8);
          292  +   pragma Assert (Ada.Streams.Stream_Element'Modulus = 2**8);
          293  +
          294  +   type Flush_Mode is new Integer range 0 .. 5;
          295  +
          296  +   type Compression_Method is new Integer range 8 .. 8;
          297  +
          298  +   type Strategy_Type is new Integer range 0 .. 3;
          299  +
          300  +   No_Flush      : constant Flush_Mode := 0;
          301  +   Partial_Flush : constant Flush_Mode := 1;
          302  +   Sync_Flush    : constant Flush_Mode := 2;
          303  +   Full_Flush    : constant Flush_Mode := 3;
          304  +   Finish        : constant Flush_Mode := 4;
          305  +   Block_Flush   : constant Flush_Mode := 5;
          306  +
          307  +   Filtered         : constant Strategy_Type := 1;
          308  +   Huffman_Only     : constant Strategy_Type := 2;
          309  +   RLE              : constant Strategy_Type := 3;
          310  +   Default_Strategy : constant Strategy_Type := 0;
          311  +
          312  +   Deflated : constant Compression_Method := 8;
          313  +
          314  +   type Z_Stream;
          315  +
          316  +   type Z_Stream_Access is access all Z_Stream;
          317  +
          318  +   type Filter_Type is tagged limited record
          319  +      Strm        : Z_Stream_Access;
          320  +      Compression : Boolean;
          321  +      Stream_End  : Boolean;
          322  +      Header      : Header_Type;
          323  +      CRC         : Unsigned_32;
          324  +      Offset      : Stream_Element_Offset;
          325  +      --  Offset for gzip header/footer output.
          326  +   end record;
          327  +
          328  +end ZLib;

Added compat/zlib/contrib/ada/zlib.gpr.

            1  +project Zlib is
            2  +
            3  +   for Languages use ("Ada");
            4  +   for Source_Dirs use (".");
            5  +   for Object_Dir use ".";
            6  +   for Main use ("test.adb", "mtest.adb", "read.adb", "buffer_demo");
            7  +
            8  +   package Compiler is
            9  +      for Default_Switches ("ada") use ("-gnatwcfilopru", "-gnatVcdfimorst", "-gnatyabcefhiklmnoprst");
           10  +   end Compiler;
           11  +
           12  +   package Linker is
           13  +      for Default_Switches ("ada") use ("-lz");
           14  +   end Linker;
           15  +
           16  +   package Builder is
           17  +      for Default_Switches ("ada") use ("-s", "-gnatQ");
           18  +   end Builder;
           19  +
           20  +end Zlib;

Added compat/zlib/contrib/amd64/amd64-match.S.

            1  +/*
            2  + * match.S -- optimized version of longest_match()
            3  + * based on the similar work by Gilles Vollant, and Brian Raiter, written 1998
            4  + *
            5  + * This is free software; you can redistribute it and/or modify it
            6  + * under the terms of the BSD License. Use by owners of Che Guevarra
            7  + * parafernalia is prohibited, where possible, and highly discouraged
            8  + * elsewhere.
            9  + */
           10  +
           11  +#ifndef NO_UNDERLINE
           12  +#	define	match_init	_match_init
           13  +#	define	longest_match	_longest_match
           14  +#endif
           15  +
           16  +#define	scanend		ebx
           17  +#define	scanendw	bx
           18  +#define	chainlenwmask	edx /* high word: current chain len low word: s->wmask */
           19  +#define	curmatch	rsi
           20  +#define	curmatchd	esi
           21  +#define	windowbestlen	r8
           22  +#define	scanalign	r9
           23  +#define	scanalignd	r9d
           24  +#define	window		r10
           25  +#define	bestlen		r11
           26  +#define	bestlend	r11d
           27  +#define	scanstart	r12d
           28  +#define	scanstartw	r12w
           29  +#define scan		r13
           30  +#define nicematch	r14d
           31  +#define	limit		r15
           32  +#define	limitd		r15d
           33  +#define prev		rcx
           34  +
           35  +/*
           36  + * The 258 is a "magic number, not a parameter -- changing it
           37  + * breaks the hell loose
           38  + */
           39  +#define	MAX_MATCH	(258)
           40  +#define	MIN_MATCH	(3)
           41  +#define	MIN_LOOKAHEAD	(MAX_MATCH + MIN_MATCH + 1)
           42  +#define	MAX_MATCH_8	((MAX_MATCH + 7) & ~7)
           43  +
           44  +/* stack frame offsets */
           45  +#define	LocalVarsSize	(112)
           46  +#define _chainlenwmask	( 8-LocalVarsSize)(%rsp)
           47  +#define _windowbestlen	(16-LocalVarsSize)(%rsp)
           48  +#define save_r14        (24-LocalVarsSize)(%rsp)
           49  +#define save_rsi        (32-LocalVarsSize)(%rsp)
           50  +#define save_rbx        (40-LocalVarsSize)(%rsp)
           51  +#define save_r12        (56-LocalVarsSize)(%rsp)
           52  +#define save_r13        (64-LocalVarsSize)(%rsp)
           53  +#define save_r15        (80-LocalVarsSize)(%rsp)
           54  +
           55  +
           56  +.globl	match_init, longest_match
           57  +
           58  +/*
           59  + * On AMD64 the first argument of a function (in our case -- the pointer to
           60  + * deflate_state structure) is passed in %rdi, hence our offsets below are
           61  + * all off of that.
           62  + */
           63  +
           64  +/* you can check the structure offset by running
           65  +
           66  +#include <stdlib.h>
           67  +#include <stdio.h>
           68  +#include "deflate.h"
           69  +
           70  +void print_depl()
           71  +{
           72  +deflate_state ds;
           73  +deflate_state *s=&ds;
           74  +printf("size pointer=%u\n",(int)sizeof(void*));
           75  +
           76  +printf("#define dsWSize         (%3u)(%%rdi)\n",(int)(((char*)&(s->w_size))-((char*)s)));
           77  +printf("#define dsWMask         (%3u)(%%rdi)\n",(int)(((char*)&(s->w_mask))-((char*)s)));
           78  +printf("#define dsWindow        (%3u)(%%rdi)\n",(int)(((char*)&(s->window))-((char*)s)));
           79  +printf("#define dsPrev          (%3u)(%%rdi)\n",(int)(((char*)&(s->prev))-((char*)s)));
           80  +printf("#define dsMatchLen      (%3u)(%%rdi)\n",(int)(((char*)&(s->match_length))-((char*)s)));
           81  +printf("#define dsPrevMatch     (%3u)(%%rdi)\n",(int)(((char*)&(s->prev_match))-((char*)s)));
           82  +printf("#define dsStrStart      (%3u)(%%rdi)\n",(int)(((char*)&(s->strstart))-((char*)s)));
           83  +printf("#define dsMatchStart    (%3u)(%%rdi)\n",(int)(((char*)&(s->match_start))-((char*)s)));
           84  +printf("#define dsLookahead     (%3u)(%%rdi)\n",(int)(((char*)&(s->lookahead))-((char*)s)));
           85  +printf("#define dsPrevLen       (%3u)(%%rdi)\n",(int)(((char*)&(s->prev_length))-((char*)s)));
           86  +printf("#define dsMaxChainLen   (%3u)(%%rdi)\n",(int)(((char*)&(s->max_chain_length))-((char*)s)));
           87  +printf("#define dsGoodMatch     (%3u)(%%rdi)\n",(int)(((char*)&(s->good_match))-((char*)s)));
           88  +printf("#define dsNiceMatch     (%3u)(%%rdi)\n",(int)(((char*)&(s->nice_match))-((char*)s)));
           89  +}
           90  +
           91  +*/
           92  +
           93  +
           94  +/*
           95  +  to compile for XCode 3.2 on MacOSX x86_64
           96  +  - run "gcc -g -c -DXCODE_MAC_X64_STRUCTURE amd64-match.S"
           97  + */
           98  +
           99  +
          100  +#ifndef CURRENT_LINX_XCODE_MAC_X64_STRUCTURE
          101  +#define dsWSize		( 68)(%rdi)
          102  +#define dsWMask		( 76)(%rdi)
          103  +#define dsWindow	( 80)(%rdi)
          104  +#define dsPrev		( 96)(%rdi)
          105  +#define dsMatchLen	(144)(%rdi)
          106  +#define dsPrevMatch	(148)(%rdi)
          107  +#define dsStrStart	(156)(%rdi)
          108  +#define dsMatchStart	(160)(%rdi)
          109  +#define dsLookahead	(164)(%rdi)
          110  +#define dsPrevLen	(168)(%rdi)
          111  +#define dsMaxChainLen	(172)(%rdi)
          112  +#define dsGoodMatch	(188)(%rdi)
          113  +#define dsNiceMatch	(192)(%rdi)
          114  +
          115  +#else 
          116  +
          117  +#ifndef STRUCT_OFFSET
          118  +#	define STRUCT_OFFSET	(0)
          119  +#endif
          120  +
          121  +
          122  +#define dsWSize		( 56 + STRUCT_OFFSET)(%rdi)
          123  +#define dsWMask		( 64 + STRUCT_OFFSET)(%rdi)
          124  +#define dsWindow	( 72 + STRUCT_OFFSET)(%rdi)
          125  +#define dsPrev		( 88 + STRUCT_OFFSET)(%rdi)
          126  +#define dsMatchLen	(136 + STRUCT_OFFSET)(%rdi)
          127  +#define dsPrevMatch	(140 + STRUCT_OFFSET)(%rdi)
          128  +#define dsStrStart	(148 + STRUCT_OFFSET)(%rdi)
          129  +#define dsMatchStart	(152 + STRUCT_OFFSET)(%rdi)
          130  +#define dsLookahead	(156 + STRUCT_OFFSET)(%rdi)
          131  +#define dsPrevLen	(160 + STRUCT_OFFSET)(%rdi)
          132  +#define dsMaxChainLen	(164 + STRUCT_OFFSET)(%rdi)
          133  +#define dsGoodMatch	(180 + STRUCT_OFFSET)(%rdi)
          134  +#define dsNiceMatch	(184 + STRUCT_OFFSET)(%rdi)
          135  +
          136  +#endif
          137  +
          138  +
          139  +
          140  +
          141  +.text
          142  +
          143  +/* uInt longest_match(deflate_state *deflatestate, IPos curmatch) */
          144  +
          145  +longest_match:
          146  +/*
          147  + * Retrieve the function arguments. %curmatch will hold cur_match
          148  + * throughout the entire function (passed via rsi on amd64).
          149  + * rdi will hold the pointer to the deflate_state (first arg on amd64)
          150  + */
          151  +		mov     %rsi, save_rsi
          152  +		mov     %rbx, save_rbx
          153  +		mov	%r12, save_r12
          154  +		mov     %r13, save_r13
          155  +		mov     %r14, save_r14
          156  +		mov     %r15, save_r15
          157  +
          158  +/* uInt wmask = s->w_mask;						*/
          159  +/* unsigned chain_length = s->max_chain_length;				*/
          160  +/* if (s->prev_length >= s->good_match) {				*/
          161  +/*     chain_length >>= 2;						*/
          162  +/* }									*/
          163  +
          164  +		movl	dsPrevLen, %eax
          165  +		movl	dsGoodMatch, %ebx
          166  +		cmpl	%ebx, %eax
          167  +		movl	dsWMask, %eax
          168  +		movl	dsMaxChainLen, %chainlenwmask
          169  +		jl	LastMatchGood
          170  +		shrl	$2, %chainlenwmask
          171  +LastMatchGood:
          172  +
          173  +/* chainlen is decremented once beforehand so that the function can	*/
          174  +/* use the sign flag instead of the zero flag for the exit test.	*/
          175  +/* It is then shifted into the high word, to make room for the wmask	*/
          176  +/* value, which it will always accompany.				*/
          177  +
          178  +		decl	%chainlenwmask
          179  +		shll	$16, %chainlenwmask
          180  +		orl	%eax, %chainlenwmask
          181  +
          182  +/* if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead;	*/
          183  +
          184  +		movl	dsNiceMatch, %eax
          185  +		movl	dsLookahead, %ebx
          186  +		cmpl	%eax, %ebx
          187  +		jl	LookaheadLess
          188  +		movl	%eax, %ebx
          189  +LookaheadLess:	movl	%ebx, %nicematch
          190  +
          191  +/* register Bytef *scan = s->window + s->strstart;			*/
          192  +
          193  +		mov	dsWindow, %window
          194  +		movl	dsStrStart, %limitd
          195  +		lea	(%limit, %window), %scan
          196  +
          197  +/* Determine how many bytes the scan ptr is off from being		*/
          198  +/* dword-aligned.							*/
          199  +
          200  +		mov	%scan, %scanalign
          201  +		negl	%scanalignd
          202  +		andl	$3, %scanalignd
          203  +
          204  +/* IPos limit = s->strstart > (IPos)MAX_DIST(s) ?			*/
          205  +/*     s->strstart - (IPos)MAX_DIST(s) : NIL;				*/
          206  +
          207  +		movl	dsWSize, %eax
          208  +		subl	$MIN_LOOKAHEAD, %eax
          209  +		xorl	%ecx, %ecx
          210  +		subl	%eax, %limitd
          211  +		cmovng	%ecx, %limitd
          212  +
          213  +/* int best_len = s->prev_length;					*/
          214  +
          215  +		movl	dsPrevLen, %bestlend
          216  +
          217  +/* Store the sum of s->window + best_len in %windowbestlen locally, and in memory.	*/
          218  +
          219  +		lea	(%window, %bestlen), %windowbestlen
          220  +		mov	%windowbestlen, _windowbestlen
          221  +
          222  +/* register ush scan_start = *(ushf*)scan;				*/
          223  +/* register ush scan_end   = *(ushf*)(scan+best_len-1);			*/
          224  +/* Posf *prev = s->prev;						*/
          225  +
          226  +		movzwl	(%scan), %scanstart
          227  +		movzwl	-1(%scan, %bestlen), %scanend
          228  +		mov	dsPrev, %prev
          229  +
          230  +/* Jump into the main loop.						*/
          231  +
          232  +		movl	%chainlenwmask, _chainlenwmask
          233  +		jmp	LoopEntry
          234  +
          235  +.balign 16
          236  +
          237  +/* do {
          238  + *     match = s->window + cur_match;
          239  + *     if (*(ushf*)(match+best_len-1) != scan_end ||
          240  + *         *(ushf*)match != scan_start) continue;
          241  + *     [...]
          242  + * } while ((cur_match = prev[cur_match & wmask]) > limit
          243  + *          && --chain_length != 0);
          244  + *
          245  + * Here is the inner loop of the function. The function will spend the
          246  + * majority of its time in this loop, and majority of that time will
          247  + * be spent in the first ten instructions.
          248  + */
          249  +LookupLoop:
          250  +		andl	%chainlenwmask, %curmatchd
          251  +		movzwl	(%prev, %curmatch, 2), %curmatchd
          252  +		cmpl	%limitd, %curmatchd
          253  +		jbe	LeaveNow
          254  +		subl	$0x00010000, %chainlenwmask
          255  +		js	LeaveNow
          256  +LoopEntry:	cmpw	-1(%windowbestlen, %curmatch), %scanendw
          257  +		jne	LookupLoop
          258  +		cmpw	%scanstartw, (%window, %curmatch)
          259  +		jne	LookupLoop
          260  +
          261  +/* Store the current value of chainlen.					*/
          262  +		movl	%chainlenwmask, _chainlenwmask
          263  +
          264  +/* %scan is the string under scrutiny, and %prev to the string we	*/
          265  +/* are hoping to match it up with. In actuality, %esi and %edi are	*/
          266  +/* both pointed (MAX_MATCH_8 - scanalign) bytes ahead, and %edx is	*/
          267  +/* initialized to -(MAX_MATCH_8 - scanalign).				*/
          268  +
          269  +		mov	$(-MAX_MATCH_8), %rdx
          270  +		lea	(%curmatch, %window), %windowbestlen
          271  +		lea	MAX_MATCH_8(%windowbestlen, %scanalign), %windowbestlen
          272  +		lea	MAX_MATCH_8(%scan, %scanalign), %prev
          273  +
          274  +/* the prefetching below makes very little difference... */
          275  +		prefetcht1	(%windowbestlen, %rdx)
          276  +		prefetcht1	(%prev, %rdx)
          277  +
          278  +/*
          279  + * Test the strings for equality, 8 bytes at a time. At the end,
          280  + * adjust %rdx so that it is offset to the exact byte that mismatched.
          281  + *
          282  + * It should be confessed that this loop usually does not represent
          283  + * much of the total running time. Replacing it with a more
          284  + * straightforward "rep cmpsb" would not drastically degrade
          285  + * performance -- unrolling it, for example, makes no difference.
          286  + */
          287  +
          288  +#undef USE_SSE	/* works, but is 6-7% slower, than non-SSE... */
          289  +
          290  +LoopCmps:
          291  +#ifdef USE_SSE
          292  +		/* Preload the SSE registers */
          293  +		movdqu	  (%windowbestlen, %rdx), %xmm1
          294  +		movdqu	  (%prev, %rdx), %xmm2
          295  +		pcmpeqb	%xmm2, %xmm1
          296  +		movdqu	16(%windowbestlen, %rdx), %xmm3
          297  +		movdqu	16(%prev, %rdx), %xmm4
          298  +		pcmpeqb	%xmm4, %xmm3
          299  +		movdqu	32(%windowbestlen, %rdx), %xmm5
          300  +		movdqu	32(%prev, %rdx), %xmm6
          301  +		pcmpeqb	%xmm6, %xmm5
          302  +		movdqu	48(%windowbestlen, %rdx), %xmm7
          303  +		movdqu	48(%prev, %rdx), %xmm8
          304  +		pcmpeqb	%xmm8, %xmm7
          305  +
          306  +		/* Check the comparisions' results */
          307  +		pmovmskb %xmm1, %rax
          308  +		notw	%ax
          309  +		bsfw	%ax, %ax
          310  +		jnz	LeaveLoopCmps
          311  +		
          312  +		/* this is the only iteration of the loop with a possibility of having
          313  +		   incremented rdx by 0x108 (each loop iteration add 16*4 = 0x40 
          314  +		   and (0x40*4)+8=0x108 */
          315  +		add	$8, %rdx
          316  +		jz LenMaximum
          317  +		add	$8, %rdx
          318  +
          319  +		
          320  +		pmovmskb %xmm3, %rax
          321  +		notw	%ax
          322  +		bsfw	%ax, %ax
          323  +		jnz	LeaveLoopCmps
          324  +		
          325  +		
          326  +		add	$16, %rdx
          327  +
          328  +
          329  +		pmovmskb %xmm5, %rax
          330  +		notw	%ax
          331  +		bsfw	%ax, %ax
          332  +		jnz	LeaveLoopCmps
          333  +		
          334  +		add	$16, %rdx
          335  +
          336  +
          337  +		pmovmskb %xmm7, %rax
          338  +		notw	%ax
          339  +		bsfw	%ax, %ax
          340  +		jnz	LeaveLoopCmps
          341  +		
          342  +		add	$16, %rdx
          343  +		
          344  +		jmp	LoopCmps
          345  +LeaveLoopCmps:	add	%rax, %rdx
          346  +#else
          347  +		mov	(%windowbestlen, %rdx), %rax
          348  +		xor	(%prev, %rdx), %rax
          349  +		jnz	LeaveLoopCmps
          350  +		
          351  +		mov	8(%windowbestlen, %rdx), %rax
          352  +		xor	8(%prev, %rdx), %rax
          353  +		jnz	LeaveLoopCmps8
          354  +
          355  +		mov	16(%windowbestlen, %rdx), %rax
          356  +		xor	16(%prev, %rdx), %rax
          357  +		jnz	LeaveLoopCmps16
          358  +				
          359  +		add	$24, %rdx
          360  +		jnz	LoopCmps
          361  +		jmp	LenMaximum
          362  +#	if 0
          363  +/*
          364  + * This three-liner is tantalizingly simple, but bsf is a slow instruction,
          365  + * and the complicated alternative down below is quite a bit faster. Sad...
          366  + */
          367  +
          368  +LeaveLoopCmps:	bsf	%rax, %rax /* find the first non-zero bit */
          369  +		shrl	$3, %eax /* divide by 8 to get the byte */
          370  +		add	%rax, %rdx
          371  +#	else
          372  +LeaveLoopCmps16:
          373  +		add	$8, %rdx
          374  +LeaveLoopCmps8:
          375  +		add	$8, %rdx
          376  +LeaveLoopCmps:	testl   $0xFFFFFFFF, %eax /* Check the first 4 bytes */
          377  +		jnz     Check16
          378  +		add     $4, %rdx
          379  +		shr     $32, %rax
          380  +Check16:        testw   $0xFFFF, %ax
          381  +		jnz     LenLower
          382  +		add	$2, %rdx
          383  +		shrl	$16, %eax
          384  +LenLower:	subb	$1, %al
          385  +		adc	$0, %rdx
          386  +#	endif
          387  +#endif
          388  +
          389  +/* Calculate the length of the match. If it is longer than MAX_MATCH,	*/
          390  +/* then automatically accept it as the best possible match and leave.	*/
          391  +
          392  +		lea	(%prev, %rdx), %rax
          393  +		sub	%scan, %rax
          394  +		cmpl	$MAX_MATCH, %eax
          395  +		jge	LenMaximum
          396  +
          397  +/* If the length of the match is not longer than the best match we	*/
          398  +/* have so far, then forget it and return to the lookup loop.		*/
          399  +
          400  +		cmpl	%bestlend, %eax
          401  +		jg	LongerMatch
          402  +		mov	_windowbestlen, %windowbestlen
          403  +		mov	dsPrev, %prev
          404  +		movl	_chainlenwmask, %edx
          405  +		jmp	LookupLoop
          406  +
          407  +/*         s->match_start = cur_match;					*/
          408  +/*         best_len = len;						*/
          409  +/*         if (len >= nice_match) break;				*/
          410  +/*         scan_end = *(ushf*)(scan+best_len-1);			*/
          411  +
          412  +LongerMatch:
          413  +		movl	%eax, %bestlend
          414  +		movl	%curmatchd, dsMatchStart
          415  +		cmpl	%nicematch, %eax
          416  +		jge	LeaveNow
          417  +
          418  +		lea	(%window, %bestlen), %windowbestlen
          419  +		mov	%windowbestlen, _windowbestlen
          420  +
          421  +		movzwl	-1(%scan, %rax), %scanend
          422  +		mov	dsPrev, %prev
          423  +		movl	_chainlenwmask, %chainlenwmask
          424  +		jmp	LookupLoop
          425  +
          426  +/* Accept the current string, with the maximum possible length.		*/
          427  +
          428  +LenMaximum:
          429  +		movl	$MAX_MATCH, %bestlend
          430  +		movl	%curmatchd, dsMatchStart
          431  +
          432  +/* if ((uInt)best_len <= s->lookahead) return (uInt)best_len;		*/
          433  +/* return s->lookahead;							*/
          434  +
          435  +LeaveNow:
          436  +		movl	dsLookahead, %eax
          437  +		cmpl	%eax, %bestlend
          438  +		cmovngl	%bestlend, %eax
          439  +LookaheadRet:
          440  +
          441  +/* Restore the registers and return from whence we came.			*/
          442  +
          443  +	mov	save_rsi, %rsi
          444  +	mov	save_rbx, %rbx
          445  +	mov	save_r12, %r12
          446  +	mov	save_r13, %r13
          447  +	mov	save_r14, %r14
          448  +	mov	save_r15, %r15
          449  +
          450  +	ret
          451  +
          452  +match_init:	ret

Added compat/zlib/contrib/asm686/README.686.

            1  +This is a patched version of zlib, modified to use
            2  +Pentium-Pro-optimized assembly code in the deflation algorithm. The
            3  +files changed/added by this patch are:
            4  +
            5  +README.686
            6  +match.S
            7  +
            8  +The speedup that this patch provides varies, depending on whether the
            9  +compiler used to build the original version of zlib falls afoul of the
           10  +PPro's speed traps. My own tests show a speedup of around 10-20% at
           11  +the default compression level, and 20-30% using -9, against a version
           12  +compiled using gcc 2.7.2.3. Your mileage may vary.
           13  +
           14  +Note that this code has been tailored for the PPro/PII in particular,
           15  +and will not perform particuarly well on a Pentium.
           16  +
           17  +If you are using an assembler other than GNU as, you will have to
           18  +translate match.S to use your assembler's syntax. (Have fun.)
           19  +
           20  +Brian Raiter
           21  +breadbox@muppetlabs.com
           22  +April, 1998
           23  +
           24  +
           25  +Added for zlib 1.1.3:
           26  +
           27  +The patches come from
           28  +http://www.muppetlabs.com/~breadbox/software/assembly.html
           29  +
           30  +To compile zlib with this asm file, copy match.S to the zlib directory
           31  +then do:
           32  +
           33  +CFLAGS="-O3 -DASMV" ./configure
           34  +make OBJA=match.o
           35  +
           36  +
           37  +Update:
           38  +
           39  +I've been ignoring these assembly routines for years, believing that
           40  +gcc's generated code had caught up with it sometime around gcc 2.95
           41  +and the major rearchitecting of the Pentium 4. However, I recently
           42  +learned that, despite what I believed, this code still has some life
           43  +in it. On the Pentium 4 and AMD64 chips, it continues to run about 8%
           44  +faster than the code produced by gcc 4.1.
           45  +
           46  +In acknowledgement of its continuing usefulness, I've altered the
           47  +license to match that of the rest of zlib. Share and Enjoy!
           48  +
           49  +Brian Raiter
           50  +breadbox@muppetlabs.com
           51  +April, 2007

Added compat/zlib/contrib/asm686/match.S.

            1  +/* match.S -- x86 assembly version of the zlib longest_match() function.
            2  + * Optimized for the Intel 686 chips (PPro and later).
            3  + *
            4  + * Copyright (C) 1998, 2007 Brian Raiter <breadbox@muppetlabs.com>
            5  + *
            6  + * This software is provided 'as-is', without any express or implied
            7  + * warranty.  In no event will the author be held liable for any damages
            8  + * arising from the use of this software.
            9  + *
           10  + * Permission is granted to anyone to use this software for any purpose,
           11  + * including commercial applications, and to alter it and redistribute it
           12  + * freely, subject to the following restrictions:
           13  + *
           14  + * 1. The origin of this software must not be misrepresented; you must not
           15  + *    claim that you wrote the original software. If you use this software
           16  + *    in a product, an acknowledgment in the product documentation would be
           17  + *    appreciated but is not required.
           18  + * 2. Altered source versions must be plainly marked as such, and must not be
           19  + *    misrepresented as being the original software.
           20  + * 3. This notice may not be removed or altered from any source distribution.
           21  + */
           22  +
           23  +#ifndef NO_UNDERLINE
           24  +#define	match_init	_match_init
           25  +#define	longest_match	_longest_match
           26  +#endif
           27  +
           28  +#define	MAX_MATCH	(258)
           29  +#define	MIN_MATCH	(3)
           30  +#define	MIN_LOOKAHEAD	(MAX_MATCH + MIN_MATCH + 1)
           31  +#define	MAX_MATCH_8	((MAX_MATCH + 7) & ~7)
           32  +
           33  +/* stack frame offsets */
           34  +
           35  +#define	chainlenwmask		0	/* high word: current chain len	*/
           36  +					/* low word: s->wmask		*/
           37  +#define	window			4	/* local copy of s->window	*/
           38  +#define	windowbestlen		8	/* s->window + bestlen		*/
           39  +#define	scanstart		16	/* first two bytes of string	*/
           40  +#define	scanend			12	/* last two bytes of string	*/
           41  +#define	scanalign		20	/* dword-misalignment of string	*/
           42  +#define	nicematch		24	/* a good enough match size	*/
           43  +#define	bestlen			28	/* size of best match so far	*/
           44  +#define	scan			32	/* ptr to string wanting match	*/
           45  +
           46  +#define	LocalVarsSize		(36)
           47  +/*	saved ebx		36 */
           48  +/*	saved edi		40 */
           49  +/*	saved esi		44 */
           50  +/*	saved ebp		48 */
           51  +/*	return address		52 */
           52  +#define	deflatestate		56	/* the function arguments	*/
           53  +#define	curmatch		60
           54  +
           55  +/* All the +zlib1222add offsets are due to the addition of fields
           56  + *  in zlib in the deflate_state structure since the asm code was first written
           57  + * (if you compile with zlib 1.0.4 or older, use "zlib1222add equ (-4)").
           58  + * (if you compile with zlib between 1.0.5 and 1.2.2.1, use "zlib1222add equ 0").
           59  + * if you compile with zlib 1.2.2.2 or later , use "zlib1222add equ 8").
           60  + */
           61  +
           62  +#define zlib1222add		(8)
           63  +
           64  +#define	dsWSize			(36+zlib1222add)
           65  +#define	dsWMask			(44+zlib1222add)
           66  +#define	dsWindow		(48+zlib1222add)
           67  +#define	dsPrev			(56+zlib1222add)
           68  +#define	dsMatchLen		(88+zlib1222add)
           69  +#define	dsPrevMatch		(92+zlib1222add)
           70  +#define	dsStrStart		(100+zlib1222add)
           71  +#define	dsMatchStart		(104+zlib1222add)
           72  +#define	dsLookahead		(108+zlib1222add)
           73  +#define	dsPrevLen		(112+zlib1222add)
           74  +#define	dsMaxChainLen		(116+zlib1222add)
           75  +#define	dsGoodMatch		(132+zlib1222add)
           76  +#define	dsNiceMatch		(136+zlib1222add)
           77  +
           78  +
           79  +.file "match.S"
           80  +
           81  +.globl	match_init, longest_match
           82  +
           83  +.text
           84  +
           85  +/* uInt longest_match(deflate_state *deflatestate, IPos curmatch) */
           86  +.cfi_sections	.debug_frame
           87  +
           88  +longest_match:
           89  +
           90  +.cfi_startproc
           91  +/* Save registers that the compiler may be using, and adjust %esp to	*/
           92  +/* make room for our stack frame.					*/
           93  +
           94  +		pushl	%ebp
           95  +		.cfi_def_cfa_offset 8
           96  +		.cfi_offset ebp, -8
           97  +		pushl	%edi
           98  +		.cfi_def_cfa_offset 12
           99  +		pushl	%esi
          100  +		.cfi_def_cfa_offset 16
          101  +		pushl	%ebx
          102  +		.cfi_def_cfa_offset 20
          103  +		subl	$LocalVarsSize, %esp
          104  +		.cfi_def_cfa_offset LocalVarsSize+20
          105  +
          106  +/* Retrieve the function arguments. %ecx will hold cur_match		*/
          107  +/* throughout the entire function. %edx will hold the pointer to the	*/
          108  +/* deflate_state structure during the function's setup (before		*/
          109  +/* entering the main loop).						*/
          110  +
          111  +		movl	deflatestate(%esp), %edx
          112  +		movl	curmatch(%esp), %ecx
          113  +
          114  +/* uInt wmask = s->w_mask;						*/
          115  +/* unsigned chain_length = s->max_chain_length;				*/
          116  +/* if (s->prev_length >= s->good_match) {				*/
          117  +/*     chain_length >>= 2;						*/
          118  +/* }									*/
          119  + 
          120  +		movl	dsPrevLen(%edx), %eax
          121  +		movl	dsGoodMatch(%edx), %ebx
          122  +		cmpl	%ebx, %eax
          123  +		movl	dsWMask(%edx), %eax
          124  +		movl	dsMaxChainLen(%edx), %ebx
          125  +		jl	LastMatchGood
          126  +		shrl	$2, %ebx
          127  +LastMatchGood:
          128  +
          129  +/* chainlen is decremented once beforehand so that the function can	*/
          130  +/* use the sign flag instead of the zero flag for the exit test.	*/
          131  +/* It is then shifted into the high word, to make room for the wmask	*/
          132  +/* value, which it will always accompany.				*/
          133  +
          134  +		decl	%ebx
          135  +		shll	$16, %ebx
          136  +		orl	%eax, %ebx
          137  +		movl	%ebx, chainlenwmask(%esp)
          138  +
          139  +/* if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead;	*/
          140  +
          141  +		movl	dsNiceMatch(%edx), %eax
          142  +		movl	dsLookahead(%edx), %ebx
          143  +		cmpl	%eax, %ebx
          144  +		jl	LookaheadLess
          145  +		movl	%eax, %ebx
          146  +LookaheadLess:	movl	%ebx, nicematch(%esp)
          147  +
          148  +/* register Bytef *scan = s->window + s->strstart;			*/
          149  +
          150  +		movl	dsWindow(%edx), %esi
          151  +		movl	%esi, window(%esp)
          152  +		movl	dsStrStart(%edx), %ebp
          153  +		lea	(%esi,%ebp), %edi
          154  +		movl	%edi, scan(%esp)
          155  +
          156  +/* Determine how many bytes the scan ptr is off from being		*/
          157  +/* dword-aligned.							*/
          158  +
          159  +		movl	%edi, %eax
          160  +		negl	%eax
          161  +		andl	$3, %eax
          162  +		movl	%eax, scanalign(%esp)
          163  +
          164  +/* IPos limit = s->strstart > (IPos)MAX_DIST(s) ?			*/
          165  +/*     s->strstart - (IPos)MAX_DIST(s) : NIL;				*/
          166  +
          167  +		movl	dsWSize(%edx), %eax
          168  +		subl	$MIN_LOOKAHEAD, %eax
          169  +		subl	%eax, %ebp
          170  +		jg	LimitPositive
          171  +		xorl	%ebp, %ebp
          172  +LimitPositive:
          173  +
          174  +/* int best_len = s->prev_length;					*/
          175  +
          176  +		movl	dsPrevLen(%edx), %eax
          177  +		movl	%eax, bestlen(%esp)
          178  +
          179  +/* Store the sum of s->window + best_len in %esi locally, and in %esi.	*/
          180  +
          181  +		addl	%eax, %esi
          182  +		movl	%esi, windowbestlen(%esp)
          183  +
          184  +/* register ush scan_start = *(ushf*)scan;				*/
          185  +/* register ush scan_end   = *(ushf*)(scan+best_len-1);			*/
          186  +/* Posf *prev = s->prev;						*/
          187  +
          188  +		movzwl	(%edi), %ebx
          189  +		movl	%ebx, scanstart(%esp)
          190  +		movzwl	-1(%edi,%eax), %ebx
          191  +		movl	%ebx, scanend(%esp)
          192  +		movl	dsPrev(%edx), %edi
          193  +
          194  +/* Jump into the main loop.						*/
          195  +
          196  +		movl	chainlenwmask(%esp), %edx
          197  +		jmp	LoopEntry
          198  +
          199  +.balign 16
          200  +
          201  +/* do {
          202  + *     match = s->window + cur_match;
          203  + *     if (*(ushf*)(match+best_len-1) != scan_end ||
          204  + *         *(ushf*)match != scan_start) continue;
          205  + *     [...]
          206  + * } while ((cur_match = prev[cur_match & wmask]) > limit
          207  + *          && --chain_length != 0);
          208  + *
          209  + * Here is the inner loop of the function. The function will spend the
          210  + * majority of its time in this loop, and majority of that time will
          211  + * be spent in the first ten instructions.
          212  + *
          213  + * Within this loop:
          214  + * %ebx = scanend
          215  + * %ecx = curmatch
          216  + * %edx = chainlenwmask - i.e., ((chainlen << 16) | wmask)
          217  + * %esi = windowbestlen - i.e., (window + bestlen)
          218  + * %edi = prev
          219  + * %ebp = limit
          220  + */
          221  +LookupLoop:
          222  +		andl	%edx, %ecx
          223  +		movzwl	(%edi,%ecx,2), %ecx
          224  +		cmpl	%ebp, %ecx
          225  +		jbe	LeaveNow
          226  +		subl	$0x00010000, %edx
          227  +		js	LeaveNow
          228  +LoopEntry:	movzwl	-1(%esi,%ecx), %eax
          229  +		cmpl	%ebx, %eax
          230  +		jnz	LookupLoop
          231  +		movl	window(%esp), %eax
          232  +		movzwl	(%eax,%ecx), %eax
          233  +		cmpl	scanstart(%esp), %eax
          234  +		jnz	LookupLoop
          235  +
          236  +/* Store the current value of chainlen.					*/
          237  +
          238  +		movl	%edx, chainlenwmask(%esp)
          239  +
          240  +/* Point %edi to the string under scrutiny, and %esi to the string we	*/
          241  +/* are hoping to match it up with. In actuality, %esi and %edi are	*/
          242  +/* both pointed (MAX_MATCH_8 - scanalign) bytes ahead, and %edx is	*/
          243  +/* initialized to -(MAX_MATCH_8 - scanalign).				*/
          244  +
          245  +		movl	window(%esp), %esi
          246  +		movl	scan(%esp), %edi
          247  +		addl	%ecx, %esi
          248  +		movl	scanalign(%esp), %eax
          249  +		movl	$(-MAX_MATCH_8), %edx
          250  +		lea	MAX_MATCH_8(%edi,%eax), %edi
          251  +		lea	MAX_MATCH_8(%esi,%eax), %esi
          252  +
          253  +/* Test the strings for equality, 8 bytes at a time. At the end,
          254  + * adjust %edx so that it is offset to the exact byte that mismatched.
          255  + *
          256  + * We already know at this point that the first three bytes of the
          257  + * strings match each other, and they can be safely passed over before
          258  + * starting the compare loop. So what this code does is skip over 0-3
          259  + * bytes, as much as necessary in order to dword-align the %edi
          260  + * pointer. (%esi will still be misaligned three times out of four.)
          261  + *
          262  + * It should be confessed that this loop usually does not represent
          263  + * much of the total running time. Replacing it with a more
          264  + * straightforward "rep cmpsb" would not drastically degrade
          265  + * performance.
          266  + */
          267  +LoopCmps:
          268  +		movl	(%esi,%edx), %eax
          269  +		xorl	(%edi,%edx), %eax
          270  +		jnz	LeaveLoopCmps
          271  +		movl	4(%esi,%edx), %eax
          272  +		xorl	4(%edi,%edx), %eax
          273  +		jnz	LeaveLoopCmps4
          274  +		addl	$8, %edx
          275  +		jnz	LoopCmps
          276  +		jmp	LenMaximum
          277  +LeaveLoopCmps4:	addl	$4, %edx
          278  +LeaveLoopCmps:	testl	$0x0000FFFF, %eax
          279  +		jnz	LenLower
          280  +		addl	$2, %edx
          281  +		shrl	$16, %eax
          282  +LenLower:	subb	$1, %al
          283  +		adcl	$0, %edx
          284  +
          285  +/* Calculate the length of the match. If it is longer than MAX_MATCH,	*/
          286  +/* then automatically accept it as the best possible match and leave.	*/
          287  +
          288  +		lea	(%edi,%edx), %eax
          289  +		movl	scan(%esp), %edi
          290  +		subl	%edi, %eax
          291  +		cmpl	$MAX_MATCH, %eax
          292  +		jge	LenMaximum
          293  +
          294  +/* If the length of the match is not longer than the best match we	*/
          295  +/* have so far, then forget it and return to the lookup loop.		*/
          296  +
          297  +		movl	deflatestate(%esp), %edx
          298  +		movl	bestlen(%esp), %ebx
          299  +		cmpl	%ebx, %eax
          300  +		jg	LongerMatch
          301  +		movl	windowbestlen(%esp), %esi
          302  +		movl	dsPrev(%edx), %edi
          303  +		movl	scanend(%esp), %ebx
          304  +		movl	chainlenwmask(%esp), %edx
          305  +		jmp	LookupLoop
          306  +
          307  +/*         s->match_start = cur_match;					*/
          308  +/*         best_len = len;						*/
          309  +/*         if (len >= nice_match) break;				*/
          310  +/*         scan_end = *(ushf*)(scan+best_len-1);			*/
          311  +
          312  +LongerMatch:	movl	nicematch(%esp), %ebx
          313  +		movl	%eax, bestlen(%esp)
          314  +		movl	%ecx, dsMatchStart(%edx)
          315  +		cmpl	%ebx, %eax
          316  +		jge	LeaveNow
          317  +		movl	window(%esp), %esi
          318  +		addl	%eax, %esi
          319  +		movl	%esi, windowbestlen(%esp)
          320  +		movzwl	-1(%edi,%eax), %ebx
          321  +		movl	dsPrev(%edx), %edi
          322  +		movl	%ebx, scanend(%esp)
          323  +		movl	chainlenwmask(%esp), %edx
          324  +		jmp	LookupLoop
          325  +
          326  +/* Accept the current string, with the maximum possible length.		*/
          327  +
          328  +LenMaximum:	movl	deflatestate(%esp), %edx
          329  +		movl	$MAX_MATCH, bestlen(%esp)
          330  +		movl	%ecx, dsMatchStart(%edx)
          331  +
          332  +/* if ((uInt)best_len <= s->lookahead) return (uInt)best_len;		*/
          333  +/* return s->lookahead;							*/
          334  +
          335  +LeaveNow:
          336  +		movl	deflatestate(%esp), %edx
          337  +		movl	bestlen(%esp), %ebx
          338  +		movl	dsLookahead(%edx), %eax
          339  +		cmpl	%eax, %ebx
          340  +		jg	LookaheadRet
          341  +		movl	%ebx, %eax
          342  +LookaheadRet:
          343  +
          344  +/* Restore the stack and return from whence we came.			*/
          345  +
          346  +		addl	$LocalVarsSize, %esp
          347  +		.cfi_def_cfa_offset 20
          348  +		popl	%ebx
          349  +		.cfi_def_cfa_offset 16
          350  +		popl	%esi
          351  +		.cfi_def_cfa_offset 12
          352  +		popl	%edi
          353  +		.cfi_def_cfa_offset 8
          354  +		popl	%ebp
          355  +		.cfi_def_cfa_offset 4
          356  +.cfi_endproc
          357  +match_init:	ret

Added compat/zlib/contrib/blast/Makefile.

            1  +blast: blast.c blast.h
            2  +	cc -DTEST -o blast blast.c
            3  +
            4  +test: blast
            5  +	blast < test.pk | cmp - test.txt
            6  +
            7  +clean:
            8  +	rm -f blast blast.o

Added compat/zlib/contrib/blast/README.

            1  +Read blast.h for purpose and usage.
            2  +
            3  +Mark Adler
            4  +madler@alumni.caltech.edu

Added compat/zlib/contrib/blast/blast.c.

            1  +/* blast.c
            2  + * Copyright (C) 2003 Mark Adler
            3  + * For conditions of distribution and use, see copyright notice in blast.h
            4  + * version 1.1, 16 Feb 2003
            5  + *
            6  + * blast.c decompresses data compressed by the PKWare Compression Library.
            7  + * This function provides functionality similar to the explode() function of
            8  + * the PKWare library, hence the name "blast".
            9  + *
           10  + * This decompressor is based on the excellent format description provided by
           11  + * Ben Rudiak-Gould in comp.compression on August 13, 2001.  Interestingly, the
           12  + * example Ben provided in the post is incorrect.  The distance 110001 should
           13  + * instead be 111000.  When corrected, the example byte stream becomes:
           14  + *
           15  + *    00 04 82 24 25 8f 80 7f
           16  + *
           17  + * which decompresses to "AIAIAIAIAIAIA" (without the quotes).
           18  + */
           19  +
           20  +/*
           21  + * Change history:
           22  + *
           23  + * 1.0  12 Feb 2003     - First version
           24  + * 1.1  16 Feb 2003     - Fixed distance check for > 4 GB uncompressed data
           25  + */
           26  +
           27  +#include <setjmp.h>             /* for setjmp(), longjmp(), and jmp_buf */
           28  +#include "blast.h"              /* prototype for blast() */
           29  +
           30  +#define local static            /* for local function definitions */
           31  +#define MAXBITS 13              /* maximum code length */
           32  +#define MAXWIN 4096             /* maximum window size */
           33  +
           34  +/* input and output state */
           35  +struct state {
           36  +    /* input state */
           37  +    blast_in infun;             /* input function provided by user */
           38  +    void *inhow;                /* opaque information passed to infun() */
           39  +    unsigned char *in;          /* next input location */
           40  +    unsigned left;              /* available input at in */
           41  +    int bitbuf;                 /* bit buffer */
           42  +    int bitcnt;                 /* number of bits in bit buffer */
           43  +
           44  +    /* input limit error return state for bits() and decode() */
           45  +    jmp_buf env;
           46  +
           47  +    /* output state */
           48  +    blast_out outfun;           /* output function provided by user */
           49  +    void *outhow;               /* opaque information passed to outfun() */
           50  +    unsigned next;              /* index of next write location in out[] */
           51  +    int first;                  /* true to check distances (for first 4K) */
           52  +    unsigned char out[MAXWIN];  /* output buffer and sliding window */
           53  +};
           54  +
           55  +/*
           56  + * Return need bits from the input stream.  This always leaves less than
           57  + * eight bits in the buffer.  bits() works properly for need == 0.
           58  + *
           59  + * Format notes:
           60  + *
           61  + * - Bits are stored in bytes from the least significant bit to the most
           62  + *   significant bit.  Therefore bits are dropped from the bottom of the bit
           63  + *   buffer, using shift right, and new bytes are appended to the top of the
           64  + *   bit buffer, using shift left.
           65  + */
           66  +local int bits(struct state *s, int need)
           67  +{
           68  +    int val;            /* bit accumulator */
           69  +
           70  +    /* load at least need bits into val */
           71  +    val = s->bitbuf;
           72  +    while (s->bitcnt < need) {
           73  +        if (s->left == 0) {
           74  +            s->left = s->infun(s->inhow, &(s->in));
           75  +            if (s->left == 0) longjmp(s->env, 1);       /* out of input */
           76  +        }
           77  +        val |= (int)(*(s->in)++) << s->bitcnt;          /* load eight bits */
           78  +        s->left--;
           79  +        s->bitcnt += 8;
           80  +    }
           81  +
           82  +    /* drop need bits and update buffer, always zero to seven bits left */
           83  +    s->bitbuf = val >> need;
           84  +    s->bitcnt -= need;
           85  +
           86  +    /* return need bits, zeroing the bits above that */
           87  +    return val & ((1 << need) - 1);
           88  +}
           89  +
           90  +/*
           91  + * Huffman code decoding tables.  count[1..MAXBITS] is the number of symbols of
           92  + * each length, which for a canonical code are stepped through in order.
           93  + * symbol[] are the symbol values in canonical order, where the number of
           94  + * entries is the sum of the counts in count[].  The decoding process can be
           95  + * seen in the function decode() below.
           96  + */
           97  +struct huffman {
           98  +    short *count;       /* number of symbols of each length */
           99  +    short *symbol;      /* canonically ordered symbols */
          100  +};
          101  +
          102  +/*
          103  + * Decode a code from the stream s using huffman table h.  Return the symbol or
          104  + * a negative value if there is an error.  If all of the lengths are zero, i.e.
          105  + * an empty code, or if the code is incomplete and an invalid code is received,
          106  + * then -9 is returned after reading MAXBITS bits.
          107  + *
          108  + * Format notes:
          109  + *
          110  + * - The codes as stored in the compressed data are bit-reversed relative to
          111  + *   a simple integer ordering of codes of the same lengths.  Hence below the
          112  + *   bits are pulled from the compressed data one at a time and used to
          113  + *   build the code value reversed from what is in the stream in order to
          114  + *   permit simple integer comparisons for decoding.
          115  + *
          116  + * - The first code for the shortest length is all ones.  Subsequent codes of
          117  + *   the same length are simply integer decrements of the previous code.  When
          118  + *   moving up a length, a one bit is appended to the code.  For a complete
          119  + *   code, the last code of the longest length will be all zeros.  To support
          120  + *   this ordering, the bits pulled during decoding are inverted to apply the
          121  + *   more "natural" ordering starting with all zeros and incrementing.
          122  + */
          123  +local int decode(struct state *s, struct huffman *h)
          124  +{
          125  +    int len;            /* current number of bits in code */
          126  +    int code;           /* len bits being decoded */
          127  +    int first;          /* first code of length len */
          128  +    int count;          /* number of codes of length len */
          129  +    int index;          /* index of first code of length len in symbol table */
          130  +    int bitbuf;         /* bits from stream */
          131  +    int left;           /* bits left in next or left to process */
          132  +    short *next;        /* next number of codes */
          133  +
          134  +    bitbuf = s->bitbuf;
          135  +    left = s->bitcnt;
          136  +    code = first = index = 0;
          137  +    len = 1;
          138  +    next = h->count + 1;
          139  +    while (1) {
          140  +        while (left--) {
          141  +            code |= (bitbuf & 1) ^ 1;   /* invert code */
          142  +            bitbuf >>= 1;
          143  +            count = *next++;
          144  +            if (code < first + count) { /* if length len, return symbol */
          145  +                s->bitbuf = bitbuf;
          146  +                s->bitcnt = (s->bitcnt - len) & 7;
          147  +                return h->symbol[index + (code - first)];
          148  +            }
          149  +            index += count;             /* else update for next length */
          150  +            first += count;
          151  +            first <<= 1;
          152  +            code <<= 1;
          153  +            len++;
          154  +        }
          155  +        left = (MAXBITS+1) - len;
          156  +        if (left == 0) break;
          157  +        if (s->left == 0) {
          158  +            s->left = s->infun(s->inhow, &(s->in));
          159  +            if (s->left == 0) longjmp(s->env, 1);       /* out of input */
          160  +        }
          161  +        bitbuf = *(s->in)++;
          162  +        s->left--;
          163  +        if (left > 8) left = 8;
          164  +    }
          165  +    return -9;                          /* ran out of codes */
          166  +}
          167  +
          168  +/*
          169  + * Given a list of repeated code lengths rep[0..n-1], where each byte is a
          170  + * count (high four bits + 1) and a code length (low four bits), generate the
          171  + * list of code lengths.  This compaction reduces the size of the object code.
          172  + * Then given the list of code lengths length[0..n-1] representing a canonical
          173  + * Huffman code for n symbols, construct the tables required to decode those
          174  + * codes.  Those tables are the number of codes of each length, and the symbols
          175  + * sorted by length, retaining their original order within each length.  The
          176  + * return value is zero for a complete code set, negative for an over-
          177  + * subscribed code set, and positive for an incomplete code set.  The tables
          178  + * can be used if the return value is zero or positive, but they cannot be used
          179  + * if the return value is negative.  If the return value is zero, it is not
          180  + * possible for decode() using that table to return an error--any stream of
          181  + * enough bits will resolve to a symbol.  If the return value is positive, then
          182  + * it is possible for decode() using that table to return an error for received
          183  + * codes past the end of the incomplete lengths.
          184  + */
          185  +local int construct(struct huffman *h, const unsigned char *rep, int n)
          186  +{
          187  +    int symbol;         /* current symbol when stepping through length[] */
          188  +    int len;            /* current length when stepping through h->count[] */
          189  +    int left;           /* number of possible codes left of current length */
          190  +    short offs[MAXBITS+1];      /* offsets in symbol table for each length */
          191  +    short length[256];  /* code lengths */
          192  +
          193  +    /* convert compact repeat counts into symbol bit length list */
          194  +    symbol = 0;
          195  +    do {
          196  +        len = *rep++;
          197  +        left = (len >> 4) + 1;
          198  +        len &= 15;
          199  +        do {
          200  +            length[symbol++] = len;
          201  +        } while (--left);
          202  +    } while (--n);
          203  +    n = symbol;
          204  +
          205  +    /* count number of codes of each length */
          206  +    for (len = 0; len <= MAXBITS; len++)
          207  +        h->count[len] = 0;
          208  +    for (symbol = 0; symbol < n; symbol++)
          209  +        (h->count[length[symbol]])++;   /* assumes lengths are within bounds */
          210  +    if (h->count[0] == n)               /* no codes! */
          211  +        return 0;                       /* complete, but decode() will fail */
          212  +
          213  +    /* check for an over-subscribed or incomplete set of lengths */
          214  +    left = 1;                           /* one possible code of zero length */
          215  +    for (len = 1; len <= MAXBITS; len++) {
          216  +        left <<= 1;                     /* one more bit, double codes left */
          217  +        left -= h->count[len];          /* deduct count from possible codes */
          218  +        if (left < 0) return left;      /* over-subscribed--return negative */
          219  +    }                                   /* left > 0 means incomplete */
          220  +
          221  +    /* generate offsets into symbol table for each length for sorting */
          222  +    offs[1] = 0;
          223  +    for (len = 1; len < MAXBITS; len++)
          224  +        offs[len + 1] = offs[len] + h->count[len];
          225  +
          226  +    /*
          227  +     * put symbols in table sorted by length, by symbol order within each
          228  +     * length
          229  +     */
          230  +    for (symbol = 0; symbol < n; symbol++)
          231  +        if (length[symbol] != 0)
          232  +            h->symbol[offs[length[symbol]]++] = symbol;
          233  +
          234  +    /* return zero for complete set, positive for incomplete set */
          235  +    return left;
          236  +}
          237  +
          238  +/*
          239  + * Decode PKWare Compression Library stream.
          240  + *
          241  + * Format notes:
          242  + *
          243  + * - First byte is 0 if literals are uncoded or 1 if they are coded.  Second
          244  + *   byte is 4, 5, or 6 for the number of extra bits in the distance code.
          245  + *   This is the base-2 logarithm of the dictionary size minus six.
          246  + *
          247  + * - Compressed data is a combination of literals and length/distance pairs
          248  + *   terminated by an end code.  Literals are either Huffman coded or
          249  + *   uncoded bytes.  A length/distance pair is a coded length followed by a
          250  + *   coded distance to represent a string that occurs earlier in the
          251  + *   uncompressed data that occurs again at the current location.
          252  + *
          253  + * - A bit preceding a literal or length/distance pair indicates which comes
          254  + *   next, 0 for literals, 1 for length/distance.
          255  + *
          256  + * - If literals are uncoded, then the next eight bits are the literal, in the
          257  + *   normal bit order in th stream, i.e. no bit-reversal is needed. Similarly,
          258  + *   no bit reversal is needed for either the length extra bits or the distance
          259  + *   extra bits.
          260  + *
          261  + * - Literal bytes are simply written to the output.  A length/distance pair is
          262  + *   an instruction to copy previously uncompressed bytes to the output.  The
          263  + *   copy is from distance bytes back in the output stream, copying for length
          264  + *   bytes.
          265  + *
          266  + * - Distances pointing before the beginning of the output data are not
          267  + *   permitted.
          268  + *
          269  + * - Overlapped copies, where the length is greater than the distance, are
          270  + *   allowed and common.  For example, a distance of one and a length of 518
          271  + *   simply copies the last byte 518 times.  A distance of four and a length of
          272  + *   twelve copies the last four bytes three times.  A simple forward copy
          273  + *   ignoring whether the length is greater than the distance or not implements
          274  + *   this correctly.
          275  + */
          276  +local int decomp(struct state *s)
          277  +{
          278  +    int lit;            /* true if literals are coded */
          279  +    int dict;           /* log2(dictionary size) - 6 */
          280  +    int symbol;         /* decoded symbol, extra bits for distance */
          281  +    int len;            /* length for copy */
          282  +    int dist;           /* distance for copy */
          283  +    int copy;           /* copy counter */
          284  +    unsigned char *from, *to;   /* copy pointers */
          285  +    static int virgin = 1;                              /* build tables once */
          286  +    static short litcnt[MAXBITS+1], litsym[256];        /* litcode memory */
          287  +    static short lencnt[MAXBITS+1], lensym[16];         /* lencode memory */
          288  +    static short distcnt[MAXBITS+1], distsym[64];       /* distcode memory */
          289  +    static struct huffman litcode = {litcnt, litsym};   /* length code */
          290  +    static struct huffman lencode = {lencnt, lensym};   /* length code */
          291  +    static struct huffman distcode = {distcnt, distsym};/* distance code */
          292  +        /* bit lengths of literal codes */
          293  +    static const unsigned char litlen[] = {
          294  +        11, 124, 8, 7, 28, 7, 188, 13, 76, 4, 10, 8, 12, 10, 12, 10, 8, 23, 8,
          295  +        9, 7, 6, 7, 8, 7, 6, 55, 8, 23, 24, 12, 11, 7, 9, 11, 12, 6, 7, 22, 5,
          296  +        7, 24, 6, 11, 9, 6, 7, 22, 7, 11, 38, 7, 9, 8, 25, 11, 8, 11, 9, 12,
          297  +        8, 12, 5, 38, 5, 38, 5, 11, 7, 5, 6, 21, 6, 10, 53, 8, 7, 24, 10, 27,
          298  +        44, 253, 253, 253, 252, 252, 252, 13, 12, 45, 12, 45, 12, 61, 12, 45,
          299  +        44, 173};
          300  +        /* bit lengths of length codes 0..15 */
          301  +    static const unsigned char lenlen[] = {2, 35, 36, 53, 38, 23};
          302  +        /* bit lengths of distance codes 0..63 */
          303  +    static const unsigned char distlen[] = {2, 20, 53, 230, 247, 151, 248};
          304  +    static const short base[16] = {     /* base for length codes */
          305  +        3, 2, 4, 5, 6, 7, 8, 9, 10, 12, 16, 24, 40, 72, 136, 264};
          306  +    static const char extra[16] = {     /* extra bits for length codes */
          307  +        0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8};
          308  +
          309  +    /* set up decoding tables (once--might not be thread-safe) */
          310  +    if (virgin) {
          311  +        construct(&litcode, litlen, sizeof(litlen));
          312  +        construct(&lencode, lenlen, sizeof(lenlen));
          313  +        construct(&distcode, distlen, sizeof(distlen));
          314  +        virgin = 0;
          315  +    }
          316  +
          317  +    /* read header */
          318  +    lit = bits(s, 8);
          319  +    if (lit > 1) return -1;
          320  +    dict = bits(s, 8);
          321  +    if (dict < 4 || dict > 6) return -2;
          322  +
          323  +    /* decode literals and length/distance pairs */
          324  +    do {
          325  +        if (bits(s, 1)) {
          326  +            /* get length */
          327  +            symbol = decode(s, &lencode);
          328  +            len = base[symbol] + bits(s, extra[symbol]);
          329  +            if (len == 519) break;              /* end code */
          330  +
          331  +            /* get distance */
          332  +            symbol = len == 2 ? 2 : dict;
          333  +            dist = decode(s, &distcode) << symbol;
          334  +            dist += bits(s, symbol);
          335  +            dist++;
          336  +            if (s->first && dist > s->next)
          337  +                return -3;              /* distance too far back */
          338  +
          339  +            /* copy length bytes from distance bytes back */
          340  +            do {
          341  +                to = s->out + s->next;
          342  +                from = to - dist;
          343  +                copy = MAXWIN;
          344  +                if (s->next < dist) {
          345  +                    from += copy;
          346  +                    copy = dist;
          347  +                }
          348  +                copy -= s->next;
          349  +                if (copy > len) copy = len;
          350  +                len -= copy;
          351  +                s->next += copy;
          352  +                do {
          353  +                    *to++ = *from++;
          354  +                } while (--copy);
          355  +                if (s->next == MAXWIN) {
          356  +                    if (s->outfun(s->outhow, s->out, s->next)) return 1;
          357  +                    s->next = 0;
          358  +                    s->first = 0;
          359  +                }
          360  +            } while (len != 0);
          361  +        }
          362  +        else {
          363  +            /* get literal and write it */
          364  +            symbol = lit ? decode(s, &litcode) : bits(s, 8);
          365  +            s->out[s->next++] = symbol;
          366  +            if (s->next == MAXWIN) {
          367  +                if (s->outfun(s->outhow, s->out, s->next)) return 1;
          368  +                s->next = 0;
          369  +                s->first = 0;
          370  +            }
          371  +        }
          372  +    } while (1);
          373  +    return 0;
          374  +}
          375  +
          376  +/* See comments in blast.h */
          377  +int blast(blast_in infun, void *inhow, blast_out outfun, void *outhow)
          378  +{
          379  +    struct state s;             /* input/output state */
          380  +    int err;                    /* return value */
          381  +
          382  +    /* initialize input state */
          383  +    s.infun = infun;
          384  +    s.inhow = inhow;
          385  +    s.left = 0;
          386  +    s.bitbuf = 0;
          387  +    s.bitcnt = 0;
          388  +
          389  +    /* initialize output state */
          390  +    s.outfun = outfun;
          391  +    s.outhow = outhow;
          392  +    s.next = 0;
          393  +    s.first = 1;
          394  +
          395  +    /* return if bits() or decode() tries to read past available input */
          396  +    if (setjmp(s.env) != 0)             /* if came back here via longjmp(), */
          397  +        err = 2;                        /*  then skip decomp(), return error */
          398  +    else
          399  +        err = decomp(&s);               /* decompress */
          400  +
          401  +    /* write any leftover output and update the error code if needed */
          402  +    if (err != 1 && s.next && s.outfun(s.outhow, s.out, s.next) && err == 0)
          403  +        err = 1;
          404  +    return err;
          405  +}
          406  +
          407  +#ifdef TEST
          408  +/* Example of how to use blast() */
          409  +#include <stdio.h>
          410  +#include <stdlib.h>
          411  +
          412  +#define CHUNK 16384
          413  +
          414  +local unsigned inf(void *how, unsigned char **buf)
          415  +{
          416  +    static unsigned char hold[CHUNK];
          417  +
          418  +    *buf = hold;
          419  +    return fread(hold, 1, CHUNK, (FILE *)how);
          420  +}
          421  +
          422  +local int outf(void *how, unsigned char *buf, unsigned len)
          423  +{
          424  +    return fwrite(buf, 1, len, (FILE *)how) != len;
          425  +}
          426  +
          427  +/* Decompress a PKWare Compression Library stream from stdin to stdout */
          428  +int main(void)
          429  +{
          430  +    int ret, n;
          431  +
          432  +    /* decompress to stdout */
          433  +    ret = blast(inf, stdin, outf, stdout);
          434  +    if (ret != 0) fprintf(stderr, "blast error: %d\n", ret);
          435  +
          436  +    /* see if there are any leftover bytes */
          437  +    n = 0;
          438  +    while (getchar() != EOF) n++;
          439  +    if (n) fprintf(stderr, "blast warning: %d unused bytes of input\n", n);
          440  +
          441  +    /* return blast() error code */
          442  +    return ret;
          443  +}
          444  +#endif

Added compat/zlib/contrib/blast/blast.h.

            1  +/* blast.h -- interface for blast.c
            2  +  Copyright (C) 2003 Mark Adler
            3  +  version 1.1, 16 Feb 2003
            4  +
            5  +  This software is provided 'as-is', without any express or implied
            6  +  warranty.  In no event will the author be held liable for any damages
            7  +  arising from the use of this software.
            8  +
            9  +  Permission is granted to anyone to use this software for any purpose,
           10  +  including commercial applications, and to alter it and redistribute it
           11  +  freely, subject to the following restrictions:
           12  +
           13  +  1. The origin of this software must not be misrepresented; you must not
           14  +     claim that you wrote the original software. If you use this software
           15  +     in a product, an acknowledgment in the product documentation would be
           16  +     appreciated but is not required.
           17  +  2. Altered source versions must be plainly marked as such, and must not be
           18  +     misrepresented as being the original software.
           19  +  3. This notice may not be removed or altered from any source distribution.
           20  +
           21  +  Mark Adler    madler@alumni.caltech.edu
           22  + */
           23  +
           24  +
           25  +/*
           26  + * blast() decompresses the PKWare Data Compression Library (DCL) compressed
           27  + * format.  It provides the same functionality as the explode() function in
           28  + * that library.  (Note: PKWare overused the "implode" verb, and the format
           29  + * used by their library implode() function is completely different and
           30  + * incompatible with the implode compression method supported by PKZIP.)
           31  + */
           32  +
           33  +
           34  +typedef unsigned (*blast_in)(void *how, unsigned char **buf);
           35  +typedef int (*blast_out)(void *how, unsigned char *buf, unsigned len);
           36  +/* Definitions for input/output functions passed to blast().  See below for
           37  + * what the provided functions need to do.
           38  + */
           39  +
           40  +
           41  +int blast(blast_in infun, void *inhow, blast_out outfun, void *outhow);
           42  +/* Decompress input to output using the provided infun() and outfun() calls.
           43  + * On success, the return value of blast() is zero.  If there is an error in
           44  + * the source data, i.e. it is not in the proper format, then a negative value
           45  + * is returned.  If there is not enough input available or there is not enough
           46  + * output space, then a positive error is returned.
           47  + *
           48  + * The input function is invoked: len = infun(how, &buf), where buf is set by
           49  + * infun() to point to the input buffer, and infun() returns the number of
           50  + * available bytes there.  If infun() returns zero, then blast() returns with
           51  + * an input error.  (blast() only asks for input if it needs it.)  inhow is for
           52  + * use by the application to pass an input descriptor to infun(), if desired.
           53  + *
           54  + * The output function is invoked: err = outfun(how, buf, len), where the bytes
           55  + * to be written are buf[0..len-1].  If err is not zero, then blast() returns
           56  + * with an output error.  outfun() is always called with len <= 4096.  outhow
           57  + * is for use by the application to pass an output descriptor to outfun(), if
           58  + * desired.
           59  + *
           60  + * The return codes are:
           61  + *
           62  + *   2:  ran out of input before completing decompression
           63  + *   1:  output error before completing decompression
           64  + *   0:  successful decompression
           65  + *  -1:  literal flag not zero or one
           66  + *  -2:  dictionary size not in 4..6
           67  + *  -3:  distance is too far back
           68  + *
           69  + * At the bottom of blast.c is an example program that uses blast() that can be
           70  + * compiled to produce a command-line decompression filter by defining TEST.
           71  + */

Added compat/zlib/contrib/blast/test.pk.

cannot compute difference between binary files

Added compat/zlib/contrib/blast/test.txt.

            1  +AIAIAIAIAIAIA

Added compat/zlib/contrib/delphi/ZLib.pas.

            1  +{*******************************************************}
            2  +{                                                       }
            3  +{       Borland Delphi Supplemental Components          }
            4  +{       ZLIB Data Compression Interface Unit            }
            5  +{                                                       }
            6  +{       Copyright (c) 1997,99 Borland Corporation       }
            7  +{                                                       }
            8  +{*******************************************************}
            9  +
           10  +{ Updated for zlib 1.2.x by Cosmin Truta <cosmint@cs.ubbcluj.ro> }
           11  +
           12  +unit ZLib;
           13  +
           14  +interface
           15  +
           16  +uses SysUtils, Classes;
           17  +
           18  +type
           19  +  TAlloc = function (AppData: Pointer; Items, Size: Integer): Pointer; cdecl;
           20  +  TFree = procedure (AppData, Block: Pointer); cdecl;
           21  +
           22  +  // Internal structure.  Ignore.
           23  +  TZStreamRec = packed record
           24  +    next_in: PChar;       // next input byte
           25  +    avail_in: Integer;    // number of bytes available at next_in
           26  +    total_in: Longint;    // total nb of input bytes read so far
           27  +
           28  +    next_out: PChar;      // next output byte should be put here
           29  +    avail_out: Integer;   // remaining free space at next_out
           30  +    total_out: Longint;   // total nb of bytes output so far
           31  +
           32  +    msg: PChar;           // last error message, NULL if no error
           33  +    internal: Pointer;    // not visible by applications
           34  +
           35  +    zalloc: TAlloc;       // used to allocate the internal state
           36  +    zfree: TFree;         // used to free the internal state
           37  +    AppData: Pointer;     // private data object passed to zalloc and zfree
           38  +
           39  +    data_type: Integer;   // best guess about the data type: ascii or binary
           40  +    adler: Longint;       // adler32 value of the uncompressed data
           41  +    reserved: Longint;    // reserved for future use
           42  +  end;
           43  +
           44  +  // Abstract ancestor class
           45  +  TCustomZlibStream = class(TStream)
           46  +  private
           47  +    FStrm: TStream;
           48  +    FStrmPos: Integer;
           49  +    FOnProgress: TNotifyEvent;
           50  +    FZRec: TZStreamRec;
           51  +    FBuffer: array [Word] of Char;
           52  +  protected
           53  +    procedure Progress(Sender: TObject); dynamic;
           54  +    property OnProgress: TNotifyEvent read FOnProgress write FOnProgress;
           55  +    constructor Create(Strm: TStream);
           56  +  end;
           57  +
           58  +{ TCompressionStream compresses data on the fly as data is written to it, and
           59  +  stores the compressed data to another stream.
           60  +
           61  +  TCompressionStream is write-only and strictly sequential. Reading from the
           62  +  stream will raise an exception. Using Seek to move the stream pointer
           63  +  will raise an exception.
           64  +
           65  +  Output data is cached internally, written to the output stream only when
           66  +  the internal output buffer is full.  All pending output data is flushed
           67  +  when the stream is destroyed.
           68  +
           69  +  The Position property returns the number of uncompressed bytes of
           70  +  data that have been written to the stream so far.
           71  +
           72  +  CompressionRate returns the on-the-fly percentage by which the original
           73  +  data has been compressed:  (1 - (CompressedBytes / UncompressedBytes)) * 100
           74  +  If raw data size = 100 and compressed data size = 25, the CompressionRate
           75  +  is 75%
           76  +
           77  +  The OnProgress event is called each time the output buffer is filled and
           78  +  written to the output stream.  This is useful for updating a progress
           79  +  indicator when you are writing a large chunk of data to the compression
           80  +  stream in a single call.}
           81  +
           82  +
           83  +  TCompressionLevel = (clNone, clFastest, clDefault, clMax);
           84  +
           85  +  TCompressionStream = class(TCustomZlibStream)
           86  +  private
           87  +    function GetCompressionRate: Single;
           88  +  public
           89  +    constructor Create(CompressionLevel: TCompressionLevel; Dest: TStream);
           90  +    destructor Destroy; override;
           91  +    function Read(var Buffer; Count: Longint): Longint; override;
           92  +    function Write(const Buffer; Count: Longint): Longint; override;
           93  +    function Seek(Offset: Longint; Origin: Word): Longint; override;
           94  +    property CompressionRate: Single read GetCompressionRate;
           95  +    property OnProgress;
           96  +  end;
           97  +
           98  +{ TDecompressionStream decompresses data on the fly as data is read from it.
           99  +
          100  +  Compressed data comes from a separate source stream.  TDecompressionStream
          101  +  is read-only and unidirectional; you can seek forward in the stream, but not
          102  +  backwards.  The special case of setting the stream position to zero is
          103  +  allowed.  Seeking forward decompresses data until the requested position in
          104  +  the uncompressed data has been reached.  Seeking backwards, seeking relative
          105  +  to the end of the stream, requesting the size of the stream, and writing to
          106  +  the stream will raise an exception.
          107  +
          108  +  The Position property returns the number of bytes of uncompressed data that
          109  +  have been read from the stream so far.
          110  +
          111  +  The OnProgress event is called each time the internal input buffer of
          112  +  compressed data is exhausted and the next block is read from the input stream.
          113  +  This is useful for updating a progress indicator when you are reading a
          114  +  large chunk of data from the decompression stream in a single call.}
          115  +
          116  +  TDecompressionStream = class(TCustomZlibStream)
          117  +  public
          118  +    constructor Create(Source: TStream);
          119  +    destructor Destroy; override;
          120  +    function Read(var Buffer; Count: Longint): Longint; override;
          121  +    function Write(const Buffer; Count: Longint): Longint; override;
          122  +    function Seek(Offset: Longint; Origin: Word): Longint; override;
          123  +    property OnProgress;
          124  +  end;
          125  +
          126  +
          127  +
          128  +{ CompressBuf compresses data, buffer to buffer, in one call.
          129  +   In: InBuf = ptr to compressed data
          130  +       InBytes = number of bytes in InBuf
          131  +  Out: OutBuf = ptr to newly allocated buffer containing decompressed data
          132  +       OutBytes = number of bytes in OutBuf   }
          133  +procedure CompressBuf(const InBuf: Pointer; InBytes: Integer;
          134  +                      out OutBuf: Pointer; out OutBytes: Integer);
          135  +
          136  +
          137  +{ DecompressBuf decompresses data, buffer to buffer, in one call.
          138  +   In: InBuf = ptr to compressed data
          139  +       InBytes = number of bytes in InBuf
          140  +       OutEstimate = zero, or est. size of the decompressed data
          141  +  Out: OutBuf = ptr to newly allocated buffer containing decompressed data
          142  +       OutBytes = number of bytes in OutBuf   }
          143  +procedure DecompressBuf(const InBuf: Pointer; InBytes: Integer;
          144  + OutEstimate: Integer; out OutBuf: Pointer; out OutBytes: Integer);
          145  +
          146  +{ DecompressToUserBuf decompresses data, buffer to buffer, in one call.
          147  +   In: InBuf = ptr to compressed data
          148  +       InBytes = number of bytes in InBuf
          149  +  Out: OutBuf = ptr to user-allocated buffer to contain decompressed data
          150  +       BufSize = number of bytes in OutBuf   }
          151  +procedure DecompressToUserBuf(const InBuf: Pointer; InBytes: Integer;
          152  +  const OutBuf: Pointer; BufSize: Integer);
          153  +
          154  +const
          155  +  zlib_version = '1.2.7';
          156  +
          157  +type
          158  +  EZlibError = class(Exception);
          159  +  ECompressionError = class(EZlibError);
          160  +  EDecompressionError = class(EZlibError);
          161  +
          162  +implementation
          163  +
          164  +uses ZLibConst;
          165  +
          166  +const
          167  +  Z_NO_FLUSH      = 0;
          168  +  Z_PARTIAL_FLUSH = 1;
          169  +  Z_SYNC_FLUSH    = 2;
          170  +  Z_FULL_FLUSH    = 3;
          171  +  Z_FINISH        = 4;
          172  +
          173  +  Z_OK            = 0;
          174  +  Z_STREAM_END    = 1;
          175  +  Z_NEED_DICT     = 2;
          176  +  Z_ERRNO         = (-1);
          177  +  Z_STREAM_ERROR  = (-2);
          178  +  Z_DATA_ERROR    = (-3);
          179  +  Z_MEM_ERROR     = (-4);
          180  +  Z_BUF_ERROR     = (-5);
          181  +  Z_VERSION_ERROR = (-6);
          182  +
          183  +  Z_NO_COMPRESSION       =   0;
          184  +  Z_BEST_SPEED           =   1;
          185  +  Z_BEST_COMPRESSION     =   9;
          186  +  Z_DEFAULT_COMPRESSION  = (-1);
          187  +
          188  +  Z_FILTERED            = 1;
          189  +  Z_HUFFMAN_ONLY        = 2;
          190  +  Z_RLE                 = 3;
          191  +  Z_DEFAULT_STRATEGY    = 0;
          192  +
          193  +  Z_BINARY   = 0;
          194  +  Z_ASCII    = 1;
          195  +  Z_UNKNOWN  = 2;
          196  +
          197  +  Z_DEFLATED = 8;
          198  +
          199  +
          200  +{$L adler32.obj}
          201  +{$L compress.obj}
          202  +{$L crc32.obj}
          203  +{$L deflate.obj}
          204  +{$L infback.obj}
          205  +{$L inffast.obj}
          206  +{$L inflate.obj}
          207  +{$L inftrees.obj}
          208  +{$L trees.obj}
          209  +{$L uncompr.obj}
          210  +{$L zutil.obj}
          211  +
          212  +procedure adler32; external;
          213  +procedure compressBound; external;
          214  +procedure crc32; external;
          215  +procedure deflateInit2_; external;
          216  +procedure deflateParams; external;
          217  +
          218  +function _malloc(Size: Integer): Pointer; cdecl;
          219  +begin
          220  +  Result := AllocMem(Size);
          221  +end;
          222  +
          223  +procedure _free(Block: Pointer); cdecl;
          224  +begin
          225  +  FreeMem(Block);
          226  +end;
          227  +
          228  +procedure _memset(P: Pointer; B: Byte; count: Integer); cdecl;
          229  +begin
          230  +  FillChar(P^, count, B);
          231  +end;
          232  +
          233  +procedure _memcpy(dest, source: Pointer; count: Integer); cdecl;
          234  +begin
          235  +  Move(source^, dest^, count);
          236  +end;
          237  +
          238  +
          239  +
          240  +// deflate compresses data
          241  +function deflateInit_(var strm: TZStreamRec; level: Integer; version: PChar;
          242  +  recsize: Integer): Integer; external;
          243  +function deflate(var strm: TZStreamRec; flush: Integer): Integer; external;
          244  +function deflateEnd(var strm: TZStreamRec): Integer; external;
          245  +
          246  +// inflate decompresses data
          247  +function inflateInit_(var strm: TZStreamRec; version: PChar;
          248  +  recsize: Integer): Integer; external;
          249  +function inflate(var strm: TZStreamRec; flush: Integer): Integer; external;
          250  +function inflateEnd(var strm: TZStreamRec): Integer; external;
          251  +function inflateReset(var strm: TZStreamRec): Integer; external;
          252  +
          253  +
          254  +function zlibAllocMem(AppData: Pointer; Items, Size: Integer): Pointer; cdecl;
          255  +begin
          256  +//  GetMem(Result, Items*Size);
          257  +  Result := AllocMem(Items * Size);
          258  +end;
          259  +
          260  +procedure zlibFreeMem(AppData, Block: Pointer); cdecl;
          261  +begin
          262  +  FreeMem(Block);
          263  +end;
          264  +
          265  +{function zlibCheck(code: Integer): Integer;
          266  +begin
          267  +  Result := code;
          268  +  if code < 0 then
          269  +    raise EZlibError.Create('error');    //!!
          270  +end;}
          271  +
          272  +function CCheck(code: Integer): Integer;
          273  +begin
          274  +  Result := code;
          275  +  if code < 0 then
          276  +    raise ECompressionError.Create('error'); //!!
          277  +end;
          278  +
          279  +function DCheck(code: Integer): Integer;
          280  +begin
          281  +  Result := code;
          282  +  if code < 0 then
          283  +    raise EDecompressionError.Create('error');  //!!
          284  +end;
          285  +
          286  +procedure CompressBuf(const InBuf: Pointer; InBytes: Integer;
          287  +                      out OutBuf: Pointer; out OutBytes: Integer);
          288  +var
          289  +  strm: TZStreamRec;
          290  +  P: Pointer;
          291  +begin
          292  +  FillChar(strm, sizeof(strm), 0);
          293  +  strm.zalloc := zlibAllocMem;
          294  +  strm.zfree := zlibFreeMem;
          295  +  OutBytes := ((InBytes + (InBytes div 10) + 12) + 255) and not 255;
          296  +  GetMem(OutBuf, OutBytes);
          297  +  try
          298  +    strm.next_in := InBuf;
          299  +    strm.avail_in := InBytes;
          300  +    strm.next_out := OutBuf;
          301  +    strm.avail_out := OutBytes;
          302  +    CCheck(deflateInit_(strm, Z_BEST_COMPRESSION, zlib_version, sizeof(strm)));
          303  +    try
          304  +      while CCheck(deflate(strm, Z_FINISH)) <> Z_STREAM_END do
          305  +      begin
          306  +        P := OutBuf;
          307  +        Inc(OutBytes, 256);
          308  +        ReallocMem(OutBuf, OutBytes);
          309  +        strm.next_out := PChar(Integer(OutBuf) + (Integer(strm.next_out) - Integer(P)));
          310  +        strm.avail_out := 256;
          311  +      end;
          312  +    finally
          313  +      CCheck(deflateEnd(strm));
          314  +    end;
          315  +    ReallocMem(OutBuf, strm.total_out);
          316  +    OutBytes := strm.total_out;
          317  +  except
          318  +    FreeMem(OutBuf);
          319  +    raise
          320  +  end;
          321  +end;
          322  +
          323  +
          324  +procedure DecompressBuf(const InBuf: Pointer; InBytes: Integer;
          325  +  OutEstimate: Integer; out OutBuf: Pointer; out OutBytes: Integer);
          326  +var
          327  +  strm: TZStreamRec;
          328  +  P: Pointer;
          329  +  BufInc: Integer;
          330  +begin
          331  +  FillChar(strm, sizeof(strm), 0);
          332  +  strm.zalloc := zlibAllocMem;
          333  +  strm.zfree := zlibFreeMem;
          334  +  BufInc := (InBytes + 255) and not 255;
          335  +  if OutEstimate = 0 then
          336  +    OutBytes := BufInc
          337  +  else
          338  +    OutBytes := OutEstimate;
          339  +  GetMem(OutBuf, OutBytes);
          340  +  try
          341  +    strm.next_in := InBuf;
          342  +