summaryrefslogtreecommitdiffstats
path: root/lzip.h
diff options
context:
space:
mode:
Diffstat (limited to 'lzip.h')
-rw-r--r--lzip.h53
1 files changed, 31 insertions, 22 deletions
diff --git a/lzip.h b/lzip.h
index cef99dc..34c9a81 100644
--- a/lzip.h
+++ b/lzip.h
@@ -1,5 +1,5 @@
/* Plzip - Parallel compressor compatible with lzip
- Copyright (C) 2009-2015 Antonio Diaz Diaz.
+ Copyright (C) 2009-2016 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
@@ -15,6 +15,10 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#ifndef LZ_API_VERSION
+#define LZ_API_VERSION 1
+#endif
+
enum {
min_dictionary_bits = 12,
min_dictionary_size = 1 << min_dictionary_bits,
@@ -31,9 +35,11 @@ class Pretty_print
mutable bool first_post;
public:
- explicit Pretty_print( const std::vector< std::string > & filenames )
+ Pretty_print( const std::vector< std::string > & filenames,
+ const int verbosity )
: stdin_name( "(stdin)" ), longest_name( 0 ), first_post( false )
{
+ if( verbosity <= 0 ) return;
const unsigned stdin_name_len = std::strlen( stdin_name );
for( unsigned i = 0; i < filenames.size(); ++i )
{
@@ -57,6 +63,11 @@ public:
};
+inline bool isvalid_ds( const unsigned dictionary_size )
+ { return ( dictionary_size >= min_dictionary_size &&
+ dictionary_size <= max_dictionary_size ); }
+
+
inline int real_bits( unsigned value )
{
int bits = 0;
@@ -91,20 +102,17 @@ struct File_header
bool dictionary_size( const unsigned sz )
{
- if( sz >= min_dictionary_size && sz <= max_dictionary_size )
+ if( !isvalid_ds( sz ) ) return false;
+ data[5] = real_bits( sz - 1 );
+ if( sz > min_dictionary_size )
{
- data[5] = real_bits( sz - 1 );
- if( sz > min_dictionary_size )
- {
- const unsigned base_size = 1 << data[5];
- const unsigned fraction = base_size / 16;
- for( int i = 7; i >= 1; --i )
- if( base_size - ( i * fraction ) >= sz )
- { data[5] |= ( i << 5 ); break; }
- }
- return true;
+ const unsigned base_size = 1 << data[5];
+ const unsigned fraction = base_size / 16;
+ for( int i = 7; i >= 1; --i )
+ if( base_size - ( i * fraction ) >= sz )
+ { data[5] |= ( i << 5 ); break; }
}
- return false;
+ return true;
}
};
@@ -152,10 +160,10 @@ struct File_trailer
// defined in compress.cc
int readblock( const int fd, uint8_t * const buf, const int size );
int writeblock( const int fd, const uint8_t * const buf, const int size );
-void xinit( pthread_mutex_t * const mutex );
-void xinit( pthread_cond_t * const cond );
-void xdestroy( pthread_mutex_t * const mutex );
-void xdestroy( pthread_cond_t * const cond );
+void xinit_mutex( pthread_mutex_t * const mutex );
+void xinit_cond( pthread_cond_t * const cond );
+void xdestroy_mutex( pthread_mutex_t * const mutex );
+void xdestroy_cond( pthread_cond_t * const cond );
void xlock( pthread_mutex_t * const mutex );
void xunlock( pthread_mutex_t * const mutex );
void xwait( pthread_cond_t * const cond, pthread_mutex_t * const mutex );
@@ -176,7 +184,8 @@ int dec_stdout( const int num_workers, const int infd, const int outfd,
// defined in dec_stream.cc
int dec_stream( const int num_workers, const int infd, const int outfd,
- const Pretty_print & pp, const int debug_level );
+ const Pretty_print & pp, const int debug_level,
+ const bool ignore_garbage );
// defined in decompress.cc
int preadblock( const int fd, uint8_t * const buf, const int size,
@@ -187,7 +196,7 @@ int decompress_read_error( struct LZ_Decoder * const decoder,
const Pretty_print & pp, const int worker_id );
int decompress( int num_workers, const int infd, const int outfd,
const Pretty_print & pp, const int debug_level,
- const bool infd_isreg );
+ const bool ignore_garbage, const bool infd_isreg );
// defined in main.cc
extern int verbosity;
@@ -214,9 +223,9 @@ class Slot_tally
public:
explicit Slot_tally( const int slots )
: num_slots( slots ), num_free( slots )
- { xinit( &mutex ); xinit( &slot_av ); }
+ { xinit_mutex( &mutex ); xinit_cond( &slot_av ); }
- ~Slot_tally() { xdestroy( &slot_av ); xdestroy( &mutex ); }
+ ~Slot_tally() { xdestroy_cond( &slot_av ); xdestroy_mutex( &mutex ); }
bool all_free() { return ( num_free == num_slots ); }