version 1.2, 1996/06/26 05:33:18 |
version 1.3, 1997/05/30 23:35:52 |
|
|
#include <sys/time.h> |
#include <sys/time.h> |
#include <tzfile.h> |
#include <tzfile.h> |
#include <stdio.h> |
#include <stdio.h> |
|
#include <stdlib.h> |
#include "finger.h" |
#include "finger.h" |
|
#include "extern.h" |
|
|
extern int entries; |
void |
|
|
sflag_print() |
sflag_print() |
{ |
{ |
extern time_t now; |
PERSON *pn; |
register PERSON *pn; |
WHERE *w; |
register WHERE *w; |
int cnt; |
register int cnt; |
char *p; |
register char *p; |
PERSON **list; |
PERSON **list, **sort(); |
|
time_t time(); |
|
char *ctime(), *prphone(); |
|
|
|
list = sort(); |
list = sort(); |
/* |
/* |
|
|
* if terminal writeable (add an '*' to the terminal name |
* if terminal writeable (add an '*' to the terminal name |
* if not) |
* if not) |
* if logged in show idle time and day logged in, else |
* if logged in show idle time and day logged in, else |
* show last login date and time. If > 6 moths, |
* show last login date and time. If > 6 months, |
* show year instead of time. |
* show year instead of time. If < 6 days, |
* office location |
* show day name instead of month & day. |
* office phone |
* if -h given |
|
* remote host |
|
* else if -o given (overriding -h) (default) |
|
* office location |
|
* office phone |
*/ |
*/ |
#define MAXREALNAME 20 |
#define MAXREALNAME 20 |
(void)printf("%-*s %-*s %s\n", UT_NAMESIZE, "Login", MAXREALNAME, |
#define MAXHOSTNAME 20 |
"Name", "Tty Idle Login Time Office Office Phone"); |
(void)printf("%-*s %-*s %s %s\n", UT_NAMESIZE, "Login", MAXREALNAME, |
|
"Name", "Tty Idle Login Time ", |
|
(oflag) ? "Office Office Phone" : "Where"); |
for (cnt = 0; cnt < entries; ++cnt) { |
for (cnt = 0; cnt < entries; ++cnt) { |
pn = list[cnt]; |
pn = list[cnt]; |
for (w = pn->whead; w != NULL; w = w->next) { |
for (w = pn->whead; w != NULL; w = w->next) { |
|
|
} else |
} else |
(void)printf(" * "); |
(void)printf(" * "); |
p = ctime(&w->loginat); |
p = ctime(&w->loginat); |
(void)printf("%.6s", p + 4); |
if (now - w->loginat < SECSPERDAY * (DAYSPERWEEK - 1)) |
|
(void)printf(" %.3s", p); |
|
else |
|
(void)printf("%.6s", p + 4); |
if (now - w->loginat >= SECSPERDAY * DAYSPERNYEAR / 2) |
if (now - w->loginat >= SECSPERDAY * DAYSPERNYEAR / 2) |
(void)printf(" %.4s", p + 20); |
(void)printf(" %.4s ", p + 20); |
else |
else |
(void)printf(" %.5s", p + 11); |
(void)printf(" %.5s", p + 11); |
office: if (pn->office) |
office: |
(void)printf(" %-10.10s", pn->office); |
putchar(' '); |
else if (pn->officephone) |
if (oflag) { |
(void)printf(" %-10.10s", " "); |
if (pn->office) |
if (pn->officephone) |
(void)printf("%-10.10s", pn->office); |
(void)printf(" %-.15s", |
else if (pn->officephone) |
prphone(pn->officephone)); |
(void)printf("%-10.10s", " "); |
|
if (pn->officephone) |
|
(void)printf(" %-.15s", |
|
prphone(pn->officephone)); |
|
} else |
|
(void)printf("%.*s", MAXHOSTNAME, w->host); |
putchar('\n'); |
putchar('\n'); |
} |
} |
} |
} |
|
|
PERSON ** |
PERSON ** |
sort() |
sort() |
{ |
{ |
register PERSON *pn, **lp; |
PERSON *pn, **lp; |
PERSON **list; |
PERSON **list; |
int psort(); |
|
char *malloc(); |
|
|
|
if (!(list = (PERSON **)malloc((u_int)(entries * sizeof(PERSON *))))) { |
if (!(list = (PERSON **)malloc((u_int)(entries * sizeof(PERSON *))))) { |
(void)fprintf(stderr, "finger: out of space.\n"); |
(void)fprintf(stderr, "finger: out of space.\n"); |
|
|
return(list); |
return(list); |
} |
} |
|
|
|
int |
psort(p, t) |
psort(p, t) |
PERSON **p, **t; |
const void *p, *t; |
{ |
{ |
return(strcmp((*p)->name, (*t)->name)); |
return(strcmp((*(PERSON **)p)->name, (*(PERSON **)t)->name)); |
} |
} |
|
|
|
void |
stimeprint(w) |
stimeprint(w) |
WHERE *w; |
WHERE *w; |
{ |
{ |
register struct tm *delta; |
struct tm *delta; |
|
|
delta = gmtime(&w->idletime); |
delta = gmtime(&w->idletime); |
if (!delta->tm_yday) |
if (!delta->tm_yday) |