=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/calendar/day.c,v retrieving revision 1.13 retrieving revision 1.18 diff -u -r1.13 -r1.18 --- src/usr.bin/calendar/day.c 2001/09/27 18:19:20 1.13 +++ src/usr.bin/calendar/day.c 2004/12/10 20:47:30 1.18 @@ -1,4 +1,4 @@ -/* $OpenBSD: day.c,v 1.13 2001/09/27 18:19:20 mickey Exp $ */ +/* $OpenBSD: day.c,v 1.18 2004/12/10 20:47:30 mickey 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.13 2001/09/27 18:19:20 mickey Exp $"; +static const char rcsid[] = "$OpenBSD: day.c,v 1.18 2004/12/10 20:47:30 mickey Exp $"; #endif #endif /* not lint */ @@ -69,6 +65,8 @@ struct tm *tp; int *cumdays, offset; char dayname[10]; +enum calendars calendar; +u_long julian; /* 1-based month, 0-based days, cumulative */ @@ -145,12 +143,15 @@ fnmonths[i].len = strlen(buf); } /* Hardwired special events */ - spev[0].name = strdup(EASTER); - spev[0].nlen = EASTERNAMELEN; - spev[0].getev = easter; - spev[1].name = strdup(PASKHA); - spev[1].nlen = PASKHALEN; - spev[1].getev = paskha; + spev[0].name = strdup(PESACH); + spev[0].nlen = PESACHLEN; + spev[0].getev = pesach; + spev[1].name = strdup(EASTER); + spev[1].nlen = EASTERNAMELEN; + spev[1].getev = easter; + spev[2].name = strdup(PASKHA); + spev[2].nlen = PASKHALEN; + spev[2].getev = paskha; for (i = 0; i < NUMEV; i++) { if (spev[i].name == NULL) err(1, NULL); @@ -242,6 +243,26 @@ return(mktime(&tm)); } +void +adjust_calendar(int *day, int *month) +{ + switch (calendar) { + case GREGORIAN: + break; + + case JULIAN: + *day += julian; + if (*day > (cumdays[*month + 1] - cumdays[*month])) { + *day -= (cumdays[*month + 1] - cumdays[*month]); + if (++*month > 12) + *month = 1; + } + break; + case LUNAR: + break; + } +} + /* * Possible date formats include any combination of: * 3-charmonth (January, Jan, Jan) @@ -316,7 +337,8 @@ if (month == -1) { month = tp->tm_mon + 1; interval = MONTHLY; - } + } else if (calendar) + adjust_calendar(&day, &month); if ((month > 12) || (month < 1)) return (NULL); } @@ -334,8 +356,11 @@ day = 1; /* If a weekday was spelled out without an ordering, * assume the first of that day in the month */ - if ((flags & F_ISDAY) && (day >= 1) && (day <=7)) - day += 10; + if ((flags & F_ISDAY)) { + if ((day >= 1) && (day <=7)) + day += 10; + } else if (calendar) + adjust_calendar(&day, &month); } /* Hm ... */ @@ -352,7 +377,8 @@ if (month == -1) { month = tp->tm_mon + 1; interval = MONTHLY; - } + } else if (calendar) + adjust_calendar(&day, &month); } /* {Month} {Weekday,Day} ... */ @@ -361,8 +387,11 @@ month = v1; /* if no recognizable day, assume the first */ day = v2 ? v2 : 1; - if ((flags & F_ISDAY) && (day >= 1) && (day <= 7)) - day += 10; + if ((flags & F_ISDAY)) { + if ((day >= 1) && (day <= 7)) + day += 10; + } else + adjust_calendar(&day, &month); } } @@ -454,8 +483,7 @@ tmp->next = NULL; return(tmp); } - } - else { + } else { varp = 1; /* Set up v1 to the event number and ... */ v1 = vwd % (NUMEV + 1) - 1; @@ -565,9 +593,9 @@ int getmonth(s) - register char *s; + char *s; { - register char **p; + char **p; struct fixs *n; for (n = fnmonths; n->name; ++n) @@ -585,9 +613,9 @@ int getday(s) - register char *s; + char *s; { - register char **p; + char **p; struct fixs *n; for (n = fndays; n->name; ++n) @@ -609,9 +637,9 @@ */ int getdayvar(s) - register char *s; + char *s; { - register int offset; + int offset; offset = strlen(s);