Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
99 | pmbaty | 1 | /* |
2 | This Software is distributed with the following X11 License, |
||
3 | sometimes also known as MIT license. |
||
4 | |||
5 | Copyright (c) 2010 Miguel A. Ballicora |
||
6 | |||
7 | Permission is hereby granted, free of charge, to any person |
||
8 | obtaining a copy of this software and associated documentation |
||
9 | files (the "Software"), to deal in the Software without |
||
10 | restriction, including without limitation the rights to use, |
||
11 | copy, modify, merge, publish, distribute, sublicense, and/or sell |
||
12 | copies of the Software, and to permit persons to whom the |
||
13 | Software is furnished to do so, subject to the following |
||
14 | conditions: |
||
15 | |||
16 | The above copyright notice and this permission notice shall be |
||
17 | included in all copies or substantial portions of the Software. |
||
18 | |||
19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
||
20 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
||
21 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
||
22 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
||
23 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
||
24 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||
25 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
||
26 | OTHER DEALINGS IN THE SOFTWARE. |
||
27 | */ |
||
28 | |||
29 | /*--------------------------------------------------------------------------*\ |
||
30 | | |
||
31 | | Compressing wrapper functions |
||
32 | | |
||
33 | *---------------------------------------------------------------------------*/ |
||
34 | #define MAXBLOCK (1 << 16) |
||
35 | |||
36 | #include <stdlib.h> |
||
37 | #include "gtb-dec.h" |
||
38 | #ifdef HUFFMAN |
||
39 | #include "hzip.h" |
||
40 | #endif |
||
41 | #include "wrap.h" |
||
42 | |||
43 | typedef int bool_t; |
||
44 | |||
45 | #ifndef TRUE |
||
46 | #define TRUE 1 |
||
47 | #endif |
||
48 | #ifndef FALSE |
||
49 | #define FALSE 0; |
||
50 | #endif |
||
51 | |||
52 | /*static unsigned char intermediate_block[MAXBLOCK] ;*/ |
||
53 | |||
54 | static int DECODE_SCHEME = CP4; |
||
55 | static int CP_SCHEME = CP4; |
||
56 | |||
57 | static int f_decode (size_t z, unsigned char *bz, size_t n, unsigned char *bp); |
||
58 | |||
59 | extern void |
||
60 | set_decoding_scheme(int x) |
||
61 | { |
||
62 | DECODE_SCHEME = x; |
||
63 | CP_SCHEME = x; |
||
64 | } |
||
65 | |||
66 | extern int decoding_scheme(void) |
||
67 | { |
||
68 | return DECODE_SCHEME; |
||
69 | } |
||
70 | |||
71 | extern int |
||
72 | decode (size_t z, unsigned char *bz, size_t n, unsigned char *bp) |
||
73 | { |
||
74 | return f_decode (z, bz, n, bp); |
||
75 | } |
||
76 | |||
77 | /*======================== WRAPPERS ========================*/ |
||
78 | |||
79 | static int |
||
80 | f_decode (size_t z, unsigned char *bz, size_t n, unsigned char *bp) |
||
81 | { |
||
82 | /* bp buffer provided |
||
83 | | bz buffer "zipped", compressed |
||
84 | | n len of buffer provided |
||
85 | | z len of buffer zipped |
||
86 | \*---------------------------------------------------------------*/ |
||
87 | |||
88 | /* |
||
89 | unsigned char *ib = intermediate_block; |
||
90 | unsigned int m; |
||
91 | return huff_decode (bz, z, ib, &m, MAXBLOCK) && rle_decode (ib, m, bp, &n, MAXBLOCK); |
||
92 | */ |
||
93 | #if defined(HUFFMAN) |
||
94 | if (CP_SCHEME == CP1) { |
||
95 | |||
96 | /* HUFFMAN */ |
||
97 | return huff_decode (bz, z, bp, &n, MAXBLOCK); |
||
98 | |||
99 | } else |
||
100 | #endif |
||
101 | #if defined(LIBLZF) |
||
102 | if (CP_SCHEME == CP2) { |
||
103 | |||
104 | /* LZF */ |
||
105 | return lzf_decode (bz, z, bp, &n, MAXBLOCK); |
||
106 | |||
107 | } else |
||
108 | #endif |
||
109 | #if defined (ZLIB) |
||
110 | if (CP_SCHEME == CP3) { |
||
111 | |||
112 | /* ZLIB */ |
||
113 | return zlib_decode (bz, z, bp, &n, MAXBLOCK); |
||
114 | |||
115 | } else |
||
116 | #endif |
||
117 | if (CP_SCHEME == CP4) { |
||
118 | |||
119 | /* LZMA86 */ |
||
120 | return lzma_decode (bz, z, bp, &n, n); /* maximum needs to be the exact number that it will produce */ |
||
121 | |||
122 | } else if (CP_SCHEME == CP7) { |
||
123 | |||
124 | /* RLE */ |
||
125 | return rle_decode (bz, z, bp, &n, MAXBLOCK); |
||
126 | |||
127 | #if defined (LIBBZIP2) |
||
128 | } else if (CP_SCHEME == CP8) { |
||
129 | |||
130 | /* BZIP2 */ |
||
131 | return bzip2_decode (bz, z, bp, &n, MAXBLOCK); |
||
132 | #endif |
||
133 | |||
134 | } else if (CP_SCHEME == CP9) { |
||
135 | |||
136 | return justcopy_decode (bz, z, bp, &n, MAXBLOCK); |
||
137 | |||
138 | } else { |
||
139 | |||
140 | return FALSE; |
||
141 | } |
||
142 | } |
||
143 |