diff options
author | ache <ache@FreeBSD.org> | 2001-03-02 23:11:38 +0000 |
---|---|---|
committer | ache <ache@FreeBSD.org> | 2001-03-02 23:11:38 +0000 |
commit | fe36abf2a2f077438e6508f74d8aab0ef94f3407 (patch) | |
tree | 86b80a29b14392eaa125a314a4bdce2acc853b75 /usr.bin/w | |
parent | 1f9d1d9ad2bc748fd0af7770e0100696ec49600e (diff) | |
download | FreeBSD-src-fe36abf2a2f077438e6508f74d8aab0ef94f3407.zip FreeBSD-src-fe36abf2a2f077438e6508f74d8aab0ef94f3407.tar.gz |
Use AM/PM time only when available in locale
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 7037f9a..436b194 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 4b9614c..30afc10 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 77540a6..fe3b163 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); |