137660Sbostic /* 237660Sbostic * Copyright (c) 1989 The Regents of the University of California. 337660Sbostic * All rights reserved. 437660Sbostic * 540027Sbostic * This code is derived from software contributed to Berkeley by 640027Sbostic * Tony Nardo of the Johns Hopkins University/Applied Physics Lab. 740027Sbostic * 842731Sbostic * %sccs.include.redist.c% 937660Sbostic */ 1037660Sbostic 1137660Sbostic #ifndef lint 12*45687Sbostic static char sccsid[] = "@(#)sprint.c 5.8 (Berkeley) 12/04/90"; 1337660Sbostic #endif /* not lint */ 1437660Sbostic 1537660Sbostic #include <sys/types.h> 1637660Sbostic #include <sys/time.h> 1737660Sbostic #include <tzfile.h> 1837660Sbostic #include <stdio.h> 1937660Sbostic #include "finger.h" 2037660Sbostic 2137660Sbostic extern int entries; 2237660Sbostic 2337660Sbostic sflag_print() 2437660Sbostic { 2537660Sbostic extern time_t now; 2637660Sbostic register PERSON *pn; 2737664Sedward register WHERE *w; 2837660Sbostic register int cnt; 2937660Sbostic register char *p; 3037660Sbostic PERSON **list, **sort(); 3137660Sbostic time_t time(); 3238052Sbostic char *ctime(), *prphone(); 3337660Sbostic 3437660Sbostic list = sort(); 3537660Sbostic /* 3637660Sbostic * short format -- 3737660Sbostic * login name 3837660Sbostic * real name 3937660Sbostic * terminal name (the XX of ttyXX) 4037660Sbostic * if terminal writeable (add an '*' to the terminal name 4137660Sbostic * if not) 4237660Sbostic * if logged in show idle time and day logged in, else 4337660Sbostic * show last login date and time. If > 6 moths, 4437660Sbostic * show year instead of time. 4537660Sbostic * office location 4637660Sbostic * office phone 4737660Sbostic */ 4837660Sbostic #define MAXREALNAME 20 4937660Sbostic (void)printf("%-*s %-*s %s\n", UT_NAMESIZE, "Login", MAXREALNAME, 50*45687Sbostic "Name", "Tty Idle Login Time Office Office Phone"); 5137660Sbostic for (cnt = 0; cnt < entries; ++cnt) { 5237660Sbostic pn = list[cnt]; 5337664Sedward for (w = pn->whead; w != NULL; w = w->next) { 5437664Sedward (void)printf("%-*.*s %-*.*s ", UT_NAMESIZE, UT_NAMESIZE, 5537664Sedward pn->name, MAXREALNAME, MAXREALNAME, 5637664Sedward pn->realname ? pn->realname : ""); 5737664Sedward if (!w->loginat) { 5837664Sedward (void)printf(" * * No logins "); 5937664Sedward goto office; 6037664Sedward } 6137664Sedward (void)putchar(w->info == LOGGEDIN && !w->writable ? 6237664Sedward '*' : ' '); 6337664Sedward if (*w->tty) 6437664Sedward (void)printf("%-2.2s ", 6537664Sedward w->tty[0] != 't' || w->tty[1] != 't' || 6637664Sedward w->tty[2] != 'y' ? w->tty : w->tty + 3); 6737664Sedward else 6837664Sedward (void)printf(" "); 6937664Sedward if (w->info == LOGGEDIN) { 7037664Sedward stimeprint(w); 7137664Sedward (void)printf(" "); 7237664Sedward } else 7337664Sedward (void)printf(" * "); 7437664Sedward p = ctime(&w->loginat); 7537664Sedward (void)printf("%.6s", p + 4); 7637664Sedward if (now - w->loginat >= SECSPERDAY * DAYSPERNYEAR / 2) 7737664Sedward (void)printf(" %.4s", p + 20); 7837664Sedward else 7937664Sedward (void)printf(" %.5s", p + 11); 8037664Sedward office: if (pn->office) 8138052Sbostic (void)printf(" %-10.10s", pn->office); 8237664Sedward else if (pn->officephone) 8338052Sbostic (void)printf(" %-10.10s", " "); 8437664Sedward if (pn->officephone) 8538052Sbostic (void)printf(" %-.15s", 8638052Sbostic prphone(pn->officephone)); 8737664Sedward putchar('\n'); 8837660Sbostic } 8937660Sbostic } 9037660Sbostic } 9137660Sbostic 9237660Sbostic PERSON ** 9337660Sbostic sort() 9437660Sbostic { 9537664Sedward register PERSON *pn, **lp; 9637660Sbostic PERSON **list; 9737660Sbostic int psort(); 9837660Sbostic char *malloc(); 9937660Sbostic 10037660Sbostic if (!(list = (PERSON **)malloc((u_int)(entries * sizeof(PERSON *))))) { 10137660Sbostic (void)fprintf(stderr, "finger: out of space.\n"); 10237660Sbostic exit(1); 10337660Sbostic } 10437664Sedward for (lp = list, pn = phead; pn != NULL; pn = pn->next) 10537664Sedward *lp++ = pn; 10637660Sbostic (void)qsort(list, entries, sizeof(PERSON *), psort); 10737660Sbostic return(list); 10837660Sbostic } 10937660Sbostic 11037660Sbostic psort(p, t) 11137660Sbostic PERSON **p, **t; 11237660Sbostic { 11337660Sbostic return(strcmp((*p)->name, (*t)->name)); 11437660Sbostic } 11537660Sbostic 11637664Sedward stimeprint(w) 11737664Sedward WHERE *w; 11837660Sbostic { 11937660Sbostic register struct tm *delta; 12037660Sbostic 12137664Sedward delta = gmtime(&w->idletime); 12237660Sbostic if (!delta->tm_yday) 12337660Sbostic if (!delta->tm_hour) 12437660Sbostic if (!delta->tm_min) 12537660Sbostic (void)printf(" "); 12637660Sbostic else 12737660Sbostic (void)printf("%5d", delta->tm_min); 12837660Sbostic else 12937660Sbostic (void)printf("%2d:%02d", 13037660Sbostic delta->tm_hour, delta->tm_min); 13137660Sbostic else 13237660Sbostic (void)printf("%4dd", delta->tm_yday); 13337660Sbostic } 134