summaryrefslogtreecommitdiffstats
path: root/usr.bin/finger/sprint.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin/finger/sprint.c')
-rw-r--r--usr.bin/finger/sprint.c73
1 files changed, 48 insertions, 25 deletions
diff --git a/usr.bin/finger/sprint.c b/usr.bin/finger/sprint.c
index 54c7eea..8c38d7c 100644
--- a/usr.bin/finger/sprint.c
+++ b/usr.bin/finger/sprint.c
@@ -35,13 +35,17 @@
*/
#ifndef lint
+#if 0
static char sccsid[] = "@(#)sprint.c 8.3 (Berkeley) 4/28/95";
+#else
+static const char rcsid[] =
+ "$Id$";
+#endif
#endif /* not lint */
#include <sys/types.h>
#include <sys/time.h>
#include <time.h>
-#include <tzfile.h>
#include <db.h>
#include <err.h>
#include <pwd.h>
@@ -58,10 +62,11 @@ void
sflag_print()
{
extern time_t now;
+ extern int oflag;
register PERSON *pn;
register WHERE *w;
- register int sflag, r;
- register char *p;
+ register int sflag, r, namelen;
+ char p[80];
PERSON *tmp;
DBT data, key;
@@ -73,14 +78,19 @@ sflag_print()
* if terminal writeable (add an '*' to the terminal name
* if not)
* if logged in show idle time and day logged in, else
- * show last login date and time. If > 6 moths,
- * show year instead of time.
- * office location
- * office phone
+ * show last login date and time.
+ * If > 6 months, show year instead of time.
+ * if (-o)
+ * office location
+ * office phone
+ * else
+ * remote host
*/
#define MAXREALNAME 20
- (void)printf("%-*s %-*s %s\n", UT_NAMESIZE, "Login", MAXREALNAME,
- "Name", "Tty Idle Login Time Office Office Phone");
+#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");
for (sflag = R_FIRST;; sflag = R_NEXT) {
r = (*db->seq)(db, &key, &data, sflag);
@@ -92,9 +102,12 @@ sflag_print()
pn = tmp;
for (w = pn->whead; w != NULL; w = w->next) {
- (void)printf("%-*.*s %-*.*s ", UT_NAMESIZE, UT_NAMESIZE,
- pn->name, MAXREALNAME, MAXREALNAME,
- pn->realname ? pn->realname : "");
+ namelen = MAXREALNAME;
+ if (w->info == LOGGEDIN && !w->writable)
+ --namelen; /* leave space before `*' */
+ (void)printf("%-*.*s %-*.*s", UT_NAMESIZE, UT_NAMESIZE,
+ pn->name, MAXREALNAME, namelen,
+ pn->realname ? pn->realname : "");
if (!w->loginat) {
(void)printf(" * * No logins ");
goto office;
@@ -102,29 +115,39 @@ sflag_print()
(void)putchar(w->info == LOGGEDIN && !w->writable ?
'*' : ' ');
if (*w->tty)
- (void)printf("%-2.2s ",
- w->tty[0] != 't' || w->tty[1] != 't' ||
- w->tty[2] != 'y' ? w->tty : w->tty + 3);
+ (void)printf("%-3.3s ",
+ (strncmp(w->tty, "tty", 3)
+ && strncmp(w->tty, "cua", 3))
+ ? w->tty : w->tty + 3);
else
- (void)printf(" ");
+ (void)printf(" ");
if (w->info == LOGGEDIN) {
stimeprint(w);
(void)printf(" ");
} else
(void)printf(" * ");
- p = ctime(&w->loginat);
- (void)printf("%.6s", p + 4);
+ strftime(p, sizeof(p), "%c", 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);
-office: if (pn->office)
- (void)printf(" %-10.10s", pn->office);
- else if (pn->officephone)
- (void)printf(" %-10.10s", " ");
- if (pn->officephone)
- (void)printf(" %-.15s",
- prphone(pn->officephone));
+office: if (oflag) {
+ if (pn->office)
+ (void)printf(" %-7.7s", pn->office);
+ else if (pn->officephone)
+ (void)printf(" %-7.7s", " ");
+ if (pn->officephone)
+ (void)printf(" %-.9s",
+ prphone(pn->officephone));
+ } else
+ (void)printf(" %.*s", MAXHOSTNAME, w->host);
putchar('\n');
}
}
OpenPOWER on IntegriCloud