Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/w Make -w flag apply to the WHAT field also (command...



details:   https://anonhg.NetBSD.org/src/rev/03abbd9d937f
branches:  trunk
changeset: 572564:03abbd9d937f
user:      kim <kim%NetBSD.org@localhost>
date:      Sat Jan 08 05:08:53 2005 +0000

description:
Make -w flag apply to the WHAT field also (command and args).

Use at most half of ttywidth for WHERE field (hostname) instead
of a hardcoded maximum width.  (XXX: this is still not a good
default for displays under 80 columns.  Should probably count
the width of all the other columns, using 8 for the WHAT field.)

diffstat:

 usr.bin/w/w.1 |   3 +--
 usr.bin/w/w.c |  31 +++++++++++++++----------------
 2 files changed, 16 insertions(+), 18 deletions(-)

diffs (106 lines):

diff -r 2dde1c96e975 -r 03abbd9d937f usr.bin/w/w.1
--- a/usr.bin/w/w.1     Sat Jan 08 05:04:34 2005 +0000
+++ b/usr.bin/w/w.1     Sat Jan 08 05:08:53 2005 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: w.1,v 1.16 2005/01/08 04:58:08 kim Exp $
+.\"    $NetBSD: w.1,v 1.17 2005/01/08 05:08:53 kim Exp $
 .\"
 .\" Copyright (c) 1980, 1990, 1991, 1993
 .\"    The Regents of the University of California.  All rights reserved.
@@ -77,7 +77,6 @@
 interprets addresses and attempts to display them symbolically).
 .It Fl w
 Show wide output without truncating any fields.
-Normally the host field is truncated to 35 characters.
 .El
 .Pp
 If a
diff -r 2dde1c96e975 -r 03abbd9d937f usr.bin/w/w.c
--- a/usr.bin/w/w.c     Sat Jan 08 05:04:34 2005 +0000
+++ b/usr.bin/w/w.c     Sat Jan 08 05:08:53 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: w.c,v 1.66 2004/12/22 17:20:30 christos Exp $  */
+/*     $NetBSD: w.c,v 1.67 2005/01/08 05:08:53 kim Exp $       */
 
 /*-
  * Copyright (c) 1980, 1991, 1993, 1994
@@ -39,7 +39,7 @@
 #if 0
 static char sccsid[] = "@(#)w.c        8.6 (Berkeley) 6/30/94";
 #else
-__RCSID("$NetBSD: w.c,v 1.66 2004/12/22 17:20:30 christos Exp $");
+__RCSID("$NetBSD: w.c,v 1.67 2005/01/08 05:08:53 kim Exp $");
 #endif
 #endif /* not lint */
 
@@ -102,7 +102,6 @@
 char           domain[MAXHOSTNAMELEN + 1];
 int maxname = 8, maxline = 3, maxhost = 16;
 
-#define HOSTWIDTH 35
 /*
  * One of these per active utmp entry.
  */
@@ -139,7 +138,6 @@
        int ch, i, nentries, nusers, wcmd;
        char *memf, *nlistf, *p, *x;
        time_t then;
-       int hostwidth;
 #ifdef SUPPORT_UTMP
        struct utmp *ut;
 #endif
@@ -316,25 +314,26 @@
                }
        }
 
-       if (wflag || maxhost < HOSTWIDTH)
-               hostwidth = maxhost;
-       else
-               hostwidth = HOSTWIDTH;
-
-       argwidth = printf("%-*s TTY     %-*s %*s  IDLE WHAT\n",
-           maxname, "USER", hostwidth, "FROM",
-           7 /* "dddhhXm" */, "LOGIN@");
-       argwidth -= sizeof("WHAT\n") - 1 /* NUL */;
-
        if ((ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) == -1 &&
            ioctl(STDERR_FILENO, TIOCGWINSZ, &ws) == -1 &&
            ioctl(STDIN_FILENO, TIOCGWINSZ, &ws) == -1) || ws.ws_col == 0)
                ttywidth = 79;
        else
                ttywidth = ws.ws_col - 1;
+
+       if (!wflag && maxhost > (ttywidth / 2))
+               maxhost = ttywidth / 2;
+
+       argwidth = printf("%-*s TTY     %-*s %*s  IDLE WHAT\n",
+           maxname, "USER", maxhost, "FROM",
+           7 /* "dddhhXm" */, "LOGIN@");
+       argwidth -= sizeof("WHAT\n") - 1 /* NUL */;
        argwidth = ttywidth - argwidth;
        if (argwidth < 4)
                argwidth = 8;
+       if (wflag)
+               argwidth = -1;
+
        /* sort by idle time */
        if (sortidle && ehead != NULL) {
                struct entry *from = ehead, *save;
@@ -421,7 +420,7 @@
                }
                (void)printf("%-*s %-7.7s %-*.*s ",
                    maxname, kp->p_login, ep->line,
-                   hostwidth, hostwidth, *p ? p : "-");
+                   maxhost, maxhost, *p ? p : "-");
                then = (time_t)ep->tv.tv_sec;
                pr_attime(&then, &now);
                pr_idle(ep->idle);
@@ -440,7 +439,7 @@
        if (kp == 0)
                goto nothing;
        left = argwidth;
-       argv = kvm_getargv2(kd, kp, argwidth);
+       argv = kvm_getargv2(kd, kp, (argwidth < 0) ? 0 : argwidth);
        if (argv == 0) {
                if (kp->p_comm == 0) {
                        goto nothing;



Home | Main Index | Thread Index | Old Index