summaryrefslogtreecommitdiffstats
path: root/rc.cc
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2022-02-03 11:13:26 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2022-02-03 11:13:44 +0000
commit50250d834c659e3593397cc6ee691d7efc721643 (patch)
treeb7f3fe28e142413de4866c7a314da8e53827c3f8 /rc.cc
parentReleasing debian version 1.10-2. (diff)
downloadzutils-50250d834c659e3593397cc6ee691d7efc721643.tar.xz
zutils-50250d834c659e3593397cc6ee691d7efc721643.zip
Merging upstream version 1.11.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'rc.cc')
-rw-r--r--rc.cc47
1 files changed, 34 insertions, 13 deletions
diff --git a/rc.cc b/rc.cc
index 0162510..e244a0e 100644
--- a/rc.cc
+++ b/rc.cc
@@ -1,5 +1,5 @@
/* Zutils - Utilities dealing with compressed files
- Copyright (C) 2009-2021 Antonio Diaz Diaz.
+ Copyright (C) 2009-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
@@ -37,12 +37,12 @@ int verbosity = 0;
namespace {
const char * const config_file_name = "zutilsrc";
-const char * const program_year = "2021";
+const char * const program_year = "2022";
std::string compressor_names[num_formats] =
- { "bzip2", "gzip", "lzip", "xz" }; // default compressor names
+ { "bzip2", "gzip", "lzip", "xz", "zstd" }; // default compressor names
-// args to compressors read from rc or from options --[bglx]z, maybe empty
+// args to compressors read from rc or from options like --lz, maybe empty
std::vector< std::string > compressor_args[num_formats];
// vector of enabled formats plus [num_formats] for uncompressed.
@@ -60,6 +60,8 @@ const struct { const char * from; const char * to; int format_index; }
{ ".tlz", ".tar", fmt_lz },
{ ".xz", "", fmt_xz },
{ ".txz", ".tar", fmt_xz },
+ { ".zst", "", fmt_zst },
+ { ".tzst", ".tar", fmt_zst },
{ 0, 0, -1 } };
@@ -83,7 +85,7 @@ int my_fgetc( FILE * const f )
}
-// Returns the parity of escapes (backslashes) at the end of a string.
+// Return the parity of escapes (backslashes) at the end of a string.
bool trailing_escape( const std::string & s )
{
unsigned len = s.size();
@@ -95,7 +97,7 @@ bool trailing_escape( const std::string & s )
/* Read a line discarding comments, leading whitespace, and blank lines.
Escaped newlines are discarded.
- Returns the empty string if at EOF.
+ Return the empty string if at EOF.
*/
const std::string & my_fgets( FILE * const f, int & linenum )
{
@@ -186,7 +188,7 @@ bool parse_rc_line( const std::string & line,
}
- // Returns 0 for success, 1 for file not found, 2 for syntax error.
+ // Return 0 if success, 1 if file not found, 2 if syntax error.
int process_rcfile( const std::string & name )
{
FILE * const f = std::fopen( name.c_str(), "r" );
@@ -217,7 +219,7 @@ bool enabled_format( const int format_index )
}
-void parse_format_list( const std::string & arg )
+void parse_format_list( const std::string & arg, const char * const pn )
{
const std::string un( "uncompressed" );
bool error = arg.empty();
@@ -236,17 +238,22 @@ void parse_format_list( const std::string & arg )
{ error = true; break; }
enabled_formats[format_index] = true;
}
- if( error )
- { show_error( "Bad argument for option '--format'." ); std::exit( 1 ); }
+ if( !error ) return;
+ if( verbosity >= 0 )
+ std::fprintf( stderr, "%s: Bad argument in option '%s'.\n",
+ program_name, pn );
+ std::exit( 1 );
}
-int parse_format_type( const std::string & arg )
+int parse_format_type( const std::string & arg, const char * const pn )
{
for( int i = 0; i < num_formats; ++i )
if( arg == format_names[i] )
return i;
- show_error( "Bad argument for option '--force-format'." );
+ if( verbosity >= 0 )
+ std::fprintf( stderr, "%s: Bad argument in option '%s'.\n",
+ program_name, pn );
std::exit( 1 );
}
@@ -322,10 +329,24 @@ void show_help_addr()
}
-void show_version()
+void show_version( const char * const command )
{
std::printf( "%s (zutils) %s\n", program_name, PROGVERSION );
std::printf( "Copyright (C) %s Antonio Diaz Diaz.\n", program_year );
+ if( command && verbosity >= 1 )
+ {
+ FILE * const f = popen( command, "r" );
+ if( f )
+ {
+ char command_version[1024] = { 0 };
+ const int rd = std::fread( command_version, 1, sizeof command_version, f );
+ pclose( f );
+ int i = 0;
+ while( i + 1 < rd && command_version[i] != '\n' ) ++i;
+ command_version[i] = 0;
+ if( command_version[0] ) std::printf( "Using %s\n", command_version );
+ }
+ }
std::printf( "License GPLv2+: GNU GPL version 2 or later <http://gnu.org/licenses/gpl.html>\n"
"This is free software: you are free to change and redistribute it.\n"
"There is NO WARRANTY, to the extent permitted by law.\n" );