summaryrefslogtreecommitdiffstats
path: root/decoder.c
diff options
context:
space:
mode:
Diffstat (limited to 'decoder.c')
-rw-r--r--decoder.c56
1 files changed, 22 insertions, 34 deletions
diff --git a/decoder.c b/decoder.c
index dc12b72..942ec60 100644
--- a/decoder.c
+++ b/decoder.c
@@ -1,5 +1,5 @@
/* Clzip - LZMA lossless data compressor
- Copyright (C) 2010-2015 Antonio Diaz Diaz.
+ Copyright (C) 2010-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
@@ -29,19 +29,17 @@
#include "decoder.h"
-CRC32 crc32;
-
-
void Pp_show_msg( struct Pretty_print * const pp, const char * const msg )
{
if( verbosity >= 0 )
{
if( pp->first_post )
{
- int i, len = pp->longest_name - strlen( pp->name );
+ unsigned i;
pp->first_post = false;
fprintf( stderr, " %s: ", pp->name );
- for( i = 0; i < len; ++i ) fputc( ' ', stderr );
+ for( i = strlen( pp->name ); i < pp->longest_name; ++i )
+ fputc( ' ', stderr );
if( !msg ) fflush( stderr );
}
if( msg ) fprintf( stderr, "%s\n", msg );
@@ -110,8 +108,8 @@ void LZd_flush_data( struct LZ_decoder * const d )
if( d->outfd >= 0 &&
writeblock( d->outfd, d->buffer + d->stream_pos, size ) != size )
{ show_error( "Write error", errno, false ); cleanup_and_fail( 1 ); }
- if( d->pos >= d->buffer_size )
- { d->partial_data_pos += d->pos; d->pos = 0; }
+ if( d->pos >= d->dictionary_size )
+ { d->partial_data_pos += d->pos; d->pos = 0; d->pos_wrapped = true; }
d->stream_pos = d->pos;
}
}
@@ -121,13 +119,11 @@ static bool LZd_verify_trailer( struct LZ_decoder * const d,
struct Pretty_print * const pp )
{
File_trailer trailer;
- const unsigned long long member_size = Rd_member_position( d->rdec ) + Ft_size;
- unsigned long long trailer_data_size;
- unsigned long long trailer_member_size;
- unsigned trailer_crc;
+ int size = Rd_read_data( d->rdec, trailer, Ft_size );
+ const unsigned long long data_size = LZd_data_position( d );
+ const unsigned long long member_size = Rd_member_position( d->rdec );
bool error = false;
- int size = Rd_read_data( d->rdec, trailer, Ft_size );
if( size < Ft_size )
{
error = true;
@@ -140,52 +136,44 @@ static bool LZd_verify_trailer( struct LZ_decoder * const d,
while( size < Ft_size ) trailer[size++] = 0;
}
- if( d->rdec->code != 0 )
- {
- error = true;
- Pp_show_msg( pp, "Range decoder final code is not zero." );
- }
- trailer_crc = Ft_get_data_crc( trailer );
- if( trailer_crc != LZd_crc( d ) )
+ if( Ft_get_data_crc( trailer ) != LZd_crc( d ) )
{
error = true;
if( verbosity >= 0 )
{
Pp_show_msg( pp, 0 );
fprintf( stderr, "CRC mismatch; trailer says %08X, data CRC is %08X\n",
- trailer_crc, LZd_crc( d ) );
+ Ft_get_data_crc( trailer ), LZd_crc( d ) );
}
}
- trailer_data_size = Ft_get_data_size( trailer );
- if( trailer_data_size != LZd_data_position( d ) )
+ if( Ft_get_data_size( trailer ) != data_size )
{
error = true;
if( verbosity >= 0 )
{
Pp_show_msg( pp, 0 );
fprintf( stderr, "Data size mismatch; trailer says %llu, data size is %llu (0x%llX)\n",
- trailer_data_size, LZd_data_position( d ), LZd_data_position( d ) );
+ Ft_get_data_size( trailer ), data_size, data_size );
}
}
- trailer_member_size = Ft_get_member_size( trailer );
- if( trailer_member_size != member_size )
+ if( Ft_get_member_size( trailer ) != member_size )
{
error = true;
if( verbosity >= 0 )
{
Pp_show_msg( pp, 0 );
fprintf( stderr, "Member size mismatch; trailer says %llu, member size is %llu (0x%llX)\n",
- trailer_member_size, member_size, member_size );
+ Ft_get_member_size( trailer ), member_size, member_size );
}
}
- if( !error && verbosity >= 2 && LZd_data_position( d ) > 0 && member_size > 0 )
+ if( !error && verbosity >= 2 && data_size > 0 && member_size > 0 )
fprintf( stderr, "%6.3f:1, %6.3f bits/byte, %5.2f%% saved. ",
- (double)LZd_data_position( d ) / member_size,
- ( 8.0 * member_size ) / LZd_data_position( d ),
- 100.0 * ( 1.0 - ( (double)member_size / LZd_data_position( d ) ) ) );
+ (double)data_size / member_size,
+ ( 8.0 * member_size ) / data_size,
+ 100.0 * ( 1.0 - ( (double)member_size / data_size ) ) );
if( !error && verbosity >= 4 )
fprintf( stderr, "data CRC %08X, data size %9llu, member size %8llu. ",
- trailer_crc, trailer_data_size, trailer_member_size );
+ LZd_crc( d ), data_size, member_size );
return !error;
}
@@ -255,8 +243,8 @@ int LZd_decode_member( struct LZ_decoder * const d,
}
else /* match */
{
- int dis_slot;
const unsigned rep0_saved = rep0;
+ int dis_slot;
len = min_match_len + Rd_decode_len( rdec, &d->match_len_model, pos_state );
dis_slot = Rd_decode_tree6( rdec, d->bm_dis_slot[get_len_state(len)] );
if( dis_slot < start_dis_model ) rep0 = dis_slot;
@@ -295,7 +283,7 @@ int LZd_decode_member( struct LZ_decoder * const d,
}
rep3 = rep2; rep2 = rep1; rep1 = rep0_saved;
state = St_set_match( state );
- if( rep0 >= d->dictionary_size || rep0 >= LZd_data_position( d ) )
+ if( rep0 >= d->dictionary_size || ( rep0 >= d->pos && !d->pos_wrapped ) )
{ LZd_flush_data( d ); return 1; }
}
LZd_copy_block( d, rep0, len );