summaryrefslogtreecommitdiffstats
path: root/decoder.h
diff options
context:
space:
mode:
Diffstat (limited to 'decoder.h')
-rw-r--r--decoder.h94
1 files changed, 45 insertions, 49 deletions
diff --git a/decoder.h b/decoder.h
index 8a948e9..853c04d 100644
--- a/decoder.h
+++ b/decoder.h
@@ -29,9 +29,9 @@ struct Range_decoder
bool at_stream_end;
};
-bool Rd_read_block( struct Range_decoder * const rdec );
+bool Rd_read_block( Range_decoder * const rdec );
-static inline bool Rd_init( struct Range_decoder * const rdec, const int ifd )
+static inline bool Rd_init( Range_decoder * const rdec, const int ifd )
{
rdec->partial_member_pos = 0;
rdec->buffer = (uint8_t *)malloc( rd_buffer_size );
@@ -45,27 +45,27 @@ static inline bool Rd_init( struct Range_decoder * const rdec, const int ifd )
return true;
}
-static inline void Rd_free( struct Range_decoder * const rdec )
+static inline void Rd_free( Range_decoder * const rdec )
{ free( rdec->buffer ); }
-static inline bool Rd_finished( struct Range_decoder * const rdec )
+static inline bool Rd_finished( Range_decoder * const rdec )
{ return rdec->pos >= rdec->stream_pos && !Rd_read_block( rdec ); }
static inline unsigned long long
-Rd_member_position( const struct Range_decoder * const rdec )
+Rd_member_position( const Range_decoder * const rdec )
{ return rdec->partial_member_pos + rdec->pos; }
-static inline void Rd_reset_member_position( struct Range_decoder * const rdec )
+static inline void Rd_reset_member_position( Range_decoder * const rdec )
{ rdec->partial_member_pos = 0; rdec->partial_member_pos -= rdec->pos; }
-static inline uint8_t Rd_get_byte( struct Range_decoder * const rdec )
+static inline uint8_t Rd_get_byte( Range_decoder * const rdec )
{
/* 0xFF avoids decoder error if member is truncated at EOS marker */
if( Rd_finished( rdec ) ) return 0xFF;
return rdec->buffer[rdec->pos++];
}
-static inline int Rd_read_data( struct Range_decoder * const rdec,
+static inline int Rd_read_data( Range_decoder * const rdec,
uint8_t * const outbuf, const int size )
{
int sz = 0;
@@ -79,25 +79,24 @@ static inline int Rd_read_data( struct Range_decoder * const rdec,
return sz;
}
-static inline bool Rd_load( struct Range_decoder * const rdec,
- const bool ignore_marking )
+static inline bool Rd_load( Range_decoder * const rdec )
{
- int i;
rdec->code = 0;
rdec->range = 0xFFFFFFFFU;
- /* check and discard first byte of the LZMA stream */
- if( Rd_get_byte( rdec ) != 0 && !ignore_marking ) return false;
- for( i = 0; i < 4; ++i ) rdec->code = (rdec->code << 8) | Rd_get_byte( rdec );
+ /* check first byte of the LZMA stream */
+ if( Rd_get_byte( rdec ) != 0 ) return false;
+ int i; for( i = 0; i < 4; ++i )
+ rdec->code = (rdec->code << 8) | Rd_get_byte( rdec );
return true;
}
-static inline void Rd_normalize( struct Range_decoder * const rdec )
+static inline void Rd_normalize( Range_decoder * const rdec )
{
if( rdec->range <= 0x00FFFFFFU )
{ rdec->range <<= 8; rdec->code = (rdec->code << 8) | Rd_get_byte( rdec ); }
}
-static inline unsigned Rd_decode( struct Range_decoder * const rdec,
+static inline unsigned Rd_decode( Range_decoder * const rdec,
const int num_bits )
{
unsigned symbol = 0;
@@ -108,14 +107,14 @@ static inline unsigned Rd_decode( struct Range_decoder * const rdec,
rdec->range >>= 1;
/* symbol <<= 1; */
/* if( rdec->code >= rdec->range ) { rdec->code -= rdec->range; symbol |= 1; } */
- const bool bit = ( rdec->code >= rdec->range );
+ const bool bit = rdec->code >= rdec->range;
symbol <<= 1; symbol += bit;
rdec->code -= rdec->range & ( 0U - bit );
}
return symbol;
}
-static inline unsigned Rd_decode_bit( struct Range_decoder * const rdec,
+static inline unsigned Rd_decode_bit( Range_decoder * const rdec,
Bit_model * const probability )
{
Rd_normalize( rdec );
@@ -135,7 +134,7 @@ static inline unsigned Rd_decode_bit( struct Range_decoder * const rdec,
}
}
-static inline void Rd_decode_symbol_bit( struct Range_decoder * const rdec,
+static inline void Rd_decode_symbol_bit( Range_decoder * const rdec,
Bit_model * const probability, unsigned * symbol )
{
Rd_normalize( rdec );
@@ -155,7 +154,7 @@ static inline void Rd_decode_symbol_bit( struct Range_decoder * const rdec,
}
}
-static inline void Rd_decode_symbol_bit_reversed( struct Range_decoder * const rdec,
+static inline void Rd_decode_symbol_bit_reversed( Range_decoder * const rdec,
Bit_model * const probability, unsigned * model,
unsigned * symbol, const int i )
{
@@ -177,7 +176,7 @@ static inline void Rd_decode_symbol_bit_reversed( struct Range_decoder * const r
}
}
-static inline unsigned Rd_decode_tree6( struct Range_decoder * const rdec,
+static inline unsigned Rd_decode_tree6( Range_decoder * const rdec,
Bit_model bm[] )
{
unsigned symbol = 1;
@@ -190,7 +189,7 @@ static inline unsigned Rd_decode_tree6( struct Range_decoder * const rdec,
return symbol & 0x3F;
}
-static inline unsigned Rd_decode_tree8( struct Range_decoder * const rdec,
+static inline unsigned Rd_decode_tree8( Range_decoder * const rdec,
Bit_model bm[] )
{
unsigned symbol = 1;
@@ -206,7 +205,7 @@ static inline unsigned Rd_decode_tree8( struct Range_decoder * const rdec,
}
static inline unsigned
-Rd_decode_tree_reversed( struct Range_decoder * const rdec,
+Rd_decode_tree_reversed( Range_decoder * const rdec,
Bit_model bm[], const int num_bits )
{
unsigned model = 1;
@@ -218,7 +217,7 @@ Rd_decode_tree_reversed( struct Range_decoder * const rdec,
}
static inline unsigned
-Rd_decode_tree_reversed4( struct Range_decoder * const rdec, Bit_model bm[] )
+Rd_decode_tree_reversed4( Range_decoder * const rdec, Bit_model bm[] )
{
unsigned model = 1;
unsigned symbol = 0;
@@ -229,7 +228,7 @@ Rd_decode_tree_reversed4( struct Range_decoder * const rdec, Bit_model bm[] )
return symbol;
}
-static inline unsigned Rd_decode_matched( struct Range_decoder * const rdec,
+static inline unsigned Rd_decode_matched( Range_decoder * const rdec,
Bit_model bm[], unsigned match_byte )
{
unsigned symbol = 1;
@@ -244,8 +243,8 @@ static inline unsigned Rd_decode_matched( struct Range_decoder * const rdec,
}
}
-static inline unsigned Rd_decode_len( struct Range_decoder * const rdec,
- struct Len_model * const lm,
+static inline unsigned Rd_decode_len( Range_decoder * const rdec,
+ Len_model * const lm,
const int pos_state )
{
Bit_model * bm;
@@ -269,10 +268,10 @@ len3:
}
-struct LZ_decoder
+typedef struct LZ_decoder
{
unsigned long long partial_data_pos;
- struct Range_decoder * rdec;
+ Range_decoder * rdec;
unsigned dictionary_size;
unsigned buffer_size;
uint8_t * buffer; /* output buffer */
@@ -281,17 +280,17 @@ struct LZ_decoder
uint32_t crc;
int outfd; /* output file descriptor */
bool pos_wrapped;
- };
+ } LZ_decoder;
-void LZd_flush_data( struct LZ_decoder * const d );
+void LZd_flush_data( LZ_decoder * const d );
unsigned seek_read_back( const int fd, uint8_t * const buf, const int size,
const int offset );
-static inline uint8_t LZd_peek_prev( const struct LZ_decoder * const d )
+static inline uint8_t LZd_peek_prev( const LZ_decoder * const d )
{ return d->buffer[((d->pos > 0) ? d->pos : d->buffer_size)-1]; }
-static inline uint8_t LZd_peek( const struct LZ_decoder * const d,
+static inline uint8_t LZd_peek( const LZ_decoder * const d,
const unsigned distance )
{
uint8_t b;
@@ -304,27 +303,27 @@ static inline uint8_t LZd_peek( const struct LZ_decoder * const d,
return b;
}
-static inline void LZd_put_byte( struct LZ_decoder * const d, const uint8_t b )
+static inline void LZd_put_byte( LZ_decoder * const d, const uint8_t b )
{
d->buffer[d->pos] = b;
if( ++d->pos >= d->buffer_size ) LZd_flush_data( d );
}
-static inline void LZd_copy_block( struct LZ_decoder * const d,
+static inline void LZd_copy_block( LZ_decoder * const d,
const unsigned distance, unsigned len )
{
unsigned lpos = d->pos, i = lpos - distance - 1;
bool fast, fast2;
if( lpos > distance )
{
- fast = ( len < d->buffer_size - lpos );
- fast2 = ( fast && len <= lpos - i );
+ fast = len < d->buffer_size - lpos;
+ fast2 = fast && len <= lpos - i;
}
else
{
i += d->buffer_size;
- fast = ( len < d->buffer_size - i ); /* (i == pos) may happen */
- fast2 = ( fast && len <= i - lpos );
+ fast = len < d->buffer_size - i; /* (i == pos) may happen */
+ fast2 = fast && len <= i - lpos;
}
if( fast ) /* no wrap */
{
@@ -342,8 +341,8 @@ static inline void LZd_copy_block( struct LZ_decoder * const d,
}
}
-/* block is (at least partially) outside of the buffer */
-static inline void LZd_copy_block2( struct LZ_decoder * const d,
+/* block is (at least partially) outside the buffer */
+static inline void LZd_copy_block2( LZ_decoder * const d,
const unsigned distance, unsigned len )
{
if( len < d->buffer_size - d->pos ) /* no wrap */
@@ -361,8 +360,7 @@ static inline void LZd_copy_block2( struct LZ_decoder * const d,
LZd_put_byte( d, LZd_peek( d, distance ) );
}
-static inline bool LZd_init( struct LZ_decoder * const d,
- struct Range_decoder * const rde,
+static inline bool LZd_init( LZ_decoder * const d, Range_decoder * const rde,
const unsigned buffer_size,
const unsigned dict_size, const int ofd )
{
@@ -382,16 +380,14 @@ static inline bool LZd_init( struct LZ_decoder * const d,
return true;
}
-static inline void LZd_free( struct LZ_decoder * const d )
+static inline void LZd_free( LZ_decoder * const d )
{ free( d->buffer ); }
-static inline unsigned LZd_crc( const struct LZ_decoder * const d )
+static inline unsigned LZd_crc( const LZ_decoder * const d )
{ return d->crc ^ 0xFFFFFFFFU; }
static inline unsigned long long
-LZd_data_position( const struct LZ_decoder * const d )
+LZd_data_position( const LZ_decoder * const d )
{ return d->partial_data_pos + d->pos; }
-int LZd_decode_member( struct LZ_decoder * const d,
- const struct Cl_options * const cl_opts,
- struct Pretty_print * const pp );
+int LZd_decode_member( LZ_decoder * const d, Pretty_print * const pp );