Merging upstream version 1.0~rc3.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
d706ddc9d9
commit
0157c9ea06
13 changed files with 267 additions and 266 deletions
56
main.c
56
main.c
|
@ -399,8 +399,9 @@ static bool next_filename()
|
|||
|
||||
|
||||
static int compress( const long long member_size, const long long volume_size,
|
||||
const struct Lzma_options * const encoder_options, const int infd,
|
||||
struct Pretty_print * const pp, const struct stat * const in_statsp )
|
||||
const struct Lzma_options * const encoder_options,
|
||||
const int infd, struct Pretty_print * const pp,
|
||||
const struct stat * const in_statsp )
|
||||
{
|
||||
if( verbosity >= 1 ) Pp_show_msg( pp, 0 );
|
||||
File_header header;
|
||||
|
@ -412,7 +413,7 @@ static int compress( const long long member_size, const long long volume_size,
|
|||
|
||||
struct Matchfinder matchfinder;
|
||||
Mf_init( &matchfinder, Fh_get_dictionary_size( header ),
|
||||
encoder_options->match_len_limit, infd );
|
||||
encoder_options->match_len_limit, infd );
|
||||
Fh_set_dictionary_size( header, Mf_dictionary_size( &matchfinder ) );
|
||||
|
||||
long long in_size = 0, out_size = 0, partial_volume_size = 0;
|
||||
|
@ -424,8 +425,7 @@ static int compress( const long long member_size, const long long volume_size,
|
|||
const long long size =
|
||||
min( member_size, volume_size - partial_volume_size );
|
||||
if( !LZe_encode_member( &encoder, size ) )
|
||||
{ Pp_show_msg( pp, 0 ); show_error( "encoder error", 0, false );
|
||||
retval = 1; break; }
|
||||
{ Pp_show_msg( pp, "encoder error" ); retval = 1; break; }
|
||||
in_size += Mf_data_position( &matchfinder );
|
||||
out_size += LZe_member_position( &encoder );
|
||||
partial_volume_size += LZe_member_position( &encoder );
|
||||
|
@ -438,15 +438,14 @@ static int compress( const long long member_size, const long long volume_size,
|
|||
{
|
||||
close_and_set_permissions( in_statsp );
|
||||
if( !next_filename() )
|
||||
{ Pp_show_msg( pp, 0 );
|
||||
show_error( "too many volume files", 0, false );
|
||||
retval = 1; break; }
|
||||
{ Pp_show_msg( pp, "too many volume files" ); retval = 1; break; }
|
||||
if( !open_outstream( true ) ) { retval = 1; break; }
|
||||
delete_output_on_interrupt = true;
|
||||
}
|
||||
}
|
||||
if( !Mf_reset( &matchfinder ) )
|
||||
{ Pp_show_msg( pp, 0 ); show_error( "can't reset matchfinder", 0, false );
|
||||
{ Pp_show_msg( pp, 0 );
|
||||
show_error( "can't reset matchfinder", errno, false );
|
||||
retval = 1; break; }
|
||||
}
|
||||
|
||||
|
@ -470,20 +469,22 @@ static int compress( const long long member_size, const long long volume_size,
|
|||
static int decompress( const int infd, struct Pretty_print * const pp,
|
||||
const bool testing )
|
||||
{
|
||||
struct Input_buffer ibuf;
|
||||
Ib_init( &ibuf, infd );
|
||||
struct Range_decoder rdec;
|
||||
Rd_init( &rdec, infd );
|
||||
long long partial_file_pos = 0;
|
||||
int retval = 0;
|
||||
|
||||
for( bool first_member = true; ; first_member = false, Pp_reset( pp ) )
|
||||
{
|
||||
File_header header;
|
||||
for( unsigned int i = 0; i < sizeof (File_header); ++i )
|
||||
header[i] = Ib_get_byte( &ibuf );
|
||||
if( Ib_finished( &ibuf ) ) // End Of File
|
||||
Rd_reset_member_position( &rdec );
|
||||
for( int i = 0; i < Fh_size; ++i )
|
||||
header[i] = Rd_get_byte( &rdec );
|
||||
if( Rd_finished( &rdec ) ) // End Of File
|
||||
{
|
||||
if( !first_member ) break;
|
||||
Pp_show_msg( pp, "error reading member header" ); retval = 1; break;
|
||||
if( first_member )
|
||||
{ Pp_show_msg( pp, "error reading member header" ); retval = 1; }
|
||||
break;
|
||||
}
|
||||
if( !Fh_verify_magic( header ) )
|
||||
{
|
||||
|
@ -513,10 +514,10 @@ static int decompress( const int infd, struct Pretty_print * const pp,
|
|||
format_num( Fh_get_dictionary_size( header ), 9999, 0 ) );
|
||||
}
|
||||
struct LZ_decoder decoder;
|
||||
LZd_init( &decoder, header, &ibuf, outfd );
|
||||
LZd_init( &decoder, header, &rdec, outfd );
|
||||
|
||||
const int result = LZd_decode_member( &decoder, pp );
|
||||
partial_file_pos += LZd_member_position( &decoder );
|
||||
partial_file_pos += Rd_member_position( &rdec );
|
||||
LZd_free( &decoder );
|
||||
if( result != 0 )
|
||||
{
|
||||
|
@ -535,7 +536,7 @@ static int decompress( const int infd, struct Pretty_print * const pp,
|
|||
{ if( testing ) fprintf( stderr, "ok\n" );
|
||||
else fprintf( stderr, "done\n" ); }
|
||||
}
|
||||
Ib_free( &ibuf );
|
||||
Rd_free( &rdec );
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
@ -683,6 +684,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, 10 }, // -1
|
||||
{ 3 << 19, 12 }, // -2
|
||||
{ 1 << 21, 17 }, // -3
|
||||
|
@ -692,7 +694,7 @@ int main( const int argc, const char * const argv[] )
|
|||
{ 1 << 24, 108 }, // -7
|
||||
{ 3 << 23, 163 }, // -8
|
||||
{ 1 << 25, 273 } }; // -9
|
||||
struct Lzma_options encoder_options = option_mapping[5]; // default = "-6"
|
||||
struct Lzma_options encoder_options = option_mapping[6]; // default = "-6"
|
||||
long long member_size = LLONG_MAX;
|
||||
long long volume_size = LLONG_MAX;
|
||||
int infd = -1;
|
||||
|
@ -709,6 +711,7 @@ int main( const int argc, const char * const argv[] )
|
|||
|
||||
const struct ap_Option options[] =
|
||||
{
|
||||
{ '0', 0, ap_no },
|
||||
{ '1', "fast", ap_no },
|
||||
{ '2', 0, ap_no },
|
||||
{ '3', 0, ap_no },
|
||||
|
@ -721,6 +724,7 @@ 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 },
|
||||
|
@ -736,9 +740,9 @@ int main( const int argc, const char * const argv[] )
|
|||
|
||||
struct Arg_parser parser;
|
||||
if( !ap_init( &parser, argc, argv, options, 0 ) )
|
||||
{ show_error( "Memory exhausted", 0, 0 ); return 1; }
|
||||
{ show_error( "memory exhausted", 0, false ); return 1; }
|
||||
if( ap_error( &parser ) ) // bad option
|
||||
{ show_error( ap_error( &parser ), 0, 1 ); return 1; }
|
||||
{ show_error( ap_error( &parser ), 0, true ); return 1; }
|
||||
|
||||
int argind = 0;
|
||||
for( ; argind < ap_arguments( &parser ); ++argind )
|
||||
|
@ -748,13 +752,13 @@ int main( const int argc, const char * const argv[] )
|
|||
if( !code ) break; // no more options
|
||||
switch( code )
|
||||
{
|
||||
case '1': case '2': case '3':
|
||||
case '4': case '5': case '6':
|
||||
case '7': case '8': case '9':
|
||||
encoder_options = option_mapping[code-'1']; break;
|
||||
case '0': case '1': case '2': case '3': case '4':
|
||||
case '5': case '6': case '7': case '8': case '9':
|
||||
encoder_options = option_mapping[code-'0']; break;
|
||||
case 'b': member_size = getnum( arg, 0, 100000, LLONG_MAX / 2 ); break;
|
||||
case 'c': to_stdout = true; break;
|
||||
case 'd': program_mode = m_decompress; break;
|
||||
case 'e': break; // ignored by now
|
||||
case 'f': force = true; break;
|
||||
case 'h': show_help(); return 0;
|
||||
case 'k': keep_input_files = true; break;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue