From owner-svn-src-all@FreeBSD.ORG Sun Sep 13 17:08:58 2009 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id BF59D106566C; Sun, 13 Sep 2009 17:08:58 +0000 (UTC) (envelope-from ume@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 755608FC0C; Sun, 13 Sep 2009 17:08:58 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n8DH8w5Z026822; Sun, 13 Sep 2009 17:08:58 GMT (envelope-from ume@svn.freebsd.org) Received: (from ume@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n8DH8wlY026818; Sun, 13 Sep 2009 17:08:58 GMT (envelope-from ume@svn.freebsd.org) Message-Id: <200909131708.n8DH8wlY026818@svn.freebsd.org> From: Hajimu UMEMOTO Date: Sun, 13 Sep 2009 17:08:58 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-7@freebsd.org X-SVN-Group: stable-7 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r197171 - stable/7/usr.bin/w X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 13 Sep 2009 17:08:59 -0000 Author: ume Date: Sun Sep 13 17:08:58 2009 New Revision: 197171 URL: http://svn.freebsd.org/changeset/base/197171 Log: MFC r196652: Fix the problem that the entry broke into two lines with multi-byte AM/PM date format. Modified: stable/7/usr.bin/w/ (props changed) stable/7/usr.bin/w/extern.h stable/7/usr.bin/w/pr_time.c stable/7/usr.bin/w/w.c Modified: stable/7/usr.bin/w/extern.h ============================================================================== --- stable/7/usr.bin/w/extern.h Sun Sep 13 17:05:56 2009 (r197170) +++ stable/7/usr.bin/w/extern.h Sun Sep 13 17:08:58 2009 (r197171) @@ -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 *); Modified: stable/7/usr.bin/w/pr_time.c ============================================================================== --- stable/7/usr.bin/w/pr_time.c Sun Sep 13 17:05:56 2009 (r197170) +++ stable/7/usr.bin/w/pr_time.c Sun Sep 13 17:08:58 2009 (r197171) @@ -52,13 +52,14 @@ static const char sccsid[] = "@(#)pr_tim * 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); } /* Modified: stable/7/usr.bin/w/w.c ============================================================================== --- stable/7/usr.bin/w/w.c Sun Sep 13 17:05:56 2009 (r197170) +++ stable/7/usr.bin/w/w.c Sun Sep 13 17:08:58 2009 (r197171) @@ -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);