├── .gitignore ├── .travis.yml ├── CHANGES ├── CMakeLists.txt ├── LICENSE ├── Makefile ├── Makefile-libbz2_so ├── README ├── README.COMPILATION.PROBLEMS ├── README.XML.STUFF ├── blocksort.c ├── bz-common.xsl ├── bz-fo.xsl ├── bz-html.xsl ├── bzdiff ├── bzdiff.1 ├── bzgrep ├── bzgrep.1 ├── bzip.css ├── bzip2.1 ├── bzip2.1.preformatted ├── bzip2.c ├── bzip2.txt ├── bzip2recover.c ├── bzlib.c ├── bzlib.h ├── bzlib_private.h ├── bzmore ├── bzmore.1 ├── cmake └── dist.cmake ├── compress.c ├── crctable.c ├── decompress.c ├── dist.info ├── dlltest.c ├── dlltest.dsp ├── entities.xml ├── format.pl ├── huffman.c ├── libbz2.def ├── libbz2.dsp ├── makefile.msc ├── manual.html ├── manual.pdf ├── manual.ps ├── manual.xml ├── mk251.c ├── randtable.c ├── sample1.bz2 ├── sample1.ref ├── sample2.bz2 ├── sample2.ref ├── sample3.bz2 ├── sample3.ref ├── spewG.c ├── unzcrash.c ├── words0 ├── words1 ├── words2 ├── words3 └── xmlproc.sh /.gitignore: -------------------------------------------------------------------------------- 1 | bzcmp.1 2 | bzegrep.1 3 | bzfgrep.1 4 | bzless.1 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # 2 | # LuaDist Travis-CI Hook 3 | # 4 | 5 | # We assume C build environments 6 | language: C 7 | 8 | # Try using multiple Lua Implementations 9 | env: 10 | - TOOL="gcc" # Use native compiler (GCC usually) 11 | - TOOL="clang" # Use clang 12 | - TOOL="i686-w64-mingw32" # 32bit MinGW 13 | - TOOL="x86_64-w64-mingw32" # 64bit MinGW 14 | - TOOL="arm-linux-gnueabihf" # ARM hard-float (hf), linux 15 | 16 | # Crosscompile builds may fail 17 | matrix: 18 | allow_failures: 19 | - env: TOOL="i686-w64-mingw32" 20 | - env: TOOL="x86_64-w64-mingw32" 21 | - env: TOOL="arm-linux-gnueabihf" 22 | 23 | # Install dependencies 24 | install: 25 | - git clone git://github.com/LuaDist/Tools.git ~/_tools 26 | - ~/_tools/travis/travis install 27 | 28 | # Bootstap 29 | before_script: 30 | - ~/_tools/travis/travis bootstrap 31 | 32 | # Build the module 33 | script: 34 | - ~/_tools/travis/travis build 35 | 36 | # Execute additional tests or commands 37 | after_script: 38 | - ~/_tools/travis/travis test 39 | 40 | # Only watch the master branch 41 | branches: 42 | only: 43 | - master 44 | 45 | # Notify the LuaDist Dev group if needed 46 | notifications: 47 | recipients: 48 | - luadist-dev@googlegroups.com 49 | email: 50 | on_success: change 51 | on_failure: always 52 | -------------------------------------------------------------------------------- /CHANGES: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------ 2 | This file is part of bzip2/libbzip2, a program and library for 3 | lossless, block-sorting data compression. 4 | 5 | bzip2/libbzip2 version 1.0.5 of 10 December 2007 6 | Copyright (C) 1996-2007 Julian Seward 7 | 8 | Please read the WARNING, DISCLAIMER and PATENTS sections in the 9 | README file. 10 | 11 | This program is released under the terms of the license contained 12 | in the file LICENSE. 13 | ------------------------------------------------------------------ 14 | 15 | 16 | 0.9.0 17 | ~~~~~ 18 | First version. 19 | 20 | 21 | 0.9.0a 22 | ~~~~~~ 23 | Removed 'ranlib' from Makefile, since most modern Unix-es 24 | don't need it, or even know about it. 25 | 26 | 27 | 0.9.0b 28 | ~~~~~~ 29 | Fixed a problem with error reporting in bzip2.c. This does not effect 30 | the library in any way. Problem is: versions 0.9.0 and 0.9.0a (of the 31 | program proper) compress and decompress correctly, but give misleading 32 | error messages (internal panics) when an I/O error occurs, instead of 33 | reporting the problem correctly. This shouldn't give any data loss 34 | (as far as I can see), but is confusing. 35 | 36 | Made the inline declarations disappear for non-GCC compilers. 37 | 38 | 39 | 0.9.0c 40 | ~~~~~~ 41 | Fixed some problems in the library pertaining to some boundary cases. 42 | This makes the library behave more correctly in those situations. The 43 | fixes apply only to features (calls and parameters) not used by 44 | bzip2.c, so the non-fixedness of them in previous versions has no 45 | effect on reliability of bzip2.c. 46 | 47 | In bzlib.c: 48 | * made zero-length BZ_FLUSH work correctly in bzCompress(). 49 | * fixed bzWrite/bzRead to ignore zero-length requests. 50 | * fixed bzread to correctly handle read requests after EOF. 51 | * wrong parameter order in call to bzDecompressInit in 52 | bzBuffToBuffDecompress. Fixed. 53 | 54 | In compress.c: 55 | * changed setting of nGroups in sendMTFValues() so as to 56 | do a bit better on small files. This _does_ effect 57 | bzip2.c. 58 | 59 | 60 | 0.9.5a 61 | ~~~~~~ 62 | Major change: add a fallback sorting algorithm (blocksort.c) 63 | to give reasonable behaviour even for very repetitive inputs. 64 | Nuked --repetitive-best and --repetitive-fast since they are 65 | no longer useful. 66 | 67 | Minor changes: mostly a whole bunch of small changes/ 68 | bugfixes in the driver (bzip2.c). Changes pertaining to the 69 | user interface are: 70 | 71 | allow decompression of symlink'd files to stdout 72 | decompress/test files even without .bz2 extension 73 | give more accurate error messages for I/O errors 74 | when compressing/decompressing to stdout, don't catch control-C 75 | read flags from BZIP2 and BZIP environment variables 76 | decline to break hard links to a file unless forced with -f 77 | allow -c flag even with no filenames 78 | preserve file ownerships as far as possible 79 | make -s -1 give the expected block size (100k) 80 | add a flag -q --quiet to suppress nonessential warnings 81 | stop decoding flags after --, so files beginning in - can be handled 82 | resolved inconsistent naming: bzcat or bz2cat ? 83 | bzip2 --help now returns 0 84 | 85 | Programming-level changes are: 86 | 87 | fixed syntax error in GET_LL4 for Borland C++ 5.02 88 | let bzBuffToBuffDecompress return BZ_DATA_ERROR{_MAGIC} 89 | fix overshoot of mode-string end in bzopen_or_bzdopen 90 | wrapped bzlib.h in #ifdef __cplusplus ... extern "C" { ... } 91 | close file handles under all error conditions 92 | added minor mods so it compiles with DJGPP out of the box 93 | fixed Makefile so it doesn't give problems with BSD make 94 | fix uninitialised memory reads in dlltest.c 95 | 96 | 0.9.5b 97 | ~~~~~~ 98 | Open stdin/stdout in binary mode for DJGPP. 99 | 100 | 0.9.5c 101 | ~~~~~~ 102 | Changed BZ_N_OVERSHOOT to be ... + 2 instead of ... + 1. The + 1 103 | version could cause the sorted order to be wrong in some extremely 104 | obscure cases. Also changed setting of quadrant in blocksort.c. 105 | 106 | 0.9.5d 107 | ~~~~~~ 108 | The only functional change is to make bzlibVersion() in the library 109 | return the correct string. This has no effect whatsoever on the 110 | functioning of the bzip2 program or library. Added a couple of casts 111 | so the library compiles without warnings at level 3 in MS Visual 112 | Studio 6.0. Included a Y2K statement in the file Y2K_INFO. All other 113 | changes are minor documentation changes. 114 | 115 | 1.0 116 | ~~~ 117 | Several minor bugfixes and enhancements: 118 | 119 | * Large file support. The library uses 64-bit counters to 120 | count the volume of data passing through it. bzip2.c 121 | is now compiled with -D_FILE_OFFSET_BITS=64 to get large 122 | file support from the C library. -v correctly prints out 123 | file sizes greater than 4 gigabytes. All these changes have 124 | been made without assuming a 64-bit platform or a C compiler 125 | which supports 64-bit ints, so, except for the C library 126 | aspect, they are fully portable. 127 | 128 | * Decompression robustness. The library/program should be 129 | robust to any corruption of compressed data, detecting and 130 | handling _all_ corruption, instead of merely relying on 131 | the CRCs. What this means is that the program should 132 | never crash, given corrupted data, and the library should 133 | always return BZ_DATA_ERROR. 134 | 135 | * Fixed an obscure race-condition bug only ever observed on 136 | Solaris, in which, if you were very unlucky and issued 137 | control-C at exactly the wrong time, both input and output 138 | files would be deleted. 139 | 140 | * Don't run out of file handles on test/decompression when 141 | large numbers of files have invalid magic numbers. 142 | 143 | * Avoid library namespace pollution. Prefix all exported 144 | symbols with BZ2_. 145 | 146 | * Minor sorting enhancements from my DCC2000 paper. 147 | 148 | * Advance the version number to 1.0, so as to counteract the 149 | (false-in-this-case) impression some people have that programs 150 | with version numbers less than 1.0 are in some way, experimental, 151 | pre-release versions. 152 | 153 | * Create an initial Makefile-libbz2_so to build a shared library. 154 | Yes, I know I should really use libtool et al ... 155 | 156 | * Make the program exit with 2 instead of 0 when decompression 157 | fails due to a bad magic number (ie, an invalid bzip2 header). 158 | Also exit with 1 (as the manual claims :-) whenever a diagnostic 159 | message would have been printed AND the corresponding operation 160 | is aborted, for example 161 | bzip2: Output file xx already exists. 162 | When a diagnostic message is printed but the operation is not 163 | aborted, for example 164 | bzip2: Can't guess original name for wurble -- using wurble.out 165 | then the exit value 0 is returned, unless some other problem is 166 | also detected. 167 | 168 | I think it corresponds more closely to what the manual claims now. 169 | 170 | 171 | 1.0.1 172 | ~~~~~ 173 | * Modified dlltest.c so it uses the new BZ2_ naming scheme. 174 | * Modified makefile-msc to fix minor build probs on Win2k. 175 | * Updated README.COMPILATION.PROBLEMS. 176 | 177 | There are no functionality changes or bug fixes relative to version 178 | 1.0.0. This is just a documentation update + a fix for minor Win32 179 | build problems. For almost everyone, upgrading from 1.0.0 to 1.0.1 is 180 | utterly pointless. Don't bother. 181 | 182 | 183 | 1.0.2 184 | ~~~~~ 185 | A bug fix release, addressing various minor issues which have appeared 186 | in the 18 or so months since 1.0.1 was released. Most of the fixes 187 | are to do with file-handling or documentation bugs. To the best of my 188 | knowledge, there have been no data-loss-causing bugs reported in the 189 | compression/decompression engine of 1.0.0 or 1.0.1. 190 | 191 | Note that this release does not improve the rather crude build system 192 | for Unix platforms. The general plan here is to autoconfiscate/ 193 | libtoolise 1.0.2 soon after release, and release the result as 1.1.0 194 | or perhaps 1.2.0. That, however, is still just a plan at this point. 195 | 196 | Here are the changes in 1.0.2. Bug-reporters and/or patch-senders in 197 | parentheses. 198 | 199 | * Fix an infinite segfault loop in 1.0.1 when a directory is 200 | encountered in -f (force) mode. 201 | (Trond Eivind Glomsrod, Nicholas Nethercote, Volker Schmidt) 202 | 203 | * Avoid double fclose() of output file on certain I/O error paths. 204 | (Solar Designer) 205 | 206 | * Don't fail with internal error 1007 when fed a long stream (> 48MB) 207 | of byte 251. Also print useful message suggesting that 1007s may be 208 | caused by bad memory. 209 | (noticed by Juan Pedro Vallejo, fixed by me) 210 | 211 | * Fix uninitialised variable silly bug in demo prog dlltest.c. 212 | (Jorj Bauer) 213 | 214 | * Remove 512-MB limitation on recovered file size for bzip2recover 215 | on selected platforms which support 64-bit ints. At the moment 216 | all GCC supported platforms, and Win32. 217 | (me, Alson van der Meulen) 218 | 219 | * Hard-code header byte values, to give correct operation on platforms 220 | using EBCDIC as their native character set (IBM's OS/390). 221 | (Leland Lucius) 222 | 223 | * Copy file access times correctly. 224 | (Marty Leisner) 225 | 226 | * Add distclean and check targets to Makefile. 227 | (Michael Carmack) 228 | 229 | * Parameterise use of ar and ranlib in Makefile. Also add $(LDFLAGS). 230 | (Rich Ireland, Bo Thorsen) 231 | 232 | * Pass -p (create parent dirs as needed) to mkdir during make install. 233 | (Jeremy Fusco) 234 | 235 | * Dereference symlinks when copying file permissions in -f mode. 236 | (Volker Schmidt) 237 | 238 | * Majorly simplify implementation of uInt64_qrm10. 239 | (Bo Lindbergh) 240 | 241 | * Check the input file still exists before deleting the output one, 242 | when aborting in cleanUpAndFail(). 243 | (Joerg Prante, Robert Linden, Matthias Krings) 244 | 245 | Also a bunch of patches courtesy of Philippe Troin, the Debian maintainer 246 | of bzip2: 247 | 248 | * Wrapper scripts (with manpages): bzdiff, bzgrep, bzmore. 249 | 250 | * Spelling changes and minor enhancements in bzip2.1. 251 | 252 | * Avoid race condition between creating the output file and setting its 253 | interim permissions safely, by using fopen_output_safely(). 254 | No changes to bzip2recover since there is no issue with file 255 | permissions there. 256 | 257 | * do not print senseless report with -v when compressing an empty 258 | file. 259 | 260 | * bzcat -f works on non-bzip2 files. 261 | 262 | * do not try to escape shell meta-characters on unix (the shell takes 263 | care of these). 264 | 265 | * added --fast and --best aliases for -1 -9 for gzip compatibility. 266 | 267 | 268 | 1.0.3 (15 Feb 05) 269 | ~~~~~~~~~~~~~~~~~ 270 | Fixes some minor bugs since the last version, 1.0.2. 271 | 272 | * Further robustification against corrupted compressed data. 273 | There are currently no known bitstreams which can cause the 274 | decompressor to crash, loop or access memory which does not 275 | belong to it. If you are using bzip2 or the library to 276 | decompress bitstreams from untrusted sources, an upgrade 277 | to 1.0.3 is recommended. This fixes CAN-2005-1260. 278 | 279 | * The documentation has been converted to XML, from which html 280 | and pdf can be derived. 281 | 282 | * Various minor bugs in the documentation have been fixed. 283 | 284 | * Fixes for various compilation warnings with newer versions of 285 | gcc, and on 64-bit platforms. 286 | 287 | * The BZ_NO_STDIO cpp symbol was not properly observed in 1.0.2. 288 | This has been fixed. 289 | 290 | 291 | 1.0.4 (20 Dec 06) 292 | ~~~~~~~~~~~~~~~~~ 293 | Fixes some minor bugs since the last version, 1.0.3. 294 | 295 | * Fix file permissions race problem (CAN-2005-0953). 296 | 297 | * Avoid possible segfault in BZ2_bzclose. From Coverity's NetBSD 298 | scan. 299 | 300 | * 'const'/prototype cleanups in the C code. 301 | 302 | * Change default install location to /usr/local, and handle multiple 303 | 'make install's without error. 304 | 305 | * Sanitise file names more carefully in bzgrep. Fixes CAN-2005-0758 306 | to the extent that applies to bzgrep. 307 | 308 | * Use 'mktemp' rather than 'tempfile' in bzdiff. 309 | 310 | * Tighten up a couple of assertions in blocksort.c following automated 311 | analysis. 312 | 313 | * Fix minor doc/comment bugs. 314 | 315 | 316 | 1.0.5 (10 Dec 07) 317 | ~~~~~~~~~~~~~~~~~ 318 | Security fix only. Fixes CERT-FI 20469 as it applies to bzip2. 319 | 320 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2007-2012 LuaDist. 2 | # Submitted by David Manura 3 | # Redistribution and use of this file is allowed according to the terms of the MIT license. 4 | # For details see the COPYRIGHT file distributed with LuaDist. 5 | # Please note that the package source code is licensed under its own license. 6 | 7 | project ( bzip2 C ) 8 | cmake_minimum_required ( VERSION 2.6 ) 9 | include ( cmake/dist.cmake ) 10 | 11 | add_definitions ( -D_FILE_OFFSET_BITS=64 ) 12 | 13 | # Library 14 | set ( BZIP2_SRCS blocksort.c huffman.c crctable.c randtable.c compress.c decompress.c 15 | bzlib.c ) 16 | 17 | add_library ( bz2 ${BZIP2_SRCS} libbz2.def ) 18 | 19 | add_executable ( bzip2 bzip2.c ) 20 | target_link_libraries ( bzip2 bz2 ) 21 | 22 | add_executable ( bzip2recover bzip2recover.c ) 23 | 24 | file ( WRITE bzegrep.1 ".so man1/bzgrep.1" ) 25 | file ( WRITE bzfgrep.1 ".so man1/bzgrep.1" ) 26 | file ( WRITE bzless.1 ".so man1/bzmore.1" ) 27 | file ( WRITE bzcmp.1 ".so man1/bzdiff.1" ) 28 | 29 | include ( CTest ) 30 | add_test ( test ${CMAKE_COMMAND} -P test.cmake ) 31 | 32 | install_executable ( bzip2 bzip2recover ) 33 | install_library ( bz2 ) 34 | install_header ( bzlib.h ) 35 | install_doc ( manual.html bzip2.1 bzgrep.1 bzmore.1 bzdiff.1 bzegrep.1 bzfgrep.1 36 | bzless.1 bzcmp.1 ) 37 | install_data ( README LICENSE ) 38 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------- 3 | 4 | This program, "bzip2", the associated library "libbzip2", and all 5 | documentation, are copyright (C) 1996-2007 Julian R Seward. All 6 | rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 12 | 1. Redistributions of source code must retain the above copyright 13 | notice, this list of conditions and the following disclaimer. 14 | 15 | 2. The origin of this software must not be misrepresented; you must 16 | not claim that you wrote the original software. If you use this 17 | software in a product, an acknowledgment in the product 18 | documentation would be appreciated but is not required. 19 | 20 | 3. Altered source versions must be plainly marked as such, and must 21 | not be misrepresented as being the original software. 22 | 23 | 4. The name of the author may not be used to endorse or promote 24 | products derived from this software without specific prior written 25 | permission. 26 | 27 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 28 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 29 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 30 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 31 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 32 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 33 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 34 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 35 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 36 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 37 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | 39 | Julian Seward, jseward@bzip.org 40 | bzip2/libbzip2 version 1.0.5 of 10 December 2007 41 | 42 | -------------------------------------------------------------------------- 43 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # ------------------------------------------------------------------ 2 | # This file is part of bzip2/libbzip2, a program and library for 3 | # lossless, block-sorting data compression. 4 | # 5 | # bzip2/libbzip2 version 1.0.5 of 10 December 2007 6 | # Copyright (C) 1996-2007 Julian Seward 7 | # 8 | # Please read the WARNING, DISCLAIMER and PATENTS sections in the 9 | # README file. 10 | # 11 | # This program is released under the terms of the license contained 12 | # in the file LICENSE. 13 | # ------------------------------------------------------------------ 14 | 15 | SHELL=/bin/sh 16 | 17 | # To assist in cross-compiling 18 | CC=gcc 19 | AR=ar 20 | RANLIB=ranlib 21 | LDFLAGS= 22 | 23 | BIGFILES=-D_FILE_OFFSET_BITS=64 24 | CFLAGS=-Wall -Winline -O2 -g $(BIGFILES) 25 | 26 | # Where you want it installed when you do 'make install' 27 | PREFIX=/usr/local 28 | 29 | 30 | OBJS= blocksort.o \ 31 | huffman.o \ 32 | crctable.o \ 33 | randtable.o \ 34 | compress.o \ 35 | decompress.o \ 36 | bzlib.o 37 | 38 | all: libbz2.a bzip2 bzip2recover test 39 | 40 | bzip2: libbz2.a bzip2.o 41 | $(CC) $(CFLAGS) $(LDFLAGS) -o bzip2 bzip2.o -L. -lbz2 42 | 43 | bzip2recover: bzip2recover.o 44 | $(CC) $(CFLAGS) $(LDFLAGS) -o bzip2recover bzip2recover.o 45 | 46 | libbz2.a: $(OBJS) 47 | rm -f libbz2.a 48 | $(AR) cq libbz2.a $(OBJS) 49 | @if ( test -f $(RANLIB) -o -f /usr/bin/ranlib -o \ 50 | -f /bin/ranlib -o -f /usr/ccs/bin/ranlib ) ; then \ 51 | echo $(RANLIB) libbz2.a ; \ 52 | $(RANLIB) libbz2.a ; \ 53 | fi 54 | 55 | check: test 56 | test: bzip2 57 | @cat words1 58 | ./bzip2 -1 < sample1.ref > sample1.rb2 59 | ./bzip2 -2 < sample2.ref > sample2.rb2 60 | ./bzip2 -3 < sample3.ref > sample3.rb2 61 | ./bzip2 -d < sample1.bz2 > sample1.tst 62 | ./bzip2 -d < sample2.bz2 > sample2.tst 63 | ./bzip2 -ds < sample3.bz2 > sample3.tst 64 | cmp sample1.bz2 sample1.rb2 65 | cmp sample2.bz2 sample2.rb2 66 | cmp sample3.bz2 sample3.rb2 67 | cmp sample1.tst sample1.ref 68 | cmp sample2.tst sample2.ref 69 | cmp sample3.tst sample3.ref 70 | @cat words3 71 | 72 | install: bzip2 bzip2recover 73 | if ( test ! -d $(PREFIX)/bin ) ; then mkdir -p $(PREFIX)/bin ; fi 74 | if ( test ! -d $(PREFIX)/lib ) ; then mkdir -p $(PREFIX)/lib ; fi 75 | if ( test ! -d $(PREFIX)/man ) ; then mkdir -p $(PREFIX)/man ; fi 76 | if ( test ! -d $(PREFIX)/man/man1 ) ; then mkdir -p $(PREFIX)/man/man1 ; fi 77 | if ( test ! -d $(PREFIX)/include ) ; then mkdir -p $(PREFIX)/include ; fi 78 | cp -f bzip2 $(PREFIX)/bin/bzip2 79 | cp -f bzip2 $(PREFIX)/bin/bunzip2 80 | cp -f bzip2 $(PREFIX)/bin/bzcat 81 | cp -f bzip2recover $(PREFIX)/bin/bzip2recover 82 | chmod a+x $(PREFIX)/bin/bzip2 83 | chmod a+x $(PREFIX)/bin/bunzip2 84 | chmod a+x $(PREFIX)/bin/bzcat 85 | chmod a+x $(PREFIX)/bin/bzip2recover 86 | cp -f bzip2.1 $(PREFIX)/man/man1 87 | chmod a+r $(PREFIX)/man/man1/bzip2.1 88 | cp -f bzlib.h $(PREFIX)/include 89 | chmod a+r $(PREFIX)/include/bzlib.h 90 | cp -f libbz2.a $(PREFIX)/lib 91 | chmod a+r $(PREFIX)/lib/libbz2.a 92 | cp -f bzgrep $(PREFIX)/bin/bzgrep 93 | ln -s -f $(PREFIX)/bin/bzgrep $(PREFIX)/bin/bzegrep 94 | ln -s -f $(PREFIX)/bin/bzgrep $(PREFIX)/bin/bzfgrep 95 | chmod a+x $(PREFIX)/bin/bzgrep 96 | cp -f bzmore $(PREFIX)/bin/bzmore 97 | ln -s -f $(PREFIX)/bin/bzmore $(PREFIX)/bin/bzless 98 | chmod a+x $(PREFIX)/bin/bzmore 99 | cp -f bzdiff $(PREFIX)/bin/bzdiff 100 | ln -s -f $(PREFIX)/bin/bzdiff $(PREFIX)/bin/bzcmp 101 | chmod a+x $(PREFIX)/bin/bzdiff 102 | cp -f bzgrep.1 bzmore.1 bzdiff.1 $(PREFIX)/man/man1 103 | chmod a+r $(PREFIX)/man/man1/bzgrep.1 104 | chmod a+r $(PREFIX)/man/man1/bzmore.1 105 | chmod a+r $(PREFIX)/man/man1/bzdiff.1 106 | echo ".so man1/bzgrep.1" > $(PREFIX)/man/man1/bzegrep.1 107 | echo ".so man1/bzgrep.1" > $(PREFIX)/man/man1/bzfgrep.1 108 | echo ".so man1/bzmore.1" > $(PREFIX)/man/man1/bzless.1 109 | echo ".so man1/bzdiff.1" > $(PREFIX)/man/man1/bzcmp.1 110 | 111 | clean: 112 | rm -f *.o libbz2.a bzip2 bzip2recover \ 113 | sample1.rb2 sample2.rb2 sample3.rb2 \ 114 | sample1.tst sample2.tst sample3.tst 115 | 116 | blocksort.o: blocksort.c 117 | @cat words0 118 | $(CC) $(CFLAGS) -c blocksort.c 119 | huffman.o: huffman.c 120 | $(CC) $(CFLAGS) -c huffman.c 121 | crctable.o: crctable.c 122 | $(CC) $(CFLAGS) -c crctable.c 123 | randtable.o: randtable.c 124 | $(CC) $(CFLAGS) -c randtable.c 125 | compress.o: compress.c 126 | $(CC) $(CFLAGS) -c compress.c 127 | decompress.o: decompress.c 128 | $(CC) $(CFLAGS) -c decompress.c 129 | bzlib.o: bzlib.c 130 | $(CC) $(CFLAGS) -c bzlib.c 131 | bzip2.o: bzip2.c 132 | $(CC) $(CFLAGS) -c bzip2.c 133 | bzip2recover.o: bzip2recover.c 134 | $(CC) $(CFLAGS) -c bzip2recover.c 135 | 136 | 137 | distclean: clean 138 | rm -f manual.ps manual.html manual.pdf 139 | 140 | DISTNAME=bzip2-1.0.5 141 | dist: check manual 142 | rm -f $(DISTNAME) 143 | ln -s -f . $(DISTNAME) 144 | tar cvf $(DISTNAME).tar \ 145 | $(DISTNAME)/blocksort.c \ 146 | $(DISTNAME)/huffman.c \ 147 | $(DISTNAME)/crctable.c \ 148 | $(DISTNAME)/randtable.c \ 149 | $(DISTNAME)/compress.c \ 150 | $(DISTNAME)/decompress.c \ 151 | $(DISTNAME)/bzlib.c \ 152 | $(DISTNAME)/bzip2.c \ 153 | $(DISTNAME)/bzip2recover.c \ 154 | $(DISTNAME)/bzlib.h \ 155 | $(DISTNAME)/bzlib_private.h \ 156 | $(DISTNAME)/Makefile \ 157 | $(DISTNAME)/LICENSE \ 158 | $(DISTNAME)/bzip2.1 \ 159 | $(DISTNAME)/bzip2.1.preformatted \ 160 | $(DISTNAME)/bzip2.txt \ 161 | $(DISTNAME)/words0 \ 162 | $(DISTNAME)/words1 \ 163 | $(DISTNAME)/words2 \ 164 | $(DISTNAME)/words3 \ 165 | $(DISTNAME)/sample1.ref \ 166 | $(DISTNAME)/sample2.ref \ 167 | $(DISTNAME)/sample3.ref \ 168 | $(DISTNAME)/sample1.bz2 \ 169 | $(DISTNAME)/sample2.bz2 \ 170 | $(DISTNAME)/sample3.bz2 \ 171 | $(DISTNAME)/dlltest.c \ 172 | $(DISTNAME)/manual.html \ 173 | $(DISTNAME)/manual.pdf \ 174 | $(DISTNAME)/manual.ps \ 175 | $(DISTNAME)/README \ 176 | $(DISTNAME)/README.COMPILATION.PROBLEMS \ 177 | $(DISTNAME)/README.XML.STUFF \ 178 | $(DISTNAME)/CHANGES \ 179 | $(DISTNAME)/libbz2.def \ 180 | $(DISTNAME)/libbz2.dsp \ 181 | $(DISTNAME)/dlltest.dsp \ 182 | $(DISTNAME)/makefile.msc \ 183 | $(DISTNAME)/unzcrash.c \ 184 | $(DISTNAME)/spewG.c \ 185 | $(DISTNAME)/mk251.c \ 186 | $(DISTNAME)/bzdiff \ 187 | $(DISTNAME)/bzdiff.1 \ 188 | $(DISTNAME)/bzmore \ 189 | $(DISTNAME)/bzmore.1 \ 190 | $(DISTNAME)/bzgrep \ 191 | $(DISTNAME)/bzgrep.1 \ 192 | $(DISTNAME)/Makefile-libbz2_so \ 193 | $(DISTNAME)/bz-common.xsl \ 194 | $(DISTNAME)/bz-fo.xsl \ 195 | $(DISTNAME)/bz-html.xsl \ 196 | $(DISTNAME)/bzip.css \ 197 | $(DISTNAME)/entities.xml \ 198 | $(DISTNAME)/manual.xml \ 199 | $(DISTNAME)/format.pl \ 200 | $(DISTNAME)/xmlproc.sh 201 | gzip -v $(DISTNAME).tar 202 | 203 | # For rebuilding the manual from sources on my SuSE 9.1 box 204 | 205 | MANUAL_SRCS= bz-common.xsl bz-fo.xsl bz-html.xsl bzip.css \ 206 | entities.xml manual.xml 207 | 208 | manual: manual.html manual.ps manual.pdf 209 | 210 | manual.ps: $(MANUAL_SRCS) 211 | ./xmlproc.sh -ps manual.xml 212 | 213 | manual.pdf: $(MANUAL_SRCS) 214 | ./xmlproc.sh -pdf manual.xml 215 | 216 | manual.html: $(MANUAL_SRCS) 217 | ./xmlproc.sh -html manual.xml 218 | -------------------------------------------------------------------------------- /Makefile-libbz2_so: -------------------------------------------------------------------------------- 1 | 2 | # This Makefile builds a shared version of the library, 3 | # libbz2.so.1.0.4, with soname libbz2.so.1.0, 4 | # at least on x86-Linux (RedHat 7.2), 5 | # with gcc-2.96 20000731 (Red Hat Linux 7.1 2.96-98). 6 | # Please see the README file for some important info 7 | # about building the library like this. 8 | 9 | # ------------------------------------------------------------------ 10 | # This file is part of bzip2/libbzip2, a program and library for 11 | # lossless, block-sorting data compression. 12 | # 13 | # bzip2/libbzip2 version 1.0.5 of 10 December 2007 14 | # Copyright (C) 1996-2007 Julian Seward 15 | # 16 | # Please read the WARNING, DISCLAIMER and PATENTS sections in the 17 | # README file. 18 | # 19 | # This program is released under the terms of the license contained 20 | # in the file LICENSE. 21 | # ------------------------------------------------------------------ 22 | 23 | 24 | SHELL=/bin/sh 25 | CC=gcc 26 | BIGFILES=-D_FILE_OFFSET_BITS=64 27 | CFLAGS=-fpic -fPIC -Wall -Winline -O2 -g $(BIGFILES) 28 | 29 | OBJS= blocksort.o \ 30 | huffman.o \ 31 | crctable.o \ 32 | randtable.o \ 33 | compress.o \ 34 | decompress.o \ 35 | bzlib.o 36 | 37 | all: $(OBJS) 38 | $(CC) -shared -Wl,-soname -Wl,libbz2.so.1.0 -o libbz2.so.1.0.4 $(OBJS) 39 | $(CC) $(CFLAGS) -o bzip2-shared bzip2.c libbz2.so.1.0.4 40 | rm -f libbz2.so.1.0 41 | ln -s libbz2.so.1.0.4 libbz2.so.1.0 42 | 43 | clean: 44 | rm -f $(OBJS) bzip2.o libbz2.so.1.0.4 libbz2.so.1.0 bzip2-shared 45 | 46 | blocksort.o: blocksort.c 47 | $(CC) $(CFLAGS) -c blocksort.c 48 | huffman.o: huffman.c 49 | $(CC) $(CFLAGS) -c huffman.c 50 | crctable.o: crctable.c 51 | $(CC) $(CFLAGS) -c crctable.c 52 | randtable.o: randtable.c 53 | $(CC) $(CFLAGS) -c randtable.c 54 | compress.o: compress.c 55 | $(CC) $(CFLAGS) -c compress.c 56 | decompress.o: decompress.c 57 | $(CC) $(CFLAGS) -c decompress.c 58 | bzlib.o: bzlib.c 59 | $(CC) $(CFLAGS) -c bzlib.c 60 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | 2 | This is the README for bzip2/libzip2. 3 | This version is fully compatible with the previous public releases. 4 | 5 | ------------------------------------------------------------------ 6 | This file is part of bzip2/libbzip2, a program and library for 7 | lossless, block-sorting data compression. 8 | 9 | bzip2/libbzip2 version 1.0.5 of 10 December 2007 10 | Copyright (C) 1996-2007 Julian Seward 11 | 12 | Please read the WARNING, DISCLAIMER and PATENTS sections in this file. 13 | 14 | This program is released under the terms of the license contained 15 | in the file LICENSE. 16 | ------------------------------------------------------------------ 17 | 18 | Complete documentation is available in Postscript form (manual.ps), 19 | PDF (manual.pdf) or html (manual.html). A plain-text version of the 20 | manual page is available as bzip2.txt. 21 | 22 | 23 | HOW TO BUILD -- UNIX 24 | 25 | Type 'make'. This builds the library libbz2.a and then the programs 26 | bzip2 and bzip2recover. Six self-tests are run. If the self-tests 27 | complete ok, carry on to installation: 28 | 29 | To install in /usr/local/bin, /usr/local/lib, /usr/local/man and 30 | /usr/local/include, type 31 | 32 | make install 33 | 34 | To install somewhere else, eg, /xxx/yyy/{bin,lib,man,include}, type 35 | 36 | make install PREFIX=/xxx/yyy 37 | 38 | If you are (justifiably) paranoid and want to see what 'make install' 39 | is going to do, you can first do 40 | 41 | make -n install or 42 | make -n install PREFIX=/xxx/yyy respectively. 43 | 44 | The -n instructs make to show the commands it would execute, but not 45 | actually execute them. 46 | 47 | 48 | HOW TO BUILD -- UNIX, shared library libbz2.so. 49 | 50 | Do 'make -f Makefile-libbz2_so'. This Makefile seems to work for 51 | Linux-ELF (RedHat 7.2 on an x86 box), with gcc. I make no claims 52 | that it works for any other platform, though I suspect it probably 53 | will work for most platforms employing both ELF and gcc. 54 | 55 | bzip2-shared, a client of the shared library, is also built, but not 56 | self-tested. So I suggest you also build using the normal Makefile, 57 | since that conducts a self-test. A second reason to prefer the 58 | version statically linked to the library is that, on x86 platforms, 59 | building shared objects makes a valuable register (%ebx) unavailable 60 | to gcc, resulting in a slowdown of 10%-20%, at least for bzip2. 61 | 62 | Important note for people upgrading .so's from 0.9.0/0.9.5 to version 63 | 1.0.X. All the functions in the library have been renamed, from (eg) 64 | bzCompress to BZ2_bzCompress, to avoid namespace pollution. 65 | Unfortunately this means that the libbz2.so created by 66 | Makefile-libbz2_so will not work with any program which used an older 67 | version of the library. I do encourage library clients to make the 68 | effort to upgrade to use version 1.0, since it is both faster and more 69 | robust than previous versions. 70 | 71 | 72 | HOW TO BUILD -- Windows 95, NT, DOS, Mac, etc. 73 | 74 | It's difficult for me to support compilation on all these platforms. 75 | My approach is to collect binaries for these platforms, and put them 76 | on the master web site (http://www.bzip.org). Look there. However 77 | (FWIW), bzip2-1.0.X is very standard ANSI C and should compile 78 | unmodified with MS Visual C. If you have difficulties building, you 79 | might want to read README.COMPILATION.PROBLEMS. 80 | 81 | At least using MS Visual C++ 6, you can build from the unmodified 82 | sources by issuing, in a command shell: 83 | 84 | nmake -f makefile.msc 85 | 86 | (you may need to first run the MSVC-provided script VCVARS32.BAT 87 | so as to set up paths to the MSVC tools correctly). 88 | 89 | 90 | VALIDATION 91 | 92 | Correct operation, in the sense that a compressed file can always be 93 | decompressed to reproduce the original, is obviously of paramount 94 | importance. To validate bzip2, I used a modified version of Mark 95 | Nelson's churn program. Churn is an automated test driver which 96 | recursively traverses a directory structure, using bzip2 to compress 97 | and then decompress each file it encounters, and checking that the 98 | decompressed data is the same as the original. 99 | 100 | 101 | 102 | Please read and be aware of the following: 103 | 104 | WARNING: 105 | 106 | This program and library (attempts to) compress data by 107 | performing several non-trivial transformations on it. 108 | Unless you are 100% familiar with *all* the algorithms 109 | contained herein, and with the consequences of modifying them, 110 | you should NOT meddle with the compression or decompression 111 | machinery. Incorrect changes can and very likely *will* 112 | lead to disastrous loss of data. 113 | 114 | 115 | DISCLAIMER: 116 | 117 | I TAKE NO RESPONSIBILITY FOR ANY LOSS OF DATA ARISING FROM THE 118 | USE OF THIS PROGRAM/LIBRARY, HOWSOEVER CAUSED. 119 | 120 | Every compression of a file implies an assumption that the 121 | compressed file can be decompressed to reproduce the original. 122 | Great efforts in design, coding and testing have been made to 123 | ensure that this program works correctly. However, the complexity 124 | of the algorithms, and, in particular, the presence of various 125 | special cases in the code which occur with very low but non-zero 126 | probability make it impossible to rule out the possibility of bugs 127 | remaining in the program. DO NOT COMPRESS ANY DATA WITH THIS 128 | PROGRAM UNLESS YOU ARE PREPARED TO ACCEPT THE POSSIBILITY, HOWEVER 129 | SMALL, THAT THE DATA WILL NOT BE RECOVERABLE. 130 | 131 | That is not to say this program is inherently unreliable. 132 | Indeed, I very much hope the opposite is true. bzip2/libbzip2 133 | has been carefully constructed and extensively tested. 134 | 135 | 136 | PATENTS: 137 | 138 | To the best of my knowledge, bzip2/libbzip2 does not use any 139 | patented algorithms. However, I do not have the resources 140 | to carry out a patent search. Therefore I cannot give any 141 | guarantee of the above statement. 142 | 143 | 144 | 145 | WHAT'S NEW IN 0.9.0 (as compared to 0.1pl2) ? 146 | 147 | * Approx 10% faster compression, 30% faster decompression 148 | * -t (test mode) is a lot quicker 149 | * Can decompress concatenated compressed files 150 | * Programming interface, so programs can directly read/write .bz2 files 151 | * Less restrictive (BSD-style) licensing 152 | * Flag handling more compatible with GNU gzip 153 | * Much more documentation, i.e., a proper user manual 154 | * Hopefully, improved portability (at least of the library) 155 | 156 | WHAT'S NEW IN 0.9.5 ? 157 | 158 | * Compression speed is much less sensitive to the input 159 | data than in previous versions. Specifically, the very 160 | slow performance caused by repetitive data is fixed. 161 | * Many small improvements in file and flag handling. 162 | * A Y2K statement. 163 | 164 | WHAT'S NEW IN 1.0.0 ? 165 | 166 | See the CHANGES file. 167 | 168 | WHAT'S NEW IN 1.0.2 ? 169 | 170 | See the CHANGES file. 171 | 172 | WHAT'S NEW IN 1.0.3 ? 173 | 174 | See the CHANGES file. 175 | 176 | WHAT'S NEW IN 1.0.4 ? 177 | 178 | See the CHANGES file. 179 | 180 | WHAT'S NEW IN 1.0.5 ? 181 | 182 | See the CHANGES file. 183 | 184 | 185 | I hope you find bzip2 useful. Feel free to contact me at 186 | jseward@bzip.org 187 | if you have any suggestions or queries. Many people mailed me with 188 | comments, suggestions and patches after the releases of bzip-0.15, 189 | bzip-0.21, and bzip2 versions 0.1pl2, 0.9.0, 0.9.5, 1.0.0, 1.0.1, 190 | 1.0.2 and 1.0.3, and the changes in bzip2 are largely a result of this 191 | feedback. I thank you for your comments. 192 | 193 | bzip2's "home" is http://www.bzip.org/ 194 | 195 | Julian Seward 196 | jseward@bzip.org 197 | Cambridge, UK. 198 | 199 | 18 July 1996 (version 0.15) 200 | 25 August 1996 (version 0.21) 201 | 7 August 1997 (bzip2, version 0.1) 202 | 29 August 1997 (bzip2, version 0.1pl2) 203 | 23 August 1998 (bzip2, version 0.9.0) 204 | 8 June 1999 (bzip2, version 0.9.5) 205 | 4 Sept 1999 (bzip2, version 0.9.5d) 206 | 5 May 2000 (bzip2, version 1.0pre8) 207 | 30 December 2001 (bzip2, version 1.0.2pre1) 208 | 15 February 2005 (bzip2, version 1.0.3) 209 | 20 December 2006 (bzip2, version 1.0.4) 210 | 10 December 2007 (bzip2, version 1.0.5) 211 | -------------------------------------------------------------------------------- /README.COMPILATION.PROBLEMS: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------ 2 | This file is part of bzip2/libbzip2, a program and library for 3 | lossless, block-sorting data compression. 4 | 5 | bzip2/libbzip2 version 1.0.5 of 10 December 2007 6 | Copyright (C) 1996-2007 Julian Seward 7 | 8 | Please read the WARNING, DISCLAIMER and PATENTS sections in the 9 | README file. 10 | 11 | This program is released under the terms of the license contained 12 | in the file LICENSE. 13 | ------------------------------------------------------------------ 14 | 15 | bzip2-1.0.5 should compile without problems on the vast majority of 16 | platforms. Using the supplied Makefile, I've built and tested it 17 | myself for x86-linux and amd64-linux. With makefile.msc, Visual C++ 18 | 6.0 and nmake, you can build a native Win32 version too. Large file 19 | support seems to work correctly on at least on amd64-linux. 20 | 21 | When I say "large file" I mean a file of size 2,147,483,648 (2^31) 22 | bytes or above. Many older OSs can't handle files above this size, 23 | but many newer ones can. Large files are pretty huge -- most files 24 | you'll encounter are not Large Files. 25 | 26 | Early versions of bzip2 (0.1, 0.9.0, 0.9.5) compiled on a wide variety 27 | of platforms without difficulty, and I hope this version will continue 28 | in that tradition. However, in order to support large files, I've had 29 | to include the define -D_FILE_OFFSET_BITS=64 in the Makefile. This 30 | can cause problems. 31 | 32 | The technique of adding -D_FILE_OFFSET_BITS=64 to get large file 33 | support is, as far as I know, the Recommended Way to get correct large 34 | file support. For more details, see the Large File Support 35 | Specification, published by the Large File Summit, at 36 | 37 | http://ftp.sas.com/standards/large.file 38 | 39 | As a general comment, if you get compilation errors which you think 40 | are related to large file support, try removing the above define from 41 | the Makefile, ie, delete the line 42 | 43 | BIGFILES=-D_FILE_OFFSET_BITS=64 44 | 45 | from the Makefile, and do 'make clean ; make'. This will give you a 46 | version of bzip2 without large file support, which, for most 47 | applications, is probably not a problem. 48 | 49 | Alternatively, try some of the platform-specific hints listed below. 50 | 51 | You can use the spewG.c program to generate huge files to test bzip2's 52 | large file support, if you are feeling paranoid. Be aware though that 53 | any compilation problems which affect bzip2 will also affect spewG.c, 54 | alas. 55 | 56 | AIX: I have reports that for large file support, you need to specify 57 | -D_LARGE_FILES rather than -D_FILE_OFFSET_BITS=64. I have not tested 58 | this myself. 59 | -------------------------------------------------------------------------------- /README.XML.STUFF: -------------------------------------------------------------------------------- 1 | ---------------------------------------------------------------- 2 | This file is part of bzip2/libbzip2, a program and library for 3 | lossless, block-sorting data compression. 4 | 5 | bzip2/libbzip2 version 1.0.5 of 10 December 2007 6 | Copyright (C) 1996-2007 Julian Seward 7 | 8 | Please read the WARNING, DISCLAIMER and PATENTS sections in the 9 | README file. 10 | 11 | This program is released under the terms of the license contained 12 | in the file LICENSE. 13 | ---------------------------------------------------------------- 14 | 15 | The script xmlproc.sh takes an xml file as input, 16 | and processes it to create .pdf, .html or .ps output. 17 | It uses format.pl, a perl script to format
 blocks nicely,
