diff options
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 46 |
1 files changed, 37 insertions, 9 deletions
@@ -1,4 +1,4 @@ -/* Clzip - Data compressor based on the LZMA algorithm +/* Clzip - LZMA lossless data compressor Copyright (C) 2010, 2011, 2012, 2013 Antonio Diaz Diaz. This program is free software: you can redistribute it and/or modify @@ -98,7 +98,7 @@ bool delete_output_on_interrupt = false; static void show_help( void ) { - printf( "%s - Data compressor based on the LZMA algorithm.\n", Program_name ); + printf( "%s - LZMA lossless data compressor.\n", Program_name ); printf( "\nUsage: %s [options] [files]\n", invocation_name ); printf( "\nOptions:\n" " -h, --help display this help and exit\n" @@ -459,22 +459,23 @@ static int compress( const unsigned long long member_size, while( true ) /* encode one member per iteration */ { struct LZ_encoder encoder; - const unsigned long long size = ( ( volume_size > 0 ) ? - min( member_size, volume_size - partial_volume_size ) : member_size ); + const unsigned long long size = ( volume_size > 0 ) ? + min( member_size, volume_size - partial_volume_size ) : member_size; if( !LZe_init( &encoder, &matchfinder, header, outfd ) ) { show_error( "Not enough memory. Try a smaller dictionary size.", 0, false ); cleanup_and_fail( 1 ); } + show_progress( in_size, &matchfinder, pp, in_statsp ); /* init */ if( !LZe_encode_member( &encoder, size ) ) { Pp_show_msg( pp, "Encoder error" ); retval = 1; break; } in_size += Mf_data_position( &matchfinder ); - out_size += Re_member_position( &encoder.range_encoder ); + out_size += Re_member_position( &encoder.renc ); LZe_free( &encoder ); if( Mf_finished( &matchfinder ) ) break; if( volume_size > 0 ) { - partial_volume_size += Re_member_position( &encoder.range_encoder ); + partial_volume_size += Re_member_position( &encoder.renc ); if( partial_volume_size >= volume_size - min_dictionary_size ) { partial_volume_size = 0; @@ -604,14 +605,13 @@ static void set_signals( void ) void Pp_init( struct Pretty_print * const pp, const char * const filenames[], - const int num_filenames, const int v ) + const int num_filenames ) { unsigned stdin_name_len; int i; pp->name = 0; pp->stdin_name = "(stdin)"; pp->longest_name = 0; - pp->verbosity = v; pp->first_post = false; stdin_name_len = strlen( pp->stdin_name ); @@ -650,6 +650,34 @@ void internal_error( const char * const msg ) } +void show_progress( const unsigned long long partial_size, + const struct Matchfinder * const m, + struct 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 struct Matchfinder * mf = 0; + static struct Pretty_print * pp = 0; + + if( m ) /* initialize static vars */ + { + psize = partial_size; mf = m; pp = p; + cfile_size = ( in_statsp && S_ISREG( in_statsp->st_mode ) ) ? + in_statsp->st_size / 100 : 0; + return; + } + if( mf && pp ) + { + const unsigned long long pos = psize + Mf_data_position( mf ); + if( cfile_size > 0 ) + fprintf( stderr, "%4llu%%", pos / cfile_size ); + fprintf( stderr, " %.1f MB\r", pos / 1000000.0 ); + Pp_reset( pp ); Pp_show_msg( pp, 0 ); /* restore cursor position */ + } + } + + int main( const int argc, const char * const argv[] ) { /* Mapping from gzip/bzip2 style 1..9 compression modes @@ -785,7 +813,7 @@ int main( const int argc, const char * const argv[] ) ( filenames_given || default_output_filename[0] ) ) set_signals(); - Pp_init( &pp, filenames, num_filenames, verbosity ); + Pp_init( &pp, filenames, num_filenames ); output_filename = resize_buffer( output_filename, 1 ); for( i = 0; i < num_filenames; ++i ) |