summaryrefslogtreecommitdiffstats
path: root/main.cc
diff options
context:
space:
mode:
Diffstat (limited to 'main.cc')
-rw-r--r--main.cc47
1 files changed, 23 insertions, 24 deletions
diff --git a/main.cc b/main.cc
index a012d73..e8f7a79 100644
--- a/main.cc
+++ b/main.cc
@@ -140,7 +140,7 @@ void show_help()
void show_version()
{
- std::printf( "%s %s\n", Program_name, PROGVERSION );
+ std::printf( "%s %s\n", program_name, PROGVERSION );
std::printf( "Copyright (C) %s Antonio Diaz Diaz.\n", program_year );
std::printf( "License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\n"
"This is free software: you are free to change and redistribute it.\n"
@@ -259,8 +259,7 @@ int open_instream( const char * const name, struct stat * const in_statsp,
}
else
{
- do infd = open( name, O_RDONLY | O_BINARY );
- while( infd < 0 && errno == EINTR );
+ infd = open( name, O_RDONLY | O_BINARY );
if( infd < 0 )
{
if( verbosity >= 0 )
@@ -323,8 +322,7 @@ bool open_outstream( const bool force )
int flags = O_CREAT | O_WRONLY | O_BINARY;
if( force ) flags |= O_TRUNC; else flags |= O_EXCL;
- do outfd = open( output_filename.c_str(), flags, outfd_mode );
- while( outfd < 0 && errno == EINTR );
+ outfd = open( output_filename.c_str(), flags, outfd_mode );
if( outfd < 0 && verbosity >= 0 )
{
if( errno == EEXIST )
@@ -429,7 +427,7 @@ int compress( const unsigned long long member_size,
if( !header.dictionary_size( encoder_options.dictionary_size ) ||
encoder_options.match_len_limit < min_match_len_limit ||
encoder_options.match_len_limit > max_match_len )
- internal_error( "invalid argument to encoder" );
+ internal_error( "invalid argument to encoder." );
try {
Matchfinder matchfinder( header.dictionary_size(),
@@ -445,7 +443,7 @@ int compress( const unsigned long long member_size,
if( verbosity >= 2 )
show_progress( in_size, &matchfinder, &pp, cfile_size ); // init
if( !encoder.encode_member( size ) )
- { pp( "Encoder error" ); retval = 1; break; }
+ { pp( "Encoder error." ); retval = 1; break; }
in_size += matchfinder.data_position();
out_size += encoder.member_position();
if( matchfinder.finished() ) break;
@@ -459,7 +457,7 @@ int compress( const unsigned long long member_size,
{
close_and_set_permissions( in_statsp );
if( !next_filename() )
- { pp( "Too many volume files" ); retval = 1; break; }
+ { pp( "Too many volume files." ); retval = 1; break; }
if( !open_outstream( true ) ) { retval = 1; break; }
delete_output_on_interrupt = true;
}
@@ -483,7 +481,7 @@ int compress( const unsigned long long member_size,
}
catch( std::bad_alloc )
{
- pp( "Not enough memory. Try a smaller dictionary size" );
+ pp( "Not enough memory. Try a smaller dictionary size." );
retval = 1;
}
catch( Error e ) { pp(); show_error( e.msg, errno ); retval = 1; }
@@ -505,7 +503,7 @@ int fcompress( const unsigned long long member_size,
try {
Fmatchfinder fmatchfinder( infd );
if( !header.dictionary_size( fmatchfinder.dictionary_size() ) )
- internal_error( "invalid argument to encoder" );
+ internal_error( "invalid argument to encoder." );
unsigned long long in_size = 0, out_size = 0, partial_volume_size = 0;
while( true ) // encode one member per iteration
@@ -516,7 +514,7 @@ int fcompress( const unsigned long long member_size,
if( verbosity >= 2 )
show_progress( in_size, &fmatchfinder, &pp, cfile_size ); // init
if( !encoder.encode_member( size ) )
- { pp( "Encoder error" ); retval = 1; break; }
+ { pp( "Encoder error." ); retval = 1; break; }
in_size += fmatchfinder.data_position();
out_size += encoder.member_position();
if( fmatchfinder.finished() ) break;
@@ -530,7 +528,7 @@ int fcompress( const unsigned long long member_size,
{
close_and_set_permissions( in_statsp );
if( !next_filename() )
- { pp( "Too many volume files" ); retval = 1; break; }
+ { pp( "Too many volume files." ); retval = 1; break; }
if( !open_outstream( true ) ) { retval = 1; break; }
delete_output_on_interrupt = true;
}
@@ -554,7 +552,7 @@ int fcompress( const unsigned long long member_size,
}
catch( std::bad_alloc )
{
- pp( "Not enough memory. Try a smaller dictionary size" );
+ pp( "Not enough memory. Try a smaller dictionary size." );
retval = 1;
}
catch( Error e ) { pp(); show_error( e.msg, errno ); retval = 1; }
@@ -594,6 +592,7 @@ void show_trailing_garbage( const uint8_t * const data, const int size,
garbage_msg += xdigit( data[i] & 0x0F );
}
}
+ garbage_msg += '.';
pp( garbage_msg.c_str() );
}
@@ -613,7 +612,7 @@ int decompress( const int infd, const Pretty_print & pp, const bool testing )
if( rdec.finished() ) // End Of File
{
if( first_member )
- { pp( "File ends unexpectedly at member header" ); retval = 2; }
+ { pp( "File ends unexpectedly at member header." ); retval = 2; }
else if( verbosity >= 4 && size > 0 )
show_trailing_garbage( header.data, size, pp, true );
break;
@@ -621,7 +620,7 @@ int decompress( const int infd, const Pretty_print & pp, const bool testing )
if( !header.verify_magic() )
{
if( first_member )
- { pp( "Bad magic number (file not in lzip format)" ); retval = 2; }
+ { pp( "Bad magic number (file not in lzip format)." ); retval = 2; }
else if( verbosity >= 4 )
show_trailing_garbage( header.data, size, pp, false );
break;
@@ -636,7 +635,7 @@ int decompress( const int infd, const Pretty_print & pp, const bool testing )
}
if( header.dictionary_size() < min_dictionary_size ||
header.dictionary_size() > max_dictionary_size )
- { pp( "Invalid dictionary size in member header" ); retval = 2; break; }
+ { pp( "Invalid dictionary size in member header." ); retval = 2; break; }
if( verbosity >= 2 || ( verbosity == 1 && first_member ) )
{ pp(); if( verbosity >= 3 ) show_header( header ); }
@@ -650,10 +649,10 @@ int decompress( const int infd, const Pretty_print & pp, const bool testing )
{
pp();
if( result == 2 )
- std::fprintf( stderr, "File ends unexpectedly at pos %llu\n",
+ std::fprintf( stderr, "File ends unexpectedly at pos %llu.\n",
partial_file_pos );
else
- std::fprintf( stderr, "Decoder error at pos %llu\n",
+ std::fprintf( stderr, "Decoder error at pos %llu.\n",
partial_file_pos );
}
retval = 2; break;
@@ -662,7 +661,7 @@ int decompress( const int infd, const Pretty_print & pp, const bool testing )
{ std::fprintf( stderr, testing ? "ok\n" : "done\n" ); pp.reset(); }
}
}
- catch( std::bad_alloc ) { pp( "Not enough memory" ); retval = 1; }
+ catch( std::bad_alloc ) { pp( "Not enough memory." ); retval = 1; }
catch( Error e ) { pp(); show_error( e.msg, errno ); retval = 1; }
if( verbosity == 1 && retval == 0 )
std::fprintf( stderr, testing ? "ok\n" : "done\n" );
@@ -698,7 +697,7 @@ void show_error( const char * const msg, const int errcode, const bool help )
{
std::fprintf( stderr, "%s: %s", program_name, msg );
if( errcode > 0 )
- std::fprintf( stderr, ": %s", std::strerror( errcode ) );
+ std::fprintf( stderr, ": %s.", std::strerror( errcode ) );
std::fprintf( stderr, "\n" );
}
if( help )
@@ -711,7 +710,7 @@ void show_error( const char * const msg, const int errcode, const bool help )
void internal_error( const char * const msg )
{
if( verbosity >= 0 )
- std::fprintf( stderr, "%s: internal error: %s.\n", program_name, msg );
+ std::fprintf( stderr, "%s: internal error: %s\n", program_name, msg );
std::exit( 3 );
}
@@ -837,7 +836,7 @@ int main( const int argc, const char * const argv[] )
case 't': program_mode = m_test; break;
case 'v': if( verbosity < 4 ) ++verbosity; break;
case 'V': show_version(); return 0;
- default : internal_error( "uncaught option" );
+ default : internal_error( "uncaught option." );
}
} // end process options
@@ -874,13 +873,13 @@ int main( const int argc, const char * const argv[] )
struct stat in_stats;
output_filename.clear();
- if( !filenames[i].size() || filenames[i] == "-" )
+ if( filenames[i].empty() || filenames[i] == "-" )
{
input_filename.clear();
infd = STDIN_FILENO;
if( program_mode != m_test )
{
- if( to_stdout || !default_output_filename.size() )
+ if( to_stdout || default_output_filename.empty() )
outfd = STDOUT_FILENO;
else
{