1 /* $NetBSD: sprint.c,v 1.16 2004/11/16 04:52:46 christos Exp $ */
4 * Copyright (c) 1989, 1993
5 * The Regents of the University of California. All rights reserved.
7 * This code is derived from software contributed to Berkeley by
8 * Tony Nardo of the Johns Hopkins University/Applied Physics Lab.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 #include <sys/cdefs.h>
38 static char sccsid
[] = "@(#)sprint.c 8.3 (Berkeley) 4/28/95";
40 __RCSID("$NetBSD: sprint.c,v 1.16 2004/11/16 04:52:46 christos Exp $");
44 #include <sys/param.h>
57 #include "utmpentry.h"
62 static void stimeprint(WHERE
*);
82 * if terminal writable (add an '*' to the terminal name
84 * if logged in show idle time and day logged in, else
85 * show last login date and time. If > 6 months,
86 * show year instead of time. If < 6 days,
87 * show day name instead of month & day.
90 * else if -o given (overriding -h) (default)
94 #define MAXREALNAME 18
95 (void)printf("%-*s %-*s %s %s\n", maxname
, "Login", MAXREALNAME
,
96 "Name", " Tty Idle Login Time ", (gflag
) ? "" :
97 (oflag
) ? "Office Office Phone" : "Where");
99 for (sflag
= R_FIRST
;; sflag
= R_NEXT
) {
100 r
= (*db
->seq
)(db
, &key
, &data
, sflag
);
105 memmove(&tmp
, data
.data
, sizeof tmp
);
108 for (w
= pn
->whead
; w
!= NULL
; w
= w
->next
) {
109 (void)printf("%-*.*s %-*.*s ", (int)maxname
,
111 pn
->name
, MAXREALNAME
, MAXREALNAME
,
112 pn
->realname
? pn
->realname
: "");
114 (void)printf(" * * No logins ");
117 (void)putchar(w
->info
== LOGGEDIN
&& !w
->writable
?
120 (void)printf("%-7.7s ", w
->tty
);
123 if (w
->info
== LOGGEDIN
) {
128 p
= ctime(&w
->loginat
);
129 if (now
- w
->loginat
< SECSPERDAY
* (DAYSPERWEEK
- 1))
130 (void)printf("%.3s %-8.5s", p
, p
+ 11);
131 else if (now
- w
->loginat
132 < SECSPERDAY
* DAYSPERNYEAR
/ 2)
133 (void)printf("%.6s %-5.5s", p
+ 4, p
+ 11);
135 (void)printf("%.6s %-5.4s", p
+ 4, p
+ 20);
142 (void)printf("%-10.10s", pn
->office
);
143 else if (pn
->officephone
)
144 (void)printf("%-10.10s", " ");
146 (void)printf(" %-.15s",
147 prphone(pn
->officephone
));
149 (void)printf("%.*s", MAXHOSTNAMELEN
, w
->host
);
161 delta
= gmtime(&w
->idletime
);
162 if (!delta
->tm_yday
) {
163 if (!delta
->tm_hour
) {
167 (void)printf("%5d", delta
->tm_min
);
169 (void)printf("%2d:%02d",
170 delta
->tm_hour
, delta
->tm_min
);
172 (void)printf("%4dd", delta
->tm_yday
);