summaryrefslogtreecommitdiffstats
path: root/lzip.h
diff options
context:
space:
mode:
Diffstat (limited to 'lzip.h')
-rw-r--r--lzip.h49
1 files changed, 40 insertions, 9 deletions
diff --git a/lzip.h b/lzip.h
index 1e6cdd2..01bf942 100644
--- a/lzip.h
+++ b/lzip.h
@@ -1,5 +1,5 @@
/* Lunzip - Decompressor for the lzip format
- Copyright (C) 2010-2017 Antonio Diaz Diaz.
+ Copyright (C) 2010-2018 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
@@ -22,6 +22,8 @@
#define min(x,y) ((x) <= (y) ? (x) : (y))
#endif
+void * resize_buffer( void * buf, const unsigned min_size );
+
typedef int State;
enum { states = 12 };
@@ -114,9 +116,13 @@ static inline void Lm_init( struct Len_model * const lm )
}
+/* defined in main.c */
+extern int verbosity;
+
struct Pretty_print
{
const char * name;
+ char * padded_name;
const char * stdin_name;
unsigned longest_name;
bool first_post;
@@ -124,11 +130,12 @@ struct Pretty_print
static inline void Pp_init( struct Pretty_print * const pp,
const char * const filenames[],
- const int num_filenames, const int verbosity )
+ 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;
@@ -147,9 +154,19 @@ static inline void Pp_init( struct Pretty_print * const pp,
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;
}
@@ -202,12 +219,21 @@ enum { Fh_size = 6 };
static inline bool Fh_verify_magic( const File_header data )
{ return ( memcmp( data, magic_string, 4 ) == 0 ); }
-/* detect truncated header */
-static inline bool Fh_verify_prefix( const File_header data, const int size )
+/* detect (truncated) header */
+static inline bool Fh_verify_prefix( const File_header data, const int sz )
{
- int i; for( i = 0; i < size && i < 4; ++i )
+ int i; for( i = 0; i < sz && i < 4; ++i )
if( data[i] != magic_string[i] ) return false;
- return ( size > 0 );
+ return ( sz > 0 );
+ }
+
+/* detect corrupt header */
+static inline bool Fh_verify_corrupt( const File_header data )
+ {
+ int matches = 0;
+ int i; for( i = 0; i < 4; ++i )
+ if( data[i] == magic_string[i] ) ++matches;
+ return ( matches > 1 && matches < 4 );
}
static inline uint8_t Fh_version( const File_header data )
@@ -256,6 +282,7 @@ static inline unsigned long long Ft_get_member_size( const File_trailer data )
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.";
/* defined in decoder.c */
@@ -263,17 +290,21 @@ int readblock( const int fd, uint8_t * const buf, const int size );
/* defined in list.c */
int list_files( const char * const filenames[], const int num_filenames,
- const bool ignore_trailing );
+ const bool ignore_trailing, const bool loose_trailing );
/* defined in main.c */
-extern int verbosity;
struct stat;
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 );
-void * resize_buffer( void * buf, const unsigned min_size );
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,
const int errcode );
+struct Range_decoder;
+void show_dprogress( const unsigned long long cfile_size,
+ const unsigned long long partial_size,
+ const struct Range_decoder * const d,
+ struct Pretty_print * const p );