svn commit: r204350 - user/edwin/calendar

Edwin Groothuis edwin at FreeBSD.org
Fri Feb 26 07:22:12 UTC 2010


Author: edwin
Date: Fri Feb 26 07:22:07 2010
New Revision: 204350
URL: http://svn.freebsd.org/changeset/base/204350

Log:
  Be able to handle national versions of first, second, third, fourth,
  fifth and last.

Modified:
  user/edwin/calendar/calendar.1
  user/edwin/calendar/calendar.h
  user/edwin/calendar/io.c
  user/edwin/calendar/locale.c
  user/edwin/calendar/parsedata.c

Modified: user/edwin/calendar/calendar.1
==============================================================================
--- user/edwin/calendar/calendar.1	Fri Feb 26 07:22:01 2010	(r204349)
+++ user/edwin/calendar/calendar.1	Fri Feb 26 07:22:07 2010	(r204350)
@@ -112,6 +112,10 @@ To handle calendars in your national cod
 .Dq LANG=<locale_name>
 in the calendar file as early as possible.
 .Pp
+To handle the local name of sequences, you can specify them as:
+.Dq SEQUENCE=<first> <second> <third> <fourth> <fifth> <last>
+in the calendar file as early as possible.
+.Pp
 The names of the following special days are recognized:
 .Bl -tag -width 123456789012345 -compact
 .It Easter

Modified: user/edwin/calendar/calendar.h
==============================================================================
--- user/edwin/calendar/calendar.h	Fri Feb 26 07:22:01 2010	(r204349)
+++ user/edwin/calendar/calendar.h	Fri Feb 26 07:22:07 2010	(r204350)
@@ -146,16 +146,19 @@ struct fixs {
 	int	len;
 };
 
+extern const char *days[];
+extern const char *fdays[];
+extern const char *fmonths[];
+extern const char *months[];
+extern const char *sequences[];
 extern struct fixs fndays[8];		/* full national days names */
-extern struct fixs ndays[8];		/* short national days names */
 extern struct fixs fnmonths[13];	/* full national months names */
+extern struct fixs ndays[8];		/* short national days names */
 extern struct fixs nmonths[13];		/* short national month names */
-extern const char *months[];
-extern const char *fmonths[];
-extern const char *days[];
-extern const char *fdays[];
+extern struct fixs nsequences[10];
 
 void	setnnames(void);
+void	setnsequences(char *);
 
 /* day.c */
 extern const struct tm tm0;

Modified: user/edwin/calendar/io.c
==============================================================================
--- user/edwin/calendar/io.c	Fri Feb 26 07:22:01 2010	(r204349)
+++ user/edwin/calendar/io.c	Fri Feb 26 07:22:07 2010	(r204350)
@@ -152,6 +152,10 @@ cal(void)
 		REPLACE("SepEquinox=", 11, nsepequinox);
 		REPLACE("JunSolstice=", 12, njunsolstice);
 		REPLACE("DecSolstice=", 12, ndecsolstice);
+		if (strncmp(buf, "SEQUENCE=", 9) == 0) {
+			setnsequences(buf + 9);
+			continue;
+		}
 
 		/*
 		 * If the line starts with a tab, the data has to be

Modified: user/edwin/calendar/locale.c
==============================================================================
--- user/edwin/calendar/locale.c	Fri Feb 26 07:22:01 2010	(r204349)
+++ user/edwin/calendar/locale.c	Fri Feb 26 07:22:07 2010	(r204350)
@@ -62,10 +62,15 @@ const char *months[] = {
 	"Jul", "Aug", "Sep", "Oct", "Nov", "Dec", NULL,
 };
 
+const char *sequences[] = {
+	"First", "Second", "Third", "Fourth", "Fifth", "Last"
+};
+
 struct fixs fndays[8];		/* full national days names */
 struct fixs ndays[8];		/* short national days names */
 struct fixs fnmonths[13];	/* full national months names */
 struct fixs nmonths[13];	/* short national month names */
+struct fixs nsequences[10];	/* national sequence names */
 
 
 void
@@ -129,3 +134,35 @@ setnnames(void)
 		fnmonths[i].len = strlen(buf);
 	}
 }
+
+void
+setnsequences(char *seq)
+{
+	int i;
+	char *p;
+
+	p = seq;
+	for (i = 0; i < 5; i++) {
+		nsequences[i].name = p;
+		if ((p = strchr(p, ' ')) == NULL) {
+			for (i = 0; i < 5; i++) {
+				nsequences[i].name = NULL;
+				nsequences[i].len = -1;
+				return;
+			}
+			
+		}
+		*p = '\0';
+		p++;
+	}
+	nsequences[i].name = p;
+
+	for (i = 0; i < 5; i++) {
+		nsequences[i].name = strdup(nsequences[i].name);
+		nsequences[i].len = nsequences[i + 1].name - nsequences[i].name;
+	}
+	nsequences[i].name = strdup(nsequences[i].name);
+	nsequences[i].len = strlen(nsequences[i].name);
+
+	return;
+}

Modified: user/edwin/calendar/parsedata.c
==============================================================================
--- user/edwin/calendar/parsedata.c	Fri Feb 26 07:22:01 2010	(r204349)
+++ user/edwin/calendar/parsedata.c	Fri Feb 26 07:22:07 2010	(r204350)
@@ -880,18 +880,26 @@ isonlydigits(char *s, int nostar)
 static int
 indextooffset(char *s)
 {
-	if (strcasecmp(s, "first") == 0)
-		return (1);
-	if (strcasecmp(s, "second") == 0)
-		return (2);
-	if (strcasecmp(s, "third") == 0)
-		return (3);
-	if (strcasecmp(s, "fourth") == 0)
-		return (4);
-	if (strcasecmp(s, "fifth") == 0)
-		return (5);
-	if (strcasecmp(s, "last") == 0)
-		return (-1);
+	int i;
+	struct fixs *n;
+
+	for (i = 0; i < 6; i++) {
+		if (strcasecmp(s, sequences[i]) == 0) {
+			if (i == 5)
+				return (-1);
+			return (i + 1);
+		}
+	}
+	for (i = 0; i < 6; i++) {
+		n = nsequences + i;
+		if (n->len == -1)
+			continue;
+		if (strncasecmp(s, n->name, n->len) == 0) {
+			if (i == 5)
+				return (-1);
+			return (i + 1);
+		}
+	}
 	return (0);
 }
 


More information about the svn-src-user mailing list