summaryrefslogtreecommitdiffstats
path: root/lzip.h
diff options
context:
space:
mode:
authorDaniel Baumann <mail@daniel-baumann.ch>2015-11-07 05:04:59 +0000
committerDaniel Baumann <mail@daniel-baumann.ch>2015-11-07 05:04:59 +0000
commitcc9a4cac57c12a9a9cd5bf6facd6be8dcdbfedda (patch)
treee53ec8610d2cd657b48aaaac049566ea25ecc8dc /lzip.h
parentAdding upstream version 1.5~rc1. (diff)
downloadlunzip-cc9a4cac57c12a9a9cd5bf6facd6be8dcdbfedda.tar.xz
lunzip-cc9a4cac57c12a9a9cd5bf6facd6be8dcdbfedda.zip
Adding upstream version 1.5~rc2.upstream/1.5_rc2
Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch>
Diffstat (limited to 'lzip.h')
-rw-r--r--lzip.h88
1 files changed, 26 insertions, 62 deletions
diff --git a/lzip.h b/lzip.h
index a8640bf..39bde22 100644
--- a/lzip.h
+++ b/lzip.h
@@ -1,5 +1,5 @@
/* Lunzip - Decompressor for lzip files
- Copyright (C) 2010, 2011, 2012, 2013 Antonio Diaz Diaz.
+ Copyright (C) 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
@@ -116,12 +116,29 @@ struct Pretty_print
{
const char * name;
const char * stdin_name;
- int longest_name;
+ unsigned longest_name;
bool first_post;
};
-void Pp_init( struct Pretty_print * const pp, const char * const filenames[],
- const int num_filenames );
+static inline void Pp_init( struct Pretty_print * const pp,
+ const char * const filenames[], const int num_filenames )
+ {
+ unsigned stdin_name_len;
+ int i;
+ pp->name = 0;
+ pp->stdin_name = "(stdin)";
+ pp->longest_name = 0;
+ pp->first_post = false;
+ stdin_name_len = strlen( pp->stdin_name );
+
+ for( i = 0; i < num_filenames; ++i )
+ {
+ const char * const s = filenames[i];
+ const unsigned len = (strcmp( s, "-" ) == 0) ? stdin_name_len : strlen( s );
+ if( len > pp->longest_name ) pp->longest_name = len;
+ }
+ if( pp->longest_name == 0 ) pp->longest_name = stdin_name_len;
+ }
static inline void Pp_set_name( struct Pretty_print * const pp,
const char * const filename )
@@ -154,11 +171,9 @@ static inline void CRC32_init( void )
}
}
-static inline void CRC32_update_byte( uint32_t * const crc, const uint8_t byte )
- { *crc = crc32[(*crc^byte)&0xFF] ^ ( *crc >> 8 ); }
-
static inline void CRC32_update_buf( uint32_t * const crc,
- const uint8_t * const buffer, const int size )
+ const uint8_t * const buffer,
+ const int size )
{
int i;
for( i = 0; i < size; ++i )
@@ -166,14 +181,6 @@ static inline void CRC32_update_buf( uint32_t * const crc,
}
-static inline int real_bits( unsigned value )
- {
- int bits = 0;
- while( value > 0 ) { value >>= 1; ++bits; }
- return bits;
- }
-
-
static const uint8_t magic_string[4] = { 0x4C, 0x5A, 0x49, 0x50 }; /* "LZIP" */
typedef uint8_t File_header[6]; /* 0-3 magic bytes */
@@ -181,9 +188,6 @@ typedef uint8_t File_header[6]; /* 0-3 magic bytes */
/* 5 coded_dict_size */
enum { Fh_size = 6 };
-static inline void Fh_set_magic( File_header data )
- { memcpy( data, magic_string, 4 ); data[4] = 1; }
-
static inline bool Fh_verify_magic( const File_header data )
{ return ( memcmp( data, magic_string, 4 ) == 0 ); }
@@ -201,25 +205,6 @@ static inline unsigned Fh_get_dictionary_size( const File_header data )
return sz;
}
-static inline bool Fh_set_dictionary_size( File_header data, const unsigned sz )
- {
- if( sz >= min_dictionary_size && sz <= max_dictionary_size )
- {
- data[5] = real_bits( sz - 1 );
- if( sz > min_dictionary_size )
- {
- const unsigned base_size = 1 << data[5];
- const unsigned wedge = base_size / 16;
- int i;
- for( i = 7; i >= 1; --i )
- if( base_size - ( i * wedge ) >= sz )
- { data[5] |= ( i << 5 ); break; }
- }
- return true;
- }
- return false;
- }
-
typedef uint8_t File_trailer[20];
/* 0-3 CRC32 of the uncompressed data */
@@ -231,45 +216,24 @@ enum { Ft_size = 20 };
static inline unsigned Ft_get_data_crc( const File_trailer data )
{
unsigned tmp = 0;
- int i;
- for( i = 3; i >= 0; --i ) { tmp <<= 8; tmp += data[i]; }
+ int i; for( i = 3; i >= 0; --i ) { tmp <<= 8; tmp += data[i]; }
return tmp;
}
-static inline void Ft_set_data_crc( File_trailer data, unsigned crc )
- {
- int i;
- for( i = 0; i <= 3; ++i ) { data[i] = (uint8_t)crc; crc >>= 8; }
- }
-
static inline unsigned long long Ft_get_data_size( const File_trailer data )
{
unsigned long long tmp = 0;
- int i;
- for( i = 11; i >= 4; --i ) { tmp <<= 8; tmp += data[i]; }
+ int i; for( i = 11; i >= 4; --i ) { tmp <<= 8; tmp += data[i]; }
return tmp;
}
-static inline void Ft_set_data_size( File_trailer data, unsigned long long sz )
- {
- int i;
- for( i = 4; i <= 11; ++i ) { data[i] = (uint8_t)sz; sz >>= 8; }
- }
-
static inline unsigned long long Ft_get_member_size( const File_trailer data )
{
unsigned long long tmp = 0;
- int i;
- for( i = 19; i >= 12; --i ) { tmp <<= 8; tmp += data[i]; }
+ int i; for( i = 19; i >= 12; --i ) { tmp <<= 8; tmp += data[i]; }
return tmp;
}
-static inline void Ft_set_member_size( File_trailer data, unsigned long long sz )
- {
- int i;
- for( i = 12; i <= 19; ++i ) { data[i] = (uint8_t)sz; sz >>= 8; }
- }
-
/* defined in main.c */
extern int verbosity;