summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Shalayeff <mickey@cvs.openbsd.org>2004-12-10 15:00:28 +0000
committerMichael Shalayeff <mickey@cvs.openbsd.org>2004-12-10 15:00:28 +0000
commit6059cf7366df3ada57d2143719a0b18c82c75bfa (patch)
tree469ad8b8bdd7d07c8720ac79680fbc80d72060ad
parent633f7942191287df2b36948b87a9fdc36c46ce2d (diff)
allow calendar files in julian
-rw-r--r--usr.bin/calendar/calendar.113
-rw-r--r--usr.bin/calendar/calendar.h6
-rw-r--r--usr.bin/calendar/calendars/ru_RU.KOI8-R/calendar.primety6
-rw-r--r--usr.bin/calendar/day.c49
-rw-r--r--usr.bin/calendar/io.c26
5 files changed, 83 insertions, 17 deletions
diff --git a/usr.bin/calendar/calendar.1 b/usr.bin/calendar/calendar.1
index ad9a0721976..656367ba194 100644
--- a/usr.bin/calendar/calendar.1
+++ b/usr.bin/calendar/calendar.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: calendar.1,v 1.25 2004/02/09 20:48:39 jmc Exp $
+.\" $OpenBSD: calendar.1,v 1.26 2004/12/10 15:00:27 mickey Exp $
.\"
.\" Copyright (c) 1989, 1990, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -90,6 +90,17 @@ To handle national Easter names in the calendars,
.Dq Paskha=<national_name>
(for Orthodox Easter) can be used.
.Pp
+.Dq CALENDAR
+variable can be used to specify the style.
+Only
+.Sq Julian
+and
+.Sq Gregorian
+styles are currently supported.
+Use
+.Dq CALENDAR=
+to return to the default (Gregorian).
+.Pp
To enforce special date calculation mode for Cyrillic calendars
you should specify
.Dq LANG=<local_name>
diff --git a/usr.bin/calendar/calendar.h b/usr.bin/calendar/calendar.h
index 6c2365fb6b1..f5ff7db8e05 100644
--- a/usr.bin/calendar/calendar.h
+++ b/usr.bin/calendar/calendar.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: calendar.h,v 1.9 2003/06/03 02:56:06 millert Exp $ */
+/* $OpenBSD: calendar.h,v 1.10 2004/12/10 15:00:27 mickey Exp $ */
/*
* Copyright (c) 1989, 1993, 1994
@@ -105,6 +105,10 @@ extern int f_dayBefore; /* days before current date */
#define PASKHA "paskha"
#define PASKHALEN (sizeof(PASKHA) - 1)
+/* calendars */
+extern enum calendars { GREGORIAN = 0, JULIAN, LUNAR } calendar;
+extern u_long julian;
+
#define NUMEV 2 /* Total number of such special events */
extern struct specialev spev[NUMEV];
diff --git a/usr.bin/calendar/calendars/ru_RU.KOI8-R/calendar.primety b/usr.bin/calendar/calendars/ru_RU.KOI8-R/calendar.primety
index 857ff7c1a2b..6afa01b16fd 100644
--- a/usr.bin/calendar/calendars/ru_RU.KOI8-R/calendar.primety
+++ b/usr.bin/calendar/calendars/ru_RU.KOI8-R/calendar.primety
@@ -1,4 +1,4 @@
-/* $OpenBSD: calendar.primety,v 1.1 2003/07/08 01:06:43 mickey Exp $ */
+/* $OpenBSD: calendar.primety,v 1.2 2004/12/10 15:00:27 mickey Exp $ */
/* based on: http://www.rus-sky.com/rc/
* w/ the following license:
@@ -6,6 +6,8 @@
* без каких-либо ограничений.
*/
+CALENDAR=julian
+
01/01 Васильев вечер. На Васильев вечер день прибавляется на куриный шаг.
В этот вечер девушки гадают о замужестве.
01/06 Крещенские морозы. Трещи, трещи, пока не пришли водохрещи.
@@ -389,3 +391,5 @@
12/31 Меланки. Щедрый вечер, Васильев вечер. Свинку да боров для Васильева
вечерка. Авсень. Таусень. Гадания. Васильева ночь звездиста - лето
ягодисто. Под Василья ведьмы крадут месяц.
+
+CALENDAR=
diff --git a/usr.bin/calendar/day.c b/usr.bin/calendar/day.c
index b8e4786c933..f6c3c4720fa 100644
--- a/usr.bin/calendar/day.c
+++ b/usr.bin/calendar/day.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: day.c,v 1.15 2003/06/03 02:56:06 millert Exp $ */
+/* $OpenBSD: day.c,v 1.16 2004/12/10 15:00:27 mickey Exp $ */
/*
* Copyright (c) 1989, 1993, 1994
@@ -39,7 +39,7 @@ static const char copyright[] =
#if 0
static const char sccsid[] = "@(#)calendar.c 8.3 (Berkeley) 3/25/94";
#else
-static char rcsid[] = "$OpenBSD: day.c,v 1.15 2003/06/03 02:56:06 millert Exp $";
+static char rcsid[] = "$OpenBSD: day.c,v 1.16 2004/12/10 15:00:27 mickey Exp $";
#endif
#endif /* not lint */
@@ -65,6 +65,8 @@ static char rcsid[] = "$OpenBSD: day.c,v 1.15 2003/06/03 02:56:06 millert Exp $"
struct tm *tp;
int *cumdays, offset;
char dayname[10];
+enum calendars calendar;
+u_long julian;
/* 1-based month, 0-based days, cumulative */
@@ -238,6 +240,26 @@ time_t Mktime (date)
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)
@@ -312,7 +334,8 @@ isnow(endp, bodun)
if (month == -1) {
month = tp->tm_mon + 1;
interval = MONTHLY;
- }
+ } else if (calendar)
+ adjust_calendar(&day, &month);
if ((month > 12) || (month < 1))
return (NULL);
}
@@ -330,8 +353,11 @@ isnow(endp, bodun)
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 ... */
@@ -348,7 +374,8 @@ isnow(endp, bodun)
if (month == -1) {
month = tp->tm_mon + 1;
interval = MONTHLY;
- }
+ } else if (calendar)
+ adjust_calendar(&day, &month);
}
/* {Month} {Weekday,Day} ... */
@@ -357,8 +384,11 @@ isnow(endp, bodun)
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);
}
}
@@ -450,8 +480,7 @@ isnow(endp, bodun)
tmp->next = NULL;
return(tmp);
}
- }
- else {
+ } else {
varp = 1;
/* Set up v1 to the event number and ... */
v1 = vwd % (NUMEV + 1) - 1;
diff --git a/usr.bin/calendar/io.c b/usr.bin/calendar/io.c
index 7b2f301eb22..799624c9beb 100644
--- a/usr.bin/calendar/io.c
+++ b/usr.bin/calendar/io.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: io.c,v 1.26 2004/06/02 14:58:46 tom Exp $ */
+/* $OpenBSD: io.c,v 1.27 2004/12/10 15:00:27 mickey Exp $ */
/*
* Copyright (c) 1989, 1993, 1994
@@ -39,7 +39,7 @@ static const char copyright[] =
#if 0
static const char sccsid[] = "@(#)calendar.c 8.3 (Berkeley) 3/25/94";
#else
-static char rcsid[] = "$OpenBSD: io.c,v 1.26 2004/06/02 14:58:46 tom Exp $";
+static char rcsid[] = "$OpenBSD: io.c,v 1.27 2004/12/10 15:00:27 mickey Exp $";
#endif
#endif /* not lint */
@@ -118,13 +118,31 @@ cal(void)
} else
bodun_maybe = 0;
continue;
- }
- if (bodun_maybe && strncmp(buf, "BODUN=", 6) == 0) {
+ } else if (strncmp(buf, "CALENDAR=", 9) == 0) {
+ char *ep;
+
+ if (buf[9] == '\0')
+ calendar = 0;
+ else if (!strcasecmp(buf + 9, "julian")) {
+ calendar = JULIAN;
+ errno = 0;
+ julian = strtoul(buf + 14, &ep, 10);
+ if (buf[0] == '\0' || *ep != '\0')
+ julian = 13;
+ if ((errno == ERANGE && julian == ULONG_MAX) ||
+ julian > 14)
+ errx(1, "Julian calendar offset is too large");
+ } else if (!strcasecmp(buf + 9, "gregorian"))
+ calendar = GREGORIAN;
+ else if (!strcasecmp(buf + 9, "lunar"))
+ calendar = LUNAR;
+ } else if (bodun_maybe && strncmp(buf, "BODUN=", 6) == 0) {
bodun++;
if (prefix)
free(prefix);
if ((prefix = strdup(buf + 6)) == NULL)
err(1, NULL);
+ continue;
}
/* User defined names for special events */
if ((p = strchr(buf, '='))) {