@@ -32,8 +32,8 @@ limitations under the License.
3232using namespace kanzi ;
3333using namespace std ;
3434
35- static const string CMD_LINE_ARGS[14 ] = {
36- " -c" , " -d" , " -i" , " -o" , " -b" , " -t" , " -e" , " -j" , " -v" , " -l" , " -s" , " -x" , " -f" , " -h"
35+ static const string CMD_LINE_ARGS[15 ] = {
36+ " -c" , " -d" , " -i" , " -o" , " -b" , " -t" , " -e" , " -j" , " -v" , " -l" , " -s" , " -x" , " -f" , " -h" , " -y "
3737};
3838
3939// static const int ARG_IDX_COMPRESS = 0;
@@ -53,7 +53,7 @@ static const int ARG_IDX_LEVEL = 9;
5353static const string KANZI_VERSION = " 2.4.0" ;
5454static const string APP_HEADER = " Kanzi " + KANZI_VERSION + " (c) Frederic Langlet" ;
5555static const string APP_SUB_HEADER = " Fast lossless data compressor." ;
56- static const string APP_USAGE = " Usage: kanzi [-c|-d] [flags and files in any order]" ;
56+ static const string APP_USAGE = " Usage: kanzi [-c|-d|-y ] [flags and files in any order]" ;
5757
5858
5959#ifdef CONCURRENCY_ENABLED
@@ -77,14 +77,16 @@ void printHelp(Printer& log, const string& mode, bool showHeader)
7777 log.println (" Options\n " , true );
7878 log.println (" -h, --help" , true );
7979
80- if ((mode. compare ( 0 , 1 , " c" ) != 0 ) && (mode. compare ( 0 , 1 , " d" ) != 0 )) {
80+ if ((mode != " c" ) && (mode != " d" ) && (mode != " y " )) {
8181 log.println (" Display this message." , true );
8282 log.println (" Use in conjunction with -c to print information for compression," , true );
8383 log.println (" or -d to print information for decompression.\n " , true );
8484 log.println (" -c, --compress" , true );
8585 log.println (" Compress mode\n " , true );
8686 log.println (" -d, --decompress" , true );
8787 log.println (" Decompress mode\n " , true );
88+ log.println (" -y, --info" , true );
89+ log.println (" Info mode: display information about compressed files\n " , true );
8890 }
8991 else {
9092 log.println (" Display this message.\n " , true );
@@ -101,23 +103,26 @@ void printHelp(Printer& log, const string& mode, bool showHeader)
101103 log.println (ss.str (), true );
102104 log.println (" If this option is not provided, kanzi reads data from stdin.\n " , true );
103105 ss.str (string ());
104- log.println (" -o, --output=<outputName>" , true );
105106
106- if (mode.compare (0 , 1 , " c" ) == 0 ) {
107- log.println (" Optional name of the output file or directory (defaults to" , true );
108- log.println (" <inputName.knz> if input is <inputName> or 'stdout' if input is 'stdin')." , true );
109- log.println (" or 'none' or 'stdout'.\n " , true );
110- }
111- else if (mode.compare (0 , 1 , " d" ) == 0 ) {
112- log.println (" Optional name of the output file or directory (defaults to" , true );
113- log.println (" <inputName> if input is <inputName.knz> or 'stdout' if input is 'stdin')." , true );
114- log.println (" or 'none' or 'stdout'.\n " , true );
115- }
116- else {
117- log.println (" Optional name of the output file or 'none' or 'stdout'.\n " , true );
107+ if (mode != " y" ) {
108+ log.println (" -o, --output=<outputName>" , true );
109+
110+ if (mode == " c" ) {
111+ log.println (" Optional name of the output file or directory (defaults to" , true );
112+ log.println (" <inputName.knz> if input is <inputName> or 'stdout' if input is 'stdin')." , true );
113+ log.println (" or 'none' or 'stdout'.\n " , true );
114+ }
115+ else if (mode == " d" ) {
116+ log.println (" Optional name of the output file or directory (defaults to" , true );
117+ log.println (" <inputName> if input is <inputName.knz> or 'stdout' if input is 'stdin')." , true );
118+ log.println (" or 'none' or 'stdout'.\n " , true );
119+ }
120+ else {
121+ log.println (" Optional name of the output file or 'none' or 'stdout'.\n " , true );
122+ }
118123 }
119124
120- if (mode. compare ( 0 , 1 , " c" ) == 0 ) {
125+ if (mode == " c" ) {
121126 log.println (" -b, --block=<size>" , true );
122127 log.println (" Size of blocks (default 4|8|16|32 MiB based on level, max 1 GiB, min 1 KiB)." , true );
123128 log.println (" 'auto' means that the compressor derives the best value" , true );
@@ -162,24 +167,29 @@ void printHelp(Printer& log, const string& mode, bool showHeader)
162167 log.println (" 4=display block size and timings, 5=display extra information" , true );
163168 log.println (" Verbosity is reduced to 1 when files are processed concurrently" , true );
164169 log.println (" Verbosity is reduced to 0 when the output is 'stdout'\n " , true );
165- log.println (" -f, --force" , true );
166- log.println (" Overwrite the output file if it already exists\n " , true );
167- log.println (" --rm" , true );
168170
169- if (mode.compare (0 , 1 , " c" ) == 0 ) {
171+ if (mode != " y" ) {
172+ log.println (" -f, --force" , true );
173+ log.println (" Overwrite the output file if it already exists\n " , true );
174+ }
175+
176+ if (mode == " c" ) {
177+ log.println (" --rm" , true );
170178 log.println (" Remove the input file after successful compression." , true );
179+ log.println (" If the input is a folder, all processed files under the folder are removed.\n " , true );
171180 }
172- else {
181+ else if (mode == " d" ) {
182+ log.println (" --rm" , true );
173183 log.println (" Remove the input file after successful decompression." , true );
184+ log.println (" If the input is a folder, all processed files under the folder are removed.\n " , true );
174185 }
175186
176- log.println (" If the input is a folder, all processed files under the folder are removed.\n " , true );
177187 log.println (" --no-link" , true );
178188 log.println (" Skip links\n " , true );
179189 log.println (" --no-dot-file" , true );
180190 log.println (" Skip dot files\n " , true );
181191
182- if (mode. compare ( 0 , 1 , " d" ) == 0 ) {
192+ if (mode == " d" ) {
183193 log.println (" --from=blockId" , true );
184194 log.println (" Decompress starting at the provided block (included)." , true );
185195 log.println (" The first block ID is 1.\n " , true );
@@ -191,7 +201,7 @@ void printHelp(Printer& log, const string& mode, bool showHeader)
191201 log.println (" kanzi --decompress --input=foo.knz --force --verbose=2 --jobs=2\n " , true );
192202 }
193203
194- if (mode. compare ( 0 , 1 , " c" ) == 0 ) {
204+ if (mode == " c" ) {
195205 log.println (" " , true );
196206 log.println (" Transforms\n " , true );
197207 log.println (" BWT: Burrows Wheeler Transform is a transform that reorders symbols" , true );
@@ -399,8 +409,8 @@ int processCommandLine(int argc, const char* argv[], Context& map, Printer& log)
399409
400410 // Extract verbosity, output and mode first
401411 if ((arg == " -c" ) || (arg.compare (0 , 10 , " --compress" ) == 0 )) {
402- if (mode == " d " ) {
403- cerr << " Both compression and decompression options were provided. " << endl;
412+ if (mode != " " ) {
413+ cerr << " Only one mode can be provided (already got ' " << mode << " ' " << endl;
404414 return Error::ERR_INVALID_PARAM;
405415 }
406416
@@ -409,15 +419,25 @@ int processCommandLine(int argc, const char* argv[], Context& map, Printer& log)
409419 }
410420
411421 if ((arg == " -d" ) || (arg.compare (0 , 12 , " --decompress" ) == 0 )) {
412- if (mode == " c " ) {
413- cerr << " Both compression and decompression options were provided. " << endl;
422+ if (mode != " " ) {
423+ cerr << " Only one mode can be provided (already got ' " << mode << " ' " << endl;
414424 return Error::ERR_INVALID_PARAM;
415425 }
416426
417427 mode = " d" ;
418428 continue ;
419429 }
420430
431+ if ((arg == " -y" ) || (arg.compare (0 , 10 , " --info" ) == 0 )) {
432+ if (mode != " " ) {
433+ cerr << " Only one mode can be provided (already got '" << mode << " ')" << endl;
434+ return Error::ERR_INVALID_PARAM;
435+ }
436+
437+ mode = " y" ;
438+ continue ;
439+ }
440+
421441 if ((ctx == ARG_IDX_VERBOSE) || (arg.compare (0 , 10 , " --verbose=" ) == 0 )) {
422442 if (verboseFlag == true ) {
423443 WARNING_OPT_DUPLICATE (" verbosity level" , arg);
@@ -467,12 +487,17 @@ int processCommandLine(int argc, const char* argv[], Context& map, Printer& log)
467487 }
468488 }
469489 else {
470- string str = outputName;
471- transform (str.begin (), str.end (), str.begin (), ::toupper);
490+ if (mode == " y" ) {
491+ log.println (" Warning: ignoring option [" + outputName + " ]. Only applicable in compression or decompression mode." , verbose > 0 );
492+ }
493+ else {
494+ string str = outputName;
495+ transform (str.begin (), str.end (), str.begin (), ::toupper);
472496
473- if (str == " STDOUT" ) {
474- verbose = 0 ;
475- verboseFlag = true ;
497+ if (str == " STDOUT" ) {
498+ verbose = 0 ;
499+ verboseFlag = true ;
500+ }
476501 }
477502 }
478503
@@ -494,7 +519,8 @@ int processCommandLine(int argc, const char* argv[], Context& map, Printer& log)
494519 arg = arg.substr (k);
495520 }
496521
497- if ((arg == " -c" ) || (arg == " -d" ) || (arg == " --compress" ) || (arg == " --decompress" )) {
522+ if ((arg == " -c" ) || (arg == " -d" ) || (arg == " -y" ) || (arg == " --compress" ) || (arg == " --decompress" ) ||
523+ (arg == " --info" )) {
498524 if (ctx != -1 ) {
499525 WARNING_OPT_NOVALUE (CMD_LINE_ARGS[ctx]);
500526 }
@@ -511,6 +537,11 @@ int processCommandLine(int argc, const char* argv[], Context& map, Printer& log)
511537 WARNING_OPT_DUPLICATE (arg, " true" );
512538 }
513539
540+ if (mode == " y" ) {
541+ WARNING_OPT_COMP_ONLY (arg);
542+ continue ;
543+ }
544+
514545 overwrite = 1 ;
515546 ctx = -1 ;
516547 continue ;
@@ -559,6 +590,10 @@ int processCommandLine(int argc, const char* argv[], Context& map, Printer& log)
559590 WARNING_OPT_DUPLICATE (arg, " true" );
560591 }
561592
593+ if (mode == " y" ) {
594+ WARNING_OPT_COMP_ONLY (arg);
595+ continue ;
596+ }
562597 remove = 1 ;
563598 ctx = -1 ;
564599 continue ;
@@ -630,6 +665,11 @@ int processCommandLine(int argc, const char* argv[], Context& map, Printer& log)
630665 WARNING_OPT_DUPLICATE (msg, arg);
631666 }
632667 else {
668+ if (mode == " y" ) {
669+ WARNING_OPT_COMP_ONLY (arg);
670+ continue ;
671+ }
672+
633673 if ((arg.length () >= 2 ) && (arg[0 ] == ' .' ) && (arg[1 ] == PATH_SEPARATOR)) {
634674 arg = (arg.length () == 2 ) ? arg.substr (0 , 1 ) : arg.substr (2 );
635675 }
@@ -1072,7 +1112,7 @@ int main(int argc, const char* argv[])
10721112 }
10731113 }
10741114
1075- if (mode == " d" ) {
1115+ if (( mode == " d" ) || (mode == " y " ) ) {
10761116 try {
10771117 BlockDecompressor bd (ctx);
10781118 uint64 read = 0 ;
0 commit comments