Adding upstream version 0.7.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
64ab85d0eb
commit
2c6d5ecc7e
8 changed files with 65 additions and 59 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
2015-07-07 Antonio Diaz Diaz <antonio@gnu.org>
|
||||||
|
|
||||||
|
* Version 0.7 released.
|
||||||
|
* Minor changes.
|
||||||
|
|
||||||
2014-08-25 Antonio Diaz Diaz <antonio@gnu.org>
|
2014-08-25 Antonio Diaz Diaz <antonio@gnu.org>
|
||||||
|
|
||||||
* Version 0.6 released.
|
* Version 0.6 released.
|
||||||
|
@ -28,7 +33,7 @@
|
||||||
* Version 0.1 released.
|
* Version 0.1 released.
|
||||||
|
|
||||||
|
|
||||||
Copyright (C) 2013, 2014 Antonio Diaz Diaz.
|
Copyright (C) 2013-2015 Antonio Diaz Diaz.
|
||||||
|
|
||||||
This file is a collection of facts, and thus it is not copyrightable,
|
This file is a collection of facts, and thus it is not copyrightable,
|
||||||
but just in case, you have unlimited permission to copy, distribute and
|
but just in case, you have unlimited permission to copy, distribute and
|
||||||
|
|
8
INSTALL
8
INSTALL
|
@ -1,7 +1,7 @@
|
||||||
Requirements
|
Requirements
|
||||||
------------
|
------------
|
||||||
You will need a C++ compiler.
|
You will need a C++ compiler.
|
||||||
I use gcc 4.9.1 and 3.3.6, but the code should compile with any
|
I use gcc 4.9.1 and 4.1.2, but the code should compile with any
|
||||||
standards compliant compiler.
|
standards compliant compiler.
|
||||||
Gcc is available at http://gcc.gnu.org.
|
Gcc is available at http://gcc.gnu.org.
|
||||||
|
|
||||||
|
@ -32,10 +32,6 @@ the main archive.
|
||||||
5. Type 'make install' to install the program and any data files and
|
5. Type 'make install' to install the program and any data files and
|
||||||
documentation.
|
documentation.
|
||||||
|
|
||||||
You can install only the program, the info manual or the man page by
|
|
||||||
typing 'make install-bin', 'make install-info' or 'make install-man'
|
|
||||||
respectively.
|
|
||||||
|
|
||||||
|
|
||||||
Another way
|
Another way
|
||||||
-----------
|
-----------
|
||||||
|
@ -54,7 +50,7 @@ After running 'configure', you can run 'make' and 'make install' as
|
||||||
explained above.
|
explained above.
|
||||||
|
|
||||||
|
|
||||||
Copyright (C) 2013, 2014 Antonio Diaz Diaz.
|
Copyright (C) 2013-2015 Antonio Diaz Diaz.
|
||||||
|
|
||||||
This file is free documentation: you have unlimited permission to copy,
|
This file is free documentation: you have unlimited permission to copy,
|
||||||
distribute and modify it.
|
distribute and modify it.
|
||||||
|
|
36
Makefile.in
36
Makefile.in
|
@ -9,20 +9,19 @@ SHELL = /bin/sh
|
||||||
objs = lzd.o
|
objs = lzd.o
|
||||||
|
|
||||||
|
|
||||||
.PHONY : all install install-bin install-info install-man install-strip \
|
.PHONY : all install install-bin install-info install-man \
|
||||||
|
install-strip install-compress install-strip-compress \
|
||||||
|
install-bin-strip install-info-compress install-man-compress \
|
||||||
uninstall uninstall-bin uninstall-info uninstall-man \
|
uninstall uninstall-bin uninstall-info uninstall-man \
|
||||||
doc info man check dist clean distclean
|
doc info man check dist clean distclean
|
||||||
|
|
||||||
all : $(progname)
|
all : $(progname)
|
||||||
|
|
||||||
$(progname) : $(objs)
|
$(progname) : $(objs)
|
||||||
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $(objs)
|
$(CXX) $(LDFLAGS) $(CXXFLAGS) -o $@ $(objs)
|
||||||
|
|
||||||
$(progname)_profiled : $(objs)
|
|
||||||
$(CXX) $(CXXFLAGS) $(LDFLAGS) -pg -o $@ $(objs)
|
|
||||||
|
|
||||||
%.o : %.cc
|
%.o : %.cc
|
||||||
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -DPROGVERSION=\"$(pkgversion)\" -c -o $@ $<
|
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -DPROGVERSION=\"$(pkgversion)\" -c -o $@ $<
|
||||||
|
|
||||||
$(objs) : Makefile
|
$(objs) : Makefile
|
||||||
|
|
||||||
|
@ -37,7 +36,7 @@ $(VPATH)/doc/$(pkgname).info : $(VPATH)/doc/$(pkgname).texi
|
||||||
man : $(VPATH)/doc/$(progname).1
|
man : $(VPATH)/doc/$(progname).1
|
||||||
|
|
||||||
$(VPATH)/doc/$(progname).1 : $(progname)
|
$(VPATH)/doc/$(progname).1 : $(progname)
|
||||||
help2man -n 'educational decompressor for lzip files' \
|
help2man -n 'educational decompressor for the lzip format' \
|
||||||
-o $@ --no-info ./$(progname)
|
-o $@ --no-info ./$(progname)
|
||||||
|
|
||||||
Makefile : $(VPATH)/configure $(VPATH)/Makefile.in
|
Makefile : $(VPATH)/configure $(VPATH)/Makefile.in
|
||||||
|
@ -47,34 +46,45 @@ check : all
|
||||||
@$(VPATH)/testsuite/check.sh $(VPATH)/testsuite $(pkgversion)
|
@$(VPATH)/testsuite/check.sh $(VPATH)/testsuite $(pkgversion)
|
||||||
|
|
||||||
install : install-bin
|
install : install-bin
|
||||||
|
install-strip : install-bin-strip
|
||||||
|
install-compress : install-bin
|
||||||
|
install-strip-compress : install-bin-strip
|
||||||
|
|
||||||
install-bin : all
|
install-bin : all
|
||||||
if [ ! -d "$(DESTDIR)$(bindir)" ] ; then $(INSTALL_DIR) "$(DESTDIR)$(bindir)" ; fi
|
if [ ! -d "$(DESTDIR)$(bindir)" ] ; then $(INSTALL_DIR) "$(DESTDIR)$(bindir)" ; fi
|
||||||
$(INSTALL_PROGRAM) ./$(progname) "$(DESTDIR)$(bindir)/$(progname)"
|
$(INSTALL_PROGRAM) ./$(progname) "$(DESTDIR)$(bindir)/$(progname)"
|
||||||
|
|
||||||
|
install-bin-strip : all
|
||||||
|
$(MAKE) INSTALL_PROGRAM='$(INSTALL_PROGRAM) -s' install-bin
|
||||||
|
|
||||||
install-info :
|
install-info :
|
||||||
if [ ! -d "$(DESTDIR)$(infodir)" ] ; then $(INSTALL_DIR) "$(DESTDIR)$(infodir)" ; fi
|
if [ ! -d "$(DESTDIR)$(infodir)" ] ; then $(INSTALL_DIR) "$(DESTDIR)$(infodir)" ; fi
|
||||||
|
-rm -f "$(DESTDIR)$(infodir)/$(pkgname).info"*
|
||||||
$(INSTALL_DATA) $(VPATH)/doc/$(pkgname).info "$(DESTDIR)$(infodir)/$(pkgname).info"
|
$(INSTALL_DATA) $(VPATH)/doc/$(pkgname).info "$(DESTDIR)$(infodir)/$(pkgname).info"
|
||||||
-install-info --info-dir="$(DESTDIR)$(infodir)" "$(DESTDIR)$(infodir)/$(pkgname).info"
|
-install-info --info-dir="$(DESTDIR)$(infodir)" "$(DESTDIR)$(infodir)/$(pkgname).info"
|
||||||
|
|
||||||
|
install-info-compress : install-info
|
||||||
|
lzip -v -9 "$(DESTDIR)$(infodir)/$(pkgname).info"
|
||||||
|
|
||||||
install-man :
|
install-man :
|
||||||
if [ ! -d "$(DESTDIR)$(mandir)/man1" ] ; then $(INSTALL_DIR) "$(DESTDIR)$(mandir)/man1" ; fi
|
if [ ! -d "$(DESTDIR)$(mandir)/man1" ] ; then $(INSTALL_DIR) "$(DESTDIR)$(mandir)/man1" ; fi
|
||||||
|
-rm -f "$(DESTDIR)$(mandir)/man1/$(progname).1"*
|
||||||
$(INSTALL_DATA) $(VPATH)/doc/$(progname).1 "$(DESTDIR)$(mandir)/man1/$(progname).1"
|
$(INSTALL_DATA) $(VPATH)/doc/$(progname).1 "$(DESTDIR)$(mandir)/man1/$(progname).1"
|
||||||
|
|
||||||
install-strip : all
|
install-man-compress : install-man
|
||||||
$(MAKE) INSTALL_PROGRAM='$(INSTALL_PROGRAM) -s' install
|
lzip -v -9 "$(DESTDIR)$(mandir)/man1/$(progname).1"
|
||||||
|
|
||||||
uninstall : uninstall-bin uninstall-info uninstall-man
|
uninstall : uninstall-bin
|
||||||
|
|
||||||
uninstall-bin :
|
uninstall-bin :
|
||||||
-rm -f "$(DESTDIR)$(bindir)/$(progname)"
|
-rm -f "$(DESTDIR)$(bindir)/$(progname)"
|
||||||
|
|
||||||
uninstall-info :
|
uninstall-info :
|
||||||
-install-info --info-dir="$(DESTDIR)$(infodir)" --remove "$(DESTDIR)$(infodir)/$(pkgname).info"
|
-install-info --info-dir="$(DESTDIR)$(infodir)" --remove "$(DESTDIR)$(infodir)/$(pkgname).info"
|
||||||
-rm -f "$(DESTDIR)$(infodir)/$(pkgname).info"
|
-rm -f "$(DESTDIR)$(infodir)/$(pkgname).info"*
|
||||||
|
|
||||||
uninstall-man :
|
uninstall-man :
|
||||||
-rm -f "$(DESTDIR)$(mandir)/man1/$(progname).1"
|
-rm -f "$(DESTDIR)$(mandir)/man1/$(progname).1"*
|
||||||
|
|
||||||
dist : doc
|
dist : doc
|
||||||
ln -sf $(VPATH) $(DISTNAME)
|
ln -sf $(VPATH) $(DISTNAME)
|
||||||
|
@ -94,7 +104,7 @@ dist : doc
|
||||||
lzip -v -9 $(DISTNAME).tar
|
lzip -v -9 $(DISTNAME).tar
|
||||||
|
|
||||||
clean :
|
clean :
|
||||||
-rm -f $(progname) $(progname)_profiled $(objs)
|
-rm -f $(progname) $(objs)
|
||||||
|
|
||||||
distclean : clean
|
distclean : clean
|
||||||
-rm -f Makefile config.status *.tar *.tar.lz
|
-rm -f Makefile config.status *.tar *.tar.lz
|
||||||
|
|
2
NEWS
2
NEWS
|
@ -1,3 +1,3 @@
|
||||||
Changes in version 0.6:
|
Changes in version 0.7:
|
||||||
|
|
||||||
Minor changes.
|
Minor changes.
|
||||||
|
|
13
README
13
README
|
@ -1,6 +1,6 @@
|
||||||
Description
|
Description
|
||||||
|
|
||||||
Lzd is a simplified decompressor for lzip files with an educational
|
Lzd is a simplified decompressor for the lzip format with an educational
|
||||||
purpose. Studying its source is a good first step to understand how lzip
|
purpose. Studying its source is a good first step to understand how lzip
|
||||||
works. It is not safe to use lzd for any real work.
|
works. It is not safe to use lzd for any real work.
|
||||||
|
|
||||||
|
@ -13,8 +13,9 @@ correctly decompress the concatenation of two or more compressed files.
|
||||||
The result is the concatenation of the corresponding decompressed data.
|
The result is the concatenation of the corresponding decompressed data.
|
||||||
Integrity of such concatenated compressed input is also verified.
|
Integrity of such concatenated compressed input is also verified.
|
||||||
|
|
||||||
The lzip file format is designed for long-term data archiving, taking
|
The lzip file format is designed for data sharing and long-term
|
||||||
into account both data integrity and decoder availability:
|
archiving, taking into account both data integrity and decoder
|
||||||
|
availability:
|
||||||
|
|
||||||
* The lzip format provides very safe integrity checking and some data
|
* The lzip format provides very safe integrity checking and some data
|
||||||
recovery means. The lziprecover program can repair bit-flip errors
|
recovery means. The lziprecover program can repair bit-flip errors
|
||||||
|
@ -29,8 +30,8 @@ into account both data integrity and decoder availability:
|
||||||
extract the data from a lzip file long after quantum computers
|
extract the data from a lzip file long after quantum computers
|
||||||
eventually render LZMA obsolete.
|
eventually render LZMA obsolete.
|
||||||
|
|
||||||
* Additionally lzip is copylefted, which guarantees that it will
|
* Additionally the lzip reference implementation is copylefted, which
|
||||||
remain free forever.
|
guarantees that it will remain free forever.
|
||||||
|
|
||||||
A nice feature of the lzip format is that a corrupt byte is easier to
|
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
|
repair the nearer it is from the beginning of the file. Therefore, with
|
||||||
|
@ -44,7 +45,7 @@ range encoding), and Igor Pavlov (for putting all the above together in
|
||||||
LZMA).
|
LZMA).
|
||||||
|
|
||||||
|
|
||||||
Copyright (C) 2013, 2014 Antonio Diaz Diaz.
|
Copyright (C) 2013-2015 Antonio Diaz Diaz.
|
||||||
|
|
||||||
This file is free documentation: you have unlimited permission to copy,
|
This file is free documentation: you have unlimited permission to copy,
|
||||||
distribute and modify it.
|
distribute and modify it.
|
||||||
|
|
10
configure
vendored
10
configure
vendored
|
@ -1,12 +1,12 @@
|
||||||
#! /bin/sh
|
#! /bin/sh
|
||||||
# configure script for Lzd - Educational decompressor for lzip files
|
# configure script for Lzd - Educational decompressor for the lzip format
|
||||||
# Copyright (C) 2013, 2014 Antonio Diaz Diaz.
|
# Copyright (C) 2013-2015 Antonio Diaz Diaz.
|
||||||
#
|
#
|
||||||
# This configure script is free software: you have unlimited permission
|
# This configure script is free software: you have unlimited permission
|
||||||
# to copy, distribute and modify it.
|
# to copy, distribute and modify it.
|
||||||
|
|
||||||
pkgname=lzd
|
pkgname=lzd
|
||||||
pkgversion=0.6
|
pkgversion=0.7
|
||||||
progname=lzd
|
progname=lzd
|
||||||
srctrigger=lzd.cc
|
srctrigger=lzd.cc
|
||||||
|
|
||||||
|
@ -164,8 +164,8 @@ echo "CXXFLAGS = ${CXXFLAGS}"
|
||||||
echo "LDFLAGS = ${LDFLAGS}"
|
echo "LDFLAGS = ${LDFLAGS}"
|
||||||
rm -f Makefile
|
rm -f Makefile
|
||||||
cat > Makefile << EOF
|
cat > Makefile << EOF
|
||||||
# Makefile for Lzd - Educational decompressor for lzip files
|
# Makefile for Lzd - Educational decompressor for the lzip format
|
||||||
# Copyright (C) 2013, 2014 Antonio Diaz Diaz.
|
# Copyright (C) 2013-2015 Antonio Diaz Diaz.
|
||||||
# This file was generated automatically by configure. Do not edit.
|
# This file was generated automatically by configure. Do not edit.
|
||||||
#
|
#
|
||||||
# This Makefile is free software: you have unlimited permission
|
# This Makefile is free software: you have unlimited permission
|
||||||
|
|
46
lzd.cc
46
lzd.cc
|
@ -1,5 +1,5 @@
|
||||||
/* Lzd - Educational decompressor for lzip files
|
/* Lzd - Educational decompressor for the lzip format
|
||||||
Copyright (C) 2013, 2014 Antonio Diaz Diaz.
|
Copyright (C) 2013-2015 Antonio Diaz Diaz.
|
||||||
|
|
||||||
This program is free software: you have unlimited permission
|
This program is free software: you have unlimited permission
|
||||||
to copy, distribute and modify it.
|
to copy, distribute and modify it.
|
||||||
|
@ -241,7 +241,7 @@ class LZ_decoder
|
||||||
|
|
||||||
void flush_data();
|
void flush_data();
|
||||||
|
|
||||||
uint8_t get_byte( const unsigned distance ) const
|
uint8_t peek( const unsigned distance ) const
|
||||||
{
|
{
|
||||||
unsigned i = pos - distance - 1;
|
unsigned i = pos - distance - 1;
|
||||||
if( pos <= distance ) i += dictionary_size;
|
if( pos <= distance ) i += dictionary_size;
|
||||||
|
@ -255,7 +255,7 @@ class LZ_decoder
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
LZ_decoder( const unsigned dict_size )
|
explicit LZ_decoder( const unsigned dict_size )
|
||||||
:
|
:
|
||||||
partial_data_pos( 0 ),
|
partial_data_pos( 0 ),
|
||||||
dictionary_size( dict_size ),
|
dictionary_size( dict_size ),
|
||||||
|
@ -282,7 +282,7 @@ void LZ_decoder::flush_data()
|
||||||
crc32.update_buf( crc_, buffer + stream_pos, size );
|
crc32.update_buf( crc_, buffer + stream_pos, size );
|
||||||
errno = 0;
|
errno = 0;
|
||||||
if( std::fwrite( buffer + stream_pos, 1, size, stdout ) != size )
|
if( std::fwrite( buffer + stream_pos, 1, size, stdout ) != size )
|
||||||
{ std::fprintf( stderr, "Write error: %s.\n", std::strerror( errno ) );
|
{ std::fprintf( stderr, "Write error: %s\n", std::strerror( errno ) );
|
||||||
std::exit( 1 ); }
|
std::exit( 1 ); }
|
||||||
if( pos >= dictionary_size ) { partial_data_pos += pos; pos = 0; }
|
if( pos >= dictionary_size ) { partial_data_pos += pos; pos = 0; }
|
||||||
stream_pos = pos;
|
stream_pos = pos;
|
||||||
|
@ -315,16 +315,16 @@ bool LZ_decoder::decode_member() // Returns false if error
|
||||||
const int pos_state = data_position() & pos_state_mask;
|
const int pos_state = data_position() & pos_state_mask;
|
||||||
if( rdec.decode_bit( bm_match[state()][pos_state] ) == 0 ) // 1st bit
|
if( rdec.decode_bit( bm_match[state()][pos_state] ) == 0 ) // 1st bit
|
||||||
{
|
{
|
||||||
const uint8_t prev_byte = get_byte( 0 );
|
const uint8_t prev_byte = peek( 0 );
|
||||||
const int literal_state = prev_byte >> ( 8 - literal_context_bits );
|
const int literal_state = prev_byte >> ( 8 - literal_context_bits );
|
||||||
Bit_model * const bm = bm_literal[literal_state];
|
Bit_model * const bm = bm_literal[literal_state];
|
||||||
if( state.is_char() )
|
if( state.is_char() )
|
||||||
put_byte( rdec.decode_tree( bm, 8 ) );
|
put_byte( rdec.decode_tree( bm, 8 ) );
|
||||||
else
|
else
|
||||||
put_byte( rdec.decode_matched( bm, get_byte( rep0 ) ) );
|
put_byte( rdec.decode_matched( bm, peek( rep0 ) ) );
|
||||||
state.set_char();
|
state.set_char();
|
||||||
}
|
}
|
||||||
else
|
else // match or repeated match
|
||||||
{
|
{
|
||||||
int len;
|
int len;
|
||||||
if( rdec.decode_bit( bm_rep[state()] ) != 0 ) // 2nd bit
|
if( rdec.decode_bit( bm_rep[state()] ) != 0 ) // 2nd bit
|
||||||
|
@ -348,12 +348,12 @@ bool LZ_decoder::decode_member() // Returns false if error
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if( rdec.decode_bit( bm_len[state()][pos_state] ) == 0 ) // 4th bit
|
if( rdec.decode_bit( bm_len[state()][pos_state] ) == 0 ) // 4th bit
|
||||||
{ state.set_short_rep(); put_byte( get_byte( rep0 ) ); continue; }
|
{ state.set_short_rep(); put_byte( peek( rep0 ) ); continue; }
|
||||||
}
|
}
|
||||||
state.set_rep();
|
state.set_rep();
|
||||||
len = min_match_len + rdec.decode_len( rep_len_model, pos_state );
|
len = min_match_len + rdec.decode_len( rep_len_model, pos_state );
|
||||||
}
|
}
|
||||||
else
|
else // match
|
||||||
{
|
{
|
||||||
rep3 = rep2; rep2 = rep1; rep1 = rep0;
|
rep3 = rep2; rep2 = rep1; rep1 = rep0;
|
||||||
len = min_match_len + rdec.decode_len( match_len_model, pos_state );
|
len = min_match_len + rdec.decode_len( match_len_model, pos_state );
|
||||||
|
@ -372,7 +372,7 @@ bool LZ_decoder::decode_member() // Returns false if error
|
||||||
{
|
{
|
||||||
rep0 += rdec.decode( direct_bits - dis_align_bits ) << dis_align_bits;
|
rep0 += rdec.decode( direct_bits - dis_align_bits ) << dis_align_bits;
|
||||||
rep0 += rdec.decode_tree_reversed( bm_align, dis_align_bits );
|
rep0 += rdec.decode_tree_reversed( bm_align, dis_align_bits );
|
||||||
if( rep0 == 0xFFFFFFFFU ) // Marker found
|
if( rep0 == 0xFFFFFFFFU ) // marker found
|
||||||
{
|
{
|
||||||
flush_data();
|
flush_data();
|
||||||
return ( len == min_match_len ); // End Of Stream marker
|
return ( len == min_match_len ); // End Of Stream marker
|
||||||
|
@ -383,7 +383,7 @@ bool LZ_decoder::decode_member() // Returns false if error
|
||||||
if( rep0 >= dictionary_size || rep0 >= data_position() )
|
if( rep0 >= dictionary_size || rep0 >= data_position() )
|
||||||
{ flush_data(); return false; }
|
{ flush_data(); return false; }
|
||||||
}
|
}
|
||||||
for( int i = 0; i < len; ++i ) put_byte( get_byte( rep0 ) );
|
for( int i = 0; i < len; ++i ) put_byte( peek( rep0 ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
flush_data();
|
flush_data();
|
||||||
|
@ -395,14 +395,14 @@ int main( const int argc, const char * const argv[] )
|
||||||
{
|
{
|
||||||
if( argc > 1 )
|
if( argc > 1 )
|
||||||
{
|
{
|
||||||
std::printf( "Lzd %s - Educational decompressor for lzip files.\n",
|
std::printf( "Lzd %s - Educational decompressor for the lzip format.\n",
|
||||||
PROGVERSION );
|
PROGVERSION );
|
||||||
std::printf( "Study the source to learn how a lzip decompressor works.\n"
|
std::printf( "Study the source to learn how a lzip decompressor works.\n"
|
||||||
"See the lzip manual for an explanation of the code.\n"
|
"See the lzip manual for an explanation of the code.\n"
|
||||||
"It is not safe to use lzd for any real work.\n"
|
"It is not safe to use lzd for any real work.\n"
|
||||||
"\nUsage: %s < file.lz > file\n", argv[0] );
|
"\nUsage: %s < file.lz > file\n", argv[0] );
|
||||||
std::printf( "Lzd decompresses from standard input to standard output.\n"
|
std::printf( "Lzd decompresses from standard input to standard output.\n"
|
||||||
"\nCopyright (C) 2014 Antonio Diaz Diaz.\n"
|
"\nCopyright (C) 2015 Antonio Diaz Diaz.\n"
|
||||||
"This is free software: you are free to change and redistribute it.\n"
|
"This is free software: you are free to change and redistribute it.\n"
|
||||||
"There is NO WARRANTY, to the extent permitted by law.\n"
|
"There is NO WARRANTY, to the extent permitted by law.\n"
|
||||||
"Report bugs to lzip-bug@nongnu.org\n"
|
"Report bugs to lzip-bug@nongnu.org\n"
|
||||||
|
@ -419,28 +419,22 @@ int main( const int argc, const char * const argv[] )
|
||||||
{
|
{
|
||||||
File_header header;
|
File_header header;
|
||||||
for( int i = 0; i < 6; ++i ) header[i] = std::getc( stdin );
|
for( int i = 0; i < 6; ++i ) header[i] = std::getc( stdin );
|
||||||
if( std::feof( stdin ) || std::memcmp( header, "LZIP", 4 ) != 0 )
|
if( std::feof( stdin ) || std::memcmp( header, "LZIP\x01", 5 ) != 0 )
|
||||||
{
|
{
|
||||||
if( first_member )
|
if( first_member )
|
||||||
{ std::fprintf( stderr, "Bad magic number (file not in lzip format)\n" );
|
{ std::fputs( "Bad magic number (file not in lzip format).\n", stderr );
|
||||||
return 2; }
|
return 2; }
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if( header[4] != 1 )
|
|
||||||
{
|
|
||||||
std::fprintf( stderr, "Version %d member format not supported.\n",
|
|
||||||
header[4] );
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
unsigned dict_size = 1 << ( header[5] & 0x1F );
|
unsigned dict_size = 1 << ( header[5] & 0x1F );
|
||||||
dict_size -= ( dict_size / 16 ) * ( ( header[5] >> 5 ) & 7 );
|
dict_size -= ( dict_size / 16 ) * ( ( header[5] >> 5 ) & 7 );
|
||||||
if( dict_size < min_dictionary_size || dict_size > max_dictionary_size )
|
if( dict_size < min_dictionary_size || dict_size > max_dictionary_size )
|
||||||
{ std::fprintf( stderr, "Invalid dictionary size in member header\n" );
|
{ std::fputs( "Invalid dictionary size in member header.\n", stderr );
|
||||||
return 2; }
|
return 2; }
|
||||||
|
|
||||||
LZ_decoder decoder( dict_size );
|
LZ_decoder decoder( dict_size );
|
||||||
if( !decoder.decode_member() )
|
if( !decoder.decode_member() )
|
||||||
{ std::fprintf( stderr, "Data error\n" ); return 2; }
|
{ std::fputs( "Data error\n", stderr ); return 2; }
|
||||||
|
|
||||||
File_trailer trailer;
|
File_trailer trailer;
|
||||||
for( int i = 0; i < 20; ++i ) trailer[i] = std::getc( stdin );
|
for( int i = 0; i < 20; ++i ) trailer[i] = std::getc( stdin );
|
||||||
|
@ -449,11 +443,11 @@ int main( const int argc, const char * const argv[] )
|
||||||
unsigned long long data_size = 0;
|
unsigned long long data_size = 0;
|
||||||
for( int i = 11; i >= 4; --i ) { data_size <<= 8; data_size += trailer[i]; }
|
for( int i = 11; i >= 4; --i ) { data_size <<= 8; data_size += trailer[i]; }
|
||||||
if( crc != decoder.crc() || data_size != decoder.data_position() )
|
if( crc != decoder.crc() || data_size != decoder.data_position() )
|
||||||
{ std::fprintf( stderr, "CRC error\n" ); return 2; }
|
{ std::fputs( "CRC error\n", stderr ); return 2; }
|
||||||
}
|
}
|
||||||
|
|
||||||
if( std::fclose( stdout ) != 0 )
|
if( std::fclose( stdout ) != 0 )
|
||||||
{ std::fprintf( stderr, "Can't close stdout: %s.\n", std::strerror( errno ) );
|
{ std::fprintf( stderr, "Can't close stdout: %s\n", std::strerror( errno ) );
|
||||||
return 1; }
|
return 1; }
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#! /bin/sh
|
#! /bin/sh
|
||||||
# check script for Lzd - Educational decompressor for lzip files
|
# check script for Lzd - Educational decompressor for lzip files
|
||||||
# Copyright (C) 2013, 2014 Antonio Diaz Diaz.
|
# Copyright (C) 2013-2015 Antonio Diaz Diaz.
|
||||||
#
|
#
|
||||||
# This script is free software: you have unlimited permission
|
# This script is free software: you have unlimited permission
|
||||||
# to copy, distribute and modify it.
|
# to copy, distribute and modify it.
|
||||||
|
|
Loading…
Add table
Reference in a new issue