Deleted Added
full compact
sprint.c (72109) sprint.c (74586)
1/*
2 * Copyright (c) 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Tony Nardo of the Johns Hopkins University/Applied Physics Lab.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 25 unchanged lines hidden (view full) ---

34 * SUCH DAMAGE.
35 */
36
37#ifndef lint
38#if 0
39static char sccsid[] = "@(#)sprint.c 8.3 (Berkeley) 4/28/95";
40#endif
41static const char rcsid[] =
1/*
2 * Copyright (c) 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Tony Nardo of the Johns Hopkins University/Applied Physics Lab.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 25 unchanged lines hidden (view full) ---

34 * SUCH DAMAGE.
35 */
36
37#ifndef lint
38#if 0
39static char sccsid[] = "@(#)sprint.c 8.3 (Berkeley) 4/28/95";
40#endif
41static const char rcsid[] =
42 "$FreeBSD: head/usr.bin/finger/sprint.c 72109 2001-02-06 20:13:48Z charnier $";
42 "$FreeBSD: head/usr.bin/finger/sprint.c 74586 2001-03-21 18:43:49Z ache $";
43#endif /* not lint */
44
45#include <db.h>
46#include <err.h>
43#endif /* not lint */
44
45#include <db.h>
46#include <err.h>
47#include <langinfo.h>
47#include <pwd.h>
48#include <stdio.h>
49#include <string.h>
50#include <time.h>
51#include <utmp.h>
52#include "finger.h"
53
54static void stimeprint __P((WHERE *));

--- 4 unchanged lines hidden (view full) ---

59 extern time_t now;
60 extern int oflag;
61 register PERSON *pn;
62 register WHERE *w;
63 register int sflag, r, namelen;
64 char p[80];
65 PERSON *tmp;
66 DBT data, key;
48#include <pwd.h>
49#include <stdio.h>
50#include <string.h>
51#include <time.h>
52#include <utmp.h>
53#include "finger.h"
54
55static void stimeprint __P((WHERE *));

--- 4 unchanged lines hidden (view full) ---

60 extern time_t now;
61 extern int oflag;
62 register PERSON *pn;
63 register WHERE *w;
64 register int sflag, r, namelen;
65 char p[80];
66 PERSON *tmp;
67 DBT data, key;
68 struct tm *lc;
67
69
70 if (d_first < 0)
71 d_first = (*nl_langinfo(D_MD_ORDER) == 'd');
68 /*
69 * short format --
70 * login name
71 * real name
72 * terminal name (the XX of ttyXX)
73 * if terminal writeable (add an '*' to the terminal name
74 * if not)
75 * if logged in show idle time and day logged in, else
76 * show last login date and time.
77 * If > 6 months, show year instead of time.
78 * if (-o)
79 * office location
80 * office phone
81 * else
82 * remote host
83 */
84#define MAXREALNAME 20
85#define MAXHOSTNAME 17 /* in reality, hosts are never longer than 16 */
86 (void)printf("%-*s %-*s%s %s\n", UT_NAMESIZE, "Login", MAXREALNAME,
72 /*
73 * short format --
74 * login name
75 * real name
76 * terminal name (the XX of ttyXX)
77 * if terminal writeable (add an '*' to the terminal name
78 * if not)
79 * if logged in show idle time and day logged in, else
80 * show last login date and time.
81 * If > 6 months, show year instead of time.
82 * if (-o)
83 * office location
84 * office phone
85 * else
86 * remote host
87 */
88#define MAXREALNAME 20
89#define MAXHOSTNAME 17 /* in reality, hosts are never longer than 16 */
90 (void)printf("%-*s %-*s%s %s\n", UT_NAMESIZE, "Login", MAXREALNAME,
87 "Name", " TTY Idle Login Time",
88 oflag ? " Office Phone" : " Where");
91 "Name", " TTY Idle Login Time",
92 oflag ? "Office Phone" : "Where");
89
90 for (sflag = R_FIRST;; sflag = R_NEXT) {
91 r = (*db->seq)(db, &key, &data, sflag);
92 if (r == -1)
93 err(1, "db seq");
94 if (r == 1)
95 break;
96 memmove(&tmp, data.data, sizeof tmp);

--- 19 unchanged lines hidden (view full) ---

116 ? w->tty : w->tty + 3);
117 else
118 (void)printf(" ");
119 if (w->info == LOGGEDIN) {
120 stimeprint(w);
121 (void)printf(" ");
122 } else
123 (void)printf(" * ");
93
94 for (sflag = R_FIRST;; sflag = R_NEXT) {
95 r = (*db->seq)(db, &key, &data, sflag);
96 if (r == -1)
97 err(1, "db seq");
98 if (r == 1)
99 break;
100 memmove(&tmp, data.data, sizeof tmp);

--- 19 unchanged lines hidden (view full) ---

120 ? w->tty : w->tty + 3);
121 else
122 (void)printf(" ");
123 if (w->info == LOGGEDIN) {
124 stimeprint(w);
125 (void)printf(" ");
126 } else
127 (void)printf(" * ");
124 strftime(p, sizeof(p), "%c", localtime(&w->loginat));
128 lc = localtime(&w->loginat);
125#define SECSPERDAY 86400
126#define DAYSPERWEEK 7
127#define DAYSPERNYEAR 365
129#define SECSPERDAY 86400
130#define DAYSPERWEEK 7
131#define DAYSPERNYEAR 365
128 if (now - w->loginat < SECSPERDAY * (DAYSPERWEEK - 1))
129 (void)printf("%.3s ", p);
130 else
131 (void)printf("%.6s", p + 4);
132 if (now - w->loginat >= SECSPERDAY * DAYSPERNYEAR / 2)
133 (void)printf(" %.4s", p + 20);
134 else
135 (void)printf(" %.5s", p + 11);
132 if (now - w->loginat < SECSPERDAY * (DAYSPERWEEK - 1)) {
133 (void)strftime(p, sizeof(p), "%a", lc);
134 } else {
135 (void)strftime(p, sizeof(p),
136 d_first ? "%e %b" : "%b %e", lc);
137 }
138 (void)printf("%-6.6s", p);
139 if (now - w->loginat >= SECSPERDAY * DAYSPERNYEAR / 2) {
140 (void)strftime(p, sizeof(p), "%Y", lc);
141 } else {
142 (void)strftime(p, sizeof(p), "%R", lc);
143 }
144 (void)printf(" %-5.5s", p);
136office: if (oflag) {
137 if (pn->office)
138 (void)printf(" %-7.7s", pn->office);
139 else if (pn->officephone)
140 (void)printf(" %-7.7s", " ");
141 if (pn->officephone)
142 (void)printf(" %-.9s",
143 prphone(pn->officephone));

--- 26 unchanged lines hidden ---
145office: if (oflag) {
146 if (pn->office)
147 (void)printf(" %-7.7s", pn->office);
148 else if (pn->officephone)
149 (void)printf(" %-7.7s", " ");
150 if (pn->officephone)
151 (void)printf(" %-.9s",
152 prphone(pn->officephone));

--- 26 unchanged lines hidden ---