diff options
author | Daniel Baumann <mail@daniel-baumann.ch> | 2015-11-08 04:40:27 +0000 |
---|---|---|
committer | Daniel Baumann <mail@daniel-baumann.ch> | 2015-11-08 04:40:27 +0000 |
commit | 6c7f7b2ed08fa742632ec389c9c7852e629c7bf2 (patch) | |
tree | 4066f3bf05144af754b8e725096e98bfc3339ac3 /zcat.cc | |
parent | Adding upstream version 1.3. (diff) | |
download | zutils-6c7f7b2ed08fa742632ec389c9c7852e629c7bf2.tar.xz zutils-6c7f7b2ed08fa742632ec389c9c7852e629c7bf2.zip |
Adding upstream version 1.4~pre2.upstream/1.4_pre2
Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch>
Diffstat (limited to '')
-rw-r--r-- | zcat.cc | 55 |
1 files changed, 10 insertions, 45 deletions
@@ -1,5 +1,5 @@ /* Zcat - decompress and concatenate files to standard output - Copyright (C) 2010-2014 Antonio Diaz Diaz. + Copyright (C) 2010-2015 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 @@ -39,14 +39,11 @@ #include "rc.h" #include "zutils.h" -#ifndef O_BINARY -#define O_BINARY 0 -#endif - namespace { #include "recursive.cc" +#include "zcatgrep.cc" struct Cat_options { @@ -111,9 +108,10 @@ void show_help() " -b, --number-nonblank number nonblank output lines\n" " -e equivalent to '-vE'\n" " -E, --show-ends display '$' at end of each line\n" - " --format=<fmt> force given format (bz2, gz, lz, xz)\n" + " -M, --format=<list> exclude formats not in <list>\n" " -n, --number number all output lines\n" " -N, --no-rcfile don't read runtime configuration file\n" + " -O, --force-format=<fmt> force given format (bz2, gz, lz, xz)\n" " -q, --quiet suppress all messages\n" " -r, --recursive operate recursively on directories\n" " -s, --squeeze-blank never more than one single blank line\n" @@ -129,41 +127,6 @@ void show_help() } -int simple_extension_index( const std::string & name ) - { - for( int i = 0; i < num_formats; ++i ) - { - const std::string ext( simple_extensions[i] ); - if( name.size() > ext.size() && - name.compare( name.size() - ext.size(), ext.size(), ext ) == 0 ) - return i; - } - return -1; - } - - -int open_instream( std::string & input_filename, const bool search ) - { - int infd = open( input_filename.c_str(), O_RDONLY | O_BINARY ); - if( infd < 0 ) - { - if( search && simple_extension_index( input_filename ) < 0 ) - { - for( int i = 0; i < num_formats; ++i ) - { - const std::string name( input_filename + - simple_extensions[format_order[i]] ); - infd = open( name.c_str(), O_RDONLY | O_BINARY ); - if( infd >= 0 ) { input_filename = name; break; } - } - } - if( infd < 0 ) - show_error2( "Can't open input file", input_filename.c_str() ); - } - return infd; - } - - int do_cat( const int infd, const int buffer_size, uint8_t * const inbuf, uint8_t * const outbuf, const std::string & input_filename, @@ -288,7 +251,7 @@ int cat( int infd, const int format_index, const std::string & input_filename, int main( const int argc, const char * const argv[] ) { - enum { format_opt = 256, verbose_opt, bz2_opt, gz_opt, lz_opt, xz_opt }; + enum { verbose_opt = 256, bz2_opt, gz_opt, lz_opt, xz_opt }; int infd = -1; int format_index = -1; bool recursive = false; @@ -310,8 +273,10 @@ int main( const int argc, const char * const argv[] ) { 'h', "help", Arg_parser::no }, { 'l', "list", Arg_parser::no }, // gzip { 'L', "license", Arg_parser::no }, // gzip + { 'M', "format", Arg_parser::yes }, { 'n', "number", Arg_parser::no }, // cat { 'N', "no-rcfile", Arg_parser::no }, + { 'O', "force-format", Arg_parser::yes }, { 'q', "quiet", Arg_parser::no }, { 'r', "recursive", Arg_parser::no }, { 's', "squeeze-blank", Arg_parser::no }, // cat @@ -319,7 +284,6 @@ int main( const int argc, const char * const argv[] ) { 'T', "show-tabs", Arg_parser::no }, // cat { 'v', "show-nonprinting", Arg_parser::no }, // cat { 'V', "version", Arg_parser::no }, - { format_opt, "format", Arg_parser::yes }, { verbose_opt, "verbose", Arg_parser::no }, { bz2_opt, "bz2", Arg_parser::yes }, { gz_opt, "gz", Arg_parser::yes }, @@ -338,7 +302,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 arg = parser.argument( argind ).c_str(); + const std::string & arg = parser.argument( argind ); switch( code ) { case 'A': cat_options.show_ends = true; @@ -353,9 +317,11 @@ int main( const int argc, const char * const argv[] ) case 'h': show_help(); return 0; case 'l': break; case 'L': break; + case 'M': parse_format_list( arg ); break; case 'n': if( cat_options.number_lines == 0 ) { cat_options.number_lines = 2; } break; case 'N': break; + case 'O': format_index = parse_format_type( arg ); break; case 'q': verbosity = -1; break; case 'r': recursive = true; break; case 's': cat_options.squeeze_blank = true; break; @@ -363,7 +329,6 @@ int main( const int argc, const char * const argv[] ) case 'T': cat_options.show_tabs = true; break; case 'v': cat_options.show_nonprinting = true; break; case 'V': show_version(); return 0; - case format_opt: format_index = parse_format_type( arg ); break; case verbose_opt: if( verbosity < 4 ) ++verbosity; break; case bz2_opt: parse_compressor( arg, fmt_bz2, 1 ); break; case gz_opt: parse_compressor( arg, fmt_gz, 1 ); break; |