summaryrefslogtreecommitdiffstats
path: root/zgrep.cc
diff options
context:
space:
mode:
authorDaniel Baumann <mail@daniel-baumann.ch>2016-05-20 06:48:08 +0000
committerDaniel Baumann <mail@daniel-baumann.ch>2016-05-20 06:48:08 +0000
commit54ee6afc95073460b77bfa6b84550f94bb1a39b5 (patch)
treedca863df8c71f8323c1df714b02814eaaf858ba5 /zgrep.cc
parentAdding upstream version 1.4. (diff)
downloadzutils-54ee6afc95073460b77bfa6b84550f94bb1a39b5.tar.xz
zutils-54ee6afc95073460b77bfa6b84550f94bb1a39b5.zip
Adding upstream version 1.5.upstream/1.5
Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch>
Diffstat (limited to '')
-rw-r--r--zgrep.cc20
1 files changed, 13 insertions, 7 deletions
diff --git a/zgrep.cc b/zgrep.cc
index 98899cd..6c8ceb1 100644
--- a/zgrep.cc
+++ b/zgrep.cc
@@ -1,5 +1,5 @@
/* Zgrep - search compressed files for a regular expression
- Copyright (C) 2010-2015 Antonio Diaz Diaz.
+ Copyright (C) 2010-2016 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
@@ -52,10 +52,11 @@ void show_help()
"file is compressed, its decompressed content is used. If a given file\n"
"does not exist, and its name does not end with one of the known\n"
"extensions, zgrep tries the compressed file names corresponding to the\n"
- "supported formats. If no files are specified, data is read from\n"
- "standard input, decompressed if needed, and fed to grep. Data read from\n"
- "standard input must be of the same type; all uncompressed or all\n"
- "in the same compression format.\n"
+ "supported formats.\n"
+ "\nIf no files are specified, or if a file is specified as '-', data is\n"
+ "read from standard input, decompressed if needed, and fed to grep. Data\n"
+ "read from standard input must be of the same type; all uncompressed or\n"
+ "all in the same compression format.\n"
"\nThe supported formats are bzip2, gzip, lzip and xz.\n"
"\nUsage: zgrep [options] <pattern> [files]\n"
"\nExit status is 0 if match, 1 if no match, 2 if trouble.\n"
@@ -337,16 +338,21 @@ int main( const int argc, const char * const argv[] )
for( ; argind < parser.arguments(); ++argind )
filenames.push_back( parser.argument( argind ) );
- if( filenames.empty() ) filenames.push_back("-");
+ if( filenames.empty() ) filenames.push_back( "-" );
if( show_name < 0 ) show_name = ( filenames.size() != 1 || recursive );
int retval = 1;
bool error = false;
+ bool stdin_used = false;
while( next_filename( filenames, input_filename, error, recursive,
false, no_messages ) )
{
- if( input_filename.empty() ) infd = STDIN_FILENO;
+ if( input_filename.empty() )
+ {
+ if( stdin_used ) continue; else stdin_used = true;
+ infd = STDIN_FILENO;
+ }
else
{
infd = open_instream( input_filename, format_index < 0, no_messages );