1
0
Fork 0

Merging upstream version 1.3.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-02-23 19:15:16 +01:00
parent b375923f9b
commit fa78de0b15
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
13 changed files with 129 additions and 103 deletions

84
main.c
View file

@ -1,6 +1,6 @@
/* Pdlzip - Data compressor based on the LZMA algorithm
2009-08-14 : Igor Pavlov : Public domain
Copyright (C) 2010, 2011 Antonio Diaz Diaz.
Copyright (C) 2010, 2011, 2012 Antonio Diaz Diaz.
This program is free software: you have unlimited permission
to copy, distribute and modify it.
@ -19,8 +19,11 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#if defined(__OS2__)
#include <io.h>
#endif
#include "carg_parser.h"
#include "pdarg_parser.h"
#include "pdlzip.h"
#include "Alloc.h"
#include "7zFile.h"
@ -50,7 +53,7 @@ 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 * const program_year = "2012";
const char * invocation_name = 0;
@ -70,7 +73,7 @@ enum Mode { m_compress, m_decompress, m_test };
char * output_filename = 0;
/* assure at least a minimum size for buffer `buf' */
/* assure at least a minimum size for buffer 'buf' */
inline void * resize_buffer( void * buf, const int min_size )
{
if( buf ) buf = realloc( buf, min_size );
@ -82,29 +85,33 @@ 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( "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" );
printf( " -V, --version output version information and exit\n" );
printf( " -c, --stdout send output to standard output\n" );
printf( " -d, --decompress decompress\n" );
/* printf( " -f, --force overwrite existing output files\n" ); */
/* printf( " -k, --keep keep (don't delete) input files\n" ); */
printf( " -m, --match-length=<n> set match length limit in bytes [36]\n" );
printf( " -q, --quiet suppress all messages\n" );
printf( " -s, --dictionary-size=<n> set dictionary size limit in bytes [8MiB]\n" );
printf( " -t, --test test compressed file integrity\n" );
printf( " -v, --verbose be verbose (a 2nd -v gives more)\n" );
printf( " -1 .. -9 set compression level [default 6]\n" );
printf( " --fast alias for -1\n" );
printf( " --best alias for -9\n" );
printf( "If no file name is given, %s compresses or decompresses\n", program_name );
printf( "from standard input to standard output.\n" );
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( "also able to decompress legacy lzma-alone (.lzma) files.\n"
"\nUsage: %s [options] [file]\n", invocation_name );
printf( "\nOptions:\n"
" -h, --help display this help and exit\n"
" -V, --version output version information and exit\n"
" -c, --stdout send output to standard output\n"
" -d, --decompress decompress\n"
/* " -f, --force overwrite existing output files\n" */
/* " -k, --keep keep (don't delete) input files\n" */
" -m, --match-length=<bytes> set match length limit in bytes [36]\n"
" -q, --quiet suppress all messages\n"
" -s, --dictionary-size=<bytes> set dictionary size limit in bytes [8MiB]\n"
" -t, --test test compressed file integrity\n"
" -v, --verbose be verbose (a 2nd -v gives more)\n"
" -1 .. -9 set compression level [default 6]\n"
" --fast alias for -1\n"
" --best alias for -9\n"
"If no file name is given, pdlzip compresses or decompresses\n"
"from standard input to standard output.\n"
"Numbers may be followed by a multiplier: k = kB = 10^3 = 1000,\n"
"Ki = KiB = 2^10 = 1024, M = 10^6, Mi = 2^20, G = 10^9, Gi = 2^30, etc...\n"
"The bidimensional parameter space of LZMA can't be mapped to a linear\n"
"scale optimal for all files. If your files are large, very repetitive,\n"
"etc, you may need to use the --match-length and --dictionary-size\n"
"options directly to achieve optimal performance.\n"
"\nReport bugs to lzip-bug@nongnu.org\n"
"Pdlzip home page: http://www.nongnu.org/lzip/pdlzip.html\n" );
}
@ -112,9 +119,9 @@ static void show_version()
{
printf( "%s %s\n", Program_name, PROGVERSION );
printf( "Copyright (C) %s Antonio Diaz Diaz.\n", program_year );
printf( "Public Domain 2009 Igor Pavlov.\n" );
printf( "This is free software: you are free to change and redistribute it.\n" );
printf( "There is NO WARRANTY, to the extent permitted by law.\n" );
printf( "Public Domain 2009 Igor Pavlov.\n"
"This is free software: you are free to change and redistribute it.\n"
"There is NO WARRANTY, to the extent permitted by law.\n" );
}
@ -125,11 +132,12 @@ static const char * format_num( long long num )
enum { buf_size = 16, factor = 1024 };
static char buf[buf_size];
const char *p = "";
bool exact = ( num % factor == 0 );
int i;
for( i = 0; i < 8 && ( llabs( num ) > 9999 ||
( llabs( num ) >= factor && num % factor == 0 ) ); ++i )
{ num /= factor; p = prefix[i]; }
( exact && llabs( num ) >= factor ) ); ++i )
{ num /= factor; if( num % factor != 0 ) exact = false; p = prefix[i]; }
snprintf( buf, buf_size, "%lld %s", num, p );
return buf;
}
@ -537,7 +545,7 @@ 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",
fprintf( stderr, "Try '%s --help' for more information.\n",
invocation_name );
}
}
@ -593,8 +601,8 @@ static void set_d_outname( const char * const name )
output_filename = resize_buffer( output_filename, strlen( name ) + 4 + 1 );
strcpy( output_filename, name );
strcat( output_filename, ".out" );
if( verbosity >= 0 )
fprintf( stderr, "%s: can't guess original name for `%s' -- using `%s'.\n",
if( verbosity >= 1 )
fprintf( stderr, "%s: Can't guess original name for '%s' -- using '%s'.\n",
program_name, name, output_filename );
}
@ -644,7 +652,6 @@ int main( const int argc, const char * const argv[] )
{ 'b', "member-size", ap_yes },
{ 'c', "stdout", ap_no },
{ 'd', "decompress", ap_no },
{ 'e', "extreme", ap_no },
{ 'f', "force", ap_no },
{ 'h', "help", ap_no },
{ 'k', "keep", ap_no },
@ -699,6 +706,11 @@ int main( const int argc, const char * const argv[] )
}
} /* end process options */
#if defined(__OS2__)
_fsetmode( stdin, "b" );
_fsetmode( stdout, "b" );
#endif
if( ap_arguments( &parser ) > argind &&
strcmp( ap_argument( &parser, argind ), "-" ) )
input_filename = ap_argument( &parser, argind );