From 6c7f7b2ed08fa742632ec389c9c7852e629c7bf2 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 8 Nov 2015 05:40:27 +0100 Subject: Adding upstream version 1.4~pre2. Signed-off-by: Daniel Baumann --- zcmpdiff.cc | 46 ++++++++++++++++------------------------------ 1 file changed, 16 insertions(+), 30 deletions(-) (limited to 'zcmpdiff.cc') diff --git a/zcmpdiff.cc b/zcmpdiff.cc index 70fa986..524b863 100644 --- a/zcmpdiff.cc +++ b/zcmpdiff.cc @@ -1,5 +1,5 @@ /* Common code for zcmp and zdiff - Copyright (C) 2010-2014 Antonio Diaz Diaz. + Copyright (C) 2010-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 @@ -19,18 +19,6 @@ #define O_BINARY 0 #endif -struct { const char * from; const char * to; } const known_extensions[] = { - { ".bz2", "" }, - { ".tbz", ".tar" }, - { ".tbz2", ".tar" }, - { ".gz", "" }, - { ".tgz", ".tar" }, - { ".lz", "" }, - { ".tlz", ".tar" }, - { ".xz", "" }, - { ".txz", ".tar" }, - { 0, 0 } }; - int open_instream( const std::string & input_filename ) { @@ -43,28 +31,26 @@ int open_instream( const std::string & input_filename ) int open_other_instream( std::string & name ) { - for( int i = 0; known_extensions[i].from; ++i ) - { // search uncompressed version - const std::string from( known_extensions[i].from ); - if( name.size() > from.size() && - name.compare( name.size() - from.size(), from.size(), from ) == 0 ) - { - name.resize( name.size() - from.size() ); - name += known_extensions[i].to; - return open( name.c_str(), O_RDONLY | O_BINARY ); - } - } - for( int i = 0; i < num_formats; ++i ) - { // search compressed version - const std::string s( name + simple_extensions[format_order[i]] ); - const int infd = open( s.c_str(), O_RDONLY | O_BINARY ); - if( infd >= 0 ) { name = s; return infd; } + const int eindex = extension_index( name ); + if( eindex >= 0 && enabled_format( -1 ) ) + { // open uncompressed version + name.resize( name.size() - std::strlen( extension_from( eindex ) ) ); + name += extension_to( eindex ); + return open( name.c_str(), O_RDONLY | O_BINARY ); } + if( eindex < 0 ) + for( int i = 0; i < num_formats; ++i ) + if( enabled_format( format_order[i] ) ) + { // search compressed version + const std::string s( name + simple_extensions[format_order[i]] ); + const int infd = open( s.c_str(), O_RDONLY | O_BINARY ); + if( infd >= 0 ) { name = s; return infd; } + } return -1; } -void parse_format_types( const std::string & arg, int format_types[2] ) +void parse_format_types2( const std::string & arg, int format_types[2] ) { const unsigned i = std::min( arg.find( ',' ), arg.size() ); if( i > 0 ) format_types[0] = parse_format_type( arg.substr( 0, i ) ); -- cgit v1.2.3