summaryrefslogtreecommitdiffstats
path: root/zgrep.cc
diff options
context:
space:
mode:
Diffstat (limited to 'zgrep.cc')
-rw-r--r--zgrep.cc14
1 files changed, 12 insertions, 2 deletions
diff --git a/zgrep.cc b/zgrep.cc
index 5bcb968..204d5d5 100644
--- a/zgrep.cc
+++ b/zgrep.cc
@@ -1,5 +1,5 @@
/* Zgrep - search compressed files for a regular expression
- Copyright (C) 2010-2017 Antonio Diaz Diaz.
+ Copyright (C) 2010-2018 Antonio Diaz Diaz.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -69,6 +69,7 @@ void show_help()
" -B, --before-context=<n> print <n> lines of leading context\n"
" -c, --count only print a count of matching lines per file\n"
" -C, --context=<n> print <n> lines of output context\n"
+ " --color[=<when>] show matched strings in color\n"
" -e, --regexp=<pattern> use <pattern> as the pattern to match\n"
" -E, --extended-regexp <pattern> is an extended regular expression\n"
" -f, --file=<file> obtain patterns from <file>\n"
@@ -209,7 +210,8 @@ int zgrep_file( int infd, const int format_index,
int main( const int argc, const char * const argv[] )
{
- enum { help_opt = 256, verbose_opt, bz2_opt, gz_opt, lz_opt, xz_opt };
+ enum { help_opt = 256, verbose_opt, color_opt,
+ bz2_opt, gz_opt, lz_opt, xz_opt };
int format_index = -1;
int infd = -1;
int list_mode = 0; // 1 = list matches, -1 = list non matches
@@ -219,6 +221,7 @@ int main( const int argc, const char * const argv[] )
std::string input_filename;
std::list< std::string > filenames;
std::vector< const char * > grep_args; // args to grep, maybe empty
+ std::string color_option; // needed because of optional arg
invocation_name = argv[0];
program_name = "zgrep";
@@ -255,6 +258,7 @@ int main( const int argc, const char * const argv[] )
{ 'x', "line-regexp", Arg_parser::no }, // grep
{ help_opt, "help", Arg_parser::no },
{ verbose_opt, "verbose", Arg_parser::no },
+ { color_opt, "color", Arg_parser::maybe },
{ bz2_opt, "bz2", Arg_parser::yes },
{ gz_opt, "gz", Arg_parser::yes },
{ lz_opt, "lz", Arg_parser::yes },
@@ -314,6 +318,9 @@ int main( const int argc, const char * const argv[] )
case help_opt : show_help(); return 0;
case verbose_opt: if( verbosity < 4 ) ++verbosity;
no_messages = false; break;
+ case color_opt: color_option = "--color";
+ if( !arg.empty() ) { color_option += '='; color_option += arg; }
+ break;
case bz2_opt: parse_compressor( arg, fmt_bz2 ); break;
case gz_opt: parse_compressor( arg, fmt_gz ); break;
case lz_opt: parse_compressor( arg, fmt_lz ); break;
@@ -322,6 +329,9 @@ int main( const int argc, const char * const argv[] )
}
} // end process options
+ if( !color_option.empty() ) // push the last value set
+ grep_args.push_back( color_option.c_str() );
+
#if defined(__MSVCRT__) || defined(__OS2__)
setmode( STDIN_FILENO, O_BINARY );
setmode( STDOUT_FILENO, O_BINARY );