=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/calendar/day.c,v retrieving revision 1.7 retrieving revision 1.11 diff -u -r1.7 -r1.11 --- src/usr.bin/calendar/day.c 1998/12/13 07:31:07 1.7 +++ src/usr.bin/calendar/day.c 2001/06/05 21:27:16 1.11 @@ -1,4 +1,4 @@ -/* $OpenBSD: day.c,v 1.7 1998/12/13 07:31:07 pjanzen Exp $ */ +/* $OpenBSD: day.c,v 1.11 2001/06/05 21:27:16 pjanzen Exp $ */ /* * Copyright (c) 1989, 1993, 1994 @@ -43,7 +43,7 @@ #if 0 static const char sccsid[] = "@(#)calendar.c 8.3 (Berkeley) 3/25/94"; #else -static char rcsid[] = "$OpenBSD: day.c,v 1.7 1998/12/13 07:31:07 pjanzen Exp $"; +static char rcsid[] = "$OpenBSD: day.c,v 1.11 2001/06/05 21:27:16 pjanzen Exp $"; #endif #endif /* not lint */ @@ -108,7 +108,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 +118,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 +131,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 +141,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 +153,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; } } @@ -248,9 +248,9 @@ * 3-charweekday (Friday, Monday, mon.) * numeric month or day (1, 2, 04) * - * Any character may separate them, or they may not be separated. Any line, - * following a line that is matched, that starts with "whitespace", is shown - * along with the matched line. + * Any character except \t or '*' may separate them, or they may not be + * separated. Any line following a line that is matched, that starts + * with \t, is shown along with the matched line. */ struct match * isnow(endp) @@ -404,6 +404,20 @@ memcpy(&tmtmp, tp, sizeof(struct tm)); tmtmp.tm_mday = dayp; 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; if ((v2 > v1) || (v2 < 0)) { if ((v2 += isleap(tp->tm_year + TM_YEAR_BASE) ? 366 : 365) @@ -413,7 +427,7 @@ return(NULL); } if ((tmp = malloc(sizeof(struct match))) == NULL) - errx(1, "cannot allocate memory"); + err(1, NULL); tmp->when = f_time + v2 * SECSPERDAY; (void)mktime(&tmtmp); if (strftime(tmp->print_date, @@ -484,7 +498,7 @@ if (flags & F_SPECIAL) { tmtmp.tm_mon = 0; /* Gee, mktime() is nice */ tmtmp.tm_mday = spev[v1].getev(tmtmp.tm_year + - vwd + TM_YEAR_BASE); + TM_YEAR_BASE) + vwd; } else if (vwd) { v1 = vwd; variable_weekday(&v1, tmtmp.tm_mon + 1, @@ -506,7 +520,7 @@ if (tdiff <= offset + f_dayAfter) { if (tdiff >= 0) { 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),