Subject: Re: bin/31436
To: None <gnats-admin@netbsd.org, netbsd-bugs@netbsd.org>
From: Zafer Aydogan <zafer@gmx.org>
List: netbsd-bugs
Date: 10/01/2005 07:14:02
The following reply was made to PR bin/31436; it has been noted by GNATS.
From: "Zafer Aydogan" <zafer@gmx.org>
To: gnats-bugs@netbsd.org
Cc:
Subject: Re: bin/31436
Date: Sat, 1 Oct 2005 09:13:06 +0200 (MEST)
A Patch for 24h format in "w".
--- w.c.old2005-10-01 08:33:22.000000000 +0200
+++ w.c2005-10-01 08:32:53.000000000 +0200
@@ -98,6 +98,7 @@
intnflag;/* true if -n flag: don't convert addrs */
intwflag;/* true if -w flag: wide printout */
intsortidle;/* sort bu idle time */
+inttimeformat;/* true if -H flag: print time in 24h format */
char *sel_user;/* login of particular user selected */
chardomain[MAXHOSTNAMELEN + 1];
int maxname = 8, maxline = 3, maxhost = 16;
@@ -159,12 +160,15 @@
p = "";
} else {
wcmd = 1;
-p = "hiM:N:nw";
+p = "hiM:N:nHw";
}
memf = nlistf = NULL;
while ((ch = getopt(argc, argv, p)) != -1)
switch (ch) {
+case 'H':
+timeformat = 1;
+break;
case 'h':
header = 0;
break;
@@ -438,7 +442,7 @@
maxname, usrnp, ep->line,
maxhost, maxhost, *p ? p : "-");
then = (time_t)ep->tv.tv_sec;
-pr_attime(&then, &now);
+pr_attime(&then, &now, &timeformat);
pr_idle(ep->idle);
pr_args(kp);
(void)printf("\n");
@@ -492,9 +496,16 @@
* SCCS forces the string manipulation below, as it replaces
* %, M, and % in a character string with the file name.
*/
-(void)strftime(buf, sizeof(buf), "%l:%" "M%p", localtime(nowp));
-buf[sizeof(buf) - 1] = '\0';
-(void)printf("%s ", buf);
+if (timeformat == 1) {
+(void)strftime(buf, sizeof(buf), "%H:%" "M:%S", localtime(nowp));
+buf[sizeof(buf) - 1] = '\0';
+(void)printf("%s ", buf);
+}
+else {
+(void)strftime(buf, sizeof(buf), "%l:%" "M%p", localtime(nowp));
+buf[sizeof(buf) - 1] = '\0';
+(void)printf("%s ", buf);
+}
/*
* Print how long system has been up.
--- pr_time.c.old2005-10-01 08:33:22.000000000 +0200
+++ pr_time.c2005-10-01 08:58:27.000000000 +0200
@@ -56,7 +56,7 @@
*%I% get replaced in the source code.
*/
void
-pr_attime(time_t *started, time_t *now)
+pr_attime(time_t *started, time_t *now, int *timeformat)
{
static char buf[256];
int tnow_yday;
@@ -72,14 +72,22 @@
if (diff > SECSPERDAY * DAYSPERWEEK)
fmt = "%d%b%y";
+/* If not today, use day-hour. */
+else if (tp->tm_yday != tnow_yday && *timeformat ==1)
+ fmt = " %a%" "%H";
+
/* If not today, use day-hour-am/pm. */
-else if (tp->tm_yday != tnow_yday)
-fmt = "%a%" "I%p";
+ else if (tp->tm_yday != tnow_yday)
+ fmt = "%a%" "%I%p";
+
+/* Default is HH:mm when flag -H set */
+else if (*timeformat ==1)
+ fmt = " %H:%" "M";
/* Default is hh:mm{am,pm}. */
else
fmt = "%l:%" "M%p";
-
+
(void)strftime(buf, sizeof(buf), fmt, tp);
buf[sizeof(buf) - 1] = '\0';
(void)fputs(buf, stdout);
--- extern.h.old2005-10-01 08:33:22.000000000 +0200
+++ extern.h2005-10-01 08:32:45.000000000 +0200
@@ -34,6 +34,6 @@
struct kinfo_proc2;
voidfmt_puts(char *, int *);
voidfmt_putc(int, int *);
-voidpr_attime(time_t *, time_t *);
+voidpr_attime(time_t *, time_t *, int *);
voidpr_idle(time_t);
intproc_compare(struct kinfo_proc2 *, struct kinfo_proc2 *);