Instead of searching only for a calendar file named `calendar' in the current

directory, use the first found of:

	./calendar
	./.calendar
	/etc/calendar

Note that currently only the first found of these is used (so that users may
override a system calendar placed in /etc if desired).  Users who want can always
use #include to continue the chain...
This commit is contained in:
jwise 2004-11-29 17:03:43 +00:00
parent e9042901ff
commit d728174e30
1 changed files with 21 additions and 4 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: calendar.c,v 1.30 2004/01/05 23:23:34 jmmv Exp $ */
/* $NetBSD: calendar.c,v 1.31 2004/11/29 17:03:43 jwise Exp $ */
/*
* Copyright (c) 1989, 1993, 1994
@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1989, 1993\n\
#if 0
static char sccsid[] = "@(#)calendar.c 8.4 (Berkeley) 1/7/95";
#endif
__RCSID("$NetBSD: calendar.c,v 1.30 2004/01/05 23:23:34 jmmv Exp $");
__RCSID("$NetBSD: calendar.c,v 1.31 2004/11/29 17:03:43 jwise Exp $");
#endif /* not lint */
#include <sys/param.h>
@ -70,7 +70,8 @@ __RCSID("$NetBSD: calendar.c,v 1.30 2004/01/05 23:23:34 jmmv Exp $");
#endif
static unsigned short lookahead = 1, weekend = 2;
static char *fname = "calendar", *datestr = NULL;
static char *fname = NULL, *datestr = NULL;
static char *defaultnames[] = {"calendar", ".calendar", "/etc/calendar", NULL};
static struct passwd *pw;
static int doall;
static char path[MAXPATHLEN + 1];
@ -325,17 +326,32 @@ static FILE *
opencal(void)
{
int fd, pdes[2];
char **name;
/* open up calendar file as stdin */
if (!freopen(fname, "rf", stdin)) {
if (fname == NULL) {
for (name = defaultnames; *name != NULL; name++) {
if (!freopen(*name, "rf", stdin))
continue;
else
break;
}
if (*name == NULL) {
if (doall)
return (NULL);
err(1, "Cannot open calendar file");
}
} else if (!freopen(fname, "rf", stdin)) {
if (doall)
return (NULL);
err(1, "Cannot open `%s'", fname);
}
if (pipe(pdes) < 0) {
warn("Cannot open pipe");
return (NULL);
}
switch (fork()) {
case -1: /* error */
(void)close(pdes[0]);
@ -353,6 +369,7 @@ opencal(void)
err(1, "Cannot exec `%s'", _PATH_CPP);
/*NOTREACHED*/
}
/* parent -- set stdin to pipe output */
(void)dup2(pdes[0], STDIN_FILENO);
(void)close(pdes[0]);