summaryrefslogtreecommitdiffstats
path: root/main.cc
diff options
context:
space:
mode:
Diffstat (limited to 'main.cc')
-rw-r--r--main.cc65
1 files changed, 33 insertions, 32 deletions
diff --git a/main.cc b/main.cc
index 2de410b..3e95eb9 100644
--- a/main.cc
+++ b/main.cc
@@ -1,5 +1,5 @@
/* Lzip - Data compressor based on the LZMA algorithm
- Copyright (C) 2008, 2009, 2010, 2011 Antonio Diaz Diaz.
+ Copyright (C) 2008, 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
@@ -77,7 +77,7 @@ namespace {
const char * const Program_name = "Lzip";
const char * const program_name = "lzip";
-const char * const program_year = "2011";
+const char * const program_year = "2012";
const char * invocation_name = 0;
#ifdef O_BINARY
@@ -135,6 +135,10 @@ void show_help() throw()
"from standard input to standard output.\n"
"Numbers may be followed by a multiplier: k = kB = 10^3 = 1000,\n"
"Ki = KiB = 2^10 = 1024, M = 10^6, Mi = 2^20, G = 10^9, Gi = 2^30, etc...\n"
+ "The bidimensional parameter space of LZMA can't be mapped to a linear\n"
+ "scale optimal for all files. If your files are large, very repetitive,\n"
+ "etc, you may need to use the --match-length and --dictionary-size\n"
+ "options directly to achieve optimal performance.\n"
"\nReport bugs to lzip-bug@nongnu.org\n"
"Lzip home page: http://www.nongnu.org/lzip/lzip.html\n" );
}
@@ -254,7 +258,7 @@ int open_instream( const std::string & name, struct stat * const in_statsp,
if( program_mode == m_compress && !recompress && eindex >= 0 )
{
if( verbosity >= 0 )
- std::fprintf( stderr, "%s: Input file `%s' already has `%s' suffix.\n",
+ std::fprintf( stderr, "%s: Input file '%s' already has '%s' suffix.\n",
program_name, name.c_str(),
known_extensions[eindex].from );
}
@@ -264,7 +268,7 @@ int open_instream( const std::string & name, struct stat * const in_statsp,
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
@@ -277,10 +281,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;
}
@@ -312,7 +316,7 @@ 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() );
}
@@ -326,10 +330,10 @@ 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 );
@@ -359,7 +363,7 @@ void cleanup_and_fail( const int retval ) throw()
{
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 )
@@ -412,14 +416,14 @@ int compress( const long long member_size, const long long volume_size,
const Lzma_options & encoder_options, const int infd,
const Pretty_print & pp, const struct stat * const in_statsp )
{
- if( verbosity >= 1 ) pp();
+ int retval = 0;
File_header header;
header.set_magic();
+ if( verbosity >= 1 ) pp();
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" );
- int retval = 0;
try {
Matchfinder matchfinder( header.dictionary_size(),
@@ -480,10 +484,10 @@ int fcompress( const long long member_size, const long long volume_size,
const int infd,
const Pretty_print & pp, const struct stat * const in_statsp )
{
- if( verbosity >= 1 ) pp();
+ int retval = 0;
File_header header;
header.set_magic();
- int retval = 0;
+ if( verbosity >= 1 ) pp();
try {
Fmatchfinder fmatchfinder( infd );
@@ -558,7 +562,7 @@ 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 += '\'';
}
@@ -585,10 +589,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 )
@@ -625,8 +627,8 @@ int decompress( const int infd, const Pretty_print & pp, const bool testing )
header.version(),
format_num( header.dictionary_size() ) );
}
- 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 )
@@ -690,13 +692,13 @@ 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 );
}
}
-void internal_error( const char * const msg )
+void internal_error( const char * const msg ) throw()
{
if( verbosity >= 0 )
std::fprintf( stderr, "%s: internal error: %s.\n", program_name, msg );
@@ -750,7 +752,6 @@ int main( const int argc, const char * const argv[] )
{ 'b', "member-size", Arg_parser::yes },
{ 'c', "stdout", Arg_parser::no },
{ 'd', "decompress", Arg_parser::no },
- { 'e', "extreme", Arg_parser::no },
{ 'f', "force", Arg_parser::no },
{ 'F', "recompress", Arg_parser::no },
{ 'h', "help", Arg_parser::no },
@@ -785,7 +786,6 @@ int main( const int argc, const char * const argv[] )
case 'b': member_size = getnum( arg, 100000, LLONG_MAX / 2 ); break;
case 'c': to_stdout = true; break;
case 'd': program_mode = m_decompress; break;
- case 'e': break; // ignored by now
case 'f': force = true; break;
case 'F': recompress = true; break;
case 'h': show_help(); return 0;
@@ -806,10 +806,18 @@ int main( const int argc, const char * const argv[] )
} // end process options
#if defined(__MSVCRT__) || defined(__OS2__)
- _setmode( STDIN_FILENO, O_BINARY );
- _setmode( STDOUT_FILENO, O_BINARY );
+ _fsetmode( stdin, "b" );
+ _fsetmode( stdout, "b" );
#endif
+ if( program_mode == m_test )
+ outfd = -1;
+ else if( program_mode == m_compress )
+ {
+ dis_slots.init();
+ prob_prices.init();
+ }
+
bool filenames_given = false;
for( ; argind < parser.arguments(); ++argind )
{
@@ -823,13 +831,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_compress )
- {
- dis_slots.init();
- prob_prices.init();
- }
int retval = 0;
for( unsigned int i = 0; i < filenames.size(); ++i )