diff options
Diffstat (limited to 'rc.cc')
-rw-r--r-- | rc.cc | 22 |
1 files changed, 16 insertions, 6 deletions
@@ -1,5 +1,5 @@ /* Zutils - Utilities dealing with compressed files - Copyright (C) 2009-2016 Antonio Diaz Diaz. + Copyright (C) 2009-2017 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,7 +37,7 @@ int verbosity = 0; namespace { const char * const config_file_name = "zutilsrc"; -const char * const program_year = "2016"; +const char * const program_year = "2017"; std::string compressor_names[num_formats] = { "bzip2", "gzip", "lzip", "xz" }; // default compressor names @@ -49,7 +49,7 @@ std::vector< std::string > compressor_args[num_formats]; // empty means all enabled. std::vector< bool > enabled_formats; -struct { const char * from; const char * to; int format_index; } const +const struct { const char * from; const char * to; int format_index; } known_extensions[] = { { ".bz2", "", fmt_bz2 }, { ".tbz", ".tar", fmt_bz2 }, @@ -253,12 +253,12 @@ int parse_format_type( const std::string & arg ) int extension_index( const std::string & name ) { - for( int i = 0; known_extensions[i].from; ++i ) + for( int eindex = 0; known_extensions[eindex].from; ++eindex ) { - const std::string ext( known_extensions[i].from ); + const std::string ext( known_extensions[eindex].from ); if( name.size() > ext.size() && name.compare( name.size() - ext.size(), ext.size(), ext ) == 0 ) - return i; + return eindex; } return -1; } @@ -347,6 +347,16 @@ void show_error( const char * const msg, const int errcode, const bool help ) } +void show_file_error( const char * const filename, const char * const msg, + const int errcode ) + { + if( verbosity < 0 ) return; + std::fprintf( stderr, "%s: %s: %s", program_name, filename, msg ); + if( errcode > 0 ) std::fprintf( stderr, ": %s", std::strerror( errcode ) ); + std::fputc( '\n', stderr ); + } + + void show_error2( const char * const msg, const char * const name ) { if( verbosity >= 0 ) |