2 * Copyright (c) 1989, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 4. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
42 const char *fdays[] = {
43 "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday",
47 const char *days[] = {
48 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", NULL,
51 const char *fmonths[] = {
52 "January", "February", "March", "April", "May", "June", "Juli",
53 "August", "September", "October", "November", "December", NULL,
56 const char *months[] = {
57 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
58 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", NULL,
61 const char *sequences[] = {
62 "First", "Second", "Third", "Fourth", "Fifth", "Last"
65 struct fixs fndays[8]; /* full national days names */
66 struct fixs ndays[8]; /* short national days names */
67 struct fixs fnmonths[13]; /* full national months names */
68 struct fixs nmonths[13]; /* short national month names */
69 struct fixs nsequences[10]; /* national sequence names */
79 memset(&tm, 0, sizeof(struct tm));
80 for (i = 0; i < 7; i++) {
82 strftime(buf, sizeof(buf), "%a", &tm);
84 l > 0 && isspace((unsigned char)buf[l - 1]);
88 if (ndays[i].name != NULL)
90 if ((ndays[i].name = strdup(buf)) == NULL)
91 errx(1, "cannot allocate memory");
92 ndays[i].len = strlen(buf);
94 strftime(buf, sizeof(buf), "%A", &tm);
96 l > 0 && isspace((unsigned char)buf[l - 1]);
100 if (fndays[i].name != NULL)
101 free(fndays[i].name);
102 if ((fndays[i].name = strdup(buf)) == NULL)
103 errx(1, "cannot allocate memory");
104 fndays[i].len = strlen(buf);
107 memset(&tm, 0, sizeof(struct tm));
108 for (i = 0; i < 12; i++) {
110 strftime(buf, sizeof(buf), "%b", &tm);
111 for (l = strlen(buf);
112 l > 0 && isspace((unsigned char)buf[l - 1]);
116 if (nmonths[i].name != NULL)
117 free(nmonths[i].name);
118 if ((nmonths[i].name = strdup(buf)) == NULL)
119 errx(1, "cannot allocate memory");
120 nmonths[i].len = strlen(buf);
122 strftime(buf, sizeof(buf), "%B", &tm);
123 for (l = strlen(buf);
124 l > 0 && isspace((unsigned char)buf[l - 1]);
128 if (fnmonths[i].name != NULL)
129 free(fnmonths[i].name);
130 if ((fnmonths[i].name = strdup(buf)) == NULL)
131 errx(1, "cannot allocate memory");
132 fnmonths[i].len = strlen(buf);
137 setnsequences(char *seq)
143 for (i = 0; i < 5; i++) {
144 nsequences[i].name = p;
145 if ((p = strchr(p, ' ')) == NULL) {
146 /* Oh oh there is something wrong. Erase! Erase! */
147 for (i = 0; i < 5; i++) {
148 nsequences[i].name = NULL;
149 nsequences[i].len = 0;
156 nsequences[i].name = p;
158 for (i = 0; i < 5; i++) {
159 nsequences[i].name = strdup(nsequences[i].name);
160 nsequences[i].len = nsequences[i + 1].name - nsequences[i].name;
162 nsequences[i].name = strdup(nsequences[i].name);
163 nsequences[i].len = strlen(nsequences[i].name);