"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "rc.cc" between
zutils-1.8.tar.lz and zutils-1.9.tar.lz

About: Zutils is a collection of utilities able to deal with any combination of compressed and non-compressed files transparently. The utilities zcat, zcmp, zdiff, zgrep and ztest supports the compressors bzip2, gzip, lzip and xz.

rc.cc  (zutils-1.8.tar.lz):rc.cc  (zutils-1.9.tar.lz)
/* Zutils - Utilities dealing with compressed files /* Zutils - Utilities dealing with compressed files
Copyright (C) 2009-2019 Antonio Diaz Diaz. Copyright (C) 2009-2020 Antonio Diaz Diaz.
This program is free software: you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or the Free Software Foundation, either version 2 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#define _FILE_OFFSET_BITS 64 #define _FILE_OFFSET_BITS 64
#include <cerrno> #include <cerrno>
#include <cstdio> #include <cstdio>
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>
#include <string> #include <string>
#include <vector> #include <vector>
skipping to change at line 39 skipping to change at line 39
#include "arg_parser.h" #include "arg_parser.h"
#include "rc.h" #include "rc.h"
const char * invocation_name = 0; const char * invocation_name = 0;
const char * program_name = 0; const char * program_name = 0;
int verbosity = 0; int verbosity = 0;
namespace { namespace {
const char * const config_file_name = "zutilsrc"; const char * const config_file_name = "zutilsrc";
const char * const program_year = "2019"; const char * const program_year = "2020";
std::string compressor_names[num_formats] = std::string compressor_names[num_formats] =
{ "bzip2", "gzip", "lzip", "xz" }; // default compressor names { "bzip2", "gzip", "lzip", "xz" }; // default compressor names
// args to compressors, maybe empty // args to compressors read from rc or from options --[bglx]z, maybe empty
std::vector< std::string > compressor_args[num_formats]; std::vector< std::string > compressor_args[num_formats];
// vector of enabled formats plus [num_formats] for uncompressed. // vector of enabled formats plus [num_formats] for uncompressed.
// empty means all enabled. // empty means all enabled.
std::vector< bool > enabled_formats; std::vector< bool > enabled_formats;
const struct { const char * from; const char * to; int format_index; } const struct { const char * from; const char * to; int format_index; }
known_extensions[] = { known_extensions[] = {
{ ".bz2", "", fmt_bz2 }, { ".bz2", "", fmt_bz2 },
{ ".tbz", ".tar", fmt_bz2 }, { ".tbz", ".tar", fmt_bz2 },
skipping to change at line 92 skipping to change at line 92
// Returns the parity of escapes (backslashes) at the end of a string. // Returns the parity of escapes (backslashes) at the end of a string.
bool trailing_escape( const std::string & s ) bool trailing_escape( const std::string & s )
{ {
unsigned len = s.size(); unsigned len = s.size();
bool odd_escape = false; bool odd_escape = false;
while( len > 0 && s[--len] == '\\' ) odd_escape = !odd_escape; while( len > 0 && s[--len] == '\\' ) odd_escape = !odd_escape;
return odd_escape; return odd_escape;
} }
// Read a line discarding comments, leading whitespace and blank lines. /* Read a line discarding comments, leading whitespace, and blank lines.
// Escaped newlines are discarded. Escaped newlines are discarded.
// Returns the empty string if at EOF. Returns the empty string if at EOF.
// */
const std::string & my_fgets( FILE * const f, int & linenum ) const std::string & my_fgets( FILE * const f, int & linenum )
{ {
static std::string s; static std::string s;
bool strip = true; // strip leading whitespace bool strip = true; // strip leading whitespace
s.clear(); s.clear();
while( true ) while( true )
{ {
int ch = my_fgetc( f ); int ch = my_fgetc( f );
if( strip ) if( strip )
skipping to change at line 231 skipping to change at line 231
int format_index = num_formats; int format_index = num_formats;
const std::string s( arg, l, r - l ); const std::string s( arg, l, r - l );
for( int i = 0; i < num_formats; ++i ) for( int i = 0; i < num_formats; ++i )
if( s == format_names[i] ) if( s == format_names[i] )
{ format_index = i; break; } { format_index = i; break; }
if( format_index == num_formats && un.find( s ) != 0 ) if( format_index == num_formats && un.find( s ) != 0 )
{ error = true; break; } { error = true; break; }
enabled_formats[format_index] = true; enabled_formats[format_index] = true;
} }
if( error ) if( error )
{ show_error( "Bad argument for '--format' option." ); std::exit( 1 ); } { show_error( "Bad argument for option '--format'." ); std::exit( 1 ); }
} }
int parse_format_type( const std::string & arg ) int parse_format_type( const std::string & arg )
{ {
for( int i = 0; i < num_formats; ++i ) for( int i = 0; i < num_formats; ++i )
if( arg == format_names[i] ) if( arg == format_names[i] )
return i; return i;
show_error( "Bad argument for '--force-format' option." ); show_error( "Bad argument for option '--force-format'." );
std::exit( 1 ); std::exit( 1 );
} }
int extension_index( const std::string & name ) int extension_index( const std::string & name )
{ {
for( int eindex = 0; known_extensions[eindex].from; ++eindex ) for( int eindex = 0; known_extensions[eindex].from; ++eindex )
{ {
const std::string ext( known_extensions[eindex].from ); const std::string ext( known_extensions[eindex].from );
if( name.size() > ext.size() && if( name.size() > ext.size() &&
name.compare( name.size() - ext.size(), ext.size(), ext ) == 0 ) name.compare( name.size() - ext.size(), ext.size(), ext ) == 0 )
 End of changes. 8 change blocks. 
21 lines changed or deleted 21 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)