summaryrefslogtreecommitdiffstats
path: root/usr.bin/calendar
diff options
context:
space:
mode:
authorache <ache@FreeBSD.org>1996-05-10 17:32:06 +0000
committerache <ache@FreeBSD.org>1996-05-10 17:32:06 +0000
commitdf58ec580d62b91cdd59aa7806163c0bb3e9fa8e (patch)
tree35650da73c5ea4db017c33335e7f268ed8fdb6bf /usr.bin/calendar
parent02fead7e055f8da6555c29a488d8a0b2569cf17c (diff)
downloadFreeBSD-src-df58ec580d62b91cdd59aa7806163c0bb3e9fa8e.zip
FreeBSD-src-df58ec580d62b91cdd59aa7806163c0bb3e9fa8e.tar.gz
Allow to configure national Easter names.
Speedup my national months/days handling code.
Diffstat (limited to 'usr.bin/calendar')
-rw-r--r--usr.bin/calendar/calendar.111
-rw-r--r--usr.bin/calendar/calendar.h6
-rw-r--r--usr.bin/calendar/day.c72
-rw-r--r--usr.bin/calendar/io.c16
-rw-r--r--usr.bin/calendar/ostern.c22
-rw-r--r--usr.bin/calendar/paskha.c17
6 files changed, 93 insertions, 51 deletions
diff --git a/usr.bin/calendar/calendar.1 b/usr.bin/calendar/calendar.1
index f3017bd..28f1ea5 100644
--- a/usr.bin/calendar/calendar.1
+++ b/usr.bin/calendar/calendar.1
@@ -75,9 +75,14 @@ as default calendar file.
.Pp
To handle calendars in your national code table you can specify
.Dq LANG=<locale_name>
-in the calendar file as early as possible.
+in the calendar file as early as possible. To handle national Easter
+names
+.Dq Easter=<national_name>
+(for Catholic Easter) or
+.Dq Paskha=<national_name>
+(for Orthodox Easter) can be used.
.Pp
-Lines should begin with a month and day.
+Other lines should begin with a month and day.
They may be entered in almost any format, either numeric or as character
strings.
A single asterisk (``*'') matches every month.
@@ -113,6 +118,8 @@ are ignored.
Some possible calendar entries:
.Bd -unfilled -offset indent
LANG=C
+Easter=Oster
+
#include <calendar.usholiday>
#include <calendar.birthday>
diff --git a/usr.bin/calendar/calendar.h b/usr.bin/calendar/calendar.h
index 2fc4923..6579e11 100644
--- a/usr.bin/calendar/calendar.h
+++ b/usr.bin/calendar/calendar.h
@@ -65,3 +65,9 @@ void setnnames __P((void));
extern f_dayAfter; /* days after current date */
extern f_dayBefore; /* days bevore current date */
+
+struct fixs {
+ char *name;
+ int len;
+};
+
diff --git a/usr.bin/calendar/day.c b/usr.bin/calendar/day.c
index 5559ba0..0a5ff8f 100644
--- a/usr.bin/calendar/day.c
+++ b/usr.bin/calendar/day.c
@@ -60,16 +60,16 @@ static char *days[] = {
"sun", "mon", "tue", "wed", "thu", "fri", "sat", NULL,
};
-static char *fndays[8]; /* full national days names */
-static char *ndays[8]; /* short national days names */
-
static char *months[] = {
"jan", "feb", "mar", "apr", "may", "jun",
"jul", "aug", "sep", "oct", "nov", "dec", NULL,
};
-static char *fnmonths[13]; /* full national months names */
-static char *nmonths[13]; /* short national month names */
+static struct fixs fndays[8]; /* full national days names */
+static struct fixs ndays[8]; /* short national days names */
+
+static struct fixs fnmonths[13]; /* full national months names */
+static struct fixs nmonths[13]; /* short national month names */
void setnnames(void)
@@ -86,9 +86,10 @@ void setnnames(void)
l--)
;
buf[l] = '\0';
- if (ndays[i] != NULL)
- free(ndays[i]);
- ndays[i] = strdup(buf);
+ if (ndays[i].name != NULL)
+ free(ndays[i].name);
+ ndays[i].name = strdup(buf);
+ ndays[i].len = strlen(buf);
strftime(buf, sizeof(buf), "%A", &tm);
for (l = strlen(buf);
@@ -96,12 +97,13 @@ void setnnames(void)
l--)
;
buf[l] = '\0';
- if (fndays[i] != NULL)
- free(fndays[i]);
- fndays[i] = strdup(buf);
+ if (fndays[i].name != NULL)
+ free(fndays[i].name);
+ fndays[i].name = strdup(buf);
+ fndays[i].len = strlen(buf);
#ifdef DEBUG
printf("ndays[%d] = %s, fndays[%d] = %s\n",
- i, ndays[i], i, fndays[i]);
+ i, ndays[i].name, i, fndays[i].name);
#endif
}
@@ -113,9 +115,10 @@ void setnnames(void)
l--)
;
buf[l] = '\0';
- if (nmonths[i] != NULL)
- free(nmonths[i]);
- nmonths[i] = strdup(buf);
+ if (nmonths[i].name != NULL)
+ free(nmonths[i].name);
+ nmonths[i].name = strdup(buf);
+ nmonths[i].len = strlen(buf);
strftime(buf, sizeof(buf), "%B", &tm);
for (l = strlen(buf);
@@ -123,12 +126,13 @@ void setnnames(void)
l--)
;
buf[l] = '\0';
- if (fnmonths[i] != NULL)
- free(fnmonths[i]);
- fnmonths[i] = strdup(buf);
+ if (fnmonths[i].name != NULL)
+ free(fnmonths[i].name);
+ fnmonths[i].name = strdup(buf);
+ fnmonths[i].len = strlen(buf);
#ifdef DEBUG
printf("nmonths[%d] = %s, fnmonths[%d] = %s\n",
- i, nmonths[i], i, fnmonths[i]);
+ i, nmonths[i].name, i, fnmonths[i].name);
#endif
}
}
@@ -388,13 +392,14 @@ getmonth(s)
register char *s;
{
register char **p;
-
- for (p = fnmonths; *p; ++p)
- if (!strncasecmp(s, *p, strlen(*p)))
- return ((p - fnmonths) + 1);
- for (p = nmonths; *p; ++p)
- if (!strncasecmp(s, *p, strlen(*p)))
- return ((p - nmonths) + 1);
+ struct fixs *n;
+
+ for (n = fnmonths; n->name; ++n)
+ if (!strncasecmp(s, n->name, n->len))
+ return ((n - fnmonths) + 1);
+ for (n = nmonths; n->name; ++n)
+ if (!strncasecmp(s, n->name, n->len))
+ return ((n - nmonths) + 1);
for (p = months; *p; ++p)
if (!strncasecmp(s, *p, 3))
return ((p - months) + 1);
@@ -407,13 +412,14 @@ getday(s)
register char *s;
{
register char **p;
-
- for (p = fndays; *p; ++p)
- if (!strncasecmp(s, *p, strlen(*p)))
- return ((p - fndays) + 1);
- for (p = ndays; *p; ++p)
- if (!strncasecmp(s, *p, strlen(*p)))
- return ((p - ndays) + 1);
+ struct fixs *n;
+
+ for (n = fndays; n->name; ++n)
+ if (!strncasecmp(s, n->name, n->len))
+ return ((n - fndays) + 1);
+ for (n = ndays; n->name; ++n)
+ if (!strncasecmp(s, n->name, n->len))
+ return ((n - ndays) + 1);
for (p = days; *p; ++p)
if (!strncasecmp(s, *p, 3))
return ((p - days) + 1);
diff --git a/usr.bin/calendar/io.c b/usr.bin/calendar/io.c
index 3f69a00..8b2a676 100644
--- a/usr.bin/calendar/io.c
+++ b/usr.bin/calendar/io.c
@@ -65,6 +65,8 @@ char *calendarFile = "calendar"; /* default calendar file */
char *calendarHome = ".calendar"; /* HOME */
char *calendarNoMail = "nomail"; /* don't sent mail if this file exist */
+struct fixs neaster, npaskha;
+
struct iovec header[] = {
{"From: ", 6},
{NULL, 0},
@@ -107,6 +109,20 @@ cal()
setnnames();
continue;
}
+ if (strncasecmp(buf, "Easter=", 7) == 0 && buf[7]) {
+ if (neaster.name != NULL)
+ free(neaster.name);
+ neaster.name = strdup(buf + 7);
+ neaster.len = strlen(buf + 7);
+ continue;
+ }
+ if (strncasecmp(buf, "Paskha=", 7) == 0 && buf[7]) {
+ if (npaskha.name != NULL)
+ free(npaskha.name);
+ npaskha.name = strdup(buf + 7);
+ npaskha.len = strlen(buf + 7);
+ continue;
+ }
if (buf[0] != '\t') {
printing = isnow(buf, &month, &day, &var) ? 1 : 0;
if ((p = strchr(buf, '\t')) == NULL)
diff --git a/usr.bin/calendar/ostern.c b/usr.bin/calendar/ostern.c
index e0ae0f5..8ff646d 100644
--- a/usr.bin/calendar/ostern.c
+++ b/usr.bin/calendar/ostern.c
@@ -1,11 +1,14 @@
/*
* Copyright (c) 1995 Wolfram Schneider. Public domain.
*
- * $Id: ostern.c,v 1.1 1996/02/02 06:02:40 wosch Exp $
+ * $Id: ostern.c,v 1.2 1996/05/10 16:29:42 ache Exp $
*/
#include <string.h>
#include <stdlib.h>
+#include <stdio.h>
+
+#include "calendar.h"
/* return year day for Easter */
@@ -62,12 +65,18 @@ geteaster(s, year)
int year;
{
register int offset = 0;
+ extern struct fixs neaster;
#define EASTER "easter"
#define EASTERNAMELEN (sizeof(EASTER) - 1)
- /* no easter */
- if (strncasecmp(s, EASTER, EASTERNAMELEN))
+ if (strncasecmp(s, EASTER, EASTERNAMELEN) == 0)
+ s += EASTERNAMELEN;
+ else if ( neaster.name != NULL
+ && strncasecmp(s, neaster.name, neaster.len) == 0
+ )
+ s += neaster.len;
+ else
return(0);
#if DEBUG
@@ -77,14 +86,11 @@ geteaster(s, year)
/* Easter+1 or Easter-2
* ^ ^ */
- switch(*(s + EASTERNAMELEN)) {
+ switch(*s) {
case '-':
- offset = -(atoi(s + EASTERNAMELEN + 1));
- break;
-
case '+':
- offset = atoi(s + EASTERNAMELEN + 1);
+ offset = atoi(s);
break;
default:
diff --git a/usr.bin/calendar/paskha.c b/usr.bin/calendar/paskha.c
index 3fa8a31..28eb8c0 100644
--- a/usr.bin/calendar/paskha.c
+++ b/usr.bin/calendar/paskha.c
@@ -26,16 +26,13 @@
#include <stdlib.h>
#include <string.h>
+#include <stdio.h>
+
+#include "calendar.h"
#define PASKHA "paskha"
#define PASKHALEN (sizeof(PASKHA) - 1)
-/* KOI8-R encoding, needed to fully handle Russian case */
-#define PASKHA1 "пасха"
-#define PASKHALEN1 (sizeof(PASKHA1) - 1)
-
-extern int *cumdays;
-
/* return year day for Orthodox Easter using Gauss formula */
/* (old style result) */
@@ -46,6 +43,7 @@ int R; /*year*/
int a, b, c, d, e;
static int x = 15;
static int y = 6;
+ extern int *cumdays;
a = R % 19;
b = R % 4;
@@ -63,11 +61,14 @@ getpaskha(s, year)
int year;
{
int offset;
+ extern struct fixs npaskha;
if (strncasecmp(s, PASKHA, PASKHALEN) == 0)
s += PASKHALEN;
- else if (strncasecmp(s, PASKHA1, PASKHALEN1) == 0)
- s += PASKHALEN1;
+ else if ( npaskha.name != NULL
+ && strncasecmp(s, npaskha.name, npaskha.len) == 0
+ )
+ s += npaskha.len;
else
return 0;
OpenPOWER on IntegriCloud