2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 1989, 1993, 1994
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <sys/cdefs.h>
33 __FBSDID("$FreeBSD$");
44 const char *fdays[] = {
45 "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday",
49 const char *days[] = {
50 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", NULL,
53 const char *fmonths[] = {
54 "January", "February", "March", "April", "May", "June", "Juli",
55 "August", "September", "October", "November", "December", NULL,
58 const char *months[] = {
59 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
60 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", NULL,
63 const char *sequences[] = {
64 "First", "Second", "Third", "Fourth", "Fifth", "Last"
67 struct fixs fndays[8]; /* full national days names */
68 struct fixs ndays[8]; /* short national days names */
69 struct fixs fnmonths[13]; /* full national months names */
70 struct fixs nmonths[13]; /* short national month names */
71 struct fixs nsequences[10]; /* national sequence names */
81 memset(&tm, 0, sizeof(struct tm));
82 for (i = 0; i < 7; i++) {
84 strftime(buf, sizeof(buf), "%a", &tm);
86 l > 0 && isspace((unsigned char)buf[l - 1]);
90 if (ndays[i].name != NULL)
92 if ((ndays[i].name = strdup(buf)) == NULL)
93 errx(1, "cannot allocate memory");
94 ndays[i].len = strlen(buf);
96 strftime(buf, sizeof(buf), "%A", &tm);
98 l > 0 && isspace((unsigned char)buf[l - 1]);
102 if (fndays[i].name != NULL)
103 free(fndays[i].name);
104 if ((fndays[i].name = strdup(buf)) == NULL)
105 errx(1, "cannot allocate memory");
106 fndays[i].len = strlen(buf);
109 memset(&tm, 0, sizeof(struct tm));
110 for (i = 0; i < 12; i++) {
112 strftime(buf, sizeof(buf), "%b", &tm);
113 for (l = strlen(buf);
114 l > 0 && isspace((unsigned char)buf[l - 1]);
118 if (nmonths[i].name != NULL)
119 free(nmonths[i].name);
120 if ((nmonths[i].name = strdup(buf)) == NULL)
121 errx(1, "cannot allocate memory");
122 nmonths[i].len = strlen(buf);
124 strftime(buf, sizeof(buf), "%B", &tm);
125 for (l = strlen(buf);
126 l > 0 && isspace((unsigned char)buf[l - 1]);
130 if (fnmonths[i].name != NULL)
131 free(fnmonths[i].name);
132 if ((fnmonths[i].name = strdup(buf)) == NULL)
133 errx(1, "cannot allocate memory");
134 fnmonths[i].len = strlen(buf);
139 setnsequences(char *seq)
145 for (i = 0; i < 5; i++) {
146 nsequences[i].name = p;
147 if ((p = strchr(p, ' ')) == NULL) {
148 /* Oh oh there is something wrong. Erase! Erase! */
149 for (i = 0; i < 5; i++) {
150 nsequences[i].name = NULL;
151 nsequences[i].len = 0;
158 nsequences[i].name = p;
160 for (i = 0; i < 5; i++) {
161 nsequences[i].name = strdup(nsequences[i].name);
162 nsequences[i].len = nsequences[i + 1].name - nsequences[i].name;
164 nsequences[i].name = strdup(nsequences[i].name);
165 nsequences[i].len = strlen(nsequences[i].name);