void shortprint(struct person *pers) { char *p; int tloc =0; (void) printf("%s", pers->pwd->pw_name); p = ctime(&pers->loginat); if (pers->loggedin) { stimeprint(&pers->idletime); (void) printf(" %3.3s %-5.5s ", p, p + 11); } else if (pers->loginat == 0) { (void) printf(" < . . . . >"); } else if (tloc - pers->loginat >= 180 * 24 * 60 * 60) { (void) printf(" <%-6.6s, %-4.4s>", p + 4, p + 20); } else { (void) printf(" <%-12.12s>", p + 4); } (void) putchar('\n'); }
void sflag_print(void) { PERSON *pn; WHERE *w; int sflag, r, namelen; char p[80]; PERSON *tmp; DBT data, key; struct tm *lc; if (d_first < 0) d_first = (*nl_langinfo(D_MD_ORDER) == 'd'); /* * short format -- * login name * real name * terminal name (the XX of ttyXX) * if terminal writeable (add an '*' to the terminal name * if not) * if logged in show idle time and day logged in, else * show last login date and time. * If > 6 months, show year instead of time. * if (-o) * office location * office phone * else * remote host */ #define MAXREALNAME 20 #define MAXHOSTNAME 17 /* in reality, hosts are never longer than 16 */ (void)printf("%-*s %-*s%s %s\n", UT_NAMESIZE, "Login", MAXREALNAME, "Name", " TTY Idle Login Time ", (gflag) ? "" : oflag ? "Office Phone" : "Where"); for (sflag = R_FIRST;; sflag = R_NEXT) { r = (*db->seq)(db, &key, &data, sflag); if (r == -1) err(1, "db seq"); if (r == 1) break; memmove(&tmp, data.data, sizeof tmp); pn = tmp; for (w = pn->whead; w != NULL; w = w->next) { namelen = MAXREALNAME; if (w->info == LOGGEDIN && !w->writable) --namelen; /* leave space before `*' */ (void)printf("%-*.*s %-*.*s", UT_NAMESIZE, UT_NAMESIZE, pn->name, MAXREALNAME, namelen, pn->realname ? pn->realname : ""); if (!w->loginat) { (void)printf(" * * No logins "); goto office; } (void)putchar(w->info == LOGGEDIN && !w->writable ? '*' : ' '); if (*w->tty) (void)printf("%-3.3s ", (strncmp(w->tty, "tty", 3) && strncmp(w->tty, "cua", 3)) ? w->tty : w->tty + 3); else (void)printf(" "); if (w->info == LOGGEDIN) { stimeprint(w); (void)printf(" "); } else (void)printf(" * "); lc = localtime(&w->loginat); #define SECSPERDAY 86400 #define DAYSPERWEEK 7 #define DAYSPERNYEAR 365 if (now - w->loginat < SECSPERDAY * (DAYSPERWEEK - 1)) { (void)strftime(p, sizeof(p), "%a", lc); } else { (void)strftime(p, sizeof(p), d_first ? "%e %b" : "%b %e", lc); } (void)printf("%-6.6s", p); if (now - w->loginat >= SECSPERDAY * DAYSPERNYEAR / 2) { (void)strftime(p, sizeof(p), "%Y", lc); } else { (void)strftime(p, sizeof(p), "%R", lc); } (void)printf(" %-5.5s ", p); office: if (gflag) goto no_gecos; if (oflag) { if (pn->office) (void)printf(" %-7.7s", pn->office); else if (pn->officephone) (void)printf(" %-7.7s", " "); if (pn->officephone) (void)printf(" %-.9s", prphone(pn->officephone)); } else (void)printf(" %.*s", MAXHOSTNAME, w->host); no_gecos: putchar('\n'); } } }
void sflag_print() { extern time_t now; register PERSON *pn; register WHERE *w; register int sflag, r; register char *p; DBT data, key; /* * short format -- * login name * real name * terminal name (the XX of ttyXX) * if terminal writeable (add an '*' to the terminal name * if not) * if logged in show idle time and day logged in, else * show last login date and time. If > 6 moths, * show year instead of time. * office location * office phone */ #define MAXREALNAME 20 (void)printf("%-*s %-*s %s\n", UT_NAMESIZE, "Login", MAXREALNAME, "Name", "Tty Idle Login Time Office Office Phone"); for (sflag = R_FIRST;; sflag = R_NEXT) { r = (*db->seq)(db, &key, &data, sflag); if (r == -1) err("db seq: %s", strerror(errno)); if (r == 1) break; pn = *(PERSON **)data.data; for (w = pn->whead; w != NULL; w = w->next) { (void)printf("%-*.*s %-*.*s ", UT_NAMESIZE, UT_NAMESIZE, pn->name, MAXREALNAME, MAXREALNAME, pn->realname ? pn->realname : ""); if (!w->loginat) { (void)printf(" * * No logins "); goto office; } (void)putchar(w->info == LOGGEDIN && !w->writable ? '*' : ' '); if (*w->tty) (void)printf("%-2.2s ", w->tty[0] != 't' || w->tty[1] != 't' || w->tty[2] != 'y' ? w->tty : w->tty + 3); else (void)printf(" "); if (w->info == LOGGEDIN) { stimeprint(w); (void)printf(" "); } else (void)printf(" * "); p = ctime(&w->loginat); (void)printf("%.6s", p + 4); if (now - w->loginat >= SECSPERDAY * DAYSPERNYEAR / 2) (void)printf(" %.4s", p + 20); else (void)printf(" %.5s", p + 11); office: if (pn->office) (void)printf(" %-10.10s", pn->office); else if (pn->officephone) (void)printf(" %-10.10s", " "); if (pn->officephone) (void)printf(" %-.15s", prphone(pn->officephone)); putchar('\n'); } } }
sflag_print() { extern time_t now; register PERSON *pn; register WHERE *w; register int cnt; register char *p; PERSON **list, **sort(); time_t time(); char *ctime(), *prphone(); list = sort(); /* * short format -- * login name * real name * terminal name (the XX of ttyXX) * if terminal writeable (add an '*' to the terminal name * if not) * if logged in show idle time and day logged in, else * show last login date and time. If > 6 moths, * show year instead of time. * office location * office phone */ #define MAXREALNAME 20 (void)printf("%-*s %-*s %s\n", UT_NAMESIZE, "Login", MAXREALNAME, "Name", "Tty Idle Login Time Office Office Phone"); for (cnt = 0; cnt < entries; ++cnt) { pn = list[cnt]; for (w = pn->whead; w != NULL; w = w->next) { (void)printf("%-*.*s %-*.*s ", UT_NAMESIZE, UT_NAMESIZE, pn->name, MAXREALNAME, MAXREALNAME, pn->realname ? pn->realname : ""); if (!w->loginat) { (void)printf(" * * No logins "); goto office; } (void)putchar(w->info == LOGGEDIN && !w->writable ? '*' : ' '); if (*w->tty) (void)printf("%-2.2s ", w->tty[0] != 't' || w->tty[1] != 't' || w->tty[2] != 'y' ? w->tty : w->tty + 3); else (void)printf(" "); if (w->info == LOGGEDIN) { stimeprint(w); (void)printf(" "); } else (void)printf(" * "); p = ctime(&w->loginat); (void)printf("%.6s", p + 4); if (now - w->loginat >= SECSPERDAY * DAYSPERNYEAR / 2) (void)printf(" %.4s", p + 20); else (void)printf(" %.5s", p + 11); office: if (pn->office) (void)printf(" %-10.10s", pn->office); else if (pn->officephone) (void)printf(" %-10.10s", " "); if (pn->officephone) (void)printf(" %-.15s", prphone(pn->officephone)); putchar('\n'); } } }
void sflag_print(void) { PERSON *pn; WHERE *w; int cnt; char *p; PERSON **list; list = sort(); /* * short format -- * login name * real name * terminal name (the XX of ttyXX) * if terminal writeable (add an '*' to the terminal name * if not) * if logged in show idle time and day logged in, else * show last login date and time. If > 6 months, * show year instead of time. If < 6 days, * show day name instead of month & day. * if -h given * remote host * else if -o given (overriding -h) (default) * office location * office phone */ #define NAME_WIDTH 8 #define MAXREALNAME 20 #define MAXHOSTNAME 20 (void)printf("%-*.*s %-*s %s %s\n", NAME_WIDTH, UT_NAMESIZE, "Login", MAXREALNAME, "Name", "Tty Idle Login Time ", (oflag) ? "Office Office Phone" : "Where"); for (cnt = 0; cnt < entries; ++cnt) { pn = list[cnt]; for (w = pn->whead; w != NULL; w = w->next) { (void)printf("%-*.*s %-*.*s ", NAME_WIDTH, UT_NAMESIZE, pn->name, MAXREALNAME, MAXREALNAME, pn->realname ? pn->realname : ""); if (!w->loginat) { (void)printf(" * * No logins "); goto office; } (void)putchar(w->info == LOGGEDIN && !w->writable ? '*' : ' '); if (*w->tty) (void)printf("%-2.2s ", w->tty[0] != 't' || w->tty[1] != 't' || w->tty[2] != 'y' ? w->tty : w->tty + 3); else (void)printf(" "); if (w->info == LOGGEDIN) { stimeprint(w); (void)printf(" "); } else (void)printf(" * "); p = ctime(&w->loginat); if (now - w->loginat < SECSPERDAY * 6) (void)printf(" %.3s", p); else (void)printf("%.6s", p + 4); if (now - w->loginat >= SIXMONTHS) (void)printf(" %.4s ", p + 20); else (void)printf(" %.5s", p + 11); office: putchar(' '); if (oflag) { if (pn->office) (void)printf("%-10.10s", pn->office); else if (pn->officephone) (void)printf("%-10.10s", " "); if (pn->officephone) (void)printf(" %-.15s", prphone(pn->officephone)); } else (void)printf("%.*s", MAXHOSTNAME, w->host); putchar('\n'); } } }