1
0
Fork 0

Merging upstream version 1.6~rc1.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-02-23 19:20:27 +01:00
parent 4d14b4402a
commit b60eef59a3
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
18 changed files with 954 additions and 870 deletions

View file

@ -1,3 +1,4 @@
Pdlzip was written by Antonio Diaz Diaz. Pdlzip was written by Antonio Diaz Diaz.
Pdlzip includes public domain code from the LZMA SDK written by Igor Pavlov. Pdlzip includes public domain (de)compression code from the LZMA SDK
(Software Development Kit) written by Igor Pavlov.

View file

@ -1,3 +1,9 @@
2015-04-09 Antonio Diaz Diaz <antonio@gnu.org>
* Version 1.6-rc1 released.
* main.c (close_and_set_permissions): Behave like 'cp -p'.
* Makefile.in: Added new targets 'install*-compress'.
2013-09-14 Antonio Diaz Diaz <antonio@gnu.org> 2013-09-14 Antonio Diaz Diaz <antonio@gnu.org>
* Version 1.5 released. * Version 1.5 released.
@ -51,7 +57,7 @@
* Using LZMA SDK 9.10 (public domain) from Igor Pavlov. * Using LZMA SDK 9.10 (public domain) from Igor Pavlov.
Copyright (C) 2010, 2011, 2012, 2013 Antonio Diaz Diaz. Copyright (C) 2010-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

25
INSTALL
View file

@ -1,7 +1,7 @@
Requirements Requirements
------------ ------------
You will need a C compiler. You will need a C compiler.
I use gcc 4.8.1 and 3.3.6, but the code should compile with any I use gcc 4.9.1 and 3.3.6, but the code should compile with any
standards compliant compiler. standards compliant compiler.
Gcc is available at http://gcc.gnu.org. Gcc is available at http://gcc.gnu.org.
@ -32,9 +32,12 @@ 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 Or type 'make install-compress', which additionally compresses the
typing 'make install-bin', 'make install-info' or 'make install-man' man page after installation. (Installing compressed docs may become
respectively. the default in the future).
You can install only the program or the man page by typing 'make
install-bin' or 'make install-man' respectively.
Instead of 'make install', you can type 'make install-as-lzip' to Instead of 'make install', you can type 'make install-as-lzip' to
install the program and any data files and documentation, and link install the program and any data files and documentation, and link
@ -43,12 +46,12 @@ the main archive.
Another way Another way
----------- -----------
You can also compile pdlzip into a separate directory. To do this, you You can also compile pdlzip into a separate directory.
must use a version of 'make' that supports the 'VPATH' variable, such To do this, you must use a version of 'make' that supports the 'VPATH'
as GNU 'make'. 'cd' to the directory where you want the object files variable, such as GNU 'make'. 'cd' to the directory where you want the
and executables to go and run the 'configure' script. 'configure' object files and executables to go and run the 'configure' script.
automatically checks for the source code in '.', in '..' and in the 'configure' automatically checks for the source code in '.', in '..' and
directory that 'configure' is in. in the directory that 'configure' is in.
'configure' recognizes the option '--srcdir=DIR' to control where to 'configure' recognizes the option '--srcdir=DIR' to control where to
look for the sources. Usually 'configure' can determine that directory look for the sources. Usually 'configure' can determine that directory
@ -58,7 +61,7 @@ After running 'configure', you can run 'make' and 'make install' as
explained above. explained above.
Copyright (C) 2010, 2011, 2012, 2013 Antonio Diaz Diaz. Copyright (C) 2010-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.

View file

@ -14,47 +14,6 @@
#include "lzip.h" #include "lzip.h"
#include "LzmaDec.h" #include "LzmaDec.h"
CRC32 crc32;
/* Returns the number of bytes really read.
If (returned value < size) and (errno == 0), means EOF was reached.
*/
int readblock( const int fd, uint8_t * const buf, const int size )
{
int rest = size;
errno = 0;
while( rest > 0 )
{
const int n = read( fd, buf + size - rest, rest );
if( n > 0 ) rest -= n;
else if( n == 0 ) break; /* EOF */
else if( errno != EINTR && errno != EAGAIN ) break;
errno = 0;
}
return size - rest;
}
/* Returns the number of bytes really written.
If (returned value < size), it is always an error.
*/
int writeblock( const int fd, const uint8_t * const buf, const int size )
{
int rest = size;
errno = 0;
while( rest > 0 )
{
const int n = write( fd, buf + size - rest, rest );
if( n > 0 ) rest -= n;
else if( n < 0 && errno != EINTR && errno != EAGAIN ) break;
errno = 0;
}
return size - rest;
}
#define kNumTopBits 24 #define kNumTopBits 24
#define kTopValue ((uint32_t)1 << kNumTopBits) #define kTopValue ((uint32_t)1 << kNumTopBits)

View file

@ -1,4 +1,4 @@
/* LzmaEnc.h -- LZMA Encoder /* LzmaEnc.h -- LZMA Encoder
2009-02-07 : Igor Pavlov : Public domain */ 2009-02-07 : Igor Pavlov : Public domain */

View file

