Merging upstream version 1.15~rc1.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
5fdbdd44aa
commit
ae3eafc693
27 changed files with 724 additions and 791 deletions
37
ChangeLog
37
ChangeLog
|
@ -1,9 +1,18 @@
|
||||||
|
2024-11-19 Antonio Diaz Diaz <antonio@gnu.org>
|
||||||
|
|
||||||
|
* Version 1.15-rc1 released.
|
||||||
|
* lzlib.h: Declare LZ_Errno, LZ_Encoder, and LZ_Decoder as typedef.
|
||||||
|
* configure, Makefile.in: Use '--soname' conditionally.
|
||||||
|
* check.sh: Use 'cp' instead of 'cat'.
|
||||||
|
|
||||||
2024-10-16 Antonio Diaz Diaz <antonio@gnu.org>
|
2024-10-16 Antonio Diaz Diaz <antonio@gnu.org>
|
||||||
|
|
||||||
* Version 1.15-pre2 released.
|
* Version 1.15-pre2 released.
|
||||||
* decoder.h (Rd_try_reload): Reject a nonzero first LZMA byte.
|
* decoder.h (Rd_try_reload): Reject a nonzero first LZMA byte.
|
||||||
* minilzip.c (do_decompress): Reject empty member in multimember.
|
* minilzip.c (do_decompress): Reject empty member in multimember.
|
||||||
|
(Pp_free): New function.
|
||||||
* configure, Makefile.in: Don't use '--soname'; create 'liblz.so.1'.
|
* configure, Makefile.in: Don't use '--soname'; create 'liblz.so.1'.
|
||||||
|
(Reported by Michael Sullivan).
|
||||||
|
|
||||||
2024-04-19 Antonio Diaz Diaz <antonio@gnu.org>
|
2024-04-19 Antonio Diaz Diaz <antonio@gnu.org>
|
||||||
|
|
||||||
|
@ -49,8 +58,8 @@
|
||||||
* encoder_base.c (LZeb_try_sync_flush):
|
* encoder_base.c (LZeb_try_sync_flush):
|
||||||
Compensate for the increase in 'rd_min_available_bytes'.
|
Compensate for the increase in 'rd_min_available_bytes'.
|
||||||
* main.c (do_decompress): Fix false report about library stall.
|
* main.c (do_decompress): Fix false report about library stall.
|
||||||
* main.c: New option '--check-lib'.
|
New option '--check-lib'.
|
||||||
* main.c (main): Report an error if a file name is empty.
|
(main): Report an error if a file name is empty.
|
||||||
Make '-o' behave like '-c', but writing to file instead of stdout.
|
Make '-o' behave like '-c', but writing to file instead of stdout.
|
||||||
Make '-c' and '-o' check whether the output is a terminal only once.
|
Make '-c' and '-o' check whether the output is a terminal only once.
|
||||||
Do not open output if input is a terminal.
|
Do not open output if input is a terminal.
|
||||||
|
@ -99,11 +108,11 @@
|
||||||
(Older versions can adjust dictionary size only once).
|
(Older versions can adjust dictionary size only once).
|
||||||
* lzlib.c (LZ_decompress_read): Detect corrupt header with HD=3.
|
* lzlib.c (LZ_decompress_read): Detect corrupt header with HD=3.
|
||||||
* main.c: New option '--loose-trailing'.
|
* main.c: New option '--loose-trailing'.
|
||||||
* main.c (main): Option '-S, --volume-size' now keeps input files.
|
(main): Make option '-S, --volume-size' keep input files.
|
||||||
* main.c: Replace 'bits/byte' with inverse compression ratio.
|
Replace 'bits/byte' with inverse compression ratio in output.
|
||||||
* main.c: Show final diagnostic when testing multiple files.
|
(main): Show final diagnostic when testing multiple files.
|
||||||
* main.c: Do not add a second .lz extension to the arg of -o.
|
(set_c_outname): Do not add a second '.lz' to the arg of '-o'.
|
||||||
* main.c: Show dictionary size at verbosity level 4 (-vvvv).
|
(do_decompress): Show dictionary size at verbosity level 4 (-vvvv).
|
||||||
* lzlib.texi: New chapter 'Invoking minilzip'.
|
* lzlib.texi: New chapter 'Invoking minilzip'.
|
||||||
|
|
||||||
2017-04-11 Antonio Diaz Diaz <antonio@gnu.org>
|
2017-04-11 Antonio Diaz Diaz <antonio@gnu.org>
|
||||||
|
@ -122,12 +131,11 @@
|
||||||
* lzlib.c (LZ_decompress_sync_to_member): Add skipped size to in_size.
|
* lzlib.c (LZ_decompress_sync_to_member): Add skipped size to in_size.
|
||||||
* decoder.c (LZd_verify_trailer): Remove test of final code.
|
* decoder.c (LZd_verify_trailer): Remove test of final code.
|
||||||
* main.c: New option '-a, --trailing-error'.
|
* main.c: New option '-a, --trailing-error'.
|
||||||
* main.c (main): Delete '--output' file if infd is a terminal.
|
(main): Delete '--output' file if infd is a terminal.
|
||||||
* main.c (main): Don't use stdin more than once.
|
(main): Don't use stdin more than once.
|
||||||
* configure: Avoid warning on some shells when testing for gcc.
|
* configure: Avoid warning on some shells when testing for gcc.
|
||||||
* Makefile.in: Detect the existence of install-info.
|
* Makefile.in: Detect the existence of install-info.
|
||||||
* check.sh: A POSIX shell is required to run the tests.
|
* check.sh: Require a POSIX shell. Don't check error messages.
|
||||||
* check.sh: Don't check error messages.
|
|
||||||
|
|
||||||
2015-07-08 Antonio Diaz Diaz <antonio@gnu.org>
|
2015-07-08 Antonio Diaz Diaz <antonio@gnu.org>
|
||||||
|
|
||||||
|
@ -166,8 +174,8 @@
|
||||||
* lzlib.c (LZ_decompress_read): Tell LZ_header_error from
|
* lzlib.c (LZ_decompress_read): Tell LZ_header_error from
|
||||||
LZ_unexpected_eof the same way as lzip does.
|
LZ_unexpected_eof the same way as lzip does.
|
||||||
* Makefile.in: New targets 'install-as-lzip' and 'install-bin'.
|
* Makefile.in: New targets 'install-as-lzip' and 'install-bin'.
|
||||||
* main.c: Use 'setmode' instead of '_setmode' on Windows and OS/2.
|
|
||||||
* main.c: Define 'strtoull' to 'strtoul' on Windows.
|
* main.c: Define 'strtoull' to 'strtoul' on Windows.
|
||||||
|
(main): Use 'setmode' instead of '_setmode' on Windows and OS/2.
|
||||||
|
|
||||||
2012-02-29 Antonio Diaz Diaz <ant_diaz@teleline.es>
|
2012-02-29 Antonio Diaz Diaz <ant_diaz@teleline.es>
|
||||||
|
|
||||||
|
@ -195,9 +203,8 @@
|
||||||
* All declarations not belonging to the API have been
|
* All declarations not belonging to the API have been
|
||||||
encapsulated in the namespace 'Lzlib'.
|
encapsulated in the namespace 'Lzlib'.
|
||||||
* testsuite: Rename 'test1' to 'test.txt'. New tests.
|
* testsuite: Rename 'test1' to 'test.txt'. New tests.
|
||||||
* Match length limits set by options -1 to -9 of minilzip have
|
* main.cc (main): Set match length limits to same values as lzip 1.11.
|
||||||
been changed to match those of lzip 1.11.
|
(main): Set stdin/stdout in binary mode on OS2.
|
||||||
* main.cc: Set stdin/stdout in binary mode on OS2.
|
|
||||||
* bbexample.cc: New file containing example functions for
|
* bbexample.cc: New file containing example functions for
|
||||||
buffer-to-buffer compression/decompression.
|
buffer-to-buffer compression/decompression.
|
||||||
|
|
||||||
|
|
11
Makefile.in
11
Makefile.in
|
@ -2,8 +2,9 @@
|
||||||
DISTNAME = $(pkgname)-$(pkgversion)
|
DISTNAME = $(pkgname)-$(pkgversion)
|
||||||
INSTALL = install
|
INSTALL = install
|
||||||
INSTALL_PROGRAM = $(INSTALL) -m 755
|
INSTALL_PROGRAM = $(INSTALL) -m 755
|
||||||
INSTALL_DATA = $(INSTALL) -m 644
|
|
||||||
INSTALL_DIR = $(INSTALL) -d -m 755
|
INSTALL_DIR = $(INSTALL) -d -m 755
|
||||||
|
INSTALL_DATA = $(INSTALL) -m 644
|
||||||
|
INSTALL_SO = $(INSTALL) -m 644
|
||||||
LDCONFIG = /sbin/ldconfig
|
LDCONFIG = /sbin/ldconfig
|
||||||
SHELL = /bin/sh
|
SHELL = /bin/sh
|
||||||
CAN_RUN_INSTALLINFO = $(SHELL) -c "install-info --version" > /dev/null 2>&1
|
CAN_RUN_INSTALLINFO = $(SHELL) -c "install-info --version" > /dev/null 2>&1
|
||||||
|
@ -28,6 +29,7 @@ lib$(libname).a : lzlib.o
|
||||||
$(AR) $(ARFLAGS) $@ $<
|
$(AR) $(ARFLAGS) $@ $<
|
||||||
|
|
||||||
lib$(libname).so.$(soversion) : lzlib_sh.o
|
lib$(libname).so.$(soversion) : lzlib_sh.o
|
||||||
|
$(CC) $(CFLAGS) $(LDFLAGS) -fpic -fPIC -shared -Wl,--soname=$@ -o $@ $< || \
|
||||||
$(CC) $(CFLAGS) $(LDFLAGS) -fpic -fPIC -shared -o $@ $<
|
$(CC) $(CFLAGS) $(LDFLAGS) -fpic -fPIC -shared -o $@ $<
|
||||||
|
|
||||||
bin : $(progname_static) $(progname_shared)
|
bin : $(progname_static) $(progname_shared)
|
||||||
|
@ -119,14 +121,15 @@ install-lib : lib
|
||||||
fi ; \
|
fi ; \
|
||||||
rm -f "$(DESTDIR)$(libdir)/lib$(libname).so" ; \
|
rm -f "$(DESTDIR)$(libdir)/lib$(libname).so" ; \
|
||||||
rm -f "$(DESTDIR)$(libdir)/lib$(libname).so.$(soversion)" ; \
|
rm -f "$(DESTDIR)$(libdir)/lib$(libname).so.$(soversion)" ; \
|
||||||
$(INSTALL_PROGRAM) ./lib$(libname).so.$(soversion) "$(DESTDIR)$(libdir)/lib$(libname).so.$(soversion)" ; \
|
$(INSTALL_SO) ./lib$(libname).so.$(soversion) "$(DESTDIR)$(libdir)/lib$(libname).so.$(pkgversion)" ; \
|
||||||
cd "$(DESTDIR)$(libdir)" && ln -s lib$(libname).so.$(soversion) lib$(libname).so ; \
|
cd "$(DESTDIR)$(libdir)" && ln -s lib$(libname).so.$(pkgversion) lib$(libname).so ; \
|
||||||
|
cd "$(DESTDIR)$(libdir)" && ln -s lib$(libname).so.$(pkgversion) lib$(libname).so.$(soversion) ; \
|
||||||
if [ "${disable_ldconfig}" != yes ] && [ $${run_ldconfig} = yes ] && \
|
if [ "${disable_ldconfig}" != yes ] && [ $${run_ldconfig} = yes ] && \
|
||||||
[ -x "$(LDCONFIG)" ] ; then "$(LDCONFIG)" -n "$(DESTDIR)$(libdir)" || true ; fi ; \
|
[ -x "$(LDCONFIG)" ] ; then "$(LDCONFIG)" -n "$(DESTDIR)$(libdir)" || true ; fi ; \
|
||||||
fi
|
fi
|
||||||
|
|
||||||
install-lib-strip : lib
|
install-lib-strip : lib
|
||||||
$(MAKE) INSTALL_PROGRAM='$(INSTALL_PROGRAM) -s' install-lib
|
$(MAKE) INSTALL_SO='$(INSTALL_SO) -s' install-lib
|
||||||
|
|
||||||
install-info :
|
install-info :
|
||||||
if [ ! -d "$(DESTDIR)$(infodir)" ] ; then $(INSTALL_DIR) "$(DESTDIR)$(infodir)" ; fi
|
if [ ! -d "$(DESTDIR)$(infodir)" ] ; then $(INSTALL_DIR) "$(DESTDIR)$(infodir)" ; fi
|
||||||
|
|
4
NEWS
4
NEWS
|
@ -15,5 +15,5 @@ minilzip is no longer built by default.
|
||||||
|
|
||||||
The use of the target 'bin' has been documented in INSTALL.
|
The use of the target 'bin' has been documented in INSTALL.
|
||||||
|
|
||||||
To improve portability, the linker option '--soname' is no longer used.
|
To improve portability, the linker option '--soname' is now used conditionally.
|
||||||
Instead the shared library is written to 'liblz.so.1'.
|
(Reported by Michael Sullivan).
|
||||||
|
|
32
README
32
README
|
@ -5,30 +5,6 @@ decompression functions, including integrity checking of the decompressed
|
||||||
data. The compressed data format used by the library is the lzip format.
|
data. The compressed data format used by the library is the lzip format.
|
||||||
Lzlib is written in C and is distributed under a 2-clause BSD license.
|
Lzlib is written in C and is distributed under a 2-clause BSD license.
|
||||||
|
|
||||||
The lzip file format is designed for data sharing and long-term archiving,
|
|
||||||
taking into account both data integrity and decoder availability:
|
|
||||||
|
|
||||||
* The lzip format provides very safe integrity checking and some data
|
|
||||||
recovery means. The program lziprecover can repair bit flip errors
|
|
||||||
(one of the most common forms of data corruption) in lzip files, and
|
|
||||||
provides data recovery capabilities, including error-checked merging
|
|
||||||
of damaged copies of a file.
|
|
||||||
|
|
||||||
* The lzip format is as simple as possible (but not simpler). The lzip
|
|
||||||
manual provides the source code of a simple decompressor along with a
|
|
||||||
detailed explanation of how it works, so that with the only help of the
|
|
||||||
lzip manual it would be possible for a digital archaeologist to extract
|
|
||||||
the data from a lzip file long after quantum computers eventually
|
|
||||||
render LZMA obsolete.
|
|
||||||
|
|
||||||
* Additionally the lzip reference implementation is copylefted, which
|
|
||||||
guarantees that it will remain free forever.
|
|
||||||
|
|
||||||
A nice feature of the lzip format is that a corrupt byte is easier to repair
|
|
||||||
the nearer it is from the beginning of the file. Therefore, with the help of
|
|
||||||
lziprecover, losing an entire archive just because of a corrupt byte near
|
|
||||||
the beginning is a thing of the past.
|
|
||||||
|
|
||||||
The functions and variables forming the interface of the compression library
|
The functions and variables forming the interface of the compression library
|
||||||
are declared in the file 'lzlib.h'. Usage examples of the library are given
|
are declared in the file 'lzlib.h'. Usage examples of the library are given
|
||||||
in the files 'bbexample.c', 'ffexample.c', and 'minilzip.c' from the source
|
in the files 'bbexample.c', 'ffexample.c', and 'minilzip.c' from the source
|
||||||
|
@ -74,10 +50,10 @@ In spite of its name (Lempel-Ziv-Markov chain-Algorithm), LZMA is not a
|
||||||
concrete algorithm; it is more like "any algorithm using the LZMA coding
|
concrete algorithm; it is more like "any algorithm using the LZMA coding
|
||||||
scheme". For example, the option '-0' of lzip uses the scheme in almost the
|
scheme". For example, the option '-0' of lzip uses the scheme in almost the
|
||||||
simplest way possible; issuing the longest match it can find, or a literal
|
simplest way possible; issuing the longest match it can find, or a literal
|
||||||
byte if it can't find a match. Inversely, a much more elaborated way of
|
byte if it can't find a match. Inversely, a more elaborate way of finding
|
||||||
finding coding sequences of minimum size than the one currently used by lzip
|
coding sequences of minimum size than the one currently used by lzip could
|
||||||
could be developed, and the resulting sequence could also be coded using the
|
be developed, and the resulting sequence could also be coded using the LZMA
|
||||||
LZMA coding scheme.
|
coding scheme.
|
||||||
|
|
||||||
Lzlib currently implements two variants of the LZMA algorithm: fast (used by
|
Lzlib currently implements two variants of the LZMA algorithm: fast (used by
|
||||||
option '-0' of minilzip) and normal (used by all other compression levels).
|
option '-0' of minilzip) and normal (used by all other compression levels).
|
||||||
|
|
22
bbexample.c
22
bbexample.c
|
@ -53,7 +53,7 @@ uint8_t * read_file( const char * const name, long * const file_sizep )
|
||||||
fprintf( stderr, "bbexample: %s: Input file is too large.\n", name );
|
fprintf( stderr, "bbexample: %s: Input file is too large.\n", name );
|
||||||
free( buffer ); fclose( f ); return 0;
|
free( buffer ); fclose( f ); return 0;
|
||||||
}
|
}
|
||||||
buffer_size = ( buffer_size <= LONG_MAX / 2 ) ? 2 * buffer_size : LONG_MAX;
|
buffer_size = (buffer_size <= LONG_MAX / 2) ? 2 * buffer_size : LONG_MAX;
|
||||||
tmp = (uint8_t *)realloc( buffer, buffer_size );
|
tmp = (uint8_t *)realloc( buffer, buffer_size );
|
||||||
if( !tmp )
|
if( !tmp )
|
||||||
{ fputs( "bbexample: read_file: Not enough memory.\n", stderr );
|
{ fputs( "bbexample: read_file: Not enough memory.\n", stderr );
|
||||||
|
@ -81,14 +81,14 @@ uint8_t * read_file( const char * const name, long * const file_sizep )
|
||||||
uint8_t * bbcompressl( const uint8_t * const inbuf, const long insize,
|
uint8_t * bbcompressl( const uint8_t * const inbuf, const long insize,
|
||||||
const int level, long * const outlenp )
|
const int level, long * const outlenp )
|
||||||
{
|
{
|
||||||
struct Lzma_options
|
typedef struct Lzma_options
|
||||||
{
|
{
|
||||||
int dictionary_size; /* 4 KiB .. 512 MiB */
|
int dictionary_size; /* 4 KiB .. 512 MiB */
|
||||||
int match_len_limit; /* 5 .. 273 */
|
int match_len_limit; /* 5 .. 273 */
|
||||||
};
|
} Lzma_options;
|
||||||
/* Mapping from gzip/bzip2 style 0..9 compression levels to the
|
/* Mapping from gzip/bzip2 style 0..9 compression levels to the
|
||||||
corresponding LZMA compression parameters. */
|
corresponding LZMA compression parameters. */
|
||||||
const struct Lzma_options option_mapping[] =
|
const Lzma_options option_mapping[] =
|
||||||
{
|
{
|
||||||
{ 65535, 16 }, /* -0 (65535,16 chooses fast encoder) */
|
{ 65535, 16 }, /* -0 (65535,16 chooses fast encoder) */
|
||||||
{ 1 << 20, 5 }, /* -1 */
|
{ 1 << 20, 5 }, /* -1 */
|
||||||
|
@ -100,10 +100,10 @@ uint8_t * bbcompressl( const uint8_t * const inbuf, const long insize,
|
||||||
{ 1 << 24, 68 }, /* -7 */
|
{ 1 << 24, 68 }, /* -7 */
|
||||||
{ 3 << 23, 132 }, /* -8 */
|
{ 3 << 23, 132 }, /* -8 */
|
||||||
{ 1 << 25, 273 } }; /* -9 */
|
{ 1 << 25, 273 } }; /* -9 */
|
||||||
struct Lzma_options encoder_options;
|
Lzma_options encoder_options;
|
||||||
struct LZ_Encoder * encoder;
|
LZ_Encoder * encoder;
|
||||||
uint8_t * outbuf;
|
uint8_t * outbuf;
|
||||||
const long delta_size = ( insize / 4 ) + 64; /* insize may be zero */
|
const long delta_size = insize / 4 + 64; /* insize may be zero */
|
||||||
long outsize = delta_size; /* initial outsize */
|
long outsize = delta_size; /* initial outsize */
|
||||||
long inpos = 0;
|
long inpos = 0;
|
||||||
long outpos = 0;
|
long outpos = 0;
|
||||||
|
@ -160,7 +160,7 @@ uint8_t * bbcompressl( const uint8_t * const inbuf, const long insize,
|
||||||
uint8_t * bbdecompressl( const uint8_t * const inbuf, const long insize,
|
uint8_t * bbdecompressl( const uint8_t * const inbuf, const long insize,
|
||||||
long * const outlenp )
|
long * const outlenp )
|
||||||
{
|
{
|
||||||
struct LZ_Decoder * const decoder = LZ_decompress_open();
|
LZ_Decoder * const decoder = LZ_decompress_open();
|
||||||
const long delta_size = insize; /* insize must be > zero */
|
const long delta_size = insize; /* insize must be > zero */
|
||||||
long outsize = delta_size; /* initial outsize */
|
long outsize = delta_size; /* initial outsize */
|
||||||
uint8_t * outbuf = (uint8_t *)malloc( outsize );
|
uint8_t * outbuf = (uint8_t *)malloc( outsize );
|
||||||
|
@ -242,7 +242,7 @@ bool bbcompress( const uint8_t * const inbuf, const int insize,
|
||||||
{
|
{
|
||||||
int inpos = 0, outpos = 0;
|
int inpos = 0, outpos = 0;
|
||||||
bool error = false;
|
bool error = false;
|
||||||
struct LZ_Encoder * const encoder =
|
LZ_Encoder * const encoder =
|
||||||
LZ_compress_open( dictionary_size, match_len_limit, INT64_MAX );
|
LZ_compress_open( dictionary_size, match_len_limit, INT64_MAX );
|
||||||
if( !encoder || LZ_compress_errno( encoder ) != LZ_ok )
|
if( !encoder || LZ_compress_errno( encoder ) != LZ_ok )
|
||||||
{ LZ_compress_close( encoder ); return false; }
|
{ LZ_compress_close( encoder ); return false; }
|
||||||
|
@ -278,7 +278,7 @@ bool bbdecompress( const uint8_t * const inbuf, const int insize,
|
||||||
{
|
{
|
||||||
int inpos = 0, outpos = 0;
|
int inpos = 0, outpos = 0;
|
||||||
bool error = false;
|
bool error = false;
|
||||||
struct LZ_Decoder * const decoder = LZ_decompress_open();
|
LZ_Decoder * const decoder = LZ_decompress_open();
|
||||||
if( !decoder || LZ_decompress_errno( decoder ) != LZ_ok )
|
if( !decoder || LZ_decompress_errno( decoder ) != LZ_ok )
|
||||||
{ LZ_decompress_close( decoder ); return false; }
|
{ LZ_decompress_close( decoder ); return false; }
|
||||||
|
|
||||||
|
@ -340,7 +340,7 @@ int main( const int argc, const char * const argv[] )
|
||||||
{
|
{
|
||||||
int retval = 0, i;
|
int retval = 0, i;
|
||||||
int open_failures = 0;
|
int open_failures = 0;
|
||||||
const bool verbose = ( argc > 2 );
|
const bool verbose = argc > 2;
|
||||||
|
|
||||||
if( argc < 2 )
|
if( argc < 2 )
|
||||||
{
|
{
|
||||||
|
|
|
@ -32,15 +32,15 @@ static void * ap_resize_buffer( void * buf, const int min_size )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static char push_back_record( struct Arg_parser * const ap, const int code,
|
static char push_back_record( Arg_parser * const ap, const int code,
|
||||||
const char * const long_name,
|
const char * const long_name,
|
||||||
const char * const argument )
|
const char * const argument )
|
||||||
{
|
{
|
||||||
struct ap_Record * p;
|
ap_Record * p;
|
||||||
void * tmp = ap_resize_buffer( ap->data,
|
void * tmp = ap_resize_buffer( ap->data,
|
||||||
( ap->data_size + 1 ) * sizeof (struct ap_Record) );
|
( ap->data_size + 1 ) * sizeof (ap_Record) );
|
||||||
if( !tmp ) return 0;
|
if( !tmp ) return 0;
|
||||||
ap->data = (struct ap_Record *)tmp;
|
ap->data = (ap_Record *)tmp;
|
||||||
p = &(ap->data[ap->data_size]);
|
p = &(ap->data[ap->data_size]);
|
||||||
p->code = code;
|
p->code = code;
|
||||||
if( long_name )
|
if( long_name )
|
||||||
|
@ -71,7 +71,7 @@ static char push_back_record( struct Arg_parser * const ap, const int code,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static char add_error( struct Arg_parser * const ap, const char * const msg )
|
static char add_error( Arg_parser * const ap, const char * const msg )
|
||||||
{
|
{
|
||||||
const int len = strlen( msg );
|
const int len = strlen( msg );
|
||||||
void * tmp = ap_resize_buffer( ap->error, ap->error_size + len + 1 );
|
void * tmp = ap_resize_buffer( ap->error, ap->error_size + len + 1 );
|
||||||
|
@ -83,7 +83,7 @@ static char add_error( struct Arg_parser * const ap, const char * const msg )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void free_data( struct Arg_parser * const ap )
|
static void free_data( Arg_parser * const ap )
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for( i = 0; i < ap->data_size; ++i )
|
for( i = 0; i < ap->data_size; ++i )
|
||||||
|
@ -94,10 +94,9 @@ static void free_data( struct Arg_parser * const ap )
|
||||||
|
|
||||||
|
|
||||||
/* Return 0 only if out of memory. */
|
/* Return 0 only if out of memory. */
|
||||||
static char parse_long_option( struct Arg_parser * const ap,
|
static char parse_long_option( Arg_parser * const ap,
|
||||||
const char * const opt, const char * const arg,
|
const char * const opt, const char * const arg,
|
||||||
const struct ap_Option options[],
|
const ap_Option options[], int * const argindp )
|
||||||
int * const argindp )
|
|
||||||
{
|
{
|
||||||
unsigned len;
|
unsigned len;
|
||||||
int index = -1, i;
|
int index = -1, i;
|
||||||
|
@ -171,10 +170,9 @@ static char parse_long_option( struct Arg_parser * const ap,
|
||||||
|
|
||||||
|
|
||||||
/* Return 0 only if out of memory. */
|
/* Return 0 only if out of memory. */
|
||||||
static char parse_short_option( struct Arg_parser * const ap,
|
static char parse_short_option( Arg_parser * const ap,
|
||||||
const char * const opt, const char * const arg,
|
const char * const opt, const char * const arg,
|
||||||
const struct ap_Option options[],
|
const ap_Option options[], int * const argindp )
|
||||||
int * const argindp )
|
|
||||||
{
|
{
|
||||||
int cind = 1; /* character index in opt */
|
int cind = 1; /* character index in opt */
|
||||||
|
|
||||||
|
@ -221,9 +219,9 @@ static char parse_short_option( struct Arg_parser * const ap,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
char ap_init( struct Arg_parser * const ap,
|
char ap_init( Arg_parser * const ap,
|
||||||
const int argc, const char * const argv[],
|
const int argc, const char * const argv[],
|
||||||
const struct ap_Option options[], const char in_order )
|
const ap_Option options[], const char in_order )
|
||||||
{
|
{
|
||||||
const char ** non_options = 0; /* skipped non-options */
|
const char ** non_options = 0; /* skipped non-options */
|
||||||
int non_options_size = 0; /* number of skipped non-options */
|
int non_options_size = 0; /* number of skipped non-options */
|
||||||
|
@ -282,7 +280,7 @@ out: if( non_options ) free( non_options );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ap_free( struct Arg_parser * const ap )
|
void ap_free( Arg_parser * const ap )
|
||||||
{
|
{
|
||||||
free_data( ap );
|
free_data( ap );
|
||||||
if( ap->error ) { free( ap->error ); ap->error = 0; }
|
if( ap->error ) { free( ap->error ); ap->error = 0; }
|
||||||
|
@ -290,29 +288,25 @@ void ap_free( struct Arg_parser * const ap )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const char * ap_error( const struct Arg_parser * const ap )
|
const char * ap_error( const Arg_parser * const ap ) { return ap->error; }
|
||||||
{ return ap->error; }
|
|
||||||
|
|
||||||
|
int ap_arguments( const Arg_parser * const ap ) { return ap->data_size; }
|
||||||
|
|
||||||
int ap_arguments( const struct Arg_parser * const ap )
|
int ap_code( const Arg_parser * const ap, const int i )
|
||||||
{ return ap->data_size; }
|
|
||||||
|
|
||||||
|
|
||||||
int ap_code( const struct Arg_parser * const ap, const int i )
|
|
||||||
{
|
{
|
||||||
if( i < 0 || i >= ap_arguments( ap ) ) return 0;
|
if( i < 0 || i >= ap_arguments( ap ) ) return 0;
|
||||||
return ap->data[i].code;
|
return ap->data[i].code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const char * ap_parsed_name( const struct Arg_parser * const ap, const int i )
|
const char * ap_parsed_name( const Arg_parser * const ap, const int i )
|
||||||
{
|
{
|
||||||
if( i < 0 || i >= ap_arguments( ap ) || !ap->data[i].parsed_name ) return "";
|
if( i < 0 || i >= ap_arguments( ap ) || !ap->data[i].parsed_name ) return "";
|
||||||
return ap->data[i].parsed_name;
|
return ap->data[i].parsed_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const char * ap_argument( const struct Arg_parser * const ap, const int i )
|
const char * ap_argument( const Arg_parser * const ap, const int i )
|
||||||
{
|
{
|
||||||
if( i < 0 || i >= ap_arguments( ap ) || !ap->data[i].argument ) return "";
|
if( i < 0 || i >= ap_arguments( ap ) || !ap->data[i].argument ) return "";
|
||||||
return ap->data[i].argument;
|
return ap->data[i].argument;
|
||||||
|
|
|
@ -50,52 +50,52 @@ extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* ap_yme = yes but maybe empty */
|
/* ap_yme = yes but maybe empty */
|
||||||
enum ap_Has_arg { ap_no, ap_yes, ap_maybe, ap_yme };
|
typedef enum ap_Has_arg { ap_no, ap_yes, ap_maybe, ap_yme } ap_Has_arg;
|
||||||
|
|
||||||
struct ap_Option
|
typedef struct ap_Option
|
||||||
{
|
{
|
||||||
int code; /* Short option letter or code ( code != 0 ) */
|
int code; /* Short option letter or code ( code != 0 ) */
|
||||||
const char * long_name; /* Long option name (maybe null) */
|
const char * long_name; /* Long option name (maybe null) */
|
||||||
enum ap_Has_arg has_arg;
|
ap_Has_arg has_arg;
|
||||||
};
|
} ap_Option;
|
||||||
|
|
||||||
|
|
||||||
struct ap_Record
|
typedef struct ap_Record
|
||||||
{
|
{
|
||||||
int code;
|
int code;
|
||||||
char * parsed_name;
|
char * parsed_name;
|
||||||
char * argument;
|
char * argument;
|
||||||
};
|
} ap_Record;
|
||||||
|
|
||||||
|
|
||||||
struct Arg_parser
|
typedef struct Arg_parser
|
||||||
{
|
{
|
||||||
struct ap_Record * data;
|
ap_Record * data;
|
||||||
char * error;
|
char * error;
|
||||||
int data_size;
|
int data_size;
|
||||||
int error_size;
|
int error_size;
|
||||||
};
|
} Arg_parser;
|
||||||
|
|
||||||
|
|
||||||
char ap_init( struct Arg_parser * const ap,
|
char ap_init( Arg_parser * const ap,
|
||||||
const int argc, const char * const argv[],
|
const int argc, const char * const argv[],
|
||||||
const struct ap_Option options[], const char in_order );
|
const ap_Option options[], const char in_order );
|
||||||
|
|
||||||
void ap_free( struct Arg_parser * const ap );
|
void ap_free( Arg_parser * const ap );
|
||||||
|
|
||||||
const char * ap_error( const struct Arg_parser * const ap );
|
const char * ap_error( const Arg_parser * const ap );
|
||||||
|
|
||||||
/* The number of arguments parsed. May be different from argc. */
|
/* The number of arguments parsed. May be different from argc. */
|
||||||
int ap_arguments( const struct Arg_parser * const ap );
|
int ap_arguments( const Arg_parser * const ap );
|
||||||
|
|
||||||
/* If ap_code( i ) is 0, ap_argument( i ) is a non-option.
|
/* If ap_code( i ) is 0, ap_argument( i ) is a non-option.
|
||||||
Else ap_argument( i ) is the option's argument (or empty). */
|
Else ap_argument( i ) is the option's argument (or empty). */
|
||||||
int ap_code( const struct Arg_parser * const ap, const int i );
|
int ap_code( const Arg_parser * const ap, const int i );
|
||||||
|
|
||||||
/* Full name of the option parsed (short or long). */
|
/* Full name of the option parsed (short or long). */
|
||||||
const char * ap_parsed_name( const struct Arg_parser * const ap, const int i );
|
const char * ap_parsed_name( const Arg_parser * const ap, const int i );
|
||||||
|
|
||||||
const char * ap_argument( const struct Arg_parser * const ap, const int i );
|
const char * ap_argument( const Arg_parser * const ap, const int i );
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
28
cbuffer.c
28
cbuffer.c
|
@ -17,15 +17,15 @@
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
struct Circular_buffer
|
typedef struct Circular_buffer
|
||||||
{
|
{
|
||||||
uint8_t * buffer;
|
uint8_t * buffer;
|
||||||
unsigned buffer_size; /* capacity == buffer_size - 1 */
|
unsigned buffer_size; /* capacity == buffer_size - 1 */
|
||||||
unsigned get; /* buffer is empty when get == put */
|
unsigned get; /* buffer is empty when get == put */
|
||||||
unsigned put;
|
unsigned put;
|
||||||
};
|
} Circular_buffer;
|
||||||
|
|
||||||
static inline bool Cb_init( struct Circular_buffer * const cb,
|
static inline bool Cb_init( Circular_buffer * const cb,
|
||||||
const unsigned buf_size )
|
const unsigned buf_size )
|
||||||
{
|
{
|
||||||
cb->buffer_size = buf_size + 1;
|
cb->buffer_size = buf_size + 1;
|
||||||
|
@ -36,38 +36,36 @@ static inline bool Cb_init( struct Circular_buffer * const cb,
|
||||||
return cb->buffer != 0;
|
return cb->buffer != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void Cb_free( struct Circular_buffer * const cb )
|
static inline void Cb_free( Circular_buffer * const cb )
|
||||||
{ free( cb->buffer ); cb->buffer = 0; }
|
{ free( cb->buffer ); cb->buffer = 0; }
|
||||||
|
|
||||||
static inline void Cb_reset( struct Circular_buffer * const cb )
|
static inline void Cb_reset( Circular_buffer * const cb )
|
||||||
{ cb->get = 0; cb->put = 0; }
|
{ cb->get = 0; cb->put = 0; }
|
||||||
|
|
||||||
static inline unsigned Cb_empty( const struct Circular_buffer * const cb )
|
static inline unsigned Cb_empty( const Circular_buffer * const cb )
|
||||||
{ return cb->get == cb->put; }
|
{ return cb->get == cb->put; }
|
||||||
|
|
||||||
static inline unsigned Cb_used_bytes( const struct Circular_buffer * const cb )
|
static inline unsigned Cb_used_bytes( const Circular_buffer * const cb )
|
||||||
{ return ( (cb->get <= cb->put) ? 0 : cb->buffer_size ) + cb->put - cb->get; }
|
{ return ( (cb->get <= cb->put) ? 0 : cb->buffer_size ) + cb->put - cb->get; }
|
||||||
|
|
||||||
static inline unsigned Cb_free_bytes( const struct Circular_buffer * const cb )
|
static inline unsigned Cb_free_bytes( const Circular_buffer * const cb )
|
||||||
{ return ( (cb->get <= cb->put) ? cb->buffer_size : 0 ) - cb->put + cb->get - 1; }
|
{ return ( (cb->get <= cb->put) ? cb->buffer_size : 0 ) - cb->put + cb->get - 1; }
|
||||||
|
|
||||||
static inline uint8_t Cb_get_byte( struct Circular_buffer * const cb )
|
static inline uint8_t Cb_get_byte( Circular_buffer * const cb )
|
||||||
{
|
{
|
||||||
const uint8_t b = cb->buffer[cb->get];
|
const uint8_t b = cb->buffer[cb->get];
|
||||||
if( ++cb->get >= cb->buffer_size ) cb->get = 0;
|
if( ++cb->get >= cb->buffer_size ) cb->get = 0;
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void Cb_put_byte( struct Circular_buffer * const cb,
|
static inline void Cb_put_byte( Circular_buffer * const cb, const uint8_t b )
|
||||||
const uint8_t b )
|
|
||||||
{
|
{
|
||||||
cb->buffer[cb->put] = b;
|
cb->buffer[cb->put] = b;
|
||||||
if( ++cb->put >= cb->buffer_size ) cb->put = 0;
|
if( ++cb->put >= cb->buffer_size ) cb->put = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool Cb_unread_data( struct Circular_buffer * const cb,
|
static bool Cb_unread_data( Circular_buffer * const cb, const unsigned size )
|
||||||
const unsigned size )
|
|
||||||
{
|
{
|
||||||
if( size > Cb_free_bytes( cb ) ) return false;
|
if( size > Cb_free_bytes( cb ) ) return false;
|
||||||
if( cb->get >= size ) cb->get -= size;
|
if( cb->get >= size ) cb->get -= size;
|
||||||
|
@ -80,7 +78,7 @@ static bool Cb_unread_data( struct Circular_buffer * const cb,
|
||||||
If 'out_buffer' is null, the bytes are discarded.
|
If 'out_buffer' is null, the bytes are discarded.
|
||||||
Return the number of bytes copied or discarded.
|
Return the number of bytes copied or discarded.
|
||||||
*/
|
*/
|
||||||
static unsigned Cb_read_data( struct Circular_buffer * const cb,
|
static unsigned Cb_read_data( Circular_buffer * const cb,
|
||||||
uint8_t * const out_buffer,
|
uint8_t * const out_buffer,
|
||||||
const unsigned out_size )
|
const unsigned out_size )
|
||||||
{
|
{
|
||||||
|
@ -113,7 +111,7 @@ static unsigned Cb_read_data( struct Circular_buffer * const cb,
|
||||||
/* Copy up to 'in_size' bytes from 'in_buffer' and update 'put'.
|
/* Copy up to 'in_size' bytes from 'in_buffer' and update 'put'.
|
||||||
Return the number of bytes copied.
|
Return the number of bytes copied.
|
||||||
*/
|
*/
|
||||||
static unsigned Cb_write_data( struct Circular_buffer * const cb,
|
static unsigned Cb_write_data( Circular_buffer * const cb,
|
||||||
const uint8_t * const in_buffer,
|
const uint8_t * const in_buffer,
|
||||||
const unsigned in_size )
|
const unsigned in_size )
|
||||||
{
|
{
|
||||||
|
|
2
configure
vendored
2
configure
vendored
|
@ -6,7 +6,7 @@
|
||||||
# to copy, distribute, and modify it.
|
# to copy, distribute, and modify it.
|
||||||
|
|
||||||
pkgname=lzlib
|
pkgname=lzlib
|
||||||
pkgversion=1.15-pre2
|
pkgversion=1.15-rc1
|
||||||
soversion=1
|
soversion=1
|
||||||
libname=lz
|
libname=lz
|
||||||
libname_static=lib${libname}.a
|
libname_static=lib${libname}.a
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int LZd_try_check_trailer( struct LZ_decoder * const d )
|
static int LZd_try_check_trailer( LZ_decoder * const d )
|
||||||
{
|
{
|
||||||
Lzip_trailer trailer;
|
Lzip_trailer trailer;
|
||||||
if( Rd_available_bytes( d->rdec ) < Lt_size )
|
if( Rd_available_bytes( d->rdec ) < Lt_size )
|
||||||
|
@ -36,9 +36,9 @@ static int LZd_try_check_trailer( struct LZ_decoder * const d )
|
||||||
/* Return value: 0 = OK, 1 = decoder error, 2 = unexpected EOF,
|
/* Return value: 0 = OK, 1 = decoder error, 2 = unexpected EOF,
|
||||||
3 = trailer error, 4 = unknown marker found,
|
3 = trailer error, 4 = unknown marker found,
|
||||||
5 = nonzero first LZMA byte found, 6 = library error. */
|
5 = nonzero first LZMA byte found, 6 = library error. */
|
||||||
static int LZd_decode_member( struct LZ_decoder * const d )
|
static int LZd_decode_member( LZ_decoder * const d )
|
||||||
{
|
{
|
||||||
struct Range_decoder * const rdec = d->rdec;
|
Range_decoder * const rdec = d->rdec;
|
||||||
State * const state = &d->state;
|
State * const state = &d->state;
|
||||||
unsigned old_mpos = rdec->member_position;
|
unsigned old_mpos = rdec->member_position;
|
||||||
|
|
||||||
|
|
96
decoder.h
96
decoder.h
|
@ -19,17 +19,17 @@
|
||||||
|
|
||||||
enum { rd_min_available_bytes = 10 };
|
enum { rd_min_available_bytes = 10 };
|
||||||
|
|
||||||
struct Range_decoder
|
typedef struct Range_decoder
|
||||||
{
|
{
|
||||||
struct Circular_buffer cb; /* input buffer */
|
Circular_buffer cb; /* input buffer */
|
||||||
unsigned long long member_position;
|
unsigned long long member_position;
|
||||||
uint32_t code;
|
uint32_t code;
|
||||||
uint32_t range;
|
uint32_t range;
|
||||||
bool at_stream_end;
|
bool at_stream_end;
|
||||||
bool reload_pending;
|
bool reload_pending;
|
||||||
};
|
} Range_decoder;
|
||||||
|
|
||||||
static inline bool Rd_init( struct Range_decoder * const rdec )
|
static inline bool Rd_init( Range_decoder * const rdec )
|
||||||
{
|
{
|
||||||
if( !Cb_init( &rdec->cb, 65536 + rd_min_available_bytes ) ) return false;
|
if( !Cb_init( &rdec->cb, 65536 + rd_min_available_bytes ) ) return false;
|
||||||
rdec->member_position = 0;
|
rdec->member_position = 0;
|
||||||
|
@ -40,25 +40,25 @@ static inline bool Rd_init( struct Range_decoder * const rdec )
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void Rd_free( struct Range_decoder * const rdec )
|
static inline void Rd_free( Range_decoder * const rdec )
|
||||||
{ Cb_free( &rdec->cb ); }
|
{ Cb_free( &rdec->cb ); }
|
||||||
|
|
||||||
static inline bool Rd_finished( const struct Range_decoder * const rdec )
|
static inline bool Rd_finished( const Range_decoder * const rdec )
|
||||||
{ return rdec->at_stream_end && Cb_empty( &rdec->cb ); }
|
{ return rdec->at_stream_end && Cb_empty( &rdec->cb ); }
|
||||||
|
|
||||||
static inline void Rd_finish( struct Range_decoder * const rdec )
|
static inline void Rd_finish( Range_decoder * const rdec )
|
||||||
{ rdec->at_stream_end = true; }
|
{ rdec->at_stream_end = true; }
|
||||||
|
|
||||||
static inline bool Rd_enough_available_bytes( const struct Range_decoder * const rdec )
|
static inline bool Rd_enough_available_bytes( const Range_decoder * const rdec )
|
||||||
{ return Cb_used_bytes( &rdec->cb ) >= rd_min_available_bytes; }
|
{ return Cb_used_bytes( &rdec->cb ) >= rd_min_available_bytes; }
|
||||||
|
|
||||||
static inline unsigned Rd_available_bytes( const struct Range_decoder * const rdec )
|
static inline unsigned Rd_available_bytes( const Range_decoder * const rdec )
|
||||||
{ return Cb_used_bytes( &rdec->cb ); }
|
{ return Cb_used_bytes( &rdec->cb ); }
|
||||||
|
|
||||||
static inline unsigned Rd_free_bytes( const struct Range_decoder * const rdec )
|
static inline unsigned Rd_free_bytes( const Range_decoder * const rdec )
|
||||||
{ return rdec->at_stream_end ? 0 : Cb_free_bytes( &rdec->cb ); }
|
{ return rdec->at_stream_end ? 0 : Cb_free_bytes( &rdec->cb ); }
|
||||||
|
|
||||||
static inline unsigned long long Rd_purge( struct Range_decoder * const rdec )
|
static inline unsigned long long Rd_purge( Range_decoder * const rdec )
|
||||||
{
|
{
|
||||||
const unsigned long long size =
|
const unsigned long long size =
|
||||||
rdec->member_position + Cb_used_bytes( &rdec->cb );
|
rdec->member_position + Cb_used_bytes( &rdec->cb );
|
||||||
|
@ -67,7 +67,7 @@ static inline unsigned long long Rd_purge( struct Range_decoder * const rdec )
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void Rd_reset( struct Range_decoder * const rdec )
|
static inline void Rd_reset( Range_decoder * const rdec )
|
||||||
{ Cb_reset( &rdec->cb );
|
{ Cb_reset( &rdec->cb );
|
||||||
rdec->member_position = 0; rdec->at_stream_end = false; }
|
rdec->member_position = 0; rdec->at_stream_end = false; }
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ static inline void Rd_reset( struct Range_decoder * const rdec )
|
||||||
/* Seek for a member header and update 'get'. Set '*skippedp' to the number
|
/* Seek for a member header and update 'get'. Set '*skippedp' to the number
|
||||||
of bytes skipped. Return true if a valid header is found.
|
of bytes skipped. Return true if a valid header is found.
|
||||||
*/
|
*/
|
||||||
static bool Rd_find_header( struct Range_decoder * const rdec,
|
static bool Rd_find_header( Range_decoder * const rdec,
|
||||||
unsigned * const skippedp )
|
unsigned * const skippedp )
|
||||||
{
|
{
|
||||||
*skippedp = 0;
|
*skippedp = 0;
|
||||||
|
@ -101,14 +101,14 @@ static bool Rd_find_header( struct Range_decoder * const rdec,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static inline int Rd_write_data( struct Range_decoder * const rdec,
|
static inline int Rd_write_data( Range_decoder * const rdec,
|
||||||
const uint8_t * const inbuf, const int size )
|
const uint8_t * const inbuf, const int size )
|
||||||
{
|
{
|
||||||
if( rdec->at_stream_end || size <= 0 ) return 0;
|
if( rdec->at_stream_end || size <= 0 ) return 0;
|
||||||
return Cb_write_data( &rdec->cb, inbuf, size );
|
return Cb_write_data( &rdec->cb, inbuf, size );
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline uint8_t Rd_get_byte( struct Range_decoder * const rdec )
|
static inline uint8_t Rd_get_byte( Range_decoder * const rdec )
|
||||||
{
|
{
|
||||||
/* 0xFF avoids decoder error if member is truncated at EOS marker */
|
/* 0xFF avoids decoder error if member is truncated at EOS marker */
|
||||||
if( Rd_finished( rdec ) ) return 0xFF;
|
if( Rd_finished( rdec ) ) return 0xFF;
|
||||||
|
@ -116,7 +116,7 @@ static inline uint8_t Rd_get_byte( struct Range_decoder * const rdec )
|
||||||
return Cb_get_byte( &rdec->cb );
|
return Cb_get_byte( &rdec->cb );
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int Rd_read_data( struct Range_decoder * const rdec,
|
static inline int Rd_read_data( Range_decoder * const rdec,
|
||||||
uint8_t * const outbuf, const int size )
|
uint8_t * const outbuf, const int size )
|
||||||
{
|
{
|
||||||
const int sz = Cb_read_data( &rdec->cb, outbuf, size );
|
const int sz = Cb_read_data( &rdec->cb, outbuf, size );
|
||||||
|
@ -124,7 +124,7 @@ static inline int Rd_read_data( struct Range_decoder * const rdec,
|
||||||
return sz;
|
return sz;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool Rd_unread_data( struct Range_decoder * const rdec,
|
static inline bool Rd_unread_data( Range_decoder * const rdec,
|
||||||
const unsigned size )
|
const unsigned size )
|
||||||
{
|
{
|
||||||
if( size > rdec->member_position || !Cb_unread_data( &rdec->cb, size ) )
|
if( size > rdec->member_position || !Cb_unread_data( &rdec->cb, size ) )
|
||||||
|
@ -133,7 +133,7 @@ static inline bool Rd_unread_data( struct Range_decoder * const rdec,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int Rd_try_reload( struct Range_decoder * const rdec )
|
static int Rd_try_reload( Range_decoder * const rdec )
|
||||||
{
|
{
|
||||||
if( rdec->reload_pending && Rd_available_bytes( rdec ) >= 5 )
|
if( rdec->reload_pending && Rd_available_bytes( rdec ) >= 5 )
|
||||||
{
|
{
|
||||||
|
@ -149,13 +149,13 @@ static int Rd_try_reload( struct Range_decoder * const rdec )
|
||||||
return !rdec->reload_pending;
|
return !rdec->reload_pending;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void Rd_normalize( struct Range_decoder * const rdec )
|
static inline void Rd_normalize( Range_decoder * const rdec )
|
||||||
{
|
{
|
||||||
if( rdec->range <= 0x00FFFFFFU )
|
if( rdec->range <= 0x00FFFFFFU )
|
||||||
{ rdec->range <<= 8; rdec->code = (rdec->code << 8) | Rd_get_byte( rdec ); }
|
{ rdec->range <<= 8; rdec->code = (rdec->code << 8) | Rd_get_byte( rdec ); }
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline unsigned Rd_decode( struct Range_decoder * const rdec,
|
static inline unsigned Rd_decode( Range_decoder * const rdec,
|
||||||
const int num_bits )
|
const int num_bits )
|
||||||
{
|
{
|
||||||
unsigned symbol = 0;
|
unsigned symbol = 0;
|
||||||
|
@ -173,7 +173,7 @@ static inline unsigned Rd_decode( struct Range_decoder * const rdec,
|
||||||
return symbol;
|
return symbol;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline unsigned Rd_decode_bit( struct Range_decoder * const rdec,
|
static inline unsigned Rd_decode_bit( Range_decoder * const rdec,
|
||||||
Bit_model * const probability )
|
Bit_model * const probability )
|
||||||
{
|
{
|
||||||
Rd_normalize( rdec );
|
Rd_normalize( rdec );
|
||||||
|
@ -193,7 +193,7 @@ static inline unsigned Rd_decode_bit( struct Range_decoder * const rdec,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void Rd_decode_symbol_bit( struct Range_decoder * const rdec,
|
static inline void Rd_decode_symbol_bit( Range_decoder * const rdec,
|
||||||
Bit_model * const probability, unsigned * symbol )
|
Bit_model * const probability, unsigned * symbol )
|
||||||
{
|
{
|
||||||
Rd_normalize( rdec );
|
Rd_normalize( rdec );
|
||||||
|
@ -213,7 +213,7 @@ static inline void Rd_decode_symbol_bit( struct Range_decoder * const rdec,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void Rd_decode_symbol_bit_reversed( struct Range_decoder * const rdec,
|
static inline void Rd_decode_symbol_bit_reversed( Range_decoder * const rdec,
|
||||||
Bit_model * const probability, unsigned * model,
|
Bit_model * const probability, unsigned * model,
|
||||||
unsigned * symbol, const int i )
|
unsigned * symbol, const int i )
|
||||||
{
|
{
|
||||||
|
@ -235,7 +235,7 @@ static inline void Rd_decode_symbol_bit_reversed( struct Range_decoder * const r
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline unsigned Rd_decode_tree6( struct Range_decoder * const rdec,
|
static inline unsigned Rd_decode_tree6( Range_decoder * const rdec,
|
||||||
Bit_model bm[] )
|
Bit_model bm[] )
|
||||||
{
|
{
|
||||||
unsigned symbol = 1;
|
unsigned symbol = 1;
|
||||||
|
@ -248,7 +248,7 @@ static inline unsigned Rd_decode_tree6( struct Range_decoder * const rdec,
|
||||||
return symbol & 0x3F;
|
return symbol & 0x3F;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline unsigned Rd_decode_tree8( struct Range_decoder * const rdec,
|
static inline unsigned Rd_decode_tree8( Range_decoder * const rdec,
|
||||||
Bit_model bm[] )
|
Bit_model bm[] )
|
||||||
{
|
{
|
||||||
unsigned symbol = 1;
|
unsigned symbol = 1;
|
||||||
|
@ -264,7 +264,7 @@ static inline unsigned Rd_decode_tree8( struct Range_decoder * const rdec,
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline unsigned
|
static inline unsigned
|
||||||
Rd_decode_tree_reversed( struct Range_decoder * const rdec,
|
Rd_decode_tree_reversed( Range_decoder * const rdec,
|
||||||
Bit_model bm[], const int num_bits )
|
Bit_model bm[], const int num_bits )
|
||||||
{
|
{
|
||||||
unsigned model = 1;
|
unsigned model = 1;
|
||||||
|
@ -276,7 +276,7 @@ Rd_decode_tree_reversed( struct Range_decoder * const rdec,
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline unsigned
|
static inline unsigned
|
||||||
Rd_decode_tree_reversed4( struct Range_decoder * const rdec, Bit_model bm[] )
|
Rd_decode_tree_reversed4( Range_decoder * const rdec, Bit_model bm[] )
|
||||||
{
|
{
|
||||||
unsigned model = 1;
|
unsigned model = 1;
|
||||||
unsigned symbol = 0;
|
unsigned symbol = 0;
|
||||||
|
@ -287,7 +287,7 @@ Rd_decode_tree_reversed4( struct Range_decoder * const rdec, Bit_model bm[] )
|
||||||
return symbol;
|
return symbol;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline unsigned Rd_decode_matched( struct Range_decoder * const rdec,
|
static inline unsigned Rd_decode_matched( Range_decoder * const rdec,
|
||||||
Bit_model bm[], unsigned match_byte )
|
Bit_model bm[], unsigned match_byte )
|
||||||
{
|
{
|
||||||
unsigned symbol = 1;
|
unsigned symbol = 1;
|
||||||
|
@ -302,8 +302,8 @@ static inline unsigned Rd_decode_matched( struct Range_decoder * const rdec,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline unsigned Rd_decode_len( struct Range_decoder * const rdec,
|
static inline unsigned Rd_decode_len( Range_decoder * const rdec,
|
||||||
struct Len_model * const lm,
|
Len_model * const lm,
|
||||||
const int pos_state )
|
const int pos_state )
|
||||||
{
|
{
|
||||||
Bit_model * bm;
|
Bit_model * bm;
|
||||||
|
@ -329,11 +329,11 @@ len3:
|
||||||
|
|
||||||
enum { lzd_min_free_bytes = max_match_len };
|
enum { lzd_min_free_bytes = max_match_len };
|
||||||
|
|
||||||
struct LZ_decoder
|
typedef struct LZ_decoder
|
||||||
{
|
{
|
||||||
struct Circular_buffer cb;
|
Circular_buffer cb;
|
||||||
unsigned long long partial_data_pos;
|
unsigned long long partial_data_pos;
|
||||||
struct Range_decoder * rdec;
|
Range_decoder * rdec;
|
||||||
unsigned dictionary_size;
|
unsigned dictionary_size;
|
||||||
uint32_t crc;
|
uint32_t crc;
|
||||||
bool check_trailer_pending;
|
bool check_trailer_pending;
|
||||||
|
@ -356,25 +356,25 @@ struct LZ_decoder
|
||||||
Bit_model bm_dis[modeled_distances-end_dis_model+1];
|
Bit_model bm_dis[modeled_distances-end_dis_model+1];
|
||||||
Bit_model bm_align[dis_align_size];
|
Bit_model bm_align[dis_align_size];
|
||||||
|
|
||||||
struct Len_model match_len_model;
|
Len_model match_len_model;
|
||||||
struct Len_model rep_len_model;
|
Len_model rep_len_model;
|
||||||
};
|
} LZ_decoder;
|
||||||
|
|
||||||
static inline bool LZd_enough_free_bytes( const struct LZ_decoder * const d )
|
static inline bool LZd_enough_free_bytes( const LZ_decoder * const d )
|
||||||
{ return Cb_free_bytes( &d->cb ) >= lzd_min_free_bytes; }
|
{ return Cb_free_bytes( &d->cb ) >= lzd_min_free_bytes; }
|
||||||
|
|
||||||
static inline uint8_t LZd_peek_prev( const struct LZ_decoder * const d )
|
static inline uint8_t LZd_peek_prev( const LZ_decoder * const d )
|
||||||
{ return d->cb.buffer[((d->cb.put > 0) ? d->cb.put : d->cb.buffer_size)-1]; }
|
{ return d->cb.buffer[((d->cb.put > 0) ? d->cb.put : d->cb.buffer_size)-1]; }
|
||||||
|
|
||||||
static inline uint8_t LZd_peek( const struct LZ_decoder * const d,
|
static inline uint8_t LZd_peek( const LZ_decoder * const d,
|
||||||
const unsigned distance )
|
const unsigned distance )
|
||||||
{
|
{
|
||||||
const unsigned i = ( ( d->cb.put > distance ) ? 0 : d->cb.buffer_size ) +
|
const unsigned i = ( (d->cb.put > distance) ? 0 : d->cb.buffer_size ) +
|
||||||
d->cb.put - distance - 1;
|
d->cb.put - distance - 1;
|
||||||
return d->cb.buffer[i];
|
return d->cb.buffer[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void LZd_put_byte( struct LZ_decoder * const d, const uint8_t b )
|
static inline void LZd_put_byte( LZ_decoder * const d, const uint8_t b )
|
||||||
{
|
{
|
||||||
CRC32_update_byte( &d->crc, b );
|
CRC32_update_byte( &d->crc, b );
|
||||||
d->cb.buffer[d->cb.put] = b;
|
d->cb.buffer[d->cb.put] = b;
|
||||||
|
@ -382,7 +382,7 @@ static inline void LZd_put_byte( struct LZ_decoder * const d, const uint8_t b )
|
||||||
{ d->partial_data_pos += d->cb.put; d->cb.put = 0; d->pos_wrapped = true; }
|
{ d->partial_data_pos += d->cb.put; d->cb.put = 0; d->pos_wrapped = true; }
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void LZd_copy_block( struct LZ_decoder * const d,
|
static inline void LZd_copy_block( LZ_decoder * const d,
|
||||||
const unsigned distance, unsigned len )
|
const unsigned distance, unsigned len )
|
||||||
{
|
{
|
||||||
unsigned lpos = d->cb.put, i = lpos - distance - 1;
|
unsigned lpos = d->cb.put, i = lpos - distance - 1;
|
||||||
|
@ -415,8 +415,7 @@ static inline void LZd_copy_block( struct LZ_decoder * const d,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool LZd_init( struct LZ_decoder * const d,
|
static inline bool LZd_init( LZ_decoder * const d, Range_decoder * const rde,
|
||||||
struct Range_decoder * const rde,
|
|
||||||
const unsigned dict_size )
|
const unsigned dict_size )
|
||||||
{
|
{
|
||||||
if( !Cb_init( &d->cb, max( 65536, dict_size ) + lzd_min_free_bytes ) )
|
if( !Cb_init( &d->cb, max( 65536, dict_size ) + lzd_min_free_bytes ) )
|
||||||
|
@ -451,15 +450,14 @@ static inline bool LZd_init( struct LZ_decoder * const d,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void LZd_free( struct LZ_decoder * const d )
|
static inline void LZd_free( LZ_decoder * const d ) { Cb_free( &d->cb ); }
|
||||||
{ Cb_free( &d->cb ); }
|
|
||||||
|
|
||||||
static inline bool LZd_member_finished( const struct LZ_decoder * const d )
|
static inline bool LZd_member_finished( const LZ_decoder * const d )
|
||||||
{ return d->member_finished && Cb_empty( &d->cb ); }
|
{ return d->member_finished && Cb_empty( &d->cb ); }
|
||||||
|
|
||||||
static inline unsigned LZd_crc( const struct LZ_decoder * const d )
|
static inline unsigned LZd_crc( const LZ_decoder * const d )
|
||||||
{ return d->crc ^ 0xFFFFFFFFU; }
|
{ return d->crc ^ 0xFFFFFFFFU; }
|
||||||
|
|
||||||
static inline unsigned long long
|
static inline unsigned long long
|
||||||
LZd_data_position( const struct LZ_decoder * const d )
|
LZd_data_position( const LZ_decoder * const d )
|
||||||
{ return d->partial_data_pos + d->cb.put; }
|
{ return d->partial_data_pos + d->cb.put; }
|
||||||
|
|
291
doc/lzlib.info
291
doc/lzlib.info
|
@ -11,7 +11,7 @@ File: lzlib.info, Node: Top, Next: Introduction, Up: (dir)
|
||||||
Lzlib Manual
|
Lzlib Manual
|
||||||
************
|
************
|
||||||
|
|
||||||
This manual is for Lzlib (version 1.15-pre2, 16 October 2024).
|
This manual is for Lzlib (version 1.15-rc1, 19 November 2024).
|
||||||
|
|
||||||
* Menu:
|
* Menu:
|
||||||
|
|
||||||
|
@ -46,31 +46,6 @@ decompression functions, including integrity checking of the decompressed
|
||||||
data. The compressed data format used by the library is the lzip format.
|
data. The compressed data format used by the library is the lzip format.
|
||||||
Lzlib is written in C and is distributed under a 2-clause BSD license.
|
Lzlib is written in C and is distributed under a 2-clause BSD license.
|
||||||
|
|
||||||
The lzip file format is designed for data sharing and long-term
|
|
||||||
archiving, taking into account both data integrity and decoder availability:
|
|
||||||
|
|
||||||
* The lzip format provides very safe integrity checking and some data
|
|
||||||
recovery means. The program lziprecover can repair bit flip errors
|
|
||||||
(one of the most common forms of data corruption) in lzip files, and
|
|
||||||
provides data recovery capabilities, including error-checked merging
|
|
||||||
of damaged copies of a file. *Note Data safety: (lziprecover)Data
|
|
||||||
safety.
|
|
||||||
|
|
||||||
* The lzip format is as simple as possible (but not simpler). The lzip
|
|
||||||
manual provides the source code of a simple decompressor along with a
|
|
||||||
detailed explanation of how it works, so that with the only help of the
|
|
||||||
lzip manual it would be possible for a digital archaeologist to extract
|
|
||||||
the data from a lzip file long after quantum computers eventually
|
|
||||||
render LZMA obsolete.
|
|
||||||
|
|
||||||
* Additionally the lzip reference implementation is copylefted, which
|
|
||||||
guarantees that it will remain free forever.
|
|
||||||
|
|
||||||
A nice feature of the lzip format is that a corrupt byte is easier to
|
|
||||||
repair the nearer it is from the beginning of the file. Therefore, with the
|
|
||||||
help of lziprecover, losing an entire archive just because of a corrupt
|
|
||||||
byte near the beginning is a thing of the past.
|
|
||||||
|
|
||||||
The functions and variables forming the interface of the compression
|
The functions and variables forming the interface of the compression
|
||||||
library are declared in the file 'lzlib.h'. Usage examples of the library
|
library are declared in the file 'lzlib.h'. Usage examples of the library
|
||||||
are given in the files 'bbexample.c', 'ffexample.c', and 'minilzip.c' from
|
are given in the files 'bbexample.c', 'ffexample.c', and 'minilzip.c' from
|
||||||
|
@ -117,10 +92,10 @@ about 2 PiB each.
|
||||||
concrete algorithm; it is more like "any algorithm using the LZMA coding
|
concrete algorithm; it is more like "any algorithm using the LZMA coding
|
||||||
scheme". For example, the option '-0' of lzip uses the scheme in almost the
|
scheme". For example, the option '-0' of lzip uses the scheme in almost the
|
||||||
simplest way possible; issuing the longest match it can find, or a literal
|
simplest way possible; issuing the longest match it can find, or a literal
|
||||||
byte if it can't find a match. Inversely, a much more elaborated way of
|
byte if it can't find a match. Inversely, a more elaborate way of finding
|
||||||
finding coding sequences of minimum size than the one currently used by
|
coding sequences of minimum size than the one currently used by lzip could
|
||||||
lzip could be developed, and the resulting sequence could also be coded
|
be developed, and the resulting sequence could also be coded using the LZMA
|
||||||
using the LZMA coding scheme.
|
coding scheme.
|
||||||
|
|
||||||
Lzlib currently implements two variants of the LZMA algorithm: fast
|
Lzlib currently implements two variants of the LZMA algorithm: fast
|
||||||
(used by option '-0' of minilzip) and normal (used by all other compression
|
(used by option '-0' of minilzip) and normal (used by all other compression
|
||||||
|
@ -269,9 +244,8 @@ them return -1 or 0, for signed and unsigned return values respectively,
|
||||||
except 'LZ_compress_open' whose return value must be checked by calling
|
except 'LZ_compress_open' whose return value must be checked by calling
|
||||||
'LZ_compress_errno' before using it.
|
'LZ_compress_errno' before using it.
|
||||||
|
|
||||||
-- Function: struct LZ_Encoder * LZ_compress_open ( const int
|
-- Function: LZ_Encoder * LZ_compress_open ( const int DICTIONARY_SIZE,
|
||||||
DICTIONARY_SIZE, const int MATCH_LEN_LIMIT, const unsigned long
|
const int MATCH_LEN_LIMIT, const unsigned long long MEMBER_SIZE )
|
||||||
long MEMBER_SIZE )
|
|
||||||
Initializes the internal stream state for compression and returns a
|
Initializes the internal stream state for compression and returns a
|
||||||
pointer that can only be used as the ENCODER argument for the other
|
pointer that can only be used as the ENCODER argument for the other
|
||||||
LZ_compress functions, or a null pointer if the encoder could not be
|
LZ_compress functions, or a null pointer if the encoder could not be
|
||||||
|
@ -303,14 +277,14 @@ except 'LZ_compress_open' whose return value must be checked by calling
|
||||||
produced. Values larger than 2 PiB are reduced to 2 PiB to prevent the
|
produced. Values larger than 2 PiB are reduced to 2 PiB to prevent the
|
||||||
uncompressed size of the member from overflowing.
|
uncompressed size of the member from overflowing.
|
||||||
|
|
||||||
-- Function: int LZ_compress_close ( struct LZ_Encoder * const ENCODER )
|
-- Function: int LZ_compress_close ( LZ_Encoder * const ENCODER )
|
||||||
Frees all dynamically allocated data structures for this stream. This
|
Frees all dynamically allocated data structures for this stream. This
|
||||||
function discards any unprocessed input and does not flush any pending
|
function discards any unprocessed input and does not flush any pending
|
||||||
output. After a call to 'LZ_compress_close', ENCODER can no longer be
|
output. After a call to 'LZ_compress_close', ENCODER can no longer be
|
||||||
used as an argument to any LZ_compress function. It is safe to call
|
used as an argument to any LZ_compress function. It is safe to call
|
||||||
'LZ_compress_close' with a null argument.
|
'LZ_compress_close' with a null argument.
|
||||||
|
|
||||||
-- Function: int LZ_compress_finish ( struct LZ_Encoder * const ENCODER )
|
-- Function: int LZ_compress_finish ( LZ_Encoder * const ENCODER )
|
||||||
Use this function to tell 'lzlib' that all the data for this member
|
Use this function to tell 'lzlib' that all the data for this member
|
||||||
have already been written (with the function 'LZ_compress_write'). It
|
have already been written (with the function 'LZ_compress_write'). It
|
||||||
is safe to call 'LZ_compress_finish' as many times as needed. After
|
is safe to call 'LZ_compress_finish' as many times as needed. After
|
||||||
|
@ -318,27 +292,26 @@ except 'LZ_compress_open' whose return value must be checked by calling
|
||||||
'LZ_compress_member_finished' returns 1, a new member can be started
|
'LZ_compress_member_finished' returns 1, a new member can be started
|
||||||
with 'LZ_compress_restart_member'.
|
with 'LZ_compress_restart_member'.
|
||||||
|
|
||||||
-- Function: int LZ_compress_restart_member ( struct LZ_Encoder * const
|
-- Function: int LZ_compress_restart_member ( LZ_Encoder * const ENCODER,
|
||||||
ENCODER, const unsigned long long MEMBER_SIZE )
|
const unsigned long long MEMBER_SIZE )
|
||||||
Use this function to start a new member in a multimember data stream.
|
Use this function to start a new member in a multimember data stream.
|
||||||
Call this function only after 'LZ_compress_member_finished' indicates
|
Call this function only after 'LZ_compress_member_finished' indicates
|
||||||
that the current member has been fully read (with the function
|
that the current member has been fully read (with the function
|
||||||
'LZ_compress_read'). *Note member_size::, for a description of
|
'LZ_compress_read'). *Note member_size::, for a description of
|
||||||
MEMBER_SIZE.
|
MEMBER_SIZE.
|
||||||
|
|
||||||
-- Function: int LZ_compress_sync_flush ( struct LZ_Encoder * const
|
-- Function: int LZ_compress_sync_flush ( LZ_Encoder * const ENCODER )
|
||||||
ENCODER )
|
|
||||||
Use this function to make available to 'LZ_compress_read' all the data
|
Use this function to make available to 'LZ_compress_read' all the data
|
||||||
already written with the function 'LZ_compress_write'. First call
|
already written with the function 'LZ_compress_write'. First call
|
||||||
'LZ_compress_sync_flush'. Then call 'LZ_compress_read' until it
|
'LZ_compress_sync_flush'. Then call 'LZ_compress_read' until it
|
||||||
returns 0.
|
returns 0.
|
||||||
|
|
||||||
This function writes at least one LZMA marker '3' ("Sync Flush" marker)
|
This function writes at least one LZMA marker '3' ('Sync Flush' marker)
|
||||||
to the compressed output. Note that the sync flush marker is not
|
to the compressed output. Note that the sync flush marker is not
|
||||||
allowed in lzip files; it is a device for interactive communication
|
allowed in lzip files; it is a device for interactive communication
|
||||||
between applications using lzlib, but is useless and wasteful in a
|
between applications using lzlib, but is useless and wasteful in a
|
||||||
file, and is excluded from the media type 'application/lzip'. The LZMA
|
file, and is excluded from the media type 'application/lzip'. The LZMA
|
||||||
marker '2' ("End Of Stream" marker) is the only marker allowed in lzip
|
marker '2' ('End Of Stream' marker) is the only marker allowed in lzip
|
||||||
files. *Note File format::.
|
files. *Note File format::.
|
||||||
|
|
||||||
Repeated use of 'LZ_compress_sync_flush' may degrade compression
|
Repeated use of 'LZ_compress_sync_flush' may degrade compression
|
||||||
|
@ -353,8 +326,8 @@ except 'LZ_compress_open' whose return value must be checked by calling
|
||||||
'LZ_compress_member_finished' returns 1, followed by a new call to
|
'LZ_compress_member_finished' returns 1, followed by a new call to
|
||||||
'LZ_compress_sync_flush'.
|
'LZ_compress_sync_flush'.
|
||||||
|
|
||||||
-- Function: int LZ_compress_read ( struct LZ_Encoder * const ENCODER,
|
-- Function: int LZ_compress_read ( LZ_Encoder * const ENCODER, uint8_t *
|
||||||
uint8_t * const BUFFER, const int SIZE )
|
const BUFFER, const int SIZE )
|
||||||
Reads up to SIZE bytes from the stream pointed to by ENCODER, storing
|
Reads up to SIZE bytes from the stream pointed to by ENCODER, storing
|
||||||
the results in BUFFER. If LZ_API_VERSION >= 1012, BUFFER may be a null
|
the results in BUFFER. If LZ_API_VERSION >= 1012, BUFFER may be a null
|
||||||
pointer, in which case the bytes read are discarded.
|
pointer, in which case the bytes read are discarded.
|
||||||
|
@ -365,14 +338,13 @@ except 'LZ_compress_open' whose return value must be checked by calling
|
||||||
'LZ_compress_write'. Note that reading less than SIZE bytes is not an
|
'LZ_compress_write'. Note that reading less than SIZE bytes is not an
|
||||||
error.
|
error.
|
||||||
|
|
||||||
-- Function: int LZ_compress_write ( struct LZ_Encoder * const ENCODER,
|
-- Function: int LZ_compress_write ( LZ_Encoder * const ENCODER, uint8_t *
|
||||||
uint8_t * const BUFFER, const int SIZE )
|
const BUFFER, const int SIZE )
|
||||||
Writes up to SIZE bytes from BUFFER to the stream pointed to by
|
Writes up to SIZE bytes from BUFFER to the stream pointed to by
|
||||||
ENCODER. Returns the number of bytes actually written. This might be
|
ENCODER. Returns the number of bytes actually written. This might be
|
||||||
less than SIZE. Note that writing less than SIZE bytes is not an error.
|
less than SIZE. Note that writing less than SIZE bytes is not an error.
|
||||||
|
|
||||||
-- Function: int LZ_compress_write_size ( struct LZ_Encoder * const
|
-- Function: int LZ_compress_write_size ( LZ_Encoder * const ENCODER )
|
||||||
ENCODER )
|
|
||||||
Returns the maximum number of bytes that can be immediately written
|
Returns the maximum number of bytes that can be immediately written
|
||||||
through 'LZ_compress_write'. For efficiency reasons, once the input
|
through 'LZ_compress_write'. For efficiency reasons, once the input
|
||||||
buffer is full and 'LZ_compress_write_size' returns 0, almost all the
|
buffer is full and 'LZ_compress_write_size' returns 0, almost all the
|
||||||
|
@ -383,39 +355,37 @@ except 'LZ_compress_open' whose return value must be checked by calling
|
||||||
It is guaranteed that an immediate call to 'LZ_compress_write' will
|
It is guaranteed that an immediate call to 'LZ_compress_write' will
|
||||||
accept a SIZE up to the returned number of bytes.
|
accept a SIZE up to the returned number of bytes.
|
||||||
|
|
||||||
-- Function: enum LZ_Errno LZ_compress_errno ( struct LZ_Encoder * const
|
-- Function: LZ_Errno LZ_compress_errno ( LZ_Encoder * const ENCODER )
|
||||||
ENCODER )
|
|
||||||
Returns the current error code for ENCODER. *Note Error codes::. It is
|
Returns the current error code for ENCODER. *Note Error codes::. It is
|
||||||
safe to call 'LZ_compress_errno' with a null argument, in which case
|
safe to call 'LZ_compress_errno' with a null argument, in which case
|
||||||
it returns 'LZ_bad_argument'.
|
it returns 'LZ_bad_argument'.
|
||||||
|
|
||||||
-- Function: int LZ_compress_finished ( struct LZ_Encoder * const ENCODER )
|
-- Function: int LZ_compress_finished ( LZ_Encoder * const ENCODER )
|
||||||
Returns 1 if all the data have been read and 'LZ_compress_close' can
|
Returns 1 if all the data have been read and 'LZ_compress_close' can
|
||||||
be safely called. Otherwise it returns 0. 'LZ_compress_finished'
|
be safely called. Otherwise it returns 0. 'LZ_compress_finished'
|
||||||
implies 'LZ_compress_member_finished'.
|
implies 'LZ_compress_member_finished'.
|
||||||
|
|
||||||
-- Function: int LZ_compress_member_finished ( struct LZ_Encoder * const
|
-- Function: int LZ_compress_member_finished ( LZ_Encoder * const ENCODER )
|
||||||
ENCODER )
|
|
||||||
Returns 1 if the current member, in a multimember data stream, has been
|
Returns 1 if the current member, in a multimember data stream, has been
|
||||||
fully read and 'LZ_compress_restart_member' can be safely called.
|
fully read and 'LZ_compress_restart_member' can be safely called.
|
||||||
Otherwise it returns 0.
|
Otherwise it returns 0.
|
||||||
|
|
||||||
-- Function: unsigned long long LZ_compress_data_position ( struct
|
-- Function: unsigned long long LZ_compress_data_position ( LZ_Encoder *
|
||||||
LZ_Encoder * const ENCODER )
|
const ENCODER )
|
||||||
Returns the number of input bytes already compressed in the current
|
Returns the number of input bytes already compressed in the current
|
||||||
member.
|
member.
|
||||||
|
|
||||||
-- Function: unsigned long long LZ_compress_member_position ( struct
|
-- Function: unsigned long long LZ_compress_member_position ( LZ_Encoder *
|
||||||
LZ_Encoder * const ENCODER )
|
const ENCODER )
|
||||||
Returns the number of compressed bytes already produced, but perhaps
|
Returns the number of compressed bytes already produced, but perhaps
|
||||||
not yet read, in the current member.
|
not yet read, in the current member.
|
||||||
|
|
||||||
-- Function: unsigned long long LZ_compress_total_in_size ( struct
|
-- Function: unsigned long long LZ_compress_total_in_size ( LZ_Encoder *
|
||||||
LZ_Encoder * const ENCODER )
|
const ENCODER )
|
||||||
Returns the total number of input bytes already compressed.
|
Returns the total number of input bytes already compressed.
|
||||||
|
|
||||||
-- Function: unsigned long long LZ_compress_total_out_size ( struct
|
-- Function: unsigned long long LZ_compress_total_out_size ( LZ_Encoder *
|
||||||
LZ_Encoder * const ENCODER )
|
const ENCODER )
|
||||||
Returns the total number of compressed bytes already produced, but
|
Returns the total number of compressed bytes already produced, but
|
||||||
perhaps not yet read.
|
perhaps not yet read.
|
||||||
|
|
||||||
|
@ -430,7 +400,7 @@ them return -1 or 0, for signed and unsigned return values respectively,
|
||||||
except 'LZ_decompress_open' whose return value must be checked by calling
|
except 'LZ_decompress_open' whose return value must be checked by calling
|
||||||
'LZ_decompress_errno' before using it.
|
'LZ_decompress_errno' before using it.
|
||||||
|
|
||||||
-- Function: struct LZ_Decoder * LZ_decompress_open ( void )
|
-- Function: LZ_Decoder * LZ_decompress_open ( void )
|
||||||
Initializes the internal stream state for decompression and returns a
|
Initializes the internal stream state for decompression and returns a
|
||||||
pointer that can only be used as the DECODER argument for the other
|
pointer that can only be used as the DECODER argument for the other
|
||||||
LZ_decompress functions, or a null pointer if the decoder could not be
|
LZ_decompress functions, or a null pointer if the decoder could not be
|
||||||
|
@ -441,14 +411,14 @@ except 'LZ_decompress_open' whose return value must be checked by calling
|
||||||
returned pointer must not be used and should be freed with
|
returned pointer must not be used and should be freed with
|
||||||
'LZ_decompress_close' to avoid memory leaks.
|
'LZ_decompress_close' to avoid memory leaks.
|
||||||
|
|
||||||
-- Function: int LZ_decompress_close ( struct LZ_Decoder * const DECODER )
|
-- Function: int LZ_decompress_close ( LZ_Decoder * const DECODER )
|
||||||
Frees all dynamically allocated data structures for this stream. This
|
Frees all dynamically allocated data structures for this stream. This
|
||||||
function discards any unprocessed input and does not flush any pending
|
function discards any unprocessed input and does not flush any pending
|
||||||
output. After a call to 'LZ_decompress_close', DECODER can no longer
|
output. After a call to 'LZ_decompress_close', DECODER can no longer
|
||||||
be used as an argument to any LZ_decompress function. It is safe to
|
be used as an argument to any LZ_decompress function. It is safe to
|
||||||
call 'LZ_decompress_close' with a null argument.
|
call 'LZ_decompress_close' with a null argument.
|
||||||
|
|
||||||
-- Function: int LZ_decompress_finish ( struct LZ_Decoder * const DECODER )
|
-- Function: int LZ_decompress_finish ( LZ_Decoder * const DECODER )
|
||||||
Use this function to tell 'lzlib' that all the data for this stream
|
Use this function to tell 'lzlib' that all the data for this stream
|
||||||
have already been written (with the function 'LZ_decompress_write').
|
have already been written (with the function 'LZ_decompress_write').
|
||||||
It is safe to call 'LZ_decompress_finish' as many times as needed. It
|
It is safe to call 'LZ_decompress_finish' as many times as needed. It
|
||||||
|
@ -456,13 +426,13 @@ except 'LZ_decompress_open' whose return value must be checked by calling
|
||||||
only contains whole members, but not calling it prevents lzlib from
|
only contains whole members, but not calling it prevents lzlib from
|
||||||
detecting a truncated member.
|
detecting a truncated member.
|
||||||
|
|
||||||
-- Function: int LZ_decompress_reset ( struct LZ_Decoder * const DECODER )
|
-- Function: int LZ_decompress_reset ( LZ_Decoder * const DECODER )
|
||||||
Resets the internal state of DECODER as it was just after opening it
|
Resets the internal state of DECODER as it was just after opening it
|
||||||
with the function 'LZ_decompress_open'. Data stored in the internal
|
with the function 'LZ_decompress_open'. Data stored in the internal
|
||||||
buffers are discarded. Position counters are set to 0.
|
buffers are discarded. Position counters are set to 0.
|
||||||
|
|
||||||
-- Function: int LZ_decompress_sync_to_member ( struct LZ_Decoder * const
|
-- Function: int LZ_decompress_sync_to_member ( LZ_Decoder * const DECODER
|
||||||
DECODER )
|
)
|
||||||
Resets the error state of DECODER and enters a search state that lasts
|
Resets the error state of DECODER and enters a search state that lasts
|
||||||
until a new member header (or the end of the stream) is found. After a
|
until a new member header (or the end of the stream) is found. After a
|
||||||
successful call to 'LZ_decompress_sync_to_member', data written with
|
successful call to 'LZ_decompress_sync_to_member', data written with
|
||||||
|
@ -474,8 +444,8 @@ except 'LZ_decompress_open' whose return value must be checked by calling
|
||||||
case of a data error. If the decoder is already at the beginning of a
|
case of a data error. If the decoder is already at the beginning of a
|
||||||
member, this function does nothing.
|
member, this function does nothing.
|
||||||
|
|
||||||
-- Function: int LZ_decompress_read ( struct LZ_Decoder * const DECODER,
|
-- Function: int LZ_decompress_read ( LZ_Decoder * const DECODER, uint8_t
|
||||||
uint8_t * const BUFFER, const int SIZE )
|
* const BUFFER, const int SIZE )
|
||||||
Reads up to SIZE bytes from the stream pointed to by DECODER, storing
|
Reads up to SIZE bytes from the stream pointed to by DECODER, storing
|
||||||
the results in BUFFER. If LZ_API_VERSION >= 1012, BUFFER may be a null
|
the results in BUFFER. If LZ_API_VERSION >= 1012, BUFFER may be a null
|
||||||
pointer, in which case the bytes read are discarded.
|
pointer, in which case the bytes read are discarded.
|
||||||
|
@ -500,14 +470,13 @@ except 'LZ_decompress_open' whose return value must be checked by calling
|
||||||
allows tools like tarlz to recover as much data as possible from each
|
allows tools like tarlz to recover as much data as possible from each
|
||||||
damaged member. *Note tarlz manual: (tarlz)Top.
|
damaged member. *Note tarlz manual: (tarlz)Top.
|
||||||
|
|
||||||
-- Function: int LZ_decompress_write ( struct LZ_Decoder * const DECODER,
|
-- Function: int LZ_decompress_write ( LZ_Decoder * const DECODER, uint8_t
|
||||||
uint8_t * const BUFFER, const int SIZE )
|
* const BUFFER, const int SIZE )
|
||||||
Writes up to SIZE bytes from BUFFER to the stream pointed to by
|
Writes up to SIZE bytes from BUFFER to the stream pointed to by
|
||||||
DECODER. Returns the number of bytes actually written. This might be
|
DECODER. Returns the number of bytes actually written. This might be
|
||||||
less than SIZE. Note that writing less than SIZE bytes is not an error.
|
less than SIZE. Note that writing less than SIZE bytes is not an error.
|
||||||
|
|
||||||
-- Function: int LZ_decompress_write_size ( struct LZ_Decoder * const
|
-- Function: int LZ_decompress_write_size ( LZ_Decoder * const DECODER )
|
||||||
DECODER )
|
|
||||||
Returns the maximum number of bytes that can be immediately written
|
Returns the maximum number of bytes that can be immediately written
|
||||||
through 'LZ_decompress_write'. This number varies smoothly; each
|
through 'LZ_decompress_write'. This number varies smoothly; each
|
||||||
compressed byte consumed may be overwritten immediately, increasing by
|
compressed byte consumed may be overwritten immediately, increasing by
|
||||||
|
@ -516,19 +485,17 @@ except 'LZ_decompress_open' whose return value must be checked by calling
|
||||||
It is guaranteed that an immediate call to 'LZ_decompress_write' will
|
It is guaranteed that an immediate call to 'LZ_decompress_write' will
|
||||||
accept a SIZE up to the returned number of bytes.
|
accept a SIZE up to the returned number of bytes.
|
||||||
|
|
||||||
-- Function: enum LZ_Errno LZ_decompress_errno ( struct LZ_Decoder * const
|
-- Function: LZ_Errno LZ_decompress_errno ( LZ_Decoder * const DECODER )
|
||||||
DECODER )
|
|
||||||
Returns the current error code for DECODER. *Note Error codes::. It is
|
Returns the current error code for DECODER. *Note Error codes::. It is
|
||||||
safe to call 'LZ_decompress_errno' with a null argument, in which case
|
safe to call 'LZ_decompress_errno' with a null argument, in which case
|
||||||
it returns 'LZ_bad_argument'.
|
it returns 'LZ_bad_argument'.
|
||||||
|
|
||||||
-- Function: int LZ_decompress_finished ( struct LZ_Decoder * const
|
-- Function: int LZ_decompress_finished ( LZ_Decoder * const DECODER )
|
||||||
DECODER )
|
|
||||||
Returns 1 if all the data have been read and 'LZ_decompress_close' can
|
Returns 1 if all the data have been read and 'LZ_decompress_close' can
|
||||||
be safely called. Otherwise it returns 0. 'LZ_decompress_finished'
|
be safely called. Otherwise it returns 0. 'LZ_decompress_finished'
|
||||||
does not imply 'LZ_decompress_member_finished'.
|
does not imply 'LZ_decompress_member_finished'.
|
||||||
|
|
||||||
-- Function: int LZ_decompress_member_finished ( struct LZ_Decoder * const
|
-- Function: int LZ_decompress_member_finished ( LZ_Decoder * const
|
||||||
DECODER )
|
DECODER )
|
||||||
Returns 1 if the previous call to 'LZ_decompress_read' finished reading
|
Returns 1 if the previous call to 'LZ_decompress_read' finished reading
|
||||||
the current member, indicating that final values for the member are
|
the current member, indicating that final values for the member are
|
||||||
|
@ -536,37 +503,36 @@ except 'LZ_decompress_open' whose return value must be checked by calling
|
||||||
'LZ_decompress_data_position', and 'LZ_decompress_member_position'.
|
'LZ_decompress_data_position', and 'LZ_decompress_member_position'.
|
||||||
Otherwise it returns 0.
|
Otherwise it returns 0.
|
||||||
|
|
||||||
-- Function: int LZ_decompress_member_version ( struct LZ_Decoder * const
|
-- Function: int LZ_decompress_member_version ( LZ_Decoder * const DECODER
|
||||||
DECODER )
|
)
|
||||||
Returns the version of the current member, read from the member header.
|
Returns the version of the current member, read from the member header.
|
||||||
|
|
||||||
-- Function: int LZ_decompress_dictionary_size ( struct LZ_Decoder * const
|
-- Function: int LZ_decompress_dictionary_size ( LZ_Decoder * const
|
||||||
DECODER )
|
DECODER )
|
||||||
Returns the dictionary size of the current member, read from the
|
Returns the dictionary size of the current member, read from the
|
||||||
member header.
|
member header.
|
||||||
|
|
||||||
-- Function: unsigned LZ_decompress_data_crc ( struct LZ_Decoder * const
|
-- Function: unsigned LZ_decompress_data_crc ( LZ_Decoder * const DECODER )
|
||||||
DECODER )
|
|
||||||
Returns the 32 bit Cyclic Redundancy Check of the data decompressed
|
Returns the 32 bit Cyclic Redundancy Check of the data decompressed
|
||||||
from the current member. The value returned is valid only when
|
from the current member. The value returned is valid only when
|
||||||
'LZ_decompress_member_finished' returns 1.
|
'LZ_decompress_member_finished' returns 1.
|
||||||
|
|
||||||
-- Function: unsigned long long LZ_decompress_data_position ( struct
|
-- Function: unsigned long long LZ_decompress_data_position ( LZ_Decoder *
|
||||||
LZ_Decoder * const DECODER )
|
const DECODER )
|
||||||
Returns the number of decompressed bytes already produced, but perhaps
|
Returns the number of decompressed bytes already produced, but perhaps
|
||||||
not yet read, in the current member.
|
not yet read, in the current member.
|
||||||
|
|
||||||
-- Function: unsigned long long LZ_decompress_member_position ( struct
|
-- Function: unsigned long long LZ_decompress_member_position ( LZ_Decoder
|
||||||
LZ_Decoder * const DECODER )
|
* const DECODER )
|
||||||
Returns the number of input bytes already decompressed in the current
|
Returns the number of input bytes already decompressed in the current
|
||||||
member.
|
member.
|
||||||
|
|
||||||
-- Function: unsigned long long LZ_decompress_total_in_size ( struct
|
-- Function: unsigned long long LZ_decompress_total_in_size ( LZ_Decoder *
|
||||||
LZ_Decoder * const DECODER )
|
const DECODER )
|
||||||
Returns the total number of input bytes already decompressed.
|
Returns the total number of input bytes already decompressed.
|
||||||
|
|
||||||
-- Function: unsigned long long LZ_decompress_total_out_size ( struct
|
-- Function: unsigned long long LZ_decompress_total_out_size ( LZ_Decoder
|
||||||
LZ_Decoder * const DECODER )
|
* const DECODER )
|
||||||
Returns the total number of decompressed bytes already produced, but
|
Returns the total number of decompressed bytes already produced, but
|
||||||
perhaps not yet read.
|
perhaps not yet read.
|
||||||
|
|
||||||
|
@ -587,35 +553,36 @@ what kind of error it was, you need to check the error code by calling
|
||||||
and you should not use 'LZ_(de)compress_errno' to determine whether a call
|
and you should not use 'LZ_(de)compress_errno' to determine whether a call
|
||||||
failed. If the call failed, then you can examine 'LZ_(de)compress_errno'.
|
failed. If the call failed, then you can examine 'LZ_(de)compress_errno'.
|
||||||
|
|
||||||
The error codes are defined in the header file 'lzlib.h'.
|
The error codes are defined in the header file 'lzlib.h'. 'LZ_Errno' is
|
||||||
|
an enum type:
|
||||||
|
|
||||||
-- Constant: enum LZ_Errno LZ_ok
|
-- Constant: LZ_Errno LZ_ok
|
||||||
The value of this constant is 0 and is used to indicate that there is
|
The value of this constant is 0 and is used to indicate that there is
|
||||||
no error.
|
no error.
|
||||||
|
|
||||||
-- Constant: enum LZ_Errno LZ_bad_argument
|
-- Constant: LZ_Errno LZ_bad_argument
|
||||||
At least one of the arguments passed to the library function was
|
At least one of the arguments passed to the library function was
|
||||||
invalid.
|
invalid.
|
||||||
|
|
||||||
-- Constant: enum LZ_Errno LZ_mem_error
|
-- Constant: LZ_Errno LZ_mem_error
|
||||||
No memory available. The system cannot allocate more virtual memory
|
No memory available. The system cannot allocate more virtual memory
|
||||||
because its capacity is full.
|
because its capacity is full.
|
||||||
|
|
||||||
-- Constant: enum LZ_Errno LZ_sequence_error
|
-- Constant: LZ_Errno LZ_sequence_error
|
||||||
A library function was called in the wrong order. For example
|
A library function was called in the wrong order. For example
|
||||||
'LZ_compress_restart_member' was called before
|
'LZ_compress_restart_member' was called before
|
||||||
'LZ_compress_member_finished' indicates that the current member is
|
'LZ_compress_member_finished' indicated that the current member is
|
||||||
finished.
|
finished.
|
||||||
|
|
||||||
-- Constant: enum LZ_Errno LZ_header_error
|
-- Constant: LZ_Errno LZ_header_error
|
||||||
An invalid member header (one with the wrong magic bytes) was read. If
|
An invalid member header (one with the wrong magic bytes) was read. If
|
||||||
this happens at the end of the data stream it may indicate trailing
|
this happens at the end of the data stream it may indicate trailing
|
||||||
data.
|
data.
|
||||||
|
|
||||||
-- Constant: enum LZ_Errno LZ_unexpected_eof
|
-- Constant: LZ_Errno LZ_unexpected_eof
|
||||||
The end of the data stream was reached in the middle of a member.
|
The end of the data stream was reached in the middle of a member.
|
||||||
|
|
||||||
-- Constant: enum LZ_Errno LZ_data_error
|
-- Constant: LZ_Errno LZ_data_error
|
||||||
The data stream is corrupt. If 'LZ_decompress_member_position' is 6 or
|
The data stream is corrupt. If 'LZ_decompress_member_position' is 6 or
|
||||||
less, it indicates either a format version not supported, an invalid
|
less, it indicates either a format version not supported, an invalid
|
||||||
dictionary size, a nonzero first LZMA byte, a corrupt header in a
|
dictionary size, a nonzero first LZMA byte, a corrupt header in a
|
||||||
|
@ -623,7 +590,7 @@ failed. If the call failed, then you can examine 'LZ_(de)compress_errno'.
|
||||||
header. Lziprecover can be used to repair some of these errors and to
|
header. Lziprecover can be used to repair some of these errors and to
|
||||||
remove conflicting trailing data from a file.
|
remove conflicting trailing data from a file.
|
||||||
|
|
||||||
-- Constant: enum LZ_Errno LZ_library_error
|
-- Constant: LZ_Errno LZ_library_error
|
||||||
A bug was detected in the library. Please, report it. *Note Problems::.
|
A bug was detected in the library. Please, report it. *Note Problems::.
|
||||||
|
|
||||||
|
|
||||||
|
@ -632,11 +599,11 @@ File: lzlib.info, Node: Error messages, Next: Invoking minilzip, Prev: Error
|
||||||
8 Error messages
|
8 Error messages
|
||||||
****************
|
****************
|
||||||
|
|
||||||
-- Function: const char * LZ_strerror ( const enum LZ_Errno LZ_ERRNO )
|
-- Function: const char * LZ_strerror ( const LZ_Errno LZ_ERRNO )
|
||||||
Returns the standard error message for a given error code. The messages
|
Returns the error message corresponding to the error code LZ_ERRNO.
|
||||||
are fairly short; there are no multi-line messages or embedded
|
The messages are fairly short; there are no multi-line messages or
|
||||||
newlines. This function makes it easy for your program to report
|
embedded newlines. This function makes it easy for your program to
|
||||||
informative error messages about the failure of a library call.
|
report informative error messages about the failure of a library call.
|
||||||
|
|
||||||
The value of LZ_ERRNO normally comes from a call to
|
The value of LZ_ERRNO normally comes from a call to
|
||||||
'LZ_(de)compress_errno'.
|
'LZ_(de)compress_errno'.
|
||||||
|
@ -647,22 +614,22 @@ File: lzlib.info, Node: Invoking minilzip, Next: File format, Prev: Error mes
|
||||||
9 Invoking minilzip
|
9 Invoking minilzip
|
||||||
*******************
|
*******************
|
||||||
|
|
||||||
Minilzip is a test program for the compression library lzlib, compatible
|
Minilzip is a test program for the compression library lzlib. Minilzip is
|
||||||
(interoperable) with lzip 1.4 or newer. Minilzip is not intended to be
|
not intended to be installed because lzip has more features, but minilzip is
|
||||||
installed because lzip has more features, but minilzip is well tested and
|
well tested and you can use it as your main compressor if so you wish.
|
||||||
you can use it as your main compressor if so you wish.
|
*Note lzip: (lzip)Top.
|
||||||
|
|
||||||
Lzip is a lossless data compressor with a user interface similar to the
|
Lzip is a lossless data compressor with a user interface similar to the
|
||||||
one of gzip or bzip2. Lzip uses a simplified form of the 'Lempel-Ziv-Markov
|
one of gzip or bzip2. Lzip uses a simplified form of LZMA (Lempel-Ziv-Markov
|
||||||
chain-Algorithm' (LZMA) stream format to maximize interoperability. The
|
chain-Algorithm) designed to achieve complete interoperability between
|
||||||
maximum dictionary size is 512 MiB so that any lzip file can be decompressed
|
implementations. The maximum dictionary size is 512 MiB so that any lzip
|
||||||
on 32-bit machines. Lzip provides accurate and robust 3-factor integrity
|
file can be decompressed on 32-bit machines. Lzip provides accurate and
|
||||||
checking. Lzip can compress about as fast as gzip (lzip -0) or compress most
|
robust 3-factor integrity checking. 'lzip -0' compresses about as fast as
|
||||||
files more than bzip2 (lzip -9). Decompression speed is intermediate between
|
gzip, while 'lzip -9' compresses most files more than bzip2. Decompression
|
||||||
gzip and bzip2. Lzip provides better data recovery capabilities than gzip
|
speed is intermediate between gzip and bzip2. Lzip provides better data
|
||||||
and bzip2. Lzip has been designed, written, and tested with great care to
|
recovery capabilities than gzip and bzip2. Lzip has been designed, written,
|
||||||
replace gzip and bzip2 as the standard general-purpose compressed format for
|
and tested with great care to replace gzip and bzip2 as general-purpose
|
||||||
Unix-like systems.
|
compressed format for Unix-like systems.
|
||||||
|
|
||||||
The format for running minilzip is:
|
The format for running minilzip is:
|
||||||
|
|
||||||
|
@ -675,7 +642,7 @@ once, the first time it appears in the command line. Remember to prepend
|
||||||
'./' to any file name beginning with a hyphen, or use '--'.
|
'./' to any file name beginning with a hyphen, or use '--'.
|
||||||
|
|
||||||
minilzip supports the following options: *Note Argument syntax:
|
minilzip supports the following options: *Note Argument syntax:
|
||||||
(arg_parser)Argument syntax.
|
(plzip)Argument syntax.
|
||||||
|
|
||||||
'-h'
|
'-h'
|
||||||
'--help'
|
'--help'
|
||||||
|
@ -694,11 +661,12 @@ minilzip supports the following options: *Note Argument syntax:
|
||||||
|
|
||||||
'-b BYTES'
|
'-b BYTES'
|
||||||
'--member-size=BYTES'
|
'--member-size=BYTES'
|
||||||
When compressing, set the member size limit to BYTES. It is advisable
|
When compressing, set the member size limit to BYTES. If BYTES is
|
||||||
to keep members smaller than RAM size so that they can be repaired with
|
smaller than the compressed size, a multimember file is produced. It is
|
||||||
lziprecover in case of corruption. A small member size may degrade
|
advisable to keep members smaller than RAM size so that they can be
|
||||||
compression ratio, so use it only when needed. Valid values range from
|
repaired with lziprecover in case of corruption. A small member size
|
||||||
100 kB to 2 PiB. Defaults to 2 PiB.
|
may degrade compression ratio, so use it only when needed. Valid
|
||||||
|
values range from 100 kB to 2 PiB. Defaults to 2 PiB.
|
||||||
|
|
||||||
'-c'
|
'-c'
|
||||||
'--stdout'
|
'--stdout'
|
||||||
|
@ -719,7 +687,8 @@ minilzip supports the following options: *Note Argument syntax:
|
||||||
status 1. If a file fails to decompress, or is a terminal, minilzip
|
status 1. If a file fails to decompress, or is a terminal, minilzip
|
||||||
exits immediately with error status 2 without decompressing the rest
|
exits immediately with error status 2 without decompressing the rest
|
||||||
of the files. A terminal is considered an uncompressed file, and
|
of the files. A terminal is considered an uncompressed file, and
|
||||||
therefore invalid.
|
therefore invalid. A multimember file with one or more empty members
|
||||||
|
is accepted if redirected to standard input.
|
||||||
|
|
||||||
'-f'
|
'-f'
|
||||||
'--force'
|
'--force'
|
||||||
|
@ -772,6 +741,8 @@ minilzip supports the following options: *Note Argument syntax:
|
||||||
For maximum compression you should use a dictionary size limit as large
|
For maximum compression you should use a dictionary size limit as large
|
||||||
as possible, but keep in mind that the decompression memory requirement
|
as possible, but keep in mind that the decompression memory requirement
|
||||||
is affected at compression time by the choice of dictionary size limit.
|
is affected at compression time by the choice of dictionary size limit.
|
||||||
|
The dictionary size used for decompression is the same dictionary size
|
||||||
|
used for compression.
|
||||||
|
|
||||||
'-S BYTES'
|
'-S BYTES'
|
||||||
'--volume-size=BYTES'
|
'--volume-size=BYTES'
|
||||||
|
@ -791,7 +762,8 @@ minilzip supports the following options: *Note Argument syntax:
|
||||||
fails the test, does not exist, can't be opened, or is a terminal,
|
fails the test, does not exist, can't be opened, or is a terminal,
|
||||||
minilzip continues testing the rest of the files. A final diagnostic
|
minilzip continues testing the rest of the files. A final diagnostic
|
||||||
is shown at verbosity level 1 or higher if any file fails the test
|
is shown at verbosity level 1 or higher if any file fails the test
|
||||||
when testing multiple files.
|
when testing multiple files. A multimember file with one or more empty
|
||||||
|
members is accepted if redirected to standard input.
|
||||||
|
|
||||||
'-v'
|
'-v'
|
||||||
'--verbose'
|
'--verbose'
|
||||||
|
@ -839,7 +811,7 @@ minilzip supports the following options: *Note Argument syntax:
|
||||||
When decompressing or testing, allow trailing data whose first bytes
|
When decompressing or testing, allow trailing data whose first bytes
|
||||||
are so similar to the magic bytes of a lzip header that they can be
|
are so similar to the magic bytes of a lzip header that they can be
|
||||||
confused with a corrupt header. Use this option if a file triggers a
|
confused with a corrupt header. Use this option if a file triggers a
|
||||||
"corrupt header" error and the cause is not indeed a corrupt header.
|
'corrupt header' error and the cause is not indeed a corrupt header.
|
||||||
|
|
||||||
'--check-lib'
|
'--check-lib'
|
||||||
Compare the version of lzlib used to compile minilzip with the version
|
Compare the version of lzlib used to compile minilzip with the version
|
||||||
|
@ -935,11 +907,11 @@ not allowed in multimember files.
|
||||||
Valid values for dictionary size range from 4 KiB to 512 MiB.
|
Valid values for dictionary size range from 4 KiB to 512 MiB.
|
||||||
|
|
||||||
'LZMA stream'
|
'LZMA stream'
|
||||||
The LZMA stream, terminated by an "End Of Stream" marker. Uses default
|
The LZMA stream, terminated by an 'End Of Stream' marker. Uses default
|
||||||
values for encoder properties. *Note Stream format: (lzip)Stream
|
values for encoder properties. *Note Stream format: (lzip)Stream
|
||||||
format, for a complete description.
|
format, for a complete description.
|
||||||
Lzip only uses the LZMA marker '2' ("End Of Stream" marker). Lzlib
|
Lzip only uses the LZMA marker '2' ('End Of Stream' marker). Lzlib
|
||||||
also uses the LZMA marker '3' ("Sync Flush" marker). *Note
|
also uses the LZMA marker '3' ('Sync Flush' marker). *Note
|
||||||
sync_flush::.
|
sync_flush::.
|
||||||
|
|
||||||
'CRC32 (4 bytes)'
|
'CRC32 (4 bytes)'
|
||||||
|
@ -999,7 +971,7 @@ bool bbcompress( const uint8_t * const inbuf, const int insize,
|
||||||
{
|
{
|
||||||
int inpos = 0, outpos = 0;
|
int inpos = 0, outpos = 0;
|
||||||
bool error = false;
|
bool error = false;
|
||||||
struct LZ_Encoder * const encoder =
|
LZ_Encoder * const encoder =
|
||||||
LZ_compress_open( dictionary_size, match_len_limit, INT64_MAX );
|
LZ_compress_open( dictionary_size, match_len_limit, INT64_MAX );
|
||||||
if( !encoder || LZ_compress_errno( encoder ) != LZ_ok )
|
if( !encoder || LZ_compress_errno( encoder ) != LZ_ok )
|
||||||
{ LZ_compress_close( encoder ); return false; }
|
{ LZ_compress_close( encoder ); return false; }
|
||||||
|
@ -1042,7 +1014,7 @@ bool bbdecompress( const uint8_t * const inbuf, const int insize,
|
||||||
{
|
{
|
||||||
int inpos = 0, outpos = 0;
|
int inpos = 0, outpos = 0;
|
||||||
bool error = false;
|
bool error = false;
|
||||||
struct LZ_Decoder * const decoder = LZ_decompress_open();
|
LZ_Decoder * const decoder = LZ_decompress_open();
|
||||||
if( !decoder || LZ_decompress_errno( decoder ) != LZ_ok )
|
if( !decoder || LZ_decompress_errno( decoder ) != LZ_ok )
|
||||||
{ LZ_decompress_close( decoder ); return false; }
|
{ LZ_decompress_close( decoder ); return false; }
|
||||||
|
|
||||||
|
@ -1073,7 +1045,7 @@ File: lzlib.info, Node: File compression, Next: File decompression, Prev: Buf
|
||||||
|
|
||||||
File-to-file compression using LZ_compress_write_size.
|
File-to-file compression using LZ_compress_write_size.
|
||||||
|
|
||||||
int ffcompress( struct LZ_Encoder * const encoder,
|
int ffcompress( LZ_Encoder * const encoder,
|
||||||
FILE * const infile, FILE * const outfile )
|
FILE * const infile, FILE * const outfile )
|
||||||
{
|
{
|
||||||
enum { buffer_size = 16384 };
|
enum { buffer_size = 16384 };
|
||||||
|
@ -1106,7 +1078,7 @@ File: lzlib.info, Node: File decompression, Next: File compression mm, Prev:
|
||||||
|
|
||||||
File-to-file decompression using LZ_decompress_write_size.
|
File-to-file decompression using LZ_decompress_write_size.
|
||||||
|
|
||||||
int ffdecompress( struct LZ_Decoder * const decoder,
|
int ffdecompress( LZ_Decoder * const decoder,
|
||||||
FILE * const infile, FILE * const outfile )
|
FILE * const infile, FILE * const outfile )
|
||||||
{
|
{
|
||||||
enum { buffer_size = 16384 };
|
enum { buffer_size = 16384 };
|
||||||
|
@ -1145,8 +1117,7 @@ int ffmmcompress( FILE * const infile, FILE * const outfile )
|
||||||
enum { buffer_size = 16384, member_size = 4096 };
|
enum { buffer_size = 16384, member_size = 4096 };
|
||||||
uint8_t buffer[buffer_size];
|
uint8_t buffer[buffer_size];
|
||||||
bool done = false;
|
bool done = false;
|
||||||
struct LZ_Encoder * const encoder =
|
LZ_Encoder * const encoder = LZ_compress_open( 65535, 16, member_size );
|
||||||
LZ_compress_open( 65535, 16, member_size );
|
|
||||||
if( !encoder || LZ_compress_errno( encoder ) != LZ_ok )
|
if( !encoder || LZ_compress_errno( encoder ) != LZ_ok )
|
||||||
{ fputs( "ffexample: Not enough memory.\n", stderr );
|
{ fputs( "ffexample: Not enough memory.\n", stderr );
|
||||||
LZ_compress_close( encoder ); return 1; }
|
LZ_compress_close( encoder ); return 1; }
|
||||||
|
@ -1183,7 +1154,7 @@ LZ_compress_open with MEMBER_SIZE > largest member).
|
||||||
for each line of text terminated by a newline character or by EOF.
|
for each line of text terminated by a newline character or by EOF.
|
||||||
Return 0 if success, 1 if error.
|
Return 0 if success, 1 if error.
|
||||||
*/
|
*/
|
||||||
int fflfcompress( struct LZ_Encoder * const encoder,
|
int fflfcompress( LZ_Encoder * const encoder,
|
||||||
FILE * const infile, FILE * const outfile )
|
FILE * const infile, FILE * const outfile )
|
||||||
{
|
{
|
||||||
enum { buffer_size = 16384 };
|
enum { buffer_size = 16384 };
|
||||||
|
@ -1229,7 +1200,7 @@ File: lzlib.info, Node: Skipping data errors, Prev: File compression mm, Up:
|
||||||
next member in case of data error, including the automatic removal of
|
next member in case of data error, including the automatic removal of
|
||||||
leading garbage.
|
leading garbage.
|
||||||
*/
|
*/
|
||||||
int ffrsdecompress( struct LZ_Decoder * const decoder,
|
int ffrsdecompress( LZ_Decoder * const decoder,
|
||||||
FILE * const infile, FILE * const outfile )
|
FILE * const infile, FILE * const outfile )
|
||||||
{
|
{
|
||||||
enum { buffer_size = 16384 };
|
enum { buffer_size = 16384 };
|
||||||
|
@ -1310,27 +1281,27 @@ Concept index
|
||||||
Tag Table:
|
Tag Table:
|
||||||
Node: Top215
|
Node: Top215
|
||||||
Node: Introduction1343
|
Node: Introduction1343
|
||||||
Node: Library version6831
|
Node: Library version5506
|
||||||
Node: Buffering9382
|
Node: Buffering8057
|
||||||
Node: Parameter limits10607
|
Node: Parameter limits9282
|
||||||
Node: Compression functions11561
|
Node: Compression functions10236
|
||||||
Ref: member_size13354
|
Ref: member_size12012
|
||||||
Ref: sync_flush15116
|
Ref: sync_flush13753
|
||||||
Node: Decompression functions19804
|
Node: Decompression functions18319
|
||||||
Node: Error codes27362
|
Node: Error codes25706
|
||||||
Node: Error messages29719
|
Node: Error messages28051
|
||||||
Node: Invoking minilzip30298
|
Node: Invoking minilzip28634
|
||||||
Node: File format41020
|
Node: File format39716
|
||||||
Ref: coded-dict-size42518
|
Ref: coded-dict-size41214
|
||||||
Node: Examples43925
|
Node: Examples42621
|
||||||
Node: Buffer compression44886
|
Node: Buffer compression43582
|
||||||
Node: Buffer decompression46406
|
Node: Buffer decompression45095
|
||||||
Node: File compression47820
|
Node: File compression46502
|
||||||
Node: File decompression48803
|
Node: File decompression47478
|
||||||
Node: File compression mm49807
|
Node: File compression mm48475
|
||||||
Node: Skipping data errors52836
|
Node: Skipping data errors51486
|
||||||
Node: Problems54141
|
Node: Problems52784
|
||||||
Node: Concept index54702
|
Node: Concept index53345
|
||||||
|
|
||||||
End Tag Table
|
End Tag Table
|
||||||
|
|
||||||
|
|
225
doc/lzlib.texi
225
doc/lzlib.texi
|
@ -6,8 +6,8 @@
|
||||||
@finalout
|
@finalout
|
||||||
@c %**end of header
|
@c %**end of header
|
||||||
|
|
||||||
@set UPDATED 16 October 2024
|
@set UPDATED 19 November 2024
|
||||||
@set VERSION 1.15-pre2
|
@set VERSION 1.15-rc1
|
||||||
|
|
||||||
@dircategory Compression
|
@dircategory Compression
|
||||||
@direntry
|
@direntry
|
||||||
|
@ -66,42 +66,10 @@ distribute, and modify it.
|
||||||
@uref{http://www.nongnu.org/lzip/lzlib.html,,Lzlib}
|
@uref{http://www.nongnu.org/lzip/lzlib.html,,Lzlib}
|
||||||
is a data compression library providing in-memory LZMA compression and
|
is a data compression library providing in-memory LZMA compression and
|
||||||
decompression functions, including integrity checking of the decompressed
|
decompression functions, including integrity checking of the decompressed
|
||||||
data. The compressed data format used by the library is the lzip format.
|
data. The compressed data format used by the library is the
|
||||||
|
@uref{http://www.nongnu.org/lzip/lzip.html,,lzip} format.
|
||||||
Lzlib is written in C and is distributed under a 2-clause BSD license.
|
Lzlib is written in C and is distributed under a 2-clause BSD license.
|
||||||
|
|
||||||
The lzip file format is designed for data sharing and long-term archiving,
|
|
||||||
taking into account both data integrity and decoder availability:
|
|
||||||
|
|
||||||
@itemize @bullet
|
|
||||||
@item
|
|
||||||
The lzip format provides very safe integrity checking and some data
|
|
||||||
recovery means. The program
|
|
||||||
@uref{http://www.nongnu.org/lzip/manual/lziprecover_manual.html#Data-safety,,lziprecover}
|
|
||||||
can repair bit flip errors (one of the most common forms of data corruption)
|
|
||||||
in lzip files, and provides data recovery capabilities, including
|
|
||||||
error-checked merging of damaged copies of a file.
|
|
||||||
@ifnothtml
|
|
||||||
@xref{Data safety,,,lziprecover}.
|
|
||||||
@end ifnothtml
|
|
||||||
|
|
||||||
@item
|
|
||||||
The lzip format is as simple as possible (but not simpler). The lzip
|
|
||||||
manual provides the source code of a simple decompressor along with a
|
|
||||||
detailed explanation of how it works, so that with the only help of the
|
|
||||||
lzip manual it would be possible for a digital archaeologist to extract
|
|
||||||
the data from a lzip file long after quantum computers eventually
|
|
||||||
render LZMA obsolete.
|
|
||||||
|
|
||||||
@item
|
|
||||||
Additionally the lzip reference implementation is copylefted, which
|
|
||||||
guarantees that it will remain free forever.
|
|
||||||
@end itemize
|
|
||||||
|
|
||||||
A nice feature of the lzip format is that a corrupt byte is easier to repair
|
|
||||||
the nearer it is from the beginning of the file. Therefore, with the help of
|
|
||||||
lziprecover, losing an entire archive just because of a corrupt byte near
|
|
||||||
the beginning is a thing of the past.
|
|
||||||
|
|
||||||
The functions and variables forming the interface of the compression library
|
The functions and variables forming the interface of the compression library
|
||||||
are declared in the file @file{lzlib.h}. Usage examples of the library are
|
are declared in the file @file{lzlib.h}. Usage examples of the library are
|
||||||
given in the files @file{bbexample.c}, @file{ffexample.c}, and
|
given in the files @file{bbexample.c}, @file{ffexample.c}, and
|
||||||
|
@ -149,10 +117,10 @@ In spite of its name (Lempel-Ziv-Markov chain-Algorithm), LZMA is not a
|
||||||
concrete algorithm; it is more like "any algorithm using the LZMA coding
|
concrete algorithm; it is more like "any algorithm using the LZMA coding
|
||||||
scheme". For example, the option @option{-0} of lzip uses the scheme in
|
scheme". For example, the option @option{-0} of lzip uses the scheme in
|
||||||
almost the simplest way possible; issuing the longest match it can find, or
|
almost the simplest way possible; issuing the longest match it can find, or
|
||||||
a literal byte if it can't find a match. Inversely, a much more elaborated
|
a literal byte if it can't find a match. Inversely, a more elaborate way of
|
||||||
way of finding coding sequences of minimum size than the one currently used
|
finding coding sequences of minimum size than the one currently used by lzip
|
||||||
by lzip could be developed, and the resulting sequence could also be coded
|
could be developed, and the resulting sequence could also be coded using the
|
||||||
using the LZMA coding scheme.
|
LZMA coding scheme.
|
||||||
|
|
||||||
Lzlib currently implements two variants of the LZMA algorithm: fast (used by
|
Lzlib currently implements two variants of the LZMA algorithm: fast (used by
|
||||||
option @option{-0} of minilzip) and normal (used by all other compression levels).
|
option @option{-0} of minilzip) and normal (used by all other compression levels).
|
||||||
|
@ -308,7 +276,7 @@ except @samp{LZ_compress_open} whose return value must be checked by
|
||||||
calling @samp{LZ_compress_errno} before using it.
|
calling @samp{LZ_compress_errno} before using it.
|
||||||
|
|
||||||
|
|
||||||
@deftypefun {struct LZ_Encoder *} LZ_compress_open ( const int @var{dictionary_size}, const int @var{match_len_limit}, const unsigned long long @var{member_size} )
|
@deftypefun {LZ_Encoder *} LZ_compress_open ( const int @var{dictionary_size}, const int @var{match_len_limit}, const unsigned long long @var{member_size} )
|
||||||
Initializes the internal stream state for compression and returns a
|
Initializes the internal stream state for compression and returns a
|
||||||
pointer that can only be used as the @var{encoder} argument for the
|
pointer that can only be used as the @var{encoder} argument for the
|
||||||
other LZ_compress functions, or a null pointer if the encoder could not
|
other LZ_compress functions, or a null pointer if the encoder could not
|
||||||
|
@ -344,7 +312,7 @@ the uncompressed size of the member from overflowing.
|
||||||
@end deftypefun
|
@end deftypefun
|
||||||
|
|
||||||
|
|
||||||
@deftypefun int LZ_compress_close ( struct LZ_Encoder * const @var{encoder} )
|
@deftypefun int LZ_compress_close ( LZ_Encoder * const @var{encoder} )
|
||||||
Frees all dynamically allocated data structures for this stream. This
|
Frees all dynamically allocated data structures for this stream. This
|
||||||
function discards any unprocessed input and does not flush any pending
|
function discards any unprocessed input and does not flush any pending
|
||||||
output. After a call to @samp{LZ_compress_close}, @var{encoder} can no
|
output. After a call to @samp{LZ_compress_close}, @var{encoder} can no
|
||||||
|
@ -353,7 +321,7 @@ It is safe to call @samp{LZ_compress_close} with a null argument.
|
||||||
@end deftypefun
|
@end deftypefun
|
||||||
|
|
||||||
|
|
||||||
@deftypefun int LZ_compress_finish ( struct LZ_Encoder * const @var{encoder} )
|
@deftypefun int LZ_compress_finish ( LZ_Encoder * const @var{encoder} )
|
||||||
Use this function to tell @samp{lzlib} that all the data for this member
|
Use this function to tell @samp{lzlib} that all the data for this member
|
||||||
have already been written (with the function @samp{LZ_compress_write}).
|
have already been written (with the function @samp{LZ_compress_write}).
|
||||||
It is safe to call @samp{LZ_compress_finish} as many times as needed.
|
It is safe to call @samp{LZ_compress_finish} as many times as needed.
|
||||||
|
@ -363,7 +331,7 @@ started with @samp{LZ_compress_restart_member}.
|
||||||
@end deftypefun
|
@end deftypefun
|
||||||
|
|
||||||
|
|
||||||
@deftypefun int LZ_compress_restart_member ( struct LZ_Encoder * const @var{encoder}, const unsigned long long @var{member_size} )
|
@deftypefun int LZ_compress_restart_member ( LZ_Encoder * const @var{encoder}, const unsigned long long @var{member_size} )
|
||||||
Use this function to start a new member in a multimember data stream. Call
|
Use this function to start a new member in a multimember data stream. Call
|
||||||
this function only after @samp{LZ_compress_member_finished} indicates that
|
this function only after @samp{LZ_compress_member_finished} indicates that
|
||||||
the current member has been fully read (with the function
|
the current member has been fully read (with the function
|
||||||
|
@ -373,18 +341,18 @@ the current member has been fully read (with the function
|
||||||
|
|
||||||
|
|
||||||
@anchor{sync_flush}
|
@anchor{sync_flush}
|
||||||
@deftypefun int LZ_compress_sync_flush ( struct LZ_Encoder * const @var{encoder} )
|
@deftypefun int LZ_compress_sync_flush ( LZ_Encoder * const @var{encoder} )
|
||||||
Use this function to make available to @samp{LZ_compress_read} all the data
|
Use this function to make available to @samp{LZ_compress_read} all the data
|
||||||
already written with the function @samp{LZ_compress_write}. First call
|
already written with the function @samp{LZ_compress_write}. First call
|
||||||
@samp{LZ_compress_sync_flush}. Then call @samp{LZ_compress_read} until it
|
@samp{LZ_compress_sync_flush}. Then call @samp{LZ_compress_read} until it
|
||||||
returns 0.
|
returns 0.
|
||||||
|
|
||||||
This function writes at least one LZMA marker @samp{3} ("Sync Flush" marker)
|
This function writes at least one LZMA marker @samp{3} ('Sync Flush' marker)
|
||||||
to the compressed output. Note that the sync flush marker is not allowed in
|
to the compressed output. Note that the sync flush marker is not allowed in
|
||||||
lzip files; it is a device for interactive communication between
|
lzip files; it is a device for interactive communication between
|
||||||
applications using lzlib, but is useless and wasteful in a file, and is
|
applications using lzlib, but is useless and wasteful in a file, and is
|
||||||
excluded from the media type @samp{application/lzip}. The LZMA marker
|
excluded from the media type @samp{application/lzip}. The LZMA marker
|
||||||
@samp{2} ("End Of Stream" marker) is the only marker allowed in lzip files.
|
@samp{2} ('End Of Stream' marker) is the only marker allowed in lzip files.
|
||||||
@xref{File format}.
|
@xref{File format}.
|
||||||
|
|
||||||
Repeated use of @samp{LZ_compress_sync_flush} may degrade compression
|
Repeated use of @samp{LZ_compress_sync_flush} may degrade compression
|
||||||
|
@ -401,7 +369,7 @@ are more bytes available than those needed to complete @var{member_size},
|
||||||
@end deftypefun
|
@end deftypefun
|
||||||
|
|
||||||
|
|
||||||
@deftypefun int LZ_compress_read ( struct LZ_Encoder * const @var{encoder}, uint8_t * const @var{buffer}, const int @var{size} )
|
@deftypefun int LZ_compress_read ( LZ_Encoder * const @var{encoder}, uint8_t * const @var{buffer}, const int @var{size} )
|
||||||
Reads up to @var{size} bytes from the stream pointed to by @var{encoder},
|
Reads up to @var{size} bytes from the stream pointed to by @var{encoder},
|
||||||
storing the results in @var{buffer}. If @w{LZ_API_VERSION >= 1012},
|
storing the results in @var{buffer}. If @w{LZ_API_VERSION >= 1012},
|
||||||
@var{buffer} may be a null pointer, in which case the bytes read are
|
@var{buffer} may be a null pointer, in which case the bytes read are
|
||||||
|
@ -415,7 +383,7 @@ not an error.
|
||||||
@end deftypefun
|
@end deftypefun
|
||||||
|
|
||||||
|
|
||||||
@deftypefun int LZ_compress_write ( struct LZ_Encoder * const @var{encoder}, uint8_t * const @var{buffer}, const int @var{size} )
|
@deftypefun int LZ_compress_write ( LZ_Encoder * const @var{encoder}, uint8_t * const @var{buffer}, const int @var{size} )
|
||||||
Writes up to @var{size} bytes from @var{buffer} to the stream pointed to by
|
Writes up to @var{size} bytes from @var{buffer} to the stream pointed to by
|
||||||
@var{encoder}. Returns the number of bytes actually written. This might be
|
@var{encoder}. Returns the number of bytes actually written. This might be
|
||||||
less than @var{size}. Note that writing less than @var{size} bytes is not an
|
less than @var{size}. Note that writing less than @var{size} bytes is not an
|
||||||
|
@ -423,7 +391,7 @@ error.
|
||||||
@end deftypefun
|
@end deftypefun
|
||||||
|
|
||||||
|
|
||||||
@deftypefun int LZ_compress_write_size ( struct LZ_Encoder * const @var{encoder} )
|
@deftypefun int LZ_compress_write_size ( LZ_Encoder * const @var{encoder} )
|
||||||
Returns the maximum number of bytes that can be immediately written through
|
Returns the maximum number of bytes that can be immediately written through
|
||||||
@samp{LZ_compress_write}. For efficiency reasons, once the input buffer is
|
@samp{LZ_compress_write}. For efficiency reasons, once the input buffer is
|
||||||
full and @samp{LZ_compress_write_size} returns 0, almost all the buffer must
|
full and @samp{LZ_compress_write_size} returns 0, almost all the buffer must
|
||||||
|
@ -436,44 +404,44 @@ accept a @var{size} up to the returned number of bytes.
|
||||||
@end deftypefun
|
@end deftypefun
|
||||||
|
|
||||||
|
|
||||||
@deftypefun {enum LZ_Errno} LZ_compress_errno ( struct LZ_Encoder * const @var{encoder} )
|
@deftypefun {LZ_Errno} LZ_compress_errno ( LZ_Encoder * const @var{encoder} )
|
||||||
Returns the current error code for @var{encoder}. @xref{Error codes}.
|
Returns the current error code for @var{encoder}. @xref{Error codes}.
|
||||||
It is safe to call @samp{LZ_compress_errno} with a null argument, in which
|
It is safe to call @samp{LZ_compress_errno} with a null argument, in which
|
||||||
case it returns @samp{LZ_bad_argument}.
|
case it returns @samp{LZ_bad_argument}.
|
||||||
@end deftypefun
|
@end deftypefun
|
||||||
|
|
||||||
|
|
||||||
@deftypefun int LZ_compress_finished ( struct LZ_Encoder * const @var{encoder} )
|
@deftypefun int LZ_compress_finished ( LZ_Encoder * const @var{encoder} )
|
||||||
Returns 1 if all the data have been read and @samp{LZ_compress_close}
|
Returns 1 if all the data have been read and @samp{LZ_compress_close}
|
||||||
can be safely called. Otherwise it returns 0. @samp{LZ_compress_finished}
|
can be safely called. Otherwise it returns 0. @samp{LZ_compress_finished}
|
||||||
implies @samp{LZ_compress_member_finished}.
|
implies @samp{LZ_compress_member_finished}.
|
||||||
@end deftypefun
|
@end deftypefun
|
||||||
|
|
||||||
|
|
||||||
@deftypefun int LZ_compress_member_finished ( struct LZ_Encoder * const @var{encoder} )
|
@deftypefun int LZ_compress_member_finished ( LZ_Encoder * const @var{encoder} )
|
||||||
Returns 1 if the current member, in a multimember data stream, has been
|
Returns 1 if the current member, in a multimember data stream, has been
|
||||||
fully read and @samp{LZ_compress_restart_member} can be safely called.
|
fully read and @samp{LZ_compress_restart_member} can be safely called.
|
||||||
Otherwise it returns 0.
|
Otherwise it returns 0.
|
||||||
@end deftypefun
|
@end deftypefun
|
||||||
|
|
||||||
|
|
||||||
@deftypefun {unsigned long long} LZ_compress_data_position ( struct LZ_Encoder * const @var{encoder} )
|
@deftypefun {unsigned long long} LZ_compress_data_position ( LZ_Encoder * const @var{encoder} )
|
||||||
Returns the number of input bytes already compressed in the current member.
|
Returns the number of input bytes already compressed in the current member.
|
||||||
@end deftypefun
|
@end deftypefun
|
||||||
|
|
||||||
|
|
||||||
@deftypefun {unsigned long long} LZ_compress_member_position ( struct LZ_Encoder * const @var{encoder} )
|
@deftypefun {unsigned long long} LZ_compress_member_position ( LZ_Encoder * const @var{encoder} )
|
||||||
Returns the number of compressed bytes already produced, but perhaps not
|
Returns the number of compressed bytes already produced, but perhaps not
|
||||||
yet read, in the current member.
|
yet read, in the current member.
|
||||||
@end deftypefun
|
@end deftypefun
|
||||||
|
|
||||||
|
|
||||||
@deftypefun {unsigned long long} LZ_compress_total_in_size ( struct LZ_Encoder * const @var{encoder} )
|
@deftypefun {unsigned long long} LZ_compress_total_in_size ( LZ_Encoder * const @var{encoder} )
|
||||||
Returns the total number of input bytes already compressed.
|
Returns the total number of input bytes already compressed.
|
||||||
@end deftypefun
|
@end deftypefun
|
||||||
|
|
||||||
|
|
||||||
@deftypefun {unsigned long long} LZ_compress_total_out_size ( struct LZ_Encoder * const @var{encoder} )
|
@deftypefun {unsigned long long} LZ_compress_total_out_size ( LZ_Encoder * const @var{encoder} )
|
||||||
Returns the total number of compressed bytes already produced, but
|
Returns the total number of compressed bytes already produced, but
|
||||||
perhaps not yet read.
|
perhaps not yet read.
|
||||||
@end deftypefun
|
@end deftypefun
|
||||||
|
@ -489,7 +457,7 @@ except @samp{LZ_decompress_open} whose return value must be checked by
|
||||||
calling @samp{LZ_decompress_errno} before using it.
|
calling @samp{LZ_decompress_errno} before using it.
|
||||||
|
|
||||||
|
|
||||||
@deftypefun {struct LZ_Decoder *} LZ_decompress_open ( void )
|
@deftypefun {LZ_Decoder *} LZ_decompress_open ( void )
|
||||||
Initializes the internal stream state for decompression and returns a
|
Initializes the internal stream state for decompression and returns a
|
||||||
pointer that can only be used as the @var{decoder} argument for the other
|
pointer that can only be used as the @var{decoder} argument for the other
|
||||||
LZ_decompress functions, or a null pointer if the decoder could not be
|
LZ_decompress functions, or a null pointer if the decoder could not be
|
||||||
|
@ -502,7 +470,7 @@ the returned pointer must not be used and should be freed with
|
||||||
@end deftypefun
|
@end deftypefun
|
||||||
|
|
||||||
|
|
||||||
@deftypefun int LZ_decompress_close ( struct LZ_Decoder * const @var{decoder} )
|
@deftypefun int LZ_decompress_close ( LZ_Decoder * const @var{decoder} )
|
||||||
Frees all dynamically allocated data structures for this stream. This
|
Frees all dynamically allocated data structures for this stream. This
|
||||||
function discards any unprocessed input and does not flush any pending
|
function discards any unprocessed input and does not flush any pending
|
||||||
output. After a call to @samp{LZ_decompress_close}, @var{decoder} can no
|
output. After a call to @samp{LZ_decompress_close}, @var{decoder} can no
|
||||||
|
@ -511,7 +479,7 @@ It is safe to call @samp{LZ_decompress_close} with a null argument.
|
||||||
@end deftypefun
|
@end deftypefun
|
||||||
|
|
||||||
|
|
||||||
@deftypefun int LZ_decompress_finish ( struct LZ_Decoder * const @var{decoder} )
|
@deftypefun int LZ_decompress_finish ( LZ_Decoder * const @var{decoder} )
|
||||||
Use this function to tell @samp{lzlib} that all the data for this stream
|
Use this function to tell @samp{lzlib} that all the data for this stream
|
||||||
have already been written (with the function @samp{LZ_decompress_write}).
|
have already been written (with the function @samp{LZ_decompress_write}).
|
||||||
It is safe to call @samp{LZ_decompress_finish} as many times as needed.
|
It is safe to call @samp{LZ_decompress_finish} as many times as needed.
|
||||||
|
@ -521,14 +489,14 @@ detecting a truncated member.
|
||||||
@end deftypefun
|
@end deftypefun
|
||||||
|
|
||||||
|
|
||||||
@deftypefun int LZ_decompress_reset ( struct LZ_Decoder * const @var{decoder} )
|
@deftypefun int LZ_decompress_reset ( LZ_Decoder * const @var{decoder} )
|
||||||
Resets the internal state of @var{decoder} as it was just after opening
|
Resets the internal state of @var{decoder} as it was just after opening
|
||||||
it with the function @samp{LZ_decompress_open}. Data stored in the
|
it with the function @samp{LZ_decompress_open}. Data stored in the
|
||||||
internal buffers are discarded. Position counters are set to 0.
|
internal buffers are discarded. Position counters are set to 0.
|
||||||
@end deftypefun
|
@end deftypefun
|
||||||
|
|
||||||
|
|
||||||
@deftypefun int LZ_decompress_sync_to_member ( struct LZ_Decoder * const @var{decoder} )
|
@deftypefun int LZ_decompress_sync_to_member ( LZ_Decoder * const @var{decoder} )
|
||||||
Resets the error state of @var{decoder} and enters a search state that lasts
|
Resets the error state of @var{decoder} and enters a search state that lasts
|
||||||
until a new member header (or the end of the stream) is found. After a
|
until a new member header (or the end of the stream) is found. After a
|
||||||
successful call to @samp{LZ_decompress_sync_to_member}, data written with
|
successful call to @samp{LZ_decompress_sync_to_member}, data written with
|
||||||
|
@ -542,7 +510,7 @@ does nothing.
|
||||||
@end deftypefun
|
@end deftypefun
|
||||||
|
|
||||||
|
|
||||||
@deftypefun int LZ_decompress_read ( struct LZ_Decoder * const @var{decoder}, uint8_t * const @var{buffer}, const int @var{size} )
|
@deftypefun int LZ_decompress_read ( LZ_Decoder * const @var{decoder}, uint8_t * const @var{buffer}, const int @var{size} )
|
||||||
Reads up to @var{size} bytes from the stream pointed to by @var{decoder},
|
Reads up to @var{size} bytes from the stream pointed to by @var{decoder},
|
||||||
storing the results in @var{buffer}. If @w{LZ_API_VERSION >= 1012},
|
storing the results in @var{buffer}. If @w{LZ_API_VERSION >= 1012},
|
||||||
@var{buffer} may be a null pointer, in which case the bytes read are
|
@var{buffer} may be a null pointer, in which case the bytes read are
|
||||||
|
@ -574,7 +542,7 @@ recover as much data as possible from each damaged member.
|
||||||
@end deftypefun
|
@end deftypefun
|
||||||
|
|
||||||
|
|
||||||
@deftypefun int LZ_decompress_write ( struct LZ_Decoder * const @var{decoder}, uint8_t * const @var{buffer}, const int @var{size} )
|
@deftypefun int LZ_decompress_write ( LZ_Decoder * const @var{decoder}, uint8_t * const @var{buffer}, const int @var{size} )
|
||||||
Writes up to @var{size} bytes from @var{buffer} to the stream pointed to by
|
Writes up to @var{size} bytes from @var{buffer} to the stream pointed to by
|
||||||
@var{decoder}. Returns the number of bytes actually written. This might be
|
@var{decoder}. Returns the number of bytes actually written. This might be
|
||||||
less than @var{size}. Note that writing less than @var{size} bytes is not an
|
less than @var{size}. Note that writing less than @var{size} bytes is not an
|
||||||
|
@ -582,7 +550,7 @@ error.
|
||||||
@end deftypefun
|
@end deftypefun
|
||||||
|
|
||||||
|
|
||||||
@deftypefun int LZ_decompress_write_size ( struct LZ_Decoder * const @var{decoder} )
|
@deftypefun int LZ_decompress_write_size ( LZ_Decoder * const @var{decoder} )
|
||||||
Returns the maximum number of bytes that can be immediately written through
|
Returns the maximum number of bytes that can be immediately written through
|
||||||
@samp{LZ_decompress_write}. This number varies smoothly; each compressed
|
@samp{LZ_decompress_write}. This number varies smoothly; each compressed
|
||||||
byte consumed may be overwritten immediately, increasing by 1 the value
|
byte consumed may be overwritten immediately, increasing by 1 the value
|
||||||
|
@ -593,21 +561,21 @@ accept a @var{size} up to the returned number of bytes.
|
||||||
@end deftypefun
|
@end deftypefun
|
||||||
|
|
||||||
|
|
||||||
@deftypefun {enum LZ_Errno} LZ_decompress_errno ( struct LZ_Decoder * const @var{decoder} )
|
@deftypefun {LZ_Errno} LZ_decompress_errno ( LZ_Decoder * const @var{decoder} )
|
||||||
Returns the current error code for @var{decoder}. @xref{Error codes}.
|
Returns the current error code for @var{decoder}. @xref{Error codes}.
|
||||||
It is safe to call @samp{LZ_decompress_errno} with a null argument, in which
|
It is safe to call @samp{LZ_decompress_errno} with a null argument, in which
|
||||||
case it returns @samp{LZ_bad_argument}.
|
case it returns @samp{LZ_bad_argument}.
|
||||||
@end deftypefun
|
@end deftypefun
|
||||||
|
|
||||||
|
|
||||||
@deftypefun int LZ_decompress_finished ( struct LZ_Decoder * const @var{decoder} )
|
@deftypefun int LZ_decompress_finished ( LZ_Decoder * const @var{decoder} )
|
||||||
Returns 1 if all the data have been read and @samp{LZ_decompress_close}
|
Returns 1 if all the data have been read and @samp{LZ_decompress_close}
|
||||||
can be safely called. Otherwise it returns 0. @samp{LZ_decompress_finished}
|
can be safely called. Otherwise it returns 0. @samp{LZ_decompress_finished}
|
||||||
does not imply @samp{LZ_decompress_member_finished}.
|
does not imply @samp{LZ_decompress_member_finished}.
|
||||||
@end deftypefun
|
@end deftypefun
|
||||||
|
|
||||||
|
|
||||||
@deftypefun int LZ_decompress_member_finished ( struct LZ_Decoder * const @var{decoder} )
|
@deftypefun int LZ_decompress_member_finished ( LZ_Decoder * const @var{decoder} )
|
||||||
Returns 1 if the previous call to @samp{LZ_decompress_read} finished reading
|
Returns 1 if the previous call to @samp{LZ_decompress_read} finished reading
|
||||||
the current member, indicating that final values for the member are available
|
the current member, indicating that final values for the member are available
|
||||||
through @samp{LZ_decompress_data_crc}, @samp{LZ_decompress_data_position},
|
through @samp{LZ_decompress_data_crc}, @samp{LZ_decompress_data_position},
|
||||||
|
@ -615,40 +583,40 @@ and @samp{LZ_decompress_member_position}. Otherwise it returns 0.
|
||||||
@end deftypefun
|
@end deftypefun
|
||||||
|
|
||||||
|
|
||||||
@deftypefun int LZ_decompress_member_version ( struct LZ_Decoder * const @var{decoder} )
|
@deftypefun int LZ_decompress_member_version ( LZ_Decoder * const @var{decoder} )
|
||||||
Returns the version of the current member, read from the member header.
|
Returns the version of the current member, read from the member header.
|
||||||
@end deftypefun
|
@end deftypefun
|
||||||
|
|
||||||
|
|
||||||
@deftypefun int LZ_decompress_dictionary_size ( struct LZ_Decoder * const @var{decoder} )
|
@deftypefun int LZ_decompress_dictionary_size ( LZ_Decoder * const @var{decoder} )
|
||||||
Returns the dictionary size of the current member, read from the member header.
|
Returns the dictionary size of the current member, read from the member header.
|
||||||
@end deftypefun
|
@end deftypefun
|
||||||
|
|
||||||
|
|
||||||
@deftypefun {unsigned} LZ_decompress_data_crc ( struct LZ_Decoder * const @var{decoder} )
|
@deftypefun {unsigned} LZ_decompress_data_crc ( LZ_Decoder * const @var{decoder} )
|
||||||
Returns the 32 bit Cyclic Redundancy Check of the data decompressed from
|
Returns the 32 bit Cyclic Redundancy Check of the data decompressed from
|
||||||
the current member. The value returned is valid only when
|
the current member. The value returned is valid only when
|
||||||
@samp{LZ_decompress_member_finished} returns 1.
|
@samp{LZ_decompress_member_finished} returns 1.
|
||||||
@end deftypefun
|
@end deftypefun
|
||||||
|
|
||||||
|
|
||||||
@deftypefun {unsigned long long} LZ_decompress_data_position ( struct LZ_Decoder * const @var{decoder} )
|
@deftypefun {unsigned long long} LZ_decompress_data_position ( LZ_Decoder * const @var{decoder} )
|
||||||
Returns the number of decompressed bytes already produced, but perhaps
|
Returns the number of decompressed bytes already produced, but perhaps
|
||||||
not yet read, in the current member.
|
not yet read, in the current member.
|
||||||
@end deftypefun
|
@end deftypefun
|
||||||
|
|
||||||
|
|
||||||
@deftypefun {unsigned long long} LZ_decompress_member_position ( struct LZ_Decoder * const @var{decoder} )
|
@deftypefun {unsigned long long} LZ_decompress_member_position ( LZ_Decoder * const @var{decoder} )
|
||||||
Returns the number of input bytes already decompressed in the current member.
|
Returns the number of input bytes already decompressed in the current member.
|
||||||
@end deftypefun
|
@end deftypefun
|
||||||
|
|
||||||
|
|
||||||
@deftypefun {unsigned long long} LZ_decompress_total_in_size ( struct LZ_Decoder * const @var{decoder} )
|
@deftypefun {unsigned long long} LZ_decompress_total_in_size ( LZ_Decoder * const @var{decoder} )
|
||||||
Returns the total number of input bytes already decompressed.
|
Returns the total number of input bytes already decompressed.
|
||||||
@end deftypefun
|
@end deftypefun
|
||||||
|
|
||||||
|
|
||||||
@deftypefun {unsigned long long} LZ_decompress_total_out_size ( struct LZ_Decoder * const @var{decoder} )
|
@deftypefun {unsigned long long} LZ_decompress_total_out_size ( LZ_Decoder * const @var{decoder} )
|
||||||
Returns the total number of decompressed bytes already produced, but
|
Returns the total number of decompressed bytes already produced, but
|
||||||
perhaps not yet read.
|
perhaps not yet read.
|
||||||
@end deftypefun
|
@end deftypefun
|
||||||
|
@ -671,37 +639,38 @@ to determine whether a call failed. If the call failed, then you can
|
||||||
examine @samp{LZ_(de)compress_errno}.
|
examine @samp{LZ_(de)compress_errno}.
|
||||||
|
|
||||||
The error codes are defined in the header file @file{lzlib.h}.
|
The error codes are defined in the header file @file{lzlib.h}.
|
||||||
|
@samp{LZ_Errno} is an enum type:
|
||||||
|
|
||||||
@deftypevr Constant {enum LZ_Errno} LZ_ok
|
@deftypevr Constant {LZ_Errno} LZ_ok
|
||||||
The value of this constant is 0 and is used to indicate that there is no error.
|
The value of this constant is 0 and is used to indicate that there is no error.
|
||||||
@end deftypevr
|
@end deftypevr
|
||||||
|
|
||||||
@deftypevr Constant {enum LZ_Errno} LZ_bad_argument
|
@deftypevr Constant {LZ_Errno} LZ_bad_argument
|
||||||
At least one of the arguments passed to the library function was invalid.
|
At least one of the arguments passed to the library function was invalid.
|
||||||
@end deftypevr
|
@end deftypevr
|
||||||
|
|
||||||
@deftypevr Constant {enum LZ_Errno} LZ_mem_error
|
@deftypevr Constant {LZ_Errno} LZ_mem_error
|
||||||
No memory available. The system cannot allocate more virtual memory
|
No memory available. The system cannot allocate more virtual memory because
|
||||||
because its capacity is full.
|
its capacity is full.
|
||||||
@end deftypevr
|
@end deftypevr
|
||||||
|
|
||||||
@deftypevr Constant {enum LZ_Errno} LZ_sequence_error
|
@deftypevr Constant {LZ_Errno} LZ_sequence_error
|
||||||
A library function was called in the wrong order. For example
|
A library function was called in the wrong order. For example
|
||||||
@samp{LZ_compress_restart_member} was called before
|
@samp{LZ_compress_restart_member} was called before
|
||||||
@samp{LZ_compress_member_finished} indicates that the current member is
|
@samp{LZ_compress_member_finished} indicated that the current member is
|
||||||
finished.
|
finished.
|
||||||
@end deftypevr
|
@end deftypevr
|
||||||
|
|
||||||
@deftypevr Constant {enum LZ_Errno} LZ_header_error
|
@deftypevr Constant {LZ_Errno} LZ_header_error
|
||||||
An invalid member header (one with the wrong magic bytes) was read. If this
|
An invalid member header (one with the wrong magic bytes) was read. If this
|
||||||
happens at the end of the data stream it may indicate trailing data.
|
happens at the end of the data stream it may indicate trailing data.
|
||||||
@end deftypevr
|
@end deftypevr
|
||||||
|
|
||||||
@deftypevr Constant {enum LZ_Errno} LZ_unexpected_eof
|
@deftypevr Constant {LZ_Errno} LZ_unexpected_eof
|
||||||
The end of the data stream was reached in the middle of a member.
|
The end of the data stream was reached in the middle of a member.
|
||||||
@end deftypevr
|
@end deftypevr
|
||||||
|
|
||||||
@deftypevr Constant {enum LZ_Errno} LZ_data_error
|
@deftypevr Constant {LZ_Errno} LZ_data_error
|
||||||
The data stream is corrupt. If @samp{LZ_decompress_member_position} is 6 or
|
The data stream is corrupt. If @samp{LZ_decompress_member_position} is 6 or
|
||||||
less, it indicates either a format version not supported, an invalid
|
less, it indicates either a format version not supported, an invalid
|
||||||
dictionary size, a nonzero first LZMA byte, a corrupt header in a multimember
|
dictionary size, a nonzero first LZMA byte, a corrupt header in a multimember
|
||||||
|
@ -710,7 +679,7 @@ Lziprecover can be used to repair some of these errors and to remove
|
||||||
conflicting trailing data from a file.
|
conflicting trailing data from a file.
|
||||||
@end deftypevr
|
@end deftypevr
|
||||||
|
|
||||||
@deftypevr Constant {enum LZ_Errno} LZ_library_error
|
@deftypevr Constant {LZ_Errno} LZ_library_error
|
||||||
A bug was detected in the library. Please, report it. @xref{Problems}.
|
A bug was detected in the library. Please, report it. @xref{Problems}.
|
||||||
@end deftypevr
|
@end deftypevr
|
||||||
|
|
||||||
|
@ -719,11 +688,11 @@ A bug was detected in the library. Please, report it. @xref{Problems}.
|
||||||
@chapter Error messages
|
@chapter Error messages
|
||||||
@cindex error messages
|
@cindex error messages
|
||||||
|
|
||||||
@deftypefun {const char *} LZ_strerror ( const enum LZ_Errno @var{lz_errno} )
|
@deftypefun {const char *} LZ_strerror ( const LZ_Errno @var{lz_errno} )
|
||||||
Returns the standard error message for a given error code. The messages
|
Returns the error message corresponding to the error code @var{lz_errno}.
|
||||||
are fairly short; there are no multi-line messages or embedded newlines.
|
The messages are fairly short; there are no multi-line messages or embedded
|
||||||
This function makes it easy for your program to report informative error
|
newlines. This function makes it easy for your program to report informative
|
||||||
messages about the failure of a library call.
|
error messages about the failure of a library call.
|
||||||
|
|
||||||
The value of @var{lz_errno} normally comes from a call to
|
The value of @var{lz_errno} normally comes from a call to
|
||||||
@samp{LZ_(de)compress_errno}.
|
@samp{LZ_(de)compress_errno}.
|
||||||
|
@ -735,23 +704,25 @@ The value of @var{lz_errno} normally comes from a call to
|
||||||
@cindex invoking
|
@cindex invoking
|
||||||
@cindex options
|
@cindex options
|
||||||
|
|
||||||
Minilzip is a test program for the compression library lzlib, compatible
|
Minilzip is a test program for the compression library lzlib. Minilzip is
|
||||||
(interoperable) with lzip 1.4 or newer. Minilzip is not intended to be
|
not intended to be installed because lzip has more features, but minilzip is
|
||||||
installed because lzip has more features, but minilzip is well tested and
|
well tested and you can use it as your main compressor if so you wish.
|
||||||
you can use it as your main compressor if so you wish.
|
@ifnothtml
|
||||||
|
@xref{Top,lzip,,lzip}.
|
||||||
|
@end ifnothtml
|
||||||
|
|
||||||
@uref{http://www.nongnu.org/lzip/lzip.html,,Lzip}
|
@uref{http://www.nongnu.org/lzip/lzip.html,,Lzip}
|
||||||
is a lossless data compressor with a user interface similar to the one
|
is a lossless data compressor with a user interface similar to the one
|
||||||
of gzip or bzip2. Lzip uses a simplified form of the 'Lempel-Ziv-Markov
|
of gzip or bzip2. Lzip uses a simplified form of LZMA (Lempel-Ziv-Markov
|
||||||
chain-Algorithm' (LZMA) stream format to maximize interoperability. The
|
chain-Algorithm) designed to achieve complete interoperability between
|
||||||
maximum dictionary size is 512 MiB so that any lzip file can be decompressed
|
implementations. The maximum dictionary size is 512 MiB so that any lzip
|
||||||
on 32-bit machines. Lzip provides accurate and robust 3-factor integrity
|
file can be decompressed on 32-bit machines. Lzip provides accurate and
|
||||||
checking. Lzip can compress about as fast as gzip @w{(lzip -0)} or compress most
|
robust 3-factor integrity checking. @w{@samp{lzip -0}} compresses about as fast as
|
||||||
files more than bzip2 @w{(lzip -9)}. Decompression speed is intermediate between
|
gzip, while @w{@samp{lzip -9}} compresses most files more than bzip2. Decompression
|
||||||
gzip and bzip2. Lzip provides better data recovery capabilities than gzip
|
speed is intermediate between gzip and bzip2. Lzip provides better data
|
||||||
and bzip2. Lzip has been designed, written, and tested with great care to
|
recovery capabilities than gzip and bzip2. Lzip has been designed, written,
|
||||||
replace gzip and bzip2 as the standard general-purpose compressed format for
|
and tested with great care to replace gzip and bzip2 as general-purpose
|
||||||
Unix-like systems.
|
compressed format for Unix-like systems.
|
||||||
|
|
||||||
@noindent
|
@noindent
|
||||||
The format for running minilzip is:
|
The format for running minilzip is:
|
||||||
|
@ -769,9 +740,9 @@ prepend @file{./} to any file name beginning with a hyphen, or use @samp{--}.
|
||||||
|
|
||||||
@noindent
|
@noindent
|
||||||
minilzip supports the following
|
minilzip supports the following
|
||||||
@uref{http://www.nongnu.org/arg-parser/manual/arg_parser_manual.html#Argument-syntax,,options}:
|
@uref{http://www.nongnu.org/lzip/manual/plzip_manual.html#Argument-syntax,,options}:
|
||||||
@ifnothtml
|
@ifnothtml
|
||||||
@xref{Argument syntax,,,arg_parser}.
|
@xref{Argument syntax,,,plzip}.
|
||||||
@end ifnothtml
|
@end ifnothtml
|
||||||
|
|
||||||
@table @code
|
@table @code
|
||||||
|
@ -792,9 +763,10 @@ garbage that can be safely ignored.
|
||||||
|
|
||||||
@item -b @var{bytes}
|
@item -b @var{bytes}
|
||||||
@itemx --member-size=@var{bytes}
|
@itemx --member-size=@var{bytes}
|
||||||
When compressing, set the member size limit to @var{bytes}. It is advisable
|
When compressing, set the member size limit to @var{bytes}. If @var{bytes}
|
||||||
to keep members smaller than RAM size so that they can be repaired with
|
is smaller than the compressed size, a multimember file is produced. It is
|
||||||
lziprecover in case of corruption. A small member size may degrade
|
advisable to keep members smaller than RAM size so that they can be repaired
|
||||||
|
with lziprecover in case of corruption. A small member size may degrade
|
||||||
compression ratio, so use it only when needed. Valid values range from
|
compression ratio, so use it only when needed. Valid values range from
|
||||||
@w{100 kB} to @w{2 PiB}. Defaults to @w{2 PiB}.
|
@w{100 kB} to @w{2 PiB}. Defaults to @w{2 PiB}.
|
||||||
|
|
||||||
|
@ -816,7 +788,8 @@ already exists and @option{--force} has not been specified, minilzip continues
|
||||||
decompressing the rest of the files and exits with error status 1. If a file
|
decompressing the rest of the files and exits with error status 1. If a file
|
||||||
fails to decompress, or is a terminal, minilzip exits immediately with error
|
fails to decompress, or is a terminal, minilzip exits immediately with error
|
||||||
status 2 without decompressing the rest of the files. A terminal is
|
status 2 without decompressing the rest of the files. A terminal is
|
||||||
considered an uncompressed file, and therefore invalid.
|
considered an uncompressed file, and therefore invalid. A multimember file
|
||||||
|
with one or more empty members is accepted if redirected to standard input.
|
||||||
|
|
||||||
@item -f
|
@item -f
|
||||||
@itemx --force
|
@itemx --force
|
||||||
|
@ -870,6 +843,8 @@ to it.
|
||||||
For maximum compression you should use a dictionary size limit as large
|
For maximum compression you should use a dictionary size limit as large
|
||||||
as possible, but keep in mind that the decompression memory requirement
|
as possible, but keep in mind that the decompression memory requirement
|
||||||
is affected at compression time by the choice of dictionary size limit.
|
is affected at compression time by the choice of dictionary size limit.
|
||||||
|
The dictionary size used for decompression is the same dictionary size used
|
||||||
|
for compression.
|
||||||
|
|
||||||
@item -S @var{bytes}
|
@item -S @var{bytes}
|
||||||
@itemx --volume-size=@var{bytes}
|
@itemx --volume-size=@var{bytes}
|
||||||
|
@ -889,7 +864,8 @@ together with @option{-v} to see information about the files. If a file
|
||||||
fails the test, does not exist, can't be opened, or is a terminal, minilzip
|
fails the test, does not exist, can't be opened, or is a terminal, minilzip
|
||||||
continues testing the rest of the files. A final diagnostic is shown at
|
continues testing the rest of the files. A final diagnostic is shown at
|
||||||
verbosity level 1 or higher if any file fails the test when testing multiple
|
verbosity level 1 or higher if any file fails the test when testing multiple
|
||||||
files.
|
files. A multimember file with one or more empty members is accepted if
|
||||||
|
redirected to standard input.
|
||||||
|
|
||||||
@item -v
|
@item -v
|
||||||
@itemx --verbose
|
@itemx --verbose
|
||||||
|
@ -936,8 +912,8 @@ Aliases for GNU gzip compatibility.
|
||||||
@item --loose-trailing
|
@item --loose-trailing
|
||||||
When decompressing or testing, allow trailing data whose first bytes are
|
When decompressing or testing, allow trailing data whose first bytes are
|
||||||
so similar to the magic bytes of a lzip header that they can be confused
|
so similar to the magic bytes of a lzip header that they can be confused
|
||||||
with a corrupt header. Use this option if a file triggers a "corrupt
|
with a corrupt header. Use this option if a file triggers a 'corrupt
|
||||||
header" error and the cause is not indeed a corrupt header.
|
header' error and the cause is not indeed a corrupt header.
|
||||||
|
|
||||||
@item --check-lib
|
@item --check-lib
|
||||||
Compare the @uref{#Library-version,,version of lzlib} used to compile
|
Compare the @uref{#Library-version,,version of lzlib} used to compile
|
||||||
|
@ -1044,7 +1020,7 @@ Example: 0xD3 = 2^19 - 6 * 2^15 = 512 KiB - 6 * 32 KiB = 320 KiB@*
|
||||||
Valid values for dictionary size range from 4 KiB to 512 MiB.
|
Valid values for dictionary size range from 4 KiB to 512 MiB.
|
||||||
|
|
||||||
@item LZMA stream
|
@item LZMA stream
|
||||||
The LZMA stream, terminated by an "End Of Stream" marker. Uses default values
|
The LZMA stream, terminated by an 'End Of Stream' marker. Uses default values
|
||||||
for encoder properties.
|
for encoder properties.
|
||||||
@ifnothtml
|
@ifnothtml
|
||||||
@xref{Stream format,,,lzip},
|
@xref{Stream format,,,lzip},
|
||||||
|
@ -1054,8 +1030,8 @@ See
|
||||||
@uref{http://www.nongnu.org/lzip/manual/lzip_manual.html#Stream-format,,Stream format}
|
@uref{http://www.nongnu.org/lzip/manual/lzip_manual.html#Stream-format,,Stream format}
|
||||||
@end ifhtml
|
@end ifhtml
|
||||||
for a complete description.@*
|
for a complete description.@*
|
||||||
Lzip only uses the LZMA marker @samp{2} ("End Of Stream" marker). Lzlib
|
Lzip only uses the LZMA marker @samp{2} ('End Of Stream' marker). Lzlib
|
||||||
also uses the LZMA marker @samp{3} ("Sync Flush" marker). @xref{sync_flush}.
|
also uses the LZMA marker @samp{3} ('Sync Flush' marker). @xref{sync_flush}.
|
||||||
|
|
||||||
@item CRC32 (4 bytes)
|
@item CRC32 (4 bytes)
|
||||||
Cyclic Redundancy Check (CRC) of the original uncompressed data.
|
Cyclic Redundancy Check (CRC) of the original uncompressed data.
|
||||||
|
@ -1115,7 +1091,7 @@ bool bbcompress( const uint8_t * const inbuf, const int insize,
|
||||||
{
|
{
|
||||||
int inpos = 0, outpos = 0;
|
int inpos = 0, outpos = 0;
|
||||||
bool error = false;
|
bool error = false;
|
||||||
struct LZ_Encoder * const encoder =
|
LZ_Encoder * const encoder =
|
||||||
LZ_compress_open( dictionary_size, match_len_limit, INT64_MAX );
|
LZ_compress_open( dictionary_size, match_len_limit, INT64_MAX );
|
||||||
if( !encoder || LZ_compress_errno( encoder ) != LZ_ok )
|
if( !encoder || LZ_compress_errno( encoder ) != LZ_ok )
|
||||||
{ LZ_compress_close( encoder ); return false; }
|
{ LZ_compress_close( encoder ); return false; }
|
||||||
|
@ -1159,7 +1135,7 @@ bool bbdecompress( const uint8_t * const inbuf, const int insize,
|
||||||
{
|
{
|
||||||
int inpos = 0, outpos = 0;
|
int inpos = 0, outpos = 0;
|
||||||
bool error = false;
|
bool error = false;
|
||||||
struct LZ_Decoder * const decoder = LZ_decompress_open();
|
LZ_Decoder * const decoder = LZ_decompress_open();
|
||||||
if( !decoder || LZ_decompress_errno( decoder ) != LZ_ok )
|
if( !decoder || LZ_decompress_errno( decoder ) != LZ_ok )
|
||||||
{ LZ_decompress_close( decoder ); return false; }
|
{ LZ_decompress_close( decoder ); return false; }
|
||||||
|
|
||||||
|
@ -1191,7 +1167,7 @@ bool bbdecompress( const uint8_t * const inbuf, const int insize,
|
||||||
File-to-file compression using LZ_compress_write_size.
|
File-to-file compression using LZ_compress_write_size.
|
||||||
|
|
||||||
@verbatim
|
@verbatim
|
||||||
int ffcompress( struct LZ_Encoder * const encoder,
|
int ffcompress( LZ_Encoder * const encoder,
|
||||||
FILE * const infile, FILE * const outfile )
|
FILE * const infile, FILE * const outfile )
|
||||||
{
|
{
|
||||||
enum { buffer_size = 16384 };
|
enum { buffer_size = 16384 };
|
||||||
|
@ -1225,7 +1201,7 @@ int ffcompress( struct LZ_Encoder * const encoder,
|
||||||
File-to-file decompression using LZ_decompress_write_size.
|
File-to-file decompression using LZ_decompress_write_size.
|
||||||
|
|
||||||
@verbatim
|
@verbatim
|
||||||
int ffdecompress( struct LZ_Decoder * const decoder,
|
int ffdecompress( LZ_Decoder * const decoder,
|
||||||
FILE * const infile, FILE * const outfile )
|
FILE * const infile, FILE * const outfile )
|
||||||
{
|
{
|
||||||
enum { buffer_size = 16384 };
|
enum { buffer_size = 16384 };
|
||||||
|
@ -1265,8 +1241,7 @@ int ffmmcompress( FILE * const infile, FILE * const outfile )
|
||||||
enum { buffer_size = 16384, member_size = 4096 };
|
enum { buffer_size = 16384, member_size = 4096 };
|
||||||
uint8_t buffer[buffer_size];
|
uint8_t buffer[buffer_size];
|
||||||
bool done = false;
|
bool done = false;
|
||||||
struct LZ_Encoder * const encoder =
|
LZ_Encoder * const encoder = LZ_compress_open( 65535, 16, member_size );
|
||||||
LZ_compress_open( 65535, 16, member_size );
|
|
||||||
if( !encoder || LZ_compress_errno( encoder ) != LZ_ok )
|
if( !encoder || LZ_compress_errno( encoder ) != LZ_ok )
|
||||||
{ fputs( "ffexample: Not enough memory.\n", stderr );
|
{ fputs( "ffexample: Not enough memory.\n", stderr );
|
||||||
LZ_compress_close( encoder ); return 1; }
|
LZ_compress_close( encoder ); return 1; }
|
||||||
|
@ -1306,7 +1281,7 @@ Example 2: Multimember compression (user-restarted members).
|
||||||
for each line of text terminated by a newline character or by EOF.
|
for each line of text terminated by a newline character or by EOF.
|
||||||
Return 0 if success, 1 if error.
|
Return 0 if success, 1 if error.
|
||||||
*/
|
*/
|
||||||
int fflfcompress( struct LZ_Encoder * const encoder,
|
int fflfcompress( LZ_Encoder * const encoder,
|
||||||
FILE * const infile, FILE * const outfile )
|
FILE * const infile, FILE * const outfile )
|
||||||
{
|
{
|
||||||
enum { buffer_size = 16384 };
|
enum { buffer_size = 16384 };
|
||||||
|
@ -1353,7 +1328,7 @@ int fflfcompress( struct LZ_Encoder * const encoder,
|
||||||
next member in case of data error, including the automatic removal of
|
next member in case of data error, including the automatic removal of
|
||||||
leading garbage.
|
leading garbage.
|
||||||
*/
|
*/
|
||||||
int ffrsdecompress( struct LZ_Decoder * const decoder,
|
int ffrsdecompress( LZ_Decoder * const decoder,
|
||||||
FILE * const infile, FILE * const outfile )
|
FILE * const infile, FILE * const outfile )
|
||||||
{
|
{
|
||||||
enum { buffer_size = 16384 };
|
enum { buffer_size = 16384 };
|
||||||
|
|
|
@ -1,25 +1,26 @@
|
||||||
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.49.2.
|
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.49.2.
|
||||||
.TH MINILZIP "1" "October 2024" "minilzip 1.15-pre2" "User Commands"
|
.TH MINILZIP "1" "November 2024" "minilzip 1.15-rc1" "User Commands"
|
||||||
.SH NAME
|
.SH NAME
|
||||||
minilzip \- reduces the size of files
|
minilzip \- reduces the size of files
|
||||||
.SH SYNOPSIS
|
.SH SYNOPSIS
|
||||||
.B minilzip
|
.B minilzip
|
||||||
[\fI\,options\/\fR] [\fI\,files\/\fR]
|
[\fI\,options\/\fR] [\fI\,files\/\fR]
|
||||||
.SH DESCRIPTION
|
.SH DESCRIPTION
|
||||||
Minilzip is a test program for the compression library lzlib, compatible
|
Minilzip is a test program for the compression library lzlib. Minilzip is
|
||||||
(interoperable) with lzip 1.4 or newer.
|
not intended to be installed because lzip has more features, but minilzip is
|
||||||
|
well tested and you can use it as your main compressor if so you wish.
|
||||||
.PP
|
.PP
|
||||||
Lzip is a lossless data compressor with a user interface similar to the one
|
Lzip is a lossless data compressor with a user interface similar to the one
|
||||||
of gzip or bzip2. Lzip uses a simplified form of the 'Lempel\-Ziv\-Markov
|
of gzip or bzip2. Lzip uses a simplified form of LZMA (Lempel\-Ziv\-Markov
|
||||||
chain\-Algorithm' (LZMA) stream format to maximize interoperability. The
|
chain\-Algorithm) designed to achieve complete interoperability between
|
||||||
maximum dictionary size is 512 MiB so that any lzip file can be decompressed
|
implementations. The maximum dictionary size is 512 MiB so that any lzip
|
||||||
on 32\-bit machines. Lzip provides accurate and robust 3\-factor integrity
|
file can be decompressed on 32\-bit machines. Lzip provides accurate and
|
||||||
checking. Lzip can compress about as fast as gzip (lzip \fB\-0\fR) or compress most
|
robust 3\-factor integrity checking. 'lzip \fB\-0\fR' compresses about as fast as
|
||||||
files more than bzip2 (lzip \fB\-9\fR). Decompression speed is intermediate between
|
gzip, while 'lzip \fB\-9\fR' compresses most files more than bzip2. Decompression
|
||||||
gzip and bzip2. Lzip provides better data recovery capabilities than gzip
|
speed is intermediate between gzip and bzip2. Lzip provides better data
|
||||||
and bzip2. Lzip has been designed, written, and tested with great care to
|
recovery capabilities than gzip and bzip2. Lzip has been designed, written,
|
||||||
replace gzip and bzip2 as the standard general\-purpose compressed format for
|
and tested with great care to replace gzip and bzip2 as general\-purpose
|
||||||
Unix\-like systems.
|
compressed format for Unix\-like systems.
|
||||||
.SH OPTIONS
|
.SH OPTIONS
|
||||||
.TP
|
.TP
|
||||||
\fB\-h\fR, \fB\-\-help\fR
|
\fB\-h\fR, \fB\-\-help\fR
|
||||||
|
@ -32,7 +33,7 @@ output version information and exit
|
||||||
exit with error status if trailing data
|
exit with error status if trailing data
|
||||||
.TP
|
.TP
|
||||||
\fB\-b\fR, \fB\-\-member\-size=\fR<bytes>
|
\fB\-b\fR, \fB\-\-member\-size=\fR<bytes>
|
||||||
set member size limit in bytes
|
set member size limit of multimember files
|
||||||
.TP
|
.TP
|
||||||
\fB\-c\fR, \fB\-\-stdout\fR
|
\fB\-c\fR, \fB\-\-stdout\fR
|
||||||
write to standard output, keep input files
|
write to standard output, keep input files
|
||||||
|
@ -120,7 +121,7 @@ License GPLv2+: GNU GPL version 2 or later <http://gnu.org/licenses/gpl.html>
|
||||||
.br
|
.br
|
||||||
This is free software: you are free to change and redistribute it.
|
This is free software: you are free to change and redistribute it.
|
||||||
There is NO WARRANTY, to the extent permitted by law.
|
There is NO WARRANTY, to the extent permitted by law.
|
||||||
Using lzlib 1.15\-pre2
|
Using lzlib 1.15\-rc1
|
||||||
Using LZ_API_VERSION = 1015
|
Using LZ_API_VERSION = 1015
|
||||||
.SH "SEE ALSO"
|
.SH "SEE ALSO"
|
||||||
The full documentation for
|
The full documentation for
|
||||||
|
|
30
encoder.c
30
encoder.c
|
@ -17,7 +17,7 @@
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int LZe_get_match_pairs( struct LZ_encoder * const e, struct Pair * pairs )
|
static int LZe_get_match_pairs( LZ_encoder * const e, Pair * pairs )
|
||||||
{
|
{
|
||||||
int32_t * ptr0 = e->eb.mb.pos_array + ( e->eb.mb.cyclic_pos << 1 );
|
int32_t * ptr0 = e->eb.mb.pos_array + ( e->eb.mb.cyclic_pos << 1 );
|
||||||
int32_t * ptr1 = ptr0 + 1;
|
int32_t * ptr1 = ptr0 + 1;
|
||||||
|
@ -31,8 +31,8 @@ static int LZe_get_match_pairs( struct LZ_encoder * const e, struct Pair * pairs
|
||||||
|
|
||||||
int maxlen = 3; /* only used if pairs != 0 */
|
int maxlen = 3; /* only used if pairs != 0 */
|
||||||
int num_pairs = 0;
|
int num_pairs = 0;
|
||||||
const int min_pos = ( e->eb.mb.pos > e->eb.mb.dictionary_size ) ?
|
const int min_pos = (e->eb.mb.pos > e->eb.mb.dictionary_size) ?
|
||||||
e->eb.mb.pos - e->eb.mb.dictionary_size : 0;
|
e->eb.mb.pos - e->eb.mb.dictionary_size : 0;
|
||||||
const uint8_t * const data = Mb_ptr_to_current_pos( &e->eb.mb );
|
const uint8_t * const data = Mb_ptr_to_current_pos( &e->eb.mb );
|
||||||
|
|
||||||
unsigned tmp = crc32[data[0]] ^ data[1];
|
unsigned tmp = crc32[data[0]] ^ data[1];
|
||||||
|
@ -121,7 +121,7 @@ static int LZe_get_match_pairs( struct LZ_encoder * const e, struct Pair * pairs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void LZe_update_distance_prices( struct LZ_encoder * const e )
|
static void LZe_update_distance_prices( LZ_encoder * const e )
|
||||||
{
|
{
|
||||||
int dis, len_state;
|
int dis, len_state;
|
||||||
for( dis = start_dis_model; dis < modeled_distances; ++dis )
|
for( dis = start_dis_model; dis < modeled_distances; ++dis )
|
||||||
|
@ -160,7 +160,7 @@ static void LZe_update_distance_prices( struct LZ_encoder * const e )
|
||||||
( trials[0].dis4 == -1 ) means literal.
|
( trials[0].dis4 == -1 ) means literal.
|
||||||
A match/rep longer or equal than match_len_limit finishes the sequence.
|
A match/rep longer or equal than match_len_limit finishes the sequence.
|
||||||
*/
|
*/
|
||||||
static int LZe_sequence_optimizer( struct LZ_encoder * const e,
|
static int LZe_sequence_optimizer( LZ_encoder * const e,
|
||||||
const int reps[num_rep_distances],
|
const int reps[num_rep_distances],
|
||||||
const State state )
|
const State state )
|
||||||
{
|
{
|
||||||
|
@ -174,7 +174,7 @@ static int LZe_sequence_optimizer( struct LZ_encoder * const e,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
num_pairs = LZe_read_match_distances( e );
|
num_pairs = LZe_read_match_distances( e );
|
||||||
const int main_len = ( num_pairs > 0 ) ? e->pairs[num_pairs-1].len : 0;
|
const int main_len = (num_pairs > 0) ? e->pairs[num_pairs-1].len : 0;
|
||||||
|
|
||||||
int replens[num_rep_distances];
|
int replens[num_rep_distances];
|
||||||
int rep_index = 0;
|
int rep_index = 0;
|
||||||
|
@ -270,7 +270,7 @@ static int LZe_sequence_optimizer( struct LZ_encoder * const e,
|
||||||
}
|
}
|
||||||
|
|
||||||
const int num_pairs = LZe_read_match_distances( e );
|
const int num_pairs = LZe_read_match_distances( e );
|
||||||
const int newlen = ( num_pairs > 0 ) ? e->pairs[num_pairs-1].len : 0;
|
const int newlen = (num_pairs > 0) ? e->pairs[num_pairs-1].len : 0;
|
||||||
if( newlen >= e->match_len_limit )
|
if( newlen >= e->match_len_limit )
|
||||||
{
|
{
|
||||||
e->pending_num_pairs = num_pairs;
|
e->pending_num_pairs = num_pairs;
|
||||||
|
@ -279,7 +279,7 @@ static int LZe_sequence_optimizer( struct LZ_encoder * const e,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* give final values to current trial */
|
/* give final values to current trial */
|
||||||
struct Trial * cur_trial = &e->trials[cur];
|
Trial * cur_trial = &e->trials[cur];
|
||||||
State cur_state;
|
State cur_state;
|
||||||
{
|
{
|
||||||
const int dis4 = cur_trial->dis4;
|
const int dis4 = cur_trial->dis4;
|
||||||
|
@ -324,7 +324,7 @@ static int LZe_sequence_optimizer( struct LZ_encoder * const e,
|
||||||
next_price += LZeb_price_matched( &e->eb, prev_byte, cur_byte, match_byte );
|
next_price += LZeb_price_matched( &e->eb, prev_byte, cur_byte, match_byte );
|
||||||
|
|
||||||
/* try last updates to next trial */
|
/* try last updates to next trial */
|
||||||
struct Trial * next_trial = &e->trials[cur+1];
|
Trial * next_trial = &e->trials[cur+1];
|
||||||
|
|
||||||
Tr_update( next_trial, next_price, -1, cur ); /* literal */
|
Tr_update( next_trial, next_price, -1, cur ); /* literal */
|
||||||
|
|
||||||
|
@ -466,12 +466,12 @@ static int LZe_sequence_optimizer( struct LZ_encoder * const e,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool LZe_encode_member( struct LZ_encoder * const e )
|
static bool LZe_encode_member( LZ_encoder * const e )
|
||||||
{
|
{
|
||||||
const bool best = ( e->match_len_limit > 12 );
|
const bool best = e->match_len_limit > 12;
|
||||||
const int dis_price_count = best ? 1 : 512;
|
const int dis_price_count = best ? 1 : 512;
|
||||||
const int align_price_count = best ? 1 : dis_align_size;
|
const int align_price_count = best ? 1 : dis_align_size;
|
||||||
const int price_count = ( e->match_len_limit > 36 ) ? 1013 : 4093;
|
const int price_count = (e->match_len_limit > 36) ? 1013 : 4093;
|
||||||
int i;
|
int i;
|
||||||
State * const state = &e->eb.state;
|
State * const state = &e->eb.state;
|
||||||
|
|
||||||
|
@ -522,7 +522,7 @@ static bool LZe_encode_member( struct LZ_encoder * const e )
|
||||||
const int len = e->trials[i].price;
|
const int len = e->trials[i].price;
|
||||||
int dis = e->trials[i].dis4;
|
int dis = e->trials[i].dis4;
|
||||||
|
|
||||||
bool bit = ( dis < 0 );
|
bool bit = dis < 0;
|
||||||
Re_encode_bit( &e->eb.renc, &e->eb.bm_match[*state][pos_state], !bit );
|
Re_encode_bit( &e->eb.renc, &e->eb.bm_match[*state][pos_state], !bit );
|
||||||
if( bit ) /* literal byte */
|
if( bit ) /* literal byte */
|
||||||
{
|
{
|
||||||
|
@ -541,11 +541,11 @@ static bool LZe_encode_member( struct LZ_encoder * const e )
|
||||||
{
|
{
|
||||||
CRC32_update_buf( &e->eb.crc, Mb_ptr_to_current_pos( &e->eb.mb ) - ahead, len );
|
CRC32_update_buf( &e->eb.crc, Mb_ptr_to_current_pos( &e->eb.mb ) - ahead, len );
|
||||||
mtf_reps( dis, e->eb.reps );
|
mtf_reps( dis, e->eb.reps );
|
||||||
bit = ( dis < num_rep_distances );
|
bit = dis < num_rep_distances;
|
||||||
Re_encode_bit( &e->eb.renc, &e->eb.bm_rep[*state], bit );
|
Re_encode_bit( &e->eb.renc, &e->eb.bm_rep[*state], bit );
|
||||||
if( bit ) /* repeated match */
|
if( bit ) /* repeated match */
|
||||||
{
|
{
|
||||||
bit = ( dis == 0 );
|
bit = dis == 0;
|
||||||
Re_encode_bit( &e->eb.renc, &e->eb.bm_rep0[*state], !bit );
|
Re_encode_bit( &e->eb.renc, &e->eb.bm_rep0[*state], !bit );
|
||||||
if( bit )
|
if( bit )
|
||||||
Re_encode_bit( &e->eb.renc, &e->eb.bm_len[*state][pos_state], len > 1 );
|
Re_encode_bit( &e->eb.renc, &e->eb.bm_len[*state][pos_state], len > 1 );
|
||||||
|
|
80
encoder.h
80
encoder.h
|
@ -17,16 +17,16 @@
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
struct Len_prices
|
typedef struct Len_prices
|
||||||
{
|
{
|
||||||
const struct Len_model * lm;
|
const Len_model * lm;
|
||||||
int len_symbols;
|
int len_symbols;
|
||||||
int count;
|
int count;
|
||||||
int prices[pos_states][max_len_symbols];
|
int prices[pos_states][max_len_symbols];
|
||||||
int counters[pos_states]; /* may decrement below 0 */
|
int counters[pos_states]; /* may decrement below 0 */
|
||||||
};
|
} Len_prices;
|
||||||
|
|
||||||
static inline void Lp_update_low_mid_prices( struct Len_prices * const lp,
|
static inline void Lp_update_low_mid_prices( Len_prices * const lp,
|
||||||
const int pos_state )
|
const int pos_state )
|
||||||
{
|
{
|
||||||
int * const pps = lp->prices[pos_state];
|
int * const pps = lp->prices[pos_state];
|
||||||
|
@ -41,7 +41,7 @@ static inline void Lp_update_low_mid_prices( struct Len_prices * const lp,
|
||||||
price_symbol3( lp->lm->bm_mid[pos_state], len - len_low_symbols );
|
price_symbol3( lp->lm->bm_mid[pos_state], len - len_low_symbols );
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void Lp_update_high_prices( struct Len_prices * const lp )
|
static inline void Lp_update_high_prices( Len_prices * const lp )
|
||||||
{
|
{
|
||||||
const int tmp = price1( lp->lm->choice1 ) + price1( lp->lm->choice2 );
|
const int tmp = price1( lp->lm->choice1 ) + price1( lp->lm->choice2 );
|
||||||
int len;
|
int len;
|
||||||
|
@ -52,24 +52,23 @@ static inline void Lp_update_high_prices( struct Len_prices * const lp )
|
||||||
price_symbol8( lp->lm->bm_high, len - len_low_symbols - len_mid_symbols );
|
price_symbol8( lp->lm->bm_high, len - len_low_symbols - len_mid_symbols );
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void Lp_reset( struct Len_prices * const lp )
|
static inline void Lp_reset( Len_prices * const lp )
|
||||||
{ int i; for( i = 0; i < pos_states; ++i ) lp->counters[i] = 0; }
|
{ int i; for( i = 0; i < pos_states; ++i ) lp->counters[i] = 0; }
|
||||||
|
|
||||||
static inline void Lp_init( struct Len_prices * const lp,
|
static inline void Lp_init( Len_prices * const lp, const Len_model * const lm,
|
||||||
const struct Len_model * const lm,
|
|
||||||
const int match_len_limit )
|
const int match_len_limit )
|
||||||
{
|
{
|
||||||
lp->lm = lm;
|
lp->lm = lm;
|
||||||
lp->len_symbols = match_len_limit + 1 - min_match_len;
|
lp->len_symbols = match_len_limit + 1 - min_match_len;
|
||||||
lp->count = ( match_len_limit > 12 ) ? 1 : lp->len_symbols;
|
lp->count = (match_len_limit > 12) ? 1 : lp->len_symbols;
|
||||||
Lp_reset( lp );
|
Lp_reset( lp );
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void Lp_decrement_counter( struct Len_prices * const lp,
|
static inline void Lp_decrement_counter( Len_prices * const lp,
|
||||||
const int pos_state )
|
const int pos_state )
|
||||||
{ --lp->counters[pos_state]; }
|
{ --lp->counters[pos_state]; }
|
||||||
|
|
||||||
static inline void Lp_update_prices( struct Len_prices * const lp )
|
static inline void Lp_update_prices( Len_prices * const lp )
|
||||||
{
|
{
|
||||||
int pos_state;
|
int pos_state;
|
||||||
bool high_pending = false;
|
bool high_pending = false;
|
||||||
|
@ -81,23 +80,23 @@ static inline void Lp_update_prices( struct Len_prices * const lp )
|
||||||
Lp_update_high_prices( lp );
|
Lp_update_high_prices( lp );
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int Lp_price( const struct Len_prices * const lp,
|
static inline int Lp_price( const Len_prices * const lp,
|
||||||
const int len, const int pos_state )
|
const int len, const int pos_state )
|
||||||
{ return lp->prices[pos_state][len - min_match_len]; }
|
{ return lp->prices[pos_state][len - min_match_len]; }
|
||||||
|
|
||||||
|
|
||||||
struct Pair /* distance-length pair */
|
typedef struct Pair /* distance-length pair */
|
||||||
{
|
{
|
||||||
int dis;
|
int dis;
|
||||||
int len;
|
int len;
|
||||||
};
|
} Pair;
|
||||||
|
|
||||||
enum { infinite_price = 0x0FFFFFFF,
|
enum { infinite_price = 0x0FFFFFFF,
|
||||||
max_num_trials = 1 << 13,
|
max_num_trials = 1 << 13,
|
||||||
single_step_trial = -2,
|
single_step_trial = -2,
|
||||||
dual_step_trial = -1 };
|
dual_step_trial = -1 };
|
||||||
|
|
||||||
struct Trial
|
typedef struct Trial
|
||||||
{
|
{
|
||||||
State state;
|
State state;
|
||||||
int price; /* dual use var; cumulative price, match length */
|
int price; /* dual use var; cumulative price, match length */
|
||||||
|
@ -107,9 +106,9 @@ struct Trial
|
||||||
/* -1 literal + rep0 */
|
/* -1 literal + rep0 */
|
||||||
/* >= 0 ( rep or match ) + literal + rep0 */
|
/* >= 0 ( rep or match ) + literal + rep0 */
|
||||||
int reps[num_rep_distances];
|
int reps[num_rep_distances];
|
||||||
};
|
} Trial;
|
||||||
|
|
||||||
static inline void Tr_update( struct Trial * const trial, const int pr,
|
static inline void Tr_update( Trial * const trial, const int pr,
|
||||||
const int distance4, const int p_i )
|
const int distance4, const int p_i )
|
||||||
{
|
{
|
||||||
if( pr < trial->price )
|
if( pr < trial->price )
|
||||||
|
@ -117,7 +116,7 @@ static inline void Tr_update( struct Trial * const trial, const int pr,
|
||||||
trial->prev_index2 = single_step_trial; }
|
trial->prev_index2 = single_step_trial; }
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void Tr_update2( struct Trial * const trial, const int pr,
|
static inline void Tr_update2( Trial * const trial, const int pr,
|
||||||
const int p_i )
|
const int p_i )
|
||||||
{
|
{
|
||||||
if( pr < trial->price )
|
if( pr < trial->price )
|
||||||
|
@ -125,7 +124,7 @@ static inline void Tr_update2( struct Trial * const trial, const int pr,
|
||||||
trial->prev_index2 = dual_step_trial; }
|
trial->prev_index2 = dual_step_trial; }
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void Tr_update3( struct Trial * const trial, const int pr,
|
static inline void Tr_update3( Trial * const trial, const int pr,
|
||||||
const int distance4, const int p_i,
|
const int distance4, const int p_i,
|
||||||
const int p_i2 )
|
const int p_i2 )
|
||||||
{
|
{
|
||||||
|
@ -135,16 +134,16 @@ static inline void Tr_update3( struct Trial * const trial, const int pr,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct LZ_encoder
|
typedef struct LZ_encoder
|
||||||
{
|
{
|
||||||
struct LZ_encoder_base eb;
|
LZ_encoder_base eb;
|
||||||
int cycles;
|
int cycles;
|
||||||
int match_len_limit;
|
int match_len_limit;
|
||||||
struct Len_prices match_len_prices;
|
Len_prices match_len_prices;
|
||||||
struct Len_prices rep_len_prices;
|
Len_prices rep_len_prices;
|
||||||
int pending_num_pairs;
|
int pending_num_pairs;
|
||||||
struct Pair pairs[max_match_len+1];
|
Pair pairs[max_match_len+1];
|
||||||
struct Trial trials[max_num_trials];
|
Trial trials[max_num_trials];
|
||||||
|
|
||||||
int dis_slot_prices[len_states][2*max_dictionary_bits];
|
int dis_slot_prices[len_states][2*max_dictionary_bits];
|
||||||
int dis_prices[len_states][modeled_distances];
|
int dis_prices[len_states][modeled_distances];
|
||||||
|
@ -154,10 +153,9 @@ struct LZ_encoder
|
||||||
int dis_price_counter;
|
int dis_price_counter;
|
||||||
int align_price_counter;
|
int align_price_counter;
|
||||||
bool been_flushed;
|
bool been_flushed;
|
||||||
};
|
} LZ_encoder;
|
||||||
|
|
||||||
static inline bool Mb_dec_pos( struct Matchfinder_base * const mb,
|
static inline bool Mb_dec_pos( Matchfinder_base * const mb, const int ahead )
|
||||||
const int ahead )
|
|
||||||
{
|
{
|
||||||
if( ahead < 0 || mb->pos < ahead ) return false;
|
if( ahead < 0 || mb->pos < ahead ) return false;
|
||||||
mb->pos -= ahead;
|
mb->pos -= ahead;
|
||||||
|
@ -166,7 +164,7 @@ static inline bool Mb_dec_pos( struct Matchfinder_base * const mb,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int LZe_get_match_pairs( struct LZ_encoder * const e, struct Pair * pairs );
|
static int LZe_get_match_pairs( LZ_encoder * const e, Pair * pairs );
|
||||||
|
|
||||||
/* move-to-front dis in/into reps; do nothing if( dis4 <= 0 ) */
|
/* move-to-front dis in/into reps; do nothing if( dis4 <= 0 ) */
|
||||||
static inline void mtf_reps( const int dis4, int reps[num_rep_distances] )
|
static inline void mtf_reps( const int dis4, int reps[num_rep_distances] )
|
||||||
|
@ -184,13 +182,13 @@ static inline void mtf_reps( const int dis4, int reps[num_rep_distances] )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int LZeb_price_shortrep( const struct LZ_encoder_base * const eb,
|
static inline int LZeb_price_shortrep( const LZ_encoder_base * const eb,
|
||||||
const State state, const int pos_state )
|
const State state, const int pos_state )
|
||||||
{
|
{
|
||||||
return price0( eb->bm_rep0[state] ) + price0( eb->bm_len[state][pos_state] );
|
return price0( eb->bm_rep0[state] ) + price0( eb->bm_len[state][pos_state] );
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int LZeb_price_rep( const struct LZ_encoder_base * const eb,
|
static inline int LZeb_price_rep( const LZ_encoder_base * const eb,
|
||||||
const int rep, const State state,
|
const int rep, const State state,
|
||||||
const int pos_state )
|
const int pos_state )
|
||||||
{
|
{
|
||||||
|
@ -207,7 +205,7 @@ static inline int LZeb_price_rep( const struct LZ_encoder_base * const eb,
|
||||||
return price;
|
return price;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int LZe_price_rep0_len( const struct LZ_encoder * const e,
|
static inline int LZe_price_rep0_len( const LZ_encoder * const e,
|
||||||
const int len, const State state,
|
const int len, const State state,
|
||||||
const int pos_state )
|
const int pos_state )
|
||||||
{
|
{
|
||||||
|
@ -215,7 +213,7 @@ static inline int LZe_price_rep0_len( const struct LZ_encoder * const e,
|
||||||
Lp_price( &e->rep_len_prices, len, pos_state );
|
Lp_price( &e->rep_len_prices, len, pos_state );
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int LZe_price_pair( const struct LZ_encoder * const e,
|
static inline int LZe_price_pair( const LZ_encoder * const e,
|
||||||
const int dis, const int len,
|
const int dis, const int len,
|
||||||
const int pos_state )
|
const int pos_state )
|
||||||
{
|
{
|
||||||
|
@ -228,7 +226,7 @@ static inline int LZe_price_pair( const struct LZ_encoder * const e,
|
||||||
e->align_prices[dis & (dis_align_size - 1)];
|
e->align_prices[dis & (dis_align_size - 1)];
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int LZe_read_match_distances( struct LZ_encoder * const e )
|
static inline int LZe_read_match_distances( LZ_encoder * const e )
|
||||||
{
|
{
|
||||||
const int num_pairs = LZe_get_match_pairs( e, e->pairs );
|
const int num_pairs = LZe_get_match_pairs( e, e->pairs );
|
||||||
if( num_pairs > 0 )
|
if( num_pairs > 0 )
|
||||||
|
@ -241,7 +239,7 @@ static inline int LZe_read_match_distances( struct LZ_encoder * const e )
|
||||||
return num_pairs;
|
return num_pairs;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool LZe_move_and_update( struct LZ_encoder * const e, int n )
|
static inline bool LZe_move_and_update( LZ_encoder * const e, int n )
|
||||||
{
|
{
|
||||||
while( true )
|
while( true )
|
||||||
{
|
{
|
||||||
|
@ -252,13 +250,13 @@ static inline bool LZe_move_and_update( struct LZ_encoder * const e, int n )
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void LZe_backward( struct LZ_encoder * const e, int cur )
|
static inline void LZe_backward( LZ_encoder * const e, int cur )
|
||||||
{
|
{
|
||||||
int dis4 = e->trials[cur].dis4;
|
int dis4 = e->trials[cur].dis4;
|
||||||
while( cur > 0 )
|
while( cur > 0 )
|
||||||
{
|
{
|
||||||
const int prev_index = e->trials[cur].prev_index;
|
const int prev_index = e->trials[cur].prev_index;
|
||||||
struct Trial * const prev_trial = &e->trials[prev_index];
|
Trial * const prev_trial = &e->trials[prev_index];
|
||||||
|
|
||||||
if( e->trials[cur].prev_index2 != single_step_trial )
|
if( e->trials[cur].prev_index2 != single_step_trial )
|
||||||
{
|
{
|
||||||
|
@ -267,7 +265,7 @@ static inline void LZe_backward( struct LZ_encoder * const e, int cur )
|
||||||
prev_trial->prev_index2 = single_step_trial;
|
prev_trial->prev_index2 = single_step_trial;
|
||||||
if( e->trials[cur].prev_index2 >= 0 )
|
if( e->trials[cur].prev_index2 >= 0 )
|
||||||
{
|
{
|
||||||
struct Trial * const prev_trial2 = &e->trials[prev_index-1];
|
Trial * const prev_trial2 = &e->trials[prev_index-1];
|
||||||
prev_trial2->dis4 = dis4; dis4 = 0; /* rep0 */
|
prev_trial2->dis4 = dis4; dis4 = 0; /* rep0 */
|
||||||
prev_trial2->prev_index = e->trials[cur].prev_index2;
|
prev_trial2->prev_index = e->trials[cur].prev_index2;
|
||||||
prev_trial2->prev_index2 = single_step_trial;
|
prev_trial2->prev_index2 = single_step_trial;
|
||||||
|
@ -282,7 +280,7 @@ static inline void LZe_backward( struct LZ_encoder * const e, int cur )
|
||||||
enum { num_prev_positions3 = 1 << 16,
|
enum { num_prev_positions3 = 1 << 16,
|
||||||
num_prev_positions2 = 1 << 10 };
|
num_prev_positions2 = 1 << 10 };
|
||||||
|
|
||||||
static inline bool LZe_init( struct LZ_encoder * const e,
|
static inline bool LZe_init( LZ_encoder * const e,
|
||||||
const int dict_size, const int len_limit,
|
const int dict_size, const int len_limit,
|
||||||
const unsigned long long member_size )
|
const unsigned long long member_size )
|
||||||
{
|
{
|
||||||
|
@ -297,7 +295,7 @@ static inline bool LZe_init( struct LZ_encoder * const e,
|
||||||
if( !LZeb_init( &e->eb, before_size, dict_size, after_size, dict_factor,
|
if( !LZeb_init( &e->eb, before_size, dict_size, after_size, dict_factor,
|
||||||
num_prev_positions23, pos_array_factor, min_free_bytes,
|
num_prev_positions23, pos_array_factor, min_free_bytes,
|
||||||
member_size ) ) return false;
|
member_size ) ) return false;
|
||||||
e->cycles = ( len_limit < max_match_len ) ? 16 + ( len_limit / 2 ) : 256;
|
e->cycles = (len_limit < max_match_len) ? 16 + ( len_limit / 2 ) : 256;
|
||||||
e->match_len_limit = len_limit;
|
e->match_len_limit = len_limit;
|
||||||
Lp_init( &e->match_len_prices, &e->eb.match_len_model, e->match_len_limit );
|
Lp_init( &e->match_len_prices, &e->eb.match_len_model, e->match_len_limit );
|
||||||
Lp_init( &e->rep_len_prices, &e->eb.rep_len_model, e->match_len_limit );
|
Lp_init( &e->rep_len_prices, &e->eb.rep_len_model, e->match_len_limit );
|
||||||
|
@ -312,7 +310,7 @@ static inline bool LZe_init( struct LZ_encoder * const e,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void LZe_reset( struct LZ_encoder * const e,
|
static inline void LZe_reset( LZ_encoder * const e,
|
||||||
const unsigned long long member_size )
|
const unsigned long long member_size )
|
||||||
{
|
{
|
||||||
LZeb_reset( &e->eb, member_size );
|
LZeb_reset( &e->eb, member_size );
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static bool Mb_normalize_pos( struct Matchfinder_base * const mb )
|
static bool Mb_normalize_pos( Matchfinder_base * const mb )
|
||||||
{
|
{
|
||||||
if( mb->pos > mb->stream_pos )
|
if( mb->pos > mb->stream_pos )
|
||||||
{ mb->pos = mb->stream_pos; return false; }
|
{ mb->pos = mb->stream_pos; return false; }
|
||||||
|
@ -40,7 +40,7 @@ static bool Mb_normalize_pos( struct Matchfinder_base * const mb )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool Mb_init( struct Matchfinder_base * const mb, const int before_size,
|
static bool Mb_init( Matchfinder_base * const mb, const int before_size,
|
||||||
const int dict_size, const int after_size,
|
const int dict_size, const int after_size,
|
||||||
const int dict_factor, const int num_prev_positions23,
|
const int dict_factor, const int num_prev_positions23,
|
||||||
const int pos_array_factor )
|
const int pos_array_factor )
|
||||||
|
@ -83,7 +83,7 @@ static bool Mb_init( struct Matchfinder_base * const mb, const int before_size,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void Mb_adjust_array( struct Matchfinder_base * const mb )
|
static void Mb_adjust_array( Matchfinder_base * const mb )
|
||||||
{
|
{
|
||||||
int size = 1 << max( 16, real_bits( mb->dictionary_size - 1 ) - 2 );
|
int size = 1 << max( 16, real_bits( mb->dictionary_size - 1 ) - 2 );
|
||||||
if( mb->dictionary_size > 1 << 26 ) size >>= 1; /* 64 MiB */
|
if( mb->dictionary_size > 1 << 26 ) size >>= 1; /* 64 MiB */
|
||||||
|
@ -94,7 +94,7 @@ static void Mb_adjust_array( struct Matchfinder_base * const mb )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void Mb_adjust_dictionary_size( struct Matchfinder_base * const mb )
|
static void Mb_adjust_dictionary_size( Matchfinder_base * const mb )
|
||||||
{
|
{
|
||||||
if( mb->stream_pos < mb->dictionary_size )
|
if( mb->stream_pos < mb->dictionary_size )
|
||||||
{
|
{
|
||||||
|
@ -105,7 +105,7 @@ static void Mb_adjust_dictionary_size( struct Matchfinder_base * const mb )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void Mb_reset( struct Matchfinder_base * const mb )
|
static void Mb_reset( Matchfinder_base * const mb )
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
if( mb->stream_pos > mb->pos )
|
if( mb->stream_pos > mb->pos )
|
||||||
|
@ -124,7 +124,7 @@ static void Mb_reset( struct Matchfinder_base * const mb )
|
||||||
|
|
||||||
|
|
||||||
/* End Of Stream marker => (dis == 0xFFFFFFFFU, len == min_match_len) */
|
/* End Of Stream marker => (dis == 0xFFFFFFFFU, len == min_match_len) */
|
||||||
static void LZeb_try_full_flush( struct LZ_encoder_base * const eb )
|
static void LZeb_try_full_flush( LZ_encoder_base * const eb )
|
||||||
{
|
{
|
||||||
if( eb->member_finished || Cb_free_bytes( &eb->renc.cb ) <
|
if( eb->member_finished || Cb_free_bytes( &eb->renc.cb ) <
|
||||||
max_marker_size + eb->renc.ff_count + Lt_size ) return;
|
max_marker_size + eb->renc.ff_count + Lt_size ) return;
|
||||||
|
@ -144,7 +144,7 @@ static void LZeb_try_full_flush( struct LZ_encoder_base * const eb )
|
||||||
|
|
||||||
|
|
||||||
/* Sync Flush marker => (dis == 0xFFFFFFFFU, len == min_match_len + 1) */
|
/* Sync Flush marker => (dis == 0xFFFFFFFFU, len == min_match_len + 1) */
|
||||||
static void LZeb_try_sync_flush( struct LZ_encoder_base * const eb )
|
static void LZeb_try_sync_flush( LZ_encoder_base * const eb )
|
||||||
{
|
{
|
||||||
const unsigned min_size = eb->renc.ff_count + max_marker_size;
|
const unsigned min_size = eb->renc.ff_count + max_marker_size;
|
||||||
if( eb->member_finished ||
|
if( eb->member_finished ||
|
||||||
|
@ -163,7 +163,7 @@ static void LZeb_try_sync_flush( struct LZ_encoder_base * const eb )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void LZeb_reset( struct LZ_encoder_base * const eb,
|
static void LZeb_reset( LZ_encoder_base * const eb,
|
||||||
const unsigned long long member_size )
|
const unsigned long long member_size )
|
||||||
{
|
{
|
||||||
const unsigned long long min_member_size = min_dictionary_size;
|
const unsigned long long min_member_size = min_dictionary_size;
|
||||||
|
|
112
encoder_base.h
112
encoder_base.h
|
@ -217,7 +217,7 @@ static inline int price_matched( const Bit_model bm[], unsigned symbol,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct Matchfinder_base
|
typedef struct Matchfinder_base
|
||||||
{
|
{
|
||||||
unsigned long long partial_data_pos;
|
unsigned long long partial_data_pos;
|
||||||
uint8_t * buffer; /* input buffer */
|
uint8_t * buffer; /* input buffer */
|
||||||
|
@ -238,52 +238,52 @@ struct Matchfinder_base
|
||||||
int saved_dictionary_size; /* dictionary_size restored by Mb_reset */
|
int saved_dictionary_size; /* dictionary_size restored by Mb_reset */
|
||||||
bool at_stream_end; /* stream_pos shows real end of file */
|
bool at_stream_end; /* stream_pos shows real end of file */
|
||||||
bool sync_flush_pending;
|
bool sync_flush_pending;
|
||||||
};
|
} Matchfinder_base;
|
||||||
|
|
||||||
static bool Mb_normalize_pos( struct Matchfinder_base * const mb );
|
static bool Mb_normalize_pos( Matchfinder_base * const mb );
|
||||||
|
|
||||||
static bool Mb_init( struct Matchfinder_base * const mb, const int before_size,
|
static bool Mb_init( Matchfinder_base * const mb, const int before_size,
|
||||||
const int dict_size, const int after_size,
|
const int dict_size, const int after_size,
|
||||||
const int dict_factor, const int num_prev_positions23,
|
const int dict_factor, const int num_prev_positions23,
|
||||||
const int pos_array_factor );
|
const int pos_array_factor );
|
||||||
|
|
||||||
static inline void Mb_free( struct Matchfinder_base * const mb )
|
static inline void Mb_free( Matchfinder_base * const mb )
|
||||||
{ free( mb->prev_positions ); free( mb->buffer ); }
|
{ free( mb->prev_positions ); free( mb->buffer ); }
|
||||||
|
|
||||||
static inline uint8_t Mb_peek( const struct Matchfinder_base * const mb,
|
static inline uint8_t Mb_peek( const Matchfinder_base * const mb,
|
||||||
const int distance )
|
const int distance )
|
||||||
{ return mb->buffer[mb->pos-distance]; }
|
{ return mb->buffer[mb->pos-distance]; }
|
||||||
|
|
||||||
static inline int Mb_available_bytes( const struct Matchfinder_base * const mb )
|
static inline int Mb_available_bytes( const Matchfinder_base * const mb )
|
||||||
{ return mb->stream_pos - mb->pos; }
|
{ return mb->stream_pos - mb->pos; }
|
||||||
|
|
||||||
static inline unsigned long long
|
static inline unsigned long long
|
||||||
Mb_data_position( const struct Matchfinder_base * const mb )
|
Mb_data_position( const Matchfinder_base * const mb )
|
||||||
{ return mb->partial_data_pos + mb->pos; }
|
{ return mb->partial_data_pos + mb->pos; }
|
||||||
|
|
||||||
static inline void Mb_finish( struct Matchfinder_base * const mb )
|
static inline void Mb_finish( Matchfinder_base * const mb )
|
||||||
{ mb->at_stream_end = true; mb->sync_flush_pending = false; }
|
{ mb->at_stream_end = true; mb->sync_flush_pending = false; }
|
||||||
|
|
||||||
static inline bool Mb_data_finished( const struct Matchfinder_base * const mb )
|
static inline bool Mb_data_finished( const Matchfinder_base * const mb )
|
||||||
{ return mb->at_stream_end && mb->pos >= mb->stream_pos; }
|
{ return mb->at_stream_end && mb->pos >= mb->stream_pos; }
|
||||||
|
|
||||||
static inline bool Mb_flushing_or_end( const struct Matchfinder_base * const mb )
|
static inline bool Mb_flushing_or_end( const Matchfinder_base * const mb )
|
||||||
{ return mb->at_stream_end || mb->sync_flush_pending; }
|
{ return mb->at_stream_end || mb->sync_flush_pending; }
|
||||||
|
|
||||||
static inline int Mb_free_bytes( const struct Matchfinder_base * const mb )
|
static inline int Mb_free_bytes( const Matchfinder_base * const mb )
|
||||||
{ if( Mb_flushing_or_end( mb ) ) return 0;
|
{ if( Mb_flushing_or_end( mb ) ) return 0;
|
||||||
return mb->buffer_size - mb->stream_pos; }
|
return mb->buffer_size - mb->stream_pos; }
|
||||||
|
|
||||||
static inline bool
|
static inline bool
|
||||||
Mb_enough_available_bytes( const struct Matchfinder_base * const mb )
|
Mb_enough_available_bytes( const Matchfinder_base * const mb )
|
||||||
{ return mb->pos + mb->after_size <= mb->stream_pos ||
|
{ return mb->pos + mb->after_size <= mb->stream_pos ||
|
||||||
( Mb_flushing_or_end( mb ) && mb->pos < mb->stream_pos ); }
|
( Mb_flushing_or_end( mb ) && mb->pos < mb->stream_pos ); }
|
||||||
|
|
||||||
static inline const uint8_t *
|
static inline const uint8_t *
|
||||||
Mb_ptr_to_current_pos( const struct Matchfinder_base * const mb )
|
Mb_ptr_to_current_pos( const Matchfinder_base * const mb )
|
||||||
{ return mb->buffer + mb->pos; }
|
{ return mb->buffer + mb->pos; }
|
||||||
|
|
||||||
static int Mb_write_data( struct Matchfinder_base * const mb,
|
static int Mb_write_data( Matchfinder_base * const mb,
|
||||||
const uint8_t * const inbuf, const int size )
|
const uint8_t * const inbuf, const int size )
|
||||||
{
|
{
|
||||||
const int sz = min( mb->buffer_size - mb->stream_pos, size );
|
const int sz = min( mb->buffer_size - mb->stream_pos, size );
|
||||||
|
@ -293,7 +293,7 @@ static int Mb_write_data( struct Matchfinder_base * const mb,
|
||||||
return sz;
|
return sz;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int Mb_true_match_len( const struct Matchfinder_base * const mb,
|
static inline int Mb_true_match_len( const Matchfinder_base * const mb,
|
||||||
const int index, const int distance )
|
const int index, const int distance )
|
||||||
{
|
{
|
||||||
const uint8_t * const data = mb->buffer + mb->pos;
|
const uint8_t * const data = mb->buffer + mb->pos;
|
||||||
|
@ -303,7 +303,7 @@ static inline int Mb_true_match_len( const struct Matchfinder_base * const mb,
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool Mb_move_pos( struct Matchfinder_base * const mb )
|
static inline bool Mb_move_pos( Matchfinder_base * const mb )
|
||||||
{
|
{
|
||||||
if( ++mb->cyclic_pos > mb->dictionary_size ) mb->cyclic_pos = 0;
|
if( ++mb->cyclic_pos > mb->dictionary_size ) mb->cyclic_pos = 0;
|
||||||
if( ++mb->pos >= mb->pos_limit ) return Mb_normalize_pos( mb );
|
if( ++mb->pos >= mb->pos_limit ) return Mb_normalize_pos( mb );
|
||||||
|
@ -311,9 +311,9 @@ static inline bool Mb_move_pos( struct Matchfinder_base * const mb )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct Range_encoder
|
typedef struct Range_encoder
|
||||||
{
|
{
|
||||||
struct Circular_buffer cb;
|
Circular_buffer cb;
|
||||||
unsigned min_free_bytes;
|
unsigned min_free_bytes;
|
||||||
uint64_t low;
|
uint64_t low;
|
||||||
unsigned long long partial_member_pos;
|
unsigned long long partial_member_pos;
|
||||||
|
@ -321,13 +321,13 @@ struct Range_encoder
|
||||||
unsigned ff_count;
|
unsigned ff_count;
|
||||||
uint8_t cache;
|
uint8_t cache;
|
||||||
Lzip_header header;
|
Lzip_header header;
|
||||||
};
|
} Range_encoder;
|
||||||
|
|
||||||
static inline void Re_shift_low( struct Range_encoder * const renc )
|
static inline void Re_shift_low( Range_encoder * const renc )
|
||||||
{
|
{
|
||||||
if( renc->low >> 24 != 0xFF )
|
if( renc->low >> 24 != 0xFF )
|
||||||
{
|
{
|
||||||
const bool carry = ( renc->low > 0xFFFFFFFFU );
|
const bool carry = renc->low > 0xFFFFFFFFU;
|
||||||
Cb_put_byte( &renc->cb, renc->cache + carry );
|
Cb_put_byte( &renc->cb, renc->cache + carry );
|
||||||
for( ; renc->ff_count > 0; --renc->ff_count )
|
for( ; renc->ff_count > 0; --renc->ff_count )
|
||||||
Cb_put_byte( &renc->cb, 0xFF + carry );
|
Cb_put_byte( &renc->cb, 0xFF + carry );
|
||||||
|
@ -337,7 +337,7 @@ static inline void Re_shift_low( struct Range_encoder * const renc )
|
||||||
renc->low = ( renc->low & 0x00FFFFFFU ) << 8;
|
renc->low = ( renc->low & 0x00FFFFFFU ) << 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void Re_reset( struct Range_encoder * const renc,
|
static inline void Re_reset( Range_encoder * const renc,
|
||||||
const unsigned dictionary_size )
|
const unsigned dictionary_size )
|
||||||
{
|
{
|
||||||
Cb_reset( &renc->cb );
|
Cb_reset( &renc->cb );
|
||||||
|
@ -350,7 +350,7 @@ static inline void Re_reset( struct Range_encoder * const renc,
|
||||||
int i; for( i = 0; i < Lh_size; ++i ) Cb_put_byte( &renc->cb, renc->header[i] );
|
int i; for( i = 0; i < Lh_size; ++i ) Cb_put_byte( &renc->cb, renc->header[i] );
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool Re_init( struct Range_encoder * const renc,
|
static inline bool Re_init( Range_encoder * const renc,
|
||||||
const unsigned dictionary_size,
|
const unsigned dictionary_size,
|
||||||
const unsigned min_free_bytes )
|
const unsigned min_free_bytes )
|
||||||
{
|
{
|
||||||
|
@ -361,17 +361,17 @@ static inline bool Re_init( struct Range_encoder * const renc,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void Re_free( struct Range_encoder * const renc )
|
static inline void Re_free( Range_encoder * const renc )
|
||||||
{ Cb_free( &renc->cb ); }
|
{ Cb_free( &renc->cb ); }
|
||||||
|
|
||||||
static inline unsigned long long
|
static inline unsigned long long
|
||||||
Re_member_position( const struct Range_encoder * const renc )
|
Re_member_position( const Range_encoder * const renc )
|
||||||
{ return renc->partial_member_pos + Cb_used_bytes( &renc->cb ) + renc->ff_count; }
|
{ return renc->partial_member_pos + Cb_used_bytes( &renc->cb ) + renc->ff_count; }
|
||||||
|
|
||||||
static inline bool Re_enough_free_bytes( const struct Range_encoder * const renc )
|
static inline bool Re_enough_free_bytes( const Range_encoder * const renc )
|
||||||
{ return Cb_free_bytes( &renc->cb ) >= renc->min_free_bytes + renc->ff_count; }
|
{ return Cb_free_bytes( &renc->cb ) >= renc->min_free_bytes + renc->ff_count; }
|
||||||
|
|
||||||
static inline int Re_read_data( struct Range_encoder * const renc,
|
static inline int Re_read_data( Range_encoder * const renc,
|
||||||
uint8_t * const out_buffer, const int out_size )
|
uint8_t * const out_buffer, const int out_size )
|
||||||
{
|
{
|
||||||
const int size = Cb_read_data( &renc->cb, out_buffer, out_size );
|
const int size = Cb_read_data( &renc->cb, out_buffer, out_size );
|
||||||
|
@ -379,7 +379,7 @@ static inline int Re_read_data( struct Range_encoder * const renc,
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void Re_flush( struct Range_encoder * const renc )
|
static inline void Re_flush( Range_encoder * const renc )
|
||||||
{
|
{
|
||||||
int i; for( i = 0; i < 5; ++i ) Re_shift_low( renc );
|
int i; for( i = 0; i < 5; ++i ) Re_shift_low( renc );
|
||||||
renc->low = 0;
|
renc->low = 0;
|
||||||
|
@ -388,7 +388,7 @@ static inline void Re_flush( struct Range_encoder * const renc )
|
||||||
renc->cache = 0;
|
renc->cache = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void Re_encode( struct Range_encoder * const renc,
|
static inline void Re_encode( Range_encoder * const renc,
|
||||||
const int symbol, const int num_bits )
|
const int symbol, const int num_bits )
|
||||||
{
|
{
|
||||||
unsigned mask;
|
unsigned mask;
|
||||||
|
@ -400,7 +400,7 @@ static inline void Re_encode( struct Range_encoder * const renc,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void Re_encode_bit( struct Range_encoder * const renc,
|
static inline void Re_encode_bit( Range_encoder * const renc,
|
||||||
Bit_model * const probability, const bool bit )
|
Bit_model * const probability, const bool bit )
|
||||||
{
|
{
|
||||||
const uint32_t bound = ( renc->range >> bit_model_total_bits ) * *probability;
|
const uint32_t bound = ( renc->range >> bit_model_total_bits ) * *probability;
|
||||||
|
@ -418,7 +418,7 @@ static inline void Re_encode_bit( struct Range_encoder * const renc,
|
||||||
if( renc->range <= 0x00FFFFFFU ) { renc->range <<= 8; Re_shift_low( renc ); }
|
if( renc->range <= 0x00FFFFFFU ) { renc->range <<= 8; Re_shift_low( renc ); }
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void Re_encode_tree3( struct Range_encoder * const renc,
|
static inline void Re_encode_tree3( Range_encoder * const renc,
|
||||||
Bit_model bm[], const int symbol )
|
Bit_model bm[], const int symbol )
|
||||||
{
|
{
|
||||||
bool bit = ( symbol >> 2 ) & 1;
|
bool bit = ( symbol >> 2 ) & 1;
|
||||||
|
@ -429,7 +429,7 @@ static inline void Re_encode_tree3( struct Range_encoder * const renc,
|
||||||
Re_encode_bit( renc, &bm[model], symbol & 1 );
|
Re_encode_bit( renc, &bm[model], symbol & 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void Re_encode_tree6( struct Range_encoder * const renc,
|
static inline void Re_encode_tree6( Range_encoder * const renc,
|
||||||
Bit_model bm[], const unsigned symbol )
|
Bit_model bm[], const unsigned symbol )
|
||||||
{
|
{
|
||||||
bool bit = ( symbol >> 5 ) & 1;
|
bool bit = ( symbol >> 5 ) & 1;
|
||||||
|
@ -446,7 +446,7 @@ static inline void Re_encode_tree6( struct Range_encoder * const renc,
|
||||||
Re_encode_bit( renc, &bm[model], symbol & 1 );
|
Re_encode_bit( renc, &bm[model], symbol & 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void Re_encode_tree8( struct Range_encoder * const renc,
|
static inline void Re_encode_tree8( Range_encoder * const renc,
|
||||||
Bit_model bm[], const int symbol )
|
Bit_model bm[], const int symbol )
|
||||||
{
|
{
|
||||||
int model = 1;
|
int model = 1;
|
||||||
|
@ -459,7 +459,7 @@ static inline void Re_encode_tree8( struct Range_encoder * const renc,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void Re_encode_tree_reversed( struct Range_encoder * const renc,
|
static inline void Re_encode_tree_reversed( Range_encoder * const renc,
|
||||||
Bit_model bm[], int symbol, const int num_bits )
|
Bit_model bm[], int symbol, const int num_bits )
|
||||||
{
|
{
|
||||||
int model = 1;
|
int model = 1;
|
||||||
|
@ -473,7 +473,7 @@ static inline void Re_encode_tree_reversed( struct Range_encoder * const renc,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void Re_encode_matched( struct Range_encoder * const renc,
|
static inline void Re_encode_matched( Range_encoder * const renc,
|
||||||
Bit_model bm[], unsigned symbol,
|
Bit_model bm[], unsigned symbol,
|
||||||
unsigned match_byte )
|
unsigned match_byte )
|
||||||
{
|
{
|
||||||
|
@ -489,17 +489,17 @@ static inline void Re_encode_matched( struct Range_encoder * const renc,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void Re_encode_len( struct Range_encoder * const renc,
|
static inline void Re_encode_len( Range_encoder * const renc,
|
||||||
struct Len_model * const lm,
|
Len_model * const lm,
|
||||||
int symbol, const int pos_state )
|
int symbol, const int pos_state )
|
||||||
{
|
{
|
||||||
bool bit = ( ( symbol -= min_match_len ) >= len_low_symbols );
|
bool bit = ( symbol -= min_match_len ) >= len_low_symbols;
|
||||||
Re_encode_bit( renc, &lm->choice1, bit );
|
Re_encode_bit( renc, &lm->choice1, bit );
|
||||||
if( !bit )
|
if( !bit )
|
||||||
Re_encode_tree3( renc, lm->bm_low[pos_state], symbol );
|
Re_encode_tree3( renc, lm->bm_low[pos_state], symbol );
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
bit = ( ( symbol -= len_low_symbols ) >= len_mid_symbols );
|
bit = ( symbol -= len_low_symbols ) >= len_mid_symbols;
|
||||||
Re_encode_bit( renc, &lm->choice2, bit );
|
Re_encode_bit( renc, &lm->choice2, bit );
|
||||||
if( !bit )
|
if( !bit )
|
||||||
Re_encode_tree3( renc, lm->bm_mid[pos_state], symbol );
|
Re_encode_tree3( renc, lm->bm_mid[pos_state], symbol );
|
||||||
|
@ -512,9 +512,9 @@ static inline void Re_encode_len( struct Range_encoder * const renc,
|
||||||
enum { max_marker_size = 16,
|
enum { max_marker_size = 16,
|
||||||
num_rep_distances = 4 }; /* must be 4 */
|
num_rep_distances = 4 }; /* must be 4 */
|
||||||
|
|
||||||
struct LZ_encoder_base
|
typedef struct LZ_encoder_base
|
||||||
{
|
{
|
||||||
struct Matchfinder_base mb;
|
Matchfinder_base mb;
|
||||||
unsigned long long member_size_limit;
|
unsigned long long member_size_limit;
|
||||||
uint32_t crc;
|
uint32_t crc;
|
||||||
|
|
||||||
|
@ -528,18 +528,18 @@ struct LZ_encoder_base
|
||||||
Bit_model bm_dis_slot[len_states][1<<dis_slot_bits];
|
Bit_model bm_dis_slot[len_states][1<<dis_slot_bits];
|
||||||
Bit_model bm_dis[modeled_distances-end_dis_model+1];
|
Bit_model bm_dis[modeled_distances-end_dis_model+1];
|
||||||
Bit_model bm_align[dis_align_size];
|
Bit_model bm_align[dis_align_size];
|
||||||
struct Len_model match_len_model;
|
Len_model match_len_model;
|
||||||
struct Len_model rep_len_model;
|
Len_model rep_len_model;
|
||||||
struct Range_encoder renc;
|
Range_encoder renc;
|
||||||
int reps[num_rep_distances];
|
int reps[num_rep_distances];
|
||||||
State state;
|
State state;
|
||||||
bool member_finished;
|
bool member_finished;
|
||||||
};
|
} LZ_encoder_base;
|
||||||
|
|
||||||
static void LZeb_reset( struct LZ_encoder_base * const eb,
|
static void LZeb_reset( LZ_encoder_base * const eb,
|
||||||
const unsigned long long member_size );
|
const unsigned long long member_size );
|
||||||
|
|
||||||
static inline bool LZeb_init( struct LZ_encoder_base * const eb,
|
static inline bool LZeb_init( LZ_encoder_base * const eb,
|
||||||
const int before_size, const int dict_size,
|
const int before_size, const int dict_size,
|
||||||
const int after_size, const int dict_factor,
|
const int after_size, const int dict_factor,
|
||||||
const int num_prev_positions23,
|
const int num_prev_positions23,
|
||||||
|
@ -555,34 +555,34 @@ static inline bool LZeb_init( struct LZ_encoder_base * const eb,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool LZeb_member_finished( const struct LZ_encoder_base * const eb )
|
static inline bool LZeb_member_finished( const LZ_encoder_base * const eb )
|
||||||
{ return eb->member_finished && Cb_empty( &eb->renc.cb ); }
|
{ return eb->member_finished && Cb_empty( &eb->renc.cb ); }
|
||||||
|
|
||||||
static inline void LZeb_free( struct LZ_encoder_base * const eb )
|
static inline void LZeb_free( LZ_encoder_base * const eb )
|
||||||
{ Re_free( &eb->renc ); Mb_free( &eb->mb ); }
|
{ Re_free( &eb->renc ); Mb_free( &eb->mb ); }
|
||||||
|
|
||||||
static inline unsigned LZeb_crc( const struct LZ_encoder_base * const eb )
|
static inline unsigned LZeb_crc( const LZ_encoder_base * const eb )
|
||||||
{ return eb->crc ^ 0xFFFFFFFFU; }
|
{ return eb->crc ^ 0xFFFFFFFFU; }
|
||||||
|
|
||||||
static inline int LZeb_price_literal( const struct LZ_encoder_base * const eb,
|
static inline int LZeb_price_literal( const LZ_encoder_base * const eb,
|
||||||
const uint8_t prev_byte, const uint8_t symbol )
|
const uint8_t prev_byte, const uint8_t symbol )
|
||||||
{ return price_symbol8( eb->bm_literal[get_lit_state(prev_byte)], symbol ); }
|
{ return price_symbol8( eb->bm_literal[get_lit_state(prev_byte)], symbol ); }
|
||||||
|
|
||||||
static inline int LZeb_price_matched( const struct LZ_encoder_base * const eb,
|
static inline int LZeb_price_matched( const LZ_encoder_base * const eb,
|
||||||
const uint8_t prev_byte, const uint8_t symbol, const uint8_t match_byte )
|
const uint8_t prev_byte, const uint8_t symbol, const uint8_t match_byte )
|
||||||
{ return price_matched( eb->bm_literal[get_lit_state(prev_byte)], symbol,
|
{ return price_matched( eb->bm_literal[get_lit_state(prev_byte)], symbol,
|
||||||
match_byte ); }
|
match_byte ); }
|
||||||
|
|
||||||
static inline void LZeb_encode_literal( struct LZ_encoder_base * const eb,
|
static inline void LZeb_encode_literal( LZ_encoder_base * const eb,
|
||||||
const uint8_t prev_byte, const uint8_t symbol )
|
const uint8_t prev_byte, const uint8_t symbol )
|
||||||
{ Re_encode_tree8( &eb->renc, eb->bm_literal[get_lit_state(prev_byte)], symbol ); }
|
{ Re_encode_tree8( &eb->renc, eb->bm_literal[get_lit_state(prev_byte)], symbol ); }
|
||||||
|
|
||||||
static inline void LZeb_encode_matched( struct LZ_encoder_base * const eb,
|
static inline void LZeb_encode_matched( LZ_encoder_base * const eb,
|
||||||
const uint8_t prev_byte, const uint8_t symbol, const uint8_t match_byte )
|
const uint8_t prev_byte, const uint8_t symbol, const uint8_t match_byte )
|
||||||
{ Re_encode_matched( &eb->renc, eb->bm_literal[get_lit_state(prev_byte)],
|
{ Re_encode_matched( &eb->renc, eb->bm_literal[get_lit_state(prev_byte)],
|
||||||
symbol, match_byte ); }
|
symbol, match_byte ); }
|
||||||
|
|
||||||
static inline void LZeb_encode_pair( struct LZ_encoder_base * const eb,
|
static inline void LZeb_encode_pair( LZ_encoder_base * const eb,
|
||||||
const unsigned dis, const int len,
|
const unsigned dis, const int len,
|
||||||
const int pos_state )
|
const int pos_state )
|
||||||
{
|
{
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int FLZe_longest_match_len( struct FLZ_encoder * const fe, int * const distance )
|
static int FLZe_longest_match_len( FLZ_encoder * const fe, int * const distance )
|
||||||
{
|
{
|
||||||
enum { len_limit = 16 };
|
enum { len_limit = 16 };
|
||||||
int32_t * ptr0 = fe->eb.mb.pos_array + fe->eb.mb.cyclic_pos;
|
int32_t * ptr0 = fe->eb.mb.pos_array + fe->eb.mb.cyclic_pos;
|
||||||
|
@ -58,7 +58,7 @@ static int FLZe_longest_match_len( struct FLZ_encoder * const fe, int * const di
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool FLZe_encode_member( struct FLZ_encoder * const fe )
|
static bool FLZe_encode_member( FLZ_encoder * const fe )
|
||||||
{
|
{
|
||||||
int rep = 0, i;
|
int rep = 0, i;
|
||||||
State * const state = &fe->eb.state;
|
State * const state = &fe->eb.state;
|
||||||
|
|
|
@ -17,13 +17,13 @@
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
struct FLZ_encoder
|
typedef struct FLZ_encoder
|
||||||
{
|
{
|
||||||
struct LZ_encoder_base eb;
|
LZ_encoder_base eb;
|
||||||
unsigned key4; /* key made from latest 4 bytes */
|
unsigned key4; /* key made from latest 4 bytes */
|
||||||
};
|
} FLZ_encoder;
|
||||||
|
|
||||||
static inline void FLZe_reset_key4( struct FLZ_encoder * const fe )
|
static inline void FLZe_reset_key4( FLZ_encoder * const fe )
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
fe->key4 = 0;
|
fe->key4 = 0;
|
||||||
|
@ -31,9 +31,9 @@ static inline void FLZe_reset_key4( struct FLZ_encoder * const fe )
|
||||||
fe->key4 = ( fe->key4 << 4 ) ^ fe->eb.mb.buffer[i];
|
fe->key4 = ( fe->key4 << 4 ) ^ fe->eb.mb.buffer[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool FLZe_update_and_move( struct FLZ_encoder * const fe, int n )
|
static inline bool FLZe_update_and_move( FLZ_encoder * const fe, int n )
|
||||||
{
|
{
|
||||||
struct Matchfinder_base * const mb = &fe->eb.mb;
|
Matchfinder_base * const mb = &fe->eb.mb;
|
||||||
while( --n >= 0 )
|
while( --n >= 0 )
|
||||||
{
|
{
|
||||||
if( Mb_available_bytes( mb ) >= 4 )
|
if( Mb_available_bytes( mb ) >= 4 )
|
||||||
|
@ -48,7 +48,7 @@ static inline bool FLZe_update_and_move( struct FLZ_encoder * const fe, int n )
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool FLZe_init( struct FLZ_encoder * const fe,
|
static inline bool FLZe_init( FLZ_encoder * const fe,
|
||||||
const unsigned long long member_size )
|
const unsigned long long member_size )
|
||||||
{
|
{
|
||||||
enum { before_size = 0,
|
enum { before_size = 0,
|
||||||
|
@ -65,6 +65,6 @@ static inline bool FLZe_init( struct FLZ_encoder * const fe,
|
||||||
member_size );
|
member_size );
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void FLZe_reset( struct FLZ_encoder * const fe,
|
static inline void FLZe_reset( FLZ_encoder * const fe,
|
||||||
const unsigned long long member_size )
|
const unsigned long long member_size )
|
||||||
{ LZeb_reset( &fe->eb, member_size ); }
|
{ LZeb_reset( &fe->eb, member_size ); }
|
||||||
|
|
22
ffexample.c
22
ffexample.c
|
@ -53,7 +53,7 @@ static void show_help( void )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int ffcompress( struct LZ_Encoder * const encoder,
|
int ffcompress( LZ_Encoder * const encoder,
|
||||||
FILE * const infile, FILE * const outfile )
|
FILE * const infile, FILE * const outfile )
|
||||||
{
|
{
|
||||||
enum { buffer_size = 16384 };
|
enum { buffer_size = 16384 };
|
||||||
|
@ -79,7 +79,7 @@ int ffcompress( struct LZ_Encoder * const encoder,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int ffdecompress( struct LZ_Decoder * const decoder,
|
int ffdecompress( LZ_Decoder * const decoder,
|
||||||
FILE * const infile, FILE * const outfile )
|
FILE * const infile, FILE * const outfile )
|
||||||
{
|
{
|
||||||
enum { buffer_size = 16384 };
|
enum { buffer_size = 16384 };
|
||||||
|
@ -105,8 +105,7 @@ int ffdecompress( struct LZ_Decoder * const decoder,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int ffboth( struct LZ_Encoder * const encoder,
|
int ffboth( LZ_Encoder * const encoder, LZ_Decoder * const decoder,
|
||||||
struct LZ_Decoder * const decoder,
|
|
||||||
FILE * const infile, FILE * const outfile )
|
FILE * const infile, FILE * const outfile )
|
||||||
{
|
{
|
||||||
enum { buffer_size = 16384 };
|
enum { buffer_size = 16384 };
|
||||||
|
@ -147,8 +146,7 @@ int ffmmcompress( FILE * const infile, FILE * const outfile )
|
||||||
enum { buffer_size = 16384, member_size = 4096 };
|
enum { buffer_size = 16384, member_size = 4096 };
|
||||||
uint8_t buffer[buffer_size];
|
uint8_t buffer[buffer_size];
|
||||||
bool done = false;
|
bool done = false;
|
||||||
struct LZ_Encoder * const encoder =
|
LZ_Encoder * const encoder = LZ_compress_open( 65535, 16, member_size );
|
||||||
LZ_compress_open( 65535, 16, member_size );
|
|
||||||
if( !encoder || LZ_compress_errno( encoder ) != LZ_ok )
|
if( !encoder || LZ_compress_errno( encoder ) != LZ_ok )
|
||||||
{ fputs( "ffexample: Not enough memory.\n", stderr );
|
{ fputs( "ffexample: Not enough memory.\n", stderr );
|
||||||
LZ_compress_close( encoder ); return 1; }
|
LZ_compress_close( encoder ); return 1; }
|
||||||
|
@ -182,7 +180,7 @@ int ffmmcompress( FILE * const infile, FILE * const outfile )
|
||||||
for each line of text terminated by a newline character or by EOF.
|
for each line of text terminated by a newline character or by EOF.
|
||||||
Return 0 if success, 1 if error.
|
Return 0 if success, 1 if error.
|
||||||
*/
|
*/
|
||||||
int fflfcompress( struct LZ_Encoder * const encoder,
|
int fflfcompress( LZ_Encoder * const encoder,
|
||||||
FILE * const infile, FILE * const outfile )
|
FILE * const infile, FILE * const outfile )
|
||||||
{
|
{
|
||||||
enum { buffer_size = 16384 };
|
enum { buffer_size = 16384 };
|
||||||
|
@ -223,7 +221,7 @@ int fflfcompress( struct LZ_Encoder * const encoder,
|
||||||
next member in case of data error, including the automatic removal of
|
next member in case of data error, including the automatic removal of
|
||||||
leading garbage.
|
leading garbage.
|
||||||
*/
|
*/
|
||||||
int ffrsdecompress( struct LZ_Decoder * const decoder,
|
int ffrsdecompress( LZ_Decoder * const decoder,
|
||||||
FILE * const infile, FILE * const outfile )
|
FILE * const infile, FILE * const outfile )
|
||||||
{
|
{
|
||||||
enum { buffer_size = 16384 };
|
enum { buffer_size = 16384 };
|
||||||
|
@ -262,11 +260,11 @@ int main( const int argc, const char * const argv[] )
|
||||||
setmode( STDOUT_FILENO, O_BINARY );
|
setmode( STDOUT_FILENO, O_BINARY );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct LZ_Encoder * const encoder = LZ_compress_open( 65535, 16, INT64_MAX );
|
LZ_Encoder * const encoder = LZ_compress_open( 65535, 16, INT64_MAX );
|
||||||
struct LZ_Decoder * const decoder = LZ_decompress_open();
|
LZ_Decoder * const decoder = LZ_decompress_open();
|
||||||
FILE * const infile = ( argc >= 3 && strcmp( argv[2], "-" ) != 0 ) ?
|
FILE * const infile = (argc >= 3 && strcmp( argv[2], "-" ) != 0) ?
|
||||||
fopen( argv[2], "rb" ) : stdin;
|
fopen( argv[2], "rb" ) : stdin;
|
||||||
FILE * const outfile = ( argc >= 4 && strcmp( argv[3], "-" ) != 0 ) ?
|
FILE * const outfile = (argc >= 4 && strcmp( argv[3], "-" ) != 0) ?
|
||||||
fopen( argv[3], "wb" ) : stdout;
|
fopen( argv[3], "wb" ) : stdout;
|
||||||
int retval;
|
int retval;
|
||||||
|
|
||||||
|
|
24
lzcheck.c
24
lzcheck.c
|
@ -41,10 +41,10 @@ static void show_line( const uint8_t * const buffer, const int size )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static struct LZ_Encoder * xopen_encoder( const int dictionary_size )
|
static LZ_Encoder * xopen_encoder( const int dictionary_size )
|
||||||
{
|
{
|
||||||
const int match_len_limit = 16;
|
const int match_len_limit = 16;
|
||||||
struct LZ_Encoder * const encoder =
|
LZ_Encoder * const encoder =
|
||||||
LZ_compress_open( dictionary_size, match_len_limit, member_size );
|
LZ_compress_open( dictionary_size, match_len_limit, member_size );
|
||||||
if( !encoder || LZ_compress_errno( encoder ) != LZ_ok )
|
if( !encoder || LZ_compress_errno( encoder ) != LZ_ok )
|
||||||
{
|
{
|
||||||
|
@ -63,9 +63,9 @@ static struct LZ_Encoder * xopen_encoder( const int dictionary_size )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static struct LZ_Decoder * xopen_decoder( void )
|
static LZ_Decoder * xopen_decoder( void )
|
||||||
{
|
{
|
||||||
struct LZ_Decoder * const decoder = LZ_decompress_open();
|
LZ_Decoder * const decoder = LZ_decompress_open();
|
||||||
if( !decoder || LZ_decompress_errno( decoder ) != LZ_ok )
|
if( !decoder || LZ_decompress_errno( decoder ) != LZ_ok )
|
||||||
{
|
{
|
||||||
LZ_decompress_close( decoder );
|
LZ_decompress_close( decoder );
|
||||||
|
@ -76,8 +76,7 @@ static struct LZ_Decoder * xopen_decoder( void )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void xclose_encoder( struct LZ_Encoder * const encoder,
|
static void xclose_encoder( LZ_Encoder * const encoder, const bool finish )
|
||||||
const bool finish )
|
|
||||||
{
|
{
|
||||||
if( finish )
|
if( finish )
|
||||||
{
|
{
|
||||||
|
@ -105,8 +104,7 @@ static void xclose_encoder( struct LZ_Encoder * const encoder,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void xclose_decoder( struct LZ_Decoder * const decoder,
|
static void xclose_decoder( LZ_Decoder * const decoder, const bool finish )
|
||||||
const bool finish )
|
|
||||||
{
|
{
|
||||||
if( finish )
|
if( finish )
|
||||||
{
|
{
|
||||||
|
@ -160,8 +158,8 @@ static const uint8_t * next_line( FILE * const file, int * const sizep )
|
||||||
|
|
||||||
static int check_sync_flush( FILE * const file, const int dictionary_size )
|
static int check_sync_flush( FILE * const file, const int dictionary_size )
|
||||||
{
|
{
|
||||||
struct LZ_Encoder * const encoder = xopen_encoder( dictionary_size );
|
LZ_Encoder * const encoder = xopen_encoder( dictionary_size );
|
||||||
struct LZ_Decoder * const decoder = xopen_decoder();
|
LZ_Decoder * const decoder = xopen_decoder();
|
||||||
int retval = 0;
|
int retval = 0;
|
||||||
|
|
||||||
while( retval <= 1 ) /* test LZ_compress_sync_flush */
|
while( retval <= 1 ) /* test LZ_compress_sync_flush */
|
||||||
|
@ -267,8 +265,8 @@ static int check_sync_flush( FILE * const file, const int dictionary_size )
|
||||||
*/
|
*/
|
||||||
static int check_members( FILE * const file, const int dictionary_size )
|
static int check_members( FILE * const file, const int dictionary_size )
|
||||||
{
|
{
|
||||||
struct LZ_Encoder * const encoder = xopen_encoder( dictionary_size );
|
LZ_Encoder * const encoder = xopen_encoder( dictionary_size );
|
||||||
struct LZ_Decoder * const decoder = xopen_decoder();
|
LZ_Decoder * const decoder = xopen_decoder();
|
||||||
int retval = 0;
|
int retval = 0;
|
||||||
|
|
||||||
while( retval <= 1 ) /* test LZ_compress_restart_member */
|
while( retval <= 1 ) /* test LZ_compress_restart_member */
|
||||||
|
@ -362,7 +360,7 @@ int main( const int argc, const char * const argv[] )
|
||||||
( strcmp( argv[1], "-m" ) == 0 || strcmp( argv[1], "-s" ) == 0 ) ) ?
|
( strcmp( argv[1], "-m" ) == 0 || strcmp( argv[1], "-s" ) == 0 ) ) ?
|
||||||
argv[1][1] : 0;
|
argv[1][1] : 0;
|
||||||
const int first = opt ? 2 : 1;
|
const int first = opt ? 2 : 1;
|
||||||
const bool verbose = ( opt != 0 || argc > first + 1 );
|
const bool verbose = opt != 0 || argc > first + 1;
|
||||||
|
|
||||||
if( argc < 2 )
|
if( argc < 2 )
|
||||||
{
|
{
|
||||||
|
|
6
lzip.h
6
lzip.h
|
@ -94,16 +94,16 @@ static inline void Bm_init( Bit_model * const probability )
|
||||||
static inline void Bm_array_init( Bit_model bm[], const int size )
|
static inline void Bm_array_init( Bit_model bm[], const int size )
|
||||||
{ int i; for( i = 0; i < size; ++i ) Bm_init( &bm[i] ); }
|
{ int i; for( i = 0; i < size; ++i ) Bm_init( &bm[i] ); }
|
||||||
|
|
||||||
struct Len_model
|
typedef struct Len_model
|
||||||
{
|
{
|
||||||
Bit_model choice1;
|
Bit_model choice1;
|
||||||
Bit_model choice2;
|
Bit_model choice2;
|
||||||
Bit_model bm_low[pos_states][len_low_symbols];
|
Bit_model bm_low[pos_states][len_low_symbols];
|
||||||
Bit_model bm_mid[pos_states][len_mid_symbols];
|
Bit_model bm_mid[pos_states][len_mid_symbols];
|
||||||
Bit_model bm_high[len_high_symbols];
|
Bit_model bm_high[len_high_symbols];
|
||||||
};
|
} Len_model;
|
||||||
|
|
||||||
static inline void Lm_init( struct Len_model * const lm )
|
static inline void Lm_init( Len_model * const lm )
|
||||||
{
|
{
|
||||||
Bm_init( &lm->choice1 );
|
Bm_init( &lm->choice1 );
|
||||||
Bm_init( &lm->choice2 );
|
Bm_init( &lm->choice2 );
|
||||||
|
|
110
lzlib.c
110
lzlib.c
|
@ -39,14 +39,14 @@ struct LZ_Encoder
|
||||||
{
|
{
|
||||||
unsigned long long partial_in_size;
|
unsigned long long partial_in_size;
|
||||||
unsigned long long partial_out_size;
|
unsigned long long partial_out_size;
|
||||||
struct LZ_encoder_base * lz_encoder_base; /* these 3 pointers make a */
|
LZ_encoder_base * lz_encoder_base; /* these 3 pointers make a */
|
||||||
struct LZ_encoder * lz_encoder; /* polymorphic encoder */
|
LZ_encoder * lz_encoder; /* polymorphic encoder */
|
||||||
struct FLZ_encoder * flz_encoder;
|
FLZ_encoder * flz_encoder;
|
||||||
enum LZ_Errno lz_errno;
|
LZ_Errno lz_errno;
|
||||||
bool fatal;
|
bool fatal;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void LZ_Encoder_init( struct LZ_Encoder * const e )
|
static void LZ_Encoder_init( LZ_Encoder * const e )
|
||||||
{
|
{
|
||||||
e->partial_in_size = 0;
|
e->partial_in_size = 0;
|
||||||
e->partial_out_size = 0;
|
e->partial_out_size = 0;
|
||||||
|
@ -62,16 +62,16 @@ struct LZ_Decoder
|
||||||
{
|
{
|
||||||
unsigned long long partial_in_size;
|
unsigned long long partial_in_size;
|
||||||
unsigned long long partial_out_size;
|
unsigned long long partial_out_size;
|
||||||
struct Range_decoder * rdec;
|
Range_decoder * rdec;
|
||||||
struct LZ_decoder * lz_decoder;
|
LZ_decoder * lz_decoder;
|
||||||
enum LZ_Errno lz_errno;
|
LZ_Errno lz_errno;
|
||||||
Lzip_header member_header; /* header of current member */
|
Lzip_header member_header; /* header of current member */
|
||||||
bool fatal;
|
bool fatal;
|
||||||
bool first_header; /* true until first header is read */
|
bool first_header; /* true until first header is read */
|
||||||
bool seeking;
|
bool seeking;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void LZ_Decoder_init( struct LZ_Decoder * const d )
|
static void LZ_Decoder_init( LZ_Decoder * const d )
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
d->partial_in_size = 0;
|
d->partial_in_size = 0;
|
||||||
|
@ -86,7 +86,7 @@ static void LZ_Decoder_init( struct LZ_Decoder * const d )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool check_encoder( struct LZ_Encoder * const e )
|
static bool check_encoder( LZ_Encoder * const e )
|
||||||
{
|
{
|
||||||
if( !e ) return false;
|
if( !e ) return false;
|
||||||
if( !e->lz_encoder_base || ( !e->lz_encoder && !e->flz_encoder ) ||
|
if( !e->lz_encoder_base || ( !e->lz_encoder && !e->flz_encoder ) ||
|
||||||
|
@ -96,7 +96,7 @@ static bool check_encoder( struct LZ_Encoder * const e )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool check_decoder( struct LZ_Decoder * const d )
|
static bool check_decoder( LZ_Decoder * const d )
|
||||||
{
|
{
|
||||||
if( !d ) return false;
|
if( !d ) return false;
|
||||||
if( !d->rdec )
|
if( !d->rdec )
|
||||||
|
@ -111,7 +111,7 @@ int LZ_api_version( void ) { return LZ_API_VERSION; }
|
||||||
|
|
||||||
const char * LZ_version( void ) { return LZ_version_string; }
|
const char * LZ_version( void ) { return LZ_version_string; }
|
||||||
|
|
||||||
const char * LZ_strerror( const enum LZ_Errno lz_errno )
|
const char * LZ_strerror( const LZ_Errno lz_errno )
|
||||||
{
|
{
|
||||||
switch( lz_errno )
|
switch( lz_errno )
|
||||||
{
|
{
|
||||||
|
@ -138,13 +138,12 @@ int LZ_max_match_len_limit( void ) { return max_match_len; }
|
||||||
|
|
||||||
/* --------------------- Compression Functions --------------------- */
|
/* --------------------- Compression Functions --------------------- */
|
||||||
|
|
||||||
struct LZ_Encoder * LZ_compress_open( const int dictionary_size,
|
LZ_Encoder * LZ_compress_open( const int dictionary_size,
|
||||||
const int match_len_limit,
|
const int match_len_limit,
|
||||||
const unsigned long long member_size )
|
const unsigned long long member_size )
|
||||||
{
|
{
|
||||||
Lzip_header header;
|
Lzip_header header;
|
||||||
struct LZ_Encoder * const e =
|
LZ_Encoder * const e = (LZ_Encoder *)malloc( sizeof (LZ_Encoder) );
|
||||||
(struct LZ_Encoder *)malloc( sizeof (struct LZ_Encoder) );
|
|
||||||
if( !e ) return 0;
|
if( !e ) return 0;
|
||||||
LZ_Encoder_init( e );
|
LZ_Encoder_init( e );
|
||||||
if( !Lh_set_dictionary_size( header, dictionary_size ) ||
|
if( !Lh_set_dictionary_size( header, dictionary_size ) ||
|
||||||
|
@ -156,14 +155,14 @@ struct LZ_Encoder * LZ_compress_open( const int dictionary_size,
|
||||||
{
|
{
|
||||||
if( dictionary_size == 65535 && match_len_limit == 16 )
|
if( dictionary_size == 65535 && match_len_limit == 16 )
|
||||||
{
|
{
|
||||||
e->flz_encoder = (struct FLZ_encoder *)malloc( sizeof (struct FLZ_encoder) );
|
e->flz_encoder = (FLZ_encoder *)malloc( sizeof (FLZ_encoder) );
|
||||||
if( e->flz_encoder && FLZe_init( e->flz_encoder, member_size ) )
|
if( e->flz_encoder && FLZe_init( e->flz_encoder, member_size ) )
|
||||||
{ e->lz_encoder_base = &e->flz_encoder->eb; return e; }
|
{ e->lz_encoder_base = &e->flz_encoder->eb; return e; }
|
||||||
free( e->flz_encoder ); e->flz_encoder = 0;
|
free( e->flz_encoder ); e->flz_encoder = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
e->lz_encoder = (struct LZ_encoder *)malloc( sizeof (struct LZ_encoder) );
|
e->lz_encoder = (LZ_encoder *)malloc( sizeof (LZ_encoder) );
|
||||||
if( e->lz_encoder && LZe_init( e->lz_encoder, Lh_get_dictionary_size( header ),
|
if( e->lz_encoder && LZe_init( e->lz_encoder, Lh_get_dictionary_size( header ),
|
||||||
match_len_limit, member_size ) )
|
match_len_limit, member_size ) )
|
||||||
{ e->lz_encoder_base = &e->lz_encoder->eb; return e; }
|
{ e->lz_encoder_base = &e->lz_encoder->eb; return e; }
|
||||||
|
@ -176,7 +175,7 @@ struct LZ_Encoder * LZ_compress_open( const int dictionary_size,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int LZ_compress_close( struct LZ_Encoder * const e )
|
int LZ_compress_close( LZ_Encoder * const e )
|
||||||
{
|
{
|
||||||
if( !e ) return -1;
|
if( !e ) return -1;
|
||||||
if( e->lz_encoder_base )
|
if( e->lz_encoder_base )
|
||||||
|
@ -187,7 +186,7 @@ int LZ_compress_close( struct LZ_Encoder * const e )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int LZ_compress_finish( struct LZ_Encoder * const e )
|
int LZ_compress_finish( LZ_Encoder * const e )
|
||||||
{
|
{
|
||||||
if( !check_encoder( e ) || e->fatal ) return -1;
|
if( !check_encoder( e ) || e->fatal ) return -1;
|
||||||
Mb_finish( &e->lz_encoder_base->mb );
|
Mb_finish( &e->lz_encoder_base->mb );
|
||||||
|
@ -205,7 +204,7 @@ int LZ_compress_finish( struct LZ_Encoder * const e )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int LZ_compress_restart_member( struct LZ_Encoder * const e,
|
int LZ_compress_restart_member( LZ_Encoder * const e,
|
||||||
const unsigned long long member_size )
|
const unsigned long long member_size )
|
||||||
{
|
{
|
||||||
if( !check_encoder( e ) || e->fatal ) return -1;
|
if( !check_encoder( e ) || e->fatal ) return -1;
|
||||||
|
@ -224,7 +223,7 @@ int LZ_compress_restart_member( struct LZ_Encoder * const e,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int LZ_compress_sync_flush( struct LZ_Encoder * const e )
|
int LZ_compress_sync_flush( LZ_Encoder * const e )
|
||||||
{
|
{
|
||||||
if( !check_encoder( e ) || e->fatal ) return -1;
|
if( !check_encoder( e ) || e->fatal ) return -1;
|
||||||
if( !e->lz_encoder_base->mb.at_stream_end )
|
if( !e->lz_encoder_base->mb.at_stream_end )
|
||||||
|
@ -233,13 +232,13 @@ int LZ_compress_sync_flush( struct LZ_Encoder * const e )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int LZ_compress_read( struct LZ_Encoder * const e,
|
int LZ_compress_read( LZ_Encoder * const e,
|
||||||
uint8_t * const buffer, const int size )
|
uint8_t * const buffer, const int size )
|
||||||
{
|
{
|
||||||
if( !check_encoder( e ) || e->fatal ) return -1;
|
if( !check_encoder( e ) || e->fatal ) return -1;
|
||||||
if( size < 0 ) return 0;
|
if( size < 0 ) return 0;
|
||||||
|
|
||||||
{ struct LZ_encoder_base * const eb = e->lz_encoder_base;
|
{ LZ_encoder_base * const eb = e->lz_encoder_base;
|
||||||
int out_size = Re_read_data( &eb->renc, buffer, size );
|
int out_size = Re_read_data( &eb->renc, buffer, size );
|
||||||
/* minimize number of calls to encode_member */
|
/* minimize number of calls to encode_member */
|
||||||
if( out_size < size || size == 0 )
|
if( out_size < size || size == 0 )
|
||||||
|
@ -255,7 +254,7 @@ int LZ_compress_read( struct LZ_Encoder * const e,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int LZ_compress_write( struct LZ_Encoder * const e,
|
int LZ_compress_write( LZ_Encoder * const e,
|
||||||
const uint8_t * const buffer, const int size )
|
const uint8_t * const buffer, const int size )
|
||||||
{
|
{
|
||||||
if( !check_encoder( e ) || e->fatal ) return -1;
|
if( !check_encoder( e ) || e->fatal ) return -1;
|
||||||
|
@ -263,21 +262,21 @@ int LZ_compress_write( struct LZ_Encoder * const e,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int LZ_compress_write_size( struct LZ_Encoder * const e )
|
int LZ_compress_write_size( LZ_Encoder * const e )
|
||||||
{
|
{
|
||||||
if( !check_encoder( e ) || e->fatal ) return -1;
|
if( !check_encoder( e ) || e->fatal ) return -1;
|
||||||
return Mb_free_bytes( &e->lz_encoder_base->mb );
|
return Mb_free_bytes( &e->lz_encoder_base->mb );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
enum LZ_Errno LZ_compress_errno( struct LZ_Encoder * const e )
|
LZ_Errno LZ_compress_errno( LZ_Encoder * const e )
|
||||||
{
|
{
|
||||||
if( !e ) return LZ_bad_argument;
|
if( !e ) return LZ_bad_argument;
|
||||||
return e->lz_errno;
|
return e->lz_errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int LZ_compress_finished( struct LZ_Encoder * const e )
|
int LZ_compress_finished( LZ_Encoder * const e )
|
||||||
{
|
{
|
||||||
if( !check_encoder( e ) ) return -1;
|
if( !check_encoder( e ) ) return -1;
|
||||||
return Mb_data_finished( &e->lz_encoder_base->mb ) &&
|
return Mb_data_finished( &e->lz_encoder_base->mb ) &&
|
||||||
|
@ -285,35 +284,35 @@ int LZ_compress_finished( struct LZ_Encoder * const e )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int LZ_compress_member_finished( struct LZ_Encoder * const e )
|
int LZ_compress_member_finished( LZ_Encoder * const e )
|
||||||
{
|
{
|
||||||
if( !check_encoder( e ) ) return -1;
|
if( !check_encoder( e ) ) return -1;
|
||||||
return LZeb_member_finished( e->lz_encoder_base );
|
return LZeb_member_finished( e->lz_encoder_base );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
unsigned long long LZ_compress_data_position( struct LZ_Encoder * const e )
|
unsigned long long LZ_compress_data_position( LZ_Encoder * const e )
|
||||||
{
|
{
|
||||||
if( !check_encoder( e ) ) return 0;
|
if( !check_encoder( e ) ) return 0;
|
||||||
return Mb_data_position( &e->lz_encoder_base->mb );
|
return Mb_data_position( &e->lz_encoder_base->mb );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
unsigned long long LZ_compress_member_position( struct LZ_Encoder * const e )
|
unsigned long long LZ_compress_member_position( LZ_Encoder * const e )
|
||||||
{
|
{
|
||||||
if( !check_encoder( e ) ) return 0;
|
if( !check_encoder( e ) ) return 0;
|
||||||
return Re_member_position( &e->lz_encoder_base->renc );
|
return Re_member_position( &e->lz_encoder_base->renc );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
unsigned long long LZ_compress_total_in_size( struct LZ_Encoder * const e )
|
unsigned long long LZ_compress_total_in_size( LZ_Encoder * const e )
|
||||||
{
|
{
|
||||||
if( !check_encoder( e ) ) return 0;
|
if( !check_encoder( e ) ) return 0;
|
||||||
return e->partial_in_size + Mb_data_position( &e->lz_encoder_base->mb );
|
return e->partial_in_size + Mb_data_position( &e->lz_encoder_base->mb );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
unsigned long long LZ_compress_total_out_size( struct LZ_Encoder * const e )
|
unsigned long long LZ_compress_total_out_size( LZ_Encoder * const e )
|
||||||
{
|
{
|
||||||
if( !check_encoder( e ) ) return 0;
|
if( !check_encoder( e ) ) return 0;
|
||||||
return e->partial_out_size + Re_member_position( &e->lz_encoder_base->renc );
|
return e->partial_out_size + Re_member_position( &e->lz_encoder_base->renc );
|
||||||
|
@ -322,14 +321,13 @@ unsigned long long LZ_compress_total_out_size( struct LZ_Encoder * const e )
|
||||||
|
|
||||||
/* -------------------- Decompression Functions -------------------- */
|
/* -------------------- Decompression Functions -------------------- */
|
||||||
|
|
||||||
struct LZ_Decoder * LZ_decompress_open( void )
|
LZ_Decoder * LZ_decompress_open( void )
|
||||||
{
|
{
|
||||||
struct LZ_Decoder * const d =
|
LZ_Decoder * const d = (LZ_Decoder *)malloc( sizeof (LZ_Decoder) );
|
||||||
(struct LZ_Decoder *)malloc( sizeof (struct LZ_Decoder) );
|
|
||||||
if( !d ) return 0;
|
if( !d ) return 0;
|
||||||
LZ_Decoder_init( d );
|
LZ_Decoder_init( d );
|
||||||
|
|
||||||
d->rdec = (struct Range_decoder *)malloc( sizeof (struct Range_decoder) );
|
d->rdec = (Range_decoder *)malloc( sizeof (Range_decoder) );
|
||||||
if( !d->rdec || !Rd_init( d->rdec ) )
|
if( !d->rdec || !Rd_init( d->rdec ) )
|
||||||
{
|
{
|
||||||
if( d->rdec ) { Rd_free( d->rdec ); free( d->rdec ); d->rdec = 0; }
|
if( d->rdec ) { Rd_free( d->rdec ); free( d->rdec ); d->rdec = 0; }
|
||||||
|
@ -339,7 +337,7 @@ struct LZ_Decoder * LZ_decompress_open( void )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int LZ_decompress_close( struct LZ_Decoder * const d )
|
int LZ_decompress_close( LZ_Decoder * const d )
|
||||||
{
|
{
|
||||||
if( !d ) return -1;
|
if( !d ) return -1;
|
||||||
if( d->lz_decoder )
|
if( d->lz_decoder )
|
||||||
|
@ -350,7 +348,7 @@ int LZ_decompress_close( struct LZ_Decoder * const d )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int LZ_decompress_finish( struct LZ_Decoder * const d )
|
int LZ_decompress_finish( LZ_Decoder * const d )
|
||||||
{
|
{
|
||||||
if( !check_decoder( d ) || d->fatal ) return -1;
|
if( !check_decoder( d ) || d->fatal ) return -1;
|
||||||
if( d->seeking )
|
if( d->seeking )
|
||||||
|
@ -360,7 +358,7 @@ int LZ_decompress_finish( struct LZ_Decoder * const d )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int LZ_decompress_reset( struct LZ_Decoder * const d )
|
int LZ_decompress_reset( LZ_Decoder * const d )
|
||||||
{
|
{
|
||||||
if( !check_decoder( d ) ) return -1;
|
if( !check_decoder( d ) ) return -1;
|
||||||
if( d->lz_decoder )
|
if( d->lz_decoder )
|
||||||
|
@ -376,7 +374,7 @@ int LZ_decompress_reset( struct LZ_Decoder * const d )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int LZ_decompress_sync_to_member( struct LZ_Decoder * const d )
|
int LZ_decompress_sync_to_member( LZ_Decoder * const d )
|
||||||
{
|
{
|
||||||
unsigned skipped = 0;
|
unsigned skipped = 0;
|
||||||
if( !check_decoder( d ) ) return -1;
|
if( !check_decoder( d ) ) return -1;
|
||||||
|
@ -395,7 +393,7 @@ int LZ_decompress_sync_to_member( struct LZ_Decoder * const d )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int LZ_decompress_read( struct LZ_Decoder * const d,
|
int LZ_decompress_read( LZ_Decoder * const d,
|
||||||
uint8_t * const buffer, const int size )
|
uint8_t * const buffer, const int size )
|
||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
|
@ -467,7 +465,7 @@ int LZ_decompress_read( struct LZ_Decoder * const d,
|
||||||
d->fatal = true;
|
d->fatal = true;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
d->lz_decoder = (struct LZ_decoder *)malloc( sizeof (struct LZ_decoder) );
|
d->lz_decoder = (LZ_decoder *)malloc( sizeof (LZ_decoder) );
|
||||||
if( !d->lz_decoder || !LZd_init( d->lz_decoder, d->rdec,
|
if( !d->lz_decoder || !LZd_init( d->lz_decoder, d->rdec,
|
||||||
Lh_get_dictionary_size( d->member_header ) ) )
|
Lh_get_dictionary_size( d->member_header ) ) )
|
||||||
{ /* not enough free memory */
|
{ /* not enough free memory */
|
||||||
|
@ -496,7 +494,7 @@ get_data:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int LZ_decompress_write( struct LZ_Decoder * const d,
|
int LZ_decompress_write( LZ_Decoder * const d,
|
||||||
const uint8_t * const buffer, const int size )
|
const uint8_t * const buffer, const int size )
|
||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
|
@ -519,21 +517,21 @@ int LZ_decompress_write( struct LZ_Decoder * const d,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int LZ_decompress_write_size( struct LZ_Decoder * const d )
|
int LZ_decompress_write_size( LZ_Decoder * const d )
|
||||||
{
|
{
|
||||||
if( !check_decoder( d ) || d->fatal ) return -1;
|
if( !check_decoder( d ) || d->fatal ) return -1;
|
||||||
return Rd_free_bytes( d->rdec );
|
return Rd_free_bytes( d->rdec );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
enum LZ_Errno LZ_decompress_errno( struct LZ_Decoder * const d )
|
LZ_Errno LZ_decompress_errno( LZ_Decoder * const d )
|
||||||
{
|
{
|
||||||
if( !d ) return LZ_bad_argument;
|
if( !d ) return LZ_bad_argument;
|
||||||
return d->lz_errno;
|
return d->lz_errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int LZ_decompress_finished( struct LZ_Decoder * const d )
|
int LZ_decompress_finished( LZ_Decoder * const d )
|
||||||
{
|
{
|
||||||
if( !check_decoder( d ) || d->fatal ) return -1;
|
if( !check_decoder( d ) || d->fatal ) return -1;
|
||||||
return Rd_finished( d->rdec ) &&
|
return Rd_finished( d->rdec ) &&
|
||||||
|
@ -541,28 +539,28 @@ int LZ_decompress_finished( struct LZ_Decoder * const d )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int LZ_decompress_member_finished( struct LZ_Decoder * const d )
|
int LZ_decompress_member_finished( LZ_Decoder * const d )
|
||||||
{
|
{
|
||||||
if( !check_decoder( d ) || d->fatal ) return -1;
|
if( !check_decoder( d ) || d->fatal ) return -1;
|
||||||
return d->lz_decoder && LZd_member_finished( d->lz_decoder );
|
return d->lz_decoder && LZd_member_finished( d->lz_decoder );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int LZ_decompress_member_version( struct LZ_Decoder * const d )
|
int LZ_decompress_member_version( LZ_Decoder * const d )
|
||||||
{
|
{
|
||||||
if( !check_decoder( d ) ) return -1;
|
if( !check_decoder( d ) ) return -1;
|
||||||
return Lh_version( d->member_header );
|
return Lh_version( d->member_header );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int LZ_decompress_dictionary_size( struct LZ_Decoder * const d )
|
int LZ_decompress_dictionary_size( LZ_Decoder * const d )
|
||||||
{
|
{
|
||||||
if( !check_decoder( d ) ) return -1;
|
if( !check_decoder( d ) ) return -1;
|
||||||
return Lh_get_dictionary_size( d->member_header );
|
return Lh_get_dictionary_size( d->member_header );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
unsigned LZ_decompress_data_crc( struct LZ_Decoder * const d )
|
unsigned LZ_decompress_data_crc( LZ_Decoder * const d )
|
||||||
{
|
{
|
||||||
if( check_decoder( d ) && d->lz_decoder )
|
if( check_decoder( d ) && d->lz_decoder )
|
||||||
return LZd_crc( d->lz_decoder );
|
return LZd_crc( d->lz_decoder );
|
||||||
|
@ -570,7 +568,7 @@ unsigned LZ_decompress_data_crc( struct LZ_Decoder * const d )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
unsigned long long LZ_decompress_data_position( struct LZ_Decoder * const d )
|
unsigned long long LZ_decompress_data_position( LZ_Decoder * const d )
|
||||||
{
|
{
|
||||||
if( check_decoder( d ) && d->lz_decoder )
|
if( check_decoder( d ) && d->lz_decoder )
|
||||||
return LZd_data_position( d->lz_decoder );
|
return LZd_data_position( d->lz_decoder );
|
||||||
|
@ -578,21 +576,21 @@ unsigned long long LZ_decompress_data_position( struct LZ_Decoder * const d )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
unsigned long long LZ_decompress_member_position( struct LZ_Decoder * const d )
|
unsigned long long LZ_decompress_member_position( LZ_Decoder * const d )
|
||||||
{
|
{
|
||||||
if( !check_decoder( d ) ) return 0;
|
if( !check_decoder( d ) ) return 0;
|
||||||
return d->rdec->member_position;
|
return d->rdec->member_position;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
unsigned long long LZ_decompress_total_in_size( struct LZ_Decoder * const d )
|
unsigned long long LZ_decompress_total_in_size( LZ_Decoder * const d )
|
||||||
{
|
{
|
||||||
if( !check_decoder( d ) ) return 0;
|
if( !check_decoder( d ) ) return 0;
|
||||||
return d->partial_in_size + d->rdec->member_position;
|
return d->partial_in_size + d->rdec->member_position;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
unsigned long long LZ_decompress_total_out_size( struct LZ_Decoder * const d )
|
unsigned long long LZ_decompress_total_out_size( LZ_Decoder * const d )
|
||||||
{
|
{
|
||||||
if( !check_decoder( d ) ) return 0;
|
if( !check_decoder( d ) ) return 0;
|
||||||
if( d->lz_decoder )
|
if( d->lz_decoder )
|
||||||
|
|
85
lzlib.h
85
lzlib.h
|
@ -26,16 +26,17 @@ extern "C" {
|
||||||
|
|
||||||
#define LZ_API_VERSION 1015
|
#define LZ_API_VERSION 1015
|
||||||
|
|
||||||
static const char * const LZ_version_string = "1.15-pre2";
|
static const char * const LZ_version_string = "1.15-rc1";
|
||||||
|
|
||||||
enum LZ_Errno { LZ_ok = 0, LZ_bad_argument, LZ_mem_error,
|
typedef enum LZ_Errno
|
||||||
LZ_sequence_error, LZ_header_error, LZ_unexpected_eof,
|
{ LZ_ok = 0, LZ_bad_argument, LZ_mem_error,
|
||||||
LZ_data_error, LZ_library_error };
|
LZ_sequence_error, LZ_header_error, LZ_unexpected_eof,
|
||||||
|
LZ_data_error, LZ_library_error } LZ_Errno;
|
||||||
|
|
||||||
|
|
||||||
int LZ_api_version( void ); /* new in 1.12 */
|
int LZ_api_version( void ); /* new in 1.12 */
|
||||||
const char * LZ_version( void );
|
const char * LZ_version( void );
|
||||||
const char * LZ_strerror( const enum LZ_Errno lz_errno );
|
const char * LZ_strerror( const LZ_Errno lz_errno );
|
||||||
|
|
||||||
int LZ_min_dictionary_bits( void );
|
int LZ_min_dictionary_bits( void );
|
||||||
int LZ_min_dictionary_size( void );
|
int LZ_min_dictionary_size( void );
|
||||||
|
@ -47,63 +48,63 @@ int LZ_max_match_len_limit( void );
|
||||||
|
|
||||||
/* --------------------- Compression Functions --------------------- */
|
/* --------------------- Compression Functions --------------------- */
|
||||||
|
|
||||||
struct LZ_Encoder;
|
typedef struct LZ_Encoder LZ_Encoder;
|
||||||
|
|
||||||
struct LZ_Encoder * LZ_compress_open( const int dictionary_size,
|
LZ_Encoder * LZ_compress_open( const int dictionary_size,
|
||||||
const int match_len_limit,
|
const int match_len_limit,
|
||||||
const unsigned long long member_size );
|
const unsigned long long member_size );
|
||||||
int LZ_compress_close( struct LZ_Encoder * const encoder );
|
int LZ_compress_close( LZ_Encoder * const encoder );
|
||||||
|
|
||||||
int LZ_compress_finish( struct LZ_Encoder * const encoder );
|
int LZ_compress_finish( LZ_Encoder * const encoder );
|
||||||
int LZ_compress_restart_member( struct LZ_Encoder * const encoder,
|
int LZ_compress_restart_member( LZ_Encoder * const encoder,
|
||||||
const unsigned long long member_size );
|
const unsigned long long member_size );
|
||||||
int LZ_compress_sync_flush( struct LZ_Encoder * const encoder );
|
int LZ_compress_sync_flush( LZ_Encoder * const encoder );
|
||||||
|
|
||||||
int LZ_compress_read( struct LZ_Encoder * const encoder,
|
int LZ_compress_read( LZ_Encoder * const encoder,
|
||||||
uint8_t * const buffer, const int size );
|
uint8_t * const buffer, const int size );
|
||||||
int LZ_compress_write( struct LZ_Encoder * const encoder,
|
int LZ_compress_write( LZ_Encoder * const encoder,
|
||||||
const uint8_t * const buffer, const int size );
|
const uint8_t * const buffer, const int size );
|
||||||
int LZ_compress_write_size( struct LZ_Encoder * const encoder );
|
int LZ_compress_write_size( LZ_Encoder * const encoder );
|
||||||
|
|
||||||
enum LZ_Errno LZ_compress_errno( struct LZ_Encoder * const encoder );
|
LZ_Errno LZ_compress_errno( LZ_Encoder * const encoder );
|
||||||
int LZ_compress_finished( struct LZ_Encoder * const encoder );
|
int LZ_compress_finished( LZ_Encoder * const encoder );
|
||||||
int LZ_compress_member_finished( struct LZ_Encoder * const encoder );
|
int LZ_compress_member_finished( LZ_Encoder * const encoder );
|
||||||
|
|
||||||
unsigned long long LZ_compress_data_position( struct LZ_Encoder * const encoder );
|
unsigned long long LZ_compress_data_position( LZ_Encoder * const encoder );
|
||||||
unsigned long long LZ_compress_member_position( struct LZ_Encoder * const encoder );
|
unsigned long long LZ_compress_member_position( LZ_Encoder * const encoder );
|
||||||
unsigned long long LZ_compress_total_in_size( struct LZ_Encoder * const encoder );
|
unsigned long long LZ_compress_total_in_size( LZ_Encoder * const encoder );
|
||||||
unsigned long long LZ_compress_total_out_size( struct LZ_Encoder * const encoder );
|
unsigned long long LZ_compress_total_out_size( LZ_Encoder * const encoder );
|
||||||
|
|
||||||
|
|
||||||
/* -------------------- Decompression Functions -------------------- */
|
/* -------------------- Decompression Functions -------------------- */
|
||||||
|
|
||||||
struct LZ_Decoder;
|
typedef struct LZ_Decoder LZ_Decoder;
|
||||||
|
|
||||||
struct LZ_Decoder * LZ_decompress_open( void );
|
LZ_Decoder * LZ_decompress_open( void );
|
||||||
int LZ_decompress_close( struct LZ_Decoder * const decoder );
|
int LZ_decompress_close( LZ_Decoder * const decoder );
|
||||||
|
|
||||||
int LZ_decompress_finish( struct LZ_Decoder * const decoder );
|
int LZ_decompress_finish( LZ_Decoder * const decoder );
|
||||||
int LZ_decompress_reset( struct LZ_Decoder * const decoder );
|
int LZ_decompress_reset( LZ_Decoder * const decoder );
|
||||||
int LZ_decompress_sync_to_member( struct LZ_Decoder * const decoder );
|
int LZ_decompress_sync_to_member( LZ_Decoder * const decoder );
|
||||||
|
|
||||||
int LZ_decompress_read( struct LZ_Decoder * const decoder,
|
int LZ_decompress_read( LZ_Decoder * const decoder,
|
||||||
uint8_t * const buffer, const int size );
|
uint8_t * const buffer, const int size );
|
||||||
int LZ_decompress_write( struct LZ_Decoder * const decoder,
|
int LZ_decompress_write( LZ_Decoder * const decoder,
|
||||||
const uint8_t * const buffer, const int size );
|
const uint8_t * const buffer, const int size );
|
||||||
int LZ_decompress_write_size( struct LZ_Decoder * const decoder );
|
int LZ_decompress_write_size( LZ_Decoder * const decoder );
|
||||||
|
|
||||||
enum LZ_Errno LZ_decompress_errno( struct LZ_Decoder * const decoder );
|
LZ_Errno LZ_decompress_errno( LZ_Decoder * const decoder );
|
||||||
int LZ_decompress_finished( struct LZ_Decoder * const decoder );
|
int LZ_decompress_finished( LZ_Decoder * const decoder );
|
||||||
int LZ_decompress_member_finished( struct LZ_Decoder * const decoder );
|
int LZ_decompress_member_finished( LZ_Decoder * const decoder );
|
||||||
|
|
||||||
int LZ_decompress_member_version( struct LZ_Decoder * const decoder );
|
int LZ_decompress_member_version( LZ_Decoder * const decoder );
|
||||||
int LZ_decompress_dictionary_size( struct LZ_Decoder * const decoder );
|
int LZ_decompress_dictionary_size( LZ_Decoder * const decoder );
|
||||||
unsigned LZ_decompress_data_crc( struct LZ_Decoder * const decoder );
|
unsigned LZ_decompress_data_crc( LZ_Decoder * const decoder );
|
||||||
|
|
||||||
unsigned long long LZ_decompress_data_position( struct LZ_Decoder * const decoder );
|
unsigned long long LZ_decompress_data_position( LZ_Decoder * const decoder );
|
||||||
unsigned long long LZ_decompress_member_position( struct LZ_Decoder * const decoder );
|
unsigned long long LZ_decompress_member_position( LZ_Decoder * const decoder );
|
||||||
unsigned long long LZ_decompress_total_in_size( struct LZ_Decoder * const decoder );
|
unsigned long long LZ_decompress_total_in_size( LZ_Decoder * const decoder );
|
||||||
unsigned long long LZ_decompress_total_out_size( struct LZ_Decoder * const decoder );
|
unsigned long long LZ_decompress_total_out_size( LZ_Decoder * const decoder );
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
109
minilzip.c
109
minilzip.c
|
@ -99,13 +99,13 @@ static const struct { const char * from; const char * to; } known_extensions[] =
|
||||||
{ ".tlz", ".tar" },
|
{ ".tlz", ".tar" },
|
||||||
{ 0, 0 } };
|
{ 0, 0 } };
|
||||||
|
|
||||||
struct Lzma_options
|
typedef struct Lzma_options
|
||||||
{
|
{
|
||||||
int dictionary_size; /* 4 KiB .. 512 MiB */
|
int dictionary_size; /* 4 KiB .. 512 MiB */
|
||||||
int match_len_limit; /* 5 .. 273 */
|
int match_len_limit; /* 5 .. 273 */
|
||||||
};
|
} Lzma_options;
|
||||||
|
|
||||||
enum Mode { m_compress, m_decompress, m_test };
|
typedef enum Mode { m_compress, m_decompress, m_test } Mode;
|
||||||
|
|
||||||
/* Variables used in signal handler context.
|
/* Variables used in signal handler context.
|
||||||
They are not declared volatile because the handler never returns. */
|
They are not declared volatile because the handler never returns. */
|
||||||
|
@ -116,25 +116,26 @@ static bool delete_output_on_interrupt = false;
|
||||||
|
|
||||||
static void show_help( void )
|
static void show_help( void )
|
||||||
{
|
{
|
||||||
printf( "Minilzip is a test program for the compression library lzlib, compatible\n"
|
printf( "Minilzip is a test program for the compression library lzlib. Minilzip is\n"
|
||||||
"(interoperable) with lzip 1.4 or newer.\n"
|
"not intended to be installed because lzip has more features, but minilzip is\n"
|
||||||
|
"well tested and you can use it as your main compressor if so you wish.\n"
|
||||||
"\nLzip is a lossless data compressor with a user interface similar to the one\n"
|
"\nLzip is a lossless data compressor with a user interface similar to the one\n"
|
||||||
"of gzip or bzip2. Lzip uses a simplified form of the 'Lempel-Ziv-Markov\n"
|
"of gzip or bzip2. Lzip uses a simplified form of LZMA (Lempel-Ziv-Markov\n"
|
||||||
"chain-Algorithm' (LZMA) stream format to maximize interoperability. The\n"
|
"chain-Algorithm) designed to achieve complete interoperability between\n"
|
||||||
"maximum dictionary size is 512 MiB so that any lzip file can be decompressed\n"
|
"implementations. The maximum dictionary size is 512 MiB so that any lzip\n"
|
||||||
"on 32-bit machines. Lzip provides accurate and robust 3-factor integrity\n"
|
"file can be decompressed on 32-bit machines. Lzip provides accurate and\n"
|
||||||
"checking. Lzip can compress about as fast as gzip (lzip -0) or compress most\n"
|
"robust 3-factor integrity checking. 'lzip -0' compresses about as fast as\n"
|
||||||
"files more than bzip2 (lzip -9). Decompression speed is intermediate between\n"
|
"gzip, while 'lzip -9' compresses most files more than bzip2. Decompression\n"
|
||||||
"gzip and bzip2. Lzip provides better data recovery capabilities than gzip\n"
|
"speed is intermediate between gzip and bzip2. Lzip provides better data\n"
|
||||||
"and bzip2. Lzip has been designed, written, and tested with great care to\n"
|
"recovery capabilities than gzip and bzip2. Lzip has been designed, written,\n"
|
||||||
"replace gzip and bzip2 as the standard general-purpose compressed format for\n"
|
"and tested with great care to replace gzip and bzip2 as general-purpose\n"
|
||||||
"Unix-like systems.\n"
|
"compressed format for Unix-like systems.\n"
|
||||||
"\nUsage: %s [options] [files]\n", invocation_name );
|
"\nUsage: %s [options] [files]\n", invocation_name );
|
||||||
printf( "\nOptions:\n"
|
printf( "\nOptions:\n"
|
||||||
" -h, --help display this help and exit\n"
|
" -h, --help display this help and exit\n"
|
||||||
" -V, --version output version information and exit\n"
|
" -V, --version output version information and exit\n"
|
||||||
" -a, --trailing-error exit with error status if trailing data\n"
|
" -a, --trailing-error exit with error status if trailing data\n"
|
||||||
" -b, --member-size=<bytes> set member size limit in bytes\n"
|
" -b, --member-size=<bytes> set member size limit of multimember files\n"
|
||||||
" -c, --stdout write to standard output, keep input files\n"
|
" -c, --stdout write to standard output, keep input files\n"
|
||||||
" -d, --decompress decompress, test compressed file integrity\n"
|
" -d, --decompress decompress, test compressed file integrity\n"
|
||||||
" -f, --force overwrite existing output files\n"
|
" -f, --force overwrite existing output files\n"
|
||||||
|
@ -264,16 +265,16 @@ static void * resize_buffer( void * buf, const unsigned min_size )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct Pretty_print
|
typedef struct Pretty_print
|
||||||
{
|
{
|
||||||
const char * name;
|
const char * name;
|
||||||
char * padded_name;
|
char * padded_name;
|
||||||
const char * stdin_name;
|
const char * stdin_name;
|
||||||
unsigned longest_name;
|
unsigned longest_name;
|
||||||
bool first_post;
|
bool first_post;
|
||||||
};
|
} Pretty_print;
|
||||||
|
|
||||||
static void Pp_init( struct Pretty_print * const pp,
|
static void Pp_init( Pretty_print * const pp,
|
||||||
const char * const filenames[], const int num_filenames )
|
const char * const filenames[], const int num_filenames )
|
||||||
{
|
{
|
||||||
pp->name = 0;
|
pp->name = 0;
|
||||||
|
@ -294,11 +295,10 @@ static void Pp_init( struct Pretty_print * const pp,
|
||||||
if( pp->longest_name == 0 ) pp->longest_name = stdin_name_len;
|
if( pp->longest_name == 0 ) pp->longest_name = stdin_name_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Pp_free( struct Pretty_print * const pp )
|
void Pp_free( Pretty_print * const pp )
|
||||||
{ if( pp->padded_name ) { free( pp->padded_name ); pp->padded_name = 0; } }
|
{ if( pp->padded_name ) { free( pp->padded_name ); pp->padded_name = 0; } }
|
||||||
|
|
||||||
static void Pp_set_name( struct Pretty_print * const pp,
|
static void Pp_set_name( Pretty_print * const pp, const char * const filename )
|
||||||
const char * const filename )
|
|
||||||
{
|
{
|
||||||
unsigned name_len, padded_name_len, i = 0;
|
unsigned name_len, padded_name_len, i = 0;
|
||||||
|
|
||||||
|
@ -316,10 +316,10 @@ static void Pp_set_name( struct Pretty_print * const pp,
|
||||||
pp->first_post = true;
|
pp->first_post = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Pp_reset( struct Pretty_print * const pp )
|
static void Pp_reset( Pretty_print * const pp )
|
||||||
{ if( pp->name && pp->name[0] ) pp->first_post = true; }
|
{ if( pp->name && pp->name[0] ) pp->first_post = true; }
|
||||||
|
|
||||||
static void Pp_show_msg( struct Pretty_print * const pp, const char * const msg )
|
static void Pp_show_msg( Pretty_print * const pp, const char * const msg )
|
||||||
{
|
{
|
||||||
if( verbosity < 0 ) return;
|
if( verbosity < 0 ) return;
|
||||||
if( pp->first_post )
|
if( pp->first_post )
|
||||||
|
@ -339,7 +339,7 @@ static void show_header( const unsigned dictionary_size )
|
||||||
const char * p = "";
|
const char * p = "";
|
||||||
const char * np = " ";
|
const char * np = " ";
|
||||||
unsigned num = dictionary_size;
|
unsigned num = dictionary_size;
|
||||||
bool exact = ( num % factor == 0 );
|
bool exact = num % factor == 0;
|
||||||
|
|
||||||
int i; for( i = 0; i < n && ( num > 9999 || ( exact && num >= factor ) ); ++i )
|
int i; for( i = 0; i < n && ( num > 9999 || ( exact && num >= factor ) ); ++i )
|
||||||
{ num /= factor; if( num % factor != 0 ) exact = false;
|
{ num /= factor; if( num % factor != 0 ) exact = false;
|
||||||
|
@ -406,7 +406,7 @@ static unsigned long long getnum( const char * const arg,
|
||||||
|
|
||||||
if( !errno && tail[0] )
|
if( !errno && tail[0] )
|
||||||
{
|
{
|
||||||
const unsigned factor = ( tail[1] == 'i' ) ? 1024 : 1000;
|
const unsigned factor = (tail[1] == 'i') ? 1024 : 1000;
|
||||||
int exponent = 0; /* 0 = bad multiplier */
|
int exponent = 0; /* 0 = bad multiplier */
|
||||||
int i;
|
int i;
|
||||||
switch( tail[0] )
|
switch( tail[0] )
|
||||||
|
@ -459,7 +459,7 @@ static int get_dict_size( const char * const arg, const char * const option_name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void set_mode( enum Mode * const program_modep, const enum Mode new_mode )
|
static void set_mode( Mode * const program_modep, const Mode new_mode )
|
||||||
{
|
{
|
||||||
if( *program_modep != m_compress && *program_modep != new_mode )
|
if( *program_modep != m_compress && *program_modep != new_mode )
|
||||||
{
|
{
|
||||||
|
@ -524,7 +524,7 @@ static void set_d_outname( const char * const name, const int eindex )
|
||||||
|
|
||||||
|
|
||||||
static int open_instream( const char * const name, struct stat * const in_statsp,
|
static int open_instream( const char * const name, struct stat * const in_statsp,
|
||||||
const enum Mode program_mode, const int eindex,
|
const Mode program_mode, const int eindex,
|
||||||
const bool one_to_one, const bool recompress )
|
const bool one_to_one, const bool recompress )
|
||||||
{
|
{
|
||||||
if( program_mode == m_compress && !recompress && eindex >= 0 )
|
if( program_mode == m_compress && !recompress && eindex >= 0 )
|
||||||
|
@ -541,9 +541,9 @@ static int open_instream( const char * const name, struct stat * const in_statsp
|
||||||
{
|
{
|
||||||
const int i = fstat( infd, in_statsp );
|
const int i = fstat( infd, in_statsp );
|
||||||
const mode_t mode = in_statsp->st_mode;
|
const mode_t mode = in_statsp->st_mode;
|
||||||
const bool can_read = ( i == 0 &&
|
const bool can_read = i == 0 &&
|
||||||
( S_ISBLK( mode ) || S_ISCHR( mode ) ||
|
( S_ISBLK( mode ) || S_ISCHR( mode ) ||
|
||||||
S_ISFIFO( mode ) || S_ISSOCK( mode ) ) );
|
S_ISFIFO( mode ) || S_ISSOCK( mode ) );
|
||||||
if( i != 0 || ( !S_ISREG( mode ) && ( !can_read || one_to_one ) ) )
|
if( i != 0 || ( !S_ISREG( mode ) && ( !can_read || one_to_one ) ) )
|
||||||
{
|
{
|
||||||
if( verbosity >= 0 )
|
if( verbosity >= 0 )
|
||||||
|
@ -609,7 +609,7 @@ static void signal_handler( int sig )
|
||||||
|
|
||||||
|
|
||||||
static bool check_tty_in( const char * const input_filename, const int infd,
|
static bool check_tty_in( const char * const input_filename, const int infd,
|
||||||
const enum Mode program_mode, int * const retval )
|
const Mode program_mode, int * const retval )
|
||||||
{
|
{
|
||||||
if( ( program_mode == m_decompress || program_mode == m_test ) &&
|
if( ( program_mode == m_decompress || program_mode == m_test ) &&
|
||||||
isatty( infd ) ) /* for example /dev/tty */
|
isatty( infd ) ) /* for example /dev/tty */
|
||||||
|
@ -621,7 +621,7 @@ static bool check_tty_in( const char * const input_filename, const int infd,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool check_tty_out( const enum Mode program_mode )
|
static bool check_tty_out( const Mode program_mode )
|
||||||
{
|
{
|
||||||
if( program_mode == m_compress && isatty( outfd ) )
|
if( program_mode == m_compress && isatty( outfd ) )
|
||||||
{ show_file_error( output_filename[0] ?
|
{ show_file_error( output_filename[0] ?
|
||||||
|
@ -717,10 +717,10 @@ static bool next_filename( void )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int do_compress( struct LZ_Encoder * const encoder,
|
static int do_compress( LZ_Encoder * const encoder,
|
||||||
const unsigned long long member_size,
|
const unsigned long long member_size,
|
||||||
const unsigned long long volume_size, const int infd,
|
const unsigned long long volume_size, const int infd,
|
||||||
struct Pretty_print * const pp,
|
Pretty_print * const pp,
|
||||||
const struct stat * const in_statsp )
|
const struct stat * const in_statsp )
|
||||||
{
|
{
|
||||||
unsigned long long partial_volume_size = 0;
|
unsigned long long partial_volume_size = 0;
|
||||||
|
@ -819,11 +819,11 @@ static int do_compress( struct LZ_Encoder * const encoder,
|
||||||
|
|
||||||
static int compress( const unsigned long long member_size,
|
static int compress( const unsigned long long member_size,
|
||||||
const unsigned long long volume_size, const int infd,
|
const unsigned long long volume_size, const int infd,
|
||||||
const struct Lzma_options * const encoder_options,
|
const Lzma_options * const encoder_options,
|
||||||
struct Pretty_print * const pp,
|
Pretty_print * const pp,
|
||||||
const struct stat * const in_statsp )
|
const struct stat * const in_statsp )
|
||||||
{
|
{
|
||||||
struct LZ_Encoder * const encoder =
|
LZ_Encoder * const encoder =
|
||||||
LZ_compress_open( encoder_options->dictionary_size,
|
LZ_compress_open( encoder_options->dictionary_size,
|
||||||
encoder_options->match_len_limit, ( volume_size > 0 ) ?
|
encoder_options->match_len_limit, ( volume_size > 0 ) ?
|
||||||
min( member_size, volume_size ) : member_size );
|
min( member_size, volume_size ) : member_size );
|
||||||
|
@ -844,8 +844,8 @@ static int compress( const unsigned long long member_size,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int do_decompress( struct LZ_Decoder * const decoder, const int infd,
|
static int do_decompress( LZ_Decoder * const decoder, const int infd,
|
||||||
struct Pretty_print * const pp, const bool from_stdin,
|
Pretty_print * const pp, const bool from_stdin,
|
||||||
const bool ignore_trailing, const bool loose_trailing,
|
const bool ignore_trailing, const bool loose_trailing,
|
||||||
const bool testing )
|
const bool testing )
|
||||||
{
|
{
|
||||||
|
@ -853,7 +853,7 @@ static int do_decompress( struct LZ_Decoder * const decoder, const int infd,
|
||||||
uint8_t buffer[buffer_size]; /* read/write buffer */
|
uint8_t buffer[buffer_size]; /* read/write buffer */
|
||||||
unsigned long long total_in = 0; /* to detect library stall */
|
unsigned long long total_in = 0; /* to detect library stall */
|
||||||
bool first_member;
|
bool first_member;
|
||||||
bool empty = false, nonempty = false;
|
bool empty = false, multi = false;
|
||||||
|
|
||||||
for( first_member = true; ; )
|
for( first_member = true; ; )
|
||||||
{
|
{
|
||||||
|
@ -894,10 +894,11 @@ static int do_decompress( struct LZ_Decoder * const decoder, const int infd,
|
||||||
{
|
{
|
||||||
const unsigned long long data_size = LZ_decompress_data_position( decoder );
|
const unsigned long long data_size = LZ_decompress_data_position( decoder );
|
||||||
if( !from_stdin )
|
if( !from_stdin )
|
||||||
{ if( data_size == 0 ) empty = true; else nonempty = true; }
|
{ multi = !first_member; if( data_size == 0 ) empty = true; }
|
||||||
if( verbosity >= 1 )
|
if( verbosity >= 1 )
|
||||||
{
|
{
|
||||||
const unsigned long long member_size = LZ_decompress_member_position( decoder );
|
const unsigned long long member_size =
|
||||||
|
LZ_decompress_member_position( decoder );
|
||||||
if( verbosity >= 2 || ( verbosity == 1 && first_member ) )
|
if( verbosity >= 2 || ( verbosity == 1 && first_member ) )
|
||||||
Pp_show_msg( pp, 0 );
|
Pp_show_msg( pp, 0 );
|
||||||
if( verbosity >= 2 )
|
if( verbosity >= 2 )
|
||||||
|
@ -925,7 +926,7 @@ static int do_decompress( struct LZ_Decoder * const decoder, const int infd,
|
||||||
if( out_size < 0 || ( first_member && out_size == 0 ) )
|
if( out_size < 0 || ( first_member && out_size == 0 ) )
|
||||||
{
|
{
|
||||||
const unsigned long long member_pos = LZ_decompress_member_position( decoder );
|
const unsigned long long member_pos = LZ_decompress_member_position( decoder );
|
||||||
const enum LZ_Errno lz_errno = LZ_decompress_errno( decoder );
|
const LZ_Errno lz_errno = LZ_decompress_errno( decoder );
|
||||||
if( lz_errno == LZ_library_error )
|
if( lz_errno == LZ_library_error )
|
||||||
internal_error( "library error (LZ_decompress_read)." );
|
internal_error( "library error (LZ_decompress_read)." );
|
||||||
if( member_pos <= 6 )
|
if( member_pos <= 6 )
|
||||||
|
@ -988,17 +989,17 @@ static int do_decompress( struct LZ_Decoder * const decoder, const int infd,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if( verbosity == 1 ) fputs( testing ? "ok\n" : "done\n", stderr );
|
if( verbosity == 1 ) fputs( testing ? "ok\n" : "done\n", stderr );
|
||||||
if( empty && nonempty )
|
if( empty && multi )
|
||||||
{ show_file_error( pp->name, "Empty member not allowed.", 0 ); return 2; }
|
{ show_file_error( pp->name, "Empty member not allowed.", 0 ); return 2; }
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int decompress( const int infd, struct Pretty_print * const pp,
|
static int decompress( const int infd, Pretty_print * const pp,
|
||||||
const bool from_stdin, const bool ignore_trailing,
|
const bool from_stdin, const bool ignore_trailing,
|
||||||
const bool loose_trailing, const bool testing )
|
const bool loose_trailing, const bool testing )
|
||||||
{
|
{
|
||||||
struct LZ_Decoder * const decoder = LZ_decompress_open();
|
LZ_Decoder * const decoder = LZ_decompress_open();
|
||||||
int retval;
|
int retval;
|
||||||
|
|
||||||
if( !decoder || LZ_decompress_errno( decoder ) != LZ_ok )
|
if( !decoder || LZ_decompress_errno( decoder ) != LZ_ok )
|
||||||
|
@ -1046,7 +1047,7 @@ int main( const int argc, const char * const argv[] )
|
||||||
{
|
{
|
||||||
/* Mapping from gzip/bzip2 style 0..9 compression levels to the
|
/* Mapping from gzip/bzip2 style 0..9 compression levels to the
|
||||||
corresponding LZMA compression parameters. */
|
corresponding LZMA compression parameters. */
|
||||||
const struct Lzma_options option_mapping[] =
|
const Lzma_options option_mapping[] =
|
||||||
{
|
{
|
||||||
{ 65535, 16 }, /* -0 (65535,16 chooses fast encoder) */
|
{ 65535, 16 }, /* -0 (65535,16 chooses fast encoder) */
|
||||||
{ 1 << 20, 5 }, /* -1 */
|
{ 1 << 20, 5 }, /* -1 */
|
||||||
|
@ -1058,14 +1059,13 @@ int main( const int argc, const char * const argv[] )
|
||||||
{ 1 << 24, 68 }, /* -7 */
|
{ 1 << 24, 68 }, /* -7 */
|
||||||
{ 3 << 23, 132 }, /* -8 */
|
{ 3 << 23, 132 }, /* -8 */
|
||||||
{ 1 << 25, 273 } }; /* -9 */
|
{ 1 << 25, 273 } }; /* -9 */
|
||||||
struct Lzma_options encoder_options = option_mapping[6]; /* default = "-6" */
|
Lzma_options encoder_options = option_mapping[6]; /* default = "-6" */
|
||||||
const unsigned long long max_member_size = 0x0008000000000000ULL; /* 2 PiB */
|
const unsigned long long max_member_size = 0x0008000000000000ULL; /* 2 PiB */
|
||||||
const unsigned long long max_volume_size = 0x4000000000000000ULL; /* 4 EiB */
|
const unsigned long long max_volume_size = 0x4000000000000000ULL; /* 4 EiB */
|
||||||
unsigned long long member_size = max_member_size;
|
unsigned long long member_size = max_member_size;
|
||||||
unsigned long long volume_size = 0;
|
unsigned long long volume_size = 0;
|
||||||
const char * default_output_filename = "";
|
const char * default_output_filename = "";
|
||||||
enum Mode program_mode = m_compress;
|
Mode program_mode = m_compress;
|
||||||
int i;
|
|
||||||
bool force = false;
|
bool force = false;
|
||||||
bool ignore_trailing = true;
|
bool ignore_trailing = true;
|
||||||
bool keep_input_files = false;
|
bool keep_input_files = false;
|
||||||
|
@ -1075,7 +1075,7 @@ int main( const int argc, const char * const argv[] )
|
||||||
if( argc > 0 ) invocation_name = argv[0];
|
if( argc > 0 ) invocation_name = argv[0];
|
||||||
|
|
||||||
enum { opt_chk = 256, opt_lt };
|
enum { opt_chk = 256, opt_lt };
|
||||||
const struct ap_Option options[] =
|
const ap_Option options[] =
|
||||||
{
|
{
|
||||||
{ '0', "fast", ap_no },
|
{ '0', "fast", ap_no },
|
||||||
{ '1', 0, ap_no },
|
{ '1', 0, ap_no },
|
||||||
|
@ -1109,7 +1109,7 @@ int main( const int argc, const char * const argv[] )
|
||||||
{ 0, 0, ap_no } };
|
{ 0, 0, ap_no } };
|
||||||
|
|
||||||
/* static because valgrind complains and memory management in C sucks */
|
/* static because valgrind complains and memory management in C sucks */
|
||||||
static struct Arg_parser parser;
|
static Arg_parser parser;
|
||||||
if( !ap_init( &parser, argc, argv, options, 0 ) )
|
if( !ap_init( &parser, argc, argv, options, 0 ) )
|
||||||
{ show_error( mem_msg, 0, false ); return 1; }
|
{ show_error( mem_msg, 0, false ); return 1; }
|
||||||
if( ap_error( &parser ) ) /* bad option */
|
if( ap_error( &parser ) ) /* bad option */
|
||||||
|
@ -1179,6 +1179,7 @@ int main( const int argc, const char * const argv[] )
|
||||||
filenames = resize_buffer( filenames, num_filenames * sizeof filenames[0] );
|
filenames = resize_buffer( filenames, num_filenames * sizeof filenames[0] );
|
||||||
filenames[0] = "-";
|
filenames[0] = "-";
|
||||||
|
|
||||||
|
int i;
|
||||||
bool filenames_given = false;
|
bool filenames_given = false;
|
||||||
for( i = 0; argind + i < ap_arguments( &parser ); ++i )
|
for( i = 0; argind + i < ap_arguments( &parser ); ++i )
|
||||||
{
|
{
|
||||||
|
@ -1208,7 +1209,7 @@ int main( const int argc, const char * const argv[] )
|
||||||
if( !to_stdout && program_mode != m_test && ( filenames_given || to_file ) )
|
if( !to_stdout && program_mode != m_test && ( filenames_given || to_file ) )
|
||||||
set_signals( signal_handler );
|
set_signals( signal_handler );
|
||||||
|
|
||||||
static struct Pretty_print pp;
|
static Pretty_print pp;
|
||||||
Pp_init( &pp, filenames, num_filenames );
|
Pp_init( &pp, filenames, num_filenames );
|
||||||
|
|
||||||
int failed_tests = 0;
|
int failed_tests = 0;
|
||||||
|
|
|
@ -73,7 +73,7 @@ done
|
||||||
"${LZIP}" -q -o out.lz nx_file
|
"${LZIP}" -q -o out.lz nx_file
|
||||||
[ $? = 1 ] || test_failed $LINENO
|
[ $? = 1 ] || test_failed $LINENO
|
||||||
[ ! -e out.lz ] || test_failed $LINENO
|
[ ! -e out.lz ] || test_failed $LINENO
|
||||||
"${LZIP}" -qf -S100k -o out in in
|
"${LZIP}" -qf -S100k -o out in in # only one file with -o and -S
|
||||||
[ $? = 1 ] || test_failed $LINENO
|
[ $? = 1 ] || test_failed $LINENO
|
||||||
{ [ ! -e out ] && [ ! -e out.lz ] ; } || test_failed $LINENO
|
{ [ ! -e out ] && [ ! -e out.lz ] ; } || test_failed $LINENO
|
||||||
# these are for code coverage
|
# these are for code coverage
|
||||||
|
@ -143,7 +143,6 @@ cmp in out || test_failed $LINENO
|
||||||
printf "to be overwritten" > out || framework_failure
|
printf "to be overwritten" > out || framework_failure
|
||||||
"${LZIP}" -df -o out < "${in_lz}" || test_failed $LINENO
|
"${LZIP}" -df -o out < "${in_lz}" || test_failed $LINENO
|
||||||
cmp in out || test_failed $LINENO
|
cmp in out || test_failed $LINENO
|
||||||
rm -f out || framework_failure
|
|
||||||
"${LZIP}" -d -o ./- "${in_lz}" || test_failed $LINENO
|
"${LZIP}" -d -o ./- "${in_lz}" || test_failed $LINENO
|
||||||
cmp in ./- || test_failed $LINENO
|
cmp in ./- || test_failed $LINENO
|
||||||
rm -f ./- || framework_failure
|
rm -f ./- || framework_failure
|
||||||
|
@ -156,7 +155,7 @@ cp "${in_lz}" anyothername || framework_failure
|
||||||
test_failed $LINENO
|
test_failed $LINENO
|
||||||
cmp in out || test_failed $LINENO
|
cmp in out || test_failed $LINENO
|
||||||
cmp in anyothername.out || test_failed $LINENO
|
cmp in anyothername.out || test_failed $LINENO
|
||||||
rm -f out anyothername.out || framework_failure
|
rm -f anyothername.out || framework_failure
|
||||||
|
|
||||||
"${LZIP}" -tq in "${in_lz}"
|
"${LZIP}" -tq in "${in_lz}"
|
||||||
[ $? = 2 ] || test_failed $LINENO
|
[ $? = 2 ] || test_failed $LINENO
|
||||||
|
@ -222,7 +221,9 @@ touch empty em || framework_failure
|
||||||
"${LZIP}" -0 em || test_failed $LINENO
|
"${LZIP}" -0 em || test_failed $LINENO
|
||||||
"${LZIP}" -dk em.lz || test_failed $LINENO
|
"${LZIP}" -dk em.lz || test_failed $LINENO
|
||||||
cmp empty em || test_failed $LINENO
|
cmp empty em || test_failed $LINENO
|
||||||
rm -f empty em || framework_failure
|
cat em.lz em.lz | "${LZIP}" -t || test_failed $LINENO
|
||||||
|
cat em.lz em.lz | "${LZIP}" -d > em || test_failed $LINENO
|
||||||
|
cmp empty em || test_failed $LINENO
|
||||||
cat em.lz "${in_lz}" | "${LZIP}" -t || test_failed $LINENO
|
cat em.lz "${in_lz}" | "${LZIP}" -t || test_failed $LINENO
|
||||||
cat em.lz "${in_lz}" | "${LZIP}" -d > out || test_failed $LINENO
|
cat em.lz "${in_lz}" | "${LZIP}" -d > out || test_failed $LINENO
|
||||||
cmp in out || test_failed $LINENO
|
cmp in out || test_failed $LINENO
|
||||||
|
@ -352,6 +353,19 @@ rm -f in8 || framework_failure
|
||||||
|
|
||||||
printf "\ntesting bad input..."
|
printf "\ntesting bad input..."
|
||||||
|
|
||||||
|
cat em.lz em.lz > ee.lz || framework_failure
|
||||||
|
"${LZIP}" -t < ee.lz || test_failed $LINENO
|
||||||
|
"${LZIP}" -d < ee.lz > em || test_failed $LINENO
|
||||||
|
cmp empty em || test_failed $LINENO
|
||||||
|
"${LZIP}" -tq ee.lz
|
||||||
|
[ $? = 2 ] || test_failed $LINENO
|
||||||
|
"${LZIP}" -dq ee.lz
|
||||||
|
[ $? = 2 ] || test_failed $LINENO
|
||||||
|
[ ! -e ee ] || test_failed $LINENO
|
||||||
|
"${LZIP}" -cdq ee.lz > em
|
||||||
|
[ $? = 2 ] || test_failed $LINENO
|
||||||
|
cmp empty em || test_failed $LINENO
|
||||||
|
rm -f empty em || framework_failure
|
||||||
cat "${in_lz}" em.lz "${in_lz}" > inein.lz || framework_failure
|
cat "${in_lz}" em.lz "${in_lz}" > inein.lz || framework_failure
|
||||||
"${LZIP}" -t < inein.lz || test_failed $LINENO
|
"${LZIP}" -t < inein.lz || test_failed $LINENO
|
||||||
"${LZIP}" -d < inein.lz > out2 || test_failed $LINENO
|
"${LZIP}" -d < inein.lz > out2 || test_failed $LINENO
|
||||||
|
@ -364,13 +378,13 @@ cmp in2 out2 || test_failed $LINENO
|
||||||
"${LZIP}" -cdq inein.lz > out2
|
"${LZIP}" -cdq inein.lz > out2
|
||||||
[ $? = 2 ] || test_failed $LINENO
|
[ $? = 2 ] || test_failed $LINENO
|
||||||
cmp in2 out2 || test_failed $LINENO
|
cmp in2 out2 || test_failed $LINENO
|
||||||
rm -f out2 inein.lz || framework_failure
|
rm -f out2 inein.lz em.lz || framework_failure
|
||||||
|
|
||||||
headers='LZIp LZiP LZip LzIP LzIp LziP lZIP lZIp lZiP lzIP'
|
headers='LZIp LZiP LZip LzIP LzIp LziP lZIP lZIp lZiP lzIP'
|
||||||
body='\001\014\000\000\101\376\367\377\377\340\000\200\000\215\357\002\322\001\000\000\000\000\000\000\000\045\000\000\000\000\000\000\000'
|
body='\001\014\000\000\101\376\367\377\377\340\000\200\000\215\357\002\322\001\000\000\000\000\000\000\000\045\000\000\000\000\000\000\000'
|
||||||
cp "${in_lz}" int.lz || framework_failure
|
cp "${in_lz}" int.lz || framework_failure
|
||||||
printf "LZIP${body}" >> int.lz || framework_failure
|
printf "LZIP${body}" >> int.lz || framework_failure
|
||||||
if "${LZIP}" -tq int.lz ; then
|
if "${LZIP}" -t int.lz ; then
|
||||||
for header in ${headers} ; do
|
for header in ${headers} ; do
|
||||||
printf "${header}${body}" > int.lz || framework_failure
|
printf "${header}${body}" > int.lz || framework_failure
|
||||||
"${LZIP}" -tq int.lz # first member
|
"${LZIP}" -tq int.lz # first member
|
||||||
|
@ -407,7 +421,7 @@ if "${LZIP}" -tq int.lz ; then
|
||||||
[ $? = 2 ] || test_failed $LINENO ${header}
|
[ $? = 2 ] || test_failed $LINENO ${header}
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
printf "\nwarning: skipping header test: 'printf' does not work on your system."
|
printf "warning: skipping header test: 'printf' does not work on your system."
|
||||||
fi
|
fi
|
||||||
rm -f int.lz || framework_failure
|
rm -f int.lz || framework_failure
|
||||||
|
|
||||||
|
@ -425,12 +439,12 @@ for i in fox_bcrc.lz fox_crc0.lz fox_das46.lz fox_mes81.lz ; do
|
||||||
[ $? = 2 ] || test_failed $LINENO $i
|
[ $? = 2 ] || test_failed $LINENO $i
|
||||||
cmp fox out || test_failed $LINENO $i
|
cmp fox out || test_failed $LINENO $i
|
||||||
done
|
done
|
||||||
rm -f fox out || framework_failure
|
rm -f fox || framework_failure
|
||||||
|
|
||||||
cat "${in_lz}" "${in_lz}" > in2.lz || framework_failure
|
cat "${in_lz}" "${in_lz}" > in2.lz || framework_failure
|
||||||
cat "${in_lz}" "${in_lz}" "${in_lz}" > in3.lz || framework_failure
|
cat "${in_lz}" "${in_lz}" "${in_lz}" > in3.lz || framework_failure
|
||||||
if dd if=in3.lz of=trunc.lz bs=14682 count=1 2> /dev/null &&
|
if dd if=in3.lz of=trunc.lz bs=14682 count=1 2> /dev/null &&
|
||||||
[ -e trunc.lz ] && cmp in2.lz trunc.lz > /dev/null 2>&1 ; then
|
[ -e trunc.lz ] && cmp in2.lz trunc.lz ; then
|
||||||
for i in 6 20 14664 14683 14684 14685 14686 14687 14688 ; do
|
for i in 6 20 14664 14683 14684 14685 14686 14687 14688 ; do
|
||||||
dd if=in3.lz of=trunc.lz bs=$i count=1 2> /dev/null
|
dd if=in3.lz of=trunc.lz bs=$i count=1 2> /dev/null
|
||||||
"${LZIP}" -tq trunc.lz
|
"${LZIP}" -tq trunc.lz
|
||||||
|
@ -443,7 +457,7 @@ if dd if=in3.lz of=trunc.lz bs=14682 count=1 2> /dev/null &&
|
||||||
[ $? = 2 ] || test_failed $LINENO $i
|
[ $? = 2 ] || test_failed $LINENO $i
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
printf "\nwarning: skipping truncation test: 'dd' does not work on your system."
|
printf "warning: skipping truncation test: 'dd' does not work on your system."
|
||||||
fi
|
fi
|
||||||
rm -f in2.lz in3.lz trunc.lz || framework_failure
|
rm -f in2.lz in3.lz trunc.lz || framework_failure
|
||||||
|
|
||||||
|
@ -454,10 +468,12 @@ cat "${in_lz}" >> ingin.lz || framework_failure
|
||||||
[ $? = 2 ] || test_failed $LINENO
|
[ $? = 2 ] || test_failed $LINENO
|
||||||
"${LZIP}" -atq < ingin.lz
|
"${LZIP}" -atq < ingin.lz
|
||||||
[ $? = 2 ] || test_failed $LINENO
|
[ $? = 2 ] || test_failed $LINENO
|
||||||
"${LZIP}" -acdq ingin.lz > /dev/null
|
"${LZIP}" -acdq ingin.lz > out
|
||||||
[ $? = 2 ] || test_failed $LINENO
|
[ $? = 2 ] || test_failed $LINENO
|
||||||
"${LZIP}" -adq < ingin.lz > /dev/null
|
cmp in out || test_failed $LINENO
|
||||||
|
"${LZIP}" -adq < ingin.lz > out
|
||||||
[ $? = 2 ] || test_failed $LINENO
|
[ $? = 2 ] || test_failed $LINENO
|
||||||
|
cmp in out || test_failed $LINENO
|
||||||
"${LZIP}" -t ingin.lz || test_failed $LINENO
|
"${LZIP}" -t ingin.lz || test_failed $LINENO
|
||||||
"${LZIP}" -t < ingin.lz || test_failed $LINENO
|
"${LZIP}" -t < ingin.lz || test_failed $LINENO
|
||||||
"${LZIP}" -dk ingin.lz || test_failed $LINENO
|
"${LZIP}" -dk ingin.lz || test_failed $LINENO
|
||||||
|
|
Loading…
Add table
Reference in a new issue