Debian Codegraph @

gtb-dec.c

raw symbols SCIP
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 #include "hzip.h"
39 #include "wrap.h"
40
41 typedef int bool_t;
42
43 #ifndef TRUE
44 #define TRUE 1
45 #endif
46 #ifndef FALSE
47 #define FALSE 0;
48 #endif
49
50 /*static unsigned char intermediate_block[MAXBLOCK] ;*/
51
52 static int DECODE_SCHEME = CP4;
53 static int CP_SCHEME = CP4;
54
55 static int f_decode (size_t z, unsigned char *bz, size_t n, unsigned char *bp);
56
57 extern void
58 set_decoding_scheme(int x)
59 {
60 DECODE_SCHEME = x;
61 CP_SCHEME = x;
62 }
63
64 extern int decoding_scheme(void)
65 {
66 return DECODE_SCHEME;
67 }
68
69 extern int
70 decode (size_t z, unsigned char *bz, size_t n, unsigned char *bp)
71 {
72 return f_decode (z, bz, n, bp);
73 }
74
75 /*======================== WRAPPERS ========================*/
76
77 static int
78 f_decode (size_t z, unsigned char *bz, size_t n, unsigned char *bp)
79 {
80 /* bp buffer provided
81 | bz buffer "zipped", compressed
82 | n len of buffer provided
83 | z len of buffer zipped
84 \*---------------------------------------------------------------*/
85
86 /*
87 unsigned char *ib = intermediate_block;
88 unsigned int m;
89 return huff_decode (bz, z, ib, &m, MAXBLOCK) && rle_decode (ib, m, bp, &n, MAXBLOCK);
90 */
91
92 if (CP_SCHEME == CP1) {
93
94 /* HUFFMAN */
95 return huff_decode (bz, z, bp, &n, MAXBLOCK);
96
97 } else if (CP_SCHEME == CP2) {
98
99 /* LZF */
100 return lzf_decode (bz, z, bp, &n, MAXBLOCK);
101
102 } else if (CP_SCHEME == CP3) {
103
104 /* ZLIB */
105 return zlib_decode (bz, z, bp, &n, MAXBLOCK);
106
107 } else if (CP_SCHEME == CP4) {
108
109 /* LZMA86 */
110 return lzma_decode (bz, z, bp, &n, n); /* maximum needs to be the exact number that it will produce */
111
112 } else if (CP_SCHEME == CP7) {
113
114 /* RLE */
115 return rle_decode (bz, z, bp, &n, MAXBLOCK);
116
117 #if defined (LIBBZIP2)
118 } else if (CP_SCHEME == CP8) {
119
120 /* BZIP2 */
121 return bzip2_decode (bz, z, bp, &n, MAXBLOCK);
122 #endif
123
124 } else if (CP_SCHEME == CP9) {
125
126 return justcopy_decode (bz, z, bp, &n, MAXBLOCK);
127
128 } else {
129
130 return FALSE;
131 }
132 }
133