summaryrefslogtreecommitdiffstats
path: root/zcmpdiff.cc
diff options
context:
space:
mode:
Diffstat (limited to 'zcmpdiff.cc')
-rw-r--r--zcmpdiff.cc33
1 files changed, 19 insertions, 14 deletions
diff --git a/zcmpdiff.cc b/zcmpdiff.cc
index bbbc87e..961a32a 100644
--- a/zcmpdiff.cc
+++ b/zcmpdiff.cc
@@ -31,21 +31,26 @@ int open_instream( const std::string & input_filename )
int open_other_instream( std::string & name )
{
- 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 );
+ const int eindex = extension_index( name ); // search extension
+ if( eindex >= 0 && enabled_format( -1 ) ) // open uncompressed version
+ {
+ std::string s( name, 0, name.size() - std::strlen( extension_from( eindex ) ) );
+ s += extension_to( eindex );
+ const int infd = open( s.c_str(), O_RDONLY | O_BINARY );
+ if( infd >= 0 ) { name = s; return infd; }
+ }
+ const int eformat = extension_format( eindex );
+ for( int i = 0; i < num_formats; ++i ) // search compressed version
+ {
+ const int format_index = format_order[i];
+ if( eformat != format_index && enabled_format( format_index ) )
+ {
+ std::string s( name, 0, name.size() - std::strlen( extension_from( eindex ) ) );
+ s += simple_extensions[format_index];
+ const int infd = open( s.c_str(), O_RDONLY | O_BINARY );
+ if( infd >= 0 ) { name = s; return infd; }
+ }
}
- if( eindex < 0 ) // search compressed version
- for( int i = 0; i < num_formats; ++i )
- if( enabled_format( format_order[i] ) )
- {
- 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;
}