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 * 4. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 static char sccsid[] = "@(#)sprint.c 8.3 (Berkeley) 4/28/95";
39 #include <sys/cdefs.h>
40 __FBSDID("$FreeBSD$");
42 #include <sys/param.h>
43 #include <sys/types.h>
44 #include <sys/socket.h>
55 static void stimeprint(WHERE *);
62 int sflag, r, namelen;
69 d_first = (*nl_langinfo(D_MD_ORDER) == 'd');
74 * terminal name (the XX of ttyXX)
75 * if terminal writeable (add an '*' to the terminal name
77 * if logged in show idle time and day logged in, else
78 * show last login date and time.
79 * If > 6 months, show year instead of time.
86 #define MAXREALNAME 16
87 #define MAXHOSTNAME 17 /* in reality, hosts are never longer than 16 */
88 (void)printf("%-*s %-*s%s %s\n", MAXLOGNAME, "Login", MAXREALNAME,
89 "Name", " TTY Idle Login Time ", (gflag) ? "" :
90 oflag ? "Office Phone" : "Where");
92 for (sflag = R_FIRST;; sflag = R_NEXT) {
93 r = (*db->seq)(db, &key, &data, sflag);
98 memmove(&tmp, data.data, sizeof tmp);
101 for (w = pn->whead; w != NULL; w = w->next) {
102 namelen = MAXREALNAME;
103 if (w->info == LOGGEDIN && !w->writable)
104 --namelen; /* leave space before `*' */
105 (void)printf("%-*.*s %-*.*s", MAXLOGNAME, MAXLOGNAME,
106 pn->name, MAXREALNAME, namelen,
107 pn->realname ? pn->realname : "");
109 (void)printf(" * * No logins ");
112 (void)putchar(w->info == LOGGEDIN && !w->writable ?
115 (void)printf("%-7.7s ",
116 (strncmp(w->tty, "tty", 3)
117 && strncmp(w->tty, "cua", 3))
118 ? w->tty : w->tty + 3);
121 if (w->info == LOGGEDIN) {
126 lc = localtime(&w->loginat);
127 #define SECSPERDAY 86400
128 #define DAYSPERWEEK 7
129 #define DAYSPERNYEAR 365
130 if (now - w->loginat < SECSPERDAY * (DAYSPERWEEK - 1)) {
131 (void)strftime(p, sizeof(p), "%a", lc);
133 (void)strftime(p, sizeof(p),
134 d_first ? "%e %b" : "%b %e", lc);
136 (void)printf("%-6.6s", p);
137 if (now - w->loginat >= SECSPERDAY * DAYSPERNYEAR / 2) {
138 (void)strftime(p, sizeof(p), "%Y", lc);
140 (void)strftime(p, sizeof(p), "%R", lc);
142 (void)printf(" %-5.5s", p);
148 (void)printf(" %-7.7s", pn->office);
149 else if (pn->officephone)
150 (void)printf(" %-7.7s", " ");
152 (void)printf(" %-.15s",
153 prphone(pn->officephone));
155 (void)printf(" %.*s", MAXHOSTNAME, w->host);
167 if (w->idletime == -1) {
172 delta = gmtime(&w->idletime);
178 (void)printf("%5d", delta->tm_min);
180 (void)printf("%2d:%02d",
181 delta->tm_hour, delta->tm_min);
183 (void)printf("%4dd", delta->tm_yday);