summaryrefslogtreecommitdiffstats
path: root/main.cc
diff options
context:
space:
mode:
Diffstat (limited to 'main.cc')
-rw-r--r--main.cc48
1 files changed, 40 insertions, 8 deletions
diff --git a/main.cc b/main.cc
index 2c4e594..921684a 100644
--- a/main.cc
+++ b/main.cc
@@ -1,4 +1,4 @@
-/* Lzip - Data compressor based on the LZMA algorithm
+/* Lzip - LZMA lossless data compressor
Copyright (C) 2008, 2009, 2010, 2011, 2012, 2013 Antonio Diaz Diaz.
This program is free software: you can redistribute it and/or modify
@@ -94,7 +94,6 @@ const unsigned long long max_volume_size = 0x7FFFFFFFFFFFFFFFULL;
std::string output_filename;
int outfd = -1;
-int verbosity = 0;
const mode_t usr_rw = S_IRUSR | S_IWUSR;
const mode_t all_rw = usr_rw | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
mode_t outfd_mode = usr_rw;
@@ -103,7 +102,7 @@ bool delete_output_on_interrupt = false;
void show_help()
{
- std::printf( "%s - Data compressor based on the LZMA algorithm.\n", Program_name );
+ std::printf( "%s - LZMA lossless data compressor.\n", Program_name );
std::printf( "\nUsage: %s [options] [files]\n", invocation_name );
std::printf( "\nOptions:\n"
" -h, --help display this help and exit\n"
@@ -434,8 +433,9 @@ int compress( const unsigned long long member_size,
while( true ) // encode one member per iteration
{
LZ_encoder encoder( matchfinder, header, outfd );
- const unsigned long long size = ( ( volume_size > 0 ) ?
- std::min( member_size, volume_size - partial_volume_size ) : member_size );
+ const unsigned long long size = ( volume_size > 0 ) ?
+ std::min( member_size, volume_size - partial_volume_size ) : member_size;
+ show_progress( in_size, &matchfinder, &pp, in_statsp ); // init
if( !encoder.encode_member( size ) )
{ pp( "Encoder error" ); retval = 1; break; }
in_size += matchfinder.data_position();
@@ -501,8 +501,9 @@ int fcompress( const unsigned long long member_size,
while( true ) // encode one member per iteration
{
FLZ_encoder encoder( fmatchfinder, header, outfd );
- const unsigned long long size = ( ( volume_size > 0 ) ?
- std::min( member_size, volume_size - partial_volume_size ) : member_size );
+ const unsigned long long size = ( volume_size > 0 ) ?
+ std::min( member_size, volume_size - partial_volume_size ) : member_size;
+ show_progress( in_size, &fmatchfinder, &pp, in_statsp ); // init
if( !encoder.encode_member( size ) )
{ pp( "Encoder error" ); retval = 1; break; }
in_size += fmatchfinder.data_position();
@@ -679,6 +680,9 @@ void set_signals()
} // end namespace
+int verbosity = 0;
+
+
void show_error( const char * const msg, const int errcode, const bool help )
{
if( verbosity >= 0 )
@@ -705,6 +709,34 @@ void internal_error( const char * const msg )
}
+void show_progress( const unsigned long long partial_size,
+ const Matchfinder_base * const m,
+ const Pretty_print * const p,
+ const struct stat * const in_statsp )
+ {
+ static unsigned long long cfile_size = 0; // file_size / 100
+ static unsigned long long psize = 0;
+ static const Matchfinder_base * mb = 0;
+ static const Pretty_print * pp = 0;
+
+ if( m ) // initialize static vars
+ {
+ psize = partial_size; mb = m; pp = p;
+ cfile_size = ( in_statsp && S_ISREG( in_statsp->st_mode ) ) ?
+ in_statsp->st_size / 100 : 0;
+ return;
+ }
+ if( mb && pp )
+ {
+ const unsigned long long pos = psize + mb->data_position();
+ if( cfile_size > 0 )
+ std::fprintf( stderr, "%4llu%%", pos / cfile_size );
+ std::fprintf( stderr, " %.1f MB\r", pos / 1000000.0 );
+ pp->reset(); (*pp)(); // restore cursor position
+ }
+ }
+
+
int main( const int argc, const char * const argv[] )
{
// Mapping from gzip/bzip2 style 1..9 compression modes
@@ -831,7 +863,7 @@ int main( const int argc, const char * const argv[] )
( filenames_given || default_output_filename.size() ) )
set_signals();
- Pretty_print pp( filenames, verbosity );
+ Pretty_print pp( filenames );
int retval = 0;
for( unsigned i = 0; i < filenames.size(); ++i )