summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--Makefile.in6
-rw-r--r--NEWS16
-rwxr-xr-xconfigure14
-rw-r--r--doc/zcat.12
-rw-r--r--doc/zcmp.12
-rw-r--r--doc/zdiff.12
-rw-r--r--doc/zgrep.12
-rw-r--r--doc/ztest.12
-rw-r--r--doc/zutils.info18
-rw-r--r--doc/zutils.texinfo4
-rw-r--r--main.cc10
-rw-r--r--zcat.cc9
-rw-r--r--zcmp.cc20
-rw-r--r--zdiff.cc42
-rw-r--r--zgrep.cc22
-rw-r--r--ztest.cc24
-rw-r--r--zutils.cc53
-rw-r--r--zutils.h4
19 files changed, 126 insertions, 131 deletions
diff --git a/ChangeLog b/ChangeLog
index 54282fe..681e746 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2010-11-20 Antonio Diaz Diaz <ant_diaz@teleline.es>
+
+ * Version 0.9-rc1 released.
+ * configure: Added new options "DIFF" and "GREP".
+
2010-11-15 Antonio Diaz Diaz <ant_diaz@teleline.es>
* Version 0.8 released.
diff --git a/Makefile.in b/Makefile.in
index 4a04228..2fc8ccb 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -51,6 +51,12 @@ ztest : ztest.in
cat $(VPATH)/ztest.in > ztest
chmod a+x ztest
+main.o : main.cc
+ $(CXX) $(CPPFLAGS) $(CXXFLAGS) -DGREP=\"$(GREP)\" -c -o $@ $<
+
+zdiff.o : zdiff.cc
+ $(CXX) $(CPPFLAGS) $(CXXFLAGS) -DDIFF=\"$(DIFF)\" -c -o $@ $<
+
zutils.o : zutils.cc
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -DPROGVERSION=\"$(pkgversion)\" -c -o $@ $<
diff --git a/NEWS b/NEWS
index cf6500b..16d3c00 100644
--- a/NEWS
+++ b/NEWS
@@ -1,15 +1,3 @@
-Changes in version 0.8:
+Changes in version 0.9:
-The option "--recursive" has been added to zgrep.
-
-All the utilities have been rewritten in C++, making them safer and more
-efficient.
-
-Zcat and zcmp implement the functionality of cat and cmp respectively.
-Cat and cmp are not needed at runtime.
-
-All mentions to zegrep and zfgrep have been removed from the
-documentation because egrep and fgrep are deprecated.
-
-Environment safeguards from configure have been removed. This allows
-environment variables to affect configuration.
+Configure now allows the selection of diff and grep programs to use.
diff --git a/configure b/configure
index 2a45a9a..4d3753c 100755
--- a/configure
+++ b/configure
@@ -5,12 +5,12 @@
# This configure script is free software: you have unlimited permission
# to copy, distribute and modify it.
#
-# Date of this version: 2010-11-15
+# Date of this version: 2010-11-20
args=
no_create=
pkgname=zutils
-pkgversion=0.8
+pkgversion=0.9-rc1
progname=zutils
srctrigger=zutils.h
@@ -25,6 +25,8 @@ datadir='$(prefix)/share'
infodir='$(datadir)/info'
mandir='$(datadir)/man'
sysconfdir='$(prefix)/etc'
+DIFF=diff
+GREP=grep
if [ -n "${CXX}" ] ; then args="${args} CXX=\"${CXX}\"" ; fi
if [ -n "${CPPFLAGS}" ] ; then args="${args} CPPFLAGS=\"${CPPFLAGS}\"" ; fi
@@ -67,6 +69,8 @@ while [ -n "$1" ] ; do
echo " CPPFLAGS=OPTIONS command line options for the preprocessor [${CPPFLAGS}]"
echo " CXXFLAGS=OPTIONS command line options for the C++ compiler [${CXXFLAGS}]"
echo " LDFLAGS=OPTIONS command line options for the linker [${LDFLAGS}]"
+ echo " DIFF=NAME diff program to use with zdiff [diff]"
+ echo " GREP=NAME grep program to use with zgrep [grep]"
echo
exit 0 ;;
--version | --ve* | -V)
@@ -95,6 +99,8 @@ while [ -n "$1" ] ; do
CPPFLAGS=*) CPPFLAGS=${optarg} ;;
CXXFLAGS=*) CXXFLAGS=${optarg} ;;
LDFLAGS=*) LDFLAGS=${optarg} ;;
+ DIFF=*) DIFF=${optarg} ;;
+ GREP=*) GREP=${optarg} ;;
--* | *=* | *-*-*) ;;
*)
@@ -166,6 +172,8 @@ echo "CXX = ${CXX}"
echo "CPPFLAGS = ${CPPFLAGS}"
echo "CXXFLAGS = ${CXXFLAGS}"
echo "LDFLAGS = ${LDFLAGS}"
+echo "DIFF = ${DIFF}"
+echo "GREP = ${GREP}"
rm -f Makefile
cat > Makefile << EOF
# Makefile for Zutils - Utilities dealing with compressed files
@@ -190,6 +198,8 @@ CXX = ${CXX}
CPPFLAGS = ${CPPFLAGS}
CXXFLAGS = ${CXXFLAGS}
LDFLAGS = ${LDFLAGS}
+DIFF = ${DIFF}
+GREP = ${GREP}
EOF
cat ${srcdir}/Makefile.in >> Makefile
diff --git a/doc/zcat.1 b/doc/zcat.1
index 244aaad..be5d381 100644
--- a/doc/zcat.1
+++ b/doc/zcat.1
@@ -1,5 +1,5 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.37.1.
-.TH ZCAT "1" "November 2010" "Zcat (zutils) 0.8" "User Commands"
+.TH ZCAT "1" "November 2010" "Zcat (zutils) 0.9-rc1" "User Commands"
.SH NAME
Zcat \- decompress and concatenate files to standard output
.SH SYNOPSIS
diff --git a/doc/zcmp.1 b/doc/zcmp.1
index ab3da39..f1e8472 100644
--- a/doc/zcmp.1
+++ b/doc/zcmp.1
@@ -1,5 +1,5 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.37.1.
-.TH ZCMP "1" "November 2010" "Zcmp (zutils) 0.8" "User Commands"
+.TH ZCMP "1" "November 2010" "Zcmp (zutils) 0.9-rc1" "User Commands"
.SH NAME
Zcmp \- decompress and compare two files byte by byte
.SH SYNOPSIS
diff --git a/doc/zdiff.1 b/doc/zdiff.1
index f6417c2..6ed05de 100644
--- a/doc/zdiff.1
+++ b/doc/zdiff.1
@@ -1,5 +1,5 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.37.1.
-.TH ZDIFF "1" "November 2010" "Zdiff (zutils) 0.8" "User Commands"
+.TH ZDIFF "1" "November 2010" "Zdiff (zutils) 0.9-rc1" "User Commands"
.SH NAME
Zdiff \- decompress and compare two files line by line
.SH SYNOPSIS
diff --git a/doc/zgrep.1 b/doc/zgrep.1
index aab13b2..2ec43dc 100644
--- a/doc/zgrep.1
+++ b/doc/zgrep.1
@@ -1,5 +1,5 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.37.1.
-.TH ZGREP "1" "November 2010" "Zgrep (zutils) 0.8" "User Commands"
+.TH ZGREP "1" "November 2010" "Zgrep (zutils) 0.9-rc1" "User Commands"
.SH NAME
Zgrep \- search compressed files for a regular expression
.SH SYNOPSIS
diff --git a/doc/ztest.1 b/doc/ztest.1
index 9a36415..8db8692 100644
--- a/doc/ztest.1
+++ b/doc/ztest.1
@@ -1,5 +1,5 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.37.1.
-.TH ZTEST "1" "November 2010" "Ztest (zutils) 0.8" "User Commands"
+.TH ZTEST "1" "November 2010" "Ztest (zutils) 0.9-rc1" "User Commands"
.SH NAME
Ztest \- verify integrity of compressed files
.SH SYNOPSIS
diff --git a/doc/zutils.info b/doc/zutils.info
index b7f1250..38e6746 100644
--- a/doc/zutils.info
+++ b/doc/zutils.info
@@ -12,7 +12,7 @@ File: zutils.info, Node: Top, Next: Introduction, Up: (dir)
Zutils Manual
*************
-This manual is for Zutils (version 0.8, 15 November 2010).
+This manual is for Zutils (version 0.9-rc1, 20 November 2010).
* Menu:
@@ -531,13 +531,13 @@ Concept Index

