diff options
Diffstat (limited to 'lzip.h')
-rw-r--r-- | lzip.h | 102 |
1 files changed, 50 insertions, 52 deletions
@@ -1,5 +1,5 @@ /* Lziprecover - Data recovery tool for lzipped files - Copyright (C) 2009, 2010, 2011 Antonio Diaz Diaz. + Copyright (C) 2009, 2010, 2011, 2012 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 @@ -21,32 +21,32 @@ class State public: enum { states = 12 }; - State() throw() : st( 0 ) {} - unsigned char operator()() const throw() { return st; } - bool is_char() const throw() { return st < 7; } + State() : st( 0 ) {} + unsigned char operator()() const { return st; } + bool is_char() const { return st < 7; } - void set_char() throw() + void set_char() { static const unsigned char next[states] = { 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 4, 5 }; st = next[st]; } - void set_match() throw() + void set_match() { static const unsigned char next[states] = { 7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10 }; st = next[st]; } - void set_rep() throw() + void set_rep() { static const unsigned char next[states] = { 8, 8, 8, 8, 8, 8, 8, 11, 11, 11, 11, 11 }; st = next[st]; } - void set_short_rep() throw() + void set_short_rep() { static const unsigned char next[states] = { 9, 9, 9, 9, 9, 9, 9, 11, 11, 11, 11, 11 }; @@ -87,7 +87,7 @@ enum { max_dis_states = 4 }; -inline int get_dis_state( int len ) throw() +inline int get_dis_state( int len ) { len -= min_match_len; if( len >= max_dis_states ) len = max_dis_states - 1; @@ -102,7 +102,7 @@ enum { bit_model_move_bits = 5, struct Bit_model { unsigned int probability; - Bit_model() throw() : probability( bit_model_total / 2 ) {} + Bit_model() : probability( bit_model_total / 2 ) {} }; @@ -145,10 +145,10 @@ public: first_post = true; } - void reset() const throw() { if( name_.size() ) first_post = true; } - const char * name() const throw() { return name_.c_str(); } - int verbosity() const throw() { return verbosity_; } - void operator()( const char * const msg = 0 ) const throw(); + 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 ) const; }; @@ -168,10 +168,10 @@ public: } } - uint32_t operator[]( const uint8_t byte ) const throw() { return data[byte]; } - void update( uint32_t & crc, const uint8_t byte ) const throw() + uint32_t operator[]( const uint8_t byte ) const { return data[byte]; } + void update( uint32_t & crc, const uint8_t byte ) const { crc = data[(crc^byte)&0xFF] ^ ( crc >> 8 ); } - void update( uint32_t & crc, const uint8_t * const buffer, const int size ) const throw() + void update( uint32_t & crc, const uint8_t * const buffer, const int size ) const { for( int i = 0; i < size; ++i ) crc = data[(crc^buffer[i])&0xFF] ^ ( crc >> 8 ); @@ -181,14 +181,15 @@ public: extern const CRC32 crc32; -inline int real_bits( const int value ) throw() +inline int real_bits( const unsigned int value ) { - int bits = 0; - for( int i = 1, mask = 1; mask > 0; ++i, mask <<= 1 ) - if( value & mask ) bits = i; + int bits = 0, i = 1; + unsigned int mask = 1; + for( ; mask > 0; ++i, mask <<= 1 ) if( value & mask ) bits = i; return bits; } + const uint8_t magic_string[4] = { 'L', 'Z', 'I', 'P' }; struct File_header @@ -198,16 +199,14 @@ struct File_header // 5 coded_dict_size enum { size = 6 }; - void set_magic() throw() - { std::memcpy( data, magic_string, 4 ); data[4] = 1; } - - bool verify_magic() const throw() + void set_magic() { std::memcpy( data, magic_string, 4 ); data[4] = 1; } + bool verify_magic() const { return ( std::memcmp( data, magic_string, 4 ) == 0 ); } - uint8_t version() const throw() { return data[4]; } - bool verify_version() const throw() { return ( data[4] <= 1 ); } + uint8_t version() const { return data[4]; } + bool verify_version() const { return ( data[4] <= 1 ); } - int dictionary_size() const throw() + int dictionary_size() const { int sz = ( 1 << ( data[5] & 0x1F ) ); if( sz > min_dictionary_size && sz <= max_dictionary_size ) @@ -215,7 +214,7 @@ struct File_header return sz; } - bool dictionary_size( const int sz ) throw() + bool dictionary_size( const int sz ) { if( sz >= min_dictionary_size && sz <= max_dictionary_size ) { @@ -244,36 +243,36 @@ struct File_trailer static int size( const int version = 1 ) { return ( ( version >= 1 ) ? 20 : 12 ); } - uint32_t data_crc() const throw() + uint32_t data_crc() const { uint32_t tmp = 0; for( int i = 3; i >= 0; --i ) { tmp <<= 8; tmp += data[i]; } return tmp; } - void data_crc( uint32_t crc ) throw() + void data_crc( uint32_t crc ) { for( int i = 0; i <= 3; ++i ) { data[i] = (uint8_t)crc; crc >>= 8; } } - long long data_size() const throw() + long long data_size() const { long long tmp = 0; for( int i = 11; i >= 4; --i ) { tmp <<= 8; tmp += data[i]; } return tmp; } - void data_size( long long sz ) throw() + void data_size( long long sz ) { for( int i = 4; i <= 11; ++i ) { data[i] = (uint8_t)sz; sz >>= 8; } } - long long member_size() const throw() + long long member_size() const { long long tmp = 0; for( int i = 19; i >= 12; --i ) { tmp <<= 8; tmp += data[i]; } return tmp; } - void member_size( long long sz ) throw() + void member_size( long long sz ) { for( int i = 12; i <= 19; ++i ) { data[i] = (uint8_t)sz; sz >>= 8; } } @@ -283,7 +282,7 @@ struct File_trailer struct Error { const char * const msg; - Error( const char * const s ) throw() : msg( s ) {} + explicit Error( const char * const s ) : msg( s ) {} }; @@ -303,41 +302,40 @@ class Block long long pos_, size_; // pos + size <= LLONG_MAX public: - Block( const long long p, const long long s ) throw() - : pos_( p ), size_( s ) {} + Block( const long long p, const long long s ) : pos_( p ), size_( s ) {} - long long pos() const throw() { return pos_; } - long long size() const throw() { return size_; } - long long end() const throw() { return pos_ + size_; } + long long pos() const { return pos_; } + long long size() const { return size_; } + long long end() const { return pos_ + size_; } - void pos( const long long p ) throw() { pos_ = p; } - void size( const long long s ) throw() { size_ = s; } + void pos( const long long p ) { pos_ = p; } + void size( const long long s ) { size_ = s; } - bool overlaps( const Block & b ) const throw() + bool overlaps( const Block & b ) const { return ( pos_ < b.end() && b.pos_ < end() ); } - void shift( Block & b ) throw() { ++size_; ++b.pos_; --b.size_; } + void shift( Block & b ) { ++size_; ++b.pos_; --b.size_; } }; // defined in decoder.cc -int readblock( const int fd, uint8_t * const buf, const int size ) throw(); -int writeblock( const int fd, const uint8_t * const buf, const int size ) throw(); +int readblock( const int fd, uint8_t * const buf, const int size ); +int writeblock( const int fd, const uint8_t * const buf, const int size ); // defined in main.cc extern int verbosity; const char * format_num( long long num, long long limit = LLONG_MAX, - const int set_prefix = 0 ) throw(); + const int set_prefix = 0 ); int open_instream( const std::string & name, struct stat * const in_statsp, - const bool to_stdout, const bool reg_only = false ) throw(); + const bool to_stdout, const bool reg_only = false ); int open_outstream_rw( const std::string & output_filename, - const bool force ) throw(); + const bool force ); void show_error( const char * const msg, const int errcode = 0, - const bool help = false ) throw(); + const bool help = false ); void internal_error( const char * const msg ); // defined in merge.cc void cleanup_and_fail( const std::string & output_filename, - const int outfd, const int retval ) throw(); + const int outfd, const int retval ); bool copy_file( const int infd, const int outfd, const long long size = LLONG_MAX ); bool try_decompress( const int fd, const long long file_size, |