From f4d292b7994a09c5e769a3eac6f056279c6a1e1c Mon Sep 17 00:00:00 2001 From: "Andrey A. Chernov" Date: Wed, 21 Mar 2001 18:43:49 +0000 Subject: [PATCH] Don't attempt to parse %c --- usr.bin/finger/extern.h | 1 + usr.bin/finger/finger.c | 1 + usr.bin/finger/lprint.c | 57 ++++++++++++++++++++++++----------------- usr.bin/finger/sprint.c | 31 ++++++++++++++-------- 4 files changed, 56 insertions(+), 34 deletions(-) diff --git a/usr.bin/finger/extern.h b/usr.bin/finger/extern.h index 69b8531807f5..a0fecd02725e 100644 --- a/usr.bin/finger/extern.h +++ b/usr.bin/finger/extern.h @@ -37,6 +37,7 @@ extern char tbuf[1024]; /* Temp buffer for anybody. */ extern int entries; /* Number of people. */ extern DB *db; /* Database. */ +extern int d_first; void enter_lastlog __P((PERSON *)); PERSON *enter_person __P((struct passwd *)); diff --git a/usr.bin/finger/finger.c b/usr.bin/finger/finger.c index 0e356b30069a..6a1f9b34cb35 100644 --- a/usr.bin/finger/finger.c +++ b/usr.bin/finger/finger.c @@ -89,6 +89,7 @@ static const char rcsid[] = DB *db; time_t now; int entries, lflag, mflag, pplan, sflag, oflag, Tflag; +int d_first = -1; char tbuf[1024]; static void loginlist __P((void)); diff --git a/usr.bin/finger/lprint.c b/usr.bin/finger/lprint.c index f990be29f920..02099fdbeb5e 100644 --- a/usr.bin/finger/lprint.c +++ b/usr.bin/finger/lprint.c @@ -47,6 +47,7 @@ static const char rcsid[] = #include #include #include +#include #include #include #include @@ -106,9 +107,10 @@ lprint(pn) register int cpr, len, maxlen; struct tm *tp; int oddfield; - char *tzn; char t[80]; + if (d_first < 0) + d_first = (*nl_langinfo(D_MD_ORDER) == 'd'); /* * long format -- * login name @@ -173,10 +175,10 @@ lprint(pn) for (w = pn->whead; w != NULL; w = w->next) { if (w->info == LOGGEDIN) { tp = localtime(&w->loginat); - strftime(t, sizeof(t), "%c", tp); - tzn = tp->tm_zone; - cpr = printf("On since %.16s (%s) on %s", - t, tzn, w->tty); + strftime(t, sizeof(t), + d_first ? "%a %e %b %R (%Z)" : "%a %b %e %R (%Z)", + tp); + cpr = printf("On since %s on %s", t, w->tty); /* * idle time is tough; if have one, print a comma, * then spaces to pad out the device name, then the @@ -204,15 +206,18 @@ lprint(pn) cpr = printf("Never logged in."); } else { tp = localtime(&w->loginat); - strftime(t, sizeof(t), "%c", tp); - tzn = tp->tm_zone; - if (now - w->loginat > 86400 * 365 / 2) - cpr = - printf("Last login %.16s %.4s (%s) on %s", - t, t + 20, tzn, w->tty); - else - cpr = printf("Last login %.16s (%s) on %s", - t, tzn, w->tty); + if (now - w->loginat > 86400 * 365 / 2) { + strftime(t, sizeof(t), + d_first ? "%a %e %b %R %Y (%Z)" : + "%a %b %e %R %Y (%Z)", + tp); + } else { + strftime(t, sizeof(t), + d_first ? "%a %e %b %R (%Z)" : + "%a %b %e %R (%Z)", + tp); + } + cpr = printf("Last login %s on %s", t, w->tty); } if (*w->host) { if (LINE_LEN < (cpr + 6 + strlen(w->host))) @@ -225,18 +230,24 @@ lprint(pn) printf("No Mail.\n"); else if (pn->mailrecv > pn->mailread) { tp = localtime(&pn->mailrecv); - strftime(t, sizeof(t), "%c", tp); - tzn = tp->tm_zone; - printf("New mail received %.16s %.4s (%s)\n", t, t + 20, tzn); + strftime(t, sizeof(t), + d_first ? "%a %e %b %R %Y (%Z)" : + "%a %b %e %R %Y (%Z)", + tp); + printf("New mail received %s\n", t); tp = localtime(&pn->mailread); - strftime(t, sizeof(t), "%c", tp); - tzn = tp->tm_zone; - printf(" Unread since %.16s %.4s (%s)\n", t, t + 20, tzn); + strftime(t, sizeof(t), + d_first ? "%a %e %b %R %Y (%Z)" : + "%a %b %e %R %Y (%Z)", + tp); + printf(" Unread since %s\n", t); } else { tp = localtime(&pn->mailread); - strftime(t, sizeof(t), "%c", tp); - tzn = tp->tm_zone; - printf("Mail last read %.16s %.4s (%s)\n", t, t + 20, tzn); + strftime(t, sizeof(t), + d_first ? "%a %e %b %R %Y (%Z)" : + "%a %b %e %R %Y (%Z)", + tp); + printf("Mail last read %s\n", t); } } diff --git a/usr.bin/finger/sprint.c b/usr.bin/finger/sprint.c index e373edbebe24..12117e4cb4a3 100644 --- a/usr.bin/finger/sprint.c +++ b/usr.bin/finger/sprint.c @@ -44,6 +44,7 @@ static const char rcsid[] = #include #include +#include #include #include #include @@ -64,7 +65,10 @@ sflag_print() char p[80]; PERSON *tmp; DBT data, key; + struct tm *lc; + if (d_first < 0) + d_first = (*nl_langinfo(D_MD_ORDER) == 'd'); /* * short format -- * login name @@ -84,8 +88,8 @@ sflag_print() #define MAXREALNAME 20 #define MAXHOSTNAME 17 /* in reality, hosts are never longer than 16 */ (void)printf("%-*s %-*s%s %s\n", UT_NAMESIZE, "Login", MAXREALNAME, - "Name", " TTY Idle Login Time", - oflag ? " Office Phone" : " Where"); + "Name", " TTY Idle Login Time", + oflag ? "Office Phone" : "Where"); for (sflag = R_FIRST;; sflag = R_NEXT) { r = (*db->seq)(db, &key, &data, sflag); @@ -121,18 +125,23 @@ sflag_print() (void)printf(" "); } else (void)printf(" * "); - strftime(p, sizeof(p), "%c", localtime(&w->loginat)); + lc = localtime(&w->loginat); #define SECSPERDAY 86400 #define DAYSPERWEEK 7 #define DAYSPERNYEAR 365 - if (now - w->loginat < SECSPERDAY * (DAYSPERWEEK - 1)) - (void)printf("%.3s ", p); - else - (void)printf("%.6s", p + 4); - if (now - w->loginat >= SECSPERDAY * DAYSPERNYEAR / 2) - (void)printf(" %.4s", p + 20); - else - (void)printf(" %.5s", p + 11); + if (now - w->loginat < SECSPERDAY * (DAYSPERWEEK - 1)) { + (void)strftime(p, sizeof(p), "%a", lc); + } else { + (void)strftime(p, sizeof(p), + d_first ? "%e %b" : "%b %e", lc); + } + (void)printf("%-6.6s", p); + if (now - w->loginat >= SECSPERDAY * DAYSPERNYEAR / 2) { + (void)strftime(p, sizeof(p), "%Y", lc); + } else { + (void)strftime(p, sizeof(p), "%R", lc); + } + (void)printf(" %-5.5s", p); office: if (oflag) { if (pn->office) (void)printf(" %-7.7s", pn->office);