Merging upstream version 1.10.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
b2b52b515a
commit
9ad9f8e387
12 changed files with 276 additions and 193 deletions
53
lzip.h
53
lzip.h
|
@ -1,5 +1,5 @@
|
|||
/* Pdlzip - LZMA lossless data compressor
|
||||
Copyright (C) 2010-2018 Antonio Diaz Diaz.
|
||||
Copyright (C) 2010-2019 Antonio Diaz Diaz.
|
||||
|
||||
This program is free software. Redistribution and use in source and
|
||||
binary forms, with or without modification, are permitted provided
|
||||
|
@ -55,7 +55,7 @@ enum {
|
|||
/* defined in main.c */
|
||||
extern int verbosity;
|
||||
|
||||
struct Pretty_print
|
||||
struct Pretty_print /* requires global var 'int verbosity' */
|
||||
{
|
||||
const char * name;
|
||||
char * padded_name;
|
||||
|
@ -82,7 +82,7 @@ static inline void Pp_init( struct Pretty_print * const pp,
|
|||
{
|
||||
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 < len ) pp->longest_name = len;
|
||||
}
|
||||
if( pp->longest_name == 0 ) pp->longest_name = stdin_name_len;
|
||||
}
|
||||
|
@ -153,43 +153,43 @@ static inline int real_bits( unsigned value )
|
|||
}
|
||||
|
||||
|
||||
static const uint8_t magic_string[4] = { 0x4C, 0x5A, 0x49, 0x50 }; /* "LZIP" */
|
||||
static const uint8_t lzip_magic[4] = { 0x4C, 0x5A, 0x49, 0x50 }; /* "LZIP" */
|
||||
|
||||
typedef uint8_t File_header[6]; /* 0-3 magic bytes */
|
||||
typedef uint8_t Lzip_header[6]; /* 0-3 magic bytes */
|
||||
/* 4 version */
|
||||
/* 5 coded_dict_size */
|
||||
enum { Fh_size = 6 };
|
||||
enum { Lh_size = 6 };
|
||||
|
||||
static inline void Fh_set_magic( File_header data )
|
||||
{ memcpy( data, magic_string, 4 ); data[4] = 1; }
|
||||
static inline void Lh_set_magic( Lzip_header data )
|
||||
{ memcpy( data, lzip_magic, 4 ); data[4] = 1; }
|
||||
|
||||
static inline bool Fh_verify_magic( const File_header data )
|
||||
{ return ( memcmp( data, magic_string, 4 ) == 0 ); }
|
||||
static inline bool Lh_verify_magic( const Lzip_header data )
|
||||
{ return ( memcmp( data, lzip_magic, 4 ) == 0 ); }
|
||||
|
||||
/* detect (truncated) header */
|
||||
static inline bool Fh_verify_prefix( const File_header data, const int sz )
|
||||
static inline bool Lh_verify_prefix( const Lzip_header data, const int sz )
|
||||
{
|
||||
int i; for( i = 0; i < sz && i < 4; ++i )
|
||||
if( data[i] != magic_string[i] ) return false;
|
||||
if( data[i] != lzip_magic[i] ) return false;
|
||||
return ( sz > 0 );
|
||||
}
|
||||
|
||||
/* detect corrupt header */
|
||||
static inline bool Fh_verify_corrupt( const File_header data )
|
||||
static inline bool Lh_verify_corrupt( const Lzip_header data )
|
||||
{
|
||||
int matches = 0;
|
||||
int i; for( i = 0; i < 4; ++i )
|
||||
if( data[i] == magic_string[i] ) ++matches;
|
||||
if( data[i] == lzip_magic[i] ) ++matches;
|
||||
return ( matches > 1 && matches < 4 );
|
||||
}
|
||||
|
||||
static inline uint8_t Fh_version( const File_header data )
|
||||
static inline uint8_t Lh_version( const Lzip_header data )
|
||||
{ return data[4]; }
|
||||
|
||||
static inline bool Fh_verify_version( const File_header data )
|
||||
static inline bool Lh_verify_version( const Lzip_header data )
|
||||
{ return ( data[4] == 1 ); }
|
||||
|
||||
static inline unsigned Fh_get_dictionary_size( const File_header data )
|
||||
static inline unsigned Lh_get_dictionary_size( const Lzip_header data )
|
||||
{
|
||||
unsigned sz = ( 1 << ( data[5] & 0x1F ) );
|
||||
if( sz > min_dictionary_size )
|
||||
|
@ -197,7 +197,7 @@ 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 )
|
||||
static inline bool Lh_set_dictionary_size( Lzip_header data, const unsigned sz )
|
||||
{
|
||||
if( !isvalid_ds( sz ) ) return false;
|
||||
data[5] = real_bits( sz - 1 );
|
||||
|
@ -214,41 +214,40 @@ static inline bool Fh_set_dictionary_size( File_header data, const unsigned sz )
|
|||
}
|
||||
|
||||
|
||||
typedef uint8_t File_trailer[20];
|
||||
typedef uint8_t Lzip_trailer[20];
|
||||
/* 0-3 CRC32 of the uncompressed data */
|
||||
/* 4-11 size of the uncompressed data */
|
||||
/* 12-19 member size including header and trailer */
|
||||
enum { Lt_size = 20 };
|
||||
|
||||
enum { Ft_size = 20 };
|
||||
|
||||
static inline unsigned Ft_get_data_crc( const File_trailer data )
|
||||
static inline unsigned Lt_get_data_crc( const Lzip_trailer data )
|
||||
{
|
||||
unsigned tmp = 0;
|
||||
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 )
|
||||
static inline void Lt_set_data_crc( Lzip_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 )
|
||||
static inline unsigned long long Lt_get_data_size( const Lzip_trailer data )
|
||||
{
|
||||
unsigned long long tmp = 0;
|
||||
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 )
|
||||
static inline void Lt_set_data_size( Lzip_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 )
|
||||
static inline unsigned long long Lt_get_member_size( const Lzip_trailer data )
|
||||
{
|
||||
unsigned long long tmp = 0;
|
||||
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 )
|
||||
static inline void Lt_set_member_size( Lzip_trailer data, unsigned long long sz )
|
||||
{ int i; for( i = 12; i <= 19; ++i ) { data[i] = (uint8_t)sz; sz >>= 8; } }
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue