diff options
Diffstat (limited to 'zcat.cc')
-rw-r--r-- | zcat.cc | 29 |
1 files changed, 17 insertions, 12 deletions
@@ -61,7 +61,7 @@ Line_number line_number; void show_zcat_help() { std::printf( "Zcat copies each given file (\"-\" means standard input), to standard\n" - "output. If any given file is compressed, its uncompressed content is\n" + "output. If any given file is compressed, its decompressed content is\n" "used. If a given file does not exist, and its name does not end with one\n" "of the known extensions, zcat tries the compressed file names\n" "corresponding to the supported formats. If no files are specified,\n" @@ -70,7 +70,7 @@ void show_zcat_help() "all uncompressed or all in the same compression format.\n" "\nThe supported formats are bzip2, gzip, lzip and xz.\n" "\nUsage: zcat [options] [files]\n" - "\nExit status is 0 if no errors occurred, 1 otherwise.\n" + "\nExit status is 0 if no errors occurred, non-zero otherwise.\n" "\nOptions:\n" " -h, --help display this help and exit\n" " -V, --version output version information and exit\n" @@ -80,13 +80,18 @@ void show_zcat_help() " -E, --show-ends display '$' at end of each line\n" " --format=<fmt> force given format (bz2, gz, lz, xz)\n" " -n, --number number all output lines\n" + " -N, --no-rcfile don't read runtime configuration file\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" " -t equivalent to '-vT'\n" " -T, --show-tabs display TAB characters as '^I'\n" " -v, --show-nonprinting use '^' and 'M-' notation, except for LF and TAB\n" - " --verbose verbose mode (show error messages)\n" ); + " --verbose verbose mode (show error messages)\n" + " --bz2=<command> set compressor and options for bzip2 format\n" + " --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" ); show_help_addr(); } @@ -187,7 +192,7 @@ int do_cat( const int infd, const int buffer_size, } -int cat( int infd, const int format_type, const std::string & input_filename, +int cat( int infd, const int format_index, const std::string & input_filename, const Cat_options & cat_options ) { enum { buffer_size = 4096 }; @@ -195,17 +200,17 @@ int cat( int infd, const int format_type, const std::string & input_filename, uint8_t * const inbuf = new uint8_t[buffer_size+1]; // buffer with space for character quoting and 255-digit line number uint8_t * const outbuf = new uint8_t[(4*buffer_size)+256]; - pid_t pid = 0; int retval = 0; - if( !set_data_feeder( &infd, &pid, format_type ) ) retval = 1; + Children children; + if( !set_data_feeder( &infd, children, format_index ) ) retval = 1; else retval = do_cat( infd, buffer_size, inbuf, outbuf, input_filename, cat_options ); - if( retval == 0 ) - if( pid && wait_for_child( pid, "data feeder" ) != 0 ) retval = 1; - if( retval == 0 ) - if( close( infd ) != 0 ) - { show_close_error( "data feeder" ); retval = 1; } - delete[] inbuf; delete[] outbuf; + + if( !good_status( children, retval == 0 ) ) retval = 1; + + if( retval == 0 && close( infd ) != 0 ) + { show_close_error( "data feeder" ); retval = 1; } + delete[] outbuf; delete[] inbuf; return retval; } |