18 |  and add CDATA tags so writers do not have to use eg. < 
19 | 
20 | The file "entities.xml" must be edited to reflect current
21 | version, year, etc.
22 | 
23 | 
24 | Usage:
25 | 
26 |   ./xmlproc.sh -v manual.xml
27 |   Validates an xml file to ensure no dtd-compliance errors
28 | 
29 |   ./xmlproc.sh -html manual.xml
30 |   Output: manual.html
31 | 
32 |   ./xmlproc.sh -pdf manual.xml
33 |   Output: manual.pdf
34 | 
35 |   ./xmlproc.sh -ps manual.xml
36 |   Output: manual.ps
37 | 
38 | 
39 | Notum bene: 
40 | - pdfxmltex barfs if given a filename with an underscore in it
41 | 
42 | - xmltex won't work yet - there's a bug in passivetex
43 |     which we are all waiting for Sebastian to fix.
44 |   So we are going the xml -> pdf -> ps route for the time being,
45 |     using pdfxmltex.
46 | 


--------------------------------------------------------------------------------
/bz-common.xsl:
--------------------------------------------------------------------------------
 1 |  
 2 | 
 4 | 
 5 | 
 6 |  
 7 | 
 8 | 
 9 | 
10 |  
11 |  
12 |    
13 |     
14 |       
15 |      
16 |   
17 | 
18 | 
19 | 
20 | 
21 | set       toc,title
22 | book      toc,title,figure,table,example,equation
23 | chapter   toc,title
24 | section   toc
25 | sect1     toc
26 | sect2     toc
27 | sect3     toc
28 | sect4     nop
29 | sect5     nop
30 | qandaset  toc
31 | qandadiv  nop
32 | appendix  toc,title
33 | article/appendix  nop
34 | article   toc,title
35 | preface   toc,title
36 | reference toc,title
37 | 
38 | 
39 | 
40 | 


--------------------------------------------------------------------------------
/bz-fo.xsl:
--------------------------------------------------------------------------------
  1 |  
  2 | 
  4 | 
  5 | 
  6 | 
  7 | 
  8 | 
  9 | 
 10 | 
 11 | 
 12 | 
 13 | 
 14 | 
 15 |       
 16 |      
 17 |    
 18 | 
 19 | 
 20 | 
 21 | 
 22 |  
 23 | 
 24 | 
 25 | 
 26 | 
 27 | 
 28 | 
 29 |   
 30 | 
 31 | 
 32 | 
 33 | 
 34 |   blue
 35 | 
 36 | 
 37 | 
 38 | 
 39 |   
 44 |     
 45 |   
 46 | 
 47 | 
 48 | 
 49 |   
 54 |     
 55 |   
 56 | 
 57 | 
 58 | 
 59 | 
 60 |   
 61 |   
 62 |   
 63 |     
 64 |       
 65 |     
 66 |   
 67 |   
 68 |     
 69 |       
 70 |         
 71 |           
 72 |           
 73 |           
 74 |         
 75 |       
 76 |     
 77 |     
 78 |           
 79 |     
 80 |   
 81 |   
 82 |     
 83 |       
 85 |         
 86 |       
 87 |     
 88 |     
 89 |       
 90 |         
 91 |       
 92 |     
 93 |   
 94 | 
 95 | 
 96 | 
 97 | 
 98 |   
 99 |   
100 |   
101 |     
102 |       
103 |         
104 |       
105 |     
106 |     
107 |           
108 |     
109 |   
110 |   
111 |     
112 |       
114 |         
115 |       
116 |     
117 |     
118 |       
119 |         
120 |       
121 |     
122 |   
123 | 
124 | 
125 | 
126 | 
127 | 
128 |   
129 |     
130 |   
133 |     
134 |   
135 |   
139 |     
140 |       
141 |     
142 |   
143 | 
144 | 
145 | 
146 | 
147 | 
148 |   
149 |   
150 |   
151 |   
152 |     
153 |       0pt
154 |     
155 |   
156 |   
157 |     
158 |       
159 |       
160 |       
161 |         
162 |           
163 |             baseline
164 |              
165 |                
166 |             
167 |           
168 |           
169 |             baseline
170 |             
171 |               
172 |                 
173 |                 
174 |                 
175 |                 
176 |               
177 |             
178 |           
179 |         
180 |       
181 |     
182 |   
183 |   
184 |   
185 |     
187 |       
188 |     
189 |     
190 |       
191 |     
192 |     
193 |       
194 |     
195 |   
196 | 
197 | 
198 | 
199 | 
200 | 
201 |   
202 |   
203 |   
204 |   
205 |     
206 |       0pt
207 |     
208 |   
209 |   
210 |     
211 |       
212 |         
213 |         
214 |         
215 |       
216 |       
217 |       
218 |       
219 |         
220 |           
221 |             baseline
222 |             
223 |                
224 |             
225 |           
226 |           
227 |             baseline
228 |             
229 |               
230 |                 
231 |                 
232 |                 
233 |                 
234 |               
235 |             
236 |           
237 |         
238 |       
239 |     
240 |   
241 |   
242 |   
243 |     
245 |       
246 |     
247 |     
248 |       
249 |     
250 |     
251 |       
252 |     
253 |   
254 | 
255 | 
256 | 
257 | 
258 | 
259 | 
260 |   always
261 |   
262 |     
263 |   
264 |   
265 |     
266 |     pt
267 |   
268 |   
269 |     
270 |     pt
271 |   
272 |   false
273 | 
274 | 
275 | 
276 | 
277 | 


--------------------------------------------------------------------------------
/bz-html.xsl:
--------------------------------------------------------------------------------
 1 |  
 2 |  ]>
 3 | 
 4 | 
 6 | 
 7 | 
 8 | 
 9 | 
10 | 
11 | 
12 | 
13 | 
14 |   
15 |   
18 | 
19 | 
20 | 
21 | 


--------------------------------------------------------------------------------
/bzdiff:
--------------------------------------------------------------------------------
 1 | #!/bin/sh
 2 | # sh is buggy on RS/6000 AIX 3.2. Replace above line with #!/bin/ksh
 3 | 
 4 | # Bzcmp/diff wrapped for bzip2, 
 5 | # adapted from zdiff by Philippe Troin  for Debian GNU/Linux.
 6 | 
 7 | # Bzcmp and bzdiff are used to invoke the cmp or the  diff  pro-
 8 | # gram  on compressed files.  All options specified are passed
 9 | # directly to cmp or diff.  If only 1 file is specified,  then
10 | # the  files  compared  are file1 and an uncompressed file1.gz.
11 | # If two files are specified, then they are  uncompressed  (if
12 | # necessary) and fed to cmp or diff.  The exit status from cmp
13 | # or diff is preserved.
14 | 
15 | PATH="/usr/bin:/bin:$PATH"; export PATH
16 | prog=`echo $0 | sed 's|.*/||'`
17 | case "$prog" in
18 |   *cmp) comp=${CMP-cmp}   ;;
19 |   *)    comp=${DIFF-diff} ;;
20 | esac
21 | 
22 | OPTIONS=
23 | FILES=
24 | for ARG
25 | do
26 |     case "$ARG" in
27 |     -*)	OPTIONS="$OPTIONS $ARG";;
28 |      *)	if test -f "$ARG"; then
29 |             FILES="$FILES $ARG"
30 |         else
31 |             echo "${prog}: $ARG not found or not a regular file"
32 | 	    exit 1
33 |         fi ;;
34 |     esac
35 | done
36 | if test -z "$FILES"; then
37 | 	echo "Usage: $prog [${comp}_options] file [file]"
38 | 	exit 1
39 | fi
40 | tmp=`mktemp ${TMPDIR:-/tmp}/bzdiff.XXXXXXXXXX` || {
41 |       echo 'cannot create a temporary file' >&2
42 |       exit 1
43 | }
44 | set $FILES
45 | if test $# -eq 1; then
46 | 	FILE=`echo "$1" | sed 's/.bz2$//'`
47 | 	bzip2 -cd "$FILE.bz2" | $comp $OPTIONS - "$FILE"
48 | 	STAT="$?"
49 | 
50 | elif test $# -eq 2; then
51 | 	case "$1" in
52 |         *.bz2)
53 |                 case "$2" in
54 | 	        *.bz2)
55 | 			F=`echo "$2" | sed 's|.*/||;s|.bz2$||'`
56 |                         bzip2 -cdfq "$2" > $tmp
57 |                         bzip2 -cdfq "$1" | $comp $OPTIONS - $tmp
58 |                         STAT="$?"
59 | 			/bin/rm -f $tmp;;
60 | 
61 |                 *)      bzip2 -cdfq "$1" | $comp $OPTIONS - "$2"
62 |                         STAT="$?";;
63 |                 esac;;
64 |         *)      case "$2" in
65 | 	        *.bz2)
66 |                         bzip2 -cdfq "$2" | $comp $OPTIONS "$1" -
67 |                         STAT="$?";;
68 |                 *)      $comp $OPTIONS "$1" "$2"
69 |                         STAT="$?";;
70 |                 esac;;
71 | 	esac
72 |         exit "$STAT"
73 | else
74 | 	echo "Usage: $prog [${comp}_options] file [file]"
75 | 	exit 1
76 | fi
77 | 


--------------------------------------------------------------------------------
/bzdiff.1:
--------------------------------------------------------------------------------
 1 | \"Shamelessly copied from zmore.1 by Philippe Troin 
 2 | \"for Debian GNU/Linux
 3 | .TH BZDIFF 1
 4 | .SH NAME
 5 | bzcmp, bzdiff \- compare bzip2 compressed files
 6 | .SH SYNOPSIS
 7 | .B bzcmp
 8 | [ cmp_options ] file1
 9 | [ file2 ]
10 | .br
11 | .B bzdiff
12 | [ diff_options ] file1
13 | [ file2 ]
14 | .SH DESCRIPTION
15 | .I  Bzcmp
16 | and 
17 | .I bzdiff
18 | are used to invoke the
19 | .I cmp
20 | or the
21 | .I diff
22 | program on bzip2 compressed files.  All options specified are passed
23 | directly to
24 | .I cmp
25 | or
26 | .IR diff "."
27 | If only 1 file is specified, then the files compared are
28 | .I file1
29 | and an uncompressed
30 | .IR file1 ".bz2."
31 | If two files are specified, then they are uncompressed if necessary and fed to
32 | .I cmp
33 | or
34 | .IR diff "."
35 | The exit status from 
36 | .I cmp
37 | or
38 | .I diff
39 | is preserved.
40 | .SH "SEE ALSO"
41 | cmp(1), diff(1), bzmore(1), bzless(1), bzgrep(1), bzip2(1)
42 | .SH BUGS
43 | Messages from the
44 | .I cmp
45 | or
46 | .I diff
47 | programs refer to temporary filenames instead of those specified.
48 | 


--------------------------------------------------------------------------------
/bzgrep:
--------------------------------------------------------------------------------
 1 | #!/bin/sh
 2 | 
 3 | # Bzgrep wrapped for bzip2, 
 4 | # adapted from zgrep by Philippe Troin  for Debian GNU/Linux.
 5 | ## zgrep notice:
 6 | ## zgrep -- a wrapper around a grep program that decompresses files as needed
 7 | ## Adapted from a version sent by Charles Levert 
 8 | 
 9 | PATH="/usr/bin:$PATH"; export PATH
