Mercurial > hg > toybox
annotate toys/pending/xzcat.c @ 944:b4faf2ae39e8
This inlines CRC64, and nothing more.
The functions involved were called only once.
author | Isaac Dunham <idunham@lavabit.com> |
---|---|
date | Sat, 06 Jul 2013 11:26:15 -0500 |
parents | 88060f1ff4a4 |
children | 13916d161ec0 |
rev | line source |
---|---|
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1 /* |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2 * Simple XZ decoder command line tool |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3 * |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
4 * Author: Lasse Collin <lasse.collin@tukaani.org> |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
5 * |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
6 * This file has been put into the public domain. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
7 * You can do whatever you want with this file. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
8 * Modified for toybox by Isaac Dunham |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
9 USE_XZCAT(NEWTOY(xzcat, NULL, TOYFLAG_USR|TOYFLAG_BIN)) |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
10 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
11 config XZCAT |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
12 bool "xzcat" |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
13 default n |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
14 help |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
15 usage: xzcat < file.xz |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
16 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
17 Read xz-compressed file from stdin and write decompressed file to stdout. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
18 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
19 */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
20 #define FOR_xzcat |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
21 #include "toys.h" |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
22 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
23 // BEGIN xz.h |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
24 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
25 /** |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
26 * enum xz_mode - Operation mode |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
27 * |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
28 * @XZ_SINGLE: Single-call mode. This uses less RAM than |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
29 * than multi-call modes, because the LZMA2 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
30 * dictionary doesn't need to be allocated as |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
31 * part of the decoder state. All required data |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
32 * structures are allocated at initialization, |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
33 * so xz_dec_run() cannot return XZ_MEM_ERROR. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
34 * @XZ_PREALLOC: Multi-call mode with preallocated LZMA2 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
35 * dictionary buffer. All data structures are |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
36 * allocated at initialization, so xz_dec_run() |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
37 * cannot return XZ_MEM_ERROR. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
38 * @XZ_DYNALLOC: Multi-call mode. The LZMA2 dictionary is |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
39 * allocated once the required size has been |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
40 * parsed from the stream headers. If the |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
41 * allocation fails, xz_dec_run() will return |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
42 * XZ_MEM_ERROR. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
43 * |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
44 * It is possible to enable support only for a subset of the above |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
45 * modes at compile time by defining XZ_DEC_SINGLE, XZ_DEC_PREALLOC, |
854
68cdd244f8b1
xzcat: more cleanup and some shrinking.
Isaac Dunham <idunham@lavabit.com>
parents:
851
diff
changeset
|
46 * or XZ_DEC_DYNALLOC. xzcat uses only XZ_DEC_DYNALLOC, |
68cdd244f8b1
xzcat: more cleanup and some shrinking.
Isaac Dunham <idunham@lavabit.com>
parents:
851
diff
changeset
|
47 * so that is the default. |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
48 */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
49 enum xz_mode { |
855 | 50 XZ_SINGLE, |
51 XZ_PREALLOC, | |
52 XZ_DYNALLOC | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
53 }; |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
54 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
55 /** |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
56 * enum xz_ret - Return codes |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
57 * @XZ_OK: Everything is OK so far. More input or more |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
58 * output space is required to continue. This |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
59 * return code is possible only in multi-call mode |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
60 * (XZ_PREALLOC or XZ_DYNALLOC). |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
61 * @XZ_STREAM_END: Operation finished successfully. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
62 * @XZ_UNSUPPORTED_CHECK: Integrity check type is not supported. Decoding |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
63 * is still possible in multi-call mode by simply |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
64 * calling xz_dec_run() again. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
65 * Note that this return value is used only if |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
66 * XZ_DEC_ANY_CHECK was defined at build time, |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
67 * which is not used in the kernel. Unsupported |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
68 * check types return XZ_OPTIONS_ERROR if |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
69 * XZ_DEC_ANY_CHECK was not defined at build time. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
70 * @XZ_MEM_ERROR: Allocating memory failed. This return code is |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
71 * possible only if the decoder was initialized |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
72 * with XZ_DYNALLOC. The amount of memory that was |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
73 * tried to be allocated was no more than the |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
74 * dict_max argument given to xz_dec_init(). |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
75 * @XZ_MEMLIMIT_ERROR: A bigger LZMA2 dictionary would be needed than |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
76 * allowed by the dict_max argument given to |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
77 * xz_dec_init(). This return value is possible |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
78 * only in multi-call mode (XZ_PREALLOC or |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
79 * XZ_DYNALLOC); the single-call mode (XZ_SINGLE) |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
80 * ignores the dict_max argument. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
81 * @XZ_FORMAT_ERROR: File format was not recognized (wrong magic |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
82 * bytes). |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
83 * @XZ_OPTIONS_ERROR: This implementation doesn't support the requested |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
84 * compression options. In the decoder this means |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
85 * that the header CRC32 matches, but the header |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
86 * itself specifies something that we don't support. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
87 * @XZ_DATA_ERROR: Compressed data is corrupt. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
88 * @XZ_BUF_ERROR: Cannot make any progress. Details are slightly |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
89 * different between multi-call and single-call |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
90 * mode; more information below. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
91 * |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
92 * In multi-call mode, XZ_BUF_ERROR is returned when two consecutive calls |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
93 * to XZ code cannot consume any input and cannot produce any new output. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
94 * This happens when there is no new input available, or the output buffer |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
95 * is full while at least one output byte is still pending. Assuming your |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
96 * code is not buggy, you can get this error only when decoding a compressed |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
97 * stream that is truncated or otherwise corrupt. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
98 * |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
99 * In single-call mode, XZ_BUF_ERROR is returned only when the output buffer |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
100 * is too small or the compressed input is corrupt in a way that makes the |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
101 * decoder produce more output than the caller expected. When it is |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
102 * (relatively) clear that the compressed input is truncated, XZ_DATA_ERROR |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
103 * is used instead of XZ_BUF_ERROR. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
104 */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
105 enum xz_ret { |
855 | 106 XZ_OK, |
107 XZ_STREAM_END, | |
108 XZ_UNSUPPORTED_CHECK, | |
109 XZ_MEM_ERROR, | |
110 XZ_MEMLIMIT_ERROR, | |
111 XZ_FORMAT_ERROR, | |
112 XZ_OPTIONS_ERROR, | |
113 XZ_DATA_ERROR, | |
114 XZ_BUF_ERROR | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
115 }; |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
116 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
117 /** |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
118 * struct xz_buf - Passing input and output buffers to XZ code |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
119 * @in: Beginning of the input buffer. This may be NULL if and only |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
120 * if in_pos is equal to in_size. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
121 * @in_pos: Current position in the input buffer. This must not exceed |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
122 * in_size. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
123 * @in_size: Size of the input buffer |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
124 * @out: Beginning of the output buffer. This may be NULL if and only |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
125 * if out_pos is equal to out_size. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
126 * @out_pos: Current position in the output buffer. This must not exceed |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
127 * out_size. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
128 * @out_size: Size of the output buffer |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
129 * |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
130 * Only the contents of the output buffer from out[out_pos] onward, and |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
131 * the variables in_pos and out_pos are modified by the XZ code. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
132 */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
133 struct xz_buf { |
855 | 134 const uint8_t *in; |
135 size_t in_pos; | |
136 size_t in_size; | |
137 | |
138 uint8_t *out; | |
139 size_t out_pos; | |
140 size_t out_size; | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
141 }; |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
142 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
143 /** |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
144 * struct xz_dec - Opaque type to hold the XZ decoder state |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
145 */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
146 struct xz_dec; |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
147 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
148 /** |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
149 * xz_dec_init() - Allocate and initialize a XZ decoder state |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
150 * @mode: Operation mode |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
151 * @dict_max: Maximum size of the LZMA2 dictionary (history buffer) for |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
152 * multi-call decoding. This is ignored in single-call mode |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
153 * (mode == XZ_SINGLE). LZMA2 dictionary is always 2^n bytes |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
154 * or 2^n + 2^(n-1) bytes (the latter sizes are less common |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
155 * in practice), so other values for dict_max don't make sense. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
156 * In the kernel, dictionary sizes of 64 KiB, 128 KiB, 256 KiB, |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
157 * 512 KiB, and 1 MiB are probably the only reasonable values, |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
158 * except for kernel and initramfs images where a bigger |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
159 * dictionary can be fine and useful. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
160 * |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
161 * Single-call mode (XZ_SINGLE): xz_dec_run() decodes the whole stream at |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
162 * once. The caller must provide enough output space or the decoding will |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
163 * fail. The output space is used as the dictionary buffer, which is why |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
164 * there is no need to allocate the dictionary as part of the decoder's |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
165 * internal state. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
166 * |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
167 * Because the output buffer is used as the workspace, streams encoded using |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
168 * a big dictionary are not a problem in single-call mode. It is enough that |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
169 * the output buffer is big enough to hold the actual uncompressed data; it |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
170 * can be smaller than the dictionary size stored in the stream headers. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
171 * |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
172 * Multi-call mode with preallocated dictionary (XZ_PREALLOC): dict_max bytes |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
173 * of memory is preallocated for the LZMA2 dictionary. This way there is no |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
174 * risk that xz_dec_run() could run out of memory, since xz_dec_run() will |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
175 * never allocate any memory. Instead, if the preallocated dictionary is too |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
176 * small for decoding the given input stream, xz_dec_run() will return |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
177 * XZ_MEMLIMIT_ERROR. Thus, it is important to know what kind of data will be |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
178 * decoded to avoid allocating excessive amount of memory for the dictionary. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
179 * |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
180 * Multi-call mode with dynamically allocated dictionary (XZ_DYNALLOC): |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
181 * dict_max specifies the maximum allowed dictionary size that xz_dec_run() |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
182 * may allocate once it has parsed the dictionary size from the stream |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
183 * headers. This way excessive allocations can be avoided while still |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
184 * limiting the maximum memory usage to a sane value to prevent running the |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
185 * system out of memory when decompressing streams from untrusted sources. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
186 * |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
187 * On success, xz_dec_init() returns a pointer to struct xz_dec, which is |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
188 * ready to be used with xz_dec_run(). If memory allocation fails, |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
189 * xz_dec_init() returns NULL. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
190 */ |
846
e02b4e932cd1
Some xzcat cleanup by Isaac Dunham.
Rob Landley <rob@landley.net>
parents:
819
diff
changeset
|
191 struct xz_dec *xz_dec_init(enum xz_mode mode, uint32_t dict_max); |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
192 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
193 /** |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
194 * xz_dec_run() - Run the XZ decoder |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
195 * @s: Decoder state allocated using xz_dec_init() |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
196 * @b: Input and output buffers |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
197 * |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
198 * The possible return values depend on build options and operation mode. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
199 * See enum xz_ret for details. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
200 * |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
201 * Note that if an error occurs in single-call mode (return value is not |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
202 * XZ_STREAM_END), b->in_pos and b->out_pos are not modified and the |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
203 * contents of the output buffer from b->out[b->out_pos] onward are |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
204 * undefined. This is true even after XZ_BUF_ERROR, because with some filter |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
205 * chains, there may be a second pass over the output buffer, and this pass |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
206 * cannot be properly done if the output buffer is truncated. Thus, you |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
207 * cannot give the single-call decoder a too small buffer and then expect to |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
208 * get that amount valid data from the beginning of the stream. You must use |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
209 * the multi-call decoder if you don't want to uncompress the whole stream. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
210 */ |
846
e02b4e932cd1
Some xzcat cleanup by Isaac Dunham.
Rob Landley <rob@landley.net>
parents:
819
diff
changeset
|
211 enum xz_ret xz_dec_run(struct xz_dec *s, struct xz_buf *b); |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
212 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
213 /** |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
214 * xz_dec_reset() - Reset an already allocated decoder state |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
215 * @s: Decoder state allocated using xz_dec_init() |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
216 * |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
217 * This function can be used to reset the multi-call decoder state without |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
218 * freeing and reallocating memory with xz_dec_end() and xz_dec_init(). |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
219 * |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
220 * In single-call mode, xz_dec_reset() is always called in the beginning of |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
221 * xz_dec_run(). Thus, explicit call to xz_dec_reset() is useful only in |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
222 * multi-call mode. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
223 */ |
846
e02b4e932cd1
Some xzcat cleanup by Isaac Dunham.
Rob Landley <rob@landley.net>
parents:
819
diff
changeset
|
224 void xz_dec_reset(struct xz_dec *s); |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
225 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
226 /** |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
227 * xz_dec_end() - Free the memory allocated for the decoder state |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
228 * @s: Decoder state allocated using xz_dec_init(). If s is NULL, |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
229 * this function does nothing. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
230 */ |
846
e02b4e932cd1
Some xzcat cleanup by Isaac Dunham.
Rob Landley <rob@landley.net>
parents:
819
diff
changeset
|
231 void xz_dec_end(struct xz_dec *s); |
e02b4e932cd1
Some xzcat cleanup by Isaac Dunham.
Rob Landley <rob@landley.net>
parents:
819
diff
changeset
|
232 |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
233 /* |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
234 * Update CRC32 value using the polynomial from IEEE-802.3. To start a new |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
235 * calculation, the third argument must be zero. To continue the calculation, |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
236 * the previously returned value is passed as the third argument. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
237 */ |
854
68cdd244f8b1
xzcat: more cleanup and some shrinking.
Isaac Dunham <idunham@lavabit.com>
parents:
851
diff
changeset
|
238 static uint32_t xz_crc32_table[256]; |
68cdd244f8b1
xzcat: more cleanup and some shrinking.
Isaac Dunham <idunham@lavabit.com>
parents:
851
diff
changeset
|
239 |
68cdd244f8b1
xzcat: more cleanup and some shrinking.
Isaac Dunham <idunham@lavabit.com>
parents:
851
diff
changeset
|
240 uint32_t xz_crc32(const uint8_t *buf, size_t size, uint32_t crc) |
68cdd244f8b1
xzcat: more cleanup and some shrinking.
Isaac Dunham <idunham@lavabit.com>
parents:
851
diff
changeset
|
241 { |
855 | 242 crc = ~crc; |
243 | |
244 while (size != 0) { | |
245 crc = xz_crc32_table[*buf++ ^ (crc & 0xFF)] ^ (crc >> 8); | |
246 --size; | |
247 } | |
248 | |
249 return ~crc; | |
854
68cdd244f8b1
xzcat: more cleanup and some shrinking.
Isaac Dunham <idunham@lavabit.com>
parents:
851
diff
changeset
|
250 } |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
251 |
850 | 252 static uint64_t xz_crc64_table[256]; |
253 | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
254 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
255 // END xz.h |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
256 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
257 static uint8_t in[BUFSIZ]; |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
258 static uint8_t out[BUFSIZ]; |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
259 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
260 void xzcat_main(void) |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
261 { |
855 | 262 struct xz_buf b; |
263 struct xz_dec *s; | |
264 enum xz_ret ret; | |
265 const char *msg; | |
266 | |
267 crc_init(xz_crc32_table, 1); | |
944
b4faf2ae39e8
This inlines CRC64, and nothing more.
Isaac Dunham <idunham@lavabit.com>
parents:
855
diff
changeset
|
268 const uint64_t poly = 0xC96C5795D7870F42ULL; |
b4faf2ae39e8
This inlines CRC64, and nothing more.
Isaac Dunham <idunham@lavabit.com>
parents:
855
diff
changeset
|
269 uint32_t i; |
b4faf2ae39e8
This inlines CRC64, and nothing more.
Isaac Dunham <idunham@lavabit.com>
parents:
855
diff
changeset
|
270 uint32_t j; |
b4faf2ae39e8
This inlines CRC64, and nothing more.
Isaac Dunham <idunham@lavabit.com>
parents:
855
diff
changeset
|
271 uint64_t r; |
b4faf2ae39e8
This inlines CRC64, and nothing more.
Isaac Dunham <idunham@lavabit.com>
parents:
855
diff
changeset
|
272 |
b4faf2ae39e8
This inlines CRC64, and nothing more.
Isaac Dunham <idunham@lavabit.com>
parents:
855
diff
changeset
|
273 /* initialize CRC64 table*/ |
b4faf2ae39e8
This inlines CRC64, and nothing more.
Isaac Dunham <idunham@lavabit.com>
parents:
855
diff
changeset
|
274 for (i = 0; i < 256; ++i) { |
b4faf2ae39e8
This inlines CRC64, and nothing more.
Isaac Dunham <idunham@lavabit.com>
parents:
855
diff
changeset
|
275 r = i; |
b4faf2ae39e8
This inlines CRC64, and nothing more.
Isaac Dunham <idunham@lavabit.com>
parents:
855
diff
changeset
|
276 for (j = 0; j < 8; ++j) |
b4faf2ae39e8
This inlines CRC64, and nothing more.
Isaac Dunham <idunham@lavabit.com>
parents:
855
diff
changeset
|
277 r = (r >> 1) ^ (poly & ~((r & 1) - 1)); |
b4faf2ae39e8
This inlines CRC64, and nothing more.
Isaac Dunham <idunham@lavabit.com>
parents:
855
diff
changeset
|
278 |
b4faf2ae39e8
This inlines CRC64, and nothing more.
Isaac Dunham <idunham@lavabit.com>
parents:
855
diff
changeset
|
279 xz_crc64_table[i] = r; |
b4faf2ae39e8
This inlines CRC64, and nothing more.
Isaac Dunham <idunham@lavabit.com>
parents:
855
diff
changeset
|
280 } |
855 | 281 |
282 /* | |
283 * Support up to 64 MiB dictionary. The actually needed memory | |
284 * is allocated once the headers have been parsed. | |
285 */ | |
286 s = xz_dec_init(XZ_DYNALLOC, 1 << 26); | |
287 if (s == NULL) { | |
288 msg = "Memory allocation failed\n"; | |
289 goto error; | |
290 } | |
291 | |
292 b.in = in; | |
293 b.in_pos = 0; | |
294 b.in_size = 0; | |
295 b.out = out; | |
296 b.out_pos = 0; | |
297 b.out_size = BUFSIZ; | |
298 | |
299 for (;;) { | |
300 if (b.in_pos == b.in_size) { | |
301 b.in_size = fread(in, 1, sizeof(in), stdin); | |
302 b.in_pos = 0; | |
303 } | |
304 | |
305 ret = xz_dec_run(s, &b); | |
306 | |
307 if (b.out_pos == sizeof(out)) { | |
308 if (fwrite(out, 1, b.out_pos, stdout) != b.out_pos) { | |
309 msg = "Write error\n"; | |
310 goto error; | |
311 } | |
312 | |
313 b.out_pos = 0; | |
314 } | |
315 | |
316 if (ret == XZ_OK) | |
317 continue; | |
318 | |
319 if (ret == XZ_UNSUPPORTED_CHECK) | |
320 continue; | |
321 | |
322 if (fwrite(out, 1, b.out_pos, stdout) != b.out_pos | |
323 || fclose(stdout)) { | |
324 msg = "Write error\n"; | |
325 goto error; | |
326 } | |
327 | |
328 switch (ret) { | |
329 case XZ_STREAM_END: | |
330 xz_dec_end(s); | |
331 return; | |
332 | |
333 case XZ_MEM_ERROR: | |
334 msg = "Memory allocation failed\n"; | |
335 goto error; | |
336 | |
337 case XZ_MEMLIMIT_ERROR: | |
338 msg = "Memory usage limit reached\n"; | |
339 goto error; | |
340 | |
341 case XZ_FORMAT_ERROR: | |
342 msg = "Not a .xz file\n"; | |
343 goto error; | |
344 | |
345 case XZ_OPTIONS_ERROR: | |
346 msg = "Unsupported options in the .xz headers\n"; | |
347 goto error; | |
348 | |
349 case XZ_DATA_ERROR: | |
350 case XZ_BUF_ERROR: | |
351 msg = "File is corrupt\n"; | |
352 goto error; | |
353 | |
354 default: | |
355 msg = "Bug!\n"; | |
356 goto error; | |
357 } | |
358 } | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
359 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
360 error: |
855 | 361 xz_dec_end(s); |
362 error_exit("%s", msg); | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
363 } |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
364 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
365 // BEGIN xz_private.h |
850 | 366 |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
367 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
368 /* Uncomment as needed to enable BCJ filter decoders. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
369 * These cost about 2.5 k when all are enabled; SPARC and IA64 make 0.7 k |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
370 * */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
371 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
372 #define XZ_DEC_X86 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
373 #define XZ_DEC_POWERPC |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
374 #define XZ_DEC_IA64 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
375 #define XZ_DEC_ARM |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
376 #define XZ_DEC_ARMTHUMB |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
377 #define XZ_DEC_SPARC |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
378 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
379 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
380 #define memeq(a, b, size) (memcmp(a, b, size) == 0) |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
381 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
382 #ifndef min |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
383 # define min(x, y) ((x) < (y) ? (x) : (y)) |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
384 #endif |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
385 #define min_t(type, x, y) min(x, y) |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
386 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
387 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
388 /* Inline functions to access unaligned unsigned 32-bit integers */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
389 #ifndef get_unaligned_le32 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
390 static inline uint32_t get_unaligned_le32(const uint8_t *buf) |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
391 { |
855 | 392 return (uint32_t)buf[0] |
393 | ((uint32_t)buf[1] << 8) | |
394 | ((uint32_t)buf[2] << 16) | |
395 | ((uint32_t)buf[3] << 24); | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
396 } |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
397 #endif |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
398 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
399 #ifndef get_unaligned_be32 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
400 static inline uint32_t get_unaligned_be32(const uint8_t *buf) |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
401 { |
855 | 402 return (uint32_t)(buf[0] << 24) |
403 | ((uint32_t)buf[1] << 16) | |
404 | ((uint32_t)buf[2] << 8) | |
405 | (uint32_t)buf[3]; | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
406 } |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
407 #endif |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
408 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
409 #ifndef put_unaligned_le32 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
410 static inline void put_unaligned_le32(uint32_t val, uint8_t *buf) |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
411 { |
855 | 412 buf[0] = (uint8_t)val; |
413 buf[1] = (uint8_t)(val >> 8); | |
414 buf[2] = (uint8_t)(val >> 16); | |
415 buf[3] = (uint8_t)(val >> 24); | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
416 } |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
417 #endif |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
418 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
419 #ifndef put_unaligned_be32 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
420 static inline void put_unaligned_be32(uint32_t val, uint8_t *buf) |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
421 { |
855 | 422 buf[0] = (uint8_t)(val >> 24); |
423 buf[1] = (uint8_t)(val >> 16); | |
424 buf[2] = (uint8_t)(val >> 8); | |
425 buf[3] = (uint8_t)val; | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
426 } |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
427 #endif |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
428 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
429 /* |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
430 * Use get_unaligned_le32() also for aligned access for simplicity. On |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
431 * little endian systems, #define get_le32(ptr) (*(const uint32_t *)(ptr)) |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
432 * could save a few bytes in code size. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
433 */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
434 #ifndef get_le32 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
435 # define get_le32 get_unaligned_le32 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
436 #endif |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
437 |
854
68cdd244f8b1
xzcat: more cleanup and some shrinking.
Isaac Dunham <idunham@lavabit.com>
parents:
851
diff
changeset
|
438 |
68cdd244f8b1
xzcat: more cleanup and some shrinking.
Isaac Dunham <idunham@lavabit.com>
parents:
851
diff
changeset
|
439 #define XZ_DEC_DYNALLOC |
68cdd244f8b1
xzcat: more cleanup and some shrinking.
Isaac Dunham <idunham@lavabit.com>
parents:
851
diff
changeset
|
440 /* DYNALLOC is what we use, but we may want these later. |
68cdd244f8b1
xzcat: more cleanup and some shrinking.
Isaac Dunham <idunham@lavabit.com>
parents:
851
diff
changeset
|
441 #define XZ_DEC_SINGLE |
68cdd244f8b1
xzcat: more cleanup and some shrinking.
Isaac Dunham <idunham@lavabit.com>
parents:
851
diff
changeset
|
442 #define XZ_DEC_PREALLOC |
68cdd244f8b1
xzcat: more cleanup and some shrinking.
Isaac Dunham <idunham@lavabit.com>
parents:
851
diff
changeset
|
443 */ |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
444 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
445 /* |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
446 * The DEC_IS_foo(mode) macros are used in "if" statements. If only some |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
447 * of the supported modes are enabled, these macros will evaluate to true or |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
448 * false at compile time and thus allow the compiler to omit unneeded code. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
449 */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
450 #ifdef XZ_DEC_SINGLE |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
451 # define DEC_IS_SINGLE(mode) ((mode) == XZ_SINGLE) |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
452 #else |
851 | 453 # define DEC_IS_SINGLE(mode) (0) |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
454 #endif |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
455 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
456 #ifdef XZ_DEC_PREALLOC |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
457 # define DEC_IS_PREALLOC(mode) ((mode) == XZ_PREALLOC) |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
458 #else |
851 | 459 # define DEC_IS_PREALLOC(mode) (0) |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
460 #endif |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
461 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
462 #ifdef XZ_DEC_DYNALLOC |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
463 # define DEC_IS_DYNALLOC(mode) ((mode) == XZ_DYNALLOC) |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
464 #else |
851 | 465 # define DEC_IS_DYNALLOC(mode) (0) |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
466 #endif |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
467 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
468 #if !defined(XZ_DEC_SINGLE) |
851 | 469 # define DEC_IS_MULTI(mode) (1) |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
470 #elif defined(XZ_DEC_PREALLOC) || defined(XZ_DEC_DYNALLOC) |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
471 # define DEC_IS_MULTI(mode) ((mode) != XZ_SINGLE) |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
472 #else |
851 | 473 # define DEC_IS_MULTI(mode) (0) |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
474 #endif |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
475 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
476 /* |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
477 * If any of the BCJ filter decoders are wanted, define XZ_DEC_BCJ. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
478 * XZ_DEC_BCJ is used to enable generic support for BCJ decoders. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
479 */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
480 #ifndef XZ_DEC_BCJ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
481 # if defined(XZ_DEC_X86) || defined(XZ_DEC_POWERPC) \ |
855 | 482 || defined(XZ_DEC_IA64) || defined(XZ_DEC_ARM) \ |
483 || defined(XZ_DEC_ARM) || defined(XZ_DEC_ARMTHUMB) \ | |
484 || defined(XZ_DEC_SPARC) | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
485 # define XZ_DEC_BCJ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
486 # endif |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
487 #endif |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
488 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
489 /* |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
490 * Allocate memory for LZMA2 decoder. xz_dec_lzma2_reset() must be used |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
491 * before calling xz_dec_lzma2_run(). |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
492 */ |
846
e02b4e932cd1
Some xzcat cleanup by Isaac Dunham.
Rob Landley <rob@landley.net>
parents:
819
diff
changeset
|
493 struct xz_dec_lzma2 *xz_dec_lzma2_create(enum xz_mode mode, |
855 | 494 uint32_t dict_max); |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
495 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
496 /* |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
497 * Decode the LZMA2 properties (one byte) and reset the decoder. Return |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
498 * XZ_OK on success, XZ_MEMLIMIT_ERROR if the preallocated dictionary is not |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
499 * big enough, and XZ_OPTIONS_ERROR if props indicates something that this |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
500 * decoder doesn't support. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
501 */ |
846
e02b4e932cd1
Some xzcat cleanup by Isaac Dunham.
Rob Landley <rob@landley.net>
parents:
819
diff
changeset
|
502 enum xz_ret xz_dec_lzma2_reset(struct xz_dec_lzma2 *s, |
855 | 503 uint8_t props); |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
504 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
505 /* Decode raw LZMA2 stream from b->in to b->out. */ |
846
e02b4e932cd1
Some xzcat cleanup by Isaac Dunham.
Rob Landley <rob@landley.net>
parents:
819
diff
changeset
|
506 enum xz_ret xz_dec_lzma2_run(struct xz_dec_lzma2 *s, |
855 | 507 struct xz_buf *b); |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
508 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
509 #ifdef XZ_DEC_BCJ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
510 /* |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
511 * Allocate memory for BCJ decoders. xz_dec_bcj_reset() must be used before |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
512 * calling xz_dec_bcj_run(). |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
513 */ |
851 | 514 struct xz_dec_bcj *xz_dec_bcj_create(int single_call); |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
515 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
516 /* |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
517 * Decode the Filter ID of a BCJ filter. This implementation doesn't |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
518 * support custom start offsets, so no decoding of Filter Properties |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
519 * is needed. Returns XZ_OK if the given Filter ID is supported. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
520 * Otherwise XZ_OPTIONS_ERROR is returned. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
521 */ |
846
e02b4e932cd1
Some xzcat cleanup by Isaac Dunham.
Rob Landley <rob@landley.net>
parents:
819
diff
changeset
|
522 enum xz_ret xz_dec_bcj_reset(struct xz_dec_bcj *s, uint8_t id); |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
523 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
524 /* |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
525 * Decode raw BCJ + LZMA2 stream. This must be used only if there actually is |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
526 * a BCJ filter in the chain. If the chain has only LZMA2, xz_dec_lzma2_run() |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
527 * must be called directly. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
528 */ |
846
e02b4e932cd1
Some xzcat cleanup by Isaac Dunham.
Rob Landley <rob@landley.net>
parents:
819
diff
changeset
|
529 enum xz_ret xz_dec_bcj_run(struct xz_dec_bcj *s, |
855 | 530 struct xz_dec_lzma2 *lzma2, |
531 struct xz_buf *b); | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
532 #endif |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
533 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
534 // END "xz_private.h" |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
535 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
536 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
537 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
538 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
539 /* |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
540 * Branch/Call/Jump (BCJ) filter decoders |
850 | 541 * The rest of the code is inside this ifdef. It makes things a little more |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
542 * convenient when building without support for any BCJ filters. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
543 */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
544 #ifdef XZ_DEC_BCJ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
545 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
546 struct xz_dec_bcj { |
855 | 547 /* Type of the BCJ filter being used */ |
548 enum { | |
549 BCJ_X86 = 4, /* x86 or x86-64 */ | |
550 BCJ_POWERPC = 5, /* Big endian only */ | |
551 BCJ_IA64 = 6, /* Big or little endian */ | |
552 BCJ_ARM = 7, /* Little endian only */ | |
553 BCJ_ARMTHUMB = 8, /* Little endian only */ | |
554 BCJ_SPARC = 9 /* Big or little endian */ | |
555 } type; | |
556 | |
557 /* | |
558 * Return value of the next filter in the chain. We need to preserve | |
559 * this information across calls, because we must not call the next | |
560 * filter anymore once it has returned XZ_STREAM_END. | |
561 */ | |
562 enum xz_ret ret; | |
563 | |
564 /* True if we are operating in single-call mode. */ | |
565 int single_call; | |
566 | |
567 /* | |
568 * Absolute position relative to the beginning of the uncompressed | |
569 * data (in a single .xz Block). We care only about the lowest 32 | |
570 * bits so this doesn't need to be uint64_t even with big files. | |
571 */ | |
572 uint32_t pos; | |
573 | |
574 /* x86 filter state */ | |
575 uint32_t x86_prev_mask; | |
576 | |
577 /* Temporary space to hold the variables from struct xz_buf */ | |
578 uint8_t *out; | |
579 size_t out_pos; | |
580 size_t out_size; | |
581 | |
582 struct { | |
583 /* Amount of already filtered data in the beginning of buf */ | |
584 size_t filtered; | |
585 | |
586 /* Total amount of data currently stored in buf */ | |
587 size_t size; | |
588 | |
589 /* | |
590 * Buffer to hold a mix of filtered and unfiltered data. This | |
591 * needs to be big enough to hold Alignment + 2 * Look-ahead: | |
592 * | |
593 * Type Alignment Look-ahead | |
594 * x86 1 4 | |
595 * PowerPC 4 0 | |
596 * IA-64 16 0 | |
597 * ARM 4 0 | |
598 * ARM-Thumb 2 2 | |
599 * SPARC 4 0 | |
600 */ | |
601 uint8_t buf[16]; | |
602 } temp; | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
603 }; |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
604 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
605 #ifdef XZ_DEC_X86 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
606 /* |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
607 * This is used to test the most significant byte of a memory address |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
608 * in an x86 instruction. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
609 */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
610 static inline int bcj_x86_test_msbyte(uint8_t b) |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
611 { |
855 | 612 return b == 0x00 || b == 0xFF; |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
613 } |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
614 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
615 static size_t bcj_x86(struct xz_dec_bcj *s, uint8_t *buf, size_t size) |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
616 { |
855 | 617 static const int mask_to_allowed_status[8] |
618 = { 1,1,1,0,1,0,0,0 }; | |
619 | |
620 static const uint8_t mask_to_bit_num[8] = { 0, 1, 2, 2, 3, 3, 3, 3 }; | |
621 | |
622 size_t i; | |
623 size_t prev_pos = (size_t)-1; | |
624 uint32_t prev_mask = s->x86_prev_mask; | |
625 uint32_t src; | |
626 uint32_t dest; | |
627 uint32_t j; | |
628 uint8_t b; | |
629 | |
630 if (size <= 4) | |
631 return 0; | |
632 | |
633 size -= 4; | |
634 for (i = 0; i < size; ++i) { | |
635 if ((buf[i] & 0xFE) != 0xE8) | |
636 continue; | |
637 | |
638 prev_pos = i - prev_pos; | |
639 if (prev_pos > 3) { | |
640 prev_mask = 0; | |
641 } else { | |
642 prev_mask = (prev_mask << (prev_pos - 1)) & 7; | |
643 if (prev_mask != 0) { | |
644 b = buf[i + 4 - mask_to_bit_num[prev_mask]]; | |
645 if (!mask_to_allowed_status[prev_mask] | |
646 || bcj_x86_test_msbyte(b)) { | |
647 prev_pos = i; | |
648 prev_mask = (prev_mask << 1) | 1; | |
649 continue; | |
650 } | |
651 } | |
652 } | |
653 | |
654 prev_pos = i; | |
655 | |
656 if (bcj_x86_test_msbyte(buf[i + 4])) { | |
657 src = get_unaligned_le32(buf + i + 1); | |
658 for (;;) { | |
659 dest = src - (s->pos + (uint32_t)i + 5); | |
660 if (prev_mask == 0) | |
661 break; | |
662 | |
663 j = mask_to_bit_num[prev_mask] * 8; | |
664 b = (uint8_t)(dest >> (24 - j)); | |
665 if (!bcj_x86_test_msbyte(b)) | |
666 break; | |
667 | |
668 src = dest ^ (((uint32_t)1 << (32 - j)) - 1); | |
669 } | |
670 | |
671 dest &= 0x01FFFFFF; | |
672 dest |= (uint32_t)0 - (dest & 0x01000000); | |
673 put_unaligned_le32(dest, buf + i + 1); | |
674 i += 4; | |
675 } else { | |
676 prev_mask = (prev_mask << 1) | 1; | |
677 } | |
678 } | |
679 | |
680 prev_pos = i - prev_pos; | |
681 s->x86_prev_mask = prev_pos > 3 ? 0 : prev_mask << (prev_pos - 1); | |
682 return i; | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
683 } |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
684 #endif |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
685 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
686 #ifdef XZ_DEC_POWERPC |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
687 static size_t bcj_powerpc(struct xz_dec_bcj *s, uint8_t *buf, size_t size) |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
688 { |
855 | 689 size_t i; |
690 uint32_t instr; | |
691 | |
692 for (i = 0; i + 4 <= size; i += 4) { | |
693 instr = get_unaligned_be32(buf + i); | |
694 if ((instr & 0xFC000003) == 0x48000001) { | |
695 instr &= 0x03FFFFFC; | |
696 instr -= s->pos + (uint32_t)i; | |
697 instr &= 0x03FFFFFC; | |
698 instr |= 0x48000001; | |
699 put_unaligned_be32(instr, buf + i); | |
700 } | |
701 } | |
702 | |
703 return i; | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
704 } |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
705 #endif |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
706 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
707 #ifdef XZ_DEC_IA64 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
708 static size_t bcj_ia64(struct xz_dec_bcj *s, uint8_t *buf, size_t size) |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
709 { |
855 | 710 static const uint8_t branch_table[32] = { |
711 0, 0, 0, 0, 0, 0, 0, 0, | |
712 0, 0, 0, 0, 0, 0, 0, 0, | |
713 4, 4, 6, 6, 0, 0, 7, 7, | |
714 4, 4, 0, 0, 4, 4, 0, 0 | |
715 }; | |
716 | |
717 /* | |
718 * The local variables take a little bit stack space, but it's less | |
719 * than what LZMA2 decoder takes, so it doesn't make sense to reduce | |
720 * stack usage here without doing that for the LZMA2 decoder too. | |
721 */ | |
722 | |
723 /* Loop counters */ | |
724 size_t i; | |
725 size_t j; | |
726 | |
727 /* Instruction slot (0, 1, or 2) in the 128-bit instruction word */ | |
728 uint32_t slot; | |
729 | |
730 /* Bitwise offset of the instruction indicated by slot */ | |
731 uint32_t bit_pos; | |
732 | |
733 /* bit_pos split into byte and bit parts */ | |
734 uint32_t byte_pos; | |
735 uint32_t bit_res; | |
736 | |
737 /* Address part of an instruction */ | |
738 uint32_t addr; | |
739 | |
740 /* Mask used to detect which instructions to convert */ | |
741 uint32_t mask; | |
742 | |
743 /* 41-bit instruction stored somewhere in the lowest 48 bits */ | |
744 uint64_t instr; | |
745 | |
746 /* Instruction normalized with bit_res for easier manipulation */ | |
747 uint64_t norm; | |
748 | |
749 for (i = 0; i + 16 <= size; i += 16) { | |
750 mask = branch_table[buf[i] & 0x1F]; | |
751 for (slot = 0, bit_pos = 5; slot < 3; ++slot, bit_pos += 41) { | |
752 if (((mask >> slot) & 1) == 0) | |
753 continue; | |
754 | |
755 byte_pos = bit_pos >> 3; | |
756 bit_res = bit_pos & 7; | |
757 instr = 0; | |
758 for (j = 0; j < 6; ++j) | |
759 instr |= (uint64_t)(buf[i + j + byte_pos]) | |
760 << (8 * j); | |
761 | |
762 norm = instr >> bit_res; | |
763 | |
764 if (((norm >> 37) & 0x0F) == 0x05 | |
765 && ((norm >> 9) & 0x07) == 0) { | |
766 addr = (norm >> 13) & 0x0FFFFF; | |
767 addr |= ((uint32_t)(norm >> 36) & 1) << 20; | |
768 addr <<= 4; | |
769 addr -= s->pos + (uint32_t)i; | |
770 addr >>= 4; | |
771 | |
772 norm &= ~((uint64_t)0x8FFFFF << 13); | |
773 norm |= (uint64_t)(addr & 0x0FFFFF) << 13; | |
774 norm |= (uint64_t)(addr & 0x100000) | |
775 << (36 - 20); | |
776 | |
777 instr &= (1 << bit_res) - 1; | |
778 instr |= norm << bit_res; | |
779 | |
780 for (j = 0; j < 6; j++) | |
781 buf[i + j + byte_pos] | |
782 = (uint8_t)(instr >> (8 * j)); | |
783 } | |
784 } | |
785 } | |
786 | |
787 return i; | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
788 } |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
789 #endif |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
790 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
791 #ifdef XZ_DEC_ARM |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
792 static size_t bcj_arm(struct xz_dec_bcj *s, uint8_t *buf, size_t size) |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
793 { |
855 | 794 size_t i; |
795 uint32_t addr; | |
796 | |
797 for (i = 0; i + 4 <= size; i += 4) { | |
798 if (buf[i + 3] == 0xEB) { | |
799 addr = (uint32_t)buf[i] | ((uint32_t)buf[i + 1] << 8) | |
800 | ((uint32_t)buf[i + 2] << 16); | |
801 addr <<= 2; | |
802 addr -= s->pos + (uint32_t)i + 8; | |
803 addr >>= 2; | |
804 buf[i] = (uint8_t)addr; | |
805 buf[i + 1] = (uint8_t)(addr >> 8); | |
806 buf[i + 2] = (uint8_t)(addr >> 16); | |
807 } | |
808 } | |
809 | |
810 return i; | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
811 } |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
812 #endif |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
813 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
814 #ifdef XZ_DEC_ARMTHUMB |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
815 static size_t bcj_armthumb(struct xz_dec_bcj *s, uint8_t *buf, size_t size) |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
816 { |
855 | 817 size_t i; |
818 uint32_t addr; | |
819 | |
820 for (i = 0; i + 4 <= size; i += 2) { | |
821 if ((buf[i + 1] & 0xF8) == 0xF0 | |
822 && (buf[i + 3] & 0xF8) == 0xF8) { | |
823 addr = (((uint32_t)buf[i + 1] & 0x07) << 19) | |
824 | ((uint32_t)buf[i] << 11) | |
825 | (((uint32_t)buf[i + 3] & 0x07) << 8) | |
826 | (uint32_t)buf[i + 2]; | |
827 addr <<= 1; | |
828 addr -= s->pos + (uint32_t)i + 4; | |
829 addr >>= 1; | |
830 buf[i + 1] = (uint8_t)(0xF0 | ((addr >> 19) & 0x07)); | |
831 buf[i] = (uint8_t)(addr >> 11); | |
832 buf[i + 3] = (uint8_t)(0xF8 | ((addr >> 8) & 0x07)); | |
833 buf[i + 2] = (uint8_t)addr; | |
834 i += 2; | |
835 } | |
836 } | |
837 | |
838 return i; | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
839 } |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
840 #endif |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
841 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
842 #ifdef XZ_DEC_SPARC |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
843 static size_t bcj_sparc(struct xz_dec_bcj *s, uint8_t *buf, size_t size) |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
844 { |
855 | 845 size_t i; |
846 uint32_t instr; | |
847 | |
848 for (i = 0; i + 4 <= size; i += 4) { | |
849 instr = get_unaligned_be32(buf + i); | |
850 if ((instr >> 22) == 0x100 || (instr >> 22) == 0x1FF) { | |
851 instr <<= 2; | |
852 instr -= s->pos + (uint32_t)i; | |
853 instr >>= 2; | |
854 instr = ((uint32_t)0x40000000 - (instr & 0x400000)) | |
855 | 0x40000000 | (instr & 0x3FFFFF); | |
856 put_unaligned_be32(instr, buf + i); | |
857 } | |
858 } | |
859 | |
860 return i; | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
861 } |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
862 #endif |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
863 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
864 /* |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
865 * Apply the selected BCJ filter. Update *pos and s->pos to match the amount |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
866 * of data that got filtered. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
867 * |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
868 * NOTE: This is implemented as a switch statement to avoid using function |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
869 * pointers, which could be problematic in the kernel boot code, which must |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
870 * avoid pointers to static data (at least on x86). |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
871 */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
872 static void bcj_apply(struct xz_dec_bcj *s, |
855 | 873 uint8_t *buf, size_t *pos, size_t size) |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
874 { |
855 | 875 size_t filtered; |
876 | |
877 buf += *pos; | |
878 size -= *pos; | |
879 | |
880 switch (s->type) { | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
881 #ifdef XZ_DEC_X86 |
855 | 882 case BCJ_X86: |
883 filtered = bcj_x86(s, buf, size); | |
884 break; | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
885 #endif |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
886 #ifdef XZ_DEC_POWERPC |
855 | 887 case BCJ_POWERPC: |
888 filtered = bcj_powerpc(s, buf, size); | |
889 break; | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
890 #endif |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
891 #ifdef XZ_DEC_IA64 |
855 | 892 case BCJ_IA64: |
893 filtered = bcj_ia64(s, buf, size); | |
894 break; | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
895 #endif |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
896 #ifdef XZ_DEC_ARM |
855 | 897 case BCJ_ARM: |
898 filtered = bcj_arm(s, buf, size); | |
899 break; | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
900 #endif |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
901 #ifdef XZ_DEC_ARMTHUMB |
855 | 902 case BCJ_ARMTHUMB: |
903 filtered = bcj_armthumb(s, buf, size); | |
904 break; | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
905 #endif |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
906 #ifdef XZ_DEC_SPARC |
855 | 907 case BCJ_SPARC: |
908 filtered = bcj_sparc(s, buf, size); | |
909 break; | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
910 #endif |
855 | 911 default: |
912 /* Never reached but silence compiler warnings. */ | |
913 filtered = 0; | |
914 break; | |
915 } | |
916 | |
917 *pos += filtered; | |
918 s->pos += filtered; | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
919 } |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
920 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
921 /* |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
922 * Flush pending filtered data from temp to the output buffer. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
923 * Move the remaining mixture of possibly filtered and unfiltered |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
924 * data to the beginning of temp. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
925 */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
926 static void bcj_flush(struct xz_dec_bcj *s, struct xz_buf *b) |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
927 { |
855 | 928 size_t copy_size; |
929 | |
930 copy_size = min_t(size_t, s->temp.filtered, b->out_size - b->out_pos); | |
931 memcpy(b->out + b->out_pos, s->temp.buf, copy_size); | |
932 b->out_pos += copy_size; | |
933 | |
934 s->temp.filtered -= copy_size; | |
935 s->temp.size -= copy_size; | |
936 memmove(s->temp.buf, s->temp.buf + copy_size, s->temp.size); | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
937 } |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
938 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
939 /* |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
940 * The BCJ filter functions are primitive in sense that they process the |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
941 * data in chunks of 1-16 bytes. To hide this issue, this function does |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
942 * some buffering. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
943 */ |
846
e02b4e932cd1
Some xzcat cleanup by Isaac Dunham.
Rob Landley <rob@landley.net>
parents:
819
diff
changeset
|
944 enum xz_ret xz_dec_bcj_run(struct xz_dec_bcj *s, |
855 | 945 struct xz_dec_lzma2 *lzma2, |
946 struct xz_buf *b) | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
947 { |
855 | 948 size_t out_start; |
949 | |
950 /* | |
951 * Flush pending already filtered data to the output buffer. Return | |
952 * immediatelly if we couldn't flush everything, or if the next | |
953 * filter in the chain had already returned XZ_STREAM_END. | |
954 */ | |
955 if (s->temp.filtered > 0) { | |
956 bcj_flush(s, b); | |
957 if (s->temp.filtered > 0) | |
958 return XZ_OK; | |
959 | |
960 if (s->ret == XZ_STREAM_END) | |
961 return XZ_STREAM_END; | |
962 } | |
963 | |
964 /* | |
965 * If we have more output space than what is currently pending in | |
966 * temp, copy the unfiltered data from temp to the output buffer | |
967 * and try to fill the output buffer by decoding more data from the | |
968 * next filter in the chain. Apply the BCJ filter on the new data | |
969 * in the output buffer. If everything cannot be filtered, copy it | |
970 * to temp and rewind the output buffer position accordingly. | |
971 * | |
972 * This needs to be always run when temp.size == 0 to handle a special | |
973 * case where the output buffer is full and the next filter has no | |
974 * more output coming but hasn't returned XZ_STREAM_END yet. | |
975 */ | |
976 if (s->temp.size < b->out_size - b->out_pos || s->temp.size == 0) { | |
977 out_start = b->out_pos; | |
978 memcpy(b->out + b->out_pos, s->temp.buf, s->temp.size); | |
979 b->out_pos += s->temp.size; | |
980 | |
981 s->ret = xz_dec_lzma2_run(lzma2, b); | |
982 if (s->ret != XZ_STREAM_END | |
983 && (s->ret != XZ_OK || s->single_call)) | |
984 return s->ret; | |
985 | |
986 bcj_apply(s, b->out, &out_start, b->out_pos); | |
987 | |
988 /* | |
989 * As an exception, if the next filter returned XZ_STREAM_END, | |
990 * we can do that too, since the last few bytes that remain | |
991 * unfiltered are meant to remain unfiltered. | |
992 */ | |
993 if (s->ret == XZ_STREAM_END) | |
994 return XZ_STREAM_END; | |
995 | |
996 s->temp.size = b->out_pos - out_start; | |
997 b->out_pos -= s->temp.size; | |
998 memcpy(s->temp.buf, b->out + b->out_pos, s->temp.size); | |
999 | |
1000 /* | |
1001 * If there wasn't enough input to the next filter to fill | |
1002 * the output buffer with unfiltered data, there's no point | |
1003 * to try decoding more data to temp. | |
1004 */ | |
1005 if (b->out_pos + s->temp.size < b->out_size) | |
1006 return XZ_OK; | |
1007 } | |
1008 | |
1009 /* | |
1010 * We have unfiltered data in temp. If the output buffer isn't full | |
1011 * yet, try to fill the temp buffer by decoding more data from the | |
1012 * next filter. Apply the BCJ filter on temp. Then we hopefully can | |
1013 * fill the actual output buffer by copying filtered data from temp. | |
1014 * A mix of filtered and unfiltered data may be left in temp; it will | |
1015 * be taken care on the next call to this function. | |
1016 */ | |
1017 if (b->out_pos < b->out_size) { | |
1018 /* Make b->out{,_pos,_size} temporarily point to s->temp. */ | |
1019 s->out = b->out; | |
1020 s->out_pos = b->out_pos; | |
1021 s->out_size = b->out_size; | |
1022 b->out = s->temp.buf; | |
1023 b->out_pos = s->temp.size; | |
1024 b->out_size = sizeof(s->temp.buf); | |
1025 | |
1026 s->ret = xz_dec_lzma2_run(lzma2, b); | |
1027 | |
1028 s->temp.size = b->out_pos; | |
1029 b->out = s->out; | |
1030 b->out_pos = s->out_pos; | |
1031 b->out_size = s->out_size; | |
1032 | |
1033 if (s->ret != XZ_OK && s->ret != XZ_STREAM_END) | |
1034 return s->ret; | |
1035 | |
1036 bcj_apply(s, s->temp.buf, &s->temp.filtered, s->temp.size); | |
1037 | |
1038 /* | |
1039 * If the next filter returned XZ_STREAM_END, we mark that | |
1040 * everything is filtered, since the last unfiltered bytes | |
1041 * of the stream are meant to be left as is. | |
1042 */ | |
1043 if (s->ret == XZ_STREAM_END) | |
1044 s->temp.filtered = s->temp.size; | |
1045 | |
1046 bcj_flush(s, b); | |
1047 if (s->temp.filtered > 0) | |
1048 return XZ_OK; | |
1049 } | |
1050 | |
1051 return s->ret; | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1052 } |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1053 |
851 | 1054 struct xz_dec_bcj *xz_dec_bcj_create(int single_call) |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1055 { |
855 | 1056 struct xz_dec_bcj *s = malloc(sizeof(*s)); |
1057 if (s != NULL) | |
1058 s->single_call = single_call; | |
1059 | |
1060 return s; | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1061 } |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1062 |
846
e02b4e932cd1
Some xzcat cleanup by Isaac Dunham.
Rob Landley <rob@landley.net>
parents:
819
diff
changeset
|
1063 enum xz_ret xz_dec_bcj_reset(struct xz_dec_bcj *s, uint8_t id) |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1064 { |
855 | 1065 switch (id) { |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1066 #ifdef XZ_DEC_X86 |
855 | 1067 case BCJ_X86: |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1068 #endif |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1069 #ifdef XZ_DEC_POWERPC |
855 | 1070 case BCJ_POWERPC: |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1071 #endif |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1072 #ifdef XZ_DEC_IA64 |
855 | 1073 case BCJ_IA64: |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1074 #endif |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1075 #ifdef XZ_DEC_ARM |
855 | 1076 case BCJ_ARM: |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1077 #endif |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1078 #ifdef XZ_DEC_ARMTHUMB |
855 | 1079 case BCJ_ARMTHUMB: |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1080 #endif |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1081 #ifdef XZ_DEC_SPARC |
855 | 1082 case BCJ_SPARC: |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1083 #endif |
855 | 1084 break; |
1085 | |
1086 default: | |
1087 /* Unsupported Filter ID */ | |
1088 return XZ_OPTIONS_ERROR; | |
1089 } | |
1090 | |
1091 s->type = id; | |
1092 s->ret = XZ_OK; | |
1093 s->pos = 0; | |
1094 s->x86_prev_mask = 0; | |
1095 s->temp.filtered = 0; | |
1096 s->temp.size = 0; | |
1097 | |
1098 return XZ_OK; | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1099 } |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1100 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1101 #endif |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1102 /* |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1103 * LZMA2 decoder |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1104 */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1105 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1106 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1107 // BEGIN xz_lzma2.h |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1108 /* |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1109 * LZMA2 definitions |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1110 * |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1111 */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1112 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1113 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1114 /* Range coder constants */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1115 #define RC_SHIFT_BITS 8 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1116 #define RC_TOP_BITS 24 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1117 #define RC_TOP_VALUE (1 << RC_TOP_BITS) |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1118 #define RC_BIT_MODEL_TOTAL_BITS 11 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1119 #define RC_BIT_MODEL_TOTAL (1 << RC_BIT_MODEL_TOTAL_BITS) |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1120 #define RC_MOVE_BITS 5 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1121 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1122 /* |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1123 * Maximum number of position states. A position state is the lowest pb |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1124 * number of bits of the current uncompressed offset. In some places there |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1125 * are different sets of probabilities for different position states. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1126 */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1127 #define POS_STATES_MAX (1 << 4) |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1128 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1129 /* |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1130 * This enum is used to track which LZMA symbols have occurred most recently |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1131 * and in which order. This information is used to predict the next symbol. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1132 * |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1133 * Symbols: |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1134 * - Literal: One 8-bit byte |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1135 * - Match: Repeat a chunk of data at some distance |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1136 * - Long repeat: Multi-byte match at a recently seen distance |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1137 * - Short repeat: One-byte repeat at a recently seen distance |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1138 * |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1139 * The symbol names are in from STATE_oldest_older_previous. REP means |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1140 * either short or long repeated match, and NONLIT means any non-literal. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1141 */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1142 enum lzma_state { |
855 | 1143 STATE_LIT_LIT, |
1144 STATE_MATCH_LIT_LIT, | |
1145 STATE_REP_LIT_LIT, | |
1146 STATE_SHORTREP_LIT_LIT, | |
1147 STATE_MATCH_LIT, | |
1148 STATE_REP_LIT, | |
1149 STATE_SHORTREP_LIT, | |
1150 STATE_LIT_MATCH, | |
1151 STATE_LIT_LONGREP, | |
1152 STATE_LIT_SHORTREP, | |
1153 STATE_NONLIT_MATCH, | |
1154 STATE_NONLIT_REP | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1155 }; |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1156 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1157 /* Total number of states */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1158 #define STATES 12 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1159 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1160 /* The lowest 7 states indicate that the previous state was a literal. */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1161 #define LIT_STATES 7 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1162 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1163 /* Indicate that the latest symbol was a literal. */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1164 static inline void lzma_state_literal(enum lzma_state *state) |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1165 { |
855 | 1166 if (*state <= STATE_SHORTREP_LIT_LIT) |
1167 *state = STATE_LIT_LIT; | |
1168 else if (*state <= STATE_LIT_SHORTREP) | |
1169 *state -= 3; | |
1170 else | |
1171 *state -= 6; | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1172 } |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1173 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1174 /* Indicate that the latest symbol was a match. */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1175 static inline void lzma_state_match(enum lzma_state *state) |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1176 { |
855 | 1177 *state = *state < LIT_STATES ? STATE_LIT_MATCH : STATE_NONLIT_MATCH; |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1178 } |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1179 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1180 /* Indicate that the latest state was a long repeated match. */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1181 static inline void lzma_state_long_rep(enum lzma_state *state) |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1182 { |
855 | 1183 *state = *state < LIT_STATES ? STATE_LIT_LONGREP : STATE_NONLIT_REP; |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1184 } |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1185 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1186 /* Indicate that the latest symbol was a short match. */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1187 static inline void lzma_state_short_rep(enum lzma_state *state) |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1188 { |
855 | 1189 *state = *state < LIT_STATES ? STATE_LIT_SHORTREP : STATE_NONLIT_REP; |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1190 } |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1191 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1192 /* Test if the previous symbol was a literal. */ |
851 | 1193 static inline int lzma_state_is_literal(enum lzma_state state) |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1194 { |
855 | 1195 return state < LIT_STATES; |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1196 } |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1197 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1198 /* Each literal coder is divided in three sections: |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1199 * - 0x001-0x0FF: Without match byte |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1200 * - 0x101-0x1FF: With match byte; match bit is 0 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1201 * - 0x201-0x2FF: With match byte; match bit is 1 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1202 * |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1203 * Match byte is used when the previous LZMA symbol was something else than |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1204 * a literal (that is, it was some kind of match). |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1205 */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1206 #define LITERAL_CODER_SIZE 0x300 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1207 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1208 /* Maximum number of literal coders */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1209 #define LITERAL_CODERS_MAX (1 << 4) |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1210 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1211 /* Minimum length of a match is two bytes. */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1212 #define MATCH_LEN_MIN 2 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1213 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1214 /* Match length is encoded with 4, 5, or 10 bits. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1215 * |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1216 * Length Bits |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1217 * 2-9 4 = Choice=0 + 3 bits |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1218 * 10-17 5 = Choice=1 + Choice2=0 + 3 bits |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1219 * 18-273 10 = Choice=1 + Choice2=1 + 8 bits |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1220 */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1221 #define LEN_LOW_BITS 3 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1222 #define LEN_LOW_SYMBOLS (1 << LEN_LOW_BITS) |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1223 #define LEN_MID_BITS 3 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1224 #define LEN_MID_SYMBOLS (1 << LEN_MID_BITS) |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1225 #define LEN_HIGH_BITS 8 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1226 #define LEN_HIGH_SYMBOLS (1 << LEN_HIGH_BITS) |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1227 #define LEN_SYMBOLS (LEN_LOW_SYMBOLS + LEN_MID_SYMBOLS + LEN_HIGH_SYMBOLS) |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1228 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1229 /* |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1230 * Maximum length of a match is 273 which is a result of the encoding |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1231 * described above. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1232 */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1233 #define MATCH_LEN_MAX (MATCH_LEN_MIN + LEN_SYMBOLS - 1) |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1234 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1235 /* |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1236 * Different sets of probabilities are used for match distances that have |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1237 * very short match length: Lengths of 2, 3, and 4 bytes have a separate |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1238 * set of probabilities for each length. The matches with longer length |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1239 * use a shared set of probabilities. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1240 */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1241 #define DIST_STATES 4 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1242 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1243 /* |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1244 * Get the index of the appropriate probability array for decoding |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1245 * the distance slot. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1246 */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1247 static inline uint32_t lzma_get_dist_state(uint32_t len) |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1248 { |
855 | 1249 return len < DIST_STATES + MATCH_LEN_MIN |
1250 ? len - MATCH_LEN_MIN : DIST_STATES - 1; | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1251 } |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1252 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1253 /* |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1254 * The highest two bits of a 32-bit match distance are encoded using six bits. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1255 * This six-bit value is called a distance slot. This way encoding a 32-bit |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1256 * value takes 6-36 bits, larger values taking more bits. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1257 */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1258 #define DIST_SLOT_BITS 6 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1259 #define DIST_SLOTS (1 << DIST_SLOT_BITS) |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1260 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1261 /* Match distances up to 127 are fully encoded using probabilities. Since |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1262 * the highest two bits (distance slot) are always encoded using six bits, |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1263 * the distances 0-3 don't need any additional bits to encode, since the |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1264 * distance slot itself is the same as the actual distance. DIST_MODEL_START |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1265 * indicates the first distance slot where at least one additional bit is |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1266 * needed. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1267 */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1268 #define DIST_MODEL_START 4 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1269 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1270 /* |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1271 * Match distances greater than 127 are encoded in three pieces: |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1272 * - distance slot: the highest two bits |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1273 * - direct bits: 2-26 bits below the highest two bits |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1274 * - alignment bits: four lowest bits |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1275 * |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1276 * Direct bits don't use any probabilities. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1277 * |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1278 * The distance slot value of 14 is for distances 128-191. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1279 */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1280 #define DIST_MODEL_END 14 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1281 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1282 /* Distance slots that indicate a distance <= 127. */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1283 #define FULL_DISTANCES_BITS (DIST_MODEL_END / 2) |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1284 #define FULL_DISTANCES (1 << FULL_DISTANCES_BITS) |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1285 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1286 /* |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1287 * For match distances greater than 127, only the highest two bits and the |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1288 * lowest four bits (alignment) is encoded using probabilities. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1289 */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1290 #define ALIGN_BITS 4 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1291 #define ALIGN_SIZE (1 << ALIGN_BITS) |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1292 #define ALIGN_MASK (ALIGN_SIZE - 1) |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1293 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1294 /* Total number of all probability variables */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1295 #define PROBS_TOTAL (1846 + LITERAL_CODERS_MAX * LITERAL_CODER_SIZE) |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1296 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1297 /* |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1298 * LZMA remembers the four most recent match distances. Reusing these |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1299 * distances tends to take less space than re-encoding the actual |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1300 * distance value. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1301 */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1302 #define REPS 4 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1303 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1304 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1305 // END xz_lzma2.h |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1306 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1307 /* |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1308 * Range decoder initialization eats the first five bytes of each LZMA chunk. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1309 */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1310 #define RC_INIT_BYTES 5 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1311 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1312 /* |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1313 * Minimum number of usable input buffer to safely decode one LZMA symbol. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1314 * The worst case is that we decode 22 bits using probabilities and 26 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1315 * direct bits. This may decode at maximum of 20 bytes of input. However, |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1316 * lzma_main() does an extra normalization before returning, thus we |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1317 * need to put 21 here. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1318 */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1319 #define LZMA_IN_REQUIRED 21 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1320 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1321 /* |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1322 * Dictionary (history buffer) |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1323 * |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1324 * These are always true: |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1325 * start <= pos <= full <= end |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1326 * pos <= limit <= end |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1327 * |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1328 * In multi-call mode, also these are true: |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1329 * end == size |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1330 * size <= size_max |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1331 * allocated <= size |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1332 * |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1333 * Most of these variables are size_t to support single-call mode, |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1334 * in which the dictionary variables address the actual output |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1335 * buffer directly. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1336 */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1337 struct dictionary { |
855 | 1338 /* Beginning of the history buffer */ |
1339 uint8_t *buf; | |
1340 | |
1341 /* Old position in buf (before decoding more data) */ | |
1342 size_t start; | |
1343 | |
1344 /* Position in buf */ | |
1345 size_t pos; | |
1346 | |
1347 /* | |
1348 * How full dictionary is. This is used to detect corrupt input that | |
1349 * would read beyond the beginning of the uncompressed stream. | |
1350 */ | |
1351 size_t full; | |
1352 | |
1353 /* Write limit; we don't write to buf[limit] or later bytes. */ | |
1354 size_t limit; | |
1355 | |
1356 /* | |
1357 * End of the dictionary buffer. In multi-call mode, this is | |
1358 * the same as the dictionary size. In single-call mode, this | |
1359 * indicates the size of the output buffer. | |
1360 */ | |
1361 size_t end; | |
1362 | |
1363 /* | |
1364 * Size of the dictionary as specified in Block Header. This is used | |
1365 * together with "full" to detect corrupt input that would make us | |
1366 * read beyond the beginning of the uncompressed stream. | |
1367 */ | |
1368 uint32_t size; | |
1369 | |
1370 /* | |
1371 * Maximum allowed dictionary size in multi-call mode. | |
1372 * This is ignored in single-call mode. | |
1373 */ | |
1374 uint32_t size_max; | |
1375 | |
1376 /* | |
1377 * Amount of memory currently allocated for the dictionary. | |
1378 * This is used only with XZ_DYNALLOC. (With XZ_PREALLOC, | |
1379 * size_max is always the same as the allocated size.) | |
1380 */ | |
1381 uint32_t allocated; | |
1382 | |
1383 /* Operation mode */ | |
1384 enum xz_mode mode; | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1385 }; |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1386 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1387 /* Range decoder */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1388 struct rc_dec { |
855 | 1389 uint32_t range; |
1390 uint32_t code; | |
1391 | |
1392 /* | |
1393 * Number of initializing bytes remaining to be read | |
1394 * by rc_read_init(). | |
1395 */ | |
1396 uint32_t init_bytes_left; | |
1397 | |
1398 /* | |
1399 * Buffer from which we read our input. It can be either | |
1400 * temp.buf or the caller-provided input buffer. | |
1401 */ | |
1402 const uint8_t *in; | |
1403 size_t in_pos; | |
1404 size_t in_limit; | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1405 }; |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1406 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1407 /* Probabilities for a length decoder. */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1408 struct lzma_len_dec { |
855 | 1409 /* Probability of match length being at least 10 */ |
1410 uint16_t choice; | |
1411 | |
1412 /* Probability of match length being at least 18 */ | |
1413 uint16_t choice2; | |
1414 | |
1415 /* Probabilities for match lengths 2-9 */ | |
1416 uint16_t low[POS_STATES_MAX][LEN_LOW_SYMBOLS]; | |
1417 | |
1418 /* Probabilities for match lengths 10-17 */ | |
1419 uint16_t mid[POS_STATES_MAX][LEN_MID_SYMBOLS]; | |
1420 | |
1421 /* Probabilities for match lengths 18-273 */ | |
1422 uint16_t high[LEN_HIGH_SYMBOLS]; | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1423 }; |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1424 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1425 struct lzma_dec { |
855 | 1426 /* Distances of latest four matches */ |
1427 uint32_t rep0; | |
1428 uint32_t rep1; | |
1429 uint32_t rep2; | |
1430 uint32_t rep3; | |
1431 | |
1432 /* Types of the most recently seen LZMA symbols */ | |
1433 enum lzma_state state; | |
1434 | |
1435 /* | |
1436 * Length of a match. This is updated so that dict_repeat can | |
1437 * be called again to finish repeating the whole match. | |
1438 */ | |
1439 uint32_t len; | |
1440 | |
1441 /* | |
1442 * LZMA properties or related bit masks (number of literal | |
1443 * context bits, a mask dervied from the number of literal | |
1444 * position bits, and a mask dervied from the number | |
1445 * position bits) | |
1446 */ | |
1447 uint32_t lc; | |
1448 uint32_t literal_pos_mask; /* (1 << lp) - 1 */ | |
1449 uint32_t pos_mask; /* (1 << pb) - 1 */ | |
1450 | |
1451 /* If 1, it's a match. Otherwise it's a single 8-bit literal. */ | |
1452 uint16_t is_match[STATES][POS_STATES_MAX]; | |
1453 | |
1454 /* If 1, it's a repeated match. The distance is one of rep0 .. rep3. */ | |
1455 uint16_t is_rep[STATES]; | |
1456 | |
1457 /* | |
1458 * If 0, distance of a repeated match is rep0. | |
1459 * Otherwise check is_rep1. | |
1460 */ | |
1461 uint16_t is_rep0[STATES]; | |
1462 | |
1463 /* | |
1464 * If 0, distance of a repeated match is rep1. | |
1465 * Otherwise check is_rep2. | |
1466 */ | |
1467 uint16_t is_rep1[STATES]; | |
1468 | |
1469 /* If 0, distance of a repeated match is rep2. Otherwise it is rep3. */ | |
1470 uint16_t is_rep2[STATES]; | |
1471 | |
1472 /* | |
1473 * If 1, the repeated match has length of one byte. Otherwise | |
1474 * the length is decoded from rep_len_decoder. | |
1475 */ | |
1476 uint16_t is_rep0_long[STATES][POS_STATES_MAX]; | |
1477 | |
1478 /* | |
1479 * Probability tree for the highest two bits of the match | |
1480 * distance. There is a separate probability tree for match | |
1481 * lengths of 2 (i.e. MATCH_LEN_MIN), 3, 4, and [5, 273]. | |
1482 */ | |
1483 uint16_t dist_slot[DIST_STATES][DIST_SLOTS]; | |
1484 | |
1485 /* | |
1486 * Probility trees for additional bits for match distance | |
1487 * when the distance is in the range [4, 127]. | |
1488 */ | |
1489 uint16_t dist_special[FULL_DISTANCES - DIST_MODEL_END]; | |
1490 | |
1491 /* | |
1492 * Probability tree for the lowest four bits of a match | |
1493 * distance that is equal to or greater than 128. | |
1494 */ | |
1495 uint16_t dist_align[ALIGN_SIZE]; | |
1496 | |
1497 /* Length of a normal match */ | |
1498 struct lzma_len_dec match_len_dec; | |
1499 | |
1500 /* Length of a repeated match */ | |
1501 struct lzma_len_dec rep_len_dec; | |
1502 | |
1503 /* Probabilities of literals */ | |
1504 uint16_t literal[LITERAL_CODERS_MAX][LITERAL_CODER_SIZE]; | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1505 }; |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1506 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1507 struct lzma2_dec { |
855 | 1508 /* Position in xz_dec_lzma2_run(). */ |
1509 enum lzma2_seq { | |
1510 SEQ_CONTROL, | |
1511 SEQ_UNCOMPRESSED_1, | |
1512 SEQ_UNCOMPRESSED_2, | |
1513 SEQ_COMPRESSED_0, | |
1514 SEQ_COMPRESSED_1, | |
1515 SEQ_PROPERTIES, | |
1516 SEQ_LZMA_PREPARE, | |
1517 SEQ_LZMA_RUN, | |
1518 SEQ_COPY | |
1519 } sequence; | |
1520 | |
1521 /* Next position after decoding the compressed size of the chunk. */ | |
1522 enum lzma2_seq next_sequence; | |
1523 | |
1524 /* Uncompressed size of LZMA chunk (2 MiB at maximum) */ | |
1525 uint32_t uncompressed; | |
1526 | |
1527 /* | |
1528 * Compressed size of LZMA chunk or compressed/uncompressed | |
1529 * size of uncompressed chunk (64 KiB at maximum) | |
1530 */ | |
1531 uint32_t compressed; | |
1532 | |
1533 /* | |
1534 * True if dictionary reset is needed. This is false before | |
1535 * the first chunk (LZMA or uncompressed). | |
1536 */ | |
1537 int need_dict_reset; | |
1538 | |
1539 /* | |
1540 * True if new LZMA properties are needed. This is false | |
1541 * before the first LZMA chunk. | |
1542 */ | |
1543 int need_props; | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1544 }; |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1545 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1546 struct xz_dec_lzma2 { |
855 | 1547 /* |
1548 * The order below is important on x86 to reduce code size and | |
1549 * it shouldn't hurt on other platforms. Everything up to and | |
1550 * including lzma.pos_mask are in the first 128 bytes on x86-32, | |
1551 * which allows using smaller instructions to access those | |
1552 * variables. On x86-64, fewer variables fit into the first 128 | |
1553 * bytes, but this is still the best order without sacrificing | |
1554 * the readability by splitting the structures. | |
1555 */ | |
1556 struct rc_dec rc; | |
1557 struct dictionary dict; | |
1558 struct lzma2_dec lzma2; | |
1559 struct lzma_dec lzma; | |
1560 | |
1561 /* | |
1562 * Temporary buffer which holds small number of input bytes between | |
1563 * decoder calls. See lzma2_lzma() for details. | |
1564 */ | |
1565 struct { | |
1566 uint32_t size; | |
1567 uint8_t buf[3 * LZMA_IN_REQUIRED]; | |
1568 } temp; | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1569 }; |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1570 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1571 /************** |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1572 * Dictionary * |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1573 **************/ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1574 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1575 /* |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1576 * Reset the dictionary state. When in single-call mode, set up the beginning |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1577 * of the dictionary to point to the actual output buffer. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1578 */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1579 static void dict_reset(struct dictionary *dict, struct xz_buf *b) |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1580 { |
855 | 1581 if (DEC_IS_SINGLE(dict->mode)) { |
1582 dict->buf = b->out + b->out_pos; | |
1583 dict->end = b->out_size - b->out_pos; | |
1584 } | |
1585 | |
1586 dict->start = 0; | |
1587 dict->pos = 0; | |
1588 dict->limit = 0; | |
1589 dict->full = 0; | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1590 } |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1591 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1592 /* Set dictionary write limit */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1593 static void dict_limit(struct dictionary *dict, size_t out_max) |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1594 { |
855 | 1595 if (dict->end - dict->pos <= out_max) |
1596 dict->limit = dict->end; | |
1597 else | |
1598 dict->limit = dict->pos + out_max; | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1599 } |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1600 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1601 /* Return true if at least one byte can be written into the dictionary. */ |
851 | 1602 static inline int dict_has_space(const struct dictionary *dict) |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1603 { |
855 | 1604 return dict->pos < dict->limit; |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1605 } |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1606 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1607 /* |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1608 * Get a byte from the dictionary at the given distance. The distance is |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1609 * assumed to valid, or as a special case, zero when the dictionary is |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1610 * still empty. This special case is needed for single-call decoding to |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1611 * avoid writing a '\0' to the end of the destination buffer. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1612 */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1613 static inline uint32_t dict_get(const struct dictionary *dict, uint32_t dist) |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1614 { |
855 | 1615 size_t offset = dict->pos - dist - 1; |
1616 | |
1617 if (dist >= dict->pos) | |
1618 offset += dict->end; | |
1619 | |
1620 return dict->full > 0 ? dict->buf[offset] : 0; | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1621 } |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1622 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1623 /* |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1624 * Put one byte into the dictionary. It is assumed that there is space for it. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1625 */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1626 static inline void dict_put(struct dictionary *dict, uint8_t byte) |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1627 { |
855 | 1628 dict->buf[dict->pos++] = byte; |
1629 | |
1630 if (dict->full < dict->pos) | |
1631 dict->full = dict->pos; | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1632 } |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1633 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1634 /* |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1635 * Repeat given number of bytes from the given distance. If the distance is |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1636 * invalid, false is returned. On success, true is returned and *len is |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1637 * updated to indicate how many bytes were left to be repeated. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1638 */ |
851 | 1639 static int dict_repeat(struct dictionary *dict, uint32_t *len, uint32_t dist) |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1640 { |
855 | 1641 size_t back; |
1642 uint32_t left; | |
1643 | |
1644 if (dist >= dict->full || dist >= dict->size) return 0; | |
1645 | |
1646 left = min_t(size_t, dict->limit - dict->pos, *len); | |
1647 *len -= left; | |
1648 | |
1649 back = dict->pos - dist - 1; | |
1650 if (dist >= dict->pos) | |
1651 back += dict->end; | |
1652 | |
1653 do { | |
1654 dict->buf[dict->pos++] = dict->buf[back++]; | |
1655 if (back == dict->end) | |
1656 back = 0; | |
1657 } while (--left > 0); | |
1658 | |
1659 if (dict->full < dict->pos) | |
1660 dict->full = dict->pos; | |
1661 | |
1662 return 1; | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1663 } |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1664 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1665 /* Copy uncompressed data as is from input to dictionary and output buffers. */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1666 static void dict_uncompressed(struct dictionary *dict, struct xz_buf *b, |
855 | 1667 uint32_t *left) |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1668 { |
855 | 1669 size_t copy_size; |
1670 | |
1671 while (*left > 0 && b->in_pos < b->in_size | |
1672 && b->out_pos < b->out_size) { | |
1673 copy_size = min(b->in_size - b->in_pos, | |
1674 b->out_size - b->out_pos); | |
1675 if (copy_size > dict->end - dict->pos) | |
1676 copy_size = dict->end - dict->pos; | |
1677 if (copy_size > *left) | |
1678 copy_size = *left; | |
1679 | |
1680 *left -= copy_size; | |
1681 | |
1682 memcpy(dict->buf + dict->pos, b->in + b->in_pos, copy_size); | |
1683 dict->pos += copy_size; | |
1684 | |
1685 if (dict->full < dict->pos) | |
1686 dict->full = dict->pos; | |
1687 | |
1688 if (DEC_IS_MULTI(dict->mode)) { | |
1689 if (dict->pos == dict->end) | |
1690 dict->pos = 0; | |
1691 | |
1692 memcpy(b->out + b->out_pos, b->in + b->in_pos, | |
1693 copy_size); | |
1694 } | |
1695 | |
1696 dict->start = dict->pos; | |
1697 | |
1698 b->out_pos += copy_size; | |
1699 b->in_pos += copy_size; | |
1700 } | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1701 } |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1702 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1703 /* |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1704 * Flush pending data from dictionary to b->out. It is assumed that there is |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1705 * enough space in b->out. This is guaranteed because caller uses dict_limit() |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1706 * before decoding data into the dictionary. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1707 */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1708 static uint32_t dict_flush(struct dictionary *dict, struct xz_buf *b) |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1709 { |
855 | 1710 size_t copy_size = dict->pos - dict->start; |
1711 | |
1712 if (DEC_IS_MULTI(dict->mode)) { | |
1713 if (dict->pos == dict->end) | |
1714 dict->pos = 0; | |
1715 | |
1716 memcpy(b->out + b->out_pos, dict->buf + dict->start, | |
1717 copy_size); | |
1718 } | |
1719 | |
1720 dict->start = dict->pos; | |
1721 b->out_pos += copy_size; | |
1722 return copy_size; | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1723 } |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1724 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1725 /***************** |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1726 * Range decoder * |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1727 *****************/ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1728 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1729 /* Reset the range decoder. */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1730 static void rc_reset(struct rc_dec *rc) |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1731 { |
855 | 1732 rc->range = (uint32_t)-1; |
1733 rc->code = 0; | |
1734 rc->init_bytes_left = RC_INIT_BYTES; | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1735 } |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1736 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1737 /* |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1738 * Read the first five initial bytes into rc->code if they haven't been |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1739 * read already. (Yes, the first byte gets completely ignored.) |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1740 */ |
851 | 1741 static int rc_read_init(struct rc_dec *rc, struct xz_buf *b) |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1742 { |
855 | 1743 while (rc->init_bytes_left > 0) { |
1744 if (b->in_pos == b->in_size) return 0; | |
1745 | |
1746 rc->code = (rc->code << 8) + b->in[b->in_pos++]; | |
1747 --rc->init_bytes_left; | |
1748 } | |
1749 | |
1750 return 1; | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1751 } |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1752 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1753 /* Return true if there may not be enough input for the next decoding loop. */ |
851 | 1754 static inline int rc_limit_exceeded(const struct rc_dec *rc) |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1755 { |
855 | 1756 return rc->in_pos > rc->in_limit; |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1757 } |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1758 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1759 /* |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1760 * Return true if it is possible (from point of view of range decoder) that |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1761 * we have reached the end of the LZMA chunk. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1762 */ |
851 | 1763 static inline int rc_is_finished(const struct rc_dec *rc) |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1764 { |
855 | 1765 return rc->code == 0; |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1766 } |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1767 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1768 /* Read the next input byte if needed. */ |
854
68cdd244f8b1
xzcat: more cleanup and some shrinking.
Isaac Dunham <idunham@lavabit.com>
parents:
851
diff
changeset
|
1769 static inline void rc_normalize(struct rc_dec *rc) |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1770 { |
855 | 1771 if (rc->range < RC_TOP_VALUE) { |
1772 rc->range <<= RC_SHIFT_BITS; | |
1773 rc->code = (rc->code << RC_SHIFT_BITS) + rc->in[rc->in_pos++]; | |
1774 } | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1775 } |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1776 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1777 /* |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1778 * Decode one bit. In some versions, this function has been splitted in three |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1779 * functions so that the compiler is supposed to be able to more easily avoid |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1780 * an extra branch. In this particular version of the LZMA decoder, this |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1781 * doesn't seem to be a good idea (tested with GCC 3.3.6, 3.4.6, and 4.3.3 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1782 * on x86). Using a non-splitted version results in nicer looking code too. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1783 * |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1784 * NOTE: This must return an int. Do not make it return a bool or the speed |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1785 * of the code generated by GCC 3.x decreases 10-15 %. (GCC 4.3 doesn't care, |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1786 * and it generates 10-20 % faster code than GCC 3.x from this file anyway.) |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1787 */ |
854
68cdd244f8b1
xzcat: more cleanup and some shrinking.
Isaac Dunham <idunham@lavabit.com>
parents:
851
diff
changeset
|
1788 static inline int rc_bit(struct rc_dec *rc, uint16_t *prob) |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1789 { |
855 | 1790 uint32_t bound; |
1791 int bit; | |
1792 | |
1793 rc_normalize(rc); | |
1794 bound = (rc->range >> RC_BIT_MODEL_TOTAL_BITS) * *prob; | |
1795 if (rc->code < bound) { | |
1796 rc->range = bound; | |
1797 *prob += (RC_BIT_MODEL_TOTAL - *prob) >> RC_MOVE_BITS; | |
1798 bit = 0; | |
1799 } else { | |
1800 rc->range -= bound; | |
1801 rc->code -= bound; | |
1802 *prob -= *prob >> RC_MOVE_BITS; | |
1803 bit = 1; | |
1804 } | |
1805 | |
1806 return bit; | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1807 } |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1808 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1809 /* Decode a bittree starting from the most significant bit. */ |
854
68cdd244f8b1
xzcat: more cleanup and some shrinking.
Isaac Dunham <idunham@lavabit.com>
parents:
851
diff
changeset
|
1810 static inline uint32_t rc_bittree(struct rc_dec *rc, |
855 | 1811 uint16_t *probs, uint32_t limit) |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1812 { |
855 | 1813 uint32_t symbol = 1; |
1814 | |
1815 do { | |
1816 if (rc_bit(rc, &probs[symbol])) | |
1817 symbol = (symbol << 1) + 1; | |
1818 else | |
1819 symbol <<= 1; | |
1820 } while (symbol < limit); | |
1821 | |
1822 return symbol; | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1823 } |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1824 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1825 /* Decode a bittree starting from the least significant bit. */ |
854
68cdd244f8b1
xzcat: more cleanup and some shrinking.
Isaac Dunham <idunham@lavabit.com>
parents:
851
diff
changeset
|
1826 static inline void rc_bittree_reverse(struct rc_dec *rc, |
855 | 1827 uint16_t *probs, |
1828 uint32_t *dest, uint32_t limit) | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1829 { |
855 | 1830 uint32_t symbol = 1; |
1831 uint32_t i = 0; | |
1832 | |
1833 do { | |
1834 if (rc_bit(rc, &probs[symbol])) { | |
1835 symbol = (symbol << 1) + 1; | |
1836 *dest += 1 << i; | |
1837 } else { | |
1838 symbol <<= 1; | |
1839 } | |
1840 } while (++i < limit); | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1841 } |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1842 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1843 /* Decode direct bits (fixed fifty-fifty probability) */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1844 static inline void rc_direct(struct rc_dec *rc, uint32_t *dest, uint32_t limit) |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1845 { |
855 | 1846 uint32_t mask; |
1847 | |
1848 do { | |
1849 rc_normalize(rc); | |
1850 rc->range >>= 1; | |
1851 rc->code -= rc->range; | |
1852 mask = (uint32_t)0 - (rc->code >> 31); | |
1853 rc->code += rc->range & mask; | |
1854 *dest = (*dest << 1) + (mask + 1); | |
1855 } while (--limit > 0); | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1856 } |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1857 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1858 /******** |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1859 * LZMA * |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1860 ********/ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1861 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1862 /* Get pointer to literal coder probability array. */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1863 static uint16_t *lzma_literal_probs(struct xz_dec_lzma2 *s) |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1864 { |
855 | 1865 uint32_t prev_byte = dict_get(&s->dict, 0); |
1866 uint32_t low = prev_byte >> (8 - s->lzma.lc); | |
1867 uint32_t high = (s->dict.pos & s->lzma.literal_pos_mask) << s->lzma.lc; | |
1868 return s->lzma.literal[low + high]; | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1869 } |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1870 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1871 /* Decode a literal (one 8-bit byte) */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1872 static void lzma_literal(struct xz_dec_lzma2 *s) |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1873 { |
855 | 1874 uint16_t *probs; |
1875 uint32_t symbol; | |
1876 uint32_t match_byte; | |
1877 uint32_t match_bit; | |
1878 uint32_t offset; | |
1879 uint32_t i; | |
1880 | |
1881 probs = lzma_literal_probs(s); | |
1882 | |
1883 if (lzma_state_is_literal(s->lzma.state)) { | |
1884 symbol = rc_bittree(&s->rc, probs, 0x100); | |
1885 } else { | |
1886 symbol = 1; | |
1887 match_byte = dict_get(&s->dict, s->lzma.rep0) << 1; | |
1888 offset = 0x100; | |
1889 | |
1890 do { | |
1891 match_bit = match_byte & offset; | |
1892 match_byte <<= 1; | |
1893 i = offset + match_bit + symbol; | |
1894 | |
1895 if (rc_bit(&s->rc, &probs[i])) { | |
1896 symbol = (symbol << 1) + 1; | |
1897 offset &= match_bit; | |
1898 } else { | |
1899 symbol <<= 1; | |
1900 offset &= ~match_bit; | |
1901 } | |
1902 } while (symbol < 0x100); | |
1903 } | |
1904 | |
1905 dict_put(&s->dict, (uint8_t)symbol); | |
1906 lzma_state_literal(&s->lzma.state); | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1907 } |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1908 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1909 /* Decode the length of the match into s->lzma.len. */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1910 static void lzma_len(struct xz_dec_lzma2 *s, struct lzma_len_dec *l, |
855 | 1911 uint32_t pos_state) |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1912 { |
855 | 1913 uint16_t *probs; |
1914 uint32_t limit; | |
1915 | |
1916 if (!rc_bit(&s->rc, &l->choice)) { | |
1917 probs = l->low[pos_state]; | |
1918 limit = LEN_LOW_SYMBOLS; | |
1919 s->lzma.len = MATCH_LEN_MIN; | |
1920 } else { | |
1921 if (!rc_bit(&s->rc, &l->choice2)) { | |
1922 probs = l->mid[pos_state]; | |
1923 limit = LEN_MID_SYMBOLS; | |
1924 s->lzma.len = MATCH_LEN_MIN + LEN_LOW_SYMBOLS; | |
1925 } else { | |
1926 probs = l->high; | |
1927 limit = LEN_HIGH_SYMBOLS; | |
1928 s->lzma.len = MATCH_LEN_MIN + LEN_LOW_SYMBOLS | |
1929 + LEN_MID_SYMBOLS; | |
1930 } | |
1931 } | |
1932 | |
1933 s->lzma.len += rc_bittree(&s->rc, probs, limit) - limit; | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1934 } |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1935 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1936 /* Decode a match. The distance will be stored in s->lzma.rep0. */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1937 static void lzma_match(struct xz_dec_lzma2 *s, uint32_t pos_state) |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1938 { |
855 | 1939 uint16_t *probs; |
1940 uint32_t dist_slot; | |
1941 uint32_t limit; | |
1942 | |
1943 lzma_state_match(&s->lzma.state); | |
1944 | |
1945 s->lzma.rep3 = s->lzma.rep2; | |
1946 s->lzma.rep2 = s->lzma.rep1; | |
1947 s->lzma.rep1 = s->lzma.rep0; | |
1948 | |
1949 lzma_len(s, &s->lzma.match_len_dec, pos_state); | |
1950 | |
1951 probs = s->lzma.dist_slot[lzma_get_dist_state(s->lzma.len)]; | |
1952 dist_slot = rc_bittree(&s->rc, probs, DIST_SLOTS) - DIST_SLOTS; | |
1953 | |
1954 if (dist_slot < DIST_MODEL_START) { | |
1955 s->lzma.rep0 = dist_slot; | |
1956 } else { | |
1957 limit = (dist_slot >> 1) - 1; | |
1958 s->lzma.rep0 = 2 + (dist_slot & 1); | |
1959 | |
1960 if (dist_slot < DIST_MODEL_END) { | |
1961 s->lzma.rep0 <<= limit; | |
1962 probs = s->lzma.dist_special + s->lzma.rep0 | |
1963 - dist_slot - 1; | |
1964 rc_bittree_reverse(&s->rc, probs, | |
1965 &s->lzma.rep0, limit); | |
1966 } else { | |
1967 rc_direct(&s->rc, &s->lzma.rep0, limit - ALIGN_BITS); | |
1968 s->lzma.rep0 <<= ALIGN_BITS; | |
1969 rc_bittree_reverse(&s->rc, s->lzma.dist_align, | |
1970 &s->lzma.rep0, ALIGN_BITS); | |
1971 } | |
1972 } | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1973 } |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1974 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1975 /* |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1976 * Decode a repeated match. The distance is one of the four most recently |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1977 * seen matches. The distance will be stored in s->lzma.rep0. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1978 */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1979 static void lzma_rep_match(struct xz_dec_lzma2 *s, uint32_t pos_state) |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1980 { |
855 | 1981 uint32_t tmp; |
1982 | |
1983 if (!rc_bit(&s->rc, &s->lzma.is_rep0[s->lzma.state])) { | |
1984 if (!rc_bit(&s->rc, &s->lzma.is_rep0_long[ | |
1985 s->lzma.state][pos_state])) { | |
1986 lzma_state_short_rep(&s->lzma.state); | |
1987 s->lzma.len = 1; | |
1988 return; | |
1989 } | |
1990 } else { | |
1991 if (!rc_bit(&s->rc, &s->lzma.is_rep1[s->lzma.state])) { | |
1992 tmp = s->lzma.rep1; | |
1993 } else { | |
1994 if (!rc_bit(&s->rc, &s->lzma.is_rep2[s->lzma.state])) { | |
1995 tmp = s->lzma.rep2; | |
1996 } else { | |
1997 tmp = s->lzma.rep3; | |
1998 s->lzma.rep3 = s->lzma.rep2; | |
1999 } | |
2000 | |
2001 s->lzma.rep2 = s->lzma.rep1; | |
2002 } | |
2003 | |
2004 s->lzma.rep1 = s->lzma.rep0; | |
2005 s->lzma.rep0 = tmp; | |
2006 } | |
2007 | |
2008 lzma_state_long_rep(&s->lzma.state); | |
2009 lzma_len(s, &s->lzma.rep_len_dec, pos_state); | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2010 } |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2011 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2012 /* LZMA decoder core */ |
851 | 2013 static int lzma_main(struct xz_dec_lzma2 *s) |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2014 { |
855 | 2015 uint32_t pos_state; |
2016 | |
2017 /* | |
2018 * If the dictionary was reached during the previous call, try to | |
2019 * finish the possibly pending repeat in the dictionary. | |
2020 */ | |
2021 if (dict_has_space(&s->dict) && s->lzma.len > 0) | |
2022 dict_repeat(&s->dict, &s->lzma.len, s->lzma.rep0); | |
2023 | |
2024 /* | |
2025 * Decode more LZMA symbols. One iteration may consume up to | |
2026 * LZMA_IN_REQUIRED - 1 bytes. | |
2027 */ | |
2028 while (dict_has_space(&s->dict) && !rc_limit_exceeded(&s->rc)) { | |
2029 pos_state = s->dict.pos & s->lzma.pos_mask; | |
2030 | |
2031 if (!rc_bit(&s->rc, &s->lzma.is_match[ | |
2032 s->lzma.state][pos_state])) { | |
2033 lzma_literal(s); | |
2034 } else { | |
2035 if (rc_bit(&s->rc, &s->lzma.is_rep[s->lzma.state])) | |
2036 lzma_rep_match(s, pos_state); | |
2037 else | |
2038 lzma_match(s, pos_state); | |
2039 | |
2040 if (!dict_repeat(&s->dict, &s->lzma.len, s->lzma.rep0)) | |
2041 return 0; | |
2042 } | |
2043 } | |
2044 | |
2045 /* | |
2046 * Having the range decoder always normalized when we are outside | |
2047 * this function makes it easier to correctly handle end of the chunk. | |
2048 */ | |
2049 rc_normalize(&s->rc); | |
2050 | |
2051 return 1; | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2052 } |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2053 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2054 /* |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2055 * Reset the LZMA decoder and range decoder state. Dictionary is nore reset |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2056 * here, because LZMA state may be reset without resetting the dictionary. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2057 */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2058 static void lzma_reset(struct xz_dec_lzma2 *s) |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2059 { |
855 | 2060 uint16_t *probs; |
2061 size_t i; | |
2062 | |
2063 s->lzma.state = STATE_LIT_LIT; | |
2064 s->lzma.rep0 = 0; | |
2065 s->lzma.rep1 = 0; | |
2066 s->lzma.rep2 = 0; | |
2067 s->lzma.rep3 = 0; | |
2068 | |
2069 /* | |
2070 * All probabilities are initialized to the same value. This hack | |
2071 * makes the code smaller by avoiding a separate loop for each | |
2072 * probability array. | |
2073 * | |
2074 * This could be optimized so that only that part of literal | |
2075 * probabilities that are actually required. In the common case | |
2076 * we would write 12 KiB less. | |
2077 */ | |
2078 probs = s->lzma.is_match[0]; | |
2079 for (i = 0; i < PROBS_TOTAL; ++i) | |
2080 probs[i] = RC_BIT_MODEL_TOTAL / 2; | |
2081 | |
2082 rc_reset(&s->rc); | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2083 } |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2084 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2085 /* |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2086 * Decode and validate LZMA properties (lc/lp/pb) and calculate the bit masks |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2087 * from the decoded lp and pb values. On success, the LZMA decoder state is |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2088 * reset and true is returned. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2089 */ |
851 | 2090 static int lzma_props(struct xz_dec_lzma2 *s, uint8_t props) |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2091 { |
855 | 2092 if (props > (4 * 5 + 4) * 9 + 8) |
2093 return 0; | |
2094 | |
2095 s->lzma.pos_mask = 0; | |
2096 while (props >= 9 * 5) { | |
2097 props -= 9 * 5; | |
2098 ++s->lzma.pos_mask; | |
2099 } | |
2100 | |
2101 s->lzma.pos_mask = (1 << s->lzma.pos_mask) - 1; | |
2102 | |
2103 s->lzma.literal_pos_mask = 0; | |
2104 while (props >= 9) { | |
2105 props -= 9; | |
2106 ++s->lzma.literal_pos_mask; | |
2107 } | |
2108 | |
2109 s->lzma.lc = props; | |
2110 | |
2111 if (s->lzma.lc + s->lzma.literal_pos_mask > 4) | |
2112 return 0; | |
2113 | |
2114 s->lzma.literal_pos_mask = (1 << s->lzma.literal_pos_mask) - 1; | |
2115 | |
2116 lzma_reset(s); | |
2117 | |
2118 return 1; | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2119 } |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2120 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2121 /********* |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2122 * LZMA2 * |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2123 *********/ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2124 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2125 /* |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2126 * The LZMA decoder assumes that if the input limit (s->rc.in_limit) hasn't |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2127 * been exceeded, it is safe to read up to LZMA_IN_REQUIRED bytes. This |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2128 * wrapper function takes care of making the LZMA decoder's assumption safe. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2129 * |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2130 * As long as there is plenty of input left to be decoded in the current LZMA |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2131 * chunk, we decode directly from the caller-supplied input buffer until |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2132 * there's LZMA_IN_REQUIRED bytes left. Those remaining bytes are copied into |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2133 * s->temp.buf, which (hopefully) gets filled on the next call to this |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2134 * function. We decode a few bytes from the temporary buffer so that we can |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2135 * continue decoding from the caller-supplied input buffer again. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2136 */ |
851 | 2137 static int lzma2_lzma(struct xz_dec_lzma2 *s, struct xz_buf *b) |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2138 { |
855 | 2139 size_t in_avail; |
2140 uint32_t tmp; | |
2141 | |
2142 in_avail = b->in_size - b->in_pos; | |
2143 if (s->temp.size > 0 || s->lzma2.compressed == 0) { | |
2144 tmp = 2 * LZMA_IN_REQUIRED - s->temp.size; | |
2145 if (tmp > s->lzma2.compressed - s->temp.size) | |
2146 tmp = s->lzma2.compressed - s->temp.size; | |
2147 if (tmp > in_avail) | |
2148 tmp = in_avail; | |
2149 | |
2150 memcpy(s->temp.buf + s->temp.size, b->in + b->in_pos, tmp); | |
2151 | |
2152 if (s->temp.size + tmp == s->lzma2.compressed) { | |
2153 memset(s->temp.buf + s->temp.size + tmp, 0, | |
2154 sizeof(s->temp.buf) | |
2155 - s->temp.size - tmp); | |
2156 s->rc.in_limit = s->temp.size + tmp; | |
2157 } else if (s->temp.size + tmp < LZMA_IN_REQUIRED) { | |
2158 s->temp.size += tmp; | |
2159 b->in_pos += tmp; | |
2160 return 1; | |
2161 } else { | |
2162 s->rc.in_limit = s->temp.size + tmp - LZMA_IN_REQUIRED; | |
2163 } | |
2164 | |
2165 s->rc.in = s->temp.buf; | |
2166 s->rc.in_pos = 0; | |
2167 | |
2168 if (!lzma_main(s) || s->rc.in_pos > s->temp.size + tmp) | |
2169 return 0; | |
2170 | |
2171 s->lzma2.compressed -= s->rc.in_pos; | |
2172 | |
2173 if (s->rc.in_pos < s->temp.size) { | |
2174 s->temp.size -= s->rc.in_pos; | |
2175 memmove(s->temp.buf, s->temp.buf + s->rc.in_pos, | |
2176 s->temp.size); | |
2177 return 1; | |
2178 } | |
2179 | |
2180 b->in_pos += s->rc.in_pos - s->temp.size; | |
2181 s->temp.size = 0; | |
2182 } | |
2183 | |
2184 in_avail = b->in_size - b->in_pos; | |
2185 if (in_avail >= LZMA_IN_REQUIRED) { | |
2186 s->rc.in = b->in; | |
2187 s->rc.in_pos = b->in_pos; | |
2188 | |
2189 if (in_avail >= s->lzma2.compressed + LZMA_IN_REQUIRED) | |
2190 s->rc.in_limit = b->in_pos + s->lzma2.compressed; | |
2191 else | |
2192 s->rc.in_limit = b->in_size - LZMA_IN_REQUIRED; | |
2193 | |
2194 if (!lzma_main(s)) | |
2195 return 0; | |
2196 | |
2197 in_avail = s->rc.in_pos - b->in_pos; | |
2198 if (in_avail > s->lzma2.compressed) return 0; | |
2199 | |
2200 s->lzma2.compressed -= in_avail; | |
2201 b->in_pos = s->rc.in_pos; | |
2202 } | |
2203 | |
2204 in_avail = b->in_size - b->in_pos; | |
2205 if (in_avail < LZMA_IN_REQUIRED) { | |
2206 if (in_avail > s->lzma2.compressed) | |
2207 in_avail = s->lzma2.compressed; | |
2208 | |
2209 memcpy(s->temp.buf, b->in + b->in_pos, in_avail); | |
2210 s->temp.size = in_avail; | |
2211 b->in_pos += in_avail; | |
2212 } | |
2213 | |
2214 return 1; | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2215 } |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2216 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2217 /* |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2218 * Take care of the LZMA2 control layer, and forward the job of actual LZMA |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2219 * decoding or copying of uncompressed chunks to other functions. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2220 */ |
846
e02b4e932cd1
Some xzcat cleanup by Isaac Dunham.
Rob Landley <rob@landley.net>
parents:
819
diff
changeset
|
2221 enum xz_ret xz_dec_lzma2_run(struct xz_dec_lzma2 *s, |
855 | 2222 struct xz_buf *b) |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2223 { |
855 | 2224 uint32_t tmp; |
2225 | |
2226 while (b->in_pos < b->in_size || s->lzma2.sequence == SEQ_LZMA_RUN) { | |
2227 switch (s->lzma2.sequence) { | |
2228 case SEQ_CONTROL: | |
2229 /* | |
2230 * LZMA2 control byte | |
2231 * | |
2232 * Exact values: | |
2233 * 0x00 End marker | |
2234 * 0x01 Dictionary reset followed by | |
2235 * an uncompressed chunk | |
2236 * 0x02 Uncompressed chunk (no dictionary reset) | |
2237 * | |
2238 * Highest three bits (s->control & 0xE0): | |
2239 * 0xE0 Dictionary reset, new properties and state | |
2240 * reset, followed by LZMA compressed chunk | |
2241 * 0xC0 New properties and state reset, followed | |
2242 * by LZMA compressed chunk (no dictionary | |
2243 * reset) | |
2244 * 0xA0 State reset using old properties, | |
2245 * followed by LZMA compressed chunk (no | |
2246 * dictionary reset) | |
2247 * 0x80 LZMA chunk (no dictionary or state reset) | |
2248 * | |
2249 * For LZMA compressed chunks, the lowest five bits | |
2250 * (s->control & 1F) are the highest bits of the | |
2251 * uncompressed size (bits 16-20). | |
2252 * | |
2253 * A new LZMA2 stream must begin with a dictionary | |
2254 * reset. The first LZMA chunk must set new | |
2255 * properties and reset the LZMA state. | |
2256 * | |
2257 * Values that don't match anything described above | |
2258 * are invalid and we return XZ_DATA_ERROR. | |
2259 */ | |
2260 tmp = b->in[b->in_pos++]; | |
2261 | |
2262 if (tmp == 0x00) | |
2263 return XZ_STREAM_END; | |
2264 | |
2265 if (tmp >= 0xE0 || tmp == 0x01) { | |
2266 s->lzma2.need_props = 1; | |
2267 s->lzma2.need_dict_reset = 0; | |
2268 dict_reset(&s->dict, b); | |
2269 } else if (s->lzma2.need_dict_reset) { | |
2270 return XZ_DATA_ERROR; | |
2271 } | |
2272 | |
2273 if (tmp >= 0x80) { | |
2274 s->lzma2.uncompressed = (tmp & 0x1F) << 16; | |
2275 s->lzma2.sequence = SEQ_UNCOMPRESSED_1; | |
2276 | |
2277 if (tmp >= 0xC0) { | |
2278 /* | |
2279 * When there are new properties, | |
2280 * state reset is done at | |
2281 * SEQ_PROPERTIES. | |
2282 */ | |
2283 s->lzma2.need_props = 0; | |
2284 s->lzma2.next_sequence | |
2285 = SEQ_PROPERTIES; | |
2286 | |
2287 } else if (s->lzma2.need_props) { | |
2288 return XZ_DATA_ERROR; | |
2289 | |
2290 } else { | |
2291 s->lzma2.next_sequence | |
2292 = SEQ_LZMA_PREPARE; | |
2293 if (tmp >= 0xA0) | |
2294 lzma_reset(s); | |
2295 } | |
2296 } else { | |
2297 if (tmp > 0x02) | |
2298 return XZ_DATA_ERROR; | |
2299 | |
2300 s->lzma2.sequence = SEQ_COMPRESSED_0; | |
2301 s->lzma2.next_sequence = SEQ_COPY; | |
2302 } | |
2303 | |
2304 break; | |
2305 | |
2306 case SEQ_UNCOMPRESSED_1: | |
2307 s->lzma2.uncompressed | |
2308 += (uint32_t)b->in[b->in_pos++] << 8; | |
2309 s->lzma2.sequence = SEQ_UNCOMPRESSED_2; | |
2310 break; | |
2311 | |
2312 case SEQ_UNCOMPRESSED_2: | |
2313 s->lzma2.uncompressed | |
2314 += (uint32_t)b->in[b->in_pos++] + 1; | |
2315 s->lzma2.sequence = SEQ_COMPRESSED_0; | |
2316 break; | |
2317 | |
2318 case SEQ_COMPRESSED_0: | |
2319 s->lzma2.compressed | |
2320 = (uint32_t)b->in[b->in_pos++] << 8; | |
2321 s->lzma2.sequence = SEQ_COMPRESSED_1; | |
2322 break; | |
2323 | |
2324 case SEQ_COMPRESSED_1: | |
2325 s->lzma2.compressed | |
2326 += (uint32_t)b->in[b->in_pos++] + 1; | |
2327 s->lzma2.sequence = s->lzma2.next_sequence; | |
2328 break; | |
2329 | |
2330 case SEQ_PROPERTIES: | |
2331 if (!lzma_props(s, b->in[b->in_pos++])) | |
2332 return XZ_DATA_ERROR; | |
2333 | |
2334 s->lzma2.sequence = SEQ_LZMA_PREPARE; | |
2335 | |
2336 case SEQ_LZMA_PREPARE: | |
2337 if (s->lzma2.compressed < RC_INIT_BYTES) | |
2338 return XZ_DATA_ERROR; | |
2339 | |
2340 if (!rc_read_init(&s->rc, b)) | |
2341 return XZ_OK; | |
2342 | |
2343 s->lzma2.compressed -= RC_INIT_BYTES; | |
2344 s->lzma2.sequence = SEQ_LZMA_RUN; | |
2345 | |
2346 case SEQ_LZMA_RUN: | |
2347 /* | |
2348 * Set dictionary limit to indicate how much we want | |
2349 * to be encoded at maximum. Decode new data into the | |
2350 * dictionary. Flush the new data from dictionary to | |
2351 * b->out. Check if we finished decoding this chunk. | |
2352 * In case the dictionary got full but we didn't fill | |
2353 * the output buffer yet, we may run this loop | |
2354 * multiple times without changing s->lzma2.sequence. | |
2355 */ | |
2356 dict_limit(&s->dict, min_t(size_t, | |
2357 b->out_size - b->out_pos, | |
2358 s->lzma2.uncompressed)); | |
2359 if (!lzma2_lzma(s, b)) | |
2360 return XZ_DATA_ERROR; | |
2361 | |
2362 s->lzma2.uncompressed -= dict_flush(&s->dict, b); | |
2363 | |
2364 if (s->lzma2.uncompressed == 0) { | |
2365 if (s->lzma2.compressed > 0 || s->lzma.len > 0 | |
2366 || !rc_is_finished(&s->rc)) | |
2367 return XZ_DATA_ERROR; | |
2368 | |
2369 rc_reset(&s->rc); | |
2370 s->lzma2.sequence = SEQ_CONTROL; | |
2371 | |
2372 } else if (b->out_pos == b->out_size | |
2373 || (b->in_pos == b->in_size | |
2374 && s->temp.size | |
2375 < s->lzma2.compressed)) { | |
2376 return XZ_OK; | |
2377 } | |
2378 | |
2379 break; | |
2380 | |
2381 case SEQ_COPY: | |
2382 dict_uncompressed(&s->dict, b, &s->lzma2.compressed); | |
2383 if (s->lzma2.compressed > 0) | |
2384 return XZ_OK; | |
2385 | |
2386 s->lzma2.sequence = SEQ_CONTROL; | |
2387 break; | |
2388 } | |
2389 } | |
2390 | |
2391 return XZ_OK; | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2392 } |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2393 |
846
e02b4e932cd1
Some xzcat cleanup by Isaac Dunham.
Rob Landley <rob@landley.net>
parents:
819
diff
changeset
|
2394 struct xz_dec_lzma2 *xz_dec_lzma2_create(enum xz_mode mode, |
855 | 2395 uint32_t dict_max) |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2396 { |
855 | 2397 struct xz_dec_lzma2 *s = malloc(sizeof(*s)); |
2398 if (s == NULL) | |
2399 return NULL; | |
2400 | |
2401 s->dict.mode = mode; | |
2402 s->dict.size_max = dict_max; | |
2403 | |
2404 if (DEC_IS_PREALLOC(mode)) { | |
2405 s->dict.buf = malloc(dict_max); | |
2406 if (s->dict.buf == NULL) { | |
2407 free(s); | |
2408 return NULL; | |
2409 } | |
2410 } else if (DEC_IS_DYNALLOC(mode)) { | |
2411 s->dict.buf = NULL; | |
2412 s->dict.allocated = 0; | |
2413 } | |
2414 | |
2415 return s; | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2416 } |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2417 |
846
e02b4e932cd1
Some xzcat cleanup by Isaac Dunham.
Rob Landley <rob@landley.net>
parents:
819
diff
changeset
|
2418 enum xz_ret xz_dec_lzma2_reset(struct xz_dec_lzma2 *s, uint8_t props) |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2419 { |
855 | 2420 /* This limits dictionary size to 3 GiB to keep parsing simpler. */ |
2421 if (props > 39) | |
2422 return XZ_OPTIONS_ERROR; | |
2423 | |
2424 s->dict.size = 2 + (props & 1); | |
2425 s->dict.size <<= (props >> 1) + 11; | |
2426 | |
2427 if (DEC_IS_MULTI(s->dict.mode)) { | |
2428 if (s->dict.size > s->dict.size_max) | |
2429 return XZ_MEMLIMIT_ERROR; | |
2430 | |
2431 s->dict.end = s->dict.size; | |
2432 | |
2433 if (DEC_IS_DYNALLOC(s->dict.mode)) { | |
2434 if (s->dict.allocated < s->dict.size) { | |
2435 free(s->dict.buf); | |
2436 s->dict.buf = malloc(s->dict.size); | |
2437 if (s->dict.buf == NULL) { | |
2438 s->dict.allocated = 0; | |
2439 return XZ_MEM_ERROR; | |
2440 } | |
2441 } | |
2442 } | |
2443 } | |
2444 | |
2445 s->lzma.len = 0; | |
2446 | |
2447 s->lzma2.sequence = SEQ_CONTROL; | |
2448 s->lzma2.need_dict_reset = 1; | |
2449 | |
2450 s->temp.size = 0; | |
2451 | |
2452 return XZ_OK; | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2453 } |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2454 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2455 /* |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2456 * .xz Stream decoder |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2457 */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2458 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2459 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2460 // BEGIN xz_stream.h |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2461 /* |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2462 * Definitions for handling the .xz file format |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2463 */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2464 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2465 /* |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2466 * See the .xz file format specification at |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2467 * http://tukaani.org/xz/xz-file-format.txt |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2468 * to understand the container format. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2469 */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2470 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2471 #define STREAM_HEADER_SIZE 12 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2472 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2473 #define HEADER_MAGIC "\3757zXZ" |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2474 #define HEADER_MAGIC_SIZE 6 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2475 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2476 #define FOOTER_MAGIC "YZ" |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2477 #define FOOTER_MAGIC_SIZE 2 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2478 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2479 /* |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2480 * Variable-length integer can hold a 63-bit unsigned integer or a special |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2481 * value indicating that the value is unknown. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2482 * |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2483 * Experimental: vli_type can be defined to uint32_t to save a few bytes |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2484 * in code size (no effect on speed). Doing so limits the uncompressed and |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2485 * compressed size of the file to less than 256 MiB and may also weaken |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2486 * error detection slightly. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2487 */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2488 typedef uint64_t vli_type; |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2489 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2490 #define VLI_MAX ((vli_type)-1 / 2) |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2491 #define VLI_UNKNOWN ((vli_type)-1) |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2492 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2493 /* Maximum encoded size of a VLI */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2494 #define VLI_BYTES_MAX (sizeof(vli_type) * 8 / 7) |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2495 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2496 /* Integrity Check types */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2497 enum xz_check { |
855 | 2498 XZ_CHECK_NONE = 0, |
2499 XZ_CHECK_CRC32 = 1, | |
2500 XZ_CHECK_CRC64 = 4, | |
2501 XZ_CHECK_SHA256 = 10 | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2502 }; |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2503 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2504 /* Maximum possible Check ID */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2505 #define XZ_CHECK_MAX 15 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2506 // END xz_stream.h |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2507 |
846
e02b4e932cd1
Some xzcat cleanup by Isaac Dunham.
Rob Landley <rob@landley.net>
parents:
819
diff
changeset
|
2508 #define IS_CRC64(check_type) ((check_type) == XZ_CHECK_CRC64) |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2509 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2510 /* Hash used to validate the Index field */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2511 struct xz_dec_hash { |
855 | 2512 vli_type unpadded; |
2513 vli_type uncompressed; | |
2514 uint32_t crc32; | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2515 }; |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2516 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2517 struct xz_dec { |
855 | 2518 /* Position in dec_main() */ |
2519 enum { | |
2520 SEQ_STREAM_HEADER, | |
2521 SEQ_BLOCK_START, | |
2522 SEQ_BLOCK_HEADER, | |
2523 SEQ_BLOCK_UNCOMPRESS, | |
2524 SEQ_BLOCK_PADDING, | |
2525 SEQ_BLOCK_CHECK, | |
2526 SEQ_INDEX, | |
2527 SEQ_INDEX_PADDING, | |
2528 SEQ_INDEX_CRC32, | |
2529 SEQ_STREAM_FOOTER | |
2530 } sequence; | |
2531 | |
2532 /* Position in variable-length integers and Check fields */ | |
2533 uint32_t pos; | |
2534 | |
2535 /* Variable-length integer decoded by dec_vli() */ | |
2536 vli_type vli; | |
2537 | |
2538 /* Saved in_pos and out_pos */ | |
2539 size_t in_start; | |
2540 size_t out_start; | |
2541 | |
2542 /* CRC32 or CRC64 value in Block or CRC32 value in Index */ | |
2543 uint64_t crc; | |
2544 | |
2545 /* Type of the integrity check calculated from uncompressed data */ | |
2546 enum xz_check check_type; | |
2547 | |
2548 /* Operation mode */ | |
2549 enum xz_mode mode; | |
2550 | |
2551 /* | |
2552 * True if the next call to xz_dec_run() is allowed to return | |
2553 * XZ_BUF_ERROR. | |
2554 */ | |
2555 int allow_buf_error; | |
2556 | |
2557 /* Information stored in Block Header */ | |
2558 struct { | |
2559 /* | |
2560 * Value stored in the Compressed Size field, or | |
2561 * VLI_UNKNOWN if Compressed Size is not present. | |
2562 */ | |
2563 vli_type compressed; | |
2564 | |
2565 /* | |
2566 * Value stored in the Uncompressed Size field, or | |
2567 * VLI_UNKNOWN if Uncompressed Size is not present. | |
2568 */ | |
2569 vli_type uncompressed; | |
2570 | |
2571 /* Size of the Block Header field */ | |
2572 uint32_t size; | |
2573 } block_header; | |
2574 | |
2575 /* Information collected when decoding Blocks */ | |
2576 struct { | |
2577 /* Observed compressed size of the current Block */ | |
2578 vli_type compressed; | |
2579 | |
2580 /* Observed uncompressed size of the current Block */ | |
2581 vli_type uncompressed; | |
2582 | |
2583 /* Number of Blocks decoded so far */ | |
2584 vli_type count; | |
2585 | |
2586 /* | |
2587 * Hash calculated from the Block sizes. This is used to | |
2588 * validate the Index field. | |
2589 */ | |
2590 struct xz_dec_hash hash; | |
2591 } block; | |
2592 | |
2593 /* Variables needed when verifying the Index field */ | |
2594 struct { | |
2595 /* Position in dec_index() */ | |
2596 enum { | |
2597 SEQ_INDEX_COUNT, | |
2598 SEQ_INDEX_UNPADDED, | |
2599 SEQ_INDEX_UNCOMPRESSED | |
2600 } sequence; | |
2601 | |
2602 /* Size of the Index in bytes */ | |
2603 vli_type size; | |
2604 | |
2605 /* Number of Records (matches block.count in valid files) */ | |
2606 vli_type count; | |
2607 | |
2608 /* | |
2609 * Hash calculated from the Records (matches block.hash in | |
2610 * valid files). | |
2611 */ | |
2612 struct xz_dec_hash hash; | |
2613 } index; | |
2614 | |
2615 /* | |
2616 * Temporary buffer needed to hold Stream Header, Block Header, | |
2617 * and Stream Footer. The Block Header is the biggest (1 KiB) | |
2618 * so we reserve space according to that. buf[] has to be aligned | |
2619 * to a multiple of four bytes; the size_t variables before it | |
2620 * should guarantee this. | |
2621 */ | |
2622 struct { | |
2623 size_t pos; | |
2624 size_t size; | |
2625 uint8_t buf[1024]; | |
2626 } temp; | |
2627 | |
2628 struct xz_dec_lzma2 *lzma2; | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2629 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2630 #ifdef XZ_DEC_BCJ |
855 | 2631 struct xz_dec_bcj *bcj; |
2632 int bcj_active; | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2633 #endif |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2634 }; |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2635 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2636 /* Sizes of the Check field with different Check IDs */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2637 static const uint8_t check_sizes[16] = { |
855 | 2638 0, |
2639 4, 4, 4, | |
2640 8, 8, 8, | |
2641 16, 16, 16, | |
2642 32, 32, 32, | |
2643 64, 64, 64 | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2644 }; |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2645 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2646 /* |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2647 * Fill s->temp by copying data starting from b->in[b->in_pos]. Caller |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2648 * must have set s->temp.pos to indicate how much data we are supposed |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2649 * to copy into s->temp.buf. Return true once s->temp.pos has reached |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2650 * s->temp.size. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2651 */ |
851 | 2652 static int fill_temp(struct xz_dec *s, struct xz_buf *b) |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2653 { |
855 | 2654 size_t copy_size = min_t(size_t, |
2655 b->in_size - b->in_pos, s->temp.size - s->temp.pos); | |
2656 | |
2657 memcpy(s->temp.buf + s->temp.pos, b->in + b->in_pos, copy_size); | |
2658 b->in_pos += copy_size; | |
2659 s->temp.pos += copy_size; | |
2660 | |
2661 if (s->temp.pos == s->temp.size) { | |
2662 s->temp.pos = 0; | |
2663 return 1; | |
2664 } | |
2665 | |
2666 return 0; | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2667 } |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2668 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2669 /* Decode a variable-length integer (little-endian base-128 encoding) */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2670 static enum xz_ret dec_vli(struct xz_dec *s, const uint8_t *in, |
855 | 2671 size_t *in_pos, size_t in_size) |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2672 { |
855 | 2673 uint8_t byte; |
2674 | |
2675 if (s->pos == 0) | |
2676 s->vli = 0; | |
2677 | |
2678 while (*in_pos < in_size) { | |
2679 byte = in[*in_pos]; | |
2680 ++*in_pos; | |
2681 | |
2682 s->vli |= (vli_type)(byte & 0x7F) << s->pos; | |
2683 | |
2684 if ((byte & 0x80) == 0) { | |
2685 /* Don't allow non-minimal encodings. */ | |
2686 if (byte == 0 && s->pos != 0) | |
2687 return XZ_DATA_ERROR; | |
2688 | |
2689 s->pos = 0; | |
2690 return XZ_STREAM_END; | |
2691 } | |
2692 | |
2693 s->pos += 7; | |
2694 if (s->pos == 7 * VLI_BYTES_MAX) | |
2695 return XZ_DATA_ERROR; | |
2696 } | |
2697 | |
2698 return XZ_OK; | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2699 } |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2700 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2701 /* |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2702 * Decode the Compressed Data field from a Block. Update and validate |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2703 * the observed compressed and uncompressed sizes of the Block so that |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2704 * they don't exceed the values possibly stored in the Block Header |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2705 * (validation assumes that no integer overflow occurs, since vli_type |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2706 * is normally uint64_t). Update the CRC32 or CRC64 value if presence of |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2707 * the CRC32 or CRC64 field was indicated in Stream Header. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2708 * |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2709 * Once the decoding is finished, validate that the observed sizes match |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2710 * the sizes possibly stored in the Block Header. Update the hash and |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2711 * Block count, which are later used to validate the Index field. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2712 */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2713 static enum xz_ret dec_block(struct xz_dec *s, struct xz_buf *b) |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2714 { |
855 | 2715 enum xz_ret ret; |
2716 | |
2717 s->in_start = b->in_pos; | |
2718 s->out_start = b->out_pos; | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2719 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2720 #ifdef XZ_DEC_BCJ |
855 | 2721 if (s->bcj_active) |
2722 ret = xz_dec_bcj_run(s->bcj, s->lzma2, b); | |
2723 else | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2724 #endif |
855 | 2725 ret = xz_dec_lzma2_run(s->lzma2, b); |
2726 | |
2727 s->block.compressed += b->in_pos - s->in_start; | |
2728 s->block.uncompressed += b->out_pos - s->out_start; | |
2729 | |
2730 /* | |
2731 * There is no need to separately check for VLI_UNKNOWN, since | |
2732 * the observed sizes are always smaller than VLI_UNKNOWN. | |
2733 */ | |
2734 if (s->block.compressed > s->block_header.compressed | |
2735 || s->block.uncompressed | |
2736 > s->block_header.uncompressed) | |
2737 return XZ_DATA_ERROR; | |
2738 | |
2739 if (s->check_type == XZ_CHECK_CRC32) | |
2740 s->crc = xz_crc32(b->out + s->out_start, | |
2741 b->out_pos - s->out_start, s->crc); | |
2742 else if (s->check_type == XZ_CHECK_CRC64) | |
944
b4faf2ae39e8
This inlines CRC64, and nothing more.
Isaac Dunham <idunham@lavabit.com>
parents:
855
diff
changeset
|
2743 s->crc = ~(s->crc); |
b4faf2ae39e8
This inlines CRC64, and nothing more.
Isaac Dunham <idunham@lavabit.com>
parents:
855
diff
changeset
|
2744 size_t size = b->out_pos - s->out_start; |
b4faf2ae39e8
This inlines CRC64, and nothing more.
Isaac Dunham <idunham@lavabit.com>
parents:
855
diff
changeset
|
2745 uint8_t *buf = b->out + s->out_start; |
b4faf2ae39e8
This inlines CRC64, and nothing more.
Isaac Dunham <idunham@lavabit.com>
parents:
855
diff
changeset
|
2746 while (size) { |
b4faf2ae39e8
This inlines CRC64, and nothing more.
Isaac Dunham <idunham@lavabit.com>
parents:
855
diff
changeset
|
2747 s->crc = xz_crc64_table[*buf++ ^ (s->crc & 0xFF)] ^ (s->crc >> 8); |
b4faf2ae39e8
This inlines CRC64, and nothing more.
Isaac Dunham <idunham@lavabit.com>
parents:
855
diff
changeset
|
2748 --size; |
b4faf2ae39e8
This inlines CRC64, and nothing more.
Isaac Dunham <idunham@lavabit.com>
parents:
855
diff
changeset
|
2749 } |
b4faf2ae39e8
This inlines CRC64, and nothing more.
Isaac Dunham <idunham@lavabit.com>
parents:
855
diff
changeset
|
2750 s->crc=~(s->crc); |
855 | 2751 |
2752 if (ret == XZ_STREAM_END) { | |
2753 if (s->block_header.compressed != VLI_UNKNOWN | |
2754 && s->block_header.compressed | |
2755 != s->block.compressed) | |
2756 return XZ_DATA_ERROR; | |
2757 | |
2758 if (s->block_header.uncompressed != VLI_UNKNOWN | |
2759 && s->block_header.uncompressed | |
2760 != s->block.uncompressed) | |
2761 return XZ_DATA_ERROR; | |
2762 | |
2763 s->block.hash.unpadded += s->block_header.size | |
2764 + s->block.compressed; | |
2765 | |
2766 s->block.hash.unpadded += check_sizes[s->check_type]; | |
2767 | |
2768 s->block.hash.uncompressed += s->block.uncompressed; | |
2769 s->block.hash.crc32 = xz_crc32( | |
2770 (const uint8_t *)&s->block.hash, | |
2771 sizeof(s->block.hash), s->block.hash.crc32); | |
2772 | |
2773 ++s->block.count; | |
2774 } | |
2775 | |
2776 return ret; | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2777 } |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2778 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2779 /* Update the Index size and the CRC32 value. */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2780 static void index_update(struct xz_dec *s, const struct xz_buf *b) |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2781 { |
855 | 2782 size_t in_used = b->in_pos - s->in_start; |
2783 s->index.size += in_used; | |
2784 s->crc = xz_crc32(b->in + s->in_start, in_used, s->crc); | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2785 } |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2786 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2787 /* |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2788 * Decode the Number of Records, Unpadded Size, and Uncompressed Size |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2789 * fields from the Index field. That is, Index Padding and CRC32 are not |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2790 * decoded by this function. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2791 * |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2792 * This can return XZ_OK (more input needed), XZ_STREAM_END (everything |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2793 * successfully decoded), or XZ_DATA_ERROR (input is corrupt). |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2794 */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2795 static enum xz_ret dec_index(struct xz_dec *s, struct xz_buf *b) |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2796 { |
855 | 2797 enum xz_ret ret; |
2798 | |
2799 do { | |
2800 ret = dec_vli(s, b->in, &b->in_pos, b->in_size); | |
2801 if (ret != XZ_STREAM_END) { | |
2802 index_update(s, b); | |
2803 return ret; | |
2804 } | |
2805 | |
2806 switch (s->index.sequence) { | |
2807 case SEQ_INDEX_COUNT: | |
2808 s->index.count = s->vli; | |
2809 | |
2810 /* | |
2811 * Validate that the Number of Records field | |
2812 * indicates the same number of Records as | |
2813 * there were Blocks in the Stream. | |
2814 */ | |
2815 if (s->index.count != s->block.count) | |
2816 return XZ_DATA_ERROR; | |
2817 | |
2818 s->index.sequence = SEQ_INDEX_UNPADDED; | |
2819 break; | |
2820 | |
2821 case SEQ_INDEX_UNPADDED: | |
2822 s->index.hash.unpadded += s->vli; | |
2823 s->index.sequence = SEQ_INDEX_UNCOMPRESSED; | |
2824 break; | |
2825 | |
2826 case SEQ_INDEX_UNCOMPRESSED: | |
2827 s->index.hash.uncompressed += s->vli; | |
2828 s->index.hash.crc32 = xz_crc32( | |
2829 (const uint8_t *)&s->index.hash, | |
2830 sizeof(s->index.hash), | |
2831 s->index.hash.crc32); | |
2832 --s->index.count; | |
2833 s->index.sequence = SEQ_INDEX_UNPADDED; | |
2834 break; | |
2835 } | |
2836 } while (s->index.count > 0); | |
2837 | |
2838 return XZ_STREAM_END; | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2839 } |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2840 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2841 /* |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2842 * Validate that the next four or eight input bytes match the value |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2843 * of s->crc. s->pos must be zero when starting to validate the first byte. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2844 * The "bits" argument allows using the same code for both CRC32 and CRC64. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2845 */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2846 static enum xz_ret crc_validate(struct xz_dec *s, struct xz_buf *b, |
855 | 2847 uint32_t bits) |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2848 { |
855 | 2849 do { |
2850 if (b->in_pos == b->in_size) | |
2851 return XZ_OK; | |
2852 | |
2853 if (((s->crc >> s->pos) & 0xFF) != b->in[b->in_pos++]) | |
2854 return XZ_DATA_ERROR; | |
2855 | |
2856 s->pos += 8; | |
2857 | |
2858 } while (s->pos < bits); | |
2859 | |
2860 s->crc = 0; | |
2861 s->pos = 0; | |
2862 | |
2863 return XZ_STREAM_END; | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2864 } |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2865 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2866 /* |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2867 * Skip over the Check field when the Check ID is not supported. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2868 * Returns true once the whole Check field has been skipped over. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2869 */ |
851 | 2870 static int check_skip(struct xz_dec *s, struct xz_buf *b) |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2871 { |
855 | 2872 while (s->pos < check_sizes[s->check_type]) { |
2873 if (b->in_pos == b->in_size) return 0; | |
2874 | |
2875 ++b->in_pos; | |
2876 ++s->pos; | |
2877 } | |
2878 | |
2879 s->pos = 0; | |
2880 | |
2881 return 1; | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2882 } |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2883 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2884 /* Decode the Stream Header field (the first 12 bytes of the .xz Stream). */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2885 static enum xz_ret dec_stream_header(struct xz_dec *s) |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2886 { |
855 | 2887 if (!memeq(s->temp.buf, HEADER_MAGIC, HEADER_MAGIC_SIZE)) |
2888 return XZ_FORMAT_ERROR; | |
2889 | |
2890 if (xz_crc32(s->temp.buf + HEADER_MAGIC_SIZE, 2, 0) | |
2891 != get_le32(s->temp.buf + HEADER_MAGIC_SIZE + 2)) | |
2892 return XZ_DATA_ERROR; | |
2893 | |
2894 if (s->temp.buf[HEADER_MAGIC_SIZE] != 0) | |
2895 return XZ_OPTIONS_ERROR; | |
2896 | |
2897 /* | |
2898 * Of integrity checks, we support none (Check ID = 0), | |
2899 * CRC32 (Check ID = 1), and optionally CRC64 (Check ID = 4). | |
2900 * However, if XZ_DEC_ANY_CHECK is defined, we will accept other | |
2901 * check types too, but then the check won't be verified and | |
2902 * a warning (XZ_UNSUPPORTED_CHECK) will be given. | |
2903 */ | |
2904 s->check_type = s->temp.buf[HEADER_MAGIC_SIZE + 1]; | |
2905 | |
2906 if (s->check_type > XZ_CHECK_MAX) | |
2907 return XZ_OPTIONS_ERROR; | |
2908 | |
2909 if (s->check_type > XZ_CHECK_CRC32 && !IS_CRC64(s->check_type)) | |
2910 return XZ_UNSUPPORTED_CHECK; | |
2911 | |
2912 return XZ_OK; | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2913 } |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2914 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2915 /* Decode the Stream Footer field (the last 12 bytes of the .xz Stream) */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2916 static enum xz_ret dec_stream_footer(struct xz_dec *s) |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2917 { |
855 | 2918 if (!memeq(s->temp.buf + 10, FOOTER_MAGIC, FOOTER_MAGIC_SIZE)) |
2919 return XZ_DATA_ERROR; | |
2920 | |
2921 if (xz_crc32(s->temp.buf + 4, 6, 0) != get_le32(s->temp.buf)) | |
2922 return XZ_DATA_ERROR; | |
2923 | |
2924 /* | |
2925 * Validate Backward Size. Note that we never added the size of the | |
2926 * Index CRC32 field to s->index.size, thus we use s->index.size / 4 | |
2927 * instead of s->index.size / 4 - 1. | |
2928 */ | |
2929 if ((s->index.size >> 2) != get_le32(s->temp.buf + 4)) | |
2930 return XZ_DATA_ERROR; | |
2931 | |
2932 if (s->temp.buf[8] != 0 || s->temp.buf[9] != s->check_type) | |
2933 return XZ_DATA_ERROR; | |
2934 | |
2935 /* | |
2936 * Use XZ_STREAM_END instead of XZ_OK to be more convenient | |
2937 * for the caller. | |
2938 */ | |
2939 return XZ_STREAM_END; | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2940 } |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2941 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2942 /* Decode the Block Header and initialize the filter chain. */ |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2943 static enum xz_ret dec_block_header(struct xz_dec *s) |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2944 { |
855 | 2945 enum xz_ret ret; |
2946 | |
2947 /* | |
2948 * Validate the CRC32. We know that the temp buffer is at least | |
2949 * eight bytes so this is safe. | |
2950 */ | |
2951 s->temp.size -= 4; | |
2952 if (xz_crc32(s->temp.buf, s->temp.size, 0) | |
2953 != get_le32(s->temp.buf + s->temp.size)) | |
2954 return XZ_DATA_ERROR; | |
2955 | |
2956 s->temp.pos = 2; | |
2957 | |
2958 /* | |
2959 * Catch unsupported Block Flags. We support only one or two filters | |
2960 * in the chain, so we catch that with the same test. | |
2961 */ | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2962 #ifdef XZ_DEC_BCJ |
855 | 2963 if (s->temp.buf[1] & 0x3E) |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2964 #else |
855 | 2965 if (s->temp.buf[1] & 0x3F) |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2966 #endif |
855 | 2967 return XZ_OPTIONS_ERROR; |
2968 | |
2969 /* Compressed Size */ | |
2970 if (s->temp.buf[1] & 0x40) { | |
2971 if (dec_vli(s, s->temp.buf, &s->temp.pos, s->temp.size) | |
2972 != XZ_STREAM_END) | |
2973 return XZ_DATA_ERROR; | |
2974 | |
2975 s->block_header.compressed = s->vli; | |
2976 } else { | |
2977 s->block_header.compressed = VLI_UNKNOWN; | |
2978 } | |
2979 | |
2980 /* Uncompressed Size */ | |
2981 if (s->temp.buf[1] & 0x80) { | |
2982 if (dec_vli(s, s->temp.buf, &s->temp.pos, s->temp.size) | |
2983 != XZ_STREAM_END) | |
2984 return XZ_DATA_ERROR; | |
2985 | |
2986 s->block_header.uncompressed = s->vli; | |
2987 } else { | |
2988 s->block_header.uncompressed = VLI_UNKNOWN; | |
2989 } | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2990 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2991 #ifdef XZ_DEC_BCJ |
855 | 2992 /* If there are two filters, the first one must be a BCJ filter. */ |
2993 s->bcj_active = s->temp.buf[1] & 0x01; | |
2994 if (s->bcj_active) { | |
2995 if (s->temp.size - s->temp.pos < 2) | |
2996 return XZ_OPTIONS_ERROR; | |
2997 | |
2998 ret = xz_dec_bcj_reset(s->bcj, s->temp.buf[s->temp.pos++]); | |
2999 if (ret != XZ_OK) | |
3000 return ret; | |
3001 | |
3002 /* | |
3003 * We don't support custom start offset, | |
3004 * so Size of Properties must be zero. | |
3005 */ | |
3006 if (s->temp.buf[s->temp.pos++] != 0x00) | |
3007 return XZ_OPTIONS_ERROR; | |
3008 } | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3009 #endif |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3010 |
855 | 3011 /* Valid Filter Flags always take at least two bytes. */ |
3012 if (s->temp.size - s->temp.pos < 2) | |
3013 return XZ_DATA_ERROR; | |
3014 | |
3015 /* Filter ID = LZMA2 */ | |
3016 if (s->temp.buf[s->temp.pos++] != 0x21) | |
3017 return XZ_OPTIONS_ERROR; | |
3018 | |
3019 /* Size of Properties = 1-byte Filter Properties */ | |
3020 if (s->temp.buf[s->temp.pos++] != 0x01) | |
3021 return XZ_OPTIONS_ERROR; | |
3022 | |
3023 /* Filter Properties contains LZMA2 dictionary size. */ | |
3024 if (s->temp.size - s->temp.pos < 1) | |
3025 return XZ_DATA_ERROR; | |
3026 | |
3027 ret = xz_dec_lzma2_reset(s->lzma2, s->temp.buf[s->temp.pos++]); | |
3028 if (ret != XZ_OK) | |
3029 return ret; | |
3030 | |
3031 /* The rest must be Header Padding. */ | |
3032 while (s->temp.pos < s->temp.size) | |
3033 if (s->temp.buf[s->temp.pos++] != 0x00) | |
3034 return XZ_OPTIONS_ERROR; | |
3035 | |
3036 s->temp.pos = 0; | |
3037 s->block.compressed = 0; | |
3038 s->block.uncompressed = 0; | |
3039 | |
3040 return XZ_OK; | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3041 } |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3042 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3043 static enum xz_ret dec_main(struct xz_dec *s, struct xz_buf *b) |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3044 { |
855 | 3045 enum xz_ret ret; |
3046 | |
3047 /* | |
3048 * Store the start position for the case when we are in the middle | |
3049 * of the Index field. | |
3050 */ | |
3051 s->in_start = b->in_pos; | |
3052 | |
3053 for (;;) { | |
3054 switch (s->sequence) { | |
3055 case SEQ_STREAM_HEADER: | |
3056 /* | |
3057 * Stream Header is copied to s->temp, and then | |
3058 * decoded from there. This way if the caller | |
3059 * gives us only little input at a time, we can | |
3060 * still keep the Stream Header decoding code | |
3061 * simple. Similar approach is used in many places | |
3062 * in this file. | |
3063 */ | |
3064 if (!fill_temp(s, b)) | |
3065 return XZ_OK; | |
3066 | |
3067 /* | |
3068 * If dec_stream_header() returns | |
3069 * XZ_UNSUPPORTED_CHECK, it is still possible | |
3070 * to continue decoding if working in multi-call | |
3071 * mode. Thus, update s->sequence before calling | |
3072 * dec_stream_header(). | |
3073 */ | |
3074 s->sequence = SEQ_BLOCK_START; | |
3075 | |
3076 ret = dec_stream_header(s); | |
3077 if (ret != XZ_OK) | |
3078 return ret; | |
3079 | |
3080 case SEQ_BLOCK_START: | |
3081 /* We need one byte of input to continue. */ | |
3082 if (b->in_pos == b->in_size) | |
3083 return XZ_OK; | |
3084 | |
3085 /* See if this is the beginning of the Index field. */ | |
3086 if (b->in[b->in_pos] == 0) { | |
3087 s->in_start = b->in_pos++; | |
3088 s->sequence = SEQ_INDEX; | |
3089 break; | |
3090 } | |
3091 | |
3092 /* | |
3093 * Calculate the size of the Block Header and | |
3094 * prepare to decode it. | |
3095 */ | |
3096 s->block_header.size | |
3097 = ((uint32_t)b->in[b->in_pos] + 1) * 4; | |
3098 | |
3099 s->temp.size = s->block_header.size; | |
3100 s->temp.pos = 0; | |
3101 s->sequence = SEQ_BLOCK_HEADER; | |
3102 | |
3103 case SEQ_BLOCK_HEADER: | |
3104 if (!fill_temp(s, b)) | |
3105 return XZ_OK; | |
3106 | |
3107 ret = dec_block_header(s); | |
3108 if (ret != XZ_OK) | |
3109 return ret; | |
3110 | |
3111 s->sequence = SEQ_BLOCK_UNCOMPRESS; | |
3112 | |
3113 case SEQ_BLOCK_UNCOMPRESS: | |
3114 ret = dec_block(s, b); | |
3115 if (ret != XZ_STREAM_END) | |
3116 return ret; | |
3117 | |
3118 s->sequence = SEQ_BLOCK_PADDING; | |
3119 | |
3120 case SEQ_BLOCK_PADDING: | |
3121 /* | |
3122 * Size of Compressed Data + Block Padding | |
3123 * must be a multiple of four. We don't need | |
3124 * s->block.compressed for anything else | |
3125 * anymore, so we use it here to test the size | |
3126 * of the Block Padding field. | |
3127 */ | |
3128 while (s->block.compressed & 3) { | |
3129 if (b->in_pos == b->in_size) | |
3130 return XZ_OK; | |
3131 | |
3132 if (b->in[b->in_pos++] != 0) | |
3133 return XZ_DATA_ERROR; | |
3134 | |
3135 ++s->block.compressed; | |
3136 } | |
3137 | |
3138 s->sequence = SEQ_BLOCK_CHECK; | |
3139 | |
3140 case SEQ_BLOCK_CHECK: | |
3141 if (s->check_type == XZ_CHECK_CRC32) { | |
3142 ret = crc_validate(s, b, 32); | |
3143 if (ret != XZ_STREAM_END) | |
3144 return ret; | |
3145 } | |
3146 else if (IS_CRC64(s->check_type)) { | |
3147 ret = crc_validate(s, b, 64); | |
3148 if (ret != XZ_STREAM_END) | |
3149 return ret; | |
3150 } | |
3151 else if (!check_skip(s, b)) { | |
3152 return XZ_OK; | |
3153 } | |
3154 | |
3155 s->sequence = SEQ_BLOCK_START; | |
3156 break; | |
3157 | |
3158 case SEQ_INDEX: | |
3159 ret = dec_index(s, b); | |
3160 if (ret != XZ_STREAM_END) | |
3161 return ret; | |
3162 | |
3163 s->sequence = SEQ_INDEX_PADDING; | |
3164 | |
3165 case SEQ_INDEX_PADDING: | |
3166 while ((s->index.size + (b->in_pos - s->in_start)) | |
3167 & 3) { | |
3168 if (b->in_pos == b->in_size) { | |
3169 index_update(s, b); | |
3170 return XZ_OK; | |
3171 } | |
3172 | |
3173 if (b->in[b->in_pos++] != 0) | |
3174 return XZ_DATA_ERROR; | |
3175 } | |
3176 | |
3177 /* Finish the CRC32 value and Index size. */ | |
3178 index_update(s, b); | |
3179 | |
3180 /* Compare the hashes to validate the Index field. */ | |
3181 if (!memeq(&s->block.hash, &s->index.hash, | |
3182 sizeof(s->block.hash))) | |
3183 return XZ_DATA_ERROR; | |
3184 | |
3185 s->sequence = SEQ_INDEX_CRC32; | |
3186 | |
3187 case SEQ_INDEX_CRC32: | |
3188 ret = crc_validate(s, b, 32); | |
3189 if (ret != XZ_STREAM_END) | |
3190 return ret; | |
3191 | |
3192 s->temp.size = STREAM_HEADER_SIZE; | |
3193 s->sequence = SEQ_STREAM_FOOTER; | |
3194 | |
3195 case SEQ_STREAM_FOOTER: | |
3196 if (!fill_temp(s, b)) | |
3197 return XZ_OK; | |
3198 | |
3199 return dec_stream_footer(s); | |
3200 } | |
3201 } | |
3202 | |
3203 /* Never reached */ | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3204 } |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3205 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3206 /* |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3207 * xz_dec_run() is a wrapper for dec_main() to handle some special cases in |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3208 * multi-call and single-call decoding. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3209 * |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3210 * In multi-call mode, we must return XZ_BUF_ERROR when it seems clear that we |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3211 * are not going to make any progress anymore. This is to prevent the caller |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3212 * from calling us infinitely when the input file is truncated or otherwise |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3213 * corrupt. Since zlib-style API allows that the caller fills the input buffer |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3214 * only when the decoder doesn't produce any new output, we have to be careful |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3215 * to avoid returning XZ_BUF_ERROR too easily: XZ_BUF_ERROR is returned only |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3216 * after the second consecutive call to xz_dec_run() that makes no progress. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3217 * |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3218 * In single-call mode, if we couldn't decode everything and no error |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3219 * occurred, either the input is truncated or the output buffer is too small. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3220 * Since we know that the last input byte never produces any output, we know |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3221 * that if all the input was consumed and decoding wasn't finished, the file |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3222 * must be corrupt. Otherwise the output buffer has to be too small or the |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3223 * file is corrupt in a way that decoding it produces too big output. |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3224 * |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3225 * If single-call decoding fails, we reset b->in_pos and b->out_pos back to |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3226 * their original values. This is because with some filter chains there won't |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3227 * be any valid uncompressed data in the output buffer unless the decoding |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3228 * actually succeeds (that's the price to pay of using the output buffer as |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3229 * the workspace). |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3230 */ |
846
e02b4e932cd1
Some xzcat cleanup by Isaac Dunham.
Rob Landley <rob@landley.net>
parents:
819
diff
changeset
|
3231 enum xz_ret xz_dec_run(struct xz_dec *s, struct xz_buf *b) |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3232 { |
855 | 3233 size_t in_start; |
3234 size_t out_start; | |
3235 enum xz_ret ret; | |
3236 | |
3237 if (DEC_IS_SINGLE(s->mode)) | |
3238 xz_dec_reset(s); | |
3239 | |
3240 in_start = b->in_pos; | |
3241 out_start = b->out_pos; | |
3242 ret = dec_main(s, b); | |
3243 | |
3244 if (DEC_IS_SINGLE(s->mode)) { | |
3245 if (ret == XZ_OK) | |
3246 ret = b->in_pos == b->in_size | |
3247 ? XZ_DATA_ERROR : XZ_BUF_ERROR; | |
3248 | |
3249 if (ret != XZ_STREAM_END) { | |
3250 b->in_pos = in_start; | |
3251 b->out_pos = out_start; | |
3252 } | |
3253 | |
3254 } else if (ret == XZ_OK && in_start == b->in_pos | |
3255 && out_start == b->out_pos) { | |
3256 if (s->allow_buf_error) | |
3257 ret = XZ_BUF_ERROR; | |
3258 | |
3259 s->allow_buf_error = 1; | |
3260 } else { | |
3261 s->allow_buf_error = 0; | |
3262 } | |
3263 | |
3264 return ret; | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3265 } |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3266 |
846
e02b4e932cd1
Some xzcat cleanup by Isaac Dunham.
Rob Landley <rob@landley.net>
parents:
819
diff
changeset
|
3267 struct xz_dec *xz_dec_init(enum xz_mode mode, uint32_t dict_max) |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3268 { |
855 | 3269 struct xz_dec *s = malloc(sizeof(*s)); |
3270 if (s == NULL) | |
3271 return NULL; | |
3272 | |
3273 s->mode = mode; | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3274 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3275 #ifdef XZ_DEC_BCJ |
855 | 3276 s->bcj = xz_dec_bcj_create(DEC_IS_SINGLE(mode)); |
3277 if (s->bcj == NULL) | |
3278 goto error_bcj; | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3279 #endif |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3280 |
855 | 3281 s->lzma2 = xz_dec_lzma2_create(mode, dict_max); |
3282 if (s->lzma2 == NULL) | |
3283 goto error_lzma2; | |
3284 | |
3285 xz_dec_reset(s); | |
3286 return s; | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3287 |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3288 error_lzma2: |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3289 #ifdef XZ_DEC_BCJ |
855 | 3290 free(s->bcj); |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3291 error_bcj: |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3292 #endif |
855 | 3293 free(s); |
3294 return NULL; | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3295 } |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3296 |
846
e02b4e932cd1
Some xzcat cleanup by Isaac Dunham.
Rob Landley <rob@landley.net>
parents:
819
diff
changeset
|
3297 void xz_dec_reset(struct xz_dec *s) |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3298 { |
855 | 3299 s->sequence = SEQ_STREAM_HEADER; |
3300 s->allow_buf_error = 0; | |
3301 s->pos = 0; | |
3302 s->crc = 0; | |
3303 memset(&s->block, 0, sizeof(s->block)); | |
3304 memset(&s->index, 0, sizeof(s->index)); | |
3305 s->temp.pos = 0; | |
3306 s->temp.size = STREAM_HEADER_SIZE; | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3307 } |
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3308 |
846
e02b4e932cd1
Some xzcat cleanup by Isaac Dunham.
Rob Landley <rob@landley.net>
parents:
819
diff
changeset
|
3309 void xz_dec_end(struct xz_dec *s) |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3310 { |
855 | 3311 if (s != NULL) { |
3312 if (DEC_IS_MULTI((s->lzma2)->dict.mode)) | |
3313 free((s->lzma2)->dict.buf); | |
3314 free(s->lzma2); | |
854
68cdd244f8b1
xzcat: more cleanup and some shrinking.
Isaac Dunham <idunham@lavabit.com>
parents:
851
diff
changeset
|
3315 |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3316 #ifdef XZ_DEC_BCJ |
855 | 3317 free(s->bcj); |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3318 #endif |
855 | 3319 free(s); |
3320 } | |
819
547f6c1d6972
Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3321 } |