~ubuntu-branches/ubuntu/raring/codeblocks/raring-proposed

« back to all changes in this revision

Viewing changes to src/plugins/contrib/help_plugin/bzip2/bzlib.c

  • Committer: Bazaar Package Importer
  • Author(s): Cosme Domínguez Díaz
  • Date: 2010-08-09 04:38:38 UTC
  • mfrom: (1.1.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20100809043838-a59ygguym4eg0jgw
Tags: 10.05-0ubuntu1
* New upstream release. Closes (LP: #322350)
 - Switch to dpkg-source 3.0 (quilt) format
 - Remove unneeded README.source
 - Add debian/get-source-orig script that removes all
   Windows prebuilt binaries
* Bump Standards-Version to 3.9.1
 - Stop shipping *.la files
* debian/control
 - Add cdbs package as Build-Depend
 - Add libbz2-dev and zlib1g-dev packages as
   Build-Depends (needed by libhelp_plugin.so)
 - Remove dpatch package of Build-Depends
 - Add codeblocks-contrib-debug package
 - Split architecture-independent files of codeblocks
   package in codeblocks-common package
* debian/rules
 - Switch to CDBS rules system
 - Add parallel build support
 - Add a call to debian/get-source-orig script
 - Use lzma compression (saves 23,5 MB of free space)
* debian/patches
 - Refresh 01_codeblocks_plugin_path
 - Add 02_no_Makefiles_in_debian_dir to remove any link
   in codeblocks build system to deleted Makefiles of debian directory
 - Drop 02_ftbfs_gcc44 and 03_ftbfs_glib221 (merged in upstream)
* debian/watch
 - Update to use the new host (berlios.de)

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
/*---                                               bzlib.c ---*/
5
5
/*-------------------------------------------------------------*/
6
6
 
7
 
/*--
8
 
  This file is a part of bzip2 and/or libbzip2, a program and
9
 
  library for lossless, block-sorting data compression.
10
 
 
11
 
  Copyright (C) 1996-2000 Julian R Seward.  All rights reserved.
12
 
 
13
 
  Redistribution and use in source and binary forms, with or without
14
 
  modification, are permitted provided that the following conditions
15
 
  are met:
16
 
 
17
 
  1. Redistributions of source code must retain the above copyright
18
 
     notice, this list of conditions and the following disclaimer.
19
 
 
20
 
  2. The origin of this software must not be misrepresented; you must 
21
 
     not claim that you wrote the original software.  If you use this 
22
 
     software in a product, an acknowledgment in the product 
23
 
     documentation would be appreciated but is not required.
24
 
 
25
 
  3. Altered source versions must be plainly marked as such, and must
26
 
     not be misrepresented as being the original software.
27
 
 
28
 
  4. The name of the author may not be used to endorse or promote 
29
 
     products derived from this software without specific prior written 
30
 
     permission.
31
 
 
32
 
  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
33
 
  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
34
 
  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35
 
  ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
36
 
  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37
 
  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
38
 
  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
39
 
  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
40
 
  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
41
 
  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
42
 
  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43
 
 
44
 
  Julian Seward, Cambridge, UK.
45
 
  jseward@acm.org
46
 
  bzip2/libbzip2 version 1.0 of 21 March 2000
47
 
 
48
 
  This program is based on (at least) the work of:
49
 
     Mike Burrows
50
 
     David Wheeler
51
 
     Peter Fenwick
52
 
     Alistair Moffat
53
 
     Radford Neal
54
 
     Ian H. Witten
55
 
     Robert Sedgewick
56
 
     Jon L. Bentley
57
 
 
58
 
  For more information on these sources, see the manual.
59
 
--*/
60
 
 
61
 
/*--
62
 
   CHANGES
63
 
   ~~~~~~~
64
 
   0.9.0 -- original version.
65
 
 
 
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 <jseward@bzip.org>
 
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
/* CHANGES
 
22
   0.9.0    -- original version.
66
23
   0.9.0a/b -- no changes in this file.
67
 
 
68
 
   0.9.0c
69
 
      * made zero-length BZ_FLUSH work correctly in bzCompress().
70
 
      * fixed bzWrite/bzRead to ignore zero-length requests.
71
 
      * fixed bzread to correctly handle read requests after EOF.
72
 
      * wrong parameter order in call to bzDecompressInit in
73
 
        bzBuffToBuffDecompress.  Fixed.
74
 
--*/
 
24
   0.9.0c   -- made zero-length BZ_FLUSH work correctly in bzCompress().
 
25
     fixed bzWrite/bzRead to ignore zero-length requests.
 
26
     fixed bzread to correctly handle read requests after EOF.
 
27
     wrong parameter order in call to bzDecompressInit in
 
28
     bzBuffToBuffDecompress.  Fixed.
 
29
*/
75
30
 
76
31
#include "bzlib_private.h"
77
32
 
88
43
   fprintf(stderr, 
89
44
      "\n\nbzip2/libbzip2: internal error number %d.\n"
90
45
      "This is a bug in bzip2/libbzip2, %s.\n"
91
 
      "Please report it to me at: jseward@acm.org.  If this happened\n"
 
46
      "Please report it to me at: jseward@bzip.org.  If this happened\n"
92
47
      "when you were using some program which uses libbzip2 as a\n"
93
48
      "component, you should also report this bug to the author(s)\n"
94
49
      "of that program.  Please make an effort to report this bug;\n"
95
50
      "timely and accurate bug reports eventually lead to higher\n"
96
 
      "quality software.  Thanks.  Julian Seward, 21 March 2000.\n\n",
 
51
      "quality software.  Thanks.  Julian Seward, 10 December 2007.\n\n",
97
52
      errcode,
98
53
      BZ2_bzlibVersion()
99
54
   );
 
55
 
 
56
   if (errcode == 1007) {
 
57
   fprintf(stderr,
 
58
      "\n*** A special note about internal error number 1007 ***\n"
 
59
      "\n"
 
60
      "Experience suggests that a common cause of i.e. 1007\n"
 
61
      "is unreliable memory or other hardware.  The 1007 assertion\n"
 
62
      "just happens to cross-check the results of huge numbers of\n"
 
63
      "memory reads/writes, and so acts (unintendedly) as a stress\n"
 
64
      "test of your memory system.\n"
 
65
      "\n"
 
66
      "I suggest the following: try compressing the file again,\n"
 
67
      "possibly monitoring progress in detail with the -vv flag.\n"
 
68
      "\n"
 
69
      "* If the error cannot be reproduced, and/or happens at different\n"
 
70
      "  points in compression, you may have a flaky memory system.\n"
 
71
      "  Try a memory-test program.  I have used Memtest86\n"
 
72
      "  (www.memtest86.com).  At the time of writing it is free (GPLd).\n"
 
73
      "  Memtest86 tests memory much more thorougly than your BIOSs\n"
 
74
      "  power-on test, and may find failures that the BIOS doesn't.\n"
 
75
      "\n"
 
76
      "* If the error can be repeatably reproduced, this is a bug in\n"
 
77
      "  bzip2, and I would very much like to hear about it.  Please\n"
 
78
      "  let me know, and, ideally, save a copy of the file causing the\n"
 
79
      "  problem -- without which I will be unable to investigate it.\n"
 
80
      "\n"
 
81
   );
 
82
   }
 
83
 
100
84
   exit(3);
101
85
}
102
86
#endif
545
529
 
546
530
 
547
531
/*---------------------------------------------------*/
 
532
/* Return  True iff data corruption is discovered.
 
533
   Returns False if there is no problem.
 
534
*/
548
535
static
549
 
void unRLE_obuf_to_output_FAST ( DState* s )
 
536
Bool unRLE_obuf_to_output_FAST ( DState* s )
550
537
{
551
538
   UChar k1;
552
539
 
555
542
      while (True) {
556
543
         /* try to finish existing run */
557
544
         while (True) {
558
 
            if (s->strm->avail_out == 0) return;
 
545
            if (s->strm->avail_out == 0) return False;
559
546
            if (s->state_out_len == 0) break;
560
547
            *( (UChar*)(s->strm->next_out) ) = s->state_out_ch;
561
548
            BZ_UPDATE_CRC ( s->calculatedBlockCRC, s->state_out_ch );
565
552
            s->strm->total_out_lo32++;
566
553
            if (s->strm->total_out_lo32 == 0) s->strm->total_out_hi32++;
567
554
         }
568
 
   
 
555
 
569
556
         /* can a new run be started? */
570
 
         if (s->nblock_used == s->save_nblock+1) return;
 
557
         if (s->nblock_used == s->save_nblock+1) return False;
571
558
               
 
559
         /* Only caused by corrupt data stream? */
 
560
         if (s->nblock_used > s->save_nblock+1)
 
561
            return True;
572
562
   
573
563
         s->state_out_len = 1;
574
564
         s->state_out_ch = s->k0;
608
598
      UInt32        c_tPos               = s->tPos;
609
599
      char*         cs_next_out          = s->strm->next_out;
610
600
      unsigned int  cs_avail_out         = s->strm->avail_out;
 
601
      Int32         ro_blockSize100k     = s->blockSize100k;
611
602
      /* end restore */
612
603
 
613
604
      UInt32       avail_out_INIT = cs_avail_out;
638
629
               cs_avail_out--;
639
630
            }
640
631
         }   
 
632
         /* Only caused by corrupt data stream? */
 
633
         if (c_nblock_used > s_save_nblockPP)
 
634
            return True;
 
635
 
641
636
         /* can a new run be started? */
642
637
         if (c_nblock_used == s_save_nblockPP) {
643
638
            c_state_out_len = 0; goto return_notr;
683
678
      s->strm->avail_out    = cs_avail_out;
684
679
      /* end save */
685
680
   }
 
681
   return False;
686
682
}
687
683
 
