]> git.ipfire.org Git - thirdparty/xz.git/commitdiff
xz: Add a new --filters-help option.
authorJia Tan <jiat0218@gmail.com>
Fri, 12 May 2023 16:44:41 +0000 (00:44 +0800)
committerJia Tan <jiat0218@gmail.com>
Mon, 17 Jul 2023 15:34:55 +0000 (23:34 +0800)
The --filters-help can be used to help create filter chains with the
--filters and --filtersX options. The message in --long-help is too
short to fully explain the syntax to construct complex filter chains.

In --robot mode, xz will only print the output from liblzma function
lzma_str_list_filters.

src/xz/args.c
src/xz/message.c
src/xz/message.h

index 6ae3c96ffbfb932bf351a40000186afe7af534e2..7af3e85003eb44ad6440dd00cfbb9afb14d7e123 100644 (file)
@@ -180,6 +180,7 @@ parse_real(args_info *args, int argc, char **argv)
                OPT_FILTERS7,
                OPT_FILTERS8,
                OPT_FILTERS9,
+               OPT_FILTERS_HELP,
 
                OPT_X86,
                OPT_POWERPC,
@@ -261,6 +262,7 @@ parse_real(args_info *args, int argc, char **argv)
                { "filters7",     optional_argument, NULL,  OPT_FILTERS7},
                { "filters8",     optional_argument, NULL,  OPT_FILTERS8},
                { "filters9",     optional_argument, NULL,  OPT_FILTERS9},
+               { "filters-help", optional_argument, NULL,  OPT_FILTERS_HELP},
 
                { "lzma1",        optional_argument, NULL,  OPT_LZMA1 },
                { "lzma2",        optional_argument, NULL,  OPT_LZMA2 },
@@ -447,6 +449,12 @@ parse_real(args_info *args, int argc, char **argv)
                                        (size_t)(c - OPT_FILTERS));
                        break;
 
+               // --filters-help
+               case OPT_FILTERS_HELP:
+                       // This doesn't return.
+                       message_filters_help();
+                       break;
+
                case OPT_X86:
                        coder_add_filter(LZMA_FILTER_X86,
                                        options_bcj(optarg));
index b28bb63c6f415a539a2318a63b9da52458c965dd..a888d29eea234866c03cf11c315562eba8552638 100644 (file)
@@ -1071,6 +1071,11 @@ message_help(bool long_help)
 "                      string syntax to use with --block-list"
                ));
 
+               puts(_(
+"  --filters-help      display more information about the liblzma filter string\n"
+"                      syntax and exit."
+               ));
+
 #if defined(HAVE_ENCODER_LZMA1) || defined(HAVE_DECODER_LZMA1) \
                || defined(HAVE_ENCODER_LZMA2) || defined(HAVE_DECODER_LZMA2)
                // TRANSLATORS: The word "literal" in "literal context bits"
@@ -1158,3 +1163,28 @@ message_help(bool long_help)
 
        tuklib_exit(E_SUCCESS, E_ERROR, verbosity != V_SILENT);
 }
+
+
+extern void
+message_filters_help(void)
+{
+       char *encoder_options;
+       if (lzma_str_list_filters(&encoder_options, LZMA_VLI_UNKNOWN,
+                       LZMA_STR_ENCODER, NULL) != LZMA_OK)
+               message_bug();
+
+       if (!opt_robot) {
+               puts(_(
+"Filter chains are set using the --filters=FILTERS or\n"
+"--filters1=FILTERS ... --filters9=FILTERS options. Each filter in the chain\n"
+"can be separated by spaces or `--'. Alternatively a preset <0-9>[e] can be\n"
+"specified instead of a filter chain.\n"
+               ));
+
+               puts(_("The supported filters and their options are:"));
+       }
+
+       puts(encoder_options);
+
+       tuklib_exit(E_SUCCESS, E_ERROR, verbosity != V_SILENT);
+}
index b264f82153a36c505c3615cca5fef0be6b68bb75..21771eb43b559dd2ff4e5d088b0c69942e5b1efe 100644 (file)
@@ -107,6 +107,11 @@ extern void message_version(void) lzma_attribute((__noreturn__));
 extern void message_help(bool long_help) lzma_attribute((__noreturn__));
 
 
+/// Prints a help message specifically for using the --filters and
+/// --filtersX command line options.
+extern void message_filters_help(void);
+
+
 /// \brief      Set the total number of files to be processed
 ///
 /// Standard input is counted as a file here. This is used when printing