diff options
author | flipk <flipk@cvs.openbsd.org> | 1997-07-28 17:38:54 +0000 |
---|---|---|
committer | flipk <flipk@cvs.openbsd.org> | 1997-07-28 17:38:54 +0000 |
commit | 9395b149a428eb8f347113a4a1f8caacb1191fd0 (patch) | |
tree | 70cdba2ccffc2d54b96c173ed70fca8511469133 | |
parent | 975ebb38463a4a9a2f8dec89cfb6f6b78b166a69 (diff) |
1) Prototypes. pretty.
2) setlocale(LC_ALL, "") from kleink@netbsd
3) Add XPG4.2 `-H' flag (show column headers) from kleink@netbsd
4) initialize flag variables before getopt
5) some Wall cleanup.
-rw-r--r-- | usr.bin/who/who.1 | 4 | ||||
-rw-r--r-- | usr.bin/who/who.c | 57 |
2 files changed, 48 insertions, 13 deletions
diff --git a/usr.bin/who/who.1 b/usr.bin/who/who.1 index 50bb6265339..a862fd41a3a 100644 --- a/usr.bin/who/who.1 +++ b/usr.bin/who/who.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: who.1,v 1.2 1996/06/26 05:43:00 deraadt Exp $ +.\" $OpenBSD: who.1,v 1.3 1997/07/28 17:38:53 flipk Exp $ .\" $NetBSD: who.1,v 1.5 1994/12/07 04:28:47 jtc Exp $ .\" .\" Copyright (c) 1986, 1991, 1993 @@ -74,6 +74,8 @@ and if a bad line is encountered. .It Fl u Print the idle time for each user. +.It Fl H +Write column headings above the regular output. .It Ar \&am I Returns the invoker's real user name. .It Ar file diff --git a/usr.bin/who/who.c b/usr.bin/who/who.c index 2a37912bdbc..22ccbe73df6 100644 --- a/usr.bin/who/who.c +++ b/usr.bin/who/who.c @@ -1,4 +1,4 @@ -/* $OpenBSD: who.c,v 1.4 1997/03/25 21:28:12 deraadt Exp $ */ +/* $OpenBSD: who.c,v 1.5 1997/07/28 17:38:53 flipk Exp $ */ /* $NetBSD: who.c,v 1.4 1994/12/07 04:28:49 jtc Exp $ */ /* @@ -47,7 +47,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)who.c 8.1 (Berkeley) 6/6/93"; #endif -static char rcsid[] = "$OpenBSD: who.c,v 1.4 1997/03/25 21:28:12 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: who.c,v 1.5 1997/07/28 17:38:53 flipk Exp $"; #endif /* not lint */ #include <sys/types.h> @@ -60,13 +60,18 @@ static char rcsid[] = "$OpenBSD: who.c,v 1.4 1997/03/25 21:28:12 deraadt Exp $"; #include <unistd.h> #include <time.h> #include <err.h> +#include <locale.h> + +void output __P((struct utmp *)); +void output_labels __P((void)); +void who_am_i __P((FILE *)); +void usage __P((void)); +FILE *file __P((char *)); -void output __P((struct utmp *)); -void who_am_i __P((FILE *)); -void usage __P((void)); int only_current_term; /* show info about the current terminal only */ int show_term; /* show term state */ int show_idle; /* show idle time */ +int show_labels; /* show column labels */ int main(argc, argv) @@ -74,10 +79,13 @@ main(argc, argv) char **argv; { struct utmp usr; - FILE *ufp, *file(); + FILE *ufp; int c; - while ((c = getopt(argc, argv, "mTu")) != -1) { + setlocale(LC_ALL, ""); + + only_current_term = show_term = show_idle = show_labels = 0; + while ((c = getopt(argc, argv, "HmTu")) != -1) { switch (c) { case 'm': only_current_term = 1; @@ -88,6 +96,9 @@ main(argc, argv) case 'u': show_idle = 1; break; + case 'H': + show_labels = 1; + break; default: usage(); /* NOTREACHED */ @@ -101,6 +112,9 @@ main(argc, argv) /* NOTREACHED */ } + if (show_labels) + output_labels(); + switch (argc) { case 0: /* who */ ufp = file(_PATH_UTMP); @@ -146,9 +160,9 @@ who_am_i(ufp) char *t; /* search through the utmp and find an entry for this tty */ - if (p = ttyname(0)) { + if ((p = ttyname(0))) { /* strip any directory component */ - if (t = strrchr(p, '/')) + if ((t = strrchr(p, '/'))) p = t + 1; while (fread((char *)&usr, sizeof(usr), 1, ufp) == 1) if (*usr.ut_name && !strcmp(usr.ut_line, p)) { @@ -173,9 +187,9 @@ output(up) { struct stat sb; char line[sizeof (up->ut_line) + 1]; - char state; + char state = '?'; static time_t now = 0; - time_t idle; + time_t idle = 0; if (show_term || show_idle) { if (now == 0) @@ -219,6 +233,25 @@ output(up) (void)putchar('\n'); } +void +output_labels() +{ + (void)printf("%-*.*s ", UT_NAMESIZE, UT_NAMESIZE, "USER"); + + if (show_term) + (void)printf("S "); + + (void)printf("%-*.*s ", UT_LINESIZE, UT_LINESIZE, "LINE"); + (void)printf("WHEN "); + + if (show_idle) + (void)printf("IDLE "); + + (void)printf("\t%.*s", UT_HOSTSIZE, "FROM"); + + (void)putchar('\n'); +} + FILE * file(name) char *name; @@ -235,6 +268,6 @@ file(name) void usage() { - (void)fprintf(stderr, "usage: who [-mTu] [ file ]\n who am i\n"); + (void)fprintf(stderr, "usage: who [-mTuH] [ file ]\n who am i\n"); exit(1); } |