summaryrefslogtreecommitdiffstats
path: root/zcat.cc
diff options
context:
space:
mode:
Diffstat (limited to 'zcat.cc')
-rw-r--r--zcat.cc71
1 files changed, 36 insertions, 35 deletions
diff --git a/zcat.cc b/zcat.cc
index bdbdab3..42e821e 100644
--- a/zcat.cc
+++ b/zcat.cc
@@ -1,5 +1,5 @@
/* Zcat - decompress and concatenate files to standard output
- Copyright (C) 2010, 2011 Antonio Diaz Diaz.
+ Copyright (C) 2010, 2011, 2012, 2013 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
@@ -23,7 +23,7 @@ struct Cat_options
bool show_tabs;
bool squeeze_blank;
- Cat_options() throw()
+ Cat_options()
: number_lines( 0 ), show_ends( false ), show_nonprinting( false ),
show_tabs( false ), squeeze_blank( false ) {}
};
@@ -32,20 +32,20 @@ struct Cat_options
class Line_number // unlimited size line counter
{
std::string str;
- int first_digit_pos;
+ unsigned first_digit_pos;
public:
Line_number() : str( " 0\t" ), first_digit_pos( 5 ) {}
void next()
{
- for( int i = str.size() - 2; i >= first_digit_pos; --i )
+ for( unsigned i = str.size() - 1; i > first_digit_pos; )
{
- if( str[i] < '9' ) { ++str[i]; return; }
+ if( str[--i] < '9' ) { ++str[i]; return; }
str[i] = '0';
}
if( first_digit_pos > 0 ) str[--first_digit_pos] = '1';
- else str.insert( 0U, 1, '1' );
+ else str.insert( first_digit_pos, 1, '1' );
}
int sprint( uint8_t * const buf )
@@ -58,34 +58,35 @@ public:
Line_number line_number;
-void show_zcat_help() throw()
+void show_zcat_help()
{
- std::printf( "Zcat copies each given file (\"-\" means standard input), to standard\n" );
- std::printf( "output. If any given file is compressed, its uncompressed content is\n" );
- std::printf( "used. If a given file does not exist, and its name does not end with one\n" );
- std::printf( "of the known extensions, zcat tries the compressed file names\n" );
- std::printf( "corresponding to the supported compressors. If no files are specified,\n" );
- std::printf( "data is read from standard input, decompressed if needed, and sent to\n" );
- std::printf( "standard output. Data read from standard input must be of the same type;\n" );
- std::printf( "all uncompressed or all compressed with the same compressor.\n" );
- std::printf( "The supported compressors are bzip2, gzip, lzip and xz.\n" );
- std::printf( "\nUsage: zcat [options] [files]\n" );
- std::printf( "\nExit status is 0 if no errors occurred, 1 otherwise.\n" );
- std::printf( "\nOptions:\n" );
- std::printf( " -h, --help display this help and exit\n" );
- std::printf( " -V, --version output version information and exit\n" );
- std::printf( " -A, --show-all equivalent to `-vET'\n" );
- std::printf( " -b, --number-nonblank number nonblank output lines\n" );
- std::printf( " -e equivalent to `-vE'\n" );
- std::printf( " -E, --show-ends display `$' at end of each line\n" );
- std::printf( " -n, --number number all output lines\n" );
- std::printf( " -q, --quiet suppress all messages\n" );
- std::printf( " -r, --recursive operate recursively on directories\n" );
- std::printf( " -s, --squeeze-blank never more than one single blank line\n" );
- std::printf( " -t equivalent to `-vT'\n" );
- std::printf( " -T, --show-tabs display TAB characters as `^I'\n" );
- std::printf( " -v, --show-nonprinting use `^' and `M-' notation, except for LF and TAB\n" );
- std::printf( " --verbose verbose mode (show error messages)\n" );
+ 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"
+ "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"
+ "data is read from standard input, decompressed if needed, and sent to\n"
+ "standard output. Data read from standard input must be of the same type;\n"
+ "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"
+ "\nOptions:\n"
+ " -h, --help display this help and exit\n"
+ " -V, --version output version information and exit\n"
+ " -A, --show-all equivalent to '-vET'\n"
+ " -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"
+ " -n, --number number all output lines\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" );
show_help_addr();
}
@@ -186,7 +187,7 @@ int do_cat( const int infd, const int buffer_size,
}
-int cat( int infd, const std::string & input_filename,
+int cat( int infd, const int format_type, const std::string & input_filename,
const Cat_options & cat_options )
{
enum { buffer_size = 4096 };
@@ -196,7 +197,7 @@ int cat( int infd, const std::string & input_filename,
uint8_t * const outbuf = new uint8_t[(4*buffer_size)+256];
pid_t pid = 0;
int retval = 0;
- if( !set_data_feeder( &infd, &pid ) ) retval = 1;
+ if( !set_data_feeder( &infd, &pid, format_type ) ) retval = 1;
else
retval = do_cat( infd, buffer_size, inbuf, outbuf,
input_filename, cat_options );