diff options
author | jmallett <jmallett@FreeBSD.org> | 2002-07-28 13:46:09 +0000 |
---|---|---|
committer | jmallett <jmallett@FreeBSD.org> | 2002-07-28 13:46:09 +0000 |
commit | fd7aefbcf8371f8643e6f7f8bafce3645e846e23 (patch) | |
tree | f0f283bcd2ccec63e1ecb732faceaa81b0032556 /usr.bin/calendar | |
parent | c755e11084087be2b6056fa2e5ad3bfb5d94ebc9 (diff) | |
download | FreeBSD-src-fd7aefbcf8371f8643e6f7f8bafce3645e846e23.zip FreeBSD-src-fd7aefbcf8371f8643e6f7f8bafce3645e846e23.tar.gz |
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
Diffstat (limited to 'usr.bin/calendar')
-rw-r--r-- | usr.bin/calendar/io.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/usr.bin/calendar/io.c b/usr.bin/calendar/io.c index c590886..df19e8c 100644 --- a/usr.bin/calendar/io.c +++ b/usr.bin/calendar/io.c @@ -68,7 +68,7 @@ __FBSDID("$FreeBSD$"); 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 */ struct fixs neaster, npaskha; @@ -236,13 +236,14 @@ FILE * opencal() { uid_t uid; - int fd, pdes[2]; + size_t i; + int fd, found, pdes[2]; struct stat sbuf; /* open up calendar file as stdin */ if (!freopen(calendarFile, "r", stdin)) { if (doall) { - if (chdir(calendarHome) != 0) + if (chdir(calendarHomes[0]) != 0) return (NULL); if (stat(calendarNoMail, &sbuf) == 0) return (NULL); @@ -250,9 +251,15 @@ opencal() return (NULL); } else { chdir(getenv("HOME")); - if (!(chdir(calendarHome) == 0 && - freopen(calendarFile, "r", stdin))) - errx(1, "no calendar file: ``%s'' or ``~/%s/%s\n", calendarFile, calendarHome, calendarFile); + for (found = i = 0; i < sizeof(calendarHomes) / + sizeof(calendarHomes[0]); i++) + 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) |