summaryrefslogtreecommitdiffstats
path: root/usr.bin/finger
diff options
context:
space:
mode:
authorache <ache@FreeBSD.org>2001-03-21 18:43:49 +0000
committerache <ache@FreeBSD.org>2001-03-21 18:43:49 +0000
commitba9451ee824bda21b42c1f3176409ce84dec625d (patch)
tree3f78b8c041292d72fca599b69814871322e0cbc1 /usr.bin/finger
parent7ce0e6c37fe4599d18e9cc31a6dee1be86e9be64 (diff)
downloadFreeBSD-src-ba9451ee824bda21b42c1f3176409ce84dec625d.zip
FreeBSD-src-ba9451ee824bda21b42c1f3176409ce84dec625d.tar.gz
Don't attempt to parse %c
Diffstat (limited to 'usr.bin/finger')
-rw-r--r--usr.bin/finger/extern.h1
-rw-r--r--usr.bin/finger/finger.c1
-rw-r--r--usr.bin/finger/lprint.c57
-rw-r--r--usr.bin/finger/sprint.c31
4 files changed, 56 insertions, 34 deletions
diff --git a/usr.bin/finger/extern.h b/usr.bin/finger/extern.h
index 69b8531..a0fecd0 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 0e356b3..6a1f9b3 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 f990be2..02099fd 100644
--- a/usr.bin/finger/lprint.c
+++ b/usr.bin/finger/lprint.c
@@ -47,6 +47,7 @@ static const char rcsid[] =
#include <db.h>
#include <err.h>
#include <fcntl.h>
+#include <langinfo.h>
#include <paths.h>
#include <pwd.h>
#include <stdio.h>
@@ -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 e373edb..12117e4 100644
--- a/usr.bin/finger/sprint.c
+++ b/usr.bin/finger/sprint.c
@@ -44,6 +44,7 @@ static const char rcsid[] =
#include <db.h>
#include <err.h>
+#include <langinfo.h>
#include <pwd.h>
#include <stdio.h>
#include <string.h>
@@ -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);
OpenPOWER on IntegriCloud