summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--COPYING19
-rw-r--r--ChangeLog8
-rw-r--r--INSTALL2
-rw-r--r--Makefile.in10
-rw-r--r--NEWS13
-rw-r--r--README14
-rw-r--r--carg_parser.c9
-rw-r--r--carg_parser.h2
-rwxr-xr-xconfigure21
-rw-r--r--doc/pdlzip.16
-rw-r--r--lzip.h18
-rw-r--r--main.c99
-rwxr-xr-xtestsuite/check.sh233
13 files changed, 270 insertions, 184 deletions
diff --git a/COPYING b/COPYING
new file mode 100644
index 0000000..b741254
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,19 @@
+ Pdlzip - LZMA lossless data compressor
+ Copyright (C) Antonio Diaz Diaz.
+ Pdlzip includes public domain (de)compression code from the LZMA SDK
+ (Software Development Kit) written by Igor Pavlov.
+
+ This program is free software. Redistribution and use in source and
+ 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,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
diff --git a/ChangeLog b/ChangeLog
index b05668d..9d6c5c3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2017-04-12 Antonio Diaz Diaz <antonio@gnu.org>
+
+ * Version 1.8 released.
+ * main.c: Continue testing if any input file is a terminal.
+ * main.c (decompress): Improved detection of trailing data.
+
2016-05-16 Antonio Diaz Diaz <antonio@gnu.org>
* Version 1.7 released.
@@ -67,7 +73,7 @@
* Using LZMA SDK 9.10 (public domain) from Igor Pavlov.
-Copyright (C) 2010-2016 Antonio Diaz Diaz.
+Copyright (C) 2010-2017 Antonio Diaz Diaz.
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
diff --git a/INSTALL b/INSTALL
index bfa113e..419e1af 100644
--- a/INSTALL
+++ b/INSTALL
@@ -61,7 +61,7 @@ After running 'configure', you can run 'make' and 'make install' as
explained above.
-Copyright (C) 2010-2016 Antonio Diaz Diaz.
+Copyright (C) 2010-2017 Antonio Diaz Diaz.
This file is free documentation: you have unlimited permission to copy,
distribute and modify it.
diff --git a/Makefile.in b/Makefile.in
index d028174..e720a0d 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -13,7 +13,8 @@ objs = carg_parser.o LzFind.o LzmaEnc.o LzmaDec.o main.o
.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
all : $(progname)
@@ -106,6 +107,7 @@ dist : doc
ln -sf $(VPATH) $(DISTNAME)
tar -Hustar --owner=root --group=root -cvf $(DISTNAME).tar \
$(DISTNAME)/AUTHORS \
+ $(DISTNAME)/COPYING \
$(DISTNAME)/ChangeLog \
$(DISTNAME)/INSTALL \
$(DISTNAME)/Makefile.in \
@@ -113,12 +115,12 @@ dist : doc
$(DISTNAME)/README \
$(DISTNAME)/configure \
$(DISTNAME)/doc/$(progname).1 \
+ $(DISTNAME)/*.h \
+ $(DISTNAME)/*.c \
$(DISTNAME)/testsuite/check.sh \
$(DISTNAME)/testsuite/test.txt \
$(DISTNAME)/testsuite/test.txt.lz \
- $(DISTNAME)/testsuite/test.txt.lzma \
- $(DISTNAME)/*.h \
- $(DISTNAME)/*.c
+ $(DISTNAME)/testsuite/test.txt.lzma
rm -f $(DISTNAME)
lzip -v -9 $(DISTNAME).tar
diff --git a/NEWS b/NEWS
index 5ffa79b..e1cbb03 100644
--- a/NEWS
+++ b/NEWS
@@ -1,11 +1,6 @@
-Changes in version 1.7:
+Changes in version 1.8:
-The option "-a, --trailing-error", which makes pdlzip exit with error
-status 2 if any remaining input is detected after decompressing the last
-member, has been added.
+In test mode, pdlzip now continues checking the rest of the files if any
+input file is a terminal.
-When decompressing, the file specified with the '--output' option is now
-deleted if the input is a terminal.
-
-A harmless check failure on Windows, caused by the failed comparison of
-a message in text mode, has been fixed.
+Trailing data shorter than a lzip header are now also reported.
diff --git a/README b/README
index ab5e4b1..e392d71 100644
--- a/README
+++ b/README
@@ -20,11 +20,11 @@ availability:
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.
+ 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.
@@ -37,7 +37,7 @@ corrupt byte near the beginning is a thing of the past.
Pdlzip is also able to decompress legacy lzma-alone (.lzma) files.
Lzma-alone is a very bad format; it is essentially a raw LZMA stream.
If you keep any lzma-alone files, it is advisable to recompress them to
-lzip format. Lziprecover can convert lzma-alone files to lzip format
+lzip format. Lziprecover can convert some lzma-alone files to lzip format
without recompressing.
Pdlzip is written in C.
@@ -52,7 +52,7 @@ users of the most non-free platforms can share lzip files with everybody
else.
-Copyright (C) 2010-2016 Antonio Diaz Diaz.
+Copyright (C) 2010-2017 Antonio Diaz Diaz.
This file is free documentation: you have unlimited permission to copy,
distribute and modify it.
diff --git a/carg_parser.c b/carg_parser.c
index 3d4e89f..6850643 100644
--- a/carg_parser.c
+++ b/carg_parser.c
@@ -1,5 +1,5 @@
/* Arg_parser - POSIX/GNU command line argument parser. (C version)
- Copyright (C) 2006-2016 Antonio Diaz Diaz.
+ Copyright (C) 2006-2017 Antonio Diaz Diaz.
This library is free software. Redistribution and use in source and
binary forms, with or without modification, are permitted provided
@@ -94,7 +94,7 @@ static char parse_long_option( struct Arg_parser * const ap,
else if( index < 0 ) index = i; /* First nonexact match found */
else if( options[index].code != options[i].code ||
options[index].has_arg != options[i].has_arg )
- ambig = 1; /* Second or later nonexact match found */
+ ambig = 1; /* Second or later nonexact match found */
}
if( ambig && !exact )
@@ -230,7 +230,9 @@ char ap_init( struct Arg_parser * const ap,
}
else
{
- if( !in_order )
+ if( in_order )
+ { if( !push_back_record( ap, 0, argv[argind++] ) ) return 0; }
+ else
{
void * tmp = ap_resize_buffer( non_options,
( non_options_size + 1 ) * sizeof *non_options );
@@ -238,7 +240,6 @@ char ap_init( struct Arg_parser * const ap,
non_options = (const char **)tmp;
non_options[non_options_size++] = argv[argind++];
}
- else if( !push_back_record( ap, 0, argv[argind++] ) ) return 0;
}
}
if( ap->error ) free_data( ap );
diff --git a/carg_parser.h b/carg_parser.h
index e918942..c4ce31d 100644
--- a/carg_parser.h
+++ b/carg_parser.h
@@ -1,5 +1,5 @@
/* Arg_parser - POSIX/GNU command line argument parser. (C version)
- Copyright (C) 2006-2016 Antonio Diaz Diaz.
+ Copyright (C) 2006-2017 Antonio Diaz Diaz.
This library is free software. Redistribution and use in source and
binary forms, with or without modification, are permitted provided
diff --git a/configure b/configure
index cab895f..4380dac 100755
--- a/configure
+++ b/configure
@@ -1,12 +1,12 @@
#! /bin/sh
# configure script for Pdlzip - LZMA lossless data compressor
-# Copyright (C) 2010-2016 Antonio Diaz Diaz.
+# Copyright (C) 2010-2017 Antonio Diaz Diaz.
#
# This configure script is free software: you have unlimited permission
# to copy, distribute and modify it.
pkgname=pdlzip
-pkgversion=1.7
+pkgversion=1.8
progname=pdlzip
srctrigger=doc/${progname}.1
@@ -26,11 +26,11 @@ CFLAGS='-Wall -W -O2'
LDFLAGS=
# checking whether we are using GNU C.
-if /bin/sh -c "${CC} --version" > /dev/null 2>&1 ; then true
-else
+/bin/sh -c "${CC} --version" > /dev/null 2>&1 ||
+ {
CC=cc
- CFLAGS='-W -O2'
-fi
+ CFLAGS=-O2
+ }
# Loop over all args
args=
@@ -52,9 +52,12 @@ while [ $# != 0 ] ; do
# Process the options
case ${option} in
--help | -h)
- echo "Usage: configure [options]"
+ echo "Usage: $0 [OPTION]... [VAR=VALUE]..."
+ echo
+ echo "To assign makefile variables (e.g., CC, CFLAGS...), specify them as"
+ echo "arguments to configure in the form VAR=VALUE."
echo
- echo "Options: [defaults in brackets]"
+ echo "Options and variables: [defaults in brackets]"
echo " -h, --help display this help and exit"
echo " -V, --version output version information and exit"
echo " --srcdir=DIR find the sources in DIR [. or ..]"
@@ -165,7 +168,7 @@ echo "LDFLAGS = ${LDFLAGS}"
rm -f Makefile
cat > Makefile << EOF
# Makefile for Pdlzip - LZMA lossless data compressor
-# Copyright (C) 2010-2016 Antonio Diaz Diaz.
+# Copyright (C) 2010-2017 Antonio Diaz Diaz.
# This file was generated automatically by configure. Don't edit.
#
# This Makefile is free software: you have unlimited permission
diff --git a/doc/pdlzip.1 b/doc/pdlzip.1
index 8e76b32..155e5c5 100644
--- a/doc/pdlzip.1
+++ b/doc/pdlzip.1
@@ -1,5 +1,5 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.46.1.
-.TH PDLZIP "1" "May 2016" "pdlzip 1.7" "User Commands"
+.TH PDLZIP "1" "April 2017" "pdlzip 1.8" "User Commands"
.SH NAME
pdlzip \- reduces the size of files
.SH SYNOPSIS
@@ -11,7 +11,7 @@ compressor also able to decompress legacy lzma\-alone (.lzma) files.
.PP
Lzma\-alone is a very bad format; it is essentially a raw LZMA stream.
If you keep any lzma\-alone files, it is advisable to recompress them to
-lzip format. Lziprecover can convert lzma\-alone files to lzip format
+lzip format. Lziprecover can convert some lzma\-alone files to lzip format
without recompressing.
.SH OPTIONS
.TP
@@ -88,7 +88,7 @@ Report bugs to lzip\-bug@nongnu.org
.br
Pdlzip home page: http://www.nongnu.org/lzip/pdlzip.html
.SH COPYRIGHT
-Copyright \(co 2016 Antonio Diaz Diaz.
+Copyright \(co 2017 Antonio Diaz Diaz.
Public Domain 2009 Igor Pavlov.
License 2\-clause BSD.
.br
diff --git a/lzip.h b/lzip.h
index f84c53c..631599d 100644
--- a/lzip.h
+++ b/lzip.h
@@ -1,5 +1,5 @@
/* Pdlzip - LZMA lossless data compressor
- Copyright (C) 2010-2016 Antonio Diaz Diaz.
+ Copyright (C) 2010-2017 Antonio Diaz Diaz.
This program is free software. Redistribution and use in source and
binary forms, with or without modification, are permitted provided
@@ -29,8 +29,10 @@ typedef int State;
enum {
min_dictionary_bits = 12,
min_dictionary_size = 1 << min_dictionary_bits,
- max_dictionary_bits = 27, /* kDicLogSizeMaxCompress */
+ max_dictionary_bits = 29,
max_dictionary_size = 1 << max_dictionary_bits,
+ max_dictionary_bits_c = 27, /* kDicLogSizeMaxCompress */
+ max_dictionary_size_c = 1 << max_dictionary_bits_c,
literal_context_bits = 3,
literal_pos_state_bits = 0, /* not used */
pos_state_bits = 2,
@@ -66,9 +68,9 @@ static inline void Pp_init( struct Pretty_print * const pp,
pp->stdin_name = "(stdin)";
pp->longest_name = 0;
pp->first_post = false;
- stdin_name_len = strlen( pp->stdin_name );
if( verbosity <= 0 ) return;
+ stdin_name_len = strlen( pp->stdin_name );
for( i = 0; i < num_filenames; ++i )
{
const char * const s = filenames[i];
@@ -114,8 +116,10 @@ static inline void CRC32_update_buf( uint32_t * const crc,
const int size )
{
int i;
+ uint32_t c = *crc;
for( i = 0; i < size; ++i )
- *crc = crc32[(*crc^buffer[i])&0xFF] ^ ( *crc >> 8 );
+ c = crc32[(c^buffer[i])&0xFF] ^ ( c >> 8 );
+ *crc = c;
}
@@ -175,7 +179,7 @@ static inline bool Fh_set_dictionary_size( File_header data, const unsigned sz )
{
const unsigned base_size = 1 << data[5];
const unsigned fraction = base_size / 16;
- int i;
+ unsigned i;
for( i = 7; i >= 1; --i )
if( base_size - ( i * fraction ) >= sz )
{ data[5] |= ( i << 5 ); break; }
@@ -222,6 +226,8 @@ 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; } }
+static const char * const trailing_msg = "Trailing data not allowed.";
+
/* defined in main.c */
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 );
@@ -230,6 +236,8 @@ int writeblock( const int fd, const uint8_t * const buf, const int size );
extern int verbosity;
void cleanup_and_fail( const int retval );
void show_error( const char * const msg, const int errcode, const bool help );
+void show_file_error( const char * const filename, const char * const msg,
+ const int errcode );
void internal_error( const char * const msg );
#define SZ_OK 0
diff --git a/main.c b/main.c
index 5e09fe0..de8e12e 100644
--- a/main.c
+++ b/main.c
@@ -1,6 +1,6 @@
/* Pdlzip - LZMA lossless data compressor
2009-08-14 : Igor Pavlov : Public domain
- Copyright (C) 2010-2016 Antonio Diaz Diaz.
+ Copyright (C) 2010-2017 Antonio Diaz Diaz.
This program is free software. Redistribution and use in source and
binary forms, with or without modification, are permitted provided
@@ -70,10 +70,10 @@ int verbosity = 0;
const char * const Program_name = "Pdlzip";
const char * const program_name = "pdlzip";
-const char * const program_year = "2016";
+const char * const program_year = "2017";
const char * invocation_name = 0;
-struct { const char * from; const char * to; } const known_extensions[] = {
+const struct { const char * from; const char * to; } known_extensions[] = {
{ ".lz", "" },
{ ".tlz", ".tar" },
{ ".lzma", "" },
@@ -98,7 +98,7 @@ static void show_help( void )
printf( "compressor also able to decompress legacy lzma-alone (.lzma) files.\n"
"\nLzma-alone is a very bad format; it is essentially a raw LZMA stream.\n"
"If you keep any lzma-alone files, it is advisable to recompress them to\n"
- "lzip format. Lziprecover can convert lzma-alone files to lzip format\n"
+ "lzip format. Lziprecover can convert some lzma-alone files to lzip format\n"
"without recompressing.\n"
"\nUsage: %s [options] [files]\n", invocation_name );
printf( "\nOptions:\n"
@@ -154,9 +154,9 @@ static void show_header( const unsigned dictionary_size )
{
if( verbosity >= 3 )
{
+ enum { factor = 1024 };
const char * const prefix[8] =
{ "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi", "Yi" };
- enum { factor = 1024 };
const char * p = "";
const char * np = " ";
unsigned num = dictionary_size, i;
@@ -165,7 +165,7 @@ static void show_header( const unsigned dictionary_size )
for( i = 0; i < 8 && ( num > 9999 || ( exact && num >= factor ) ); ++i )
{ num /= factor; if( num % factor != 0 ) exact = false;
p = prefix[i]; np = ""; }
- fprintf( stderr, "dictionary size %s%4u %sB. ", np, num, p );
+ fprintf( stderr, "dictionary %s%4u %sB. ", np, num, p );
}
}
@@ -186,7 +186,7 @@ static unsigned long getnum( const char * const ptr,
if( !errno && tail[0] )
{
- const int factor = ( tail[1] == 'i' ) ? 1024 : 1000;
+ const unsigned factor = ( tail[1] == 'i' ) ? 1024 : 1000;
int exponent = 0; /* 0 = bad multiplier */
int i;
switch( tail[0] )
@@ -225,25 +225,25 @@ static unsigned long getnum( const char * const ptr,
static int get_dict_size( const char * const arg )
{
char * tail;
- const int bits = strtol( arg, &tail, 0 );
+ const long bits = strtol( arg, &tail, 0 );
if( bits >= min_dictionary_bits &&
- bits <= max_dictionary_bits && *tail == 0 )
+ bits <= max_dictionary_bits_c && *tail == 0 )
return ( 1 << bits );
- return getnum( arg, min_dictionary_size, max_dictionary_size );
+ return getnum( arg, min_dictionary_size, max_dictionary_size_c );
}
static int extension_index( const char * const name )
{
- int i;
- for( i = 0; known_extensions[i].from; ++i )
+ int eindex;
+ for( eindex = 0; known_extensions[eindex].from; ++eindex )
{
- const char * const ext = known_extensions[i].from;
+ const char * const ext = known_extensions[eindex].from;
const unsigned name_len = strlen( name );
const unsigned ext_len = strlen( ext );
if( name_len > ext_len &&
strncmp( name + name_len - ext_len, ext, ext_len ) == 0 )
- return i;
+ return eindex;
}
return -1;
}
@@ -264,11 +264,7 @@ static int open_instream( const char * const name, struct stat * const in_statsp
{
infd = open( name, O_RDONLY | O_BINARY );
if( infd < 0 )
- {
- if( verbosity >= 0 )
- fprintf( stderr, "%s: Can't open input file '%s': %s\n",
- program_name, name, strerror( errno ) );
- }
+ show_file_error( name, "Can't open input file", errno );
else
{
const int i = fstat( infd, in_statsp );
@@ -294,7 +290,7 @@ static int open_instream( const char * const name, struct stat * const in_statsp
/* assure at least a minimum size for buffer 'buf' */
-static void * resize_buffer( void * buf, const int min_size )
+static void * resize_buffer( void * buf, const unsigned min_size )
{
if( buf ) buf = realloc( buf, min_size );
else buf = malloc( min_size );
@@ -316,19 +312,19 @@ 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 eindex )
{
const unsigned name_len = strlen( name );
- if( i >= 0 )
+ if( eindex >= 0 )
{
- const char * const from = known_extensions[i].from;
+ const char * const from = known_extensions[eindex].from;
const unsigned from_len = strlen( from );
if( name_len > from_len )
{
output_filename = resize_buffer( output_filename, name_len +
- strlen( known_extensions[0].to ) + 1 );
+ strlen( known_extensions[eindex].to ) + 1 );
strcpy( output_filename, name );
- strcpy( output_filename + name_len - from_len, known_extensions[i].to );
+ strcpy( output_filename + name_len - from_len, known_extensions[eindex].to );
return;
}
}
@@ -364,7 +360,8 @@ static bool open_outstream( const bool force, const bool from_stdin )
}
-static bool check_tty( const int infd, const enum Mode program_mode )
+static bool check_tty( const char * const input_filename, const int infd,
+ const enum Mode program_mode )
{
if( program_mode == m_compress && isatty( outfd ) )
{
@@ -374,7 +371,8 @@ static bool check_tty( const int infd, const enum Mode program_mode )
if( ( program_mode == m_decompress || program_mode == m_test ) &&
isatty( infd ) )
{
- show_error( "I won't read compressed data from a terminal.", 0, true );
+ show_file_error( input_filename,
+ "I won't read compressed data from a terminal.", 0 );
return false;
}
return true;
@@ -432,7 +430,7 @@ static void close_and_set_permissions( const struct stat * const in_statsp )
static int compress( const struct Lzma_options * const encoder_options,
- const int infd, struct Pretty_print * const pp )
+ struct Pretty_print * const pp, const int infd )
{
int retval = 0;
CLzmaEncHandle encoder = 0;
@@ -604,9 +602,8 @@ static int lzip_decode( CLzmaDec *decoder, const int infd, uint8_t inBuf[],
{
error = true;
if( verbosity >= 0 )
- fprintf( stderr, "Trailer truncated at trailer position %u;"
- " some checks may fail.\n",
- (unsigned)(*inSize - *inPos) );
+ fprintf( stderr, "Trailer truncated at trailer position %d;"
+ " some checks may fail.\n", *inSize - *inPos );
for( i = *inSize - *inPos; i < Ft_size; ++i )
inBuf[*inPos+i] = 0;
}
@@ -641,7 +638,7 @@ static int lzip_decode( CLzmaDec *decoder, const int infd, uint8_t inBuf[],
( 8.0 * total_in ) / total_out,
100.0 * ( 1.0 - ( (double)total_in / total_out ) ) );
if( !error && verbosity >= 4 )
- fprintf( stderr, "data CRC %08X, data size %9llu, member size %8llu. ",
+ fprintf( stderr, "CRC %08X, decompressed %9llu, compressed %8llu. ",
crc, total_out, total_in );
if( error ) return 2;
return 0;
@@ -677,6 +674,8 @@ static int decompress( const int infd, struct Pretty_print * const pp,
if( first_member || Fh_verify_prefix( header, size ) )
{ Pp_show_msg( pp, "File ends unexpectedly at member header." );
retval = 2; }
+ else if( size > 0 && !ignore_trailing )
+ { show_file_error( pp->name, trailing_msg, 0 ); retval = 2; }
break;
}
if( !Fh_verify_magic( header ) )
@@ -684,7 +683,7 @@ static int decompress( const int infd, struct Pretty_print * const pp,
if( !first_member )
{
if( !ignore_trailing )
- { Pp_show_msg( pp, "Trailing data not allowed." ); retval = 2; }
+ { show_file_error( pp->name, trailing_msg, 0 ); retval = 2; }
break;
}
if( inSize - inPos >= lzma_header_size - Fh_size ) /* try lzma-alone */
@@ -704,7 +703,8 @@ static int decompress( const int infd, struct Pretty_print * const pp,
}
if( lzip_mode )
{
- Pp_show_msg( pp, "Bad magic number (file not in lzip format)." );
+ show_file_error( pp->name,
+ "Bad magic number (file not in lzip format).", 0 );
retval = 2; break;
}
}
@@ -839,6 +839,16 @@ void show_error( const char * const msg, const int errcode, const bool help )
}
+void show_file_error( const char * const filename, const char * const msg,
+ const int errcode )
+ {
+ if( verbosity < 0 ) return;
+ fprintf( stderr, "%s: %s: %s", program_name, filename, msg );
+ if( errcode > 0 ) fprintf( stderr, ": %s", strerror( errcode ) );
+ fputc( '\n', stderr );
+ }
+
+
void internal_error( const char * const msg )
{
if( verbosity >= 0 )
@@ -864,7 +874,6 @@ int main( const int argc, const char * const argv[] )
{ 3 << 23, 132 }, /* -8 */
{ 1 << 25, 273 } }; /* -9 */
struct Lzma_options encoder_options = option_mapping[6]; /* default = "-6" */
- const char * input_filename = "";
const char * default_output_filename = "";
const char ** filenames = 0;
int num_filenames = 0;
@@ -877,8 +886,8 @@ int main( const int argc, const char * const argv[] )
bool force = false;
bool ignore_trailing = true;
bool keep_input_files = false;
- bool stdin_used = false;
bool recompress = false;
+ bool stdin_used = false;
bool to_stdout = false;
struct Pretty_print pp;
@@ -961,9 +970,6 @@ int main( const int argc, const char * const argv[] )
setmode( STDOUT_FILENO, O_BINARY );
#endif
- if( program_mode == m_test )
- outfd = -1;
-
num_filenames = max( 1, ap_arguments( &parser ) - argind );
filenames = resize_buffer( filenames, num_filenames * sizeof filenames[0] );
filenames[0] = "-";
@@ -974,6 +980,9 @@ int main( const int argc, const char * const argv[] )
if( strcmp( filenames[i], "-" ) != 0 ) filenames_given = true;
}
+ if( program_mode == m_test )
+ outfd = -1;
+
if( !to_stdout && program_mode != m_test &&
( filenames_given || default_output_filename[0] ) )
set_signals();
@@ -983,6 +992,7 @@ int main( const int argc, const char * const argv[] )
output_filename = resize_buffer( output_filename, 1 );
for( i = 0; i < num_filenames; ++i )
{
+ const char * input_filename = "";
int tmp;
struct stat in_stats;
const struct stat * in_statsp;
@@ -991,7 +1001,6 @@ int main( const int argc, const char * const argv[] )
if( !filenames[i][0] || strcmp( filenames[i], "-" ) == 0 )
{
if( stdin_used ) continue; else stdin_used = true;
- input_filename = "";
infd = STDIN_FILENO;
if( program_mode != m_test )
{
@@ -1018,8 +1027,7 @@ int main( const int argc, const char * const argv[] )
}
else
{
- const int eindex = extension_index( filenames[i] );
- input_filename = filenames[i];
+ const int eindex = extension_index( input_filename = filenames[i] );
infd = open_instream( input_filename, &in_stats, program_mode,
eindex, recompress, to_stdout );
if( infd < 0 ) { if( retval < 1 ) retval = 1; continue; }
@@ -1041,16 +1049,17 @@ int main( const int argc, const char * const argv[] )
}
}
- if( !check_tty( infd, program_mode ) )
+ Pp_set_name( &pp, input_filename );
+ if( !check_tty( pp.name, infd, program_mode ) )
{
if( retval < 1 ) retval = 1;
+ if( program_mode == m_test ) { close( infd ); infd = -1; continue; }
cleanup_and_fail( retval );
}
in_statsp = input_filename[0] ? &in_stats : 0;
- Pp_set_name( &pp, input_filename );
if( program_mode == m_compress )
- tmp = compress( &encoder_options, infd, &pp );
+ tmp = compress( &encoder_options, &pp, infd );
else
tmp = decompress( infd, &pp, ignore_trailing, program_mode == m_test );
if( tmp > retval ) retval = tmp;
diff --git a/testsuite/check.sh b/testsuite/check.sh
index 1147256..82e609a 100755
--- a/testsuite/check.sh
+++ b/testsuite/check.sh
@@ -1,6 +1,6 @@
#! /bin/sh
# check script for Pdlzip - LZMA lossless data compressor
-# Copyright (C) 2010-2016 Antonio Diaz Diaz.
+# Copyright (C) 2010-2017 Antonio Diaz Diaz.
#
# This script is free software: you have unlimited permission
# to copy, distribute and modify it.
@@ -17,12 +17,12 @@ if [ ! -f "${LZIP}" ] || [ ! -x "${LZIP}" ] ; then
exit 1
fi
-if [ -e "${LZIP}" ] 2> /dev/null ; then true
-else
+[ -e "${LZIP}" ] 2> /dev/null ||
+ {
echo "$0: a POSIX shell is required to run the tests"
echo "Try bash -c \"$0 $1 $2\""
exit 1
-fi
+ }
if [ -d tmp ] ; then rm -rf tmp ; fi
mkdir tmp
@@ -31,149 +31,192 @@ cd "${objdir}"/tmp || framework_failure
cat "${testdir}"/test.txt > in || framework_failure
in_lz="${testdir}"/test.txt.lz
fail=0
+test_failed() { fail=1 ; printf " $1" ; [ -z "$2" ] || printf "($2)" ; }
printf "testing pdlzip-%s..." "$2"
"${LZIP}" -fkqm4 in
-if [ $? = 1 ] && [ ! -e in.lz ] ; then printf . ; else printf - ; fail=1 ; fi
+{ [ $? = 1 ] && [ ! -e in.lz ] ; } || test_failed $LINENO
"${LZIP}" -fkqm274 in
-if [ $? = 1 ] && [ ! -e in.lz ] ; then printf . ; else printf - ; fail=1 ; fi
-"${LZIP}" -fkqs-1 in
-if [ $? = 1 ] && [ ! -e in.lz ] ; then printf . ; else printf - ; fail=1 ; fi
-"${LZIP}" -fkqs0 in
-if [ $? = 1 ] && [ ! -e in.lz ] ; then printf . ; else printf - ; fail=1 ; fi
-"${LZIP}" -fkqs4095 in
-if [ $? = 1 ] && [ ! -e in.lz ] ; then printf . ; else printf - ; fail=1 ; fi
-"${LZIP}" -fkqs513MiB in
-if [ $? = 1 ] && [ ! -e in.lz ] ; then printf . ; else printf - ; fail=1 ; fi
+{ [ $? = 1 ] && [ ! -e in.lz ] ; } || test_failed $LINENO
+for i in bad_size -1 0 4095 513MiB 1G 1T 1P 1E 1Z 1Y 10KB ; do
+ "${LZIP}" -fkqs $i in
+ { [ $? = 1 ] && [ ! -e in.lz ] ; } || test_failed $LINENO $i
+done
"${LZIP}" -tq in
-if [ $? = 2 ] ; then printf . ; else printf - ; fail=1 ; fi
+[ $? = 2 ] || test_failed $LINENO
"${LZIP}" -tq < in
-if [ $? = 2 ] ; then printf . ; else printf - ; fail=1 ; fi
+[ $? = 2 ] || test_failed $LINENO
"${LZIP}" -cdq in
-if [ $? = 2 ] ; then printf . ; else printf - ; fail=1 ; fi
+[ $? = 2 ] || test_failed $LINENO
"${LZIP}" -cdq < in
-if [ $? = 2 ] ; then printf . ; else printf - ; fail=1 ; fi
-dd if="${in_lz}" bs=1 count=6 2> /dev/null | "${LZIP}" -tq
-if [ $? = 2 ] ; then printf . ; else printf - ; fail=1 ; fi
-dd if="${in_lz}" bs=1 count=20 2> /dev/null | "${LZIP}" -tq
-if [ $? = 2 ] ; then printf . ; else printf - ; fail=1 ; fi
+[ $? = 2 ] || test_failed $LINENO
+# these are for code coverage
+"${LZIP}" -t -- nx_file 2> /dev/null
+[ $? = 1 ] || test_failed $LINENO
+"${LZIP}" --help > /dev/null || test_failed $LINENO
+"${LZIP}" -n1 -V > /dev/null || test_failed $LINENO
+"${LZIP}" -m 2> /dev/null
+[ $? = 1 ] || test_failed $LINENO
+"${LZIP}" -z 2> /dev/null
+[ $? = 1 ] || test_failed $LINENO
+"${LZIP}" --bad_option 2> /dev/null
+[ $? = 1 ] || test_failed $LINENO
+"${LZIP}" --t 2> /dev/null
+[ $? = 1 ] || test_failed $LINENO
+"${LZIP}" --test=2 2> /dev/null
+[ $? = 1 ] || test_failed $LINENO
+"${LZIP}" --output= 2> /dev/null
+[ $? = 1 ] || test_failed $LINENO
+"${LZIP}" --output 2> /dev/null
+[ $? = 1 ] || test_failed $LINENO
+printf "LZIP\001-.............................." | "${LZIP}" -t 2> /dev/null
+printf "LZIP\002-.............................." | "${LZIP}" -t 2> /dev/null
+printf "LZIP\001+.............................." | "${LZIP}" -t 2> /dev/null
printf "\ntesting decompression..."
-"${LZIP}" -t "${in_lz}"
-if [ $? = 0 ] ; then printf . ; else printf - ; fail=1 ; fi
-"${LZIP}" -cd "${in_lz}" > copy || fail=1
-cmp in copy || fail=1
-printf .
+"${LZIP}" -t "${in_lz}" || test_failed $LINENO
+"${LZIP}" -cd "${in_lz}" > copy || test_failed $LINENO
+cmp in copy || test_failed $LINENO
-"${LZIP}" -t "${testdir}"/test.txt.lzma
-if [ $? = 0 ] ; then printf . ; else printf - ; fail=1 ; fi
-"${LZIP}" -cd "${testdir}"/test.txt.lzma > copy || fail=1
-cmp in copy || fail=1
-printf .
+"${LZIP}" -t "${testdir}"/test.txt.lzma || test_failed $LINENO
+"${LZIP}" -cd "${testdir}"/test.txt.lzma > copy || test_failed $LINENO
+cmp in copy || test_failed $LINENO
rm -f copy
cat "${in_lz}" > copy.lz || framework_failure
-"${LZIP}" -dk copy.lz || fail=1
-cmp in copy || fail=1
+"${LZIP}" -dk copy.lz || test_failed $LINENO
+cmp in copy || test_failed $LINENO
printf "to be overwritten" > copy || framework_failure
-"${LZIP}" -dq copy.lz
-if [ $? = 1 ] ; then printf . ; else printf - ; fail=1 ; fi
+"${LZIP}" -d copy.lz 2> /dev/null
+[ $? = 1 ] || test_failed $LINENO
"${LZIP}" -df copy.lz
-if [ $? = 0 ] && [ ! -e copy.lz ] && cmp in copy ; then
- printf . ; else printf - ; fail=1 ; fi
+{ [ $? = 0 ] && [ ! -e copy.lz ] && cmp in copy ; } || test_failed $LINENO
printf "to be overwritten" > copy || framework_failure
-"${LZIP}" -df -o copy < "${in_lz}" || fail=1
-cmp in copy || fail=1
-printf .
+"${LZIP}" -df -o copy < "${in_lz}" || test_failed $LINENO
+cmp in copy || test_failed $LINENO
rm -f copy
-"${LZIP}" -s16 < in > anyothername || fail=1
-"${LZIP}" -d -o copy - anyothername - < "${in_lz}"
-if [ $? = 0 ] && cmp in copy && cmp in anyothername.out ; then
- printf . ; else printf - ; fail=1 ; fi
+"${LZIP}" -s16 < in > anyothername || test_failed $LINENO
+"${LZIP}" -dv --output copy - anyothername - < "${in_lz}" 2> /dev/null
+{ [ $? = 0 ] && cmp in copy && cmp in anyothername.out ; } ||
+ test_failed $LINENO
rm -f copy anyothername.out
"${LZIP}" -tq in "${in_lz}"
-if [ $? = 2 ] ; then printf . ; else printf - ; fail=1 ; fi
-"${LZIP}" -tq foo.lz "${in_lz}"
-if [ $? = 1 ] ; then printf . ; else printf - ; fail=1 ; fi
+[ $? = 2 ] || test_failed $LINENO
+"${LZIP}" -tq nx_file.lz "${in_lz}"
+[ $? = 1 ] || test_failed $LINENO
"${LZIP}" -cdq in "${in_lz}" > copy
-if [ $? = 2 ] && cat copy in | cmp in - ; then printf . ; else printf - ; fail=1 ; fi
-"${LZIP}" -cdq foo.lz "${in_lz}" > copy
-if [ $? = 1 ] && cmp in copy ; then printf . ; else printf - ; fail=1 ; fi
+{ [ $? = 2 ] && cat copy in | cmp in - ; } || test_failed $LINENO
+"${LZIP}" -cdq nx_file.lz "${in_lz}" > copy
+{ [ $? = 1 ] && cmp in copy ; } || test_failed $LINENO
rm -f copy
cat "${in_lz}" > copy.lz || framework_failure
+for i in 1 2 3 4 5 6 7 ; do
+ printf "g" >> copy.lz || framework_failure
+ "${LZIP}" -atvvvv copy.lz "${in_lz}" 2> /dev/null
+ [ $? = 2 ] || test_failed $LINENO $i
+done
"${LZIP}" -dq in copy.lz
-if [ $? = 2 ] && [ -e copy.lz ] && [ ! -e copy ] && [ ! -e in.out ] ; then
- printf . ; else printf - ; fail=1 ; fi
-"${LZIP}" -dq foo.lz copy.lz
-if [ $? = 1 ] && [ ! -e copy.lz ] && [ ! -e foo ] && cmp in copy ; then
- printf . ; else printf - ; fail=1 ; fi
+{ [ $? = 2 ] && [ -e copy.lz ] && [ ! -e copy ] && [ ! -e in.out ] ; } ||
+ test_failed $LINENO
+"${LZIP}" -dq nx_file.lz copy.lz
+{ [ $? = 1 ] && [ ! -e copy.lz ] && [ ! -e nx_file ] && cmp in copy ; } ||
+ test_failed $LINENO
cat in in > in2 || framework_failure
-"${LZIP}" -s16 -o copy2 < in2 || fail=1
-"${LZIP}" -t copy2.lz || fail=1
-"${LZIP}" -cd copy2.lz > copy2 || fail=1
-cmp in2 copy2 || fail=1
-printf .
-
-printf "garbage" >> copy2.lz || framework_failure
+cat "${in_lz}" "${in_lz}" > in2.lz || framework_failure
+"${LZIP}" -t in2.lz || test_failed $LINENO
+"${LZIP}" -cd in2.lz > copy2 || test_failed $LINENO
+cmp in2 copy2 || test_failed $LINENO
+
+"${LZIP}" -s16 --output=copy2 < in2 || test_failed $LINENO
+"${LZIP}" -t copy2.lz || test_failed $LINENO
+"${LZIP}" -cd copy2.lz > copy2 || test_failed $LINENO
+cmp in2 copy2 || test_failed $LINENO
+
+printf "\ngarbage" >> copy2.lz || framework_failure
+"${LZIP}" -tvvvv copy2.lz 2> /dev/null || test_failed $LINENO
rm -f copy2
"${LZIP}" -atq copy2.lz
-if [ $? = 2 ] ; then printf . ; else printf - ; fail=1 ; fi
+[ $? = 2 ] || test_failed $LINENO
"${LZIP}" -atq < copy2.lz
-if [ $? = 2 ] ; then printf . ; else printf - ; fail=1 ; fi
+[ $? = 2 ] || test_failed $LINENO
"${LZIP}" -adkq copy2.lz
-if [ $? = 2 ] && [ ! -e copy2 ] ; then printf . ; else printf - ; fail=1 ; fi
+{ [ $? = 2 ] && [ ! -e copy2 ] ; } || test_failed $LINENO
"${LZIP}" -adkq -o copy2 < copy2.lz
-if [ $? = 2 ] && [ ! -e copy2 ] ; then printf . ; else printf - ; fail=1 ; fi
+{ [ $? = 2 ] && [ ! -e copy2 ] ; } || test_failed $LINENO
printf "to be overwritten" > copy2 || framework_failure
-"${LZIP}" -df copy2.lz || fail=1
-cmp in2 copy2 || fail=1
-printf .
+"${LZIP}" -df copy2.lz || test_failed $LINENO
+cmp in2 copy2 || test_failed $LINENO
printf "\ntesting compression..."
-"${LZIP}" -cfq "${in_lz}" > out # /dev/null is a tty on OS/2
-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 .
+"${LZIP}" -cf "${in_lz}" > out 2> /dev/null # /dev/null is a tty on OS/2
+[ $? = 1 ] || test_failed $LINENO
+"${LZIP}" -cFvvm36 -s16 "${in_lz}" > out 2> /dev/null || test_failed $LINENO
+"${LZIP}" -cd out | "${LZIP}" -d > copy || test_failed $LINENO
+cmp in copy || test_failed $LINENO
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
- printf "garbage" >> copy.lz || fail=1
- "${LZIP}" -df copy.lz || fail=1
- cmp in copy || fail=1
+ "${LZIP}" -k -$i -s16 in || test_failed $LINENO $i
+ mv -f in.lz copy.lz || test_failed $LINENO $i
+ printf "garbage" >> copy.lz || framework_failure
+ "${LZIP}" -df copy.lz || test_failed $LINENO $i
+ cmp in copy || test_failed $LINENO $i
done
-printf .
for i in s4Ki 0 1 2 3 4 5 6 7 8 9 ; do
- "${LZIP}" -c -$i -s16 in > out || fail=1
- printf "g" >> out || fail=1
- "${LZIP}" -cd out > copy || fail=1
- cmp in copy || fail=1
+ "${LZIP}" -c -$i -s16 in > out || test_failed $LINENO $i
+ printf "g" >> out || framework_failure
+ "${LZIP}" -cd out > copy || test_failed $LINENO $i
+ cmp in copy || test_failed $LINENO $i
done
-printf .
for i in s4Ki 0 1 2 3 4 5 6 7 8 9 ; do
- "${LZIP}" -$i -s16 < in > out || fail=1
- "${LZIP}" -d < out > copy || fail=1
- cmp in copy || fail=1
+ "${LZIP}" -$i -s16 < in > out || test_failed $LINENO $i
+ "${LZIP}" -d < out > copy || test_failed $LINENO $i
+ cmp in copy || test_failed $LINENO $i
done
-printf .
for i in s4Ki 0 1 2 3 4 5 6 7 8 9 ; do
- "${LZIP}" -f -$i -s16 -o out < in || fail=1
- "${LZIP}" -df -o copy < out.lz || fail=1
- cmp in copy || fail=1
+ "${LZIP}" -f -$i -s16 -o out < in || test_failed $LINENO $i
+ "${LZIP}" -df -o copy < out.lz || test_failed $LINENO $i
+ cmp in copy || test_failed $LINENO $i
done
-printf .
+
+printf "\ntesting bad input..."
+
+cat "${in_lz}" "${in_lz}" "${in_lz}" > in3.lz || framework_failure
+if dd if=in3.lz of=trunc.lz bs=14752 count=1 2> /dev/null &&
+ [ -e trunc.lz ] && cmp in2.lz trunc.lz > /dev/null 2>&1 ; then
+ for i in 6 20 14734 14753 14754 14755 14756 14757 14758 ; do
+ dd if=in3.lz of=trunc.lz bs=$i count=1 2> /dev/null
+ "${LZIP}" -t trunc.lz 2> /dev/null
+ [ $? = 2 ] || test_failed $LINENO $i
+ "${LZIP}" -tq < trunc.lz
+ [ $? = 2 ] || test_failed $LINENO $i
+ "${LZIP}" -cdq trunc.lz > out
+ [ $? = 2 ] || test_failed $LINENO $i
+ "${LZIP}" -dq < trunc.lz > out
+ [ $? = 2 ] || test_failed $LINENO $i
+ done
+else
+ printf "\nwarning: skipping truncation test: 'dd' does not work on your system."
+fi
+
+cat "${in_lz}" > ingin.lz || framework_failure
+printf "g" >> ingin.lz || framework_failure
+cat "${in_lz}" >> ingin.lz || framework_failure
+"${LZIP}" -t ingin.lz || test_failed $LINENO
+"${LZIP}" -cd ingin.lz > copy || test_failed $LINENO
+cmp in copy || test_failed $LINENO
+"${LZIP}" -t < ingin.lz || test_failed $LINENO
+"${LZIP}" -d < ingin.lz > copy || test_failed $LINENO
+cmp in copy || test_failed $LINENO
echo
if [ ${fail} = 0 ] ; then