Parolin 0.7.9 6796
Console (soon DLLs) to do a tar like job
Loading...
Searching...
No Matches
decompress_for_all_z.c
Go to the documentation of this file.
1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2
3 #2023 X March 21 19:50 PM Brasília Time
4
5* *
6* Licensa de Copia (C) <2023> <Aurora Boreal> *
7* *
8* Este programa e software livre: voce pode redistribuir isto e/ou *
9* modificar isto sobre os termos do GNU Licensa Geral Pública como 25
10* publicado pela Fundacao de Software Livre, tanto a versão 3 da *
11* Licensa, ou (dependendo da sua opcao) qualquer versao posterior. *
12* *
13* Este programa e distribuido na esperanca que isto vai ser util, *
14* mas SEM QUALQUER GARANTIA; sem ate mesmo a implicada garantia de *
15* COMERCIALIZAcaO ou CABIMENTO PARA UM FIM PARTICULAR. Veja a *
16* Licensa Geral Publica para mais detalhes. *
17* *
18* Você deve ter recebido uma cópia da LICENSA GERAL PUBLICA e a GNU *
19* Licensa Publica Menor junto com este programa *
20* Se não, veja <http://www.gnu.org/licenses/>. *
21* *
22* Suporte: sourceforge.net github.com *
23* *
24* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
25
26* Pereira: arsoftware25@gmail.com ricardo@arsoftware.net.br *
27* xcx: arsoftware10@gmail.com charli@arsoftware.net.br *
28 Yasmin: yasmin@arsoftware.net.br *
29 pereira1001@users.sourceforge.net
30 */
31
33
34int THE_DECOMPRESSOR_FUNCION_NAME_Z(fdin, fdout, amanda)
35FILE *fdin;
36FILE *fdout;
37my_thread_struct_z *amanda;
38{
40 init_vars_ric(amanda);
42 REG2 char_type *stackp;
44 REG4 int finchar;
45 REG5 code_int oldcode;
46 REG6 code_int incode;
47 REG7 int inbits;
48 REG8 int posbits;
49 REG9 int outpos;
50 REG10 int insize;
51 REG11 int bitmask;
52 REG12 code_int free_ent;
53 REG13 code_int maxcode;
54 REG14 code_int maxmaxcode;
55 REG15 int n_bits;
56 REG16 int rsize;
57
58 amanda->bytes_in = 0;
59 amanda->bytes_out = 0;
60 insize = 0;
61
62 while (insize < 3 && (rsize = fread(amanda->inbuf + insize, 1, min(IBUFSIZ, amanda->size_of_input_file_copy_z), fdin)) > 0)
63 {
64 *((*amanda).bytes_read_z) += rsize;
65 amanda->size_of_input_file_copy_z -= rsize;
66 insize += rsize;
67
68 while (*((*amanda).intpause_14))
69 {
70 Sleep(50);
71 if (*((*amanda).intcancel_14))
72 {
73 amanda->internal_error_arp = 119;
74 return 1;
75 }
76 }
77
78 if (*((*amanda).intcancel_14))
79 {
80 amanda->internal_error_arp = 119;
81 return 1;
82 }
83 }
84
85 if (insize < 3 || amanda->inbuf[0] != MAGIC_1 || amanda->inbuf[1] != MAGIC_2)
86 {
87 if (rsize < 0)
88 return 5;
89
90 if (insize > 0)
91 {
92 /*
93 fprintf(stderr, "%s: not in compressed format\n",
94 (ifname[0] != '\0' ? ifname : "stdin"));
95 */
96 amanda->exit_code = 1;
97 }
98
99 return 7;
100 }
101
102 amanda->maxbits = amanda->inbuf[2] & BIT_MASK;
103 amanda->block_mode = amanda->inbuf[2] & BLOCK_MODE;
104
105 if (amanda->maxbits > BITS)
106 {
107 /*
108 fprintf(stderr,
109 "%s: compressed with %d bits, can only handle %d bits\n",
110 (*ifname != '\0' ? ifname : "stdin"), maxbits, BITS);
111 */
112 amanda->exit_code = 4;
113 return 7;
114 }
115
116 maxmaxcode = MAXCODE(amanda->maxbits);
117
118 amanda->bytes_in = insize;
119 maxcode = MAXCODE(n_bits = INIT_BITS) - 1;
120 bitmask = (1 << n_bits) - 1;
121 oldcode = -1;
122 finchar = 0;
123 outpos = 0;
124 posbits = 3 << 3;
125
126 free_ent = ((amanda->block_mode) ? FIRST : 256);
127
128 clear_tab_prefixof(); /* As above, initialize the first
129 256 entries in the table. */
130
131 for (code = 255; code >= 0; --code)
133
134 do
135 {
136 resetbuf:;
137 {
138 REG1 int i;
139 int e;
140 int o;
141
142 o = posbits >> 3;
143 e = o <= insize ? insize - o : 0;
144
145 for (i = 0; i < e; ++i)
146 amanda->inbuf[i] = amanda->inbuf[i + o];
147
148 insize = e;
149 posbits = 0;
150 }
151
152 if (insize < (int)(sizeof(amanda->inbuf) - IBUFSIZ))
153 {
154 if ((rsize = fread(amanda->inbuf + insize, 1, min(IBUFSIZ, amanda->size_of_input_file_copy_z), fdin)) < 0)
155 return 5;
156 /*
157 processado_rspk += rsize;
158
159 while(intpause___aakp)
160 {
161 Sleep(50);
162
163 if(intcancel__rspk)
164 {
165 return 119;
166 }
167 }
168
169 if(intcancel__rspk)
170 {
171 return 119;
172 }
173 */
174
175 while (*((*amanda).intpause_14))
176 {
177 Sleep(50);
178 if (*((*amanda).intcancel_14))
179 {
180 amanda->internal_error_arp = 119;
181 return 1;
182 }
183 }
184
185 if (*((*amanda).intcancel_14))
186 {
187 amanda->internal_error_arp = 119;
188 return 1;
189 }
190
191 *((*amanda).bytes_read_z) += rsize;
192 insize += rsize;
193 amanda->size_of_input_file_copy_z -= rsize;
194 }
195
196 inbits = ((rsize > 0) ? (insize - insize % n_bits) << 3 : (insize << 3) - (n_bits - 1));
197
198 while (inbits > posbits)
199 {
200 if (free_ent > maxcode)
201 {
202 posbits = ((posbits - 1) + ((n_bits << 3) -
203 (posbits - 1 + (n_bits << 3)) % (n_bits << 3)));
204
205 ++n_bits;
206 if (n_bits == amanda->maxbits)
207 maxcode = maxmaxcode;
208 else
209 maxcode = MAXCODE(n_bits) - 1;
210
211 bitmask = (1 << n_bits) - 1;
212 goto resetbuf;
213 }
214
215 input(amanda->inbuf, posbits, code, n_bits, bitmask);
216
217 if (oldcode == -1)
218 {
219 if (code >= 256)
220 {
221 pedro_dprintf(2, "oldcode:-1 code:%i\n", (int)(code));
222 pedro_dprintf(2, "uncompress: corrupt input\n");
223 // abort_compress();
224 return 1;
225 }
226 amanda->outbuf[outpos++] = (char_type)(finchar = (int)(oldcode = code));
227 continue;
228 }
229
230 if (code == CLEAR && amanda->block_mode)
231 {
233 free_ent = FIRST - 1;
234 posbits = ((posbits - 1) + ((n_bits << 3) -
235 (posbits - 1 + (n_bits << 3)) % (n_bits << 3)));
236 maxcode = MAXCODE(n_bits = INIT_BITS) - 1;
237 bitmask = (1 << n_bits) - 1;
238 goto resetbuf;
239 }
240
241 incode = code;
242 stackp = de_stack;
243
244 if (code >= free_ent) /* Special case for KwKwK string. */
245 {
246 if (code > free_ent)
247 {
248 REG1 char_type *p;
249
250 posbits -= n_bits;
251 p = &amanda->inbuf[posbits >> 3];
252
253 pedro_dprintf(2, "insize:%d posbits:%d inbuf:%02X %02X %02X %02X %02X (%d)\n", insize, posbits,
254 p[-1], p[0], p[1], p[2], p[3], (posbits & 07));
255 pedro_dprintf(2, "uncompress: corrupt input\n");
256 // abort_compress();
257
258 return 1;
259 }
260
261 *--stackp = (char_type)finchar;
262 code = oldcode;
263 }
264
265 while ((cmp_code_int)code >= (cmp_code_int)256)
266 { /* Generate output characters in reverse order */
267 *--stackp = tab_suffixof(code);
269 }
270
271 *--stackp = (char_type)(finchar = tab_suffixof(code));
272
273 /* And put them out in forward order */
274
275 {
276 REG1 int i;
277
278 if (outpos + (i = (de_stack - stackp)) >= OBUFSIZ)
279 {
280 do
281 {
282 if (i > OBUFSIZ - outpos)
283 i = OBUFSIZ - outpos;
284
285 if (i > 0)
286 {
287 memcpy(amanda->outbuf + outpos, stackp, i);
288 outpos += i;
289 }
290
291 if (outpos >= OBUFSIZ)
292 {
293 if (amanda->dest_is_FILE_z)
294 {
295 if ((int)fwrite(amanda->outbuf, 1, outpos, amanda->dest) != (int)outpos)
296 {
297
298 amanda->internal_error_arp = 6;
299 return 6;
300 }
301 }
302 else
303 {
304 if ((int)fwrite(amanda->outbuf, 1, outpos, fdout) != (int)outpos)
305 {
306
307 amanda->internal_error_arp = 6;
308 return 6;
309 }
310 }
311 amanda->size_of_destination_file_z += outpos;
312
313 outpos = 0;
314 }
315 stackp += i;
316 } while ((i = (de_stack - stackp)) > 0);
317 }
318 else
319 {
320 memcpy(amanda->outbuf + outpos, stackp, i);
321 outpos += i;
322 }
323 }
324
325 if ((code = free_ent) < maxmaxcode) /* Generate the new entry. */
326 {
327 tab_prefixof(code) = (unsigned short)oldcode;
328 tab_suffixof(code) = (char_type)finchar;
329 free_ent = code + 1;
330 }
331
332 oldcode = incode; /* Remember previous code. */
333 }
334
335 amanda->bytes_in += rsize;
336 } while (rsize > 0);
337
338 if (amanda->dest_is_FILE_z)
339 {
340 if (outpos > 0 && (int)fwrite(amanda->outbuf, 1, outpos, amanda->dest) != (int)outpos)
341 {
342 amanda->internal_error_arp = 6;
343 return 6; // cannot write to output file
344 }
345 }
346 else
347 {
348 if (outpos > 0 && (int)fwrite(amanda->outbuf, 1, outpos, fdout) != (int)outpos)
349 {
350 amanda->internal_error_arp = 6;
351 return 6; // cannot write to output file
352 }
353 }
354 amanda->size_of_destination_file_z += outpos;
355 return 0;
356}
void pedro_dprintf(int amanda_level, char *format,...)
Definition pedro.c:43
#define THE_DECOMPRESSOR_FUNCION_NAME_Z
Definition compress42_thread_1.c:3
void init_vars_ric(my_thread_struct_z *amanda)
Definition compress42_thread_1.c:746
#define de_stack
Definition compress42.c:703
#define REG12
Definition compress42.c:480
#define INIT_BITS
Definition compress42.c:328
long int code_int
Definition compress42.c:449
#define REG5
Definition compress42.c:473
#define MAXCODE(n)
Definition compress42.c:464
#define REG1
Definition compress42.c:469
#define REG13
Definition compress42.c:481
#define REG15
Definition compress42.c:483
#define REG7
Definition compress42.c:475
#define REG4
Definition compress42.c:472
char_type inbuf[IBUFSIZ+64]
Definition compress42.c:634
#define FIRST
Definition compress42.c:325
#define REG10
Definition compress42.c:478
#define CLEAR
Definition compress42.c:326
#define REG6
Definition compress42.c:474
#define clear_tab_prefixof()
Definition compress42.c:705
#define IBUFSIZ
Definition compress42.c:307
#define BIT_MASK
Definition compress42.c:316
#define REG9
Definition compress42.c:477
#define REG16
Definition compress42.c:484
#define input(b, o, c, n, m)
Definition compress42.c:610
#define tab_suffixof(i)
Definition compress42.c:702
#define REG11
Definition compress42.c:479
#define BITS
Definition compress42.c:403
#define MAGIC_1
Definition compress42.c:314
#define REG8
Definition compress42.c:476
#define tab_prefixof(i)
Definition compress42.c:701
long int cmp_code_int
Definition compress42.c:457
#define min(a, b)
Definition compress42.c:304
#define REG2
Definition compress42.c:470
unsigned char char_type
Definition compress42.c:460
#define REG14
Definition compress42.c:482
#define OBUFSIZ
Definition compress42.c:310
#define BLOCK_MODE
Definition compress42.c:320
#define MAGIC_2
Definition compress42.c:315
#define REG3
Definition compress42.c:471
Definition inftrees.h:24
Definition stdio_v3.h:23
unsigned char outbuf[512+2048]
Definition stdio_v3.h:63
int maxbits
Definition stdio_v3.h:58
int64_t size_of_input_file_copy_z
Definition stdio_v3.h:46
long bytes_in
Definition stdio_v3.h:69
int64_t size_of_destination_file_z
Definition stdio_v3.h:45
long bytes_out
Definition stdio_v3.h:70
bool dest_is_FILE_z
Definition stdio_v3.h:32
int block_mode
Definition stdio_v3.h:57
int exit_code
Definition stdio_v3.h:60
FILE * dest
Definition stdio_v3.h:26
int internal_error_arp
Definition stdio_v3.h:36
unsigned char inbuf[512+64]
Definition stdio_v3.h:62
#define e(i)
Definition sha256.c:45
lzma_index ** i
Definition index.h:629