From 7d36a275870c0f13175bff792bc241216dade2e2 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 7 Nov 2015 15:26:21 +0100 Subject: Merging upstream version 1.2. Signed-off-by: Daniel Baumann --- main.c | 64 +++++++++++++++++++++++++++------------------------------------- 1 file changed, 27 insertions(+), 37 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index b5e35df..3a75453 100644 --- a/main.c +++ b/main.c @@ -1,6 +1,6 @@ -/* Pdlzip - A data compressor based on the LZMA algorithm +/* Pdlzip - Data compressor based on the LZMA algorithm 2009-08-14 : Igor Pavlov : Public domain - Copyright (C) 2010 Antonio Diaz Diaz. + Copyright (C) 2010, 2011 Antonio Diaz Diaz. This program is free software: you have unlimited permission to copy, distribute and modify it. @@ -48,10 +48,10 @@ static void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); } static void SzFree(void *p, void *address) { p = p; MyFree(address); } static ISzAlloc g_Alloc = { SzAlloc, SzFree }; +const char * const Program_name = "Pdlzip"; +const char * const program_name = "pdlzip"; +const char * const program_year = "2011"; const char * invocation_name = 0; -const char * const Program_name = "Pdlzip"; -const char * const program_name = "pdlzip"; -const char * const program_year = "2010"; struct { const char * from; const char * to; } const known_extensions[] = { @@ -66,7 +66,7 @@ struct Lzma_options int match_len_limit; /* 5..273 */ }; -enum Mode { m_compress = 0, m_decompress, m_test }; +enum Mode { m_compress, m_decompress, m_test }; char * output_filename = 0; @@ -82,7 +82,7 @@ inline void * resize_buffer( void * buf, const int min_size ) static void show_help() { printf( "%s - A \"public domain\" version of the lzip data compressor\n", Program_name ); - printf( "able to decompress legacy lzma-alone (.lzma) files.\n" ); + printf( "also able to decompress legacy lzma-alone (.lzma) files.\n" ); printf( "\nUsage: %s [options] [file]\n", invocation_name ); printf( "\nOptions:\n" ); printf( " -h, --help display this help and exit\n" ); @@ -104,7 +104,7 @@ static void show_help() printf( "Numbers may be followed by a multiplier: k = kB = 10^3 = 1000,\n" ); printf( "Ki = KiB = 2^10 = 1024, M = 10^6, Mi = 2^20, G = 10^9, Gi = 2^30, etc...\n" ); printf( "\nReport bugs to lzip-bug@nongnu.org\n" ); -/* printf( "Pdlzip home page: http://www.nongnu.org/lzip/pdlzip.html\n" ); */ + printf( "Pdlzip home page: http://www.nongnu.org/lzip/pdlzip.html\n" ); } @@ -118,34 +118,24 @@ static void show_version() } -static const char * format_num( long long num, long long limit, - const int set_prefix ) +static const char * format_num( long long num ) { - const char * const si_prefix[8] = - { "k", "M", "G", "T", "P", "E", "Z", "Y" }; - const char * const binary_prefix[8] = + const char * const prefix[8] = { "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi", "Yi" }; - static bool si = false; - static char buf[16]; - - if( set_prefix ) si = ( set_prefix > 0 ); - { - const int factor = ( si ) ? 1000 : 1024; - const char * const *prefix = ( si ) ? si_prefix : binary_prefix; + enum { buf_size = 16, factor = 1024 }; + static char buf[buf_size]; const char *p = ""; int i; - limit = max( 999LL, min( 999999LL, limit ) ); - for( i = 0; i < 8 && ( llabs( num ) > limit || + for( i = 0; i < 8 && ( llabs( num ) > 9999 || ( llabs( num ) >= factor && num % factor == 0 ) ); ++i ) { num /= factor; p = prefix[i]; } - snprintf( buf, sizeof buf, "%lld %s", num, p ); - } + snprintf( buf, buf_size, "%lld %s", num, p ); return buf; } -static long long getnum( const char * const ptr, const int bs, +static long long getnum( const char * const ptr, const long long llimit, const long long ulimit ) { long long result; @@ -167,9 +157,6 @@ static long long getnum( const char * const ptr, const int bs, switch( tail[0] ) { case ' ': break; - case 'b': if( bs > 0 ) { factor = bs; exponent = 1; } - else bad_multiplier = true; - break; case 'Y': exponent = 8; break; case 'Z': exponent = 7; break; case 'E': exponent = 6; break; @@ -211,7 +198,7 @@ static int get_dict_size( const char * const arg ) if( bits >= min_dictionary_bits && bits <= max_dictionary_bits && *tail == 0 ) return ( 1 << bits ); - return getnum( arg, 0, min_dictionary_size, max_dictionary_size ); + return getnum( arg, min_dictionary_size, max_dictionary_size ); } @@ -297,7 +284,7 @@ static int lzma_Decode2( UInt64 unpackSize, CLzmaDec *state, { show_error( "Data error.", 0, false ); return 1; } if( verbosity >= 2 ) fprintf( stderr, "lzma-alone, dictionary size %7sB. ", - format_num( state->prop.dicSize, 9999, 0 ) ); + format_num( state->prop.dicSize ) ); if( verbosity >= 3 ) fprintf( stderr, "uncompressed size %9lld, compressed size %8lld. ", total_out, total_in ); @@ -365,7 +352,8 @@ static int Decode2( CLzmaDec *state, ISeqOutStream *outStream, error = true; if( verbosity >= 0 ) fprintf( stderr, "trailer truncated at trailer position %u;" - " some checks may fail.\n", (unsigned int)(*inSize - *inPos) ); + " some checks may fail.\n", + (unsigned int)(*inSize - *inPos) ); for( i = *inSize - *inPos; i < trailer_size; ++i ) inBuf[*inPos+i] = 0; } @@ -474,7 +462,7 @@ static int Decode( ISeqOutStream *outStream, ISeqInStream *inStream, if( verbosity >= 2 ) fprintf( stderr, "version %d, dictionary size %7sB. ", Fh_version( header ), - format_num( Fh_get_dictionary_size( header ), 9999, 0 ) ); + format_num( Fh_get_dictionary_size( header ) ) ); props[0] = 93; /* (45 * 2) + (9 * 0) + 3 */ ds = Fh_get_dictionary_size( header ); @@ -549,14 +537,16 @@ void show_error( const char * const msg, const int errcode, const bool help ) fprintf( stderr, "\n" ); } if( help && invocation_name && invocation_name[0] ) - fprintf( stderr, "Try `%s --help' for more information.\n", invocation_name ); + fprintf( stderr, "Try `%s --help' for more information.\n", + invocation_name ); } } void internal_error( const char * const msg ) { - fprintf( stderr, "%s: internal error: %s.\n", program_name, msg ); + if( verbosity >= 0 ) + fprintf( stderr, "%s: internal error: %s.\n", program_name, msg ); exit( 3 ); } @@ -618,7 +608,7 @@ int main( const int argc, const char * const argv[] ) to the corresponding LZMA compression modes. */ const struct Lzma_options option_mapping[] = { - { 1 << 16, 5 }, /* -0 */ + { 1 << 20, 5 }, /* -0 */ { 1 << 20, 5 }, /* -1 */ { 3 << 19, 6 }, /* -2 */ { 1 << 21, 8 }, /* -3 */ @@ -697,7 +687,7 @@ int main( const int argc, const char * const argv[] ) case 'h': show_help(); return 0; case 'k': keep_input_files = true; break; case 'm': encoder_options.match_len_limit = - getnum( arg, 0, min_match_len_limit, max_match_len ); break; + getnum( arg, min_match_len_limit, max_match_len ); break; case 'q': verbosity = -1; break; case 's': encoder_options.dictionary_size = get_dict_size( arg ); break; @@ -707,7 +697,7 @@ int main( const int argc, const char * const argv[] ) case 'V': show_version(); return 0; default : internal_error( "uncaught option" ); } - } + } /* end process options */ if( ap_arguments( &parser ) > argind && strcmp( ap_argument( &parser, argind ), "-" ) ) -- cgit v1.2.3