2 * Copyright (c) 1989, 1993
3 * The Regents of the University of California. All rights reserved.
5 * This code is derived from software contributed to Berkeley by
6 * Tony Nardo of the Johns Hopkins University/Applied Physics Lab.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 static char sccsid[] = "@(#)sprint.c 8.3 (Berkeley) 4/28/95";
41 static const char rcsid[] =
46 #include <sys/types.h>
59 static void stimeprint __P((WHERE *));
68 register int sflag, r, namelen;
77 * terminal name (the XX of ttyXX)
78 * if terminal writeable (add an '*' to the terminal name
80 * if logged in show idle time and day logged in, else
81 * show last login date and time.
82 * If > 6 months, show year instead of time.
89 #define MAXREALNAME 20
90 #define MAXHOSTNAME 17 /* in reality, hosts are never longer than 16 */
91 (void)printf("%-*s %-*s%s %s\n", UT_NAMESIZE, "Login", MAXREALNAME,
92 "Name", " TTY Idle Login Time",
93 oflag ? " Office Phone" : " Where");
95 for (sflag = R_FIRST;; sflag = R_NEXT) {
96 r = (*db->seq)(db, &key, &data, sflag);
101 memmove(&tmp, data.data, sizeof tmp);
104 for (w = pn->whead; w != NULL; w = w->next) {
105 namelen = MAXREALNAME;
106 if (w->info == LOGGEDIN && !w->writable)
107 --namelen; /* leave space before `*' */
108 (void)printf("%-*.*s %-*.*s", UT_NAMESIZE, UT_NAMESIZE,
109 pn->name, MAXREALNAME, namelen,
110 pn->realname ? pn->realname : "");
112 (void)printf(" * * No logins ");
115 (void)putchar(w->info == LOGGEDIN && !w->writable ?
118 (void)printf("%-3.3s ",
119 (strncmp(w->tty, "tty", 3)
120 && strncmp(w->tty, "cua", 3))
121 ? w->tty : w->tty + 3);
124 if (w->info == LOGGEDIN) {
129 strftime(p, sizeof(p), "%c", localtime(&w->loginat));
130 #define SECSPERDAY 86400
131 #define DAYSPERWEEK 7
132 #define DAYSPERNYEAR 365
133 if (now - w->loginat < SECSPERDAY * (DAYSPERWEEK - 1))
134 (void)printf("%.3s ", p);
136 (void)printf("%.6s", p + 4);
137 if (now - w->loginat >= SECSPERDAY * DAYSPERNYEAR / 2)
138 (void)printf(" %.4s", p + 20);
140 (void)printf(" %.5s", p + 11);
143 (void)printf(" %-7.7s", pn->office);
144 else if (pn->officephone)
145 (void)printf(" %-7.7s", " ");
147 (void)printf(" %-.9s",
148 prphone(pn->officephone));
150 (void)printf(" %.*s", MAXHOSTNAME, w->host);
160 register struct tm *delta;
162 delta = gmtime(&w->idletime);
168 (void)printf("%5d", delta->tm_min);
170 (void)printf("%2d:%02d",
171 delta->tm_hour, delta->tm_min);
173 (void)printf("%4dd", delta->tm_yday);