Makefile.am | 4 ++-- Makefile.in | 6 +++--- configure.in | 11 +++-------- resuse.h | 13 +------------ time.c | 28 ++++++++++++++++++++-------- time.texi | 9 +++++++++ version.texi | 2 +- 7 files changed, 39 insertions(+), 34 deletions(-) diff --git a/Makefile.am b/Makefile.am index 1dbf7d7..3c494c7 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,7 +1,7 @@ bin_PROGRAMS = time info_TEXINFOS = time.texi -time_SOURCES = time.c getopt.c getopt1.c error.c resuse.c version.c \ - getopt.h getpagesize.h resuse.h port.h wait.h +time_SOURCES = time.c resuse.c version.c \ + getpagesize.h resuse.h port.h EXTRA_DIST = texinfo.tex DISTCLEANFILES = stamp-v version.c diff --git a/Makefile.in b/Makefile.in index 7ee5080..f5b2e96 100644 --- a/Makefile.in +++ b/Makefile.in @@ -40,8 +40,8 @@ transform = @program_transform_name@ bin_PROGRAMS = time info_TEXINFOS = time.texi -time_SOURCES = time.c getopt.c getopt1.c error.c resuse.c version.c \ - getopt.h getpagesize.h resuse.h port.h wait.h +time_SOURCES = time.c resuse.c version.c \ + getpagesize.h resuse.h port.h wait.h EXTRA_DIST = texinfo.tex DISTCLEANFILES = stamp-v version.c @@ -61,7 +61,7 @@ LIBS = @LIBS@ COMPILE = $(CC) -c $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS) LINK = $(CC) $(LDFLAGS) -o $@ -time_OBJECTS = time.o getopt.o getopt1.o error.o resuse.o version.o +time_OBJECTS = time.o resuse.o version.o EXTRA_time_SOURCES = time_LDADD = $(LDADD) diff --git a/configure.in b/configure.in index 1531bad..2b39a07 100644 --- a/configure.in +++ b/configure.in @@ -1,11 +1,6 @@ dnl Process this file with autoconf to produce a configure script. AC_INIT(time.c) -VERSION=1.7 -AC_SUBST(VERSION) -PACKAGE=time -AC_SUBST(PACKAGE) - -AC_ARG_PROGRAM +AM_INIT_AUTOMAKE(time, 1.7) dnl Checks for programs. AC_PROG_CC @@ -15,7 +10,7 @@ AC_PROG_INSTALL dnl Checks for header files. AC_HEADER_STDC AC_HEADER_SYS_WAIT -AC_CHECK_HEADERS(unistd.h string.h sys/rusage.h) +AC_CHECK_HEADERS(unistd.h string.h sys/rusage.h sys/resource.h) dnl Checks for typedefs, structures, and compiler characteristics. AC_C_CONST @@ -31,7 +26,7 @@ test $have_tv = yes && AC_DEFINE(HAVE_TIMEVAL) dnl Checks for library functions. AC_FUNC_VPRINTF AC_FUNC_WAIT3 -AC_CHECK_FUNCS(strerror) +AC_CHECK_FUNCS(strerror wait3) AC_MSG_CHECKING(for getpagesize) AC_TRY_LINK([#include ], diff --git a/resuse.h b/resuse.h index 992143f..8f652d1 100644 --- a/resuse.h +++ b/resuse.h @@ -36,19 +36,8 @@ struct timeval # include #else # define TV_MSEC tv_usec / 1000 -# if HAVE_WAIT3 +# if HAVE_SYS_RESOURCE_H # include -# else -/* Process resource usage structure. */ -struct rusage -{ - struct timeval ru_utime; /* User time used. */ - struct timeval ru_stime; /* System time used. */ - int ru_maxrss, ru_ixrss, ru_idrss, ru_isrss, - ru_minflt, ru_majflt, ru_nswap, ru_inblock, - ru_oublock, ru_msgsnd, ru_msgrcv, ru_nsignals, - ru_nvcsw, ru_nivcsw; -}; # endif #endif diff --git a/time.c b/time.c index 9d5cf2c..151f8ff 100644 --- a/time.c +++ b/time.c @@ -147,6 +147,10 @@ static const char *const longstats[] = NULL }; + +/* If true, do not show the exit message */ +static boolean quiet; + /* If true, show an English description next to each statistic. */ static boolean verbose; @@ -172,6 +176,7 @@ static struct option longopts[] = {"help", no_argument, NULL, 'h'}, {"output-file", required_argument, NULL, 'o'}, {"portability", no_argument, NULL, 'p'}, + {"quiet", no_argument, NULL, 'q'}, {"verbose", no_argument, NULL, 'v'}, {"version", no_argument, NULL, 'V'}, {NULL, no_argument, NULL, 0} @@ -333,7 +338,8 @@ summarize (fp, fmt, command, resp) else if (WIFSIGNALED (resp->waitstatus)) fprintf (fp, "Command terminated by signal %d\n", WTERMSIG (resp->waitstatus)); - else if (WIFEXITED (resp->waitstatus) && WEXITSTATUS (resp->waitstatus)) + else if (WIFEXITED (resp->waitstatus) && WEXITSTATUS (resp->waitstatus) + && !quiet) fprintf (fp, "Command exited with non-zero status %d\n", WEXITSTATUS (resp->waitstatus)); @@ -523,6 +529,7 @@ getargs (argc, argv) char *format; /* Format found in environment. */ /* Initialize the option flags. */ + quiet = false; verbose = false; outfile = NULL; outfp = stderr; @@ -536,7 +543,7 @@ getargs (argc, argv) if (format) output_format = format; - while ((optc = getopt_long (argc, argv, "+af:o:pvV", longopts, (int *) 0)) + while ((optc = getopt_long (argc, argv, "+af:o:pqvV", longopts, (int *) 0)) != EOF) { switch (optc) @@ -555,6 +562,9 @@ getargs (argc, argv) case 'p': output_format = posix_format; break; + case 'q': + quiet = true; + break; case 'v': verbose = true; break; @@ -628,7 +638,7 @@ run_command (cmd, resp) signal (SIGQUIT, quit_signal); } -void +int main (argc, argv) int argc; char **argv; @@ -637,16 +647,18 @@ main (argc, argv) RESUSE res; command_line = getargs (argc, argv); - run_command (command_line, &res); + run_command ((char *const *)command_line, &res); summarize (outfp, output_format, command_line, &res); fflush (outfp); if (WIFSTOPPED (res.waitstatus)) - exit (WSTOPSIG (res.waitstatus)); + return WSTOPSIG (res.waitstatus) + 128; else if (WIFSIGNALED (res.waitstatus)) - exit (WTERMSIG (res.waitstatus)); + return WTERMSIG (res.waitstatus) + 128; else if (WIFEXITED (res.waitstatus)) - exit (WEXITSTATUS (res.waitstatus)); + return WEXITSTATUS (res.waitstatus); + else + return 0; } static void @@ -657,7 +669,7 @@ usage (stream, status) fprintf (stream, "\ Usage: %s [-apvV] [-f format] [-o file] [--append] [--verbose]\n\ [--portability] [--format=format] [--output=file] [--version]\n\ - [--help] command [arg...]\n", + [--quiet] [--help] command [arg...]\n", program_name); exit (status); } diff --git a/time.texi b/time.texi index 8d5af92..bc3f4d6 100644 --- a/time.texi +++ b/time.texi @@ -12,6 +12,11 @@ @end iftex @ifinfo +@dircategory Individual utilities +@direntry +* time: (time). Run programs and summarize + system resource usage. +@end direntry This file documents the the GNU @code{time} command for running programs and summarizing the system resources they use. @@ -185,6 +190,10 @@ user %U sys %S @end example +@item -q +@itemx --quiet +Suppress non-zero error code from the executed program. + @item -v @itemx --verbose @cindex format diff --git a/version.texi b/version.texi index ef9acdc..2d46fc1 100644 --- a/version.texi +++ b/version.texi @@ -1,3 +1,3 @@ -@set UPDATED 12 June 1996 +@set UPDATED 9 May 2002 @set EDITION 1.7 @set VERSION 1.7