示例#1
0
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');
		}
	}
}
示例#2
0
文件: lprint.c 项目: AzerTyQsdF/osx
static void
lprint(PERSON *pn)
{
	struct tm *delta;
	WHERE *w;
	int cpr, len, maxlen;
	struct tm *tp;
	int oddfield;
	char t[80];

	if (d_first < 0)
		d_first = (*nl_langinfo(D_MD_ORDER) == 'd');
	/*
	 * long format --
	 *	login name
	 *	real name
	 *	home directory
	 *	shell
	 *	office, office phone, home phone if available
	 *	mail status
	 */
	(void)printf("Login: %-15s\t\t\tName: %s\nDirectory: %-25s",
	    pn->name, pn->realname, pn->dir);
	(void)printf("\tShell: %-s\n", *pn->shell ? pn->shell : _PATH_BSHELL);

	if (gflag)
		goto no_gecos;
	/*
	 * try and print office, office phone, and home phone on one line;
	 * if that fails, do line filling so it looks nice.
	 */
#define	OFFICE_TAG		"Office"
#define	OFFICE_PHONE_TAG	"Office Phone"
	oddfield = 0;
	if (pn->office && pn->officephone &&
	    strlen(pn->office) + strlen(pn->officephone) +
	    sizeof(OFFICE_TAG) + 2 <= 5 * TAB_LEN) {
		(void)snprintf(tbuf, sizeof(tbuf), "%s: %s, %s",
		    OFFICE_TAG, pn->office, prphone(pn->officephone));
		oddfield = demi_print(tbuf, oddfield);
	} else {
		if (pn->office) {
			(void)snprintf(tbuf, sizeof(tbuf), "%s: %s",
			    OFFICE_TAG, pn->office);
			oddfield = demi_print(tbuf, oddfield);
		}
		if (pn->officephone) {
			(void)snprintf(tbuf, sizeof(tbuf), "%s: %s",
			    OFFICE_PHONE_TAG, prphone(pn->officephone));
			oddfield = demi_print(tbuf, oddfield);
		}
	}
	if (pn->homephone) {
		(void)snprintf(tbuf, sizeof(tbuf), "%s: %s", "Home Phone",
		    prphone(pn->homephone));
		oddfield = demi_print(tbuf, oddfield);
	}
	if (oddfield)
		putchar('\n');

no_gecos:
	/*
	 * long format con't:
	 * if logged in
	 *	terminal
	 *	idle time
	 *	if messages allowed
	 *	where logged in from
	 * if not logged in
	 *	when last logged in
	 */
	/* find out longest device name for this user for formatting */
	for (w = pn->whead, maxlen = -1; w != NULL; w = w->next)
		if ((len = strlen(w->tty)) > maxlen)
			maxlen = len;
	/* find rest of entries for user */
	for (w = pn->whead; w != NULL; w = w->next) {
		if (w->info == LOGGEDIN) {
			tp = localtime(&w->loginat);
			strftime(t, sizeof(t),
			    d_first ? "%a %e %b %R (%Z)" : "%a %b %e %R (%Z)",
			    tp);
			cpr = printf("On since %s on %s", t, w->tty);
			/*
			 * idle time is tough; if have one, print a comma,
			 * then spaces to pad out the device name, then the
			 * idle time.  Follow with a comma if a remote login.
			 */
			delta = gmtime(&w->idletime);
			if (w->idletime != -1 && (delta->tm_yday ||
			    delta->tm_hour || delta->tm_min)) {
				cpr += printf("%-*s idle ",
				    maxlen - (int)strlen(w->tty) + 1, ",");
				if (delta->tm_yday > 0) {
					cpr += printf("%d day%s ",
					   delta->tm_yday,
					   delta->tm_yday == 1 ? "" : "s");
				}
				cpr += printf("%d:%02d",
				    delta->tm_hour, delta->tm_min);
				if (*w->host) {
					putchar(',');
					++cpr;
				}
			}
			if (!w->writable)
				cpr += printf(" (messages off)");
		} else if (w->loginat == 0) {
			cpr = printf("Never logged in.");
		} else {
			tp = localtime(&w->loginat);
			if (now - w->loginat > 86400 * 365 / 2) {
				strftime(t, sizeof(t),
					 d_first ? "%a %e %b %R %Y (%Z)" :
						   "%a %b %e %R %Y (%Z)",
					 tp);
			} else {
				strftime(t, sizeof(t),
					 d_first ? "%a %e %b %R (%Z)" :
						   "%a %b %e %R (%Z)",
					 tp);
			}
			cpr = printf("Last login %s on %s", t, w->tty);
		}
		if (*w->host) {
			if (LINE_LEN < (cpr + 6 + strlen(w->host)))
				(void)printf("\n   ");
			(void)printf(" from %s", w->host);
		}
		putchar('\n');
	}
	if (pn->mailrecv == -1)
		printf("No Mail.\n");
	else if (pn->mailrecv > pn->mailread) {
		tp = localtime(&pn->mailrecv);
		strftime(t, sizeof(t),
			 d_first ? "%a %e %b %R %Y (%Z)" :
				   "%a %b %e %R %Y (%Z)",
			 tp);
		printf("New mail received %s\n", t);
		tp = localtime(&pn->mailread);
		strftime(t, sizeof(t),
			 d_first ? "%a %e %b %R %Y (%Z)" :
				   "%a %b %e %R %Y (%Z)",
			 tp);
		printf("     Unread since %s\n", t);
	} else {
		tp = localtime(&pn->mailread);
		strftime(t, sizeof(t),
			 d_first ? "%a %e %b %R %Y (%Z)" :
				   "%a %b %e %R %Y (%Z)",
			 tp);
		printf("Mail last read %s\n", t);
	}
}
示例#3
0
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');
		}
	}
}
示例#4
0
文件: sprint.c 项目: coyizumi/cs111
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	16
#define MAXHOSTNAME     17      /* in reality, hosts are never longer than 16 */
	(void)printf("%-*s %-*s%s %s\n", MAXLOGNAME, "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", MAXLOGNAME, MAXLOGNAME,
				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("%-7.7s ",
					     (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');
		}
	}
}
示例#5
0
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');
		}
	}
}