Module Name:    src
Committed By:   martin
Date:           Sat Apr 25 10:50:47 UTC 2020

Modified Files:
        src/bin/csh [netbsd-9]: extern.h time.c
        src/usr.bin/time [netbsd-9]: ext.h time.1 time.c

Log Message:
Pull up following revision(s) (requested by simonb in ticket #853):

        bin/csh/time.c: revision 1.22
        usr.bin/time/time.c: revision 1.24
        bin/csh/extern.h: revision 1.32
        usr.bin/time/time.1: revision 1.29
        usr.bin/time/ext.h: revision 1.4

Add '-t' option for tcsh-style time output.


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.31.2.1 src/bin/csh/extern.h
cvs rdiff -u -r1.21 -r1.21.8.1 src/bin/csh/time.c
cvs rdiff -u -r1.3 -r1.3.8.1 src/usr.bin/time/ext.h
cvs rdiff -u -r1.28 -r1.28.8.1 src/usr.bin/time/time.1
cvs rdiff -u -r1.23 -r1.23.8.1 src/usr.bin/time/time.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/bin/csh/extern.h
diff -u src/bin/csh/extern.h:1.31 src/bin/csh/extern.h:1.31.2.1
--- src/bin/csh/extern.h:1.31	Sat Jan  5 16:54:00 2019
+++ src/bin/csh/extern.h	Sat Apr 25 10:50:47 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: extern.h,v 1.31 2019/01/05 16:54:00 christos Exp $ */
+/* $NetBSD: extern.h,v 1.31.2.1 2020/04/25 10:50:47 martin Exp $ */
 
 /*-
  * Copyright (c) 1991, 1993
@@ -297,7 +297,7 @@ void plist(struct varent *);
  */
 void donice(Char **, struct command *);
 void dotime(Char **, struct command *);
-void prusage1(FILE *, const char *, struct rusage *, struct rusage *,
+void prusage1(FILE *, const char *, int, struct rusage *, struct rusage *,
 	     struct timespec *, struct timespec *);
 void prusage(FILE *, struct rusage *, struct rusage *, struct timespec *,
              struct timespec *);

Index: src/bin/csh/time.c
diff -u src/bin/csh/time.c:1.21 src/bin/csh/time.c:1.21.8.1
--- src/bin/csh/time.c:1.21	Sat Jul 15 14:35:55 2017
+++ src/bin/csh/time.c	Sat Apr 25 10:50:47 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: time.c,v 1.21 2017/07/15 14:35:55 christos Exp $ */
+/* $NetBSD: time.c,v 1.21.8.1 2020/04/25 10:50:47 martin Exp $ */
 
 /*-
  * Copyright (c) 1980, 1991, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)time.c	8.1 (Berkeley) 5/31/93";
 #else
-__RCSID("$NetBSD: time.c,v 1.21 2017/07/15 14:35:55 christos Exp $");
+__RCSID("$NetBSD: time.c,v 1.21.8.1 2020/04/25 10:50:47 martin Exp $");
 #endif
 #endif /* not lint */
 
@@ -49,7 +49,7 @@ __RCSID("$NetBSD: time.c,v 1.21 2017/07/
 /*
  * C Shell - routines handling process timing and niceing
  */
-static void pdeltat(FILE *, struct timeval *, struct timeval *);
+static void pdeltat(FILE *, int, struct timeval *, struct timeval *);
 static void pcsecs(FILE *, long);
 
 #ifndef NOT_CSH
@@ -138,12 +138,13 @@ prusage(FILE *fp, struct rusage *r0, str
 	cp = short2str(vp->vec[1]);
     else
 	cp = "%Uu %Ss %E %P %X+%Dk %I+%Oio %Fpf+%Ww";
-    prusage1(fp, cp, r0, r1, e, b);
+    prusage1(fp, cp, 1, r0, r1, e, b);
 }
 #endif
 
 void
-prusage1(FILE *fp, const char *cp, struct rusage *r0, struct rusage *r1,
+prusage1(FILE *fp, const char *cp, int prec,
+    struct rusage *r0, struct rusage *r1,
     struct timespec *e, struct timespec *b)
 {
     long i;
@@ -201,10 +202,10 @@ prusage1(FILE *fp, const char *cp, struc
 		(void)fprintf(fp, "%ld", r1->ru_minflt - r0->ru_minflt);
 		break;
 	    case 'S':		/* system CPU time used */
-		pdeltat(fp, &r1->ru_stime, &r0->ru_stime);
+		pdeltat(fp, prec, &r1->ru_stime, &r0->ru_stime);
 		break;
 	    case 'U':		/* user CPU time used */
-		pdeltat(fp, &r1->ru_utime, &r0->ru_utime);
+		pdeltat(fp, prec, &r1->ru_utime, &r0->ru_utime);
 		break;
 	    case 'W':		/* number of swaps */
 		i = r1->ru_nswap - r0->ru_nswap;
@@ -234,13 +235,13 @@ prusage1(FILE *fp, const char *cp, struc
 }
 
 static void
-pdeltat(FILE *fp, struct timeval *t1, struct timeval *t0)
+pdeltat(FILE *fp, int prec, struct timeval *t1, struct timeval *t0)
 {
     struct timeval td;
 
     timersub(t1, t0, &td);
-    (void)fprintf(fp, "%ld.%01ld", (long)td.tv_sec,
-	(long)(td.tv_usec / 100000));
+    (void)fprintf(fp, "%ld.%0*ld", (long)td.tv_sec,
+	prec, (long)(td.tv_usec / 100000));
 }
 
 #define  P2DIG(fp, i) (void)fprintf(fp, "%ld%ld", (i) / 10, (i) % 10)

Index: src/usr.bin/time/ext.h
diff -u src/usr.bin/time/ext.h:1.3 src/usr.bin/time/ext.h:1.3.8.1
--- src/usr.bin/time/ext.h:1.3	Sat Jul 15 14:34:08 2017
+++ src/usr.bin/time/ext.h	Sat Apr 25 10:50:47 2020
@@ -1,5 +1,5 @@
-/*	$NetBSD: ext.h,v 1.3 2017/07/15 14:34:08 christos Exp $	*/
+/*	$NetBSD: ext.h,v 1.3.8.1 2020/04/25 10:50:47 martin Exp $	*/
 
 /* borrowed from ../../bin/csh/extern.h */
-void prusage1(FILE *, const char *fmt, struct rusage *, struct rusage *,
+void prusage1(FILE *, const char *fmt, int, struct rusage *, struct rusage *,
     struct timespec *, struct timespec *);

Index: src/usr.bin/time/time.1
diff -u src/usr.bin/time/time.1:1.28 src/usr.bin/time/time.1:1.28.8.1
--- src/usr.bin/time/time.1:1.28	Sat Jul 15 14:40:36 2017
+++ src/usr.bin/time/time.1	Sat Apr 25 10:50:47 2020
@@ -1,4 +1,4 @@
-.\"	$NetBSD: time.1,v 1.28 2017/07/15 14:40:36 wiz Exp $
+.\"	$NetBSD: time.1,v 1.28.8.1 2020/04/25 10:50:47 martin Exp $
 .\"
 .\" Copyright (c) 1980, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\"
 .\"     @(#)time.1	8.1 (Berkeley) 6/6/93
 .\"
-.Dd July 15, 2017
+.Dd April 23, 2020
 .Dt TIME 1
 .Os
 .Sh NAME
@@ -124,6 +124,13 @@ structure are printed; see below.
 .It Fl p
 The output is formatted as specified by
 .St -p1003.2-92 .
+.It Fl t
+Displays information in the format used by default the
+.Nm
+builtin of
+.Xr tcsh 1
+uses (%Uu %Ss %E %P\\t%X+%Dk %I+%Oio %Fpf+%Ww) with
+three decimal places for time values.
 .El
 .Pp
 Some shells, such as

Index: src/usr.bin/time/time.c
diff -u src/usr.bin/time/time.c:1.23 src/usr.bin/time/time.c:1.23.8.1
--- src/usr.bin/time/time.c:1.23	Sat Jul 15 14:34:08 2017
+++ src/usr.bin/time/time.c	Sat Apr 25 10:50:47 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: time.c,v 1.23 2017/07/15 14:34:08 christos Exp $	*/
+/*	$NetBSD: time.c,v 1.23.8.1 2020/04/25 10:50:47 martin Exp $	*/
 
 /*
  * Copyright (c) 1987, 1988, 1993
@@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1987, 19
 #if 0
 static char sccsid[] = "@(#)time.c	8.1 (Berkeley) 6/6/93";
 #endif
-__RCSID("$NetBSD: time.c,v 1.23 2017/07/15 14:34:08 christos Exp $");
+__RCSID("$NetBSD: time.c,v 1.23.8.1 2020/04/25 10:50:47 martin Exp $");
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -67,7 +67,7 @@ int
 main(int argc, char ** volatile argv)
 {
 	int pid;
-	int ch, status;
+	int ch, status, prec;
 	int volatile portableflag;
 	int volatile lflag;
 	const char *decpt;
@@ -79,20 +79,21 @@ main(int argc, char ** volatile argv)
 	(void)setlocale(LC_ALL, "");
 
 	lflag = portableflag = 0;
+	prec = 1;
 	fmt = NULL;
-	while ((ch = getopt(argc, argv, "cf:lp")) != -1) {
+	while ((ch = getopt(argc, argv, "cf:lpt")) != -1) {
 		switch (ch) {
 		case 'f':
 			fmt = optarg;
 			portableflag = 0;
 			lflag = 0;
 			break;
-		case 'c':
+		case 'c':	/* csh format */
 			fmt = "%Uu %Ss %E %P %X+%Dk %I+%Oio %Fpf+%Ww";
 			portableflag = 0;
 			lflag = 0;
 			break;
-		case 'p':
+		case 'p':	/* POSIX.2 format */
 			portableflag = 1;
 			fmt = NULL;
 			lflag = 0;
@@ -102,6 +103,12 @@ main(int argc, char ** volatile argv)
 			portableflag = 0;
 			fmt = NULL;
 			break;
+		case 't':	/* tcsh format */
+			fmt = "%Uu %Ss %E %P\t%X+%Dk %I+%Oio %Fpf+%Ww";
+			prec = 3;
+			portableflag = 0;
+			lflag = 0;
+			break;
 		case '?':
 		default:
 			usage();
@@ -143,7 +150,7 @@ main(int argc, char ** volatile argv)
 		static struct rusage null_ru;
 		before.tv_sec = 0;
 		before.tv_nsec = 0;
-		prusage1(stderr, fmt, &null_ru, &ru, &after, &before);
+		prusage1(stderr, fmt, prec, &null_ru, &ru, &after, &before);
 	} else if (portableflag) {
 		prts("real ", decpt, &after, "\n");
 		prtv("user ", decpt, &ru.ru_utime, "\n");
@@ -184,7 +191,8 @@ static void
 usage(void)
 {
 
-	(void)fprintf(stderr, "Usage: %s [-clp] [-f <fmt>] utility [argument ...]\n",
+	(void)fprintf(stderr,
+	    "Usage: %s [-clpt] [-f <fmt>] utility [argument ...]\n",
 	    getprogname());
 	exit(EXIT_FAILURE);
 }

Reply via email to