Module Name: src Committed By: wiz Date: Tue Dec 8 13:49:08 UTC 2009
Modified Files: src/usr.bin/calendar: calendar.c Log Message: Fix problem of reporting wrong matches noted in PR 41945 by using a patch provided by Robert Elz in that PR. To generate a diff of this commit: cvs rdiff -u -r1.47 -r1.48 src/usr.bin/calendar/calendar.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/calendar/calendar.c diff -u src/usr.bin/calendar/calendar.c:1.47 src/usr.bin/calendar/calendar.c:1.48 --- src/usr.bin/calendar/calendar.c:1.47 Tue Sep 30 05:51:41 2008 +++ src/usr.bin/calendar/calendar.c Tue Dec 8 13:49:08 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: calendar.c,v 1.47 2008/09/30 05:51:41 dholland Exp $ */ +/* $NetBSD: calendar.c,v 1.48 2009/12/08 13:49:08 wiz Exp $ */ /* * Copyright (c) 1989, 1993, 1994 @@ -39,7 +39,7 @@ #if 0 static char sccsid[] = "@(#)calendar.c 8.4 (Berkeley) 1/7/95"; #endif -__RCSID("$NetBSD: calendar.c,v 1.47 2008/09/30 05:51:41 dholland Exp $"); +__RCSID("$NetBSD: calendar.c,v 1.48 2009/12/08 13:49:08 wiz Exp $"); #endif /* not lint */ #include <sys/param.h> @@ -63,6 +63,13 @@ #include "pathnames.h" + /* flags used by calendar file parser */ +#define F_ISMONTH 0x01 +#define F_ISDAY 0x02 +#define F_ISDOW 0x04 +#define F_WILDMONTH 0x10 +#define F_WILDDAY 0x20 + static unsigned short lookahead = 1; static unsigned short weekend = 2; static char *fname = NULL; @@ -247,18 +254,13 @@ int v1; int v2; -#define F_ISMONTH 0x01 -#define F_ISDAY 0x02 -#define F_WILDMONTH 0x04 -#define F_WILDDAY 0x08 - flags = 0; /* didn't recognize anything, skip it */ if (!(v1 = getfield(endp, &endp, &flags))) return false; - if (flags & F_ISDAY || v1 > 12) { + if ((flags & (F_ISDAY|F_ISDOW)) || v1 > 12) { /* found a day */ day = v1; /* if no recognizable month, assume wildcard ('*') month */ @@ -295,10 +297,17 @@ if (flags & F_WILDMONTH && flags & F_ISDAY && day == tp->tm_mday) return true; + if (flags & F_WILDMONTH && flags & F_ISDOW && day == tp->tm_wday + 1) + return true; + if (flags & F_ISMONTH && flags & F_WILDDAY && month == tp->tm_mon + 1) return true; - if (flags & F_ISDAY) + if (flags & F_ISMONTH && flags & F_ISDOW && month == tp->tm_mon + 1 && + day == tp->tm_wday + 1) + return true; + + if (flags & F_ISDOW) day = tp->tm_mday + (((day - 1) - tp->tm_wday + 7) % 7); day = cumdays[month] + day; @@ -320,9 +329,15 @@ char *start; char savech; +/* + * note this macro has an arg that isn't used ... it is retained + * (it is believed) to make the macro call look more "natural" + * and suggest at the call site what is happening. + */ #define FLDCHAR(a) (*p != '\0' && !isdigit((unsigned char)*p) && \ !isalpha((unsigned char)*p) && *p != '*') + val = 0; for (/*EMPTY*/; FLDCHAR(*p); ++p) continue; if (*p == '*') { /* `*' is current month */ @@ -343,17 +358,21 @@ *endp = p; return val; } - for (start = p; *p != '\0' && isalpha((unsigned char)*++p); /*EMPTY*/) + for (start = p; *p != '\0' && isalpha((unsigned char)*p); p++) continue; + savech = *p; - *p = '\0'; - if ((val = getmonth(start)) != 0) - *flags |= F_ISMONTH; - else if ((val = getday(start)) != 0) - *flags |= F_ISDAY; - else { - *p = savech; - return 0; + if (p != start) { + *p = '\0'; + if ((val = getmonth(start)) != 0) + *flags |= F_ISMONTH; + else if ((val = getday(start)) != 0) + *flags |= F_ISDOW; + else { + *p = savech; + *endp = start; + return 0; + } } for (*p = savech; FLDCHAR(*p); ++p) continue;