diff options
author | Andrey A. Chernov <ache@FreeBSD.org> | 2001-03-02 23:11:38 +0000 |
---|---|---|
committer | Andrey A. Chernov <ache@FreeBSD.org> | 2001-03-02 23:11:38 +0000 |
commit | 000346454c6dc7c62495204afd8d6e11a1578ad9 (patch) | |
tree | 83cbe87ed66b33eea7c86731063fd27cdae6c8f6 /usr.bin/w | |
parent | f366f1bed4a84deaf988156c7d5246687f8445d5 (diff) | |
download | src-000346454c6dc7c62495204afd8d6e11a1578ad9.tar.gz src-000346454c6dc7c62495204afd8d6e11a1578ad9.zip |
Use AM/PM time only when available in locale
Notes
Notes:
svn path=/head/; revision=73365
Diffstat (limited to 'usr.bin/w')
-rw-r--r-- | usr.bin/w/extern.h | 2 | ||||
-rw-r--r-- | usr.bin/w/pr_time.c | 7 | ||||
-rw-r--r-- | usr.bin/w/w.c | 8 |
3 files changed, 10 insertions, 7 deletions
diff --git a/usr.bin/w/extern.h b/usr.bin/w/extern.h index 7037f9ad10e3..436b194f1a0d 100644 --- a/usr.bin/w/extern.h +++ b/usr.bin/w/extern.h @@ -35,6 +35,8 @@ */ +extern int use_ampm; + struct kinfo_proc; void pr_attime __P((time_t *, time_t *)); int pr_idle __P((time_t)); diff --git a/usr.bin/w/pr_time.c b/usr.bin/w/pr_time.c index 4b9614c1af88..30afc10dbdf2 100644 --- a/usr.bin/w/pr_time.c +++ b/usr.bin/w/pr_time.c @@ -50,9 +50,6 @@ static const char rcsid[] = /* * pr_attime -- * Print the time since the user logged in. - * - * Note: SCCS forces the bizarre string manipulation, things like - * 8.2 get replaced in the source code. */ void pr_attime(started, now) @@ -77,12 +74,12 @@ pr_attime(started, 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, __CONCAT("%a%", "I%p")); + (void)strcpy(fmt, use_ampm ? "%a%I%p" : "%a%H "); } /* Default is hh:mm{am,pm}. */ else { - (void)strcpy(fmt, __CONCAT("%l:%", "M%p")); + (void)strcpy(fmt, use_ampm ? "%l:%M%p" : "%k:%M "); } (void)strftime(buf, sizeof(buf) - 1, fmt, &tp); diff --git a/usr.bin/w/w.c b/usr.bin/w/w.c index 77540a6eae54..fe3b16391afa 100644 --- a/usr.bin/w/w.c +++ b/usr.bin/w/w.c @@ -70,6 +70,8 @@ static const char rcsid[] = #include <errno.h> #include <fcntl.h> #include <kvm.h> +#include <langinfo.h> +#include <locale.h> #include <netdb.h> #include <nlist.h> #include <paths.h> @@ -79,7 +81,6 @@ static const char rcsid[] = #include <unistd.h> #include <utmp.h> #include <vis.h> -#include <locale.h> #include <arpa/nameser.h> #include <resolv.h> @@ -98,6 +99,7 @@ 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 by idle time */ +int use_ampm; /* use AM/PM time */ char **sel_users; /* login array of particular users selected */ char domain[MAXHOSTNAMELEN]; @@ -140,6 +142,7 @@ main(argc, argv) char buf[MAXHOSTNAMELEN], errbuf[256]; (void)setlocale(LC_ALL, ""); + use_ampm = (*nl_langinfo(T_FMT_AMPM) != '\0'); /* Are we w(1) or uptime(1)? */ if (this_is_uptime(argv[0]) == 0) { @@ -428,7 +431,8 @@ pr_header(nowp, nusers) /* * Print time of day. */ - (void)strftime(buf, sizeof(buf) - 1, "%l:%M%p", localtime(nowp)); + (void)strftime(buf, sizeof(buf) - 1, + use_ampm ? "%l:%M%p" : "%k:%M", localtime(nowp)); buf[sizeof(buf) - 1] = '\0'; (void)printf("%s ", buf); |