Tag Table:
Node: Top224
-Node: Introduction987
-Node: Zcat2442
-Node: Zcmp4326
-Node: Zdiff6383
-Node: Zgrep8620
-Node: Ztest11387
-Node: Problems12470
-Node: Concept Index12999
+Node: Introduction991
+Node: Zcat2446
+Node: Zcmp4330
+Node: Zdiff6387
+Node: Zgrep8624
+Node: Ztest11391
+Node: Problems12474
+Node: Concept Index13003

End Tag Table
diff --git a/doc/zutils.texinfo b/doc/zutils.texinfo
index bb6eb6c..dbae4bb 100644
--- a/doc/zutils.texinfo
+++ b/doc/zutils.texinfo
@@ -5,8 +5,8 @@
@finalout
@c %**end of header
-@set UPDATED 15 November 2010
-@set VERSION 0.8
+@set UPDATED 20 November 2010
+@set VERSION 0.9-rc1
@dircategory Data Compression
@direntry
diff --git a/main.cc b/main.cc
index bc7c5fb..56cbf06 100644
--- a/main.cc
+++ b/main.cc
@@ -19,7 +19,6 @@
#include <cerrno>
#include <climits>
-#include <csignal>
#include <cstdio>
#include <cstdlib>
#include <cstring>
@@ -100,9 +99,8 @@ int open_instream( std::string & input_filename, const Mode program_mode ) throw
if( infd >= 0 ) { input_filename = name; break; }
}
}
- if( infd < 0 && verbosity >= 0 )
- std::fprintf( stderr, "%s: Can't open input file `%s': %s.\n",
- util_name, input_filename.c_str(), std::strerror( errno ) );
+ if( infd < 0 )
+ show_error2( "Can't open input file", input_filename.c_str() );
}
return infd;
}
@@ -371,9 +369,7 @@ int main( const int argc, const char * const argv[] )
DIR * const dirp = opendir( input_filename.c_str() );
if( !dirp )
{
- if( verbosity >= 0 )
- std::fprintf( stderr, "%s: Can't open directory `%s': %s.\n",
- util_name, input_filename.c_str(), std::strerror( errno ) );
+ show_error2( "Can't open directory", input_filename.c_str() );
if( retval < 1 ) retval = 1; continue;
}
std::list< std::string > tmp_list;
diff --git a/zcat.cc b/zcat.cc
index f813bbe..1ead9f4 100644
--- a/zcat.cc
+++ b/zcat.cc
@@ -45,7 +45,7 @@ public:
str[i] = '0';
}
if( first_digit_pos > 0 ) str[--first_digit_pos] = '1';
- else str.insert( 0, 1, '1' );
+ else str.insert( 0U, 1, '1' );
}
int sprint( uint8_t * const buf )
@@ -116,10 +116,7 @@ int do_cat( const int infd, const int buffer_size,
rd = readblock( infd, inbuf, buffer_size );
if( rd != buffer_size && errno )
{
- if( verbosity >= 0 )
- std::fprintf( stderr, "%s: Error reading file `%s': %s.\n",
- util_name, input_filename.c_str(),
- std::strerror( errno ) );
+ show_error2( "Error reading file", input_filename.c_str() );
return 1;
}
if( rd == 0 )
@@ -206,7 +203,7 @@ int cat( int infd, const std::string & input_filename,
input_filename, cat_options );
if( pid && wait_for_child( pid, "data feeder" ) != 0 ) retval = 1;
if( close( infd ) != 0 )
- { show_error( "Can't close output of data feeder", errno ); retval = 1; }
+ { show_close_error( "data feeder" ); retval = 1; }
}
delete[] inbuf; delete[] outbuf;
return retval;
diff --git a/zcmp.cc b/zcmp.cc
index caa7852..a2779b9 100644
--- a/zcmp.cc
+++ b/zcmp.cc
@@ -20,7 +20,6 @@
#include <cctype>
#include <cerrno>
#include <climits>
-#include <csignal>
#include <cstdio>
#include <cstdlib>
#include <cstring>
@@ -166,9 +165,8 @@ long long getnum( const char * const ptr, const char ** const tailp = 0,
int open_instream( const std::string & input_filename ) throw()
{
int infd = open( input_filename.c_str(), O_RDONLY | o_binary );
- if( infd < 0 && verbosity >= 0 )
- std::fprintf( stderr, "%s: Can't open input file `%s': %s.\n",
- util_name, input_filename.c_str(), std::strerror( errno ) );
+ if( infd < 0 )
+ show_error2( "Can't open input file", input_filename.c_str() );
return infd;
}
@@ -293,9 +291,7 @@ int cmp( const long long max_size, const int infd[2],
rd[i] = readblock( infd[i], buffer[i], size );
if( rd[i] != size && errno )
{
- if( verbosity >= 0 )
- std::fprintf( stderr, "%s: Error reading file `%s': %s.\n",
- util_name, filenames[i].c_str(), std::strerror( errno ) );
+ show_error2( "Error reading file", filenames[i].c_str() );
return 2;
}
}
@@ -467,9 +463,7 @@ int main( const int argc, const char * const argv[] )
for( int i = 0; i < 2; ++i )
if( !skip_ignore_initial( ignore_initial[i], infd[i] ) )
{
- if( verbosity >= 0 )
- std::fprintf( stderr, "%s: Can't skip initial bytes from file `%s': %s.\n",
- util_name, filenames[i].c_str(), std::strerror( errno ) );
+ show_error2( "Can't skip initial bytes from file", filenames[i].c_str() );
return 2;
}
@@ -483,12 +477,10 @@ int main( const int argc, const char * const argv[] )
for( int i = 0; i < 2; ++i )
{
if( close( infd[i] ) != 0 )
- { show_error( "Can't close output of data feeder", errno ); retval = 2; }
+ { show_close_error( "data feeder" ); retval = 2; }
if( filenames[i] != "-" && close( old_infd[i] ) != 0 )
{
- if( verbosity >= 0 )
- std::fprintf( stderr, "%s: Can't close input file `%s': %s.\n",
- util_name, filenames[i].c_str(), std::strerror( errno ) );
+ show_error2( "Can't close input file", filenames[i].c_str() );
retval = 2;
}
}
diff --git a/zdiff.cc b/zdiff.cc
index d01f492..b9c4c77 100644
--- a/zdiff.cc
+++ b/zdiff.cc
@@ -122,9 +122,8 @@ void show_help() throw()
int open_instream( const std::string & input_filename ) throw()
{
int infd = open( input_filename.c_str(), O_RDONLY | o_binary );
- if( infd < 0 && verbosity >= 0 )
- std::fprintf( stderr, "%s: Can't open input file `%s': %s.\n",
- util_name, input_filename.c_str(), std::strerror( errno ) );
+ if( infd < 0 )
+ show_error2( "Can't open input file", input_filename.c_str() );
return infd;
}
@@ -169,7 +168,7 @@ const char * my_basename( const char * filename ) throw()
}
-void remove_fifos() throw()
+extern "C" void remove_fifos() throw()
{
if( fifonames[0].size() )
{ std::remove( fifonames[0].c_str() ); fifonames[0].clear(); }
@@ -209,9 +208,7 @@ bool set_fifonames( const std::string filenames[2] )
if( mkfifo( fifonames[i].c_str(), S_IRUSR | S_IWUSR ) == 0 )
continue;
}
- if( verbosity >= 0 )
- std::fprintf( stderr, "%s: Can't create FIFO `%s': %s.\n",
- util_name, fifonames[i].c_str(), std::strerror( errno ) );
+ show_error2( "Can't create FIFO", fifonames[i].c_str() );
return false;
}
return true;
@@ -251,30 +248,23 @@ bool set_data_feeder( const std::string & fifoname, const int infd,
close( fda[0] ) == 0 && close( fda[1] ) == 0 &&
close( outfd ) == 0 )
execlp( file_type.c_str(), file_type.c_str(), "-cdfq", (char *)0 );
- if( verbosity >= 0 )
- std::fprintf( stderr, "%s: Can't exec `%s': %s.\n",
- util_name, file_type.c_str(), std::strerror( errno ) );
+ show_exec_error( file_type.c_str() );
_exit( 2 );
}
if( pid2 < 0 )
- {
- if( verbosity >= 0 )
- std::fprintf( stderr, "%s: Can't fork `%s': %s.\n",
- util_name, file_type.c_str(), std::strerror( errno ) );
- _exit( 2 );
- }
+ { show_fork_error( file_type.c_str() ); _exit( 2 ); }
if( close( fda[0] ) != 0 ||
!feed_data( infd, fda[1], magic_data, magic_size ) )
_exit( 2 );
if( close( fda[1] ) != 0 )
- { show_error( "Can't close output of feeder", errno ); _exit( 2 ); }
+ { show_close_error( "data feeder" ); _exit( 2 ); }
_exit( wait_for_child( pid2, file_type.c_str() ) );
}
// parent
close( fda[0] ); close( fda[1] );
if( pid < 0 )
- { show_error( "Can't fork decompressor feeder", errno ); return false; }
+ { show_fork_error( "decompressor feeder" ); return false; }
*pidp = pid;
}
else // not compressed
@@ -293,12 +283,12 @@ bool set_data_feeder( const std::string & fifoname, const int infd,
if( !feed_data( infd, outfd, magic_data, magic_size ) )
_exit( 2 );
if( close( outfd ) != 0 )
- { show_error( "Can't close output of feeder", errno ); _exit( 2 ); }
+ { show_close_error( "data feeder" ); _exit( 2 ); }
_exit( 0 );
}
// parent
if( pid < 0 )
- { show_error( "Can't fork data feeder", errno ); return false; }
+ { show_fork_error( "data feeder" ); return false; }
*pidp = pid;
}
return true;
@@ -431,7 +421,7 @@ int main( const int argc, const char * const argv[] )
if( diff_pid == 0 ) // child (diff)
{
const char ** const argv = new const char *[diff_args.size()+5];
- argv[0] = "diff";
+ argv[0] = DIFF;
for( unsigned int i = 0; i < diff_args.size(); ++i )
argv[i+1] = diff_args[i];
argv[diff_args.size()+1] = "--";
@@ -439,19 +429,19 @@ int main( const int argc, const char * const argv[] )
argv[diff_args.size()+3] = fifonames[1].c_str();
argv[diff_args.size()+4] = 0;
execvp( argv[0], (char **)argv );
- show_error( "Can't exec `diff'." );
+ show_exec_error( DIFF );
_exit( 2 );
}
// parent
if( diff_pid < 0 )
- { show_error( "Can't fork `diff'", errno ); return 2; }
+ { show_fork_error( DIFF ); return 2; }
pid_t pid[2];
if( !set_data_feeder( fifonames[0], infd[0], &pid[0] ) ||
!set_data_feeder( fifonames[1], infd[1], &pid[1] ) )
return 2;
- int retval = wait_for_child( diff_pid, "diff" );
+ int retval = wait_for_child( diff_pid, DIFF );
if( retval != 0 )
{
@@ -466,9 +456,7 @@ int main( const int argc, const char * const argv[] )
for( int i = 0; i < 2; ++i )
if( filenames[i] != "-" && close( infd[i] ) != 0 )
{
- if( verbosity >= 0 )
- std::fprintf( stderr, "%s: Can't close input file `%s': %s.\n",
- util_name, filenames[i].c_str(), std::strerror( errno ) );
+ show_error2( "Can't close input file", filenames[i].c_str() );
retval = 2;
}
diff --git a/zgrep.cc b/zgrep.cc
index b1c18b4..41317a5 100644
--- a/zgrep.cc
+++ b/zgrep.cc
@@ -72,23 +72,23 @@ int zgrep_stdin( int infd, const std::vector< const char * > & grep_args )
if( dup2( infd, STDIN_FILENO ) >= 0 && close( infd ) == 0 )
{
const char ** const argv = new const char *[grep_args.size()+2];
- argv[0] = "grep";
+ argv[0] = GREP;
for( unsigned int i = 0; i < grep_args.size(); ++i )
argv[i+1] = grep_args[i];
argv[grep_args.size()+1] = 0;
execvp( argv[0], (char **)argv );
}
- show_error( "Can't exec `grep'." );
+ show_exec_error( GREP );
_exit( 2 );
}
// parent
if( grep_pid < 0 )
- { show_error( "Can't fork `grep'", errno ); return 2; }
+ { show_fork_error( GREP ); return 2; }
int retval = 0;
if( pid && wait_for_child( pid, "data feeder" ) != 0 ) retval = 2;
- if( wait_for_child( grep_pid, "grep" ) != 0 ) retval = 2;
+ if( wait_for_child( grep_pid, GREP ) != 0 ) retval = 2;
if( close( infd ) != 0 )
- { show_error( "Can't close output of data feeder", errno ); return 2; }
+ { show_close_error( "data feeder" ); return 2; }
return retval;
}
@@ -110,19 +110,19 @@ int zgrep_file( int infd, const std::string & input_filename,
close( infd ) == 0 && close( fda[0] ) == 0 && close( fda[1] ) == 0 )
{
const char ** const argv = new const char *[grep_args.size()+2];
- argv[0] = "grep";
+ argv[0] = GREP;
for( unsigned int i = 0; i < grep_args.size(); ++i )
argv[i+1] = grep_args[i];
argv[grep_args.size()+1] = 0;
execvp( argv[0], (char **)argv );
}
- show_error( "Can't exec `grep'." );
+ show_exec_error( GREP );
_exit( 2 );
}
// parent
close( fda[1] );
if( grep_pid < 0 )
- { show_error( "Can't fork `grep'", errno ); return 2; }
+ { show_fork_error( GREP ); return 2; }
enum { buffer_size = 256 };
uint8_t buffer[buffer_size];
bool line_begin = true;
@@ -148,12 +148,12 @@ int zgrep_file( int infd, const std::string & input_filename,
}
int retval = 0;
if( pid && wait_for_child( pid, "data feeder" ) != 0 ) retval = 2;
- if( wait_for_child( grep_pid, "grep" ) != 0 ) retval = 2;
+ if( wait_for_child( grep_pid, GREP ) != 0 ) retval = 2;
if( grep_list && retval == 0 )
std::printf( "%s\n", input_filename.c_str() );
if( close( infd ) != 0 )
- { show_error( "Can't close output of data feeder", errno ); return 2; }
+ { show_close_error( "data feeder" ); return 2; }
if( close( fda[0] ) != 0 )
- { show_error( "Can't close output of grep", errno ); return 2; }
+ { show_close_error( GREP ); return 2; }
return retval;
}
diff --git a/ztest.cc b/ztest.cc
index 6a9b910..3672aa8 100644
--- a/ztest.cc
+++ b/ztest.cc
@@ -60,23 +60,16 @@ int ztest_stdin( const int infd,
argv[ztest_args.size()+2] = 0;
execvp( argv[0], (char **)argv );
}
- if( verbosity >= 0 )
- std::fprintf( stderr, "%s: Can't exec `%s': %s.\n",
- util_name, file_type.c_str(), std::strerror( errno ) );
+ show_exec_error( file_type.c_str() );
_exit( 1 );
}
// parent
if( pid < 0 )
- {
- if( verbosity >= 0 )
- std::fprintf( stderr, "%s: Can't fork `%s': %s.\n",
- util_name, file_type.c_str(), std::strerror( errno ) );
- return 1;
- }
+ { show_fork_error( file_type.c_str() ); return 1; }
close( fda[0] );
if( !feed_data( infd, fda[1], magic_data, magic_size ) ) return 1;
if( close( fda[1] ) != 0 )
- { show_error( "Can't close output of data feeder", errno ); return 1; }
+ { show_close_error( "data feeder" ); return 1; }
return wait_for_child( pid, file_type.c_str() );
}
@@ -102,18 +95,11 @@ int ztest_file( const int infd, const std::string & input_filename,
argv[ztest_args.size()+3] = input_filename.c_str();
argv[ztest_args.size()+4] = 0;
execvp( argv[0], (char **)argv );
- if( verbosity >= 0 )
- std::fprintf( stderr, "%s: Can't exec `%s': %s.\n",
- util_name, argv[0], std::strerror( errno ) );
+ show_exec_error( file_type.c_str() );
_exit( 1 );
}
// parent
if( pid < 0 )
- {
- if( verbosity >= 0 )
- std::fprintf( stderr, "%s: Can't fork `%s': %s.\n",
- util_name, file_type.c_str(), std::strerror( errno ) );
- return 1;
- }
+ { show_fork_error( file_type.c_str() ); return 1; }
return wait_for_child( pid, file_type.c_str() );
}
diff --git a/zutils.cc b/zutils.cc
index 5451534..01a0152 100644
--- a/zutils.cc
+++ b/zutils.cc
@@ -119,32 +119,24 @@ bool set_data_feeder( int * const infdp, pid_t * const pidp )
close( fda[0] ) == 0 && close( fda[1] ) == 0 &&
close( fda2[0] ) == 0 && close( fda2[1] ) == 0 )
execlp( file_type.c_str(), file_type.c_str(), "-cdfq", (char *)0 );
- if( verbosity >= 0 )
- std::fprintf( stderr, "%s: Can't exec `%s': %s.\n",
- util_name, file_type.c_str(), std::strerror( errno ) );
+ show_exec_error( file_type.c_str() );
_exit( 2 );
}
if( pid2 < 0 )
- {
- if( verbosity >= 0 )
- std::fprintf( stderr, "%s: Can't fork `%s': %s.\n",
- util_name, file_type.c_str(), std::strerror( errno ) );
- _exit( 2 );
- }
+ { show_fork_error( file_type.c_str() ); _exit( 2 ); }
if( close( fda[0] ) != 0 ||
close( fda2[0] ) != 0 || close( fda2[1] ) != 0 ||
!feed_data( old_infd, fda[1], magic_data, magic_size ) )
_exit( 2 );
if( close( fda[1] ) != 0 )
- { show_error( "Can't close output of decompressor feeder", errno );
- _exit( 2 ); }
+ { show_close_error( "decompressor feeder" ); _exit( 2 ); }
_exit( wait_for_child( pid2, file_type.c_str() ) );
}
// parent
close( fda[0] ); close( fda[1] ); close( fda2[1] );
if( pid < 0 )
- { show_error( "Can't fork decompressor feeder", errno ); return false; }
+ { show_fork_error( "decompressor feeder" ); return false; }
*pidp = pid;
}
else // not compressed
@@ -161,14 +153,13 @@ bool set_data_feeder( int * const infdp, pid_t * const pidp )
!feed_data( old_infd, fda[1], magic_data, magic_size ) )
_exit( 2 );
if( close( fda[1] ) != 0 )
- { show_error( "Can't close output of data feeder", errno );
- _exit( 2 ); }
+ { show_close_error( "data feeder" ); _exit( 2 ); }
_exit( 0 );
}
// parent
close( fda[1] );
if( pid < 0 )
- { show_error( "Can't fork data feeder", errno ); return false; }
+ { show_fork_error( "data feeder" ); return false; }
*pidp = pid;
}
return true;
@@ -214,6 +205,38 @@ void show_error( const char * const msg, const int errcode,
}
+void show_error2( const char * const msg, const char * const name ) throw()
+ {
+ if( verbosity >= 0 )
+ std::fprintf( stderr, "%s: %s `%s': %s.\n",
+ util_name, msg, name, std::strerror( errno ) );
+ }
+
+
+void show_close_error( const char * const prog_name ) throw()
+ {
+ if( verbosity >= 0 )
+ std::fprintf( stderr, "%s: Can't close output of %s: %s.\n",
+ util_name, prog_name, std::strerror( errno ) );
+ }
+
+
+void show_exec_error( const char * const prog_name ) throw()
+ {
+ if( verbosity >= 0 )
+ std::fprintf( stderr, "%s: Can't exec `%s': %s.\n",
+ util_name, prog_name, std::strerror( errno ) );
+ }
+
+
+void show_fork_error( const char * const prog_name ) throw()
+ {
+ if( verbosity >= 0 )
+ std::fprintf( stderr, "%s: Can't fork `%s': %s.\n",
+ util_name, prog_name, std::strerror( errno ) );
+ }
+
+
void internal_error( const char * const msg )
{
if( verbosity >= 0 )
diff --git a/zutils.h b/zutils.h
index 296f3ac..87eddca 100644
--- a/zutils.h
+++ b/zutils.h
@@ -45,6 +45,10 @@ void show_help_addr() throw();
void show_version( const char * const Util_name = 0 ) throw();
void show_error( const char * const msg, const int errcode = 0,
const bool help = false ) throw();
+void show_error2( const char * const msg, const char * const name ) throw();
+void show_close_error( const char * const prog_name ) throw();
+void show_exec_error( const char * const prog_name ) throw();
+void show_fork_error( const char * const prog_name ) throw();
void internal_error( const char * const msg );
bool test_format( const int infd, std::string & file_type,