]> icculus.org git repositories - icculus/xz.git/blob - src/liblzma/common/raw_decoder.c
Update the code to mostly match the new simpler file format
[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 "simple_coder.h"
22 #include "subblock_decoder.h"
23 #include "subblock_decoder_helper.h"
24 #include "delta_decoder.h"
25 #include "lzma_decoder.h"
26
27
28 static lzma_init_function
29 get_function(lzma_vli id)
30 {
31         switch (id) {
32 #ifdef HAVE_FILTER_SUBBLOCK
33         case LZMA_FILTER_SUBBLOCK:
34                 return &lzma_subblock_decoder_init;
35 #endif
36
37 #ifdef HAVE_FILTER_X86
38         case LZMA_FILTER_X86:
39                 return &lzma_simple_x86_decoder_init;
40 #endif
41
42 #ifdef HAVE_FILTER_POWERPC
43         case LZMA_FILTER_POWERPC:
44                 return &lzma_simple_powerpc_decoder_init;
45 #endif
46
47 #ifdef HAVE_FILTER_IA64
48         case LZMA_FILTER_IA64:
49                 return &lzma_simple_ia64_decoder_init;
50 #endif
51
52 #ifdef HAVE_FILTER_ARM
53         case LZMA_FILTER_ARM:
54                 return &lzma_simple_arm_decoder_init;
55 #endif
56
57 #ifdef HAVE_FILTER_ARMTHUMB
58         case LZMA_FILTER_ARMTHUMB:
59                 return &lzma_simple_armthumb_decoder_init;
60 #endif
61
62 #ifdef HAVE_FILTER_SPARC
63         case LZMA_FILTER_SPARC:
64                 return &lzma_simple_sparc_decoder_init;
65 #endif
66
67 #ifdef HAVE_FILTER_DELTA
68         case LZMA_FILTER_DELTA:
69                 return &lzma_delta_decoder_init;
70 #endif
71
72 #ifdef HAVE_FILTER_LZMA
73         case LZMA_FILTER_LZMA:
74                 return &lzma_lzma_decoder_init;
75 #endif
76
77 #ifdef HAVE_FILTER_SUBBLOCK
78         case LZMA_FILTER_SUBBLOCK_HELPER:
79                 return &lzma_subblock_decoder_helper_init;
80 #endif
81         }
82
83         return NULL;
84 }
85
86
87 extern lzma_ret
88 lzma_raw_decoder_init(lzma_next_coder *next, lzma_allocator *allocator,
89                 const lzma_options_filter *options)
90 {
91         const lzma_ret ret = lzma_raw_coder_init(next, allocator,
92                         options, &get_function, false);
93
94         if (ret != LZMA_OK)
95                 lzma_next_coder_end(next, allocator);
96
97         return ret;
98 }
99
100
101 extern LZMA_API lzma_ret
102 lzma_raw_decoder(lzma_stream *strm, const lzma_options_filter *options)
103 {
104         return_if_error(lzma_strm_init(strm));
105
106         strm->internal->supported_actions[LZMA_RUN] = true;
107         strm->internal->supported_actions[LZMA_SYNC_FLUSH] = true;
108
109         const lzma_ret ret = lzma_raw_coder_init(&strm->internal->next,
110                         strm->allocator, options, &get_function, false);
111
112         if (ret != LZMA_OK)
113                 lzma_end(strm);
114
115         return ret;
116 }