version 1.7, 1998/12/13 07:31:07 |
version 1.14, 2001/11/19 19:02:13 |
|
|
if (ndays[i].name != NULL) |
if (ndays[i].name != NULL) |
free(ndays[i].name); |
free(ndays[i].name); |
if ((ndays[i].name = strdup(buf)) == NULL) |
if ((ndays[i].name = strdup(buf)) == NULL) |
errx(1, "cannot allocate memory"); |
err(1, NULL); |
ndays[i].len = strlen(buf); |
ndays[i].len = strlen(buf); |
|
|
l = strftime(buf, sizeof(buf), "%A", &tm); |
l = strftime(buf, sizeof(buf), "%A", &tm); |
|
|
if (fndays[i].name != NULL) |
if (fndays[i].name != NULL) |
free(fndays[i].name); |
free(fndays[i].name); |
if ((fndays[i].name = strdup(buf)) == NULL) |
if ((fndays[i].name = strdup(buf)) == NULL) |
errx(1, "cannot allocate memory"); |
err(1, NULL); |
fndays[i].len = strlen(buf); |
fndays[i].len = strlen(buf); |
} |
} |
|
|
|
|
if (nmonths[i].name != NULL) |
if (nmonths[i].name != NULL) |
free(nmonths[i].name); |
free(nmonths[i].name); |
if ((nmonths[i].name = strdup(buf)) == NULL) |
if ((nmonths[i].name = strdup(buf)) == NULL) |
errx(1, "cannot allocate memory"); |
err(1, NULL); |
nmonths[i].len = strlen(buf); |
nmonths[i].len = strlen(buf); |
|
|
l = strftime(buf, sizeof(buf), "%B", &tm); |
l = strftime(buf, sizeof(buf), "%B", &tm); |
|
|
if (fnmonths[i].name != NULL) |
if (fnmonths[i].name != NULL) |
free(fnmonths[i].name); |
free(fnmonths[i].name); |
if ((fnmonths[i].name = strdup(buf)) == NULL) |
if ((fnmonths[i].name = strdup(buf)) == NULL) |
errx(1, "cannot allocate memory"); |
err(1, NULL); |
fnmonths[i].len = strlen(buf); |
fnmonths[i].len = strlen(buf); |
} |
} |
/* Hardwired special events */ |
/* Hardwired special events */ |
|
|
spev[1].getev = paskha; |
spev[1].getev = paskha; |
for (i = 0; i < NUMEV; i++) { |
for (i = 0; i < NUMEV; i++) { |
if (spev[i].name == NULL) |
if (spev[i].name == NULL) |
errx(1, "cannot allocate memory"); |
err(1, NULL); |
spev[i].uname = NULL; |
spev[i].uname = NULL; |
} |
} |
} |
} |
|
|
* 3-charweekday (Friday, Monday, mon.) |
* 3-charweekday (Friday, Monday, mon.) |
* numeric month or day (1, 2, 04) |
* numeric month or day (1, 2, 04) |
* |
* |
* Any character may separate them, or they may not be separated. Any line, |
* Any character except \t or '*' may separate them, or they may not be |
* following a line that is matched, that starts with "whitespace", is shown |
* separated. Any line following a line that is matched, that starts |
* along with the matched line. |
* with \t, is shown along with the matched line. |
*/ |
*/ |
struct match * |
struct match * |
isnow(endp) |
isnow(endp, bodun) |
char *endp; |
char *endp; |
|
int bodun; |
{ |
{ |
int day = 0, flags = 0, month = 0, v1, v2, i; |
int day = 0, flags = 0, month = 0, v1, v2, i; |
int monthp, dayp, varp = 0; |
int monthp, dayp, varp = 0; |
|
|
if (!(v1 = getfield(endp, &endp, &flags))) |
if (!(v1 = getfield(endp, &endp, &flags))) |
return (NULL); |
return (NULL); |
|
|
|
/* adjust bodun rate */ |
|
if (bodun && !bodun_always) |
|
bodun = !(arc4random() % 3); |
|
|
/* Easter or Easter depending days */ |
/* Easter or Easter depending days */ |
if (flags & F_SPECIAL) |
if (flags & F_SPECIAL) |
vwd = v1; |
vwd = v1; |
|
|
memcpy(&tmtmp, tp, sizeof(struct tm)); |
memcpy(&tmtmp, tp, sizeof(struct tm)); |
tmtmp.tm_mday = dayp; |
tmtmp.tm_mday = dayp; |
tmtmp.tm_mon = monthp - 1; |
tmtmp.tm_mon = monthp - 1; |
|
if (vwd) { |
|
/* We want the event next year if it's late now |
|
* this year. The 50-day limit means we don't have to |
|
* worry if next year is or isn't a leap year. |
|
*/ |
|
if (tp->tm_yday > 300 && tmtmp.tm_mon <= 1) |
|
variable_weekday(&vwd, tmtmp.tm_mon + 1, |
|
tmtmp.tm_year + TM_YEAR_BASE + 1); |
|
else |
|
variable_weekday(&vwd, tmtmp.tm_mon + 1, |
|
tmtmp.tm_year + TM_YEAR_BASE); |
|
day = cumdays[tmtmp.tm_mon + 1] + vwd; |
|
tmtmp.tm_mday = vwd; |
|
} |
v2 = day - tp->tm_yday; |
v2 = day - tp->tm_yday; |
if ((v2 > v1) || (v2 < 0)) { |
if ((v2 > v1) || (v2 < 0)) { |
if ((v2 += isleap(tp->tm_year + TM_YEAR_BASE) ? 366 : 365) |
if ((v2 += isleap(tp->tm_year + TM_YEAR_BASE) ? 366 : 365) |
<= v1) |
<= v1) |
tmtmp.tm_year++; |
tmtmp.tm_year++; |
else |
else if(!bodun || (day - tp->tm_yday) != -1) |
return(NULL); |
return(NULL); |
} |
} |
if ((tmp = malloc(sizeof(struct match))) == NULL) |
if ((tmp = malloc(sizeof(struct match))) == NULL) |
errx(1, "cannot allocate memory"); |
err(1, NULL); |
tmp->when = f_time + v2 * SECSPERDAY; |
|
|
if (bodun && (day - tp->tm_yday) == -1) { |
|
tmp->when = f_time - 1 * SECSPERDAY; |
|
tmtmp.tm_mday++; |
|
tmp->bodun = 1; |
|
} else { |
|
tmp->when = f_time + v2 * SECSPERDAY; |
|
tmp->bodun = 0; |
|
} |
|
|
(void)mktime(&tmtmp); |
(void)mktime(&tmtmp); |
if (strftime(tmp->print_date, |
if (strftime(tmp->print_date, |
sizeof(tmp->print_date), |
sizeof(tmp->print_date), |
/* "%a %b %d", &tm); Skip weekdays */ |
/* "%a %b %d", &tm); Skip weekdays */ |
"%b %d", &tmtmp) == 0) |
"%b %d", &tmtmp) == 0) |
tmp->print_date[sizeof(tmp->print_date) - 1] = '\0'; |
tmp->print_date[sizeof(tmp->print_date) - 1] = '\0'; |
|
|
tmp->var = varp; |
tmp->var = varp; |
tmp->next = NULL; |
tmp->next = NULL; |
return(tmp); |
return(tmp); |
|
|
if (flags & F_SPECIAL) { |
if (flags & F_SPECIAL) { |
tmtmp.tm_mon = 0; /* Gee, mktime() is nice */ |
tmtmp.tm_mon = 0; /* Gee, mktime() is nice */ |
tmtmp.tm_mday = spev[v1].getev(tmtmp.tm_year + |
tmtmp.tm_mday = spev[v1].getev(tmtmp.tm_year + |
vwd + TM_YEAR_BASE); |
TM_YEAR_BASE) + vwd; |
} else if (vwd) { |
} else if (vwd) { |
v1 = vwd; |
v1 = vwd; |
variable_weekday(&v1, tmtmp.tm_mon + 1, |
variable_weekday(&v1, tmtmp.tm_mon + 1, |
|
|
warnx("time out of range: %s", endp); |
warnx("time out of range: %s", endp); |
else { |
else { |
tdiff = difftime(ttmp, f_time)/ SECSPERDAY; |
tdiff = difftime(ttmp, f_time)/ SECSPERDAY; |
if (tdiff <= offset + f_dayAfter) { |
if (tdiff <= offset + f_dayAfter || |
if (tdiff >= 0) { |
(bodun && tdiff == -1)) { |
|
if (tdiff >= 0 || |
|
(bodun && tdiff == -1)) { |
if ((tmp = malloc(sizeof(struct match))) == NULL) |
if ((tmp = malloc(sizeof(struct match))) == NULL) |
errx(1, "cannot allocate memory"); |
err(1, NULL); |
tmp->when = ttmp; |
tmp->when = ttmp; |
if (strftime(tmp->print_date, |
if (strftime(tmp->print_date, |
sizeof(tmp->print_date), |
sizeof(tmp->print_date), |
/* "%a %b %d", &tm); Skip weekdays */ |
/* "%a %b %d", &tm); Skip weekdays */ |
"%b %d", &tmtmp) == 0) |
"%b %d", &tmtmp) == 0) |
tmp->print_date[sizeof(tmp->print_date) - 1] = '\0'; |
tmp->print_date[sizeof(tmp->print_date) - 1] = '\0'; |
|
tmp->bodun = bodun && tdiff == -1; |
tmp->var = varp; |
tmp->var = varp; |
tmp->next = NULL; |
tmp->next = NULL; |
if (tmp2) |
if (tmp2) |
|
|
|
|
int |
int |
getmonth(s) |
getmonth(s) |
register char *s; |
char *s; |
{ |
{ |
register char **p; |
char **p; |
struct fixs *n; |
struct fixs *n; |
|
|
for (n = fnmonths; n->name; ++n) |
for (n = fnmonths; n->name; ++n) |
|
|
|
|
int |
int |
getday(s) |
getday(s) |
register char *s; |
char *s; |
{ |
{ |
register char **p; |
char **p; |
struct fixs *n; |
struct fixs *n; |
|
|
for (n = fndays; n->name; ++n) |
for (n = fndays; n->name; ++n) |
|
|
*/ |
*/ |
int |
int |
getdayvar(s) |
getdayvar(s) |
register char *s; |
char *s; |
{ |
{ |
register int offset; |
int offset; |
|
|
|
|
offset = strlen(s); |
offset = strlen(s); |