aboutsummaryrefslogtreecommitdiff
path: root/src/liblzma/common
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/liblzma/common/filter_common.h3
-rw-r--r--src/liblzma/common/filter_decoder.c80
-rw-r--r--src/liblzma/common/filter_decoder.h5
-rw-r--r--src/liblzma/common/filter_encoder.c82
-rw-r--r--src/liblzma/common/filter_encoder.h4
5 files changed, 54 insertions, 120 deletions
diff --git a/src/liblzma/common/filter_common.h b/src/liblzma/common/filter_common.h
index 9def50b9..5241e5df 100644
--- a/src/liblzma/common/filter_common.h
+++ b/src/liblzma/common/filter_common.h
@@ -25,6 +25,9 @@
/// Both lzma_filter_encoder and lzma_filter_decoder begin with these members.
typedef struct {
+ /// Filter ID
+ lzma_vli id;
+
/// Initializes the filter encoder and calls lzma_next_filter_init()
/// for filters + 1.
lzma_init_function init;
diff --git a/src/liblzma/common/filter_decoder.c b/src/liblzma/common/filter_decoder.c
index 5eb6d770..fb5632e8 100644
--- a/src/liblzma/common/filter_decoder.c
+++ b/src/liblzma/common/filter_decoder.c
@@ -28,6 +28,9 @@
typedef struct {
+ /// Filter ID
+ lzma_vli id;
+
/// Initializes the filter encoder and calls lzma_next_filter_init()
/// for filters + 1.
lzma_init_function init;
@@ -47,60 +50,10 @@ typedef struct {
} lzma_filter_decoder;
-static const lzma_vli ids[] = {
-#ifdef HAVE_DECODER_LZMA
- LZMA_FILTER_LZMA,
-#endif
-
-#ifdef HAVE_DECODER_LZMA2
- LZMA_FILTER_LZMA2,
-#endif
-
-#ifdef HAVE_DECODER_SUBBLOCK
- LZMA_FILTER_SUBBLOCK,
- LZMA_FILTER_SUBBLOCK_HELPER,
-#endif
-
-#ifdef HAVE_DECODER_X86
- LZMA_FILTER_X86,
-#endif
-
-#ifdef HAVE_DECODER_POWERPC
- LZMA_FILTER_POWERPC,
-#endif
-
-#ifdef HAVE_DECODER_IA64
- LZMA_FILTER_IA64,
-#endif
-
-#ifdef HAVE_DECODER_ARM
- LZMA_FILTER_ARM,
-#endif
-
-#ifdef HAVE_DECODER_ARMTHUMB
- LZMA_FILTER_ARMTHUMB,
-#endif
-
-#ifdef HAVE_DECODER_SPARC
- LZMA_FILTER_SPARC,
-#endif
-
-#ifdef HAVE_DECODER_DELTA
- LZMA_FILTER_DELTA,
-#endif
-
- LZMA_VLI_VALUE_UNKNOWN
-};
-
-
-// Using a pointer to avoid putting the size of the array to API/ABI.
-LZMA_API const lzma_vli *const lzma_filter_decoders = ids;
-
-
-// These must be in the same order as ids[].
-static const lzma_filter_decoder funcs[] = {
+static const lzma_filter_decoder decoders[] = {
#ifdef HAVE_DECODER_LZMA
{
+ .id = LZMA_FILTER_LZMA,
.init = &lzma_lzma_decoder_init,
.memusage = &lzma_lzma_decoder_memusage,
.props_decode = &lzma_lzma_props_decode,
@@ -108,6 +61,7 @@ static const lzma_filter_decoder funcs[] = {
#endif
#ifdef HAVE_DECODER_LZMA2
{
+ .id = LZMA_FILTER_LZMA2,
.init = &lzma_lzma2_decoder_init,
.memusage = &lzma_lzma2_decoder_memusage,
.props_decode = &lzma_lzma2_props_decode,
@@ -115,11 +69,13 @@ static const lzma_filter_decoder funcs[] = {
#endif
#ifdef HAVE_DECODER_SUBBLOCK
{
+ .id = LZMA_FILTER_SUBBLOCK,
.init = &lzma_subblock_decoder_init,
// .memusage = &lzma_subblock_decoder_memusage,
.props_decode = NULL,
},
{
+ .id = LZMA_FILTER_SUBBLOCK_HELPER,
.init = &lzma_subblock_decoder_helper_init,
.memusage = NULL,
.props_decode = NULL,
@@ -127,6 +83,7 @@ static const lzma_filter_decoder funcs[] = {
#endif
#ifdef HAVE_DECODER_X86
{
+ .id = LZMA_FILTER_X86,
.init = &lzma_simple_x86_decoder_init,
.memusage = NULL,
.props_decode = &lzma_simple_props_decode,
@@ -134,6 +91,7 @@ static const lzma_filter_decoder funcs[] = {
#endif
#ifdef HAVE_DECODER_POWERPC
{
+ .id = LZMA_FILTER_POWERPC,
.init = &lzma_simple_powerpc_decoder_init,
.memusage = NULL,
.props_decode = &lzma_simple_props_decode,
@@ -141,6 +99,7 @@ static const lzma_filter_decoder funcs[] = {
#endif
#ifdef HAVE_DECODER_IA64
{
+ .id = LZMA_FILTER_IA64,
.init = &lzma_simple_ia64_decoder_init,
.memusage = NULL,
.props_decode = &lzma_simple_props_decode,
@@ -148,6 +107,7 @@ static const lzma_filter_decoder funcs[] = {
#endif
#ifdef HAVE_DECODER_ARM
{
+ .id = LZMA_FILTER_ARM,
.init = &lzma_simple_arm_decoder_init,
.memusage = NULL,
.props_decode = &lzma_simple_props_decode,
@@ -155,6 +115,7 @@ static const lzma_filter_decoder funcs[] = {
#endif
#ifdef HAVE_DECODER_ARMTHUMB
{
+ .id = LZMA_FILTER_ARMTHUMB,
.init = &lzma_simple_armthumb_decoder_init,
.memusage = NULL,
.props_decode = &lzma_simple_props_decode,
@@ -162,6 +123,7 @@ static const lzma_filter_decoder funcs[] = {
#endif
#ifdef HAVE_DECODER_SPARC
{
+ .id = LZMA_FILTER_SPARC,
.init = &lzma_simple_sparc_decoder_init,
.memusage = NULL,
.props_decode = &lzma_simple_props_decode,
@@ -169,6 +131,7 @@ static const lzma_filter_decoder funcs[] = {
#endif
#ifdef HAVE_DECODER_DELTA
{
+ .id = LZMA_FILTER_DELTA,
.init = &lzma_delta_decoder_init,
.memusage = NULL,
.props_decode = &lzma_delta_props_decode,
@@ -180,14 +143,21 @@ static const lzma_filter_decoder funcs[] = {
static const lzma_filter_decoder *
decoder_find(lzma_vli id)
{
- for (size_t i = 0; ids[i] != LZMA_VLI_VALUE_UNKNOWN; ++i)
- if (ids[i] == id)
- return funcs + i;
+ for (size_t i = 0; i < ARRAY_SIZE(decoders); ++i)
+ if (decoders[i].id == id)
+ return decoders + i;
return NULL;
}
+extern LZMA_API lzma_bool
+lzma_filter_decoder_is_supported(lzma_vli id)
+{
+ return decoder_find(id) != NULL;
+}
+
+
extern lzma_ret
lzma_raw_decoder_init(lzma_next_coder *next, lzma_allocator *allocator,
const lzma_filter *options)
diff --git a/src/liblzma/common/filter_decoder.h b/src/liblzma/common/filter_decoder.h
index 33e491d1..6d651e69 100644
--- a/src/liblzma/common/filter_decoder.h
+++ b/src/liblzma/common/filter_decoder.h
@@ -22,11 +22,6 @@
#include "common.h"
-// FIXME !!! Public API
-extern lzma_ret lzma_properties_decode(
- lzma_filter *filter, lzma_allocator *allocator,
- const uint8_t *props, size_t props_size);
-
extern lzma_ret lzma_raw_decoder_init(
lzma_next_coder *next, lzma_allocator *allocator,
diff --git a/src/liblzma/common/filter_encoder.c b/src/liblzma/common/filter_encoder.c
index 55862e18..8f2c517f 100644
--- a/src/liblzma/common/filter_encoder.c
+++ b/src/liblzma/common/filter_encoder.c
@@ -27,6 +27,9 @@
typedef struct {
+ /// Filter ID
+ lzma_vli id;
+
/// Initializes the filter encoder and calls lzma_next_filter_init()
/// for filters + 1.
lzma_init_function init;
@@ -58,59 +61,10 @@ typedef struct {
} lzma_filter_encoder;
-static const lzma_vli ids[] = {
-#ifdef HAVE_ENCODER_LZMA
- LZMA_FILTER_LZMA,
-#endif
-
-#ifdef HAVE_ENCODER_LZMA2
- LZMA_FILTER_LZMA2,
-#endif
-
-#ifdef HAVE_ENCODER_SUBBLOCK
- LZMA_FILTER_SUBBLOCK,
-#endif
-
-#ifdef HAVE_ENCODER_X86
- LZMA_FILTER_X86,
-#endif
-
-#ifdef HAVE_ENCODER_POWERPC
- LZMA_FILTER_POWERPC,
-#endif
-
-#ifdef HAVE_ENCODER_IA64
- LZMA_FILTER_IA64,
-#endif
-
-#ifdef HAVE_ENCODER_ARM
- LZMA_FILTER_ARM,
-#endif
-
-#ifdef HAVE_ENCODER_ARMTHUMB
- LZMA_FILTER_ARMTHUMB,
-#endif
-
-#ifdef HAVE_ENCODER_SPARC
- LZMA_FILTER_SPARC,
-#endif
-
-#ifdef HAVE_ENCODER_DELTA
- LZMA_FILTER_DELTA,
-#endif
-
- LZMA_VLI_VALUE_UNKNOWN
-};
-
-
-// Using a pointer to avoid putting the size of the array to API/ABI.
-LZMA_API const lzma_vli *const lzma_filter_encoders = ids;
-
-
-// These must be in the same order as ids[].
-static const lzma_filter_encoder funcs[] = {
+static const lzma_filter_encoder encoders[] = {
#ifdef HAVE_ENCODER_LZMA
{
+ .id = LZMA_FILTER_LZMA,
.init = &lzma_lzma_encoder_init,
.memusage = &lzma_lzma_encoder_memusage,
.chunk_size = NULL, // FIXME
@@ -121,6 +75,7 @@ static const lzma_filter_encoder funcs[] = {
#endif
#ifdef HAVE_ENCODER_LZMA2
{
+ .id = LZMA_FILTER_LZMA2,
.init = &lzma_lzma2_encoder_init,
.memusage = &lzma_lzma2_encoder_memusage,
.chunk_size = NULL, // FIXME
@@ -131,6 +86,7 @@ static const lzma_filter_encoder funcs[] = {
#endif
#ifdef HAVE_ENCODER_SUBBLOCK
{
+ .id = LZMA_FILTER_SUBBLOCK,
.init = &lzma_subblock_encoder_init,
// .memusage = &lzma_subblock_encoder_memusage,
.chunk_size = NULL,
@@ -141,6 +97,7 @@ static const lzma_filter_encoder funcs[] = {
#endif
#ifdef HAVE_ENCODER_X86
{
+ .id = LZMA_FILTER_X86,
.init = &lzma_simple_x86_encoder_init,
.memusage = NULL,
.chunk_size = NULL,
@@ -150,6 +107,7 @@ static const lzma_filter_encoder funcs[] = {
#endif
#ifdef HAVE_ENCODER_POWERPC
{
+ .id = LZMA_FILTER_POWERPC,
.init = &lzma_simple_powerpc_encoder_init,
.memusage = NULL,
.chunk_size = NULL,
@@ -159,6 +117,7 @@ static const lzma_filter_encoder funcs[] = {
#endif
#ifdef HAVE_ENCODER_IA64
{
+ .id = LZMA_FILTER_IA64,
.init = &lzma_simple_ia64_encoder_init,
.memusage = NULL,
.chunk_size = NULL,
@@ -168,6 +127,7 @@ static const lzma_filter_encoder funcs[] = {
#endif
#ifdef HAVE_ENCODER_ARM
{
+ .id = LZMA_FILTER_ARM,
.init = &lzma_simple_arm_encoder_init,
.memusage = NULL,
.chunk_size = NULL,
@@ -177,6 +137,7 @@ static const lzma_filter_encoder funcs[] = {
#endif
#ifdef HAVE_ENCODER_ARMTHUMB
{
+ .id = LZMA_FILTER_ARMTHUMB,
.init = &lzma_simple_armthumb_encoder_init,
.memusage = NULL,
.chunk_size = NULL,
@@ -186,6 +147,7 @@ static const lzma_filter_encoder funcs[] = {
#endif
#ifdef HAVE_ENCODER_SPARC
{
+ .id = LZMA_FILTER_SPARC,
.init = &lzma_simple_sparc_encoder_init,
.memusage = NULL,
.chunk_size = NULL,
@@ -195,6 +157,7 @@ static const lzma_filter_encoder funcs[] = {
#endif
#ifdef HAVE_ENCODER_DELTA
{
+ .id = LZMA_FILTER_DELTA,
.init = &lzma_delta_encoder_init,
.memusage = NULL,
.chunk_size = NULL,
@@ -209,14 +172,21 @@ static const lzma_filter_encoder funcs[] = {
static const lzma_filter_encoder *
encoder_find(lzma_vli id)
{
- for (size_t i = 0; ids[i] != LZMA_VLI_VALUE_UNKNOWN; ++i)
- if (ids[i] == id)
- return funcs + i;
+ for (size_t i = 0; i < ARRAY_SIZE(encoders); ++i)
+ if (encoders[i].id == id)
+ return encoders + i;
return NULL;
}
+extern LZMA_API lzma_bool
+lzma_filter_encoder_is_supported(lzma_vli id)
+{
+ return encoder_find(id) != NULL;
+}
+
+
extern lzma_ret
lzma_raw_encoder_init(lzma_next_coder *next, lzma_allocator *allocator,
const lzma_filter *options)
@@ -251,7 +221,7 @@ lzma_memusage_encoder(const lzma_filter *filters)
extern LZMA_API lzma_vli
lzma_chunk_size(const lzma_filter *filters)
{
- uint64_t max = 0;
+ lzma_vli max = 0;
for (size_t i = 0; filters[i].id != LZMA_VLI_VALUE_UNKNOWN; ++i) {
const lzma_filter_encoder *const fe
@@ -285,7 +255,7 @@ lzma_properties_size(uint32_t *size, const lzma_filter *filter)
}
if (fe->props_size_get == NULL) {
- // No props_size() function, use props_size_fixed.
+ // No props_size_get() function, use props_size_fixed.
*size = fe->props_size_fixed;
return LZMA_OK;
}
diff --git a/src/liblzma/common/filter_encoder.h b/src/liblzma/common/filter_encoder.h
index b2bf851d..55201258 100644
--- a/src/liblzma/common/filter_encoder.h
+++ b/src/liblzma/common/filter_encoder.h
@@ -25,10 +25,6 @@
// FIXME !!! Public API
extern lzma_vli lzma_chunk_size(const lzma_filter *filters);
-extern lzma_ret lzma_properties_size(
- uint32_t *size, const lzma_filter *filter);
-extern lzma_ret lzma_properties_encode(
- const lzma_filter *filter, uint8_t *props);
extern lzma_ret lzma_raw_encoder_init(