@ -1,31 +1,30 @@
DISTNAME = $(pkgname)-$(pkgversion) DISTNAME = $(pkgname)-$(pkgversion)
INSTALL = install INSTALL = install
INSTALL_PROGRAM = $(INSTALL) -p -m 755 INSTALL_PROGRAM = $(INSTALL) -m 755
INSTALL_DATA = $(INSTALL) -p -m 644 INSTALL_DATA = $(INSTALL) -m 644
INSTALL_DIR = $(INSTALL) -d -m 755 INSTALL_DIR = $(INSTALL) -d -m 755
SHELL = /bin/sh SHELL = /bin/sh
objs = carg_parser.o LzFind.o LzmaEnc.o LzmaDec.o main.o objs = carg_parser.o LzFind.o LzmaEnc.o LzmaDec.o main.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 \
install-as-lzip uninstall uninstall-bin uninstall-info uninstall-man \ install-as-lzip 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)
$(CC) $(LDFLAGS) -o $@ $(objs) $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(objs)
$(progname)_profiled : $(objs)
$(CC) $(LDFLAGS) -pg -o $@ $(objs)
main.o : main.c main.o : main.c
$(CC) $(CPPFLAGS) $(CFLAGS) -DPROGVERSION=\"$(pkgversion)\" -c -o $@ $< $(CC) $(CFLAGS) $(CPPFLAGS) -DPROGVERSION=\"$(pkgversion)\" -c -o $@ $<
%.o : %.c %.o : %.c
$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $< $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
$(objs) : Makefile $(objs) : Makefile
carg_parser.o : carg_parser.h carg_parser.o : carg_parser.h
@ -39,8 +38,8 @@ doc : man
info : $(VPATH)/doc/$(pkgname).info info : $(VPATH)/doc/$(pkgname).info
$(VPATH)/doc/$(pkgname).info : $(VPATH)/doc/$(pkgname).texinfo $(VPATH)/doc/$(pkgname).info : $(VPATH)/doc/$(pkgname).texi
cd $(VPATH)/doc && makeinfo $(pkgname).texinfo cd $(VPATH)/doc && makeinfo $(pkgname).texi
man : $(VPATH)/doc/$(progname).1 man : $(VPATH)/doc/$(progname).1
@ -54,42 +53,53 @@ check : all
@$(VPATH)/testsuite/check.sh $(VPATH)/testsuite $(pkgversion) @$(VPATH)/testsuite/check.sh $(VPATH)/testsuite $(pkgversion)
install : install-bin install-man install : install-bin install-man
install-strip : install-bin-strip install-man
install-compress : install-bin install-man-compress
install-strip-compress : install-bin-strip install-man-compress
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"
install-as-lzip : install install-as-lzip : install
-rm -f "$(DESTDIR)$(bindir)/lzip" -rm -f "$(DESTDIR)$(bindir)/lzip"
cd "$(DESTDIR)$(bindir)" && ln -s $(progname) lzip cd "$(DESTDIR)$(bindir)" && ln -s $(progname) lzip
uninstall : uninstall-bin uninstall-man uninstall : uninstall-man 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)
tar -cvf $(DISTNAME).tar \ tar -Hustar --owner=root --group=root -cvf $(DISTNAME).tar \
$(DISTNAME)/AUTHORS \ $(DISTNAME)/AUTHORS \
$(DISTNAME)/ChangeLog \ $(DISTNAME)/ChangeLog \
$(DISTNAME)/INSTALL \ $(DISTNAME)/INSTALL \
@ -108,7 +118,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

9
NEWS
View file

@ -1,5 +1,8 @@
Changes in version 1.5: Changes in version 1.6:
Decompressing and testing no more show file version in lzip mode. Copying of file dates, permissions, and ownership now behaves like "cp -p".
(If the user ID or the group ID can't be duplicated, the file permission
bits S_ISUID and S_ISGID are cleared).
Minor fixes. The targets "install-compress", "install-strip-compress" and
"install-man-compress" have been added to the Makefile.

41
README
View file

@ -6,17 +6,50 @@ the one of lzip, bzip2 or gzip.
Pdlzip uses the lzip file format; the files produced by pdlzip are Pdlzip uses the lzip file format; the files produced by pdlzip are
(hope)fully compatible with lzip-1.4 or newer. Pdlzip is in fact a (hope)fully compatible with lzip-1.4 or newer. Pdlzip is in fact a
"public domain" version of the lzip data compressor, intended for those "public domain" version of the lzip data compressor, intended for those
who can't distribute GPL licensed Free Software. who can't distribute (or even use) GPL licensed Free Software.
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 lziprecover program 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 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.
Pdlzip is also able to decompress legacy lzma-alone (.lzma) files. Pdlzip is also able to decompress legacy lzma-alone (.lzma) files.
Lzma-alone is a very bad format. If you keep any lzma-alone files, it is
advisable to recompress them to lzip format.
Pdlzip is written in C. Pdlzip is written in C.
Pdlzip includes public domain compression code from the LZMA SDK written Pdlzip includes public domain (de)compression code from the LZMA SDK
by Igor Pavlov. (Software Development Kit) written by Igor Pavlov.
I would not write non-copylefted software unless it is too simple to be
worth copylefting it, but one of the uses of the lzip format is the
interchange of information, and it is therefore desirable that even the
users of the most non-free platforms can share lzip files with everybody
else.
Copyright (C) 2010, 2011, 2012, 2013 Antonio Diaz Diaz. Copyright (C) 2010-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.

View file

