diff options
author | Daniel Baumann <mail@daniel-baumann.ch> | 2015-11-07 11:45:12 +0000 |
---|---|---|
committer | Daniel Baumann <mail@daniel-baumann.ch> | 2015-11-07 11:45:12 +0000 |
commit | 2085b1344e4c2b3c4a3d21d4bc10227679a55507 (patch) | |
tree | 86328decac9bdf54fb41b6af1bd15b23fff1edd7 /decoder.cc | |
parent | Adding debian version 1.15-2. (diff) | |
download | lziprecover-2085b1344e4c2b3c4a3d21d4bc10227679a55507.tar.xz lziprecover-2085b1344e4c2b3c4a3d21d4bc10227679a55507.zip |
Merging upstream version 1.16~pre1.
Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch>
Diffstat (limited to '')
-rw-r--r-- | decoder.cc | 42 |
1 files changed, 20 insertions, 22 deletions
@@ -1,5 +1,5 @@ /* Lziprecover - Data recovery tool for lzip files - Copyright (C) 2009, 2010, 2011, 2012, 2013 Antonio Diaz Diaz. + Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014 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 @@ -46,14 +46,14 @@ void Pretty_print::operator()( const char * const msg, FILE * const f ) const std::fprintf( f, " " ); if( !msg ) std::fflush( f ); } - if( msg ) std::fprintf( f, "%s.\n", msg ); + if( msg ) std::fprintf( f, "%s\n", msg ); } } -// Returns the number of bytes really read. -// If (returned value < size) and (errno == 0), means EOF was reached. -// +/* Returns the number of bytes really read. + If (returned value < size) and (errno == 0), means EOF was reached. +*/ int readblock( const int fd, uint8_t * const buf, const int size ) { int rest = size; @@ -63,16 +63,16 @@ int readblock( const int fd, uint8_t * const buf, const int size ) const int n = read( fd, buf + size - rest, rest ); if( n > 0 ) rest -= n; else if( n == 0 ) break; // EOF - else if( errno != EINTR && errno != EAGAIN ) break; + else if( errno != EINTR ) break; errno = 0; } return size - rest; } -// Returns the number of bytes really written. -// If (returned value < size), it is always an error. -// +/* Returns the number of bytes really written. + If (returned value < size), it is always an error. +*/ int writeblock( const int fd, const uint8_t * const buf, const int size ) { int rest = size; @@ -81,7 +81,7 @@ int writeblock( const int fd, const uint8_t * const buf, const int size ) { const int n = write( fd, buf + size - rest, rest ); if( n > 0 ) rest -= n; - else if( n < 0 && errno != EINTR && errno != EAGAIN ) break; + else if( n < 0 && errno != EINTR ) break; errno = 0; } return size - rest; @@ -127,8 +127,7 @@ bool LZ_decoder::verify_trailer( const Pretty_print & pp ) const { File_trailer trailer; const int trailer_size = File_trailer::size; - const unsigned long long member_size = - rdec.member_position() + trailer_size; + const unsigned long long member_size = rdec.member_position() + trailer_size; bool error = false; int size = rdec.read_data( trailer.data, trailer_size ); @@ -147,7 +146,7 @@ bool LZ_decoder::verify_trailer( const Pretty_print & pp ) const if( !rdec.code_is_zero() ) { error = true; - pp( "Range decoder final code is not zero" ); + pp( "Range decoder final code is not zero." ); } if( trailer.data_crc() != crc() ) { @@ -191,8 +190,8 @@ bool LZ_decoder::verify_trailer( const Pretty_print & pp ) const } -// Return value: 0 = OK, 1 = decoder error, 2 = unexpected EOF, -// 3 = trailer error, 4 = unknown marker found. +/* Return value: 0 = OK, 1 = decoder error, 2 = unexpected EOF, + 3 = trailer error, 4 = unknown marker found. */ int LZ_decoder::decode_member( const Pretty_print & pp ) { Bit_model bm_literal[1<<literal_context_bits][0x300]; @@ -202,7 +201,7 @@ int LZ_decoder::decode_member( const Pretty_print & pp ) Bit_model bm_rep1[State::states]; Bit_model bm_rep2[State::states]; Bit_model bm_len[State::states][pos_states]; - Bit_model bm_dis_slot[dis_states][1<<dis_slot_bits]; + Bit_model bm_dis_slot[len_states][1<<dis_slot_bits]; Bit_model bm_dis[modeled_distances-end_dis_model]; Bit_model bm_align[dis_align_size]; Len_model match_len_model; @@ -223,7 +222,7 @@ int LZ_decoder::decode_member( const Pretty_print & pp ) if( state.is_char() ) { state.set_char1(); - put_byte( rdec.decode_tree( bm_literal[get_lit_state(prev_byte)], 8 ) ); + put_byte( rdec.decode_tree8( bm_literal[get_lit_state(prev_byte)] ) ); } else { @@ -235,9 +234,9 @@ int LZ_decoder::decode_member( const Pretty_print & pp ) else { int len; - if( rdec.decode_bit( bm_rep[state()] ) == 1 ) // 2nd bit + if( rdec.decode_bit( bm_rep[state()] ) != 0 ) // 2nd bit { - if( rdec.decode_bit( bm_rep0[state()] ) == 1 ) // 3rd bit + if( rdec.decode_bit( bm_rep0[state()] ) != 0 ) // 3rd bit { unsigned distance; if( rdec.decode_bit( bm_rep1[state()] ) == 0 ) // 4th bit @@ -265,7 +264,7 @@ int LZ_decoder::decode_member( const Pretty_print & pp ) { const unsigned rep0_saved = rep0; len = min_match_len + rdec.decode_len( match_len_model, pos_state ); - const int dis_slot = rdec.decode_tree6( bm_dis_slot[get_dis_state(len)] ); + const int dis_slot = rdec.decode_tree6( bm_dis_slot[get_len_state(len)] ); if( dis_slot < start_dis_model ) rep0 = dis_slot; else { @@ -302,8 +301,7 @@ int LZ_decoder::decode_member( const Pretty_print & pp ) } rep3 = rep2; rep2 = rep1; rep1 = rep0_saved; state.set_match(); - if( rep0 >= (unsigned)dictionary_size || - ( rep0 >= (unsigned)pos && !partial_data_pos ) ) + if( rep0 >= dictionary_size || rep0 >= data_position() ) { flush_data(); return 1; } } copy_block( rep0, len ); |