Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-9]: src Pull up following revision(s) (requested by simonb in tic...



details:   https://anonhg.NetBSD.org/src/rev/57a7d88250fd
branches:  netbsd-9
changeset: 963811:57a7d88250fd
user:      martin <martin%NetBSD.org@localhost>
date:      Sat Apr 25 10:50:47 2020 +0000

description:
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.

diffstat:

 bin/csh/extern.h    |   4 ++--
 bin/csh/time.c      |  21 +++++++++++----------
 usr.bin/time/ext.h  |   4 ++--
 usr.bin/time/time.1 |  11 +++++++++--
 usr.bin/time/time.c |  24 ++++++++++++++++--------
 5 files changed, 40 insertions(+), 24 deletions(-)

diffs (218 lines):

diff -r 7ae629f51d5b -r 57a7d88250fd bin/csh/extern.h
--- a/bin/csh/extern.h  Sat Apr 25 10:40:45 2020 +0000
+++ b/bin/csh/extern.h  Sat Apr 25 10:50:47 2020 +0000
@@ -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 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 *);
diff -r 7ae629f51d5b -r 57a7d88250fd bin/csh/time.c
--- a/bin/csh/time.c    Sat Apr 25 10:40:45 2020 +0000
+++ b/bin/csh/time.c    Sat Apr 25 10:50:47 2020 +0000
@@ -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 @@
 /*
  * 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 @@
        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 @@
                (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 @@
 }
 
 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)
diff -r 7ae629f51d5b -r 57a7d88250fd usr.bin/time/ext.h
--- a/usr.bin/time/ext.h        Sat Apr 25 10:40:45 2020 +0000
+++ b/usr.bin/time/ext.h        Sat Apr 25 10:50:47 2020 +0000
@@ -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 *);
diff -r 7ae629f51d5b -r 57a7d88250fd usr.bin/time/time.1
--- a/usr.bin/time/time.1       Sat Apr 25 10:40:45 2020 +0000
+++ b/usr.bin/time/time.1       Sat Apr 25 10:50:47 2020 +0000
@@ -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 @@
 .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
diff -r 7ae629f51d5b -r 57a7d88250fd usr.bin/time/time.c
--- a/usr.bin/time/time.c       Sat Apr 25 10:40:45 2020 +0000
+++ b/usr.bin/time/time.c       Sat Apr 25 10:50:47 2020 +0000
@@ -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 @@
 #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 @@
 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 @@
        (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 @@
                        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 @@
                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 @@
 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);
 }



Home | Main Index | Thread Index | Old Index