diff options
Diffstat (limited to 'bzip2recover.c')
-rw-r--r-- | bzip2recover.c | 88 |
1 files changed, 28 insertions, 60 deletions
diff --git a/bzip2recover.c b/bzip2recover.c index 5cd405d..ffe60bc 100644 --- a/bzip2recover.c +++ b/bzip2recover.c | |||
@@ -1,56 +1,24 @@ | |||
1 | |||
2 | /*-----------------------------------------------------------*/ | 1 | /*-----------------------------------------------------------*/ |
3 | /*--- Block recoverer program for bzip2 ---*/ | 2 | /*--- Block recoverer program for bzip2 ---*/ |
4 | /*--- bzip2recover.c ---*/ | 3 | /*--- bzip2recover.c ---*/ |
5 | /*-----------------------------------------------------------*/ | 4 | /*-----------------------------------------------------------*/ |
6 | 5 | ||
7 | /*-- | 6 | /* ------------------------------------------------------------------ |
8 | This program is bzip2recover, a program to attempt data | 7 | This file is part of bzip2/libbzip2, a program and library for |
9 | salvage from damaged files created by the accompanying | 8 | lossless, block-sorting data compression. |
10 | bzip2-1.0.3 program. | ||
11 | |||
12 | Copyright (C) 1996-2005 Julian R Seward. All rights reserved. | ||
13 | |||
14 | Redistribution and use in source and binary forms, with or without | ||
15 | modification, are permitted provided that the following conditions | ||
16 | are met: | ||
17 | |||
18 | 1. Redistributions of source code must retain the above copyright | ||
19 | notice, this list of conditions and the following disclaimer. | ||
20 | |||
21 | 2. The origin of this software must not be misrepresented; you must | ||
22 | not claim that you wrote the original software. If you use this | ||
23 | software in a product, an acknowledgment in the product | ||
24 | documentation would be appreciated but is not required. | ||
25 | |||
26 | 3. Altered source versions must be plainly marked as such, and must | ||
27 | not be misrepresented as being the original software. | ||
28 | |||
29 | 4. The name of the author may not be used to endorse or promote | ||
30 | products derived from this software without specific prior written | ||
31 | permission. | ||
32 | |||
33 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS | ||
34 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
35 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
36 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY | ||
37 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
38 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE | ||
39 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
40 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||
41 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
42 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
43 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
44 | |||
45 | Julian Seward, Cambridge, UK. | ||
46 | jseward@bzip.org | ||
47 | bzip2/libbzip2 version 1.0.3 of 15 February 2005 | ||
48 | --*/ | ||
49 | 9 | ||
50 | /*-- | 10 | bzip2/libbzip2 version 1.0.4 of 20 December 2006 |
51 | This program is a complete hack and should be rewritten | 11 | Copyright (C) 1996-2006 Julian Seward <jseward@bzip.org> |
52 | properly. It isn't very complicated. | 12 | |
53 | --*/ | 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. */ | ||
54 | 22 | ||
55 | #include <stdio.h> | 23 | #include <stdio.h> |
56 | #include <errno.h> | 24 | #include <errno.h> |
@@ -114,7 +82,7 @@ MaybeUInt64 bytesIn = 0; | |||
114 | /*---------------------------------------------------*/ | 82 | /*---------------------------------------------------*/ |
115 | 83 | ||
116 | /*---------------------------------------------*/ | 84 | /*---------------------------------------------*/ |
117 | void readError ( void ) | 85 | static void readError ( void ) |
118 | { | 86 | { |
119 | fprintf ( stderr, | 87 | fprintf ( stderr, |
120 | "%s: I/O error reading `%s', possible reason follows.\n", | 88 | "%s: I/O error reading `%s', possible reason follows.\n", |
@@ -127,7 +95,7 @@ void readError ( void ) | |||
127 | 95 | ||
128 | 96 | ||
129 | /*---------------------------------------------*/ | 97 | /*---------------------------------------------*/ |
130 | void writeError ( void ) | 98 | static void writeError ( void ) |
131 | { | 99 | { |
132 | fprintf ( stderr, | 100 | fprintf ( stderr, |
133 | "%s: I/O error reading `%s', possible reason follows.\n", | 101 | "%s: I/O error reading `%s', possible reason follows.\n", |
@@ -140,7 +108,7 @@ void writeError ( void ) | |||
140 | 108 | ||
141 | 109 | ||
142 | /*---------------------------------------------*/ | 110 | /*---------------------------------------------*/ |
143 | void mallocFail ( Int32 n ) | 111 | static void mallocFail ( Int32 n ) |
144 | { | 112 | { |
145 | fprintf ( stderr, | 113 | fprintf ( stderr, |
146 | "%s: malloc failed on request for %d bytes.\n", | 114 | "%s: malloc failed on request for %d bytes.\n", |
@@ -152,7 +120,7 @@ void mallocFail ( Int32 n ) | |||
152 | 120 | ||
153 | 121 | ||
154 | /*---------------------------------------------*/ | 122 | /*---------------------------------------------*/ |
155 | void tooManyBlocks ( Int32 max_handled_blocks ) | 123 | static void tooManyBlocks ( Int32 max_handled_blocks ) |
156 | { | 124 | { |
157 | fprintf ( stderr, | 125 | fprintf ( stderr, |
158 | "%s: `%s' appears to contain more than %d blocks\n", | 126 | "%s: `%s' appears to contain more than %d blocks\n", |
@@ -183,7 +151,7 @@ typedef | |||
183 | 151 | ||
184 | 152 | ||
185 | /*---------------------------------------------*/ | 153 | /*---------------------------------------------*/ |
186 | BitStream* bsOpenReadStream ( FILE* stream ) | 154 | static BitStream* bsOpenReadStream ( FILE* stream ) |
187 | { | 155 | { |
188 | BitStream *bs = malloc ( sizeof(BitStream) ); | 156 | BitStream *bs = malloc ( sizeof(BitStream) ); |
189 | if (bs == NULL) mallocFail ( sizeof(BitStream) ); | 157 | if (bs == NULL) mallocFail ( sizeof(BitStream) ); |
@@ -196,7 +164,7 @@ BitStream* bsOpenReadStream ( FILE* stream ) | |||
196 | 164 | ||
197 | 165 | ||
198 | /*---------------------------------------------*/ | 166 | /*---------------------------------------------*/ |
199 | BitStream* bsOpenWriteStream ( FILE* stream ) | 167 | static BitStream* bsOpenWriteStream ( FILE* stream ) |
200 | { | 168 | { |
201 | BitStream *bs = malloc ( sizeof(BitStream) ); | 169 | BitStream *bs = malloc ( sizeof(BitStream) ); |
202 | if (bs == NULL) mallocFail ( sizeof(BitStream) ); | 170 | if (bs == NULL) mallocFail ( sizeof(BitStream) ); |
@@ -209,7 +177,7 @@ BitStream* bsOpenWriteStream ( FILE* stream ) | |||
209 | 177 | ||
210 | 178 | ||
211 | /*---------------------------------------------*/ | 179 | /*---------------------------------------------*/ |
212 | void bsPutBit ( BitStream* bs, Int32 bit ) | 180 | static void bsPutBit ( BitStream* bs, Int32 bit ) |
213 | { | 181 | { |
214 | if (bs->buffLive == 8) { | 182 | if (bs->buffLive == 8) { |
215 | Int32 retVal = putc ( (UChar) bs->buffer, bs->handle ); | 183 | Int32 retVal = putc ( (UChar) bs->buffer, bs->handle ); |
@@ -228,7 +196,7 @@ void bsPutBit ( BitStream* bs, Int32 bit ) | |||
228 | /*-- | 196 | /*-- |
229 | Returns 0 or 1, or 2 to indicate EOF. | 197 | Returns 0 or 1, or 2 to indicate EOF. |
230 | --*/ | 198 | --*/ |
231 | Int32 bsGetBit ( BitStream* bs ) | 199 | static Int32 bsGetBit ( BitStream* bs ) |
232 | { | 200 | { |
233 | if (bs->buffLive > 0) { | 201 | if (bs->buffLive > 0) { |
234 | bs->buffLive --; | 202 | bs->buffLive --; |
@@ -247,7 +215,7 @@ Int32 bsGetBit ( BitStream* bs ) | |||
247 | 215 | ||
248 | 216 | ||
249 | /*---------------------------------------------*/ | 217 | /*---------------------------------------------*/ |
250 | void bsClose ( BitStream* bs ) | 218 | static void bsClose ( BitStream* bs ) |
251 | { | 219 | { |
252 | Int32 retVal; | 220 | Int32 retVal; |
253 | 221 | ||
@@ -271,7 +239,7 @@ void bsClose ( BitStream* bs ) | |||
271 | 239 | ||
272 | 240 | ||
273 | /*---------------------------------------------*/ | 241 | /*---------------------------------------------*/ |
274 | void bsPutUChar ( BitStream* bs, UChar c ) | 242 | static void bsPutUChar ( BitStream* bs, UChar c ) |
275 | { | 243 | { |
276 | Int32 i; | 244 | Int32 i; |
277 | for (i = 7; i >= 0; i--) | 245 | for (i = 7; i >= 0; i--) |
@@ -280,7 +248,7 @@ void bsPutUChar ( BitStream* bs, UChar c ) | |||
280 | 248 | ||
281 | 249 | ||
282 | /*---------------------------------------------*/ | 250 | /*---------------------------------------------*/ |
283 | void bsPutUInt32 ( BitStream* bs, UInt32 c ) | 251 | static void bsPutUInt32 ( BitStream* bs, UInt32 c ) |
284 | { | 252 | { |
285 | Int32 i; | 253 | Int32 i; |
286 | 254 | ||
@@ -290,7 +258,7 @@ void bsPutUInt32 ( BitStream* bs, UInt32 c ) | |||
290 | 258 | ||
291 | 259 | ||
292 | /*---------------------------------------------*/ | 260 | /*---------------------------------------------*/ |
293 | Bool endsInBz2 ( Char* name ) | 261 | static Bool endsInBz2 ( Char* name ) |
294 | { | 262 | { |
295 | Int32 n = strlen ( name ); | 263 | Int32 n = strlen ( name ); |
296 | if (n <= 4) return False; | 264 | if (n <= 4) return False; |
@@ -345,7 +313,7 @@ Int32 main ( Int32 argc, Char** argv ) | |||
345 | inFileName[0] = outFileName[0] = 0; | 313 | inFileName[0] = outFileName[0] = 0; |
346 | 314 | ||
347 | fprintf ( stderr, | 315 | fprintf ( stderr, |
348 | "bzip2recover 1.0.3: extracts blocks from damaged .bz2 files.\n" ); | 316 | "bzip2recover 1.0.4: extracts blocks from damaged .bz2 files.\n" ); |
349 | 317 | ||
350 | if (argc != 2) { | 318 | if (argc != 2) { |
351 | fprintf ( stderr, "%s: usage is `%s damaged_file_name'.\n", | 319 | fprintf ( stderr, "%s: usage is `%s damaged_file_name'.\n", |