=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/calendar/day.c,v retrieving revision 1.10 retrieving revision 1.15 diff -u -r1.10 -r1.15 --- src/usr.bin/calendar/day.c 1999/11/25 03:46:46 1.10 +++ src/usr.bin/calendar/day.c 2003/06/03 02:56:06 1.15 @@ -1,4 +1,4 @@ -/* $OpenBSD: day.c,v 1.10 1999/11/25 03:46:46 pjanzen Exp $ */ +/* $OpenBSD: day.c,v 1.15 2003/06/03 02:56:06 millert Exp $ */ /* * Copyright (c) 1989, 1993, 1994 @@ -12,11 +12,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -43,7 +39,7 @@ #if 0 static const char sccsid[] = "@(#)calendar.c 8.3 (Berkeley) 3/25/94"; #else -static char rcsid[] = "$OpenBSD: day.c,v 1.10 1999/11/25 03:46:46 pjanzen Exp $"; +static char rcsid[] = "$OpenBSD: day.c,v 1.15 2003/06/03 02:56:06 millert Exp $"; #endif #endif /* not lint */ @@ -108,7 +104,7 @@ if (ndays[i].name != NULL) free(ndays[i].name); if ((ndays[i].name = strdup(buf)) == NULL) - errx(1, "cannot allocate memory"); + err(1, NULL); ndays[i].len = strlen(buf); l = strftime(buf, sizeof(buf), "%A", &tm); @@ -118,7 +114,7 @@ if (fndays[i].name != NULL) free(fndays[i].name); if ((fndays[i].name = strdup(buf)) == NULL) - errx(1, "cannot allocate memory"); + err(1, NULL); fndays[i].len = strlen(buf); } @@ -131,7 +127,7 @@ if (nmonths[i].name != NULL) free(nmonths[i].name); if ((nmonths[i].name = strdup(buf)) == NULL) - errx(1, "cannot allocate memory"); + err(1, NULL); nmonths[i].len = strlen(buf); l = strftime(buf, sizeof(buf), "%B", &tm); @@ -141,7 +137,7 @@ if (fnmonths[i].name != NULL) free(fnmonths[i].name); if ((fnmonths[i].name = strdup(buf)) == NULL) - errx(1, "cannot allocate memory"); + err(1, NULL); fnmonths[i].len = strlen(buf); } /* Hardwired special events */ @@ -153,7 +149,7 @@ spev[1].getev = paskha; for (i = 0; i < NUMEV; i++) { if (spev[i].name == NULL) - errx(1, "cannot allocate memory"); + err(1, NULL); spev[i].uname = NULL; } } @@ -253,8 +249,9 @@ * with \t, is shown along with the matched line. */ struct match * -isnow(endp) +isnow(endp, bodun) char *endp; + int bodun; { int day = 0, flags = 0, month = 0, v1, v2, i; int monthp, dayp, varp = 0; @@ -279,6 +276,10 @@ if (!(v1 = getfield(endp, &endp, &flags))) return (NULL); + /* adjust bodun rate */ + if (bodun && !bodun_always) + bodun = !(arc4random() % 3); + /* Easter or Easter depending days */ if (flags & F_SPECIAL) vwd = v1; @@ -423,18 +424,28 @@ if ((v2 += isleap(tp->tm_year + TM_YEAR_BASE) ? 366 : 365) <= v1) tmtmp.tm_year++; - else + else if(!bodun || (day - tp->tm_yday) != -1) return(NULL); } if ((tmp = malloc(sizeof(struct match))) == NULL) - errx(1, "cannot allocate memory"); - tmp->when = f_time + v2 * SECSPERDAY; + err(1, NULL); + + 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); if (strftime(tmp->print_date, 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->next = NULL; return(tmp); @@ -517,16 +528,19 @@ warnx("time out of range: %s", endp); else { tdiff = difftime(ttmp, f_time)/ SECSPERDAY; - if (tdiff <= offset + f_dayAfter) { - if (tdiff >= 0) { + if (tdiff <= offset + f_dayAfter || + (bodun && tdiff == -1)) { + if (tdiff >= 0 || + (bodun && tdiff == -1)) { if ((tmp = malloc(sizeof(struct match))) == NULL) - errx(1, "cannot allocate memory"); + err(1, NULL); tmp->when = ttmp; if (strftime(tmp->print_date, 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->var = varp; tmp->next = NULL; if (tmp2) @@ -547,9 +561,9 @@ int getmonth(s) - register char *s; + char *s; { - register char **p; + char **p; struct fixs *n; for (n = fnmonths; n->name; ++n) @@ -567,9 +581,9 @@ int getday(s) - register char *s; + char *s; { - register char **p; + char **p; struct fixs *n; for (n = fndays; n->name; ++n) @@ -591,9 +605,9 @@ */ int getdayvar(s) - register char *s; + char *s; { - register int offset; + int offset; offset = strlen(s);