1 /* Copyright (C) 1998-2021 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, see <https://www.gnu.org/licenses/>. */
30 #include "localedef.h"
31 #include "localeinfo.h"
35 /* The real definition of the struct for the LC_IDENTIFICATION locale. */
36 struct locale_identification_t
46 const char *territory
;
48 const char *application
;
49 const char *abbreviation
;
52 const char *category
[__LC_LAST
];
56 static const char *category_name
[__LC_LAST
] =
58 [LC_CTYPE
] = "LC_CTYPE",
59 [LC_NUMERIC
] = "LC_NUMERIC",
60 [LC_TIME
] = "LC_TIME",
61 [LC_COLLATE
] = "LC_COLLATE",
62 [LC_MONETARY
] = "LC_MONETARY",
63 [LC_MESSAGES
] = "LC_MESSAGES",
65 [LC_PAPER
] = "LC_PAPER",
66 [LC_NAME
] = "LC_NAME",
67 [LC_ADDRESS
] = "LC_ADDRESS",
68 [LC_TELEPHONE
] = "LC_TELEPHONE",
69 [LC_MEASUREMENT
] = "LC_MEASUREMENT",
70 [LC_IDENTIFICATION
] = "LC_IDENTIFICATION"
75 identification_startup (struct linereader
*lr
, struct localedef_t
*locale
,
80 locale
->categories
[LC_IDENTIFICATION
].identification
=
81 (struct locale_identification_t
*)
82 xcalloc (1, sizeof (struct locale_identification_t
));
84 locale
->categories
[LC_IDENTIFICATION
].identification
->category
[LC_ALL
] =
90 lr
->translate_strings
= 1;
91 lr
->return_widestr
= 0;
97 identification_finish (struct localedef_t
*locale
,
98 const struct charmap_t
*charmap
)
100 struct locale_identification_t
*identification
101 = locale
->categories
[LC_IDENTIFICATION
].identification
;
105 /* Now resolve copying and also handle completely missing definitions. */
106 if (identification
== NULL
)
108 /* First see whether we were supposed to copy. If yes, find the
109 actual definition. */
110 if (locale
->copy_name
[LC_IDENTIFICATION
] != NULL
)
112 /* Find the copying locale. This has to happen transitively since
113 the locale we are copying from might also copying another one. */
114 struct localedef_t
*from
= locale
;
117 from
= find_locale (LC_IDENTIFICATION
,
118 from
->copy_name
[LC_IDENTIFICATION
],
119 from
->repertoire_name
, charmap
);
120 while (from
->categories
[LC_IDENTIFICATION
].identification
== NULL
121 && from
->copy_name
[LC_IDENTIFICATION
] != NULL
);
123 identification
= locale
->categories
[LC_IDENTIFICATION
].identification
124 = from
->categories
[LC_IDENTIFICATION
].identification
;
127 /* If there is still no definition issue an warning and create an
129 if (identification
== NULL
)
132 No definition for %s category found"), "LC_IDENTIFICATION");
133 identification_startup (NULL
, locale
, 0);
135 = locale
->categories
[LC_IDENTIFICATION
].identification
;
140 #define TEST_ELEM(cat) \
141 if (identification->cat == NULL) \
143 if (verbose && ! nothing) \
144 record_warning (_("%s: field `%s' not defined"), "LC_IDENTIFICATION", \
146 identification->cat = ""; \
156 TEST_ELEM (language
);
157 TEST_ELEM (territory
);
158 TEST_ELEM (audience
);
159 TEST_ELEM (application
);
160 TEST_ELEM (abbreviation
);
161 TEST_ELEM (revision
);
164 for (num
= 0; num
< __LC_LAST
; ++num
)
166 /* We don't accept/parse this category, so skip it early. */
170 if (identification
->category
[num
] == NULL
)
172 if (verbose
&& ! nothing
)
174 %s: no identification for category `%s'"), "LC_IDENTIFICATION",
176 identification
->category
[num
] = "";
180 /* Only list the standards we care about. This is based on the
181 ISO 30112 WD10 [2014] standard which supersedes all previous
182 revisions of the ISO 14652 standard. */
183 static const char * const standards
[] =
190 bool matched
= false;
192 for (i
= 0; i
< sizeof (standards
) / sizeof (standards
[0]); ++i
)
193 if (strcmp (identification
->category
[num
], standards
[i
]) == 0)
197 record_error (0, 0, _("\
198 %s: unknown standard `%s' for category `%s'"),
200 identification
->category
[num
],
208 identification_output (struct localedef_t
*locale
,
209 const struct charmap_t
*charmap
,
210 const char *output_path
)
212 struct locale_identification_t
*identification
213 = locale
->categories
[LC_IDENTIFICATION
].identification
;
214 struct locale_file file
;
217 init_locale_data (&file
, _NL_ITEM_INDEX (_NL_NUM_LC_IDENTIFICATION
));
218 add_locale_string (&file
, identification
->title
);
219 add_locale_string (&file
, identification
->source
);
220 add_locale_string (&file
, identification
->address
);
221 add_locale_string (&file
, identification
->contact
);
222 add_locale_string (&file
, identification
->email
);
223 add_locale_string (&file
, identification
->tel
);
224 add_locale_string (&file
, identification
->fax
);
225 add_locale_string (&file
, identification
->language
);
226 add_locale_string (&file
, identification
->territory
);
227 add_locale_string (&file
, identification
->audience
);
228 add_locale_string (&file
, identification
->application
);
229 add_locale_string (&file
, identification
->abbreviation
);
230 add_locale_string (&file
, identification
->revision
);
231 add_locale_string (&file
, identification
->date
);
232 start_locale_structure (&file
);
233 for (num
= 0; num
< __LC_LAST
; ++num
)
235 add_locale_string (&file
, identification
->category
[num
]);
236 end_locale_structure (&file
);
237 add_locale_string (&file
, charmap
->code_set_name
);
238 write_locale_data (output_path
, LC_IDENTIFICATION
, "LC_IDENTIFICATION",
243 /* The parser for the LC_IDENTIFICATION section of the locale definition. */
245 identification_read (struct linereader
*ldfile
, struct localedef_t
*result
,
246 const struct charmap_t
*charmap
, const char *repertoire_name
,
249 struct locale_identification_t
*identification
;
252 struct token
*cattok
;
256 /* The rest of the line containing `LC_IDENTIFICATION' must be free. */
257 lr_ignore_rest (ldfile
, 1);
261 now
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
264 while (nowtok
== tok_eol
);
266 /* If we see `copy' now we are almost done. */
267 if (nowtok
== tok_copy
)
269 handle_copy (ldfile
, charmap
, repertoire_name
, result
,
270 tok_lc_identification
, LC_IDENTIFICATION
,
271 "LC_IDENTIFICATION", ignore_content
);
275 /* Prepare the data structures. */
276 identification_startup (ldfile
, result
, ignore_content
);
277 identification
= result
->categories
[LC_IDENTIFICATION
].identification
;
281 /* Of course we don't proceed beyond the end of file. */
282 if (nowtok
== tok_eof
)
285 /* Ignore empty lines. */
286 if (nowtok
== tok_eol
)
288 now
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
295 #define STR_ELEM(cat) \
297 /* Ignore the rest of the line if we don't need the input of \
299 if (ignore_content) \
301 lr_ignore_rest (ldfile, 0); \
305 arg = lr_token (ldfile, charmap, result, NULL, verbose); \
306 if (arg->tok != tok_string) \
308 if (identification->cat != NULL) \
309 lr_error (ldfile, _("\
310 %s: field `%s' declared more than once"), "LC_IDENTIFICATION", #cat); \
311 else if (!ignore_content && arg->val.str.startmb == NULL) \
313 lr_error (ldfile, _("\
314 %s: unknown character in field `%s'"), "LC_IDENTIFICATION", #cat); \
315 identification->cat = ""; \
317 else if (!ignore_content) \
318 identification->cat = arg->val.str.startmb; \
329 STR_ELEM (territory
);
331 STR_ELEM (application
);
332 STR_ELEM (abbreviation
);
337 /* Ignore the rest of the line if we don't need the input of
341 lr_ignore_rest (ldfile
, 0);
345 /* We expect two operands. */
346 arg
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
347 if (arg
->tok
!= tok_string
&& arg
->tok
!= tok_ident
)
349 /* Next is a semicolon. */
350 cattok
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
351 if (cattok
->tok
!= tok_semicolon
)
353 /* Now a LC_xxx identifier. */
354 cattok
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
357 #define CATEGORY(lname, uname) \
358 case tok_lc_##lname: \
359 category = LC_##uname; \
362 CATEGORY (identification
, IDENTIFICATION
);
363 CATEGORY (ctype
, CTYPE
);
364 CATEGORY (collate
, COLLATE
);
365 CATEGORY (time
, TIME
);
366 CATEGORY (numeric
, NUMERIC
);
367 CATEGORY (monetary
, MONETARY
);
368 CATEGORY (messages
, MESSAGES
);
369 CATEGORY (paper
, PAPER
);
370 CATEGORY (name
, NAME
);
371 CATEGORY (address
, ADDRESS
);
372 CATEGORY (telephone
, TELEPHONE
);
373 CATEGORY (measurement
, MEASUREMENT
);
378 if (identification
->category
[category
] != NULL
)
380 lr_error (ldfile
, _("\
381 %s: duplicate category version definition"), "LC_IDENTIFICATION");
382 free (arg
->val
.str
.startmb
);
385 identification
->category
[category
] = arg
->val
.str
.startmb
;
389 /* Next we assume `LC_IDENTIFICATION'. */
390 arg
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
391 if (arg
->tok
== tok_eof
)
393 if (arg
->tok
== tok_eol
)
394 lr_error (ldfile
, _("%s: incomplete `END' line"),
395 "LC_IDENTIFICATION");
396 else if (arg
->tok
!= tok_lc_identification
)
397 lr_error (ldfile
, _("\
398 %1$s: definition does not end with `END %1$s'"), "LC_IDENTIFICATION");
399 lr_ignore_rest (ldfile
, arg
->tok
== tok_lc_identification
);
404 SYNTAX_ERROR (_("%s: syntax error"), "LC_IDENTIFICATION");
407 /* Prepare for the next round. */
408 now
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
412 /* When we come here we reached the end of the file. */
413 lr_error (ldfile
, _("%s: premature end of file"), "LC_IDENTIFICATION");