Adding upstream version 1.3~rc1.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
fa76077496
commit
50960e34c0
13 changed files with 168 additions and 120 deletions
|
@ -1,3 +1,11 @@
|
||||||
|
2013-05-18 Antonio Diaz Diaz <antonio@gnu.org>
|
||||||
|
|
||||||
|
* Version 1.3-rc1 released.
|
||||||
|
* Decompression time has been reduced by 1%.
|
||||||
|
* main.c (show_header): Show header version if verbosity >= 4.
|
||||||
|
* Ignore option '-n, --threads' for compatibility with plzip.
|
||||||
|
* configure: Options now accept a separate argument.
|
||||||
|
|
||||||
2013-02-18 Antonio Diaz Diaz <ant_diaz@teleline.es>
|
2013-02-18 Antonio Diaz Diaz <ant_diaz@teleline.es>
|
||||||
|
|
||||||
* Version 1.2 released.
|
* Version 1.2 released.
|
||||||
|
|
7
INSTALL
7
INSTALL
|
@ -1,7 +1,7 @@
|
||||||
Requirements
|
Requirements
|
||||||
------------
|
------------
|
||||||
You will need a C compiler.
|
You will need a C compiler.
|
||||||
I use gcc 4.7.2 and 3.3.6, but the code should compile with any
|
I use gcc 4.8.0 and 3.3.6, but the code should compile with any
|
||||||
standards compliant compiler.
|
standards compliant compiler.
|
||||||
Gcc is available at http://gcc.gnu.org.
|
Gcc is available at http://gcc.gnu.org.
|
||||||
|
|
||||||
|
@ -36,8 +36,9 @@ the main archive.
|
||||||
typing 'make install-bin', 'make install-info' or 'make install-man'
|
typing 'make install-bin', 'make install-info' or 'make install-man'
|
||||||
respectively.
|
respectively.
|
||||||
|
|
||||||
5a. Type 'make install-as-lzip' to install the program and any data
|
Instead of 'make install', you can type 'make install-as-lzip' to
|
||||||
files and documentation, and link the program to the name 'lzip'.
|
install the program and any data files and documentation, and link
|
||||||
|
the program to the name 'lzip'.
|
||||||
|
|
||||||
|
|
||||||
Another way
|
Another way
|
||||||
|
|
|
@ -29,8 +29,8 @@ main.o : main.c
|
||||||
|
|
||||||
$(objs) : Makefile
|
$(objs) : Makefile
|
||||||
carg_parser.o : carg_parser.h
|
carg_parser.o : carg_parser.h
|
||||||
decoder.o : lunzip.h decoder.h
|
decoder.o : lzip.h decoder.h
|
||||||
main.o : carg_parser.h lunzip.h decoder.h
|
main.o : carg_parser.h lzip.h decoder.h
|
||||||
|
|
||||||
|
|
||||||
doc : man
|
doc : man
|
||||||
|
|
11
NEWS
11
NEWS
|
@ -1,7 +1,10 @@
|
||||||
Changes in version 1.2:
|
Changes in version 1.3:
|
||||||
|
|
||||||
Decompression time has been reduced by 12%.
|
Decompression time has been reduced by 1%.
|
||||||
|
|
||||||
The target "install-as-lzip" has been added to the Makefile.
|
File version is now shown only if verbosity >= 4.
|
||||||
|
|
||||||
The target "install-bin" has been added to the Makefile.
|
Option "-n, --threads" is now accepted and ignored for compatibility
|
||||||
|
with plzip.
|
||||||
|
|
||||||
|
"configure" now accepts options with a separate argument.
|
||||||
|
|
12
README
12
README
|
@ -5,6 +5,18 @@ small size makes it well suited for embedded devices or software
|
||||||
installers that need to decompress files but do not need compression
|
installers that need to decompress files but do not need compression
|
||||||
capabilities.
|
capabilities.
|
||||||
|
|
||||||
|
Lunzip uses the same well-defined exit status values used by bzip2,
|
||||||
|
which makes it safer when used in pipes or scripts than compressors
|
||||||
|
returning ambiguous warning values, like gzip.
|
||||||
|
|
||||||
|
The 4 factor integrity checking of the lzip format guarantees that the
|
||||||
|
decompressed version of the data is identical to the original. This
|
||||||
|
guards against corruption of the compressed data, and against undetected
|
||||||
|
bugs in lunzip (hopefully very unlikely). The chances of data corruption
|
||||||
|
going undetected are microscopic. Be aware, though, that the check
|
||||||
|
occurs upon decompression, so it can only tell you that something is
|
||||||
|
wrong. It can't help you recover the original uncompressed data.
|
||||||
|
|
||||||
If you ever need to recover data from a damaged lzip file, try the
|
If you ever need to recover data from a damaged lzip file, try the
|
||||||
lziprecover program.
|
lziprecover program.
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/* Arg_parser - POSIX/GNU command line argument parser. (C version)
|
/* Arg_parser - POSIX/GNU command line argument parser. (C version)
|
||||||
Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012
|
Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013
|
||||||
Antonio Diaz Diaz.
|
Antonio Diaz Diaz.
|
||||||
|
|
||||||
This library is free software: you can redistribute it and/or modify
|
This library is free software: you can redistribute it and/or modify
|
||||||
|
@ -89,15 +89,14 @@ static char parse_long_option( struct Arg_parser * const ap,
|
||||||
int * const argindp )
|
int * const argindp )
|
||||||
{
|
{
|
||||||
unsigned len;
|
unsigned len;
|
||||||
int index = -1;
|
int index = -1, i;
|
||||||
int i;
|
|
||||||
char exact = 0, ambig = 0;
|
char exact = 0, ambig = 0;
|
||||||
|
|
||||||
for( len = 0; opt[len+2] && opt[len+2] != '='; ++len ) ;
|
for( len = 0; opt[len+2] && opt[len+2] != '='; ++len ) ;
|
||||||
|
|
||||||
/* Test all long options for either exact match or abbreviated matches. */
|
/* Test all long options for either exact match or abbreviated matches. */
|
||||||
for( i = 0; options[i].code != 0; ++i )
|
for( i = 0; options[i].code != 0; ++i )
|
||||||
if( options[i].name && !strncmp( options[i].name, &opt[2], len ) )
|
if( options[i].name && strncmp( options[i].name, &opt[2], len ) == 0 )
|
||||||
{
|
{
|
||||||
if( strlen( options[i].name ) == len ) /* Exact match found */
|
if( strlen( options[i].name ) == len ) /* Exact match found */
|
||||||
{ index = i; exact = 1; break; }
|
{ index = i; exact = 1; break; }
|
||||||
|
@ -165,8 +164,7 @@ static char parse_short_option( struct Arg_parser * const ap,
|
||||||
|
|
||||||
while( cind > 0 )
|
while( cind > 0 )
|
||||||
{
|
{
|
||||||
int index = -1;
|
int index = -1, i;
|
||||||
int i;
|
|
||||||
const unsigned char code = opt[cind];
|
const unsigned char code = opt[cind];
|
||||||
char code_str[2];
|
char code_str[2];
|
||||||
code_str[0] = code; code_str[1] = 0;
|
code_str[0] = code; code_str[1] = 0;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/* Arg_parser - POSIX/GNU command line argument parser. (C version)
|
/* Arg_parser - POSIX/GNU command line argument parser. (C version)
|
||||||
Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012
|
Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013
|
||||||
Antonio Diaz Diaz.
|
Antonio Diaz Diaz.
|
||||||
|
|
||||||
This library is free software: you can redistribute it and/or modify
|
This library is free software: you can redistribute it and/or modify
|
||||||
|
|
28
configure
vendored
28
configure
vendored
|
@ -5,12 +5,10 @@
|
||||||
# This configure script is free software: you have unlimited permission
|
# This configure script is free software: you have unlimited permission
|
||||||
# to copy, distribute and modify it.
|
# to copy, distribute and modify it.
|
||||||
|
|
||||||
args=
|
|
||||||
no_create=
|
|
||||||
pkgname=lunzip
|
pkgname=lunzip
|
||||||
pkgversion=1.2
|
pkgversion=1.3-rc1
|
||||||
progname=lunzip
|
progname=lunzip
|
||||||
srctrigger=lunzip.h
|
srctrigger=doc/lunzip.1
|
||||||
|
|
||||||
# clear some things potentially inherited from environment.
|
# clear some things potentially inherited from environment.
|
||||||
LC_ALL=C
|
LC_ALL=C
|
||||||
|
@ -36,10 +34,12 @@ if [ ! -x /bin/gcc ] &&
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Loop over all args
|
# Loop over all args
|
||||||
while [ -n "$1" ] ; do
|
args=
|
||||||
|
no_create=
|
||||||
|
while [ $# != 0 ] ; do
|
||||||
|
|
||||||
# Get the first arg, and shuffle
|
# Get the first arg, and shuffle
|
||||||
option=$1
|
option=$1 ; arg2=no
|
||||||
shift
|
shift
|
||||||
|
|
||||||
# Add the argument quoted to args
|
# Add the argument quoted to args
|
||||||
|
@ -74,6 +74,14 @@ while [ -n "$1" ] ; do
|
||||||
--version | -V)
|
--version | -V)
|
||||||
echo "Configure script for ${pkgname} version ${pkgversion}"
|
echo "Configure script for ${pkgname} version ${pkgversion}"
|
||||||
exit 0 ;;
|
exit 0 ;;
|
||||||
|
--srcdir) srcdir=$1 ; arg2=yes ;;
|
||||||
|
--prefix) prefix=$1 ; arg2=yes ;;
|
||||||
|
--exec-prefix) exec_prefix=$1 ; arg2=yes ;;
|
||||||
|
--bindir) bindir=$1 ; arg2=yes ;;
|
||||||
|
--datarootdir) datarootdir=$1 ; arg2=yes ;;
|
||||||
|
--infodir) infodir=$1 ; arg2=yes ;;
|
||||||
|
--mandir) mandir=$1 ; arg2=yes ;;
|
||||||
|
|
||||||
--srcdir=*) srcdir=${optarg} ;;
|
--srcdir=*) srcdir=${optarg} ;;
|
||||||
--prefix=*) prefix=${optarg} ;;
|
--prefix=*) prefix=${optarg} ;;
|
||||||
--exec-prefix=*) exec_prefix=${optarg} ;;
|
--exec-prefix=*) exec_prefix=${optarg} ;;
|
||||||
|
@ -93,6 +101,14 @@ while [ -n "$1" ] ; do
|
||||||
echo "configure: Unrecognized option: \"${option}\"; use --help for usage." 1>&2
|
echo "configure: Unrecognized option: \"${option}\"; use --help for usage." 1>&2
|
||||||
exit 1 ;;
|
exit 1 ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
# Check if the option took a separate argument
|
||||||
|
if [ "${arg2}" = yes ] ; then
|
||||||
|
if [ $# != 0 ] ; then args="${args} \"$1\"" ; shift
|
||||||
|
else echo "configure: Missing argument to \"${option}\"" 1>&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# Find the source files, if location was not specified.
|
# Find the source files, if location was not specified.
|
||||||
|
|
69
decoder.c
69
decoder.c
|
@ -25,7 +25,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "lunzip.h"
|
#include "lzip.h"
|
||||||
#include "decoder.h"
|
#include "decoder.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -124,10 +124,10 @@ bool LZd_verify_trailer( struct LZ_decoder * const decoder,
|
||||||
File_trailer trailer;
|
File_trailer trailer;
|
||||||
const int trailer_size = Ft_versioned_size( decoder->member_version );
|
const int trailer_size = Ft_versioned_size( decoder->member_version );
|
||||||
const unsigned long long member_size =
|
const unsigned long long member_size =
|
||||||
Rd_member_position( decoder->range_decoder ) + trailer_size;
|
Rd_member_position( decoder->rdec ) + trailer_size;
|
||||||
bool error = false;
|
bool error = false;
|
||||||
|
|
||||||
int size = Rd_read_data( decoder->range_decoder, trailer, trailer_size );
|
int size = Rd_read_data( decoder->rdec, trailer, trailer_size );
|
||||||
if( size < trailer_size )
|
if( size < trailer_size )
|
||||||
{
|
{
|
||||||
error = true;
|
error = true;
|
||||||
|
@ -139,8 +139,10 @@ bool LZd_verify_trailer( struct LZ_decoder * const decoder,
|
||||||
}
|
}
|
||||||
while( size < trailer_size ) trailer[size++] = 0;
|
while( size < trailer_size ) trailer[size++] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( decoder->member_version == 0 ) Ft_set_member_size( trailer, member_size );
|
if( decoder->member_version == 0 ) Ft_set_member_size( trailer, member_size );
|
||||||
if( decoder->range_decoder->code != 0 )
|
|
||||||
|
if( decoder->rdec->code != 0 )
|
||||||
{
|
{
|
||||||
error = true;
|
error = true;
|
||||||
Pp_show_msg( pp, "Range decoder final code is not zero" );
|
Pp_show_msg( pp, "Range decoder final code is not zero" );
|
||||||
|
@ -175,7 +177,7 @@ bool LZd_verify_trailer( struct LZ_decoder * const decoder,
|
||||||
Ft_get_member_size( trailer ), member_size, member_size );
|
Ft_get_member_size( trailer ), member_size, member_size );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if( !error && pp->verbosity >= 3 && LZd_data_position( decoder ) > 0 && member_size > 0 )
|
if( !error && pp->verbosity >= 2 && LZd_data_position( decoder ) > 0 && member_size > 0 )
|
||||||
fprintf( stderr, "%6.3f:1, %6.3f bits/byte, %5.2f%% saved. ",
|
fprintf( stderr, "%6.3f:1, %6.3f bits/byte, %5.2f%% saved. ",
|
||||||
(double)LZd_data_position( decoder ) / member_size,
|
(double)LZd_data_position( decoder ) / member_size,
|
||||||
( 8.0 * member_size ) / LZd_data_position( decoder ),
|
( 8.0 * member_size ) / LZd_data_position( decoder ),
|
||||||
|
@ -193,88 +195,87 @@ bool LZd_verify_trailer( struct LZ_decoder * const decoder,
|
||||||
int LZd_decode_member( struct LZ_decoder * const decoder,
|
int LZd_decode_member( struct LZ_decoder * const decoder,
|
||||||
struct Pretty_print * const pp )
|
struct Pretty_print * const pp )
|
||||||
{
|
{
|
||||||
|
struct Range_decoder * const rdec = decoder->rdec;
|
||||||
unsigned rep0 = 0; /* rep[0-3] latest four distances */
|
unsigned rep0 = 0; /* rep[0-3] latest four distances */
|
||||||
unsigned rep1 = 0; /* used for efficient coding of */
|
unsigned rep1 = 0; /* used for efficient coding of */
|
||||||
unsigned rep2 = 0; /* repeated distances */
|
unsigned rep2 = 0; /* repeated distances */
|
||||||
unsigned rep3 = 0;
|
unsigned rep3 = 0;
|
||||||
|
|
||||||
State state = 0;
|
State state = 0;
|
||||||
Rd_load( decoder->range_decoder );
|
|
||||||
|
|
||||||
while( !Rd_finished( decoder->range_decoder ) )
|
Rd_load( rdec );
|
||||||
|
while( !Rd_finished( rdec ) )
|
||||||
{
|
{
|
||||||
const int pos_state = LZd_data_position( decoder ) & pos_state_mask;
|
const int pos_state = LZd_data_position( decoder ) & pos_state_mask;
|
||||||
if( Rd_decode_bit( decoder->range_decoder, &decoder->bm_match[state][pos_state] ) == 0 )
|
if( Rd_decode_bit( rdec, &decoder->bm_match[state][pos_state] ) == 0 ) /* 1st bit */
|
||||||
{
|
{
|
||||||
const uint8_t prev_byte = LZd_get_prev_byte( decoder );
|
const uint8_t prev_byte = LZd_get_prev_byte( decoder );
|
||||||
if( St_is_char( state ) )
|
if( St_is_char( state ) )
|
||||||
{
|
{
|
||||||
state -= ( state < 4 ) ? state : 3;
|
state -= ( state < 4 ) ? state : 3;
|
||||||
LZd_put_byte( decoder, Rd_decode_tree( decoder->range_decoder,
|
LZd_put_byte( decoder, Rd_decode_tree( rdec,
|
||||||
decoder->bm_literal[get_lit_state(prev_byte)], 8 ) );
|
decoder->bm_literal[get_lit_state(prev_byte)], 8 ) );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
state -= ( state < 10 ) ? 3 : 6;
|
state -= ( state < 10 ) ? 3 : 6;
|
||||||
LZd_put_byte( decoder, Rd_decode_matched( decoder->range_decoder,
|
LZd_put_byte( decoder, Rd_decode_matched( rdec,
|
||||||
decoder->bm_literal[get_lit_state(prev_byte)], LZd_get_byte( decoder, rep0 ) ) );
|
decoder->bm_literal[get_lit_state(prev_byte)],
|
||||||
|
LZd_get_byte( decoder, rep0 ) ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int len;
|
int len;
|
||||||
if( Rd_decode_bit( decoder->range_decoder, &decoder->bm_rep[state] ) == 1 )
|
if( Rd_decode_bit( rdec, &decoder->bm_rep[state] ) == 1 ) /* 2nd bit */
|
||||||
{
|
{
|
||||||
len = 0;
|
if( Rd_decode_bit( rdec, &decoder->bm_rep0[state] ) == 0 ) /* 3rd bit */
|
||||||
if( Rd_decode_bit( decoder->range_decoder, &decoder->bm_rep0[state] ) == 1 )
|
{
|
||||||
|
if( Rd_decode_bit( rdec, &decoder->bm_len[state][pos_state] ) == 0 ) /* 4th bit */
|
||||||
|
{ state = St_set_short_rep( state );
|
||||||
|
LZd_put_byte( decoder, LZd_get_byte( decoder, rep0 ) ); continue; }
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
unsigned distance;
|
unsigned distance;
|
||||||
if( Rd_decode_bit( decoder->range_decoder, &decoder->bm_rep1[state] ) == 0 )
|
if( Rd_decode_bit( rdec, &decoder->bm_rep1[state] ) == 0 ) /* 4th bit */
|
||||||
distance = rep1;
|
distance = rep1;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if( Rd_decode_bit( decoder->range_decoder, &decoder->bm_rep2[state] ) == 0 )
|
if( Rd_decode_bit( rdec, &decoder->bm_rep2[state] ) == 0 ) /* 5th bit */
|
||||||
distance = rep2;
|
distance = rep2;
|
||||||
else { distance = rep3; rep3 = rep2; }
|
else
|
||||||
|
{ distance = rep3; rep3 = rep2; }
|
||||||
rep2 = rep1;
|
rep2 = rep1;
|
||||||
}
|
}
|
||||||
rep1 = rep0;
|
rep1 = rep0;
|
||||||
rep0 = distance;
|
rep0 = distance;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
if( Rd_decode_bit( decoder->range_decoder, &decoder->bm_len[state][pos_state] ) == 0 )
|
|
||||||
{ state = St_set_short_rep( state ); len = 1; }
|
|
||||||
}
|
|
||||||
if( len == 0 )
|
|
||||||
{
|
|
||||||
state = St_set_rep( state );
|
state = St_set_rep( state );
|
||||||
len = min_match_len + Led_decode( &decoder->rep_match_len_decoder, decoder->range_decoder, pos_state );
|
len = min_match_len + Rd_decode_len( rdec, &decoder->rep_len_model, pos_state );
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int dis_slot;
|
int dis_slot;
|
||||||
const unsigned rep0_saved = rep0;
|
const unsigned rep0_saved = rep0;
|
||||||
len = min_match_len + Led_decode( &decoder->len_decoder, decoder->range_decoder, pos_state );
|
len = min_match_len + Rd_decode_len( rdec, &decoder->match_len_model, pos_state );
|
||||||
dis_slot = Rd_decode_tree6( decoder->range_decoder, decoder->bm_dis_slot[get_dis_state(len)] );
|
dis_slot = Rd_decode_tree6( rdec, decoder->bm_dis_slot[get_dis_state(len)] );
|
||||||
if( dis_slot < start_dis_model ) rep0 = dis_slot;
|
if( dis_slot < start_dis_model ) rep0 = dis_slot;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const int direct_bits = ( dis_slot >> 1 ) - 1;
|
const int direct_bits = ( dis_slot >> 1 ) - 1;
|
||||||
rep0 = ( 2 | ( dis_slot & 1 ) ) << direct_bits;
|
rep0 = ( 2 | ( dis_slot & 1 ) ) << direct_bits;
|
||||||
if( dis_slot < end_dis_model )
|
if( dis_slot < end_dis_model )
|
||||||
rep0 += Rd_decode_tree_reversed( decoder->range_decoder,
|
rep0 += Rd_decode_tree_reversed( rdec,
|
||||||
decoder->bm_dis + rep0 - dis_slot - 1,
|
decoder->bm_dis + rep0 - dis_slot - 1,
|
||||||
direct_bits );
|
direct_bits );
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
rep0 += Rd_decode( decoder->range_decoder, direct_bits - dis_align_bits ) << dis_align_bits;
|
rep0 += Rd_decode( rdec, direct_bits - dis_align_bits ) << dis_align_bits;
|
||||||
rep0 += Rd_decode_tree_reversed4( decoder->range_decoder, decoder->bm_align );
|
rep0 += Rd_decode_tree_reversed4( rdec, decoder->bm_align );
|
||||||
if( rep0 == 0xFFFFFFFFU ) /* Marker found */
|
if( rep0 == 0xFFFFFFFFU ) /* Marker found */
|
||||||
{
|
{
|
||||||
rep0 = rep0_saved;
|
rep0 = rep0_saved;
|
||||||
Rd_normalize( decoder->range_decoder );
|
Rd_normalize( rdec );
|
||||||
LZd_flush_data( decoder );
|
LZd_flush_data( decoder );
|
||||||
if( len == min_match_len ) /* End Of Stream marker */
|
if( len == min_match_len ) /* End Of Stream marker */
|
||||||
{
|
{
|
||||||
|
@ -282,7 +283,7 @@ int LZd_decode_member( struct LZ_decoder * const decoder,
|
||||||
}
|
}
|
||||||
if( len == min_match_len + 1 ) /* Sync Flush marker */
|
if( len == min_match_len + 1 ) /* Sync Flush marker */
|
||||||
{
|
{
|
||||||
Rd_load( decoder->range_decoder ); continue;
|
Rd_load( rdec ); continue;
|
||||||
}
|
}
|
||||||
if( pp->verbosity >= 0 )
|
if( pp->verbosity >= 0 )
|
||||||
{
|
{
|
||||||
|
|
69
decoder.h
69
decoder.h
|
@ -140,24 +140,24 @@ static inline int Rd_decode_bit( struct Range_decoder * const rdec,
|
||||||
static inline int Rd_decode_tree( struct Range_decoder * const rdec,
|
static inline int Rd_decode_tree( struct Range_decoder * const rdec,
|
||||||
Bit_model bm[], const int num_bits )
|
Bit_model bm[], const int num_bits )
|
||||||
{
|
{
|
||||||
int model = 1;
|
int symbol = 1;
|
||||||
int i;
|
int i;
|
||||||
for( i = num_bits; i > 0; --i )
|
for( i = num_bits; i > 0; --i )
|
||||||
model = ( model << 1 ) | Rd_decode_bit( rdec, &bm[model] );
|
symbol = ( symbol << 1 ) | Rd_decode_bit( rdec, &bm[symbol] );
|
||||||
return model - (1 << num_bits);
|
return symbol - (1 << num_bits);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int Rd_decode_tree6( struct Range_decoder * const rdec,
|
static inline int Rd_decode_tree6( struct Range_decoder * const rdec,
|
||||||
Bit_model bm[] )
|
Bit_model bm[] )
|
||||||
{
|
{
|
||||||
int model = 1;
|
int symbol = 1;
|
||||||
model = ( model << 1 ) | Rd_decode_bit( rdec, &bm[model] );
|
symbol = ( symbol << 1 ) | Rd_decode_bit( rdec, &bm[symbol] );
|
||||||
model = ( model << 1 ) | Rd_decode_bit( rdec, &bm[model] );
|
symbol = ( symbol << 1 ) | Rd_decode_bit( rdec, &bm[symbol] );
|
||||||
model = ( model << 1 ) | Rd_decode_bit( rdec, &bm[model] );
|
symbol = ( symbol << 1 ) | Rd_decode_bit( rdec, &bm[symbol] );
|
||||||
model = ( model << 1 ) | Rd_decode_bit( rdec, &bm[model] );
|
symbol = ( symbol << 1 ) | Rd_decode_bit( rdec, &bm[symbol] );
|
||||||
model = ( model << 1 ) | Rd_decode_bit( rdec, &bm[model] );
|
symbol = ( symbol << 1 ) | Rd_decode_bit( rdec, &bm[symbol] );
|
||||||
model = ( model << 1 ) | Rd_decode_bit( rdec, &bm[model] );
|
symbol = ( symbol << 1 ) | Rd_decode_bit( rdec, &bm[symbol] );
|
||||||
return model - (1 << 6);
|
return symbol - (1 << 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int Rd_decode_tree_reversed( struct Range_decoder * const rdec,
|
static inline int Rd_decode_tree_reversed( struct Range_decoder * const rdec,
|
||||||
|
@ -213,36 +213,17 @@ static inline int Rd_decode_matched( struct Range_decoder * const rdec,
|
||||||
return symbol - 0x100;
|
return symbol - 0x100;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline int Rd_decode_len( struct Range_decoder * const rdec,
|
||||||
struct Len_decoder
|
struct Len_model * const lm,
|
||||||
{
|
|
||||||
Bit_model choice1;
|
|
||||||
Bit_model choice2;
|
|
||||||
Bit_model bm_low[pos_states][len_low_symbols];
|
|
||||||
Bit_model bm_mid[pos_states][len_mid_symbols];
|
|
||||||
Bit_model bm_high[len_high_symbols];
|
|
||||||
};
|
|
||||||
|
|
||||||
static inline void Led_init( struct Len_decoder * const len_decoder )
|
|
||||||
{
|
|
||||||
Bm_init( &len_decoder->choice1 );
|
|
||||||
Bm_init( &len_decoder->choice2 );
|
|
||||||
Bm_array_init( len_decoder->bm_low[0], pos_states * len_low_symbols );
|
|
||||||
Bm_array_init( len_decoder->bm_mid[0], pos_states * len_mid_symbols );
|
|
||||||
Bm_array_init( len_decoder->bm_high, len_high_symbols );
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline int Led_decode( struct Len_decoder * const len_decoder,
|
|
||||||
struct Range_decoder * const rdec,
|
|
||||||
const int pos_state )
|
const int pos_state )
|
||||||
{
|
{
|
||||||
if( Rd_decode_bit( rdec, &len_decoder->choice1 ) == 0 )
|
if( Rd_decode_bit( rdec, &lm->choice1 ) == 0 )
|
||||||
return Rd_decode_tree( rdec, len_decoder->bm_low[pos_state], len_low_bits );
|
return Rd_decode_tree( rdec, lm->bm_low[pos_state], len_low_bits );
|
||||||
if( Rd_decode_bit( rdec, &len_decoder->choice2 ) == 0 )
|
if( Rd_decode_bit( rdec, &lm->choice2 ) == 0 )
|
||||||
return len_low_symbols +
|
return len_low_symbols +
|
||||||
Rd_decode_tree( rdec, len_decoder->bm_mid[pos_state], len_mid_bits );
|
Rd_decode_tree( rdec, lm->bm_mid[pos_state], len_mid_bits );
|
||||||
return len_low_symbols + len_mid_symbols +
|
return len_low_symbols + len_mid_symbols +
|
||||||
Rd_decode_tree( rdec, len_decoder->bm_high, len_high_bits );
|
Rd_decode_tree( rdec, lm->bm_high, len_high_bits );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -269,9 +250,9 @@ struct LZ_decoder
|
||||||
Bit_model bm_dis[modeled_distances-end_dis_model];
|
Bit_model bm_dis[modeled_distances-end_dis_model];
|
||||||
Bit_model bm_align[dis_align_size];
|
Bit_model bm_align[dis_align_size];
|
||||||
|
|
||||||
struct Range_decoder * range_decoder;
|
struct Range_decoder * rdec;
|
||||||
struct Len_decoder len_decoder;
|
struct Len_model match_len_model;
|
||||||
struct Len_decoder rep_match_len_decoder;
|
struct Len_model rep_len_model;
|
||||||
};
|
};
|
||||||
|
|
||||||
void LZd_flush_data( struct LZ_decoder * const decoder );
|
void LZd_flush_data( struct LZ_decoder * const decoder );
|
||||||
|
@ -322,7 +303,7 @@ static inline void LZd_copy_block( struct LZ_decoder * const decoder,
|
||||||
|
|
||||||
static inline bool LZd_init( struct LZ_decoder * const decoder,
|
static inline bool LZd_init( struct LZ_decoder * const decoder,
|
||||||
const File_header header,
|
const File_header header,
|
||||||
struct Range_decoder * const rdec, const int ofd )
|
struct Range_decoder * const rde, const int ofd )
|
||||||
{
|
{
|
||||||
decoder->partial_data_pos = 0;
|
decoder->partial_data_pos = 0;
|
||||||
decoder->dictionary_size = Fh_get_dictionary_size( header );
|
decoder->dictionary_size = Fh_get_dictionary_size( header );
|
||||||
|
@ -346,9 +327,9 @@ static inline bool LZd_init( struct LZ_decoder * const decoder,
|
||||||
Bm_array_init( decoder->bm_dis, modeled_distances - end_dis_model );
|
Bm_array_init( decoder->bm_dis, modeled_distances - end_dis_model );
|
||||||
Bm_array_init( decoder->bm_align, dis_align_size );
|
Bm_array_init( decoder->bm_align, dis_align_size );
|
||||||
|
|
||||||
decoder->range_decoder = rdec;
|
decoder->rdec = rde;
|
||||||
Led_init( &decoder->len_decoder );
|
Lm_init( &decoder->match_len_model );
|
||||||
Led_init( &decoder->rep_match_len_decoder );
|
Lm_init( &decoder->rep_len_model );
|
||||||
decoder->buffer[decoder->buffer_size-1] = 0; /* prev_byte of first_byte */
|
decoder->buffer[decoder->buffer_size-1] = 0; /* prev_byte of first_byte */
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.37.1.
|
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.37.1.
|
||||||
.TH LUNZIP "1" "February 2013" "Lunzip 1.2" "User Commands"
|
.TH LUNZIP "1" "May 2013" "Lunzip 1.3-rc1" "User Commands"
|
||||||
.SH NAME
|
.SH NAME
|
||||||
Lunzip \- small decompressor for lzip files
|
Lunzip \- small decompressor for lzip files
|
||||||
.SH SYNOPSIS
|
.SH SYNOPSIS
|
||||||
|
@ -41,6 +41,11 @@ be verbose (a 2nd \fB\-v\fR gives more)
|
||||||
.PP
|
.PP
|
||||||
If no file names are given, lunzip decompresses from standard input to
|
If no file names are given, lunzip decompresses from standard input to
|
||||||
standard output.
|
standard output.
|
||||||
|
.PP
|
||||||
|
Exit status: 0 for a normal exit, 1 for environmental problems (file
|
||||||
|
not found, invalid flags, I/O errors, etc), 2 to indicate a corrupt or
|
||||||
|
invalid input file, 3 for an internal consistency error (eg, bug) which
|
||||||
|
caused lunzip to panic.
|
||||||
.SH "REPORTING BUGS"
|
.SH "REPORTING BUGS"
|
||||||
Report bugs to lzip\-bug@nongnu.org
|
Report bugs to lzip\-bug@nongnu.org
|
||||||
.br
|
.br
|
||||||
|
|
|
@ -57,7 +57,7 @@ enum {
|
||||||
dis_slot_bits = 6,
|
dis_slot_bits = 6,
|
||||||
start_dis_model = 4,
|
start_dis_model = 4,
|
||||||
end_dis_model = 14,
|
end_dis_model = 14,
|
||||||
modeled_distances = 1 << (end_dis_model / 2),
|
modeled_distances = 1 << (end_dis_model / 2), /* 128 */
|
||||||
dis_align_bits = 4,
|
dis_align_bits = 4,
|
||||||
dis_align_size = 1 << dis_align_bits,
|
dis_align_size = 1 << dis_align_bits,
|
||||||
|
|
||||||
|
@ -94,6 +94,24 @@ static inline void Bm_init( Bit_model * const probability )
|
||||||
static inline void Bm_array_init( Bit_model * const p, const int size )
|
static inline void Bm_array_init( Bit_model * const p, const int size )
|
||||||
{ int i = 0; while( i < size ) p[i++] = bit_model_total / 2; }
|
{ int i = 0; while( i < size ) p[i++] = bit_model_total / 2; }
|
||||||
|
|
||||||
|
struct Len_model
|
||||||
|
{
|
||||||
|
Bit_model choice1;
|
||||||
|
Bit_model choice2;
|
||||||
|
Bit_model bm_low[pos_states][len_low_symbols];
|
||||||
|
Bit_model bm_mid[pos_states][len_mid_symbols];
|
||||||
|
Bit_model bm_high[len_high_symbols];
|
||||||
|
};
|
||||||
|
|
||||||
|
static inline void Lm_init( struct Len_model * const lm )
|
||||||
|
{
|
||||||
|
Bm_init( &lm->choice1 );
|
||||||
|
Bm_init( &lm->choice2 );
|
||||||
|
Bm_array_init( lm->bm_low[0], pos_states * len_low_symbols );
|
||||||
|
Bm_array_init( lm->bm_mid[0], pos_states * len_mid_symbols );
|
||||||
|
Bm_array_init( lm->bm_high, len_high_symbols );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
struct Pretty_print
|
struct Pretty_print
|
||||||
{
|
{
|
||||||
|
@ -138,11 +156,11 @@ static inline void CRC32_init( void )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void CRC32_update_byte( uint32_t * crc, const uint8_t byte )
|
static inline void CRC32_update_byte( uint32_t * const crc, const uint8_t byte )
|
||||||
{ *crc = crc32[(*crc^byte)&0xFF] ^ ( *crc >> 8 ); }
|
{ *crc = crc32[(*crc^byte)&0xFF] ^ ( *crc >> 8 ); }
|
||||||
|
|
||||||
static inline void CRC32_update_buf( uint32_t * crc, const uint8_t * const buffer,
|
static inline void CRC32_update_buf( uint32_t * const crc,
|
||||||
const int size )
|
const uint8_t * const buffer, const int size )
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for( i = 0; i < size; ++i )
|
for( i = 0; i < size; ++i )
|
||||||
|
@ -177,11 +195,11 @@ static inline uint8_t Fh_version( const File_header data )
|
||||||
static inline bool Fh_verify_version( const File_header data )
|
static inline bool Fh_verify_version( const File_header data )
|
||||||
{ return ( data[4] <= 1 ); }
|
{ return ( data[4] <= 1 ); }
|
||||||
|
|
||||||
static inline int Fh_get_dictionary_size( const File_header data )
|
static inline unsigned Fh_get_dictionary_size( const File_header data )
|
||||||
{
|
{
|
||||||
int sz = ( 1 << ( data[5] & 0x1F ) );
|
unsigned sz = ( 1 << ( data[5] & 0x1F ) );
|
||||||
if( sz > min_dictionary_size && sz <= max_dictionary_size )
|
if( sz > min_dictionary_size )
|
||||||
sz -= ( sz / 16 ) * ( ( data[5] >> 5 ) & 0x07 );
|
sz -= ( sz / 16 ) * ( ( data[5] >> 5 ) & 7 );
|
||||||
return sz;
|
return sz;
|
||||||
}
|
}
|
||||||
|
|
23
main.c
23
main.c
|
@ -15,7 +15,7 @@
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
Return values: 0 for a normal exit, 1 for environmental problems
|
Exit status: 0 for a normal exit, 1 for environmental problems
|
||||||
(file not found, invalid flags, I/O errors, etc), 2 to indicate a
|
(file not found, invalid flags, I/O errors, etc), 2 to indicate a
|
||||||
corrupt or invalid input file, 3 for an internal consistency error
|
corrupt or invalid input file, 3 for an internal consistency error
|
||||||
(eg, bug) which caused lunzip to panic.
|
(eg, bug) which caused lunzip to panic.
|
||||||
|
@ -51,7 +51,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "carg_parser.h"
|
#include "carg_parser.h"
|
||||||
#include "lunzip.h"
|
#include "lzip.h"
|
||||||
#include "decoder.h"
|
#include "decoder.h"
|
||||||
|
|
||||||
#if CHAR_BIT != 8
|
#if CHAR_BIT != 8
|
||||||
|
@ -101,6 +101,10 @@ static void show_help( void )
|
||||||
" -v, --verbose be verbose (a 2nd -v gives more)\n"
|
" -v, --verbose be verbose (a 2nd -v gives more)\n"
|
||||||
"If no file names are given, lunzip decompresses from standard input to\n"
|
"If no file names are given, lunzip decompresses from standard input to\n"
|
||||||
"standard output.\n"
|
"standard output.\n"
|
||||||
|
"\nExit status: 0 for a normal exit, 1 for environmental problems (file\n"
|
||||||
|
"not found, invalid flags, I/O errors, etc), 2 to indicate a corrupt or\n"
|
||||||
|
"invalid input file, 3 for an internal consistency error (eg, bug) which\n"
|
||||||
|
"caused lunzip to panic.\n"
|
||||||
"\nReport bugs to lzip-bug@nongnu.org\n"
|
"\nReport bugs to lzip-bug@nongnu.org\n"
|
||||||
"Lunzip home page: http://www.nongnu.org/lzip/lunzip.html\n" );
|
"Lunzip home page: http://www.nongnu.org/lzip/lunzip.html\n" );
|
||||||
}
|
}
|
||||||
|
@ -129,8 +133,9 @@ void show_header( const File_header header )
|
||||||
for( i = 0; i < 8 && ( num > 9999 || ( exact && num >= factor ) ); ++i )
|
for( i = 0; i < 8 && ( num > 9999 || ( exact && num >= factor ) ); ++i )
|
||||||
{ num /= factor; if( num % factor != 0 ) exact = false;
|
{ num /= factor; if( num % factor != 0 ) exact = false;
|
||||||
p = prefix[i]; np = ""; }
|
p = prefix[i]; np = ""; }
|
||||||
fprintf( stderr, "version %d, dictionary size %s%4u %sB. ",
|
if( verbosity >= 4 )
|
||||||
Fh_version( header ), np, num, p );
|
fprintf( stderr, "version %d, ", Fh_version( header ) );
|
||||||
|
fprintf( stderr, "dictionary size %s%4u %sB. ", np, num, p );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -326,7 +331,7 @@ static int decompress( const int infd, struct Pretty_print * const pp,
|
||||||
retval = 2; break; }
|
retval = 2; break; }
|
||||||
|
|
||||||
if( verbosity >= 2 || ( verbosity == 1 && first_member ) )
|
if( verbosity >= 2 || ( verbosity == 1 && first_member ) )
|
||||||
{ Pp_show_msg( pp, 0 ); if( verbosity >= 2 ) show_header( header ); }
|
{ Pp_show_msg( pp, 0 ); if( verbosity >= 3 ) show_header( header ); }
|
||||||
|
|
||||||
if( !LZd_init( &decoder, header, &rdec, outfd ) )
|
if( !LZd_init( &decoder, header, &rdec, outfd ) )
|
||||||
{
|
{
|
||||||
|
@ -350,13 +355,11 @@ static int decompress( const int infd, struct Pretty_print * const pp,
|
||||||
retval = 2; break;
|
retval = 2; break;
|
||||||
}
|
}
|
||||||
if( verbosity >= 2 )
|
if( verbosity >= 2 )
|
||||||
{ if( testing ) fprintf( stderr, "ok\n" );
|
{ fprintf( stderr, testing ? "ok\n" : "done\n" ); Pp_reset( pp ); }
|
||||||
else fprintf( stderr, "done\n" ); Pp_reset( pp ); }
|
|
||||||
}
|
}
|
||||||
Rd_free( &rdec );
|
Rd_free( &rdec );
|
||||||
if( verbosity == 1 && retval == 0 )
|
if( verbosity == 1 && retval == 0 )
|
||||||
{ if( testing ) fprintf( stderr, "ok\n" );
|
fprintf( stderr, testing ? "ok\n" : "done\n" );
|
||||||
else fprintf( stderr, "done\n" ); }
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -448,6 +451,7 @@ int main( const int argc, const char * const argv[] )
|
||||||
{ 'f', "force", ap_no },
|
{ 'f', "force", ap_no },
|
||||||
{ 'h', "help", ap_no },
|
{ 'h', "help", ap_no },
|
||||||
{ 'k', "keep", ap_no },
|
{ 'k', "keep", ap_no },
|
||||||
|
{ 'n', "threads", ap_yes },
|
||||||
{ 'o', "output", ap_yes },
|
{ 'o', "output", ap_yes },
|
||||||
{ 'q', "quiet", ap_no },
|
{ 'q', "quiet", ap_no },
|
||||||
{ 't', "test", ap_no },
|
{ 't', "test", ap_no },
|
||||||
|
@ -477,6 +481,7 @@ int main( const int argc, const char * const argv[] )
|
||||||
case 'f': force = true; break;
|
case 'f': force = true; break;
|
||||||
case 'h': show_help(); return 0;
|
case 'h': show_help(); return 0;
|
||||||
case 'k': keep_input_files = true; break;
|
case 'k': keep_input_files = true; break;
|
||||||
|
case 'n': break;
|
||||||
case 'o': default_output_filename = arg; break;
|
case 'o': default_output_filename = arg; break;
|
||||||
case 'q': verbosity = -1; break;
|
case 'q': verbosity = -1; break;
|
||||||
case 't': testing = true; break;
|
case 't': testing = true; break;
|
||||||
|
|
Loading…
Add table
Reference in a new issue