Commit | Line | Data |
---|---|---|
6b8910b8 KB |
1 | /* |
2 | * Copyright (c) 1989 The Regents of the University of California. | |
3 | * All rights reserved. | |
4 | * | |
f15db449 | 5 | * %sccs.include.redist.c% |
6b8910b8 KB |
6 | */ |
7 | ||
8 | #ifndef lint | |
f15db449 | 9 | static char sccsid[] = "@(#)sprint.c 5.7 (Berkeley) %G%"; |
6b8910b8 KB |
10 | #endif /* not lint */ |
11 | ||
12 | #include <sys/types.h> | |
13 | #include <sys/time.h> | |
14 | #include <tzfile.h> | |
15 | #include <stdio.h> | |
16 | #include "finger.h" | |
17 | ||
18 | extern int entries; | |
19 | ||
20 | sflag_print() | |
21 | { | |
22 | extern time_t now; | |
23 | register PERSON *pn; | |
7619ff47 | 24 | register WHERE *w; |
6b8910b8 KB |
25 | register int cnt; |
26 | register char *p; | |
27 | PERSON **list, **sort(); | |
28 | time_t time(); | |
f156ea40 | 29 | char *ctime(), *prphone(); |
6b8910b8 KB |
30 | |
31 | list = sort(); | |
32 | /* | |
33 | * short format -- | |
34 | * login name | |
35 | * real name | |
36 | * terminal name (the XX of ttyXX) | |
37 | * if terminal writeable (add an '*' to the terminal name | |
38 | * if not) | |
39 | * if logged in show idle time and day logged in, else | |
40 | * show last login date and time. If > 6 moths, | |
41 | * show year instead of time. | |
42 | * office location | |
43 | * office phone | |
44 | */ | |
45 | #define MAXREALNAME 20 | |
46 | (void)printf("%-*s %-*s %s\n", UT_NAMESIZE, "Login", MAXREALNAME, | |
f156ea40 | 47 | "Name", "Tty Idle Login Office Office Phone"); |
6b8910b8 KB |
48 | for (cnt = 0; cnt < entries; ++cnt) { |
49 | pn = list[cnt]; | |
7619ff47 EW |
50 | for (w = pn->whead; w != NULL; w = w->next) { |
51 | (void)printf("%-*.*s %-*.*s ", UT_NAMESIZE, UT_NAMESIZE, | |
52 | pn->name, MAXREALNAME, MAXREALNAME, | |
53 | pn->realname ? pn->realname : ""); | |
54 | if (!w->loginat) { | |
55 | (void)printf(" * * No logins "); | |
56 | goto office; | |
57 | } | |
58 | (void)putchar(w->info == LOGGEDIN && !w->writable ? | |
59 | '*' : ' '); | |
60 | if (*w->tty) | |
61 | (void)printf("%-2.2s ", | |
62 | w->tty[0] != 't' || w->tty[1] != 't' || | |
63 | w->tty[2] != 'y' ? w->tty : w->tty + 3); | |
64 | else | |
65 | (void)printf(" "); | |
66 | if (w->info == LOGGEDIN) { | |
67 | stimeprint(w); | |
68 | (void)printf(" "); | |
69 | } else | |
70 | (void)printf(" * "); | |
71 | p = ctime(&w->loginat); | |
72 | (void)printf("%.6s", p + 4); | |
73 | if (now - w->loginat >= SECSPERDAY * DAYSPERNYEAR / 2) | |
74 | (void)printf(" %.4s", p + 20); | |
75 | else | |
76 | (void)printf(" %.5s", p + 11); | |
77 | office: if (pn->office) | |
f156ea40 | 78 | (void)printf(" %-10.10s", pn->office); |
7619ff47 | 79 | else if (pn->officephone) |
f156ea40 | 80 | (void)printf(" %-10.10s", " "); |
7619ff47 | 81 | if (pn->officephone) |
f156ea40 KB |
82 | (void)printf(" %-.15s", |
83 | prphone(pn->officephone)); | |
7619ff47 | 84 | putchar('\n'); |
6b8910b8 | 85 | } |
6b8910b8 KB |
86 | } |
87 | } | |
88 | ||
89 | PERSON ** | |
90 | sort() | |
91 | { | |
7619ff47 | 92 | register PERSON *pn, **lp; |
6b8910b8 KB |
93 | PERSON **list; |
94 | int psort(); | |
95 | char *malloc(); | |
96 | ||
97 | if (!(list = (PERSON **)malloc((u_int)(entries * sizeof(PERSON *))))) { | |
98 | (void)fprintf(stderr, "finger: out of space.\n"); | |
99 | exit(1); | |
100 | } | |
7619ff47 EW |
101 | for (lp = list, pn = phead; pn != NULL; pn = pn->next) |
102 | *lp++ = pn; | |
6b8910b8 KB |
103 | (void)qsort(list, entries, sizeof(PERSON *), psort); |
104 | return(list); | |
105 | } | |
106 | ||
107 | psort(p, t) | |
108 | PERSON **p, **t; | |
109 | { | |
110 | return(strcmp((*p)->name, (*t)->name)); | |
111 | } | |
112 | ||
7619ff47 EW |
113 | stimeprint(w) |
114 | WHERE *w; | |
6b8910b8 KB |
115 | { |
116 | register struct tm *delta; | |
117 | ||
7619ff47 | 118 | delta = gmtime(&w->idletime); |
6b8910b8 KB |
119 | if (!delta->tm_yday) |
120 | if (!delta->tm_hour) | |
121 | if (!delta->tm_min) | |
122 | (void)printf(" "); | |
123 | else | |
124 | (void)printf("%5d", delta->tm_min); | |
125 | else | |
126 | (void)printf("%2d:%02d", | |
127 | delta->tm_hour, delta->tm_min); | |
128 | else | |
129 | (void)printf("%4dd", delta->tm_yday); | |
130 | } |