summaryrefslogtreecommitdiffstats
path: root/zcmpdiff.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 /zcmpdiff.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 'zcmpdiff.cc')
-rw-r--r--zcmpdiff.cc46
1 files changed, 16 insertions, 30 deletions
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 ) );