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.
This commit is contained in:
Peter Wemm 1999-01-10 15:28:37 +00:00
parent c03fa7f977
commit 69b41093b5
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=42481
2 changed files with 15 additions and 13 deletions

View File

@ -36,7 +36,7 @@
static char sccsid[] = "@(#)pr_time.c 8.2 (Berkeley) 4/4/94"; static char sccsid[] = "@(#)pr_time.c 8.2 (Berkeley) 4/4/94";
#endif #endif
static const char rcsid[] = static const char rcsid[] =
"$Id: pr_time.c,v 1.10 1997/08/26 06:59:34 charnier Exp $"; "$Id: pr_time.c,v 1.11 1997/12/28 17:50:10 alex Exp $";
#endif /* not lint */ #endif /* not lint */
#include <sys/types.h> #include <sys/types.h>
@ -88,6 +88,7 @@ pr_attime(started, now)
/* /*
* pr_idle -- * pr_idle --
* Display the idle time. * Display the idle time.
* Returns number of excess characters that were used for long idle time.
*/ */
int int
pr_idle(idle) pr_idle(idle)
@ -97,8 +98,10 @@ pr_idle(idle)
if (idle >= 36 * 3600) { if (idle >= 36 * 3600) {
int days = idle / 86400; int days = idle / 86400;
(void)printf(" %dday%s ", days, days > 1 ? "s" : " " ); (void)printf(" %dday%s ", days, days > 1 ? "s" : " " );
if (days >= 100)
return (2);
if (days >= 10) if (days >= 10)
return(1); return (1);
} }
/* If idle more than an hour, print as HH:MM. */ /* If idle more than an hour, print as HH:MM. */
@ -113,5 +116,5 @@ pr_idle(idle)
else else
(void)printf(" %2d ", (int)(idle / 60)); (void)printf(" %2d ", (int)(idle / 60));
return(0); /* not idle longer than 9 days */ return (0); /* not idle longer than 9 days */
} }

View File

@ -42,7 +42,7 @@ static const char copyright[] =
static char sccsid[] = "@(#)w.c 8.4 (Berkeley) 4/16/94"; static char sccsid[] = "@(#)w.c 8.4 (Berkeley) 4/16/94";
#endif #endif
static const char rcsid[] = 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 */ #endif /* not lint */
/* /*
@ -97,7 +97,7 @@ int argwidth; /* width of tty */
int header = 1; /* true if -h flag: don't print heading */ int header = 1; /* true if -h flag: don't print heading */
int nflag; /* true if -n flag: don't convert addrs */ int nflag; /* true if -n flag: don't convert addrs */
int dflag; /* true if -d flag: output debug info */ 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 *sel_user; /* login of particular user selected */
char domain[MAXHOSTNAMELEN]; char domain[MAXHOSTNAMELEN];
@ -287,7 +287,7 @@ main(argc, argv)
*/ */
dkp = ep->dkp; dkp = ep->dkp;
ep->dkp = kp; 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; 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); hp = gethostbyname(p);
if (hp != NULL) { if (hp != NULL) {
@ -367,8 +368,8 @@ main(argc, argv)
ep->utmp.ut_host + UT_HOSTSIZE - x, x); ep->utmp.ut_host + UT_HOSTSIZE - x, x);
p = buf; p = buf;
} }
if( dflag) { if (dflag) {
for( dkp = ep->dkp; dkp != NULL; dkp = *((struct kinfo_proc **)(&dkp->kp_eproc.e_spare[ 0]))) { for (dkp = ep->dkp; dkp != NULL; dkp = *((struct kinfo_proc **)(&dkp->kp_eproc.e_spare[0]))) {
char *p; char *p;
p = fmt_argv(kvm_getargv(kd, dkp, argwidth), p = fmt_argv(kvm_getargv(kd, dkp, argwidth),
dkp->kp_proc.p_comm, MAXCOMLEN); dkp->kp_proc.p_comm, MAXCOMLEN);
@ -385,10 +386,8 @@ main(argc, argv)
ep->utmp.ut_line : ep->utmp.ut_line + 3, ep->utmp.ut_line : ep->utmp.ut_line + 3,
UT_HOSTSIZE, UT_HOSTSIZE, *p ? p : "-"); UT_HOSTSIZE, UT_HOSTSIZE, *p ? p : "-");
pr_attime(&ep->utmp.ut_time, &now); pr_attime(&ep->utmp.ut_time, &now);
longidle=pr_idle(ep->idle); longidle = pr_idle(ep->idle);
if (longidle) (void)printf("%.*s\n", argwidth - longidle, ep->args);
argwidth--;
(void)printf("%.*s\n", argwidth, ep->args);
} }
exit(0); exit(0);
} }