Search the include path for the argument to -f, to make lives easier for

those of us who want to figure out how old Jim Mock is, but only want to
type 'calendar -f calendar.freebsd'.  This is done in a way that should
be totally backwards compatible with no noticable differences, at all.

Reviewed by:	mux
MFC after:	4 weeks
This commit is contained in:
Juli Mallett 2002-07-28 13:46:09 +00:00
parent 6ee0eb7eda
commit afb325f75d

View File

@ -68,7 +68,7 @@ __FBSDID("$FreeBSD$");
const char *calendarFile = "calendar"; /* default calendar file */ const char *calendarFile = "calendar"; /* default calendar file */
const char *calendarHome = ".calendar"; /* HOME */ const char *calendarHomes[] = { ".calendar", _PATH_INCLUDE }; /* HOME */
const char *calendarNoMail = "nomail"; /* don't sent mail if this file exist */ const char *calendarNoMail = "nomail"; /* don't sent mail if this file exist */
struct fixs neaster, npaskha; struct fixs neaster, npaskha;
@ -236,13 +236,14 @@ FILE *
opencal() opencal()
{ {
uid_t uid; uid_t uid;
int fd, pdes[2]; size_t i;
int fd, found, pdes[2];
struct stat sbuf; struct stat sbuf;
/* open up calendar file as stdin */ /* open up calendar file as stdin */
if (!freopen(calendarFile, "r", stdin)) { if (!freopen(calendarFile, "r", stdin)) {
if (doall) { if (doall) {
if (chdir(calendarHome) != 0) if (chdir(calendarHomes[0]) != 0)
return (NULL); return (NULL);
if (stat(calendarNoMail, &sbuf) == 0) if (stat(calendarNoMail, &sbuf) == 0)
return (NULL); return (NULL);
@ -250,9 +251,15 @@ opencal()
return (NULL); return (NULL);
} else { } else {
chdir(getenv("HOME")); chdir(getenv("HOME"));
if (!(chdir(calendarHome) == 0 && for (found = i = 0; i < sizeof(calendarHomes) /
freopen(calendarFile, "r", stdin))) sizeof(calendarHomes[0]); i++)
errx(1, "no calendar file: ``%s'' or ``~/%s/%s\n", calendarFile, calendarHome, calendarFile); if (chdir(calendarHomes[i]) == 0 &&
freopen(calendarFile, "r", stdin)) {
found = 1;
break;
}
if (!found)
errx(1, "no calendar file: ``%s''", calendarFile);
} }
} }
if (pipe(pdes) < 0) if (pipe(pdes) < 0)