summaryrefslogtreecommitdiffstats
path: root/decoder.cc
diff options
context:
space:
mode:
Diffstat (limited to 'decoder.cc')
-rw-r--r--decoder.cc72
1 files changed, 33 insertions, 39 deletions
diff --git a/decoder.cc b/decoder.cc
index 734fc9d..9ba8315 100644
--- a/decoder.cc
+++ b/decoder.cc
@@ -1,5 +1,5 @@
/* Lziprecover - Data recovery tool for the lzip format
- 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
@@ -34,23 +34,6 @@
const CRC32 crc32;
-void Pretty_print::operator()( const char * const msg, FILE * const f ) const
- {
- if( verbosity_ >= 0 )
- {
- if( first_post )
- {
- first_post = false;
- std::fprintf( f, " %s: ", name_.c_str() );
- for( unsigned i = name_.size(); i < longest_name; ++i )
- std::fputc( ' ', f );
- if( !msg ) std::fflush( f );
- }
- if( msg ) std::fprintf( f, "%s\n", msg );
- }
- }
-
-
/* Returns the number of bytes really read.
If (returned value < size) and (errno == 0), means EOF was reached.
*/
@@ -97,6 +80,7 @@ bool Range_decoder::read_block()
at_stream_end = ( stream_pos < buffer_size );
partial_member_pos += pos;
pos = 0;
+ show_dprogress();
}
return pos < stream_pos;
}
@@ -130,7 +114,6 @@ bool LZ_decoder::verify_trailer( const Pretty_print & pp ) const
int size = rdec.read_data( trailer.data, File_trailer::size );
const unsigned long long data_size = data_position();
const unsigned long long member_size = rdec.member_position();
- const int verbosity = pp.verbosity();
bool error = false;
if( size < File_trailer::size )
@@ -145,50 +128,61 @@ bool LZ_decoder::verify_trailer( const Pretty_print & pp ) const
while( size < File_trailer::size ) trailer.data[size++] = 0;
}
- if( trailer.data_crc() != crc() )
+ const unsigned td_crc = trailer.data_crc();
+ if( td_crc != crc() )
{
error = true;
if( verbosity >= 0 )
{
pp();
- std::fprintf( stderr, "CRC mismatch; trailer says %08X, data CRC is %08X\n",
- trailer.data_crc(), crc() );
+ std::fprintf( stderr, "CRC mismatch; stored %08X, computed %08X\n",
+ td_crc, crc() );
}
}
- if( trailer.data_size() != data_size )
+ const unsigned long long td_size = trailer.data_size();
+ if( td_size != data_size )
{
error = true;
if( verbosity >= 0 )
{
pp();
- std::fprintf( stderr, "Data size mismatch; trailer says %llu, data size is %llu (0x%llX)\n",
- trailer.data_size(), data_size, data_size );
+ std::fprintf( stderr, "Data size mismatch; stored %llu (0x%llX), computed %llu (0x%llX)\n",
+ td_size, td_size, data_size, data_size );
}
}
- if( trailer.member_size() != member_size )
+ const unsigned long long tm_size = trailer.member_size();
+ if( tm_size != member_size )
{
error = true;
if( verbosity >= 0 )
{
pp();
- std::fprintf( stderr, "Member size mismatch; trailer says %llu, member size is %llu (0x%llX)\n",
- trailer.member_size(), member_size, member_size );
+ std::fprintf( stderr, "Member size mismatch; stored %llu (0x%llX), computed %llu (0x%llX)\n",
+ tm_size, tm_size, member_size, member_size );
}
}
- if( !error && verbosity >= 2 && data_size > 0 && member_size > 0 )
- std::fprintf( stderr, "%6.3f:1, %6.3f bits/byte, %5.2f%% saved. ",
- (double)data_size / member_size,
- ( 8.0 * member_size ) / data_size,
- 100.0 * ( 1.0 - ( (double)member_size / data_size ) ) );
- if( !error && verbosity >= 4 )
- std::fprintf( stderr, "CRC %08X, decompressed %9llu, compressed %8llu. ",
- crc(), data_size, member_size );
- if( rdec.get_code() != 0 && !error && verbosity >= 1 )
+ if( error ) return false;
+ if( verbosity >= 2 )
+ {
+ if( verbosity >= 4 ) show_header( dictionary_size );
+ if( data_size == 0 || member_size == 0 )
+ std::fputs( "no data compressed. ", stderr );
+ else
+ std::fprintf( stderr, "%6.3f:1, %5.2f%% ratio, %5.2f%% saved. ",
+ (double)data_size / member_size,
+ ( 100.0 * member_size ) / data_size,
+ 100.0 - ( ( 100.0 * member_size ) / data_size ) );
+ if( verbosity >= 4 ) std::fprintf( stderr, "CRC %08X, ", td_crc );
+ if( verbosity >= 3 )
+ std::fprintf( stderr, "decompressed %9llu, compressed %8llu. ",
+ data_size, member_size );
+ }
+ if( rdec.get_code() != 0 && verbosity >= 1 )
{ // corruption in the last 4 bytes of the EOS marker
pp();
std::fprintf( stderr, "Range decoder final code is %08X\n", rdec.get_code() );
}
- return !error;
+ return true;
}
@@ -284,7 +278,7 @@ int LZ_decoder::decode_member( const Pretty_print & pp )
{
rdec.load(); continue;
}
- if( pp.verbosity() >= 0 )
+ if( verbosity >= 0 )
{
pp();
std::fprintf( stderr, "Unsupported marker code '%d'\n", len );