summaryrefslogtreecommitdiffstats
path: root/range_dec.cc
diff options
context:
space:
mode:
Diffstat (limited to 'range_dec.cc')
-rw-r--r--range_dec.cc92
1 files changed, 14 insertions, 78 deletions
diff --git a/range_dec.cc b/range_dec.cc
index eeb542a..e105aaa 100644
--- a/range_dec.cc
+++ b/range_dec.cc
@@ -1,5 +1,5 @@
/* Lziprecover - Data recovery tool for the lzip format
- Copyright (C) 2009-2016 Antonio Diaz Diaz.
+ Copyright (C) 2009-2017 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
@@ -71,62 +71,9 @@ int decompress_member( const int infd, const Pretty_print & pp,
}
-int list_file( const char * const input_filename, const Pretty_print & pp )
- {
- struct stat in_stats; // not used
- const int infd = open_instream( input_filename, &in_stats, true, true );
- if( infd < 0 ) return 1;
-
- const File_index file_index( infd );
- close( infd );
- if( file_index.retval() != 0 )
- { pp( file_index.error().c_str() ); return file_index.retval(); }
-
- if( pp.verbosity() >= 0 )
- {
- const unsigned long long data_size = file_index.data_end();
- const unsigned long long file_size = file_index.file_end();
- unsigned dictionary_size = 0;
- for( long i = 0; i < file_index.members(); ++i )
- dictionary_size =
- std::max( dictionary_size, file_index.dictionary_size( i ) );
- pp( 0, stdout );
- show_header( dictionary_size, 1 );
- if( data_size > 0 && file_size > 0 )
- std::printf( "%6.3f:1, %6.3f bits/byte, %5.2f%% saved. ",
- (double)data_size / file_size,
- ( 8.0 * file_size ) / data_size,
- 100.0 * ( 1.0 - ( (double)file_size / data_size ) ) );
- std::printf( "decompressed size %9llu, compressed size %8llu.\n",
- data_size, file_size );
-
- if( pp.verbosity() >= 1 && file_index.members() > 1 )
- {
- std::printf( " Total members in file = %ld\n", file_index.members() );
- if( pp.verbosity() >= 2 )
- for( long i = 0; i < file_index.members(); ++i )
- {
- const Block & db = file_index.dblock( i );
- const Block & mb = file_index.mblock( i );
- std::printf( " Member %3ld data pos %9llu data size %7llu "
- "member pos %9llu member size %7llu.\n", i + 1,
- db.pos(), db.size(), mb.pos(), mb.size() );
- }
- }
- const long long trailing_size = file_index.file_size() - file_index.file_end();
- if( pp.verbosity() >= 1 && trailing_size > 0 )
- std::printf( " %lld bytes of trailing data at end of file.\n",
- trailing_size );
- }
- return 0;
- }
-
-} // end namespace
-
-
const char * format_num( unsigned long long num,
- unsigned long long limit,
- const int set_prefix )
+ unsigned long long limit = -1ULL,
+ const int set_prefix = 0 )
{
const char * const si_prefix[8] =
{ "k", "M", "G", "T", "P", "E", "Z", "Y" };
@@ -150,6 +97,8 @@ const char * format_num( unsigned long long num,
return buf;
}
+} // end namespace
+
bool safe_seek( const int fd, const long long pos )
{
@@ -158,37 +107,24 @@ bool safe_seek( const int fd, const long long pos )
}
-int list_files( const std::vector< std::string > & filenames,
- const int verbosity )
- {
- Pretty_print pp( filenames, verbosity );
- int retval = 0;
- for( unsigned i = 0; i < filenames.size(); ++i )
- {
- pp.set_name( filenames[i] );
- const int tmp = list_file( filenames[i].c_str(), pp );
- if( tmp > retval ) retval = tmp;
- }
- return retval;
- }
-
-
int range_decompress( const std::string & input_filename,
const std::string & default_output_filename,
Block range, const int verbosity, const bool force,
- const bool ignore, const bool to_stdout )
+ const bool ignore_errors, const bool ignore_trailing,
+ const bool to_stdout )
{
struct stat in_stats;
const int infd = open_instream( input_filename.c_str(), &in_stats, true, true );
if( infd < 0 ) return 1;
Pretty_print pp( input_filename, verbosity );
- const File_index file_index( infd );
+ const File_index file_index( infd, ignore_errors, ignore_trailing );
if( file_index.retval() != 0 )
- { pp( file_index.error().c_str() ); return file_index.retval(); }
+ { show_file_error( input_filename.c_str(), file_index.error().c_str() );
+ return file_index.retval(); }
- if( range.end() > file_index.data_end() )
- range.size( std::max( 0LL, file_index.data_end() - range.pos() ) );
+ if( range.end() > file_index.udata_size() )
+ range.size( std::max( 0LL, file_index.udata_size() - range.pos() ) );
if( range.size() <= 0 )
{ if( verbosity >= 0 ) pp( "Nothing to do." ); return 0; }
@@ -196,7 +132,7 @@ int range_decompress( const std::string & input_filename,
{
if( verbosity >= 2 )
std::fprintf( stderr, "Decompressed file size = %sB\n",
- format_num( file_index.data_end() ) );
+ format_num( file_index.udata_size() ) );
std::fprintf( stderr, "Decompressing range %sB to %sB (%sBytes)\n",
format_num( range.pos() ),
format_num( range.pos() + range.size() ),
@@ -225,7 +161,7 @@ int range_decompress( const std::string & input_filename,
const long long mpos = file_index.mblock( i ).pos();
if( !safe_seek( infd, mpos ) ) { retval = 1; break; }
const int tmp = decompress_member( infd, pp, mpos, outskip, outend );
- if( tmp && ( tmp != 2 || !ignore ) )
+ if( tmp && ( tmp != 2 || !ignore_errors ) )
cleanup_and_fail( tmp );
if( tmp > retval ) retval = tmp;
pp.reset();