688
684
 
703
699
 
704
700
 
705
701
/*---------------------------------------------------*/
 
702
/* Return  True iff data corruption is discovered.
 
703
   Returns False if there is no problem.
 
704
*/
706
705
static
707
 
void unRLE_obuf_to_output_SMALL ( DState* s )
 
706
Bool unRLE_obuf_to_output_SMALL ( DState* s )
708
707
{
709
708
   UChar k1;
710
709
 
713
712
      while (True) {
714
713
         /* try to finish existing run */
715
714
         while (True) {
716
 
            if (s->strm->avail_out == 0) return;
 
715
            if (s->strm->avail_out == 0) return False;
717
716
            if (s->state_out_len == 0) break;
718
717
            *( (UChar*)(s->strm->next_out) ) = s->state_out_ch;
719
718
            BZ_UPDATE_CRC ( s->calculatedBlockCRC, s->state_out_ch );
725
724
         }
726
725
   
727
726
         /* can a new run be started? */
728
 
         if (s->nblock_used == s->save_nblock+1) return;
729
 
               
 
727
         if (s->nblock_used == s->save_nblock+1) return False;
 
728
 
 
729
         /* Only caused by corrupt data stream? */
 
730
         if (s->nblock_used > s->save_nblock+1)
 
731
            return True;
730
732
   
731
733
         s->state_out_len = 1;
732
734
         s->state_out_ch = s->k0;
759
761
      while (True) {
760
762
         /* try to finish existing run */
761
763
         while (True) {
762
 
            if (s->strm->avail_out == 0) return;
 
764
            if (s->strm->avail_out == 0) return False;
763
765
            if (s->state_out_len == 0) break;
764
766
            *( (UChar*)(s->strm->next_out) ) = s->state_out_ch;
765
767
            BZ_UPDATE_CRC ( s->calculatedBlockCRC, s->state_out_ch );
771
773
         }
772
774
   
773
775
         /* can a new run be started? */
774
 
         if (s->nblock_used == s->save_nblock+1) return;
 
776
         if (s->nblock_used == s->save_nblock+1) return False;
 
777
 
 
778
         /* Only caused by corrupt data stream? */
 
779
         if (s->nblock_used > s->save_nblock+1)
 
780
            return True;
775
781
   
776
782
         s->state_out_len = 1;
777
783
         s->state_out_ch = s->k0;
801
807
/*---------------------------------------------------*/
802
808
int BZ_API(BZ2_bzDecompress) ( bz_stream *strm )
803
809
{
 
810
   Bool    corrupt;
804
811
   DState* s;
805
812
   if (strm == NULL) return BZ_PARAM_ERROR;
806
813
   s = strm->state;
811
818
      if (s->state == BZ_X_IDLE) return BZ_SEQUENCE_ERROR;
812
819
      if (s->state == BZ_X_OUTPUT) {
813
820
         if (s->smallDecompress)
814
 
            unRLE_obuf_to_output_SMALL ( s ); else
815
 
            unRLE_obuf_to_output_FAST  ( s );
 
821
            corrupt = unRLE_obuf_to_output_SMALL ( s ); else
 
822
            corrupt = unRLE_obuf_to_output_FAST  ( s );
 
823
         if (corrupt) return BZ_DATA_ERROR;
816
824
         if (s->nblock_used == s->save_nblock+1 && s->state_out_len == 0) {
817
825
            BZ_FINALISE_CRC ( s->calculatedBlockCRC );
818
826
            if (s->verbosity >= 3) 
819
 
               VPrintf2 ( " {0x%x, 0x%x}", s->storedBlockCRC, 
 
827
               VPrintf2 ( " {0x%08x, 0x%08x}", s->storedBlockCRC, 
820
828
                          s->calculatedBlockCRC );
821
829
            if (s->verbosity >= 2) VPrintf0 ( "]" );
822
830
            if (s->calculatedBlockCRC != s->storedBlockCRC)
834
842
         Int32 r = BZ2_decompress ( s );
835
843
         if (r == BZ_STREAM_END) {
836
844
            if (s->verbosity >= 3)
837
 
               VPrintf2 ( "\n    combined CRCs: stored = 0x%x, computed = 0x%x", 
 
845
               VPrintf2 ( "\n    combined CRCs: stored = 0x%08x, computed = 0x%08x", 
838
846
                          s->storedCombinedCRC, s->calculatedCombinedCRC );
839
847
            if (s->calculatedCombinedCRC != s->storedCombinedCRC)
840
848
               return BZ_DATA_ERROR;
1342
1350
 
1343
1351
/*---------------------------------------------------*/
1344
1352
/*--
1345
 
   Code contributed by Yoshioka Tsuneo
1346
 
   (QWF00133@niftyserve.or.jp/tsuneo-y@is.aist-nara.ac.jp),
 
1353
   Code contributed by Yoshioka Tsuneo (tsuneo@rr.iij4u.or.jp)
1347
1354
   to support better zlib compatibility.
1348
1355
   This code is not _officially_ part of libbzip2 (yet);
1349
1356
   I haven't tested it, documented it, or considered the
1354
1361
 
1355
1362
/*---------------------------------------------------*/
1356
1363
/*--
1357
 
   return version like "0.9.0c".
 
1364
   return version like "0.9.5d, 4-Sept-1999".
1358
1365
--*/
1359
1366
const char * BZ_API(BZ2_bzlibVersion)(void)
1360
1367
{
1402
1409
         smallMode = 1; break;
1403
1410
      default:
1404
1411
         if (isdigit((int)(*mode))) {
1405
 
            blockSize100k = *mode-'0';
 
1412
            blockSize100k = *mode-BZ_HDR_0;
1406
1413
         }
1407
1414
      }
1408
1415
      mode++;
1507
1514
void BZ_API(BZ2_bzclose) (BZFILE* b)
1508
1515
{
1509
1516
   int bzerr;
1510
 
   FILE *fp = ((bzFile *)b)->handle;
 
1517
   FILE *fp;
1511
1518
   
1512
1519
   if (b==NULL) {return;}
 
1520
   fp = ((bzFile *)b)->handle;
1513
1521
   if(((bzFile*)b)->writing){
1514
1522
      BZ2_bzWriteClose(&bzerr,b,0,NULL,NULL);
1515
1523
      if(bzerr != BZ_OK){
1528
1536
/*--
1529
1537
   return last error code 
1530
1538
--*/
1531
 
static char *bzerrorstrings[] = {
 
1539
static const char *bzerrorstrings[] = {
1532
1540
       "OK"
1533
1541
      ,"SEQUENCE_ERROR"
1534
1542
      ,"PARAM_ERROR"