aboutsummaryrefslogtreecommitdiff
path: root/src/lzma
diff options
context:
space:
mode:
authorLasse Collin <lasse.collin@tukaani.org>2008-09-27 19:09:21 +0300
committerLasse Collin <lasse.collin@tukaani.org>2008-09-27 19:09:21 +0300
commit1dcecfb09b55157b8653d747963069c8bed74f04 (patch)
tree81fa1f1e8bf6871981970ca826d897db6f33527b /src/lzma
parentAdded 7z2lzma.bash. (diff)
downloadxz-1dcecfb09b55157b8653d747963069c8bed74f04.tar.xz
Some API changes, bug fixes, cleanups etc.
Diffstat (limited to 'src/lzma')
-rw-r--r--src/lzma/args.c33
-rw-r--r--src/lzma/help.c17
-rw-r--r--src/lzma/options.c92
3 files changed, 82 insertions, 60 deletions
diff --git a/src/lzma/args.c b/src/lzma/args.c
index 2ddb93ed..ddaa0f91 100644
--- a/src/lzma/args.c
+++ b/src/lzma/args.c
@@ -124,7 +124,7 @@ static const struct option long_opts[] = {
static void
add_filter(lzma_vli id, const char *opt_str)
{
- if (filter_count == 7) {
+ if (filter_count == LZMA_BLOCK_FILTERS_MAX) {
errmsg(V_ERROR, _("Maximum number of filters is seven"));
my_exit(ERROR);
}
@@ -142,7 +142,7 @@ add_filter(lzma_vli id, const char *opt_str)
= parse_options_delta(opt_str);
break;
- case LZMA_FILTER_LZMA:
+ case LZMA_FILTER_LZMA1:
case LZMA_FILTER_LZMA2:
opt_filters[filter_count].options
= parse_options_lzma(opt_str);
@@ -301,7 +301,7 @@ parse_real(int argc, char **argv)
break;
case OPT_LZMA1:
- add_filter(LZMA_FILTER_LZMA, optarg);
+ add_filter(LZMA_FILTER_LZMA1, optarg);
break;
case OPT_LZMA2:
@@ -452,11 +452,17 @@ parse_environment(void)
static void
set_compression_settings(void)
{
+ static lzma_options_lzma opt_lzma;
+
if (filter_count == 0) {
+ if (lzma_lzma_preset(&opt_lzma, preset_number)) {
+ errmsg(V_ERROR, _("Internal error (bug)"));
+ my_exit(ERROR);
+ }
+
opt_filters[0].id = opt_header == HEADER_ALONE
- ? LZMA_FILTER_LZMA : LZMA_FILTER_LZMA2;
- opt_filters[0].options = (lzma_options_lzma *)(
- lzma_preset_lzma + preset_number);
+ ? LZMA_FILTER_LZMA1 : LZMA_FILTER_LZMA2;
+ opt_filters[0].options = &opt_lzma;
filter_count = 1;
}
@@ -466,12 +472,14 @@ set_compression_settings(void)
// If we are using the LZMA_Alone format, allow exactly one filter
// which has to be LZMA.
if (opt_header == HEADER_ALONE && (filter_count != 1
- || opt_filters[0].id != LZMA_FILTER_LZMA)) {
- errmsg(V_ERROR, _("With --format=alone only the LZMA filter "
+ || opt_filters[0].id != LZMA_FILTER_LZMA1)) {
+ errmsg(V_ERROR, _("With --format=alone only the LZMA1 filter "
"is supported"));
my_exit(ERROR);
}
+ // TODO: liblzma probably needs an API to validate the filter chain.
+
// If using --format=raw, we can be decoding.
uint64_t memory_usage = opt_mode == MODE_COMPRESS
? lzma_memusage_encoder(opt_filters)
@@ -488,10 +496,11 @@ set_compression_settings(void)
my_exit(ERROR);
}
- --preset_number;
- opt_filters[0].options = (lzma_options_lzma *)(
- lzma_preset_lzma
- + preset_number);
+ if (lzma_lzma_preset(&opt_lzma, --preset_number)) {
+ errmsg(V_ERROR, _("Internal error (bug)"));
+ my_exit(ERROR);
+ }
+
memory_usage = lzma_memusage_encoder(opt_filters);
}
} else {
diff --git a/src/lzma/help.c b/src/lzma/help.c
index d4888653..0b530ff5 100644
--- a/src/lzma/help.c
+++ b/src/lzma/help.c
@@ -82,13 +82,13 @@ show_help(void)
" --lzma1=[OPTS] LZMA1 or LZMA2; OPTS is a comma-separated list of zero or\n"
" --lzma2=[OPTS] more of the following options (valid values; default):\n"
" dict=NUM dictionary size in bytes (1 - 1GiB; 8MiB)\n"
-" lc=NUM number of literal context bits (0-8; 3)\n"
+" lc=NUM number of literal context bits (0-4; 3)\n"
" lp=NUM number of literal position bits (0-4; 0)\n"
" pb=NUM number of position bits (0-4; 2)\n"
" mode=MODE compression mode (`fast' or `best'; `best')\n"
-" fb=NUM number of fast bytes (5-273; 128)\n"
+" nice=NUM nice length of a match (2-273; 64)\n"
" mf=NAME match finder (hc3, hc4, bt2, bt3, bt4; bt4)\n"
-" mfc=NUM match finder cycles; 0=automatic (default)\n"
+" depth=NUM maximum search depth; 0=automatic (default)\n"
"\n"
" --x86 x86 filter (sometimes called BCJ filter)\n"
" --powerpc PowerPC (big endian) filter\n"
@@ -98,14 +98,13 @@ show_help(void)
" --sparc SPARC filter\n"
"\n"
" --delta=[OPTS] Delta filter; valid OPTS (valid values; default):\n"
-" distance=NUM Distance between bytes being\n"
-" subtracted from each other (1-256; 1)\n"
+" dist=NUM distance between bytes being subtracted\n"
+" from each other (1-256; 1)\n"
"\n"
-" --copy No filtering (useful only when specified alone)\n"
" --subblock=[OPTS] Subblock filter; valid OPTS (valid values; default):\n"
-" size=NUM number of bytes of data per subblock\n"
-" (1 - 256Mi; 4Ki)\n"
-" rle=NUM run-length encoder chunk size (0-256; 0)\n"
+" size=NUM number of bytes of data per subblock\n"
+" (1 - 256Mi; 4Ki)\n"
+" rle=NUM run-length encoder chunk size (0-256; 0)\n"
));
puts(_(
diff --git a/src/lzma/options.c b/src/lzma/options.c
index b2ec200e..f5ebdd8e 100644
--- a/src/lzma/options.c
+++ b/src/lzma/options.c
@@ -81,8 +81,7 @@ parse_options(const char *str, const option_map *opts,
if (value == NULL || value[0] == '\0') {
errmsg(V_ERROR, _("%s: Options must be `name=value' "
- "pairs separated with commas"),
- str);
+ "pairs separated with commas"), str);
my_exit(ERROR);
}
@@ -201,7 +200,7 @@ parse_options_subblock(const char *str)
///////////
enum {
- OPT_DISTANCE,
+ OPT_DIST,
};
@@ -210,8 +209,8 @@ set_delta(void *options, uint32_t key, uint64_t value)
{
lzma_options_delta *opt = options;
switch (key) {
- case OPT_DISTANCE:
- opt->distance = value;
+ case OPT_DIST:
+ opt->dist = value;
break;
}
}
@@ -221,15 +220,16 @@ extern lzma_options_delta *
parse_options_delta(const char *str)
{
static const option_map opts[] = {
- { "distance", NULL, LZMA_DELTA_DISTANCE_MIN,
- LZMA_DELTA_DISTANCE_MAX },
+ { "dist", NULL, LZMA_DELTA_DIST_MIN,
+ LZMA_DELTA_DIST_MAX },
{ NULL, NULL, 0, 0 }
};
lzma_options_delta *options = xmalloc(sizeof(lzma_options_subblock));
*options = (lzma_options_delta){
// It's hard to give a useful default for this.
- .distance = LZMA_DELTA_DISTANCE_MIN,
+ .type = LZMA_DELTA_TYPE_BYTE,
+ .dist = LZMA_DELTA_DIST_MIN,
};
parse_options(str, opts, &set_delta, options);
@@ -248,9 +248,9 @@ enum {
OPT_LP,
OPT_PB,
OPT_MODE,
- OPT_FB,
+ OPT_NICE,
OPT_MF,
- OPT_MC
+ OPT_DEPTH,
};
@@ -261,35 +261,35 @@ set_lzma(void *options, uint32_t key, uint64_t value)
switch (key) {
case OPT_DICT:
- opt->dictionary_size = value;
+ opt->dict_size = value;
break;
case OPT_LC:
- opt->literal_context_bits = value;
+ opt->lc = value;
break;
case OPT_LP:
- opt->literal_pos_bits = value;
+ opt->lp = value;
break;
case OPT_PB:
- opt->pos_bits = value;
+ opt->pb = value;
break;
case OPT_MODE:
opt->mode = value;
break;
- case OPT_FB:
- opt->fast_bytes = value;
+ case OPT_NICE:
+ opt->nice_len = value;
break;
case OPT_MF:
- opt->match_finder = value;
+ opt->mf = value;
break;
- case OPT_MC:
- opt->match_finder_cycles = value;
+ case OPT_DEPTH:
+ opt->depth = value;
break;
}
}
@@ -314,35 +314,49 @@ parse_options_lzma(const char *str)
};
static const option_map opts[] = {
- { "dict", NULL, LZMA_DICTIONARY_SIZE_MIN,
- LZMA_DICTIONARY_SIZE_MAX },
- { "lc", NULL, LZMA_LITERAL_CONTEXT_BITS_MIN,
- LZMA_LITERAL_CONTEXT_BITS_MAX },
- { "lp", NULL, LZMA_LITERAL_POS_BITS_MIN,
- LZMA_LITERAL_POS_BITS_MAX },
- { "pb", NULL, LZMA_POS_BITS_MIN, LZMA_POS_BITS_MAX },
- { "mode", modes, 0, 0 },
- { "fb", NULL, LZMA_FAST_BYTES_MIN, LZMA_FAST_BYTES_MAX },
- { "mf", mfs, 0, 0 },
- { "mc", NULL, 0, UINT32_MAX },
- { NULL, NULL, 0, 0 }
+ { "dict", NULL, LZMA_DICT_SIZE_MIN,
+ (UINT32_C(1) << 30) + (UINT32_C(1) << 29) },
+ { "lc", NULL, LZMA_LCLP_MIN, LZMA_LCLP_MAX },
+ { "lp", NULL, LZMA_LCLP_MIN, LZMA_LCLP_MAX },
+ { "pb", NULL, LZMA_PB_MIN, LZMA_PB_MAX },
+ { "mode", modes, 0, 0 },
+ { "nice", NULL, 2, 273 },
+ { "mf", mfs, 0, 0 },
+ { "depth", NULL, 0, UINT32_MAX },
+ { NULL, NULL, 0, 0 }
};
+ // TODO There should be a way to take some preset as the base for
+ // custom settings.
lzma_options_lzma *options = xmalloc(sizeof(lzma_options_lzma));
*options = (lzma_options_lzma){
- .dictionary_size = LZMA_DICTIONARY_SIZE_DEFAULT,
- .literal_context_bits = LZMA_LITERAL_CONTEXT_BITS_DEFAULT,
- .literal_pos_bits = LZMA_LITERAL_POS_BITS_DEFAULT,
- .pos_bits = LZMA_POS_BITS_DEFAULT,
- .preset_dictionary = NULL,
+ .dict_size = LZMA_DICT_SIZE_DEFAULT,
+ .preset_dict = NULL,
+ .preset_dict_size = 0,
+ .lc = LZMA_LC_DEFAULT,
+ .lp = LZMA_LP_DEFAULT,
+ .pb = LZMA_PB_DEFAULT,
.persistent = false,
.mode = LZMA_MODE_NORMAL,
- .fast_bytes = LZMA_FAST_BYTES_DEFAULT,
- .match_finder = LZMA_MF_BT4,
- .match_finder_cycles = 0,
+ .nice_len = 64,
+ .mf = LZMA_MF_BT4,
+ .depth = 0,
};
parse_options(str, opts, &set_lzma, options);
+ if (options->lc + options->lp > LZMA_LCLP_MAX) {
+ errmsg(V_ERROR, "The sum of lc and lp must be at "
+ "maximum of 4");
+ exit(ERROR);
+ }
+
+ const uint32_t nice_len_min = options->mf & 0x0F;
+ if (options->nice_len < nice_len_min) {
+ errmsg(V_ERROR, "The selected match finder requires at "
+ "least nice=%" PRIu32, nice_len_min);
+ exit(ERROR);
+ }
+
return options;
}