]> icculus.org git repositories - icculus/xz.git/blob - src/liblzma/common/raw_decoder.c
Made lzma_extra pointers const in lzma_options_stream.
[icculus/xz.git] / src / liblzma / common / raw_decoder.c
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 /// \file       raw_decoder.c
4 /// \brief      Raw decoder initialization API
5 //
6 //  Copyright (C) 2007 Lasse Collin
7 //
8 //  This library is free software; you can redistribute it and/or
9 //  modify it under the terms of the GNU Lesser General Public
10 //  License as published by the Free Software Foundation; either
11 //  version 2.1 of the License, or (at your option) any later version.
12 //
13 //  This library is distributed in the hope that it will be useful,
14 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
15 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 //  Lesser General Public License for more details.
17 //
18 ///////////////////////////////////////////////////////////////////////////////
19
20 #include "raw_decoder.h"
21 #include "copy_coder.h"
22 #include "simple_coder.h"
23 #include "subblock_decoder.h"
24 #include "subblock_decoder_helper.h"
25 #include "delta_decoder.h"
26 #include "lzma_decoder.h"
27 #include "metadata_decoder.h"
28
29
30 static lzma_init_function
31 get_function(lzma_vli id)
32 {
33         switch (id) {
34 #ifdef HAVE_FILTER_COPY
35         case LZMA_FILTER_COPY:
36                 return &lzma_copy_decoder_init;
37 #endif
38
39 #ifdef HAVE_FILTER_SUBBLOCK
40         case LZMA_FILTER_SUBBLOCK:
41                 return &lzma_subblock_decoder_init;
42 #endif
43
44 #ifdef HAVE_FILTER_X86
45         case LZMA_FILTER_X86:
46                 return &lzma_simple_x86_decoder_init;
47 #endif
48
49 #ifdef HAVE_FILTER_POWERPC
50         case LZMA_FILTER_POWERPC:
51                 return &lzma_simple_powerpc_decoder_init;
52 #endif
53
54 #ifdef HAVE_FILTER_IA64
55         case LZMA_FILTER_IA64:
56                 return &lzma_simple_ia64_decoder_init;
57 #endif
58
59 #ifdef HAVE_FILTER_ARM
60         case LZMA_FILTER_ARM:
61                 return &lzma_simple_arm_decoder_init;
62 #endif
63
64 #ifdef HAVE_FILTER_ARMTHUMB
65         case LZMA_FILTER_ARMTHUMB:
66                 return &lzma_simple_armthumb_decoder_init;
67 #endif
68
69 #ifdef HAVE_FILTER_SPARC
70         case LZMA_FILTER_SPARC:
71                 return &lzma_simple_sparc_decoder_init;
72 #endif
73
74 #ifdef HAVE_FILTER_DELTA
75         case LZMA_FILTER_DELTA:
76                 return &lzma_delta_decoder_init;
77 #endif
78
79 #ifdef HAVE_FILTER_LZMA
80         case LZMA_FILTER_LZMA:
81                 return &lzma_lzma_decoder_init;
82 #endif
83
84 #ifdef HAVE_FILTER_SUBBLOCK
85         case LZMA_FILTER_SUBBLOCK_HELPER:
86                 return &lzma_subblock_decoder_helper_init;
87 #endif
88         }
89
90         return NULL;
91 }
92
93
94 extern lzma_ret
95 lzma_raw_decoder_init(lzma_next_coder *next, lzma_allocator *allocator,
96                 const lzma_options_filter *options,
97                 lzma_vli uncompressed_size, bool allow_implicit)
98 {
99         const lzma_ret ret = lzma_raw_coder_init(next, allocator,
100                         options, uncompressed_size, &get_function,
101                         allow_implicit, false);
102
103         if (ret != LZMA_OK)
104                 lzma_next_coder_end(next, allocator);
105
106         return ret;
107 }
108
109
110 extern LZMA_API lzma_ret
111 lzma_raw_decoder(lzma_stream *strm, const lzma_options_filter *options,
112                 lzma_vli uncompressed_size, lzma_bool allow_implicit)
113 {
114         return_if_error(lzma_strm_init(strm));
115
116         strm->internal->supported_actions[LZMA_RUN] = true;
117         strm->internal->supported_actions[LZMA_SYNC_FLUSH] = true;
118
119         const lzma_ret ret = lzma_raw_coder_init(&strm->internal->next,
120                         strm->allocator, options, uncompressed_size,
121                         &get_function, allow_implicit, false);
122
123         if (ret != LZMA_OK)
124                 lzma_end(strm);
125
126         return ret;
127 }