summaryrefslogtreecommitdiffstats
path: root/zupdate.cc
diff options
context:
space:
mode:
authorDaniel Baumann <mail@daniel-baumann.ch>2015-11-08 04:40:35 +0000
committerDaniel Baumann <mail@daniel-baumann.ch>2015-11-08 04:40:35 +0000
commitf7deb94049481143ef12eab590840d39aecedc14 (patch)
tree9ff4090b78d8343fd073ba1ea32068bb0d07caa6 /zupdate.cc
parentAdding debian version 1.3-4. (diff)
downloadzutils-f7deb94049481143ef12eab590840d39aecedc14.tar.xz
zutils-f7deb94049481143ef12eab590840d39aecedc14.zip
Merging upstream version 1.4~pre2.
Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch>
Diffstat (limited to 'zupdate.cc')
-rw-r--r--zupdate.cc55
1 files changed, 21 insertions, 34 deletions
diff --git a/zupdate.cc b/zupdate.cc
index 62fc2c1..8685018 100644
--- a/zupdate.cc
+++ b/zupdate.cc
@@ -1,5 +1,5 @@
/* Zupdate - recompress bzip2, gzip, xz files to lzip files
- Copyright (C) 2013, 2014 Antonio Diaz Diaz.
+ Copyright (C) 2013-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
@@ -75,6 +75,7 @@ void show_help()
" -f, --force do not skip a file even if the .lz exists\n"
" -k, --keep keep (don't delete) input files\n"
" -l, --lzip-verbose pass a -v option to the lzip compressor\n"
+ " -M, --format=<list> exclude formats not in <list>\n"
" -N, --no-rcfile don't read runtime configuration file\n"
" -q, --quiet suppress all messages\n"
" -r, --recursive operate recursively on directories\n"
@@ -124,47 +125,29 @@ void set_permissions( const char * const rname, const struct stat & in_stats )
}
-struct { const char * from; const char * to; int format_index; } const
- known_extensions[] = {
- { ".bz2", "", fmt_bz2 },
- { ".tbz", ".tar", fmt_bz2 },
- { ".tbz2", ".tar", fmt_bz2 },
- { ".gz", "", fmt_gz },
- { ".tgz", ".tar", fmt_gz },
- { ".lz", "", fmt_lz },
- { ".tlz", ".tar", fmt_lz },
- { ".xz", "", fmt_xz },
- { ".txz", ".tar", fmt_xz },
- { 0, 0, -1 } };
-
-
// Returns 0 for success, -1 for file skipped, 1 for error.
int zupdate_file( const std::string & name, const char * const lzip_name,
const std::vector< std::string > & lzip_args2,
- const bool force, const bool keep_input_files )
+ const bool force, const bool keep_input_files,
+ const bool no_rcfile )
{
static int disable_xz = -1; // tri-state bool
int format_index = -1;
std::string dname; // decompressed_name
- for( int i = 0; known_extensions[i].from; ++i ) // search extension
+ const int eindex = extension_index( name ); // search extension
+ if( eindex >= 0 )
{
- const std::string from( known_extensions[i].from );
- if( name.size() > from.size() &&
- name.compare( name.size() - from.size(), from.size(), from ) == 0 )
+ format_index = extension_format( eindex );
+ if( format_index == fmt_lz )
{
- dname.assign( name, 0, name.size() - from.size() );
- dname += known_extensions[i].to;
- format_index = known_extensions[i].format_index;
- if( format_index == fmt_lz )
- {
- if( verbosity >= 2 )
- std::fprintf( stderr, "%s: Input file '%s' already has '%s' suffix.\n",
- program_name, name.c_str(), known_extensions[i].from );
- return 0; // ignore this file
- }
- break;
+ if( verbosity >= 2 )
+ std::fprintf( stderr, "%s: Input file '%s' already has '%s' suffix.\n",
+ program_name, name.c_str(), extension_from( eindex ) );
+ return 0; // ignore this file
}
+ dname.assign( name, 0, name.size() - std::strlen( extension_from( eindex ) ) );
+ dname += extension_to( eindex );
}
const char * const compressor_name = get_compressor_name( format_index );
if( !compressor_name )
@@ -285,6 +268,7 @@ int zupdate_file( const std::string & name, const char * const lzip_name,
while( i > 0 && zcmp_command[i-1] != '/' ) --i;
zcmp_command.resize( i );
zcmp_command += "zcmp "; // ${bindir}zcmp
+ if( no_rcfile ) zcmp_command += "-N ";
zcmp_command += name; zcmp_command += ' '; zcmp_command += rname;
int status = std::system( zcmp_command.c_str() );
if( status != 0 )
@@ -313,6 +297,7 @@ int main( const int argc, const char * const argv[] )
std::vector< std::string > lzip_args2; // args to lzip, maybe empty
bool force = false;
bool keep_input_files = false;
+ bool no_rcfile = false;
bool recursive = false;
invocation_name = argv[0];
program_name = "zupdate";
@@ -333,6 +318,7 @@ int main( const int argc, const char * const argv[] )
{ 'h', "help", Arg_parser::no },
{ 'k', "keep", Arg_parser::no },
{ 'l', "lzip-verbose", Arg_parser::no },
+ { 'M', "format", Arg_parser::yes },
{ 'N', "no-rcfile", Arg_parser::no },
{ 'q', "quiet", Arg_parser::no },
{ 'r', "recursive", Arg_parser::no },
@@ -355,7 +341,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 '0': case '1': case '2': case '3': case '4':
@@ -365,7 +351,8 @@ int main( const int argc, const char * const argv[] )
case 'h': show_help(); return 0;
case 'k': keep_input_files = true; break;
case 'l': lzip_args2.push_back( "-v" ); break;
- case 'N': break;
+ case 'M': parse_format_list( arg ); break;
+ case 'N': no_rcfile = true; break;
case 'q': verbosity = -1; lzip_args2.push_back( "-q" ); break;
case 'r': recursive = true; break;
case 'v': if( verbosity < 4 ) ++verbosity; break;
@@ -395,7 +382,7 @@ int main( const int argc, const char * const argv[] )
while( next_filename( filenames, input_filename, error, recursive, true ) )
{
int tmp = zupdate_file( input_filename, lzip_name, lzip_args2, force,
- keep_input_files );
+ keep_input_files, no_rcfile );
if( tmp < 0 ) error = true;
if( tmp > retval ) retval = tmp;
if( tmp > 0 ) break;