10 | 
11 | prog=`echo $0 | sed 's|.*/||'`
12 | case "$prog" in
13 | 	*egrep)	grep=${EGREP-egrep}	;;
14 | 	*fgrep)	grep=${FGREP-fgrep}	;;
15 | 	*)	grep=${GREP-grep}	;;
16 | esac
17 | pat=""
18 | while test $# -ne 0; do
19 |   case "$1" in
20 |   -e | -f) opt="$opt $1"; shift; pat="$1"
21 |            if test "$grep" = grep; then  # grep is buggy with -e on SVR4
22 |              grep=egrep
23 |            fi;;
24 |   -A | -B) opt="$opt $1 $2"; shift;;
25 |   -*)	   opt="$opt $1";;
26 |    *)      if test -z "$pat"; then
27 | 	     pat="$1"
28 | 	   else
29 | 	     break;
30 |            fi;;
31 |   esac
32 |   shift
33 | done
34 | 
35 | if test -z "$pat"; then
36 |   echo "grep through bzip2 files"
37 |   echo "usage: $prog [grep_options] pattern [files]"
38 |   exit 1
39 | fi
40 | 
41 | list=0
42 | silent=0
43 | op=`echo "$opt" | sed -e 's/ //g' -e 's/-//g'`
44 | case "$op" in
45 |   *l*) list=1
46 | esac
47 | case "$op" in
48 |   *h*) silent=1
49 | esac
50 | 
51 | if test $# -eq 0; then
52 |   bzip2 -cdfq | $grep $opt "$pat"
53 |   exit $?
54 | fi
55 | 
56 | res=0
57 | for i do
58 |   if test -f "$i"; then :; else if test -f "$i.bz2"; then i="$i.bz2"; fi; fi
59 |   if test $list -eq 1; then
60 |     bzip2 -cdfq "$i" | $grep $opt "$pat" 2>&1 > /dev/null && echo $i
61 |     r=$?
62 |   elif test $# -eq 1 -o $silent -eq 1; then
63 |     bzip2 -cdfq "$i" | $grep $opt "$pat"
64 |     r=$?
65 |   else
66 |     j=${i//\\/\\\\}
67 |     j=${j//|/\\|}
68 |     j=${j//&/\\&}
69 |     j=`printf "%s" "$j" | tr '\n' ' '`
70 |     bzip2 -cdfq "$i" | $grep $opt "$pat" | sed "s|^|${j}:|"
71 |     r=$?
72 |   fi
73 |   test "$r" -ne 0 && res="$r"
74 | done
75 | exit $res
76 | 


--------------------------------------------------------------------------------
/bzgrep.1:
--------------------------------------------------------------------------------
 1 | \"Shamelessly copied from zmore.1 by Philippe Troin 
 2 | \"for Debian GNU/Linux
 3 | .TH BZGREP 1
 4 | .SH NAME
 5 | bzgrep, bzfgrep, bzegrep \- search possibly bzip2 compressed files for a regular expression
 6 | .SH SYNOPSIS
 7 | .B bzgrep
 8 | [ grep_options ]
 9 | .BI  [\ -e\ ] " pattern"
10 | .IR filename ".\|.\|."
11 | .br
12 | .B bzegrep
13 | [ egrep_options ]
14 | .BI  [\ -e\ ] " pattern"
15 | .IR filename ".\|.\|."
16 | .br
17 | .B bzfgrep
18 | [ fgrep_options ]
19 | .BI  [\ -e\ ] " pattern"
20 | .IR filename ".\|.\|."
21 | .SH DESCRIPTION
22 | .IR  Bzgrep
23 | is used to invoke the
24 | .I grep
25 | on bzip2-compressed files. All options specified are passed directly to
26 | .I grep.
27 | If no file is specified, then the standard input is decompressed
28 | if necessary and fed to grep.
29 | Otherwise the given files are uncompressed if necessary and fed to
30 | .I grep.
31 | .PP
32 | If
33 | .I bzgrep
34 | is invoked as
35 | .I bzegrep
36 | or
37 | .I bzfgrep
38 | then
39 | .I egrep
40 | or
41 | .I fgrep
42 | is used instead of
43 | .I grep.
44 | If the GREP environment variable is set,
45 | .I bzgrep
46 | uses it as the
47 | .I grep
48 | program to be invoked. For example:
49 | 
50 |     for sh:  GREP=fgrep  bzgrep string files
51 |     for csh: (setenv GREP fgrep; bzgrep string files)
52 | .SH AUTHOR
53 | Charles Levert (charles@comm.polymtl.ca). Adapted to bzip2 by Philippe
54 | Troin  for Debian GNU/Linux.
55 | .SH "SEE ALSO"
56 | grep(1), egrep(1), fgrep(1), bzdiff(1), bzmore(1), bzless(1), bzip2(1)
57 | 


--------------------------------------------------------------------------------
/bzip.css:
--------------------------------------------------------------------------------
 1 | /* Colours:
 2 | #74240f  dark brown      h1, h2, h3, h4
 3 | #336699  medium blue     links
 4 | #339999  turquoise       link hover colour
 5 | #202020  almost black    general text
 6 | #761596  purple          md5sum text
 7 | #626262  dark gray       pre border
 8 | #eeeeee  very light gray pre background
 9 | #f2f2f9  very light blue nav table background
10 | #3366cc  medium blue     nav table border
11 | */
12 | 
13 | a, a:link, a:visited, a:active { color: #336699; }
14 | a:hover { color: #339999; }
15 | 
16 | body { font: 80%/126% sans-serif; }
17 | h1, h2, h3, h4 { color: #74240f; }
18 | 
19 | dt { color: #336699; font-weight: bold }
20 | dd { 
21 |  margin-left: 1.5em; 
22 |  padding-bottom: 0.8em;
23 | }
24 | 
25 | /* -- ruler -- */
26 | div.hr_blue { 
27 |   height:  3px; 
28 |   background:#ffffff url("/images/hr_blue.png") repeat-x; }
29 | div.hr_blue hr { display:none; }
30 | 
31 | /* release styles */
32 | #release p { margin-top: 0.4em; }
33 | #release .md5sum { color: #761596; }
34 | 
35 | 
36 | /* ------ styles for docs|manuals|howto ------ */
37 | /* -- lists -- */
38 | ul  { 
39 |  margin:     0px 4px 16px 16px;
40 |  padding:    0px;
41 |  list-style: url("/images/li-blue.png"); 
42 | }
43 | ul li { 
44 |  margin-bottom: 10px;
45 | }
46 | ul ul	{ 
47 |  list-style-type:  none; 
48 |  list-style-image: none; 
49 |  margin-left:      0px; 
50 | }
51 | 
52 | /* header / footer nav tables */
53 | table.nav {
54 |  border:     solid 1px #3366cc;
55 |  background: #f2f2f9;
56 |  background-color: #f2f2f9;
57 |  margin-bottom: 0.5em;
58 | }
59 | /* don't have underlined links in chunked nav menus */
60 | table.nav a { text-decoration: none; }
61 | table.nav a:hover { text-decoration: underline; }
62 | table.nav td { font-size: 85%; }
63 | 
64 | code, tt, pre { font-size: 120%; }
65 | code, tt { color: #761596; }
66 | 
67 | div.literallayout, pre.programlisting, pre.screen {
68 |  color:      #000000;
69 |  padding:    0.5em;
70 |  background: #eeeeee;
71 |  border:     1px solid #626262;
72 |  background-color: #eeeeee;
73 |  margin: 4px 0px 4px 0px; 
74 | }
75 | 


--------------------------------------------------------------------------------
/bzip2.1:
--------------------------------------------------------------------------------
  1 | .PU
  2 | .TH bzip2 1
  3 | .SH NAME
  4 | bzip2, bunzip2 \- a block-sorting file compressor, v1.0.4
  5 | .br
  6 | bzcat \- decompresses files to stdout
  7 | .br
  8 | bzip2recover \- recovers data from damaged bzip2 files
  9 | 
 10 | .SH SYNOPSIS
 11 | .ll +8
 12 | .B bzip2
 13 | .RB [ " \-cdfkqstvzVL123456789 " ]
 14 | [
 15 | .I "filenames \&..."
 16 | ]
 17 | .ll -8
 18 | .br
 19 | .B bunzip2
 20 | .RB [ " \-fkvsVL " ]
 21 | [ 
 22 | .I "filenames \&..."
 23 | ]
 24 | .br
 25 | .B bzcat
 26 | .RB [ " \-s " ]
 27 | [ 
 28 | .I "filenames \&..."
 29 | ]
 30 | .br
 31 | .B bzip2recover
 32 | .I "filename"
 33 | 
 34 | .SH DESCRIPTION
 35 | .I bzip2
 36 | compresses files using the Burrows-Wheeler block sorting
 37 | text compression algorithm, and Huffman coding.  Compression is
 38 | generally considerably better than that achieved by more conventional
 39 | LZ77/LZ78-based compressors, and approaches the performance of the PPM
 40 | family of statistical compressors.
 41 | 
 42 | The command-line options are deliberately very similar to 
 43 | those of 
 44 | .I GNU gzip, 
 45 | but they are not identical.
 46 | 
 47 | .I bzip2
 48 | expects a list of file names to accompany the
 49 | command-line flags.  Each file is replaced by a compressed version of
 50 | itself, with the name "original_name.bz2".  
 51 | Each compressed file
 52 | has the same modification date, permissions, and, when possible,
 53 | ownership as the corresponding original, so that these properties can
 54 | be correctly restored at decompression time.  File name handling is
 55 | naive in the sense that there is no mechanism for preserving original
 56 | file names, permissions, ownerships or dates in filesystems which lack
 57 | these concepts, or have serious file name length restrictions, such as
 58 | MS-DOS.
 59 | 
 60 | .I bzip2
 61 | and
 62 | .I bunzip2
 63 | will by default not overwrite existing
 64 | files.  If you want this to happen, specify the \-f flag.
 65 | 
 66 | If no file names are specified,
 67 | .I bzip2
 68 | compresses from standard
 69 | input to standard output.  In this case,
 70 | .I bzip2
 71 | will decline to
 72 | write compressed output to a terminal, as this would be entirely
 73 | incomprehensible and therefore pointless.
 74 | 
 75 | .I bunzip2
 76 | (or
 77 | .I bzip2 \-d) 
 78 | decompresses all
 79 | specified files.  Files which were not created by 
 80 | .I bzip2
 81 | will be detected and ignored, and a warning issued.  
 82 | .I bzip2
 83 | attempts to guess the filename for the decompressed file 
 84 | from that of the compressed file as follows:
 85 | 
 86 |        filename.bz2    becomes   filename
 87 |        filename.bz     becomes   filename
 88 |        filename.tbz2   becomes   filename.tar
 89 |        filename.tbz    becomes   filename.tar
 90 |        anyothername    becomes   anyothername.out
 91 | 
 92 | If the file does not end in one of the recognised endings, 
 93 | .I .bz2, 
 94 | .I .bz, 
 95 | .I .tbz2
 96 | or
 97 | .I .tbz, 
 98 | .I bzip2 
 99 | complains that it cannot
100 | guess the name of the original file, and uses the original name
101 | with
102 | .I .out
103 | appended.
104 | 
105 | As with compression, supplying no
106 | filenames causes decompression from 
107 | standard input to standard output.
108 | 
109 | .I bunzip2 
110 | will correctly decompress a file which is the
111 | concatenation of two or more compressed files.  The result is the
112 | concatenation of the corresponding uncompressed files.  Integrity
113 | testing (\-t) 
114 | of concatenated 
115 | compressed files is also supported.
116 | 
117 | You can also compress or decompress files to the standard output by
118 | giving the \-c flag.  Multiple files may be compressed and
119 | decompressed like this.  The resulting outputs are fed sequentially to
120 | stdout.  Compression of multiple files 
121 | in this manner generates a stream
122 | containing multiple compressed file representations.  Such a stream
123 | can be decompressed correctly only by
124 | .I bzip2 
125 | version 0.9.0 or
126 | later.  Earlier versions of
127 | .I bzip2
128 | will stop after decompressing
129 | the first file in the stream.
130 | 
131 | .I bzcat
132 | (or
133 | .I bzip2 -dc) 
134 | decompresses all specified files to
135 | the standard output.
136 | 
137 | .I bzip2
138 | will read arguments from the environment variables
139 | .I BZIP2
140 | and
141 | .I BZIP,
142 | in that order, and will process them
143 | before any arguments read from the command line.  This gives a 
144 | convenient way to supply default arguments.
145 | 
146 | Compression is always performed, even if the compressed 
147 | file is slightly
148 | larger than the original.  Files of less than about one hundred bytes
149 | tend to get larger, since the compression mechanism has a constant
150 | overhead in the region of 50 bytes.  Random data (including the output
151 | of most file compressors) is coded at about 8.05 bits per byte, giving
152 | an expansion of around 0.5%.
153 | 
154 | As a self-check for your protection, 
155 | .I 
156 | bzip2
157 | uses 32-bit CRCs to
158 | make sure that the decompressed version of a file is identical to the
159 | original.  This guards against corruption of the compressed data, and
160 | against undetected bugs in
161 | .I bzip2
162 | (hopefully very unlikely).  The
163 | chances of data corruption going undetected is microscopic, about one
164 | chance in four billion for each file processed.  Be aware, though, that
165 | the check occurs upon decompression, so it can only tell you that
166 | something is wrong.  It can't help you 
167 | recover the original uncompressed
168 | data.  You can use 
169 | .I bzip2recover
170 | to try to recover data from
171 | damaged files.
172 | 
173 | Return values: 0 for a normal exit, 1 for environmental problems (file
174 | not found, invalid flags, I/O errors, &c), 2 to indicate a corrupt
175 | compressed file, 3 for an internal consistency error (eg, bug) which
176 | caused
177 | .I bzip2
178 | to panic.
179 | 
180 | .SH OPTIONS
181 | .TP
182 | .B \-c --stdout
183 | Compress or decompress to standard output.
184 | .TP
185 | .B \-d --decompress
186 | Force decompression.  
187 | .I bzip2, 
188 | .I bunzip2 
189 | and
190 | .I bzcat 
191 | are
192 | really the same program, and the decision about what actions to take is
193 | done on the basis of which name is used.  This flag overrides that
194 | mechanism, and forces 
195 | .I bzip2
196 | to decompress.
197 | .TP
198 | .B \-z --compress
199 | The complement to \-d: forces compression, regardless of the
200 | invocation name.
201 | .TP
202 | .B \-t --test
203 | Check integrity of the specified file(s), but don't decompress them.
204 | This really performs a trial decompression and throws away the result.
205 | .TP
206 | .B \-f --force
207 | Force overwrite of output files.  Normally,
208 | .I bzip2 
209 | will not overwrite
210 | existing output files.  Also forces 
211 | .I bzip2 
212 | to break hard links
213 | to files, which it otherwise wouldn't do.
214 | 
215 | bzip2 normally declines to decompress files which don't have the
216 | correct magic header bytes.  If forced (-f), however, it will pass
217 | such files through unmodified.  This is how GNU gzip behaves.
218 | .TP
219 | .B \-k --keep
220 | Keep (don't delete) input files during compression
221 | or decompression.
222 | .TP
223 | .B \-s --small
224 | Reduce memory usage, for compression, decompression and testing.  Files
225 | are decompressed and tested using a modified algorithm which only
226 | requires 2.5 bytes per block byte.  This means any file can be
227 | decompressed in 2300k of memory, albeit at about half the normal speed.
228 | 
229 | During compression, \-s selects a block size of 200k, which limits
230 | memory use to around the same figure, at the expense of your compression
231 | ratio.  In short, if your machine is low on memory (8 megabytes or
232 | less), use \-s for everything.  See MEMORY MANAGEMENT below.
233 | .TP
234 | .B \-q --quiet
235 | Suppress non-essential warning messages.  Messages pertaining to
236 | I/O errors and other critical events will not be suppressed.
237 | .TP
238 | .B \-v --verbose
239 | Verbose mode -- show the compression ratio for each file processed.
240 | Further \-v's increase the verbosity level, spewing out lots of
241 | information which is primarily of interest for diagnostic purposes.
242 | .TP
243 | .B \-L --license -V --version
244 | Display the software version, license terms and conditions.
245 | .TP
246 | .B \-1 (or \-\-fast) to \-9 (or \-\-best)
247 | Set the block size to 100 k, 200 k ..  900 k when compressing.  Has no
248 | effect when decompressing.  See MEMORY MANAGEMENT below.
249 | The \-\-fast and \-\-best aliases are primarily for GNU gzip 
250 | compatibility.  In particular, \-\-fast doesn't make things
251 | significantly faster.  
252 | And \-\-best merely selects the default behaviour.
253 | .TP
254 | .B \--
255 | Treats all subsequent arguments as file names, even if they start
256 | with a dash.  This is so you can handle files with names beginning
257 | with a dash, for example: bzip2 \-- \-myfilename.
258 | .TP
259 | .B \--repetitive-fast --repetitive-best
260 | These flags are redundant in versions 0.9.5 and above.  They provided
261 | some coarse control over the behaviour of the sorting algorithm in
262 | earlier versions, which was sometimes useful.  0.9.5 and above have an
263 | improved algorithm which renders these flags irrelevant.
264 | 
265 | .SH MEMORY MANAGEMENT
266 | .I bzip2 
267 | compresses large files in blocks.  The block size affects
268 | both the compression ratio achieved, and the amount of memory needed for
269 | compression and decompression.  The flags \-1 through \-9
270 | specify the block size to be 100,000 bytes through 900,000 bytes (the
271 | default) respectively.  At decompression time, the block size used for
272 | compression is read from the header of the compressed file, and
273 | .I bunzip2
274 | then allocates itself just enough memory to decompress
275 | the file.  Since block sizes are stored in compressed files, it follows
276 | that the flags \-1 to \-9 are irrelevant to and so ignored
277 | during decompression.
278 | 
279 | Compression and decompression requirements, 
280 | in bytes, can be estimated as:
281 | 
282 |        Compression:   400k + ( 8 x block size )
283 | 
284 |        Decompression: 100k + ( 4 x block size ), or
285 |                       100k + ( 2.5 x block size )
286 | 
287 | Larger block sizes give rapidly diminishing marginal returns.  Most of
288 | the compression comes from the first two or three hundred k of block
289 | size, a fact worth bearing in mind when using
290 | .I bzip2
291 | on small machines.
292 | It is also important to appreciate that the decompression memory
293 | requirement is set at compression time by the choice of block size.
294 | 
295 | For files compressed with the default 900k block size,
296 | .I bunzip2
297 | will require about 3700 kbytes to decompress.  To support decompression
298 | of any file on a 4 megabyte machine, 
299 | .I bunzip2
300 | has an option to
301 | decompress using approximately half this amount of memory, about 2300
302 | kbytes.  Decompression speed is also halved, so you should use this
303 | option only where necessary.  The relevant flag is -s.
304 | 
305 | In general, try and use the largest block size memory constraints allow,
306 | since that maximises the compression achieved.  Compression and
307 | decompression speed are virtually unaffected by block size.
308 | 
309 | Another significant point applies to files which fit in a single block
310 | -- that means most files you'd encounter using a large block size.  The
311 | amount of real memory touched is proportional to the size of the file,
312 | since the file is smaller than a block.  For example, compressing a file
313 | 20,000 bytes long with the flag -9 will cause the compressor to
314 | allocate around 7600k of memory, but only touch 400k + 20000 * 8 = 560
315 | kbytes of it.  Similarly, the decompressor will allocate 3700k but only
316 | touch 100k + 20000 * 4 = 180 kbytes.
317 | 
318 | Here is a table which summarises the maximum memory usage for different
319 | block sizes.  Also recorded is the total compressed size for 14 files of
320 | the Calgary Text Compression Corpus totalling 3,141,622 bytes.  This
321 | column gives some feel for how compression varies with block size.
322 | These figures tend to understate the advantage of larger block sizes for
323 | larger files, since the Corpus is dominated by smaller files.
324 | 
325 |            Compress   Decompress   Decompress   Corpus
326 |     Flag     usage      usage       -s usage     Size
327 | 
328 |      -1      1200k       500k         350k      914704
329 |      -2      2000k       900k         600k      877703
330 |      -3      2800k      1300k         850k      860338
331 |      -4      3600k      1700k        1100k      846899
332 |      -5      4400k      2100k        1350k      845160
333 |      -6      5200k      2500k        1600k      838626
334 |      -7      6100k      2900k        1850k      834096
335 |      -8      6800k      3300k        2100k      828642
336 |      -9      7600k      3700k        2350k      828642
337 | 
338 | .SH RECOVERING DATA FROM DAMAGED FILES
339 | .I bzip2
340 | compresses files in blocks, usually 900kbytes long.  Each
341 | block is handled independently.  If a media or transmission error causes
342 | a multi-block .bz2
343 | file to become damaged, it may be possible to
344 | recover data from the undamaged blocks in the file.
345 | 
346 | The compressed representation of each block is delimited by a 48-bit
347 | pattern, which makes it possible to find the block boundaries with
348 | reasonable certainty.  Each block also carries its own 32-bit CRC, so
349 | damaged blocks can be distinguished from undamaged ones.
350 | 
351 | .I bzip2recover
352 | is a simple program whose purpose is to search for
353 | blocks in .bz2 files, and write each block out into its own .bz2 
354 | file.  You can then use
355 | .I bzip2 
356 | \-t
357 | to test the
358 | integrity of the resulting files, and decompress those which are
359 | undamaged.
360 | 
361 | .I bzip2recover
362 | takes a single argument, the name of the damaged file, 
363 | and writes a number of files "rec00001file.bz2",
364 | "rec00002file.bz2", etc, containing the  extracted  blocks.
365 | The  output  filenames  are  designed  so  that the use of
366 | wildcards in subsequent processing -- for example,  
367 | "bzip2 -dc  rec*file.bz2 > recovered_data" -- processes the files in
368 | the correct order.
369 | 
370 | .I bzip2recover
371 | should be of most use dealing with large .bz2
372 | files,  as  these will contain many blocks.  It is clearly
373 | futile to use it on damaged single-block  files,  since  a
374 | damaged  block  cannot  be recovered.  If you wish to minimise 
375 | any potential data loss through media  or  transmission errors, 
376 | you might consider compressing with a smaller
377 | block size.
378 | 
379 | .SH PERFORMANCE NOTES
380 | The sorting phase of compression gathers together similar strings in the
381 | file.  Because of this, files containing very long runs of repeated
382 | symbols, like "aabaabaabaab ..."  (repeated several hundred times) may
383 | compress more slowly than normal.  Versions 0.9.5 and above fare much
384 | better than previous versions in this respect.  The ratio between
385 | worst-case and average-case compression time is in the region of 10:1.
386 | For previous versions, this figure was more like 100:1.  You can use the
387 | \-vvvv option to monitor progress in great detail, if you want.
388 | 
389 | Decompression speed is unaffected by these phenomena.
390 | 
391 | .I bzip2
392 | usually allocates several megabytes of memory to operate
393 | in, and then charges all over it in a fairly random fashion.  This means
394 | that performance, both for compressing and decompressing, is largely
395 | determined by the speed at which your machine can service cache misses.
396 | Because of this, small changes to the code to reduce the miss rate have
397 | been observed to give disproportionately large performance improvements.
398 | I imagine 
399 | .I bzip2
400 | will perform best on machines with very large caches.
401 | 
402 | .SH CAVEATS
403 | I/O error messages are not as helpful as they could be.
404 | .I bzip2
405 | tries hard to detect I/O errors and exit cleanly, but the details of
406 | what the problem is sometimes seem rather misleading.
407 | 
408 | This manual page pertains to version 1.0.4 of
409 | .I bzip2.  
410 | Compressed data created by this version is entirely forwards and
411 | backwards compatible with the previous public releases, versions
412 | 0.1pl2, 0.9.0, 0.9.5, 1.0.0, 1.0.1, 1.0.2 and 1.0.3, but with the following
413 | exception: 0.9.0 and above can correctly decompress multiple
414 | concatenated compressed files.  0.1pl2 cannot do this; it will stop
415 | after decompressing just the first file in the stream.
416 | 
417 | .I bzip2recover
418 | versions prior to 1.0.2 used 32-bit integers to represent
419 | bit positions in compressed files, so they could not handle compressed
420 | files more than 512 megabytes long.  Versions 1.0.2 and above use
421 | 64-bit ints on some platforms which support them (GNU supported
422 | targets, and Windows).  To establish whether or not bzip2recover was
423 | built with such a limitation, run it without arguments.  In any event
424 | you can build yourself an unlimited version if you can recompile it
425 | with MaybeUInt64 set to be an unsigned 64-bit integer.
426 | 
427 | 
428 | 
429 | .SH AUTHOR
430 | Julian Seward, jsewardbzip.org.
431 | 
432 | http://www.bzip.org
433 | 
434 | The ideas embodied in
435 | .I bzip2
436 | are due to (at least) the following
437 | people: Michael Burrows and David Wheeler (for the block sorting
438 | transformation), David Wheeler (again, for the Huffman coder), Peter
439 | Fenwick (for the structured coding model in the original
440 | .I bzip,
441 | and many refinements), and Alistair Moffat, Radford Neal and Ian Witten
442 | (for the arithmetic coder in the original
443 | .I bzip).  
444 | I am much
445 | indebted for their help, support and advice.  See the manual in the
446 | source distribution for pointers to sources of documentation.  Christian
447 | von Roques encouraged me to look for faster sorting algorithms, so as to
448 | speed up compression.  Bela Lubkin encouraged me to improve the
449 | worst-case compression performance.  
450 | Donna Robinson XMLised the documentation.
451 | The bz* scripts are derived from those of GNU gzip.
452 | Many people sent patches, helped
453 | with portability problems, lent machines, gave advice and were generally
454 | helpful.
455 | 


--------------------------------------------------------------------------------
/bzip2.1.preformatted:
--------------------------------------------------------------------------------
  1 | bzip2(1)                                                 bzip2(1)
  2 | 
  3 | 
  4 | 
  5 | NNAAMMEE
  6 |        bzip2, bunzip2 − a block‐sorting file compressor, v1.0.4
  7 |        bzcat − decompresses files to stdout
  8 |        bzip2recover − recovers data from damaged bzip2 files
  9 | 
 10 | 
 11 | SSYYNNOOPPSSIISS
 12 |        bbzziipp22 [ −−ccddffkkqqssttvvzzVVLL112233445566778899 ] [ _f_i_l_e_n_a_m_e_s _._._.  ]
 13 |        bbuunnzziipp22 [ −−ffkkvvssVVLL ] [ _f_i_l_e_n_a_m_e_s _._._.  ]
 14 |        bbzzccaatt [ −−ss ] [ _f_i_l_e_n_a_m_e_s _._._.  ]
 15 |        bbzziipp22rreeccoovveerr _f_i_l_e_n_a_m_e
 16 | 
 17 | 
 18 | DDEESSCCRRIIPPTTIIOONN
 19 |        _b_z_i_p_2  compresses  files  using  the Burrows‐Wheeler block
 20 |        sorting text compression algorithm,  and  Huffman  coding.
 21 |        Compression  is  generally  considerably  better than that
 22 |        achieved by more conventional LZ77/LZ78‐based compressors,
 23 |        and  approaches  the performance of the PPM family of sta­
 24 |        tistical compressors.
 25 | 
 26 |        The command‐line options are deliberately very similar  to
 27 |        those of _G_N_U _g_z_i_p_, but they are not identical.
 28 | 
 29 |        _b_z_i_p_2  expects  a list of file names to accompany the com­
 30 |        mand‐line flags.  Each file is replaced  by  a  compressed
 31 |        version  of  itself,  with  the  name "original_name.bz2".
 32 |        Each compressed file has the same modification date,  per­
 33 |        missions, and, when possible, ownership as the correspond­
 34 |        ing original, so that these properties  can  be  correctly
 35 |        restored  at  decompression  time.   File name handling is
 36 |        naive in the sense that there is no mechanism for preserv­
 37 |        ing  original file names, permissions, ownerships or dates
 38 |        in filesystems which lack these concepts, or have  serious
 39 |        file name length restrictions, such as MS‐DOS.
 40 | 
 41 |        _b_z_i_p_2  and  _b_u_n_z_i_p_2 will by default not overwrite existing
 42 |        files.  If you want this to happen, specify the −f flag.
 43 | 
 44 |        If no file names  are  specified,  _b_z_i_p_2  compresses  from
 45 |        standard  input  to  standard output.  In this case, _b_z_i_p_2
 46 |        will decline to write compressed output to a terminal,  as
 47 |        this  would  be  entirely  incomprehensible  and therefore
 48 |        pointless.
 49 | 
 50 |        _b_u_n_z_i_p_2 (or _b_z_i_p_2 _−_d_) decompresses  all  specified  files.
 51 |        Files which were not created by _b_z_i_p_2 will be detected and
 52 |        ignored, and a warning issued.  _b_z_i_p_2  attempts  to  guess
 53 |        the  filename  for  the decompressed file from that of the
 54 |        compressed file as follows:
 55 | 
 56 |               filename.bz2    becomes   filename
 57 |               filename.bz     becomes   filename
 58 |               filename.tbz2   becomes   filename.tar
 59 |               filename.tbz    becomes   filename.tar
 60 |               anyothername    becomes   anyothername.out
 61 | 
 62 |        If the file does not end in one of the recognised endings,
 63 |        _._b_z_2_,  _._b_z_,  _._t_b_z_2 or _._t_b_z_, _b_z_i_p_2 complains that it cannot
 64 |        guess the name of the original file, and uses the original
 65 |        name with _._o_u_t appended.
 66 | 
 67 |        As  with compression, supplying no filenames causes decom­
 68 |        pression from standard input to standard output.
 69 | 
 70 |        _b_u_n_z_i_p_2 will correctly decompress a file which is the con­
 71 |        catenation of two or more compressed files.  The result is
 72 |        the concatenation of the corresponding uncompressed files.
 73 |        Integrity testing (−t) of concatenated compressed files is
 74 |        also supported.
 75 | 
 76 |        You can also compress or decompress files to the  standard
 77 |        output  by giving the −c flag.  Multiple files may be com­
 78 |        pressed and decompressed like this.  The resulting outputs
 79 |        are  fed  sequentially to stdout.  Compression of multiple
 80 |        files in this manner generates a stream containing  multi­
 81 |        ple compressed file representations.  Such a stream can be
 82 |        decompressed correctly only  by  _b_z_i_p_2  version  0.9.0  or
 83 |        later.   Earlier  versions of _b_z_i_p_2 will stop after decom­
 84 |        pressing the first file in the stream.
 85 | 
 86 |        _b_z_c_a_t (or _b_z_i_p_2 _‐_d_c_) decompresses all specified  files  to
 87 |        the standard output.
 88 | 
 89 |        _b_z_i_p_2  will  read arguments from the environment variables
 90 |        _B_Z_I_P_2 and _B_Z_I_P_, in  that  order,  and  will  process  them
 91 |        before  any  arguments  read  from the command line.  This
 92 |        gives a convenient way to supply default arguments.
 93 | 
 94 |        Compression is always performed, even  if  the  compressed
 95 |        file  is slightly larger than the original.  Files of less
 96 |        than about one hundred bytes tend to get larger, since the
 97 |        compression  mechanism  has  a  constant  overhead  in the
 98 |        region of 50 bytes.  Random data (including the output  of
 99 |        most  file  compressors)  is  coded at about 8.05 bits per
100 |        byte, giving an expansion of around 0.5%.
101 | 
102 |        As a self‐check for your  protection,  _b_z_i_p_2  uses  32‐bit
103 |        CRCs  to make sure that the decompressed version of a file
104 |        is identical to the original.  This guards against corrup­
105 |        tion  of  the compressed data, and against undetected bugs
106 |        in _b_z_i_p_2 (hopefully very unlikely).  The chances  of  data
107 |        corruption  going  undetected  is  microscopic,  about one
108 |        chance in four billion for each file processed.  Be aware,
109 |        though,  that  the  check occurs upon decompression, so it
110 |        can only tell you that something is wrong.  It can’t  help
111 |        you  recover  the original uncompressed data.  You can use
112 |        _b_z_i_p_2_r_e_c_o_v_e_r to try to recover data from damaged files.
113 | 
114 |        Return values: 0 for a normal exit,  1  for  environmental
115 |        problems  (file not found, invalid flags, I/O errors, &c),
116 |        2 to indicate a corrupt compressed file, 3 for an internal
117 |        consistency error (eg, bug) which caused _b_z_i_p_2 to panic.
118 | 
119 | 
120 | OOPPTTIIOONNSS
121 |        −−cc ‐‐‐‐ssttddoouutt
122 |               Compress or decompress to standard output.
123 | 
124 |        −−dd ‐‐‐‐ddeeccoommpprreessss
125 |               Force  decompression.  _b_z_i_p_2_, _b_u_n_z_i_p_2 and _b_z_c_a_t are
126 |               really the same program,  and  the  decision  about
127 |               what  actions to take is done on the basis of which
128 |               name is used.  This flag overrides that  mechanism,
129 |               and forces _b_z_i_p_2 to decompress.
130 | 
131 |        −−zz ‐‐‐‐ccoommpprreessss
132 |               The   complement   to   −d:   forces   compression,
133 |               regardless of the invocation name.
134 | 
135 |        −−tt ‐‐‐‐tteesstt
136 |               Check integrity of the specified file(s), but don’t
137 |               decompress  them.   This  really  performs  a trial
138 |               decompression and throws away the result.
139 | 
140 |        −−ff ‐‐‐‐ffoorrccee
141 |               Force overwrite of output files.   Normally,  _b_z_i_p_2
142 |               will  not  overwrite  existing  output files.  Also
143 |               forces _b_z_i_p_2 to break hard links to files, which it
144 |               otherwise wouldn’t do.
145 | 
146 |               bzip2  normally  declines to decompress files which
147 |               don’t have the  correct  magic  header  bytes.   If
148 |               forced  (‐f),  however,  it  will  pass  such files
149 |               through unmodified.  This is how GNU gzip  behaves.
150 | 
151 |        −−kk ‐‐‐‐kkeeeepp
152 |               Keep  (don’t delete) input files during compression
153 |               or decompression.
154 | 
155 |        −−ss ‐‐‐‐ssmmaallll
156 |               Reduce memory usage, for compression, decompression
157 |               and  testing.   Files  are  decompressed and tested
158 |               using a modified algorithm which only requires  2.5
159 |               bytes  per  block byte.  This means any file can be
160 |               decompressed in 2300k of memory,  albeit  at  about
161 |               half the normal speed.
162 | 
163 |               During  compression,  −s  selects  a  block size of
164 |               200k, which limits memory use to  around  the  same
165 |               figure,  at  the expense of your compression ratio.
166 |               In short, if your  machine  is  low  on  memory  (8
167 |               megabytes  or  less),  use  −s for everything.  See
168 |               MEMORY MANAGEMENT below.
169 | 
170 |        −−qq ‐‐‐‐qquuiieett
171 |               Suppress non‐essential warning messages.   Messages
172 |               pertaining  to I/O errors and other critical events
173 |               will not be suppressed.
174 | 
175 |        −−vv ‐‐‐‐vveerrbboossee
176 |               Verbose mode ‐‐ show the compression ratio for each
177 |               file  processed.   Further  −v’s  increase the ver­
178 |               bosity level, spewing out lots of information which
179 |               is primarily of interest for diagnostic purposes.
180 | 
181 |        −−LL ‐‐‐‐lliicceennssee ‐‐VV ‐‐‐‐vveerrssiioonn
182 |               Display  the  software  version,  license terms and
183 |               conditions.
184 | 
185 |        −−11 ((oorr −−−−ffaasstt)) ttoo −−99 ((oorr −−−−bbeesstt))
186 |               Set the block size to 100 k, 200 k ..  900  k  when
187 |               compressing.   Has  no  effect  when decompressing.
188 |               See MEMORY MANAGEMENT below.  The −−fast and −−best
189 |               aliases  are  primarily for GNU gzip compatibility.
190 |               In particular, −−fast doesn’t make things  signifi­
191 |               cantly  faster.   And  −−best  merely  selects  the
192 |               default behaviour.
193 | 
194 |        −−‐‐     Treats all subsequent arguments as file names, even
195 |               if they start with a dash.  This is so you can han­
196 |               dle files with names beginning  with  a  dash,  for
197 |               example: bzip2 −‐ −myfilename.
198 | 
199 |        −−‐‐rreeppeettiittiivvee‐‐ffaasstt ‐‐‐‐rreeppeettiittiivvee‐‐bbeesstt
200 |               These  flags  are  redundant  in versions 0.9.5 and
201 |               above.  They provided some coarse control over  the
202 |               behaviour  of the sorting algorithm in earlier ver­
203 |               sions, which was sometimes useful.  0.9.5 and above
204 |               have  an  improved  algorithm  which  renders these
205 |               flags irrelevant.
206 | 
207 | 
208 | MMEEMMOORRYY MMAANNAAGGEEMMEENNTT
209 |        _b_z_i_p_2 compresses large files in blocks.   The  block  size
210 |        affects  both  the  compression  ratio  achieved,  and the
211 |        amount of memory needed for compression and decompression.
212 |        The  flags  −1  through  −9  specify  the block size to be
213 |        100,000 bytes through 900,000 bytes (the default)  respec­
214 |        tively.   At  decompression  time, the block size used for
215 |        compression is read from  the  header  of  the  compressed
216 |        file, and _b_u_n_z_i_p_2 then allocates itself just enough memory
217 |        to decompress the file.  Since block sizes are  stored  in
218 |        compressed  files,  it follows that the flags −1 to −9 are
219 |        irrelevant to and so ignored during decompression.
220 | 
221 |        Compression and decompression requirements, in bytes,  can
222 |        be estimated as:
223 | 
224 |               Compression:   400k + ( 8 x block size )
225 | 
226 |               Decompression: 100k + ( 4 x block size ), or
227 |                              100k + ( 2.5 x block size )
228 | 
229 |        Larger  block  sizes  give  rapidly  diminishing  marginal
230 |        returns.  Most of the compression comes from the first two
231 |        or  three hundred k of block size, a fact worth bearing in
232 |        mind when using _b_z_i_p_2  on  small  machines.   It  is  also
233 |        important  to  appreciate  that  the  decompression memory
234 |        requirement is set at compression time by  the  choice  of
235 |        block size.
236 | 
237 |        For  files  compressed  with  the default 900k block size,
238 |        _b_u_n_z_i_p_2 will require about 3700 kbytes to decompress.   To
239 |        support decompression of any file on a 4 megabyte machine,
240 |        _b_u_n_z_i_p_2 has an option to  decompress  using  approximately
241 |        half this amount of memory, about 2300 kbytes.  Decompres­
242 |        sion speed is also halved, so you should use  this  option
243 |        only where necessary.  The relevant flag is ‐s.
244 | 
245 |        In general, try and use the largest block size memory con­
246 |        straints  allow,  since  that  maximises  the  compression
247 |        achieved.   Compression and decompression speed are virtu­
248 |        ally unaffected by block size.
249 | 
250 |        Another significant point applies to files which fit in  a
251 |        single  block  ‐‐  that  means  most files you’d encounter
252 |        using a large block  size.   The  amount  of  real  memory
253 |        touched is proportional to the size of the file, since the
254 |        file is smaller than a block.  For example, compressing  a
255 |        file  20,000  bytes  long  with the flag ‐9 will cause the
256 |        compressor to allocate around 7600k of  memory,  but  only
257 |        touch 400k + 20000 * 8 = 560 kbytes of it.  Similarly, the
258 |        decompressor will allocate 3700k but  only  touch  100k  +
259 |        20000 * 4 = 180 kbytes.
260 | 
261 |        Here  is a table which summarises the maximum memory usage
262 |        for different block sizes.  Also  recorded  is  the  total
263 |        compressed  size for 14 files of the Calgary Text Compres­
264 |        sion Corpus totalling 3,141,622 bytes.  This column  gives
265 |        some  feel  for  how  compression  varies with block size.
266 |        These figures tend to understate the advantage  of  larger
267 |        block  sizes  for  larger files, since the Corpus is domi­
268 |        nated by smaller files.
269 | 
270 |                   Compress   Decompress   Decompress   Corpus
271 |            Flag     usage      usage       ‐s usage     Size
272 | 
273 |             ‐1      1200k       500k         350k      914704
274 |             ‐2      2000k       900k         600k      877703
275 |             ‐3      2800k      1300k         850k      860338
276 |             ‐4      3600k      1700k        1100k      846899
277 |             ‐5      4400k      2100k        1350k      845160
278 |             ‐6      5200k      2500k        1600k      838626
279 |             ‐7      6100k      2900k        1850k      834096
280 |             ‐8      6800k      3300k        2100k      828642
281 |             ‐9      7600k      3700k        2350k      828642
282 | 
283 | 
284 | RREECCOOVVEERRIINNGG DDAATTAA FFRROOMM DDAAMMAAGGEEDD FFIILLEESS
285 |        _b_z_i_p_2 compresses files in blocks, usually 900kbytes  long.
286 |        Each block is handled independently.  If a media or trans­
287 |        mission error causes a multi‐block  .bz2  file  to  become
288 |        damaged,  it  may  be  possible  to  recover data from the
289 |        undamaged blocks in the file.
290 | 
291 |        The compressed representation of each block  is  delimited
292 |        by  a  48‐bit pattern, which makes it possible to find the
293 |        block boundaries with reasonable  certainty.   Each  block
294 |        also  carries its own 32‐bit CRC, so damaged blocks can be
295 |        distinguished from undamaged ones.
296 | 
297 |        _b_z_i_p_2_r_e_c_o_v_e_r is a  simple  program  whose  purpose  is  to
298 |        search  for blocks in .bz2 files, and write each block out
299 |        into its own .bz2 file.  You can then use _b_z_i_p_2 −t to test
300 |        the integrity of the resulting files, and decompress those
301 |        which are undamaged.
302 | 
303 |        _b_z_i_p_2_r_e_c_o_v_e_r takes a single argument, the name of the dam­
304 |        aged    file,    and    writes    a    number   of   files
305 |        "rec00001file.bz2",  "rec00002file.bz2",  etc,  containing
306 |        the   extracted   blocks.   The   output   filenames   are
307 |        designed  so  that the use of wildcards in subsequent pro­
308 |        cessing  ‐‐ for example, "bzip2 ‐dc  rec*file.bz2 > recov­
309 |        ered_data" ‐‐ processes the files in the correct order.
310 | 
311 |        _b_z_i_p_2_r_e_c_o_v_e_r should be of most use dealing with large .bz2
312 |        files,  as  these will contain many blocks.  It is clearly
313 |        futile to use it on damaged single‐block  files,  since  a
314 |        damaged  block  cannot  be recovered.  If you wish to min­
315 |        imise any potential data loss through media  or  transmis­
316 |        sion errors, you might consider compressing with a smaller
317 |        block size.
318 | 
319 | 
320 | PPEERRFFOORRMMAANNCCEE NNOOTTEESS
321 |        The sorting phase of compression gathers together  similar
322 |        strings  in  the  file.  Because of this, files containing
323 |        very long runs of  repeated  symbols,  like  "aabaabaabaab
324 |        ..."   (repeated  several hundred times) may compress more
325 |        slowly than normal.  Versions 0.9.5 and  above  fare  much
326 |        better  than previous versions in this respect.  The ratio
327 |        between worst‐case and average‐case compression time is in
328 |        the  region  of  10:1.  For previous versions, this figure
329 |        was more like 100:1.  You can use the −vvvv option to mon­
330 |        itor progress in great detail, if you want.
331 | 
332 |        Decompression speed is unaffected by these phenomena.
333 | 
334 |        _b_z_i_p_2  usually  allocates  several  megabytes of memory to
335 |        operate in, and then charges all over it in a fairly  ran­
336 |        dom  fashion.   This means that performance, both for com­
337 |        pressing and decompressing, is largely determined  by  the
338 |        speed  at  which  your  machine  can service cache misses.
339 |        Because of this, small changes to the code to  reduce  the
340 |        miss  rate  have  been observed to give disproportionately
341 |        large performance improvements.  I imagine _b_z_i_p_2 will per­
342 |        form best on machines with very large caches.
343 | 
344 | 
345 | CCAAVVEEAATTSS
346 |        I/O  error  messages  are not as helpful as they could be.
347 |        _b_z_i_p_2 tries hard to detect I/O errors  and  exit  cleanly,
348 |        but  the  details  of  what  the problem is sometimes seem
349 |        rather misleading.
350 | 
351 |        This manual page pertains to version 1.0.4 of _b_z_i_p_2_.  Com­
352 |        pressed  data created by this version is entirely forwards
353 |        and  backwards  compatible  with   the   previous   public
354 |        releases,  versions  0.1pl2,  0.9.0,  0.9.5, 1.0.0, 1.0.1, 
355 |        1.0.2 and 1.0.3, but with the  following  exception: 0.9.0
356 |        and above can  correctly decompress  multiple concatenated
357 |        compressed files.  0.1pl2  cannot do this;  it  will  stop 
358 |        after  decompressing just the first file in the stream.
359 | 
360 |        _b_z_i_p_2_r_e_c_o_v_e_r  versions prior to 1.0.2 used 32‐bit integers
361 |        to represent bit positions in compressed  files,  so  they
362 |        could  not handle compressed files more than 512 megabytes
363 |        long.  Versions 1.0.2 and above use 64‐bit  ints  on  some
364 |        platforms  which  support them (GNU supported targets, and
365 |        Windows).  To establish whether or  not  bzip2recover  was
366 |        built  with  such  a limitation, run it without arguments.
367 |        In any event you can build yourself an  unlimited  version
368 |        if  you  can  recompile  it  with MaybeUInt64 set to be an
369 |        unsigned 64‐bit integer.
370 | 
371 | 
372 | 
373 | 
374 | AAUUTTHHOORR
375 |        Julian Seward, jsewardbzip.org.
376 | 
377 |        http://www.bzip.org
378 | 
379 |        The ideas embodied in _b_z_i_p_2 are due to (at least) the fol­
380 |        lowing  people: Michael Burrows and David Wheeler (for the
381 |        block sorting transformation), David Wheeler  (again,  for
382 |        the Huffman coder), Peter Fenwick (for the structured cod­
383 |        ing model in the original _b_z_i_p_, and many refinements), and
384 |        Alistair  Moffat,  Radford  Neal  and  Ian Witten (for the
385 |        arithmetic  coder  in  the  original  _b_z_i_p_)_.   I  am  much
386 |        indebted for their help, support and advice.  See the man­
387 |        ual in the source distribution for pointers to sources  of
388 |        documentation.  Christian von Roques encouraged me to look
389 |        for faster sorting algorithms, so as to speed up  compres­
390 |        sion.  Bela Lubkin encouraged me to improve the worst‐case
391 |        compression performance.  Donna Robinson XMLised the docu­
392 |        mentation.   The bz* scripts are derived from those of GNU
393 |        gzip.  Many people sent patches, helped  with  portability
394 |        problems,  lent  machines,  gave advice and were generally
395 |        helpful.
396 | 
397 | 
398 | 
399 |                                                          bzip2(1)
400 | 


--------------------------------------------------------------------------------
/bzip2.txt:
--------------------------------------------------------------------------------
  1 | 
  2 | NAME
  3 |        bzip2, bunzip2 - a block-sorting file compressor, v1.0.4
  4 |        bzcat - decompresses files to stdout
  5 |        bzip2recover - recovers data from damaged bzip2 files
  6 | 
  7 | 
  8 | SYNOPSIS
  9 |        bzip2 [ -cdfkqstvzVL123456789 ] [ filenames ...  ]
 10 |        bunzip2 [ -fkvsVL ] [ filenames ...  ]
 11 |        bzcat [ -s ] [ filenames ...  ]
 12 |        bzip2recover filename
 13 | 
 14 | 
 15 | DESCRIPTION
 16 |        bzip2  compresses  files  using  the Burrows-Wheeler block
 17 |        sorting text compression algorithm,  and  Huffman  coding.
 18 |        Compression  is  generally  considerably  better than that
 19 |        achieved by more conventional LZ77/LZ78-based compressors,
 20 |        and  approaches  the performance of the PPM family of sta-
 21 |        tistical compressors.
 22 | 
 23 |        The command-line options are deliberately very similar  to
 24 |        those of GNU gzip, but they are not identical.
 25 | 
 26 |        bzip2  expects  a list of file names to accompany the com-
 27 |        mand-line flags.  Each file is replaced  by  a  compressed
 28 |        version  of  itself,  with  the  name "original_name.bz2".
 29 |        Each compressed file has the same modification date,  per-
 30 |        missions, and, when possible, ownership as the correspond-
 31 |        ing original, so that these properties  can  be  correctly
 32 |        restored  at  decompression  time.   File name handling is
 33 |        naive in the sense that there is no mechanism for preserv-
 34 |        ing  original file names, permissions, ownerships or dates
 35 |        in filesystems which lack these concepts, or have  serious
 36 |        file name length restrictions, such as MS-DOS.
 37 | 
 38 |        bzip2  and  bunzip2 will by default not overwrite existing
 39 |        files.  If you want this to happen, specify the -f flag.
 40 | 
 41 |        If no file names  are  specified,  bzip2  compresses  from
 42 |        standard  input  to  standard output.  In this case, bzip2
 43 |        will decline to write compressed output to a terminal,  as
 44 |        this  would  be  entirely  incomprehensible  and therefore
 45 |        pointless.
 46 | 
 47 |        bunzip2 (or bzip2 -d) decompresses  all  specified  files.
 48 |        Files which were not created by bzip2 will be detected and
 49 |        ignored, and a warning issued.  bzip2  attempts  to  guess
 50 |        the  filename  for  the decompressed file from that of the
 51 |        compressed file as follows:
 52 | 
 53 |               filename.bz2    becomes   filename
 54 |               filename.bz     becomes   filename
 55 |               filename.tbz2   becomes   filename.tar
 56 |               filename.tbz    becomes   filename.tar
 57 |               anyothername    becomes   anyothername.out
 58 | 
 59 |        If the file does not end in one of the recognised endings,
 60 |        .bz2,  .bz,  .tbz2 or .tbz, bzip2 complains that it cannot
 61 |        guess the name of the original file, and uses the original
 62 |        name with .out appended.
 63 | 
 64 |        As  with compression, supplying no filenames causes decom-
 65 |        pression from standard input to standard output.
 66 | 
 67 |        bunzip2 will correctly decompress a file which is the con-
 68 |        catenation of two or more compressed files.  The result is
 69 |        the concatenation of the corresponding uncompressed files.
 70 |        Integrity testing (-t) of concatenated compressed files is
 71 |        also supported.
 72 | 
 73 |        You can also compress or decompress files to the  standard
 74 |        output  by giving the -c flag.  Multiple files may be com-
 75 |        pressed and decompressed like this.  The resulting outputs
 76 |        are  fed  sequentially to stdout.  Compression of multiple
 77 |        files in this manner generates a stream containing  multi-
 78 |        ple compressed file representations.  Such a stream can be
 79 |        decompressed correctly only  by  bzip2  version  0.9.0  or
 80 |        later.   Earlier  versions of bzip2 will stop after decom-
 81 |        pressing the first file in the stream.
 82 | 
 83 |        bzcat (or bzip2 -dc) decompresses all specified  files  to
 84 |        the standard output.
 85 | 
 86 |        bzip2  will  read arguments from the environment variables
 87 |        BZIP2 and BZIP, in  that  order,  and  will  process  them
 88 |        before  any  arguments  read  from the command line.  This
 89 |        gives a convenient way to supply default arguments.
 90 | 
 91 |        Compression is always performed, even  if  the  compressed
 92 |        file  is slightly larger than the original.  Files of less
 93 |        than about one hundred bytes tend to get larger, since the
 94 |        compression  mechanism  has  a  constant  overhead  in the
 95 |        region of 50 bytes.  Random data (including the output  of
 96 |        most  file  compressors)  is  coded at about 8.05 bits per
 97 |        byte, giving an expansion of around 0.5%.
 98 | 
 99 |        As a self-check for your  protection,  bzip2  uses  32-bit
100 |        CRCs  to make sure that the decompressed version of a file
101 |        is identical to the original.  This guards against corrup-
102 |        tion  of  the compressed data, and against undetected bugs
103 |        in bzip2 (hopefully very unlikely).  The chances  of  data
104 |        corruption  going  undetected  is  microscopic,  about one
105 |        chance in four billion for each file processed.  Be aware,
106 |        though,  that  the  check occurs upon decompression, so it
107 |        can only tell you that something is wrong.  It can't  help
108 |        you  recover  the original uncompressed data.  You can use
109 |        bzip2recover to try to recover data from damaged files.
110 | 
111 |        Return values: 0 for a normal exit,  1  for  environmental
112 |        problems  (file not found, invalid flags, I/O errors, &c),
113 |        2 to indicate a corrupt compressed file, 3 for an internal
114 |        consistency error (eg, bug) which caused bzip2 to panic.
115 | 
116 | 
117 | OPTIONS
118 |        -c --stdout
119 |               Compress or decompress to standard output.
120 | 
121 |        -d --decompress
122 |               Force  decompression.  bzip2, bunzip2 and bzcat are
123 |               really the same program,  and  the  decision  about
124 |               what  actions to take is done on the basis of which
125 |               name is used.  This flag overrides that  mechanism,
126 |               and forces bzip2 to decompress.
127 | 
128 |        -z --compress
129 |               The   complement   to   -d:   forces   compression,
130 |               regardless of the invocation name.
131 | 
132 |        -t --test
133 |               Check integrity of the specified file(s), but don't
134 |               decompress  them.   This  really  performs  a trial
135 |               decompression and throws away the result.
136 | 
137 |        -f --force
138 |               Force overwrite of output files.   Normally,  bzip2
139 |               will  not  overwrite  existing  output files.  Also
140 |               forces bzip2 to break hard links to files, which it
141 |               otherwise wouldn't do.
142 | 
143 |               bzip2  normally  declines to decompress files which
144 |               don't have the  correct  magic  header  bytes.   If
145 |               forced  (-f),  however,  it  will  pass  such files
146 |               through unmodified.  This is how GNU gzip  behaves.
147 | 
148 |        -k --keep
149 |               Keep  (don't delete) input files during compression
150 |               or decompression.
151 | 
152 |        -s --small
153 |               Reduce memory usage, for compression, decompression
154 |               and  testing.   Files  are  decompressed and tested
155 |               using a modified algorithm which only requires  2.5
156 |               bytes  per  block byte.  This means any file can be
157 |               decompressed in 2300k of memory,  albeit  at  about
158 |               half the normal speed.
159 | 
160 |               During  compression,  -s  selects  a  block size of
161 |               200k, which limits memory use to  around  the  same
162 |               figure,  at  the expense of your compression ratio.
163 |               In short, if your  machine  is  low  on  memory  (8
164 |               megabytes  or  less),  use  -s for everything.  See
165 |               MEMORY MANAGEMENT below.
166 | 
167 |        -q --quiet
168 |               Suppress non-essential warning messages.   Messages
169 |               pertaining  to I/O errors and other critical events
170 |               will not be suppressed.
171 | 
172 |        -v --verbose
173 |               Verbose mode -- show the compression ratio for each
174 |               file  processed.   Further  -v's  increase the ver-
175 |               bosity level, spewing out lots of information which
176 |               is primarily of interest for diagnostic purposes.
177 | 
178 |        -L --license -V --version
179 |               Display  the  software  version,  license terms and
180 |               conditions.
181 | 
182 |        -1 (or --fast) to -9 (or --best)
183 |               Set the block size to 100 k, 200 k ..  900  k  when
184 |               compressing.   Has  no  effect  when decompressing.
185 |               See MEMORY MANAGEMENT below.  The --fast and --best
186 |               aliases  are  primarily for GNU gzip compatibility.
187 |               In particular, --fast doesn't make things  signifi-
188 |               cantly  faster.   And  --best  merely  selects  the
189 |               default behaviour.
190 | 
191 |        --     Treats all subsequent arguments as file names, even
192 |               if they start with a dash.  This is so you can han-
193 |               dle files with names beginning  with  a  dash,  for
194 |               example: bzip2 -- -myfilename.
195 | 
196 |        --repetitive-fast --repetitive-best
197 |               These  flags  are  redundant  in versions 0.9.5 and
198 |               above.  They provided some coarse control over  the
199 |               behaviour  of the sorting algorithm in earlier ver-
200 |               sions, which was sometimes useful.  0.9.5 and above
201 |               have  an  improved  algorithm  which  renders these
202 |               flags irrelevant.
203 | 
204 | 
205 | MEMORY MANAGEMENT
206 |        bzip2 compresses large files in blocks.   The  block  size
207 |        affects  both  the  compression  ratio  achieved,  and the
208 |        amount of memory needed for compression and decompression.
209 |        The  flags  -1  through  -9  specify  the block size to be
210 |        100,000 bytes through 900,000 bytes (the default)  respec-
211 |        tively.   At  decompression  time, the block size used for
212 |        compression is read from  the  header  of  the  compressed
213 |        file, and bunzip2 then allocates itself just enough memory
214 |        to decompress the file.  Since block sizes are  stored  in
215 |        compressed  files,  it follows that the flags -1 to -9 are
216 |        irrelevant to and so ignored during decompression.
217 | 
218 |        Compression and decompression requirements, in bytes,  can
219 |        be estimated as:
220 | 
221 |               Compression:   400k + ( 8 x block size )
222 | 
223 |               Decompression: 100k + ( 4 x block size ), or
224 |                              100k + ( 2.5 x block size )
225 | 
226 |        Larger  block  sizes  give  rapidly  diminishing  marginal
227 |        returns.  Most of the compression comes from the first two
228 |        or  three hundred k of block size, a fact worth bearing in
229 |        mind when using bzip2  on  small  machines.   It  is  also
230 |        important  to  appreciate  that  the  decompression memory
231 |        requirement is set at compression time by  the  choice  of
232 |        block size.
233 | 
234 |        For  files  compressed  with  the default 900k block size,
235 |        bunzip2 will require about 3700 kbytes to decompress.   To
236 |        support decompression of any file on a 4 megabyte machine,
237 |        bunzip2 has an option to  decompress  using  approximately
238 |        half this amount of memory, about 2300 kbytes.  Decompres-
239 |        sion speed is also halved, so you should use  this  option
240 |        only where necessary.  The relevant flag is -s.
241 | 
242 |        In general, try and use the largest block size memory con-
243 |        straints  allow,  since  that  maximises  the  compression
244 |        achieved.   Compression and decompression speed are virtu-
245 |        ally unaffected by block size.
246 | 
247 |        Another significant point applies to files which fit in  a
248 |        single  block  --  that  means  most files you'd encounter
249 |        using a large block  size.   The  amount  of  real  memory
250 |        touched is proportional to the size of the file, since the
251 |        file is smaller than a block.  For example, compressing  a
252 |        file  20,000  bytes  long  with the flag -9 will cause the
253 |        compressor to allocate around 7600k of  memory,  but  only
254 |        touch 400k + 20000 * 8 = 560 kbytes of it.  Similarly, the
255 |        decompressor will allocate 3700k but  only  touch  100k  +
256 |        20000 * 4 = 180 kbytes.
257 | 
258 |        Here  is a table which summarises the maximum memory usage
259 |        for different block sizes.  Also  recorded  is  the  total
260 |        compressed  size for 14 files of the Calgary Text Compres-
261 |        sion Corpus totalling 3,141,622 bytes.  This column  gives
262 |        some  feel  for  how  compression  varies with block size.
263 |        These figures tend to understate the advantage  of  larger
264 |        block  sizes  for  larger files, since the Corpus is domi-
265 |        nated by smaller files.
266 | 
267 |                   Compress   Decompress   Decompress   Corpus
268 |            Flag     usage      usage       -s usage     Size
269 | 
270 |             -1      1200k       500k         350k      914704
271 |             -2      2000k       900k         600k      877703
272 |             -3      2800k      1300k         850k      860338
273 |             -4      3600k      1700k        1100k      846899
274 |             -5      4400k      2100k        1350k      845160
275 |             -6      5200k      2500k        1600k      838626
276 |             -7      6100k      2900k        1850k      834096
277 |             -8      6800k      3300k        2100k      828642
278 |             -9      7600k      3700k        2350k      828642
279 | 
280 | 
281 | RECOVERING DATA FROM DAMAGED FILES
282 |        bzip2 compresses files in blocks, usually 900kbytes  long.
283 |        Each block is handled independently.  If a media or trans-
284 |        mission error causes a multi-block  .bz2  file  to  become
285 |        damaged,  it  may  be  possible  to  recover data from the
286 |        undamaged blocks in the file.
287 | 
288 |        The compressed representation of each block  is  delimited
289 |        by  a  48-bit pattern, which makes it possible to find the
290 |        block boundaries with reasonable  certainty.   Each  block
291 |        also  carries its own 32-bit CRC, so damaged blocks can be
292 |        distinguished from undamaged ones.
293 | 
294 |        bzip2recover is a  simple  program  whose  purpose  is  to
295 |        search  for blocks in .bz2 files, and write each block out
296 |        into its own .bz2 file.  You can then use bzip2 -t to test
297 |        the integrity of the resulting files, and decompress those
298 |        which are undamaged.
299 | 
300 |        bzip2recover takes a single argument, the name of the dam-
301 |        aged    file,    and    writes    a    number   of   files
302 |        "rec00001file.bz2",  "rec00002file.bz2",  etc,  containing
303 |        the   extracted   blocks.   The   output   filenames   are
304 |        designed  so  that the use of wildcards in subsequent pro-
305 |        cessing  -- for example, "bzip2 -dc  rec*file.bz2 > recov-
306 |        ered_data" -- processes the files in the correct order.
307 | 
308 |        bzip2recover should be of most use dealing with large .bz2
309 |        files,  as  these will contain many blocks.  It is clearly
310 |        futile to use it on damaged single-block  files,  since  a
311 |        damaged  block  cannot  be recovered.  If you wish to min-
312 |        imise any potential data loss through media  or  transmis-
313 |        sion errors, you might consider compressing with a smaller
314 |        block size.
315 | 
316 | 
317 | PERFORMANCE NOTES
318 |        The sorting phase of compression gathers together  similar
319 |        strings  in  the  file.  Because of this, files containing
320 |        very long runs of  repeated  symbols,  like  "aabaabaabaab
321 |        ..."   (repeated  several hundred times) may compress more
322 |        slowly than normal.  Versions 0.9.5 and  above  fare  much
323 |        better  than previous versions in this respect.  The ratio
324 |        between worst-case and average-case compression time is in
325 |        the  region  of  10:1.  For previous versions, this figure
326 |        was more like 100:1.  You can use the -vvvv option to mon-
327 |        itor progress in great detail, if you want.
328 | 
329 |        Decompression speed is unaffected by these phenomena.
330 | 
331 |        bzip2  usually  allocates  several  megabytes of memory to
332 |        operate in, and then charges all over it in a fairly  ran-
333 |        dom  fashion.   This means that performance, both for com-
334 |        pressing and decompressing, is largely determined  by  the
335 |        speed  at  which  your  machine  can service cache misses.
336 |        Because of this, small changes to the code to  reduce  the
337 |        miss  rate  have  been observed to give disproportionately
338 |        large performance improvements.  I imagine bzip2 will per-
339 |        form best on machines with very large caches.
340 | 
341 | 
342 | CAVEATS
343 |        I/O  error  messages  are not as helpful as they could be.
344 |        bzip2 tries hard to detect I/O errors  and  exit  cleanly,
345 |        but  the  details  of  what  the problem is sometimes seem
346 |        rather misleading.
347 | 
348 |        This manual page pertains to version 1.0.4 of bzip2.  Com-
349 |        pressed  data created by this version is entirely forwards
350 |        and  backwards  compatible  with   the   previous   public
351 |        releases,  versions  0.1pl2,  0.9.0,  0.9.5, 1.0.0, 1.0.1,
352 |        1.0.2 and 1.0.3, but with the  following  exception: 0.9.0
353 |        and above can  correctly decompress  multiple concatenated
354 |        compressed files.  0.1pl2  cannot do this;  it  will  stop
355 |        after  decompressing just the first file in the stream.
356 | 
357 |        bzip2recover  versions prior to 1.0.2 used 32-bit integers
358 |        to represent bit positions in compressed  files,  so  they
359 |        could  not handle compressed files more than 512 megabytes
360 |        long.  Versions 1.0.2 and above use 64-bit  ints  on  some
361 |        platforms  which  support them (GNU supported targets, and
362 |        Windows).  To establish whether or  not  bzip2recover  was
363 |        built  with  such  a limitation, run it without arguments.
364 |        In any event you can build yourself an  unlimited  version
365 |        if  you  can  recompile  it  with MaybeUInt64 set to be an
366 |        unsigned 64-bit integer.
367 | 
368 | 
369 | AUTHOR
370 |        Julian Seward, jsewardbzip.org.
371 | 
372 |        http://www.bzip.org
373 | 
374 |        The ideas embodied in bzip2 are due to (at least) the fol-
375 |        lowing  people: Michael Burrows and David Wheeler (for the
376 |        block sorting transformation), David Wheeler  (again,  for
377 |        the Huffman coder), Peter Fenwick (for the structured cod-
378 |        ing model in the original bzip, and many refinements), and
379 |        Alistair  Moffat,  Radford  Neal  and  Ian Witten (for the
380 |        arithmetic  coder  in  the  original  bzip).   I  am  much
381 |        indebted for their help, support and advice.  See the man-
382 |        ual in the source distribution for pointers to sources  of
383 |        documentation.  Christian von Roques encouraged me to look
384 |        for faster sorting algorithms, so as to speed up  compres-
385 |        sion.  Bela Lubkin encouraged me to improve the worst-case
386 |        compression performance.  Donna Robinson XMLised the docu-
387 |        mentation.   The bz* scripts are derived from those of GNU
388 |        gzip.  Many people sent patches, helped  with  portability
389 |        problems,  lent  machines,  gave advice and were generally
390 |        helpful.
391 | 
392 | 


--------------------------------------------------------------------------------
/bzip2recover.c:
--------------------------------------------------------------------------------
  1 | /*-----------------------------------------------------------*/
  2 | /*--- Block recoverer program for bzip2                   ---*/
  3 | /*---                                      bzip2recover.c ---*/
  4 | /*-----------------------------------------------------------*/
  5 | 
  6 | /* ------------------------------------------------------------------
  7 |    This file is part of bzip2/libbzip2, a program and library for
  8 |    lossless, block-sorting data compression.
  9 | 
 10 |    bzip2/libbzip2 version 1.0.5 of 10 December 2007
 11 |    Copyright (C) 1996-2007 Julian Seward 
 12 | 
 13 |    Please read the WARNING, DISCLAIMER and PATENTS sections in the 
 14 |    README file.
 15 | 
 16 |    This program is released under the terms of the license contained
 17 |    in the file LICENSE.
 18 |    ------------------------------------------------------------------ */
 19 | 
 20 | /* This program is a complete hack and should be rewritten properly.
 21 | 	 It isn't very complicated. */
 22 | 
 23 | #include 
 24 | #include 
 25 | #include 
 26 | #include 
 27 | 
 28 | 
 29 | /* This program records bit locations in the file to be recovered.
 30 |    That means that if 64-bit ints are not supported, we will not
 31 |    be able to recover .bz2 files over 512MB (2^32 bits) long.
 32 |    On GNU supported platforms, we take advantage of the 64-bit
 33 |    int support to circumvent this problem.  Ditto MSVC.
 34 | 
 35 |    This change occurred in version 1.0.2; all prior versions have
 36 |    the 512MB limitation.
 37 | */
 38 | #ifdef __GNUC__
 39 |    typedef  unsigned long long int  MaybeUInt64;
 40 | #  define MaybeUInt64_FMT "%Lu"
 41 | #else
 42 | #ifdef _MSC_VER
 43 |    typedef  unsigned __int64  MaybeUInt64;
 44 | #  define MaybeUInt64_FMT "%I64u"
 45 | #else
 46 |    typedef  unsigned int   MaybeUInt64;
 47 | #  define MaybeUInt64_FMT "%u"
 48 | #endif
 49 | #endif
 50 | 
 51 | typedef  unsigned int   UInt32;
 52 | typedef  int            Int32;
 53 | typedef  unsigned char  UChar;
 54 | typedef  char           Char;
 55 | typedef  unsigned char  Bool;
 56 | #define True    ((Bool)1)
 57 | #define False   ((Bool)0)
 58 | 
 59 | 
 60 | #define BZ_MAX_FILENAME 2000
 61 | 
 62 | Char inFileName[BZ_MAX_FILENAME];
 63 | Char outFileName[BZ_MAX_FILENAME];
 64 | Char progName[BZ_MAX_FILENAME];
 65 | 
 66 | MaybeUInt64 bytesOut = 0;
 67 | MaybeUInt64 bytesIn  = 0;
 68 | 
 69 | 
 70 | /*---------------------------------------------------*/
 71 | /*--- Header bytes                                ---*/
 72 | /*---------------------------------------------------*/
 73 | 
 74 | #define BZ_HDR_B 0x42                         /* 'B' */
 75 | #define BZ_HDR_Z 0x5a                         /* 'Z' */
 76 | #define BZ_HDR_h 0x68                         /* 'h' */
 77 | #define BZ_HDR_0 0x30                         /* '0' */
 78 |  
 79 | 
 80 | /*---------------------------------------------------*/
 81 | /*--- I/O errors                                  ---*/
 82 | /*---------------------------------------------------*/
 83 | 
 84 | /*---------------------------------------------*/
 85 | static void readError ( void )
 86 | {
 87 |    fprintf ( stderr,
 88 |              "%s: I/O error reading `%s', possible reason follows.\n",
 89 |             progName, inFileName );
 90 |    perror ( progName );
 91 |    fprintf ( stderr, "%s: warning: output file(s) may be incomplete.\n",
 92 |              progName );
 93 |    exit ( 1 );
 94 | }
 95 | 
 96 | 
 97 | /*---------------------------------------------*/
 98 | static void writeError ( void )
 99 | {
100 |    fprintf ( stderr,
101 |              "%s: I/O error reading `%s', possible reason follows.\n",
102 |             progName, inFileName );
103 |    perror ( progName );
104 |    fprintf ( stderr, "%s: warning: output file(s) may be incomplete.\n",
105 |              progName );
106 |    exit ( 1 );
107 | }
108 | 
109 | 
110 | /*---------------------------------------------*/
111 | static void mallocFail ( Int32 n )
112 | {
113 |    fprintf ( stderr,
114 |              "%s: malloc failed on request for %d bytes.\n",
115 |             progName, n );
116 |    fprintf ( stderr, "%s: warning: output file(s) may be incomplete.\n",
117 |              progName );
118 |    exit ( 1 );
119 | }
120 | 
121 | 
122 | /*---------------------------------------------*/
123 | static void tooManyBlocks ( Int32 max_handled_blocks )
124 | {
125 |    fprintf ( stderr,
126 |              "%s: `%s' appears to contain more than %d blocks\n",
127 |             progName, inFileName, max_handled_blocks );
128 |    fprintf ( stderr,
129 |              "%s: and cannot be handled.  To fix, increase\n",
130 |              progName );
131 |    fprintf ( stderr, 
132 |              "%s: BZ_MAX_HANDLED_BLOCKS in bzip2recover.c, and recompile.\n",
133 |              progName );
134 |    exit ( 1 );
135 | }
136 | 
137 | 
138 | 
139 | /*---------------------------------------------------*/
140 | /*--- Bit stream I/O                              ---*/
141 | /*---------------------------------------------------*/
142 | 
143 | typedef
144 |    struct {
145 |       FILE*  handle;
146 |       Int32  buffer;
147 |       Int32  buffLive;
148 |       Char   mode;
149 |    }
150 |    BitStream;
151 | 
152 | 
153 | /*---------------------------------------------*/
154 | static BitStream* bsOpenReadStream ( FILE* stream )
155 | {
156 |    BitStream *bs = malloc ( sizeof(BitStream) );
157 |    if (bs == NULL) mallocFail ( sizeof(BitStream) );
158 |    bs->handle = stream;
159 |    bs->buffer = 0;
160 |    bs->buffLive = 0;
161 |    bs->mode = 'r';
162 |    return bs;
163 | }
164 | 
165 | 
166 | /*---------------------------------------------*/
167 | static BitStream* bsOpenWriteStream ( FILE* stream )
168 | {
169 |    BitStream *bs = malloc ( sizeof(BitStream) );
170 |    if (bs == NULL) mallocFail ( sizeof(BitStream) );
171 |    bs->handle = stream;
172 |    bs->buffer = 0;
173 |    bs->buffLive = 0;
174 |    bs->mode = 'w';
175 |    return bs;
176 | }
177 | 
178 | 
179 | /*---------------------------------------------*/
180 | static void bsPutBit ( BitStream* bs, Int32 bit )
181 | {
182 |    if (bs->buffLive == 8) {
183 |       Int32 retVal = putc ( (UChar) bs->buffer, bs->handle );
184 |       if (retVal == EOF) writeError();
185 |       bytesOut++;
186 |       bs->buffLive = 1;
187 |       bs->buffer = bit & 0x1;
188 |    } else {
189 |       bs->buffer = ( (bs->buffer << 1) | (bit & 0x1) );
190 |       bs->buffLive++;
191 |    };
192 | }
193 | 
194 | 
195 | /*---------------------------------------------*/
196 | /*--
197 |    Returns 0 or 1, or 2 to indicate EOF.
198 | --*/
199 | static Int32 bsGetBit ( BitStream* bs )
200 | {
201 |    if (bs->buffLive > 0) {
202 |       bs->buffLive --;
203 |       return ( ((bs->buffer) >> (bs->buffLive)) & 0x1 );
204 |    } else {
205 |       Int32 retVal = getc ( bs->handle );
206 |       if ( retVal == EOF ) {
207 |          if (errno != 0) readError();
208 |          return 2;
209 |       }
210 |       bs->buffLive = 7;
211 |       bs->buffer = retVal;
212 |       return ( ((bs->buffer) >> 7) & 0x1 );
213 |    }
214 | }
215 | 
216 | 
217 | /*---------------------------------------------*/
218 | static void bsClose ( BitStream* bs )
219 | {
220 |    Int32 retVal;
221 | 
222 |    if ( bs->mode == 'w' ) {
223 |       while ( bs->buffLive < 8 ) {
224 |          bs->buffLive++;
225 |          bs->buffer <<= 1;
226 |       };
227 |       retVal = putc ( (UChar) (bs->buffer), bs->handle );
228 |       if (retVal == EOF) writeError();
229 |       bytesOut++;
230 |       retVal = fflush ( bs->handle );
231 |       if (retVal == EOF) writeError();
232 |    }
233 |    retVal = fclose ( bs->handle );
234 |    if (retVal == EOF) {
235 |       if (bs->mode == 'w') writeError(); else readError();
236 |    }
237 |    free ( bs );
238 | }
239 | 
240 | 
241 | /*---------------------------------------------*/
242 | static void bsPutUChar ( BitStream* bs, UChar c )
243 | {
244 |    Int32 i;
245 |    for (i = 7; i >= 0; i--)
246 |       bsPutBit ( bs, (((UInt32) c) >> i) & 0x1 );
247 | }
248 | 
249 | 
250 | /*---------------------------------------------*/
251 | static void bsPutUInt32 ( BitStream* bs, UInt32 c )
252 | {
253 |    Int32 i;
254 | 
255 |    for (i = 31; i >= 0; i--)
256 |       bsPutBit ( bs, (c >> i) & 0x1 );
257 | }
258 | 
259 | 
260 | /*---------------------------------------------*/
261 | static Bool endsInBz2 ( Char* name )
262 | {
263 |    Int32 n = strlen ( name );
264 |    if (n <= 4) return False;
265 |    return
266 |       (name[n-4] == '.' &&
267 |        name[n-3] == 'b' &&
268 |        name[n-2] == 'z' &&
269 |        name[n-1] == '2');
270 | }
271 | 
272 | 
273 | /*---------------------------------------------------*/
274 | /*---                                             ---*/
275 | /*---------------------------------------------------*/
276 | 
277 | /* This logic isn't really right when it comes to Cygwin. */
278 | #ifdef _WIN32
279 | #  define  BZ_SPLIT_SYM  '\\'  /* path splitter on Windows platform */
280 | #else
281 | #  define  BZ_SPLIT_SYM  '/'   /* path splitter on Unix platform */
282 | #endif
283 | 
284 | #define BLOCK_HEADER_HI  0x00003141UL
285 | #define BLOCK_HEADER_LO  0x59265359UL
286 | 
287 | #define BLOCK_ENDMARK_HI 0x00001772UL
288 | #define BLOCK_ENDMARK_LO 0x45385090UL
289 | 
290 | /* Increase if necessary.  However, a .bz2 file with > 50000 blocks
291 |    would have an uncompressed size of at least 40GB, so the chances
292 |    are low you'll need to up this.
293 | */
294 | #define BZ_MAX_HANDLED_BLOCKS 50000
295 | 
296 | MaybeUInt64 bStart [BZ_MAX_HANDLED_BLOCKS];
297 | MaybeUInt64 bEnd   [BZ_MAX_HANDLED_BLOCKS];
298 | MaybeUInt64 rbStart[BZ_MAX_HANDLED_BLOCKS];
299 | MaybeUInt64 rbEnd  [BZ_MAX_HANDLED_BLOCKS];
300 | 
301 | Int32 main ( Int32 argc, Char** argv )
302 | {
303 |    FILE*       inFile;
304 |    FILE*       outFile;
305 |    BitStream*  bsIn, *bsWr;
306 |    Int32       b, wrBlock, currBlock, rbCtr;
307 |    MaybeUInt64 bitsRead;
308 | 
309 |    UInt32      buffHi, buffLo, blockCRC;
310 |    Char*       p;
311 | 
312 |    strcpy ( progName, argv[0] );
313 |    inFileName[0] = outFileName[0] = 0;
314 | 
315 |    fprintf ( stderr, 
316 |              "bzip2recover 1.0.5: extracts blocks from damaged .bz2 files.\n" );
317 | 
318 |    if (argc != 2) {
319 |       fprintf ( stderr, "%s: usage is `%s damaged_file_name'.\n",
320 |                         progName, progName );
321 |       switch (sizeof(MaybeUInt64)) {
322 |          case 8:
323 |             fprintf(stderr, 
324 |                     "\trestrictions on size of recovered file: None\n");
325 |             break;
326 |          case 4:
327 |             fprintf(stderr, 
328 |                     "\trestrictions on size of recovered file: 512 MB\n");
329 |             fprintf(stderr, 
330 |                     "\tto circumvent, recompile with MaybeUInt64 as an\n"
331 |                     "\tunsigned 64-bit int.\n");
332 |             break;
333 |          default:
334 |             fprintf(stderr, 
335 |                     "\tsizeof(MaybeUInt64) is not 4 or 8 -- "
336 |                     "configuration error.\n");
337 |             break;
338 |       }
339 |       exit(1);
340 |    }
341 | 
342 |    if (strlen(argv[1]) >= BZ_MAX_FILENAME-20) {
343 |       fprintf ( stderr, 
344 |                 "%s: supplied filename is suspiciously (>= %d chars) long.  Bye!\n",
345 |                 progName, (int)strlen(argv[1]) );
346 |       exit(1);
347 |    }
348 | 
349 |    strcpy ( inFileName, argv[1] );
350 | 
351 |    inFile = fopen ( inFileName, "rb" );
352 |    if (inFile == NULL) {
353 |       fprintf ( stderr, "%s: can't read `%s'\n", progName, inFileName );
354 |       exit(1);
355 |    }
356 | 
357 |    bsIn = bsOpenReadStream ( inFile );
358 |    fprintf ( stderr, "%s: searching for block boundaries ...\n", progName );
359 | 
360 |    bitsRead = 0;
361 |    buffHi = buffLo = 0;
362 |    currBlock = 0;
363 |    bStart[currBlock] = 0;
364 | 
365 |    rbCtr = 0;
366 | 
367 |    while (True) {
368 |       b = bsGetBit ( bsIn );
369 |       bitsRead++;
370 |       if (b == 2) {
371 |          if (bitsRead >= bStart[currBlock] &&
372 |             (bitsRead - bStart[currBlock]) >= 40) {
373 |             bEnd[currBlock] = bitsRead-1;
374 |             if (currBlock > 0)
375 |                fprintf ( stderr, "   block %d runs from " MaybeUInt64_FMT 
376 |                                  " to " MaybeUInt64_FMT " (incomplete)\n",
377 |                          currBlock,  bStart[currBlock], bEnd[currBlock] );
378 |          } else
379 |             currBlock--;
380 |          break;
381 |       }
382 |       buffHi = (buffHi << 1) | (buffLo >> 31);
383 |       buffLo = (buffLo << 1) | (b & 1);
384 |       if ( ( (buffHi & 0x0000ffff) == BLOCK_HEADER_HI 
385 |              && buffLo == BLOCK_HEADER_LO)
386 |            || 
387 |            ( (buffHi & 0x0000ffff) == BLOCK_ENDMARK_HI 
388 |              && buffLo == BLOCK_ENDMARK_LO)
389 |          ) {
390 |          if (bitsRead > 49) {
391 |             bEnd[currBlock] = bitsRead-49;
392 |          } else {
393 |             bEnd[currBlock] = 0;
394 |          }
395 |          if (currBlock > 0 &&
396 | 	     (bEnd[currBlock] - bStart[currBlock]) >= 130) {
397 |             fprintf ( stderr, "   block %d runs from " MaybeUInt64_FMT 
398 |                               " to " MaybeUInt64_FMT "\n",
399 |                       rbCtr+1,  bStart[currBlock], bEnd[currBlock] );
400 |             rbStart[rbCtr] = bStart[currBlock];
401 |             rbEnd[rbCtr] = bEnd[currBlock];
402 |             rbCtr++;
403 |          }
404 |          if (currBlock >= BZ_MAX_HANDLED_BLOCKS)
405 |             tooManyBlocks(BZ_MAX_HANDLED_BLOCKS);
406 |          currBlock++;
407 | 
408 |          bStart[currBlock] = bitsRead;
409 |       }
410 |    }
411 | 
412 |    bsClose ( bsIn );
413 | 
414 |    /*-- identified blocks run from 1 to rbCtr inclusive. --*/
415 | 
416 |    if (rbCtr < 1) {
417 |       fprintf ( stderr,
418 |                 "%s: sorry, I couldn't find any block boundaries.\n",
419 |                 progName );
420 |       exit(1);
421 |    };
422 | 
423 |    fprintf ( stderr, "%s: splitting into blocks\n", progName );
424 | 
425 |    inFile = fopen ( inFileName, "rb" );
426 |    if (inFile == NULL) {
427 |       fprintf ( stderr, "%s: can't open `%s'\n", progName, inFileName );
428 |       exit(1);
429 |    }
430 |    bsIn = bsOpenReadStream ( inFile );
431 | 
432 |    /*-- placate gcc's dataflow analyser --*/
433 |    blockCRC = 0; bsWr = 0;
434 | 
435 |    bitsRead = 0;
436 |    outFile = NULL;
437 |    wrBlock = 0;
438 |    while (True) {
439 |       b = bsGetBit(bsIn);
440 |       if (b == 2) break;
441 |       buffHi = (buffHi << 1) | (buffLo >> 31);
442 |       buffLo = (buffLo << 1) | (b & 1);
443 |       if (bitsRead == 47+rbStart[wrBlock]) 
444 |          blockCRC = (buffHi << 16) | (buffLo >> 16);
445 | 
446 |       if (outFile != NULL && bitsRead >= rbStart[wrBlock]
447 |                           && bitsRead <= rbEnd[wrBlock]) {
448 |          bsPutBit ( bsWr, b );
449 |       }
450 | 
451 |       bitsRead++;
452 | 
453 |       if (bitsRead == rbEnd[wrBlock]+1) {
454 |          if (outFile != NULL) {
455 |             bsPutUChar ( bsWr, 0x17 ); bsPutUChar ( bsWr, 0x72 );
456 |             bsPutUChar ( bsWr, 0x45 ); bsPutUChar ( bsWr, 0x38 );
457 |             bsPutUChar ( bsWr, 0x50 ); bsPutUChar ( bsWr, 0x90 );
458 |             bsPutUInt32 ( bsWr, blockCRC );
459 |             bsClose ( bsWr );
460 |          }
461 |          if (wrBlock >= rbCtr) break;
462 |          wrBlock++;
463 |       } else
464 |       if (bitsRead == rbStart[wrBlock]) {
465 |          /* Create the output file name, correctly handling leading paths. 
466 |             (31.10.2001 by Sergey E. Kusikov) */
467 |          Char* split;
468 |          Int32 ofs, k;
469 |          for (k = 0; k < BZ_MAX_FILENAME; k++) 
470 |             outFileName[k] = 0;
471 |          strcpy (outFileName, inFileName);
472 |          split = strrchr (outFileName, BZ_SPLIT_SYM);
473 |          if (split == NULL) {
474 |             split = outFileName;
475 |          } else {
476 |             ++split;
477 | 	 }
478 | 	 /* Now split points to the start of the basename. */
479 |          ofs  = split - outFileName;
480 |          sprintf (split, "rec%5d", wrBlock+1);
481 |          for (p = split; *p != 0; p++) if (*p == ' ') *p = '0';
482 |          strcat (outFileName, inFileName + ofs);
483 | 
484 |          if ( !endsInBz2(outFileName)) strcat ( outFileName, ".bz2" );
485 | 
486 |          fprintf ( stderr, "   writing block %d to `%s' ...\n",
487 |                            wrBlock+1, outFileName );
488 | 
489 |          outFile = fopen ( outFileName, "wb" );
490 |          if (outFile == NULL) {
491 |             fprintf ( stderr, "%s: can't write `%s'\n",
492 |                       progName, outFileName );
493 |             exit(1);
494 |          }
495 |          bsWr = bsOpenWriteStream ( outFile );
496 |          bsPutUChar ( bsWr, BZ_HDR_B );    
497 |          bsPutUChar ( bsWr, BZ_HDR_Z );    
498 |          bsPutUChar ( bsWr, BZ_HDR_h );    
499 |          bsPutUChar ( bsWr, BZ_HDR_0 + 9 );
500 |          bsPutUChar ( bsWr, 0x31 ); bsPutUChar ( bsWr, 0x41 );
501 |          bsPutUChar ( bsWr, 0x59 ); bsPutUChar ( bsWr, 0x26 );
502 |          bsPutUChar ( bsWr, 0x53 ); bsPutUChar ( bsWr, 0x59 );
503 |       }
504 |    }
505 | 
506 |    fprintf ( stderr, "%s: finished\n", progName );
507 |    return 0;
508 | }
509 | 
510 | 
511 | 
512 | /*-----------------------------------------------------------*/
513 | /*--- end                                  bzip2recover.c ---*/
514 | /*-----------------------------------------------------------*/
515 | 


--------------------------------------------------------------------------------
/bzlib.h:
--------------------------------------------------------------------------------
  1 | 
  2 | /*-------------------------------------------------------------*/
  3 | /*--- Public header file for the library.                   ---*/
  4 | /*---                                               bzlib.h ---*/
  5 | /*-------------------------------------------------------------*/
  6 | 
  7 | /* ------------------------------------------------------------------
  8 |    This file is part of bzip2/libbzip2, a program and library for
  9 |    lossless, block-sorting data compression.
 10 | 
 11 |    bzip2/libbzip2 version 1.0.5 of 10 December 2007
 12 |    Copyright (C) 1996-2007 Julian Seward 
 13 | 
 14 |    Please read the WARNING, DISCLAIMER and PATENTS sections in the 
 15 |    README file.
 16 | 
 17 |    This program is released under the terms of the license contained
 18 |    in the file LICENSE.
 19 |    ------------------------------------------------------------------ */
 20 | 
 21 | 
 22 | #ifndef _BZLIB_H
 23 | #define _BZLIB_H
 24 | 
 25 | #ifdef __cplusplus
 26 | extern "C" {
 27 | #endif
 28 | 
 29 | #define BZ_RUN               0
 30 | #define BZ_FLUSH             1
 31 | #define BZ_FINISH            2
 32 | 
 33 | #define BZ_OK                0
 34 | #define BZ_RUN_OK            1
 35 | #define BZ_FLUSH_OK          2
 36 | #define BZ_FINISH_OK         3
 37 | #define BZ_STREAM_END        4
 38 | #define BZ_SEQUENCE_ERROR    (-1)
 39 | #define BZ_PARAM_ERROR       (-2)
 40 | #define BZ_MEM_ERROR         (-3)
 41 | #define BZ_DATA_ERROR        (-4)
 42 | #define BZ_DATA_ERROR_MAGIC  (-5)
 43 | #define BZ_IO_ERROR          (-6)
 44 | #define BZ_UNEXPECTED_EOF    (-7)
 45 | #define BZ_OUTBUFF_FULL      (-8)
 46 | #define BZ_CONFIG_ERROR      (-9)
 47 | 
 48 | typedef 
 49 |    struct {
 50 |       char *next_in;
 51 |       unsigned int avail_in;
 52 |       unsigned int total_in_lo32;
 53 |       unsigned int total_in_hi32;
 54 | 
 55 |       char *next_out;
 56 |       unsigned int avail_out;
 57 |       unsigned int total_out_lo32;
 58 |       unsigned int total_out_hi32;
 59 | 
 60 |       void *state;
 61 | 
 62 |       void *(*bzalloc)(void *,int,int);
 63 |       void (*bzfree)(void *,void *);
 64 |       void *opaque;
 65 |    } 
 66 |    bz_stream;
 67 | 
 68 | 
 69 | #ifndef BZ_IMPORT
 70 | #define BZ_EXPORT
 71 | #endif
 72 | 
 73 | #ifndef BZ_NO_STDIO
 74 | /* Need a definitition for FILE */
 75 | #include 
 76 | #endif
 77 | 
 78 | #ifdef _WIN32
 79 | #   include 
 80 | #   ifdef small
 81 |       /* windows.h define small to char */
 82 | #      undef small
 83 | #   endif
 84 | #   ifdef BZ_EXPORT
 85 | #   define BZ_API(func) WINAPI func
 86 | #   define BZ_EXTERN extern
 87 | #   else
 88 |    /* import windows dll dynamically */
 89 | #   define BZ_API(func) (WINAPI * func)
 90 | #   define BZ_EXTERN
 91 | #   endif
 92 | #else
 93 | #   define BZ_API(func) func
 94 | #   define BZ_EXTERN extern
 95 | #endif
 96 | 
 97 | 
 98 | /*-- Core (low-level) library functions --*/
 99 | 
100 | BZ_EXTERN int BZ_API(BZ2_bzCompressInit) ( 
101 |       bz_stream* strm, 
102 |       int        blockSize100k, 
103 |       int        verbosity, 
104 |       int        workFactor 
105 |    );
106 | 
107 | BZ_EXTERN int BZ_API(BZ2_bzCompress) ( 
108 |       bz_stream* strm, 
109 |       int action 
110 |    );
111 | 
112 | BZ_EXTERN int BZ_API(BZ2_bzCompressEnd) ( 
113 |       bz_stream* strm 
114 |    );
115 | 
116 | BZ_EXTERN int BZ_API(BZ2_bzDecompressInit) ( 
117 |       bz_stream *strm, 
118 |       int       verbosity, 
119 |       int       small
120 |    );
121 | 
122 | BZ_EXTERN int BZ_API(BZ2_bzDecompress) ( 
123 |       bz_stream* strm 
124 |    );
125 | 
126 | BZ_EXTERN int BZ_API(BZ2_bzDecompressEnd) ( 
127 |       bz_stream *strm 
128 |    );
129 | 
130 | 
131 | 
132 | /*-- High(er) level library functions --*/
133 | 
134 | #ifndef BZ_NO_STDIO
135 | #define BZ_MAX_UNUSED 5000
136 | 
137 | typedef void BZFILE;
138 | 
139 | BZ_EXTERN BZFILE* BZ_API(BZ2_bzReadOpen) ( 
140 |       int*  bzerror,   
141 |       FILE* f, 
142 |       int   verbosity, 
143 |       int   small,
144 |       void* unused,    
145 |       int   nUnused 
146 |    );
147 | 
148 | BZ_EXTERN void BZ_API(BZ2_bzReadClose) ( 
149 |       int*    bzerror, 
150 |       BZFILE* b 
151 |    );
152 | 
153 | BZ_EXTERN void BZ_API(BZ2_bzReadGetUnused) ( 
154 |       int*    bzerror, 
155 |       BZFILE* b, 
156 |       void**  unused,  
157 |       int*    nUnused 
158 |    );
159 | 
160 | BZ_EXTERN int BZ_API(BZ2_bzRead) ( 
161 |       int*    bzerror, 
162 |       BZFILE* b, 
163 |       void*   buf, 
164 |       int     len 
165 |    );
166 | 
167 | BZ_EXTERN BZFILE* BZ_API(BZ2_bzWriteOpen) ( 
168 |       int*  bzerror,      
169 |       FILE* f, 
170 |       int   blockSize100k, 
171 |       int   verbosity, 
172 |       int   workFactor 
173 |    );
174 | 
175 | BZ_EXTERN void BZ_API(BZ2_bzWrite) ( 
176 |       int*    bzerror, 
177 |       BZFILE* b, 
178 |       void*   buf, 
179 |       int     len 
180 |    );
181 | 
182 | BZ_EXTERN void BZ_API(BZ2_bzWriteClose) ( 
183 |       int*          bzerror, 
184 |       BZFILE*       b, 
185 |       int           abandon, 
186 |       unsigned int* nbytes_in, 
187 |       unsigned int* nbytes_out 
188 |    );
189 | 
190 | BZ_EXTERN void BZ_API(BZ2_bzWriteClose64) ( 
191 |       int*          bzerror, 
192 |       BZFILE*       b, 
193 |       int           abandon, 
194 |       unsigned int* nbytes_in_lo32, 
195 |       unsigned int* nbytes_in_hi32, 
196 |       unsigned int* nbytes_out_lo32, 
197 |       unsigned int* nbytes_out_hi32
198 |    );
199 | #endif
200 | 
201 | 
202 | /*-- Utility functions --*/
203 | 
204 | BZ_EXTERN int BZ_API(BZ2_bzBuffToBuffCompress) ( 
205 |       char*         dest, 
206 |       unsigned int* destLen,
207 |       char*         source, 
208 |       unsigned int  sourceLen,
209 |       int           blockSize100k, 
210 |       int           verbosity, 
211 |       int           workFactor 
212 |    );
213 | 
214 | BZ_EXTERN int BZ_API(BZ2_bzBuffToBuffDecompress) ( 
215 |       char*         dest, 
216 |       unsigned int* destLen,
217 |       char*         source, 
218 |       unsigned int  sourceLen,
219 |       int           small, 
220 |       int           verbosity 
221 |    );
222 | 
223 | 
224 | /*--
225 |    Code contributed by Yoshioka Tsuneo (tsuneo@rr.iij4u.or.jp)
226 |    to support better zlib compatibility.
227 |    This code is not _officially_ part of libbzip2 (yet);
228 |    I haven't tested it, documented it, or considered the
229 |    threading-safeness of it.
230 |    If this code breaks, please contact both Yoshioka and me.
231 | --*/
232 | 
233 | BZ_EXTERN const char * BZ_API(BZ2_bzlibVersion) (
234 |       void
235 |    );
236 | 
237 | #ifndef BZ_NO_STDIO
238 | BZ_EXTERN BZFILE * BZ_API(BZ2_bzopen) (
239 |       const char *path,
240 |       const char *mode
241 |    );
242 | 
243 | BZ_EXTERN BZFILE * BZ_API(BZ2_bzdopen) (
244 |       int        fd,
245 |       const char *mode
246 |    );
247 |          
248 | BZ_EXTERN int BZ_API(BZ2_bzread) (
249 |       BZFILE* b, 
250 |       void* buf, 
251 |       int len 
252 |    );
253 | 
254 | BZ_EXTERN int BZ_API(BZ2_bzwrite) (
255 |       BZFILE* b, 
256 |       void*   buf, 
257 |       int     len 
258 |    );
259 | 
260 | BZ_EXTERN int BZ_API(BZ2_bzflush) (
261 |       BZFILE* b
262 |    );
263 | 
264 | BZ_EXTERN void BZ_API(BZ2_bzclose) (
265 |       BZFILE* b
266 |    );
267 | 
268 | BZ_EXTERN const char * BZ_API(BZ2_bzerror) (
269 |       BZFILE *b, 
270 |       int    *errnum
271 |    );
272 | #endif
273 | 
274 | #ifdef __cplusplus
275 | }
276 | #endif
277 | 
278 | #endif
279 | 
280 | /*-------------------------------------------------------------*/
281 | /*--- end                                           bzlib.h ---*/
282 | /*-------------------------------------------------------------*/
283 | 


--------------------------------------------------------------------------------
/bzlib_private.h:
--------------------------------------------------------------------------------
  1 | 
  2 | /*-------------------------------------------------------------*/
  3 | /*--- Private header file for the library.                  ---*/
  4 | /*---                                       bzlib_private.h ---*/
  5 | /*-------------------------------------------------------------*/
  6 | 
  7 | /* ------------------------------------------------------------------
  8 |    This file is part of bzip2/libbzip2, a program and library for
  9 |    lossless, block-sorting data compression.
 10 | 
 11 |    bzip2/libbzip2 version 1.0.5 of 10 December 2007
 12 |    Copyright (C) 1996-2007 Julian Seward 
 13 | 
 14 |    Please read the WARNING, DISCLAIMER and PATENTS sections in the 
 15 |    README file.
 16 | 
 17 |    This program is released under the terms of the license contained
 18 |    in the file LICENSE.
 19 |    ------------------------------------------------------------------ */
 20 | 
 21 | 
 22 | #ifndef _BZLIB_PRIVATE_H
 23 | #define _BZLIB_PRIVATE_H
 24 | 
 25 | #include 
 26 | 
 27 | #ifndef BZ_NO_STDIO
 28 | #include 
 29 | #include 
 30 | #include 
 31 | #endif
 32 | 
 33 | #include "bzlib.h"
 34 | 
 35 | 
 36 | 
 37 | /*-- General stuff. --*/
 38 | 
 39 | #define BZ_VERSION  "1.0.5, 10-Dec-2007"
 40 | 
 41 | typedef char            Char;
 42 | typedef unsigned char   Bool;
 43 | typedef unsigned char   UChar;
 44 | typedef int             Int32;
 45 | typedef unsigned int    UInt32;
 46 | typedef short           Int16;
 47 | typedef unsigned short  UInt16;
 48 | 
 49 | #define True  ((Bool)1)
 50 | #define False ((Bool)0)
 51 | 
 52 | #ifndef __GNUC__
 53 | #define __inline__  /* */
 54 | #endif 
 55 | 
 56 | #ifndef BZ_NO_STDIO
 57 | 
 58 | extern void BZ2_bz__AssertH__fail ( int errcode );
 59 | #define AssertH(cond,errcode) \
 60 |    { if (!(cond)) BZ2_bz__AssertH__fail ( errcode ); }
 61 | 
 62 | #if BZ_DEBUG
 63 | #define AssertD(cond,msg) \
 64 |    { if (!(cond)) {       \
 65 |       fprintf ( stderr,   \
 66 |         "\n\nlibbzip2(debug build): internal error\n\t%s\n", msg );\
 67 |       exit(1); \
 68 |    }}
 69 | #else
 70 | #define AssertD(cond,msg) /* */
 71 | #endif
 72 | 
 73 | #define VPrintf0(zf) \
 74 |    fprintf(stderr,zf)
 75 | #define VPrintf1(zf,za1) \
 76 |    fprintf(stderr,zf,za1)
 77 | #define VPrintf2(zf,za1,za2) \
 78 |    fprintf(stderr,zf,za1,za2)
 79 | #define VPrintf3(zf,za1,za2,za3) \
 80 |    fprintf(stderr,zf,za1,za2,za3)
 81 | #define VPrintf4(zf,za1,za2,za3,za4) \
 82 |    fprintf(stderr,zf,za1,za2,za3,za4)
 83 | #define VPrintf5(zf,za1,za2,za3,za4,za5) \
 84 |    fprintf(stderr,zf,za1,za2,za3,za4,za5)
 85 | 
 86 | #else
 87 | 
 88 | extern void bz_internal_error ( int errcode );
 89 | #define AssertH(cond,errcode) \
 90 |    { if (!(cond)) bz_internal_error ( errcode ); }
 91 | #define AssertD(cond,msg)                do { } while (0)
 92 | #define VPrintf0(zf)                     do { } while (0)
 93 | #define VPrintf1(zf,za1)                 do { } while (0)
 94 | #define VPrintf2(zf,za1,za2)             do { } while (0)
 95 | #define VPrintf3(zf,za1,za2,za3)         do { } while (0)
 96 | #define VPrintf4(zf,za1,za2,za3,za4)     do { } while (0)
 97 | #define VPrintf5(zf,za1,za2,za3,za4,za5) do { } while (0)
 98 | 
 99 | #endif
100 | 
101 | 
102 | #define BZALLOC(nnn) (strm->bzalloc)(strm->opaque,(nnn),1)
103 | #define BZFREE(ppp)  (strm->bzfree)(strm->opaque,(ppp))
104 | 
105 | 
106 | /*-- Header bytes. --*/
107 | 
108 | #define BZ_HDR_B 0x42   /* 'B' */
109 | #define BZ_HDR_Z 0x5a   /* 'Z' */
110 | #define BZ_HDR_h 0x68   /* 'h' */
111 | #define BZ_HDR_0 0x30   /* '0' */
112 |   
113 | /*-- Constants for the back end. --*/
114 | 
115 | #define BZ_MAX_ALPHA_SIZE 258
116 | #define BZ_MAX_CODE_LEN    23
117 | 
118 | #define BZ_RUNA 0
119 | #define BZ_RUNB 1
120 | 
121 | #define BZ_N_GROUPS 6
122 | #define BZ_G_SIZE   50
123 | #define BZ_N_ITERS  4
124 | 
125 | #define BZ_MAX_SELECTORS (2 + (900000 / BZ_G_SIZE))
126 | 
127 | 
128 | 
129 | /*-- Stuff for randomising repetitive blocks. --*/
130 | 
131 | extern Int32 BZ2_rNums[512];
132 | 
133 | #define BZ_RAND_DECLS                          \
134 |    Int32 rNToGo;                               \
135 |    Int32 rTPos                                 \
136 | 
137 | #define BZ_RAND_INIT_MASK                      \
138 |    s->rNToGo = 0;                              \
139 |    s->rTPos  = 0                               \
140 | 
141 | #define BZ_RAND_MASK ((s->rNToGo == 1) ? 1 : 0)
142 | 
143 | #define BZ_RAND_UPD_MASK                       \
144 |    if (s->rNToGo == 0) {                       \
145 |       s->rNToGo = BZ2_rNums[s->rTPos];         \
146 |       s->rTPos++;                              \
147 |       if (s->rTPos == 512) s->rTPos = 0;       \
148 |    }                                           \
149 |    s->rNToGo--;
150 | 
151 | 
152 | 
153 | /*-- Stuff for doing CRCs. --*/
154 | 
155 | extern UInt32 BZ2_crc32Table[256];
156 | 
157 | #define BZ_INITIALISE_CRC(crcVar)              \
158 | {                                              \
159 |    crcVar = 0xffffffffL;                       \
160 | }
161 | 
162 | #define BZ_FINALISE_CRC(crcVar)                \
163 | {                                              \
164 |    crcVar = ~(crcVar);                         \
165 | }
166 | 
167 | #define BZ_UPDATE_CRC(crcVar,cha)              \
168 | {                                              \
169 |    crcVar = (crcVar << 8) ^                    \
170 |             BZ2_crc32Table[(crcVar >> 24) ^    \
171 |                            ((UChar)cha)];      \
172 | }
173 | 
174 | 
175 | 
176 | /*-- States and modes for compression. --*/
177 | 
178 | #define BZ_M_IDLE      1
179 | #define BZ_M_RUNNING   2
180 | #define BZ_M_FLUSHING  3
181 | #define BZ_M_FINISHING 4
182 | 
183 | #define BZ_S_OUTPUT    1
184 | #define BZ_S_INPUT     2
185 | 
186 | #define BZ_N_RADIX 2
187 | #define BZ_N_QSORT 12
188 | #define BZ_N_SHELL 18
189 | #define BZ_N_OVERSHOOT (BZ_N_RADIX + BZ_N_QSORT + BZ_N_SHELL + 2)
190 | 
191 | 
192 | 
193 | 
194 | /*-- Structure holding all the compression-side stuff. --*/
195 | 
196 | typedef
197 |    struct {
198 |       /* pointer back to the struct bz_stream */
199 |       bz_stream* strm;
200 | 
201 |       /* mode this stream is in, and whether inputting */
202 |       /* or outputting data */
203 |       Int32    mode;
204 |       Int32    state;
205 | 
206 |       /* remembers avail_in when flush/finish requested */
207 |       UInt32   avail_in_expect;
208 | 
209 |       /* for doing the block sorting */
210 |       UInt32*  arr1;
211 |       UInt32*  arr2;
212 |       UInt32*  ftab;
213 |       Int32    origPtr;
214 | 
215 |       /* aliases for arr1 and arr2 */
216 |       UInt32*  ptr;
217 |       UChar*   block;
218 |       UInt16*  mtfv;
219 |       UChar*   zbits;
220 | 
221 |       /* for deciding when to use the fallback sorting algorithm */
222 |       Int32    workFactor;
223 | 
224 |       /* run-length-encoding of the input */
225 |       UInt32   state_in_ch;
226 |       Int32    state_in_len;
227 |       BZ_RAND_DECLS;
228 | 
229 |       /* input and output limits and current posns */
230 |       Int32    nblock;
231 |       Int32    nblockMAX;
232 |       Int32    numZ;
233 |       Int32    state_out_pos;
234 | 
235 |       /* map of bytes used in block */
236 |       Int32    nInUse;
237 |       Bool     inUse[256];
238 |       UChar    unseqToSeq[256];
239 | 
240 |       /* the buffer for bit stream creation */
241 |       UInt32   bsBuff;
242 |       Int32    bsLive;
243 | 
244 |       /* block and combined CRCs */
245 |       UInt32   blockCRC;
246 |       UInt32   combinedCRC;
247 | 
248 |       /* misc administratium */
249 |       Int32    verbosity;
250 |       Int32    blockNo;
251 |       Int32    blockSize100k;
252 | 
253 |       /* stuff for coding the MTF values */
254 |       Int32    nMTF;
255 |       Int32    mtfFreq    [BZ_MAX_ALPHA_SIZE];
256 |       UChar    selector   [BZ_MAX_SELECTORS];
257 |       UChar    selectorMtf[BZ_MAX_SELECTORS];
258 | 
259 |       UChar    len     [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
260 |       Int32    code    [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
261 |       Int32    rfreq   [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
262 |       /* second dimension: only 3 needed; 4 makes index calculations faster */
263 |       UInt32   len_pack[BZ_MAX_ALPHA_SIZE][4];
264 | 
265 |    }
266 |    EState;
267 | 
268 | 
269 | 
270 | /*-- externs for compression. --*/
271 | 
272 | extern void 
273 | BZ2_blockSort ( EState* );
274 | 
275 | extern void 
276 | BZ2_compressBlock ( EState*, Bool );
277 | 
278 | extern void 
279 | BZ2_bsInitWrite ( EState* );
280 | 
281 | extern void 
282 | BZ2_hbAssignCodes ( Int32*, UChar*, Int32, Int32, Int32 );
283 | 
284 | extern void 
285 | BZ2_hbMakeCodeLengths ( UChar*, Int32*, Int32, Int32 );
286 | 
287 | 
288 | 
289 | /*-- states for decompression. --*/
290 | 
291 | #define BZ_X_IDLE        1
292 | #define BZ_X_OUTPUT      2
293 | 
294 | #define BZ_X_MAGIC_1     10
295 | #define BZ_X_MAGIC_2     11
296 | #define BZ_X_MAGIC_3     12
297 | #define BZ_X_MAGIC_4     13
298 | #define BZ_X_BLKHDR_1    14
299 | #define BZ_X_BLKHDR_2    15
300 | #define BZ_X_BLKHDR_3    16
301 | #define BZ_X_BLKHDR_4    17
302 | #define BZ_X_BLKHDR_5    18
303 | #define BZ_X_BLKHDR_6    19
304 | #define BZ_X_BCRC_1      20
305 | #define BZ_X_BCRC_2      21
306 | #define BZ_X_BCRC_3      22
307 | #define BZ_X_BCRC_4      23
308 | #define BZ_X_RANDBIT     24
309 | #define BZ_X_ORIGPTR_1   25
310 | #define BZ_X_ORIGPTR_2   26
311 | #define BZ_X_ORIGPTR_3   27
312 | #define BZ_X_MAPPING_1   28
313 | #define BZ_X_MAPPING_2   29
314 | #define BZ_X_SELECTOR_1  30
315 | #define BZ_X_SELECTOR_2  31
316 | #define BZ_X_SELECTOR_3  32
317 | #define BZ_X_CODING_1    33
318 | #define BZ_X_CODING_2    34
319 | #define BZ_X_CODING_3    35
320 | #define BZ_X_MTF_1       36
321 | #define BZ_X_MTF_2       37
322 | #define BZ_X_MTF_3       38
323 | #define BZ_X_MTF_4       39
324 | #define BZ_X_MTF_5       40
325 | #define BZ_X_MTF_6       41
326 | #define BZ_X_ENDHDR_2    42
327 | #define BZ_X_ENDHDR_3    43
328 | #define BZ_X_ENDHDR_4    44
329 | #define BZ_X_ENDHDR_5    45
330 | #define BZ_X_ENDHDR_6    46
331 | #define BZ_X_CCRC_1      47
332 | #define BZ_X_CCRC_2      48
333 | #define BZ_X_CCRC_3      49
334 | #define BZ_X_CCRC_4      50
335 | 
336 | 
337 | 
338 | /*-- Constants for the fast MTF decoder. --*/
339 | 
340 | #define MTFA_SIZE 4096
341 | #define MTFL_SIZE 16
342 | 
343 | 
344 | 
345 | /*-- Structure holding all the decompression-side stuff. --*/
346 | 
347 | typedef
348 |    struct {
349 |       /* pointer back to the struct bz_stream */
350 |       bz_stream* strm;
351 | 
352 |       /* state indicator for this stream */
353 |       Int32    state;
354 | 
355 |       /* for doing the final run-length decoding */
356 |       UChar    state_out_ch;
357 |       Int32    state_out_len;
358 |       Bool     blockRandomised;
359 |       BZ_RAND_DECLS;
360 | 
361 |       /* the buffer for bit stream reading */
362 |       UInt32   bsBuff;
363 |       Int32    bsLive;
364 | 
365 |       /* misc administratium */
366 |       Int32    blockSize100k;
367 |       Bool     smallDecompress;
368 |       Int32    currBlockNo;
369 |       Int32    verbosity;
370 | 
371 |       /* for undoing the Burrows-Wheeler transform */
372 |       Int32    origPtr;
373 |       UInt32   tPos;
374 |       Int32    k0;
375 |       Int32    unzftab[256];
376 |       Int32    nblock_used;
377 |       Int32    cftab[257];
378 |       Int32    cftabCopy[257];
379 | 
380 |       /* for undoing the Burrows-Wheeler transform (FAST) */
381 |       UInt32   *tt;
382 | 
383 |       /* for undoing the Burrows-Wheeler transform (SMALL) */
384 |       UInt16   *ll16;
385 |       UChar    *ll4;
386 | 
387 |       /* stored and calculated CRCs */
388 |       UInt32   storedBlockCRC;
389 |       UInt32   storedCombinedCRC;
390 |       UInt32   calculatedBlockCRC;
391 |       UInt32   calculatedCombinedCRC;
392 | 
393 |       /* map of bytes used in block */
394 |       Int32    nInUse;
395 |       Bool     inUse[256];
396 |       Bool     inUse16[16];
397 |       UChar    seqToUnseq[256];
398 | 
399 |       /* for decoding the MTF values */
400 |       UChar    mtfa   [MTFA_SIZE];
401 |       Int32    mtfbase[256 / MTFL_SIZE];
402 |       UChar    selector   [BZ_MAX_SELECTORS];
403 |       UChar    selectorMtf[BZ_MAX_SELECTORS];
404 |       UChar    len  [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
405 | 
406 |       Int32    limit  [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
407 |       Int32    base   [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
408 |       Int32    perm   [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
409 |       Int32    minLens[BZ_N_GROUPS];
410 | 
411 |       /* save area for scalars in the main decompress code */
412 |       Int32    save_i;
413 |       Int32    save_j;
414 |       Int32    save_t;
415 |       Int32    save_alphaSize;
416 |       Int32    save_nGroups;
417 |       Int32    save_nSelectors;
418 |       Int32    save_EOB;
419 |       Int32    save_groupNo;
420 |       Int32    save_groupPos;
421 |       Int32    save_nextSym;
422 |       Int32    save_nblockMAX;
423 |       Int32    save_nblock;
424 |       Int32    save_es;
425 |       Int32    save_N;
426 |       Int32    save_curr;
427 |       Int32    save_zt;
428 |       Int32    save_zn; 
429 |       Int32    save_zvec;
430 |       Int32    save_zj;
431 |       Int32    save_gSel;
432 |       Int32    save_gMinlen;
433 |       Int32*   save_gLimit;
434 |       Int32*   save_gBase;
435 |       Int32*   save_gPerm;
436 | 
437 |    }
438 |    DState;
439 | 
440 | 
441 | 
442 | /*-- Macros for decompression. --*/
443 | 
444 | #define BZ_GET_FAST(cccc)                     \
445 |     /* c_tPos is unsigned, hence test < 0 is pointless. */ \
446 |     if (s->tPos >= (UInt32)100000 * (UInt32)s->blockSize100k) return True; \
447 |     s->tPos = s->tt[s->tPos];                 \
448 |     cccc = (UChar)(s->tPos & 0xff);           \
449 |     s->tPos >>= 8;
450 | 
451 | #define BZ_GET_FAST_C(cccc)                   \
452 |     /* c_tPos is unsigned, hence test < 0 is pointless. */ \
453 |     if (c_tPos >= (UInt32)100000 * (UInt32)ro_blockSize100k) return True; \
454 |     c_tPos = c_tt[c_tPos];                    \
455 |     cccc = (UChar)(c_tPos & 0xff);            \
456 |     c_tPos >>= 8;
457 | 
458 | #define SET_LL4(i,n)                                          \
459 |    { if (((i) & 0x1) == 0)                                    \
460 |         s->ll4[(i) >> 1] = (s->ll4[(i) >> 1] & 0xf0) | (n); else    \
461 |         s->ll4[(i) >> 1] = (s->ll4[(i) >> 1] & 0x0f) | ((n) << 4);  \
462 |    }
463 | 
464 | #define GET_LL4(i)                             \
465 |    ((((UInt32)(s->ll4[(i) >> 1])) >> (((i) << 2) & 0x4)) & 0xF)
466 | 
467 | #define SET_LL(i,n)                          \
468 |    { s->ll16[i] = (UInt16)(n & 0x0000ffff);  \
469 |      SET_LL4(i, n >> 16);                    \
470 |    }
471 | 
472 | #define GET_LL(i) \
473 |    (((UInt32)s->ll16[i]) | (GET_LL4(i) << 16))
474 | 
475 | #define BZ_GET_SMALL(cccc)                            \
476 |     /* c_tPos is unsigned, hence test < 0 is pointless. */ \
477 |     if (s->tPos >= (UInt32)100000 * (UInt32)s->blockSize100k) return True; \
478 |     cccc = BZ2_indexIntoF ( s->tPos, s->cftab );    \
479 |     s->tPos = GET_LL(s->tPos);
480 | 
481 | 
482 | /*-- externs for decompression. --*/
483 | 
484 | extern Int32 
485 | BZ2_indexIntoF ( Int32, Int32* );
486 | 
487 | extern Int32 
488 | BZ2_decompress ( DState* );
489 | 
490 | extern void 
491 | BZ2_hbCreateDecodeTables ( Int32*, Int32*, Int32*, UChar*,
492 |                            Int32,  Int32, Int32 );
493 | 
494 | 
495 | #endif
496 | 
497 | 
498 | /*-- BZ_NO_STDIO seems to make NULL disappear on some platforms. --*/
499 | 
500 | #ifdef BZ_NO_STDIO
501 | #ifndef NULL
502 | #define NULL 0
503 | #endif
504 | #endif
505 | 
506 | 
507 | /*-------------------------------------------------------------*/
508 | /*--- end                                   bzlib_private.h ---*/
509 | /*-------------------------------------------------------------*/
510 | 


--------------------------------------------------------------------------------
/bzmore:
--------------------------------------------------------------------------------
 1 | #!/bin/sh
 2 | 
 3 | # Bzmore wrapped for bzip2, 
 4 | # adapted from zmore by Philippe Troin  for Debian GNU/Linux.
 5 | 
 6 | PATH="/usr/bin:$PATH"; export PATH
 7 | 
 8 | prog=`echo $0 | sed 's|.*/||'`
 9 | case "$prog" in
10 | 	*less)	more=less	;;
11 | 	*)	more=more       ;;
12 | esac
13 | 
14 | if test "`echo -n a`" = "-n a"; then
15 |   # looks like a SysV system:
16 |   n1=''; n2='\c'
17 | else
18 |   n1='-n'; n2=''
19 | fi
20 | oldtty=`stty -g 2>/dev/null`
21 | if stty -cbreak 2>/dev/null; then
22 |   cb='cbreak'; ncb='-cbreak'
23 | else
24 |   # 'stty min 1' resets eof to ^a on both SunOS and SysV!
25 |   cb='min 1 -icanon'; ncb='icanon eof ^d'
26 | fi
27 | if test $? -eq 0 -a -n "$oldtty"; then
28 |    trap 'stty $oldtty 2>/dev/null; exit' 0 2 3 5 10 13 15
29 | else
30 |    trap 'stty $ncb echo 2>/dev/null; exit' 0 2 3 5 10 13 15
31 | fi
32 | 
33 | if test $# = 0; then
34 |     if test -t 0; then
35 | 	echo usage: $prog files...
36 |     else
37 | 	bzip2 -cdfq | eval $more
38 |     fi
39 | else
40 |     FIRST=1
41 |     for FILE
42 |     do
43 | 	if test $FIRST -eq 0; then
44 | 		echo $n1 "--More--(Next file: $FILE)$n2"
45 | 		stty $cb -echo 2>/dev/null
46 | 		ANS=`dd bs=1 count=1 2>/dev/null` 
47 | 		stty $ncb echo 2>/dev/null
48 | 		echo " "
49 | 		if test "$ANS" = 'e' -o "$ANS" = 'q'; then
50 | 			exit
51 | 		fi
52 | 	fi
53 | 	if test "$ANS" != 's'; then
54 | 		echo "------> $FILE <------"
55 | 		bzip2 -cdfq "$FILE" | eval $more
56 | 	fi
57 | 	if test -t; then
58 | 		FIRST=0
59 | 	fi
60 |     done
61 | fi
62 | 


--------------------------------------------------------------------------------
/bzmore.1:
--------------------------------------------------------------------------------
  1 | .\"Shamelessly copied from zmore.1 by Philippe Troin 
  2 | .\"for Debian GNU/Linux
  3 | .TH BZMORE 1
  4 | .SH NAME
  5 | bzmore, bzless \- file perusal filter for crt viewing of bzip2 compressed text
  6 | .SH SYNOPSIS
  7 | .B bzmore
  8 | [ name ...  ]
  9 | .br
 10 | .B bzless
 11 | [ name ...  ]
 12 | .SH NOTE
 13 | In the following description,
 14 | .I bzless
 15 | and
 16 | .I less
 17 | can be used interchangeably with
 18 | .I bzmore
 19 | and
 20 | .I more.
 21 | .SH DESCRIPTION
 22 | .I  Bzmore
 23 | is a filter which allows examination of compressed or plain text files
 24 | one screenful at a time on a soft-copy terminal.
 25 | .I bzmore
 26 | works on files compressed with
 27 | .I bzip2
 28 | and also on uncompressed files.
 29 | If a file does not exist,
 30 | .I bzmore
 31 | looks for a file of the same name with the addition of a .bz2 suffix.
 32 | .PP
 33 | .I Bzmore
 34 | normally pauses after each screenful, printing --More--
 35 | at the bottom of the screen.
 36 | If the user then types a carriage return, one more line is displayed.
 37 | If the user hits a space,
 38 | another screenful is displayed.  Other possibilities are enumerated later.
 39 | .PP
 40 | .I Bzmore
 41 | looks in the file
 42 | .I /etc/termcap
 43 | to determine terminal characteristics,
 44 | and to determine the default window size.
 45 | On a terminal capable of displaying 24 lines,
 46 | the default window size is 22 lines.
 47 | Other sequences which may be typed when
 48 | .I bzmore
 49 | pauses, and their effects, are as follows (\fIi\fP is an optional integer
 50 | argument, defaulting to 1) :
 51 | .PP
 52 | .IP \fIi\|\fP
 53 | display
 54 | .I i
 55 | more lines, (or another screenful if no argument is given)
 56 | .PP
 57 | .IP ^D
 58 | display 11 more lines (a ``scroll'').
 59 | If
 60 | .I i
 61 | is given, then the scroll size is set to \fIi\|\fP.
 62 | .PP
 63 | .IP d
 64 | same as ^D (control-D)
 65 | .PP
 66 | .IP \fIi\|\fPz
 67 | same as typing a space except that \fIi\|\fP, if present, becomes the new
 68 | window size.  Note that the window size reverts back to the default at the
 69 | end of the current file.
 70 | .PP
 71 | .IP \fIi\|\fPs
 72 | skip \fIi\|\fP lines and print a screenful of lines
 73 | .PP
 74 | .IP \fIi\|\fPf
 75 | skip \fIi\fP screenfuls and print a screenful of lines
 76 | .PP
 77 | .IP "q or Q"
 78 | quit reading the current file; go on to the next (if any)
 79 | .PP
 80 | .IP "e or q"
 81 | When the prompt --More--(Next file: 
 82 | .IR file )
 83 | is printed, this command causes bzmore to exit.
 84 | .PP
 85 | .IP s
 86 | When the prompt --More--(Next file: 
 87 | .IR file )
 88 | is printed, this command causes bzmore to skip the next file and continue.
 89 | .PP 
 90 | .IP =
 91 | Display the current line number.
 92 | .PP
 93 | .IP \fIi\|\fP/expr
 94 | search for the \fIi\|\fP-th occurrence of the regular expression \fIexpr.\fP
 95 | If the pattern is not found,
 96 | .I bzmore
 97 | goes on to the next file (if any).
 98 | Otherwise, a screenful is displayed, starting two lines before the place
 99 | where the expression was found.
100 | The user's erase and kill characters may be used to edit the regular
101 | expression.
102 | Erasing back past the first column cancels the search command.
103 | .PP
104 | .IP \fIi\|\fPn
105 | search for the \fIi\|\fP-th occurrence of the last regular expression entered.
106 | .PP
107 | .IP !command
108 | invoke a shell with \fIcommand\|\fP. 
109 | The character `!' in "command" are replaced with the
110 | previous shell command.  The sequence "\\!" is replaced by "!".
111 | .PP
112 | .IP ":q or :Q"
113 | quit reading the current file; go on to the next (if any)
114 | (same as q or Q).
115 | .PP
116 | .IP .
117 | (dot) repeat the previous command.
118 | .PP
119 | The commands take effect immediately, i.e., it is not necessary to
120 | type a carriage return.
121 | Up to the time when the command character itself is given,
122 | the user may hit the line kill character to cancel the numerical
123 | argument being formed.
124 | In addition, the user may hit the erase character to redisplay the
125 | --More-- message.
126 | .PP
127 | At any time when output is being sent to the terminal, the user can
128 | hit the quit key (normally control\-\\).
129 | .I Bzmore
130 | will stop sending output, and will display the usual --More--
131 | prompt.
132 | The user may then enter one of the above commands in the normal manner.
133 | Unfortunately, some output is lost when this is done, due to the
134 | fact that any characters waiting in the terminal's output queue
135 | are flushed when the quit signal occurs.
136 | .PP
137 | The terminal is set to
138 | .I noecho
139 | mode by this program so that the output can be continuous.
140 | What you type will thus not show on your terminal, except for the / and !
141 | commands.
142 | .PP
143 | If the standard output is not a teletype, then
144 | .I bzmore
145 | acts just like
146 | .I bzcat,
147 | except that a header is printed before each file.
148 | .SH FILES
149 | .DT
150 | /etc/termcap		Terminal data base
151 | .SH "SEE ALSO"
152 | more(1), less(1), bzip2(1), bzdiff(1), bzgrep(1)
153 | 


--------------------------------------------------------------------------------
/cmake/dist.cmake:
--------------------------------------------------------------------------------
  1 | # LuaDist CMake utility library.
  2 | # Provides sane project defaults and macros common to LuaDist CMake builds.
  3 | # 
  4 | # Copyright (C) 2007-2012 LuaDist.
  5 | # by David Manura, Peter Drahoš
  6 | # Redistribution and use of this file is allowed according to the terms of the MIT license.
  7 | # For details see the COPYRIGHT file distributed with LuaDist.
  8 | # Please note that the package source code is licensed under its own license.
  9 | 
 10 | ## Extract information from dist.info
 11 | if ( NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/dist.info )
 12 |   message ( FATAL_ERROR
 13 |     "Missing dist.info file (${CMAKE_CURRENT_SOURCE_DIR}/dist.info)." )
 14 | endif ()
 15 | file ( READ ${CMAKE_CURRENT_SOURCE_DIR}/dist.info DIST_INFO )
 16 | if ( "${DIST_INFO}" STREQUAL "" )
 17 |   message ( FATAL_ERROR "Failed to load dist.info." )
 18 | endif ()
 19 | # Reads field `name` from dist.info string `DIST_INFO` into variable `var`.
 20 | macro ( _parse_dist_field name var )
 21 |   string ( REGEX REPLACE ".*${name}[ \t]?=[ \t]?[\"']([^\"']+)[\"'].*" "\\1"
 22 |            ${var} "${DIST_INFO}" )
 23 |   if ( ${var} STREQUAL DIST_INFO )
 24 |     message ( FATAL_ERROR "Failed to extract \"${var}\" from dist.info" )
 25 |   endif ()
 26 | endmacro ()
 27 | #
 28 | _parse_dist_field ( name DIST_NAME )
 29 | _parse_dist_field ( version DIST_VERSION )
 30 | _parse_dist_field ( license DIST_LICENSE )
 31 | _parse_dist_field ( author DIST_AUTHOR )
 32 | _parse_dist_field ( maintainer DIST_MAINTAINER )
 33 | _parse_dist_field ( url DIST_URL )
 34 | _parse_dist_field ( desc DIST_DESC )
 35 | message ( "DIST_NAME: ${DIST_NAME}")
 36 | message ( "DIST_VERSION: ${DIST_VERSION}")
 37 | message ( "DIST_LICENSE: ${DIST_LICENSE}")
 38 | message ( "DIST_AUTHOR: ${DIST_AUTHOR}")
 39 | message ( "DIST_MAINTAINER: ${DIST_MAINTAINER}")
 40 | message ( "DIST_URL: ${DIST_URL}")
 41 | message ( "DIST_DESC: ${DIST_DESC}")
 42 | string ( REGEX REPLACE ".*depends[ \t]?=[ \t]?[\"']([^\"']+)[\"'].*" "\\1"
 43 |          DIST_DEPENDS ${DIST_INFO} )
 44 | if ( DIST_DEPENDS STREQUAL DIST_INFO )
 45 |   set ( DIST_DEPENDS "" )
 46 | endif ()
 47 | message ( "DIST_DEPENDS: ${DIST_DEPENDS}")
 48 | ## 2DO: Parse DIST_DEPENDS and try to install Dependencies with automatically using externalproject_add
 49 | 
 50 | 
 51 | ## INSTALL DEFAULTS (Relative to CMAKE_INSTALL_PREFIX)
 52 | # Primary paths
 53 | set ( INSTALL_BIN bin CACHE PATH "Where to install binaries to." )
 54 | set ( INSTALL_LIB lib CACHE PATH "Where to install libraries to." )
 55 | set ( INSTALL_INC include CACHE PATH "Where to install headers to." )
 56 | set ( INSTALL_ETC etc CACHE PATH "Where to store configuration files" )
 57 | set ( INSTALL_SHARE share CACHE PATH "Directory for shared data." )
 58 | 
 59 | # Secondary paths
 60 | option ( INSTALL_VERSION
 61 |       "Install runtime libraries and executables with version information." OFF)
 62 | set ( INSTALL_DATA ${INSTALL_SHARE}/${DIST_NAME} CACHE PATH
 63 |       "Directory the package can store documentation, tests or other data in.")  
 64 | set ( INSTALL_DOC  ${INSTALL_DATA}/doc CACHE PATH
 65 |       "Recommended directory to install documentation into.")
 66 | set ( INSTALL_EXAMPLE ${INSTALL_DATA}/example CACHE PATH
 67 |       "Recommended directory to install examples into.")
 68 | set ( INSTALL_TEST ${INSTALL_DATA}/test CACHE PATH
 69 |       "Recommended directory to install tests into.")
 70 | set ( INSTALL_FOO  ${INSTALL_DATA}/etc CACHE PATH
 71 |       "Where to install additional files")
 72 | 
 73 | # Tweaks and other defaults
 74 | # Setting CMAKE to use loose block and search for find modules in source directory
 75 | set ( CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true )
 76 | set ( CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH} )
 77 | option ( BUILD_SHARED_LIBS "Build shared libraries" ON )
 78 | 
 79 | # In MSVC, prevent warnings that can occur when using standard libraries.
 80 | if ( MSVC )
 81 |   add_definitions ( -D_CRT_SECURE_NO_WARNINGS )
 82 | endif ()
 83 | 
 84 | # RPath and relative linking
 85 | option ( USE_RPATH "Use relative linking." ON)
 86 | if ( USE_RPATH )
 87 |   string ( REGEX REPLACE "[^!/]+" ".." UP_DIR ${INSTALL_BIN} )
 88 |   set ( CMAKE_SKIP_BUILD_RPATH FALSE CACHE STRING "" FORCE )
 89 |   set ( CMAKE_BUILD_WITH_INSTALL_RPATH FALSE CACHE STRING "" FORCE )
 90 |   set ( CMAKE_INSTALL_RPATH $ORIGIN/${UP_DIR}/${INSTALL_LIB}
 91 |         CACHE STRING "" FORCE )
 92 |   set ( CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE CACHE STRING "" FORCE )
 93 |   set ( CMAKE_INSTALL_NAME_DIR @executable_path/${UP_DIR}/${INSTALL_LIB}
 94 |         CACHE STRING "" FORCE )
 95 | endif ()
 96 | 
 97 | ## MACROS
 98 | # Parser macro
 99 | macro ( parse_arguments prefix arg_names option_names)
100 |   set ( DEFAULT_ARGS )
101 |   foreach ( arg_name ${arg_names} )
102 |     set ( ${prefix}_${arg_name} )
103 |   endforeach ()
104 |   foreach ( option ${option_names} )
105 |     set ( ${prefix}_${option} FALSE )
106 |   endforeach ()
107 | 
108 |   set ( current_arg_name DEFAULT_ARGS )
109 |   set ( current_arg_list )
110 |   foreach ( arg ${ARGN} )            
111 |     set ( larg_names ${arg_names} )    
112 |     list ( FIND larg_names "${arg}" is_arg_name )                   
113 |     if ( is_arg_name GREATER -1 )
114 |       set ( ${prefix}_${current_arg_name} ${current_arg_list} )
115 |       set ( current_arg_name ${arg} )
116 |       set ( current_arg_list )
117 |     else ()
118 |       set ( loption_names ${option_names} )    
119 |       list ( FIND loption_names "${arg}" is_option )            
120 |       if ( is_option GREATER -1 )
121 |         set ( ${prefix}_${arg} TRUE )
122 |       else ()
123 |         set ( current_arg_list ${current_arg_list} ${arg} )
124 |       endif ()
125 |     endif ()
126 |   endforeach ()
127 |   set ( ${prefix}_${current_arg_name} ${current_arg_list} )
128 | endmacro ()
129 | 
130 | 
131 | # install_executable ( executable_targets )
132 | # Installs any executables generated using "add_executable".
133 | # USE: install_executable ( lua )
134 | # NOTE: subdirectories are NOT supported
135 | set ( CPACK_COMPONENT_RUNTIME_DISPLAY_NAME "${DIST_NAME} Runtime" )
136 | set ( CPACK_COMPONENT_RUNTIME_DESCRIPTION
137 |       "Executables and runtime libraries. Installed into ${INSTALL_BIN}." )
138 | macro ( install_executable )
139 |   foreach ( _file ${ARGN} )
140 |     if ( INSTALL_VERSION )
141 |       set_target_properties ( ${_file} PROPERTIES VERSION ${DIST_VERSION}
142 |                               SOVERSION ${DIST_VERSION} )
143 |     endif ()
144 |     install ( TARGETS ${_file} RUNTIME DESTINATION ${INSTALL_BIN}
145 |               COMPONENT Runtime )
146 |   endforeach()
147 | endmacro ()
148 | 
149 | # install_library ( library_targets )
150 | # Installs any libraries generated using "add_library" into apropriate places.
151 | # USE: install_library ( libexpat )
152 | # NOTE: subdirectories are NOT supported
153 | set ( CPACK_COMPONENT_LIBRARY_DISPLAY_NAME "${DIST_NAME} Development Libraries" )
154 | set ( CPACK_COMPONENT_LIBRARY_DESCRIPTION
155 |   "Static and import libraries needed for development. Installed into ${INSTALL_LIB} or ${INSTALL_BIN}." )
156 | macro ( install_library )
157 |   foreach ( _file ${ARGN} )
158 |     if ( INSTALL_VERSION )
159 |       set_target_properties ( ${_file} PROPERTIES VERSION ${DIST_VERSION}
160 |                               SOVERSION ${DIST_VERSION} )
161 |     endif ()
162 |     install ( TARGETS ${_file}
163 |               RUNTIME DESTINATION ${INSTALL_BIN} COMPONENT Runtime
164 |               LIBRARY DESTINATION ${INSTALL_LIB} COMPONENT Runtime 
165 |               ARCHIVE DESTINATION ${INSTALL_LIB} COMPONENT Library )
166 |   endforeach()
167 | endmacro ()
168 | 
169 | # helper function for various install_* functions, for PATTERN/REGEX args.
170 | macro ( _complete_install_args )
171 |   if ( NOT("${_ARG_PATTERN}" STREQUAL "") )
172 |     set ( _ARG_PATTERN PATTERN ${_ARG_PATTERN} )
173 |   endif ()
174 |   if ( NOT("${_ARG_REGEX}" STREQUAL "") )
175 |     set ( _ARG_REGEX REGEX ${_ARG_REGEX} )
176 |   endif ()
177 | endmacro ()
178 | 
179 | # install_header ( files/directories [INTO destination] )
180 | # Install a directories or files into header destination.
181 | # USE: install_header ( lua.h luaconf.h ) or install_header ( GL )
182 | # USE: install_header ( mylib.h INTO mylib )
183 | # For directories, supports optional PATTERN/REGEX arguments like install().
184 | set ( CPACK_COMPONENT_HEADER_DISPLAY_NAME "${DIST_NAME} Development Headers" )
185 | set ( CPACK_COMPONENT_HEADER_DESCRIPTION
186 |       "Headers needed for development. Installed into ${INSTALL_INC}." )
187 | macro ( install_header )
188 |   parse_arguments ( _ARG "INTO;PATTERN;REGEX" "" ${ARGN} )
189 |   _complete_install_args()
190 |   foreach ( _file ${_ARG_DEFAULT_ARGS} )
191 |     if ( IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${_file}" )
192 |       install ( DIRECTORY ${_file} DESTINATION ${INSTALL_INC}/${_ARG_INTO}
193 |                 COMPONENT Header ${_ARG_PATTERN} ${_ARG_REGEX} )
194 |     else ()
195 |       install ( FILES ${_file} DESTINATION ${INSTALL_INC}/${_ARG_INTO}
196 |                 COMPONENT Header )
197 |     endif ()
198 |   endforeach()
199 | endmacro ()
200 | 
201 | # install_data ( files/directories [INTO destination] )
202 | # This installs additional data files or directories.
203 | # USE: install_data ( extra data.dat )
204 | # USE: install_data ( image1.png image2.png INTO images )
205 | # For directories, supports optional PATTERN/REGEX arguments like install().
206 | set ( CPACK_COMPONENT_DATA_DISPLAY_NAME "${DIST_NAME} Data" )
207 | set ( CPACK_COMPONENT_DATA_DESCRIPTION
208 |       "Application data. Installed into ${INSTALL_DATA}." )
209 | macro ( install_data )
210 |   parse_arguments ( _ARG "INTO;PATTERN;REGEX" "" ${ARGN} )
211 |   _complete_install_args()
212 |   foreach ( _file ${_ARG_DEFAULT_ARGS} )
213 |     if ( IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${_file}" )
214 |       install ( DIRECTORY ${_file}
215 |                 DESTINATION ${INSTALL_DATA}/${_ARG_INTO}
216 |                 COMPONENT Data ${_ARG_PATTERN} ${_ARG_REGEX} )
217 |     else ()
218 |       install ( FILES ${_file} DESTINATION ${INSTALL_DATA}/${_ARG_INTO}
219 |                 COMPONENT Data )
220 |     endif ()
221 |   endforeach()
222 | endmacro ()
223 | 
224 | # INSTALL_DOC ( files/directories [INTO destination] )
225 | # This installs documentation content
226 | # USE: install_doc ( doc/ doc.pdf )
227 | # USE: install_doc ( index.html INTO html )
228 | # For directories, supports optional PATTERN/REGEX arguments like install().
229 | set ( CPACK_COMPONENT_DOCUMENTATION_DISPLAY_NAME "${DIST_NAME} Documentation" )
230 | set ( CPACK_COMPONENT_DOCUMENTATION_DESCRIPTION
231 |       "Application documentation. Installed into ${INSTALL_DOC}." )
232 | macro ( install_doc )
233 |   parse_arguments ( _ARG "INTO;PATTERN;REGEX" "" ${ARGN} )
234 |   _complete_install_args()
235 |   foreach ( _file ${_ARG_DEFAULT_ARGS} )
236 |     if ( IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${_file}" )
237 |       install ( DIRECTORY ${_file} DESTINATION ${INSTALL_DOC}/${_ARG_INTO}
238 |                 COMPONENT Documentation ${_ARG_PATTERN} ${_ARG_REGEX} )
239 |     else ()
240 |       install ( FILES ${_file} DESTINATION ${INSTALL_DOC}/${_ARG_INTO}
241 |                 COMPONENT Documentation )
242 |     endif ()
243 |   endforeach()
244 | endmacro ()
245 | 
246 | # install_example ( files/directories [INTO destination]  )
247 | # This installs additional examples
248 | # USE: install_example ( examples/ exampleA )
249 | # USE: install_example ( super_example super_data INTO super)
250 | # For directories, supports optional PATTERN/REGEX argument like install().
251 | set ( CPACK_COMPONENT_EXAMPLE_DISPLAY_NAME "${DIST_NAME} Examples" )
252 | set ( CPACK_COMPONENT_EXAMPLE_DESCRIPTION
253 |     "Examples and their associated data. Installed into ${INSTALL_EXAMPLE}." )
254 | macro ( install_example )
255 |   parse_arguments ( _ARG "INTO;PATTERN;REGEX" "" ${ARGN} )
256 |   _complete_install_args()
257 |   foreach ( _file ${_ARG_DEFAULT_ARGS} )
258 |     if ( IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${_file}" )
259 |       install ( DIRECTORY ${_file} DESTINATION ${INSTALL_EXAMPLE}/${_ARG_INTO}
260 |                 COMPONENT Example ${_ARG_PATTERN} ${_ARG_REGEX} )
261 |     else ()
262 |       install ( FILES ${_file} DESTINATION ${INSTALL_EXAMPLE}/${_ARG_INTO}
263 |                 COMPONENT Example )
264 |     endif ()
265 |   endforeach()
266 | endmacro ()
267 | 
268 | # install_test ( files/directories [INTO destination] )
269 | # This installs tests and test files, DOES NOT EXECUTE TESTS
270 | # USE: install_test ( my_test data.sql )
271 | # USE: install_test ( feature_x_test INTO x )
272 | # For directories, supports optional PATTERN/REGEX argument like install().
273 | set ( CPACK_COMPONENT_TEST_DISPLAY_NAME "${DIST_NAME} Tests" )
274 | set ( CPACK_COMPONENT_TEST_DESCRIPTION
275 |       "Tests and associated data. Installed into ${INSTALL_TEST}." )
276 | macro ( install_test )
277 |   parse_arguments ( _ARG "INTO;PATTERN;REGEX" "" ${ARGN} )
278 |   _complete_install_args()
279 |   foreach ( _file ${_ARG_DEFAULT_ARGS} )
280 |     if ( IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${_file}" )
281 |       install ( DIRECTORY ${_file} DESTINATION ${INSTALL_TEST}/${_ARG_INTO}
282 |                 COMPONENT Test ${_ARG_PATTERN} ${_ARG_REGEX} )
283 |     else ()
284 |       install ( FILES ${_file} DESTINATION ${INSTALL_TEST}/${_ARG_INTO}
285 |                 COMPONENT Test )
286 |     endif ()
287 |   endforeach()
288 | endmacro ()
289 | 
290 | # install_foo ( files/directories [INTO destination] )
291 | # This installs optional or otherwise unneeded content
292 | # USE: install_foo ( etc/ example.doc )
293 | # USE: install_foo ( icon.png logo.png INTO icons)
294 | # For directories, supports optional PATTERN/REGEX argument like install().
295 | set ( CPACK_COMPONENT_OTHER_DISPLAY_NAME "${DIST_NAME} Unspecified Content" )
296 | set ( CPACK_COMPONENT_OTHER_DESCRIPTION
297 |       "Other unspecified content. Installed into ${INSTALL_FOO}." )
298 | macro ( install_foo )
299 |   parse_arguments ( _ARG "INTO;PATTERN;REGEX" "" ${ARGN} )
300 |   _complete_install_args()
301 |   foreach ( _file ${_ARG_DEFAULT_ARGS} )
302 |     if ( IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${_file}" )
303 |       install ( DIRECTORY ${_file} DESTINATION ${INSTALL_FOO}/${_ARG_INTO}
304 |                 COMPONENT Other ${_ARG_PATTERN} ${_ARG_REGEX} )
305 |     else ()
306 |       install ( FILES ${_file} DESTINATION ${INSTALL_FOO}/${_ARG_INTO}
307 |                 COMPONENT Other )
308 |     endif ()
309 |   endforeach()
310 | endmacro ()
311 | 
312 | ## CTest defaults
313 | 
314 | ## CPack defaults
315 | set ( CPACK_GENERATOR "ZIP" )
316 | set ( CPACK_STRIP_FILES TRUE )
317 | set ( CPACK_PACKAGE_NAME "${DIST_NAME}" )
318 | set ( CPACK_PACKAGE_VERSION "${DIST_VERSION}")
319 | set ( CPACK_PACKAGE_VENDOR "LuaDist" )
320 | set ( CPACK_COMPONENTS_ALL Runtime Library Header Data Documentation Example Other )
321 | include ( CPack )
322 | 


--------------------------------------------------------------------------------
/crctable.c:
--------------------------------------------------------------------------------
  1 | 
  2 | /*-------------------------------------------------------------*/
  3 | /*--- Table for doing CRCs                                  ---*/
  4 | /*---                                            crctable.c ---*/
  5 | /*-------------------------------------------------------------*/
  6 | 
  7 | /* ------------------------------------------------------------------
  8 |    This file is part of bzip2/libbzip2, a program and library for
  9 |    lossless, block-sorting data compression.
 10 | 
 11 |    bzip2/libbzip2 version 1.0.5 of 10 December 2007
 12 |    Copyright (C) 1996-2007 Julian Seward 
 13 | 
 14 |    Please read the WARNING, DISCLAIMER and PATENTS sections in the 
 15 |    README file.
 16 | 
 17 |    This program is released under the terms of the license contained
 18 |    in the file LICENSE.
 19 |    ------------------------------------------------------------------ */
 20 | 
 21 | 
 22 | #include "bzlib_private.h"
 23 | 
 24 | /*--
 25 |   I think this is an implementation of the AUTODIN-II,
 26 |   Ethernet & FDDI 32-bit CRC standard.  Vaguely derived
 27 |   from code by Rob Warnock, in Section 51 of the
 28 |   comp.compression FAQ.
 29 | --*/
 30 | 
 31 | UInt32 BZ2_crc32Table[256] = {
 32 | 
 33 |    /*-- Ugly, innit? --*/
 34 | 
 35 |    0x00000000L, 0x04c11db7L, 0x09823b6eL, 0x0d4326d9L,
 36 |    0x130476dcL, 0x17c56b6bL, 0x1a864db2L, 0x1e475005L,
 37 |    0x2608edb8L, 0x22c9f00fL, 0x2f8ad6d6L, 0x2b4bcb61L,
 38 |    0x350c9b64L, 0x31cd86d3L, 0x3c8ea00aL, 0x384fbdbdL,
 39 |    0x4c11db70L, 0x48d0c6c7L, 0x4593e01eL, 0x4152fda9L,
 40 |    0x5f15adacL, 0x5bd4b01bL, 0x569796c2L, 0x52568b75L,
 41 |    0x6a1936c8L, 0x6ed82b7fL, 0x639b0da6L, 0x675a1011L,
 42 |    0x791d4014L, 0x7ddc5da3L, 0x709f7b7aL, 0x745e66cdL,
 43 |    0x9823b6e0L, 0x9ce2ab57L, 0x91a18d8eL, 0x95609039L,
 44 |    0x8b27c03cL, 0x8fe6dd8bL, 0x82a5fb52L, 0x8664e6e5L,
 45 |    0xbe2b5b58L, 0xbaea46efL, 0xb7a96036L, 0xb3687d81L,
 46 |    0xad2f2d84L, 0xa9ee3033L, 0xa4ad16eaL, 0xa06c0b5dL,
 47 |    0xd4326d90L, 0xd0f37027L, 0xddb056feL, 0xd9714b49L,
 48 |    0xc7361b4cL, 0xc3f706fbL, 0xceb42022L, 0xca753d95L,
 49 |    0xf23a8028L, 0xf6fb9d9fL, 0xfbb8bb46L, 0xff79a6f1L,
 50 |    0xe13ef6f4L, 0xe5ffeb43L, 0xe8bccd9aL, 0xec7dd02dL,
 51 |    0x34867077L, 0x30476dc0L, 0x3d044b19L, 0x39c556aeL,
 52 |    0x278206abL, 0x23431b1cL, 0x2e003dc5L, 0x2ac12072L,
 53 |    0x128e9dcfL, 0x164f8078L, 0x1b0ca6a1L, 0x1fcdbb16L,
 54 |    0x018aeb13L, 0x054bf6a4L, 0x0808d07dL, 0x0cc9cdcaL,
 55 |    0x7897ab07L, 0x7c56b6b0L, 0x71159069L, 0x75d48ddeL,
 56 |    0x6b93dddbL, 0x6f52c06cL, 0x6211e6b5L, 0x66d0fb02L,
 57 |    0x5e9f46bfL, 0x5a5e5b08L, 0x571d7dd1L, 0x53dc6066L,
 58 |    0x4d9b3063L, 0x495a2dd4L, 0x44190b0dL, 0x40d816baL,
 59 |    0xaca5c697L, 0xa864db20L, 0xa527fdf9L, 0xa1e6e04eL,
 60 |    0xbfa1b04bL, 0xbb60adfcL, 0xb6238b25L, 0xb2e29692L,
 61 |    0x8aad2b2fL, 0x8e6c3698L, 0x832f1041L, 0x87ee0df6L,
 62 |    0x99a95df3L, 0x9d684044L, 0x902b669dL, 0x94ea7b2aL,
 63 |    0xe0b41de7L, 0xe4750050L, 0xe9362689L, 0xedf73b3eL,
 64 |    0xf3b06b3bL, 0xf771768cL, 0xfa325055L, 0xfef34de2L,
 65 |    0xc6bcf05fL, 0xc27dede8L, 0xcf3ecb31L, 0xcbffd686L,
 66 |    0xd5b88683L, 0xd1799b34L, 0xdc3abdedL, 0xd8fba05aL,
 67 |    0x690ce0eeL, 0x6dcdfd59L, 0x608edb80L, 0x644fc637L,
 68 |    0x7a089632L, 0x7ec98b85L, 0x738aad5cL, 0x774bb0ebL,
 69 |    0x4f040d56L, 0x4bc510e1L, 0x46863638L, 0x42472b8fL,
 70 |    0x5c007b8aL, 0x58c1663dL, 0x558240e4L, 0x51435d53L,
 71 |    0x251d3b9eL, 0x21dc2629L, 0x2c9f00f0L, 0x285e1d47L,
 72 |    0x36194d42L, 0x32d850f5L, 0x3f9b762cL, 0x3b5a6b9bL,
 73 |    0x0315d626L, 0x07d4cb91L, 0x0a97ed48L, 0x0e56f0ffL,
 74 |    0x1011a0faL, 0x14d0bd4dL, 0x19939b94L, 0x1d528623L,
 75 |    0xf12f560eL, 0xf5ee4bb9L, 0xf8ad6d60L, 0xfc6c70d7L,
 76 |    0xe22b20d2L, 0xe6ea3d65L, 0xeba91bbcL, 0xef68060bL,
 77 |    0xd727bbb6L, 0xd3e6a601L, 0xdea580d8L, 0xda649d6fL,
 78 |    0xc423cd6aL, 0xc0e2d0ddL, 0xcda1f604L, 0xc960ebb3L,
 79 |    0xbd3e8d7eL, 0xb9ff90c9L, 0xb4bcb610L, 0xb07daba7L,
 80 |    0xae3afba2L, 0xaafbe615L, 0xa7b8c0ccL, 0xa379dd7bL,
 81 |    0x9b3660c6L, 0x9ff77d71L, 0x92b45ba8L, 0x9675461fL,
 82 |    0x8832161aL, 0x8cf30badL, 0x81b02d74L, 0x857130c3L,
 83 |    0x5d8a9099L, 0x594b8d2eL, 0x5408abf7L, 0x50c9b640L,
 84 |    0x4e8ee645L, 0x4a4ffbf2L, 0x470cdd2bL, 0x43cdc09cL,
 85 |    0x7b827d21L, 0x7f436096L, 0x7200464fL, 0x76c15bf8L,
 86 |    0x68860bfdL, 0x6c47164aL, 0x61043093L, 0x65c52d24L,
 87 |    0x119b4be9L, 0x155a565eL, 0x18197087L, 0x1cd86d30L,
 88 |    0x029f3d35L, 0x065e2082L, 0x0b1d065bL, 0x0fdc1becL,
 89 |    0x3793a651L, 0x3352bbe6L, 0x3e119d3fL, 0x3ad08088L,
 90 |    0x2497d08dL, 0x2056cd3aL, 0x2d15ebe3L, 0x29d4f654L,
 91 |    0xc5a92679L, 0xc1683bceL, 0xcc2b1d17L, 0xc8ea00a0L,
 92 |    0xd6ad50a5L, 0xd26c4d12L, 0xdf2f6bcbL, 0xdbee767cL,
 93 |    0xe3a1cbc1L, 0xe760d676L, 0xea23f0afL, 0xeee2ed18L,
 94 |    0xf0a5bd1dL, 0xf464a0aaL, 0xf9278673L, 0xfde69bc4L,
 95 |    0x89b8fd09L, 0x8d79e0beL, 0x803ac667L, 0x84fbdbd0L,
 96 |    0x9abc8bd5L, 0x9e7d9662L, 0x933eb0bbL, 0x97ffad0cL,
 97 |    0xafb010b1L, 0xab710d06L, 0xa6322bdfL, 0xa2f33668L,
 98 |    0xbcb4666dL, 0xb8757bdaL, 0xb5365d03L, 0xb1f740b4L
 99 | };
100 | 
101 | 
102 | /*-------------------------------------------------------------*/
103 | /*--- end                                        crctable.c ---*/
104 | /*-------------------------------------------------------------*/
105 | 


--------------------------------------------------------------------------------
/dist.info:
--------------------------------------------------------------------------------
 1 | --- This file is part of LuaDist project
 2 | 
 3 | name = "bzip2"
 4 | version = "1.0.5"
 5 | 
 6 | desc = "bzip2 is a high compression ratio data compression library."
 7 | author = "Julian Seward"
 8 | license = "BSD"
 9 | url = "http://www.bzip.org/"
10 | maintainer = "Peter Kapec"
11 | 


--------------------------------------------------------------------------------
/dlltest.c:
--------------------------------------------------------------------------------
  1 | /*
  2 |    minibz2
  3 |       libbz2.dll test program.
  4 |       by Yoshioka Tsuneo (tsuneo@rr.iij4u.or.jp)
  5 |       This file is Public Domain.  Welcome any email to me.
  6 | 
  7 |    usage: minibz2 [-d] [-{1,2,..9}] [[srcfilename] destfilename]
  8 | */
  9 | 
 10 | #define BZ_IMPORT
 11 | #include 
 12 | #include 
 13 | #include "bzlib.h"
 14 | #ifdef _WIN32
 15 | #include 
 16 | #endif
 17 | 
 18 | 
 19 | #ifdef _WIN32
 20 | 
 21 | #define BZ2_LIBNAME "libbz2-1.0.2.DLL" 
 22 | 
 23 | #include 
 24 | static int BZ2DLLLoaded = 0;
 25 | static HINSTANCE BZ2DLLhLib;
 26 | int BZ2DLLLoadLibrary(void)
 27 | {
 28 |    HINSTANCE hLib;
 29 | 
 30 |    if(BZ2DLLLoaded==1){return 0;}
 31 |    hLib=LoadLibrary(BZ2_LIBNAME);
 32 |    if(hLib == NULL){
 33 |       fprintf(stderr,"Can't load %s\n",BZ2_LIBNAME);
 34 |       return -1;
 35 |    }
 36 |    BZ2_bzlibVersion=GetProcAddress(hLib,"BZ2_bzlibVersion");
 37 |    BZ2_bzopen=GetProcAddress(hLib,"BZ2_bzopen");
 38 |    BZ2_bzdopen=GetProcAddress(hLib,"BZ2_bzdopen");
 39 |    BZ2_bzread=GetProcAddress(hLib,"BZ2_bzread");
 40 |    BZ2_bzwrite=GetProcAddress(hLib,"BZ2_bzwrite");
 41 |    BZ2_bzflush=GetProcAddress(hLib,"BZ2_bzflush");
 42 |    BZ2_bzclose=GetProcAddress(hLib,"BZ2_bzclose");
 43 |    BZ2_bzerror=GetProcAddress(hLib,"BZ2_bzerror");
 44 | 
 45 |    if (!BZ2_bzlibVersion || !BZ2_bzopen || !BZ2_bzdopen
 46 |        || !BZ2_bzread || !BZ2_bzwrite || !BZ2_bzflush
 47 |        || !BZ2_bzclose || !BZ2_bzerror) {
 48 |       fprintf(stderr,"GetProcAddress failed.\n");
 49 |       return -1;
 50 |    }
 51 |    BZ2DLLLoaded=1;
 52 |    BZ2DLLhLib=hLib;
 53 |    return 0;
 54 | 
 55 | }
 56 | int BZ2DLLFreeLibrary(void)
 57 | {
 58 |    if(BZ2DLLLoaded==0){return 0;}
 59 |    FreeLibrary(BZ2DLLhLib);
 60 |    BZ2DLLLoaded=0;
 61 | }
 62 | #endif /* WIN32 */
 63 | 
 64 | void usage(void)
 65 | {
 66 |    puts("usage: minibz2 [-d] [-{1,2,..9}] [[srcfilename] destfilename]");
 67 | }
 68 | 
 69 | int main(int argc,char *argv[])
 70 | {
 71 |    int decompress = 0;
 72 |    int level = 9;
 73 |    char *fn_r = NULL;
 74 |    char *fn_w = NULL;
 75 | 
 76 | #ifdef _WIN32
 77 |    if(BZ2DLLLoadLibrary()<0){
 78 |       fprintf(stderr,"Loading of %s failed.  Giving up.\n", BZ2_LIBNAME);
 79 |       exit(1);
 80 |    }
 81 |    printf("Loading of %s succeeded.  Library version is %s.\n",
 82 |           BZ2_LIBNAME, BZ2_bzlibVersion() );
 83 | #endif
 84 |    while(++argv,--argc){
 85 |       if(**argv =='-' || **argv=='/'){
 86 |          char *p;
 87 | 
 88 |          for(p=*argv+1;*p;p++){
 89 |             if(*p=='d'){
 90 |                decompress = 1;
 91 |             }else if('1'<=*p && *p<='9'){
 92 |                level = *p - '0';
 93 |             }else{
 94 |                usage();
 95 |                exit(1);
 96 |             }
 97 |          }
 98 |       }else{
 99 |          break;
100 |       }
101 |    }
102 |    if(argc>=1){
103 |       fn_r = *argv;
104 |       argc--;argv++;
105 |    }else{
106 |       fn_r = NULL;
107 |    }
108 |    if(argc>=1){
109 |       fn_w = *argv;
110 |       argc--;argv++;
111 |    }else{
112 |       fn_w = NULL;
113 |    }
114 |    {
115 |       int len;
116 |       char buff[0x1000];
117 |       char mode[10];
118 | 
119 |       if(decompress){
120 |          BZFILE *BZ2fp_r = NULL;
121 |          FILE *fp_w = NULL;
122 | 
123 |          if(fn_w){
124 |             if((fp_w = fopen(fn_w,"wb"))==NULL){
125 |                printf("can't open [%s]\n",fn_w);
126 |                perror("reason:");
127 |                exit(1);
128 |             }
129 |          }else{
130 |             fp_w = stdout;
131 |          }
132 |          if((fn_r == NULL && (BZ2fp_r = BZ2_bzdopen(fileno(stdin),"rb"))==NULL)
133 |             || (fn_r != NULL && (BZ2fp_r = BZ2_bzopen(fn_r,"rb"))==NULL)){
134 |             printf("can't bz2openstream\n");
135 |             exit(1);
136 |          }
137 |          while((len=BZ2_bzread(BZ2fp_r,buff,0x1000))>0){
138 |             fwrite(buff,1,len,fp_w);
139 |          }
140 |          BZ2_bzclose(BZ2fp_r);
141 |          if(fp_w != stdout) fclose(fp_w);
142 |       }else{
143 |          BZFILE *BZ2fp_w = NULL;
144 |          FILE *fp_r = NULL;
145 | 
146 |          if(fn_r){
147 |             if((fp_r = fopen(fn_r,"rb"))==NULL){
148 |                printf("can't open [%s]\n",fn_r);
149 |                perror("reason:");
150 |                exit(1);
151 |             }
152 |          }else{
153 |             fp_r = stdin;
154 |          }
155 |          mode[0]='w';
156 |          mode[1] = '0' + level;
157 |          mode[2] = '\0';
158 | 
159 |          if((fn_w == NULL && (BZ2fp_w = BZ2_bzdopen(fileno(stdout),mode))==NULL)
160 |             || (fn_w !=NULL && (BZ2fp_w = BZ2_bzopen(fn_w,mode))==NULL)){
161 |             printf("can't bz2openstream\n");
162 |             exit(1);
163 |          }
164 |          while((len=fread(buff,1,0x1000,fp_r))>0){
165 |             BZ2_bzwrite(BZ2fp_w,buff,len);
166 |          }
167 |          BZ2_bzclose(BZ2fp_w);
168 |          if(fp_r!=stdin)fclose(fp_r);
169 |       }
170 |    }
171 | #ifdef _WIN32
172 |    BZ2DLLFreeLibrary();
173 | #endif
174 |    return 0;
175 | }
176 | 


--------------------------------------------------------------------------------
/dlltest.dsp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LuaDist/bzip2/55ff70772d3bbe5e911d4ce970368cb630461c63/dlltest.dsp


--------------------------------------------------------------------------------
/entities.xml:
--------------------------------------------------------------------------------
 1 | 
 2 | 
 3 | 
 4 | 
 5 | 
 6 | 
 7 | 
 8 | 
 9 | 
10 | 


--------------------------------------------------------------------------------
/format.pl:
--------------------------------------------------------------------------------
 1 | #!/usr/bin/perl -w
 2 | #
 3 | # ------------------------------------------------------------------
 4 | # This file is part of bzip2/libbzip2, a program and library for
 5 | # lossless, block-sorting data compression.
 6 | #
 7 | # bzip2/libbzip2 version 1.0.5 of 10 December 2007
 8 | # Copyright (C) 1996-2007 Julian Seward 
 9 | #
10 | # Please read the WARNING, DISCLAIMER and PATENTS sections in the 
11 | # README file.
12 | #
13 | # This program is released under the terms of the license contained
14 | # in the file LICENSE.
15 | # ------------------------------------------------------------------
16 | #
17 | use strict;
18 | 
19 | # get command line values:
20 | if ( $#ARGV !=1 ) {
21 |     die "Usage:  $0 xml_infile xml_outfile\n";
22 | }
23 | 
24 | my $infile = shift;
25 | # check infile exists
26 | die "Can't find file \"$infile\""
27 |   unless -f $infile;
28 | # check we can read infile
29 | if (! -r $infile) {
30 |     die "Can't read input $infile\n";
31 | }
32 | # check we can open infile
33 | open( INFILE,"<$infile" ) or 
34 |     die "Can't input $infile $!";
35 | 
36 | #my $outfile = 'fmt-manual.xml';
37 | my $outfile = shift;
38 | #print "Infile: $infile, Outfile: $outfile\n";
39 | # check we can write to outfile
40 | open( OUTFILE,">$outfile" ) or 
41 |     die "Can't output $outfile $! for writing";
42 | 
43 | my ($prev, $curr, $str);
44 | $prev = ''; $curr = '';
45 | while (  ) {
46 | 
47 | 		print OUTFILE $prev;
48 |     $prev = $curr;
49 |     $curr = $_;
50 |     $str = '';
51 | 
52 |     if ( $prev =~ /$|$/ ) {
53 |         chomp $prev;
54 |         $curr = join( '', $prev, "|<\/screen>/ ) {
59 |         chomp $prev;
60 |         $curr = join( '', $prev, "]]>", $curr );
61 | 				$prev = '';
62 |         next;
63 |     }
64 | }
65 | print OUTFILE $curr;
66 | close INFILE;
67 | close OUTFILE;
68 | exit;
69 | 


--------------------------------------------------------------------------------
/huffman.c:
--------------------------------------------------------------------------------
  1 | 
  2 | /*-------------------------------------------------------------*/
  3 | /*--- Huffman coding low-level stuff                        ---*/
  4 | /*---                                             huffman.c ---*/
  5 | /*-------------------------------------------------------------*/
  6 | 
  7 | /* ------------------------------------------------------------------
  8 |    This file is part of bzip2/libbzip2, a program and library for
  9 |    lossless, block-sorting data compression.
 10 | 
 11 |    bzip2/libbzip2 version 1.0.5 of 10 December 2007
 12 |    Copyright (C) 1996-2007 Julian Seward 
 13 | 
 14 |    Please read the WARNING, DISCLAIMER and PATENTS sections in the 
 15 |    README file.
 16 | 
 17 |    This program is released under the terms of the license contained
 18 |    in the file LICENSE.
 19 |    ------------------------------------------------------------------ */
 20 | 
 21 | 
 22 | #include "bzlib_private.h"
 23 | 
 24 | /*---------------------------------------------------*/
 25 | #define WEIGHTOF(zz0)  ((zz0) & 0xffffff00)
 26 | #define DEPTHOF(zz1)   ((zz1) & 0x000000ff)
 27 | #define MYMAX(zz2,zz3) ((zz2) > (zz3) ? (zz2) : (zz3))
 28 | 
 29 | #define ADDWEIGHTS(zw1,zw2)                           \
 30 |    (WEIGHTOF(zw1)+WEIGHTOF(zw2)) |                    \
 31 |    (1 + MYMAX(DEPTHOF(zw1),DEPTHOF(zw2)))
 32 | 
 33 | #define UPHEAP(z)                                     \
 34 | {                                                     \
 35 |    Int32 zz, tmp;                                     \
 36 |    zz = z; tmp = heap[zz];                            \
 37 |    while (weight[tmp] < weight[heap[zz >> 1]]) {      \
 38 |       heap[zz] = heap[zz >> 1];                       \
 39 |       zz >>= 1;                                       \
 40 |    }                                                  \
 41 |    heap[zz] = tmp;                                    \
 42 | }
 43 | 
 44 | #define DOWNHEAP(z)                                   \
 45 | {                                                     \
 46 |    Int32 zz, yy, tmp;                                 \
 47 |    zz = z; tmp = heap[zz];                            \
 48 |    while (True) {                                     \
 49 |       yy = zz << 1;                                   \
 50 |       if (yy > nHeap) break;                          \
 51 |       if (yy < nHeap &&                               \
 52 |           weight[heap[yy+1]] < weight[heap[yy]])      \
 53 |          yy++;                                        \
 54 |       if (weight[tmp] < weight[heap[yy]]) break;      \
 55 |       heap[zz] = heap[yy];                            \
 56 |       zz = yy;                                        \
 57 |    }                                                  \
 58 |    heap[zz] = tmp;                                    \
 59 | }
 60 | 
 61 | 
 62 | /*---------------------------------------------------*/
 63 | void BZ2_hbMakeCodeLengths ( UChar *len, 
 64 |                              Int32 *freq,
 65 |                              Int32 alphaSize,
 66 |                              Int32 maxLen )
 67 | {
 68 |    /*--
 69 |       Nodes and heap entries run from 1.  Entry 0
 70 |       for both the heap and nodes is a sentinel.
 71 |    --*/
 72 |    Int32 nNodes, nHeap, n1, n2, i, j, k;
 73 |    Bool  tooLong;
 74 | 
 75 |    Int32 heap   [ BZ_MAX_ALPHA_SIZE + 2 ];
 76 |    Int32 weight [ BZ_MAX_ALPHA_SIZE * 2 ];
 77 |    Int32 parent [ BZ_MAX_ALPHA_SIZE * 2 ]; 
 78 | 
 79 |    for (i = 0; i < alphaSize; i++)
 80 |       weight[i+1] = (freq[i] == 0 ? 1 : freq[i]) << 8;
 81 | 
 82 |    while (True) {
 83 | 
 84 |       nNodes = alphaSize;
 85 |       nHeap = 0;
 86 | 
 87 |       heap[0] = 0;
 88 |       weight[0] = 0;
 89 |       parent[0] = -2;
 90 | 
 91 |       for (i = 1; i <= alphaSize; i++) {
 92 |          parent[i] = -1;
 93 |          nHeap++;
 94 |          heap[nHeap] = i;
 95 |          UPHEAP(nHeap);
 96 |       }
 97 | 
 98 |       AssertH( nHeap < (BZ_MAX_ALPHA_SIZE+2), 2001 );
 99 |    
100 |       while (nHeap > 1) {
101 |          n1 = heap[1]; heap[1] = heap[nHeap]; nHeap--; DOWNHEAP(1);
102 |          n2 = heap[1]; heap[1] = heap[nHeap]; nHeap--; DOWNHEAP(1);
103 |          nNodes++;
104 |          parent[n1] = parent[n2] = nNodes;
105 |          weight[nNodes] = ADDWEIGHTS(weight[n1], weight[n2]);
106 |          parent[nNodes] = -1;
107 |          nHeap++;
108 |          heap[nHeap] = nNodes;
109 |          UPHEAP(nHeap);
110 |       }
111 | 
112 |       AssertH( nNodes < (BZ_MAX_ALPHA_SIZE * 2), 2002 );
113 | 
114 |       tooLong = False;
115 |       for (i = 1; i <= alphaSize; i++) {
116 |          j = 0;
117 |          k = i;
118 |          while (parent[k] >= 0) { k = parent[k]; j++; }
119 |          len[i-1] = j;
120 |          if (j > maxLen) tooLong = True;
121 |       }
122 |       
123 |       if (! tooLong) break;
124 | 
125 |       /* 17 Oct 04: keep-going condition for the following loop used
126 |          to be 'i < alphaSize', which missed the last element,
127 |          theoretically leading to the possibility of the compressor
128 |          looping.  However, this count-scaling step is only needed if
129 |          one of the generated Huffman code words is longer than
130 |          maxLen, which up to and including version 1.0.2 was 20 bits,
131 |          which is extremely unlikely.  In version 1.0.3 maxLen was
132 |          changed to 17 bits, which has minimal effect on compression
133 |          ratio, but does mean this scaling step is used from time to
134 |          time, enough to verify that it works.
135 | 
136 |          This means that bzip2-1.0.3 and later will only produce
137 |          Huffman codes with a maximum length of 17 bits.  However, in
138 |          order to preserve backwards compatibility with bitstreams
139 |          produced by versions pre-1.0.3, the decompressor must still
140 |          handle lengths of up to 20. */
141 | 
142 |       for (i = 1; i <= alphaSize; i++) {
143 |          j = weight[i] >> 8;
144 |          j = 1 + (j / 2);
145 |          weight[i] = j << 8;
146 |       }
147 |    }
148 | }
149 | 
150 | 
151 | /*---------------------------------------------------*/
152 | void BZ2_hbAssignCodes ( Int32 *code,
153 |                          UChar *length,
154 |                          Int32 minLen,
155 |                          Int32 maxLen,
156 |                          Int32 alphaSize )
157 | {
158 |    Int32 n, vec, i;
159 | 
160 |    vec = 0;
161 |    for (n = minLen; n <= maxLen; n++) {
162 |       for (i = 0; i < alphaSize; i++)
163 |          if (length[i] == n) { code[i] = vec; vec++; };
164 |       vec <<= 1;
165 |    }
166 | }
167 | 
168 | 
169 | /*---------------------------------------------------*/
170 | void BZ2_hbCreateDecodeTables ( Int32 *limit,
171 |                                 Int32 *base,
172 |                                 Int32 *perm,
173 |                                 UChar *length,
174 |                                 Int32 minLen,
175 |                                 Int32 maxLen,
176 |                                 Int32 alphaSize )
177 | {
178 |    Int32 pp, i, j, vec;
179 | 
180 |    pp = 0;
181 |    for (i = minLen; i <= maxLen; i++)
182 |       for (j = 0; j < alphaSize; j++)
183 |          if (length[j] == i) { perm[pp] = j; pp++; };
184 | 
185 |    for (i = 0; i < BZ_MAX_CODE_LEN; i++) base[i] = 0;
186 |    for (i = 0; i < alphaSize; i++) base[length[i]+1]++;
187 | 
188 |    for (i = 1; i < BZ_MAX_CODE_LEN; i++) base[i] += base[i-1];
189 | 
190 |    for (i = 0; i < BZ_MAX_CODE_LEN; i++) limit[i] = 0;
191 |    vec = 0;
192 | 
193 |    for (i = minLen; i <= maxLen; i++) {
194 |       vec += (base[i+1] - base[i]);
195 |       limit[i] = vec-1;
196 |       vec <<= 1;
197 |    }
198 |    for (i = minLen + 1; i <= maxLen; i++)
199 |       base[i] = ((limit[i-1] + 1) << 1) - base[i];
200 | }
201 | 
202 | 
203 | /*-------------------------------------------------------------*/
204 | /*--- end                                         huffman.c ---*/
205 | /*-------------------------------------------------------------*/
206 | 


--------------------------------------------------------------------------------
/libbz2.def:
--------------------------------------------------------------------------------
 1 | LIBRARY			LIBBZ2
 2 | DESCRIPTION		"libbzip2: library for data compression"
 3 | EXPORTS
 4 | 	BZ2_bzCompressInit
 5 | 	BZ2_bzCompress
 6 | 	BZ2_bzCompressEnd
 7 | 	BZ2_bzDecompressInit
 8 | 	BZ2_bzDecompress
 9 | 	BZ2_bzDecompressEnd
10 | 	BZ2_bzReadOpen
11 | 	BZ2_bzReadClose
12 | 	BZ2_bzReadGetUnused
13 | 	BZ2_bzRead
14 | 	BZ2_bzWriteOpen
15 | 	BZ2_bzWrite
16 | 	BZ2_bzWriteClose
17 | 	BZ2_bzWriteClose64
18 | 	BZ2_bzBuffToBuffCompress
19 | 	BZ2_bzBuffToBuffDecompress
20 | 	BZ2_bzlibVersion
21 | 	BZ2_bzopen
22 | 	BZ2_bzdopen
23 | 	BZ2_bzread
24 | 	BZ2_bzwrite
25 | 	BZ2_bzflush
26 | 	BZ2_bzclose
27 | 	BZ2_bzerror
28 | 


--------------------------------------------------------------------------------
/libbz2.dsp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LuaDist/bzip2/55ff70772d3bbe5e911d4ce970368cb630461c63/libbz2.dsp


--------------------------------------------------------------------------------
/makefile.msc:
--------------------------------------------------------------------------------
 1 | # Makefile for Microsoft Visual C++ 6.0
 2 | # usage: nmake -f makefile.msc
 3 | # K.M. Syring (syring@gsf.de)
 4 | # Fixed up by JRS for bzip2-0.9.5d release.
 5 | 
 6 | CC=cl
 7 | CFLAGS= -DWIN32 -MD -Ox -D_FILE_OFFSET_BITS=64 -nologo
 8 | 
 9 | OBJS= blocksort.obj  \
10 |       huffman.obj    \
11 |       crctable.obj   \
12 |       randtable.obj  \
13 |       compress.obj   \
14 |       decompress.obj \
15 |       bzlib.obj
16 | 
17 | all: lib bzip2 test
18 | 
19 | bzip2: lib
20 | 	$(CC) $(CFLAGS) -o bzip2 bzip2.c libbz2.lib setargv.obj
21 | 	$(CC) $(CFLAGS) -o bzip2recover bzip2recover.c
22 | 
23 | lib: $(OBJS)
24 | 	lib /out:libbz2.lib $(OBJS)
25 | 
26 | test: bzip2
27 | 	type words1
28 | 	.\\bzip2 -1  < sample1.ref > sample1.rb2
29 | 	.\\bzip2 -2  < sample2.ref > sample2.rb2
30 | 	.\\bzip2 -3  < sample3.ref > sample3.rb2
31 | 	.\\bzip2 -d  < sample1.bz2 > sample1.tst
32 | 	.\\bzip2 -d  < sample2.bz2 > sample2.tst
33 | 	.\\bzip2 -ds < sample3.bz2 > sample3.tst
34 | 	@echo All six of the fc's should find no differences.
35 | 	@echo If fc finds an error on sample3.bz2, this could be
36 | 	@echo because WinZip's 'TAR file smart CR/LF conversion'
37 | 	@echo is too clever for its own good.  Disable this option.
38 | 	@echo The correct size for sample3.ref is 120,244.  If it
39 | 	@echo is 150,251, WinZip has messed it up.
40 | 	fc sample1.bz2 sample1.rb2 
41 | 	fc sample2.bz2 sample2.rb2
42 | 	fc sample3.bz2 sample3.rb2
43 | 	fc sample1.tst sample1.ref
44 | 	fc sample2.tst sample2.ref
45 | 	fc sample3.tst sample3.ref
46 | 
47 | 
48 | 
49 | clean: 
50 | 	del *.obj
51 | 	del libbz2.lib 
52 | 	del bzip2.exe
53 | 	del bzip2recover.exe
54 | 	del sample1.rb2 
55 | 	del sample2.rb2 
56 | 	del sample3.rb2
57 | 	del sample1.tst 
58 | 	del sample2.tst
59 | 	del sample3.tst
60 | 
61 | .c.obj: 
62 | 	$(CC) $(CFLAGS) -c $*.c -o $*.obj
63 | 
64 | 


--------------------------------------------------------------------------------
/manual.html:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LuaDist/bzip2/55ff70772d3bbe5e911d4ce970368cb630461c63/manual.html


--------------------------------------------------------------------------------
/manual.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LuaDist/bzip2/55ff70772d3bbe5e911d4ce970368cb630461c63/manual.pdf


--------------------------------------------------------------------------------
/mk251.c:
--------------------------------------------------------------------------------
 1 | 
 2 | /* Spew out a long sequence of the byte 251.  When fed to bzip2
 3 |    versions 1.0.0 or 1.0.1, causes it to die with internal error
 4 |    1007 in blocksort.c.  This assertion misses an extremely rare
 5 |    case, which is fixed in this version (1.0.2) and above.
 6 | */
 7 | 
 8 | /* ------------------------------------------------------------------
 9 |    This file is part of bzip2/libbzip2, a program and library for
10 |    lossless, block-sorting data compression.
11 | 
12 |    bzip2/libbzip2 version 1.0.5 of 10 December 2007
13 |    Copyright (C) 1996-2007 Julian Seward 
14 | 
15 |    Please read the WARNING, DISCLAIMER and PATENTS sections in the 
16 |    README file.
17 | 
18 |    This program is released under the terms of the license contained
19 |    in the file LICENSE.
20 |    ------------------------------------------------------------------ */
21 | 
22 | 
23 | #include 
24 | 
25 | int main ()
26 | {
27 |    int i;
28 |    for (i = 0; i < 48500000 ; i++)
29 |      putchar(251);
30 |    return 0;
31 | }
32 | 


--------------------------------------------------------------------------------
/randtable.c:
--------------------------------------------------------------------------------
 1 | 
 2 | /*-------------------------------------------------------------*/
 3 | /*--- Table for randomising repetitive blocks               ---*/
 4 | /*---                                           randtable.c ---*/
 5 | /*-------------------------------------------------------------*/
 6 | 
 7 | /* ------------------------------------------------------------------
 8 |    This file is part of bzip2/libbzip2, a program and library for
 9 |    lossless, block-sorting data compression.
10 | 
11 |    bzip2/libbzip2 version 1.0.5 of 10 December 2007
12 |    Copyright (C) 1996-2007 Julian Seward 
13 | 
14 |    Please read the WARNING, DISCLAIMER and PATENTS sections in the 
15 |    README file.
16 | 
17 |    This program is released under the terms of the license contained
18 |    in the file LICENSE.
19 |    ------------------------------------------------------------------ */
20 | 
21 | 
22 | #include "bzlib_private.h"
23 | 
24 | 
25 | /*---------------------------------------------*/
26 | Int32 BZ2_rNums[512] = { 
27 |    619, 720, 127, 481, 931, 816, 813, 233, 566, 247, 
28 |    985, 724, 205, 454, 863, 491, 741, 242, 949, 214, 
29 |    733, 859, 335, 708, 621, 574, 73, 654, 730, 472, 
30 |    419, 436, 278, 496, 867, 210, 399, 680, 480, 51, 
31 |    878, 465, 811, 169, 869, 675, 611, 697, 867, 561, 
32 |    862, 687, 507, 283, 482, 129, 807, 591, 733, 623, 
33 |    150, 238, 59, 379, 684, 877, 625, 169, 643, 105, 
34 |    170, 607, 520, 932, 727, 476, 693, 425, 174, 647, 
35 |    73, 122, 335, 530, 442, 853, 695, 249, 445, 515, 
36 |    909, 545, 703, 919, 874, 474, 882, 500, 594, 612, 
37 |    641, 801, 220, 162, 819, 984, 589, 513, 495, 799, 
38 |    161, 604, 958, 533, 221, 400, 386, 867, 600, 782, 
39 |    382, 596, 414, 171, 516, 375, 682, 485, 911, 276, 
40 |    98, 553, 163, 354, 666, 933, 424, 341, 533, 870, 
41 |    227, 730, 475, 186, 263, 647, 537, 686, 600, 224, 
42 |    469, 68, 770, 919, 190, 373, 294, 822, 808, 206, 
43 |    184, 943, 795, 384, 383, 461, 404, 758, 839, 887, 
44 |    715, 67, 618, 276, 204, 918, 873, 777, 604, 560, 
45 |    951, 160, 578, 722, 79, 804, 96, 409, 713, 940, 
46 |    652, 934, 970, 447, 318, 353, 859, 672, 112, 785, 
47 |    645, 863, 803, 350, 139, 93, 354, 99, 820, 908, 
48 |    609, 772, 154, 274, 580, 184, 79, 626, 630, 742, 
49 |    653, 282, 762, 623, 680, 81, 927, 626, 789, 125, 
50 |    411, 521, 938, 300, 821, 78, 343, 175, 128, 250, 
51 |    170, 774, 972, 275, 999, 639, 495, 78, 352, 126, 
52 |    857, 956, 358, 619, 580, 124, 737, 594, 701, 612, 
53 |    669, 112, 134, 694, 363, 992, 809, 743, 168, 974, 
54 |    944, 375, 748, 52, 600, 747, 642, 182, 862, 81, 
55 |    344, 805, 988, 739, 511, 655, 814, 334, 249, 515, 
56 |    897, 955, 664, 981, 649, 113, 974, 459, 893, 228, 
57 |    433, 837, 553, 268, 926, 240, 102, 654, 459, 51, 
58 |    686, 754, 806, 760, 493, 403, 415, 394, 687, 700, 
59 |    946, 670, 656, 610, 738, 392, 760, 799, 887, 653, 
60 |    978, 321, 576, 617, 626, 502, 894, 679, 243, 440, 
61 |    680, 879, 194, 572, 640, 724, 926, 56, 204, 700, 
62 |    707, 151, 457, 449, 797, 195, 791, 558, 945, 679, 
63 |    297, 59, 87, 824, 713, 663, 412, 693, 342, 606, 
64 |    134, 108, 571, 364, 631, 212, 174, 643, 304, 329, 
65 |    343, 97, 430, 751, 497, 314, 983, 374, 822, 928, 
66 |    140, 206, 73, 263, 980, 736, 876, 478, 430, 305, 
67 |    170, 514, 364, 692, 829, 82, 855, 953, 676, 246, 
68 |    369, 970, 294, 750, 807, 827, 150, 790, 288, 923, 
69 |    804, 378, 215, 828, 592, 281, 565, 555, 710, 82, 
70 |    896, 831, 547, 261, 524, 462, 293, 465, 502, 56, 
71 |    661, 821, 976, 991, 658, 869, 905, 758, 745, 193, 
72 |    768, 550, 608, 933, 378, 286, 215, 979, 792, 961, 
73 |    61, 688, 793, 644, 986, 403, 106, 366, 905, 644, 
74 |    372, 567, 466, 434, 645, 210, 389, 550, 919, 135, 
75 |    780, 773, 635, 389, 707, 100, 626, 958, 165, 504, 
76 |    920, 176, 193, 713, 857, 265, 203, 50, 668, 108, 
77 |    645, 990, 626, 197, 510, 357, 358, 850, 858, 364, 
78 |    936, 638
79 | };
80 | 
81 | 
82 | /*-------------------------------------------------------------*/
83 | /*--- end                                       randtable.c ---*/
84 | /*-------------------------------------------------------------*/
85 | 


--------------------------------------------------------------------------------
/sample1.bz2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LuaDist/bzip2/55ff70772d3bbe5e911d4ce970368cb630461c63/sample1.bz2


--------------------------------------------------------------------------------
/sample1.ref:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LuaDist/bzip2/55ff70772d3bbe5e911d4ce970368cb630461c63/sample1.ref


--------------------------------------------------------------------------------
/sample2.bz2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LuaDist/bzip2/55ff70772d3bbe5e911d4ce970368cb630461c63/sample2.bz2


--------------------------------------------------------------------------------
/sample2.ref:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LuaDist/bzip2/55ff70772d3bbe5e911d4ce970368cb630461c63/sample2.ref


--------------------------------------------------------------------------------
/sample3.bz2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LuaDist/bzip2/55ff70772d3bbe5e911d4ce970368cb630461c63/sample3.bz2


--------------------------------------------------------------------------------
/spewG.c:
--------------------------------------------------------------------------------
 1 | 
 2 | /* spew out a thoroughly gigantic file designed so that bzip2
 3 |    can compress it reasonably rapidly.  This is to help test
 4 |    support for large files (> 2GB) in a reasonable amount of time.
 5 |    I suggest you use the undocumented --exponential option to
 6 |    bzip2 when compressing the resulting file; this saves a bit of
 7 |    time.  Note: *don't* bother with --exponential when compressing 
 8 |    Real Files; it'll just waste a lot of CPU time :-)
 9 |    (but is otherwise harmless).
10 | */
11 | 
12 | /* ------------------------------------------------------------------
13 |    This file is part of bzip2/libbzip2, a program and library for
14 |    lossless, block-sorting data compression.
15 | 
16 |    bzip2/libbzip2 version 1.0.5 of 10 December 2007
17 |    Copyright (C) 1996-2007 Julian Seward 
18 | 
19 |    Please read the WARNING, DISCLAIMER and PATENTS sections in the 
20 |    README file.
21 | 
22 |    This program is released under the terms of the license contained
23 |    in the file LICENSE.
24 | 	 ------------------------------------------------------------------ */
25 | 
26 | 
27 | #define _FILE_OFFSET_BITS 64
28 | 
29 | #include 
30 | #include 
31 | 
32 | /* The number of megabytes of junk to spew out (roughly) */
33 | #define MEGABYTES 5000
34 | 
35 | #define N_BUF 1000000
36 | char buf[N_BUF];
37 | 
38 | int main ( int argc, char** argv )
39 | {
40 |    int ii, kk, p;
41 |    srandom(1);
42 |    setbuffer ( stdout, buf, N_BUF );
43 |    for (kk = 0; kk < MEGABYTES * 515; kk+=3) {
44 |       p = 25+random()%50;
45 |       for (ii = 0; ii < p; ii++)
46 |          printf ( "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" );
47 |       for (ii = 0; ii < p-1; ii++)
48 |          printf ( "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" );
49 |       for (ii = 0; ii < p+1; ii++)
50 |          printf ( "ccccccccccccccccccccccccccccccccccccc" );
51 |    }
52 |    fflush(stdout);
53 |    return 0;
54 | }
55 | 


--------------------------------------------------------------------------------
/unzcrash.c:
--------------------------------------------------------------------------------
  1 | 
  2 | /* A test program written to test robustness to decompression of
  3 |    corrupted data.  Usage is 
  4 |        unzcrash filename
  5 |    and the program will read the specified file, compress it (in memory),
  6 |    and then repeatedly decompress it, each time with a different bit of
  7 |    the compressed data inverted, so as to test all possible one-bit errors.
  8 |    This should not cause any invalid memory accesses.  If it does, 
  9 |    I want to know about it!
 10 | 
 11 |    PS.  As you can see from the above description, the process is
 12 |    incredibly slow.  A file of size eg 5KB will cause it to run for
 13 |    many hours.
 14 | */
 15 | 
 16 | /* ------------------------------------------------------------------
 17 |    This file is part of bzip2/libbzip2, a program and library for
 18 |    lossless, block-sorting data compression.
 19 | 
 20 |    bzip2/libbzip2 version 1.0.5 of 10 December 2007
 21 |    Copyright (C) 1996-2007 Julian Seward 
 22 | 
 23 |    Please read the WARNING, DISCLAIMER and PATENTS sections in the 
 24 |    README file.
 25 | 
 26 |    This program is released under the terms of the license contained
 27 |    in the file LICENSE.
 28 |    ------------------------------------------------------------------ */
 29 | 
 30 | 
 31 | #include 
 32 | #include 
 33 | #include "bzlib.h"
 34 | 
 35 | #define M_BLOCK 1000000
 36 | 
 37 | typedef unsigned char uchar;
 38 | 
 39 | #define M_BLOCK_OUT (M_BLOCK + 1000000)
 40 | uchar inbuf[M_BLOCK];
 41 | uchar outbuf[M_BLOCK_OUT];
 42 | uchar zbuf[M_BLOCK + 600 + (M_BLOCK / 100)];
 43 | 
 44 | int nIn, nOut, nZ;
 45 | 
 46 | static char *bzerrorstrings[] = {
 47 |        "OK"
 48 |       ,"SEQUENCE_ERROR"
 49 |       ,"PARAM_ERROR"
 50 |       ,"MEM_ERROR"
 51 |       ,"DATA_ERROR"
 52 |       ,"DATA_ERROR_MAGIC"
 53 |       ,"IO_ERROR"
 54 |       ,"UNEXPECTED_EOF"
 55 |       ,"OUTBUFF_FULL"
 56 |       ,"???"   /* for future */
 57 |       ,"???"   /* for future */
 58 |       ,"???"   /* for future */
 59 |       ,"???"   /* for future */
 60 |       ,"???"   /* for future */
 61 |       ,"???"   /* for future */
 62 | };
 63 | 
 64 | void flip_bit ( int bit )
 65 | {
 66 |    int byteno = bit / 8;
 67 |    int bitno  = bit % 8;
 68 |    uchar mask = 1 << bitno;
 69 |    //fprintf ( stderr, "(byte %d  bit %d  mask %d)",
 70 |    //          byteno, bitno, (int)mask );
 71 |    zbuf[byteno] ^= mask;
 72 | }
 73 | 
 74 | int main ( int argc, char** argv )
 75 | {
 76 |    FILE* f;
 77 |    int   r;
 78 |    int   bit;
 79 |    int   i;
 80 | 
 81 |    if (argc != 2) {
 82 |       fprintf ( stderr, "usage: unzcrash filename\n" );
 83 |       return 1;
 84 |    }
 85 | 
 86 |    f = fopen ( argv[1], "r" );
 87 |    if (!f) {
 88 |       fprintf ( stderr, "unzcrash: can't open %s\n", argv[1] );
 89 |       return 1;
 90 |    }
 91 | 
 92 |    nIn = fread ( inbuf, 1, M_BLOCK, f );
 93 |    fprintf ( stderr, "%d bytes read\n", nIn );
 94 | 
 95 |    nZ = M_BLOCK;
 96 |    r = BZ2_bzBuffToBuffCompress (
 97 |          zbuf, &nZ, inbuf, nIn, 9, 0, 30 );
 98 | 
 99 |    assert (r == BZ_OK);
100 |    fprintf ( stderr, "%d after compression\n", nZ );
101 | 
102 |    for (bit = 0; bit < nZ*8; bit++) {
103 |       fprintf ( stderr, "bit %d  ", bit );
104 |       flip_bit ( bit );
105 |       nOut = M_BLOCK_OUT;
106 |       r = BZ2_bzBuffToBuffDecompress (
107 |             outbuf, &nOut, zbuf, nZ, 0, 0 );
108 |       fprintf ( stderr, " %d  %s ", r, bzerrorstrings[-r] );
109 | 
110 |       if (r != BZ_OK) {
111 |          fprintf ( stderr, "\n" );
112 |       } else {
113 |          if (nOut != nIn) {
114 |            fprintf(stderr, "nIn/nOut mismatch %d %d\n", nIn, nOut );
115 |            return 1;
116 |          } else {
117 |            for (i = 0; i < nOut; i++)
118 |              if (inbuf[i] != outbuf[i]) { 
119 |                 fprintf(stderr, "mismatch at %d\n", i ); 
120 |                 return 1; 
121 |            }
122 |            if (i == nOut) fprintf(stderr, "really ok!\n" );
123 |          }
124 |       }
125 | 
126 |       flip_bit ( bit );
127 |    }
128 | 
129 | #if 0
130 |    assert (nOut == nIn);
131 |    for (i = 0; i < nOut; i++) {
132 |      if (inbuf[i] != outbuf[i]) {
133 |         fprintf ( stderr, "difference at %d !\n", i );
134 |         return 1;
135 |      }
136 |    }
137 | #endif
138 | 
139 |    fprintf ( stderr, "all ok\n" );
140 |    return 0;
141 | }
142 | 


--------------------------------------------------------------------------------
/words0:
--------------------------------------------------------------------------------
 1 | 
 2 | If compilation produces errors, or a large number of warnings,
 3 | please read README.COMPILATION.PROBLEMS -- you might be able to
 4 | adjust the flags in this Makefile to improve matters.
 5 | 
 6 | Also in README.COMPILATION.PROBLEMS are some hints that may help
 7 | if your build produces an executable which is unable to correctly
 8 | handle so-called 'large files' -- files of size 2GB or more.
 9 | 
10 | 


--------------------------------------------------------------------------------
/words1:
--------------------------------------------------------------------------------
1 | 
2 | Doing 6 tests (3 compress, 3 uncompress) ...
3 | If there's a problem, things might stop at this point.
4 |  
5 | 


--------------------------------------------------------------------------------
/words2:
--------------------------------------------------------------------------------
1 | 
2 | Checking test results.  If any of the four "cmp"s which follow
3 | report any differences, something is wrong.  If you can't easily
4 | figure out what, please let me know (jseward@bzip.org).
5 | 
6 | 


--------------------------------------------------------------------------------
/words3:
--------------------------------------------------------------------------------
 1 | 
 2 | If you got this far and the 'cmp's didn't complain, it looks
 3 | like you're in business.  
 4 | 
 5 | To install in /usr/local/bin, /usr/local/lib, /usr/local/man and 
 6 | /usr/local/include, type
 7 | 
 8 |    make install
 9 | 
10 | To install somewhere else, eg, /xxx/yyy/{bin,lib,man,include}, type 
11 | 
12 |    make install PREFIX=/xxx/yyy
13 | 
14 | If you are (justifiably) paranoid and want to see what 'make install'
15 | is going to do, you can first do
16 | 
17 |    make -n install                      or
18 |    make -n install PREFIX=/xxx/yyy      respectively.
19 | 
20 | The -n instructs make to show the commands it would execute, but
21 | not actually execute them.
22 | 
23 | Instructions for use are in the preformatted manual page, in the file
24 | bzip2.txt.  For more detailed documentation, read the full manual.  
25 | It is available in Postscript form (manual.ps), PDF form (manual.pdf),
26 | and HTML form (manual.html).
27 | 
28 | You can also do "bzip2 --help" to see some helpful information. 
29 | "bzip2 -L" displays the software license.
30 | 
31 | 


--------------------------------------------------------------------------------
/xmlproc.sh:
--------------------------------------------------------------------------------
  1 | #!/bin/bash
  2 | # see the README file for usage etc.
  3 | #
  4 | # ------------------------------------------------------------------
  5 | #  This file is part of bzip2/libbzip2, a program and library for
  6 | #  lossless, block-sorting data compression.
  7 | #
  8 | #  bzip2/libbzip2 version 1.0.5 of 10 December 2007
  9 | #  Copyright (C) 1996-2007 Julian Seward 
 10 | #
 11 | #  Please read the WARNING, DISCLAIMER and PATENTS sections in the 
 12 | #  README file.
 13 | #
 14 | #  This program is released under the terms of the license contained
 15 | #  in the file LICENSE.
 16 | # ----------------------------------------------------------------
 17 | 
 18 | 
 19 | usage() {
 20 |   echo '';
 21 |   echo 'Usage: xmlproc.sh -[option] ';
 22 |   echo 'Specify a target from:';
 23 |   echo '-v      verify xml file conforms to dtd';
 24 |   echo '-html   output in html format (single file)';
 25 |   echo '-ps     output in postscript format';
 26 |   echo '-pdf    output in pdf format';
 27 |   exit;
 28 | }
 29 | 
 30 | if test $# -ne 2; then
 31 |   usage
 32 | fi
 33 | # assign the variable for the output type
 34 | action=$1; shift
 35 | # assign the output filename
 36 | xmlfile=$1; shift
 37 | # and check user input it correct
 38 | if !(test -f $xmlfile); then
 39 |   echo "No such file: $xmlfile";
 40 |   exit;
 41 | fi
 42 | # some other stuff we will use
 43 | OUT=output
 44 | xsl_fo=bz-fo.xsl
 45 | xsl_html=bz-html.xsl
 46 | 
 47 | basename=$xmlfile
 48 | basename=${basename//'.xml'/''}
 49 | 
 50 | fofile="${basename}.fo"
 51 | htmlfile="${basename}.html"
 52 | pdffile="${basename}.pdf"
 53 | psfile="${basename}.ps"
 54 | xmlfmtfile="${basename}.fmt"
 55 | 
 56 | # first process the xmlfile with CDATA tags
 57 | ./format.pl $xmlfile $xmlfmtfile
 58 | # so the shell knows where the catalogs live
 59 | export XML_CATALOG_FILES=/etc/xml/catalog
 60 | 
 61 | # post-processing tidy up
 62 | cleanup() {
 63 |   echo "Cleaning up: $@" 
 64 |   while [ $# != 0 ]
 65 |   do
 66 |     arg=$1; shift;
 67 |     echo "  deleting $arg";
 68 |     rm $arg
 69 |   done
 70 | }
 71 | 
 72 | case $action in
 73 |   -v)
 74 |    flags='--noout --xinclude --noblanks --postvalid'
 75 |    dtd='--dtdvalid http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd'
 76 |    xmllint $flags $dtd $xmlfmtfile 2> $OUT 
 77 |    egrep 'error' $OUT 
 78 |    rm $OUT
 79 |   ;;
 80 | 
 81 |   -html)
 82 |    echo "Creating $htmlfile ..."
 83 |    xsltproc --nonet --xinclude  -o $htmlfile $xsl_html $xmlfmtfile
 84 |    cleanup $xmlfmtfile
 85 |   ;;
 86 | 
 87 |   -pdf)
 88 |    echo "Creating $pdffile ..."
 89 |    xsltproc --nonet --xinclude -o $fofile $xsl_fo $xmlfmtfile
 90 |    pdfxmltex $fofile >$OUT $OUT $OUT $OUT $OUT $OUT $OUT $OUT $OUT