From: "Juan Manuel Guerrero" Organization: Darmstadt University of Technology To: eliz AT is DOT elta DOT co DOT il Date: Mon, 4 Dec 2000 12:59:44 +0200 MIME-Version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT Subject: Re: bzip2 support for DJTAR CC: djgpp-workers AT delorie DOT com In-reply-to: <2950-Sat25Nov2000131328+0200-eliz@is.elta.co.il> X-mailer: Pegasus Mail for Windows (v2.54DE) Message-ID: <733DC62C68@HRZ1.hrz.tu-darmstadt.de> Reply-To: djgpp-workers AT delorie DOT com Errors-To: nobody AT delorie DOT com X-Mailing-List: djgpp-workers AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk Patch for bzip support for DJTAR. Patch 2/4 diff -acprNC5 djgpp.orig/src/utils/djtar/huffman.c djgpp/src/utils/djtar/huffman.c *** djgpp.orig/src/utils/djtar/huffman.c Thu Jan 1 00:00:00 1970 --- djgpp/src/utils/djtar/huffman.c Sun Dec 3 00:57:26 2000 *************** *** 0 **** --- 1,103 ---- + /* Copyright (C) 2000 DJ Delorie, see COPYING.DJ for details */ + + /*-------------------------------------------------------------*/ + /*--- Huffman coding low-level stuff ---*/ + /*--- huffman.c ---*/ + /*-------------------------------------------------------------*/ + + /*-- + This file is a part of bzip2 and/or libbzip2, a program and + library for lossless, block-sorting data compression. + + Copyright (C) 1996-2000 Julian R Seward. All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 2. The origin of this software must not be misrepresented; you must + not claim that you wrote the original software. If you use this + software in a product, an acknowledgment in the product + documentation would be appreciated but is not required. + + 3. Altered source versions must be plainly marked as such, and must + not be misrepresented as being the original software. + + 4. The name of the author may not be used to endorse or promote + products derived from this software without specific prior written + permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + Julian Seward, Cambridge, UK. + jseward AT acm DOT org + bzip2/libbzip2 version 1.0 of 21 March 2000 + + This program is based on (at least) the work of: + Mike Burrows + David Wheeler + Peter Fenwick + Alistair Moffat + Radford Neal + Ian H. Witten + Robert Sedgewick + Jon L. Bentley + + For more information on these sources, see the manual. + + Minor changes for DJTAR program, Juan Manuel Guerrero December 2000 + --*/ + + + #include "bzlib_private.h" + + /*---------------------------------------------------*/ + void BZ2_hbCreateDecodeTables ( Int32 *limit, + Int32 *base, + Int32 *perm, + UChar *length, + Int32 minLen, + Int32 maxLen, + Int32 alphaSize ) + { + Int32 pp, i, j, vec; + + pp = 0; + for (i = minLen; i <= maxLen; i++) + for (j = 0; j < alphaSize; j++) + if (length[j] == i) { perm[pp] = j; pp++; }; + + for (i = 0; i < BZ_MAX_CODE_LEN; i++) base[i] = 0; + for (i = 0; i < alphaSize; i++) base[length[i]+1]++; + + for (i = 1; i < BZ_MAX_CODE_LEN; i++) base[i] += base[i-1]; + + for (i = 0; i < BZ_MAX_CODE_LEN; i++) limit[i] = 0; + vec = 0; + + for (i = minLen; i <= maxLen; i++) { + vec += (base[i+1] - base[i]); + limit[i] = vec-1; + vec <<= 1; + } + for (i = minLen + 1; i <= maxLen; i++) + base[i] = ((limit[i-1] + 1) << 1) - base[i]; + } + + + /*-------------------------------------------------------------*/ + /*--- end huffman.c ---*/ + /*-------------------------------------------------------------*/ diff -acprNC5 djgpp.orig/src/utils/djtar/makefile djgpp/src/utils/djtar/makefile *** djgpp.orig/src/utils/djtar/makefile Tue Nov 28 21:05:28 2000 --- djgpp/src/utils/djtar/makefile Sat Dec 2 20:34:56 2000 *************** EOBJS = \ *** 14,23 **** --- 14,29 ---- unpack.o \ inflate.o \ crypt.o \ util.o \ zmethod.o \ + unbzip2.o \ + bzlib.o \ + decompress.o \ + huffman.o \ + randtable.o \ + crctable.o \ $E EXTRA_FILES += $(BIN)/djtarx.exe EXTRA_FILES += $(BIN)/djtart.exe diff -acprNC5 djgpp.orig/src/utils/djtar/randtable.c djgpp/src/utils/djtar/randtable.c *** djgpp.orig/src/utils/djtar/randtable.c Thu Jan 1 00:00:00 1970 --- djgpp/src/utils/djtar/randtable.c Sun Dec 3 00:57:22 2000 *************** *** 0 **** --- 1,127 ---- + /* Copyright (C) 2000 DJ Delorie, see COPYING.DJ for details */ + + /*-------------------------------------------------------------*/ + /*--- Table for randomising repetitive blocks ---*/ + /*--- randtable.c ---*/ + /*-------------------------------------------------------------*/ + + /*-- + This file is a part of bzip2 and/or libbzip2, a program and + library for lossless, block-sorting data compression. + + Copyright (C) 1996-2000 Julian R Seward. All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 2. The origin of this software must not be misrepresented; you must + not claim that you wrote the original software. If you use this + software in a product, an acknowledgment in the product + documentation would be appreciated but is not required. + + 3. Altered source versions must be plainly marked as such, and must + not be misrepresented as being the original software. + + 4. The name of the author may not be used to endorse or promote + products derived from this software without specific prior written + permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + Julian Seward, Cambridge, UK. + jseward AT acm DOT org + bzip2/libbzip2 version 1.0 of 21 March 2000 + + This program is based on (at least) the work of: + Mike Burrows + David Wheeler + Peter Fenwick + Alistair Moffat + Radford Neal + Ian H. Witten + Robert Sedgewick + Jon L. Bentley + + For more information on these sources, see the manual. + + Minor changes for DJTAR program, Juan Manuel Guerrero December 2000 + --*/ + + + #include "bzlib_private.h" + + + /*---------------------------------------------*/ + Int32 BZ2_rNums[512] = { + 619, 720, 127, 481, 931, 816, 813, 233, 566, 247, + 985, 724, 205, 454, 863, 491, 741, 242, 949, 214, + 733, 859, 335, 708, 621, 574, 73, 654, 730, 472, + 419, 436, 278, 496, 867, 210, 399, 680, 480, 51, + 878, 465, 811, 169, 869, 675, 611, 697, 867, 561, + 862, 687, 507, 283, 482, 129, 807, 591, 733, 623, + 150, 238, 59, 379, 684, 877, 625, 169, 643, 105, + 170, 607, 520, 932, 727, 476, 693, 425, 174, 647, + 73, 122, 335, 530, 442, 853, 695, 249, 445, 515, + 909, 545, 703, 919, 874, 474, 882, 500, 594, 612, + 641, 801, 220, 162, 819, 984, 589, 513, 495, 799, + 161, 604, 958, 533, 221, 400, 386, 867, 600, 782, + 382, 596, 414, 171, 516, 375, 682, 485, 911, 276, + 98, 553, 163, 354, 666, 933, 424, 341, 533, 870, + 227, 730, 475, 186, 263, 647, 537, 686, 600, 224, + 469, 68, 770, 919, 190, 373, 294, 822, 808, 206, + 184, 943, 795, 384, 383, 461, 404, 758, 839, 887, + 715, 67, 618, 276, 204, 918, 873, 777, 604, 560, + 951, 160, 578, 722, 79, 804, 96, 409, 713, 940, + 652, 934, 970, 447, 318, 353, 859, 672, 112, 785, + 645, 863, 803, 350, 139, 93, 354, 99, 820, 908, + 609, 772, 154, 274, 580, 184, 79, 626, 630, 742, + 653, 282, 762, 623, 680, 81, 927, 626, 789, 125, + 411, 521, 938, 300, 821, 78, 343, 175, 128, 250, + 170, 774, 972, 275, 999, 639, 495, 78, 352, 126, + 857, 956, 358, 619, 580, 124, 737, 594, 701, 612, + 669, 112, 134, 694, 363, 992, 809, 743, 168, 974, + 944, 375, 748, 52, 600, 747, 642, 182, 862, 81, + 344, 805, 988, 739, 511, 655, 814, 334, 249, 515, + 897, 955, 664, 981, 649, 113, 974, 459, 893, 228, + 433, 837, 553, 268, 926, 240, 102, 654, 459, 51, + 686, 754, 806, 760, 493, 403, 415, 394, 687, 700, + 946, 670, 656, 610, 738, 392, 760, 799, 887, 653, + 978, 321, 576, 617, 626, 502, 894, 679, 243, 440, + 680, 879, 194, 572, 640, 724, 926, 56, 204, 700, + 707, 151, 457, 449, 797, 195, 791, 558, 945, 679, + 297, 59, 87, 824, 713, 663, 412, 693, 342, 606, + 134, 108, 571, 364, 631, 212, 174, 643, 304, 329, + 343, 97, 430, 751, 497, 314, 983, 374, 822, 928, + 140, 206, 73, 263, 980, 736, 876, 478, 430, 305, + 170, 514, 364, 692, 829, 82, 855, 953, 676, 246, + 369, 970, 294, 750, 807, 827, 150, 790, 288, 923, + 804, 378, 215, 828, 592, 281, 565, 555, 710, 82, + 896, 831, 547, 261, 524, 462, 293, 465, 502, 56, + 661, 821, 976, 991, 658, 869, 905, 758, 745, 193, + 768, 550, 608, 933, 378, 286, 215, 979, 792, 961, + 61, 688, 793, 644, 986, 403, 106, 366, 905, 644, + 372, 567, 466, 434, 645, 210, 389, 550, 919, 135, + 780, 773, 635, 389, 707, 100, 626, 958, 165, 504, + 920, 176, 193, 713, 857, 265, 203, 50, 668, 108, + 645, 990, 626, 197, 510, 357, 358, 850, 858, 364, + 936, 638 + }; + + + /*-------------------------------------------------------------*/ + /*--- end randtable.c ---*/ + /*-------------------------------------------------------------*/ diff -acprNC5 djgpp.orig/src/utils/djtar/unbzip2.c djgpp/src/utils/djtar/unbzip2.c *** djgpp.orig/src/utils/djtar/unbzip2.c Thu Jan 1 00:00:00 1970 --- djgpp/src/utils/djtar/unbzip2.c Mon Dec 4 05:18:04 2000 *************** *** 0 **** --- 1,190 ---- + /* Copyright (C) 2000 DJ Delorie, see COPYING.DJ for details */ + + /* + * This file provides bzip2 support for DJTAR. + */ + + + #include + #include "oread.h" + #include "zread.h" + #include "unbzip2.h" + + #define FALSE 0 + #define TRUE 1 + + local int read_stream (void) + { + int bytes_in, bytes_read; + + /* Read as much as possible */ + bytes_in = bytes_read = 0; + do + { + bytes_read = oread_read(ifd, (char *)inbuf+bytes_in); + if (bytes_read == 0 || bytes_read == EOF) + break; + bytes_in += bytes_read; + } + while (bytes_in < INBUFSIZ); + + return bytes_in; + } + + + #define ABORT_IF_ERROR(bzip_status) \ + do { \ + if ((bzip_status) != BZ_OK && (bzip_status) != BZ_STREAM_END) \ + goto error_handler; \ + if ((bzip_status) == BZ_OK && nbytes == EOF && \ + data->avail_in == 0 && data->avail_out > 0) \ + goto error_handler; \ + } while (FALSE) + + #define CHECK_IF_BZ_STREAM_END_IS_EOF(buf) \ + do { \ + if ((buf)[0] == 'B' && (buf)[1] == 'Z' && (buf)[2] == 'h') \ + EOF_reached = FALSE; \ + else \ + EOF_reached = TRUE; \ + } while (FALSE) + + int unbzip2 (void *f) + { + bz_stream* data = NULL; + int bzip_status; + int EOF_reached = TRUE; + int small = 0; /* Use fast decompressing algorithm. */ + int verbosity = 0; /* No verbose output at all. */ + int nbytes = 0; + + + + if (f == NULL) + return ERROR; + ifd = f; + + + /* Initialise bzip stream structure. */ + data = (bz_stream *) xmalloc (sizeof (bz_stream)); + data->next_in = inbuf; + data->avail_in = INBUFSIZ; + data->next_out = outbuf; + data->avail_out = OUTBUFSIZ; + data->bzalloc = NULL; + data->bzfree = NULL; + data->opaque = NULL; + bzip_status = BZ2_bzDecompressInit (data, verbosity, small); + if (bzip_status != BZ_OK) + goto error_handler; + + /* Decompress every stream (.bz2 file) contained in this file. */ + while (TRUE) + { + /* Decompress the actual stream (.bz2 file) contained in this file. */ + while (bzip_status == BZ_OK) + { + /* Read the complete compressed block and decompress it. */ + while (bzip_status == BZ_OK) + { + bzip_status = BZ2_bzDecompress (data); + ABORT_IF_ERROR (bzip_status); + + /* Reading compressed block. */ + if (data->avail_in == 0) + { + nbytes = read_stream (); + data->avail_in = nbytes; + data->next_in = inbuf; + } + + /* Writing decompressed block. */ + if (data->avail_out == 0) + { + tarread (outbuf, (unsigned long) OUTBUFSIZ); + data->avail_out = OUTBUFSIZ; + data->next_out = outbuf; + } + if (bzip_status == BZ_STREAM_END) + { + nbytes = OUTBUFSIZ - data->avail_out; + tarread (outbuf, (unsigned long) nbytes); + CHECK_IF_BZ_STREAM_END_IS_EOF(data->next_in); + } + } /* End of block loop. */ + + if (bzip_status != BZ_STREAM_END) + goto error_handler; + } /* End of stream (single .bz2 file) loop. */ + + if (bzip_status != BZ_STREAM_END) + goto error_handler; + else + { + /* Release all allocated ressources for the processed stream. */ + bzip_status = BZ2_bzDecompressEnd (data); + if (bzip_status != BZ_OK) + goto error_handler; + + if (EOF_reached) + break; + else + { + /* Reinitialise inbuf[] with the unused but + still availabe compressed data of the next + stream and allocate all resources needed + to processes it. */ + + int i; + for (i = 0; i < data->avail_in; i++) + inbuf[i] = data->next_in[i]; + + bzip_status = BZ2_bzDecompressInit (data, verbosity, small); + if (bzip_status != BZ_OK) + goto error_handler; + data->next_in = inbuf; + data->next_out = outbuf; + data->avail_out = OUTBUFSIZ; + } + } + } /* End of full file loop. */ + + free (data); + return OK; + + + error_handler: + + BZ2_bzDecompressEnd (data); + free (data); + exit_code = ERROR; + switch (bzip_status) + { + case BZ_SEQUENCE_ERROR: + error ("wrong sequence of bzip2 commands"); + break; + case BZ_PARAM_ERROR: + error ("wrong bzip2 parameters"); + break; + case BZ_MEM_ERROR: + error ("memory exhausted"); + break; + case BZ_DATA_ERROR: + error ("bzip2 data block corrupted"); + break; + case BZ_DATA_ERROR_MAGIC: + error ("not compressed with bzip2"); + break; + case BZ_IO_ERROR: + error ("I/O error"); + break; + case BZ_UNEXPECTED_EOF: + error ("unexpected end of file"); + break; + case BZ_CONFIG_ERROR: + error ("program has been mis-compiled"); + break; + } + + return ERROR; + } diff -acprNC5 djgpp.orig/src/utils/djtar/unbzip2.h djgpp/src/utils/djtar/unbzip2.h *** djgpp.orig/src/utils/djtar/unbzip2.h Thu Jan 1 00:00:00 1970 --- djgpp/src/utils/djtar/unbzip2.h Sun Dec 3 00:57:20 2000 *************** *** 0 **** --- 1,144 ---- + /* Copyright (C) 2000 DJ Delorie, see COPYING.DJ for details */ + + /*-------------------------------------------------------------*/ + /*--- Public header file for the library. ---*/ + /*--- bzlib.h ---*/ + /*-------------------------------------------------------------*/ + + /*-- + This file is a part of bzip2 and/or libbzip2, a program and + library for lossless, block-sorting data compression. + + Copyright (C) 1996-2000 Julian R Seward. All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 2. The origin of this software must not be misrepresented; you must + not claim that you wrote the original software. If you use this + software in a product, an acknowledgment in the product + documentation would be appreciated but is not required. + + 3. Altered source versions must be plainly marked as such, and must + not be misrepresented as being the original software. + + 4. The name of the author may not be used to endorse or promote + products derived from this software without specific prior written + permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + Julian Seward, Cambridge, UK. + jseward AT acm DOT org + bzip2/libbzip2 version 1.0 of 21 March 2000 + + This program is based on (at least) the work of: + Mike Burrows + David Wheeler + Peter Fenwick + Alistair Moffat + Radford Neal + Ian H. Witten + Robert Sedgewick + Jon L. Bentley + + For more information on these sources, see the manual. + + Minor changes for DJTAR program, Juan Manuel Guerrero December 2000 + --*/ + + + #ifndef _BZLIB_H + #define _BZLIB_H + + #ifdef __cplusplus + extern "C" { + #endif + + #define BZ_RUN 0 + #define BZ_FLUSH 1 + #define BZ_FINISH 2 + + #define BZ_OK 0 + #define BZ_RUN_OK 1 + #define BZ_FLUSH_OK 2 + #define BZ_FINISH_OK 3 + #define BZ_STREAM_END 4 + #define BZ_SEQUENCE_ERROR (-1) + #define BZ_PARAM_ERROR (-2) + #define BZ_MEM_ERROR (-3) + #define BZ_DATA_ERROR (-4) + #define BZ_DATA_ERROR_MAGIC (-5) + #define BZ_IO_ERROR (-6) + #define BZ_UNEXPECTED_EOF (-7) + #define BZ_OUTBUFF_FULL (-8) + #define BZ_CONFIG_ERROR (-9) + + typedef + struct { + char *next_in; + unsigned int avail_in; + unsigned int total_in_lo32; + unsigned int total_in_hi32; + + char *next_out; + unsigned int avail_out; + unsigned int total_out_lo32; + unsigned int total_out_hi32; + + void *state; + + void *(*bzalloc)(void *,int,int); + void (*bzfree)(void *,void *); + void *opaque; + } + bz_stream; + + + #define BZ_API(func) func + #define BZ_EXTERN extern + + + /*-- Core (low-level) library functions --*/ + + BZ_EXTERN int BZ_API(BZ2_bzDecompressInit) ( + bz_stream *strm, + int verbosity, + int small + ); + + BZ_EXTERN int BZ_API(BZ2_bzDecompress) ( + bz_stream* strm + ); + + BZ_EXTERN int BZ_API(BZ2_bzDecompressEnd) ( + bz_stream *strm + ); + + BZ_EXTERN const char * BZ_API(BZ2_bzlibVersion) ( + void + ); + + #ifdef __cplusplus + } + #endif + + #endif + + /*-------------------------------------------------------------*/ + /*--- end bzlib.h ---*/ + /*-------------------------------------------------------------*/ diff -acprNC5 djgpp.orig/src/utils/djtar/untar.c djgpp/src/utils/djtar/untar.c *** djgpp.orig/src/utils/djtar/untar.c Tue Nov 28 21:20:44 2000 --- djgpp/src/utils/djtar/untar.c Tue Nov 28 22:03:32 2000 *************** static const char *zip_description[] = { *** 310,320 **** "LZH'ed", "compressed by unknown method (4)", "compressed by unknown method (5)", "compressed by unknown method (6)", "compressed by unknown method (7)", ! "deflated by " }; void tar_gz_read(char *fname) { --- 310,321 ---- "LZH'ed", "compressed by unknown method (4)", "compressed by unknown method (5)", "compressed by unknown method (6)", "compressed by unknown method (7)", ! "deflated by ", ! "BZIP2'ed" }; void tar_gz_read(char *fname) {