From 5eff2e98bd094757d69bc247acf07faa4a0b1b26 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 24 Feb 2018 14:29:16 +0100 Subject: Merging upstream version 1.7. Signed-off-by: Daniel Baumann --- zgrep.cc | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'zgrep.cc') 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= print lines of leading context\n" " -c, --count only print a count of matching lines per file\n" " -C, --context= print lines of output context\n" + " --color[=] show matched strings in color\n" " -e, --regexp= use as the pattern to match\n" " -E, --extended-regexp is an extended regular expression\n" " -f, --file= obtain patterns from \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 ); -- cgit v1.2.3