1 2/*-----------------------------------------------------------*/ 3/*--- A block-sorting, lossless compressor bzip2.c ---*/ 4/*-----------------------------------------------------------*/ 5 6/*-- 7 This file is a part of bzip2 and/or libbzip2, a program and 8 library for lossless, block-sorting data compression. 9 |
10 Copyright (C) 1996-2005 Julian R Seward. All rights reserved. |
11 12 Redistribution and use in source and binary forms, with or without 13 modification, are permitted provided that the following conditions 14 are met: 15 16 1. Redistributions of source code must retain the above copyright 17 notice, this list of conditions and the following disclaimer. 18 --- 17 unchanged lines hidden (view full) --- 36 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 37 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 38 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 39 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 40 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 41 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 42 43 Julian Seward, Cambridge, UK. |
44 jseward@bzip.org |
45 bzip2/libbzip2 version 1.0 of 21 March 2000 46 47 This program is based on (at least) the work of: 48 Mike Burrows 49 David Wheeler 50 Peter Fenwick 51 Alistair Moffat 52 Radford Neal --- 467 unchanged lines hidden (view full) --- 520static 521Bool uncompressStream ( FILE *zStream, FILE *stream ) 522{ 523 BZFILE* bzf = NULL; 524 Int32 bzerr, bzerr_dummy, ret, nread, streamNo, i; 525 UChar obuf[5000]; 526 UChar unused[BZ_MAX_UNUSED]; 527 Int32 nUnused; |
528 void* unusedTmpV; |
529 UChar* unusedTmp; 530 531 nUnused = 0; 532 streamNo = 0; 533 534 SET_BINARY_MODE(stream); 535 SET_BINARY_MODE(zStream); 536 --- 13 unchanged lines hidden (view full) --- 550 nread = BZ2_bzRead ( &bzerr, bzf, obuf, 5000 ); 551 if (bzerr == BZ_DATA_ERROR_MAGIC) goto trycat; 552 if ((bzerr == BZ_OK || bzerr == BZ_STREAM_END) && nread > 0) 553 fwrite ( obuf, sizeof(UChar), nread, stream ); 554 if (ferror(stream)) goto errhandler_io; 555 } 556 if (bzerr != BZ_STREAM_END) goto errhandler; 557 |
558 BZ2_bzReadGetUnused ( &bzerr, bzf, &unusedTmpV, &nUnused ); |
559 if (bzerr != BZ_OK) panic ( "decompress:bzReadGetUnused" ); 560 |
561 unusedTmp = (UChar*)unusedTmpV; |
562 for (i = 0; i < nUnused; i++) unused[i] = unusedTmp[i]; 563 564 BZ2_bzReadClose ( &bzerr, bzf ); 565 if (bzerr != BZ_OK) panic ( "decompress:bzReadGetUnused" ); 566 567 if (nUnused == 0 && myfeof(zStream)) break; 568 } 569 --- 66 unchanged lines hidden (view full) --- 636static 637Bool testStream ( FILE *zStream ) 638{ 639 BZFILE* bzf = NULL; 640 Int32 bzerr, bzerr_dummy, ret, nread, streamNo, i; 641 UChar obuf[5000]; 642 UChar unused[BZ_MAX_UNUSED]; 643 Int32 nUnused; |
644 void* unusedTmpV; |
645 UChar* unusedTmp; 646 647 nUnused = 0; 648 streamNo = 0; 649 650 SET_BINARY_MODE(zStream); 651 if (ferror(zStream)) goto errhandler_io; 652 --- 7 unchanged lines hidden (view full) --- 660 streamNo++; 661 662 while (bzerr == BZ_OK) { 663 nread = BZ2_bzRead ( &bzerr, bzf, obuf, 5000 ); 664 if (bzerr == BZ_DATA_ERROR_MAGIC) goto errhandler; 665 } 666 if (bzerr != BZ_STREAM_END) goto errhandler; 667 |
668 BZ2_bzReadGetUnused ( &bzerr, bzf, &unusedTmpV, &nUnused ); |
669 if (bzerr != BZ_OK) panic ( "test:bzReadGetUnused" ); 670 |
671 unusedTmp = (UChar*)unusedTmpV; |
672 for (i = 0; i < nUnused; i++) unused[i] = unusedTmp[i]; 673 674 BZ2_bzReadClose ( &bzerr, bzf ); 675 if (bzerr != BZ_OK) panic ( "test:bzReadGetUnused" ); 676 if (nUnused == 0 && myfeof(zStream)) break; 677 678 } 679 --- 147 unchanged lines hidden (view full) --- 827/*---------------------------------------------*/ 828static 829void panic ( Char* s ) 830{ 831 fprintf ( stderr, 832 "\n%s: PANIC -- internal consistency error:\n" 833 "\t%s\n" 834 "\tThis is a BUG. Please report it to me at:\n" |
835 "\tjseward@bzip.org\n", |
836 progName, s ); 837 showFileNames(); 838 cleanUpAndFail( 3 ); 839} 840 841 842/*---------------------------------------------*/ 843static --- 63 unchanged lines hidden (view full) --- 907 " (1) This computer has unreliable memory or cache hardware\n" 908 " (a surprisingly common problem; try a different machine.)\n" 909 " (2) A bug in the compiler used to create this executable\n" 910 " (unlikely, if you didn't compile bzip2 yourself.)\n" 911 " (3) A real bug in bzip2 -- I hope this should never be the case.\n" 912 " The user's manual, Section 4.3, has more info on (1) and (2).\n" 913 " \n" 914 " If you suspect this is a bug in bzip2, or are unsure about (1)\n" |
915 " or (2), feel free to report it to me at: jseward@bzip.org.\n" |
916 " Section 4.3 of the user's manual describes the info a useful\n" 917 " bug report should have. If the manual is available on your\n" 918 " system, please try and read it before mailing me. If you don't\n" 919 " have the manual or can't be bothered to read it, mail me anyway.\n" 920 "\n", 921 progName ); 922 else 923 fprintf ( --- 6 unchanged lines hidden (view full) --- 930 " (2) This computer has unreliable memory or cache hardware\n" 931 " (a surprisingly common problem; try a different machine.)\n" 932 " (3) A bug in the compiler used to create this executable\n" 933 " (unlikely, if you didn't compile bzip2 yourself.)\n" 934 " (4) A real bug in bzip2 -- I hope this should never be the case.\n" 935 " The user's manual, Section 4.3, has more info on (2) and (3).\n" 936 " \n" 937 " If you suspect this is a bug in bzip2, or are unsure about (2)\n" |
938 " or (3), feel free to report it to me at: jseward@bzip.org.\n" |
939 " Section 4.3 of the user's manual describes the info a useful\n" 940 " bug report should have. If the manual is available on your\n" 941 " system, please try and read it before mailing me. If you don't\n" 942 " have the manual or can't be bothered to read it, mail me anyway.\n" 943 "\n", 944 progName ); 945 946 showFileNames(); --- 726 unchanged lines hidden (view full) --- 1673static 1674void license ( void ) 1675{ 1676 fprintf ( stderr, 1677 1678 "bzip2, a block-sorting file compressor. " 1679 "Version %s.\n" 1680 " \n" |
1681 " Copyright (C) 1996-2005 by Julian Seward.\n" |
1682 " \n" 1683 " This program is free software; you can redistribute it and/or modify\n" 1684 " it under the terms set out in the LICENSE file, which is included\n" 1685 " in the bzip2-1.0 source distribution.\n" 1686 " \n" 1687 " This program is distributed in the hope that it will be useful,\n" 1688 " but WITHOUT ANY WARRANTY; without even the implied warranty of\n" 1689 " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" --- 418 unchanged lines hidden --- |