murray.calavera wrote:
Currently when invoking `lzip -h` the usage text contains all sorts of
auxiliary information about lzip and its implementation, it's so long
It's been asked before[1].
Anyway. There is my attempt to solve it in attachment. If anyone wants to use it, feel free and help yourself. I used `-hh' option, like unzip, to not make any new options.
1. https://lists.nongnu.org/archive/html/lzip-bug/2021-11/msg00006.html
diff -rup clzip-1.14/main.c clzip-1.14-h/main.c
--- clzip-1.14/main.c 2024-01-22 12:59:34.000000000 +0000
+++ clzip-1.14-h/main.c 2024-02-04 17:38:44.000000000 +0000
@@ -103,9 +103,13 @@ static int outfd = -1;
static bool delete_output_on_interrupt = false;
-static void show_help( void )
+void show_help( unsigned int help_long )
{
- printf( "Clzip is a C language version of lzip, compatible with lzip 1.4 or newer. As\n"
+ const char* messages[] =
+ {
+ "Clzip - LZMA lossless data compressor.\n"
+ "\n", /* 0 */
+ "Clzip is a C language version of lzip, compatible with lzip 1.4 or newer. As\n"
"clzip is written in C, it may be easier to integrate in applications like\n"
"package managers, embedded devices, or systems lacking a C++ compiler.\n"
"\nLzip is a lossless data compressor with a user interface similar to the one\n"
@@ -119,10 +123,10 @@ static void show_help( void )
"perspective. Lzip has been designed, written, and tested with great care to\n"
"replace gzip and bzip2 as the standard general-purpose compressed format for\n"
"Unix-like systems.\n"
- "\nUsage: %s [options] [files]\n", invocation_name );
- printf( "\nOptions:\n"
- " -h, --help display this help and exit\n"
- " -V, --version output version information and exit\n"
+ "\n", /* 1 */
+ "Usage: clzip [options] [files]\n"
+ "\n", /* 2 */
+ "Options:\n"
" -a, --trailing-error exit with error status if trailing data\n"
" -b, --member-size=<bytes> set member size limit in bytes\n"
" -c, --stdout write to standard output, keep input files\n"
@@ -131,21 +135,27 @@ static void show_help( void )
" -F, --recompress force re-compression of compressed files\n"
" -k, --keep keep (don't delete) input files\n"
" -l, --list print (un)compressed file sizes\n"
- " -m, --match-length=<bytes> set match length limit in bytes [36]\n"
+ " -m, --match-length=<bytes> set match length limit in bytes {36}\n"
" -o, --output=<file> write to <file>, keep input files\n"
" -q, --quiet suppress all messages\n"
- " -s, --dictionary-size=<bytes> set dictionary size limit in bytes [8 MiB]\n"
+ " -s, --dictionary-size=<bytes> set dictionary size limit in bytes {8 MiB}\n"
" -S, --volume-size=<bytes> set volume size limit in bytes\n"
" -t, --test test compressed file integrity\n"
" -v, --verbose be verbose (a 2nd -v gives more)\n"
- " -0 .. -9 set compression level [default 6]\n"
+ " -0 .. -9 set compression level {6}\n"
" --fast alias for -0\n"
" --best alias for -9\n"
" --empty-error exit with error status if empty member in file\n"
" --marking-error exit with error status if 1st LZMA byte not 0\n"
" --loose-trailing allow trailing data seeming corrupt header\n"
+ "\n"
+ " -h, --help display this help and exit\n"
+ " -hh, --help-long display detailed, advanced help\n"
+ " -v, --verbose be verbose (a 2nd -v gives more)\n"
+ " -V, --version output version information and exit\n"
"\nIf no file names are given, or if a file is '-', clzip compresses or\n"
"decompresses from standard input to standard output.\n"
+ "\n", /* 3 */
"Numbers may be followed by a multiplier: k = kB = 10^3 = 1000,\n"
"Ki = KiB = 2^10 = 1024, M = 10^6, Mi = 2^20, G = 10^9, Gi = 2^30, etc...\n"
"Dictionary sizes 12 to 29 are interpreted as powers of two, meaning 2^12 to\n"
@@ -154,6 +164,17 @@ static void show_help( void )
"optimal for all files. If your files are large, very repetitive, etc, you\n"
"may need to use the options --dictionary-size and --match-length directly\n"
"to achieve optimal performance.\n"
+ "\n Level Dictionary size (-s) Match length limit (-m)\n"
+ " -0 64 KiB 16 bytes\n"
+ " -1 1 MiB 5 bytes\n"
+ " -2 1.5 MiB 6 bytes\n"
+ " -3 2 MiB 8 bytes\n"
+ " -4 3 MiB 12 bytes\n"
+ " -5 4 MiB 20 bytes\n"
+ " -6 8 MiB 36 bytes\n"
+ " -7 16 MiB 68 bytes\n"
+ " -8 24 MiB 132 bytes\n"
+ " -9 32 MiB 273 bytes\n"
"\nTo extract all the files from archive 'foo.tar.lz', use the commands\n"
"'tar -xf foo.tar.lz' or 'clzip -cd foo.tar.lz | tar -xf -'.\n"
"\nExit status: 0 for a normal exit, 1 for environmental problems\n"
@@ -165,11 +186,22 @@ static void show_help( void )
"definition of Markov chains), G.N.N. Martin (for the definition of range\n"
"encoding), Igor Pavlov (for putting all the above together in LZMA), and\n"
"Julian Seward (for bzip2's CLI).\n"
- "\nReport bugs to [email protected]\n"
- "Clzip home page: http://www.nongnu.org/lzip/clzip.html\n" );
+ "\n", /* 4 */
+ "Report bugs to [email protected]\n"
+ "Clzip home page: http://www.nongnu.org/lzip/clzip.html\n"
+ "\n", /* 5 */
+ };
+ int i = 0;
+ const char* msgs2[2][7] = { { messages[0], messages[2], messages[3], messages[5], NULL , NULL, NULL },
+ { messages[0], messages[1], messages[2], messages[3], messages[4], messages[5], NULL } };
+ help_long = (help_long > 0);
+ while (msgs2[help_long][i])
+ {
+ printf("%s", msgs2[help_long][i]);
+ i++;
+ }
}
-
static void show_version( void )
{
printf( "%s %s\n", program_name, PROGVERSION );
@@ -988,6 +1020,7 @@ int main( const int argc, const char * c
int i;
struct Cl_options cl_opts; /* command-line options */
Cl_options_init( &cl_opts );
+ unsigned int help = 0;
bool force = false;
bool keep_input_files = false;
bool recompress = false;
@@ -995,7 +1028,7 @@ int main( const int argc, const char * c
bool zero = false;
if( argc > 0 ) invocation_name = argv[0];
- enum { opt_eer = 256, opt_lt, opt_mer };
+ enum { opt_eer = 256, opt_lt, opt_mer, opt_hlp2 };
const struct ap_Option options[] =
{
{ '0', "fast", ap_no },
@@ -1029,6 +1062,7 @@ int main( const int argc, const char * c
{ opt_eer, "empty-error", ap_no },
{ opt_lt, "loose-trailing", ap_no },
{ opt_mer, "marking-error", ap_no },
+ { opt_hlp2, "help-long", ap_no },
{ 0, 0, ap_no } };
CRC32_init();
@@ -1059,7 +1093,7 @@ int main( const int argc, const char * c
case 'd': set_mode( &program_mode, m_decompress ); break;
case 'f': force = true; break;
case 'F': recompress = true; break;
- case 'h': show_help(); return 0;
+ case 'h': help++; break;
case 'k': keep_input_files = true; break;
case 'l': set_mode( &program_mode, m_list ); break;
case 'm': encoder_options.match_len_limit =
@@ -1078,10 +1112,17 @@ int main( const int argc, const char * c
case opt_eer: cl_opts.ignore_empty = false; break;
case opt_lt: cl_opts.loose_trailing = true; break;
case opt_mer: cl_opts.ignore_marking = false; break;
+ case opt_hlp2: help += 2; break;
default: internal_error( "uncaught option." );
}
} /* end process options */
+ if( help )
+ {
+ show_help( help - 1 );
+ return 0;
+ }
+
#if defined __MSVCRT__ || defined __OS2__ || defined __DJGPP__
setmode( STDIN_FILENO, O_BINARY );
setmode( STDOUT_FILENO, O_BINARY );
