diff options
Diffstat (limited to '')
-rw-r--r-- | lzip.h | 61 |
1 files changed, 35 insertions, 26 deletions
@@ -1,5 +1,5 @@ /* Plzip - Parallel compressor compatible with lzip - 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 @@ -27,16 +27,19 @@ enum { min_member_size = 36 }; -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; mutable bool first_post; public: - Pretty_print( const std::vector< std::string > & filenames, - const int verbosity ) + Pretty_print( const std::vector< std::string > & filenames ) : stdin_name( "(stdin)" ), longest_name( 0 ), first_post( false ) { if( verbosity <= 0 ) return; @@ -54,6 +57,9 @@ 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; } @@ -88,11 +94,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]; } @@ -165,6 +179,7 @@ struct File_trailer 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 compress.cc @@ -179,7 +194,8 @@ void xunlock( pthread_mutex_t * const mutex ); void xwait( pthread_cond_t * const cond, pthread_mutex_t * const mutex ); void xsignal( pthread_cond_t * const cond ); void xbroadcast( pthread_cond_t * const cond ); -int compress( const int data_size, const int dictionary_size, +int compress( const unsigned long long cfile_size, + const int data_size, const int dictionary_size, const int match_len_limit, const int num_workers, const int infd, const int outfd, const Pretty_print & pp, const int debug_level ); @@ -193,25 +209,26 @@ int dec_stdout( const int num_workers, const int infd, const int outfd, const File_index & file_index ); // defined in dec_stream.cc -int dec_stream( const int num_workers, const int infd, const int outfd, +int dec_stream( const unsigned long long cfile_size, + const int num_workers, const int infd, const int outfd, const Pretty_print & pp, const int debug_level, - const bool ignore_trailing ); + const bool ignore_trailing, const bool loose_trailing ); // defined in decompress.cc int preadblock( const int fd, uint8_t * const buf, const int size, const long long pos ); int decompress_read_error( struct LZ_Decoder * const decoder, const Pretty_print & pp, const int worker_id ); -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 ); // defined in list.cc int list_files( const std::vector< std::string > & filenames, - const bool ignore_trailing ); + const bool ignore_trailing, const bool loose_trailing ); // defined in main.cc -extern int verbosity; struct stat; const char * bad_version( const unsigned version ); const char * format_ds( const unsigned dictionary_size ); @@ -224,9 +241,9 @@ void show_error( const char * const msg, const int errcode = 0, void show_file_error( const char * const filename, const char * const msg, const int errcode = 0 ); void internal_error( const char * const msg ); -void show_progress( const int packet_size, - const Pretty_print * const p = 0, - const unsigned long long cfile_size = 0 ); +void show_progress( const unsigned long long packet_size, + const unsigned long long cfile_size = 0, + const Pretty_print * const p = 0 ); class Slot_tally @@ -262,12 +279,4 @@ public: if( ++num_free == 1 ) xsignal( &slot_av ); // num_free was 0 xunlock( &mutex ); } - - void leave_slots( const int slots ) // return slots to the tally - { - xlock( &mutex ); - num_free += slots; - if( num_free == slots ) xsignal( &slot_av ); // num_free was 0 - xunlock( &mutex ); - } }; |