diff options
Diffstat (limited to '')
-rw-r--r-- | lzip.h | 69 |
1 files changed, 38 insertions, 31 deletions
@@ -1,5 +1,5 @@ /* Plzip - Massively parallel implementation of lzip - Copyright (C) 2009-2022 Antonio Diaz Diaz. + Copyright (C) 2009-2024 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 @@ -68,8 +68,8 @@ public: inline bool isvalid_ds( const unsigned dictionary_size ) - { return ( dictionary_size >= min_dictionary_size && - dictionary_size <= max_dictionary_size ); } + { return dictionary_size >= min_dictionary_size && + dictionary_size <= max_dictionary_size; } inline int real_bits( unsigned value ) @@ -84,35 +84,35 @@ const uint8_t lzip_magic[4] = { 0x4C, 0x5A, 0x49, 0x50 }; // "LZIP" struct Lzip_header { - uint8_t data[6]; // 0-3 magic bytes + enum { size = 6 }; + uint8_t data[size]; // 0-3 magic bytes // 4 version // 5 coded dictionary size - enum { size = 6 }; void set_magic() { std::memcpy( data, lzip_magic, 4 ); data[4] = 1; } - bool verify_magic() const - { return ( std::memcmp( data, lzip_magic, 4 ) == 0 ); } + bool check_magic() const { return std::memcmp( data, lzip_magic, 4 ) == 0; } - bool verify_prefix( const int sz ) const // detect (truncated) header + bool check_prefix( const int sz ) const // detect (truncated) header { for( int i = 0; i < sz && i < 4; ++i ) if( data[i] != lzip_magic[i] ) return false; - return ( sz > 0 ); + return sz > 0; } - bool verify_corrupt() const // detect corrupt header + + bool check_corrupt() const // detect corrupt header { int matches = 0; for( int i = 0; i < 4; ++i ) if( data[i] == lzip_magic[i] ) ++matches; - return ( matches > 1 && matches < 4 ); + return matches > 1 && matches < 4; } uint8_t version() const { return data[4]; } - bool verify_version() const { return ( data[4] == 1 ); } + bool check_version() const { return data[4] == 1; } unsigned dictionary_size() const { - unsigned sz = ( 1 << ( data[5] & 0x1F ) ); + unsigned sz = 1 << ( data[5] & 0x1F ); if( sz > min_dictionary_size ) sz -= ( sz / 16 ) * ( ( data[5] >> 5 ) & 7 ); return sz; @@ -128,23 +128,23 @@ struct Lzip_header const unsigned fraction = base_size / 16; for( unsigned i = 7; i >= 1; --i ) if( base_size - ( i * fraction ) >= sz ) - { data[5] |= ( i << 5 ); break; } + { data[5] |= i << 5; break; } } return true; } - bool verify() const - { return verify_magic() && verify_version() && + bool check() const + { return check_magic() && check_version() && isvalid_ds( dictionary_size() ); } }; struct Lzip_trailer { - uint8_t data[20]; // 0-3 CRC32 of the uncompressed data + enum { size = 20 }; + uint8_t data[size]; // 0-3 CRC32 of the uncompressed data // 4-11 size of the uncompressed data // 12-19 member size including header and trailer - enum { size = 20 }; unsigned data_crc() const { @@ -176,7 +176,7 @@ struct Lzip_trailer void member_size( unsigned long long sz ) { for( int i = 12; i <= 19; ++i ) { data[i] = (uint8_t)sz; sz >>= 8; } } - bool verify_consistency() const // check internal consistency + bool check_consistency() const // check internal consistency { const unsigned crc = data_crc(); const unsigned long long dsize = data_size(); @@ -192,6 +192,15 @@ struct Lzip_trailer }; +struct Cl_options // command-line options + { + bool ignore_trailing; + bool loose_trailing; + + Cl_options() : ignore_trailing( true ), loose_trailing( false ) {} + }; + + inline void set_retval( int & retval, const int new_val ) { if( retval < new_val ) retval = new_val; } @@ -220,7 +229,7 @@ int compress( const unsigned long long cfile_size, const Pretty_print & pp, const int debug_level ); // defined in lzip_index.cc -class Lzip_index; +class Lzip_index; // forward declaration // defined in dec_stdout.cc int dec_stdout( const int num_workers, const int infd, const int outfd, @@ -228,11 +237,10 @@ int dec_stdout( const int num_workers, const int infd, const int outfd, const int out_slots, const Lzip_index & lzip_index ); // defined in dec_stream.cc -int dec_stream( const unsigned long long cfile_size, - 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 Cl_options & cl_opts, const Pretty_print & pp, const int debug_level, - const int in_slots, const int out_slots, - const bool ignore_trailing, const bool loose_trailing ); + const int in_slots, const int out_slots ); // defined in decompress.cc int preadblock( const int fd, uint8_t * const buf, const int size, @@ -245,15 +253,14 @@ void show_results( const unsigned long long in_size, const unsigned long long out_size, const unsigned dictionary_size, const bool testing ); 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 int in_slots, - const int out_slots, const bool ignore_trailing, - const bool loose_trailing, const bool infd_isreg, - const bool one_to_one ); + const int infd, const int outfd, const Cl_options & cl_opts, + const Pretty_print & pp, const int debug_level, + const int in_slots, const int out_slots, + const bool infd_isreg, const bool one_to_one ); // defined in list.cc int list_files( const std::vector< std::string > & filenames, - const bool ignore_trailing, const bool loose_trailing ); + const Cl_options & cl_opts ); // defined in main.cc struct stat; @@ -290,7 +297,7 @@ public: ~Slot_tally() { xdestroy_cond( &slot_av ); xdestroy_mutex( &mutex ); } - bool all_free() { return ( num_free == num_slots ); } + bool all_free() { return num_free == num_slots; } void get_slot() // wait for a free slot { |