annotate toys/pending/xzcat.c @ 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.
author Rob Landley <rob@landley.net>
date Fri, 15 Mar 2013 20:16:25 -0500
parents
children e02b4e932cd1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * This is really limited: Not all filters from .xz format are supported 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
25 * decoding of concatenated .xz streams is not supported. Thus, you may want
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * to look at xzdec from XZ Utils if a few KiB bigger tool is not a problem.
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 #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
29 #define XZ_DEC_ANY_CHECK
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 #include <stdbool.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
32
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 // 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
34 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * XZ decompressor
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 *
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * Authors: 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
38 * Igor Pavlov <http://7-zip.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
39 *
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
41 * 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
42 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 #ifndef 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
45 #define 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
46
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
47 #include <stddef.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
48 #include <stdint.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
49
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
50 #ifdef __cplusplus
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
51 extern "C" {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
52 #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
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 /* In Linux, this is used to make extern functions static when 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
55 #ifndef XZ_EXTERN
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 # define XZ_EXTERN extern
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 #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
58
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /**
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
61 *
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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_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
63 * 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
64 * 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
65 * 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
66 * 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
67 * 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
68 * @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
69 * 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
70 * 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
71 * 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
72 * @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
73 * 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
74 * 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
75 * 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
76 * 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
77 *
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
79 * modes at compile time by defining XZ_DEC_SINGLE, 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
80 * or XZ_DEC_DYNALLOC. The xz_dec kernel module is always compiled
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * with support for all operation modes, but the preboot code may
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * be built with fewer features to minimize 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
83 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 enum xz_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
85 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
86 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
87 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
88 };
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /**
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
92 * @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
93 * 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
94 * 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
95 * (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
96 * @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
97 * @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
98 * 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
99 * 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
100 * 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
101 * 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
102 * 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
103 * 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
104 * 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
105 * @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
106 * 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
107 * 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
108 * 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
109 * 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
110 * @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
111 * 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
112 * 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
113 * 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
114 * 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
115 * 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
116 * @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
117 * 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
118 * @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
119 * 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
120 * 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
121 * 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
122 * @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
123 * @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
124 * 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
125 * 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
126 *
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
128 * 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
129 * 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
130 * 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
131 * 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
132 * 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
133 *
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
134 * 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
135 * 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
136 * 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
137 * (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
138 * 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
139 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
140 enum xz_ret {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 XZ_OK,
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 XZ_STREAM_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
143 XZ_UNSUPPORTED_CHECK,
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 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
145 XZ_MEMLIMIT_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
146 XZ_FORMAT_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
147 XZ_OPTIONS_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
148 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
149 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
150 };
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /**
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
154 * @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
155 * 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
156 * @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
157 * 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
158 * @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
159 * @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
160 * 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
161 * @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
162 * 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
163 * @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
164 *
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
166 * 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
167 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 struct xz_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
169 const uint8_t *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
170 size_t in_pos;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 size_t 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
172
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 uint8_t *out;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 size_t out_pos;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 size_t 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
176 };
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /**
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
180 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 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
182
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /**
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
185 * @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
186 * @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
187 * 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
188 * (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
189 * 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
190 * 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
191 * 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
192 * 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
193 * 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
194 * 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
195 *
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
197 * 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
198 * 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
199 * 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
200 * 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
201 *
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
203 * 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
204 * 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
205 * 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
206 *
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
208 * 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
209 * 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
210 * 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
211 * 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
212 * 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
213 * 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
214 *
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
216 * 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
217 * 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
218 * 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
219 * 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
220 * 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
221 *
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
223 * 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
224 * 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
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 XZ_EXTERN struct xz_dec *xz_dec_init(enum xz_mode mode, uint32_t dict_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
227
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /**
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
230 * @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
231 * @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
232 *
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
234 * 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
235 *
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
237 * 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
238 * 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
239 * 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
240 * 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
241 * 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
242 * 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
243 * 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
244 * 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
245 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
246 XZ_EXTERN enum xz_ret xz_dec_run(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
247
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
248 /**
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
249 * 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
250 * @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
251 *
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
252 * 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
253 * 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
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 * 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
256 * 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
257 * 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
258 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 XZ_EXTERN void xz_dec_reset(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
260
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /**
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
262 * 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
263 * @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
264 * 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
265 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
266 XZ_EXTERN void xz_dec_end(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
267
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
268 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
269 * Standalone build (userspace build or in-kernel build for boot time 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
270 * needs a CRC32 implementation. For normal in-kernel use, kernel's own
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
271 * CRC32 module is used instead, and users of this module don't need 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
272 * care about the functions 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
273 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
274 #ifndef XZ_INTERNAL_CRC32
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
275 # ifdef __KERNEL__
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
276 # define XZ_INTERNAL_CRC32 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
277 # else
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
278 # define XZ_INTERNAL_CRC32 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
279 # 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
280 #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
281
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
282 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
283 * If CRC64 support has been enabled with XZ_USE_CRC64, a 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
284 * implementation is needed 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
285 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
286 #ifndef XZ_USE_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
287 # undef XZ_INTERNAL_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
288 # define XZ_INTERNAL_CRC64 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
289 #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
290 #ifndef XZ_INTERNAL_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
291 # ifdef __KERNEL__
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
292 # error Using CRC64 in the kernel has not been implemented.
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
293 # else
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
294 # define XZ_INTERNAL_CRC64 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
295 # 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
296 #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
297
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
298 #if XZ_INTERNAL_CRC32
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
299 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
300 * This must be called before any other xz_* function to initialize
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
301 * the CRC32 lookup table.
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
302 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
303 XZ_EXTERN void xz_crc32_init(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
304
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
305 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
306 * 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
307 * 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
308 * 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
309 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
310 XZ_EXTERN uint32_t xz_crc32(const uint8_t *buf, size_t size, uint32_t crc);
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
311 #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
312
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
313 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
314 * This must be called before any other xz_* function (except xz_crc32_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
315 * to initialize the CRC64 lookup table.
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
316 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
317 XZ_EXTERN void xz_crc64_init(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
318
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
319 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
320 * Update CRC64 value using the polynomial from ECMA-182. 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
321 * 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
322 * 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
323 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
324 XZ_EXTERN uint64_t xz_crc64(const uint8_t *buf, size_t size, uint64_t crc);
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
325
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
326 #ifdef __cplusplus
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
327 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
328 #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
329
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
330 #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
331
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
332 // 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
333
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
334 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
335 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
336
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
337 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
338 {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
339 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
340 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
341 enum xz_ret ret;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
342 const char *msg;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
343
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
344 xz_crc32_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
345 xz_crc64_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
346
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
347 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
348 * Support up to 64 MiB dictionary. The actually needed memory
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
349 * is allocated once the headers have been parsed.
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
350 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
351 s = xz_dec_init(XZ_DYNALLOC, 1 << 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
352 if (s == 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
353 msg = "Memory allocation failed\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
354 goto 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
355 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
356
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
357 b.in = 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
358 b.in_pos = 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
359 b.in_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
360 b.out = out;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
361 b.out_pos = 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
362 b.out_size = 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
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 while (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
365 if (b.in_pos == b.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
366 b.in_size = fread(in, 1, sizeof(in), stdin);
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 b.in_pos = 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
368 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 ret = xz_dec_run(s, &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
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 if (b.out_pos == sizeof(out)) {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 if (fwrite(out, 1, b.out_pos, stdout) != b.out_pos) {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 msg = "Write error\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
375 goto 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
376 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 b.out_pos = 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
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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 if (ret == XZ_OK)
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 continue;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 #ifdef XZ_DEC_ANY_CHECK
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 if (ret == XZ_UNSUPPORTED_CHECK)
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 continue;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 #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
388
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 if (fwrite(out, 1, b.out_pos, stdout) != b.out_pos
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 || fclose(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
391 msg = "Write error\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
392 goto 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
393 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
394
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
395 switch (ret) {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 case XZ_STREAM_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
397 xz_dec_end(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
398 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
399
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 case 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
401 msg = "Memory allocation failed\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
402 goto 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
403
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
404 case XZ_MEMLIMIT_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
405 msg = "Memory usage limit reached\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
406 goto 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
407
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 case XZ_FORMAT_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
409 msg = "Not a .xz file\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
410 goto 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
411
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
412 case XZ_OPTIONS_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
413 msg = "Unsupported options in the .xz headers\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
414 goto 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
415
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 case 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
417 case 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
418 msg = "File is corrupt\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
419 goto 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
420
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 default:
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
422 msg = "Bug!\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
423 goto 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
424 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
425 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 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
428 xz_dec_end(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
429 error_exit("%s", msg);
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * CRC32 using the polynomial from IEEE-802.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
433 * CRC64 using the polynomial from ECMA-182
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 *
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * Authors: 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
436 * Igor Pavlov <http://7-zip.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
437 *
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
438 * 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
439 * 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
440 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
441
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
442 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
443 * This is not the fastest implementation, but it is pretty compact.
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * The fastest versions of xz_crc32() on modern CPUs without hardware
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * accelerated CRC instruction are 3-5 times as fast as this version,
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * but they are bigger and use more memory for the lookup table.
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 // BEGIN 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
450 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * Private includes and 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
452 *
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
453 * 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
454 *
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
456 * 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
457 *
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
459 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 #ifndef 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
462 #define 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
463
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /* Enable CRC64 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
465 #define XZ_USE_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
466
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /* 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
468 * 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
469 * */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 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
472 #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
473 #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
474 #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
475 #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
476 #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
477
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 #include <stdbool.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
479 #include <stdlib.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
480 #include <string.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
481
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
482 #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
483 #define memzero(buf, size) memset(buf, 0, 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
484
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 #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
486 # 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
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 #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
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 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * Some functions have been marked with __always_inline to keep 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
492 * performance reasonable even when the compiler is optimizing 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
493 * small code size. You may be able to save a few bytes by #defining
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
494 * __always_inline to plain inline, but don't complain if the 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
495 * becomes slow.
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * NOTE: System headers on GNU/Linux may #define this macro already,
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * so if you want to change it, you need to #undef it first.
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 #ifndef __always_inline
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 # ifdef __GNUC__
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
502 # define __always_inline \
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
503 inline __attribute__((__always_inline__))
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 # else
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 # define __always_inline inline
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
506 # 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
507 #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
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 /* 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
510 #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
511 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
512 {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 return (uint32_t)buf[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
514 | ((uint32_t)buf[1] << 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
515 | ((uint32_t)buf[2] << 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
516 | ((uint32_t)buf[3] << 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
517 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 #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
519
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 #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
521 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
522 {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 return (uint32_t)(buf[0] << 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
524 | ((uint32_t)buf[1] << 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
525 | ((uint32_t)buf[2] << 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
526 | (uint32_t)buf[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
527 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 #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
529
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
530 #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
531 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
532 {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 buf[0] = (uint8_t)val;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 buf[1] = (uint8_t)(val >> 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
535 buf[2] = (uint8_t)(val >> 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
536 buf[3] = (uint8_t)(val >> 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
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 #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
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 #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
541 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
542 {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 buf[0] = (uint8_t)(val >> 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
544 buf[1] = (uint8_t)(val >> 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
545 buf[2] = (uint8_t)(val >> 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
546 buf[3] = (uint8_t)val;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
547 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
548 #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
549
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
550 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
551 * 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
552 * 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
553 * 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
554 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
555 #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
556 # 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
557 #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
558
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
559 /* If no specific decoding mode is requested, enable support for all modes. */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
560 #if !defined(XZ_DEC_SINGLE) && !defined(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
561 && !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
562 # define 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
563 # define 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
564 # define 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
565 #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
566
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
567 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
568 * 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
569 * 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
570 * 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
571 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
572 #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
573 # 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
574 #else
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
575 # define DEC_IS_SINGLE(mode) (false)
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
576 #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
577
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
578 #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
579 # 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
580 #else
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
581 # define DEC_IS_PREALLOC(mode) (false)
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
582 #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
583
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
584 #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
585 # 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
586 #else
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
587 # define DEC_IS_DYNALLOC(mode) (false)
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
588 #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
589
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
590 #if !defined(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
591 # define DEC_IS_MULTI(mode) (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
592 #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
593 # 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
594 #else
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
595 # define DEC_IS_MULTI(mode) (false)
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
596 #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
597
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
598 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
599 * 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
600 * 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
601 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
602 #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
603 # if defined(XZ_DEC_X86) || defined(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
604 || defined(XZ_DEC_IA64) || defined(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
605 || defined(XZ_DEC_ARM) || defined(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
606 || defined(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
607 # 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
608 # 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
609 #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
610
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
612 * 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
613 * 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
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 XZ_EXTERN struct xz_dec_lzma2 *xz_dec_lzma2_create(enum xz_mode 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
616 uint32_t dict_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
617
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
618 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
619 * 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
620 * 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
621 * 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
622 * 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
623 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
624 XZ_EXTERN enum xz_ret xz_dec_lzma2_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
625 uint8_t props);
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
626
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
627 /* Decode raw LZMA2 stream from b->in to b->out. */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
628 XZ_EXTERN enum xz_ret xz_dec_lzma2_run(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
629 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
630
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
631 /* Free the memory allocated for the 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
632 XZ_EXTERN void xz_dec_lzma2_end(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
633
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
634 #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
635 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
636 * 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
637 * 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
638 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
639 XZ_EXTERN struct xz_dec_bcj *xz_dec_bcj_create(bool 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
640
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
641 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
642 * 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
643 * 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
644 * 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
645 * 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
646 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
647 XZ_EXTERN enum xz_ret xz_dec_bcj_reset(struct xz_dec_bcj *s, uint8_t 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
648
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
649 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
650 * 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
651 * 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
652 * 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
653 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
654 XZ_EXTERN enum xz_ret xz_dec_bcj_run(struct xz_dec_bcj *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
655 struct xz_dec_lzma2 *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
656 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
657
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
658 /* Free the memory allocated for the 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
659 #define xz_dec_bcj_end(s) free(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
660 #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
661
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
662 #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
663
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
664 // 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
665
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
666 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
667 * STATIC_RW_DATA is used in the pre-boot environment on some architectures.
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
668 * See <linux/decompress/mm.h> 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
669 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
670 #ifndef STATIC_RW_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
671 # define STATIC_RW_DATA static
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
672 #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
673
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
674 STATIC_RW_DATA uint32_t xz_crc32_table[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
675
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
676 XZ_EXTERN void xz_crc32_init(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
677 {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
678 const uint32_t poly = 0xEDB88320;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
679
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
680 uint32_t i;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
681 uint32_t j;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
682 uint32_t r;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 for (i = 0; i < 256; ++i) {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 r = i;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 for (j = 0; j < 8; ++j)
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 r = (r >> 1) ^ (poly & ~((r & 1) - 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
688
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
689 xz_crc32_table[i] = r;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
690 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
691
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
692 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
693 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
694
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
695 XZ_EXTERN uint32_t xz_crc32(const uint8_t *buf, size_t size, uint32_t crc)
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
696 {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
697 crc = ~crc;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
698
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
699 while (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
700 crc = xz_crc32_table[*buf++ ^ (crc & 0xFF)] ^ (crc >> 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
701 --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
702 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
703
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 return ~crc;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 STATIC_RW_DATA uint64_t xz_crc64_table[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
710
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
711 XZ_EXTERN void xz_crc64_init(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
712 {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
713 const uint64_t poly = 0xC96C5795D7870F42ULL;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
714
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
715 uint32_t i;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
716 uint32_t j;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
717 uint64_t r;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
718
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
719 for (i = 0; i < 256; ++i) {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
720 r = i;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
721 for (j = 0; j < 8; ++j)
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
722 r = (r >> 1) ^ (poly & ~((r & 1) - 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
723
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
724 xz_crc64_table[i] = r;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
725 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
726
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
727 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
728 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
729
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
730 XZ_EXTERN uint64_t xz_crc64(const uint8_t *buf, size_t size, uint64_t crc)
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
731 {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
732 crc = ~crc;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
733
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
734 while (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
735 crc = xz_crc64_table[*buf++ ^ (crc & 0xFF)] ^ (crc >> 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
736 --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
737 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
738
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
739 return ~crc;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
740 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
741 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
742 * Branch/Call/Jump (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
743 *
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
744 * Authors: 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
745 * Igor Pavlov <http://7-zip.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
746 *
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
747 * 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
748 * 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
749 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
750
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
751 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
752 * The rest of the file is inside this ifdef. It makes things a little 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
753 * 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
754 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
755 #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
756
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
757 struct 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
758 /* Type of the BCJ filter being 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
759 enum {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
760 BCJ_X86 = 4, /* x86 or x86-64 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
761 BCJ_POWERPC = 5, /* Big endian 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
762 BCJ_IA64 = 6, /* Big or little endian */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
763 BCJ_ARM = 7, /* Little endian 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
764 BCJ_ARMTHUMB = 8, /* Little endian 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
765 BCJ_SPARC = 9 /* Big or little endian */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
766 } 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
767
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
768 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
769 * Return value of the next filter in the chain. We need to preserve
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
770 * this information across calls, because we must not call the next
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
771 * filter anymore once it has returned XZ_STREAM_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
772 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
773 enum xz_ret ret;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
774
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
775 /* True if we are operating 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
776 bool 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
777
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
778 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
779 * Absolute position relative to the beginning of the uncompressed
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
780 * data (in a single .xz Block). We care only about the lowest 32
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
781 * bits so this doesn't need to be uint64_t even with big files.
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
782 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
783 uint32_t pos;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
784
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
785 /* x86 filter 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
786 uint32_t x86_prev_mask;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
787
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /* Temporary space to hold the variables from struct xz_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
789 uint8_t *out;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 size_t out_pos;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 size_t 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
792
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 struct {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
794 /* Amount of already filtered data in the beginning of 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
795 size_t 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
796
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
797 /* Total amount of data currently stored in 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
798 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
799
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
800 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
801 * Buffer to hold a mix of filtered and unfiltered data. 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
802 * needs to be big enough to hold Alignment + 2 * Look-ahead:
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
803 *
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
804 * Type Alignment Look-ahead
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
805 * x86 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
806 * PowerPC 4 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
807 * IA-64 16 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
808 * ARM 4 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
809 * ARM-Thumb 2 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
810 * SPARC 4 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
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 uint8_t buf[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
813 } 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
814 };
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 #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
817 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
818 * 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
819 * 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
820 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
821 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
822 {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
823 return b == 0x00 || b == 0xFF;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
824 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
825
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
826 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
827 {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
828 static const bool mask_to_allowed_status[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
829 = { true, true, true, false, true, false, false, false };
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
830
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
831 static const uint8_t mask_to_bit_num[8] = { 0, 1, 2, 2, 3, 3, 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
832
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
833 size_t i;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
834 size_t prev_pos = (size_t)-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
835 uint32_t prev_mask = s->x86_prev_mask;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
836 uint32_t src;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
837 uint32_t dest;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
838 uint32_t j;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 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
840
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 if (size <= 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
842 return 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
843
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 size -= 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
845 for (i = 0; i < size; ++i) {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
846 if ((buf[i] & 0xFE) != 0xE8)
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
847 continue;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
848
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
849 prev_pos = i - prev_pos;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
850 if (prev_pos > 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
851 prev_mask = 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
852 } else {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
853 prev_mask = (prev_mask << (prev_pos - 1)) & 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
854 if (prev_mask != 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
855 b = buf[i + 4 - mask_to_bit_num[prev_mask]];
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
856 if (!mask_to_allowed_status[prev_mask]
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
857 || bcj_x86_test_msbyte(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
858 prev_pos = i;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
859 prev_mask = (prev_mask << 1) | 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
860 continue;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 prev_pos = i;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 if (bcj_x86_test_msbyte(buf[i + 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
868 src = get_unaligned_le32(buf + i + 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
869 while (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
870 dest = src - (s->pos + (uint32_t)i + 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
871 if (prev_mask == 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
872 break;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
873
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 j = mask_to_bit_num[prev_mask] * 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
875 b = (uint8_t)(dest >> (24 - j));
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
876 if (!bcj_x86_test_msbyte(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
877 break;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
878
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
879 src = dest ^ (((uint32_t)1 << (32 - j)) - 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
880 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
882 dest &= 0x01FFFFFF;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
883 dest |= (uint32_t)0 - (dest & 0x01000000);
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
884 put_unaligned_le32(dest, buf + i + 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
885 i += 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
886 } else {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
887 prev_mask = (prev_mask << 1) | 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
888 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
889 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 prev_pos = i - prev_pos;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
892 s->x86_prev_mask = prev_pos > 3 ? 0 : prev_mask << (prev_pos - 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
893 return i;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
894 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
897 #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
898 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
899 {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 size_t i;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 uint32_t instr;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
902
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
903 for (i = 0; i + 4 <= size; i += 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
904 instr = get_unaligned_be32(buf + i);
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 if ((instr & 0xFC000003) == 0x48000001) {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 instr &= 0x03FFFFFC;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
907 instr -= s->pos + (uint32_t)i;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
908 instr &= 0x03FFFFFC;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
909 instr |= 0x48000001;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 put_unaligned_be32(instr, buf + i);
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
911 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
912 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
913
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
914 return i;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
915 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
916 #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
917
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
918 #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
919 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
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 static const uint8_t branch_table[32] = {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 0, 0, 0, 0, 0, 0, 0, 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
923 0, 0, 0, 0, 0, 0, 0, 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
924 4, 4, 6, 6, 0, 0, 7, 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
925 4, 4, 0, 0, 4, 4, 0, 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
926 };
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
928 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
929 * The local variables take a little bit stack space, but it's less
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
930 * than what LZMA2 decoder takes, so it doesn't make sense to reduce
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
931 * stack usage here without doing that for the LZMA2 decoder 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
932 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
933
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
934 /* Loop counters */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
935 size_t i;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
936 size_t j;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /* Instruction slot (0, 1, or 2) in the 128-bit instruction word */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 uint32_t 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
940
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /* Bitwise offset of the instruction indicated by 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
942 uint32_t bit_pos;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
944 /* bit_pos split into byte and bit parts */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
945 uint32_t byte_pos;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
946 uint32_t bit_res;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
948 /* Address part of an 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
949 uint32_t addr;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
950
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
951 /* Mask used to detect which instructions to convert */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
952 uint32_t mask;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
953
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
954 /* 41-bit instruction stored somewhere in the lowest 48 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
955 uint64_t instr;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
956
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
957 /* Instruction normalized with bit_res for easier manipulation */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
958 uint64_t norm;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
959
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
960 for (i = 0; i + 16 <= size; i += 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
961 mask = branch_table[buf[i] & 0x1F];
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
962 for (slot = 0, bit_pos = 5; slot < 3; ++slot, bit_pos += 41) {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
963 if (((mask >> slot) & 1) == 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
964 continue;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
965
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
966 byte_pos = bit_pos >> 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
967 bit_res = bit_pos & 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
968 instr = 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
969 for (j = 0; j < 6; ++j)
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
970 instr |= (uint64_t)(buf[i + j + byte_pos])
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
971 << (8 * j);
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
972
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
973 norm = instr >> bit_res;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
974
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
975 if (((norm >> 37) & 0x0F) == 0x05
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
976 && ((norm >> 9) & 0x07) == 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
977 addr = (norm >> 13) & 0x0FFFFF;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
978 addr |= ((uint32_t)(norm >> 36) & 1) << 20;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
979 addr <<= 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
980 addr -= s->pos + (uint32_t)i;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
981 addr >>= 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
982
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
983 norm &= ~((uint64_t)0x8FFFFF << 13);
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
984 norm |= (uint64_t)(addr & 0x0FFFFF) << 13;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
985 norm |= (uint64_t)(addr & 0x100000)
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
986 << (36 - 20);
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
987
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
988 instr &= (1 << bit_res) - 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
989 instr |= norm << bit_res;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
990
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
991 for (j = 0; j < 6; j++)
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
992 buf[i + j + byte_pos]
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
993 = (uint8_t)(instr >> (8 * j));
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
994 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
995 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
996 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
997
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
998 return i;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
999 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1000 #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
1001
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1002 #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
1003 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
1004 {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1005 size_t i;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1006 uint32_t addr;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1007
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1008 for (i = 0; i + 4 <= size; i += 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
1009 if (buf[i + 3] == 0xEB) {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1010 addr = (uint32_t)buf[i] | ((uint32_t)buf[i + 1] << 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
1011 | ((uint32_t)buf[i + 2] << 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
1012 addr <<= 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
1013 addr -= s->pos + (uint32_t)i + 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
1014 addr >>= 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
1015 buf[i] = (uint8_t)addr;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1016 buf[i + 1] = (uint8_t)(addr >> 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
1017 buf[i + 2] = (uint8_t)(addr >> 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
1018 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1019 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1020
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1021 return i;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1022 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1023 #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
1024
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1025 #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
1026 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
1027 {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1028 size_t i;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1029 uint32_t addr;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1030
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1031 for (i = 0; i + 4 <= size; i += 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
1032 if ((buf[i + 1] & 0xF8) == 0xF0
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1033 && (buf[i + 3] & 0xF8) == 0xF8) {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1034 addr = (((uint32_t)buf[i + 1] & 0x07) << 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
1035 | ((uint32_t)buf[i] << 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
1036 | (((uint32_t)buf[i + 3] & 0x07) << 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
1037 | (uint32_t)buf[i + 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
1038 addr <<= 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
1039 addr -= s->pos + (uint32_t)i + 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
1040 addr >>= 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
1041 buf[i + 1] = (uint8_t)(0xF0 | ((addr >> 19) & 0x07));
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1042 buf[i] = (uint8_t)(addr >> 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
1043 buf[i + 3] = (uint8_t)(0xF8 | ((addr >> 8) & 0x07));
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1044 buf[i + 2] = (uint8_t)addr;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1045 i += 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
1046 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1047 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1048
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1049 return i;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1050 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1051 #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
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 #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
1054 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
1055 {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1056 size_t i;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1057 uint32_t instr;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1058
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1059 for (i = 0; i + 4 <= size; i += 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
1060 instr = get_unaligned_be32(buf + i);
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 if ((instr >> 22) == 0x100 || (instr >> 22) == 0x1FF) {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 instr <<= 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
1063 instr -= s->pos + (uint32_t)i;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 instr >>= 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
1065 instr = ((uint32_t)0x40000000 - (instr & 0x400000))
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 | 0x40000000 | (instr & 0x3FFFFF);
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1067 put_unaligned_be32(instr, buf + i);
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1070
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 return i;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1073 #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
1074
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1076 * 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
1077 * 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
1078 *
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1079 * 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
1080 * 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
1081 * 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
1082 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 static void bcj_apply(struct xz_dec_bcj *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
1084 uint8_t *buf, size_t *pos, 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
1085 {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1086 size_t 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
1087
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1088 buf += *pos;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1089 size -= *pos;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1090
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1091 switch (s->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
1092 #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
1093 case BCJ_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
1094 filtered = bcj_x86(s, buf, 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
1095 break;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1096 #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
1097 #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
1098 case BCJ_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
1099 filtered = bcj_powerpc(s, buf, 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
1100 break;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 #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
1103 case BCJ_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
1104 filtered = bcj_ia64(s, buf, 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
1105 break;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 #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
1107 #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
1108 case BCJ_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
1109 filtered = bcj_arm(s, buf, 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
1110 break;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 #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
1112 #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
1113 case BCJ_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
1114 filtered = bcj_armthumb(s, buf, 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
1115 break;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 #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
1117 #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
1118 case BCJ_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
1119 filtered = bcj_sparc(s, buf, 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
1120 break;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 #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
1122 default:
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /* Never reached but silence compiler warnings. */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 filtered = 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
1125 break;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 *pos += 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
1129 s->pos += 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
1130 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
1134 * 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
1135 * 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
1136 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 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
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 size_t copy_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
1140
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 copy_size = min_t(size_t, s->temp.filtered, b->out_size - b->out_pos);
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 memcpy(b->out + b->out_pos, s->temp.buf, copy_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
1143 b->out_pos += copy_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
1144
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1145 s->temp.filtered -= copy_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
1146 s->temp.size -= copy_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
1147 memmove(s->temp.buf, s->temp.buf + copy_size, 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
1148 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1149
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1150 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1151 * 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
1152 * 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
1153 * 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
1154 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 XZ_EXTERN enum xz_ret xz_dec_bcj_run(struct xz_dec_bcj *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
1156 struct xz_dec_lzma2 *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
1157 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
1158 {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 size_t out_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
1160
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * Flush pending already filtered data to the output buffer. 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
1163 * immediatelly if we couldn't flush everything, or if the next
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * filter in the chain had already returned XZ_STREAM_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
1165 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1166 if (s->temp.filtered > 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
1167 bcj_flush(s, 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
1168 if (s->temp.filtered > 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
1169 return XZ_OK;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1170
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1171 if (s->ret == XZ_STREAM_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
1172 return XZ_STREAM_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
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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * If we have more output space than what is currently pending 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
1177 * temp, copy the unfiltered 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
1178 * and try to fill the output buffer by decoding more data from 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
1179 * next filter in the chain. Apply the BCJ filter on the new 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
1180 * in the output buffer. If everything cannot be filtered, copy 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
1181 * to temp and rewind the output buffer position accordingly.
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 *
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1183 * This needs to be always run when temp.size == 0 to handle 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
1184 * case where the output buffer is full and the next filter has 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
1185 * more output coming but hasn't returned XZ_STREAM_END yet.
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 if (s->temp.size < b->out_size - b->out_pos || s->temp.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
1188 out_start = b->out_pos;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1189 memcpy(b->out + b->out_pos, s->temp.buf, 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
1190 b->out_pos += 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
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 s->ret = xz_dec_lzma2_run(lzma2, 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
1193 if (s->ret != XZ_STREAM_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
1194 && (s->ret != XZ_OK || s->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
1195 return s->ret;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 bcj_apply(s, b->out, &out_start, b->out_pos);
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * As an exception, if the next filter returned XZ_STREAM_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
1201 * we can do that too, since the last few bytes that remain
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * unfiltered are meant to remain 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
1203 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 if (s->ret == XZ_STREAM_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
1205 return XZ_STREAM_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
1206
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 s->temp.size = b->out_pos - out_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
1208 b->out_pos -= 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
1209 memcpy(s->temp.buf, b->out + b->out_pos, 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
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 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * If there wasn't enough input to the next filter to fill
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * the output buffer with unfiltered data, there's no point
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * to try decoding more data to 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
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 if (b->out_pos + s->temp.size < b->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
1217 return XZ_OK;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * We have unfiltered data in temp. If the output buffer isn't full
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * yet, try to fill the temp buffer by decoding more data from 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
1223 * next filter. Apply the BCJ filter on temp. Then we hopefully 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
1224 * fill the actual output buffer by copying filtered data from 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
1225 * A mix of filtered and unfiltered data may be left in temp; it 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
1226 * be taken care on the next call to 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
1227 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 if (b->out_pos < b->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
1229 /* Make b->out{,_pos,_size} temporarily point to s->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
1230 s->out = b->out;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 s->out_pos = b->out_pos;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 s->out_size = b->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
1233 b->out = s->temp.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
1234 b->out_pos = 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
1235 b->out_size = sizeof(s->temp.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
1236
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 s->ret = xz_dec_lzma2_run(lzma2, 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
1238
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 s->temp.size = b->out_pos;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 b->out = s->out;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 b->out_pos = s->out_pos;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 b->out_size = s->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
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 if (s->ret != XZ_OK && s->ret != XZ_STREAM_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
1245 return s->ret;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 bcj_apply(s, s->temp.buf, &s->temp.filtered, 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
1248
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1249 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1250 * If the next filter returned XZ_STREAM_END, we mark 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
1251 * everything is filtered, since the last unfiltered 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
1252 * of the stream are meant to be left as 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
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 if (s->ret == XZ_STREAM_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
1255 s->temp.filtered = 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
1256
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 bcj_flush(s, 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
1258 if (s->temp.filtered > 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
1259 return XZ_OK;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 return s->ret;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 XZ_EXTERN struct xz_dec_bcj *xz_dec_bcj_create(bool 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
1266 {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 struct xz_dec_bcj *s = malloc(sizeof(*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
1268 if (s != 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
1269 s->single_call = 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
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 return 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
1272 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 XZ_EXTERN enum xz_ret xz_dec_bcj_reset(struct xz_dec_bcj *s, uint8_t 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
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 switch (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
1277 #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
1278 case BCJ_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
1279 #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
1280 #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
1281 case BCJ_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
1282 #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
1283 #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
1284 case BCJ_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
1285 #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
1286 #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
1287 case BCJ_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
1288 #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
1289 #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
1290 case BCJ_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
1291 #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
1292 #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
1293 case BCJ_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
1294 #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
1295 break;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 default:
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /* Unsupported Filter 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
1299 return XZ_OPTIONS_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
1300 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 s->type = 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
1303 s->ret = XZ_OK;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 s->pos = 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
1305 s->x86_prev_mask = 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
1306 s->temp.filtered = 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
1307 s->temp.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
1308
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 return XZ_OK;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 #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
1313 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
1315 *
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * Authors: 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
1317 * Igor Pavlov <http://7-zip.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
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 * 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
1320 * 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
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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 // 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
1325 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
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 * Authors: 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
1329 * Igor Pavlov <http://7-zip.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
1330 *
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
1332 * 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
1333 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 #ifndef 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
1336 #define 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
1337
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1338 /* 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
1339 #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
1340 #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
1341 #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
1342 #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
1343 #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
1344 #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
1345
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1346 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1347 * 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
1348 * 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
1349 * 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
1350 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1351 #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
1352
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1353 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1354 * 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
1355 * 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
1356 *
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1357 * 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
1358 * - 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
1359 * - 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
1360 * - 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
1361 * - 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
1362 *
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1363 * 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
1364 * 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
1365 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1366 enum lzma_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
1367 STATE_LIT_LIT,
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1368 STATE_MATCH_LIT_LIT,
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1369 STATE_REP_LIT_LIT,
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1370 STATE_SHORTREP_LIT_LIT,
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1371 STATE_MATCH_LIT,
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1372 STATE_REP_LIT,
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1373 STATE_SHORTREP_LIT,
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1374 STATE_LIT_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
1375 STATE_LIT_LONGREP,
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1376 STATE_LIT_SHORTREP,
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1377 STATE_NONLIT_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
1378 STATE_NONLIT_REP
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1379 };
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1380
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1381 /* 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
1382 #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
1383
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1384 /* 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
1385 #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
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 /* 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
1388 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
1389 {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1390 if (*state <= STATE_SHORTREP_LIT_LIT)
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1391 *state = STATE_LIT_LIT;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1392 else if (*state <= STATE_LIT_SHORTREP)
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1393 *state -= 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
1394 else
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1395 *state -= 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
1396 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1397
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1398 /* 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
1399 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
1400 {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1401 *state = *state < LIT_STATES ? STATE_LIT_MATCH : STATE_NONLIT_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
1402 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1403
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1404 /* 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
1405 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
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 *state = *state < LIT_STATES ? STATE_LIT_LONGREP : STATE_NONLIT_REP;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1409
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1410 /* 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
1411 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
1412 {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1413 *state = *state < LIT_STATES ? STATE_LIT_SHORTREP : STATE_NONLIT_REP;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1414 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1415
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1416 /* Test if the previous 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
1417 static inline bool lzma_state_is_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
1418 {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1419 return state < LIT_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
1420 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1421
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1422 /* 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
1423 * - 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
1424 * - 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
1425 * - 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
1426 *
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1427 * 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
1428 * 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
1429 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1430 #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
1431
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1432 /* 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
1433 #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
1434
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1435 /* 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
1436 #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
1437
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1438 /* 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
1439 *
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1440 * 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
1441 * 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
1442 * 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
1443 * 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
1444 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1445 #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
1446 #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
1447 #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
1448 #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
1449 #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
1450 #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
1451 #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
1452
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1453 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1454 * 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
1455 * 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
1456 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1457 #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
1458
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1459 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1460 * 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
1461 * 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
1462 * 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
1463 * 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
1464 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1465 #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
1466
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1467 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1468 * 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
1469 * 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
1470 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1471 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
1472 {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1473 return len < DIST_STATES + MATCH_LEN_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
1474 ? len - MATCH_LEN_MIN : DIST_STATES - 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
1475 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1476
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1477 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1478 * 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
1479 * 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
1480 * 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
1481 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1482 #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
1483 #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
1484
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1485 /* 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
1486 * 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
1487 * 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
1488 * 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
1489 * 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
1490 * 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
1491 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1492 #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
1493
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1494 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1495 * 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
1496 * - 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
1497 * - 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
1498 * - 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
1499 *
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1500 * 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
1501 *
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1502 * 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
1503 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1504 #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
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 /* 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
1507 #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
1508 #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
1509
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1510 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1511 * 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
1512 * 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
1513 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1514 #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
1515 #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
1516 #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
1517
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1518 /* 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
1519 #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
1520
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1521 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1522 * 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
1523 * 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
1524 * 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
1525 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1526 #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
1527
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1528 #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
1529
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1530 // 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
1531
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1532 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1533 * 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
1534 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1535 #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
1536
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1537 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1538 * 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
1539 * 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
1540 * 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
1541 * 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
1542 * 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
1543 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 #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
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 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1547 * 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
1548 *
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1549 * 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
1550 * 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
1551 * 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
1552 *
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1553 * 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
1554 * 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
1555 * 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
1556 * 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
1557 *
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1558 * 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
1559 * 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
1560 * 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
1561 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1562 struct 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
1563 /* Beginning of the 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
1564 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
1565
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1566 /* Old position in buf (before decoding more 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
1567 size_t 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
1568
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /* Position in 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
1570 size_t pos;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * How full dictionary is. This is used to detect corrupt input 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
1574 * would read beyond the beginning of the uncompressed 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
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 size_t full;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /* Write limit; we don't write to buf[limit] or later 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
1579 size_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
1580
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1581 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1582 * End of the dictionary buffer. In multi-call mode, this 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
1583 * the same as the dictionary size. In single-call mode, 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
1584 * indicates the 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
1585 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1586 size_t 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
1587
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1588 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1589 * Size of the dictionary as specified in Block Header. This is 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
1590 * together with "full" to detect corrupt input that would make us
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * read beyond the beginning of the uncompressed 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
1592 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 uint32_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
1594
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1595 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1596 * Maximum allowed dictionary size 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
1597 * 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
1598 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 uint32_t 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
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 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1602 * Amount of memory currently allocated 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
1603 * This is used only with XZ_DYNALLOC. (With 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
1604 * size_max is always the same as the 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
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 uint32_t allocated;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /* 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
1609 enum xz_mode 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
1610 };
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /* 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
1613 struct rc_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
1614 uint32_t range;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1615 uint32_t 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
1616
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1617 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1618 * Number of initializing bytes remaining to be read
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1619 * by rc_read_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
1620 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 uint32_t init_bytes_left;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * Buffer from which we read our input. It can be either
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * temp.buf or the caller-provided 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
1626 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 const uint8_t *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
1628 size_t in_pos;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1629 size_t in_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
1630 };
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1631
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /* 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
1633 struct lzma_len_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
1634 /* Probability of match length being at least 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
1635 uint16_t choice;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /* Probability of match length being at least 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
1638 uint16_t choice2;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1639
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /* Probabilities for match lengths 2-9 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1641 uint16_t low[POS_STATES_MAX][LEN_LOW_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
1642
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1643 /* Probabilities for match lengths 10-17 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1644 uint16_t mid[POS_STATES_MAX][LEN_MID_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
1645
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1646 /* Probabilities for match lengths 18-273 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1647 uint16_t high[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
1648 };
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1649
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1650 struct lzma_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
1651 /* Distances of latest four matches */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1652 uint32_t 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
1653 uint32_t rep1;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1654 uint32_t rep2;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1655 uint32_t rep3;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1656
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1657 /* Types of the most recently seen LZMA 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
1658 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
1659
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1660 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1661 * Length of a match. This is updated so that dict_repeat 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
1662 * be called again to finish repeating the whole 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
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 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
1665
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1667 * LZMA properties or related bit masks (number of 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
1668 * context bits, a mask dervied from the number of 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
1669 * position bits, and a mask dervied from the number
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1670 * position 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
1671 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1672 uint32_t lc;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1673 uint32_t literal_pos_mask; /* (1 << lp) - 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
1674 uint32_t pos_mask; /* (1 << pb) - 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
1675
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1676 /* If 1, it's a match. Otherwise it's a single 8-bit 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
1677 uint16_t is_match[STATES][POS_STATES_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
1678
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1679 /* If 1, it's a repeated match. The distance is one of rep0 .. rep3. */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1680 uint16_t is_rep[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
1681
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1682 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1683 * If 0, distance of a repeated match is 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
1684 * Otherwise check is_rep1.
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1685 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1686 uint16_t is_rep0[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
1687
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1688 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1689 * If 0, distance of a repeated match is rep1.
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1690 * Otherwise check is_rep2.
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1691 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1692 uint16_t is_rep1[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
1693
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1694 /* If 0, distance of a repeated match is rep2. Otherwise it is rep3. */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1695 uint16_t is_rep2[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
1696
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1697 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1698 * If 1, the repeated match has length of one byte. 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
1699 * the length is decoded from rep_len_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
1700 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 uint16_t is_rep0_long[STATES][POS_STATES_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
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 * Probability tree for the highest two bits of the 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
1705 * distance. There is a separate probability tree for 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
1706 * lengths of 2 (i.e. MATCH_LEN_MIN), 3, 4, and [5, 273].
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 uint16_t dist_slot[DIST_STATES][DIST_SLOTS];
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1710 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1711 * Probility trees for additional bits for match 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
1712 * when the distance is in the range [4, 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
1713 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1714 uint16_t dist_special[FULL_DISTANCES - DIST_MODEL_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
1715
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1716 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1717 * Probability tree for the lowest four bits of 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
1718 * distance that is equal to or greater than 128.
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1719 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1720 uint16_t dist_align[ALIGN_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
1721
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1722 /* Length of a normal 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
1723 struct lzma_len_dec match_len_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
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 /* Length of a 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
1726 struct lzma_len_dec rep_len_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
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 /* Probabilities of literals */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 uint16_t literal[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
1730 };
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1732 struct lzma2_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
1733 /* Position in 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
1734 enum lzma2_seq {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 SEQ_CONTROL,
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 SEQ_UNCOMPRESSED_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
1737 SEQ_UNCOMPRESSED_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
1738 SEQ_COMPRESSED_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
1739 SEQ_COMPRESSED_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
1740 SEQ_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
1741 SEQ_LZMA_PREPARE,
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 SEQ_LZMA_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
1743 SEQ_COPY
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1744 } sequence;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1745
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1746 /* Next position after decoding the compressed size of the 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
1747 enum lzma2_seq next_sequence;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1748
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1749 /* Uncompressed size of LZMA chunk (2 MiB at maximum) */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1750 uint32_t uncompressed;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * Compressed size of LZMA chunk or compressed/uncompressed
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1754 * size of uncompressed chunk (64 KiB at maximum)
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1756 uint32_t 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
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 * True if dictionary reset is needed. This is false 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
1760 * the first chunk (LZMA or uncompressed).
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 bool need_dict_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
1763
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1765 * True if new LZMA properties are needed. This is false
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * before the first 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
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 bool need_props;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1769 };
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1771 struct xz_dec_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
1772 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1773 * The order below is important on x86 to reduce code size 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
1774 * it shouldn't hurt on other platforms. Everything up to 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
1775 * including lzma.pos_mask are in the first 128 bytes on x86-32,
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * which allows using smaller instructions to access those
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * variables. On x86-64, fewer variables fit into the first 128
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * bytes, but this is still the best order without sacrificing
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * the readability by splitting the structures.
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 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
1782 struct dictionary dict;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 struct lzma2_dec 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
1784 struct lzma_dec 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
1785
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * Temporary buffer which holds small number of input bytes between
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1788 * decoder calls. See lzma2_lzma() 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
1789 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1790 struct {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1791 uint32_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
1792 uint8_t buf[3 * LZMA_IN_REQUIRED];
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1793 } 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
1794 };
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1795
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1796 /**************
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1797 * 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
1798 **************/
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1799
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1800 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1801 * 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
1802 * 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
1803 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1804 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
1805 {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1806 if (DEC_IS_SINGLE(dict->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
1807 dict->buf = b->out + b->out_pos;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 dict->end = b->out_size - b->out_pos;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1810
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1811 dict->start = 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
1812 dict->pos = 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
1813 dict->limit = 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
1814 dict->full = 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
1815 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1816
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1817 /* 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
1818 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
1819 {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1820 if (dict->end - dict->pos <= 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
1821 dict->limit = dict->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
1822 else
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 dict->limit = dict->pos + 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
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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1826 /* Return true if at least one byte can be written 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
1827 static inline bool dict_has_space(const struct dictionary *dict)
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1828 {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 return dict->pos < 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
1830 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1831
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1832 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1833 * 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
1834 * 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
1835 * 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
1836 * 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
1837 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1838 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
1839 {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1840 size_t offset = dict->pos - dist - 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
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 if (dist >= dict->pos)
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 offset += dict->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
1844
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 return dict->full > 0 ? dict->buf[offset] : 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
1846 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1847
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1848 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1849 * 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
1850 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1851 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
1852 {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1853 dict->buf[dict->pos++] = 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
1854
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1855 if (dict->full < dict->pos)
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 dict->full = dict->pos;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
1861 * 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
1862 * 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
1863 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 static bool dict_repeat(struct dictionary *dict, uint32_t *len, 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
1865 {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1866 size_t back;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1867 uint32_t left;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1868
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 if (dist >= dict->full || dist >= dict->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
1870 return false;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 left = min_t(size_t, dict->limit - dict->pos, *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
1873 *len -= left;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1874
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1875 back = dict->pos - dist - 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
1876 if (dist >= dict->pos)
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1877 back += dict->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
1878
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1879 do {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1880 dict->buf[dict->pos++] = dict->buf[back++];
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1881 if (back == dict->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
1882 back = 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
1883 } while (--left > 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
1884
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1885 if (dict->full < dict->pos)
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1886 dict->full = dict->pos;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1887
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1888 return 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
1889 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1890
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1891 /* 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
1892 static void dict_uncompressed(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
1893 uint32_t *left)
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1894 {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1895 size_t copy_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
1896
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1897 while (*left > 0 && b->in_pos < b->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
1898 && b->out_pos < b->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
1899 copy_size = min(b->in_size - b->in_pos,
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1900 b->out_size - b->out_pos);
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1901 if (copy_size > dict->end - dict->pos)
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1902 copy_size = dict->end - dict->pos;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1903 if (copy_size > *left)
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1904 copy_size = *left;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1905
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1906 *left -= copy_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
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 memcpy(dict->buf + dict->pos, b->in + b->in_pos, copy_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
1909 dict->pos += copy_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
1910
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1911 if (dict->full < dict->pos)
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 dict->full = dict->pos;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1913
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1914 if (DEC_IS_MULTI(dict->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
1915 if (dict->pos == dict->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
1916 dict->pos = 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
1917
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1918 memcpy(b->out + b->out_pos, b->in + b->in_pos,
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1919 copy_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
1920 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1921
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1922 dict->start = dict->pos;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1923
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1924 b->out_pos += copy_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
1925 b->in_pos += copy_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
1926 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1927 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1928
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1929 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1930 * 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
1931 * 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
1932 * 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
1933 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 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
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 size_t copy_size = dict->pos - dict->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
1937
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 if (DEC_IS_MULTI(dict->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
1939 if (dict->pos == dict->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
1940 dict->pos = 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
1941
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1942 memcpy(b->out + b->out_pos, dict->buf + dict->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
1943 copy_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
1944 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1945
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1946 dict->start = dict->pos;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1947 b->out_pos += copy_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
1948 return copy_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
1949 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1950
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1951 /*****************
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1952 * 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
1953 *****************/
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1954
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1955 /* 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
1956 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
1957 {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1958 rc->range = (uint32_t)-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
1959 rc->code = 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
1960 rc->init_bytes_left = RC_INIT_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
1961 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1962
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1963 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1964 * 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
1965 * 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
1966 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1967 static bool rc_read_init(struct rc_dec *rc, 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
1968 {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1969 while (rc->init_bytes_left > 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
1970 if (b->in_pos == b->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
1971 return false;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1972
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 rc->code = (rc->code << 8) + b->in[b->in_pos++];
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 --rc->init_bytes_left;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 return 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
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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /* Return true if there may not be enough input for the next decoding loop. */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1981 static inline bool rc_limit_exceeded(const 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
1982 {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1983 return rc->in_pos > rc->in_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
1984 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1985
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1986 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1987 * 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
1988 * 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
1989 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1990 static inline bool rc_is_finished(const 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
1991 {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1992 return rc->code == 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
1993 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1994
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1995 /* Read the next input byte if 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
1996 static __always_inline void rc_normalize(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
1997 {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1998 if (rc->range < RC_TOP_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
1999 rc->range <<= RC_SHIFT_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
2000 rc->code = (rc->code << RC_SHIFT_BITS) + rc->in[rc->in_pos++];
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2001 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2002 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2003
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2004 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2005 * 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
2006 * 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
2007 * 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
2008 * 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
2009 * 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
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 * 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
2012 * 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
2013 * 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
2014 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2015 static __always_inline int rc_bit(struct rc_dec *rc, uint16_t *prob)
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2016 {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2017 uint32_t bound;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2018 int 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
2019
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2020 rc_normalize(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
2021 bound = (rc->range >> RC_BIT_MODEL_TOTAL_BITS) * *prob;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2022 if (rc->code < bound) {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2023 rc->range = bound;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2024 *prob += (RC_BIT_MODEL_TOTAL - *prob) >> RC_MOVE_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
2025 bit = 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
2026 } else {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2027 rc->range -= bound;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2028 rc->code -= bound;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2029 *prob -= *prob >> RC_MOVE_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
2030 bit = 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
2031 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2032
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2033 return 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
2034 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2035
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2036 /* Decode a bittree starting from the most significant 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
2037 static __always_inline uint32_t rc_bittree(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
2038 uint16_t *probs, 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
2039 {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2040 uint32_t symbol = 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
2041
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2042 do {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2043 if (rc_bit(rc, &probs[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
2044 symbol = (symbol << 1) + 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
2045 else
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2046 symbol <<= 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
2047 } while (symbol < 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
2048
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2049 return 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
2050 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2051
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /* Decode a bittree starting from the least significant 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
2053 static __always_inline void rc_bittree_reverse(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
2054 uint16_t *probs,
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 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
2056 {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 uint32_t symbol = 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
2058 uint32_t i = 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
2059
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2060 do {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2061 if (rc_bit(rc, &probs[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
2062 symbol = (symbol << 1) + 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
2063 *dest += 1 << i;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2064 } else {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2065 symbol <<= 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
2066 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2067 } while (++i < 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
2068 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2069
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2070 /* 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
2071 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
2072 {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2073 uint32_t mask;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2074
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2075 do {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2076 rc_normalize(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
2077 rc->range >>= 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
2078 rc->code -= rc->range;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2079 mask = (uint32_t)0 - (rc->code >> 31);
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2080 rc->code += rc->range & mask;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2081 *dest = (*dest << 1) + (mask + 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
2082 } while (--limit > 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
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 * 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
2087 ********/
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /* 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
2090 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
2091 {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2092 uint32_t prev_byte = dict_get(&s->dict, 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
2093 uint32_t low = prev_byte >> (8 - s->lzma.lc);
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2094 uint32_t high = (s->dict.pos & s->lzma.literal_pos_mask) << s->lzma.lc;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2095 return s->lzma.literal[low + high];
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2096 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2097
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2098 /* 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
2099 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
2100 {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2101 uint16_t *probs;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2102 uint32_t 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
2103 uint32_t 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
2104 uint32_t match_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
2105 uint32_t offset;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2106 uint32_t i;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2107
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2108 probs = lzma_literal_probs(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
2109
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2110 if (lzma_state_is_literal(s->lzma.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
2111 symbol = rc_bittree(&s->rc, probs, 0x100);
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2112 } else {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2113 symbol = 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
2114 match_byte = dict_get(&s->dict, s->lzma.rep0) << 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
2115 offset = 0x100;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2116
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2117 do {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2118 match_bit = match_byte & offset;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 match_byte <<= 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
2120 i = offset + match_bit + 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
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 if (rc_bit(&s->rc, &probs[i])) {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 symbol = (symbol << 1) + 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
2124 offset &= match_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
2125 } else {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 symbol <<= 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
2127 offset &= ~match_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
2128 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 } while (symbol < 0x100);
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 dict_put(&s->dict, (uint8_t)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
2133 lzma_state_literal(&s->lzma.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
2134 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /* 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
2137 static void lzma_len(struct xz_dec_lzma2 *s, struct lzma_len_dec *l,
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 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
2139 {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2140 uint16_t *probs;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2141 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
2142
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2143 if (!rc_bit(&s->rc, &l->choice)) {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2144 probs = l->low[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
2145 limit = LEN_LOW_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
2146 s->lzma.len = MATCH_LEN_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
2147 } else {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2148 if (!rc_bit(&s->rc, &l->choice2)) {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2149 probs = l->mid[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
2150 limit = LEN_MID_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
2151 s->lzma.len = MATCH_LEN_MIN + LEN_LOW_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
2152 } else {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2153 probs = l->high;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2154 limit = 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
2155 s->lzma.len = MATCH_LEN_MIN + LEN_LOW_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
2156 + LEN_MID_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
2157 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2158 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2159
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2160 s->lzma.len += rc_bittree(&s->rc, probs, limit) - 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
2161 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2162
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2163 /* 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
2164 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
2165 {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2166 uint16_t *probs;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2167 uint32_t dist_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
2168 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
2169
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2170 lzma_state_match(&s->lzma.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
2171
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2172 s->lzma.rep3 = s->lzma.rep2;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2173 s->lzma.rep2 = s->lzma.rep1;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2174 s->lzma.rep1 = 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
2175
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2176 lzma_len(s, &s->lzma.match_len_dec, 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
2177
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2178 probs = s->lzma.dist_slot[lzma_get_dist_state(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
2179 dist_slot = rc_bittree(&s->rc, probs, DIST_SLOTS) - DIST_SLOTS;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2180
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2181 if (dist_slot < 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
2182 s->lzma.rep0 = dist_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
2183 } else {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2184 limit = (dist_slot >> 1) - 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
2185 s->lzma.rep0 = 2 + (dist_slot & 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
2186
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2187 if (dist_slot < DIST_MODEL_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
2188 s->lzma.rep0 <<= 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
2189 probs = s->lzma.dist_special + 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
2190 - dist_slot - 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
2191 rc_bittree_reverse(&s->rc, probs,
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2192 &s->lzma.rep0, 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
2193 } else {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2194 rc_direct(&s->rc, &s->lzma.rep0, limit - 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
2195 s->lzma.rep0 <<= 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
2196 rc_bittree_reverse(&s->rc, s->lzma.dist_align,
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2197 &s->lzma.rep0, 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
2198 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2199 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2200 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2201
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2202 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2203 * 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
2204 * 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
2205 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2206 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
2207 {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2208 uint32_t tmp;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2209
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2210 if (!rc_bit(&s->rc, &s->lzma.is_rep0[s->lzma.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
2211 if (!rc_bit(&s->rc, &s->lzma.is_rep0_long[
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2212 s->lzma.state][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
2213 lzma_state_short_rep(&s->lzma.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
2214 s->lzma.len = 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
2215 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
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 } else {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 if (!rc_bit(&s->rc, &s->lzma.is_rep1[s->lzma.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
2219 tmp = s->lzma.rep1;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 } else {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2221 if (!rc_bit(&s->rc, &s->lzma.is_rep2[s->lzma.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
2222 tmp = s->lzma.rep2;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 } else {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2224 tmp = s->lzma.rep3;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2225 s->lzma.rep3 = s->lzma.rep2;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2226 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2227
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2228 s->lzma.rep2 = s->lzma.rep1;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2229 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2230
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2231 s->lzma.rep1 = 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
2232 s->lzma.rep0 = tmp;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2233 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2234
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2235 lzma_state_long_rep(&s->lzma.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
2236 lzma_len(s, &s->lzma.rep_len_dec, 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
2237 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2238
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2239 /* LZMA decoder core */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2240 static bool lzma_main(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
2241 {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2242 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
2243
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2244 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2245 * If the dictionary was reached during the previous call, try 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
2246 * finish the possibly pending repeat in 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
2247 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2248 if (dict_has_space(&s->dict) && s->lzma.len > 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
2249 dict_repeat(&s->dict, &s->lzma.len, 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
2250
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2251 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2252 * Decode more LZMA symbols. One iteration may consume up 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
2253 * LZMA_IN_REQUIRED - 1 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
2254 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2255 while (dict_has_space(&s->dict) && !rc_limit_exceeded(&s->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
2256 pos_state = s->dict.pos & s->lzma.pos_mask;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2257
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2258 if (!rc_bit(&s->rc, &s->lzma.is_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
2259 s->lzma.state][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
2260 lzma_literal(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
2261 } else {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2262 if (rc_bit(&s->rc, &s->lzma.is_rep[s->lzma.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
2263 lzma_rep_match(s, 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
2264 else
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2265 lzma_match(s, 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
2266
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2267 if (!dict_repeat(&s->dict, &s->lzma.len, 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
2268 return false;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2269 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2270 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2271
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2272 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2273 * Having the range decoder always normalized when we are outside
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2274 * this function makes it easier to correctly handle end of the 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
2275 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2276 rc_normalize(&s->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
2277
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2278 return 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
2279 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2280
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2281 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2282 * 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
2283 * 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
2284 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2285 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
2286 {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2287 uint16_t *probs;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2288 size_t i;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2289
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2290 s->lzma.state = STATE_LIT_LIT;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2291 s->lzma.rep0 = 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
2292 s->lzma.rep1 = 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
2293 s->lzma.rep2 = 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
2294 s->lzma.rep3 = 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
2295
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2296 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2297 * All probabilities are initialized to the same value. This hack
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2298 * makes the code smaller by avoiding a separate loop for each
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2299 * 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
2300 *
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2301 * This could be optimized so that only that part of 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
2302 * probabilities that are actually required. In the common case
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2303 * we would write 12 KiB less.
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2304 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2305 probs = s->lzma.is_match[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
2306 for (i = 0; i < PROBS_TOTAL; ++i)
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2307 probs[i] = RC_BIT_MODEL_TOTAL / 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
2308
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2309 rc_reset(&s->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
2310 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2311
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2312 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2313 * 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
2314 * 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
2315 * 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
2316 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2317 static bool lzma_props(struct xz_dec_lzma2 *s, uint8_t props)
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2318 {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2319 if (props > (4 * 5 + 4) * 9 + 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
2320 return false;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2321
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2322 s->lzma.pos_mask = 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
2323 while (props >= 9 * 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
2324 props -= 9 * 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
2325 ++s->lzma.pos_mask;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2326 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2327
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2328 s->lzma.pos_mask = (1 << s->lzma.pos_mask) - 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
2329
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2330 s->lzma.literal_pos_mask = 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
2331 while (props >= 9) {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2332 props -= 9;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2333 ++s->lzma.literal_pos_mask;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2334 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2335
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2336 s->lzma.lc = props;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2337
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2338 if (s->lzma.lc + s->lzma.literal_pos_mask > 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
2339 return false;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2340
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2341 s->lzma.literal_pos_mask = (1 << s->lzma.literal_pos_mask) - 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
2342
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2343 lzma_reset(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
2344
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2345 return 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
2346 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2347
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2348 /*********
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2349 * 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
2350 *********/
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2351
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2352 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2353 * 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
2354 * 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
2355 * 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
2356 *
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2357 * 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
2358 * 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
2359 * 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
2360 * 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
2361 * 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
2362 * 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
2363 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2364 static bool lzma2_lzma(struct xz_dec_lzma2 *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
2365 {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2366 size_t in_avail;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2367 uint32_t tmp;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2368
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2369 in_avail = b->in_size - b->in_pos;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2370 if (s->temp.size > 0 || s->lzma2.compressed == 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
2371 tmp = 2 * LZMA_IN_REQUIRED - 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
2372 if (tmp > s->lzma2.compressed - 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
2373 tmp = s->lzma2.compressed - 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
2374 if (tmp > in_avail)
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2375 tmp = in_avail;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2376
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2377 memcpy(s->temp.buf + s->temp.size, b->in + b->in_pos, tmp);
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2378
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2379 if (s->temp.size + tmp == s->lzma2.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
2380 memzero(s->temp.buf + s->temp.size + tmp,
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2381 sizeof(s->temp.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
2382 - s->temp.size - tmp);
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2383 s->rc.in_limit = s->temp.size + tmp;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2384 } else if (s->temp.size + tmp < LZMA_IN_REQUIRED) {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2385 s->temp.size += tmp;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2386 b->in_pos += tmp;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2387 return 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
2388 } else {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2389 s->rc.in_limit = s->temp.size + tmp - LZMA_IN_REQUIRED;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2390 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2391
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 s->rc.in = s->temp.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
2393 s->rc.in_pos = 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
2394
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2395 if (!lzma_main(s) || s->rc.in_pos > s->temp.size + tmp)
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 return false;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2397
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2398 s->lzma2.compressed -= s->rc.in_pos;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2399
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2400 if (s->rc.in_pos < 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
2401 s->temp.size -= s->rc.in_pos;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2402 memmove(s->temp.buf, s->temp.buf + s->rc.in_pos,
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2403 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
2404 return 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
2405 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2406
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2407 b->in_pos += s->rc.in_pos - 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
2408 s->temp.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
2409 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2410
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2411 in_avail = b->in_size - b->in_pos;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2412 if (in_avail >= LZMA_IN_REQUIRED) {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2413 s->rc.in = b->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
2414 s->rc.in_pos = b->in_pos;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2415
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 if (in_avail >= s->lzma2.compressed + LZMA_IN_REQUIRED)
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 s->rc.in_limit = b->in_pos + s->lzma2.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
2418 else
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 s->rc.in_limit = b->in_size - LZMA_IN_REQUIRED;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2420
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2421 if (!lzma_main(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
2422 return false;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2423
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2424 in_avail = s->rc.in_pos - b->in_pos;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2425 if (in_avail > s->lzma2.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
2426 return false;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2427
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2428 s->lzma2.compressed -= in_avail;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2429 b->in_pos = s->rc.in_pos;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2430 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2431
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2432 in_avail = b->in_size - b->in_pos;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2433 if (in_avail < LZMA_IN_REQUIRED) {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2434 if (in_avail > s->lzma2.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
2435 in_avail = s->lzma2.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
2436
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2437 memcpy(s->temp.buf, b->in + b->in_pos, in_avail);
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2438 s->temp.size = in_avail;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2439 b->in_pos += in_avail;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2440 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2441
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2442 return 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
2443 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2444
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2445 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2446 * 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
2447 * 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
2448 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2449 XZ_EXTERN enum xz_ret xz_dec_lzma2_run(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
2450 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
2451 {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2452 uint32_t tmp;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 while (b->in_pos < b->in_size || s->lzma2.sequence == SEQ_LZMA_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
2455 switch (s->lzma2.sequence) {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 case SEQ_CONTROL:
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * LZMA2 control 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
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 * Exact 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
2461 * 0x00 End marker
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 0x01 Dictionary reset followed by
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * an uncompressed 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
2464 * 0x02 Uncompressed chunk (no dictionary 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
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 * Highest three bits (s->control & 0xE0):
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 0xE0 Dictionary reset, new properties and 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
2468 * reset, followed by LZMA compressed 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
2469 * 0xC0 New properties and state reset, followed
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * by LZMA compressed chunk (no 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
2471 * 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
2472 * 0xA0 State reset using old 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
2473 * followed by LZMA compressed chunk (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
2474 * dictionary 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
2475 * 0x80 LZMA chunk (no dictionary or state 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
2476 *
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * For LZMA compressed chunks, the lowest five 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
2478 * (s->control & 1F) are the highest bits of 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
2479 * uncompressed size (bits 16-20).
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 *
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * A new LZMA2 stream must begin with a 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
2482 * reset. The first LZMA chunk must set 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
2483 * properties and reset the LZMA 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
2484 *
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * Values that don't match anything 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
2486 * are invalid and we return 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
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 tmp = b->in[b->in_pos++];
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 if (tmp == 0x00)
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 return XZ_STREAM_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
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 if (tmp >= 0xE0 || tmp == 0x01) {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 s->lzma2.need_props = 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
2495 s->lzma2.need_dict_reset = false;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 dict_reset(&s->dict, 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
2497 } else if (s->lzma2.need_dict_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
2498 return 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
2499 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2500
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2501 if (tmp >= 0x80) {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 s->lzma2.uncompressed = (tmp & 0x1F) << 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
2503 s->lzma2.sequence = SEQ_UNCOMPRESSED_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
2504
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 if (tmp >= 0xC0) {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * When there are new 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
2508 * state reset is done 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
2509 * SEQ_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
2510 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 s->lzma2.need_props = false;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2512 s->lzma2.next_sequence
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2513 = SEQ_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
2514
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 } else if (s->lzma2.need_props) {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 return 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
2517
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2518 } else {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2519 s->lzma2.next_sequence
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2520 = SEQ_LZMA_PREPARE;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2521 if (tmp >= 0xA0)
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2522 lzma_reset(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
2523 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2524 } else {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2525 if (tmp > 0x02)
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2526 return 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
2527
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2528 s->lzma2.sequence = SEQ_COMPRESSED_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
2529 s->lzma2.next_sequence = SEQ_COPY;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2530 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2531
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2532 break;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2533
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2534 case SEQ_UNCOMPRESSED_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
2535 s->lzma2.uncompressed
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2536 += (uint32_t)b->in[b->in_pos++] << 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
2537 s->lzma2.sequence = SEQ_UNCOMPRESSED_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
2538 break;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2539
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2540 case SEQ_UNCOMPRESSED_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
2541 s->lzma2.uncompressed
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2542 += (uint32_t)b->in[b->in_pos++] + 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
2543 s->lzma2.sequence = SEQ_COMPRESSED_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
2544 break;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2545
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2546 case SEQ_COMPRESSED_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
2547 s->lzma2.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
2548 = (uint32_t)b->in[b->in_pos++] << 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
2549 s->lzma2.sequence = SEQ_COMPRESSED_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
2550 break;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2551
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2552 case SEQ_COMPRESSED_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
2553 s->lzma2.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
2554 += (uint32_t)b->in[b->in_pos++] + 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
2555 s->lzma2.sequence = s->lzma2.next_sequence;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2556 break;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2557
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2558 case SEQ_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
2559 if (!lzma_props(s, b->in[b->in_pos++]))
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2560 return 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
2561
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2562 s->lzma2.sequence = SEQ_LZMA_PREPARE;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2563
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2564 case SEQ_LZMA_PREPARE:
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2565 if (s->lzma2.compressed < RC_INIT_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
2566 return 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
2567
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2568 if (!rc_read_init(&s->rc, 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
2569 return XZ_OK;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2570
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2571 s->lzma2.compressed -= RC_INIT_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
2572 s->lzma2.sequence = SEQ_LZMA_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
2573
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2574 case SEQ_LZMA_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
2575 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2576 * Set dictionary limit to indicate how much we want
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2577 * to be encoded at maximum. Decode new data into 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
2578 * dictionary. Flush the new data from dictionary 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
2579 * b->out. Check if we finished decoding this 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
2580 * In case the dictionary got full but we didn't fill
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2581 * the output buffer yet, we may run this loop
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2582 * multiple times without changing s->lzma2.sequence.
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2583 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2584 dict_limit(&s->dict, min_t(size_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
2585 b->out_size - b->out_pos,
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2586 s->lzma2.uncompressed));
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2587 if (!lzma2_lzma(s, 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
2588 return 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
2589
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2590 s->lzma2.uncompressed -= dict_flush(&s->dict, 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
2591
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2592 if (s->lzma2.uncompressed == 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
2593 if (s->lzma2.compressed > 0 || s->lzma.len > 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
2594 || !rc_is_finished(&s->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
2595 return 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
2596
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2597 rc_reset(&s->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
2598 s->lzma2.sequence = SEQ_CONTROL;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2599
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2600 } else if (b->out_pos == b->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
2601 || (b->in_pos == b->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
2602 && 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
2603 < s->lzma2.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
2604 return XZ_OK;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2605 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2606
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2607 break;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2608
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2609 case SEQ_COPY:
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2610 dict_uncompressed(&s->dict, b, &s->lzma2.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
2611 if (s->lzma2.compressed > 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
2612 return XZ_OK;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2613
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2614 s->lzma2.sequence = SEQ_CONTROL;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2615 break;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2616 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2617 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2618
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2619 return XZ_OK;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2620 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2621
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2622 XZ_EXTERN struct xz_dec_lzma2 *xz_dec_lzma2_create(enum xz_mode 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
2623 uint32_t dict_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
2624 {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2625 struct xz_dec_lzma2 *s = malloc(sizeof(*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
2626 if (s == 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
2627 return 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
2628
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 s->dict.mode = 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
2630 s->dict.size_max = dict_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
2631
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2632 if (DEC_IS_PREALLOC(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
2633 s->dict.buf = malloc(dict_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
2634 if (s->dict.buf == 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
2635 free(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
2636 return 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
2637 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2638 } else if (DEC_IS_DYNALLOC(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
2639 s->dict.buf = 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
2640 s->dict.allocated = 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
2641 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2642
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2643 return 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
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 XZ_EXTERN enum xz_ret xz_dec_lzma2_reset(struct xz_dec_lzma2 *s, uint8_t props)
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /* This limits dictionary size to 3 GiB to keep parsing simpler. */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 if (props > 39)
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 return XZ_OPTIONS_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
2651
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2652 s->dict.size = 2 + (props & 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
2653 s->dict.size <<= (props >> 1) + 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
2654
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2655 if (DEC_IS_MULTI(s->dict.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
2656 if (s->dict.size > s->dict.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
2657 return XZ_MEMLIMIT_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
2658
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2659 s->dict.end = s->dict.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
2660
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2661 if (DEC_IS_DYNALLOC(s->dict.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
2662 if (s->dict.allocated < s->dict.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
2663 free(s->dict.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
2664 s->dict.buf = malloc(s->dict.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
2665 if (s->dict.buf == 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
2666 s->dict.allocated = 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
2667 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
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 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2671 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2673 s->lzma.len = 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
2674
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2675 s->lzma2.sequence = SEQ_CONTROL;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2676 s->lzma2.need_dict_reset = 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
2677
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2678 s->temp.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
2679
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2680 return XZ_OK;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2681 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2682
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2683 XZ_EXTERN void xz_dec_lzma2_end(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
2684 {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2685 if (DEC_IS_MULTI(s->dict.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
2686 free(s->dict.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
2687
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2688 free(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
2689 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2690 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2691 * .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
2692 *
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2693 * 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
2694 *
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2695 * 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
2696 * 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
2697 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2698
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 // 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
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 * 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
2703 *
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
2705 *
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
2707 * 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
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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 #ifndef 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
2711 #define 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
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 #if defined(__KERNEL__) && !XZ_INTERNAL_CRC32
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 # include <linux/crc32.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
2715 # undef crc32
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2716 # define xz_crc32(buf, size, crc) \
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2717 (~crc32_le(~(uint32_t)(crc), buf, 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
2718 #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
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 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2721 * 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
2722 * 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
2723 * 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
2724 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2725
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2726 #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
2727
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2728 #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
2729 #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
2730
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2731 #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
2732 #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
2733
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2734 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2735 * 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
2736 * 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
2737 *
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2738 * 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
2739 * 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
2740 * 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
2741 * 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
2742 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2743 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
2744
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2745 #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
2746 #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
2747
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2748 /* 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
2749 #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
2750
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2751 /* 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
2752 enum xz_check {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2753 XZ_CHECK_NONE = 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
2754 XZ_CHECK_CRC32 = 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
2755 XZ_CHECK_CRC64 = 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
2756 XZ_CHECK_SHA256 = 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
2757 };
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2758
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2759 /* 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
2760 #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
2761
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2762 #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
2763 // 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
2764
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2765 #ifdef XZ_USE_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
2766 # define IS_CRC64(check_type) ((check_type) == XZ_CHECK_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
2767 #else
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2768 # define IS_CRC64(check_type) false
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2769 #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
2770
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2771 /* 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
2772 struct xz_dec_hash {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2773 vli_type unpadded;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2774 vli_type uncompressed;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2775 uint32_t crc32;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2776 };
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 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
2779 /* Position in dec_main() */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 enum {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 SEQ_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
2782 SEQ_BLOCK_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
2783 SEQ_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
2784 SEQ_BLOCK_UNCOMPRESS,
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 SEQ_BLOCK_PADDING,
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 SEQ_BLOCK_CHECK,
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 SEQ_INDEX,
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 SEQ_INDEX_PADDING,
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 SEQ_INDEX_CRC32,
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 SEQ_STREAM_FOOTER
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 } sequence;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /* Position in variable-length integers and Check fields */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 uint32_t pos;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /* Variable-length integer decoded by dec_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
2797 vli_type 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
2798
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2799 /* Saved in_pos and out_pos */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2800 size_t in_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
2801 size_t out_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
2802
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2803 #ifdef XZ_USE_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
2804 /* CRC32 or CRC64 value in Block or CRC32 value in Index */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2805 uint64_t crc;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2806 #else
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2807 /* CRC32 value in Block or Index */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2808 uint32_t crc;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2809 #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
2810
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2811 /* Type of the integrity check calculated from uncompressed 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
2812 enum xz_check check_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
2813
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2814 /* 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
2815 enum xz_mode 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
2816
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2817 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2818 * True if the next call to xz_dec_run() is allowed to 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
2819 * 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
2820 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2821 bool allow_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
2822
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2823 /* Information stored in 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
2824 struct {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2825 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2826 * Value stored in the Compressed Size field, 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
2827 * VLI_UNKNOWN if Compressed Size is not present.
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2828 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2829 vli_type 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
2830
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2831 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2832 * Value stored in the Uncompressed Size field, 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
2833 * VLI_UNKNOWN if Uncompressed Size is not present.
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2834 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2835 vli_type uncompressed;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2836
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2837 /* Size of the Block Header 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
2838 uint32_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
2839 } 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
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 /* Information collected when decoding Blocks */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 struct {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /* Observed compressed size of the current Block */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 vli_type 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
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 /* Observed uncompressed size of the current Block */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2847 vli_type uncompressed;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2849 /* Number of Blocks decoded so far */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2850 vli_type count;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2851
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2852 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2853 * Hash calculated from the Block sizes. This is used 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
2854 * 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
2855 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2856 struct xz_dec_hash hash;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2857 } block;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2858
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2859 /* Variables needed when verifying 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
2860 struct {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2861 /* Position in dec_index() */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2862 enum {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2863 SEQ_INDEX_COUNT,
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 SEQ_INDEX_UNPADDED,
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 SEQ_INDEX_UNCOMPRESSED
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 } sequence;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /* Size of the Index in 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
2869 vli_type 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
2870
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /* Number of Records (matches block.count in valid files) */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2872 vli_type count;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2873
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2874 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2875 * Hash calculated from the Records (matches block.hash 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
2876 * valid files).
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2877 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2878 struct xz_dec_hash hash;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2879 } index;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2880
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2881 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * Temporary buffer needed to hold Stream Header, 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
2883 * and Stream Footer. The Block Header is the biggest (1 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
2884 * so we reserve space according to that. buf[] has to be aligned
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * to a multiple of four bytes; the size_t variables before 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
2886 * should guarantee 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
2887 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2888 struct {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2889 size_t pos;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2890 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
2891 uint8_t buf[1024];
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2892 } 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
2893
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2894 struct xz_dec_lzma2 *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
2895
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2896 #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
2897 struct xz_dec_bcj *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
2898 bool bcj_active;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2899 #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
2900 };
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2901
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2902 #ifdef XZ_DEC_ANY_CHECK
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2903 /* 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
2904 static const uint8_t check_sizes[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
2905 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
2906 4, 4, 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
2907 8, 8, 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
2908 16, 16, 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
2909 32, 32, 32,
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2910 64, 64, 64
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2911 };
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2912 #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
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 * 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
2916 * 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
2917 * 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
2918 * 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
2919 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2920 static bool fill_temp(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
2921 {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2922 size_t copy_size = min_t(size_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
2923 b->in_size - b->in_pos, s->temp.size - s->temp.pos);
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2924
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2925 memcpy(s->temp.buf + s->temp.pos, b->in + b->in_pos, copy_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
2926 b->in_pos += copy_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
2927 s->temp.pos += copy_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
2928
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2929 if (s->temp.pos == 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
2930 s->temp.pos = 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
2931 return 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
2932 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2933
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2934 return false;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2935 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2936
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2937 /* 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
2938 static enum xz_ret dec_vli(struct xz_dec *s, const uint8_t *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
2939 size_t *in_pos, size_t 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
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 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
2942
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 if (s->pos == 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
2944 s->vli = 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
2945
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2946 while (*in_pos < 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
2947 byte = in[*in_pos];
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2948 ++*in_pos;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2949
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2950 s->vli |= (vli_type)(byte & 0x7F) << s->pos;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2951
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2952 if ((byte & 0x80) == 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
2953 /* Don't allow non-minimal encodings. */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2954 if (byte == 0 && s->pos != 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
2955 return 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
2956
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2957 s->pos = 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
2958 return XZ_STREAM_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
2959 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2960
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2961 s->pos += 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
2962 if (s->pos == 7 * VLI_BYTES_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
2963 return 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
2964 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2965
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 return XZ_OK;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2967 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2968
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2969 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2970 * 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
2971 * 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
2972 * 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
2973 * (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
2974 * 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
2975 * 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
2976 *
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2977 * 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
2978 * 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
2979 * 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
2980 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2981 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
2982 {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2983 enum xz_ret ret;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2984
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2985 s->in_start = b->in_pos;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2986 s->out_start = b->out_pos;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2987
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2988 #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
2989 if (s->bcj_active)
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 ret = xz_dec_bcj_run(s->bcj, s->lzma2, 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
2991 else
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2992 #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
2993 ret = xz_dec_lzma2_run(s->lzma2, 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
2994
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2995 s->block.compressed += b->in_pos - s->in_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
2996 s->block.uncompressed += b->out_pos - s->out_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
2997
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2998 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2999 * There is no need to separately check for VLI_UNKNOWN, 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
3000 * the observed sizes are always smaller than VLI_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
3001 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3002 if (s->block.compressed > s->block_header.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
3003 || s->block.uncompressed
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3004 > s->block_header.uncompressed)
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3005 return 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
3006
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3007 if (s->check_type == XZ_CHECK_CRC32)
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3008 s->crc = xz_crc32(b->out + s->out_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
3009 b->out_pos - s->out_start, s->crc);
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 #ifdef XZ_USE_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
3011 else if (s->check_type == XZ_CHECK_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
3012 s->crc = xz_crc64(b->out + s->out_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
3013 b->out_pos - s->out_start, s->crc);
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3014 #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
3015
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3016 if (ret == XZ_STREAM_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
3017 if (s->block_header.compressed != VLI_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
3018 && s->block_header.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
3019 != s->block.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
3020 return 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
3021
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3022 if (s->block_header.uncompressed != VLI_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
3023 && s->block_header.uncompressed
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3024 != s->block.uncompressed)
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3025 return 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
3026
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3027 s->block.hash.unpadded += s->block_header.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
3028 + s->block.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
3029
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3030 #ifdef XZ_DEC_ANY_CHECK
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3031 s->block.hash.unpadded += check_sizes[s->check_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
3032 #else
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3033 if (s->check_type == XZ_CHECK_CRC32)
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3034 s->block.hash.unpadded += 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
3035 else if (IS_CRC64(s->check_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
3036 s->block.hash.unpadded += 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
3037 #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
3038
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3039 s->block.hash.uncompressed += s->block.uncompressed;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3040 s->block.hash.crc32 = xz_crc32(
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 (const uint8_t *)&s->block.hash,
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 sizeof(s->block.hash), s->block.hash.crc32);
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 ++s->block.count;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3045 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3046
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3047 return ret;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3048 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3049
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3050 /* 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
3051 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
3052 {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3053 size_t in_used = b->in_pos - s->in_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
3054 s->index.size += in_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
3055 s->crc = xz_crc32(b->in + s->in_start, in_used, s->crc);
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3056 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3057
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3058 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3059 * 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
3060 * 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
3061 * 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
3062 *
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3063 * 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
3064 * 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
3065 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3066 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
3067 {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3068 enum xz_ret ret;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3069
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3070 do {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3071 ret = dec_vli(s, b->in, &b->in_pos, b->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
3072 if (ret != XZ_STREAM_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
3073 index_update(s, 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
3074 return ret;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3075 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3076
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3077 switch (s->index.sequence) {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3078 case SEQ_INDEX_COUNT:
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3079 s->index.count = s->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
3080
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3081 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3082 * Validate that the Number of Records 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
3083 * indicates the same number of Records 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
3084 * there were Blocks in 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
3085 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3086 if (s->index.count != s->block.count)
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3087 return 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
3088
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3089 s->index.sequence = SEQ_INDEX_UNPADDED;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3090 break;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3091
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3092 case SEQ_INDEX_UNPADDED:
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3093 s->index.hash.unpadded += s->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
3094 s->index.sequence = SEQ_INDEX_UNCOMPRESSED;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3095 break;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3096
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3097 case SEQ_INDEX_UNCOMPRESSED:
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3098 s->index.hash.uncompressed += s->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
3099 s->index.hash.crc32 = xz_crc32(
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3100 (const uint8_t *)&s->index.hash,
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3101 sizeof(s->index.hash),
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3102 s->index.hash.crc32);
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3103 --s->index.count;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3104 s->index.sequence = SEQ_INDEX_UNPADDED;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3105 break;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3106 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3107 } while (s->index.count > 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
3108
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3109 return XZ_STREAM_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
3110 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3111
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3112 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3113 * 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
3114 * 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
3115 * 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
3116 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3117 static enum xz_ret crc_validate(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
3118 uint32_t 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
3119 {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3120 do {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3121 if (b->in_pos == b->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
3122 return XZ_OK;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3123
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3124 if (((s->crc >> s->pos) & 0xFF) != b->in[b->in_pos++])
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3125 return 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
3126
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3127 s->pos += 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
3128
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3129 } while (s->pos < 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
3130
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3131 s->crc = 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
3132 s->pos = 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
3133
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3134 return XZ_STREAM_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
3135 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3136
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3137 #ifdef XZ_DEC_ANY_CHECK
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3138 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3139 * 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
3140 * 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
3141 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3142 static bool check_skip(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
3143 {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3144 while (s->pos < check_sizes[s->check_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
3145 if (b->in_pos == b->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
3146 return false;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3147
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3148 ++b->in_pos;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3149 ++s->pos;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3150 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3151
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3152 s->pos = 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
3153
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3154 return 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
3155 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3156 #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
3157
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3158 /* 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
3159 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
3160 {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3161 if (!memeq(s->temp.buf, HEADER_MAGIC, HEADER_MAGIC_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
3162 return XZ_FORMAT_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
3163
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3164 if (xz_crc32(s->temp.buf + HEADER_MAGIC_SIZE, 2, 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
3165 != get_le32(s->temp.buf + HEADER_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
3166 return 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
3167
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3168 if (s->temp.buf[HEADER_MAGIC_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
3169 return XZ_OPTIONS_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
3170
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3171 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3172 * Of integrity checks, we support none (Check ID = 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
3173 * CRC32 (Check ID = 1), and optionally CRC64 (Check ID = 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
3174 * However, if XZ_DEC_ANY_CHECK is defined, we will accept other
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3175 * check types too, but then the check won't be verified 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
3176 * a warning (XZ_UNSUPPORTED_CHECK) will be given.
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3177 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3178 s->check_type = s->temp.buf[HEADER_MAGIC_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
3179
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3180 #ifdef XZ_DEC_ANY_CHECK
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3181 if (s->check_type > XZ_CHECK_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
3182 return XZ_OPTIONS_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
3183
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3184 if (s->check_type > XZ_CHECK_CRC32 && !IS_CRC64(s->check_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
3185 return XZ_UNSUPPORTED_CHECK;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3186 #else
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3187 if (s->check_type > XZ_CHECK_CRC32 && !IS_CRC64(s->check_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
3188 return XZ_OPTIONS_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
3189 #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
3190
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3191 return XZ_OK;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3192 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3193
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3194 /* 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
3195 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
3196 {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3197 if (!memeq(s->temp.buf + 10, FOOTER_MAGIC, FOOTER_MAGIC_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
3198 return 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
3199
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3200 if (xz_crc32(s->temp.buf + 4, 6, 0) != get_le32(s->temp.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
3201 return 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
3202
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3203 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * Validate Backward Size. Note that we never added the size of 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
3205 * Index CRC32 field to s->index.size, thus we use s->index.size / 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
3206 * instead of s->index.size / 4 - 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
3207 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 if ((s->index.size >> 2) != get_le32(s->temp.buf + 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
3209 return 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
3210
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 if (s->temp.buf[8] != 0 || s->temp.buf[9] != s->check_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
3212 return 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
3213
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * Use XZ_STREAM_END instead of XZ_OK to be more convenient
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * for 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
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 return XZ_STREAM_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
3219 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /* 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
3222 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
3223 {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 enum xz_ret ret;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * Validate the CRC32. We know that the temp buffer is at least
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * eight bytes so this is 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
3229 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 s->temp.size -= 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
3231 if (xz_crc32(s->temp.buf, s->temp.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
3232 != get_le32(s->temp.buf + 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
3233 return 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
3234
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3235 s->temp.pos = 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
3236
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3237 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3238 * Catch unsupported Block Flags. We support only one or two 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
3239 * in the chain, so we catch that with the same test.
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3240 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3241 #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
3242 if (s->temp.buf[1] & 0x3E)
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3243 #else
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3244 if (s->temp.buf[1] & 0x3F)
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3245 #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
3246 return XZ_OPTIONS_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
3247
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3248 /* Compressed 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
3249 if (s->temp.buf[1] & 0x40) {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3250 if (dec_vli(s, s->temp.buf, &s->temp.pos, 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
3251 != XZ_STREAM_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
3252 return 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
3253
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3254 s->block_header.compressed = s->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
3255 } else {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3256 s->block_header.compressed = VLI_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
3257 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3258
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3259 /* 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
3260 if (s->temp.buf[1] & 0x80) {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3261 if (dec_vli(s, s->temp.buf, &s->temp.pos, 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
3262 != XZ_STREAM_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
3263 return 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
3264
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 s->block_header.uncompressed = s->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
3266 } else {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3267 s->block_header.uncompressed = VLI_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
3268 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3269
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3270 #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
3271 /* If there are two filters, the first one must be a BCJ 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
3272 s->bcj_active = s->temp.buf[1] & 0x01;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3273 if (s->bcj_active) {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 if (s->temp.size - s->temp.pos < 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
3275 return XZ_OPTIONS_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
3276
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3277 ret = xz_dec_bcj_reset(s->bcj, s->temp.buf[s->temp.pos++]);
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3278 if (ret != XZ_OK)
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 return ret;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3281 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3282 * We don't support custom start offset,
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3283 * so Size of Properties must be zero.
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3284 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3285 if (s->temp.buf[s->temp.pos++] != 0x00)
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3286 return XZ_OPTIONS_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
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 #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
3289
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3290 /* Valid Filter Flags always take at least 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
3291 if (s->temp.size - s->temp.pos < 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
3292 return 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
3293
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3294 /* Filter ID = 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
3295 if (s->temp.buf[s->temp.pos++] != 0x21)
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 return XZ_OPTIONS_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
3297
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /* Size of Properties = 1-byte 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
3299 if (s->temp.buf[s->temp.pos++] != 0x01)
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3300 return XZ_OPTIONS_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
3301
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3302 /* Filter Properties contains LZMA2 dictionary 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
3303 if (s->temp.size - s->temp.pos < 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
3304 return 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
3305
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3306 ret = xz_dec_lzma2_reset(s->lzma2, s->temp.buf[s->temp.pos++]);
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 if (ret != XZ_OK)
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 return ret;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3309
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /* The rest must be Header Padding. */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3311 while (s->temp.pos < 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
3312 if (s->temp.buf[s->temp.pos++] != 0x00)
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3313 return XZ_OPTIONS_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
3314
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3315 s->temp.pos = 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
3316 s->block.compressed = 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
3317 s->block.uncompressed = 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
3318
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3319 return XZ_OK;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3320 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3322 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
3323 {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3324 enum xz_ret ret;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3325
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3326 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3327 * Store the start position for the case when we are in the middle
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3328 * of 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
3329 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3330 s->in_start = b->in_pos;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3331
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3332 while (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
3333 switch (s->sequence) {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3334 case SEQ_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
3335 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3336 * Stream Header is copied to s->temp, and then
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3337 * decoded from there. This way if 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
3338 * gives us only little input at a time, 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
3339 * still keep the Stream Header decoding 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
3340 * simple. Similar approach is used in many places
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3341 * in 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
3342 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3343 if (!fill_temp(s, 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
3344 return XZ_OK;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3345
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3346 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3347 * If dec_stream_header() returns
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3348 * XZ_UNSUPPORTED_CHECK, it is still 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
3349 * to continue decoding if working in multi-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
3350 * mode. Thus, update s->sequence before calling
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3351 * dec_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
3352 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3353 s->sequence = SEQ_BLOCK_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
3354
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3355 ret = dec_stream_header(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
3356 if (ret != XZ_OK)
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3357 return ret;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3358
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3359 case SEQ_BLOCK_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
3360 /* We need one byte of input to continue. */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3361 if (b->in_pos == b->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
3362 return XZ_OK;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3363
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3364 /* See if this is the beginning of 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
3365 if (b->in[b->in_pos] == 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
3366 s->in_start = b->in_pos++;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3367 s->sequence = SEQ_INDEX;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3368 break;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3369 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3370
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3371 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3372 * Calculate the size of the Block Header 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
3373 * prepare to decode 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
3374 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3375 s->block_header.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
3376 = ((uint32_t)b->in[b->in_pos] + 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
3377
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3378 s->temp.size = s->block_header.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
3379 s->temp.pos = 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
3380 s->sequence = SEQ_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
3381
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3382 case SEQ_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
3383 if (!fill_temp(s, 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
3384 return XZ_OK;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3385
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3386 ret = dec_block_header(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
3387 if (ret != XZ_OK)
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3388 return ret;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3389
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3390 s->sequence = SEQ_BLOCK_UNCOMPRESS;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3391
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3392 case SEQ_BLOCK_UNCOMPRESS:
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3393 ret = dec_block(s, 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
3394 if (ret != XZ_STREAM_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
3395 return ret;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3396
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3397 s->sequence = SEQ_BLOCK_PADDING;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3398
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3399 case SEQ_BLOCK_PADDING:
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3400 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3401 * Size of Compressed Data + Block Padding
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3402 * must be a multiple of four. We don't need
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3403 * s->block.compressed for anything else
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3404 * anymore, so we use it here to test the 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
3405 * of the Block Padding 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
3406 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3407 while (s->block.compressed & 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
3408 if (b->in_pos == b->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
3409 return XZ_OK;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3410
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3411 if (b->in[b->in_pos++] != 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
3412 return 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
3413
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3414 ++s->block.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
3415 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3416
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3417 s->sequence = SEQ_BLOCK_CHECK;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3418
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3419 case SEQ_BLOCK_CHECK:
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3420 if (s->check_type == XZ_CHECK_CRC32) {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3421 ret = crc_validate(s, b, 32);
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3422 if (ret != XZ_STREAM_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
3423 return ret;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3424 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3425 else if (IS_CRC64(s->check_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
3426 ret = crc_validate(s, b, 64);
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3427 if (ret != XZ_STREAM_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
3428 return ret;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3429 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3430 #ifdef XZ_DEC_ANY_CHECK
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3431 else if (!check_skip(s, 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
3432 return XZ_OK;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3433 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3434 #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
3435
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3436 s->sequence = SEQ_BLOCK_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
3437 break;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3438
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3439 case SEQ_INDEX:
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3440 ret = dec_index(s, 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
3441 if (ret != XZ_STREAM_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
3442 return ret;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3443
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3444 s->sequence = SEQ_INDEX_PADDING;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3445
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3446 case SEQ_INDEX_PADDING:
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3447 while ((s->index.size + (b->in_pos - s->in_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
3448 & 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
3449 if (b->in_pos == b->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
3450 index_update(s, 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
3451 return XZ_OK;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3452 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3453
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3454 if (b->in[b->in_pos++] != 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
3455 return 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
3456 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3457
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3458 /* Finish the CRC32 value and Index 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
3459 index_update(s, 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
3460
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3461 /* Compare the hashes 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
3462 if (!memeq(&s->block.hash, &s->index.hash,
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3463 sizeof(s->block.hash)))
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3464 return 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
3465
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3466 s->sequence = SEQ_INDEX_CRC32;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3467
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3468 case SEQ_INDEX_CRC32:
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3469 ret = crc_validate(s, b, 32);
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3470 if (ret != XZ_STREAM_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
3471 return ret;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3472
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3473 s->temp.size = STREAM_HEADER_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
3474 s->sequence = SEQ_STREAM_FOOTER;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3475
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3476 case SEQ_STREAM_FOOTER:
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3477 if (!fill_temp(s, 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
3478 return XZ_OK;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3479
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3480 return dec_stream_footer(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
3481 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3482 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3483
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3484 /* Never 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
3485 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3486
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3487 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3488 * 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
3489 * 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
3490 *
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3491 * 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
3492 * 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
3493 * 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
3494 * 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
3495 * 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
3496 * 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
3497 * 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
3498 *
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3499 * 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
3500 * 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
3501 * 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
3502 * 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
3503 * 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
3504 * 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
3505 *
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3506 * 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
3507 * 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
3508 * 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
3509 * 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
3510 * 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
3511 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3512 XZ_EXTERN enum xz_ret xz_dec_run(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
3513 {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3514 size_t in_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
3515 size_t out_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
3516 enum xz_ret ret;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3517
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3518 if (DEC_IS_SINGLE(s->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
3519 xz_dec_reset(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
3520
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3521 in_start = b->in_pos;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3522 out_start = b->out_pos;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3523 ret = dec_main(s, 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
3524
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3525 if (DEC_IS_SINGLE(s->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
3526 if (ret == XZ_OK)
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3527 ret = b->in_pos == b->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
3528 ? XZ_DATA_ERROR : 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
3529
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3530 if (ret != XZ_STREAM_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
3531 b->in_pos = in_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
3532 b->out_pos = out_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
3533 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3534
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3535 } else if (ret == XZ_OK && in_start == b->in_pos
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3536 && out_start == b->out_pos) {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3537 if (s->allow_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
3538 ret = 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
3539
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3540 s->allow_buf_error = 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
3541 } else {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3542 s->allow_buf_error = false;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3543 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3544
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3545 return ret;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3546 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3547
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3548 XZ_EXTERN struct xz_dec *xz_dec_init(enum xz_mode mode, uint32_t dict_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
3549 {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3550 struct xz_dec *s = malloc(sizeof(*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
3551 if (s == 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
3552 return 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
3553
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3554 s->mode = 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
3555
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3556 #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
3557 s->bcj = xz_dec_bcj_create(DEC_IS_SINGLE(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
3558 if (s->bcj == 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
3559 goto 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
3560 #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
3561
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3562 s->lzma2 = xz_dec_lzma2_create(mode, dict_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
3563 if (s->lzma2 == 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
3564 goto 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
3565
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3566 xz_dec_reset(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
3567 return 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
3568
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3569 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
3570 #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
3571 xz_dec_bcj_end(s->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
3572 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
3573 #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
3574 free(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
3575 return 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
3576 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3577
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3578 XZ_EXTERN void xz_dec_reset(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
3579 {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3580 s->sequence = SEQ_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
3581 s->allow_buf_error = false;
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3582 s->pos = 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
3583 s->crc = 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
3584 memzero(&s->block, sizeof(s->block));
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3585 memzero(&s->index, sizeof(s->index));
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3586 s->temp.pos = 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
3587 s->temp.size = STREAM_HEADER_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
3588 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3589
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3590 XZ_EXTERN void xz_dec_end(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
3591 {
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3592 if (s != 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
3593 xz_dec_lzma2_end(s->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
3594 #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
3595 xz_dec_bcj_end(s->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
3596 #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
3597 free(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
3598 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3599 }