summaryrefslogtreecommitdiffstats
path: root/zgrep.cc
diff options
context:
space:
mode:
Diffstat (limited to 'zgrep.cc')
-rw-r--r--zgrep.cc40
1 files changed, 19 insertions, 21 deletions
diff --git a/zgrep.cc b/zgrep.cc
index ef8db6b..3df7b58 100644
--- a/zgrep.cc
+++ b/zgrep.cc
@@ -93,7 +93,7 @@ void show_help()
" -n, --line-number print the line number of each line\n"
" -N, --no-rcfile don't read runtime configuration file\n"
" -o, --only-matching show only the part of a line matching <pattern>\n"
- " -O, --force-format=<fmt> force the format given (bz2, gz, lz, xz, zst)\n"
+ " -O, --force-format=<fmt> force the input format\n"
" -P, --perl-regexp <pattern> is a Perl regular expression\n"
" -q, --quiet, --silent suppress all messages\n"
" -r, --recursive operate recursively on directories\n"
@@ -111,6 +111,8 @@ void show_help()
" --lz=<command> set compressor and options for lzip format\n"
" --xz=<command> set compressor and options for xz format\n"
" --zst=<command> set compressor and options for zstd format\n"
+ "\nValid formats for options '-M' and '-O' are 'bz2', 'gz', 'lz', 'xz', 'zst',\n"
+ "and 'un' for uncompressed.\n"
"\nNumbers 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" );
show_help_addr();
@@ -210,7 +212,7 @@ int main( const int argc, const char * const argv[] )
{
enum { help_opt = 256, verbose_opt, color_opt, label_opt, linebuf_opt,
bz2_opt, gz_opt, lz_opt, xz_opt, zst_opt };
- int format_index = -1;
+ int format_index = -1; // undefined
int list_mode = 0; // 1 = list matches, -1 = list non-matches
int recursive = 0; // 1 = '-r', 2 = '-R'
int show_name = -1; // tri-state bool
@@ -222,7 +224,7 @@ int main( const int argc, const char * const argv[] )
std::vector< const char * > grep_args; // args to grep, maybe empty
std::string color_option; // additional args to grep
std::string label_option;
- std::string label = "(standard input)"; // prefix for standard input
+ const char * label = "(standard input)"; // prefix for standard input
program_name = "zgrep";
invocation_name = ( argc > 0 ) ? argv[0] : program_name;
@@ -294,19 +296,16 @@ int main( const int argc, const char * const argv[] )
switch( code )
{
case 'a': grep_args.push_back( "-a" ); break;
- case 'A': grep_args.push_back( "-A" );
- grep_args.push_back( arg ); break;
+ case 'A': grep_args.push_back( "-A" ); grep_args.push_back( arg ); break;
case 'b': grep_args.push_back( "-b" ); break;
- case 'B': grep_args.push_back( "-B" );
- grep_args.push_back( arg ); break;
+ case 'B': grep_args.push_back( "-B" ); grep_args.push_back( arg ); break;
case 'c': grep_args.push_back( "-c" ); break;
- case 'C': grep_args.push_back( "-C" );
- grep_args.push_back( arg ); break;
- case 'e': grep_args.push_back( "-e" );
- grep_args.push_back( arg ); pattern_found = true; break;
+ case 'C': grep_args.push_back( "-C" ); grep_args.push_back( arg ); break;
+ case 'e': grep_args.push_back( "-e" ); grep_args.push_back( arg );
+ pattern_found = true; break;
case 'E': grep_args.push_back( "-E" ); break;
- case 'f': grep_args.push_back( "-f" );
- grep_args.push_back( arg ); pattern_found = true; break;
+ case 'f': grep_args.push_back( "-f" ); grep_args.push_back( arg );
+ pattern_found = true; break;
case 'F': grep_args.push_back( "-F" ); break;
case 'G': grep_args.push_back( "-G" ); break;
case 'h': show_name = false; break;
@@ -315,8 +314,7 @@ int main( const int argc, const char * const argv[] )
case 'I': grep_args.push_back( "-I" ); break;
case 'l': grep_args.push_back( "-l" ); list_mode = 1; break;
case 'L': grep_args.push_back( "-L" ); list_mode = -1; break;
- case 'm': grep_args.push_back( "-m" );
- grep_args.push_back( arg ); break;
+ case 'm': grep_args.push_back( "-m" ); grep_args.push_back( arg ); break;
case 'M': parse_format_list( sarg, pn ); break;
case 'n': grep_args.push_back( "-n" ); break;
case 'N': break;
@@ -340,14 +338,14 @@ int main( const int argc, const char * const argv[] )
case color_opt: color_option = "--color";
if( !sarg.empty() ) { color_option += '='; color_option += sarg; }
break;
- case label_opt: label_option = label = sarg; break;
+ case label_opt: label_option = sarg; label = arg; break;
case linebuf_opt: grep_args.push_back( "--line-buffered" );
line_buffered = true; break;
- case bz2_opt: parse_compressor( sarg, fmt_bz2 ); break;
- case gz_opt: parse_compressor( sarg, fmt_gz ); break;
- case lz_opt: parse_compressor( sarg, fmt_lz ); break;
- case xz_opt: parse_compressor( sarg, fmt_xz ); break;
- case zst_opt: parse_compressor( sarg, fmt_zst ); break;
+ case bz2_opt: parse_compressor( sarg, pn, fmt_bz2 ); break;
+ case gz_opt: parse_compressor( sarg, pn, fmt_gz ); break;
+ case lz_opt: parse_compressor( sarg, pn, fmt_lz ); break;
+ case xz_opt: parse_compressor( sarg, pn, fmt_xz ); break;
+ case zst_opt: parse_compressor( sarg, pn, fmt_zst ); break;
default : internal_error( "uncaught option." );
}
} // end process options