annotate toys/pending/xzcat.c @ 1183:0752b2d58909 draft

Rename xmsprintf() to just xmprintf(). Partly because there's no supplied target string ala sprintf, and partly because I can never remember what order the m and s go in.
author Rob Landley <rob@landley.net>
date Thu, 16 Jan 2014 09:26:50 -0600
parents e922fc4e7a2e
children
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
954
1cf9c28012a7 make xzcat use loopfiles(), thereby allowing regular usage.
Isaac Dunham <idunham@lavabit.com>
parents: 953
diff changeset
15 usage: xzcat [filename...]
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
16
954
1cf9c28012a7 make xzcat use loopfiles(), thereby allowing regular usage.
Isaac Dunham <idunham@lavabit.com>
parents: 953
diff changeset
17 Decompress listed files to stdout. Use stdin if no files listed.
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
18
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
19 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
20 #define FOR_xzcat
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
21 #include "toys.h"
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
22
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
23 // BEGIN xz.h
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
24
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
25 /**
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
26 * enum xz_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
27 * @XZ_OK: Everything is OK so far. More input or more
967
e922fc4e7a2e This removes xz_mode.
Isaac Dunham <idunham@lavabit.com>
parents: 954
diff changeset
28 * output space is required to continue.
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
29 * @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
30 * @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
31 * 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
32 * 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
33 * 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
34 * 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
35 * 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
36 * 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
37 * XZ_DEC_ANY_CHECK was not defined at build time.
967
e922fc4e7a2e This removes xz_mode.
Isaac Dunham <idunham@lavabit.com>
parents: 954
diff changeset
38 * @XZ_MEM_ERROR: Allocating memory failed. The amount of memory
e922fc4e7a2e This removes xz_mode.
Isaac Dunham <idunham@lavabit.com>
parents: 954
diff changeset
39 * that was tried to be allocated was no more than the
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
40 * 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
41 * @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
42 * allowed by the dict_max argument given to
967
e922fc4e7a2e This removes xz_mode.
Isaac Dunham <idunham@lavabit.com>
parents: 954
diff changeset
43 * xz_dec_init().
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
44 * @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
45 * 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
46 * @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
47 * 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
48 * 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
49 * 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
50 * @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
51 * @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
52 * 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
53 * 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
54 *
967
e922fc4e7a2e This removes xz_mode.
Isaac Dunham <idunham@lavabit.com>
parents: 954
diff changeset
55 * XZ_BUF_ERROR is returned when two consecutive calls to XZ code cannot
e922fc4e7a2e This removes xz_mode.
Isaac Dunham <idunham@lavabit.com>
parents: 954
diff changeset
56 * consume any input and cannot produce any new output. This happens when
e922fc4e7a2e This removes xz_mode.
Isaac Dunham <idunham@lavabit.com>
parents: 954
diff changeset
57 * there is no new input available, or the output buffer is full while at
e922fc4e7a2e This removes xz_mode.
Isaac Dunham <idunham@lavabit.com>
parents: 954
diff changeset
58 * least one output byte is still pending. Assuming your code is not buggy,
e922fc4e7a2e This removes xz_mode.
Isaac Dunham <idunham@lavabit.com>
parents: 954
diff changeset
59 * you can get this error only when decoding a compressed stream that is
e922fc4e7a2e This removes xz_mode.
Isaac Dunham <idunham@lavabit.com>
parents: 954
diff changeset
60 * truncated or otherwise corrupt.
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
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 enum xz_ret {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
63 XZ_OK,
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
64 XZ_STREAM_END,
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
65 XZ_UNSUPPORTED_CHECK,
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
66 XZ_MEM_ERROR,
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
67 XZ_MEMLIMIT_ERROR,
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
68 XZ_FORMAT_ERROR,
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
69 XZ_OPTIONS_ERROR,
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
70 XZ_DATA_ERROR,
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
71 XZ_BUF_ERROR
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
72 };
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /**
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
76 * @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
77 * 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
78 * @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
79 * 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
80 * @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
81 * @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
82 * 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
83 * @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
84 * 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
85 * @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
86 *
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
88 * 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
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 struct xz_buf {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
91 const uint8_t *in;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
92 size_t in_pos;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
93 size_t in_size;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
94
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
95 uint8_t *out;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
96 size_t out_pos;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
97 size_t out_size;
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
98 };
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
99
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /**
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
102 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 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
104
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
105 /**
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
107 * @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
108 * @dict_max: Maximum size of the LZMA2 dictionary (history buffer) for
967
e922fc4e7a2e This removes xz_mode.
Isaac Dunham <idunham@lavabit.com>
parents: 954
diff changeset
109 * multi-call decoding. LZMA2 dictionary is always 2^n bytes
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
110 * 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
111 * 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
112 * 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
113 * 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
114 * 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
115 * 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
116 *
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
117 * 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
118 * 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
119 * 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
120 * 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
121 * 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
122 *
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
124 * 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
125 * 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
126 */
967
e922fc4e7a2e This removes xz_mode.
Isaac Dunham <idunham@lavabit.com>
parents: 954
diff changeset
127 struct xz_dec *xz_dec_init(uint32_t dict_max);
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
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
129 /**
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
130 * 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
131 * @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
132 * @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
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 * 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
135 * 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
136 *
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
138 * 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
139 * 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
140 * 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
141 * 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
142 * 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
143 * 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
144 * 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
145 * 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
146 */
846
e02b4e932cd1 Some xzcat cleanup by Isaac Dunham.
Rob Landley <rob@landley.net>
parents: 819
diff changeset
147 enum xz_ret xz_dec_run(struct xz_dec *s, struct xz_buf *b);
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
148
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
149 /**
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
151 * @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
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 * 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
154 * 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
155 *
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 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
157 * 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
158 * 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
159 */
846
e02b4e932cd1 Some xzcat cleanup by Isaac Dunham.
Rob Landley <rob@landley.net>
parents: 819
diff changeset
160 void xz_dec_reset(struct xz_dec *s);
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
161
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /**
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
164 * @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
165 * 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
166 */
846
e02b4e932cd1 Some xzcat cleanup by Isaac Dunham.
Rob Landley <rob@landley.net>
parents: 819
diff changeset
167 void xz_dec_end(struct xz_dec *s);
e02b4e932cd1 Some xzcat cleanup by Isaac Dunham.
Rob Landley <rob@landley.net>
parents: 819
diff changeset
168
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
169 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
171 * 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
172 * 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
173 */
854
68cdd244f8b1 xzcat: more cleanup and some shrinking.
Isaac Dunham <idunham@lavabit.com>
parents: 851
diff changeset
174 static uint32_t xz_crc32_table[256];
68cdd244f8b1 xzcat: more cleanup and some shrinking.
Isaac Dunham <idunham@lavabit.com>
parents: 851
diff changeset
175
68cdd244f8b1 xzcat: more cleanup and some shrinking.
Isaac Dunham <idunham@lavabit.com>
parents: 851
diff changeset
176 uint32_t xz_crc32(const uint8_t *buf, size_t size, uint32_t crc)
68cdd244f8b1 xzcat: more cleanup and some shrinking.
Isaac Dunham <idunham@lavabit.com>
parents: 851
diff changeset
177 {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
178 crc = ~crc;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
179
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
180 while (size != 0) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
181 crc = xz_crc32_table[*buf++ ^ (crc & 0xFF)] ^ (crc >> 8);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
182 --size;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
183 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
184
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
185 return ~crc;
854
68cdd244f8b1 xzcat: more cleanup and some shrinking.
Isaac Dunham <idunham@lavabit.com>
parents: 851
diff changeset
186 }
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
187
850
fef134bc206c More of same.
Isaac Dunham <idunham@lavabit.com>
parents: 846
diff changeset
188 static uint64_t xz_crc64_table[256];
fef134bc206c More of same.
Isaac Dunham <idunham@lavabit.com>
parents: 846
diff changeset
189
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
190
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 // 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
192
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
193 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
194 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
195
954
1cf9c28012a7 make xzcat use loopfiles(), thereby allowing regular usage.
Isaac Dunham <idunham@lavabit.com>
parents: 953
diff changeset
196 void do_xzcat(int fd, char *name)
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
197 {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
198 struct xz_buf b;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
199 struct xz_dec *s;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
200 enum xz_ret ret;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
201 const char *msg;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
202
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
203 crc_init(xz_crc32_table, 1);
944
b4faf2ae39e8 This inlines CRC64, and nothing more.
Isaac Dunham <idunham@lavabit.com>
parents: 855
diff changeset
204 const uint64_t poly = 0xC96C5795D7870F42ULL;
b4faf2ae39e8 This inlines CRC64, and nothing more.
Isaac Dunham <idunham@lavabit.com>
parents: 855
diff changeset
205 uint32_t i;
b4faf2ae39e8 This inlines CRC64, and nothing more.
Isaac Dunham <idunham@lavabit.com>
parents: 855
diff changeset
206 uint32_t j;
b4faf2ae39e8 This inlines CRC64, and nothing more.
Isaac Dunham <idunham@lavabit.com>
parents: 855
diff changeset
207 uint64_t r;
b4faf2ae39e8 This inlines CRC64, and nothing more.
Isaac Dunham <idunham@lavabit.com>
parents: 855
diff changeset
208
b4faf2ae39e8 This inlines CRC64, and nothing more.
Isaac Dunham <idunham@lavabit.com>
parents: 855
diff changeset
209 /* initialize CRC64 table*/
b4faf2ae39e8 This inlines CRC64, and nothing more.
Isaac Dunham <idunham@lavabit.com>
parents: 855
diff changeset
210 for (i = 0; i < 256; ++i) {
b4faf2ae39e8 This inlines CRC64, and nothing more.
Isaac Dunham <idunham@lavabit.com>
parents: 855
diff changeset
211 r = i;
b4faf2ae39e8 This inlines CRC64, and nothing more.
Isaac Dunham <idunham@lavabit.com>
parents: 855
diff changeset
212 for (j = 0; j < 8; ++j)
b4faf2ae39e8 This inlines CRC64, and nothing more.
Isaac Dunham <idunham@lavabit.com>
parents: 855
diff changeset
213 r = (r >> 1) ^ (poly & ~((r & 1) - 1));
b4faf2ae39e8 This inlines CRC64, and nothing more.
Isaac Dunham <idunham@lavabit.com>
parents: 855
diff changeset
214
b4faf2ae39e8 This inlines CRC64, and nothing more.
Isaac Dunham <idunham@lavabit.com>
parents: 855
diff changeset
215 xz_crc64_table[i] = r;
b4faf2ae39e8 This inlines CRC64, and nothing more.
Isaac Dunham <idunham@lavabit.com>
parents: 855
diff changeset
216 }
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
217
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
218 /*
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
219 * Support up to 64 MiB dictionary. The actually needed memory
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
220 * is allocated once the headers have been parsed.
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
221 */
967
e922fc4e7a2e This removes xz_mode.
Isaac Dunham <idunham@lavabit.com>
parents: 954
diff changeset
222 s = xz_dec_init(1 << 26);
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
223 if (s == NULL) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
224 msg = "Memory allocation failed\n";
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
225 goto error;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
226 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
227
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
228 b.in = in;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
229 b.in_pos = 0;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
230 b.in_size = 0;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
231 b.out = out;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
232 b.out_pos = 0;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
233 b.out_size = BUFSIZ;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
234
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
235 for (;;) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
236 if (b.in_pos == b.in_size) {
954
1cf9c28012a7 make xzcat use loopfiles(), thereby allowing regular usage.
Isaac Dunham <idunham@lavabit.com>
parents: 953
diff changeset
237 b.in_size = read(fd, in, sizeof(in));
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
238 b.in_pos = 0;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
239 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
240
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
241 ret = xz_dec_run(s, &b);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
242
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
243 if (b.out_pos == sizeof(out)) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
244 if (fwrite(out, 1, b.out_pos, stdout) != b.out_pos) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
245 msg = "Write error\n";
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
246 goto error;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
247 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
248
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
249 b.out_pos = 0;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
250 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
251
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
252 if (ret == XZ_OK)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
253 continue;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
254
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
255 if (ret == XZ_UNSUPPORTED_CHECK)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
256 continue;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
257
954
1cf9c28012a7 make xzcat use loopfiles(), thereby allowing regular usage.
Isaac Dunham <idunham@lavabit.com>
parents: 953
diff changeset
258 if (fwrite(out, 1, b.out_pos, stdout) != b.out_pos) {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
259 msg = "Write error\n";
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
260 goto error;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
261 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
262
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
263 switch (ret) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
264 case XZ_STREAM_END:
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
265 xz_dec_end(s);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
266 return;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
267
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
268 case XZ_MEM_ERROR:
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
269 msg = "Memory allocation failed\n";
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
270 goto error;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
271
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
272 case XZ_MEMLIMIT_ERROR:
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
273 msg = "Memory usage limit reached\n";
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
274 goto error;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
275
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
276 case XZ_FORMAT_ERROR:
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
277 msg = "Not a .xz file\n";
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
278 goto error;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
279
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
280 case XZ_OPTIONS_ERROR:
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
281 msg = "Unsupported options in the .xz headers\n";
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
282 goto error;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
283
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
284 case XZ_DATA_ERROR:
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
285 case XZ_BUF_ERROR:
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
286 msg = "File is corrupt\n";
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
287 goto error;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
288
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
289 default:
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
290 msg = "Bug!\n";
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
291 goto error;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
292 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
293 }
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
294
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 error:
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
296 xz_dec_end(s);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
297 error_exit("%s", msg);
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
298 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
954
1cf9c28012a7 make xzcat use loopfiles(), thereby allowing regular usage.
Isaac Dunham <idunham@lavabit.com>
parents: 953
diff changeset
300 void xzcat_main(void)
1cf9c28012a7 make xzcat use loopfiles(), thereby allowing regular usage.
Isaac Dunham <idunham@lavabit.com>
parents: 953
diff changeset
301 {
1cf9c28012a7 make xzcat use loopfiles(), thereby allowing regular usage.
Isaac Dunham <idunham@lavabit.com>
parents: 953
diff changeset
302 loopfiles(toys.optargs, do_xzcat);
1cf9c28012a7 make xzcat use loopfiles(), thereby allowing regular usage.
Isaac Dunham <idunham@lavabit.com>
parents: 953
diff changeset
303 }
1cf9c28012a7 make xzcat use loopfiles(), thereby allowing regular usage.
Isaac Dunham <idunham@lavabit.com>
parents: 953
diff changeset
304
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
305 // BEGIN xz_private.h
850
fef134bc206c More of same.
Isaac Dunham <idunham@lavabit.com>
parents: 846
diff changeset
306
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
307
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /* 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
309 * 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
310 * */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 #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
313 #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
314 #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
315 #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
316 #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
317 #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
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 #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
321
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 #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
323 # 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
324 #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
325 #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
326
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /* 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
329 #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
330 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
331 {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
332 return (uint32_t)buf[0]
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
333 | ((uint32_t)buf[1] << 8)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
334 | ((uint32_t)buf[2] << 16)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
335 | ((uint32_t)buf[3] << 24);
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
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 #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
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 #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
340 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
341 {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
342 return (uint32_t)(buf[0] << 24)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
343 | ((uint32_t)buf[1] << 16)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
344 | ((uint32_t)buf[2] << 8)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
345 | (uint32_t)buf[3];
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
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 #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
348
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 #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
350 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
351 {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
352 buf[0] = (uint8_t)val;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
353 buf[1] = (uint8_t)(val >> 8);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
354 buf[2] = (uint8_t)(val >> 16);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
355 buf[3] = (uint8_t)(val >> 24);
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
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 #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
358
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 #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
360 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
361 {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
362 buf[0] = (uint8_t)(val >> 24);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
363 buf[1] = (uint8_t)(val >> 16);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
364 buf[2] = (uint8_t)(val >> 8);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
365 buf[3] = (uint8_t)val;
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
366 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 #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
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 * 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
371 * 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
372 * 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
373 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 #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
375 # 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
376 #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
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 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
380 * 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
381 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
382 #ifndef 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
383 # if defined(XZ_DEC_X86) || defined(XZ_DEC_POWERPC) \
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
384 || defined(XZ_DEC_IA64) || defined(XZ_DEC_ARM) \
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
385 || defined(XZ_DEC_ARM) || defined(XZ_DEC_ARMTHUMB) \
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
386 || defined(XZ_DEC_SPARC)
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
387 # 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
388 # 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
389 #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
390
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
393 * 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
394 */
967
e922fc4e7a2e This removes xz_mode.
Isaac Dunham <idunham@lavabit.com>
parents: 954
diff changeset
395 struct xz_dec_lzma2 *xz_dec_lzma2_create(uint32_t dict_max);
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
396
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
397 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
399 * 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
400 * 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
401 * 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
402 */
846
e02b4e932cd1 Some xzcat cleanup by Isaac Dunham.
Rob Landley <rob@landley.net>
parents: 819
diff changeset
403 enum xz_ret xz_dec_lzma2_reset(struct xz_dec_lzma2 *s,
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
404 uint8_t props);
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
405
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /* Decode raw LZMA2 stream from b->in to b->out. */
846
e02b4e932cd1 Some xzcat cleanup by Isaac Dunham.
Rob Landley <rob@landley.net>
parents: 819
diff changeset
407 enum xz_ret xz_dec_lzma2_run(struct xz_dec_lzma2 *s,
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
408 struct xz_buf *b);
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
409
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 // 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
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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * Branch/Call/Jump (BCJ) filter decoders
850
fef134bc206c More of same.
Isaac Dunham <idunham@lavabit.com>
parents: 846
diff changeset
417 * The rest of the code is inside this ifdef. It makes things a little more
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
418 * 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
419 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 #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
421
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 struct xz_dec_bcj {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
423 /* Type of the BCJ filter being used */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
424 enum {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
425 BCJ_X86 = 4, /* x86 or x86-64 */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
426 BCJ_POWERPC = 5, /* Big endian only */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
427 BCJ_IA64 = 6, /* Big or little endian */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
428 BCJ_ARM = 7, /* Little endian only */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
429 BCJ_ARMTHUMB = 8, /* Little endian only */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
430 BCJ_SPARC = 9 /* Big or little endian */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
431 } type;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
432
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
433 /*
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
434 * Return value of the next filter in the chain. We need to preserve
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
435 * this information across calls, because we must not call the next
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
436 * filter anymore once it has returned XZ_STREAM_END.
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
437 */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
438 enum xz_ret ret;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
439
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
440 /*
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
441 * Absolute position relative to the beginning of the uncompressed
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
442 * data (in a single .xz Block). We care only about the lowest 32
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
443 * bits so this doesn't need to be uint64_t even with big files.
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
444 */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
445 uint32_t pos;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
446
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
447 /* x86 filter state */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
448 uint32_t x86_prev_mask;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
449
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
450 /* Temporary space to hold the variables from struct xz_buf */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
451 uint8_t *out;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
452 size_t out_pos;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
453 size_t out_size;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
454
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
455 struct {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
456 /* Amount of already filtered data in the beginning of buf */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
457 size_t filtered;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
458
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
459 /* Total amount of data currently stored in buf */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
460 size_t size;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
461
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
462 /*
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
463 * Buffer to hold a mix of filtered and unfiltered data. This
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
464 * needs to be big enough to hold Alignment + 2 * Look-ahead:
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
465 *
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
466 * Type Alignment Look-ahead
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
467 * x86 1 4
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
468 * PowerPC 4 0
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
469 * IA-64 16 0
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
470 * ARM 4 0
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
471 * ARM-Thumb 2 2
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
472 * SPARC 4 0
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
473 */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
474 uint8_t buf[16];
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
475 } temp;
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
476 };
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
477
953
13916d161ec0 xzcat: remove XZ_(PREALLOC|SINGLE), inline xz_dec_bcj_create
Isaac Dunham <idunham@lavabit.com>
parents: 944
diff changeset
478 /*
13916d161ec0 xzcat: remove XZ_(PREALLOC|SINGLE), inline xz_dec_bcj_create
Isaac Dunham <idunham@lavabit.com>
parents: 944
diff changeset
479 * Decode the Filter ID of a BCJ filter. This implementation doesn't
13916d161ec0 xzcat: remove XZ_(PREALLOC|SINGLE), inline xz_dec_bcj_create
Isaac Dunham <idunham@lavabit.com>
parents: 944
diff changeset
480 * support custom start offsets, so no decoding of Filter Properties
13916d161ec0 xzcat: remove XZ_(PREALLOC|SINGLE), inline xz_dec_bcj_create
Isaac Dunham <idunham@lavabit.com>
parents: 944
diff changeset
481 * is needed. Returns XZ_OK if the given Filter ID is supported.
13916d161ec0 xzcat: remove XZ_(PREALLOC|SINGLE), inline xz_dec_bcj_create
Isaac Dunham <idunham@lavabit.com>
parents: 944
diff changeset
482 * Otherwise XZ_OPTIONS_ERROR is returned.
13916d161ec0 xzcat: remove XZ_(PREALLOC|SINGLE), inline xz_dec_bcj_create
Isaac Dunham <idunham@lavabit.com>
parents: 944
diff changeset
483 */
13916d161ec0 xzcat: remove XZ_(PREALLOC|SINGLE), inline xz_dec_bcj_create
Isaac Dunham <idunham@lavabit.com>
parents: 944
diff changeset
484 enum xz_ret xz_dec_bcj_reset(struct xz_dec_bcj *s, uint8_t id);
13916d161ec0 xzcat: remove XZ_(PREALLOC|SINGLE), inline xz_dec_bcj_create
Isaac Dunham <idunham@lavabit.com>
parents: 944
diff changeset
485
13916d161ec0 xzcat: remove XZ_(PREALLOC|SINGLE), inline xz_dec_bcj_create
Isaac Dunham <idunham@lavabit.com>
parents: 944
diff changeset
486 /*
13916d161ec0 xzcat: remove XZ_(PREALLOC|SINGLE), inline xz_dec_bcj_create
Isaac Dunham <idunham@lavabit.com>
parents: 944
diff changeset
487 * Decode raw BCJ + LZMA2 stream. This must be used only if there actually is
13916d161ec0 xzcat: remove XZ_(PREALLOC|SINGLE), inline xz_dec_bcj_create
Isaac Dunham <idunham@lavabit.com>
parents: 944
diff changeset
488 * a BCJ filter in the chain. If the chain has only LZMA2, xz_dec_lzma2_run()
13916d161ec0 xzcat: remove XZ_(PREALLOC|SINGLE), inline xz_dec_bcj_create
Isaac Dunham <idunham@lavabit.com>
parents: 944
diff changeset
489 * must be called directly.
13916d161ec0 xzcat: remove XZ_(PREALLOC|SINGLE), inline xz_dec_bcj_create
Isaac Dunham <idunham@lavabit.com>
parents: 944
diff changeset
490 */
13916d161ec0 xzcat: remove XZ_(PREALLOC|SINGLE), inline xz_dec_bcj_create
Isaac Dunham <idunham@lavabit.com>
parents: 944
diff changeset
491 enum xz_ret xz_dec_bcj_run(struct xz_dec_bcj *s,
13916d161ec0 xzcat: remove XZ_(PREALLOC|SINGLE), inline xz_dec_bcj_create
Isaac Dunham <idunham@lavabit.com>
parents: 944
diff changeset
492 struct xz_dec_lzma2 *lzma2,
13916d161ec0 xzcat: remove XZ_(PREALLOC|SINGLE), inline xz_dec_bcj_create
Isaac Dunham <idunham@lavabit.com>
parents: 944
diff changeset
493 struct xz_buf *b);
13916d161ec0 xzcat: remove XZ_(PREALLOC|SINGLE), inline xz_dec_bcj_create
Isaac Dunham <idunham@lavabit.com>
parents: 944
diff changeset
494
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
495 #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
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 * 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
498 * 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
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 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
501 {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
502 return b == 0x00 || b == 0xFF;
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
503 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
504
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
505 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
506 {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
507 static const int mask_to_allowed_status[8]
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
508 = { 1,1,1,0,1,0,0,0 };
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
509
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
510 static const uint8_t mask_to_bit_num[8] = { 0, 1, 2, 2, 3, 3, 3, 3 };
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
511
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
512 size_t i;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
513 size_t prev_pos = (size_t)-1;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
514 uint32_t prev_mask = s->x86_prev_mask;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
515 uint32_t src;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
516 uint32_t dest;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
517 uint32_t j;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
518 uint8_t b;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
519
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
520 if (size <= 4)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
521 return 0;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
522
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
523 size -= 4;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
524 for (i = 0; i < size; ++i) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
525 if ((buf[i] & 0xFE) != 0xE8)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
526 continue;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
527
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
528 prev_pos = i - prev_pos;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
529 if (prev_pos > 3) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
530 prev_mask = 0;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
531 } else {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
532 prev_mask = (prev_mask << (prev_pos - 1)) & 7;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
533 if (prev_mask != 0) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
534 b = buf[i + 4 - mask_to_bit_num[prev_mask]];
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
535 if (!mask_to_allowed_status[prev_mask]
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
536 || bcj_x86_test_msbyte(b)) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
537 prev_pos = i;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
538 prev_mask = (prev_mask << 1) | 1;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
539 continue;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
540 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
541 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
542 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
543
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
544 prev_pos = i;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
545
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
546 if (bcj_x86_test_msbyte(buf[i + 4])) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
547 src = get_unaligned_le32(buf + i + 1);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
548 for (;;) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
549 dest = src - (s->pos + (uint32_t)i + 5);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
550 if (prev_mask == 0)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
551 break;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
552
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
553 j = mask_to_bit_num[prev_mask] * 8;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
554 b = (uint8_t)(dest >> (24 - j));
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
555 if (!bcj_x86_test_msbyte(b))
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
556 break;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
557
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
558 src = dest ^ (((uint32_t)1 << (32 - j)) - 1);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
559 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
560
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
561 dest &= 0x01FFFFFF;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
562 dest |= (uint32_t)0 - (dest & 0x01000000);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
563 put_unaligned_le32(dest, buf + i + 1);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
564 i += 4;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
565 } else {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
566 prev_mask = (prev_mask << 1) | 1;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
567 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
568 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
569
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
570 prev_pos = i - prev_pos;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
571 s->x86_prev_mask = prev_pos > 3 ? 0 : prev_mask << (prev_pos - 1);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
572 return i;
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
573 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 #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
575
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 #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
577 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
578 {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
579 size_t i;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
580 uint32_t instr;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
581
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
582 for (i = 0; i + 4 <= size; i += 4) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
583 instr = get_unaligned_be32(buf + i);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
584 if ((instr & 0xFC000003) == 0x48000001) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
585 instr &= 0x03FFFFFC;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
586 instr -= s->pos + (uint32_t)i;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
587 instr &= 0x03FFFFFC;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
588 instr |= 0x48000001;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
589 put_unaligned_be32(instr, buf + i);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
590 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
591 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
592
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
593 return i;
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
594 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 #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
596
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 #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
598 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
599 {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
600 static const uint8_t branch_table[32] = {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
601 0, 0, 0, 0, 0, 0, 0, 0,
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
602 0, 0, 0, 0, 0, 0, 0, 0,
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
603 4, 4, 6, 6, 0, 0, 7, 7,
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
604 4, 4, 0, 0, 4, 4, 0, 0
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
605 };
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
606
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
607 /*
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
608 * The local variables take a little bit stack space, but it's less
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
609 * than what LZMA2 decoder takes, so it doesn't make sense to reduce
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
610 * stack usage here without doing that for the LZMA2 decoder too.
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
611 */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
612
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
613 /* Loop counters */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
614 size_t i;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
615 size_t j;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
616
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
617 /* Instruction slot (0, 1, or 2) in the 128-bit instruction word */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
618 uint32_t slot;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
619
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
620 /* Bitwise offset of the instruction indicated by slot */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
621 uint32_t bit_pos;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
622
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
623 /* bit_pos split into byte and bit parts */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
624 uint32_t byte_pos;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
625 uint32_t bit_res;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
626
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
627 /* Address part of an instruction */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
628 uint32_t addr;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
629
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
630 /* Mask used to detect which instructions to convert */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
631 uint32_t mask;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
632
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
633 /* 41-bit instruction stored somewhere in the lowest 48 bits */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
634 uint64_t instr;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
635
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
636 /* Instruction normalized with bit_res for easier manipulation */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
637 uint64_t norm;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
638
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
639 for (i = 0; i + 16 <= size; i += 16) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
640 mask = branch_table[buf[i] & 0x1F];
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
641 for (slot = 0, bit_pos = 5; slot < 3; ++slot, bit_pos += 41) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
642 if (((mask >> slot) & 1) == 0)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
643 continue;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
644
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
645 byte_pos = bit_pos >> 3;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
646 bit_res = bit_pos & 7;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
647 instr = 0;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
648 for (j = 0; j < 6; ++j)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
649 instr |= (uint64_t)(buf[i + j + byte_pos])
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
650 << (8 * j);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
651
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
652 norm = instr >> bit_res;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
653
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
654 if (((norm >> 37) & 0x0F) == 0x05
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
655 && ((norm >> 9) & 0x07) == 0) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
656 addr = (norm >> 13) & 0x0FFFFF;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
657 addr |= ((uint32_t)(norm >> 36) & 1) << 20;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
658 addr <<= 4;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
659 addr -= s->pos + (uint32_t)i;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
660 addr >>= 4;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
661
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
662 norm &= ~((uint64_t)0x8FFFFF << 13);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
663 norm |= (uint64_t)(addr & 0x0FFFFF) << 13;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
664 norm |= (uint64_t)(addr & 0x100000)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
665 << (36 - 20);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
666
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
667 instr &= (1 << bit_res) - 1;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
668 instr |= norm << bit_res;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
669
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
670 for (j = 0; j < 6; j++)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
671 buf[i + j + byte_pos]
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
672 = (uint8_t)(instr >> (8 * j));
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
673 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
674 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
675 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
676
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
677 return i;
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
678 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 #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
680
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 #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
682 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
683 {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
684 size_t i;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
685 uint32_t addr;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
686
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
687 for (i = 0; i + 4 <= size; i += 4) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
688 if (buf[i + 3] == 0xEB) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
689 addr = (uint32_t)buf[i] | ((uint32_t)buf[i + 1] << 8)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
690 | ((uint32_t)buf[i + 2] << 16);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
691 addr <<= 2;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
692 addr -= s->pos + (uint32_t)i + 8;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
693 addr >>= 2;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
694 buf[i] = (uint8_t)addr;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
695 buf[i + 1] = (uint8_t)(addr >> 8);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
696 buf[i + 2] = (uint8_t)(addr >> 16);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
697 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
698 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
699
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
700 return i;
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
701 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 #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
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 #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
705 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
706 {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
707 size_t i;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
708 uint32_t addr;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
709
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
710 for (i = 0; i + 4 <= size; i += 2) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
711 if ((buf[i + 1] & 0xF8) == 0xF0
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
712 && (buf[i + 3] & 0xF8) == 0xF8) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
713 addr = (((uint32_t)buf[i + 1] & 0x07) << 19)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
714 | ((uint32_t)buf[i] << 11)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
715 | (((uint32_t)buf[i + 3] & 0x07) << 8)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
716 | (uint32_t)buf[i + 2];
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
717 addr <<= 1;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
718 addr -= s->pos + (uint32_t)i + 4;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
719 addr >>= 1;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
720 buf[i + 1] = (uint8_t)(0xF0 | ((addr >> 19) & 0x07));
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
721 buf[i] = (uint8_t)(addr >> 11);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
722 buf[i + 3] = (uint8_t)(0xF8 | ((addr >> 8) & 0x07));
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
723 buf[i + 2] = (uint8_t)addr;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
724 i += 2;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
725 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
726 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
727
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
728 return i;
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
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 #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
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 #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
733 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
734 {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
735 size_t i;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
736 uint32_t instr;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
737
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
738 for (i = 0; i + 4 <= size; i += 4) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
739 instr = get_unaligned_be32(buf + i);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
740 if ((instr >> 22) == 0x100 || (instr >> 22) == 0x1FF) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
741 instr <<= 2;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
742 instr -= s->pos + (uint32_t)i;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
743 instr >>= 2;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
744 instr = ((uint32_t)0x40000000 - (instr & 0x400000))
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
745 | 0x40000000 | (instr & 0x3FFFFF);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
746 put_unaligned_be32(instr, buf + i);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
747 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
748 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
749
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
750 return i;
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
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 #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
753
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
756 * 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
757 *
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
759 * 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
760 * 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
761 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 static void bcj_apply(struct xz_dec_bcj *s,
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
763 uint8_t *buf, size_t *pos, size_t size)
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
764 {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
765 size_t filtered;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
766
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
767 buf += *pos;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
768 size -= *pos;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
769
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
770 switch (s->type) {
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
771 #ifdef XZ_DEC_X86
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
772 case BCJ_X86:
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
773 filtered = bcj_x86(s, buf, size);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
774 break;
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
775 #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
776 #ifdef XZ_DEC_POWERPC
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
777 case BCJ_POWERPC:
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
778 filtered = bcj_powerpc(s, buf, size);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
779 break;
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
780 #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
781 #ifdef XZ_DEC_IA64
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
782 case BCJ_IA64:
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
783 filtered = bcj_ia64(s, buf, size);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
784 break;
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
785 #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
786 #ifdef XZ_DEC_ARM
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
787 case BCJ_ARM:
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
788 filtered = bcj_arm(s, buf, size);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
789 break;
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
790 #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
791 #ifdef XZ_DEC_ARMTHUMB
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
792 case BCJ_ARMTHUMB:
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
793 filtered = bcj_armthumb(s, buf, size);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
794 break;
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
795 #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
796 #ifdef XZ_DEC_SPARC
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
797 case BCJ_SPARC:
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
798 filtered = bcj_sparc(s, buf, size);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
799 break;
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
800 #endif
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
801 default:
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
802 /* Never reached but silence compiler warnings. */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
803 filtered = 0;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
804 break;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
805 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
806
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
807 *pos += filtered;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
808 s->pos += filtered;
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
809 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
813 * 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
814 * 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
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 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
817 {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
818 size_t copy_size;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
819
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
820 copy_size = min_t(size_t, s->temp.filtered, b->out_size - b->out_pos);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
821 memcpy(b->out + b->out_pos, s->temp.buf, copy_size);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
822 b->out_pos += copy_size;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
823
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
824 s->temp.filtered -= copy_size;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
825 s->temp.size -= copy_size;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
826 memmove(s->temp.buf, s->temp.buf + copy_size, s->temp.size);
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
831 * 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
832 * 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
833 */
846
e02b4e932cd1 Some xzcat cleanup by Isaac Dunham.
Rob Landley <rob@landley.net>
parents: 819
diff changeset
834 enum xz_ret xz_dec_bcj_run(struct xz_dec_bcj *s,
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
835 struct xz_dec_lzma2 *lzma2,
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
836 struct xz_buf *b)
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
837 {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
838 size_t out_start;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
839
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
840 /*
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
841 * Flush pending already filtered data to the output buffer. Return
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
842 * immediatelly if we couldn't flush everything, or if the next
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
843 * filter in the chain had already returned XZ_STREAM_END.
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
844 */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
845 if (s->temp.filtered > 0) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
846 bcj_flush(s, b);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
847 if (s->temp.filtered > 0)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
848 return XZ_OK;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
849
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
850 if (s->ret == XZ_STREAM_END)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
851 return XZ_STREAM_END;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
852 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
853
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
854 /*
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
855 * If we have more output space than what is currently pending in
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
856 * temp, copy the unfiltered data from temp to the output buffer
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
857 * and try to fill the output buffer by decoding more data from the
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
858 * next filter in the chain. Apply the BCJ filter on the new data
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
859 * in the output buffer. If everything cannot be filtered, copy it
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
860 * to temp and rewind the output buffer position accordingly.
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
861 *
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
862 * This needs to be always run when temp.size == 0 to handle a special
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
863 * case where the output buffer is full and the next filter has no
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
864 * more output coming but hasn't returned XZ_STREAM_END yet.
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
865 */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
866 if (s->temp.size < b->out_size - b->out_pos || s->temp.size == 0) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
867 out_start = b->out_pos;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
868 memcpy(b->out + b->out_pos, s->temp.buf, s->temp.size);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
869 b->out_pos += s->temp.size;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
870
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
871 s->ret = xz_dec_lzma2_run(lzma2, b);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
872 if (s->ret != XZ_STREAM_END
953
13916d161ec0 xzcat: remove XZ_(PREALLOC|SINGLE), inline xz_dec_bcj_create
Isaac Dunham <idunham@lavabit.com>
parents: 944
diff changeset
873 && (s->ret != XZ_OK ))
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
874 return s->ret;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
875
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
876 bcj_apply(s, b->out, &out_start, b->out_pos);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
877
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
878 /*
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
879 * As an exception, if the next filter returned XZ_STREAM_END,
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
880 * we can do that too, since the last few bytes that remain
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
881 * unfiltered are meant to remain unfiltered.
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
882 */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
883 if (s->ret == XZ_STREAM_END)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
884 return XZ_STREAM_END;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
885
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
886 s->temp.size = b->out_pos - out_start;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
887 b->out_pos -= s->temp.size;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
888 memcpy(s->temp.buf, b->out + b->out_pos, s->temp.size);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
889
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
890 /*
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
891 * If there wasn't enough input to the next filter to fill
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
892 * the output buffer with unfiltered data, there's no point
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
893 * to try decoding more data to temp.
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
894 */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
895 if (b->out_pos + s->temp.size < b->out_size)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
896 return XZ_OK;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
897 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
898
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
899 /*
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
900 * We have unfiltered data in temp. If the output buffer isn't full
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
901 * yet, try to fill the temp buffer by decoding more data from the
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
902 * next filter. Apply the BCJ filter on temp. Then we hopefully can
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
903 * fill the actual output buffer by copying filtered data from temp.
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
904 * A mix of filtered and unfiltered data may be left in temp; it will
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
905 * be taken care on the next call to this function.
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
906 */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
907 if (b->out_pos < b->out_size) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
908 /* Make b->out{,_pos,_size} temporarily point to s->temp. */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
909 s->out = b->out;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
910 s->out_pos = b->out_pos;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
911 s->out_size = b->out_size;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
912 b->out = s->temp.buf;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
913 b->out_pos = s->temp.size;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
914 b->out_size = sizeof(s->temp.buf);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
915
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
916 s->ret = xz_dec_lzma2_run(lzma2, b);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
917
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
918 s->temp.size = b->out_pos;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
919 b->out = s->out;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
920 b->out_pos = s->out_pos;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
921 b->out_size = s->out_size;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
922
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
923 if (s->ret != XZ_OK && s->ret != XZ_STREAM_END)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
924 return s->ret;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
925
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
926 bcj_apply(s, s->temp.buf, &s->temp.filtered, s->temp.size);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
927
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
928 /*
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
929 * If the next filter returned XZ_STREAM_END, we mark that
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
930 * everything is filtered, since the last unfiltered bytes
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
931 * of the stream are meant to be left as is.
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
932 */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
933 if (s->ret == XZ_STREAM_END)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
934 s->temp.filtered = s->temp.size;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
935
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
936 bcj_flush(s, b);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
937 if (s->temp.filtered > 0)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
938 return XZ_OK;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
939 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
940
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
941 return s->ret;
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
942 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
943
846
e02b4e932cd1 Some xzcat cleanup by Isaac Dunham.
Rob Landley <rob@landley.net>
parents: 819
diff changeset
944 enum xz_ret xz_dec_bcj_reset(struct xz_dec_bcj *s, uint8_t id)
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
945 {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
946 switch (id) {
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
947 #ifdef XZ_DEC_X86
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
948 case BCJ_X86:
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
949 #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
950 #ifdef XZ_DEC_POWERPC
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
951 case BCJ_POWERPC:
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
952 #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
953 #ifdef XZ_DEC_IA64
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
954 case BCJ_IA64:
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
955 #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
956 #ifdef XZ_DEC_ARM
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
957 case BCJ_ARM:
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
958 #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
959 #ifdef XZ_DEC_ARMTHUMB
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
960 case BCJ_ARMTHUMB:
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
961 #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
962 #ifdef XZ_DEC_SPARC
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
963 case BCJ_SPARC:
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
964 #endif
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
965 break;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
966
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
967 default:
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
968 /* Unsupported Filter ID */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
969 return XZ_OPTIONS_ERROR;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
970 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
971
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
972 s->type = id;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
973 s->ret = XZ_OK;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
974 s->pos = 0;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
975 s->x86_prev_mask = 0;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
976 s->temp.filtered = 0;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
977 s->temp.size = 0;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
978
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
979 return XZ_OK;
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
980 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 #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
983 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
985 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 // 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
989 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
991 *
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /* 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
996 #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
997 #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
998 #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
999 #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
1000 #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
1001 #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
1002
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
1005 * 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
1006 * 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
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 #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
1009
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
1012 * 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
1013 *
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
1015 * - 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
1016 * - 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
1017 * - 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
1018 * - 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
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 * 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
1021 * 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
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 enum lzma_state {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1024 STATE_LIT_LIT,
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1025 STATE_MATCH_LIT_LIT,
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1026 STATE_REP_LIT_LIT,
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1027 STATE_SHORTREP_LIT_LIT,
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1028 STATE_MATCH_LIT,
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1029 STATE_REP_LIT,
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1030 STATE_SHORTREP_LIT,
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1031 STATE_LIT_MATCH,
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1032 STATE_LIT_LONGREP,
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1033 STATE_LIT_SHORTREP,
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1034 STATE_NONLIT_MATCH,
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1035 STATE_NONLIT_REP
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1036 };
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /* 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
1039 #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
1040
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /* 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
1042 #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
1043
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /* 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
1045 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
1046 {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1047 if (*state <= STATE_SHORTREP_LIT_LIT)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1048 *state = STATE_LIT_LIT;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1049 else if (*state <= STATE_LIT_SHORTREP)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1050 *state -= 3;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1051 else
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1052 *state -= 6;
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1053 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /* 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
1056 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
1057 {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1058 *state = *state < LIT_STATES ? STATE_LIT_MATCH : STATE_NONLIT_MATCH;
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1059 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /* 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
1062 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
1063 {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1064 *state = *state < LIT_STATES ? STATE_LIT_LONGREP : STATE_NONLIT_REP;
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1065 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /* 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
1068 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
1069 {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1070 *state = *state < LIT_STATES ? STATE_LIT_SHORTREP : STATE_NONLIT_REP;
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1071 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /* Test if the previous symbol was a literal. */
851
db9878df884a More xzcat cleanup.
Rob Landley <rob@landley.net>
parents: 850
diff changeset
1074 static inline int lzma_state_is_literal(enum lzma_state state)
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1075 {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1076 return state < LIT_STATES;
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1077 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /* 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
1080 * - 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
1081 * - 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
1082 * - 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
1083 *
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
1085 * 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
1086 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 #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
1088
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /* 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
1090 #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
1091
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /* 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
1093 #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
1094
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /* 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
1096 *
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
1098 * 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
1099 * 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
1100 * 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
1101 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 #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
1103 #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
1104 #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
1105 #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
1106 #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
1107 #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
1108 #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
1109
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1110 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1111 * 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
1112 * 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
1113 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1114 #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
1115
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
1118 * 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
1119 * 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
1120 * 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
1121 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1122 #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
1123
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
1126 * 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
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 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
1129 {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1130 return len < DIST_STATES + MATCH_LEN_MIN
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1131 ? len - MATCH_LEN_MIN : DIST_STATES - 1;
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
1136 * 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
1137 * 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
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 #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
1140 #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
1141
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1142 /* 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
1143 * 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
1144 * 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
1145 * 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
1146 * 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
1147 * 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
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 #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
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 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
1153 * - 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
1154 * - 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
1155 * - 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
1156 *
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1157 * 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
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 * 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
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 #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
1162
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1163 /* 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
1164 #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
1165 #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
1166
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
1169 * 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
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 #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
1172 #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
1173 #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
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 /* 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
1176 #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
1177
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1178 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1179 * 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
1180 * 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
1181 * 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
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 #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
1184
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1185
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1186 // 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
1187
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
1190 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1191 #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
1192
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
1195 * 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
1196 * 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
1197 * 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
1198 * 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
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 #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
1201
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1202 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1203 * 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
1204 *
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
1206 * 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
1207 * 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
1208 * 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
1209 * 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
1210 * 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
1211 *
967
e922fc4e7a2e This removes xz_mode.
Isaac Dunham <idunham@lavabit.com>
parents: 954
diff changeset
1212 * Most of these variables are size_t as a relic of single-call mode,
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1213 * 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
1214 * 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
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 struct dictionary {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1217 /* Beginning of the history buffer */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1218 uint8_t *buf;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1219
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1220 /* Old position in buf (before decoding more data) */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1221 size_t start;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1222
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1223 /* Position in buf */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1224 size_t pos;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1225
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1226 /*
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1227 * How full dictionary is. This is used to detect corrupt input that
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1228 * would read beyond the beginning of the uncompressed stream.
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1229 */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1230 size_t full;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1231
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1232 /* Write limit; we don't write to buf[limit] or later bytes. */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1233 size_t limit;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1234
967
e922fc4e7a2e This removes xz_mode.
Isaac Dunham <idunham@lavabit.com>
parents: 954
diff changeset
1235 /* End of the dictionary buffer. This is the same as the dictionary size. */
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1236 size_t end;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1237
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1238 /*
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1239 * Size of the dictionary as specified in Block Header. This is used
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1240 * together with "full" to detect corrupt input that would make us
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1241 * read beyond the beginning of the uncompressed stream.
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1242 */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1243 uint32_t size;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1244
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1245 /*
967
e922fc4e7a2e This removes xz_mode.
Isaac Dunham <idunham@lavabit.com>
parents: 954
diff changeset
1246 * Maximum allowed dictionary size.
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1247 */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1248 uint32_t size_max;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1249
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1250 /*
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1251 * Amount of memory currently allocated for the dictionary.
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1252 */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1253 uint32_t allocated;
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
1254 };
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /* 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
1257 struct rc_dec {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1258 uint32_t range;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1259 uint32_t code;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1260
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1261 /*
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1262 * Number of initializing bytes remaining to be read
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1263 * by rc_read_init().
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1264 */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1265 uint32_t init_bytes_left;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1266
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1267 /*
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1268 * Buffer from which we read our input. It can be either
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1269 * temp.buf or the caller-provided input buffer.
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1270 */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1271 const uint8_t *in;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1272 size_t in_pos;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1273 size_t in_limit;
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1274 };
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /* 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
1277 struct lzma_len_dec {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1278 /* Probability of match length being at least 10 */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1279 uint16_t choice;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1280
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1281 /* Probability of match length being at least 18 */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1282 uint16_t choice2;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1283
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1284 /* Probabilities for match lengths 2-9 */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1285 uint16_t low[POS_STATES_MAX][LEN_LOW_SYMBOLS];
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1286
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1287 /* Probabilities for match lengths 10-17 */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1288 uint16_t mid[POS_STATES_MAX][LEN_MID_SYMBOLS];
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1289
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1290 /* Probabilities for match lengths 18-273 */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1291 uint16_t high[LEN_HIGH_SYMBOLS];
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1292 };
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1293
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1294 struct lzma_dec {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1295 /* Distances of latest four matches */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1296 uint32_t rep0;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1297 uint32_t rep1;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1298 uint32_t rep2;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1299 uint32_t rep3;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1300
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1301 /* Types of the most recently seen LZMA symbols */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1302 enum lzma_state state;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1303
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1304 /*
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1305 * Length of a match. This is updated so that dict_repeat can
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1306 * be called again to finish repeating the whole match.
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1307 */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1308 uint32_t len;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1309
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1310 /*
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1311 * LZMA properties or related bit masks (number of literal
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1312 * context bits, a mask dervied from the number of literal
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1313 * position bits, and a mask dervied from the number
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1314 * position bits)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1315 */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1316 uint32_t lc;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1317 uint32_t literal_pos_mask; /* (1 << lp) - 1 */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1318 uint32_t pos_mask; /* (1 << pb) - 1 */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1319
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1320 /* If 1, it's a match. Otherwise it's a single 8-bit literal. */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1321 uint16_t is_match[STATES][POS_STATES_MAX];
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1322
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1323 /* If 1, it's a repeated match. The distance is one of rep0 .. rep3. */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1324 uint16_t is_rep[STATES];
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1325
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1326 /*
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1327 * If 0, distance of a repeated match is rep0.
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1328 * Otherwise check is_rep1.
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1329 */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1330 uint16_t is_rep0[STATES];
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1331
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1332 /*
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1333 * If 0, distance of a repeated match is rep1.
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1334 * Otherwise check is_rep2.
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1335 */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1336 uint16_t is_rep1[STATES];
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1337
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1338 /* If 0, distance of a repeated match is rep2. Otherwise it is rep3. */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1339 uint16_t is_rep2[STATES];
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1340
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1341 /*
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1342 * If 1, the repeated match has length of one byte. Otherwise
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1343 * the length is decoded from rep_len_decoder.
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1344 */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1345 uint16_t is_rep0_long[STATES][POS_STATES_MAX];
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1346
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1347 /*
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1348 * Probability tree for the highest two bits of the match
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1349 * distance. There is a separate probability tree for match
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1350 * lengths of 2 (i.e. MATCH_LEN_MIN), 3, 4, and [5, 273].
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1351 */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1352 uint16_t dist_slot[DIST_STATES][DIST_SLOTS];
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1353
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1354 /*
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1355 * Probility trees for additional bits for match distance
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1356 * when the distance is in the range [4, 127].
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1357 */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1358 uint16_t dist_special[FULL_DISTANCES - DIST_MODEL_END];
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1359
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1360 /*
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1361 * Probability tree for the lowest four bits of a match
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1362 * distance that is equal to or greater than 128.
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1363 */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1364 uint16_t dist_align[ALIGN_SIZE];
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1365
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1366 /* Length of a normal match */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1367 struct lzma_len_dec match_len_dec;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1368
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1369 /* Length of a repeated match */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1370 struct lzma_len_dec rep_len_dec;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1371
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1372 /* Probabilities of literals */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1373 uint16_t literal[LITERAL_CODERS_MAX][LITERAL_CODER_SIZE];
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1374 };
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 struct lzma2_dec {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1377 /* Position in xz_dec_lzma2_run(). */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1378 enum lzma2_seq {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1379 SEQ_CONTROL,
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1380 SEQ_UNCOMPRESSED_1,
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1381 SEQ_UNCOMPRESSED_2,
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1382 SEQ_COMPRESSED_0,
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1383 SEQ_COMPRESSED_1,
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1384 SEQ_PROPERTIES,
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1385 SEQ_LZMA_PREPARE,
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1386 SEQ_LZMA_RUN,
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1387 SEQ_COPY
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1388 } sequence;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1389
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1390 /* Next position after decoding the compressed size of the chunk. */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1391 enum lzma2_seq next_sequence;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1392
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1393 /* Uncompressed size of LZMA chunk (2 MiB at maximum) */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1394 uint32_t uncompressed;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1395
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1396 /*
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1397 * Compressed size of LZMA chunk or compressed/uncompressed
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1398 * size of uncompressed chunk (64 KiB at maximum)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1399 */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1400 uint32_t compressed;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1401
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1402 /*
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1403 * True if dictionary reset is needed. This is false before
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1404 * the first chunk (LZMA or uncompressed).
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1405 */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1406 int need_dict_reset;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1407
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1408 /*
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1409 * True if new LZMA properties are needed. This is false
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1410 * before the first LZMA chunk.
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1411 */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1412 int need_props;
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1413 };
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 struct xz_dec_lzma2 {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1416 /*
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1417 * The order below is important on x86 to reduce code size and
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1418 * it shouldn't hurt on other platforms. Everything up to and
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1419 * including lzma.pos_mask are in the first 128 bytes on x86-32,
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1420 * which allows using smaller instructions to access those
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1421 * variables. On x86-64, fewer variables fit into the first 128
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1422 * bytes, but this is still the best order without sacrificing
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1423 * the readability by splitting the structures.
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1424 */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1425 struct rc_dec rc;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1426 struct dictionary dict;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1427 struct lzma2_dec lzma2;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1428 struct lzma_dec lzma;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1429
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1430 /*
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1431 * Temporary buffer which holds small number of input bytes between
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1432 * decoder calls. See lzma2_lzma() for details.
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1433 */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1434 struct {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1435 uint32_t size;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1436 uint8_t buf[3 * LZMA_IN_REQUIRED];
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1437 } temp;
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1438 };
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /**************
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
1442 **************/
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
967
e922fc4e7a2e This removes xz_mode.
Isaac Dunham <idunham@lavabit.com>
parents: 954
diff changeset
1444 /* Reset the dictionary state. */
e922fc4e7a2e This removes xz_mode.
Isaac Dunham <idunham@lavabit.com>
parents: 954
diff changeset
1445 static void dict_reset(struct dictionary *dict)
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1446 {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1447 dict->start = 0;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1448 dict->pos = 0;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1449 dict->limit = 0;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1450 dict->full = 0;
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1451 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /* 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
1454 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
1455 {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1456 if (dict->end - dict->pos <= out_max)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1457 dict->limit = dict->end;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1458 else
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1459 dict->limit = dict->pos + out_max;
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1460 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /* Return true if at least one byte can be written into the dictionary. */
851
db9878df884a More xzcat cleanup.
Rob Landley <rob@landley.net>
parents: 850
diff changeset
1463 static inline int dict_has_space(const struct dictionary *dict)
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1464 {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1465 return dict->pos < dict->limit;
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
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 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
1470 * 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
1471 * 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
1472 * 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
1473 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 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
1475 {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1476 size_t offset = dict->pos - dist - 1;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1477
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1478 if (dist >= dict->pos)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1479 offset += dict->end;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1480
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1481 return dict->full > 0 ? dict->buf[offset] : 0;
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1482 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
1486 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 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
1488 {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1489 dict->buf[dict->pos++] = byte;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1490
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1491 if (dict->full < dict->pos)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1492 dict->full = dict->pos;
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
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 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
1497 * 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
1498 * 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
1499 */
851
db9878df884a More xzcat cleanup.
Rob Landley <rob@landley.net>
parents: 850
diff changeset
1500 static int dict_repeat(struct dictionary *dict, uint32_t *len, uint32_t dist)
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1501 {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1502 size_t back;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1503 uint32_t left;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1504
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1505 if (dist >= dict->full || dist >= dict->size) return 0;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1506
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1507 left = min_t(size_t, dict->limit - dict->pos, *len);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1508 *len -= left;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1509
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1510 back = dict->pos - dist - 1;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1511 if (dist >= dict->pos)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1512 back += dict->end;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1513
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1514 do {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1515 dict->buf[dict->pos++] = dict->buf[back++];
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1516 if (back == dict->end)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1517 back = 0;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1518 } while (--left > 0);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1519
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1520 if (dict->full < dict->pos)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1521 dict->full = dict->pos;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1522
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1523 return 1;
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1524 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /* 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
1527 static void dict_uncompressed(struct dictionary *dict, struct xz_buf *b,
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1528 uint32_t *left)
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1529 {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1530 size_t copy_size;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1531
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1532 while (*left > 0 && b->in_pos < b->in_size
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1533 && b->out_pos < b->out_size) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1534 copy_size = min(b->in_size - b->in_pos,
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1535 b->out_size - b->out_pos);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1536 if (copy_size > dict->end - dict->pos)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1537 copy_size = dict->end - dict->pos;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1538 if (copy_size > *left)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1539 copy_size = *left;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1540
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1541 *left -= copy_size;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1542
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1543 memcpy(dict->buf + dict->pos, b->in + b->in_pos, copy_size);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1544 dict->pos += copy_size;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1545
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1546 if (dict->full < dict->pos)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1547 dict->full = dict->pos;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1548
953
13916d161ec0 xzcat: remove XZ_(PREALLOC|SINGLE), inline xz_dec_bcj_create
Isaac Dunham <idunham@lavabit.com>
parents: 944
diff changeset
1549 if (dict->pos == dict->end)
13916d161ec0 xzcat: remove XZ_(PREALLOC|SINGLE), inline xz_dec_bcj_create
Isaac Dunham <idunham@lavabit.com>
parents: 944
diff changeset
1550 dict->pos = 0;
13916d161ec0 xzcat: remove XZ_(PREALLOC|SINGLE), inline xz_dec_bcj_create
Isaac Dunham <idunham@lavabit.com>
parents: 944
diff changeset
1551
13916d161ec0 xzcat: remove XZ_(PREALLOC|SINGLE), inline xz_dec_bcj_create
Isaac Dunham <idunham@lavabit.com>
parents: 944
diff changeset
1552 memcpy(b->out + b->out_pos, b->in + b->in_pos,
13916d161ec0 xzcat: remove XZ_(PREALLOC|SINGLE), inline xz_dec_bcj_create
Isaac Dunham <idunham@lavabit.com>
parents: 944
diff changeset
1553 copy_size);
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1554
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1555 dict->start = dict->pos;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1556
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1557 b->out_pos += copy_size;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1558 b->in_pos += copy_size;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1559 }
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
1560 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
1564 * 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
1565 * 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
1566 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 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
1568 {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1569 size_t copy_size = dict->pos - dict->start;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1570
953
13916d161ec0 xzcat: remove XZ_(PREALLOC|SINGLE), inline xz_dec_bcj_create
Isaac Dunham <idunham@lavabit.com>
parents: 944
diff changeset
1571 if (dict->pos == dict->end)
13916d161ec0 xzcat: remove XZ_(PREALLOC|SINGLE), inline xz_dec_bcj_create
Isaac Dunham <idunham@lavabit.com>
parents: 944
diff changeset
1572 dict->pos = 0;
13916d161ec0 xzcat: remove XZ_(PREALLOC|SINGLE), inline xz_dec_bcj_create
Isaac Dunham <idunham@lavabit.com>
parents: 944
diff changeset
1573
13916d161ec0 xzcat: remove XZ_(PREALLOC|SINGLE), inline xz_dec_bcj_create
Isaac Dunham <idunham@lavabit.com>
parents: 944
diff changeset
1574 memcpy(b->out + b->out_pos, dict->buf + dict->start,
13916d161ec0 xzcat: remove XZ_(PREALLOC|SINGLE), inline xz_dec_bcj_create
Isaac Dunham <idunham@lavabit.com>
parents: 944
diff changeset
1575 copy_size);
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1576
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1577 dict->start = dict->pos;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1578 b->out_pos += copy_size;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1579 return copy_size;
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
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 /*****************
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
1584 *****************/
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /* 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
1587 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
1588 {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1589 rc->range = (uint32_t)-1;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1590 rc->code = 0;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1591 rc->init_bytes_left = RC_INIT_BYTES;
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
1596 * 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
1597 */
851
db9878df884a More xzcat cleanup.
Rob Landley <rob@landley.net>
parents: 850
diff changeset
1598 static int rc_read_init(struct rc_dec *rc, struct xz_buf *b)
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1599 {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1600 while (rc->init_bytes_left > 0) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1601 if (b->in_pos == b->in_size) return 0;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1602
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1603 rc->code = (rc->code << 8) + b->in[b->in_pos++];
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1604 --rc->init_bytes_left;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1605 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1606
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1607 return 1;
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1608 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /* Return true if there may not be enough input for the next decoding loop. */
851
db9878df884a More xzcat cleanup.
Rob Landley <rob@landley.net>
parents: 850
diff changeset
1611 static inline int rc_limit_exceeded(const struct rc_dec *rc)
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1612 {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1613 return rc->in_pos > rc->in_limit;
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1614 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
1618 * 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
1619 */
851
db9878df884a More xzcat cleanup.
Rob Landley <rob@landley.net>
parents: 850
diff changeset
1620 static inline int rc_is_finished(const struct rc_dec *rc)
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1621 {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1622 return rc->code == 0;
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /* Read the next input byte if needed. */
854
68cdd244f8b1 xzcat: more cleanup and some shrinking.
Isaac Dunham <idunham@lavabit.com>
parents: 851
diff changeset
1626 static inline void rc_normalize(struct rc_dec *rc)
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1627 {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1628 if (rc->range < RC_TOP_VALUE) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1629 rc->range <<= RC_SHIFT_BITS;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1630 rc->code = (rc->code << RC_SHIFT_BITS) + rc->in[rc->in_pos++];
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1631 }
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1632 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1633
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1634 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1635 * 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
1636 * 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
1637 * 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
1638 * 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
1639 * 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
1640 *
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
1642 * 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
1643 * 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
1644 */
854
68cdd244f8b1 xzcat: more cleanup and some shrinking.
Isaac Dunham <idunham@lavabit.com>
parents: 851
diff changeset
1645 static inline int rc_bit(struct rc_dec *rc, uint16_t *prob)
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1646 {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1647 uint32_t bound;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1648 int bit;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1649
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1650 rc_normalize(rc);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1651 bound = (rc->range >> RC_BIT_MODEL_TOTAL_BITS) * *prob;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1652 if (rc->code < bound) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1653 rc->range = bound;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1654 *prob += (RC_BIT_MODEL_TOTAL - *prob) >> RC_MOVE_BITS;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1655 bit = 0;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1656 } else {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1657 rc->range -= bound;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1658 rc->code -= bound;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1659 *prob -= *prob >> RC_MOVE_BITS;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1660 bit = 1;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1661 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1662
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1663 return bit;
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1664 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1665
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /* Decode a bittree starting from the most significant bit. */
854
68cdd244f8b1 xzcat: more cleanup and some shrinking.
Isaac Dunham <idunham@lavabit.com>
parents: 851
diff changeset
1667 static inline uint32_t rc_bittree(struct rc_dec *rc,
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1668 uint16_t *probs, uint32_t limit)
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1669 {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1670 uint32_t symbol = 1;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1671
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1672 do {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1673 if (rc_bit(rc, &probs[symbol]))
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1674 symbol = (symbol << 1) + 1;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1675 else
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1676 symbol <<= 1;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1677 } while (symbol < limit);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1678
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1679 return symbol;
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1680 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /* Decode a bittree starting from the least significant bit. */
854
68cdd244f8b1 xzcat: more cleanup and some shrinking.
Isaac Dunham <idunham@lavabit.com>
parents: 851
diff changeset
1683 static inline void rc_bittree_reverse(struct rc_dec *rc,
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1684 uint16_t *probs,
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1685 uint32_t *dest, uint32_t limit)
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1686 {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1687 uint32_t symbol = 1;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1688 uint32_t i = 0;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1689
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1690 do {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1691 if (rc_bit(rc, &probs[symbol])) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1692 symbol = (symbol << 1) + 1;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1693 *dest += 1 << i;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1694 } else {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1695 symbol <<= 1;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1696 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1697 } while (++i < limit);
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1698 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /* 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
1701 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
1702 {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1703 uint32_t mask;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1704
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1705 do {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1706 rc_normalize(rc);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1707 rc->range >>= 1;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1708 rc->code -= rc->range;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1709 mask = (uint32_t)0 - (rc->code >> 31);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1710 rc->code += rc->range & mask;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1711 *dest = (*dest << 1) + (mask + 1);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1712 } while (--limit > 0);
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
1717 ********/
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /* 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
1720 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
1721 {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1722 uint32_t prev_byte = dict_get(&s->dict, 0);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1723 uint32_t low = prev_byte >> (8 - s->lzma.lc);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1724 uint32_t high = (s->dict.pos & s->lzma.literal_pos_mask) << s->lzma.lc;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1725 return s->lzma.literal[low + high];
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1726 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /* 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
1729 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
1730 {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1731 uint16_t *probs;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1732 uint32_t symbol;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1733 uint32_t match_byte;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1734 uint32_t match_bit;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1735 uint32_t offset;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1736 uint32_t i;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1737
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1738 probs = lzma_literal_probs(s);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1739
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1740 if (lzma_state_is_literal(s->lzma.state)) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1741 symbol = rc_bittree(&s->rc, probs, 0x100);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1742 } else {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1743 symbol = 1;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1744 match_byte = dict_get(&s->dict, s->lzma.rep0) << 1;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1745 offset = 0x100;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1746
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1747 do {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1748 match_bit = match_byte & offset;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1749 match_byte <<= 1;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1750 i = offset + match_bit + symbol;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1751
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1752 if (rc_bit(&s->rc, &probs[i])) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1753 symbol = (symbol << 1) + 1;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1754 offset &= match_bit;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1755 } else {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1756 symbol <<= 1;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1757 offset &= ~match_bit;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1758 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1759 } while (symbol < 0x100);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1760 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1761
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1762 dict_put(&s->dict, (uint8_t)symbol);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1763 lzma_state_literal(&s->lzma.state);
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /* 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
1767 static void lzma_len(struct xz_dec_lzma2 *s, struct lzma_len_dec *l,
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1768 uint32_t pos_state)
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1769 {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1770 uint16_t *probs;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1771 uint32_t limit;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1772
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1773 if (!rc_bit(&s->rc, &l->choice)) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1774 probs = l->low[pos_state];
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1775 limit = LEN_LOW_SYMBOLS;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1776 s->lzma.len = MATCH_LEN_MIN;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1777 } else {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1778 if (!rc_bit(&s->rc, &l->choice2)) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1779 probs = l->mid[pos_state];
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1780 limit = LEN_MID_SYMBOLS;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1781 s->lzma.len = MATCH_LEN_MIN + LEN_LOW_SYMBOLS;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1782 } else {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1783 probs = l->high;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1784 limit = LEN_HIGH_SYMBOLS;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1785 s->lzma.len = MATCH_LEN_MIN + LEN_LOW_SYMBOLS
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1786 + LEN_MID_SYMBOLS;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1787 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1788 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1789
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1790 s->lzma.len += rc_bittree(&s->rc, probs, limit) - limit;
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1791 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /* 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
1794 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
1795 {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1796 uint16_t *probs;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1797 uint32_t dist_slot;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1798 uint32_t limit;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1799
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1800 lzma_state_match(&s->lzma.state);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1801
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1802 s->lzma.rep3 = s->lzma.rep2;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1803 s->lzma.rep2 = s->lzma.rep1;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1804 s->lzma.rep1 = s->lzma.rep0;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1805
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1806 lzma_len(s, &s->lzma.match_len_dec, pos_state);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1807
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1808 probs = s->lzma.dist_slot[lzma_get_dist_state(s->lzma.len)];
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1809 dist_slot = rc_bittree(&s->rc, probs, DIST_SLOTS) - DIST_SLOTS;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1810
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1811 if (dist_slot < DIST_MODEL_START) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1812 s->lzma.rep0 = dist_slot;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1813 } else {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1814 limit = (dist_slot >> 1) - 1;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1815 s->lzma.rep0 = 2 + (dist_slot & 1);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1816
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1817 if (dist_slot < DIST_MODEL_END) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1818 s->lzma.rep0 <<= limit;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1819 probs = s->lzma.dist_special + s->lzma.rep0
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1820 - dist_slot - 1;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1821 rc_bittree_reverse(&s->rc, probs,
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1822 &s->lzma.rep0, limit);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1823 } else {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1824 rc_direct(&s->rc, &s->lzma.rep0, limit - ALIGN_BITS);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1825 s->lzma.rep0 <<= ALIGN_BITS;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1826 rc_bittree_reverse(&s->rc, s->lzma.dist_align,
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1827 &s->lzma.rep0, ALIGN_BITS);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1828 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1829 }
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
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 * 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
1834 * 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
1835 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 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
1837 {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1838 uint32_t tmp;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1839
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1840 if (!rc_bit(&s->rc, &s->lzma.is_rep0[s->lzma.state])) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1841 if (!rc_bit(&s->rc, &s->lzma.is_rep0_long[
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1842 s->lzma.state][pos_state])) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1843 lzma_state_short_rep(&s->lzma.state);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1844 s->lzma.len = 1;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1845 return;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1846 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1847 } else {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1848 if (!rc_bit(&s->rc, &s->lzma.is_rep1[s->lzma.state])) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1849 tmp = s->lzma.rep1;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1850 } else {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1851 if (!rc_bit(&s->rc, &s->lzma.is_rep2[s->lzma.state])) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1852 tmp = s->lzma.rep2;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1853 } else {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1854 tmp = s->lzma.rep3;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1855 s->lzma.rep3 = s->lzma.rep2;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1856 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1857
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1858 s->lzma.rep2 = s->lzma.rep1;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1859 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1860
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1861 s->lzma.rep1 = s->lzma.rep0;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1862 s->lzma.rep0 = tmp;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1863 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1864
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1865 lzma_state_long_rep(&s->lzma.state);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1866 lzma_len(s, &s->lzma.rep_len_dec, pos_state);
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1867 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /* LZMA decoder core */
851
db9878df884a More xzcat cleanup.
Rob Landley <rob@landley.net>
parents: 850
diff changeset
1870 static int lzma_main(struct xz_dec_lzma2 *s)
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1871 {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1872 uint32_t pos_state;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1873
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1874 /*
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1875 * If the dictionary was reached during the previous call, try to
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1876 * finish the possibly pending repeat in the dictionary.
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1877 */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1878 if (dict_has_space(&s->dict) && s->lzma.len > 0)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1879 dict_repeat(&s->dict, &s->lzma.len, s->lzma.rep0);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1880
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1881 /*
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1882 * Decode more LZMA symbols. One iteration may consume up to
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1883 * LZMA_IN_REQUIRED - 1 bytes.
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1884 */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1885 while (dict_has_space(&s->dict) && !rc_limit_exceeded(&s->rc)) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1886 pos_state = s->dict.pos & s->lzma.pos_mask;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1887
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1888 if (!rc_bit(&s->rc, &s->lzma.is_match[
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1889 s->lzma.state][pos_state])) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1890 lzma_literal(s);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1891 } else {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1892 if (rc_bit(&s->rc, &s->lzma.is_rep[s->lzma.state]))
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1893 lzma_rep_match(s, pos_state);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1894 else
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1895 lzma_match(s, pos_state);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1896
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1897 if (!dict_repeat(&s->dict, &s->lzma.len, s->lzma.rep0))
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1898 return 0;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1899 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1900 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1901
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1902 /*
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1903 * Having the range decoder always normalized when we are outside
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1904 * this function makes it easier to correctly handle end of the chunk.
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1905 */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1906 rc_normalize(&s->rc);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1907
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1908 return 1;
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1909 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
1913 * 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
1914 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 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
1916 {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1917 uint16_t *probs;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1918 size_t i;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1919
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1920 s->lzma.state = STATE_LIT_LIT;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1921 s->lzma.rep0 = 0;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1922 s->lzma.rep1 = 0;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1923 s->lzma.rep2 = 0;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1924 s->lzma.rep3 = 0;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1925
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1926 /*
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1927 * All probabilities are initialized to the same value. This hack
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1928 * makes the code smaller by avoiding a separate loop for each
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1929 * probability array.
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1930 *
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1931 * This could be optimized so that only that part of literal
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1932 * probabilities that are actually required. In the common case
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1933 * we would write 12 KiB less.
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1934 */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1935 probs = s->lzma.is_match[0];
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1936 for (i = 0; i < PROBS_TOTAL; ++i)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1937 probs[i] = RC_BIT_MODEL_TOTAL / 2;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1938
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1939 rc_reset(&s->rc);
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1940 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
1944 * 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
1945 * 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
1946 */
851
db9878df884a More xzcat cleanup.
Rob Landley <rob@landley.net>
parents: 850
diff changeset
1947 static int lzma_props(struct xz_dec_lzma2 *s, uint8_t props)
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1948 {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1949 if (props > (4 * 5 + 4) * 9 + 8)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1950 return 0;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1951
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1952 s->lzma.pos_mask = 0;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1953 while (props >= 9 * 5) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1954 props -= 9 * 5;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1955 ++s->lzma.pos_mask;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1956 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1957
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1958 s->lzma.pos_mask = (1 << s->lzma.pos_mask) - 1;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1959
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1960 s->lzma.literal_pos_mask = 0;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1961 while (props >= 9) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1962 props -= 9;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1963 ++s->lzma.literal_pos_mask;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1964 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1965
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1966 s->lzma.lc = props;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1967
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1968 if (s->lzma.lc + s->lzma.literal_pos_mask > 4)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1969 return 0;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1970
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1971 s->lzma.literal_pos_mask = (1 << s->lzma.literal_pos_mask) - 1;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1972
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1973 lzma_reset(s);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1974
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1975 return 1;
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
1980 *********/
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
1984 * 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
1985 * 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
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 * 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
1988 * 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
1989 * 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
1990 * 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
1991 * 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
1992 * 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
1993 */
851
db9878df884a More xzcat cleanup.
Rob Landley <rob@landley.net>
parents: 850
diff changeset
1994 static int lzma2_lzma(struct xz_dec_lzma2 *s, struct xz_buf *b)
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
1995 {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1996 size_t in_avail;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1997 uint32_t tmp;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1998
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
1999 in_avail = b->in_size - b->in_pos;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2000 if (s->temp.size > 0 || s->lzma2.compressed == 0) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2001 tmp = 2 * LZMA_IN_REQUIRED - s->temp.size;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2002 if (tmp > s->lzma2.compressed - s->temp.size)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2003 tmp = s->lzma2.compressed - s->temp.size;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2004 if (tmp > in_avail)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2005 tmp = in_avail;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2006
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2007 memcpy(s->temp.buf + s->temp.size, b->in + b->in_pos, tmp);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2008
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2009 if (s->temp.size + tmp == s->lzma2.compressed) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2010 memset(s->temp.buf + s->temp.size + tmp, 0,
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2011 sizeof(s->temp.buf)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2012 - s->temp.size - tmp);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2013 s->rc.in_limit = s->temp.size + tmp;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2014 } else if (s->temp.size + tmp < LZMA_IN_REQUIRED) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2015 s->temp.size += tmp;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2016 b->in_pos += tmp;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2017 return 1;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2018 } else {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2019 s->rc.in_limit = s->temp.size + tmp - LZMA_IN_REQUIRED;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2020 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2021
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2022 s->rc.in = s->temp.buf;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2023 s->rc.in_pos = 0;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2024
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2025 if (!lzma_main(s) || s->rc.in_pos > s->temp.size + tmp)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2026 return 0;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2027
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2028 s->lzma2.compressed -= s->rc.in_pos;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2029
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2030 if (s->rc.in_pos < s->temp.size) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2031 s->temp.size -= s->rc.in_pos;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2032 memmove(s->temp.buf, s->temp.buf + s->rc.in_pos,
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2033 s->temp.size);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2034 return 1;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2035 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2036
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2037 b->in_pos += s->rc.in_pos - s->temp.size;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2038 s->temp.size = 0;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2039 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2040
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2041 in_avail = b->in_size - b->in_pos;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2042 if (in_avail >= LZMA_IN_REQUIRED) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2043 s->rc.in = b->in;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2044 s->rc.in_pos = b->in_pos;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2045
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2046 if (in_avail >= s->lzma2.compressed + LZMA_IN_REQUIRED)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2047 s->rc.in_limit = b->in_pos + s->lzma2.compressed;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2048 else
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2049 s->rc.in_limit = b->in_size - LZMA_IN_REQUIRED;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2050
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2051 if (!lzma_main(s))
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2052 return 0;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2053
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2054 in_avail = s->rc.in_pos - b->in_pos;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2055 if (in_avail > s->lzma2.compressed) return 0;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2056
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2057 s->lzma2.compressed -= in_avail;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2058 b->in_pos = s->rc.in_pos;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2059 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2060
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2061 in_avail = b->in_size - b->in_pos;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2062 if (in_avail < LZMA_IN_REQUIRED) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2063 if (in_avail > s->lzma2.compressed)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2064 in_avail = s->lzma2.compressed;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2065
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2066 memcpy(s->temp.buf, b->in + b->in_pos, in_avail);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2067 s->temp.size = in_avail;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2068 b->in_pos += in_avail;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2069 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2070
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2071 return 1;
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
2076 * 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
2077 */
846
e02b4e932cd1 Some xzcat cleanup by Isaac Dunham.
Rob Landley <rob@landley.net>
parents: 819
diff changeset
2078 enum xz_ret xz_dec_lzma2_run(struct xz_dec_lzma2 *s,
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2079 struct xz_buf *b)
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2080 {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2081 uint32_t tmp;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2082
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2083 while (b->in_pos < b->in_size || s->lzma2.sequence == SEQ_LZMA_RUN) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2084 switch (s->lzma2.sequence) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2085 case SEQ_CONTROL:
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2086 /*
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2087 * LZMA2 control byte
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2088 *
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2089 * Exact values:
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2090 * 0x00 End marker
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2091 * 0x01 Dictionary reset followed by
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2092 * an uncompressed chunk
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2093 * 0x02 Uncompressed chunk (no dictionary reset)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2094 *
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2095 * Highest three bits (s->control & 0xE0):
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2096 * 0xE0 Dictionary reset, new properties and state
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2097 * reset, followed by LZMA compressed chunk
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2098 * 0xC0 New properties and state reset, followed
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2099 * by LZMA compressed chunk (no dictionary
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2100 * reset)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2101 * 0xA0 State reset using old properties,
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2102 * followed by LZMA compressed chunk (no
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2103 * dictionary reset)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2104 * 0x80 LZMA chunk (no dictionary or state reset)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2105 *
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2106 * For LZMA compressed chunks, the lowest five bits
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2107 * (s->control & 1F) are the highest bits of the
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2108 * uncompressed size (bits 16-20).
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2109 *
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2110 * A new LZMA2 stream must begin with a dictionary
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2111 * reset. The first LZMA chunk must set new
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2112 * properties and reset the LZMA state.
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2113 *
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2114 * Values that don't match anything described above
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2115 * are invalid and we return XZ_DATA_ERROR.
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2116 */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2117 tmp = b->in[b->in_pos++];
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2118
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2119 if (tmp == 0x00)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2120 return XZ_STREAM_END;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2121
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2122 if (tmp >= 0xE0 || tmp == 0x01) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2123 s->lzma2.need_props = 1;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2124 s->lzma2.need_dict_reset = 0;
967
e922fc4e7a2e This removes xz_mode.
Isaac Dunham <idunham@lavabit.com>
parents: 954
diff changeset
2125 dict_reset(&s->dict);
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2126 } else if (s->lzma2.need_dict_reset) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2127 return XZ_DATA_ERROR;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2128 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2129
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2130 if (tmp >= 0x80) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2131 s->lzma2.uncompressed = (tmp & 0x1F) << 16;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2132 s->lzma2.sequence = SEQ_UNCOMPRESSED_1;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2133
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2134 if (tmp >= 0xC0) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2135 /*
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2136 * When there are new properties,
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2137 * state reset is done at
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2138 * SEQ_PROPERTIES.
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2139 */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2140 s->lzma2.need_props = 0;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2141 s->lzma2.next_sequence
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2142 = SEQ_PROPERTIES;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2143
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2144 } else if (s->lzma2.need_props) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2145 return XZ_DATA_ERROR;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2146
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2147 } else {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2148 s->lzma2.next_sequence
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2149 = SEQ_LZMA_PREPARE;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2150 if (tmp >= 0xA0)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2151 lzma_reset(s);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2152 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2153 } else {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2154 if (tmp > 0x02)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2155 return XZ_DATA_ERROR;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2156
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2157 s->lzma2.sequence = SEQ_COMPRESSED_0;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2158 s->lzma2.next_sequence = SEQ_COPY;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2159 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2160
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2161 break;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2162
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2163 case SEQ_UNCOMPRESSED_1:
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2164 s->lzma2.uncompressed
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2165 += (uint32_t)b->in[b->in_pos++] << 8;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2166 s->lzma2.sequence = SEQ_UNCOMPRESSED_2;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2167 break;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2168
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2169 case SEQ_UNCOMPRESSED_2:
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2170 s->lzma2.uncompressed
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2171 += (uint32_t)b->in[b->in_pos++] + 1;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2172 s->lzma2.sequence = SEQ_COMPRESSED_0;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2173 break;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2174
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2175 case SEQ_COMPRESSED_0:
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2176 s->lzma2.compressed
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2177 = (uint32_t)b->in[b->in_pos++] << 8;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2178 s->lzma2.sequence = SEQ_COMPRESSED_1;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2179 break;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2180
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2181 case SEQ_COMPRESSED_1:
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2182 s->lzma2.compressed
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2183 += (uint32_t)b->in[b->in_pos++] + 1;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2184 s->lzma2.sequence = s->lzma2.next_sequence;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2185 break;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2186
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2187 case SEQ_PROPERTIES:
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2188 if (!lzma_props(s, b->in[b->in_pos++]))
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2189 return XZ_DATA_ERROR;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2190
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2191 s->lzma2.sequence = SEQ_LZMA_PREPARE;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2192
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2193 case SEQ_LZMA_PREPARE:
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2194 if (s->lzma2.compressed < RC_INIT_BYTES)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2195 return XZ_DATA_ERROR;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2196
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2197 if (!rc_read_init(&s->rc, b))
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2198 return XZ_OK;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2199
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2200 s->lzma2.compressed -= RC_INIT_BYTES;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2201 s->lzma2.sequence = SEQ_LZMA_RUN;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2202
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2203 case SEQ_LZMA_RUN:
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2204 /*
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2205 * Set dictionary limit to indicate how much we want
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2206 * to be encoded at maximum. Decode new data into the
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2207 * dictionary. Flush the new data from dictionary to
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2208 * b->out. Check if we finished decoding this chunk.
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2209 * In case the dictionary got full but we didn't fill
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2210 * the output buffer yet, we may run this loop
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2211 * multiple times without changing s->lzma2.sequence.
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2212 */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2213 dict_limit(&s->dict, min_t(size_t,
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2214 b->out_size - b->out_pos,
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2215 s->lzma2.uncompressed));
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2216 if (!lzma2_lzma(s, b))
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2217 return XZ_DATA_ERROR;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2218
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2219 s->lzma2.uncompressed -= dict_flush(&s->dict, b);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2220
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2221 if (s->lzma2.uncompressed == 0) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2222 if (s->lzma2.compressed > 0 || s->lzma.len > 0
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2223 || !rc_is_finished(&s->rc))
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2224 return XZ_DATA_ERROR;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2225
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2226 rc_reset(&s->rc);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2227 s->lzma2.sequence = SEQ_CONTROL;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2228
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2229 } else if (b->out_pos == b->out_size
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2230 || (b->in_pos == b->in_size
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2231 && s->temp.size
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2232 < s->lzma2.compressed)) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2233 return XZ_OK;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2234 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2235
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2236 break;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2237
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2238 case SEQ_COPY:
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2239 dict_uncompressed(&s->dict, b, &s->lzma2.compressed);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2240 if (s->lzma2.compressed > 0)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2241 return XZ_OK;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2242
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2243 s->lzma2.sequence = SEQ_CONTROL;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2244 break;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2245 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2246 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2247
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2248 return XZ_OK;
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2249 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
967
e922fc4e7a2e This removes xz_mode.
Isaac Dunham <idunham@lavabit.com>
parents: 954
diff changeset
2251 struct xz_dec_lzma2 *xz_dec_lzma2_create(uint32_t dict_max)
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2252 {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2253 struct xz_dec_lzma2 *s = malloc(sizeof(*s));
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2254 if (s == NULL)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2255 return NULL;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2256
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2257 s->dict.size_max = dict_max;
953
13916d161ec0 xzcat: remove XZ_(PREALLOC|SINGLE), inline xz_dec_bcj_create
Isaac Dunham <idunham@lavabit.com>
parents: 944
diff changeset
2258 s->dict.buf = NULL;
13916d161ec0 xzcat: remove XZ_(PREALLOC|SINGLE), inline xz_dec_bcj_create
Isaac Dunham <idunham@lavabit.com>
parents: 944
diff changeset
2259 s->dict.allocated = 0;
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2260
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2261 return s;
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2262 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
846
e02b4e932cd1 Some xzcat cleanup by Isaac Dunham.
Rob Landley <rob@landley.net>
parents: 819
diff changeset
2264 enum xz_ret xz_dec_lzma2_reset(struct xz_dec_lzma2 *s, uint8_t props)
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2265 {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2266 /* This limits dictionary size to 3 GiB to keep parsing simpler. */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2267 if (props > 39)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2268 return XZ_OPTIONS_ERROR;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2269
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2270 s->dict.size = 2 + (props & 1);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2271 s->dict.size <<= (props >> 1) + 11;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2272
953
13916d161ec0 xzcat: remove XZ_(PREALLOC|SINGLE), inline xz_dec_bcj_create
Isaac Dunham <idunham@lavabit.com>
parents: 944
diff changeset
2273 if (s->dict.size > s->dict.size_max)
13916d161ec0 xzcat: remove XZ_(PREALLOC|SINGLE), inline xz_dec_bcj_create
Isaac Dunham <idunham@lavabit.com>
parents: 944
diff changeset
2274 return XZ_MEMLIMIT_ERROR;
13916d161ec0 xzcat: remove XZ_(PREALLOC|SINGLE), inline xz_dec_bcj_create
Isaac Dunham <idunham@lavabit.com>
parents: 944
diff changeset
2275
13916d161ec0 xzcat: remove XZ_(PREALLOC|SINGLE), inline xz_dec_bcj_create
Isaac Dunham <idunham@lavabit.com>
parents: 944
diff changeset
2276 s->dict.end = s->dict.size;
13916d161ec0 xzcat: remove XZ_(PREALLOC|SINGLE), inline xz_dec_bcj_create
Isaac Dunham <idunham@lavabit.com>
parents: 944
diff changeset
2277
13916d161ec0 xzcat: remove XZ_(PREALLOC|SINGLE), inline xz_dec_bcj_create
Isaac Dunham <idunham@lavabit.com>
parents: 944
diff changeset
2278 if (s->dict.allocated < s->dict.size) {
13916d161ec0 xzcat: remove XZ_(PREALLOC|SINGLE), inline xz_dec_bcj_create
Isaac Dunham <idunham@lavabit.com>
parents: 944
diff changeset
2279 free(s->dict.buf);
13916d161ec0 xzcat: remove XZ_(PREALLOC|SINGLE), inline xz_dec_bcj_create
Isaac Dunham <idunham@lavabit.com>
parents: 944
diff changeset
2280 s->dict.buf = malloc(s->dict.size);
13916d161ec0 xzcat: remove XZ_(PREALLOC|SINGLE), inline xz_dec_bcj_create
Isaac Dunham <idunham@lavabit.com>
parents: 944
diff changeset
2281 if (s->dict.buf == NULL) {
13916d161ec0 xzcat: remove XZ_(PREALLOC|SINGLE), inline xz_dec_bcj_create
Isaac Dunham <idunham@lavabit.com>
parents: 944
diff changeset
2282 s->dict.allocated = 0;
13916d161ec0 xzcat: remove XZ_(PREALLOC|SINGLE), inline xz_dec_bcj_create
Isaac Dunham <idunham@lavabit.com>
parents: 944
diff changeset
2283 return XZ_MEM_ERROR;
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2284 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2285 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2286
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2287 s->lzma.len = 0;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2288
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2289 s->lzma2.sequence = SEQ_CONTROL;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2290 s->lzma2.need_dict_reset = 1;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2291
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2292 s->temp.size = 0;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2293
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2294 return XZ_OK;
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
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 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * .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
2299 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 // 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
2303 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
2305 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
2309 * 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
2310 * 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
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 #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
2314
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 #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
2316 #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
2317
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 #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
2319 #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
2320
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
2323 * 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
2324 *
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
2326 * 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
2327 * 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
2328 * 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
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 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
2331
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 #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
2333 #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
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 /* 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
2336 #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
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 /* 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
2339 enum xz_check {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2340 XZ_CHECK_NONE = 0,
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2341 XZ_CHECK_CRC32 = 1,
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2342 XZ_CHECK_CRC64 = 4,
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2343 XZ_CHECK_SHA256 = 10
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /* 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
2347 #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
2348 // 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
2349
846
e02b4e932cd1 Some xzcat cleanup by Isaac Dunham.
Rob Landley <rob@landley.net>
parents: 819
diff changeset
2350 #define IS_CRC64(check_type) ((check_type) == XZ_CHECK_CRC64)
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
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 /* 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
2353 struct xz_dec_hash {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2354 vli_type unpadded;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2355 vli_type uncompressed;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2356 uint32_t crc32;
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2357 };
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 struct xz_dec {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2360 /* Position in dec_main() */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2361 enum {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2362 SEQ_STREAM_HEADER,
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2363 SEQ_BLOCK_START,
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2364 SEQ_BLOCK_HEADER,
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2365 SEQ_BLOCK_UNCOMPRESS,
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2366 SEQ_BLOCK_PADDING,
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2367 SEQ_BLOCK_CHECK,
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2368 SEQ_INDEX,
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2369 SEQ_INDEX_PADDING,
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2370 SEQ_INDEX_CRC32,
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2371 SEQ_STREAM_FOOTER
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2372 } sequence;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2373
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2374 /* Position in variable-length integers and Check fields */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2375 uint32_t pos;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2376
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2377 /* Variable-length integer decoded by dec_vli() */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2378 vli_type vli;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2379
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2380 /* Saved in_pos and out_pos */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2381 size_t in_start;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2382 size_t out_start;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2383
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2384 /* CRC32 or CRC64 value in Block or CRC32 value in Index */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2385 uint64_t crc;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2386
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2387 /* Type of the integrity check calculated from uncompressed data */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2388 enum xz_check check_type;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2389
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2390 /*
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2391 * True if the next call to xz_dec_run() is allowed to return
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2392 * XZ_BUF_ERROR.
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2393 */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2394 int allow_buf_error;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2395
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2396 /* Information stored in Block Header */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2397 struct {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2398 /*
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2399 * Value stored in the Compressed Size field, or
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2400 * VLI_UNKNOWN if Compressed Size is not present.
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2401 */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2402 vli_type compressed;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2403
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2404 /*
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2405 * Value stored in the Uncompressed Size field, or
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2406 * VLI_UNKNOWN if Uncompressed Size is not present.
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2407 */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2408 vli_type uncompressed;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2409
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2410 /* Size of the Block Header field */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2411 uint32_t size;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2412 } block_header;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2413
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2414 /* Information collected when decoding Blocks */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2415 struct {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2416 /* Observed compressed size of the current Block */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2417 vli_type compressed;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2418
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2419 /* Observed uncompressed size of the current Block */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2420 vli_type uncompressed;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2421
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2422 /* Number of Blocks decoded so far */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2423 vli_type count;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2424
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2425 /*
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2426 * Hash calculated from the Block sizes. This is used to
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2427 * validate the Index field.
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2428 */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2429 struct xz_dec_hash hash;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2430 } block;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2431
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2432 /* Variables needed when verifying the Index field */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2433 struct {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2434 /* Position in dec_index() */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2435 enum {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2436 SEQ_INDEX_COUNT,
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2437 SEQ_INDEX_UNPADDED,
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2438 SEQ_INDEX_UNCOMPRESSED
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2439 } sequence;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2440
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2441 /* Size of the Index in bytes */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2442 vli_type size;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2443
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2444 /* Number of Records (matches block.count in valid files) */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2445 vli_type count;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2446
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2447 /*
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2448 * Hash calculated from the Records (matches block.hash in
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2449 * valid files).
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2450 */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2451 struct xz_dec_hash hash;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2452 } index;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2453
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2454 /*
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2455 * Temporary buffer needed to hold Stream Header, Block Header,
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2456 * and Stream Footer. The Block Header is the biggest (1 KiB)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2457 * so we reserve space according to that. buf[] has to be aligned
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2458 * to a multiple of four bytes; the size_t variables before it
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2459 * should guarantee this.
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2460 */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2461 struct {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2462 size_t pos;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2463 size_t size;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2464 uint8_t buf[1024];
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2465 } temp;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2466
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2467 struct xz_dec_lzma2 *lzma2;
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2468
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 #ifdef XZ_DEC_BCJ
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2470 struct xz_dec_bcj *bcj;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2471 int bcj_active;
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2472 #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
2473 };
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /* 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
2476 static const uint8_t check_sizes[16] = {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2477 0,
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2478 4, 4, 4,
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2479 8, 8, 8,
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2480 16, 16, 16,
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2481 32, 32, 32,
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2482 64, 64, 64
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2483 };
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
2487 * 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
2488 * 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
2489 * 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
2490 */
851
db9878df884a More xzcat cleanup.
Rob Landley <rob@landley.net>
parents: 850
diff changeset
2491 static int fill_temp(struct xz_dec *s, struct xz_buf *b)
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2492 {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2493 size_t copy_size = min_t(size_t,
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2494 b->in_size - b->in_pos, s->temp.size - s->temp.pos);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2495
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2496 memcpy(s->temp.buf + s->temp.pos, b->in + b->in_pos, copy_size);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2497 b->in_pos += copy_size;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2498 s->temp.pos += copy_size;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2499
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2500 if (s->temp.pos == s->temp.size) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2501 s->temp.pos = 0;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2502 return 1;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2503 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2504
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2505 return 0;
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /* 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
2509 static enum xz_ret dec_vli(struct xz_dec *s, const uint8_t *in,
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2510 size_t *in_pos, size_t in_size)
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2511 {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2512 uint8_t byte;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2513
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2514 if (s->pos == 0)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2515 s->vli = 0;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2516
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2517 while (*in_pos < in_size) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2518 byte = in[*in_pos];
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2519 ++*in_pos;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2520
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2521 s->vli |= (vli_type)(byte & 0x7F) << s->pos;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2522
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2523 if ((byte & 0x80) == 0) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2524 /* Don't allow non-minimal encodings. */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2525 if (byte == 0 && s->pos != 0)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2526 return XZ_DATA_ERROR;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2527
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2528 s->pos = 0;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2529 return XZ_STREAM_END;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2530 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2531
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2532 s->pos += 7;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2533 if (s->pos == 7 * VLI_BYTES_MAX)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2534 return XZ_DATA_ERROR;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2535 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2536
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2537 return XZ_OK;
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2538 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
2542 * 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
2543 * 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
2544 * (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
2545 * 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
2546 * 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
2547 *
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
2549 * 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
2550 * 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
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 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
2553 {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2554 enum xz_ret ret;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2555
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2556 s->in_start = b->in_pos;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2557 s->out_start = b->out_pos;
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2558
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 #ifdef XZ_DEC_BCJ
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2560 if (s->bcj_active)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2561 ret = xz_dec_bcj_run(s->bcj, s->lzma2, b);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2562 else
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2563 #endif
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2564 ret = xz_dec_lzma2_run(s->lzma2, b);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2565
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2566 s->block.compressed += b->in_pos - s->in_start;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2567 s->block.uncompressed += b->out_pos - s->out_start;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2568
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2569 /*
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2570 * There is no need to separately check for VLI_UNKNOWN, since
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2571 * the observed sizes are always smaller than VLI_UNKNOWN.
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2572 */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2573 if (s->block.compressed > s->block_header.compressed
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2574 || s->block.uncompressed
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2575 > s->block_header.uncompressed)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2576 return XZ_DATA_ERROR;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2577
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2578 if (s->check_type == XZ_CHECK_CRC32)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2579 s->crc = xz_crc32(b->out + s->out_start,
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2580 b->out_pos - s->out_start, s->crc);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2581 else if (s->check_type == XZ_CHECK_CRC64)
944
b4faf2ae39e8 This inlines CRC64, and nothing more.
Isaac Dunham <idunham@lavabit.com>
parents: 855
diff changeset
2582 s->crc = ~(s->crc);
b4faf2ae39e8 This inlines CRC64, and nothing more.
Isaac Dunham <idunham@lavabit.com>
parents: 855
diff changeset
2583 size_t size = b->out_pos - s->out_start;
b4faf2ae39e8 This inlines CRC64, and nothing more.
Isaac Dunham <idunham@lavabit.com>
parents: 855
diff changeset
2584 uint8_t *buf = b->out + s->out_start;
b4faf2ae39e8 This inlines CRC64, and nothing more.
Isaac Dunham <idunham@lavabit.com>
parents: 855
diff changeset
2585 while (size) {
b4faf2ae39e8 This inlines CRC64, and nothing more.
Isaac Dunham <idunham@lavabit.com>
parents: 855
diff changeset
2586 s->crc = xz_crc64_table[*buf++ ^ (s->crc & 0xFF)] ^ (s->crc >> 8);
b4faf2ae39e8 This inlines CRC64, and nothing more.
Isaac Dunham <idunham@lavabit.com>
parents: 855
diff changeset
2587 --size;
b4faf2ae39e8 This inlines CRC64, and nothing more.
Isaac Dunham <idunham@lavabit.com>
parents: 855
diff changeset
2588 }
b4faf2ae39e8 This inlines CRC64, and nothing more.
Isaac Dunham <idunham@lavabit.com>
parents: 855
diff changeset
2589 s->crc=~(s->crc);
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2590
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2591 if (ret == XZ_STREAM_END) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2592 if (s->block_header.compressed != VLI_UNKNOWN
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2593 && s->block_header.compressed
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2594 != s->block.compressed)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2595 return XZ_DATA_ERROR;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2596
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2597 if (s->block_header.uncompressed != VLI_UNKNOWN
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2598 && s->block_header.uncompressed
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2599 != s->block.uncompressed)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2600 return XZ_DATA_ERROR;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2601
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2602 s->block.hash.unpadded += s->block_header.size
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2603 + s->block.compressed;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2604
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2605 s->block.hash.unpadded += check_sizes[s->check_type];
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2606
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2607 s->block.hash.uncompressed += s->block.uncompressed;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2608 s->block.hash.crc32 = xz_crc32(
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2609 (const uint8_t *)&s->block.hash,
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2610 sizeof(s->block.hash), s->block.hash.crc32);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2611
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2612 ++s->block.count;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2613 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2614
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2615 return ret;
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
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 /* 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
2619 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
2620 {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2621 size_t in_used = b->in_pos - s->in_start;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2622 s->index.size += in_used;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2623 s->crc = xz_crc32(b->in + s->in_start, in_used, s->crc);
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
2628 * 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
2629 * 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
2630 *
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
2632 * 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
2633 */
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 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
2635 {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2636 enum xz_ret ret;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2637
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2638 do {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2639 ret = dec_vli(s, b->in, &b->in_pos, b->in_size);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2640 if (ret != XZ_STREAM_END) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2641 index_update(s, b);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2642 return ret;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2643 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2644
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2645 switch (s->index.sequence) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2646 case SEQ_INDEX_COUNT:
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2647 s->index.count = s->vli;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2648
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2649 /*
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2650 * Validate that the Number of Records field
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2651 * indicates the same number of Records as
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2652 * there were Blocks in the Stream.
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2653 */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2654 if (s->index.count != s->block.count)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2655 return XZ_DATA_ERROR;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2656
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2657 s->index.sequence = SEQ_INDEX_UNPADDED;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2658 break;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2659
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2660 case SEQ_INDEX_UNPADDED:
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2661 s->index.hash.unpadded += s->vli;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2662 s->index.sequence = SEQ_INDEX_UNCOMPRESSED;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2663 break;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2664
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2665 case SEQ_INDEX_UNCOMPRESSED:
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2666 s->index.hash.uncompressed += s->vli;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2667 s->index.hash.crc32 = xz_crc32(
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2668 (const uint8_t *)&s->index.hash,
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2669 sizeof(s->index.hash),
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2670 s->index.hash.crc32);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2671 --s->index.count;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2672 s->index.sequence = SEQ_INDEX_UNPADDED;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2673 break;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2674 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2675 } while (s->index.count > 0);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2676
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2677 return XZ_STREAM_END;
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2678 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /*
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
2682 * 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
2683 * 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
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 static enum xz_ret crc_validate(struct xz_dec *s, struct xz_buf *b,
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2686 uint32_t bits)
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2687 {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2688 do {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2689 if (b->in_pos == b->in_size)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2690 return XZ_OK;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2691
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2692 if (((s->crc >> s->pos) & 0xFF) != b->in[b->in_pos++])
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2693 return XZ_DATA_ERROR;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2694
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2695 s->pos += 8;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2696
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2697 } while (s->pos < bits);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2698
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2699 s->crc = 0;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2700 s->pos = 0;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2701
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2702 return XZ_STREAM_END;
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
2707 * 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
2708 */
851
db9878df884a More xzcat cleanup.
Rob Landley <rob@landley.net>
parents: 850
diff changeset
2709 static int check_skip(struct xz_dec *s, struct xz_buf *b)
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2710 {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2711 while (s->pos < check_sizes[s->check_type]) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2712 if (b->in_pos == b->in_size) return 0;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2713
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2714 ++b->in_pos;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2715 ++s->pos;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2716 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2717
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2718 s->pos = 0;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2719
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2720 return 1;
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2721 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /* 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
2724 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
2725 {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2726 if (!memeq(s->temp.buf, HEADER_MAGIC, HEADER_MAGIC_SIZE))
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2727 return XZ_FORMAT_ERROR;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2728
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2729 if (xz_crc32(s->temp.buf + HEADER_MAGIC_SIZE, 2, 0)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2730 != get_le32(s->temp.buf + HEADER_MAGIC_SIZE + 2))
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2731 return XZ_DATA_ERROR;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2732
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2733 if (s->temp.buf[HEADER_MAGIC_SIZE] != 0)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2734 return XZ_OPTIONS_ERROR;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2735
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2736 /*
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2737 * Of integrity checks, we support none (Check ID = 0),
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2738 * CRC32 (Check ID = 1), and optionally CRC64 (Check ID = 4).
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2739 * However, if XZ_DEC_ANY_CHECK is defined, we will accept other
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2740 * check types too, but then the check won't be verified and
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2741 * a warning (XZ_UNSUPPORTED_CHECK) will be given.
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2742 */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2743 s->check_type = s->temp.buf[HEADER_MAGIC_SIZE + 1];
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2744
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2745 if (s->check_type > XZ_CHECK_MAX)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2746 return XZ_OPTIONS_ERROR;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2747
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2748 if (s->check_type > XZ_CHECK_CRC32 && !IS_CRC64(s->check_type))
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2749 return XZ_UNSUPPORTED_CHECK;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2750
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2751 return XZ_OK;
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2752 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /* 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
2755 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
2756 {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2757 if (!memeq(s->temp.buf + 10, FOOTER_MAGIC, FOOTER_MAGIC_SIZE))
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2758 return XZ_DATA_ERROR;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2759
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2760 if (xz_crc32(s->temp.buf + 4, 6, 0) != get_le32(s->temp.buf))
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2761 return XZ_DATA_ERROR;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2762
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2763 /*
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2764 * Validate Backward Size. Note that we never added the size of the
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2765 * Index CRC32 field to s->index.size, thus we use s->index.size / 4
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2766 * instead of s->index.size / 4 - 1.
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2767 */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2768 if ((s->index.size >> 2) != get_le32(s->temp.buf + 4))
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2769 return XZ_DATA_ERROR;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2770
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2771 if (s->temp.buf[8] != 0 || s->temp.buf[9] != s->check_type)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2772 return XZ_DATA_ERROR;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2773
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2774 /*
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2775 * Use XZ_STREAM_END instead of XZ_OK to be more convenient
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2776 * for the caller.
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2777 */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2778 return XZ_STREAM_END;
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2779 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 /* 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
2782 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
2783 {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2784 enum xz_ret ret;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2785
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2786 /*
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2787 * Validate the CRC32. We know that the temp buffer is at least
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2788 * eight bytes so this is safe.
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2789 */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2790 s->temp.size -= 4;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2791 if (xz_crc32(s->temp.buf, s->temp.size, 0)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2792 != get_le32(s->temp.buf + s->temp.size))
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2793 return XZ_DATA_ERROR;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2794
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2795 s->temp.pos = 2;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2796
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2797 /*
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2798 * Catch unsupported Block Flags. We support only one or two filters
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2799 * in the chain, so we catch that with the same test.
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2800 */
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
2801 #ifdef XZ_DEC_BCJ
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2802 if (s->temp.buf[1] & 0x3E)
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2803 #else
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2804 if (s->temp.buf[1] & 0x3F)
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2805 #endif
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2806 return XZ_OPTIONS_ERROR;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2807
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2808 /* Compressed Size */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2809 if (s->temp.buf[1] & 0x40) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2810 if (dec_vli(s, s->temp.buf, &s->temp.pos, s->temp.size)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2811 != XZ_STREAM_END)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2812 return XZ_DATA_ERROR;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2813
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2814 s->block_header.compressed = s->vli;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2815 } else {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2816 s->block_header.compressed = VLI_UNKNOWN;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2817 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2818
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2819 /* Uncompressed Size */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2820 if (s->temp.buf[1] & 0x80) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2821 if (dec_vli(s, s->temp.buf, &s->temp.pos, s->temp.size)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2822 != XZ_STREAM_END)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2823 return XZ_DATA_ERROR;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2824
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2825 s->block_header.uncompressed = s->vli;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2826 } else {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2827 s->block_header.uncompressed = VLI_UNKNOWN;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2828 }
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
2829
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 #ifdef XZ_DEC_BCJ
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2831 /* If there are two filters, the first one must be a BCJ filter. */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2832 s->bcj_active = s->temp.buf[1] & 0x01;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2833 if (s->bcj_active) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2834 if (s->temp.size - s->temp.pos < 2)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2835 return XZ_OPTIONS_ERROR;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2836
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2837 ret = xz_dec_bcj_reset(s->bcj, s->temp.buf[s->temp.pos++]);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2838 if (ret != XZ_OK)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2839 return ret;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2840
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2841 /*
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2842 * We don't support custom start offset,
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2843 * so Size of Properties must be zero.
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2844 */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2845 if (s->temp.buf[s->temp.pos++] != 0x00)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2846 return XZ_OPTIONS_ERROR;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2847 }
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
2848 #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
2849
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2850 /* Valid Filter Flags always take at least two bytes. */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2851 if (s->temp.size - s->temp.pos < 2)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2852 return XZ_DATA_ERROR;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2853
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2854 /* Filter ID = LZMA2 */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2855 if (s->temp.buf[s->temp.pos++] != 0x21)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2856 return XZ_OPTIONS_ERROR;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2857
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2858 /* Size of Properties = 1-byte Filter Properties */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2859 if (s->temp.buf[s->temp.pos++] != 0x01)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2860 return XZ_OPTIONS_ERROR;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2861
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2862 /* Filter Properties contains LZMA2 dictionary size. */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2863 if (s->temp.size - s->temp.pos < 1)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2864 return XZ_DATA_ERROR;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2865
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2866 ret = xz_dec_lzma2_reset(s->lzma2, s->temp.buf[s->temp.pos++]);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2867 if (ret != XZ_OK)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2868 return ret;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2869
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2870 /* The rest must be Header Padding. */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2871 while (s->temp.pos < s->temp.size)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2872 if (s->temp.buf[s->temp.pos++] != 0x00)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2873 return XZ_OPTIONS_ERROR;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2874
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2875 s->temp.pos = 0;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2876 s->block.compressed = 0;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2877 s->block.uncompressed = 0;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2878
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2879 return XZ_OK;
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
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 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
2883 {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2884 enum xz_ret ret;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2885
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2886 /*
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2887 * Store the start position for the case when we are in the middle
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2888 * of the Index field.
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2889 */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2890 s->in_start = b->in_pos;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2891
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2892 for (;;) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2893 switch (s->sequence) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2894 case SEQ_STREAM_HEADER:
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2895 /*
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2896 * Stream Header is copied to s->temp, and then
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2897 * decoded from there. This way if the caller
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2898 * gives us only little input at a time, we can
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2899 * still keep the Stream Header decoding code
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2900 * simple. Similar approach is used in many places
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2901 * in this file.
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2902 */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2903 if (!fill_temp(s, b))
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2904 return XZ_OK;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2905
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2906 /*
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2907 * If dec_stream_header() returns
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2908 * XZ_UNSUPPORTED_CHECK, it is still possible
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2909 * to continue decoding if working in multi-call
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2910 * mode. Thus, update s->sequence before calling
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2911 * dec_stream_header().
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2912 */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2913 s->sequence = SEQ_BLOCK_START;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2914
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2915 ret = dec_stream_header(s);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2916 if (ret != XZ_OK)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2917 return ret;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2918
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2919 case SEQ_BLOCK_START:
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2920 /* We need one byte of input to continue. */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2921 if (b->in_pos == b->in_size)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2922 return XZ_OK;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2923
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2924 /* See if this is the beginning of the Index field. */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2925 if (b->in[b->in_pos] == 0) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2926 s->in_start = b->in_pos++;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2927 s->sequence = SEQ_INDEX;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2928 break;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2929 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2930
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2931 /*
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2932 * Calculate the size of the Block Header and
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2933 * prepare to decode it.
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2934 */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2935 s->block_header.size
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2936 = ((uint32_t)b->in[b->in_pos] + 1) * 4;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2937
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2938 s->temp.size = s->block_header.size;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2939 s->temp.pos = 0;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2940 s->sequence = SEQ_BLOCK_HEADER;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2941
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2942 case SEQ_BLOCK_HEADER:
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2943 if (!fill_temp(s, b))
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2944 return XZ_OK;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2945
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2946 ret = dec_block_header(s);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2947 if (ret != XZ_OK)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2948 return ret;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2949
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2950 s->sequence = SEQ_BLOCK_UNCOMPRESS;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2951
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2952 case SEQ_BLOCK_UNCOMPRESS:
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2953 ret = dec_block(s, b);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2954 if (ret != XZ_STREAM_END)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2955 return ret;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2956
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2957 s->sequence = SEQ_BLOCK_PADDING;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2958
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2959 case SEQ_BLOCK_PADDING:
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2960 /*
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2961 * Size of Compressed Data + Block Padding
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2962 * must be a multiple of four. We don't need
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2963 * s->block.compressed for anything else
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2964 * anymore, so we use it here to test the size
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2965 * of the Block Padding field.
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2966 */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2967 while (s->block.compressed & 3) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2968 if (b->in_pos == b->in_size)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2969 return XZ_OK;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2970
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2971 if (b->in[b->in_pos++] != 0)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2972 return XZ_DATA_ERROR;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2973
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2974 ++s->block.compressed;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2975 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2976
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2977 s->sequence = SEQ_BLOCK_CHECK;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2978
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2979 case SEQ_BLOCK_CHECK:
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2980 if (s->check_type == XZ_CHECK_CRC32) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2981 ret = crc_validate(s, b, 32);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2982 if (ret != XZ_STREAM_END)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2983 return ret;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2984 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2985 else if (IS_CRC64(s->check_type)) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2986 ret = crc_validate(s, b, 64);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2987 if (ret != XZ_STREAM_END)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2988 return ret;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2989 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2990 else if (!check_skip(s, b)) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2991 return XZ_OK;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2992 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2993
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2994 s->sequence = SEQ_BLOCK_START;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2995 break;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2996
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2997 case SEQ_INDEX:
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2998 ret = dec_index(s, b);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
2999 if (ret != XZ_STREAM_END)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3000 return ret;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3001
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3002 s->sequence = SEQ_INDEX_PADDING;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3003
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3004 case SEQ_INDEX_PADDING:
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3005 while ((s->index.size + (b->in_pos - s->in_start))
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3006 & 3) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3007 if (b->in_pos == b->in_size) {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3008 index_update(s, b);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3009 return XZ_OK;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3010 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3011
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3012 if (b->in[b->in_pos++] != 0)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3013 return XZ_DATA_ERROR;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3014 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3015
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3016 /* Finish the CRC32 value and Index size. */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3017 index_update(s, b);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3018
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3019 /* Compare the hashes to validate the Index field. */
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3020 if (!memeq(&s->block.hash, &s->index.hash,
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3021 sizeof(s->block.hash)))
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3022 return XZ_DATA_ERROR;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3023
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3024 s->sequence = SEQ_INDEX_CRC32;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3025
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3026 case SEQ_INDEX_CRC32:
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3027 ret = crc_validate(s, b, 32);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3028 if (ret != XZ_STREAM_END)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3029 return ret;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3030
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3031 s->temp.size = STREAM_HEADER_SIZE;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3032 s->sequence = SEQ_STREAM_FOOTER;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3033
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3034 case SEQ_STREAM_FOOTER:
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3035 if (!fill_temp(s, b))
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3036 return XZ_OK;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3037
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3038 return dec_stream_footer(s);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3039 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3040 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3041
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3042 /* Never reached */
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
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
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
3047 * 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
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 * 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
3050 * 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
3051 * 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
3052 * 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
3053 * 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
3054 * 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
3055 * 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
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 * 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
3058 * 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
3059 * 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
3060 * 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
3061 * 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
3062 * 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
3063 *
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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 * 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
3065 * 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
3066 * 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
3067 * 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
3068 * 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
3069 */
846
e02b4e932cd1 Some xzcat cleanup by Isaac Dunham.
Rob Landley <rob@landley.net>
parents: 819
diff changeset
3070 enum xz_ret xz_dec_run(struct xz_dec *s, struct xz_buf *b)
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3071 {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3072 size_t in_start;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3073 size_t out_start;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3074 enum xz_ret ret;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3075
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3076 in_start = b->in_pos;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3077 out_start = b->out_pos;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3078 ret = dec_main(s, b);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3079
953
13916d161ec0 xzcat: remove XZ_(PREALLOC|SINGLE), inline xz_dec_bcj_create
Isaac Dunham <idunham@lavabit.com>
parents: 944
diff changeset
3080 if (ret == XZ_OK && in_start == b->in_pos && out_start == b->out_pos) {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3081 if (s->allow_buf_error)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3082 ret = XZ_BUF_ERROR;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3083
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3084 s->allow_buf_error = 1;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3085 } else {
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3086 s->allow_buf_error = 0;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3087 }
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3088
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3089 return ret;
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3090 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
967
e922fc4e7a2e This removes xz_mode.
Isaac Dunham <idunham@lavabit.com>
parents: 954
diff changeset
3092 struct xz_dec *xz_dec_init(uint32_t dict_max)
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3093 {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3094 struct xz_dec *s = malloc(sizeof(*s));
953
13916d161ec0 xzcat: remove XZ_(PREALLOC|SINGLE), inline xz_dec_bcj_create
Isaac Dunham <idunham@lavabit.com>
parents: 944
diff changeset
3095 if (!s)
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3096 return NULL;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3097
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
3098 #ifdef XZ_DEC_BCJ
953
13916d161ec0 xzcat: remove XZ_(PREALLOC|SINGLE), inline xz_dec_bcj_create
Isaac Dunham <idunham@lavabit.com>
parents: 944
diff changeset
3099 s->bcj = malloc(sizeof(*s->bcj));
13916d161ec0 xzcat: remove XZ_(PREALLOC|SINGLE), inline xz_dec_bcj_create
Isaac Dunham <idunham@lavabit.com>
parents: 944
diff changeset
3100 if (!s->bcj)
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3101 goto error_bcj;
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3102 #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
3103
967
e922fc4e7a2e This removes xz_mode.
Isaac Dunham <idunham@lavabit.com>
parents: 954
diff changeset
3104 s->lzma2 = xz_dec_lzma2_create(dict_max);
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3105 if (s->lzma2 == NULL)
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3106 goto error_lzma2;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3107
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3108 xz_dec_reset(s);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3109 return s;
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
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 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
3112 #ifdef XZ_DEC_BCJ
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3113 free(s->bcj);
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3114 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
3115 #endif
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3116 free(s);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3117 return NULL;
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3118 }
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one 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
846
e02b4e932cd1 Some xzcat cleanup by Isaac Dunham.
Rob Landley <rob@landley.net>
parents: 819
diff changeset
3120 void xz_dec_reset(struct xz_dec *s)
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3121 {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3122 s->sequence = SEQ_STREAM_HEADER;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3123 s->allow_buf_error = 0;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3124 s->pos = 0;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3125 s->crc = 0;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3126 memset(&s->block, 0, sizeof(s->block));
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3127 memset(&s->index, 0, sizeof(s->index));
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3128 s->temp.pos = 0;
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3129 s->temp.size = STREAM_HEADER_SIZE;
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
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
846
e02b4e932cd1 Some xzcat cleanup by Isaac Dunham.
Rob Landley <rob@landley.net>
parents: 819
diff changeset
3132 void xz_dec_end(struct xz_dec *s)
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3133 {
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3134 if (s != NULL) {
953
13916d161ec0 xzcat: remove XZ_(PREALLOC|SINGLE), inline xz_dec_bcj_create
Isaac Dunham <idunham@lavabit.com>
parents: 944
diff changeset
3135 free((s->lzma2)->dict.buf);
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3136 free(s->lzma2);
854
68cdd244f8b1 xzcat: more cleanup and some shrinking.
Isaac Dunham <idunham@lavabit.com>
parents: 851
diff changeset
3137
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
3138 #ifdef XZ_DEC_BCJ
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3139 free(s->bcj);
819
547f6c1d6972 Isaac Dunham took the public domain xz-embedded code and made an xzcat. I glued all his files together into one big one and threw it in pending. It needs something between cleanup and a complete rewrite.
Rob Landley <rob@landley.net>
parents:
diff changeset
3140 #endif
855
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3141 free(s);
88060f1ff4a4 Convert tabs to spaces.
Rob Landley <rob@landley.net>
parents: 854
diff changeset
3142 }
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
3143 }