summaryrefslogtreecommitdiffstats
path: root/decoder.c
diff options
context:
space:
mode:
authorDaniel Baumann <mail@daniel-baumann.ch>2015-11-07 13:49:18 +0000
committerDaniel Baumann <mail@daniel-baumann.ch>2015-11-07 13:49:18 +0000
commit3464658cfb26bfbc85ab6fa50185d503dcec4688 (patch)
tree0813dbfdfd5cb882816f532673abe404f32e2c5b /decoder.c
parentAdding upstream version 1.4. (diff)
downloadlzlib-3464658cfb26bfbc85ab6fa50185d503dcec4688.tar.xz
lzlib-3464658cfb26bfbc85ab6fa50185d503dcec4688.zip
Adding upstream version 1.5~rc1.upstream/1.5_rc1
Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch>
Diffstat (limited to 'decoder.c')
-rw-r--r--decoder.c57
1 files changed, 27 insertions, 30 deletions
diff --git a/decoder.c b/decoder.c
index 7f46009..1b7e071 100644
--- a/decoder.c
+++ b/decoder.c
@@ -1,4 +1,4 @@
-/* Lzlib - A compression library for lzip files
+/* Lzlib - Compression library for lzip files
Copyright (C) 2009, 2010, 2011, 2012, 2013 Antonio Diaz Diaz.
This library is free software: you can redistribute it and/or modify
@@ -28,16 +28,13 @@
static bool LZd_verify_trailer( struct LZ_decoder * const decoder )
{
File_trailer trailer;
- const int trailer_size = Ft_versioned_size( decoder->member_version );
const unsigned long long member_size =
- decoder->rdec->member_position + trailer_size;
+ decoder->rdec->member_position + Ft_size;
- int size = Rd_read_data( decoder->rdec, trailer, trailer_size );
- if( size < trailer_size )
+ int size = Rd_read_data( decoder->rdec, trailer, Ft_size );
+ if( size < Ft_size )
return false;
- if( decoder->member_version == 0 ) Ft_set_member_size( trailer, member_size );
-
return ( decoder->rdec->code == 0 &&
Ft_get_data_crc( trailer ) == LZd_crc( decoder ) &&
Ft_get_data_size( trailer ) == LZd_data_position( decoder ) &&
@@ -49,38 +46,39 @@ static bool LZd_verify_trailer( struct LZ_decoder * const decoder )
3 = trailer error, 4 = unknown marker found. */
static int LZd_decode_member( struct LZ_decoder * const decoder )
{
+ struct Range_decoder * const rdec = decoder->rdec;
State * const state = &decoder->state;
+
if( decoder->member_finished ) return 0;
- if( !Rd_try_reload( decoder->rdec, false ) ) return 0;
+ if( !Rd_try_reload( rdec, false ) ) return 0;
if( decoder->verify_trailer_pending )
{
- if( Rd_available_bytes( decoder->rdec ) < Ft_versioned_size( decoder->member_version ) &&
- !decoder->rdec->at_stream_end )
+ if( Rd_available_bytes( rdec ) < Ft_size && !rdec->at_stream_end )
return 0;
decoder->verify_trailer_pending = false;
decoder->member_finished = true;
if( LZd_verify_trailer( decoder ) ) return 0; else return 3;
}
- while( !Rd_finished( decoder->rdec ) )
+ while( !Rd_finished( rdec ) )
{
const int pos_state = LZd_data_position( decoder ) & pos_state_mask;
- if( !Rd_enough_available_bytes( decoder->rdec ) ||
+ if( !Rd_enough_available_bytes( rdec ) ||
!LZd_enough_free_bytes( decoder ) )
return 0;
- if( Rd_decode_bit( decoder->rdec, &decoder->bm_match[*state][pos_state] ) == 0 ) /* 1st bit */
+ if( Rd_decode_bit( rdec, &decoder->bm_match[*state][pos_state] ) == 0 ) /* 1st bit */
{
const uint8_t prev_byte = LZd_get_prev_byte( decoder );
if( St_is_char( *state ) )
{
*state -= ( *state < 4 ) ? *state : 3;
- LZd_put_byte( decoder, Rd_decode_tree( decoder->rdec,
+ LZd_put_byte( decoder, Rd_decode_tree( rdec,
decoder->bm_literal[get_lit_state(prev_byte)], 8 ) );
}
else
{
*state -= ( *state < 10 ) ? 3 : 6;
- LZd_put_byte( decoder, Rd_decode_matched( decoder->rdec,
+ LZd_put_byte( decoder, Rd_decode_matched( rdec,
decoder->bm_literal[get_lit_state(prev_byte)],
LZd_get_byte( decoder, decoder->rep0 ) ) );
}
@@ -88,22 +86,22 @@ static int LZd_decode_member( struct LZ_decoder * const decoder )
else
{
int len;
- if( Rd_decode_bit( decoder->rdec, &decoder->bm_rep[*state] ) == 1 ) /* 2nd bit */
+ if( Rd_decode_bit( rdec, &decoder->bm_rep[*state] ) == 1 ) /* 2nd bit */
{
- if( Rd_decode_bit( decoder->rdec, &decoder->bm_rep0[*state] ) == 0 ) /* 3rd bit */
+ if( Rd_decode_bit( rdec, &decoder->bm_rep0[*state] ) == 0 ) /* 3rd bit */
{
- if( Rd_decode_bit( decoder->rdec, &decoder->bm_len[*state][pos_state] ) == 0 ) /* 4th bit */
+ if( Rd_decode_bit( rdec, &decoder->bm_len[*state][pos_state] ) == 0 ) /* 4th bit */
{ *state = St_set_short_rep( *state );
LZd_put_byte( decoder, LZd_get_byte( decoder, decoder->rep0 ) ); continue; }
}
else
{
unsigned distance;
- if( Rd_decode_bit( decoder->rdec, &decoder->bm_rep1[*state] ) == 0 ) /* 4th bit */
+ if( Rd_decode_bit( rdec, &decoder->bm_rep1[*state] ) == 0 ) /* 4th bit */
distance = decoder->rep1;
else
{
- if( Rd_decode_bit( decoder->rdec, &decoder->bm_rep2[*state] ) == 0 ) /* 5th bit */
+ if( Rd_decode_bit( rdec, &decoder->bm_rep2[*state] ) == 0 ) /* 5th bit */
distance = decoder->rep2;
else
{ distance = decoder->rep3; decoder->rep3 = decoder->rep2; }
@@ -113,42 +111,41 @@ static int LZd_decode_member( struct LZ_decoder * const decoder )
decoder->rep0 = distance;
}
*state = St_set_rep( *state );
- len = min_match_len + Rd_decode_len( decoder->rdec, &decoder->rep_len_model, pos_state );
+ len = min_match_len + Rd_decode_len( rdec, &decoder->rep_len_model, pos_state );
}
else
{
int dis_slot;
const unsigned rep0_saved = decoder->rep0;
- len = min_match_len + Rd_decode_len( decoder->rdec, &decoder->match_len_model, pos_state );
- dis_slot = Rd_decode_tree6( decoder->rdec, decoder->bm_dis_slot[get_dis_state(len)] );
+ len = min_match_len + Rd_decode_len( rdec, &decoder->match_len_model, pos_state );
+ dis_slot = Rd_decode_tree6( rdec, decoder->bm_dis_slot[get_dis_state(len)] );
if( dis_slot < start_dis_model ) decoder->rep0 = dis_slot;
else
{
const int direct_bits = ( dis_slot >> 1 ) - 1;
decoder->rep0 = ( 2 | ( dis_slot & 1 ) ) << direct_bits;
if( dis_slot < end_dis_model )
- decoder->rep0 += Rd_decode_tree_reversed( decoder->rdec,
+ decoder->rep0 += Rd_decode_tree_reversed( rdec,
decoder->bm_dis + decoder->rep0 - dis_slot - 1,
direct_bits );
else
{
- decoder->rep0 += Rd_decode( decoder->rdec, direct_bits - dis_align_bits ) << dis_align_bits;
- decoder->rep0 += Rd_decode_tree_reversed4( decoder->rdec, decoder->bm_align );
+ decoder->rep0 += Rd_decode( rdec, direct_bits - dis_align_bits ) << dis_align_bits;
+ decoder->rep0 += Rd_decode_tree_reversed4( rdec, decoder->bm_align );
if( decoder->rep0 == 0xFFFFFFFFU ) /* Marker found */
{
decoder->rep0 = rep0_saved;
- Rd_normalize( decoder->rdec );
+ Rd_normalize( rdec );
if( len == min_match_len ) /* End Of Stream marker */
{
- if( Rd_available_bytes( decoder->rdec ) < Ft_versioned_size( decoder->member_version ) &&
- !decoder->rdec->at_stream_end )
+ if( Rd_available_bytes( rdec ) < Ft_size && !rdec->at_stream_end )
{ decoder->verify_trailer_pending = true; return 0; }
decoder->member_finished = true;
if( LZd_verify_trailer( decoder ) ) return 0; else return 3;
}
if( len == min_match_len + 1 ) /* Sync Flush marker */
{
- if( Rd_try_reload( decoder->rdec, true ) ) continue;
+ if( Rd_try_reload( rdec, true ) ) continue;
else return 0;
}
return 4;