summaryrefslogtreecommitdiffstats
path: root/decompress.cc
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2018-02-13 07:06:07 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2018-02-13 07:06:07 +0000
commitac32e8eabf1b97208c4ccdfe908aea863d09d1f3 (patch)
tree97843c59827d6028ef778206eb2d194f772126dc /decompress.cc
parentAdding upstream version 1.6. (diff)
downloadplzip-ac32e8eabf1b97208c4ccdfe908aea863d09d1f3.tar.xz
plzip-ac32e8eabf1b97208c4ccdfe908aea863d09d1f3.zip
Adding upstream version 1.7.upstream/1.7
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'decompress.cc')
-rw-r--r--decompress.cc68
1 files changed, 31 insertions, 37 deletions
diff --git a/decompress.cc b/decompress.cc
index f580bca..ed1ac21 100644
--- a/decompress.cc
+++ b/decompress.cc
@@ -1,6 +1,6 @@
/* Plzip - Parallel compressor compatible with lzip
Copyright (C) 2009 Laszlo Ersek.
- Copyright (C) 2009-2017 Antonio Diaz Diaz.
+ Copyright (C) 2009-2018 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
@@ -37,23 +37,6 @@
#include "file_index.h"
-void Pretty_print::operator()( const char * const msg ) const
- {
- if( verbosity >= 0 )
- {
- if( first_post )
- {
- first_post = false;
- std::fprintf( stderr, " %s: ", name_.c_str() );
- for( unsigned i = name_.size(); i < longest_name; ++i )
- std::fputc( ' ', stderr );
- if( !msg ) std::fflush( stderr );
- }
- if( msg ) std::fprintf( stderr, "%s\n", msg );
- }
- }
-
-
// Returns the number of bytes really read.
// If (returned value < size) and (errno == 0), means EOF was reached.
//
@@ -197,6 +180,7 @@ extern "C" void * dworker( void * arg )
if( rd == 0 ) break;
}
}
+ show_progress( file_index.mblock( i ).size() );
}
delete[] obuffer; delete[] ibuffer;
@@ -211,25 +195,30 @@ extern "C" void * dworker( void * arg )
// start the workers and wait for them to finish.
-int decompress( int num_workers, const int infd, const int outfd,
- const Pretty_print & pp, const int debug_level,
- const bool ignore_trailing, const bool infd_isreg )
+int decompress( const unsigned long long cfile_size, int num_workers,
+ const int infd, const int outfd, const Pretty_print & pp,
+ const int debug_level, const bool ignore_trailing,
+ const bool loose_trailing, const bool infd_isreg )
{
if( !infd_isreg )
- return dec_stream( num_workers, infd, outfd, pp, debug_level, ignore_trailing );
+ return dec_stream( cfile_size, num_workers, infd, outfd, pp,
+ debug_level, ignore_trailing, loose_trailing );
- const File_index file_index( infd, ignore_trailing );
+ const File_index file_index( infd, ignore_trailing, loose_trailing );
if( file_index.retval() == 1 )
{
lseek( infd, 0, SEEK_SET );
- return dec_stream( num_workers, infd, outfd, pp, debug_level, ignore_trailing );
+ return dec_stream( cfile_size, num_workers, infd, outfd, pp,
+ debug_level, ignore_trailing, loose_trailing );
}
if( file_index.retval() != 0 )
- { pp( file_index.error().c_str() ); return file_index.retval(); }
+ { show_file_error( pp.name(), file_index.error().c_str() );
+ return file_index.retval(); }
- show_header( file_index.dictionary_size( 0 ) );
if( num_workers > file_index.members() )
num_workers = file_index.members();
+ if( verbosity >= 1 ) pp();
+ show_progress( 0, cfile_size, &pp ); // init
if( outfd >= 0 )
{
@@ -266,17 +255,22 @@ int decompress( int num_workers, const int infd, const int outfd,
delete[] worker_threads;
delete[] worker_args;
- const unsigned long long in_size = file_index.cdata_size();
- const unsigned long long out_size = file_index.udata_size();
- if( verbosity >= 2 && out_size > 0 && in_size > 0 )
- std::fprintf( stderr, "%6.3f:1, %6.3f bits/byte, %5.2f%% saved. ",
- (double)out_size / in_size,
- ( 8.0 * in_size ) / out_size,
- 100.0 * ( 1.0 - ( (double)in_size / out_size ) ) );
- if( verbosity >= 4 )
- std::fprintf( stderr, "decompressed %9llu, compressed %9llu. ",
- out_size, in_size );
-
+ if( verbosity >= 2 )
+ {
+ if( verbosity >= 4 ) show_header( file_index.dictionary_size( 0 ) );
+ const unsigned long long in_size = file_index.cdata_size();
+ const unsigned long long out_size = file_index.udata_size();
+ if( out_size == 0 || in_size == 0 )
+ std::fputs( "no data compressed. ", stderr );
+ else
+ std::fprintf( stderr, "%6.3f:1, %5.2f%% ratio, %5.2f%% saved. ",
+ (double)out_size / in_size,
+ ( 100.0 * in_size ) / out_size,
+ 100.0 - ( ( 100.0 * in_size ) / out_size ) );
+ if( verbosity >= 3 )
+ std::fprintf( stderr, "decompressed %9llu, compressed %8llu. ",
+ out_size, in_size );
+ }
if( verbosity >= 1 ) std::fputs( (outfd < 0) ? "ok\n" : "done\n", stderr );
return 0;