Fix problem of reporting wrong matches noted in PR 41945 by using a patch

provided by Robert Elz in that PR.
This commit is contained in:
wiz 2009-12-08 13:49:08 +00:00
parent 7a77e181aa
commit 3d8b25a8ff
1 changed files with 37 additions and 18 deletions

View File

@ -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 * Copyright (c) 1989, 1993, 1994
@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1989, 1993\
#if 0 #if 0
static char sccsid[] = "@(#)calendar.c 8.4 (Berkeley) 1/7/95"; static char sccsid[] = "@(#)calendar.c 8.4 (Berkeley) 1/7/95";
#endif #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 */ #endif /* not lint */
#include <sys/param.h> #include <sys/param.h>
@ -63,6 +63,13 @@ __RCSID("$NetBSD: calendar.c,v 1.47 2008/09/30 05:51:41 dholland Exp $");
#include "pathnames.h" #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 lookahead = 1;
static unsigned short weekend = 2; static unsigned short weekend = 2;
static char *fname = NULL; static char *fname = NULL;
@ -247,18 +254,13 @@ isnow(char *endp)
int v1; int v1;
int v2; int v2;
#define F_ISMONTH 0x01
#define F_ISDAY 0x02
#define F_WILDMONTH 0x04
#define F_WILDDAY 0x08
flags = 0; flags = 0;
/* didn't recognize anything, skip it */ /* didn't recognize anything, skip it */
if (!(v1 = getfield(endp, &endp, &flags))) if (!(v1 = getfield(endp, &endp, &flags)))
return false; return false;
if (flags & F_ISDAY || v1 > 12) { if ((flags & (F_ISDAY|F_ISDOW)) || v1 > 12) {
/* found a day */ /* found a day */
day = v1; day = v1;
/* if no recognizable month, assume wildcard ('*') month */ /* if no recognizable month, assume wildcard ('*') month */
@ -295,10 +297,17 @@ isnow(char *endp)
if (flags & F_WILDMONTH && flags & F_ISDAY && day == tp->tm_mday) if (flags & F_WILDMONTH && flags & F_ISDAY && day == tp->tm_mday)
return true; 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) if (flags & F_ISMONTH && flags & F_WILDDAY && month == tp->tm_mon + 1)
return true; 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 = tp->tm_mday + (((day - 1) - tp->tm_wday + 7) % 7);
day = cumdays[month] + day; day = cumdays[month] + day;
@ -320,9 +329,15 @@ getfield(char *p, char **endp, int *flags)
char *start; char *start;
char savech; 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) && \ #define FLDCHAR(a) (*p != '\0' && !isdigit((unsigned char)*p) && \
!isalpha((unsigned char)*p) && *p != '*') !isalpha((unsigned char)*p) && *p != '*')
val = 0;
for (/*EMPTY*/; FLDCHAR(*p); ++p) for (/*EMPTY*/; FLDCHAR(*p); ++p)
continue; continue;
if (*p == '*') { /* `*' is current month */ if (*p == '*') { /* `*' is current month */
@ -343,17 +358,21 @@ getfield(char *p, char **endp, int *flags)
*endp = p; *endp = p;
return val; return val;
} }
for (start = p; *p != '\0' && isalpha((unsigned char)*++p); /*EMPTY*/) for (start = p; *p != '\0' && isalpha((unsigned char)*p); p++)
continue; continue;
savech = *p; savech = *p;
*p = '\0'; if (p != start) {
if ((val = getmonth(start)) != 0) *p = '\0';
*flags |= F_ISMONTH; if ((val = getmonth(start)) != 0)
else if ((val = getday(start)) != 0) *flags |= F_ISMONTH;
*flags |= F_ISDAY; else if ((val = getday(start)) != 0)
else { *flags |= F_ISDOW;
*p = savech; else {
return 0; *p = savech;
*endp = start;
return 0;
}
} }
for (*p = savech; FLDCHAR(*p); ++p) for (*p = savech; FLDCHAR(*p); ++p)
continue; continue;