version 1.28, 2015/03/15 00:41:28 |
version 1.34, 2016/09/14 15:09:46 |
|
|
static struct fixs nmonths[13]; /* short national month names */ |
static struct fixs nmonths[13]; /* short national month names */ |
|
|
void |
void |
|
fill_print_date(struct match *m, struct tm *tm) |
|
{ |
|
if (strftime(m->print_date, sizeof(m->print_date), |
|
daynames ? "%a %b %d" : "%b %d", tm) == 0) |
|
m->print_date[sizeof(m->print_date) - 1] = '\0'; |
|
} |
|
|
|
void |
setnnames(void) |
setnnames(void) |
{ |
{ |
char buf[80]; |
char buf[80]; |
|
|
for (; l > 0 && isspace((unsigned char)buf[l - 1]); l--) |
for (; l > 0 && isspace((unsigned char)buf[l - 1]); l--) |
; |
; |
buf[l] = '\0'; |
buf[l] = '\0'; |
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) |
err(1, NULL); |
err(1, NULL); |
ndays[i].len = strlen(buf); |
ndays[i].len = strlen(buf); |
|
|
for (; l > 0 && isspace((unsigned char)buf[l - 1]); l--) |
for (; l > 0 && isspace((unsigned char)buf[l - 1]); l--) |
; |
; |
buf[l] = '\0'; |
buf[l] = '\0'; |
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) |
err(1, NULL); |
err(1, NULL); |
fndays[i].len = strlen(buf); |
fndays[i].len = strlen(buf); |
|
|
for (; l > 0 && isspace((unsigned char)buf[l - 1]); l--) |
for (; l > 0 && isspace((unsigned char)buf[l - 1]); l--) |
; |
; |
buf[l] = '\0'; |
buf[l] = '\0'; |
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) |
err(1, NULL); |
err(1, NULL); |
nmonths[i].len = strlen(buf); |
nmonths[i].len = strlen(buf); |
|
|
for (; l > 0 && isspace((unsigned char)buf[l - 1]); l--) |
for (; l > 0 && isspace((unsigned char)buf[l - 1]); l--) |
; |
; |
buf[l] = '\0'; |
buf[l] = '\0'; |
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) |
err(1, NULL); |
err(1, NULL); |
fnmonths[i].len = strlen(buf); |
fnmonths[i].len = strlen(buf); |
|
|
tp->tm_isdst = 0; |
tp->tm_isdst = 0; |
tp->tm_hour = 12; |
tp->tm_hour = 12; |
*now = mktime(tp); |
*now = mktime(tp); |
if (isleap(tp->tm_year + TM_YEAR_BASE)) |
if (isleap(tp->tm_year + 1900)) |
cumdays = daytab[1]; |
cumdays = daytab[1]; |
else |
else |
cumdays = daytab[0]; |
cumdays = daytab[0]; |
|
|
*(date + len - 4) = '\0'; |
*(date + len - 4) = '\0'; |
tm.tm_year = atoi(date); |
tm.tm_year = atoi(date); |
|
|
/* tm_year up TM_YEAR_BASE ... */ |
|
if (tm.tm_year < 69) /* Y2K */ |
if (tm.tm_year < 69) /* Y2K */ |
tm.tm_year += 2000 - TM_YEAR_BASE; |
tm.tm_year += 100; |
else if (tm.tm_year < 100) |
else if (tm.tm_year > 1900) |
tm.tm_year += 1900 - TM_YEAR_BASE; |
tm.tm_year -= 1900; |
else if (tm.tm_year > TM_YEAR_BASE) |
|
tm.tm_year -= TM_YEAR_BASE; |
|
} |
} |
|
|
#if DEBUG |
#if DEBUG |
|
|
/* adjust bodun rate */ |
/* adjust bodun rate */ |
if (bodun && !bodun_always) |
if (bodun && !bodun_always) |
bodun = !arc4random_uniform(3); |
bodun = !arc4random_uniform(3); |
|
|
/* Easter or Easter depending days */ |
/* Easter or Easter depending days */ |
if (flags & F_SPECIAL) |
if (flags & F_SPECIAL) |
vwd = v1; |
vwd = v1; |
|
|
*/ |
*/ |
if (tp->tm_yday > 300 && tmtmp.tm_mon <= 1) |
if (tp->tm_yday > 300 && tmtmp.tm_mon <= 1) |
variable_weekday(&vwd, tmtmp.tm_mon + 1, |
variable_weekday(&vwd, tmtmp.tm_mon + 1, |
tmtmp.tm_year + TM_YEAR_BASE + 1); |
tmtmp.tm_year + 1900 + 1); |
else |
else |
variable_weekday(&vwd, tmtmp.tm_mon + 1, |
variable_weekday(&vwd, tmtmp.tm_mon + 1, |
tmtmp.tm_year + TM_YEAR_BASE); |
tmtmp.tm_year + 1900); |
day = cumdays[tmtmp.tm_mon + 1] + vwd; |
day = cumdays[tmtmp.tm_mon + 1] + vwd; |
tmtmp.tm_mday = 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 + 1900) ? 366 : 365) |
<= v1) |
<= v1) |
tmtmp.tm_year++; |
tmtmp.tm_year++; |
else if(!bodun || (day - tp->tm_yday) != -1) |
else if(!bodun || (day - tp->tm_yday) != -1) |
|
|
} |
} |
|
|
(void)mktime(&tmtmp); |
(void)mktime(&tmtmp); |
if (strftime(tmp->print_date, |
fill_print_date(tmp, &tmtmp); |
sizeof(tmp->print_date), |
|
/* "%a %b %d", &tm); Skip weekdays */ |
|
"%b %d", &tmtmp) == 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 (vwd) { |
if (vwd) { |
v1 = vwd; |
v1 = vwd; |
variable_weekday(&v1, tmtmp.tm_mon + 1, |
variable_weekday(&v1, tmtmp.tm_mon + 1, |
tmtmp.tm_year + TM_YEAR_BASE); |
tmtmp.tm_year + 1900); |
tmtmp.tm_mday = v1; |
tmtmp.tm_mday = v1; |
} else |
} else |
tmtmp.tm_mday = dayp; |
tmtmp.tm_mday = dayp; |
|
|
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 + |
TM_YEAR_BASE) + vwd; |
1900) + 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, |
tmtmp.tm_year + TM_YEAR_BASE); |
tmtmp.tm_year + 1900); |
tmtmp.tm_mday = v1; |
tmtmp.tm_mday = v1; |
} else { |
} else { |
/* Need the following to keep Feb 29 from |
/* Need the following to keep Feb 29 from |
|
|
tdiff = difftime(ttmp, f_time)/ SECSPERDAY; |
tdiff = difftime(ttmp, f_time)/ SECSPERDAY; |
if (tdiff <= offset + f_dayAfter || |
if (tdiff <= offset + f_dayAfter || |
(bodun && tdiff == -1)) { |
(bodun && tdiff == -1)) { |
if (tdiff >= 0 || |
if (((tmtmp.tm_mon == month) || |
(bodun && tdiff == -1)) { |
(flags & F_SPECIAL) || |
|
(interval == WEEKLY)) && |
|
(tdiff >= 0 || |
|
(bodun && tdiff == -1))) { |
if ((tmp = malloc(sizeof(struct match))) == NULL) |
if ((tmp = malloc(sizeof(struct match))) == NULL) |
err(1, NULL); |
err(1, NULL); |
tmp->when = ttmp; |
tmp->when = ttmp; |
if (strftime(tmp->print_date, |
fill_print_date(tmp, &tmtmp); |
sizeof(tmp->print_date), |
|
/* "%a %b %d", &tm); Skip weekdays */ |
|
"%b %d", &tmtmp) == 0) |
|
tmp->print_date[sizeof(tmp->print_date) - 1] = '\0'; |
|
tmp->bodun = bodun && tdiff == -1; |
tmp->bodun = bodun && tdiff == -1; |
tmp->var = varp; |
tmp->var = varp; |
tmp->next = NULL; |
tmp->next = NULL; |