aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Wemm <peter@FreeBSD.org>1999-01-10 15:28:37 +0000
committerPeter Wemm <peter@FreeBSD.org>1999-01-10 15:28:37 +0000
commit69b41093b5e335a9d938be3ea703f53887ab1201 (patch)
tree6dbf8d9ccfb816dc544767a3a11b4ed91197a6ea
parentc03fa7f977282b20757a4d0ebf197bb220cfd306 (diff)
downloadsrc-69b41093b5e335a9d938be3ea703f53887ab1201.tar.gz
src-69b41093b5e335a9d938be3ea703f53887ab1201.zip
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.
Notes
Notes: svn path=/head/; revision=42481
-rw-r--r--usr.bin/w/pr_time.c9
-rw-r--r--usr.bin/w/w.c19
2 files changed, 15 insertions, 13 deletions
diff --git a/usr.bin/w/pr_time.c b/usr.bin/w/pr_time.c
index 0b53586c304c..5b38b58dd126 100644
--- a/usr.bin/w/pr_time.c
+++ b/usr.bin/w/pr_time.c
@@ -36,7 +36,7 @@
static char sccsid[] = "@(#)pr_time.c 8.2 (Berkeley) 4/4/94";
#endif
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 */
#include <sys/types.h>
@@ -88,6 +88,7 @@ pr_attime(started, now)
/*
* pr_idle --
* Display the idle time.
+ * Returns number of excess characters that were used for long idle time.
*/
int
pr_idle(idle)
@@ -97,8 +98,10 @@ pr_idle(idle)
if (idle >= 36 * 3600) {
int days = idle / 86400;
(void)printf(" %dday%s ", days, days > 1 ? "s" : " " );
+ if (days >= 100)
+ return (2);
if (days >= 10)
- return(1);
+ return (1);
}
/* If idle more than an hour, print as HH:MM. */
@@ -113,5 +116,5 @@ pr_idle(idle)
else
(void)printf(" %2d ", (int)(idle / 60));
- return(0); /* not idle longer than 9 days */
+ return (0); /* not idle longer than 9 days */
}
diff --git a/usr.bin/w/w.c b/usr.bin/w/w.c
index 299b0d6560da..18e43c061941 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);
}