summaryrefslogtreecommitdiffstats
path: root/main.cc
diff options
context:
space:
mode:
authorDaniel Baumann <mail@daniel-baumann.ch>2015-11-07 10:16:41 +0000
committerDaniel Baumann <mail@daniel-baumann.ch>2015-11-07 10:16:41 +0000
commitd909f71ac50b6f45f5b91f35fd801d66d31898cd (patch)
tree7de62fc69cf3bbb88f2ab67d7be742c4d21a9e3a /main.cc
parentAdding debian version 1.13~rc2-1. (diff)
downloadlziprecover-d909f71ac50b6f45f5b91f35fd801d66d31898cd.tar.xz
lziprecover-d909f71ac50b6f45f5b91f35fd801d66d31898cd.zip
Merging upstream version 1.13.
Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch>
Diffstat (limited to 'main.cc')
-rw-r--r--main.cc92
1 files changed, 50 insertions, 42 deletions
diff --git a/main.cc b/main.cc
index dec1ec5..7480038 100644
--- a/main.cc
+++ b/main.cc
@@ -1,5 +1,5 @@
/* Lziprecover - Data recovery tool for lzipped files
- Copyright (C) 2009, 2010, 2011 Antonio Diaz Diaz.
+ Copyright (C) 2009, 2010, 2011, 2012 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
@@ -38,6 +38,10 @@
#include <utime.h>
#include <sys/stat.h>
#if defined(__MSVCRT__)
+#define fchmod(x,y) 0
+#define fchown(x,y,z) 0
+#define SIGHUP SIGTERM
+#define S_ISSOCK(x) 0
#define S_IRGRP 0
#define S_IWGRP 0
#define S_IROTH 0
@@ -57,7 +61,7 @@ namespace {
const char * const Program_name = "Lziprecover";
const char * const program_name = "lziprecover";
-const char * const program_year = "2011";
+const char * const program_year = "2012";
const char * invocation_name = 0;
#ifdef O_BINARY
@@ -82,7 +86,7 @@ mode_t outfd_mode = usr_rw;
bool delete_output_on_interrupt = false;
-void show_help() throw()
+void show_help()
{
std::printf( "%s - Data recovery tool and decompressor for lzipped files.\n", Program_name );
std::printf( "\nUsage: %s [options] [files]\n", invocation_name );
@@ -101,7 +105,7 @@ void show_help() throw()
" -q, --quiet suppress all messages\n"
// " -r, --recover correct errors in file using a recover file\n"
" -R, --repair try to repair a small error in file\n"
- " -s, --split split multimember file in single-member files\n"
+ " -s, --split split multi-member file in single-member files\n"
" -t, --test test compressed file integrity\n"
// " -u, --update convert file from version 0 to version 1\n"
" -v, --verbose be verbose (a 2nd -v gives more)\n"
@@ -112,7 +116,7 @@ void show_help() throw()
}
-void show_version() throw()
+void show_version()
{
std::printf( "%s %s\n", Program_name, PROGVERSION );
std::printf( "Copyright (C) %s Antonio Diaz Diaz.\n", program_year );
@@ -122,7 +126,7 @@ void show_version() throw()
}
-void one_file( const int argind, const int arguments ) throw()
+void one_file( const int argind, const int arguments )
{
if( argind + 1 != arguments )
{
@@ -132,7 +136,7 @@ void one_file( const int argind, const int arguments ) throw()
}
-void set_mode( Mode & program_mode, const Mode new_mode ) throw()
+void set_mode( Mode & program_mode, const Mode new_mode )
{
if( program_mode != m_none && program_mode != new_mode )
{
@@ -143,7 +147,7 @@ void set_mode( Mode & program_mode, const Mode new_mode ) throw()
}
-int extension_index( const std::string & name ) throw()
+int extension_index( const std::string & name )
{
for( int i = 0; known_extensions[i].from; ++i )
{
@@ -156,7 +160,7 @@ int extension_index( const std::string & name ) throw()
}
-void set_d_outname( const std::string & name, const int i ) throw()
+void set_d_outname( const std::string & name, const int i )
{
if( i >= 0 )
{
@@ -170,12 +174,12 @@ void set_d_outname( const std::string & name, const int i ) throw()
}
output_filename = name; output_filename += ".out";
if( verbosity >= 1 )
- std::fprintf( stderr, "%s: Can't guess original name for `%s' -- using `%s'.\n",
+ std::fprintf( stderr, "%s: Can't guess original name for '%s' -- using '%s'.\n",
program_name, name.c_str(), output_filename.c_str() );
}
-bool open_outstream( const bool force ) throw()
+bool open_outstream( const bool force )
{
int flags = O_CREAT | O_WRONLY | o_binary;
if( force ) flags |= O_TRUNC; else flags |= O_EXCL;
@@ -184,17 +188,17 @@ bool open_outstream( const bool force ) throw()
if( outfd < 0 && verbosity >= 0 )
{
if( errno == EEXIST )
- std::fprintf( stderr, "%s: Output file `%s' already exists, skipping.\n",
+ std::fprintf( stderr, "%s: Output file '%s' already exists, skipping.\n",
program_name, output_filename.c_str() );
else
- std::fprintf( stderr, "%s: Can't create output file `%s': %s.\n",
+ std::fprintf( stderr, "%s: Can't create output file '%s': %s.\n",
program_name, output_filename.c_str(), std::strerror( errno ) );
}
return ( outfd >= 0 );
}
-bool check_tty( const int infd ) throw()
+bool check_tty( const int infd )
{
if( isatty( infd ) )
{
@@ -205,13 +209,13 @@ bool check_tty( const int infd ) throw()
}
-void cleanup_and_fail( const int retval ) throw()
+void cleanup_and_fail( const int retval )
{
if( delete_output_on_interrupt )
{
delete_output_on_interrupt = false;
if( verbosity >= 0 )
- std::fprintf( stderr, "%s: Deleting output file `%s', if it exists.\n",
+ std::fprintf( stderr, "%s: Deleting output file '%s', if it exists.\n",
program_name, output_filename.c_str() );
if( outfd >= 0 ) { close( outfd ); outfd = -1; }
if( std::remove( output_filename.c_str() ) != 0 && errno != ENOENT )
@@ -247,7 +251,7 @@ void close_and_set_permissions( const struct stat * const in_statsp )
}
-std::string insert_fixed( std::string name ) throw()
+std::string insert_fixed( std::string name )
{
if( name.size() > 4 && name.compare( name.size() - 4, 4, ".tlz" ) == 0 )
name.insert( name.size() - 4, "_fixed" );
@@ -258,7 +262,7 @@ std::string insert_fixed( std::string name ) throw()
}
-unsigned char xdigit( const int value ) throw()
+unsigned char xdigit( const int value )
{
if( value >= 0 && value <= 9 ) return '0' + value;
if( value >= 10 && value <= 15 ) return 'A' + value - 10;
@@ -267,7 +271,7 @@ unsigned char xdigit( const int value ) throw()
void show_trailing_garbage( const uint8_t * const data, const int size,
- const Pretty_print & pp, const bool all ) throw()
+ const Pretty_print & pp, const bool all )
{
std::string garbage_msg;
if( !all ) garbage_msg = "first bytes of ";
@@ -277,11 +281,11 @@ void show_trailing_garbage( const uint8_t * const data, const int size,
if( !std::isprint( data[i] ) ) { text = false; break; }
if( text )
{
- garbage_msg += '`';
+ garbage_msg += '\'';
garbage_msg.append( (const char *)data, size );
garbage_msg += '\'';
}
- else
+ else
{
for( int i = 0; i < size; ++i )
{
@@ -304,10 +308,8 @@ int decompress( const int infd, const Pretty_print & pp, const bool testing )
for( bool first_member = true; ; first_member = false, pp.reset() )
{
File_header header;
- int size;
rdec.reset_member_position();
- for( size = 0; size < File_header::size && !rdec.finished(); ++size )
- header.data[size] = rdec.get_byte();
+ const int size = rdec.read( header.data, File_header::size );
if( rdec.finished() ) // End Of File
{
if( first_member )
@@ -344,8 +346,8 @@ int decompress( const int infd, const Pretty_print & pp, const bool testing )
header.version(),
format_num( header.dictionary_size(), 9999, -1 ) );
}
- LZ_decoder decoder( header, rdec, outfd );
+ LZ_decoder decoder( header, rdec, outfd );
const int result = decoder.decode_member( pp );
partial_file_pos += rdec.member_position();
if( result != 0 )
@@ -380,14 +382,14 @@ int decompress( const int infd, const Pretty_print & pp, const bool testing )
}
-extern "C" void signal_handler( int ) throw()
+extern "C" void signal_handler( int )
{
show_error( "Control-C or similar caught, quitting." );
cleanup_and_fail( 1 );
}
-void set_signals() throw()
+void set_signals()
{
std::signal( SIGHUP, signal_handler );
std::signal( SIGINT, signal_handler );
@@ -401,7 +403,7 @@ int verbosity = 0;
const char * format_num( long long num, long long limit,
- const int set_prefix ) throw()
+ const int set_prefix )
{
const char * const si_prefix[8] =
{ "k", "M", "G", "T", "P", "E", "Z", "Y" };
@@ -425,13 +427,13 @@ const char * format_num( long long num, long long limit,
int open_instream( const std::string & name, struct stat * const in_statsp,
- const bool to_stdout, const bool reg_only ) throw()
+ const bool to_stdout, const bool reg_only )
{
int infd = open( name.c_str(), O_RDONLY | o_binary );
if( infd < 0 )
{
if( verbosity >= 0 )
- std::fprintf( stderr, "%s: Can't open input file `%s': %s.\n",
+ std::fprintf( stderr, "%s: Can't open input file '%s': %s.\n",
program_name, name.c_str(), std::strerror( errno ) );
}
else
@@ -444,10 +446,10 @@ int open_instream( const std::string & name, struct stat * const in_statsp,
if( i != 0 || ( !S_ISREG( mode ) && ( !to_stdout || !can_read ) ) )
{
if( verbosity >= 0 )
- std::fprintf( stderr, "%s: Input file `%s' is not a regular file%s.\n",
+ std::fprintf( stderr, "%s: Input file '%s' is not a regular file%s.\n",
program_name, name.c_str(),
( can_read && !to_stdout ) ?
- " and `--stdout' was not specified" : "" );
+ " and '--stdout' was not specified" : "" );
close( infd );
infd = -1;
}
@@ -457,7 +459,7 @@ int open_instream( const std::string & name, struct stat * const in_statsp,
int open_outstream_rw( const std::string & output_filename,
- const bool force ) throw()
+ const bool force )
{
int flags = O_CREAT | O_RDWR | o_binary;
if( force ) flags |= O_TRUNC; else flags |= O_EXCL;
@@ -466,18 +468,18 @@ int open_outstream_rw( const std::string & output_filename,
if( outfd < 0 && verbosity >= 0 )
{
if( errno == EEXIST )
- std::fprintf( stderr, "%s: Output file `%s' already exists."
- " Use `--force' to overwrite it.\n",
+ std::fprintf( stderr, "%s: Output file '%s' already exists."
+ " Use '--force' to overwrite it.\n",
program_name, output_filename.c_str() );
else
- std::fprintf( stderr, "%s: Can't create output file `%s': %s.\n",
+ std::fprintf( stderr, "%s: Can't create output file '%s': %s.\n",
program_name, output_filename.c_str(), std::strerror( errno ) );
}
return outfd;
}
-void show_error( const char * const msg, const int errcode, const bool help ) throw()
+void show_error( const char * const msg, const int errcode, const bool help )
{
if( verbosity >= 0 )
{
@@ -489,7 +491,7 @@ void show_error( const char * const msg, const int errcode, const bool help ) th
std::fprintf( stderr, "\n" );
}
if( help && invocation_name && invocation_name[0] )
- std::fprintf( stderr, "Try `%s --help' for more information.\n",
+ std::fprintf( stderr, "Try '%s --help' for more information.\n",
invocation_name );
}
}
@@ -567,6 +569,11 @@ int main( const int argc, const char * const argv[] )
}
} // end process options
+#if defined(__MSVCRT__) || defined(__OS2__)
+ _fsetmode( stdin, "b" );
+ _fsetmode( stdout, "b" );
+#endif
+
if( program_mode == m_none )
{
show_error( "You must specify the operation to be performed.", 0, true );
@@ -607,6 +614,11 @@ int main( const int argc, const char * const argv[] )
case m_test: break;
}
+ if( program_mode == m_test )
+ outfd = -1;
+ else if( program_mode != m_decompress )
+ internal_error( "invalid decompressor operation" );
+
bool filenames_given = false;
for( ; argind < parser.arguments(); ++argind )
{
@@ -620,10 +632,6 @@ int main( const int argc, const char * const argv[] )
set_signals();
Pretty_print pp( filenames, verbosity );
- if( program_mode == m_test )
- outfd = -1;
- else if( program_mode != m_decompress )
- internal_error( "invalid decompressor operation" );
int retval = 0;
for( unsigned int i = 0; i < filenames.size(); ++i )