1 /* SPDX-License-Identifier: BSD-2-Clause */
28 xfrm_utf (const wchar_t *ws
, int slist
)
30 static char xfrm
[4096];
36 if (*ws
< 0x80 && (!wconst
|| !wcschr (L
"aAbBcCdDeEfF", *ws
)))
43 p
+= sprintf (p
, "\\x%04lx", *ws
);
51 p
+= sprintf (p
, ";");
59 xfrm_slist (const char *slist
)
61 static wchar_t wxfrm
[4096], *wp
;
67 size_t len
= mbstowcs (wp
, slist
, wxfrm
+ 4096 - wp
) + 1;
68 slist
+= strlen (slist
) + 1;
72 xfrm
= xfrm_utf (wxfrm
, 1);
77 ret
= (char *) malloc (p
- xfrm
);
78 memcpy (ret
, xfrm
, p
- xfrm
);
83 read_locale_era (char *name
)
85 char *nl
, *nlera
, *altd
;
89 strcpy (locale
, name
);
90 nl
= strchr (locale
, '@');
92 stpcpy (stpcpy (nl
, ".utf8"), strchr (name
, '@'));
94 strcat (locale
, ".utf8");
95 printf ("%s\n", locale
);
96 setlocale (LC_ALL
, locale
);
98 nlera
= nl_langinfo (ERA
);
99 altd
= nl_langinfo (ALT_DIGITS
);
101 if (!*nlera
&& !*altd
)
104 strcpy (era
[ecnt
].locale
, name
);
105 nl
= nl_langinfo (_DATE_FMT
);
106 mbstowcs (nlbuf
, nl
, 256);
107 era
[ecnt
].date_fmt
= strdup (xfrm_utf (nlbuf
, 0));
108 nl
= nl_langinfo (D_FMT
);
109 mbstowcs (nlbuf
, nl
, 256);
110 era
[ecnt
].d_fmt
= strdup (xfrm_utf (nlbuf
, 0));
111 nl
= nl_langinfo (D_T_FMT
);
112 mbstowcs (nlbuf
, nl
, 256);
113 era
[ecnt
].d_t_fmt
= strdup (xfrm_utf (nlbuf
, 0));
114 nl
= nl_langinfo (T_FMT
);
115 mbstowcs (nlbuf
, nl
, 256);
116 era
[ecnt
].t_fmt
= strdup (xfrm_utf (nlbuf
, 0));
117 nl
= nl_langinfo (T_FMT_AMPM
);
118 mbstowcs (nlbuf
, nl
, 256);
119 era
[ecnt
].t_fmt_ampm
= strdup (xfrm_utf (nlbuf
, 0));
121 era
[ecnt
].era
= *nlera
? xfrm_slist (nlera
) : "\0";
122 era
[ecnt
].alt_digits
= *altd
? xfrm_slist (altd
) : "\0";
124 nl
= nl_langinfo (ERA_D_FMT
);
125 mbstowcs (nlbuf
, nl
, 256);
126 era
[ecnt
].era_d_fmt
= strdup (xfrm_utf (nlbuf
, 0));
127 nl
= nl_langinfo (ERA_D_T_FMT
);
128 mbstowcs (nlbuf
, nl
, 256);
129 era
[ecnt
].era_d_t_fmt
= strdup (xfrm_utf (nlbuf
, 0));
130 nl
= nl_langinfo (ERA_T_FMT
);
131 mbstowcs (nlbuf
, nl
, 256);
132 era
[ecnt
].era_t_fmt
= strdup (xfrm_utf (nlbuf
, 0));
133 /* Serbian locale rename weirdness */
134 if (!strncmp (era
[ecnt
].locale
, "sr_RS", 5))
136 /* Create additional equivalent entries for the old locale sr_SP. */
138 memcpy (&era
[ecnt
], &era
[ecnt
- 1], sizeof era
[ecnt
]);
139 era
[ecnt
].locale
[3] = 'S';
140 era
[ecnt
].locale
[4] = 'P';
141 /* Create additional equivalent entry for sr_ME@latin missing in Linux. */
142 if (!strcmp (era
[ecnt
].locale
, "sr_SP@latin"))
145 memcpy (&era
[ecnt
], &era
[ecnt
- 1], sizeof era
[ecnt
]);
146 era
[ecnt
].locale
[3] = 'M';
147 era
[ecnt
].locale
[4] = 'E';
154 locale_cmp (const void *a
, const void *b
)
156 struct lc_era_t
*la
= (struct lc_era_t
*) a
;
157 struct lc_era_t
*lb
= (struct lc_era_t
*) b
;
158 return strcmp (la
->locale
, lb
->locale
);
164 FILE *fp
= fopen ("lc_era.h", "w");
165 FILE *pp
= popen ("rpm -q glibc", "r");
172 fgets (vers
, 64, pp
);
174 if (strchr (vers
, '\n'))
175 *strchr (vers
, '\n') = '\0';
178 strftime (tstr
, 64, "%F", tm
);
180 "/* This struct of LC_TIME ERA data has been generated by fetching locale\n"
181 " data from a Linux system using %s on %s. */\n"
185 " const char *locale;\n"
186 " const wchar_t *date_fmt;\n"
187 " const wchar_t *d_fmt;\n"
188 " const wchar_t *d_t_fmt;\n"
189 " const wchar_t *t_fmt;\n"
190 " const wchar_t *t_fmt_ampm;\n"
191 " const wchar_t *era;\n"
192 " const wchar_t *era_d_fmt;\n"
193 " const wchar_t *era_d_t_fmt;\n"
194 " const wchar_t *era_t_fmt;\n"
195 " const wchar_t *alt_digits;\n"
198 "static struct lc_era_t lc_era[] =\n"
201 qsort (era
, ecnt
, sizeof (struct lc_era_t
), locale_cmp
);
202 for (i
= 0; i
< ecnt
; ++i
)
203 fprintf (fp
, " { \"%s\", L\"%s\", L\"%s\", L\"%s\", L\"%s\", L\"%s\", "
204 "L\"%s\", L\"%s\", L\"%s\", L\"%s\", L\"%s\" },\n",
205 era
[i
].locale
, era
[i
].date_fmt
,
206 era
[i
].d_fmt
, era
[i
].d_t_fmt
,
207 era
[i
].t_fmt
, era
[i
].t_fmt_ampm
,
208 era
[i
].era
, era
[i
].era_d_fmt
,
209 era
[i
].era_d_t_fmt
, era
[i
].era_t_fmt
,
221 pp
= popen ("locale -a | grep -a '_' | grep -F -v .", "r");
224 perror ("popen failed");
227 while (fgets (name
, 32, pp
))
229 c
= strchr (name
, '\n');
232 read_locale_era (name
);