@ -1,10 +1,18 @@
/* Pdlzip - LZMA lossless data compressor /* Arg_parser - POSIX/GNU command line argument parser. (C version)
Copyright (C) 2010, 2011, 2012, 2013 Antonio Diaz Diaz. Copyright (C) 2006-2015 Antonio Diaz Diaz.
This program is free software: you have unlimited permission This library is free software. Redistribution and use in source and
to copy, distribute and modify it. binary forms, with or without modification, are permitted provided
that the following conditions are met:
This program is distributed in the hope that it will be useful, 1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/ */
@ -28,7 +36,7 @@ static char push_back_record( struct Arg_parser * const ap,
const int code, const char * const argument ) const int code, const char * const argument )
{ {
const int len = strlen( argument ); const int len = strlen( argument );
struct ap_Record *p; struct 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 (struct ap_Record) );
if( !tmp ) return 0; if( !tmp ) return 0;
@ -159,7 +167,8 @@ static char parse_short_option( struct Arg_parser * const ap,
if( index < 0 ) if( index < 0 )
{ {
add_error( ap, "invalid option -- " ); add_error( ap, code_str ); add_error( ap, "invalid option -- '" ); add_error( ap, code_str );
add_error( ap, "'" );
return 1; return 1;
} }
@ -174,8 +183,8 @@ static char parse_short_option( struct Arg_parser * const ap,
{ {
if( !arg || !arg[0] ) if( !arg || !arg[0] )
{ {
add_error( ap, "option requires an argument -- " ); add_error( ap, "option requires an argument -- '" );
add_error( ap, code_str ); add_error( ap, code_str ); add_error( ap, "'" );
return 1; return 1;
} }
++*argindp; cind = 0; ++*argindp; cind = 0;

View file

@ -1,10 +1,18 @@
/* Pdlzip - LZMA lossless data compressor /* Arg_parser - POSIX/GNU command line argument parser. (C version)
Copyright (C) 2010, 2011, 2012, 2013 Antonio Diaz Diaz. Copyright (C) 2006-2015 Antonio Diaz Diaz.
This program is free software: you have unlimited permission This library is free software. Redistribution and use in source and
to copy, distribute and modify it. binary forms, with or without modification, are permitted provided
that the following conditions are met:
This program is distributed in the hope that it will be useful, 1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/ */

8
configure vendored
View file

@ -1,12 +1,12 @@
#! /bin/sh #! /bin/sh
# configure script for Pdlzip - LZMA lossless data compressor # configure script for Pdlzip - LZMA lossless data compressor
# Copyright (C) 2010, 2011, 2012, 2013 Antonio Diaz Diaz. # Copyright (C) 2010-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=pdlzip pkgname=pdlzip
pkgversion=1.5 pkgversion=1.6-rc1
progname=pdlzip progname=pdlzip
srctrigger=doc/${progname}.1 srctrigger=doc/${progname}.1
@ -64,7 +64,7 @@ while [ $# != 0 ] ; do
echo " --datarootdir=DIR base directory for doc and data [${datarootdir}]" echo " --datarootdir=DIR base directory for doc and data [${datarootdir}]"
echo " --infodir=DIR info files directory [${infodir}]" echo " --infodir=DIR info files directory [${infodir}]"
echo " --mandir=DIR man pages directory [${mandir}]" echo " --mandir=DIR man pages directory [${mandir}]"
echo " CC=COMPILER C compiler to use [gcc]" echo " CC=COMPILER C compiler to use [${CC}]"
echo " CPPFLAGS=OPTIONS command line options for the preprocessor [${CPPFLAGS}]" echo " CPPFLAGS=OPTIONS command line options for the preprocessor [${CPPFLAGS}]"
echo " CFLAGS=OPTIONS command line options for the C compiler [${CFLAGS}]" echo " CFLAGS=OPTIONS command line options for the C compiler [${CFLAGS}]"
echo " LDFLAGS=OPTIONS command line options for the linker [${LDFLAGS}]" echo " LDFLAGS=OPTIONS command line options for the linker [${LDFLAGS}]"
@ -165,7 +165,7 @@ echo "LDFLAGS = ${LDFLAGS}"
rm -f Makefile rm -f Makefile
cat > Makefile << EOF cat > Makefile << EOF
# Makefile for Pdlzip - LZMA lossless data compressor # Makefile for Pdlzip - LZMA lossless data compressor
# Copyright (C) 2010, 2011, 2012, 2013 Antonio Diaz Diaz. # Copyright (C) 2010-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

View file

@ -1,10 +1,10 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.37.1. .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.46.1.
.TH PDLZIP "1" "September 2013" "Pdlzip 1.5" "User Commands" .TH PDLZIP "1" "April 2015" "pdlzip 1.6-rc1" "User Commands"
.SH NAME .SH NAME
Pdlzip \- reduces the size of files pdlzip \- reduces the size of files
.SH SYNOPSIS .SH SYNOPSIS
.B pdlzip .B pdlzip
[\fIoptions\fR] [\fIfiles\fR] [\fI\,options\/\fR] [\fI\,files\/\fR]
.SH DESCRIPTION .SH DESCRIPTION
Pdlzip \- A "public domain" version of the lzip data compressor Pdlzip \- A "public domain" version of the lzip data compressor
also able to decompress legacy lzma\-alone (.lzma) files. also able to decompress legacy lzma\-alone (.lzma) files.
@ -77,8 +77,9 @@ Report bugs to lzip\-bug@nongnu.org
.br .br
Pdlzip home page: http://www.nongnu.org/lzip/pdlzip.html Pdlzip home page: http://www.nongnu.org/lzip/pdlzip.html
.SH COPYRIGHT .SH COPYRIGHT
Copyright \(co 2013 Antonio Diaz Diaz. Copyright \(co 2015 Antonio Diaz Diaz.
Public Domain 2009 Igor Pavlov. Public Domain 2009 Igor Pavlov.
License 2\-clause BSD.
.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.

69
lzip.h
View file

@ -1,8 +1,16 @@
/* Pdlzip - LZMA lossless data compressor /* Pdlzip - LZMA lossless data compressor
Copyright (C) 2010, 2011, 2012, 2013 Antonio Diaz Diaz. Copyright (C) 2010-2015 Antonio Diaz Diaz.
This program is free software: you have unlimited permission This program is free software. Redistribution and use in source and
to copy, distribute and modify it. binary forms, with or without modification, are permitted provided
that the following conditions are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
@ -48,12 +56,29 @@ struct Pretty_print
{ {
const char * name; const char * name;
const char * stdin_name; const char * stdin_name;
int longest_name; unsigned longest_name;
bool first_post; bool first_post;
}; };
void Pp_init( struct Pretty_print * const pp, const char * const filenames[], static inline void Pp_init( struct Pretty_print * const pp,
const int num_filenames ); const char * const filenames[], const int num_filenames )
{
unsigned stdin_name_len;
int i;
pp->name = 0;
pp->stdin_name = "(stdin)";
pp->longest_name = 0;
pp->first_post = false;
stdin_name_len = strlen( pp->stdin_name );
for( i = 0; i < num_filenames; ++i )
{
const char * const s = filenames[i];
const unsigned len = (strcmp( s, "-" ) == 0) ? stdin_name_len : strlen( s );
if( len > pp->longest_name ) pp->longest_name = len;
}
if( pp->longest_name == 0 ) pp->longest_name = stdin_name_len;
}
static inline void Pp_set_name( struct Pretty_print * const pp, static inline void Pp_set_name( struct Pretty_print * const pp,
const char * const filename ) const char * const filename )
@ -86,11 +111,9 @@ static inline void CRC32_init( void )
} }
} }
static inline void CRC32_update_byte( uint32_t * const crc, const uint8_t byte )
{ *crc = crc32[(*crc^byte)&0xFF] ^ ( *crc >> 8 ); }
static inline void CRC32_update_buf( uint32_t * const crc, static inline void CRC32_update_buf( uint32_t * const crc,
const uint8_t * const buffer, const int size ) const uint8_t * const buffer,
const int size )
{ {
int i; int i;
for( i = 0; i < size; ++i ) for( i = 0; i < size; ++i )
@ -163,47 +186,35 @@ enum { Ft_size = 20 };
static inline unsigned Ft_get_data_crc( const File_trailer data ) static inline unsigned Ft_get_data_crc( const File_trailer data )
{ {
unsigned tmp = 0; unsigned tmp = 0;
int i; int i; for( i = 3; i >= 0; --i ) { tmp <<= 8; tmp += data[i]; }
for( i = 3; i >= 0; --i ) { tmp <<= 8; tmp += data[i]; }
return tmp; return tmp;
} }
static inline void Ft_set_data_crc( File_trailer data, unsigned crc ) static inline void Ft_set_data_crc( File_trailer data, unsigned crc )
{ { int i; for( i = 0; i <= 3; ++i ) { data[i] = (uint8_t)crc; crc >>= 8; } }
int i;
for( i = 0; i <= 3; ++i ) { data[i] = (uint8_t)crc; crc >>= 8; }
}
static inline unsigned long long Ft_get_data_size( const File_trailer data ) static inline unsigned long long Ft_get_data_size( const File_trailer data )
{ {
unsigned long long tmp = 0; unsigned long long tmp = 0;
int i; int i; for( i = 11; i >= 4; --i ) { tmp <<= 8; tmp += data[i]; }
for( i = 11; i >= 4; --i ) { tmp <<= 8; tmp += data[i]; }
return tmp; return tmp;
} }
static inline void Ft_set_data_size( File_trailer data, unsigned long long sz ) static inline void Ft_set_data_size( File_trailer data, unsigned long long sz )
{ { int i; for( i = 4; i <= 11; ++i ) { data[i] = (uint8_t)sz; sz >>= 8; } }
int i;
for( i = 4; i <= 11; ++i ) { data[i] = (uint8_t)sz; sz >>= 8; }
}
static inline unsigned long long Ft_get_member_size( const File_trailer data ) static inline unsigned long long Ft_get_member_size( const File_trailer data )
{ {
unsigned long long tmp = 0; unsigned long long tmp = 0;
int i; int i; for( i = 19; i >= 12; --i ) { tmp <<= 8; tmp += data[i]; }
for( i = 19; i >= 12; --i ) { tmp <<= 8; tmp += data[i]; }
return tmp; return tmp;
} }
static inline void Ft_set_member_size( File_trailer data, unsigned long long sz ) static inline void Ft_set_member_size( File_trailer data, unsigned long long sz )
{ { int i; for( i = 12; i <= 19; ++i ) { data[i] = (uint8_t)sz; sz >>= 8; } }
int i;
for( i = 12; i <= 19; ++i ) { data[i] = (uint8_t)sz; sz >>= 8; }
}
/* defined in LzmaDec.c */ /* defined in main.c */
int readblock( const int fd, uint8_t * const buf, const int size ); int readblock( const int fd, uint8_t * const buf, const int size );
int writeblock( const int fd, const uint8_t * const buf, const int size ); int writeblock( const int fd, const uint8_t * const buf, const int size );

196
main.c
View file

@ -1,9 +1,17 @@
/* Pdlzip - LZMA lossless data compressor /* Pdlzip - LZMA lossless data compressor
2009-08-14 : Igor Pavlov : Public domain 2009-08-14 : Igor Pavlov : Public domain
Copyright (C) 2010, 2011, 2012, 2013 Antonio Diaz Diaz. Copyright (C) 2010-2015 Antonio Diaz Diaz.
This program is free software: you have unlimited permission This program is free software. Redistribution and use in source and
to copy, distribute and modify it. binary forms, with or without modification, are permitted provided
that the following conditions are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
@ -49,6 +57,10 @@
#include "LzmaDec.h" #include "LzmaDec.h"
#include "LzmaEnc.h" #include "LzmaEnc.h"
#ifndef O_BINARY
#define O_BINARY 0
#endif
#if CHAR_BIT != 8 #if CHAR_BIT != 8
#error "Environments where CHAR_BIT != 8 are not supported." #error "Environments where CHAR_BIT != 8 are not supported."
#endif #endif
@ -56,15 +68,9 @@
const char * const Program_name = "Pdlzip"; const char * const Program_name = "Pdlzip";
const char * const program_name = "pdlzip"; const char * const program_name = "pdlzip";
const char * const program_year = "2013"; const char * const program_year = "2015";
const char * invocation_name = 0; const char * invocation_name = 0;
#ifdef O_BINARY
const int o_binary = O_BINARY;
#else
const int o_binary = 0;
#endif
struct { const char * from; const char * to; } const known_extensions[] = { struct { const char * from; const char * to; } const known_extensions[] = {
{ ".lz", "" }, { ".lz", "" },
{ ".tlz", ".tar" }, { ".tlz", ".tar" },
@ -130,39 +136,23 @@ static void show_help( void )
static void show_version( void ) static void show_version( void )
{ {
printf( "%s %s\n", Program_name, PROGVERSION ); printf( "%s %s\n", program_name, PROGVERSION );
printf( "Copyright (C) %s Antonio Diaz Diaz.\n", program_year ); printf( "Copyright (C) %s Antonio Diaz Diaz.\n", program_year );
printf( "Public Domain 2009 Igor Pavlov.\n" printf( "Public Domain 2009 Igor Pavlov.\n"
"License 2-clause BSD.\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" );
} }
static const char * format_num( unsigned num ) static void show_header( const unsigned dictionary_size )
{
const char * const prefix[8] =
{ "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi", "Yi" };
enum { buf_size = 16, factor = 1024 };
static char buf[buf_size];
const char * p = "";
bool exact = ( num % factor == 0 );
int i;
for( i = 0; i < 8 && ( num > 9999 || ( exact && num >= factor ) ); ++i )
{ num /= factor; if( num % factor != 0 ) exact = false; p = prefix[i]; }
snprintf( buf, buf_size, "%u %s", num, p );
return buf;
}
static void show_header( const File_header header )
{ {
const char * const prefix[8] = const char * const prefix[8] =
{ "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi", "Yi" }; { "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi", "Yi" };
enum { factor = 1024 }; enum { factor = 1024 };
const char * p = ""; const char * p = "";
const char * np = " "; const char * np = " ";
unsigned num = Fh_get_dictionary_size( header ), i; unsigned num = dictionary_size, i;
bool exact = ( num % factor == 0 ); bool exact = ( num % factor == 0 );
for( i = 0; i < 8 && ( num > 9999 || ( exact && num >= factor ) ); ++i ) for( i = 0; i < 8 && ( num > 9999 || ( exact && num >= factor ) ); ++i )
@ -245,8 +235,10 @@ static int extension_index( const char * const name )
for( i = 0; known_extensions[i].from; ++i ) for( i = 0; known_extensions[i].from; ++i )
{ {
const char * const ext = known_extensions[i].from; const char * const ext = known_extensions[i].from;
if( strlen( name ) > strlen( ext ) && const unsigned name_len = strlen( name );
strncmp( name + strlen( name ) - strlen( ext ), ext, strlen( ext ) ) == 0 ) const unsigned ext_len = strlen( ext );
if( name_len > ext_len &&
strncmp( name + name_len - ext_len, ext, ext_len ) == 0 )
return i; return i;
} }
return -1; return -1;
@ -266,7 +258,7 @@ static int open_instream( const char * const name, struct stat * const in_statsp
} }
else else
{ {
infd = open( name, O_RDONLY | o_binary ); infd = open( name, O_RDONLY | O_BINARY );
if( infd < 0 ) if( infd < 0 )
{ {
if( verbosity >= 0 ) if( verbosity >= 0 )
@ -322,20 +314,21 @@ static void set_c_outname( const char * const name )
static void set_d_outname( const char * const name, const int i ) static void set_d_outname( const char * const name, const int i )
{ {
const unsigned name_len = strlen( name );
if( i >= 0 ) if( i >= 0 )
{ {
const char * const from = known_extensions[i].from; const char * const from = known_extensions[i].from;
if( strlen( name ) > strlen( from ) ) const unsigned from_len = strlen( from );
if( name_len > from_len )
{ {
output_filename = resize_buffer( output_filename, strlen( name ) + output_filename = resize_buffer( output_filename, name_len +
strlen( known_extensions[0].to ) + 1 ); strlen( known_extensions[0].to ) + 1 );
strcpy( output_filename, name ); strcpy( output_filename, name );
strcpy( output_filename + strlen( name ) - strlen( from ), strcpy( output_filename + name_len - from_len, known_extensions[i].to );
known_extensions[i].to );
return; return;
} }
} }
output_filename = resize_buffer( output_filename, strlen( name ) + 4 + 1 ); output_filename = resize_buffer( output_filename, name_len + 4 + 1 );
strcpy( output_filename, name ); strcpy( output_filename, name );
strcat( output_filename, ".out" ); strcat( output_filename, ".out" );
if( verbosity >= 1 ) if( verbosity >= 1 )
@ -346,7 +339,7 @@ static void set_d_outname( const char * const name, const int i )
static bool open_outstream( const bool force ) static bool open_outstream( const bool force )
{ {
int flags = O_CREAT | O_WRONLY | o_binary; int flags = O_CREAT | O_WRONLY | O_BINARY;
if( force ) flags |= O_TRUNC; else flags |= O_EXCL; if( force ) flags |= O_TRUNC; else flags |= O_EXCL;
outfd = open( output_filename, flags, outfd_mode ); outfd = open( output_filename, flags, outfd_mode );
@ -365,7 +358,7 @@ static bool open_outstream( const bool force )
static bool check_tty( const int infd, const enum Mode program_mode ) static bool check_tty( const int infd, const enum Mode program_mode )
{ {
if( program_mode == m_compress && outfd >= 0 && isatty( outfd ) ) if( program_mode == m_compress && isatty( outfd ) )
{ {
show_error( "I won't write compressed data to a terminal.", 0, true ); show_error( "I won't write compressed data to a terminal.", 0, true );
return false; return false;
@ -402,10 +395,14 @@ static void close_and_set_permissions( const struct stat * const in_statsp )
bool warning = false; bool warning = false;
if( in_statsp ) if( in_statsp )
{ {
const mode_t mode = in_statsp->st_mode;
/* fchown will in many cases return with EPERM, which can be safely ignored. */ /* fchown will in many cases return with EPERM, which can be safely ignored. */
if( ( fchown( outfd, in_statsp->st_uid, in_statsp->st_gid ) != 0 && if( fchown( outfd, in_statsp->st_uid, in_statsp->st_gid ) == 0 )
errno != EPERM ) || { if( fchmod( outfd, mode ) != 0 ) warning = true; }
fchmod( outfd, in_statsp->st_mode ) != 0 ) warning = true; else
if( errno != EPERM ||
fchmod( outfd, mode & ~( S_ISUID | S_ISGID | S_ISVTX ) ) != 0 )
warning = true;
} }
if( close( outfd ) != 0 ) cleanup_and_fail( 1 ); if( close( outfd ) != 0 ) cleanup_and_fail( 1 );
outfd = -1; outfd = -1;
@ -426,21 +423,21 @@ static int compress( const struct Lzma_options * const encoder_options,
const int infd, struct Pretty_print * const pp ) const int infd, struct Pretty_print * const pp )
{ {
int retval = 0; int retval = 0;
CLzmaEncHandle encoder; CLzmaEncHandle encoder = 0;
File_header header; File_header header;
Fh_set_magic( header ); Fh_set_magic( header );
if( verbosity >= 1 ) Pp_show_msg( pp, 0 ); if( verbosity >= 1 ) Pp_show_msg( pp, 0 );
if( !Fh_set_dictionary_size( header, encoder_options->dictionary_size ) || if( Fh_set_dictionary_size( header, encoder_options->dictionary_size ) &&
encoder_options->match_len_limit < min_match_len_limit || encoder_options->match_len_limit >= min_match_len_limit &&
encoder_options->match_len_limit > max_match_len ) encoder_options->match_len_limit <= max_match_len )
internal_error( "invalid argument to encoder" ); encoder = LzmaEnc_Init( Fh_get_dictionary_size( header ),
encoder_options->match_len_limit, infd, outfd );
else internal_error( "invalid argument to encoder." );
encoder = LzmaEnc_Init( Fh_get_dictionary_size( header ),
encoder_options->match_len_limit, infd, outfd );
if( !encoder ) if( !encoder )
{ {
Pp_show_msg( pp, "Not enough memory. Try a smaller dictionary size" ); Pp_show_msg( pp, "Not enough memory. Try a smaller dictionary size." );
return 1; return 1;
} }
@ -448,7 +445,7 @@ static int compress( const struct Lzma_options * const encoder_options,
{ show_error( "Can not write output file", errno, false ); retval = 1; } { show_error( "Can not write output file", errno, false ); retval = 1; }
else else
if( LzmaEnc_Encode( encoder ) != 0 ) if( LzmaEnc_Encode( encoder ) != 0 )
{ Pp_show_msg( pp, "Encoder error" ); retval = 1; } { Pp_show_msg( pp, "Encoder error." ); retval = 1; }
LzmaEnc_Free( encoder ); LzmaEnc_Free( encoder );
return retval; return retval;
} }
@ -529,8 +526,7 @@ static int lzma_decode( uint64_t unpackSize, CLzmaDec *decoder, const int infd,
( !thereIsSize && status != LZMA_STATUS_FINISHED_WITH_MARK ) ) ( !thereIsSize && status != LZMA_STATUS_FINISHED_WITH_MARK ) )
{ show_error( "Data error.", 0, false ); return 2; } { show_error( "Data error.", 0, false ); return 2; }
if( verbosity >= 2 ) if( verbosity >= 2 )
fprintf( stderr, "lzma-alone, dictionary size %7sB. ", { fprintf( stderr, "lzma-alone, " ); show_header( decoder->dicBufSize ); }
format_num( decoder->dicBufSize ) );
if( verbosity >= 3 ) if( verbosity >= 3 )
fprintf( stderr, "uncompressed size %9llu, compressed size %8llu. ", fprintf( stderr, "uncompressed size %9llu, compressed size %8llu. ",
total_out, total_in ); total_out, total_in );
@ -652,13 +648,14 @@ static int decompress( const int infd, struct Pretty_print * const pp,
for( first_member = true; ; first_member = false ) for( first_member = true; ; first_member = false )
{ {
int i; int i;
unsigned dictionary_size = 0;
File_header header; File_header header;
if( inSize - inPos < lzma_header_size && if( inSize - inPos < lzma_header_size &&
!read_inbuf( infd, inBuf, &inPos, &inSize ) ) return 1; !read_inbuf( infd, inBuf, &inPos, &inSize ) ) return 1;
if( inSize - inPos <= Fh_size ) /* End Of File */ if( inSize - inPos <= Fh_size ) /* End Of File */
{ {
if( first_member ) if( first_member )
{ Pp_show_msg( pp, "File ends unexpectedly at member header" ); { Pp_show_msg( pp, "File ends unexpectedly at member header." );
retval = 2; } retval = 2; }
break; break;
} }
@ -678,7 +675,7 @@ static int decompress( const int infd, struct Pretty_print * const pp,
} }
if( lzip_mode ) if( lzip_mode )
{ {
Pp_show_msg( pp, "Bad magic number (file not in lzip format)" ); Pp_show_msg( pp, "Bad magic number (file not in lzip format)." );
retval = 2; break; retval = 2; break;
} }
} }
@ -693,25 +690,24 @@ static int decompress( const int infd, struct Pretty_print * const pp,
Fh_version( header ) ); } Fh_version( header ) ); }
retval = 2; break; retval = 2; break;
} }
if( Fh_get_dictionary_size( header ) < min_dictionary_size || dictionary_size = Fh_get_dictionary_size( header );
Fh_get_dictionary_size( header ) > max_dictionary_size ) if( dictionary_size < min_dictionary_size ||
{ Pp_show_msg( pp, "Invalid dictionary size in member header" ); dictionary_size > max_dictionary_size )
{ Pp_show_msg( pp, "Invalid dictionary size in member header." );
retval = 2; break; } retval = 2; break; }
raw_props[0] = 93; /* (45 * 2) + (9 * 0) + 3 */ raw_props[0] = 93; /* (45 * 2) + (9 * 0) + 3 */
ds = Fh_get_dictionary_size( header ); ds = dictionary_size;
for( i = 1; i <= 4; ++i ) { raw_props[i] = ds & 0xFF; ds >>= 8; } for( i = 1; i <= 4; ++i ) { raw_props[i] = ds & 0xFF; ds >>= 8; }
} }
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( lzip_mode && verbosity >= 3 ) show_header( dictionary_size ); }
if( lzip_mode && verbosity >= 3 ) show_header( header );
}
if( !LzmaDec_Init( &decoder, raw_props ) ) if( !LzmaDec_Init( &decoder, raw_props ) )
{ {
show_error( "Not enough memory. Find a machine with more memory.", 0, false ); show_error( "Not enough memory.", 0, false );
cleanup_and_fail( 1 ); cleanup_and_fail( 1 );
} }
if( lzip_mode ) if( lzip_mode )
@ -746,25 +742,7 @@ static void set_signals( void )
} }
void Pp_init( struct Pretty_print * const pp, const char * const filenames[], CRC32 crc32;
const int num_filenames )
{
unsigned stdin_name_len;
int i;
pp->name = 0;
pp->stdin_name = "(stdin)";
pp->longest_name = 0;
pp->first_post = false;
stdin_name_len = strlen( pp->stdin_name );
for( i = 0; i < num_filenames; ++i )
{
const char * const s = filenames[i];
const int len = ( (strcmp( s, "-" ) == 0) ? stdin_name_len : strlen( s ) );
if( len > pp->longest_name ) pp->longest_name = len;
}
if( pp->longest_name == 0 ) pp->longest_name = stdin_name_len;
}
void Pp_show_msg( struct Pretty_print * const pp, const char * const msg ) void Pp_show_msg( struct Pretty_print * const pp, const char * const msg )
@ -780,11 +758,48 @@ void Pp_show_msg( struct Pretty_print * const pp, const char * const msg )
for( i = 0; i < len; ++i ) fprintf( stderr, " " ); for( i = 0; i < len; ++i ) fprintf( stderr, " " );
if( !msg ) fflush( stderr ); if( !msg ) fflush( stderr );
} }
if( msg ) fprintf( stderr, "%s.\n", msg ); if( msg ) fprintf( stderr, "%s\n", msg );
} }
} }
/* Returns the number of bytes really read.
If (returned value < size) and (errno == 0), means EOF was reached.
*/
int readblock( const int fd, uint8_t * const buf, const int size )
{
int sz = 0;
errno = 0;
while( sz < size )
{
const int n = read( fd, buf + sz, size - sz );
if( n > 0 ) sz += n;
else if( n == 0 ) break; /* EOF */
else if( errno != EINTR ) break;
errno = 0;
}
return sz;
}
/* Returns the number of bytes really written.
If (returned value < size), it is always an error.
*/
int writeblock( const int fd, const uint8_t * const buf, const int size )
{
int sz = 0;
errno = 0;
while( sz < size )
{
const int n = write( fd, buf + sz, size - sz );
if( n > 0 ) sz += n;
else if( n < 0 && errno != EINTR ) break;
errno = 0;
}
return sz;
}
void show_error( const char * const msg, const int errcode, const bool help ) void show_error( const char * const msg, const int errcode, const bool help )
{ {
if( verbosity >= 0 ) if( verbosity >= 0 )
@ -792,7 +807,7 @@ void show_error( const char * const msg, const int errcode, const bool help )
if( msg && msg[0] ) if( msg && msg[0] )
{ {
fprintf( stderr, "%s: %s", program_name, msg ); fprintf( stderr, "%s: %s", program_name, msg );
if( errcode > 0 ) fprintf( stderr, ": %s", strerror( errcode ) ); if( errcode > 0 ) fprintf( stderr, ": %s.", strerror( errcode ) );
fprintf( stderr, "\n" ); fprintf( stderr, "\n" );
} }
if( help ) if( help )
@ -805,7 +820,7 @@ void show_error( const char * const msg, const int errcode, const bool help )
void internal_error( const char * const msg ) void internal_error( const char * const msg )
{ {
if( verbosity >= 0 ) if( verbosity >= 0 )
fprintf( stderr, "%s: internal error: %s.\n", program_name, msg ); fprintf( stderr, "%s: internal error: %s\n", program_name, msg );
exit( 3 ); exit( 3 );
} }
@ -879,7 +894,7 @@ int main( const int argc, const char * const argv[] )
CRC32_init(); CRC32_init();
if( !ap_init( &parser, argc, argv, options, 0 ) ) if( !ap_init( &parser, argc, argv, options, 0 ) )
{ show_error( "Memory exhausted.", 0, false ); return 1; } { show_error( "Not enough memory.", 0, false ); return 1; }
if( ap_error( &parser ) ) /* bad option */ if( ap_error( &parser ) ) /* bad option */
{ show_error( ap_error( &parser ), 0, true ); return 1; } { show_error( ap_error( &parser ), 0, true ); return 1; }
@ -890,8 +905,7 @@ int main( const int argc, const char * const argv[] )
if( !code ) break; /* no more options */ if( !code ) break; /* no more options */
switch( code ) switch( code )
{ {
case '0': case '0': case '1': case '2': case '3': case '4':
case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9': case '5': case '6': case '7': case '8': case '9':
encoder_options = option_mapping[code-'0']; break; encoder_options = option_mapping[code-'0']; break;
case 'b': break; case 'b': break;
@ -912,7 +926,7 @@ int main( const int argc, const char * const argv[] )
case 't': program_mode = m_test; break; case 't': program_mode = m_test; break;
case 'v': if( verbosity < 4 ) ++verbosity; break; case 'v': if( verbosity < 4 ) ++verbosity; break;
case 'V': show_version(); return 0; case 'V': show_version(); return 0;
default : internal_error( "uncaught option" ); default : internal_error( "uncaught option." );
} }
} /* end process options */ } /* end process options */

