https://git.reactos.org/?p=reactos.git;a=commitdiff;h=983f57b6e098786f4ddd8…
commit 983f57b6e098786f4ddd8fef75004f0b4e6ecb6c
Author: Thomas Faber <thomas.faber(a)reactos.org>
AuthorDate: Sun Oct 20 12:04:41 2019 +0200
Commit: Thomas Faber <thomas.faber(a)reactos.org>
CommitDate: Sun Oct 20 12:45:59 2019 +0200
[BZIP2] Remove unused library. CORE-16440
This was once used by the "ramdrv" driver, removed in r37739 (c47ab26e825).
---
media/doc/3rd Party Files.txt | 4 -
sdk/lib/3rdparty/CMakeLists.txt | 1 -
sdk/lib/3rdparty/bzip2/CHANGES | 327 -----
sdk/lib/3rdparty/bzip2/CMakeLists.txt | 22 -
sdk/lib/3rdparty/bzip2/LICENSE | 42 -
sdk/lib/3rdparty/bzip2/README | 215 ----
sdk/lib/3rdparty/bzip2/README.reactos | 8 -
sdk/lib/3rdparty/bzip2/Y2K_INFO | 34 -
sdk/lib/3rdparty/bzip2/blocksort.c | 1094 -----------------
sdk/lib/3rdparty/bzip2/bzip2.c | 2034 --------------------------------
sdk/lib/3rdparty/bzip2/bzip2recover.c | 514 --------
sdk/lib/3rdparty/bzip2/bzlib.c | 1589 -------------------------
sdk/lib/3rdparty/bzip2/bzlib.h | 282 -----
sdk/lib/3rdparty/bzip2/bzlib_private.h | 509 --------
sdk/lib/3rdparty/bzip2/compress.c | 672 -----------
sdk/lib/3rdparty/bzip2/crctable.c | 104 --
sdk/lib/3rdparty/bzip2/decompress.c | 646 ----------
sdk/lib/3rdparty/bzip2/dllmain.c | 19 -
sdk/lib/3rdparty/bzip2/dlltest.c | 175 ---
sdk/lib/3rdparty/bzip2/huffman.c | 205 ----
sdk/lib/3rdparty/bzip2/libbz2.def | 27 -
sdk/lib/3rdparty/bzip2/randtable.c | 84 --
sdk/lib/3rdparty/bzip2/spewG.c | 54 -
sdk/lib/3rdparty/bzip2/unbzip2.spec | 1 -
sdk/lib/3rdparty/bzip2/unzcrash.c | 141 ---
25 files changed, 8803 deletions(-)
diff --git a/media/doc/3rd Party Files.txt b/media/doc/3rd Party Files.txt
index 26274a45ebd..820d90305a4 100644
--- a/media/doc/3rd Party Files.txt
+++ b/media/doc/3rd Party Files.txt
@@ -38,10 +38,6 @@ Title: GNU adns
Used Version: 1.0 REV 5
Website:
http://www.gnu.org/software/adns/ |
http://adns.jgaa.com
-Title: BZip2
-Used Version: 1.0.6
-Website:
http://www.bzip.org
-
Title: LibXML
Used Version: 2.9.9
Website:
http://xmlsoft.org |
ftp://xmlsoft.org/libxml2/
diff --git a/sdk/lib/3rdparty/CMakeLists.txt b/sdk/lib/3rdparty/CMakeLists.txt
index 3bcf67656b0..2a5c5ea3b30 100644
--- a/sdk/lib/3rdparty/CMakeLists.txt
+++ b/sdk/lib/3rdparty/CMakeLists.txt
@@ -1,6 +1,5 @@
add_subdirectory(adns)
-add_subdirectory(bzip2)
add_subdirectory(cardlib)
add_subdirectory(freetype)
add_subdirectory(libmpg123)
diff --git a/sdk/lib/3rdparty/bzip2/CHANGES b/sdk/lib/3rdparty/bzip2/CHANGES
deleted file mode 100644
index 81e97ca6fa2..00000000000
--- a/sdk/lib/3rdparty/bzip2/CHANGES
+++ /dev/null
@@ -1,327 +0,0 @@
- ------------------------------------------------------------------
- This file is part of bzip2/libbzip2, a program and library for
- lossless, block-sorting data compression.
-
- bzip2/libbzip2 version 1.0.6 of 6 September 2010
- Copyright (C) 1996-2010 Julian Seward <jseward(a)bzip.org>
-
- Please read the WARNING, DISCLAIMER and PATENTS sections in the
- README file.
-
- This program is released under the terms of the license contained
- in the file LICENSE.
- ------------------------------------------------------------------
-
-
-0.9.0
-~~~~~
-First version.
-
-
-0.9.0a
-~~~~~~
-Removed 'ranlib' from Makefile, since most modern Unix-es
-don't need it, or even know about it.
-
-
-0.9.0b
-~~~~~~
-Fixed a problem with error reporting in bzip2.c. This does not effect
-the library in any way. Problem is: versions 0.9.0 and 0.9.0a (of the
-program proper) compress and decompress correctly, but give misleading
-error messages (internal panics) when an I/O error occurs, instead of
-reporting the problem correctly. This shouldn't give any data loss
-(as far as I can see), but is confusing.
-
-Made the inline declarations disappear for non-GCC compilers.
-
-
-0.9.0c
-~~~~~~
-Fixed some problems in the library pertaining to some boundary cases.
-This makes the library behave more correctly in those situations. The
-fixes apply only to features (calls and parameters) not used by
-bzip2.c, so the non-fixedness of them in previous versions has no
-effect on reliability of bzip2.c.
-
-In bzlib.c:
- * made zero-length BZ_FLUSH work correctly in bzCompress().
- * fixed bzWrite/bzRead to ignore zero-length requests.
- * fixed bzread to correctly handle read requests after EOF.
- * wrong parameter order in call to bzDecompressInit in
- bzBuffToBuffDecompress. Fixed.
-
-In compress.c:
- * changed setting of nGroups in sendMTFValues() so as to
- do a bit better on small files. This _does_ effect
- bzip2.c.
-
-
-0.9.5a
-~~~~~~
-Major change: add a fallback sorting algorithm (blocksort.c)
-to give reasonable behaviour even for very repetitive inputs.
-Nuked --repetitive-best and --repetitive-fast since they are
-no longer useful.
-
-Minor changes: mostly a whole bunch of small changes/
-bugfixes in the driver (bzip2.c). Changes pertaining to the
-user interface are:
-
- allow decompression of symlink'd files to stdout
- decompress/test files even without .bz2 extension
- give more accurate error messages for I/O errors
- when compressing/decompressing to stdout, don't catch control-C
- read flags from BZIP2 and BZIP environment variables
- decline to break hard links to a file unless forced with -f
- allow -c flag even with no filenames
- preserve file ownerships as far as possible
- make -s -1 give the expected block size (100k)
- add a flag -q --quiet to suppress nonessential warnings
- stop decoding flags after --, so files beginning in - can be handled
- resolved inconsistent naming: bzcat or bz2cat ?
- bzip2 --help now returns 0
-
-Programming-level changes are:
-
- fixed syntax error in GET_LL4 for Borland C++ 5.02
- let bzBuffToBuffDecompress return BZ_DATA_ERROR{_MAGIC}
- fix overshoot of mode-string end in bzopen_or_bzdopen
- wrapped bzlib.h in #ifdef __cplusplus ... extern "C" { ... }
- close file handles under all error conditions
- added minor mods so it compiles with DJGPP out of the box
- fixed Makefile so it doesn't give problems with BSD make
- fix uninitialised memory reads in dlltest.c
-
-0.9.5b
-~~~~~~
-Open stdin/stdout in binary mode for DJGPP.
-
-0.9.5c
-~~~~~~
-Changed BZ_N_OVERSHOOT to be ... + 2 instead of ... + 1. The + 1
-version could cause the sorted order to be wrong in some extremely
-obscure cases. Also changed setting of quadrant in blocksort.c.
-
-0.9.5d
-~~~~~~
-The only functional change is to make bzlibVersion() in the library
-return the correct string. This has no effect whatsoever on the
-functioning of the bzip2 program or library. Added a couple of casts
-so the library compiles without warnings at level 3 in MS Visual
-Studio 6.0. Included a Y2K statement in the file Y2K_INFO. All other
-changes are minor documentation changes.
-
-1.0
-~~~
-Several minor bugfixes and enhancements:
-
-* Large file support. The library uses 64-bit counters to
- count the volume of data passing through it. bzip2.c
- is now compiled with -D_FILE_OFFSET_BITS=64 to get large
- file support from the C library. -v correctly prints out
- file sizes greater than 4 gigabytes. All these changes have
- been made without assuming a 64-bit platform or a C compiler
- which supports 64-bit ints, so, except for the C library
- aspect, they are fully portable.
-
-* Decompression robustness. The library/program should be
- robust to any corruption of compressed data, detecting and
- handling _all_ corruption, instead of merely relying on
- the CRCs. What this means is that the program should
- never crash, given corrupted data, and the library should
- always return BZ_DATA_ERROR.
-
-* Fixed an obscure race-condition bug only ever observed on
- Solaris, in which, if you were very unlucky and issued
- control-C at exactly the wrong time, both input and output
- files would be deleted.
-
-* Don't run out of file handles on test/decompression when
- large numbers of files have invalid magic numbers.
-
-* Avoid library namespace pollution. Prefix all exported
- symbols with BZ2_.
-
-* Minor sorting enhancements from my DCC2000 paper.
-
-* Advance the version number to 1.0, so as to counteract the
- (false-in-this-case) impression some people have that programs
- with version numbers less than 1.0 are in some way, experimental,
- pre-release versions.
-
-* Create an initial Makefile-libbz2_so to build a shared library.
- Yes, I know I should really use libtool et al ...
-
-* Make the program exit with 2 instead of 0 when decompression
- fails due to a bad magic number (ie, an invalid bzip2 header).
- Also exit with 1 (as the manual claims :-) whenever a diagnostic
- message would have been printed AND the corresponding operation
- is aborted, for example
- bzip2: Output file xx already exists.
- When a diagnostic message is printed but the operation is not
- aborted, for example
- bzip2: Can't guess original name for wurble -- using wurble.out
- then the exit value 0 is returned, unless some other problem is
- also detected.
-
- I think it corresponds more closely to what the manual claims now.
-
-
-1.0.1
-~~~~~
-* Modified dlltest.c so it uses the new BZ2_ naming scheme.
-* Modified makefile-msc to fix minor build probs on Win2k.
-* Updated README.COMPILATION.PROBLEMS.
-
-There are no functionality changes or bug fixes relative to version
-1.0.0. This is just a documentation update + a fix for minor Win32
-build problems. For almost everyone, upgrading from 1.0.0 to 1.0.1 is
-utterly pointless. Don't bother.
-
-
-1.0.2
-~~~~~
-A bug fix release, addressing various minor issues which have appeared
-in the 18 or so months since 1.0.1 was released. Most of the fixes
-are to do with file-handling or documentation bugs. To the best of my
-knowledge, there have been no data-loss-causing bugs reported in the
-compression/decompression engine of 1.0.0 or 1.0.1.
-
-Note that this release does not improve the rather crude build system
-for Unix platforms. The general plan here is to autoconfiscate/
-libtoolise 1.0.2 soon after release, and release the result as 1.1.0
-or perhaps 1.2.0. That, however, is still just a plan at this point.
-
-Here are the changes in 1.0.2. Bug-reporters and/or patch-senders in
-parentheses.
-
-* Fix an infinite segfault loop in 1.0.1 when a directory is
- encountered in -f (force) mode.
- (Trond Eivind Glomsrod, Nicholas Nethercote, Volker Schmidt)
-
-* Avoid double fclose() of output file on certain I/O error paths.
- (Solar Designer)
-
-* Don't fail with internal error 1007 when fed a long stream (> 48MB)
- of byte 251. Also print useful message suggesting that 1007s may be
- caused by bad memory.
- (noticed by Juan Pedro Vallejo, fixed by me)
-
-* Fix uninitialised variable silly bug in demo prog dlltest.c.
- (Jorj Bauer)
-
-* Remove 512-MB limitation on recovered file size for bzip2recover
- on selected platforms which support 64-bit ints. At the moment
- all GCC supported platforms, and Win32.
- (me, Alson van der Meulen)
-
-* Hard-code header byte values, to give correct operation on platforms
- using EBCDIC as their native character set (IBM's OS/390).
- (Leland Lucius)
-
-* Copy file access times correctly.
- (Marty Leisner)
-
-* Add distclean and check targets to Makefile.
- (Michael Carmack)
-
-* Parameterise use of ar and ranlib in Makefile. Also add $(LDFLAGS).
- (Rich Ireland, Bo Thorsen)
-
-* Pass -p (create parent dirs as needed) to mkdir during make install.
- (Jeremy Fusco)
-
-* Dereference symlinks when copying file permissions in -f mode.
- (Volker Schmidt)
-
-* Majorly simplify implementation of uInt64_qrm10.
- (Bo Lindbergh)
-
-* Check the input file still exists before deleting the output one,
- when aborting in cleanUpAndFail().
- (Joerg Prante, Robert Linden, Matthias Krings)
-
-Also a bunch of patches courtesy of Philippe Troin, the Debian maintainer
-of bzip2:
-
-* Wrapper scripts (with manpages): bzdiff, bzgrep, bzmore.
-
-* Spelling changes and minor enhancements in bzip2.1.
-
-* Avoid race condition between creating the output file and setting its
- interim permissions safely, by using fopen_output_safely().
- No changes to bzip2recover since there is no issue with file
- permissions there.
-
-* do not print senseless report with -v when compressing an empty
- file.
-
-* bzcat -f works on non-bzip2 files.
-
-* do not try to escape shell meta-characters on unix (the shell takes
- care of these).
-
-* added --fast and --best aliases for -1 -9 for gzip compatibility.
-
-
-1.0.3 (15 Feb 05)
-~~~~~~~~~~~~~~~~~
-Fixes some minor bugs since the last version, 1.0.2.
-
-* Further robustification against corrupted compressed data.
- There are currently no known bitstreams which can cause the
- decompressor to crash, loop or access memory which does not
- belong to it. If you are using bzip2 or the library to
- decompress bitstreams from untrusted sources, an upgrade
- to 1.0.3 is recommended. This fixes CAN-2005-1260.
-
-* The documentation has been converted to XML, from which html
- and pdf can be derived.
-
-* Various minor bugs in the documentation have been fixed.
-
-* Fixes for various compilation warnings with newer versions of
- gcc, and on 64-bit platforms.
-
-* The BZ_NO_STDIO cpp symbol was not properly observed in 1.0.2.
- This has been fixed.
-
-
-1.0.4 (20 Dec 06)
-~~~~~~~~~~~~~~~~~
-Fixes some minor bugs since the last version, 1.0.3.
-
-* Fix file permissions race problem (CAN-2005-0953).
-
-* Avoid possible segfault in BZ2_bzclose. From Coverity's NetBSD
- scan.
-
-* 'const'/prototype cleanups in the C code.
-
-* Change default install location to /usr/local, and handle multiple
- 'make install's without error.
-
-* Sanitise file names more carefully in bzgrep. Fixes CAN-2005-0758
- to the extent that applies to bzgrep.
-
-* Use 'mktemp' rather than 'tempfile' in bzdiff.
-
-* Tighten up a couple of assertions in blocksort.c following automated
- analysis.
-
-* Fix minor doc/comment bugs.
-
-
-1.0.5 (10 Dec 07)
-~~~~~~~~~~~~~~~~~
-Security fix only. Fixes CERT-FI 20469 as it applies to bzip2.
-
-
-1.0.6 (6 Sept 10)
-~~~~~~~~~~~~~~~~~
-
-* Security fix for CVE-2010-0405. This was reported by Mikolaj
- Izdebski.
-
-* Make the documentation build on Ubuntu 10.04
diff --git a/sdk/lib/3rdparty/bzip2/CMakeLists.txt
b/sdk/lib/3rdparty/bzip2/CMakeLists.txt
deleted file mode 100644
index d30189d7d1b..00000000000
--- a/sdk/lib/3rdparty/bzip2/CMakeLists.txt
+++ /dev/null
@@ -1,22 +0,0 @@
-
-add_definitions(-DBZ_NO_STDIO -DBZ_DECOMPRESS_ONLY)
-spec2def(unbzip2.sys unbzip2.spec)
-
-list(APPEND SOURCE
- bzlib.c
- randtable.c
- crctable.c
- decompress.c
- huffman.c
- dllmain.c
- bzlib_private.h)
-
-add_library(bzip2 MODULE
- ${SOURCE}
- ${CMAKE_CURRENT_BINARY_DIR}/unbzip2.def)
-
-set_module_type(bzip2 kernelmodedriver)
-add_importlibs(bzip2 ntoskrnl)
-target_link_libraries(bzip2 libcntpr)
-add_pch(bzip2 bzlib_private.h SOURCE)
-set_target_properties(bzip2 PROPERTIES OUTPUT_NAME "unbzip2")
diff --git a/sdk/lib/3rdparty/bzip2/LICENSE b/sdk/lib/3rdparty/bzip2/LICENSE
deleted file mode 100644
index cc614178cf7..00000000000
--- a/sdk/lib/3rdparty/bzip2/LICENSE
+++ /dev/null
@@ -1,42 +0,0 @@
-
---------------------------------------------------------------------------
-
-This program, "bzip2", the associated library "libbzip2", and all
-documentation, are copyright (C) 1996-2010 Julian R Seward. All
-rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions
-are met:
-
-1. Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
-
-2. The origin of this software must not be misrepresented; you must
- not claim that you wrote the original software. If you use this
- software in a product, an acknowledgment in the product
- documentation would be appreciated but is not required.
-
-3. Altered source versions must be plainly marked as such, and must
- not be misrepresented as being the original software.
-
-4. The name of the author may not be used to endorse or promote
- products derived from this software without specific prior written
- permission.
-
-THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
-OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
-DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
-GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
-NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-Julian Seward, jseward(a)bzip.org
-bzip2/libbzip2 version 1.0.6 of 6 September 2010
-
---------------------------------------------------------------------------
diff --git a/sdk/lib/3rdparty/bzip2/README b/sdk/lib/3rdparty/bzip2/README
deleted file mode 100644
index 9fb0f636013..00000000000
--- a/sdk/lib/3rdparty/bzip2/README
+++ /dev/null
@@ -1,215 +0,0 @@
-
-This is the README for bzip2/libzip2.
-This version is fully compatible with the previous public releases.
-
-------------------------------------------------------------------
-This file is part of bzip2/libbzip2, a program and library for
-lossless, block-sorting data compression.
-
-bzip2/libbzip2 version 1.0.6 of 6 September 2010
-Copyright (C) 1996-2010 Julian Seward <jseward(a)bzip.org>
-
-Please read the WARNING, DISCLAIMER and PATENTS sections in this file.
-
-This program is released under the terms of the license contained
-in the file LICENSE.
-------------------------------------------------------------------
-
-Complete documentation is available in Postscript form (manual.ps),
-PDF (manual.pdf) or html (manual.html). A plain-text version of the
-manual page is available as bzip2.txt.
-
-
-HOW TO BUILD -- UNIX
-
-Type 'make'. This builds the library libbz2.a and then the programs
-bzip2 and bzip2recover. Six self-tests are run. If the self-tests
-complete ok, carry on to installation:
-
-To install in /usr/local/bin, /usr/local/lib, /usr/local/man and
-/usr/local/include, type
-
- make install
-
-To install somewhere else, eg, /xxx/yyy/{bin,lib,man,include}, type
-
- make install PREFIX=/xxx/yyy
-
-If you are (justifiably) paranoid and want to see what 'make install'
-is going to do, you can first do
-
- make -n install or
- make -n install PREFIX=/xxx/yyy respectively.
-
-The -n instructs make to show the commands it would execute, but not
-actually execute them.
-
-
-HOW TO BUILD -- UNIX, shared library libbz2.so.
-
-Do 'make -f Makefile-libbz2_so'. This Makefile seems to work for
-Linux-ELF (RedHat 7.2 on an x86 box), with gcc. I make no claims
-that it works for any other platform, though I suspect it probably
-will work for most platforms employing both ELF and gcc.
-
-bzip2-shared, a client of the shared library, is also built, but not
-self-tested. So I suggest you also build using the normal Makefile,
-since that conducts a self-test. A second reason to prefer the
-version statically linked to the library is that, on x86 platforms,
-building shared objects makes a valuable register (%ebx) unavailable
-to gcc, resulting in a slowdown of 10%-20%, at least for bzip2.
-
-Important note for people upgrading .so's from 0.9.0/0.9.5 to version
-1.0.X. All the functions in the library have been renamed, from (eg)
-bzCompress to BZ2_bzCompress, to avoid namespace pollution.
-Unfortunately this means that the libbz2.so created by
-Makefile-libbz2_so will not work with any program which used an older
-version of the library. I do encourage library clients to make the
-effort to upgrade to use version 1.0, since it is both faster and more
-robust than previous versions.
-
-
-HOW TO BUILD -- Windows 95, NT, DOS, Mac, etc.
-
-It's difficult for me to support compilation on all these platforms.
-My approach is to collect binaries for these platforms, and put them
-on the master web site (
http://www.bzip.org). Look there. However
-(FWIW), bzip2-1.0.X is very standard ANSI C and should compile
-unmodified with MS Visual C. If you have difficulties building, you
-might want to read README.COMPILATION.PROBLEMS.
-
-At least using MS Visual C++ 6, you can build from the unmodified
-sources by issuing, in a command shell:
-
- nmake -f makefile.msc
-
-(you may need to first run the MSVC-provided script VCVARS32.BAT
- so as to set up paths to the MSVC tools correctly).
-
-
-VALIDATION
-
-Correct operation, in the sense that a compressed file can always be
-decompressed to reproduce the original, is obviously of paramount
-importance. To validate bzip2, I used a modified version of Mark
-Nelson's churn program. Churn is an automated test driver which
-recursively traverses a directory structure, using bzip2 to compress
-and then decompress each file it encounters, and checking that the
-decompressed data is the same as the original.
-
-
-
-Please read and be aware of the following:
-
-WARNING:
-
- This program and library (attempts to) compress data by
- performing several non-trivial transformations on it.
- Unless you are 100% familiar with *all* the algorithms
- contained herein, and with the consequences of modifying them,
- you should NOT meddle with the compression or decompression
- machinery. Incorrect changes can and very likely *will*
- lead to disastrous loss of data.
-
-
-DISCLAIMER:
-
- I TAKE NO RESPONSIBILITY FOR ANY LOSS OF DATA ARISING FROM THE
- USE OF THIS PROGRAM/LIBRARY, HOWSOEVER CAUSED.
-
- Every compression of a file implies an assumption that the
- compressed file can be decompressed to reproduce the original.
- Great efforts in design, coding and testing have been made to
- ensure that this program works correctly. However, the complexity
- of the algorithms, and, in particular, the presence of various
- special cases in the code which occur with very low but non-zero
- probability make it impossible to rule out the possibility of bugs
- remaining in the program. DO NOT COMPRESS ANY DATA WITH THIS
- PROGRAM UNLESS YOU ARE PREPARED TO ACCEPT THE POSSIBILITY, HOWEVER
- SMALL, THAT THE DATA WILL NOT BE RECOVERABLE.
-
- That is not to say this program is inherently unreliable.
- Indeed, I very much hope the opposite is true. bzip2/libbzip2
- has been carefully constructed and extensively tested.
-
-
-PATENTS:
-
- To the best of my knowledge, bzip2/libbzip2 does not use any
- patented algorithms. However, I do not have the resources
- to carry out a patent search. Therefore I cannot give any
- guarantee of the above statement.
-
-
-
-WHAT'S NEW IN 0.9.0 (as compared to 0.1pl2) ?
-
- * Approx 10% faster compression, 30% faster decompression
- * -t (test mode) is a lot quicker
- * Can decompress concatenated compressed files
- * Programming interface, so programs can directly read/write .bz2 files
- * Less restrictive (BSD-style) licensing
- * Flag handling more compatible with GNU gzip
- * Much more documentation, i.e., a proper user manual
- * Hopefully, improved portability (at least of the library)
-
-WHAT'S NEW IN 0.9.5 ?
-
- * Compression speed is much less sensitive to the input
- data than in previous versions. Specifically, the very
- slow performance caused by repetitive data is fixed.
- * Many small improvements in file and flag handling.
- * A Y2K statement.
-
-WHAT'S NEW IN 1.0.0 ?
-
- See the CHANGES file.
-
-WHAT'S NEW IN 1.0.2 ?
-
- See the CHANGES file.
-
-WHAT'S NEW IN 1.0.3 ?
-
- See the CHANGES file.
-
-WHAT'S NEW IN 1.0.4 ?
-
- See the CHANGES file.
-
-WHAT'S NEW IN 1.0.5 ?
-
- See the CHANGES file.
-
-WHAT'S NEW IN 1.0.6 ?
-
- See the CHANGES file.
-
-
-I hope you find bzip2 useful. Feel free to contact me at
- jseward(a)bzip.org
-if you have any suggestions or queries. Many people mailed me with
-comments, suggestions and patches after the releases of bzip-0.15,
-bzip-0.21, and bzip2 versions 0.1pl2, 0.9.0, 0.9.5, 1.0.0, 1.0.1,
-1.0.2 and 1.0.3, and the changes in bzip2 are largely a result of this
-feedback. I thank you for your comments.
-
-bzip2's "home" is
http://www.bzip.org/
-
-Julian Seward
-jseward(a)bzip.org
-Cambridge, UK.
-
-18 July 1996 (version 0.15)
-25 August 1996 (version 0.21)
- 7 August 1997 (bzip2, version 0.1)
-29 August 1997 (bzip2, version 0.1pl2)
-23 August 1998 (bzip2, version 0.9.0)
- 8 June 1999 (bzip2, version 0.9.5)
- 4 Sept 1999 (bzip2, version 0.9.5d)
- 5 May 2000 (bzip2, version 1.0pre8)
-30 December 2001 (bzip2, version 1.0.2pre1)
-15 February 2005 (bzip2, version 1.0.3)
-20 December 2006 (bzip2, version 1.0.4)
-10 December 2007 (bzip2, version 1.0.5)
- 6 Sept 2010 (bzip2, version 1.0.6)
diff --git a/sdk/lib/3rdparty/bzip2/README.reactos
b/sdk/lib/3rdparty/bzip2/README.reactos
deleted file mode 100644
index 8d5b127c445..00000000000
--- a/sdk/lib/3rdparty/bzip2/README.reactos
+++ /dev/null
@@ -1,8 +0,0 @@
-2001-10-16: Imported bzip2 code into reactos project to create a decompression
-library for use by the ramdisk driver to decompress the ramdisk image into mem
-Modified makefile and some source code to build a .dll with only the
-decompression code. There are 3 exports: the decompression routine, and two
-function pointers that must be initialized to C malloc and free routines.
-
- - Phillip Susi
-
diff --git a/sdk/lib/3rdparty/bzip2/Y2K_INFO b/sdk/lib/3rdparty/bzip2/Y2K_INFO
deleted file mode 100644
index 55fd56a2edb..00000000000
--- a/sdk/lib/3rdparty/bzip2/Y2K_INFO
+++ /dev/null
@@ -1,34 +0,0 @@
-
-Y2K status of bzip2 and libbzip2, versions 0.1, 0.9.0 and 0.9.5
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-Informally speaking:
- bzip2 is a compression program built on top of libbzip2,
- a library which does the real work of compression and
- decompression. As far as I am aware, libbzip2 does not have
- any date-related code at all.
-
- bzip2 itself copies dates from source to destination files
- when compressing or decompressing, using the 'stat' and 'utime'
- UNIX system calls. It doesn't examine, manipulate or store the
- dates in any way. So as far as I can see, there shouldn't be any
- problem with bzip2 providing 'stat' and 'utime' work correctly
- on your system.
-
- On non-unix platforms (those for which BZ_UNIX in bzip2.c is
- not set to 1), bzip2 doesn't even do the date copying.
-
- Overall, informally speaking, I don't think bzip2 or libbzip2
- have a Y2K problem.
-
-Formally speaking:
- I am not prepared to offer you any assurance whatsoever
- regarding Y2K issues in my software. You alone assume the
- entire risk of using the software. The disclaimer of liability
- in the LICENSE file in the bzip2 source distribution continues
- to apply on this issue as with every other issue pertaining
- to the software.
-
-Julian Seward
-Cambridge, UK
-25 August 1999
diff --git a/sdk/lib/3rdparty/bzip2/blocksort.c b/sdk/lib/3rdparty/bzip2/blocksort.c
deleted file mode 100644
index d0d662cd4e9..00000000000
--- a/sdk/lib/3rdparty/bzip2/blocksort.c
+++ /dev/null
@@ -1,1094 +0,0 @@
-
-/*-------------------------------------------------------------*/
-/*--- Block sorting machinery ---*/
-/*--- blocksort.c ---*/
-/*-------------------------------------------------------------*/
-
-/* ------------------------------------------------------------------
- This file is part of bzip2/libbzip2, a program and library for
- lossless, block-sorting data compression.
-
- bzip2/libbzip2 version 1.0.6 of 6 September 2010
- Copyright (C) 1996-2010 Julian Seward <jseward(a)bzip.org>
-
- Please read the WARNING, DISCLAIMER and PATENTS sections in the
- README file.
-
- This program is released under the terms of the license contained
- in the file LICENSE.
- ------------------------------------------------------------------ */
-
-
-#include "bzlib_private.h"
-
-/*---------------------------------------------*/
-/*--- Fallback O(N log(N)^2) sorting ---*/
-/*--- algorithm, for repetitive blocks ---*/
-/*---------------------------------------------*/
-
-/*---------------------------------------------*/
-static
-__inline__
-void fallbackSimpleSort ( UInt32* fmap,
- UInt32* eclass,
- Int32 lo,
- Int32 hi )
-{
- Int32 i, j, tmp;
- UInt32 ec_tmp;
-
- if (lo == hi) return;
-
- if (hi - lo > 3) {
- for ( i = hi-4; i >= lo; i-- ) {
- tmp = fmap[i];
- ec_tmp = eclass[tmp];
- for ( j = i+4; j <= hi && ec_tmp > eclass[fmap[j]]; j += 4 )
- fmap[j-4] = fmap[j];
- fmap[j-4] = tmp;
- }
- }
-
- for ( i = hi-1; i >= lo; i-- ) {
- tmp = fmap[i];
- ec_tmp = eclass[tmp];
- for ( j = i+1; j <= hi && ec_tmp > eclass[fmap[j]]; j++ )
- fmap[j-1] = fmap[j];
- fmap[j-1] = tmp;
- }
-}
-
-
-/*---------------------------------------------*/
-#define fswap(zz1, zz2) \
- { Int32 zztmp = zz1; zz1 = zz2; zz2 = zztmp; }
-
-#define fvswap(zzp1, zzp2, zzn) \
-{ \
- Int32 yyp1 = (zzp1); \
- Int32 yyp2 = (zzp2); \
- Int32 yyn = (zzn); \
- while (yyn > 0) { \
- fswap(fmap[yyp1], fmap[yyp2]); \
- yyp1++; yyp2++; yyn--; \
- } \
-}
-
-
-#define fmin(a,b) ((a) < (b)) ? (a) : (b)
-
-#define fpush(lz,hz) { stackLo[sp] = lz; \
- stackHi[sp] = hz; \
- sp++; }
-
-#define fpop(lz,hz) { sp--; \
- lz = stackLo[sp]; \
- hz = stackHi[sp]; }
-
-#define FALLBACK_QSORT_SMALL_THRESH 10
-#define FALLBACK_QSORT_STACK_SIZE 100
-
-
-static
-void fallbackQSort3 ( UInt32* fmap,
- UInt32* eclass,
- Int32 loSt,
- Int32 hiSt )
-{
- Int32 unLo, unHi, ltLo, gtHi, n, m;
- Int32 sp, lo, hi;
- UInt32 med, r, r3;
- Int32 stackLo[FALLBACK_QSORT_STACK_SIZE];
- Int32 stackHi[FALLBACK_QSORT_STACK_SIZE];
-
- r = 0;
-
- sp = 0;
- fpush ( loSt, hiSt );
-
- while (sp > 0) {
-
- AssertH ( sp < FALLBACK_QSORT_STACK_SIZE - 1, 1004 );
-
- fpop ( lo, hi );
- if (hi - lo < FALLBACK_QSORT_SMALL_THRESH) {
- fallbackSimpleSort ( fmap, eclass, lo, hi );
- continue;
- }
-
- /* Random partitioning. Median of 3 sometimes fails to
- avoid bad cases. Median of 9 seems to help but
- looks rather expensive. This too seems to work but
- is cheaper. Guidance for the magic constants
- 7621 and 32768 is taken from Sedgewick's algorithms
- book, chapter 35.
- */
- r = ((r * 7621) + 1) % 32768;
- r3 = r % 3;
- if (r3 == 0) med = eclass[fmap[lo]]; else
- if (r3 == 1) med = eclass[fmap[(lo+hi)>>1]]; else
- med = eclass[fmap[hi]];
-
- unLo = ltLo = lo;
- unHi = gtHi = hi;
-
- while (1) {
- while (1) {
- if (unLo > unHi) break;
- n = (Int32)eclass[fmap[unLo]] - (Int32)med;
- if (n == 0) {
- fswap(fmap[unLo], fmap[ltLo]);
- ltLo++; unLo++;
- continue;
- };
- if (n > 0) break;
- unLo++;
- }
- while (1) {
- if (unLo > unHi) break;
- n = (Int32)eclass[fmap[unHi]] - (Int32)med;
- if (n == 0) {
- fswap(fmap[unHi], fmap[gtHi]);
- gtHi--; unHi--;
- continue;
- };
- if (n < 0) break;
- unHi--;
- }
- if (unLo > unHi) break;
- fswap(fmap[unLo], fmap[unHi]); unLo++; unHi--;
- }
-
- AssertD ( unHi == unLo-1, "fallbackQSort3(2)" );
-
- if (gtHi < ltLo) continue;
-
- n = fmin(ltLo-lo, unLo-ltLo); fvswap(lo, unLo-n, n);
- m = fmin(hi-gtHi, gtHi-unHi); fvswap(unLo, hi-m+1, m);
-
- n = lo + unLo - ltLo - 1;
- m = hi - (gtHi - unHi) + 1;
-
- if (n - lo > hi - m) {
- fpush ( lo, n );
- fpush ( m, hi );
- } else {
- fpush ( m, hi );
- fpush ( lo, n );
- }
- }
-}
-
-#undef fmin
-#undef fpush
-#undef fpop
-#undef fswap
-#undef fvswap
-#undef FALLBACK_QSORT_SMALL_THRESH
-#undef FALLBACK_QSORT_STACK_SIZE
-
-
-/*---------------------------------------------*/
-/* Pre:
- nblock > 0
- eclass exists for [0 .. nblock-1]
- ((UChar*)eclass) [0 .. nblock-1] holds block
- ptr exists for [0 .. nblock-1]
-
- Post:
- ((UChar*)eclass) [0 .. nblock-1] holds block
- All other areas of eclass destroyed
- fmap [0 .. nblock-1] holds sorted order
- bhtab [ 0 .. 2+(nblock/32) ] destroyed
-*/
-
-#define SET_BH(zz) bhtab[(zz) >> 5] |= (1 << ((zz) & 31))
-#define CLEAR_BH(zz) bhtab[(zz) >> 5] &= ~(1 << ((zz) & 31))
-#define ISSET_BH(zz) (bhtab[(zz) >> 5] & (1 << ((zz) & 31)))
-#define WORD_BH(zz) bhtab[(zz) >> 5]
-#define UNALIGNED_BH(zz) ((zz) & 0x01f)
-
-static
-void fallbackSort ( UInt32* fmap,
- UInt32* eclass,
- UInt32* bhtab,
- Int32 nblock,
- Int32 verb )
-{
- Int32 ftab[257];
- Int32 ftabCopy[256];
- Int32 H, i, j, k, l, r, cc, cc1;
- Int32 nNotDone;
- Int32 nBhtab;
- UChar* eclass8 = (UChar*)eclass;
-
- /*--
- Initial 1-char radix sort to generate
- initial fmap and initial BH bits.
- --*/
- if (verb >= 4)
- VPrintf0 ( " bucket sorting ...\n" );
- for (i = 0; i < 257; i++) ftab[i] = 0;
- for (i = 0; i < nblock; i++) ftab[eclass8[i]]++;
- for (i = 0; i < 256; i++) ftabCopy[i] = ftab[i];
- for (i = 1; i < 257; i++) ftab[i] += ftab[i-1];
-
- for (i = 0; i < nblock; i++) {
- j = eclass8[i];
- k = ftab[j] - 1;
- ftab[j] = k;
- fmap[k] = i;
- }
-
- nBhtab = 2 + (nblock / 32);
- for (i = 0; i < nBhtab; i++) bhtab[i] = 0;
- for (i = 0; i < 256; i++) SET_BH(ftab[i]);
-
- /*--
- Inductively refine the buckets. Kind-of an
- "exponential radix sort" (!), inspired by the
- Manber-Myers suffix array construction algorithm.
- --*/
-
- /*-- set sentinel bits for block-end detection --*/
- for (i = 0; i < 32; i++) {
- SET_BH(nblock + 2*i);
- CLEAR_BH(nblock + 2*i + 1);
- }
-
- /*-- the log(N) loop --*/
- H = 1;
- while (1) {
-
- if (verb >= 4)
- VPrintf1 ( " depth %6d has ", H );
-
- j = 0;
- for (i = 0; i < nblock; i++) {
- if (ISSET_BH(i)) j = i;
- k = fmap[i] - H; if (k < 0) k += nblock;
- eclass[k] = j;
- }
-
- nNotDone = 0;
- r = -1;
- while (1) {
-
- /*-- find the next non-singleton bucket --*/
- k = r + 1;
- while (ISSET_BH(k) && UNALIGNED_BH(k)) k++;
- if (ISSET_BH(k)) {
- while (WORD_BH(k) == 0xffffffff) k += 32;
- while (ISSET_BH(k)) k++;
- }
- l = k - 1;
- if (l >= nblock) break;
- while (!ISSET_BH(k) && UNALIGNED_BH(k)) k++;
- if (!ISSET_BH(k)) {
- while (WORD_BH(k) == 0x00000000) k += 32;
- while (!ISSET_BH(k)) k++;
- }
- r = k - 1;
- if (r >= nblock) break;
-
- /*-- now [l, r] bracket current bucket --*/
- if (r > l) {
- nNotDone += (r - l + 1);
- fallbackQSort3 ( fmap, eclass, l, r );
-
- /*-- scan bucket and generate header bits-- */
- cc = -1;
- for (i = l; i <= r; i++) {
- cc1 = eclass[fmap[i]];
- if (cc != cc1) { SET_BH(i); cc = cc1; };
- }
- }
- }
-
- if (verb >= 4)
- VPrintf1 ( "%6d unresolved strings\n", nNotDone );
-
- H *= 2;
- if (H > nblock || nNotDone == 0) break;
- }
-
- /*--
- Reconstruct the original block in
- eclass8 [0 .. nblock-1], since the
- previous phase destroyed it.
- --*/
- if (verb >= 4)
- VPrintf0 ( " reconstructing block ...\n" );
- j = 0;
- for (i = 0; i < nblock; i++) {
- while (ftabCopy[j] == 0) j++;
- ftabCopy[j]--;
- eclass8[fmap[i]] = (UChar)j;
- }
- AssertH ( j < 256, 1005 );
-}
-
-#undef SET_BH
-#undef CLEAR_BH
-#undef ISSET_BH
-#undef WORD_BH
-#undef UNALIGNED_BH
-
-
-/*---------------------------------------------*/
-/*--- The main, O(N^2 log(N)) sorting ---*/
-/*--- algorithm. Faster for "normal" ---*/
-/*--- non-repetitive blocks. ---*/
-/*---------------------------------------------*/
-
-/*---------------------------------------------*/
-static
-__inline__
-Bool mainGtU ( UInt32 i1,
- UInt32 i2,
- UChar* block,
- UInt16* quadrant,
- UInt32 nblock,
- Int32* budget )
-{
- Int32 k;
- UChar c1, c2;
- UInt16 s1, s2;
-
- AssertD ( i1 != i2, "mainGtU" );
- /* 1 */
- c1 = block[i1]; c2 = block[i2];
- if (c1 != c2) return (c1 > c2);
- i1++; i2++;
- /* 2 */
- c1 = block[i1]; c2 = block[i2];
- if (c1 != c2) return (c1 > c2);
- i1++; i2++;
- /* 3 */
- c1 = block[i1]; c2 = block[i2];
- if (c1 != c2) return (c1 > c2);
- i1++; i2++;
- /* 4 */
- c1 = block[i1]; c2 = block[i2];
- if (c1 != c2) return (c1 > c2);
- i1++; i2++;
- /* 5 */
- c1 = block[i1]; c2 = block[i2];
- if (c1 != c2) return (c1 > c2);
- i1++; i2++;
- /* 6 */
- c1 = block[i1]; c2 = block[i2];
- if (c1 != c2) return (c1 > c2);
- i1++; i2++;
- /* 7 */
- c1 = block[i1]; c2 = block[i2];
- if (c1 != c2) return (c1 > c2);
- i1++; i2++;
- /* 8 */
- c1 = block[i1]; c2 = block[i2];
- if (c1 != c2) return (c1 > c2);
- i1++; i2++;
- /* 9 */
- c1 = block[i1]; c2 = block[i2];
- if (c1 != c2) return (c1 > c2);
- i1++; i2++;
- /* 10 */
- c1 = block[i1]; c2 = block[i2];
- if (c1 != c2) return (c1 > c2);
- i1++; i2++;
- /* 11 */
- c1 = block[i1]; c2 = block[i2];
- if (c1 != c2) return (c1 > c2);
- i1++; i2++;
- /* 12 */
- c1 = block[i1]; c2 = block[i2];
- if (c1 != c2) return (c1 > c2);
- i1++; i2++;
-
- k = nblock + 8;
-
- do {
- /* 1 */
- c1 = block[i1]; c2 = block[i2];
- if (c1 != c2) return (c1 > c2);
- s1 = quadrant[i1]; s2 = quadrant[i2];
- if (s1 != s2) return (s1 > s2);
- i1++; i2++;
- /* 2 */
- c1 = block[i1]; c2 = block[i2];
- if (c1 != c2) return (c1 > c2);
- s1 = quadrant[i1]; s2 = quadrant[i2];
- if (s1 != s2) return (s1 > s2);
- i1++; i2++;
- /* 3 */
- c1 = block[i1]; c2 = block[i2];
- if (c1 != c2) return (c1 > c2);
- s1 = quadrant[i1]; s2 = quadrant[i2];
- if (s1 != s2) return (s1 > s2);
- i1++; i2++;
- /* 4 */
- c1 = block[i1]; c2 = block[i2];
- if (c1 != c2) return (c1 > c2);
- s1 = quadrant[i1]; s2 = quadrant[i2];
- if (s1 != s2) return (s1 > s2);
- i1++; i2++;
- /* 5 */
- c1 = block[i1]; c2 = block[i2];
- if (c1 != c2) return (c1 > c2);
- s1 = quadrant[i1]; s2 = quadrant[i2];
- if (s1 != s2) return (s1 > s2);
- i1++; i2++;
- /* 6 */
- c1 = block[i1]; c2 = block[i2];
- if (c1 != c2) return (c1 > c2);
- s1 = quadrant[i1]; s2 = quadrant[i2];
- if (s1 != s2) return (s1 > s2);
- i1++; i2++;
- /* 7 */
- c1 = block[i1]; c2 = block[i2];
- if (c1 != c2) return (c1 > c2);
- s1 = quadrant[i1]; s2 = quadrant[i2];
- if (s1 != s2) return (s1 > s2);
- i1++; i2++;
- /* 8 */
- c1 = block[i1]; c2 = block[i2];
- if (c1 != c2) return (c1 > c2);
- s1 = quadrant[i1]; s2 = quadrant[i2];
- if (s1 != s2) return (s1 > s2);
- i1++; i2++;
-
- if (i1 >= nblock) i1 -= nblock;
- if (i2 >= nblock) i2 -= nblock;
-
- k -= 8;
- (*budget)--;
- }
- while (k >= 0);
-
- return False;
-}
-
-
-/*---------------------------------------------*/
-/*--
- Knuth's increments seem to work better
- than Incerpi-Sedgewick here. Possibly
- because the number of elems to sort is
- usually small, typically <= 20.
---*/
-static
-Int32 incs[14] = { 1, 4, 13, 40, 121, 364, 1093, 3280,
- 9841, 29524, 88573, 265720,
- 797161, 2391484 };
-
-static
-void mainSimpleSort ( UInt32* ptr,
- UChar* block,
- UInt16* quadrant,
- Int32 nblock,
- Int32 lo,
- Int32 hi,
- Int32 d,
- Int32* budget )
-{
- Int32 i, j, h, bigN, hp;
- UInt32 v;
-
- bigN = hi - lo + 1;
- if (bigN < 2) return;
-
- hp = 0;
- while (incs[hp] < bigN) hp++;
- hp--;
-
- for (; hp >= 0; hp--) {
- h = incs[hp];
-
- i = lo + h;
- while (True) {
-
- /*-- copy 1 --*/
- if (i > hi) break;
- v = ptr[i];
- j = i;
- while ( mainGtU (
- ptr[j-h]+d, v+d, block, quadrant, nblock, budget
- ) ) {
- ptr[j] = ptr[j-h];
- j = j - h;
- if (j <= (lo + h - 1)) break;
- }
- ptr[j] = v;
- i++;
-
- /*-- copy 2 --*/
- if (i > hi) break;
- v = ptr[i];
- j = i;
- while ( mainGtU (
- ptr[j-h]+d, v+d, block, quadrant, nblock, budget
- ) ) {
- ptr[j] = ptr[j-h];
- j = j - h;
- if (j <= (lo + h - 1)) break;
- }
- ptr[j] = v;
- i++;
-
- /*-- copy 3 --*/
- if (i > hi) break;
- v = ptr[i];
- j = i;
- while ( mainGtU (
- ptr[j-h]+d, v+d, block, quadrant, nblock, budget
- ) ) {
- ptr[j] = ptr[j-h];
- j = j - h;
- if (j <= (lo + h - 1)) break;
- }
- ptr[j] = v;
- i++;
-
- if (*budget < 0) return;
- }
- }
-}
-
-
-/*---------------------------------------------*/
-/*--
- The following is an implementation of
- an elegant 3-way quicksort for strings,
- described in a paper "Fast Algorithms for
- Sorting and Searching Strings", by Robert
- Sedgewick and Jon L. Bentley.
---*/
-
-#define mswap(zz1, zz2) \
- { Int32 zztmp = zz1; zz1 = zz2; zz2 = zztmp; }
-
-#define mvswap(zzp1, zzp2, zzn) \
-{ \
- Int32 yyp1 = (zzp1); \
- Int32 yyp2 = (zzp2); \
- Int32 yyn = (zzn); \
- while (yyn > 0) { \
- mswap(ptr[yyp1], ptr[yyp2]); \
- yyp1++; yyp2++; yyn--; \
- } \
-}
-
-static
-__inline__
-UChar mmed3 ( UChar a, UChar b, UChar c )
-{
- UChar t;
- if (a > b) { t = a; a = b; b = t; };
- if (b > c) {
- b = c;
- if (a > b) b = a;
- }
- return b;
-}
-
-#define mmin(a,b) ((a) < (b)) ? (a) : (b)
-
-#define mpush(lz,hz,dz) { stackLo[sp] = lz; \
- stackHi[sp] = hz; \
- stackD [sp] = dz; \
- sp++; }
-
-#define mpop(lz,hz,dz) { sp--; \
- lz = stackLo[sp]; \
- hz = stackHi[sp]; \
- dz = stackD [sp]; }
-
-
-#define mnextsize(az) (nextHi[az]-nextLo[az])
-
-#define mnextswap(az,bz) \
- { Int32 tz; \
- tz = nextLo[az]; nextLo[az] = nextLo[bz]; nextLo[bz] = tz; \
- tz = nextHi[az]; nextHi[az] = nextHi[bz]; nextHi[bz] = tz; \
- tz = nextD [az]; nextD [az] = nextD [bz]; nextD [bz] = tz; }
-
-
-#define MAIN_QSORT_SMALL_THRESH 20
-#define MAIN_QSORT_DEPTH_THRESH (BZ_N_RADIX + BZ_N_QSORT)
-#define MAIN_QSORT_STACK_SIZE 100
-
-static
-void mainQSort3 ( UInt32* ptr,
- UChar* block,
- UInt16* quadrant,
- Int32 nblock,
- Int32 loSt,
- Int32 hiSt,
- Int32 dSt,
- Int32* budget )
-{
- Int32 unLo, unHi, ltLo, gtHi, n, m, med;
- Int32 sp, lo, hi, d;
-
- Int32 stackLo[MAIN_QSORT_STACK_SIZE];
- Int32 stackHi[MAIN_QSORT_STACK_SIZE];
- Int32 stackD [MAIN_QSORT_STACK_SIZE];
-
- Int32 nextLo[3];
- Int32 nextHi[3];
- Int32 nextD [3];
-
- sp = 0;
- mpush ( loSt, hiSt, dSt );
-
- while (sp > 0) {
-
- AssertH ( sp < MAIN_QSORT_STACK_SIZE - 2, 1001 );
-
- mpop ( lo, hi, d );
- if (hi - lo < MAIN_QSORT_SMALL_THRESH ||
- d > MAIN_QSORT_DEPTH_THRESH) {
- mainSimpleSort ( ptr, block, quadrant, nblock, lo, hi, d, budget );
- if (*budget < 0) return;
- continue;
- }
-
- med = (Int32)
- mmed3 ( block[ptr[ lo ]+d],
- block[ptr[ hi ]+d],
- block[ptr[ (lo+hi)>>1 ]+d] );
-
- unLo = ltLo = lo;
- unHi = gtHi = hi;
-
- while (True) {
- while (True) {
- if (unLo > unHi) break;
- n = ((Int32)block[ptr[unLo]+d]) - med;
- if (n == 0) {
- mswap(ptr[unLo], ptr[ltLo]);
- ltLo++; unLo++; continue;
- };
- if (n > 0) break;
- unLo++;
- }
- while (True) {
- if (unLo > unHi) break;
- n = ((Int32)block[ptr[unHi]+d]) - med;
- if (n == 0) {
- mswap(ptr[unHi], ptr[gtHi]);
- gtHi--; unHi--; continue;
- };
- if (n < 0) break;
- unHi--;
- }
- if (unLo > unHi) break;
- mswap(ptr[unLo], ptr[unHi]); unLo++; unHi--;
- }
-
- AssertD ( unHi == unLo-1, "mainQSort3(2)" );
-
- if (gtHi < ltLo) {
- mpush(lo, hi, d+1 );
- continue;
- }
-
- n = mmin(ltLo-lo, unLo-ltLo); mvswap(lo, unLo-n, n);
- m = mmin(hi-gtHi, gtHi-unHi); mvswap(unLo, hi-m+1, m);
-
- n = lo + unLo - ltLo - 1;
- m = hi - (gtHi - unHi) + 1;
-
- nextLo[0] = lo; nextHi[0] = n; nextD[0] = d;
- nextLo[1] = m; nextHi[1] = hi; nextD[1] = d;
- nextLo[2] = n+1; nextHi[2] = m-1; nextD[2] = d+1;
-
- if (mnextsize(0) < mnextsize(1)) mnextswap(0,1);
- if (mnextsize(1) < mnextsize(2)) mnextswap(1,2);
- if (mnextsize(0) < mnextsize(1)) mnextswap(0,1);
-
- AssertD (mnextsize(0) >= mnextsize(1), "mainQSort3(8)" );
- AssertD (mnextsize(1) >= mnextsize(2), "mainQSort3(9)" );
-
- mpush (nextLo[0], nextHi[0], nextD[0]);
- mpush (nextLo[1], nextHi[1], nextD[1]);
- mpush (nextLo[2], nextHi[2], nextD[2]);
- }
-}
-
-#undef mswap
-#undef mvswap
-#undef mpush
-#undef mpop
-#undef mmin
-#undef mnextsize
-#undef mnextswap
-#undef MAIN_QSORT_SMALL_THRESH
-#undef MAIN_QSORT_DEPTH_THRESH
-#undef MAIN_QSORT_STACK_SIZE
-
-
-/*---------------------------------------------*/
-/* Pre:
- nblock > N_OVERSHOOT
- block32 exists for [0 .. nblock-1 +N_OVERSHOOT]
- ((UChar*)block32) [0 .. nblock-1] holds block
- ptr exists for [0 .. nblock-1]
-
- Post:
- ((UChar*)block32) [0 .. nblock-1] holds block
- All other areas of block32 destroyed
- ftab [0 .. 65536 ] destroyed
- ptr [0 .. nblock-1] holds sorted order
- if (*budget < 0), sorting was abandoned
-*/
-
-#define BIGFREQ(b) (ftab[((b)+1) << 8] - ftab[(b) << 8])
-#define SETMASK (1 << 21)
-#define CLEARMASK (~(SETMASK))
-
-static
-void mainSort ( UInt32* ptr,
- UChar* block,
- UInt16* quadrant,
- UInt32* ftab,
- Int32 nblock,
- Int32 verb,
- Int32* budget )
-{
- Int32 i, j, k, ss, sb;
- Int32 runningOrder[256];
- Bool bigDone[256];
- Int32 copyStart[256];
- Int32 copyEnd [256];
- UChar c1;
- Int32 numQSorted;
- UInt16 s;
- if (verb >= 4) VPrintf0 ( " main sort initialise ...\n" );
-
- /*-- set up the 2-byte frequency table --*/
- for (i = 65536; i >= 0; i--) ftab[i] = 0;
-
- j = block[0] << 8;
- i = nblock-1;
- for (; i >= 3; i -= 4) {
- quadrant[i] = 0;
- j = (j >> 8) | ( ((UInt16)block[i]) << 8);
- ftab[j]++;
- quadrant[i-1] = 0;
- j = (j >> 8) | ( ((UInt16)block[i-1]) << 8);
- ftab[j]++;
- quadrant[i-2] = 0;
- j = (j >> 8) | ( ((UInt16)block[i-2]) << 8);
- ftab[j]++;
- quadrant[i-3] = 0;
- j = (j >> 8) | ( ((UInt16)block[i-3]) << 8);
- ftab[j]++;
- }
- for (; i >= 0; i--) {
- quadrant[i] = 0;
- j = (j >> 8) | ( ((UInt16)block[i]) << 8);
- ftab[j]++;
- }
-
- /*-- (emphasises close relationship of block & quadrant) --*/
- for (i = 0; i < BZ_N_OVERSHOOT; i++) {
- block [nblock+i] = block[i];
- quadrant[nblock+i] = 0;
- }
-
- if (verb >= 4) VPrintf0 ( " bucket sorting ...\n" );
-
- /*-- Complete the initial radix sort --*/
- for (i = 1; i <= 65536; i++) ftab[i] += ftab[i-1];
-
- s = block[0] << 8;
- i = nblock-1;
- for (; i >= 3; i -= 4) {
- s = (s >> 8) | (block[i] << 8);
- j = ftab[s] -1;
- ftab[s] = j;
- ptr[j] = i;
- s = (s >> 8) | (block[i-1] << 8);
- j = ftab[s] -1;
- ftab[s] = j;
- ptr[j] = i-1;
- s = (s >> 8) | (block[i-2] << 8);
- j = ftab[s] -1;
- ftab[s] = j;
- ptr[j] = i-2;
- s = (s >> 8) | (block[i-3] << 8);
- j = ftab[s] -1;
- ftab[s] = j;
- ptr[j] = i-3;
- }
- for (; i >= 0; i--) {
- s = (s >> 8) | (block[i] << 8);
- j = ftab[s] -1;
- ftab[s] = j;
- ptr[j] = i;
- }
-
- /*--
- Now ftab contains the first loc of every small bucket.
- Calculate the running order, from smallest to largest
- big bucket.
- --*/
- for (i = 0; i <= 255; i++) {
- bigDone [i] = False;
- runningOrder[i] = i;
- }
-
- {
- Int32 vv;
- Int32 h = 1;
- do h = 3 * h + 1; while (h <= 256);
- do {
- h = h / 3;
- for (i = h; i <= 255; i++) {
- vv = runningOrder[i];
- j = i;
- while ( BIGFREQ(runningOrder[j-h]) > BIGFREQ(vv) ) {
- runningOrder[j] = runningOrder[j-h];
- j = j - h;
- if (j <= (h - 1)) goto zero;
- }
- zero:
- runningOrder[j] = vv;
- }
- } while (h != 1);
- }
-
- /*--
- The main sorting loop.
- --*/
-
- numQSorted = 0;
-
- for (i = 0; i <= 255; i++) {
-
- /*--
- Process big buckets, starting with the least full.
- Basically this is a 3-step process in which we call
- mainQSort3 to sort the small buckets [ss, j], but
- also make a big effort to avoid the calls if we can.
- --*/
- ss = runningOrder[i];
-
- /*--
- Step 1:
- Complete the big bucket [ss] by quicksorting
- any unsorted small buckets [ss, j], for j != ss.
- Hopefully previous pointer-scanning phases have already
- completed many of the small buckets [ss, j], so
- we don't have to sort them at all.
- --*/
- for (j = 0; j <= 255; j++) {
- if (j != ss) {
- sb = (ss << 8) + j;
- if ( ! (ftab[sb] & SETMASK) ) {
- Int32 lo = ftab[sb] & CLEARMASK;
- Int32 hi = (ftab[sb+1] & CLEARMASK) - 1;
- if (hi > lo) {
- if (verb >= 4)
- VPrintf4 ( " qsort [0x%x, 0x%x] "
- "done %d this %d\n",
- ss, j, numQSorted, hi - lo + 1 );
- mainQSort3 (
- ptr, block, quadrant, nblock,
- lo, hi, BZ_N_RADIX, budget
- );
- numQSorted += (hi - lo + 1);
- if (*budget < 0) return;
- }
- }
- ftab[sb] |= SETMASK;
- }
- }
-
- AssertH ( !bigDone[ss], 1006 );
-
- /*--
- Step 2:
- Now scan this big bucket [ss] so as to synthesise the
- sorted order for small buckets [t, ss] for all t,
- including, magically, the bucket [ss,ss] too.
- This will avoid doing Real Work in subsequent Step 1's.
- --*/
- {
- for (j = 0; j <= 255; j++) {
- copyStart[j] = ftab[(j << 8) + ss] & CLEARMASK;
- copyEnd [j] = (ftab[(j << 8) + ss + 1] & CLEARMASK) - 1;
- }
- for (j = ftab[ss << 8] & CLEARMASK; j < copyStart[ss]; j++) {
- k = ptr[j]-1; if (k < 0) k += nblock;
- c1 = block[k];
- if (!bigDone[c1])
- ptr[ copyStart[c1]++ ] = k;
- }
- for (j = (ftab[(ss+1) << 8] & CLEARMASK) - 1; j > copyEnd[ss]; j--)
{
- k = ptr[j]-1; if (k < 0) k += nblock;
- c1 = block[k];
- if (!bigDone[c1])
- ptr[ copyEnd[c1]-- ] = k;
- }
- }
-
- AssertH ( (copyStart[ss]-1 == copyEnd[ss])
- ||
- /* Extremely rare case missing in bzip2-1.0.0 and 1.0.1.
- Necessity for this case is demonstrated by compressing
- a sequence of approximately 48.5 million of character
- 251; 1.0.0/1.0.1 will then die here. */
- (copyStart[ss] == 0 && copyEnd[ss] == nblock-1),
- 1007 )
-
- for (j = 0; j <= 255; j++) ftab[(j << 8) + ss] |= SETMASK;
-
- /*--
- Step 3:
- The [ss] big bucket is now done. Record this fact,
- and update the quadrant descriptors. Remember to
- update quadrants in the overshoot area too, if
- necessary. The "if (i < 255)" test merely skips
- this updating for the last bucket processed, since
- updating for the last bucket is pointless.
-
- The quadrant array provides a way to incrementally
- cache sort orderings, as they appear, so as to
- make subsequent comparisons in fullGtU() complete
- faster. For repetitive blocks this makes a big
- difference (but not big enough to be able to avoid
- the fallback sorting mechanism, exponential radix sort).
-
- The precise meaning is: at all times:
-
- for 0 <= i < nblock and 0 <= j <= nblock
-
- if block[i] != block[j],
-
- then the relative values of quadrant[i] and
- quadrant[j] are meaningless.
-
- else {
- if quadrant[i] < quadrant[j]
- then the string starting at i lexicographically
- precedes the string starting at j
-
- else if quadrant[i] > quadrant[j]
- then the string starting at j lexicographically
- precedes the string starting at i
-
- else
- the relative ordering of the strings starting
- at i and j has not yet been determined.
- }
- --*/
- bigDone[ss] = True;
-
- if (i < 255) {
- Int32 bbStart = ftab[ss << 8] & CLEARMASK;
- Int32 bbSize = (ftab[(ss+1) << 8] & CLEARMASK) - bbStart;
- Int32 shifts = 0;
-
- while ((bbSize >> shifts) > 65534) shifts++;
-
- for (j = bbSize-1; j >= 0; j--) {
- Int32 a2update = ptr[bbStart + j];
- UInt16 qVal = (UInt16)(j >> shifts);
- quadrant[a2update] = qVal;
- if (a2update < BZ_N_OVERSHOOT)
- quadrant[a2update + nblock] = qVal;
- }
- AssertH ( ((bbSize-1) >> shifts) <= 65535, 1002 );
- }
-
- }
-
- if (verb >= 4)
- VPrintf3 ( " %d pointers, %d sorted, %d scanned\n",
- nblock, numQSorted, nblock - numQSorted );
-}
-
-#undef BIGFREQ
-#undef SETMASK
-#undef CLEARMASK
-
-
-/*---------------------------------------------*/
-/* Pre:
- nblock > 0
- arr2 exists for [0 .. nblock-1 +N_OVERSHOOT]
- ((UChar*)arr2) [0 .. nblock-1] holds block
- arr1 exists for [0 .. nblock-1]
-
- Post:
- ((UChar*)arr2) [0 .. nblock-1] holds block
- All other areas of block destroyed
- ftab [ 0 .. 65536 ] destroyed
- arr1 [0 .. nblock-1] holds sorted order
-*/
-void BZ2_blockSort ( EState* s )
-{
- UInt32* ptr = s->ptr;
- UChar* block = s->block;
- UInt32* ftab = s->ftab;
- Int32 nblock = s->nblock;
- Int32 verb = s->verbosity;
- Int32 wfact = s->workFactor;
- UInt16* quadrant;
- Int32 budget;
- Int32 budgetInit;
- Int32 i;
-
- if (nblock < 10000) {
- fallbackSort ( s->arr1, s->arr2, ftab, nblock, verb );
- } else {
- /* Calculate the location for quadrant, remembering to get
- the alignment right. Assumes that &(block[0]) is at least
- 2-byte aligned -- this should be ok since block is really
- the first section of arr2.
- */
- i = nblock+BZ_N_OVERSHOOT;
- if (i & 1) i++;
- quadrant = (UInt16*)(&(block[i]));
-
- /* (wfact-1) / 3 puts the default-factor-30
- transition point at very roughly the same place as
- with v0.1 and v0.9.0.
- Not that it particularly matters any more, since the
- resulting compressed stream is now the same regardless
- of whether or not we use the main sort or fallback sort.
- */
- if (wfact < 1 ) wfact = 1;
- if (wfact > 100) wfact = 100;
- budgetInit = nblock * ((wfact-1) / 3);
- budget = budgetInit;
-
- mainSort ( ptr, block, quadrant, ftab, nblock, verb, &budget );
- if (verb >= 3)
- VPrintf3 ( " %d work, %d block, ratio %5.2f\n",
- budgetInit - budget,
- nblock,
- (float)(budgetInit - budget) /
- (float)(nblock==0 ? 1 : nblock) );
- if (budget < 0) {
- if (verb >= 2)
- VPrintf0 ( " too repetitive; using fallback"
- " sorting algorithm\n" );
- fallbackSort ( s->arr1, s->arr2, ftab, nblock, verb );
- }
- }
-
- s->origPtr = -1;
- for (i = 0; i < s->nblock; i++)
- if (ptr[i] == 0)
- { s->origPtr = i; break; };
-
- AssertH( s->origPtr != -1, 1003 );
-}
-
-
-/*-------------------------------------------------------------*/
-/*--- end blocksort.c ---*/
-/*-------------------------------------------------------------*/
diff --git a/sdk/lib/3rdparty/bzip2/bzip2.c b/sdk/lib/3rdparty/bzip2/bzip2.c
deleted file mode 100644
index 6de9d1d1488..00000000000
--- a/sdk/lib/3rdparty/bzip2/bzip2.c
+++ /dev/null
@@ -1,2034 +0,0 @@
-
-/*-----------------------------------------------------------*/
-/*--- A block-sorting, lossless compressor bzip2.c ---*/
-/*-----------------------------------------------------------*/
-
-/* ------------------------------------------------------------------
- This file is part of bzip2/libbzip2, a program and library for
- lossless, block-sorting data compression.
-
- bzip2/libbzip2 version 1.0.6 of 6 September 2010
- Copyright (C) 1996-2010 Julian Seward <jseward(a)bzip.org>
-
- Please read the WARNING, DISCLAIMER and PATENTS sections in the
- README file.
-
- This program is released under the terms of the license contained
- in the file LICENSE.
- ------------------------------------------------------------------ */
-
-
-/* Place a 1 beside your platform, and 0 elsewhere.
- Generic 32-bit Unix.
- Also works on 64-bit Unix boxes.
- This is the default.
-*/
-#define BZ_UNIX 1
-
-/*--
- Win32, as seen by Jacob Navia's excellent
- port of (Chris Fraser & David Hanson)'s excellent
- lcc compiler. Or with MS Visual C.
- This is selected automatically if compiled by a compiler which
- defines _WIN32, not including the Cygwin GCC.
---*/
-#define BZ_LCCWIN32 0
-
-#if defined(_WIN32) && !defined(__CYGWIN__)
-#undef BZ_LCCWIN32
-#define BZ_LCCWIN32 1
-#undef BZ_UNIX
-#define BZ_UNIX 0
-#endif
-
-
-/*---------------------------------------------*/
-/*--
- Some stuff for all platforms.
---*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <signal.h>
-#include <math.h>
-#include <errno.h>
-#include <ctype.h>
-#include "bzlib.h"
-
-#define ERROR_IF_EOF(i) { if ((i) == EOF) ioError(); }
-#define ERROR_IF_NOT_ZERO(i) { if ((i) != 0) ioError(); }
-#define ERROR_IF_MINUS_ONE(i) { if ((i) == (-1)) ioError(); }
-
-
-/*---------------------------------------------*/
-/*--
- Platform-specific stuff.
---*/
-
-#if BZ_UNIX
-# include <fcntl.h>
-# include <sys/types.h>
-# include <utime.h>
-# include <unistd.h>
-# include <sys/stat.h>
-# include <sys/times.h>
-
-# define PATH_SEP '/'
-# define MY_LSTAT lstat
-# define MY_STAT stat
-# define MY_S_ISREG S_ISREG
-# define MY_S_ISDIR S_ISDIR
-
-# define APPEND_FILESPEC(root, name) \
- root=snocString((root), (name))
-
-# define APPEND_FLAG(root, name) \
- root=snocString((root), (name))
-
-# define SET_BINARY_MODE(fd) /**/
-
-# ifdef __GNUC__
-# define NORETURN __attribute__ ((noreturn))
-# else
-# define NORETURN /**/
-# endif
-
-# ifdef __DJGPP__
-# include <io.h>
-# include <fcntl.h>
-# undef MY_LSTAT
-# undef MY_STAT
-# define MY_LSTAT stat
-# define MY_STAT stat
-# undef SET_BINARY_MODE
-# define SET_BINARY_MODE(fd) \
- do { \
- int retVal = setmode ( fileno ( fd ), \
- O_BINARY ); \
- ERROR_IF_MINUS_ONE ( retVal ); \
- } while ( 0 )
-# endif
-
-# ifdef __CYGWIN__
-# include <io.h>
-# include <fcntl.h>
-# undef SET_BINARY_MODE
-# define SET_BINARY_MODE(fd) \
- do { \
- int retVal = setmode ( fileno ( fd ), \
- O_BINARY ); \
- ERROR_IF_MINUS_ONE ( retVal ); \
- } while ( 0 )
-# endif
-#endif /* BZ_UNIX */
-
-
-
-#if BZ_LCCWIN32
-# include <io.h>
-# include <fcntl.h>
-# include <sys\stat.h>
-
-# define NORETURN /**/
-# define PATH_SEP '\\'
-# define MY_LSTAT _stat
-# define MY_STAT _stat
-# define MY_S_ISREG(x) ((x) & _S_IFREG)
-# define MY_S_ISDIR(x) ((x) & _S_IFDIR)
-
-# define APPEND_FLAG(root, name) \
- root=snocString((root), (name))
-
-# define APPEND_FILESPEC(root, name) \
- root = snocString ((root), (name))
-
-# define SET_BINARY_MODE(fd) \
- do { \
- int retVal = setmode ( fileno ( fd ), \
- O_BINARY ); \
- ERROR_IF_MINUS_ONE ( retVal ); \
- } while ( 0 )
-
-#endif /* BZ_LCCWIN32 */
-
-
-/*---------------------------------------------*/
-/*--
- Some more stuff for all platforms :-)
---*/
-
-typedef char Char;
-typedef unsigned char Bool;
-typedef unsigned char UChar;
-typedef int Int32;
-typedef unsigned int UInt32;
-typedef short Int16;
-typedef unsigned short UInt16;
-
-#define True ((Bool)1)
-#define False ((Bool)0)
-
-/*--
- IntNative is your platform's `native' int size.
- Only here to avoid probs with 64-bit platforms.
---*/
-typedef int IntNative;
-
-
-/*---------------------------------------------------*/
-/*--- Misc (file handling) data decls ---*/
-/*---------------------------------------------------*/
-
-Int32 verbosity;
-Bool keepInputFiles, smallMode, deleteOutputOnInterrupt;
-Bool forceOverwrite, testFailsExist, unzFailsExist, noisy;
-Int32 numFileNames, numFilesProcessed, blockSize100k;
-Int32 exitValue;
-
-/*-- source modes; F==file, I==stdin, O==stdout --*/
-#define SM_I2O 1
-#define SM_F2O 2
-#define SM_F2F 3
-
-/*-- operation modes --*/
-#define OM_Z 1
-#define OM_UNZ 2
-#define OM_TEST 3
-
-Int32 opMode;
-Int32 srcMode;
-
-#define FILE_NAME_LEN 1034
-
-Int32 longestFileName;
-Char inName [FILE_NAME_LEN];
-Char outName[FILE_NAME_LEN];
-Char tmpName[FILE_NAME_LEN];
-Char *progName;
-Char progNameReally[FILE_NAME_LEN];
-FILE *outputHandleJustInCase;
-Int32 workFactor;
-
-static void panic ( const Char* ) NORETURN;
-static void ioError ( void ) NORETURN;
-static void outOfMemory ( void ) NORETURN;
-static void configError ( void ) NORETURN;
-static void crcError ( void ) NORETURN;
-static void cleanUpAndFail ( Int32 ) NORETURN;
-static void compressedStreamEOF ( void ) NORETURN;
-
-static void copyFileName ( Char*, Char* );
-static void* myMalloc ( Int32 );
-static void applySavedFileAttrToOutputFile ( IntNative fd );
-
-
-
-/*---------------------------------------------------*/
-/*--- An implementation of 64-bit ints. Sigh. ---*/
-/*--- Roll on widespread deployment of ANSI C9X ! ---*/
-/*---------------------------------------------------*/
-
-typedef
- struct { UChar b[8]; }
- UInt64;
-
-
-static
-void uInt64_from_UInt32s ( UInt64* n, UInt32 lo32, UInt32 hi32 )
-{
- n->b[7] = (UChar)((hi32 >> 24) & 0xFF);
- n->b[6] = (UChar)((hi32 >> 16) & 0xFF);
- n->b[5] = (UChar)((hi32 >> 8) & 0xFF);
- n->b[4] = (UChar) (hi32 & 0xFF);
- n->b[3] = (UChar)((lo32 >> 24) & 0xFF);
- n->b[2] = (UChar)((lo32 >> 16) & 0xFF);
- n->b[1] = (UChar)((lo32 >> 8) & 0xFF);
- n->b[0] = (UChar) (lo32 & 0xFF);
-}
-
-
-static
-double uInt64_to_double ( UInt64* n )
-{
- Int32 i;
- double base = 1.0;
- double sum = 0.0;
- for (i = 0; i < 8; i++) {
- sum += base * (double)(n->b[i]);
- base *= 256.0;
- }
- return sum;
-}
-
-
-static
-Bool uInt64_isZero ( UInt64* n )
-{
- Int32 i;
- for (i = 0; i < 8; i++)
- if (n->b[i] != 0) return 0;
- return 1;
-}
-
-
-/* Divide *n by 10, and return the remainder. */
-static
-Int32 uInt64_qrm10 ( UInt64* n )
-{
- UInt32 rem, tmp;
- Int32 i;
- rem = 0;
- for (i = 7; i >= 0; i--) {
- tmp = rem * 256 + n->b[i];
- n->b[i] = tmp / 10;
- rem = tmp % 10;
- }
- return rem;
-}
-
-
-/* ... and the Whole Entire Point of all this UInt64 stuff is
- so that we can supply the following function.
-*/
-static
-void uInt64_toAscii ( char* outbuf, UInt64* n )
-{
- Int32 i, q;
- UChar buf[32];
- Int32 nBuf = 0;
- UInt64 n_copy = *n;
- do {
- q = uInt64_qrm10 ( &n_copy );
- buf[nBuf] = q + '0';
- nBuf++;
- } while (!uInt64_isZero(&n_copy));
- outbuf[nBuf] = 0;
- for (i = 0; i < nBuf; i++)
- outbuf[i] = buf[nBuf-i-1];
-}
-
-
-/*---------------------------------------------------*/
-/*--- Processing of complete files and streams ---*/
-/*---------------------------------------------------*/
-
-/*---------------------------------------------*/
-static
-Bool myfeof ( FILE* f )
-{
- Int32 c = fgetc ( f );
- if (c == EOF) return True;
- ungetc ( c, f );
- return False;
-}
-
-
-/*---------------------------------------------*/
-static
-void compressStream ( FILE *stream, FILE *zStream )
-{
- BZFILE* bzf = NULL;
- UChar ibuf[5000];
- Int32 nIbuf;
- UInt32 nbytes_in_lo32, nbytes_in_hi32;
- UInt32 nbytes_out_lo32, nbytes_out_hi32;
- Int32 bzerr, bzerr_dummy, ret;
-
- SET_BINARY_MODE(stream);
- SET_BINARY_MODE(zStream);
-
- if (ferror(stream)) goto errhandler_io;
- if (ferror(zStream)) goto errhandler_io;
-
- bzf = BZ2_bzWriteOpen ( &bzerr, zStream,
- blockSize100k, verbosity, workFactor );
- if (bzerr != BZ_OK) goto errhandler;
-
- if (verbosity >= 2) fprintf ( stderr, "\n" );
-
- while (True) {
-
- if (myfeof(stream)) break;
- nIbuf = fread ( ibuf, sizeof(UChar), 5000, stream );
- if (ferror(stream)) goto errhandler_io;
- if (nIbuf > 0) BZ2_bzWrite ( &bzerr, bzf, (void*)ibuf, nIbuf );
- if (bzerr != BZ_OK) goto errhandler;
-
- }
-
- BZ2_bzWriteClose64 ( &bzerr, bzf, 0,
- &nbytes_in_lo32, &nbytes_in_hi32,
- &nbytes_out_lo32, &nbytes_out_hi32 );
- if (bzerr != BZ_OK) goto errhandler;
-
- if (ferror(zStream)) goto errhandler_io;
- ret = fflush ( zStream );
- if (ret == EOF) goto errhandler_io;
- if (zStream != stdout) {
- Int32 fd = fileno ( zStream );
- if (fd < 0) goto errhandler_io;
- applySavedFileAttrToOutputFile ( fd );
- ret = fclose ( zStream );
- outputHandleJustInCase = NULL;
- if (ret == EOF) goto errhandler_io;
- }
- outputHandleJustInCase = NULL;
- if (ferror(stream)) goto errhandler_io;
- ret = fclose ( stream );
- if (ret == EOF) goto errhandler_io;
-
- if (verbosity >= 1) {
- if (nbytes_in_lo32 == 0 && nbytes_in_hi32 == 0) {
- fprintf ( stderr, " no data compressed.\n");
- } else {
- Char buf_nin[32], buf_nout[32];
- UInt64 nbytes_in, nbytes_out;
- double nbytes_in_d, nbytes_out_d;
- uInt64_from_UInt32s ( &nbytes_in,
- nbytes_in_lo32, nbytes_in_hi32 );
- uInt64_from_UInt32s ( &nbytes_out,
- nbytes_out_lo32, nbytes_out_hi32 );
- nbytes_in_d = uInt64_to_double ( &nbytes_in );
- nbytes_out_d = uInt64_to_double ( &nbytes_out );
- uInt64_toAscii ( buf_nin, &nbytes_in );
- uInt64_toAscii ( buf_nout, &nbytes_out );
- fprintf ( stderr, "%6.3f:1, %6.3f bits/byte, "
- "%5.2f%% saved, %s in, %s out.\n",
- nbytes_in_d / nbytes_out_d,
- (8.0 * nbytes_out_d) / nbytes_in_d,
- 100.0 * (1.0 - nbytes_out_d / nbytes_in_d),
- buf_nin,
- buf_nout
- );
- }
- }
-
- return;
-
- errhandler:
- BZ2_bzWriteClose64 ( &bzerr_dummy, bzf, 1,
- &nbytes_in_lo32, &nbytes_in_hi32,
- &nbytes_out_lo32, &nbytes_out_hi32 );
- switch (bzerr) {
- case BZ_CONFIG_ERROR:
- configError(); break;
- case BZ_MEM_ERROR:
- outOfMemory (); break;
- case BZ_IO_ERROR:
- errhandler_io:
- ioError(); break;
- default:
- panic ( "compress:unexpected error" );
- }
-
- panic ( "compress:end" );
- /*notreached*/
-}
-
-
-
-/*---------------------------------------------*/
-static
-Bool uncompressStream ( FILE *zStream, FILE *stream )
-{
- BZFILE* bzf = NULL;
- Int32 bzerr, bzerr_dummy, ret, nread, streamNo, i;
- UChar obuf[5000];
- UChar unused[BZ_MAX_UNUSED];
- Int32 nUnused;
- void* unusedTmpV;
- UChar* unusedTmp;
-
- nUnused = 0;
- streamNo = 0;
-
- SET_BINARY_MODE(stream);
- SET_BINARY_MODE(zStream);
-
- if (ferror(stream)) goto errhandler_io;
- if (ferror(zStream)) goto errhandler_io;
-
- while (True) {
-
- bzf = BZ2_bzReadOpen (
- &bzerr, zStream, verbosity,
- (int)smallMode, unused, nUnused
- );
- if (bzf == NULL || bzerr != BZ_OK) goto errhandler;
- streamNo++;
-
- while (bzerr == BZ_OK) {
- nread = BZ2_bzRead ( &bzerr, bzf, obuf, 5000 );
- if (bzerr == BZ_DATA_ERROR_MAGIC) goto trycat;
- if ((bzerr == BZ_OK || bzerr == BZ_STREAM_END) && nread > 0)
- fwrite ( obuf, sizeof(UChar), nread, stream );
- if (ferror(stream)) goto errhandler_io;
- }
- if (bzerr != BZ_STREAM_END) goto errhandler;
-
- BZ2_bzReadGetUnused ( &bzerr, bzf, &unusedTmpV, &nUnused );
- if (bzerr != BZ_OK) panic ( "decompress:bzReadGetUnused" );
-
- unusedTmp = (UChar*)unusedTmpV;
- for (i = 0; i < nUnused; i++) unused[i] = unusedTmp[i];
-
- BZ2_bzReadClose ( &bzerr, bzf );
- if (bzerr != BZ_OK) panic ( "decompress:bzReadGetUnused" );
-
- if (nUnused == 0 && myfeof(zStream)) break;
- }
-
- closeok:
- if (ferror(zStream)) goto errhandler_io;
- if (stream != stdout) {
- Int32 fd = fileno ( stream );
- if (fd < 0) goto errhandler_io;
- applySavedFileAttrToOutputFile ( fd );
- }
- ret = fclose ( zStream );
- if (ret == EOF) goto errhandler_io;
-
- if (ferror(stream)) goto errhandler_io;
- ret = fflush ( stream );
- if (ret != 0) goto errhandler_io;
- if (stream != stdout) {
- ret = fclose ( stream );
- outputHandleJustInCase = NULL;
- if (ret == EOF) goto errhandler_io;
- }
- outputHandleJustInCase = NULL;
- if (verbosity >= 2) fprintf ( stderr, "\n " );
- return True;
-
- trycat:
- if (forceOverwrite) {
- rewind(zStream);
- while (True) {
- if (myfeof(zStream)) break;
- nread = fread ( obuf, sizeof(UChar), 5000, zStream );
- if (ferror(zStream)) goto errhandler_io;
- if (nread > 0) fwrite ( obuf, sizeof(UChar), nread, stream );
- if (ferror(stream)) goto errhandler_io;
- }
- goto closeok;
- }
-
- errhandler:
- BZ2_bzReadClose ( &bzerr_dummy, bzf );
- switch (bzerr) {
- case BZ_CONFIG_ERROR:
- configError(); break;
- case BZ_IO_ERROR:
- errhandler_io:
- ioError(); break;
- case BZ_DATA_ERROR:
- crcError();
- case BZ_MEM_ERROR:
- outOfMemory();
- case BZ_UNEXPECTED_EOF:
- compressedStreamEOF();
- case BZ_DATA_ERROR_MAGIC:
- if (zStream != stdin) fclose(zStream);
- if (stream != stdout) fclose(stream);
- if (streamNo == 1) {
- return False;
- } else {
- if (noisy)
- fprintf ( stderr,
- "\n%s: %s: trailing garbage after EOF ignored\n",
- progName, inName );
- return True;
- }
- default:
- panic ( "decompress:unexpected error" );
- }
-
- panic ( "decompress:end" );
- return True; /*notreached*/
-}
-
-
-/*---------------------------------------------*/
-static
-Bool testStream ( FILE *zStream )
-{
- BZFILE* bzf = NULL;
- Int32 bzerr, bzerr_dummy, ret, nread, streamNo, i;
- UChar obuf[5000];
- UChar unused[BZ_MAX_UNUSED];
- Int32 nUnused;
- void* unusedTmpV;
- UChar* unusedTmp;
-
- nUnused = 0;
- streamNo = 0;
-
- SET_BINARY_MODE(zStream);
- if (ferror(zStream)) goto errhandler_io;
-
- while (True) {
-
- bzf = BZ2_bzReadOpen (
- &bzerr, zStream, verbosity,
- (int)smallMode, unused, nUnused
- );
- if (bzf == NULL || bzerr != BZ_OK) goto errhandler;
- streamNo++;
-
- while (bzerr == BZ_OK) {
- nread = BZ2_bzRead ( &bzerr, bzf, obuf, 5000 );
- if (bzerr == BZ_DATA_ERROR_MAGIC) goto errhandler;
- }
- if (bzerr != BZ_STREAM_END) goto errhandler;
-
- BZ2_bzReadGetUnused ( &bzerr, bzf, &unusedTmpV, &nUnused );
- if (bzerr != BZ_OK) panic ( "test:bzReadGetUnused" );
-
- unusedTmp = (UChar*)unusedTmpV;
- for (i = 0; i < nUnused; i++) unused[i] = unusedTmp[i];
-
- BZ2_bzReadClose ( &bzerr, bzf );
- if (bzerr != BZ_OK) panic ( "test:bzReadGetUnused" );
- if (nUnused == 0 && myfeof(zStream)) break;
-
- }
-
- if (ferror(zStream)) goto errhandler_io;
- ret = fclose ( zStream );
- if (ret == EOF) goto errhandler_io;
-
- if (verbosity >= 2) fprintf ( stderr, "\n " );
- return True;
-
- errhandler:
- BZ2_bzReadClose ( &bzerr_dummy, bzf );
- if (verbosity == 0)
- fprintf ( stderr, "%s: %s: ", progName, inName );
- switch (bzerr) {
- case BZ_CONFIG_ERROR:
- configError(); break;
- case BZ_IO_ERROR:
- errhandler_io:
- ioError(); break;
- case BZ_DATA_ERROR:
- fprintf ( stderr,
- "data integrity (CRC) error in data\n" );
- return False;
- case BZ_MEM_ERROR:
- outOfMemory();
- case BZ_UNEXPECTED_EOF:
- fprintf ( stderr,
- "file ends unexpectedly\n" );
- return False;
- case BZ_DATA_ERROR_MAGIC:
- if (zStream != stdin) fclose(zStream);
- if (streamNo == 1) {
- fprintf ( stderr,
- "bad magic number (file not created by bzip2)\n" );
- return False;
- } else {
- if (noisy)
- fprintf ( stderr,
- "trailing garbage after EOF ignored\n" );
- return True;
- }
- default:
- panic ( "test:unexpected error" );
- }
-
- panic ( "test:end" );
- return True; /*notreached*/
-}
-
-
-/*---------------------------------------------------*/
-/*--- Error [non-] handling grunge ---*/
-/*---------------------------------------------------*/
-
-/*---------------------------------------------*/
-static
-void setExit ( Int32 v )
-{
- if (v > exitValue) exitValue = v;
-}
-
-
-/*---------------------------------------------*/
-static
-void cadvise ( void )
-{
- if (noisy)
- fprintf (
- stderr,
- "\nIt is possible that the compressed file(s) have become corrupted.\n"
- "You can use the -tvv option to test integrity of such files.\n\n"
- "You can use the `bzip2recover' program to attempt to recover\n"
- "data from undamaged sections of corrupted files.\n\n"
- );
-}
-
-
-/*---------------------------------------------*/
-static
-void showFileNames ( void )
-{
- if (noisy)
- fprintf (
- stderr,
- "\tInput file = %s, output file = %s\n",
- inName, outName
- );
-}
-
-
-/*---------------------------------------------*/
-static
-void cleanUpAndFail ( Int32 ec )
-{
- IntNative retVal;
- struct MY_STAT statBuf;
-
- if ( srcMode == SM_F2F
- && opMode != OM_TEST
- && deleteOutputOnInterrupt ) {
-
- /* Check whether input file still exists. Delete output file
- only if input exists to avoid loss of data. Joerg Prante, 5
- January 2002. (JRS 06-Jan-2002: other changes in 1.0.2 mean
- this is less likely to happen. But to be ultra-paranoid, we
- do the check anyway.) */
- retVal = MY_STAT ( inName, &statBuf );
- if (retVal == 0) {
- if (noisy)
- fprintf ( stderr,
- "%s: Deleting output file %s, if it exists.\n",
- progName, outName );
- if (outputHandleJustInCase != NULL)
- fclose ( outputHandleJustInCase );
- retVal = remove ( outName );
- if (retVal != 0)
- fprintf ( stderr,
- "%s: WARNING: deletion of output file "
- "(apparently) failed.\n",
- progName );
- } else {
- fprintf ( stderr,
- "%s: WARNING: deletion of output file suppressed\n",
- progName );
- fprintf ( stderr,
- "%s: since input file no longer exists. Output file\n",
- progName );
- fprintf ( stderr,
- "%s: `%s' may be incomplete.\n",
- progName, outName );
- fprintf ( stderr,
- "%s: I suggest doing an integrity test (bzip2 -tv)"
- " of it.\n",
- progName );
- }
- }
-
- if (noisy && numFileNames > 0 && numFilesProcessed <
numFileNames) {
- fprintf ( stderr,
- "%s: WARNING: some files have not been processed:\n"
- "%s: %d specified on command line, %d not processed
yet.\n\n",
- progName, progName,
- numFileNames, numFileNames - numFilesProcessed );
- }
- setExit(ec);
- exit(exitValue);
-}
-
-
-/*---------------------------------------------*/
-static
-void panic ( const Char* s )
-{
- fprintf ( stderr,
- "\n%s: PANIC -- internal consistency error:\n"
- "\t%s\n"
- "\tThis is a BUG. Please report it to me at:\n"
- "\tjseward(a)bzip.org\n"rg\n",
- progName, s );
- showFileNames();
- cleanUpAndFail( 3 );
-}
-
-
-/*---------------------------------------------*/
-static
-void crcError ( void )
-{
- fprintf ( stderr,
- "\n%s: Data integrity error when decompressing.\n",
- progName );
- showFileNames();
- cadvise();
- cleanUpAndFail( 2 );
-}
-
-
-/*---------------------------------------------*/
-static
-void compressedStreamEOF ( void )
-{
- if (noisy) {
- fprintf ( stderr,
- "\n%s: Compressed file ends unexpectedly;\n\t"
- "perhaps it is corrupted? *Possible* reason follows.\n",
- progName );
- perror ( progName );
- showFileNames();
- cadvise();
- }
- cleanUpAndFail( 2 );
-}
-
-
-/*---------------------------------------------*/
-static
-void ioError ( void )
-{
- fprintf ( stderr,
- "\n%s: I/O or other error, bailing out. "
- "Possible reason follows.\n",
- progName );
- perror ( progName );
- showFileNames();
- cleanUpAndFail( 1 );
-}
-
-
-/*---------------------------------------------*/
-static
-void mySignalCatcher ( IntNative n )
-{
- fprintf ( stderr,
- "\n%s: Control-C or similar caught, quitting.\n",
- progName );
- cleanUpAndFail(1);
-}
-
-
-/*---------------------------------------------*/
-static
-void mySIGSEGVorSIGBUScatcher ( IntNative n )
-{
- if (opMode == OM_Z)
- fprintf (
- stderr,
- "\n%s: Caught a SIGSEGV or SIGBUS whilst compressing.\n"
- "\n"
- " Possible causes are (most likely first):\n"
- " (1) This computer has unreliable memory or cache hardware\n"
- " (a surprisingly common problem; try a different machine.)\n"
- " (2) A bug in the compiler used to create this executable\n"
- " (unlikely, if you didn't compile bzip2 yourself.)\n"
- " (3) A real bug in bzip2 -- I hope this should never be the case.\n"
- " The user's manual, Section 4.3, has more info on (1) and (2).\n"
- " \n"
- " If you suspect this is a bug in bzip2, or are unsure about (1)\n"
- " or (2), feel free to report it to me at: jseward(a)bzip.org.\n"
- " Section 4.3 of the user's manual describes the info a useful\n"
- " bug report should have. If the manual is available on your\n"
- " system, please try and read it before mailing me. If you
don't\n"
- " have the manual or can't be bothered to read it, mail me
anyway.\n"
- "\n",
- progName );
- else
- fprintf (
- stderr,
- "\n%s: Caught a SIGSEGV or SIGBUS whilst decompressing.\n"
- "\n"
- " Possible causes are (most likely first):\n"
- " (1) The compressed data is corrupted, and bzip2's usual
checks\n"
- " failed to detect this. Try bzip2 -tvv my_file.bz2.\n"
- " (2) This computer has unreliable memory or cache hardware\n"
- " (a surprisingly common problem; try a different machine.)\n"
- " (3) A bug in the compiler used to create this executable\n"
- " (unlikely, if you didn't compile bzip2 yourself.)\n"
- " (4) A real bug in bzip2 -- I hope this should never be the case.\n"
- " The user's manual, Section 4.3, has more info on (2) and (3).\n"
- " \n"
- " If you suspect this is a bug in bzip2, or are unsure about (2)\n"
- " or (3), feel free to report it to me at: jseward(a)bzip.org.\n"
- " Section 4.3 of the user's manual describes the info a useful\n"
- " bug report should have. If the manual is available on your\n"
- " system, please try and read it before mailing me. If you
don't\n"
- " have the manual or can't be bothered to read it, mail me
anyway.\n"
- "\n",
- progName );
-
- showFileNames();
- if (opMode == OM_Z)
- cleanUpAndFail( 3 ); else
- { cadvise(); cleanUpAndFail( 2 ); }
-}
-
-
-/*---------------------------------------------*/
-static
-void outOfMemory ( void )
-{
- fprintf ( stderr,
- "\n%s: couldn't allocate enough memory\n",
- progName );
- showFileNames();
- cleanUpAndFail(1);
-}
-
-
-/*---------------------------------------------*/
-static
-void configError ( void )
-{
- fprintf ( stderr,
- "bzip2: I'm not configured correctly for this platform!\n"
- "\tI require Int32, Int16 and Char to have sizes\n"
- "\tof 4, 2 and 1 bytes to run properly, and they don't.\n"
- "\tProbably you can fix this by defining them correctly,\n"
- "\tand recompiling. Bye!\n" );
- setExit(3);
- exit(exitValue);
-}
-
-
-/*---------------------------------------------------*/
-/*--- The main driver machinery ---*/
-/*---------------------------------------------------*/
-
-/* All rather crufty. The main problem is that input files
- are stat()d multiple times before use. This should be
- cleaned up.
-*/
-
-/*---------------------------------------------*/
-static
-void pad ( Char *s )
-{
- Int32 i;
- if ( (Int32)strlen(s) >= longestFileName ) return;
- for (i = 1; i <= longestFileName - (Int32)strlen(s); i++)
- fprintf ( stderr, " " );
-}
-
-
-/*---------------------------------------------*/
-static
-void copyFileName ( Char* to, Char* from )
-{
- if ( strlen(from) > FILE_NAME_LEN-10 ) {
- fprintf (
- stderr,
- "bzip2: file name\n`%s'\n"
- "is suspiciously (more than %d chars) long.\n"
- "Try using a reasonable file name instead. Sorry! :-)\n",
- from, FILE_NAME_LEN-10
- );
- setExit(1);
- exit(exitValue);
- }
-
- strncpy(to,from,FILE_NAME_LEN-10);
- to[FILE_NAME_LEN-10]='\0';
-}
-
-
-/*---------------------------------------------*/
-static
-Bool fileExists ( Char* name )
-{
- FILE *tmp = fopen ( name, "rb" );
- Bool exists = (tmp != NULL);
- if (tmp != NULL) fclose ( tmp );
- return exists;
-}
-
-
-/*---------------------------------------------*/
-/* Open an output file safely with O_EXCL and good permissions.
- This avoids a race condition in versions < 1.0.2, in which
- the file was first opened and then had its interim permissions
- set safely. We instead use open() to create the file with
- the interim permissions required. (--- --- rw-).
-
- For non-Unix platforms, if we are not worrying about
- security issues, simple this simply behaves like fopen.
-*/
-static
-FILE* fopen_output_safely ( Char* name, const char* mode )
-{
-# if BZ_UNIX
- FILE* fp;
- IntNative fh;
- fh = open(name, O_WRONLY|O_CREAT|O_EXCL, S_IWUSR|S_IRUSR);
- if (fh == -1) return NULL;
- fp = fdopen(fh, mode);
- if (fp == NULL) close(fh);
- return fp;
-# else
- return fopen(name, mode);
-# endif
-}
-
-
-/*---------------------------------------------*/
-/*--
- if in doubt, return True
---*/
-static
-Bool notAStandardFile ( Char* name )
-{
- IntNative i;
- struct MY_STAT statBuf;
-
- i = MY_LSTAT ( name, &statBuf );
- if (i != 0) return True;
- if (MY_S_ISREG(statBuf.st_mode)) return False;
- return True;
-}
-
-
-/*---------------------------------------------*/
-/*--
- rac 11/21/98 see if file has hard links to it
---*/
-static
-Int32 countHardLinks ( Char* name )
-{
- IntNative i;
- struct MY_STAT statBuf;
-
- i = MY_LSTAT ( name, &statBuf );
- if (i != 0) return 0;
- return (statBuf.st_nlink - 1);
-}
-
-
-/*---------------------------------------------*/
-/* Copy modification date, access date, permissions and owner from the
- source to destination file. We have to copy this meta-info off
- into fileMetaInfo before starting to compress / decompress it,
- because doing it afterwards means we get the wrong access time.
-
- To complicate matters, in compress() and decompress() below, the
- sequence of tests preceding the call to saveInputFileMetaInfo()
- involves calling fileExists(), which in turn establishes its result
- by attempting to fopen() the file, and if successful, immediately
- fclose()ing it again. So we have to assume that the fopen() call
- does not cause the access time field to be updated.
-
- Reading of the man page for stat() (man 2 stat) on RedHat 7.2 seems
- to imply that merely doing open() will not affect the access time.
- Therefore we merely need to hope that the C library only does
- open() as a result of fopen(), and not any kind of read()-ahead
- cleverness.
-
- It sounds pretty fragile to me. Whether this carries across
- robustly to arbitrary Unix-like platforms (or even works robustly
- on this one, RedHat 7.2) is unknown to me. Nevertheless ...
-*/
-#if BZ_UNIX
-static
-struct MY_STAT fileMetaInfo;
-#endif
-
-static
-void saveInputFileMetaInfo ( Char *srcName )
-{
-# if BZ_UNIX
- IntNative retVal;
- /* Note use of stat here, not lstat. */
- retVal = MY_STAT( srcName, &fileMetaInfo );
- ERROR_IF_NOT_ZERO ( retVal );
-# endif
-}
-
-
-static
-void applySavedTimeInfoToOutputFile ( Char *dstName )
-{
-# if BZ_UNIX
- IntNative retVal;
- struct utimbuf uTimBuf;
-
- uTimBuf.actime = fileMetaInfo.st_atime;
- uTimBuf.modtime = fileMetaInfo.st_mtime;
-
- retVal = utime ( dstName, &uTimBuf );
- ERROR_IF_NOT_ZERO ( retVal );
-# endif
-}
-
-static
-void applySavedFileAttrToOutputFile ( IntNative fd )
-{
-# if BZ_UNIX
- IntNative retVal;
-
- retVal = fchmod ( fd, fileMetaInfo.st_mode );
- ERROR_IF_NOT_ZERO ( retVal );
-
- (void) fchown ( fd, fileMetaInfo.st_uid, fileMetaInfo.st_gid );
- /* chown() will in many cases return with EPERM, which can
- be safely ignored.
- */
-# endif
-}
-
-
-/*---------------------------------------------*/
-static
-Bool containsDubiousChars ( Char* name )
-{
-# if BZ_UNIX
- /* On unix, files can contain any characters and the file expansion
- * is performed by the shell.
- */
- return False;
-# else /* ! BZ_UNIX */
- /* On non-unix (Win* platforms), wildcard characters are not allowed in
- * filenames.
- */
- for (; *name != '\0'; name++)
- if (*name == '?' || *name == '*') return True;
- return False;
-# endif /* BZ_UNIX */
-}
-
-
-/*---------------------------------------------*/
-#define BZ_N_SUFFIX_PAIRS 4
-
-const Char* zSuffix[BZ_N_SUFFIX_PAIRS]
- = { ".bz2", ".bz", ".tbz2", ".tbz" };
-const Char* unzSuffix[BZ_N_SUFFIX_PAIRS]
- = { "", "", ".tar", ".tar" };
-
-static
-Bool hasSuffix ( Char* s, const Char* suffix )
-{
- Int32 ns = strlen(s);
- Int32 nx = strlen(suffix);
- if (ns < nx) return False;
- if (strcmp(s + ns - nx, suffix) == 0) return True;
- return False;
-}
-
-static
-Bool mapSuffix ( Char* name,
- const Char* oldSuffix,
- const Char* newSuffix )
-{
- if (!hasSuffix(name,oldSuffix)) return False;
- name[strlen(name)-strlen(oldSuffix)] = 0;
- strcat ( name, newSuffix );
- return True;
-}
-
-
-/*---------------------------------------------*/
-static
-void compress ( Char *name )
-{
- FILE *inStr;
- FILE *outStr;
- Int32 n, i;
- struct MY_STAT statBuf;
-
- deleteOutputOnInterrupt = False;
-
- if (name == NULL && srcMode != SM_I2O)
- panic ( "compress: bad modes\n" );
-
- switch (srcMode) {
- case SM_I2O:
- copyFileName ( inName, (Char*)"(stdin)" );
- copyFileName ( outName, (Char*)"(stdout)" );
- break;
- case SM_F2F:
- copyFileName ( inName, name );
- copyFileName ( outName, name );
- strcat ( outName, ".bz2" );
- break;
- case SM_F2O:
- copyFileName ( inName, name );
- copyFileName ( outName, (Char*)"(stdout)" );
- break;
- }
-
- if ( srcMode != SM_I2O && containsDubiousChars ( inName ) ) {
- if (noisy)
- fprintf ( stderr, "%s: There are no files matching `%s'.\n",
- progName, inName );
- setExit(1);
- return;
- }
- if ( srcMode != SM_I2O && !fileExists ( inName ) ) {
- fprintf ( stderr, "%s: Can't open input file %s: %s.\n",
- progName, inName, strerror(errno) );
- setExit(1);
- return;
- }
- for (i = 0; i < BZ_N_SUFFIX_PAIRS; i++) {
- if (hasSuffix(inName, zSuffix[i])) {
- if (noisy)
- fprintf ( stderr,
- "%s: Input file %s already has %s suffix.\n",
- progName, inName, zSuffix[i] );
- setExit(1);
- return;
- }
- }
- if ( srcMode == SM_F2F || srcMode == SM_F2O ) {
- MY_STAT(inName, &statBuf);
- if ( MY_S_ISDIR(statBuf.st_mode) ) {
- fprintf( stderr,
- "%s: Input file %s is a directory.\n",
- progName,inName);
- setExit(1);
- return;
- }
- }
- if ( srcMode == SM_F2F && !forceOverwrite && notAStandardFile ( inName
)) {
- if (noisy)
- fprintf ( stderr, "%s: Input file %s is not a normal file.\n",
- progName, inName );
- setExit(1);
- return;
- }
- if ( srcMode == SM_F2F && fileExists ( outName ) ) {
- if (forceOverwrite) {
- remove(outName);
- } else {
- fprintf ( stderr, "%s: Output file %s already exists.\n",
- progName, outName );
- setExit(1);
- return;
- }
- }
- if ( srcMode == SM_F2F && !forceOverwrite &&
- (n=countHardLinks ( inName )) > 0) {
- fprintf ( stderr, "%s: Input file %s has %d other link%s.\n",
- progName, inName, n, n > 1 ? "s" : "" );
- setExit(1);
- return;
- }
-
- if ( srcMode == SM_F2F ) {
- /* Save the file's meta-info before we open it. Doing it later
- means we mess up the access times. */
- saveInputFileMetaInfo ( inName );
- }
-
- switch ( srcMode ) {
-
- case SM_I2O:
- inStr = stdin;
- outStr = stdout;
- if ( isatty ( fileno ( stdout ) ) ) {
- fprintf ( stderr,
- "%s: I won't write compressed data to a
terminal.\n",
- progName );
- fprintf ( stderr, "%s: For help, type: `%s --help'.\n",
- progName, progName );
- setExit(1);
- return;
- };
- break;
-
- case SM_F2O:
- inStr = fopen ( inName, "rb" );
- outStr = stdout;
- if ( isatty ( fileno ( stdout ) ) ) {
- fprintf ( stderr,
- "%s: I won't write compressed data to a
terminal.\n",
- progName );
- fprintf ( stderr, "%s: For help, type: `%s --help'.\n",
- progName, progName );
- if ( inStr != NULL ) fclose ( inStr );
- setExit(1);
- return;
- };
- if ( inStr == NULL ) {
- fprintf ( stderr, "%s: Can't open input file %s: %s.\n",
- progName, inName, strerror(errno) );
- setExit(1);
- return;
- };
- break;
-
- case SM_F2F:
- inStr = fopen ( inName, "rb" );
- outStr = fopen_output_safely ( outName, "wb" );
- if ( outStr == NULL) {
- fprintf ( stderr, "%s: Can't create output file %s: %s.\n",
- progName, outName, strerror(errno) );
- if ( inStr != NULL ) fclose ( inStr );
- setExit(1);
- return;
- }
- if ( inStr == NULL ) {
- fprintf ( stderr, "%s: Can't open input file %s: %s.\n",
- progName, inName, strerror(errno) );
- if ( outStr != NULL ) fclose ( outStr );
- setExit(1);
- return;
- };
- break;
-
- default:
- panic ( "compress: bad srcMode" );
- break;
- }
-
- if (verbosity >= 1) {
- fprintf ( stderr, " %s: ", inName );
- pad ( inName );
- fflush ( stderr );
- }
-
- /*--- Now the input and output handles are sane. Do the Biz. ---*/
- outputHandleJustInCase = outStr;
- deleteOutputOnInterrupt = True;
- compressStream ( inStr, outStr );
- outputHandleJustInCase = NULL;
-
- /*--- If there was an I/O error, we won't get here. ---*/
- if ( srcMode == SM_F2F ) {
- applySavedTimeInfoToOutputFile ( outName );
- deleteOutputOnInterrupt = False;
- if ( !keepInputFiles ) {
- IntNative retVal = remove ( inName );
- ERROR_IF_NOT_ZERO ( retVal );
- }
- }
-
- deleteOutputOnInterrupt = False;
-}
-
-
-/*---------------------------------------------*/
-static
-void uncompress ( Char *name )
-{
- FILE *inStr;
- FILE *outStr;
- Int32 n, i;
- Bool magicNumberOK;
- Bool cantGuess;
- struct MY_STAT statBuf;
-
- deleteOutputOnInterrupt = False;
-
- if (name == NULL && srcMode != SM_I2O)
- panic ( "uncompress: bad modes\n" );
-
- cantGuess = False;
- switch (srcMode) {
- case SM_I2O:
- copyFileName ( inName, (Char*)"(stdin)" );
- copyFileName ( outName, (Char*)"(stdout)" );
- break;
- case SM_F2F:
- copyFileName ( inName, name );
- copyFileName ( outName, name );
- for (i = 0; i < BZ_N_SUFFIX_PAIRS; i++)
- if (mapSuffix(outName,zSuffix[i],unzSuffix[i]))
- goto zzz;
- cantGuess = True;
- strcat ( outName, ".out" );
- break;
- case SM_F2O:
- copyFileName ( inName, name );
- copyFileName ( outName, (Char*)"(stdout)" );
- break;
- }
-
- zzz:
- if ( srcMode != SM_I2O && containsDubiousChars ( inName ) ) {
- if (noisy)
- fprintf ( stderr, "%s: There are no files matching `%s'.\n",
- progName, inName );
- setExit(1);
- return;
- }
- if ( srcMode != SM_I2O && !fileExists ( inName ) ) {
- fprintf ( stderr, "%s: Can't open input file %s: %s.\n",
- progName, inName, strerror(errno) );
- setExit(1);
- return;
- }
- if ( srcMode == SM_F2F || srcMode == SM_F2O ) {
- MY_STAT(inName, &statBuf);
- if ( MY_S_ISDIR(statBuf.st_mode) ) {
- fprintf( stderr,
- "%s: Input file %s is a directory.\n",
- progName,inName);
- setExit(1);
- return;
- }
- }
- if ( srcMode == SM_F2F && !forceOverwrite && notAStandardFile ( inName
)) {
- if (noisy)
- fprintf ( stderr, "%s: Input file %s is not a normal file.\n",
- progName, inName );
- setExit(1);
- return;
- }
- if ( /* srcMode == SM_F2F implied && */ cantGuess ) {
- if (noisy)
- fprintf ( stderr,
- "%s: Can't guess original name for %s -- using %s\n",
- progName, inName, outName );
- /* just a warning, no return */
- }
- if ( srcMode == SM_F2F && fileExists ( outName ) ) {
- if (forceOverwrite) {
- remove(outName);
- } else {
- fprintf ( stderr, "%s: Output file %s already exists.\n",
- progName, outName );
- setExit(1);
- return;
- }
- }
- if ( srcMode == SM_F2F && !forceOverwrite &&
- (n=countHardLinks ( inName ) ) > 0) {
- fprintf ( stderr, "%s: Input file %s has %d other link%s.\n",
- progName, inName, n, n > 1 ? "s" : "" );
- setExit(1);
- return;
- }
-
- if ( srcMode == SM_F2F ) {
- /* Save the file's meta-info before we open it. Doing it later
- means we mess up the access times. */
- saveInputFileMetaInfo ( inName );
- }
-
- switch ( srcMode ) {
-
- case SM_I2O:
- inStr = stdin;
- outStr = stdout;
- if ( isatty ( fileno ( stdin ) ) ) {
- fprintf ( stderr,
- "%s: I won't read compressed data from a
terminal.\n",
- progName );
- fprintf ( stderr, "%s: For help, type: `%s --help'.\n",
- progName, progName );
- setExit(1);
- return;
- };
- break;
-
- case SM_F2O:
- inStr = fopen ( inName, "rb" );
- outStr = stdout;
- if ( inStr == NULL ) {
- fprintf ( stderr, "%s: Can't open input file %s:%s.\n",
- progName, inName, strerror(errno) );
- if ( inStr != NULL ) fclose ( inStr );
- setExit(1);
- return;
- };
- break;
-
- case SM_F2F:
- inStr = fopen ( inName, "rb" );
- outStr = fopen_output_safely ( outName, "wb" );
- if ( outStr == NULL) {
- fprintf ( stderr, "%s: Can't create output file %s: %s.\n",
- progName, outName, strerror(errno) );
- if ( inStr != NULL ) fclose ( inStr );
- setExit(1);
- return;
- }
- if ( inStr == NULL ) {
- fprintf ( stderr, "%s: Can't open input file %s: %s.\n",
- progName, inName, strerror(errno) );
- if ( outStr != NULL ) fclose ( outStr );
- setExit(1);
- return;
- };
- break;
-
- default:
- panic ( "uncompress: bad srcMode" );
- break;
- }
-
- if (verbosity >= 1) {
- fprintf ( stderr, " %s: ", inName );
- pad ( inName );
- fflush ( stderr );
- }
-
- /*--- Now the input and output handles are sane. Do the Biz. ---*/
- outputHandleJustInCase = outStr;
- deleteOutputOnInterrupt = True;
- magicNumberOK = uncompressStream ( inStr, outStr );
- outputHandleJustInCase = NULL;
-
- /*--- If there was an I/O error, we won't get here. ---*/
- if ( magicNumberOK ) {
- if ( srcMode == SM_F2F ) {
- applySavedTimeInfoToOutputFile ( outName );
- deleteOutputOnInterrupt = False;
- if ( !keepInputFiles ) {
- IntNative retVal = remove ( inName );
- ERROR_IF_NOT_ZERO ( retVal );
- }
- }
- } else {
- unzFailsExist = True;
- deleteOutputOnInterrupt = False;
- if ( srcMode == SM_F2F ) {
- IntNative retVal = remove ( outName );
- ERROR_IF_NOT_ZERO ( retVal );
- }
- }
- deleteOutputOnInterrupt = False;
-
- if ( magicNumberOK ) {
- if (verbosity >= 1)
- fprintf ( stderr, "done\n" );
- } else {
- setExit(2);
- if (verbosity >= 1)
- fprintf ( stderr, "not a bzip2 file.\n" ); else
- fprintf ( stderr,
- "%s: %s is not a bzip2 file.\n",
- progName, inName );
- }
-
-}
-
-
-/*---------------------------------------------*/
-static
-void testf ( Char *name )
-{
- FILE *inStr;
- Bool allOK;
- struct MY_STAT statBuf;
-
- deleteOutputOnInterrupt = False;
-
- if (name == NULL && srcMode != SM_I2O)
- panic ( "testf: bad modes\n" );
-
- copyFileName ( outName, (Char*)"(none)" );
- switch (srcMode) {
- case SM_I2O: copyFileName ( inName, (Char*)"(stdin)" ); break;
- case SM_F2F: copyFileName ( inName, name ); break;
- case SM_F2O: copyFileName ( inName, name ); break;
- }
-
- if ( srcMode != SM_I2O && containsDubiousChars ( inName ) ) {
- if (noisy)
- fprintf ( stderr, "%s: There are no files matching `%s'.\n",
- progName, inName );
- setExit(1);
- return;
- }
- if ( srcMode != SM_I2O && !fileExists ( inName ) ) {
- fprintf ( stderr, "%s: Can't open input %s: %s.\n",
- progName, inName, strerror(errno) );
- setExit(1);
- return;
- }
- if ( srcMode != SM_I2O ) {
- MY_STAT(inName, &statBuf);
- if ( MY_S_ISDIR(statBuf.st_mode) ) {
- fprintf( stderr,
- "%s: Input file %s is a directory.\n",
- progName,inName);
- setExit(1);
- return;
- }
- }
-
- switch ( srcMode ) {
-
- case SM_I2O:
- if ( isatty ( fileno ( stdin ) ) ) {
- fprintf ( stderr,
- "%s: I won't read compressed data from a
terminal.\n",
- progName );
- fprintf ( stderr, "%s: For help, type: `%s --help'.\n",
- progName, progName );
- setExit(1);
- return;
- };
- inStr = stdin;
- break;
-
- case SM_F2O: case SM_F2F:
- inStr = fopen ( inName, "rb" );
- if ( inStr == NULL ) {
- fprintf ( stderr, "%s: Can't open input file %s:%s.\n",
- progName, inName, strerror(errno) );
- setExit(1);
- return;
- };
- break;
-
- default:
- panic ( "testf: bad srcMode" );
- break;
- }
-
- if (verbosity >= 1) {
- fprintf ( stderr, " %s: ", inName );
- pad ( inName );
- fflush ( stderr );
- }
-
- /*--- Now the input handle is sane. Do the Biz. ---*/
- outputHandleJustInCase = NULL;
- allOK = testStream ( inStr );
-
- if (allOK && verbosity >= 1) fprintf ( stderr, "ok\n" );
- if (!allOK) testFailsExist = True;
-}
-
-
-/*---------------------------------------------*/
-static
-void license ( void )
-{
- fprintf ( stderr,
-
- "bzip2, a block-sorting file compressor. "
- "Version %s.\n"
- " \n"
- " Copyright (C) 1996-2010 by Julian Seward.\n"
- " \n"
- " This program is free software; you can redistribute it and/or
modify\n"
- " it under the terms set out in the LICENSE file, which is included\n"
- " in the bzip2-1.0.6 source distribution.\n"
- " \n"
- " This program is distributed in the hope that it will be useful,\n"
- " but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
- " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
- " LICENSE file for more details.\n"
- " \n",
- BZ2_bzlibVersion()
- );
-}
-
-
-/*---------------------------------------------*/
-static
-void usage ( Char *fullProgName )
-{
- fprintf (
- stderr,
- "bzip2, a block-sorting file compressor. "
- "Version %s.\n"
- "\n usage: %s [flags and input files in any order]\n"
- "\n"
- " -h --help print this message\n"
- " -d --decompress force decompression\n"
- " -z --compress force compression\n"
- " -k --keep keep (don't delete) input files\n"
- " -f --force overwrite existing output files\n"
- " -t --test test compressed file integrity\n"
- " -c --stdout output to standard out\n"
- " -q --quiet suppress noncritical error messages\n"
- " -v --verbose be verbose (a 2nd -v gives more)\n"
- " -L --license display software version & license\n"
- " -V --version display software version & license\n"
- " -s --small use less memory (at most 2500k)\n"
- " -1 .. -9 set block size to 100k .. 900k\n"
- " --fast alias for -1\n"
- " --best alias for -9\n"
- "\n"
- " If invoked as `bzip2', default action is to compress.\n"
- " as `bunzip2', default action is to decompress.\n"
- " as `bzcat', default action is to decompress to
stdout.\n"
- "\n"
- " If no file names are given, bzip2 compresses or decompresses\n"
- " from standard input to standard output. You can combine\n"
- " short flags, so `-v -4' means the same as -v4 or -4v, &c.\n"
-# if BZ_UNIX
- "\n"
-# endif
- ,
-
- BZ2_bzlibVersion(),
- fullProgName
- );
-}
-
-
-/*---------------------------------------------*/
-static
-void redundant ( Char* flag )
-{
- fprintf (
- stderr,
- "%s: %s is redundant in versions 0.9.5 and above\n",
- progName, flag );
-}
-
-
-/*---------------------------------------------*/
-/*--
- All the garbage from here to main() is purely to
- implement a linked list of command-line arguments,
- into which main() copies argv[1 .. argc-1].
-
- The purpose of this exercise is to facilitate
- the expansion of wildcard characters * and ? in
- filenames for OSs which don't know how to do it
- themselves, like MSDOS, Windows 95 and NT.
-
- The actual Dirty Work is done by the platform-
- specific macro APPEND_FILESPEC.
---*/
-
-typedef
- struct zzzz {
- Char *name;
- struct zzzz *link;
- }
- Cell;
-
-
-/*---------------------------------------------*/
-static
-void *myMalloc ( Int32 n )
-{
- void* p;
-
- p = malloc ( (size_t)n );
- if (p == NULL) outOfMemory ();
- return p;
-}
-
-
-/*---------------------------------------------*/
-static
-Cell *mkCell ( void )
-{
- Cell *c;
-
- c = (Cell*) myMalloc ( sizeof ( Cell ) );
- c->name = NULL;
- c->link = NULL;
- return c;
-}
-
-
-/*---------------------------------------------*/
-static
-Cell *snocString ( Cell *root, Char *name )
-{
- if (root == NULL) {
- Cell *tmp = mkCell();
- tmp->name = (Char*) myMalloc ( 5 + strlen(name) );
- strcpy ( tmp->name, name );
- return tmp;
- } else {
- Cell *tmp = root;
- while (tmp->link != NULL) tmp = tmp->link;
- tmp->link = snocString ( tmp->link, name );
- return root;
- }
-}
-
-
-/*---------------------------------------------*/
-static
-void addFlagsFromEnvVar ( Cell** argList, Char* varName )
-{
- Int32 i, j, k;
- Char *envbase, *p;
-
- envbase = getenv(varName);
- if (envbase != NULL) {
- p = envbase;
- i = 0;
- while (True) {
- if (p[i] == 0) break;
- p += i;
- i = 0;
- while (isspace((Int32)(p[0]))) p++;
- while (p[i] != 0 && !isspace((Int32)(p[i]))) i++;
- if (i > 0) {
- k = i; if (k > FILE_NAME_LEN-10) k = FILE_NAME_LEN-10;
- for (j = 0; j < k; j++) tmpName[j] = p[j];
- tmpName[k] = 0;
- APPEND_FLAG(*argList, tmpName);
- }
- }
- }
-}
-
-
-/*---------------------------------------------*/
-#define ISFLAG(s) (strcmp(aa->name, (s))==0)
-
-IntNative main ( IntNative argc, Char *argv[] )
-{
- Int32 i, j;
- Char *tmp;
- Cell *argList;
- Cell *aa;
- Bool decode;
-
- /*-- Be really really really paranoid :-) --*/
- if (sizeof(Int32) != 4 || sizeof(UInt32) != 4 ||
- sizeof(Int16) != 2 || sizeof(UInt16) != 2 ||
- sizeof(Char) != 1 || sizeof(UChar) != 1)
- configError();
-
- /*-- Initialise --*/
- outputHandleJustInCase = NULL;
- smallMode = False;
- keepInputFiles = False;
- forceOverwrite = False;
- noisy = True;
- verbosity = 0;
- blockSize100k = 9;
- testFailsExist = False;
- unzFailsExist = False;
- numFileNames = 0;
- numFilesProcessed = 0;
- workFactor = 30;
- deleteOutputOnInterrupt = False;
- exitValue = 0;
- i = j = 0; /* avoid bogus warning from egcs-1.1.X */
-
- /*-- Set up signal handlers for mem access errors --*/
- signal (SIGSEGV, mySIGSEGVorSIGBUScatcher);
-# if BZ_UNIX
-# ifndef __DJGPP__
- signal (SIGBUS, mySIGSEGVorSIGBUScatcher);
-# endif
-# endif
-
- copyFileName ( inName, (Char*)"(none)" );
- copyFileName ( outName, (Char*)"(none)" );
-
- copyFileName ( progNameReally, argv[0] );
- progName = &progNameReally[0];
- for (tmp = &progNameReally[0]; *tmp != '\0'; tmp++)
- if (*tmp == PATH_SEP) progName = tmp + 1;
-
-
- /*-- Copy flags from env var BZIP2, and
- expand filename wildcards in arg list.
- --*/
- argList = NULL;
- addFlagsFromEnvVar ( &argList, (Char*)"BZIP2" );
- addFlagsFromEnvVar ( &argList, (Char*)"BZIP" );
- for (i = 1; i <= argc-1; i++)
- APPEND_FILESPEC(argList, argv[i]);
-
-
- /*-- Find the length of the longest filename --*/
- longestFileName = 7;
- numFileNames = 0;
- decode = True;
- for (aa = argList; aa != NULL; aa = aa->link) {
- if (ISFLAG("--")) { decode = False; continue; }
- if (aa->name[0] == '-' && decode) continue;
- numFileNames++;
- if (longestFileName < (Int32)strlen(aa->name) )
- longestFileName = (Int32)strlen(aa->name);
- }
-
-
- /*-- Determine source modes; flag handling may change this too. --*/
- if (numFileNames == 0)
- srcMode = SM_I2O; else srcMode = SM_F2F;
-
-
- /*-- Determine what to do (compress/uncompress/test/cat). --*/
- /*-- Note that subsequent flag handling may change this. --*/
- opMode = OM_Z;
-
- if ( (strstr ( progName, "unzip" ) != 0) ||
- (strstr ( progName, "UNZIP" ) != 0) )
- opMode = OM_UNZ;
-
- if ( (strstr ( progName, "z2cat" ) != 0) ||
- (strstr ( progName, "Z2CAT" ) != 0) ||
- (strstr ( progName, "zcat" ) != 0) ||
- (strstr ( progName, "ZCAT" ) != 0) ) {
- opMode = OM_UNZ;
- srcMode = (numFileNames == 0) ? SM_I2O : SM_F2O;
- }
-
-
- /*-- Look at the flags. --*/
- for (aa = argList; aa != NULL; aa = aa->link) {
- if (ISFLAG("--")) break;
- if (aa->name[0] == '-' && aa->name[1] != '-') {
- for (j = 1; aa->name[j] != '\0'; j++) {
- switch (aa->name[j]) {
- case 'c': srcMode = SM_F2O; break;
- case 'd': opMode = OM_UNZ; break;
- case 'z': opMode = OM_Z; break;
- case 'f': forceOverwrite = True; break;
- case 't': opMode = OM_TEST; break;
- case 'k': keepInputFiles = True; break;
- case 's': smallMode = True; break;
- case 'q': noisy = False; break;
- case '1': blockSize100k = 1; break;
- case '2': blockSize100k = 2; break;
- case '3': blockSize100k = 3; break;
- case '4': blockSize100k = 4; break;
- case '5': blockSize100k = 5; break;
- case '6': blockSize100k = 6; break;
- case '7': blockSize100k = 7; break;
- case '8': blockSize100k = 8; break;
- case '9': blockSize100k = 9; break;
- case 'V':
- case 'L': license(); break;
- case 'v': verbosity++; break;
- case 'h': usage ( progName );
- exit ( 0 );
- break;
- default: fprintf ( stderr, "%s: Bad flag `%s'\n",
- progName, aa->name );
- usage ( progName );
- exit ( 1 );
- break;
- }
- }
- }
- }
-
- /*-- And again ... --*/
- for (aa = argList; aa != NULL; aa = aa->link) {
- if (ISFLAG("--")) break;
- if (ISFLAG("--stdout")) srcMode = SM_F2O; else
- if (ISFLAG("--decompress")) opMode = OM_UNZ; else
- if (ISFLAG("--compress")) opMode = OM_Z; else
- if (ISFLAG("--force")) forceOverwrite = True; else
- if (ISFLAG("--test")) opMode = OM_TEST; else
- if (ISFLAG("--keep")) keepInputFiles = True; else
- if (ISFLAG("--small")) smallMode = True; else
- if (ISFLAG("--quiet")) noisy = False; else
- if (ISFLAG("--version")) license(); else
- if (ISFLAG("--license")) license(); else
- if (ISFLAG("--exponential")) workFactor = 1; else
- if (ISFLAG("--repetitive-best")) redundant(aa->name); else
- if (ISFLAG("--repetitive-fast")) redundant(aa->name); else
- if (ISFLAG("--fast")) blockSize100k = 1; else
- if (ISFLAG("--best")) blockSize100k = 9; else
- if (ISFLAG("--verbose")) verbosity++; else
- if (ISFLAG("--help")) { usage ( progName ); exit ( 0 ); }
- else
- if (strncmp ( aa->name, "--", 2) == 0) {
- fprintf ( stderr, "%s: Bad flag `%s'\n", progName, aa->name
);
- usage ( progName );
- exit ( 1 );
- }
- }
-
- if (verbosity > 4) verbosity = 4;
- if (opMode == OM_Z && smallMode && blockSize100k > 2)
- blockSize100k = 2;
-
- if (opMode == OM_TEST && srcMode == SM_F2O) {
- fprintf ( stderr, "%s: -c and -t cannot be used together.\n",
- progName );
- exit ( 1 );
- }
-
- if (srcMode == SM_F2O && numFileNames == 0)
- srcMode = SM_I2O;
-
- if (opMode != OM_Z) blockSize100k = 0;
-
- if (srcMode == SM_F2F) {
- signal (SIGINT, mySignalCatcher);
- signal (SIGTERM, mySignalCatcher);
-# if BZ_UNIX
- signal (SIGHUP, mySignalCatcher);
-# endif
- }
-
- if (opMode == OM_Z) {
- if (srcMode == SM_I2O) {
- compress ( NULL );
- } else {
- decode = True;
- for (aa = argList; aa != NULL; aa = aa->link) {
- if (ISFLAG("--")) { decode = False; continue; }
- if (aa->name[0] == '-' && decode) continue;
- numFilesProcessed++;
- compress ( aa->name );
- }
- }
- }
- else
-
- if (opMode == OM_UNZ) {
- unzFailsExist = False;
- if (srcMode == SM_I2O) {
- uncompress ( NULL );
- } else {
- decode = True;
- for (aa = argList; aa != NULL; aa = aa->link) {
- if (ISFLAG("--")) { decode = False; continue; }
- if (aa->name[0] == '-' && decode) continue;
- numFilesProcessed++;
- uncompress ( aa->name );
- }
- }
- if (unzFailsExist) {
- setExit(2);
- exit(exitValue);
- }
- }
-
- else {
- testFailsExist = False;
- if (srcMode == SM_I2O) {
- testf ( NULL );
- } else {
- decode = True;
- for (aa = argList; aa != NULL; aa = aa->link) {
- if (ISFLAG("--")) { decode = False; continue; }
- if (aa->name[0] == '-' && decode) continue;
- numFilesProcessed++;
- testf ( aa->name );
- }
- }
- if (testFailsExist && noisy) {
- fprintf ( stderr,
- "\n"
- "You can use the `bzip2recover' program to attempt to
recover\n"
- "data from undamaged sections of corrupted files.\n\n"
- );
- setExit(2);
- exit(exitValue);
- }
- }
-
- /* Free the argument list memory to mollify leak detectors
- (eg) Purify, Checker. Serves no other useful purpose.
- */
- aa = argList;
- while (aa != NULL) {
- Cell* aa2 = aa->link;
- if (aa->name != NULL) free(aa->name);
- free(aa);
- aa = aa2;
- }
-
- return exitValue;
-}
-
-
-/*-----------------------------------------------------------*/
-/*--- end bzip2.c ---*/
-/*-----------------------------------------------------------*/
diff --git a/sdk/lib/3rdparty/bzip2/bzip2recover.c
b/sdk/lib/3rdparty/bzip2/bzip2recover.c
deleted file mode 100644
index f9de0496abf..00000000000
--- a/sdk/lib/3rdparty/bzip2/bzip2recover.c
+++ /dev/null
@@ -1,514 +0,0 @@
-/*-----------------------------------------------------------*/
-/*--- Block recoverer program for bzip2 ---*/
-/*--- bzip2recover.c ---*/
-/*-----------------------------------------------------------*/
-
-/* ------------------------------------------------------------------
- This file is part of bzip2/libbzip2, a program and library for
- lossless, block-sorting data compression.
-
- bzip2/libbzip2 version 1.0.6 of 6 September 2010
- Copyright (C) 1996-2010 Julian Seward <jseward(a)bzip.org>
-
- Please read the WARNING, DISCLAIMER and PATENTS sections in the
- README file.
-
- This program is released under the terms of the license contained
- in the file LICENSE.
- ------------------------------------------------------------------ */
-
-/* This program is a complete hack and should be rewritten properly.
- It isn't very complicated. */
-
-#include <stdio.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-
-
-/* This program records bit locations in the file to be recovered.
- That means that if 64-bit ints are not supported, we will not
- be able to recover .bz2 files over 512MB (2^32 bits) long.
- On GNU supported platforms, we take advantage of the 64-bit
- int support to circumvent this problem. Ditto MSVC.
-
- This change occurred in version 1.0.2; all prior versions have
- the 512MB limitation.
-*/
-#ifdef __GNUC__
- typedef unsigned long long int MaybeUInt64;
-# define MaybeUInt64_FMT "%Lu"
-#else
-#ifdef _MSC_VER
- typedef unsigned __int64 MaybeUInt64;
-# define MaybeUInt64_FMT "%I64u"
-#else
- typedef unsigned int MaybeUInt64;
-# define MaybeUInt64_FMT "%u"
-#endif
-#endif
-
-typedef unsigned int UInt32;
-typedef int Int32;
-typedef unsigned char UChar;
-typedef char Char;
-typedef unsigned char Bool;
-#define True ((Bool)1)
-#define False ((Bool)0)
-
-
-#define BZ_MAX_FILENAME 2000
-
-Char inFileName[BZ_MAX_FILENAME];
-Char outFileName[BZ_MAX_FILENAME];
-Char progName[BZ_MAX_FILENAME];
-
-MaybeUInt64 bytesOut = 0;
-MaybeUInt64 bytesIn = 0;
-
-
-/*---------------------------------------------------*/
-/*--- Header bytes ---*/
-/*---------------------------------------------------*/
-
-#define BZ_HDR_B 0x42 /* 'B' */
-#define BZ_HDR_Z 0x5a /* 'Z' */
-#define BZ_HDR_h 0x68 /* 'h' */
-#define BZ_HDR_0 0x30 /* '0' */
-
-
-/*---------------------------------------------------*/
-/*--- I/O errors ---*/
-/*---------------------------------------------------*/
-
-/*---------------------------------------------*/
-static void readError ( void )
-{
- fprintf ( stderr,
- "%s: I/O error reading `%s', possible reason follows.\n",
- progName, inFileName );
- perror ( progName );
- fprintf ( stderr, "%s: warning: output file(s) may be incomplete.\n",
- progName );
- exit ( 1 );
-}
-
-
-/*---------------------------------------------*/
-static void writeError ( void )
-{
- fprintf ( stderr,
- "%s: I/O error reading `%s', possible reason follows.\n",
- progName, inFileName );
- perror ( progName );
- fprintf ( stderr, "%s: warning: output file(s) may be incomplete.\n",
- progName );
- exit ( 1 );
-}
-
-
-/*---------------------------------------------*/
-static void mallocFail ( Int32 n )
-{
- fprintf ( stderr,
- "%s: malloc failed on request for %d bytes.\n",
- progName, n );
- fprintf ( stderr, "%s: warning: output file(s) may be incomplete.\n",
- progName );
- exit ( 1 );
-}
-
-
-/*---------------------------------------------*/
-static void tooManyBlocks ( Int32 max_handled_blocks )
-{
- fprintf ( stderr,
- "%s: `%s' appears to contain more than %d blocks\n",
- progName, inFileName, max_handled_blocks );
- fprintf ( stderr,
- "%s: and cannot be handled. To fix, increase\n",
- progName );
- fprintf ( stderr,
- "%s: BZ_MAX_HANDLED_BLOCKS in bzip2recover.c, and recompile.\n",
- progName );
- exit ( 1 );
-}
-
-
-
-/*---------------------------------------------------*/
-/*--- Bit stream I/O ---*/
-/*---------------------------------------------------*/
-
-typedef
- struct {
- FILE* handle;
- Int32 buffer;
- Int32 buffLive;
- Char mode;
- }
- BitStream;
-
-
-/*---------------------------------------------*/
-static BitStream* bsOpenReadStream ( FILE* stream )
-{
- BitStream *bs = malloc ( sizeof(BitStream) );
- if (bs == NULL) mallocFail ( sizeof(BitStream) );
- bs->handle = stream;
- bs->buffer = 0;
- bs->buffLive = 0;
- bs->mode = 'r';
- return bs;
-}
-
-
-/*---------------------------------------------*/
-static BitStream* bsOpenWriteStream ( FILE* stream )
-{
- BitStream *bs = malloc ( sizeof(BitStream) );
- if (bs == NULL) mallocFail ( sizeof(BitStream) );
- bs->handle = stream;
- bs->buffer = 0;
- bs->buffLive = 0;
- bs->mode = 'w';
- return bs;
-}
-
-
-/*---------------------------------------------*/
-static void bsPutBit ( BitStream* bs, Int32 bit )
-{
- if (bs->buffLive == 8) {
- Int32 retVal = putc ( (UChar) bs->buffer, bs->handle );
- if (retVal == EOF) writeError();
- bytesOut++;
- bs->buffLive = 1;
- bs->buffer = bit & 0x1;
- } else {
- bs->buffer = ( (bs->buffer << 1) | (bit & 0x1) );
- bs->buffLive++;
- };
-}
-
-
-/*---------------------------------------------*/
-/*--
- Returns 0 or 1, or 2 to indicate EOF.
---*/
-static Int32 bsGetBit ( BitStream* bs )
-{
- if (bs->buffLive > 0) {
- bs->buffLive --;
- return ( ((bs->buffer) >> (bs->buffLive)) & 0x1 );
- } else {
- Int32 retVal = getc ( bs->handle );
- if ( retVal == EOF ) {
- if (errno != 0) readError();
- return 2;
- }
- bs->buffLive = 7;
- bs->buffer = retVal;
- return ( ((bs->buffer) >> 7) & 0x1 );
- }
-}
-
-
-/*---------------------------------------------*/
-static void bsClose ( BitStream* bs )
-{
- Int32 retVal;
-
- if ( bs->mode == 'w' ) {
- while ( bs->buffLive < 8 ) {
- bs->buffLive++;
- bs->buffer <<= 1;
- };
- retVal = putc ( (UChar) (bs->buffer), bs->handle );
- if (retVal == EOF) writeError();
- bytesOut++;
- retVal = fflush ( bs->handle );
- if (retVal == EOF) writeError();
- }
- retVal = fclose ( bs->handle );
- if (retVal == EOF) {
- if (bs->mode == 'w') writeError(); else readError();
- }
- free ( bs );
-}
-
-
-/*---------------------------------------------*/
-static void bsPutUChar ( BitStream* bs, UChar c )
-{
- Int32 i;
- for (i = 7; i >= 0; i--)
- bsPutBit ( bs, (((UInt32) c) >> i) & 0x1 );
-}
-
-
-/*---------------------------------------------*/
-static void bsPutUInt32 ( BitStream* bs, UInt32 c )
-{
- Int32 i;
-
- for (i = 31; i >= 0; i--)
- bsPutBit ( bs, (c >> i) & 0x1 );
-}
-
-
-/*---------------------------------------------*/
-static Bool endsInBz2 ( Char* name )
-{
- Int32 n = strlen ( name );
- if (n <= 4) return False;
- return
- (name[n-4] == '.' &&
- name[n-3] == 'b' &&
- name[n-2] == 'z' &&
- name[n-1] == '2');
-}
-
-
-/*---------------------------------------------------*/
-/*--- ---*/
-/*---------------------------------------------------*/
-
-/* This logic isn't really right when it comes to Cygwin. */
-#ifdef _WIN32
-# define BZ_SPLIT_SYM '\\' /* path splitter on Windows platform */
-#else
-# define BZ_SPLIT_SYM '/' /* path splitter on Unix platform */
-#endif
-
-#define BLOCK_HEADER_HI 0x00003141UL
-#define BLOCK_HEADER_LO 0x59265359UL
-
-#define BLOCK_ENDMARK_HI 0x00001772UL
-#define BLOCK_ENDMARK_LO 0x45385090UL
-
-/* Increase if necessary. However, a .bz2 file with > 50000 blocks
- would have an uncompressed size of at least 40GB, so the chances
- are low you'll need to up this.
-*/
-#define BZ_MAX_HANDLED_BLOCKS 50000
-
-MaybeUInt64 bStart [BZ_MAX_HANDLED_BLOCKS];
-MaybeUInt64 bEnd [BZ_MAX_HANDLED_BLOCKS];
-MaybeUInt64 rbStart[BZ_MAX_HANDLED_BLOCKS];
-MaybeUInt64 rbEnd [BZ_MAX_HANDLED_BLOCKS];
-
-Int32 main ( Int32 argc, Char** argv )
-{
- FILE* inFile;
- FILE* outFile;
- BitStream* bsIn, *bsWr;
- Int32 b, wrBlock, currBlock, rbCtr;
- MaybeUInt64 bitsRead;
-
- UInt32 buffHi, buffLo, blockCRC;
- Char* p;
-
- strcpy ( progName, argv[0] );
- inFileName[0] = outFileName[0] = 0;
-
- fprintf ( stderr,
- "bzip2recover 1.0.6: extracts blocks from damaged .bz2 files.\n"
);
-
- if (argc != 2) {
- fprintf ( stderr, "%s: usage is `%s damaged_file_name'.\n",
- progName, progName );
- switch (sizeof(MaybeUInt64)) {
- case 8:
- fprintf(stderr,
- "\trestrictions on size of recovered file: None\n");
- break;
- case 4:
- fprintf(stderr,
- "\trestrictions on size of recovered file: 512 MB\n");
- fprintf(stderr,
- "\tto circumvent, recompile with MaybeUInt64 as an\n"
- "\tunsigned 64-bit int.\n");
- break;
- default:
- fprintf(stderr,
- "\tsizeof(MaybeUInt64) is not 4 or 8 -- "
- "configuration error.\n");
- break;
- }
- exit(1);
- }
-
- if (strlen(argv[1]) >= BZ_MAX_FILENAME-20) {
- fprintf ( stderr,
- "%s: supplied filename is suspiciously (>= %d chars) long.
Bye!\n",
- progName, (int)strlen(argv[1]) );
- exit(1);
- }
-
- strcpy ( inFileName, argv[1] );
-
- inFile = fopen ( inFileName, "rb" );
- if (inFile == NULL) {
- fprintf ( stderr, "%s: can't read `%s'\n", progName, inFileName
);
- exit(1);
- }
-
- bsIn = bsOpenReadStream ( inFile );
- fprintf ( stderr, "%s: searching for block boundaries ...\n", progName );
-
- bitsRead = 0;
- buffHi = buffLo = 0;
- currBlock = 0;
- bStart[currBlock] = 0;
-
- rbCtr = 0;
-
- while (True) {
- b = bsGetBit ( bsIn );
- bitsRead++;
- if (b == 2) {
- if (bitsRead >= bStart[currBlock] &&
- (bitsRead - bStart[currBlock]) >= 40) {
- bEnd[currBlock] = bitsRead-1;
- if (currBlock > 0)
- fprintf ( stderr, " block %d runs from " MaybeUInt64_FMT
- " to " MaybeUInt64_FMT "
(incomplete)\n",
- currBlock, bStart[currBlock], bEnd[currBlock] );
- } else
- currBlock--;
- break;
- }
- buffHi = (buffHi << 1) | (buffLo >> 31);
- buffLo = (buffLo << 1) | (b & 1);
- if ( ( (buffHi & 0x0000ffff) == BLOCK_HEADER_HI
- && buffLo == BLOCK_HEADER_LO)
- ||
- ( (buffHi & 0x0000ffff) == BLOCK_ENDMARK_HI
- && buffLo == BLOCK_ENDMARK_LO)
- ) {
- if (bitsRead > 49) {
- bEnd[currBlock] = bitsRead-49;
- } else {
- bEnd[currBlock] = 0;
- }
- if (currBlock > 0 &&
- (bEnd[currBlock] - bStart[currBlock]) >= 130) {
- fprintf ( stderr, " block %d runs from " MaybeUInt64_FMT
- " to " MaybeUInt64_FMT "\n",
- rbCtr+1, bStart[currBlock], bEnd[currBlock] );
- rbStart[rbCtr] = bStart[currBlock];
- rbEnd[rbCtr] = bEnd[currBlock];
- rbCtr++;
- }
- if (currBlock >= BZ_MAX_HANDLED_BLOCKS)
- tooManyBlocks(BZ_MAX_HANDLED_BLOCKS);
- currBlock++;
-
- bStart[currBlock] = bitsRead;
- }
- }
-
- bsClose ( bsIn );
-
- /*-- identified blocks run from 1 to rbCtr inclusive. --*/
-
- if (rbCtr < 1) {
- fprintf ( stderr,
- "%s: sorry, I couldn't find any block boundaries.\n",
- progName );
- exit(1);
- };
-
- fprintf ( stderr, "%s: splitting into blocks\n", progName );
-
- inFile = fopen ( inFileName, "rb" );
- if (inFile == NULL) {
- fprintf ( stderr, "%s: can't open `%s'\n", progName, inFileName
);
- exit(1);
- }
- bsIn = bsOpenReadStream ( inFile );
-
- /*-- placate gcc's dataflow analyser --*/
- blockCRC = 0; bsWr = 0;
-
- bitsRead = 0;
- outFile = NULL;
- wrBlock = 0;
- while (True) {
- b = bsGetBit(bsIn);
- if (b == 2) break;
- buffHi = (buffHi << 1) | (buffLo >> 31);
- buffLo = (buffLo << 1) | (b & 1);
- if (bitsRead == 47+rbStart[wrBlock])
- blockCRC = (buffHi << 16) | (buffLo >> 16);
-
- if (outFile != NULL && bitsRead >= rbStart[wrBlock]
- && bitsRead <= rbEnd[wrBlock]) {
- bsPutBit ( bsWr, b );
- }
-
- bitsRead++;
-
- if (bitsRead == rbEnd[wrBlock]+1) {
- if (outFile != NULL) {
- bsPutUChar ( bsWr, 0x17 ); bsPutUChar ( bsWr, 0x72 );
- bsPutUChar ( bsWr, 0x45 ); bsPutUChar ( bsWr, 0x38 );
- bsPutUChar ( bsWr, 0x50 ); bsPutUChar ( bsWr, 0x90 );
- bsPutUInt32 ( bsWr, blockCRC );
- bsClose ( bsWr );
- }
- if (wrBlock >= rbCtr) break;
- wrBlock++;
- } else
- if (bitsRead == rbStart[wrBlock]) {
- /* Create the output file name, correctly handling leading paths.
- (31.10.2001 by Sergey E. Kusikov) */
- Char* split;
- Int32 ofs, k;
- for (k = 0; k < BZ_MAX_FILENAME; k++)
- outFileName[k] = 0;
- strcpy (outFileName, inFileName);
- split = strrchr (outFileName, BZ_SPLIT_SYM);
- if (split == NULL) {
- split = outFileName;
- } else {
- ++split;
- }
- /* Now split points to the start of the basename. */
- ofs = split - outFileName;
- sprintf (split, "rec%5d", wrBlock+1);
- for (p = split; *p != 0; p++) if (*p == ' ') *p = '0';
- strcat (outFileName, inFileName + ofs);
-
- if ( !endsInBz2(outFileName)) strcat ( outFileName, ".bz2" );
-
- fprintf ( stderr, " writing block %d to `%s' ...\n",
- wrBlock+1, outFileName );
-
- outFile = fopen ( outFileName, "wb" );
- if (outFile == NULL) {
- fprintf ( stderr, "%s: can't write `%s'\n",
- progName, outFileName );
- exit(1);
- }
- bsWr = bsOpenWriteStream ( outFile );
- bsPutUChar ( bsWr, BZ_HDR_B );
- bsPutUChar ( bsWr, BZ_HDR_Z );
- bsPutUChar ( bsWr, BZ_HDR_h );
- bsPutUChar ( bsWr, BZ_HDR_0 + 9 );
- bsPutUChar ( bsWr, 0x31 ); bsPutUChar ( bsWr, 0x41 );
- bsPutUChar ( bsWr, 0x59 ); bsPutUChar ( bsWr, 0x26 );
- bsPutUChar ( bsWr, 0x53 ); bsPutUChar ( bsWr, 0x59 );
- }
- }
-
- fprintf ( stderr, "%s: finished\n", progName );
- return 0;
-}
-
-
-
-/*-----------------------------------------------------------*/
-/*--- end bzip2recover.c ---*/
-/*-----------------------------------------------------------*/
diff --git a/sdk/lib/3rdparty/bzip2/bzlib.c b/sdk/lib/3rdparty/bzip2/bzlib.c
deleted file mode 100644
index f3091cf7cd6..00000000000
--- a/sdk/lib/3rdparty/bzip2/bzlib.c
+++ /dev/null
@@ -1,1589 +0,0 @@
-
-/*-------------------------------------------------------------*/
-/*--- Library top-level functions. ---*/
-/*--- bzlib.c ---*/
-/*-------------------------------------------------------------*/
-
-/* ------------------------------------------------------------------
- This file is part of bzip2/libbzip2, a program and library for
- lossless, block-sorting data compression.
-
- bzip2/libbzip2 version 1.0.6 of 6 September 2010
- Copyright (C) 1996-2010 Julian Seward <jseward(a)bzip.org>
-
- Please read the WARNING, DISCLAIMER and PATENTS sections in the
- README file.
-
- This program is released under the terms of the license contained
- in the file LICENSE.
- ------------------------------------------------------------------ */
-
-/* CHANGES
- 0.9.0 -- original version.
- 0.9.0a/b -- no changes in this file.
- 0.9.0c -- made zero-length BZ_FLUSH work correctly in bzCompress().
- fixed bzWrite/bzRead to ignore zero-length requests.
- fixed bzread to correctly handle read requests after EOF.
- wrong parameter order in call to bzDecompressInit in
- bzBuffToBuffDecompress. Fixed.
-*/
-
-#ifdef BZ_DECOMPRESS_ONLY
-#ifndef __NTDRIVER__
- #define __NTDRIVER__
-#endif
-#include <wdm.h>
-#include <debug.h>
-#endif
-#include "bzlib_private.h"
-
-
-/*---------------------------------------------------*/
-/*--- Compression stuff ---*/
-/*---------------------------------------------------*/
-
-
-/*---------------------------------------------------*/
-#ifndef BZ_NO_STDIO
-void BZ2_bz__AssertH__fail ( int errcode )
-{
- fprintf(stderr,
- "\n\nbzip2/libbzip2: internal error number %d.\n"
- "This is a bug in bzip2/libbzip2, %s.\n"
- "Please report it to me at: jseward(a)bzip.org. If this happened\n"
- "when you were using some program which uses libbzip2 as a\n"
- "component, you should also report this bug to the author(s)\n"
- "of that program. Please make an effort to report this bug;\n"
- "timely and accurate bug reports eventually lead to higher\n"
- "quality software. Thanks. Julian Seward, 10 December 2007.\n\n",
- errcode,
- BZ2_bzlibVersion()
- );
-
- if (errcode == 1007) {
- fprintf(stderr,
- "\n*** A special note about internal error number 1007 ***\n"
- "\n"
- "Experience suggests that a common cause of i.e. 1007\n"
- "is unreliable memory or other hardware. The 1007 assertion\n"
- "just happens to cross-check the results of huge numbers of\n"
- "memory reads/writes, and so acts (unintendedly) as a stress\n"
- "test of your memory system.\n"
- "\n"
- "I suggest the following: try compressing the file again,\n"
- "possibly monitoring progress in detail with the -vv flag.\n"
- "\n"
- "* If the error cannot be reproduced, and/or happens at different\n"
- " points in compression, you may have a flaky memory system.\n"
- " Try a memory-test program. I have used Memtest86\n"
- " (
www.memtest86.com). At the time of writing it is free (GPLd).\n"
- " Memtest86 tests memory much more thorougly than your BIOSs\n"
- " power-on test, and may find failures that the BIOS doesn't.\n"
- "\n"
- "* If the error can be repeatably reproduced, this is a bug in\n"
- " bzip2, and I would very much like to hear about it. Please\n"
- " let me know, and, ideally, save a copy of the file causing the\n"
- " problem -- without which I will be unable to investigate it.\n"
- "\n"
- );
- }
-
- exit(3);
-}
-#endif
-
-
-/*---------------------------------------------------*/
-static
-int bz_config_ok ( void )
-{
- if (sizeof(int) != 4) return 0;
- if (sizeof(short) != 2) return 0;
- if (sizeof(char) != 1) return 0;
- return 1;
-}
-
-
-/*---------------------------------------------------*/
-static
-void* default_bzalloc ( void* opaque, Int32 items, Int32 size )
-{
- return ExAllocatePool( PagedPool, items * size );
-}
-
-static
-void default_bzfree ( void* opaque, void* addr )
-{
- ExFreePool( addr );
-}
-
-#ifndef BZ_DECOMPRESS_ONLY
-
-/*---------------------------------------------------*/
-static
-void prepare_new_block ( EState* s )
-{
- Int32 i;
- s->nblock = 0;
- s->numZ = 0;
- s->state_out_pos = 0;
- BZ_INITIALISE_CRC ( s->blockCRC );
- for (i = 0; i < 256; i++) s->inUse[i] = False;
- s->blockNo++;
-}
-
-
-/*---------------------------------------------------*/
-static
-void init_RL ( EState* s )
-{
- s->state_in_ch = 256;
- s->state_in_len = 0;
-}
-
-
-static
-Bool isempty_RL ( EState* s )
-{
- if (s->state_in_ch < 256 && s->state_in_len > 0)
- return False; else
- return True;
-}
-
-
-/*---------------------------------------------------*/
-int BZ_API(BZ2_bzCompressInit)
- ( bz_stream* strm,
- int blockSize100k,
- int verbosity,
- int workFactor )
-{
- Int32 n;
- EState* s;
-
- if (!bz_config_ok()) return BZ_CONFIG_ERROR;
-
- if (strm == NULL ||
- blockSize100k < 1 || blockSize100k > 9 ||
- workFactor < 0 || workFactor > 250)
- return BZ_PARAM_ERROR;
-
- if (workFactor == 0) workFactor = 30;
- if (strm->bzalloc == NULL) strm->bzalloc = default_bzalloc;
- if (strm->bzfree == NULL) strm->bzfree = default_bzfree;
-
- s = BZALLOC( sizeof(EState) );
- if (s == NULL) return BZ_MEM_ERROR;
- s->strm = strm;
-
- s->arr1 = NULL;
- s->arr2 = NULL;
- s->ftab = NULL;
-
- n = 100000 * blockSize100k;
- s->arr1 = BZALLOC( n * sizeof(UInt32) );
- s->arr2 = BZALLOC( (n+BZ_N_OVERSHOOT) * sizeof(UInt32) );
- s->ftab = BZALLOC( 65537 * sizeof(UInt32) );
-
- if (s->arr1 == NULL || s->arr2 == NULL || s->ftab == NULL) {
- if (s->arr1 != NULL) BZFREE(s->arr1);
- if (s->arr2 != NULL) BZFREE(s->arr2);
- if (s->ftab != NULL) BZFREE(s->ftab);
- if (s != NULL) BZFREE(s);
- return BZ_MEM_ERROR;
- }
-
- s->blockNo = 0;
- s->state = BZ_S_INPUT;
- s->mode = BZ_M_RUNNING;
- s->combinedCRC = 0;
- s->blockSize100k = blockSize100k;
- s->nblockMAX = 100000 * blockSize100k - 19;
- s->verbosity = verbosity;
- s->workFactor = workFactor;
-
- s->block = (UChar*)s->arr2;
- s->mtfv = (UInt16*)s->arr1;
- s->zbits = NULL;
- s->ptr = (UInt32*)s->arr1;
-
- strm->state = s;
- strm->total_in_lo32 = 0;
- strm->total_in_hi32 = 0;
- strm->total_out_lo32 = 0;
- strm->total_out_hi32 = 0;
- init_RL ( s );
- prepare_new_block ( s );
- return BZ_OK;
-}
-
-
-/*---------------------------------------------------*/
-static
-void add_pair_to_block ( EState* s )
-{
- Int32 i;
- UChar ch = (UChar)(s->state_in_ch);
- for (i = 0; i < s->state_in_len; i++) {
- BZ_UPDATE_CRC( s->blockCRC, ch );
- }
- s->inUse[s->state_in_ch] = True;
- switch (s->state_in_len) {
- case 1:
- s->block[s->nblock] = (UChar)ch; s->nblock++;
- break;
- case 2:
- s->block[s->nblock] = (UChar)ch; s->nblock++;
- s->block[s->nblock] = (UChar)ch; s->nblock++;
- break;
- case 3:
- s->block[s->nblock] = (UChar)ch; s->nblock++;
- s->block[s->nblock] = (UChar)ch; s->nblock++;
- s->block[s->nblock] = (UChar)ch; s->nblock++;
- break;
- default:
- s->inUse[s->state_in_len-4] = True;
- s->block[s->nblock] = (UChar)ch; s->nblock++;
- s->block[s->nblock] = (UChar)ch; s->nblock++;
- s->block[s->nblock] = (UChar)ch; s->nblock++;
- s->block[s->nblock] = (UChar)ch; s->nblock++;
- s->block[s->nblock] = ((UChar)(s->state_in_len-4));
- s->nblock++;
- break;
- }
-}
-
-
-/*---------------------------------------------------*/
-static
-void flush_RL ( EState* s )
-{
- if (s->state_in_ch < 256) add_pair_to_block ( s );
- init_RL ( s );
-}
-
-
-/*---------------------------------------------------*/
-#define ADD_CHAR_TO_BLOCK(zs,zchh0) \
-{ \
- UInt32 zchh = (UInt32)(zchh0); \
- /*-- fast track the common case --*/ \
- if (zchh != zs->state_in_ch && \
- zs->state_in_len == 1) { \
- UChar ch = (UChar)(zs->state_in_ch); \
- BZ_UPDATE_CRC( zs->blockCRC, ch ); \
- zs->inUse[zs->state_in_ch] = True; \
- zs->block[zs->nblock] = (UChar)ch; \
- zs->nblock++; \
- zs->state_in_ch = zchh; \
- } \
- else \
- /*-- general, uncommon cases --*/ \
- if (zchh != zs->state_in_ch || \
- zs->state_in_len == 255) { \
- if (zs->state_in_ch < 256) \
- add_pair_to_block ( zs ); \
- zs->state_in_ch = zchh; \
- zs->state_in_len = 1; \
- } else { \
- zs->state_in_len++; \
- } \
-}
-
-
-/*---------------------------------------------------*/
-static
-Bool copy_input_until_stop ( EState* s )
-{
- Bool progress_in = False;
-
- if (s->mode == BZ_M_RUNNING) {
-
- /*-- fast track the common case --*/
- while (True) {
- /*-- block full? --*/
- if (s->nblock >= s->nblockMAX) break;
- /*-- no input? --*/
- if (s->strm->avail_in == 0) break;
- progress_in = True;
- ADD_CHAR_TO_BLOCK ( s, (UInt32)(*((UChar*)(s->strm->next_in))) );
- s->strm->next_in++;
- s->strm->avail_in--;
- s->strm->total_in_lo32++;
- if (s->strm->total_in_lo32 == 0) s->strm->total_in_hi32++;
- }
-
- } else {
-
- /*-- general, uncommon case --*/
- while (True) {
- /*-- block full? --*/
- if (s->nblock >= s->nblockMAX) break;
- /*-- no input? --*/
- if (s->strm->avail_in == 0) break;
- /*-- flush/finish end? --*/
- if (s->avail_in_expect == 0) break;
- progress_in = True;
- ADD_CHAR_TO_BLOCK ( s, (UInt32)(*((UChar*)(s->strm->next_in))) );
- s->strm->next_in++;
- s->strm->avail_in--;
- s->strm->total_in_lo32++;
- if (s->strm->total_in_lo32 == 0) s->strm->total_in_hi32++;
- s->avail_in_expect--;
- }
- }
- return progress_in;
-}
-
-
-/*---------------------------------------------------*/
-static
-Bool copy_output_until_stop ( EState* s )
-{
- Bool progress_out = False;
-
- while (True) {
-
- /*-- no output space? --*/
- if (s->strm->avail_out == 0) break;
-
- /*-- block done? --*/
- if (s->state_out_pos >= s->numZ) break;
-
- progress_out = True;
- *(s->strm->next_out) = s->zbits[s->state_out_pos];
- s->state_out_pos++;
- s->strm->avail_out--;
- s->strm->next_out++;
- s->strm->total_out_lo32++;
- if (s->strm->total_out_lo32 == 0) s->strm->total_out_hi32++;
- }
-
- return progress_out;
-}
-
-
-/*---------------------------------------------------*/
-static
-Bool handle_compress ( bz_stream* strm )
-{
- Bool progress_in = False;
- Bool progress_out = False;
- EState* s = strm->state;
-
- while (True) {
-
- if (s->state == BZ_S_OUTPUT) {
- progress_out |= copy_output_until_stop ( s );
- if (s->state_out_pos < s->numZ) break;
- if (s->mode == BZ_M_FINISHING &&
- s->avail_in_expect == 0 &&
- isempty_RL(s)) break;
- prepare_new_block ( s );
- s->state = BZ_S_INPUT;
- if (s->mode == BZ_M_FLUSHING &&
- s->avail_in_expect == 0 &&
- isempty_RL(s)) break;
- }
-
- if (s->state == BZ_S_INPUT) {
- progress_in |= copy_input_until_stop ( s );
- if (s->mode != BZ_M_RUNNING && s->avail_in_expect == 0) {
- flush_RL ( s );
- BZ2_compressBlock ( s, (Bool)(s->mode == BZ_M_FINISHING) );
- s->state = BZ_S_OUTPUT;
- }
- else
- if (s->nblock >= s->nblockMAX) {
- BZ2_compressBlock ( s, False );
- s->state = BZ_S_OUTPUT;
- }
- else
- if (s->strm->avail_in == 0) {
- break;
- }
- }
-
- }
-
- return progress_in || progress_out;
-}
-
-
-/*---------------------------------------------------*/
-int BZ_API(BZ2_bzCompress) ( bz_stream *strm, int action )
-{
- Bool progress;
- EState* s;
- if (strm == NULL) return BZ_PARAM_ERROR;
- s = strm->state;
- if (s == NULL) return BZ_PARAM_ERROR;
- if (s->strm != strm) return BZ_PARAM_ERROR;
-
- preswitch:
- switch (s->mode) {
-
- case BZ_M_IDLE:
- return BZ_SEQUENCE_ERROR;
-
- case BZ_M_RUNNING:
- if (action == BZ_RUN) {
- progress = handle_compress ( strm );
- return progress ? BZ_RUN_OK : BZ_PARAM_ERROR;
- }
- else
- if (action == BZ_FLUSH) {
- s->avail_in_expect = strm->avail_in;
- s->mode = BZ_M_FLUSHING;
- goto preswitch;
- }
- else
- if (action == BZ_FINISH) {
- s->avail_in_expect = strm->avail_in;
- s->mode = BZ_M_FINISHING;
- goto preswitch;
- }
- else
- return BZ_PARAM_ERROR;
-
- case BZ_M_FLUSHING:
- if (action != BZ_FLUSH) return BZ_SEQUENCE_ERROR;
- if (s->avail_in_expect != s->strm->avail_in)
- return BZ_SEQUENCE_ERROR;
- progress = handle_compress ( strm );
- if (s->avail_in_expect > 0 || !isempty_RL(s) ||
- s->state_out_pos < s->numZ) return BZ_FLUSH_OK;
- s->mode = BZ_M_RUNNING;
- return BZ_RUN_OK;
-
- case BZ_M_FINISHING:
- if (action != BZ_FINISH) return BZ_SEQUENCE_ERROR;
- if (s->avail_in_expect != s->strm->avail_in)
- return BZ_SEQUENCE_ERROR;
- progress = handle_compress ( strm );
- if (!progress) return BZ_SEQUENCE_ERROR;
- if (s->avail_in_expect > 0 || !isempty_RL(s) ||
- s->state_out_pos < s->numZ) return BZ_FINISH_OK;
- s->mode = BZ_M_IDLE;
- return BZ_STREAM_END;
- }
- return BZ_OK; /*--not reached--*/
-}
-
-
-/*---------------------------------------------------*/
-int BZ_API(BZ2_bzCompressEnd) ( bz_stream *strm )
-{
- EState* s;
- if (strm == NULL) return BZ_PARAM_ERROR;
- s = strm->state;
- if (s == NULL) return BZ_PARAM_ERROR;
- if (s->strm != strm) return BZ_PARAM_ERROR;
-
- if (s->arr1 != NULL) BZFREE(s->arr1);
- if (s->arr2 != NULL) BZFREE(s->arr2);
- if (s->ftab != NULL) BZFREE(s->ftab);
- BZFREE(strm->state);
-
- strm->state = NULL;
-
- return BZ_OK;
-}
-
-#endif // BZ_DECOMPRESS_ONLY
-
-/*---------------------------------------------------*/
-/*--- Decompression stuff ---*/
-/*---------------------------------------------------*/
-
-/*---------------------------------------------------*/
-int BZ_API(BZ2_bzDecompressInit)
- ( bz_stream* strm,
- int verbosity,
- int small )
-{
- DState* s;
-
- if (!bz_config_ok()) return BZ_CONFIG_ERROR;
-
- if (strm == NULL) return BZ_PARAM_ERROR;
- if (small != 0 && small != 1) return BZ_PARAM_ERROR;
- if (verbosity < 0 || verbosity > 4) return BZ_PARAM_ERROR;
-
- if (strm->bzalloc == NULL) strm->bzalloc = default_bzalloc;
- if (strm->bzfree == NULL) strm->bzfree = default_bzfree;
-
- s = BZALLOC( sizeof(DState) );
- if (s == NULL) return BZ_MEM_ERROR;
- s->strm = strm;
- strm->state = s;
- s->state = BZ_X_MAGIC_1;
- s->bsLive = 0;
- s->bsBuff = 0;
- s->calculatedCombinedCRC = 0;
- strm->total_in_lo32 = 0;
- strm->total_in_hi32 = 0;
- strm->total_out_lo32 = 0;
- strm->total_out_hi32 = 0;
- s->smallDecompress = (Bool)small;
- s->ll4 = NULL;
- s->ll16 = NULL;
- s->tt = NULL;
- s->currBlockNo = 0;
- s->verbosity = verbosity;
-
- return BZ_OK;
-}
-
-#ifndef BZ_DECOMPRESS_ONLY
-
-/*---------------------------------------------------*/
-/* Return True iff data corruption is discovered.
- Returns False if there is no problem.
-*/
-static
-Bool unRLE_obuf_to_output_FAST ( DState* s )
-{
- UChar k1;
-
- if (s->blockRandomised) {
-
- while (True) {
- /* try to finish existing run */
- while (True) {
- if (s->strm->avail_out == 0) return False;
- if (s->state_out_len == 0) break;
- *( (UChar*)(s->strm->next_out) ) = s->state_out_ch;
- BZ_UPDATE_CRC ( s->calculatedBlockCRC, s->state_out_ch );
- s->state_out_len--;
- s->strm->next_out++;
- s->strm->avail_out--;
- s->strm->total_out_lo32++;
- if (s->strm->total_out_lo32 == 0) s->strm->total_out_hi32++;
- }
-
- /* can a new run be started? */
- if (s->nblock_used == s->save_nblock+1) return False;
-
- /* Only caused by corrupt data stream? */
- if (s->nblock_used > s->save_nblock+1)
- return True;
-
- s->state_out_len = 1;
- s->state_out_ch = s->k0;
- BZ_GET_FAST(k1); BZ_RAND_UPD_MASK;
- k1 ^= BZ_RAND_MASK; s->nblock_used++;
- if (s->nblock_used == s->save_nblock+1) continue;
- if (k1 != s->k0) { s->k0 = k1; continue; };
-
- s->state_out_len = 2;
- BZ_GET_FAST(k1); BZ_RAND_UPD_MASK;
- k1 ^= BZ_RAND_MASK; s->nblock_used++;
- if (s->nblock_used == s->save_nblock+1) continue;
- if (k1 != s->k0) { s->k0 = k1; continue; };
-
- s->state_out_len = 3;
- BZ_GET_FAST(k1); BZ_RAND_UPD_MASK;
- k1 ^= BZ_RAND_MASK; s->nblock_used++;
... 3999 lines suppressed ...