summaryrefslogtreecommitdiffstats
path: root/lzip.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--lzip.h69
1 files changed, 47 insertions, 22 deletions
diff --git a/lzip.h b/lzip.h
index ed57aa2..1861443 100644
--- a/lzip.h
+++ b/lzip.h
@@ -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
@@ -100,20 +100,22 @@ struct Len_model
};
-class Pretty_print
+// defined in main.cc
+extern int verbosity;
+
+class Pretty_print // requires global var 'int verbosity'
{
std::string name_;
+ std::string padded_name;
const char * const stdin_name;
unsigned longest_name;
- const int verbosity_;
mutable bool first_post;
public:
- Pretty_print( const std::vector< std::string > & filenames, const int v )
- : stdin_name( "(stdin)" ), longest_name( 0 ), verbosity_( v ),
- first_post( false )
+ Pretty_print( const std::vector< std::string > & filenames )
+ : stdin_name( "(stdin)" ), longest_name( 0 ), first_post( false )
{
- if( verbosity_ <= 0 ) return;
+ if( verbosity <= 0 ) return;
const unsigned stdin_name_len = std::strlen( stdin_name );
for( unsigned i = 0; i < filenames.size(); ++i )
{
@@ -124,8 +126,8 @@ public:
if( longest_name == 0 ) longest_name = stdin_name_len;
}
- Pretty_print( const std::string & filename, const int v )
- : stdin_name( "(stdin)" ), verbosity_( v ), first_post( false )
+ Pretty_print( const std::string & filename )
+ : stdin_name( "(stdin)" ), first_post( false )
{
const unsigned stdin_name_len = std::strlen( stdin_name );
longest_name = ( filename == "-" ) ? stdin_name_len : filename.size();
@@ -137,12 +139,14 @@ public:
{
if( filename.size() && filename != "-" ) name_ = filename;
else name_ = stdin_name;
+ padded_name = " "; padded_name += name_; padded_name += ": ";
+ if( name_.size() < longest_name )
+ padded_name.append( longest_name - name_.size(), ' ' );
first_post = true;
}
void reset() const { if( name_.size() ) first_post = true; }
const char * name() const { return name_.c_str(); }
- int verbosity() const { return verbosity_; }
void operator()( const char * const msg = 0, FILE * const f = stderr ) const;
};
@@ -206,11 +210,19 @@ struct File_header
void set_magic() { std::memcpy( data, magic_string, 4 ); data[4] = 1; }
bool verify_magic() const
{ return ( std::memcmp( data, magic_string, 4 ) == 0 ); }
- bool verify_prefix( const int size ) const // detect truncated header
+
+ bool verify_prefix( const int sz ) const // detect (truncated) header
{
- for( int i = 0; i < size && i < 4; ++i )
+ for( int i = 0; i < sz && i < 4; ++i )
if( data[i] != magic_string[i] ) return false;
- return ( size > 0 );
+ return ( sz > 0 );
+ }
+ bool verify_corrupt() const // detect corrupt header
+ {
+ int matches = 0;
+ for( int i = 0; i < 4; ++i )
+ if( data[i] == magic_string[i] ) ++matches;
+ return ( matches > 1 && matches < 4 );
}
uint8_t version() const { return data[4]; }
@@ -312,6 +324,7 @@ inline unsigned long long positive_diff( const unsigned long long x,
const char * const bad_magic_msg = "Bad magic number (file not in lzip format).";
const char * const bad_dict_msg = "Invalid dictionary size in member header.";
+const char * const corrupt_mm_msg = "Corrupt header in multimember file.";
const char * const trailing_msg = "Trailing data not allowed.";
// defined in alone_to_lz.cc
@@ -327,7 +340,7 @@ int seek_read( const int fd, uint8_t * const buf, const int size,
// defined in list.cc
int list_files( const std::vector< std::string > & filenames,
- const int verbosity, const bool ignore_trailing );
+ const bool ignore_trailing, const bool loose_trailing );
// defined in main.cc
extern std::string output_filename; // global vars for output file
@@ -335,9 +348,11 @@ extern int outfd;
struct stat;
const char * bad_version( const unsigned version );
const char * format_ds( const unsigned dictionary_size );
-void show_header( const unsigned dictionary_size, const int vlevel = 3 );
+void show_header( const unsigned dictionary_size );
int open_instream( const char * const name, struct stat * const in_statsp,
const bool no_ofile, const bool reg_only = false );
+int open_truncable_stream( const char * const name,
+ struct stat * const in_statsp );
bool open_outstream( const bool force, const bool from_stdin,
const bool rw = false, const bool skipping = true );
bool file_exists( const std::string & filename );
@@ -353,6 +368,11 @@ void show_error2( const char * const msg1, const char * const name,
const char * const msg2 );
void show_error4( const char * const msg1, const char * const name1,
const char * const name2, const char * const msg2 );
+class Range_decoder;
+void show_dprogress( const unsigned long long cfile_size = 0,
+ const unsigned long long partial_size = 0,
+ const Range_decoder * const d = 0,
+ const Pretty_print * const p = 0 );
// defined in merge.cc
bool copy_file( const int infd, const int outfd,
@@ -361,7 +381,7 @@ bool test_member_from_file( const int infd, const unsigned long long msize,
long long * const failure_posp = 0 );
int merge_files( const std::vector< std::string > & filenames,
const std::string & default_output_filename,
- const int verbosity, const bool force );
+ const bool force );
// defined in range_dec.cc
bool safe_seek( const int fd, const long long pos );
@@ -369,15 +389,20 @@ bool safe_seek( const int fd, const long long pos );
// defined in repair.cc
int repair_file( const std::string & input_filename,
const std::string & default_output_filename,
- const int verbosity, const bool force );
+ const bool force );
int debug_repair( const std::string & input_filename,
- const Bad_byte & bad_byte, const int verbosity );
+ const Bad_byte & bad_byte );
int debug_decompress( const std::string & input_filename,
- const Bad_byte & bad_byte, const int verbosity,
- const bool show_packets );
+ const Bad_byte & bad_byte, const bool show_packets );
// defined in split.cc
bool verify_header( const File_header & header, const Pretty_print & pp );
int split_file( const std::string & input_filename,
- const std::string & default_output_filename,
- const int verbosity, const bool force );
+ const std::string & default_output_filename, const bool force );
+
+// defined in trailing_data.cc
+int dump_tdata( const std::vector< std::string > & filenames,
+ const std::string & default_output_filename, const bool force,
+ const bool strip, const bool loose_trailing );
+int remove_tdata( const std::vector< std::string > & filenames,
+ const bool loose_trailing );