summaryrefslogtreecommitdiffstats
path: root/mtester.h
diff options
context:
space:
mode:
authorDaniel Baumann <mail@daniel-baumann.ch>2016-05-20 06:54:36 +0000
committerDaniel Baumann <mail@daniel-baumann.ch>2016-05-20 06:54:36 +0000
commite6759ba4e68c66f0927bb89bfb87215eb29016ae (patch)
treef35bf07aaaf1ad2d1bfc0eced16ff820f1193cd5 /mtester.h
parentAdding upstream version 1.18~pre2. (diff)
downloadlziprecover-e6759ba4e68c66f0927bb89bfb87215eb29016ae.tar.xz
lziprecover-e6759ba4e68c66f0927bb89bfb87215eb29016ae.zip
Adding upstream version 1.18.upstream/1.18
Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch>
Diffstat (limited to 'mtester.h')
-rw-r--r--mtester.h32
1 files changed, 21 insertions, 11 deletions
diff --git a/mtester.h b/mtester.h
index 71df64d..53f0abe 100644
--- a/mtester.h
+++ b/mtester.h
@@ -1,5 +1,5 @@
/* Lziprecover - Data recovery tool for the lzip format
- Copyright (C) 2009-2015 Antonio Diaz Diaz.
+ Copyright (C) 2009-2016 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
@@ -37,27 +37,29 @@ public:
at_stream_end( false )
{}
- bool code_is_zero() const { return ( code == 0 ); }
bool finished() { return pos >= buffer_size; }
- long member_position() const { return pos; }
+ unsigned long member_position() const { return pos; }
uint8_t get_byte()
{
- if( finished() ) return 0xAA; // make code != 0
+ // 0xFF avoids decoder error if member is truncated at EOS marker
+ if( finished() ) return 0xFF;
return buffer[pos++];
}
const File_trailer * get_trailer()
{
if( buffer_size - pos < File_trailer::size ) return 0;
- const File_trailer * const p = (File_trailer *)(buffer + pos);
+ const File_trailer * const p = (File_trailer *)( buffer + pos );
pos += File_trailer::size;
return p;
}
void load()
{
+ code = 0;
for( int i = 0; i < 5; ++i ) code = (code << 8) | get_byte();
+ range = 0xFFFFFFFFU;
code &= range; // make sure that first byte is discarded
}
@@ -198,11 +200,14 @@ class LZ_mtester
unsigned pos; // current pos in buffer
unsigned stream_pos; // first byte not yet written to file
uint32_t crc_;
+ const int outfd; // output file descriptor
unsigned rep0; // rep[0-3] latest four distances
unsigned rep1; // used for efficient coding of
unsigned rep2; // repeated distances
unsigned rep3;
State state;
+ unsigned max_rep0; // maximum distance found
+ bool pos_wrapped;
Bit_model bm_literal[1<<literal_context_bits][0x300];
Bit_model bm_match[State::states][pos_states];
@@ -267,7 +272,7 @@ class LZ_mtester
public:
LZ_mtester( const uint8_t * const ibuf, const long ibuf_size,
- const int dict_size )
+ const unsigned dict_size, const int ofd = -1 )
:
partial_data_pos( 0 ),
rdec( ibuf, ibuf_size ),
@@ -276,10 +281,13 @@ public:
pos( 0 ),
stream_pos( 0 ),
crc_( 0xFFFFFFFFU ),
+ outfd( ofd ),
rep0( 0 ),
rep1( 0 ),
rep2( 0 ),
- rep3( 0 )
+ rep3( 0 ),
+ max_rep0( 0 ),
+ pos_wrapped( false )
{ buffer[dictionary_size-1] = 0; } // prev_byte of first byte
~LZ_mtester() { delete[] buffer; }
@@ -287,12 +295,13 @@ public:
unsigned crc() const { return crc_ ^ 0xFFFFFFFFU; }
unsigned long long data_position() const { return partial_data_pos + pos; }
bool finished() { return rdec.finished(); }
- long member_position() const { return rdec.member_position(); }
+ unsigned long member_position() const { return rdec.member_position(); }
+ unsigned max_distance() const { return max_rep0 + 1; }
void duplicate_buffer();
- int test_member( const long pos_limit = LONG_MAX );
+ int test_member( const unsigned long pos_limit = LONG_MAX ); // sets max_rep0
int debug_decode_member( const long long dpos, const long long mpos,
- const bool show_packets );
+ const bool show_packets ); // sets max_rep0
};
@@ -300,5 +309,6 @@ uint8_t * read_member( const int infd, const long long mpos,
const long long msize );
const LZ_mtester * prepare_master( const uint8_t * const buffer,
const long buffer_size,
- const long pos_limit );
+ const unsigned long pos_limit,
+ const unsigned dictionary_size );
bool test_member_rest( const LZ_mtester & master, long * const failure_posp = 0 );