summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorume <ume@FreeBSD.org>2009-08-30 11:17:42 +0000
committerume <ume@FreeBSD.org>2009-08-30 11:17:42 +0000
commit5fb95a2095446b02c21f0e4ecad4b7bff41c856a (patch)
tree7bf9aeb96248569d4de361589958b5bc4732cbe8
parent7417f9bcd242fe20479c87d0e5f24840616ab1d3 (diff)
downloadFreeBSD-src-5fb95a2095446b02c21f0e4ecad4b7bff41c856a.zip
FreeBSD-src-5fb95a2095446b02c21f0e4ecad4b7bff41c856a.tar.gz
Fix the problem that the entry broke into two lines with multi-byte
AM/PM format. Reported by: takawata
-rw-r--r--usr.bin/w/extern.h2
-rw-r--r--usr.bin/w/pr_time.c27
-rw-r--r--usr.bin/w/w.c7
3 files changed, 24 insertions, 12 deletions
diff --git a/usr.bin/w/extern.h b/usr.bin/w/extern.h
index 070d055..f3c0045 100644
--- a/usr.bin/w/extern.h
+++ b/usr.bin/w/extern.h
@@ -38,6 +38,6 @@
extern int use_ampm;
struct kinfo_proc;
-void pr_attime(time_t *, time_t *);
+int pr_attime(time_t *, time_t *);
int pr_idle(time_t);
int proc_compare(struct kinfo_proc *, struct kinfo_proc *);
diff --git a/usr.bin/w/pr_time.c b/usr.bin/w/pr_time.c
index 9fe0b11..4576b5e 100644
--- a/usr.bin/w/pr_time.c
+++ b/usr.bin/w/pr_time.c
@@ -52,13 +52,14 @@ static const char sccsid[] = "@(#)pr_time.c 8.2 (Berkeley) 4/4/94";
* pr_attime --
* Print the time since the user logged in.
*/
-void
+int
pr_attime(time_t *started, time_t *now)
{
- static char buf[256];
+ static wchar_t buf[256];
struct tm tp, tm;
time_t diff;
- char fmt[20];
+ wchar_t *fmt;
+ int len, width, offset = 0;
tp = *localtime(started);
tm = *localtime(now);
@@ -66,7 +67,7 @@ pr_attime(time_t *started, time_t *now)
/* If more than a week, use day-month-year. */
if (diff > 86400 * 7)
- (void)strcpy(fmt, "%d%b%y");
+ fmt = L"%d%b%y";
/* If not today, use day-hour-am/pm. */
else if (tm.tm_mday != tp.tm_mday ||
@@ -74,16 +75,26 @@ pr_attime(time_t *started, time_t *now)
tm.tm_year != tp.tm_year) {
/* The line below does not take DST into consideration */
/* else if (*now / 86400 != *started / 86400) { */
- (void)strcpy(fmt, use_ampm ? "%a%I%p" : "%a%H");
+ fmt = use_ampm ? L"%a%I%p" : L"%a%H";
}
/* Default is hh:mm{am,pm}. */
else {
- (void)strcpy(fmt, use_ampm ? "%l:%M%p" : "%k:%M");
+ fmt = use_ampm ? L"%l:%M%p" : L"%k:%M";
}
- (void)strftime(buf, sizeof(buf), fmt, &tp);
- (void)wprintf(L"%-7.7s", buf);
+ (void)wcsftime(buf, sizeof(buf), fmt, &tp);
+ len = wcslen(buf);
+ width = wcswidth(buf, len);
+ if (len == width)
+ (void)wprintf(L"%-7.7ls", buf);
+ else if (width < 7)
+ (void)wprintf(L"%ls%.*s", buf, 7 - width, " ");
+ else {
+ (void)wprintf(L"%ls", buf);
+ offset = width - 7;
+ }
+ return (offset);
}
/*
diff --git a/usr.bin/w/w.c b/usr.bin/w/w.c
index 379e6a4..10ec7b0 100644
--- a/usr.bin/w/w.c
+++ b/usr.bin/w/w.c
@@ -137,7 +137,7 @@ main(int argc, char *argv[])
struct stat *stp;
FILE *ut;
time_t touched;
- int ch, i, nentries, nusers, wcmd, longidle, dropgid;
+ int ch, i, nentries, nusers, wcmd, longidle, longattime, dropgid;
const char *memf, *nlistf, *p;
char *x_suffix;
char buf[MAXHOSTNAMELEN], errbuf[_POSIX2_LINE_MAX];
@@ -406,9 +406,10 @@ main(int argc, char *argv[])
ep->utmp.ut_line : ep->utmp.ut_line + 3,
W_DISPHOSTSIZE, W_DISPHOSTSIZE, *p ? p : "-");
t = _time_to_time32(ep->utmp.ut_time);
- pr_attime(&t, &now);
+ longattime = pr_attime(&t, &now);
longidle = pr_idle(ep->idle);
- (void)printf("%.*s\n", argwidth - longidle, ep->args);
+ (void)printf("%.*s\n", argwidth - longidle - longattime,
+ ep->args);
}
(void)kvm_close(kd);
exit(0);
OpenPOWER on IntegriCloud