137660Sbostic /*
261995Sbostic * Copyright (c) 1989, 1993
361995Sbostic * The Regents of the University of California. All rights reserved.
437660Sbostic *
540027Sbostic * This code is derived from software contributed to Berkeley by
640027Sbostic * Tony Nardo of the Johns Hopkins University/Applied Physics Lab.
740027Sbostic *
842731Sbostic * %sccs.include.redist.c%
937660Sbostic */
1037660Sbostic
1137660Sbostic #ifndef lint
12*69102Sbostic static char sccsid[] = "@(#)sprint.c 8.3 (Berkeley) 04/28/95";
1337660Sbostic #endif /* not lint */
1437660Sbostic
1537660Sbostic #include <sys/types.h>
1637660Sbostic #include <sys/time.h>
1750596Sbostic #include <time.h>
1837660Sbostic #include <tzfile.h>
1950613Sbostic #include <db.h>
2069101Sbostic #include <err.h>
2150596Sbostic #include <pwd.h>
2250613Sbostic #include <errno.h>
2350596Sbostic #include <utmp.h>
2437660Sbostic #include <stdio.h>
2550596Sbostic #include <stdlib.h>
2650596Sbostic #include <string.h>
2737660Sbostic #include "finger.h"
2837660Sbostic
2950596Sbostic static void stimeprint __P((WHERE *));
3037660Sbostic
3150596Sbostic void
sflag_print()3237660Sbostic sflag_print()
3337660Sbostic {
3437660Sbostic extern time_t now;
3537660Sbostic register PERSON *pn;
3637664Sedward register WHERE *w;
3751423Sbostic register int sflag, r;
3837660Sbostic register char *p;
3969101Sbostic PERSON *tmp;
4051423Sbostic DBT data, key;
4137660Sbostic
4237660Sbostic /*
4337660Sbostic * short format --
4437660Sbostic * login name
4537660Sbostic * real name
4637660Sbostic * terminal name (the XX of ttyXX)
4737660Sbostic * if terminal writeable (add an '*' to the terminal name
4837660Sbostic * if not)
4937660Sbostic * if logged in show idle time and day logged in, else
5037660Sbostic * show last login date and time. If > 6 moths,
5137660Sbostic * show year instead of time.
5237660Sbostic * office location
5337660Sbostic * office phone
5437660Sbostic */
5537660Sbostic #define MAXREALNAME 20
5637660Sbostic (void)printf("%-*s %-*s %s\n", UT_NAMESIZE, "Login", MAXREALNAME,
5745687Sbostic "Name", "Tty Idle Login Time Office Office Phone");
5851423Sbostic
5951423Sbostic for (sflag = R_FIRST;; sflag = R_NEXT) {
6051423Sbostic r = (*db->seq)(db, &key, &data, sflag);
6151423Sbostic if (r == -1)
6269101Sbostic err(1, "db seq");
6351423Sbostic if (r == 1)
6451423Sbostic break;
65*69102Sbostic memmove(&tmp, data.data, sizeof tmp);
6669101Sbostic pn = tmp;
6751423Sbostic
6837664Sedward for (w = pn->whead; w != NULL; w = w->next) {
6937664Sedward (void)printf("%-*.*s %-*.*s ", UT_NAMESIZE, UT_NAMESIZE,
7037664Sedward pn->name, MAXREALNAME, MAXREALNAME,
7137664Sedward pn->realname ? pn->realname : "");
7237664Sedward if (!w->loginat) {
7337664Sedward (void)printf(" * * No logins ");
7437664Sedward goto office;
7537664Sedward }
7637664Sedward (void)putchar(w->info == LOGGEDIN && !w->writable ?
7737664Sedward '*' : ' ');
7837664Sedward if (*w->tty)
7937664Sedward (void)printf("%-2.2s ",
8037664Sedward w->tty[0] != 't' || w->tty[1] != 't' ||
8137664Sedward w->tty[2] != 'y' ? w->tty : w->tty + 3);
8237664Sedward else
8337664Sedward (void)printf(" ");
8437664Sedward if (w->info == LOGGEDIN) {
8537664Sedward stimeprint(w);
8637664Sedward (void)printf(" ");
8737664Sedward } else
8837664Sedward (void)printf(" * ");
8937664Sedward p = ctime(&w->loginat);
9037664Sedward (void)printf("%.6s", p + 4);
9137664Sedward if (now - w->loginat >= SECSPERDAY * DAYSPERNYEAR / 2)
9237664Sedward (void)printf(" %.4s", p + 20);
9337664Sedward else
9437664Sedward (void)printf(" %.5s", p + 11);
9537664Sedward office: if (pn->office)
9638052Sbostic (void)printf(" %-10.10s", pn->office);
9737664Sedward else if (pn->officephone)
9838052Sbostic (void)printf(" %-10.10s", " ");
9937664Sedward if (pn->officephone)
10038052Sbostic (void)printf(" %-.15s",
10138052Sbostic prphone(pn->officephone));
10237664Sedward putchar('\n');
10337660Sbostic }
10437660Sbostic }
10537660Sbostic }
10637660Sbostic
10750596Sbostic static void
stimeprint(w)10837664Sedward stimeprint(w)
10937664Sedward WHERE *w;
11037660Sbostic {
11137660Sbostic register struct tm *delta;
11237660Sbostic
11337664Sedward delta = gmtime(&w->idletime);
11437660Sbostic if (!delta->tm_yday)
11537660Sbostic if (!delta->tm_hour)
11637660Sbostic if (!delta->tm_min)
11737660Sbostic (void)printf(" ");
11837660Sbostic else
11937660Sbostic (void)printf("%5d", delta->tm_min);
12037660Sbostic else
12137660Sbostic (void)printf("%2d:%02d",
12237660Sbostic delta->tm_hour, delta->tm_min);
12337660Sbostic else
12437660Sbostic (void)printf("%4dd", delta->tm_yday);
12537660Sbostic }
126