]> icculus.org git repositories - icculus/xz.git/blob - src/liblzma/common/raw_encoder.c
Update the code to mostly match the new simpler file format
[icculus/xz.git] / src / liblzma / common / raw_encoder.c
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 /// \file       raw_encoder.c
4 /// \brief      Raw encoder 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_encoder.h"
21 #include "simple_coder.h"
22 #include "subblock_encoder.h"
23 #include "delta_encoder.h"
24 #include "lzma_encoder.h"
25
26
27 static lzma_init_function
28 get_function(lzma_vli id)
29 {
30         switch (id) {
31 #ifdef HAVE_FILTER_SUBBLOCK
32         case LZMA_FILTER_SUBBLOCK:
33                 return &lzma_subblock_encoder_init;
34 #endif
35
36 #ifdef HAVE_FILTER_X86
37         case LZMA_FILTER_X86:
38                 return &lzma_simple_x86_encoder_init;
39 #endif
40
41 #ifdef HAVE_FILTER_POWERPC
42         case LZMA_FILTER_POWERPC:
43                 return &lzma_simple_powerpc_encoder_init;
44 #endif
45
46 #ifdef HAVE_FILTER_IA64
47         case LZMA_FILTER_IA64:
48                 return &lzma_simple_ia64_encoder_init;
49 #endif
50
51 #ifdef HAVE_FILTER_ARM
52         case LZMA_FILTER_ARM:
53                 return &lzma_simple_arm_encoder_init;
54 #endif
55
56 #ifdef HAVE_FILTER_ARMTHUMB
57         case LZMA_FILTER_ARMTHUMB:
58                 return &lzma_simple_armthumb_encoder_init;
59 #endif
60
61 #ifdef HAVE_FILTER_SPARC
62         case LZMA_FILTER_SPARC:
63                 return &lzma_simple_sparc_encoder_init;
64 #endif
65
66 #ifdef HAVE_FILTER_DELTA
67         case LZMA_FILTER_DELTA:
68                 return &lzma_delta_encoder_init;
69 #endif
70
71 #ifdef HAVE_FILTER_LZMA
72         case LZMA_FILTER_LZMA:
73                 return &lzma_lzma_encoder_init;
74 #endif
75         }
76
77         return NULL;
78 }
79
80
81 extern lzma_ret
82 lzma_raw_encoder_init(lzma_next_coder *next, lzma_allocator *allocator,
83                 const lzma_options_filter *options)
84 {
85         const lzma_ret ret = lzma_raw_coder_init(next, allocator,
86                         options, &get_function, true);
87
88         if (ret != LZMA_OK)
89                 lzma_next_coder_end(next, allocator);
90
91         return ret;
92 }
93
94
95 extern LZMA_API lzma_ret
96 lzma_raw_encoder(lzma_stream *strm, const lzma_options_filter *options)
97 {
98         return_if_error(lzma_strm_init(strm));
99
100         strm->internal->supported_actions[LZMA_RUN] = true;
101         strm->internal->supported_actions[LZMA_SYNC_FLUSH] = true;
102         strm->internal->supported_actions[LZMA_FINISH] = true;
103
104         const lzma_ret ret = lzma_raw_coder_init(&strm->internal->next,
105                         strm->allocator, options, &get_function, true);
106
107         if (ret != LZMA_OK)
108                 lzma_end(strm);
109
110         return ret;
111 }