View file

@ -1,6 +1,6 @@
#! /bin/sh #! /bin/sh
# check script for Pdlzip - LZMA lossless data compressor # check script for Pdlzip - LZMA lossless data compressor
# Copyright (C) 2010, 2011, 2012, 2013 Antonio Diaz Diaz. # Copyright (C) 2010-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.
@ -12,7 +12,7 @@ testdir=`cd "$1" ; pwd`
LZIP="${objdir}"/pdlzip LZIP="${objdir}"/pdlzip
framework_failure() { echo "failure in testing framework" ; exit 1 ; } framework_failure() { echo "failure in testing framework" ; exit 1 ; }
if [ ! -x "${LZIP}" ] ; then if [ ! -f "${LZIP}" ] || [ ! -x "${LZIP}" ] ; then
echo "${LZIP}: cannot execute" echo "${LZIP}: cannot execute"
exit 1 exit 1
fi fi
@ -27,22 +27,29 @@ fail=0
printf "testing pdlzip-%s..." "$2" printf "testing pdlzip-%s..." "$2"
"${LZIP}" -cqs-1 in > /dev/null "${LZIP}" -cqm4 in > /dev/null
if [ $? = 1 ] ; then printf . ; else fail=1 ; printf - ; fi if [ $? = 1 ] ; then printf . ; else printf - ; fail=1 ; fi
"${LZIP}" -cqs0 in > /dev/null
if [ $? = 1 ] ; then printf . ; else fail=1 ; printf - ; fi
"${LZIP}" -cqs4095 in > /dev/null
if [ $? = 1 ] ; then printf . ; else fail=1 ; printf - ; fi
"${LZIP}" -cqm274 in > /dev/null "${LZIP}" -cqm274 in > /dev/null
if [ $? = 1 ] ; then printf . ; else fail=1 ; printf - ; fi if [ $? = 1 ] ; then printf . ; else printf - ; fail=1 ; fi
"${LZIP}" -tq in "${LZIP}" -cqs-1 in > /dev/null
if [ $? = 2 ] ; then printf . ; else fail=1 ; printf - ; fi if [ $? = 1 ] ; then printf . ; else printf - ; fail=1 ; fi
"${LZIP}" -tq < in "${LZIP}" -cqs0 in > /dev/null
if [ $? = 2 ] ; then printf . ; else fail=1 ; printf - ; fi if [ $? = 1 ] ; then printf . ; else printf - ; fail=1 ; fi
"${LZIP}" -cqs4095 in > /dev/null
if [ $? = 1 ] ; then printf . ; else printf - ; fail=1 ; fi
"${LZIP}" -cqs513MiB in > /dev/null
if [ $? = 1 ] ; then printf . ; else printf - ; fail=1 ; fi
printf " in: Bad magic number (file not in lzip format).\n" > msg
"${LZIP}" -t in 2> out
if [ $? = 2 ] && cmp out msg ; then printf . ; else printf - ; fail=1 ; fi
printf " (stdin): Bad magic number (file not in lzip format).\n" > msg
"${LZIP}" -t < in 2> out
if [ $? = 2 ] && cmp out msg ; then printf . ; else printf - ; fail=1 ; fi
rm -f out msg
"${LZIP}" -cdq in "${LZIP}" -cdq in
if [ $? = 2 ] ; then printf . ; else fail=1 ; printf - ; fi if [ $? = 2 ] ; then printf . ; else printf - ; fail=1 ; fi
"${LZIP}" -cdq < in "${LZIP}" -cdq < in
if [ $? = 2 ] ; then printf . ; else fail=1 ; printf - ; fi if [ $? = 2 ] ; then printf . ; else printf - ; fail=1 ; fi
dd if="${in_lz}" bs=1 count=6 2> /dev/null | "${LZIP}" -tq dd if="${in_lz}" bs=1 count=6 2> /dev/null | "${LZIP}" -tq
if [ $? = 2 ] ; then printf . ; else printf - ; fail=1 ; fi if [ $? = 2 ] ; then printf . ; else printf - ; fail=1 ; fi
dd if="${in_lz}" bs=1 count=20 2> /dev/null | "${LZIP}" -tq dd if="${in_lz}" bs=1 count=20 2> /dev/null | "${LZIP}" -tq
@ -53,20 +60,50 @@ if [ $? = 2 ] ; then printf . ; else printf - ; fail=1 ; fi
cmp in copy || fail=1 cmp in copy || fail=1
printf . printf .
"${LZIP}" -cfq "${in_lz}" > out
if [ $? = 1 ] ; then printf . ; else fail=1 ; printf - ; fi
"${LZIP}" -cF "${in_lz}" > out || fail=1
"${LZIP}" -cd out | "${LZIP}" -d > copy || fail=1
cmp in copy || fail=1
printf .
"${LZIP}" -t "${testdir}"/test.txt.lzma || fail=1 "${LZIP}" -t "${testdir}"/test.txt.lzma || fail=1
"${LZIP}" -cd "${testdir}"/test.txt.lzma > copy || fail=1 "${LZIP}" -cd "${testdir}"/test.txt.lzma > copy || fail=1
cmp in copy || fail=1 cmp in copy || fail=1
printf . printf .
for i in s4Ki 0 1 2 3 4 5 6 7 8s16 9s16 ; do cat "${in_lz}" > copy.lz || framework_failure
"${LZIP}" -k -$i in || fail=1 printf "to be overwritten" > copy || framework_failure
"${LZIP}" -df copy.lz || fail=1
cmp in copy || fail=1
printf .
printf "to be overwritten" > copy || framework_failure
"${LZIP}" -df -o copy < "${in_lz}" || fail=1
cmp in copy || fail=1
printf .
"${LZIP}" -s16 < in > anyothername || fail=1
"${LZIP}" -d anyothername || fail=1
cmp in anyothername.out || fail=1
printf .
cat in in > in2 || framework_failure
"${LZIP}" -s16 -o copy2 < in2 || fail=1
"${LZIP}" -t copy2.lz || fail=1
printf .
"${LZIP}" -cd copy2.lz > copy2 || fail=1
cmp in2 copy2 || fail=1
printf .
printf "garbage" >> copy2.lz || framework_failure
printf "to be overwritten" > copy2 || framework_failure
"${LZIP}" -df copy2.lz || fail=1
cmp in2 copy2 || fail=1
printf .
"${LZIP}" -cfq "${in_lz}" > out
if [ $? = 1 ] ; then printf . ; else printf - ; fail=1 ; fi
"${LZIP}" -cF -s16 "${in_lz}" > out || fail=1
"${LZIP}" -cd out | "${LZIP}" -d > copy || fail=1
cmp in copy || fail=1
printf .
for i in s4Ki 0 1 2 3 4 5 6 7 8 9 ; do
"${LZIP}" -k -$i -s16 in || fail=1
mv -f in.lz copy.lz || fail=1 mv -f in.lz copy.lz || fail=1
printf "garbage" >> copy.lz || fail=1 printf "garbage" >> copy.lz || fail=1
"${LZIP}" -df copy.lz || fail=1 "${LZIP}" -df copy.lz || fail=1
@ -74,39 +111,28 @@ for i in s4Ki 0 1 2 3 4 5 6 7 8s16 9s16 ; do
done done
printf . printf .
for i in s4Ki 0 1 2 3 4 5 6 7 8s16 9s16 ; do for i in s4Ki 0 1 2 3 4 5 6 7 8 9 ; do
"${LZIP}" -c -$i in > out || fail=1 "${LZIP}" -c -$i -s16 in > out || fail=1
printf "g" >> out || fail=1 printf "g" >> out || fail=1
"${LZIP}" -cd out > copy || fail=1 "${LZIP}" -cd out > copy || fail=1
cmp in copy || fail=1 cmp in copy || fail=1
done done
printf . printf .
for i in s4Ki 0 1 2 3 4 5 6 7 8s16 9s16 ; do for i in s4Ki 0 1 2 3 4 5 6 7 8 9 ; do
"${LZIP}" -$i < in > out || fail=1 "${LZIP}" -$i -s16 < in > out || fail=1
"${LZIP}" -d < out > copy || fail=1 "${LZIP}" -d < out > copy || fail=1
cmp in copy || fail=1 cmp in copy || fail=1
done done
printf . printf .
for i in s4Ki 0 1 2 3 4 5 6 7 8s16 9s16 ; do for i in s4Ki 0 1 2 3 4 5 6 7 8 9 ; do
"${LZIP}" -f -$i -o out < in || fail=1 "${LZIP}" -f -$i -s16 -o out < in || fail=1
"${LZIP}" -df -o copy < out.lz || fail=1 "${LZIP}" -df -o copy < out.lz || fail=1
cmp in copy || fail=1 cmp in copy || fail=1
done done
printf . printf .
"${LZIP}" < in > anyothername || fail=1
"${LZIP}" -d anyothername || fail=1
cmp in anyothername.out || fail=1
printf .
cat in in > in2 || framework_failure
"${LZIP}" < in2 > out2 || fail=1
"${LZIP}" -d < out2 > copy2 || fail=1
cmp in2 copy2 || fail=1
printf .
echo echo
if [ ${fail} = 0 ] ; then if [ ${fail} = 0 ] ; then
echo "tests completed successfully." echo "tests completed successfully."

File diff suppressed because it is too large Load diff

Binary file not shown.

Binary file not shown.