[tex-k] newer
Reinhard Kotucha
reinhard.kotucha at web.de
Mon Apr 4 03:23:46 CEST 2005
Hi Olaf,
the current version of the program `newer' accepts only two
arguments. The patch below allows an arbitrary number of arguments,
so that you can say:
if newer *.tex file.dvi; then ...
instead of:
if newer file_1.tex file.dvi ||
newer file_2.tex file.dvi ||
newer file_3.tex file.dvi ||
newer file_4.tex file.dvi ; then ...
I added an option --verbose which lists missing input files to stderr.
This is what I get:
$ newer --help
Usage: newer [OPTION] src1 [ src2 ... srcN ] dependent
Exit successfully if `src1' ... `srcN' exist and at least
one of them is not older than `dependent'.
Also exit successfully if `dependent' doesn't exist.
--help display this help and exit
--verbose list missing input files
--version output version information and exit
Email bug reports to tex-k at mail.tug.org.
$
$ newer a b c x ; echo "=> $?"
=> 1
$ newer --verbose a b c x ; echo "=> $?"
newer: file `a' doesn't exist.
newer: file `b' doesn't exist.
newer: file `c' doesn't exist.
=> 1
$ touch a b c
$ newer --verbose a b c x ; echo "=> $?"
=> 0
$ touch x
$ newer --verbose a b c x ; echo "=> $?"
=> 1
$ touch a
$ newer --verbose a b c x ; echo "=> $?"
=> 0
There are some bugs in web2c.texi. It says that -help is a valid
option to mpto, but in fact --help is required.
$ mpto -help
mpto: -help: No such file or directory
I suppose that a lot of programs are affected.
I moved the version number of newer from 0.63 to 0.64 and the date in
the .man file to "4 April 2005".
Does it make it sense to remove the paragraph beginning with "Although
this could be written as a Perl script ..." from web2c.texi?
If not, shouldn't we have to explain why it is not written in COBOL?
Cheers,
Reinhard
==================================================================
--- mpware/newer.c.orig Sun Nov 17 23:27:19 2002
+++ mpware/newer.c Mon Apr 4 02:02:05 2005
@@ -29,31 +29,48 @@
#include <sys/stat.h>
#endif
+int i;
+int verbose=0;
+int missing_infile=0;
+
/*
- * newer x y
+ * newer src1 [ src2 ... srcN ] dependent
*
- * returns 0 if x exists and y does not, or if
- * files x and y both exist and x was modified
- * at least as recently as y, and nonzero otherwise.
- * (i.e., it's really ``is x older than y'', not ``is y newer than x'')
- * Perhaps this program should be replaced by ls -lt, but then two
- * files with the same mtime couldn't be handled right ...
+ * returns 0 if files `src1' ... `srcN' exist and
+ * at least one of them is not older than `dependent'
+ * or if `dependent' doesn't exist.
*/
int main P2C(int,argc, char**,argv)
{
struct stat x, y;
+ /* We assume that newer is called with at most one optional
+ * argument. Checking for --verbose first handles cases like
+ * newer --verbose --help
+ * gracefully.
+ */
+
+ if ( argc > 1 && ( strcmp (argv[1], "-v") == 0 ||
+ strcmp (argv[1], "--verbose") == 0)) {
+ verbose=1;
+ argv+=1;
+ argc-=1;
+ }
+
if (argc > 1 && strcmp (argv[1], "--help") == 0) {
- fputs ("Usage: newer [OPTION]... FILE1 FILE2\n\
- Exit successfully if FILE1 exists and is at least as recent as FILE2.\n\
+ fputs ("Usage: newer [OPTION] src1 [ src2 ... srcN ] dependent\n\
+ Exit successfully if `src1' ... `srcN' exist and at least\n\
+ one of them is not older than `dependent'.\n\
+ Also exit successfully if `dependent' doesn't exist.\n\
\n\
--help display this help and exit\n\
+--verbose list missing input files\n\
--version output version information and exit\n\n", stdout);
fputs ("Email bug reports to tex-k at mail.tug.org.\n", stdout);
exit(0);
} else if (argc > 1 && strcmp (argv[1], "--version") == 0) {
- printf ("newer%s 0.63\n\
+ printf ("newer%s 0.64\n\
Copyright (C) 1996 AT&T Bell Laboratories.\n\
There is NO warranty. You may redistribute this software\n\
under the terms of the GNU General Public License\n\
@@ -63,27 +80,41 @@
Primary author of newer: John Hobby.\n",
WEB2CVERSION);
exit (0);
- }
+ }
+
+ /* do we have at leat two arguments? */
+ if (argc < 3) {
+ fputs ("newer: Too few arguments. \
+Try `newer --help' for more information.\n",stderr);
+ exit (1);
+ }
- /* insist on exactly two args */
- if (argc != 3) {
- fputs ("newer: Need exactly two arguments.\n", stderr);
- fputs ("Try `newer --help' for more information.\n", stderr);
- exit(1);
+ /* do all the input files exist?
+ --verbose option lists missing input files */
+ for (i=1; i<(argc-1); i++) {
+ if (stat (argv[i], &x) < 0) {
+ if (verbose)
+ fprintf (stderr, "newer: file `%s' doesn't exist.\n",
+ argv[i]);
+ missing_infile=1;
+ }
+ }
+ if (missing_infile)
+ exit (1);
+
+ /* does the output file exist? */
+ if (stat (argv[argc-1], &y) < 0) { /* file doesn't exist */
+ exit(0);
}
-
- /* does the first file exist? */
- if (stat (argv[1], &x) < 0)
- exit(1);
-
- /* does the second file exist? */
- if (stat (argv[2], &y) < 0)
+
+ /* succeed unless one of the the input file is older than
+ the output file or both files have the same timestamp */
+ for (i=1; i<(argc-1); i++) {
+ stat (argv[i], &x);
+ if (x.st_mtime >= y.st_mtime)
exit(0);
-
- /* fail if the first file is older than the second */
- if (x.st_mtime < y.st_mtime)
- exit(1);
-
- /* otherwise, succeed */
- exit(0);
+ }
+
+ /* otherwise, fail */
+ exit(1);
}
--- man/newer.man.orig Fri Jan 21 10:35:46 2005
+++ man/newer.man Mon Apr 4 00:47:18 2005
@@ -1,19 +1,23 @@
-.TH NEWER 1 "4 January 1998" "Web2C @VERSION@"
+.TH NEWER 1 "4 April 2005" "Web2C @VERSION@"
.\"=====================================================================
.SH NAME
newer \- compare file modification times
.SH SYNOPSIS
.B newer
.RI [ option ]
-.I file1 file2
+.I src1
+[
+.I src2 ... srcN
+]
+.I dependent
.\"=====================================================================
.SH DESCRIPTION
-Exit successfully if
-.I file1
-exists and is not older than
-.IR file2 .
+Exit successfully if files
+.I src1 ... srcN
+exist and at least one of them is not older than
+.IR dependent .
Also exit successfully if
-.I file2
+.I dependent
doesn't exist.
.\"=====================================================================
.SH OPTIONS
@@ -27,3 +31,7 @@
.B --version
.rb
Print version information and exit.
+.TP
+.B --verbose, -v
+.rb
+List missing source files.
--- doc/web2c.texi.orig Sat Feb 5 14:00:40 2005
+++ doc/web2c.texi Mon Apr 4 01:49:53 2005
@@ -2810,14 +2810,24 @@
Newer compares file modification times. Synopsis:
@example
-newer @var{src} @var{dependent}
+newer @var{src1} [ @var{src2} ... @var{srcN} ] @var{dependent}
@end example
@noindent
-Newer exits successfully if the file @var{src} exists and is older as
- at var{dependent}, i.e., the modification time (mtime) of @var{src} is
-greater than that of @var{dependent}. @xref{Attribute Meanings,,, libc,
-GNU C Library}.
+Newer exits successfully if the files @var{src1} ... @var{srcN} exist
+and at least one of them is not older than @var{dependent}, i.e., the
+modification time (mtime) of at least one of the source files
+is greater than or the same as that of @var{dependent}. Newer also
+exits successfully if the file @var{dependent} doesn't exist.
+ at xref{Attribute Meanings,,, libc, GNU C Library}.
+
+The program accepts the following option, as well as the standard
+ at samp{--help} and @samp{--version} (@pxref{Common options}):
+ at table @samp
+ at item --verbose
+ at opindex --verbose (newer)
+List missing source files to STDERR.
+ at end table
Although this could be written as a Perl script (see the perlop man
page) or using the @samp{--full-time} option supported by @code{ls}
--
----------------------------------------------------------------------------
Reinhard Kotucha Phone: +49-511-4592165
Marschnerstr. 25
D-30167 Hannover mailto:reinhard.kotucha at web.de
----------------------------------------------------------------------------
Microsoft isn't the answer. Microsoft is the question, and the answer is NO.
----------------------------------------------------------------------------
More information about the tex-k
mailing list