Merging upstream version 1.11.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
ddac2f7869
commit
bd6a3e4e88
31 changed files with 734 additions and 377 deletions
43
zgrep.cc
43
zgrep.cc
|
@ -1,5 +1,5 @@
|
|||
/* Zgrep - search compressed files for a regular expression
|
||||
Copyright (C) 2010-2021 Antonio Diaz Diaz.
|
||||
Copyright (C) 2010-2022 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
|
||||
|
@ -31,7 +31,7 @@
|
|||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#if defined(__MSVCRT__) || defined(__OS2__)
|
||||
#if defined __MSVCRT__ || defined __OS2__
|
||||
#include <io.h>
|
||||
#endif
|
||||
|
||||
|
@ -60,7 +60,8 @@ void show_help()
|
|||
"compressed format.\n"
|
||||
"\nIf no files are specified, recursive searches examine the current\n"
|
||||
"working directory, and nonrecursive searches read standard input.\n"
|
||||
"\nThe formats supported are bzip2, gzip, lzip, and xz.\n"
|
||||
"\n'zgrep --verbose -V' prints the version of the grep program used.\n"
|
||||
"\nThe formats supported are bzip2, gzip, lzip, xz, and zstd.\n"
|
||||
"\nUsage: zgrep [options] <pattern> [files]\n"
|
||||
"\nExit status is 0 if match, 1 if no match, 2 if trouble.\n"
|
||||
"Some options only work if the grep program used supports them.\n"
|
||||
|
@ -78,8 +79,8 @@ void show_help()
|
|||
" -E, --extended-regexp <pattern> is an extended regular expression\n"
|
||||
" -f, --file=<file> obtain patterns from <file>\n"
|
||||
" -F, --fixed-strings <pattern> is a set of newline-separated strings\n"
|
||||
" -h, --no-filename suppress the prefixing filename on output\n"
|
||||
" -H, --with-filename print the filename for each match\n"
|
||||
" -h, --no-filename suppress the prefixing file name on output\n"
|
||||
" -H, --with-filename print the file name for each match\n"
|
||||
" -i, --ignore-case ignore case distinctions\n"
|
||||
" -I ignore binary files\n"
|
||||
" -l, --files-with-matches only print names of files containing matches\n"
|
||||
|
@ -89,7 +90,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)\n"
|
||||
" -O, --force-format=<fmt> force the format given (bz2, gz, lz, xz, zst)\n"
|
||||
" -q, --quiet suppress all messages\n"
|
||||
" -r, --recursive operate recursively on directories\n"
|
||||
" -R, --dereference-recursive recursively follow symbolic links\n"
|
||||
|
@ -102,6 +103,7 @@ void show_help()
|
|||
" --gz=<command> set compressor and options for gzip format\n"
|
||||
" --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"
|
||||
"\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();
|
||||
|
@ -217,7 +219,7 @@ int zgrep_file( int infd, const int format_index,
|
|||
int main( const int argc, const char * const argv[] )
|
||||
{
|
||||
enum { help_opt = 256, verbose_opt, color_opt,
|
||||
bz2_opt, gz_opt, lz_opt, xz_opt };
|
||||
bz2_opt, gz_opt, lz_opt, xz_opt, zst_opt };
|
||||
int format_index = -1;
|
||||
int list_mode = 0; // 1 = list matches, -1 = list non-matches
|
||||
int recursive = 0; // 1 = '-r', 2 = '-R'
|
||||
|
@ -264,11 +266,12 @@ int main( const int argc, const char * const argv[] )
|
|||
{ 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 },
|
||||
{ xz_opt, "xz", Arg_parser::yes },
|
||||
{ 0 , 0, Arg_parser::no } };
|
||||
{ bz2_opt, "bz2", Arg_parser::yes },
|
||||
{ gz_opt, "gz", Arg_parser::yes },
|
||||
{ lz_opt, "lz", Arg_parser::yes },
|
||||
{ xz_opt, "xz", Arg_parser::yes },
|
||||
{ zst_opt, "zst", Arg_parser::yes },
|
||||
{ 0, 0, Arg_parser::no } };
|
||||
|
||||
const Arg_parser parser( argc, argv, options );
|
||||
if( parser.error().size() ) // bad option
|
||||
|
@ -282,6 +285,7 @@ int main( const int argc, const char * const argv[] )
|
|||
{
|
||||
const int code = parser.code( argind );
|
||||
if( !code ) break; // no more options
|
||||
const char * const pn = parser.parsed_name( argind ).c_str();
|
||||
const std::string & arg = parser.argument( argind );
|
||||
switch( code )
|
||||
{
|
||||
|
@ -308,22 +312,22 @@ int main( const int argc, const char * const argv[] )
|
|||
case 'L': grep_args.push_back( "-L" ); list_mode = -1; break;
|
||||
case 'm': grep_args.push_back( "-m" );
|
||||
grep_args.push_back( arg.c_str() ); break;
|
||||
case 'M': parse_format_list( arg ); break;
|
||||
case 'M': parse_format_list( arg, pn ); break;
|
||||
case 'n': grep_args.push_back( "-n" ); break;
|
||||
case 'N': break;
|
||||
case 'o': grep_args.push_back( "-o" ); break;
|
||||
case 'O': format_index = parse_format_type( arg ); break;
|
||||
case 'O': format_index = parse_format_type( arg, pn ); break;
|
||||
case 'q': grep_args.push_back( "-q" ); verbosity = -1; break;
|
||||
case 'r': recursive = 1; break;
|
||||
case 'R': recursive = 2; break;
|
||||
case 's': grep_args.push_back( "-s" ); no_messages = true; break;
|
||||
case 'v': grep_args.push_back( "-v" ); break;
|
||||
case 'V': show_version(); return 0;
|
||||
case 'V': show_version( GREP " --version" ); return 0;
|
||||
case 'w': grep_args.push_back( "-w" ); break;
|
||||
case 'x': grep_args.push_back( "-x" ); break;
|
||||
case help_opt : show_help(); return 0;
|
||||
case verbose_opt: if( verbosity < 4 ) ++verbosity;
|
||||
no_messages = false; break;
|
||||
case help_opt: show_help(); return 0;
|
||||
case verbose_opt: no_messages = false; if( verbosity < 4 ) ++verbosity;
|
||||
break;
|
||||
case color_opt: color_option = "--color";
|
||||
if( !arg.empty() ) { color_option += '='; color_option += arg; }
|
||||
break;
|
||||
|
@ -331,6 +335,7 @@ int main( const int argc, const char * const argv[] )
|
|||
case gz_opt: parse_compressor( arg, fmt_gz ); break;
|
||||
case lz_opt: parse_compressor( arg, fmt_lz ); break;
|
||||
case xz_opt: parse_compressor( arg, fmt_xz ); break;
|
||||
case zst_opt: parse_compressor( arg, fmt_zst ); break;
|
||||
default : internal_error( "uncaught option." );
|
||||
}
|
||||
} // end process options
|
||||
|
@ -338,7 +343,7 @@ int main( const int argc, const char * const argv[] )
|
|||
if( !color_option.empty() ) // push the last value set
|
||||
grep_args.push_back( color_option.c_str() );
|
||||
|
||||
#if defined(__MSVCRT__) || defined(__OS2__)
|
||||
#if defined __MSVCRT__ || defined __OS2__
|
||||
setmode( STDIN_FILENO, O_BINARY );
|
||||
setmode( STDOUT_FILENO, O_BINARY );
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue