version 1.5, 1998/11/04 11:32:02 |
version 1.6, 1998/11/08 04:31:13 |
|
|
* following a line that is matched, that starts with "whitespace", is shown |
* following a line that is matched, that starts with "whitespace", is shown |
* along with the matched line. |
* along with the matched line. |
*/ |
*/ |
int |
struct match * |
isnow(endp, monthp, dayp, varp) |
isnow(endp) |
char *endp; |
char *endp; |
int *monthp; |
|
int *dayp; |
|
int *varp; |
|
{ |
{ |
int day, flags = 0, month = 0, v1, v2; |
int day, flags = 0, month = 0, v1, v2; |
|
int monthp, dayp, varp; |
|
struct match *matches; |
|
|
/* |
/* |
* CONVENTION |
* CONVENTION |
|
|
/* read first field */ |
/* read first field */ |
/* 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 (0); |
return (NULL); |
|
|
/* Easter or Easter depending days */ |
/* Easter or Easter depending days */ |
if (flags & F_EASTER) |
if (flags & F_EASTER) |
|
|
if (flags & F_ISMONTH) { |
if (flags & F_ISMONTH) { |
day = v1; |
day = v1; |
month = v2; |
month = v2; |
*varp = 0; |
varp = 0; |
} |
} |
|
|
/* {Month} {Weekday,Day} ... */ |
/* {Month} {Weekday,Day} ... */ |
|
|
month = v1; |
month = v1; |
/* if no recognizable day, assume the first */ |
/* if no recognizable day, assume the first */ |
day = v2 ? v2 : 1; |
day = v2 ? v2 : 1; |
*varp = 0; |
varp = 0; |
} |
} |
} |
} |
|
|
|
|
fprintf(stderr, "\nday: %d %s month %d\n", day, endp, month); |
fprintf(stderr, "\nday: %d %s month %d\n", day, endp, month); |
#endif |
#endif |
|
|
*varp = 1; |
varp = 1; |
/* variable weekday, SundayLast, MondayFirst ... */ |
/* variable weekday, SundayLast, MondayFirst ... */ |
if (day < 0 || day >= 10) { |
if (day < 0 || day >= 10) { |
|
|
|
|
#endif |
#endif |
} |
} |
} |
} |
|
else |
|
day = tp->tm_mday + (((day - 1) - tp->tm_wday + 7) % 7); |
} |
} |
|
|
if (!(flags & F_EASTER)) { |
if (!(flags & F_EASTER)) { |
*monthp = month; |
monthp = month; |
*dayp = day; |
dayp = day; |
day = cumdays[month] + day; |
day = cumdays[month] + day; |
} |
} |
else { |
else { |
for (v1 = 0; day > cumdays[v1]; v1++) |
for (v1 = 0; day > cumdays[v1]; v1++) |
; |
; |
*monthp = v1 - 1; |
monthp = v1 - 1; |
*dayp = day - cumdays[v1 - 1]; |
dayp = day - cumdays[v1 - 1]; |
*varp = 1; |
varp = 1; |
} |
} |
|
|
#if DEBUG |
#if DEBUG |
fprintf(stderr, "day2: day %d(%d) yday %d\n", *dayp, day, tp->tm_yday); |
fprintf(stderr, "day2: day %d(%d) yday %d\n", dayp, day, tp->tm_yday); |
#endif |
#endif |
/* if today or today + offset days */ |
/* if today or today + offset days */ |
if (day >= tp->tm_yday - f_dayBefore && |
if ((day >= tp->tm_yday - f_dayBefore && |
day <= tp->tm_yday + offset + f_dayAfter) |
day <= tp->tm_yday + offset + f_dayAfter) || |
return (1); |
|
|
|
/* if number of days left in this year + days to event in next year */ |
/* if number of days left in this year + days to event in next year */ |
if (yrdays - tp->tm_yday + day <= offset + f_dayAfter || |
(yrdays - tp->tm_yday + day <= offset + f_dayAfter || |
/* a year backward, eg. 6 Jan and 10 days before -> 27. Dec */ |
/* a year backward, eg. 6 Jan and 10 days before -> 27. Dec */ |
tp->tm_yday + day - f_dayBefore < 0 |
tp->tm_yday + day - f_dayBefore < 0 |
) |
)) { |
return (1); |
if ((matches = malloc(sizeof(struct match))) == NULL) |
return (0); |
errx(1,"cannot allocate memory"); |
|
matches->month = monthp; |
|
matches->day = dayp; |
|
matches->var = varp; |
|
matches->year = tp->tm_year; /* XXX */ |
|
matches->next = NULL; |
|
return (matches); |
|
} |
|
return (NULL); |
} |
} |
|
|
|
|