From d66a1cb0301100ca00653d74bc27539c03a788c6 Mon Sep 17 00:00:00 2001 From: peter Date: Sun, 10 Jan 1999 15:28:37 +0000 Subject: Fix the annoying bug introduced in rev 1.18 that caused each line to be one character shorter than the previous in a stairstep fashion when long idle times were involved. A couple of nits: - spelling/typo fix. - some of the easier style(9) fixes where it was bothering me. - Handle 100+ days idle time (ha!). Probably the right thing to do is to do a snprintf into a buffer and strlen the result rather than doing hackery on magic numbers. XXX the wide (and mostly unused) username and tty columns annoy me since it it could be used for more useful information for the command. We should actually count the largest username and tty and adjust like 'ls -l' does. --- usr.bin/w/w.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'usr.bin/w/w.c') diff --git a/usr.bin/w/w.c b/usr.bin/w/w.c index 299b0d6..18e43c0 100644 --- a/usr.bin/w/w.c +++ b/usr.bin/w/w.c @@ -42,7 +42,7 @@ static const char copyright[] = static char sccsid[] = "@(#)w.c 8.4 (Berkeley) 4/16/94"; #endif static const char rcsid[] = - "$Id: w.c,v 1.30 1998/12/24 18:20:58 steve Exp $"; + "$Id: w.c,v 1.31 1998/12/24 23:27:33 dillon Exp $"; #endif /* not lint */ /* @@ -97,7 +97,7 @@ int argwidth; /* width of tty */ int header = 1; /* true if -h flag: don't print heading */ int nflag; /* true if -n flag: don't convert addrs */ int dflag; /* true if -d flag: output debug info */ -int sortidle; /* sort bu idle time */ +int sortidle; /* sort by idle time */ char *sel_user; /* login of particular user selected */ char domain[MAXHOSTNAMELEN]; @@ -287,7 +287,7 @@ main(argc, argv) */ dkp = ep->dkp; ep->dkp = kp; - *((struct kinfo_proc **)(&kp->kp_eproc.e_spare[ 0])) = dkp; + *((struct kinfo_proc **)(&kp->kp_eproc.e_spare[0])) = dkp; } } } @@ -352,7 +352,8 @@ main(argc, argv) } p = hp->h_name; } - if (nflag && *p && strcmp(p, "-") && inet_addr(p) == INADDR_NONE) { + if (nflag && *p && strcmp(p, "-") && + inet_addr(p) == INADDR_NONE) { hp = gethostbyname(p); if (hp != NULL) { @@ -367,8 +368,8 @@ main(argc, argv) ep->utmp.ut_host + UT_HOSTSIZE - x, x); p = buf; } - if( dflag) { - for( dkp = ep->dkp; dkp != NULL; dkp = *((struct kinfo_proc **)(&dkp->kp_eproc.e_spare[ 0]))) { + if (dflag) { + for (dkp = ep->dkp; dkp != NULL; dkp = *((struct kinfo_proc **)(&dkp->kp_eproc.e_spare[0]))) { char *p; p = fmt_argv(kvm_getargv(kd, dkp, argwidth), dkp->kp_proc.p_comm, MAXCOMLEN); @@ -385,10 +386,8 @@ main(argc, argv) ep->utmp.ut_line : ep->utmp.ut_line + 3, UT_HOSTSIZE, UT_HOSTSIZE, *p ? p : "-"); pr_attime(&ep->utmp.ut_time, &now); - longidle=pr_idle(ep->idle); - if (longidle) - argwidth--; - (void)printf("%.*s\n", argwidth, ep->args); + longidle = pr_idle(ep->idle); + (void)printf("%.*s\n", argwidth - longidle, ep->args); } exit(0); } -- cgit v1.1