summaryrefslogtreecommitdiffstats
path: root/lzip.h
diff options
context:
space:
mode:
Diffstat (limited to 'lzip.h')
-rw-r--r--lzip.h105
1 files changed, 29 insertions, 76 deletions
diff --git a/lzip.h b/lzip.h
index 23db964..3961c33 100644
--- a/lzip.h
+++ b/lzip.h
@@ -1,18 +1,18 @@
-/* Lunzip - Decompressor for the lzip format
- Copyright (C) 2010-2019 Antonio Diaz Diaz.
+/* Lunzip - Decompressor for the lzip format
+ Copyright (C) 2010-2021 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
- the Free Software Foundation, either version 2 of the License, or
- (at your option) any later version.
+ 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
+ the Free Software Foundation, either version 2 of the License, or
+ (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef max
@@ -22,8 +22,6 @@
#define min(x,y) ((x) <= (y) ? (x) : (y))
#endif
-void * resize_buffer( void * buf, const unsigned min_size );
-
typedef int State;
enum { states = 12 };
@@ -82,7 +80,7 @@ static inline int get_len_state( const int len )
{ return min( len - min_match_len, len_states - 1 ); }
static inline int get_lit_state( const uint8_t prev_byte )
- { return ( prev_byte >> ( 8 - literal_context_bits ) ); }
+ { return prev_byte >> ( 8 - literal_context_bits ); }
enum { bit_model_move_bits = 5,
@@ -116,65 +114,6 @@ static inline void Lm_init( struct Len_model * const lm )
}
-/* defined in main.c */
-extern int verbosity;
-
-struct Pretty_print /* requires global var 'int verbosity' */
- {
- const char * name;
- char * padded_name;
- const char * stdin_name;
- unsigned longest_name;
- bool first_post;
- };
-
-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->padded_name = 0;
- pp->stdin_name = "(stdin)";
- pp->longest_name = 0;
- pp->first_post = false;
-
- if( verbosity <= 0 ) return;
- 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( pp->longest_name < len ) 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 )
- {
- unsigned name_len, padded_name_len, i = 0;
-
- if( filename && filename[0] && strcmp( filename, "-" ) != 0 )
- pp->name = filename;
- else pp->name = pp->stdin_name;
- name_len = strlen( pp->name );
- padded_name_len = max( name_len, pp->longest_name ) + 4;
- pp->padded_name = resize_buffer( pp->padded_name, padded_name_len + 1 );
- while( i < 2 ) pp->padded_name[i++] = ' ';
- while( i < name_len + 2 ) { pp->padded_name[i] = pp->name[i-2]; ++i; }
- pp->padded_name[i++] = ':';
- while( i < padded_name_len ) pp->padded_name[i++] = ' ';
- pp->padded_name[i] = 0;
- pp->first_post = true;
- }
-
-static inline void Pp_reset( struct Pretty_print * const pp )
- { if( pp->name && pp->name[0] ) pp->first_post = true; }
-void Pp_show_msg( struct Pretty_print * const pp, const char * const msg );
-
-
typedef uint32_t CRC32[256]; /* Table of CRCs of all 8-bit messages. */
extern CRC32 crc32;
@@ -213,7 +152,7 @@ static const uint8_t lzip_magic[4] = { 0x4C, 0x5A, 0x49, 0x50 }; /* "LZIP" */
typedef uint8_t Lzip_header[6]; /* 0-3 magic bytes */
/* 4 version */
- /* 5 coded_dict_size */
+ /* 5 coded dictionary size */
enum { Lh_size = 6 };
static inline bool Lh_verify_magic( const Lzip_header data )
@@ -250,6 +189,12 @@ static inline unsigned Lh_get_dictionary_size( const Lzip_header data )
return sz;
}
+static inline bool Lh_verify( const Lzip_header data )
+ {
+ return Lh_verify_magic( data ) && Lh_verify_version( data ) &&
+ isvalid_ds( Lh_get_dictionary_size( data ) );
+ }
+
typedef uint8_t Lzip_trailer[20];
/* 0-3 CRC32 of the uncompressed data */
@@ -294,10 +239,14 @@ static inline bool Lt_verify_consistency( const Lzip_trailer data )
}
+static inline void set_retval( int * retval, const int new_val )
+ { if( *retval < new_val ) *retval = new_val; }
+
static const char * const bad_magic_msg = "Bad magic number (file not in lzip format).";
static const char * const bad_dict_msg = "Invalid dictionary size in member header.";
static const char * const corrupt_mm_msg = "Corrupt header in multimember file.";
static const char * const trailing_msg = "Trailing data not allowed.";
+static const char * const mem_msg = "Not enough memory.";
/* defined in decoder.c */
int readblock( const int fd, uint8_t * const buf, const int size );
@@ -308,11 +257,15 @@ int list_files( const char * const filenames[], const int num_filenames,
/* defined in main.c */
struct stat;
+struct Pretty_print;
+extern int verbosity;
+void * resize_buffer( void * buf, const unsigned min_size );
+void Pp_show_msg( struct Pretty_print * const pp, const char * const msg );
const char * bad_version( const unsigned version );
const char * format_ds( const unsigned dictionary_size );
void show_header( const unsigned dictionary_size );
int open_instream( const char * const name, struct stat * const in_statsp,
- const bool no_ofile, const bool reg_only );
+ const bool one_to_one, const bool reg_only );
void cleanup_and_fail( const int retval );
void show_error( const char * const msg, const int errcode, const bool help );
void show_file_error( const char * const filename, const char * const msg,