1 /* Copyright (C) 1998-2017 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 <http://www.gnu.org/licenses/>. */
31 #include "localedef.h"
32 #include "localeinfo.h"
36 /* The real definition of the struct for the LC_IDENTIFICATION locale. */
37 struct locale_identification_t
47 const char *territory
;
49 const char *application
;
50 const char *abbreviation
;
53 const char *category
[__LC_LAST
];
57 static const char *category_name
[__LC_LAST
] =
59 [LC_CTYPE
] = "LC_CTYPE",
60 [LC_NUMERIC
] = "LC_NUMERIC",
61 [LC_TIME
] = "LC_TIME",
62 [LC_COLLATE
] = "LC_COLLATE",
63 [LC_MONETARY
] = "LC_MONETARY",
64 [LC_MESSAGES
] = "LC_MESSAGES",
66 [LC_PAPER
] = "LC_PAPER",
67 [LC_NAME
] = "LC_NAME",
68 [LC_ADDRESS
] = "LC_ADDRESS",
69 [LC_TELEPHONE
] = "LC_TELEPHONE",
70 [LC_MEASUREMENT
] = "LC_MEASUREMENT",
71 [LC_IDENTIFICATION
] = "LC_IDENTIFICATION"
76 identification_startup (struct linereader
*lr
, struct localedef_t
*locale
,
81 locale
->categories
[LC_IDENTIFICATION
].identification
=
82 (struct locale_identification_t
*)
83 xcalloc (1, sizeof (struct locale_identification_t
));
85 locale
->categories
[LC_IDENTIFICATION
].identification
->category
[LC_ALL
] =
91 lr
->translate_strings
= 1;
92 lr
->return_widestr
= 0;
98 identification_finish (struct localedef_t
*locale
,
99 const struct charmap_t
*charmap
)
101 struct locale_identification_t
*identification
102 = locale
->categories
[LC_IDENTIFICATION
].identification
;
106 /* Now resolve copying and also handle completely missing definitions. */
107 if (identification
== NULL
)
109 /* First see whether we were supposed to copy. If yes, find the
110 actual definition. */
111 if (locale
->copy_name
[LC_IDENTIFICATION
] != NULL
)
113 /* Find the copying locale. This has to happen transitively since
114 the locale we are copying from might also copying another one. */
115 struct localedef_t
*from
= locale
;
118 from
= find_locale (LC_IDENTIFICATION
,
119 from
->copy_name
[LC_IDENTIFICATION
],
120 from
->repertoire_name
, charmap
);
121 while (from
->categories
[LC_IDENTIFICATION
].identification
== NULL
122 && from
->copy_name
[LC_IDENTIFICATION
] != NULL
);
124 identification
= locale
->categories
[LC_IDENTIFICATION
].identification
125 = from
->categories
[LC_IDENTIFICATION
].identification
;
128 /* If there is still no definition issue an warning and create an
130 if (identification
== NULL
)
133 WITH_CUR_LOCALE (error (0, 0, _("\
134 No definition for %s category found"), "LC_IDENTIFICATION"));
135 identification_startup (NULL
, locale
, 0);
137 = locale
->categories
[LC_IDENTIFICATION
].identification
;
142 #define TEST_ELEM(cat) \
143 if (identification->cat == NULL) \
145 if (verbose && ! nothing) \
146 WITH_CUR_LOCALE (error (0, 0, _("%s: field `%s' not defined"), \
147 "LC_IDENTIFICATION", #cat)); \
148 identification->cat = ""; \
158 TEST_ELEM (language
);
159 TEST_ELEM (territory
);
160 TEST_ELEM (audience
);
161 TEST_ELEM (application
);
162 TEST_ELEM (abbreviation
);
163 TEST_ELEM (revision
);
166 for (num
= 0; num
< __LC_LAST
; ++num
)
168 /* We don't accept/parse this category, so skip it early. */
172 if (identification
->category
[num
] == NULL
)
174 if (verbose
&& ! nothing
)
175 WITH_CUR_LOCALE (error (0, 0, _("\
176 %s: no identification for category `%s'"),
177 "LC_IDENTIFICATION", category_name
[num
]));
178 identification
->category
[num
] = "";
182 /* Only list the standards we care about. This is based on the
183 ISO 30112 WD10 [2014] standard which supersedes all previous
184 revisions of the ISO 14652 standard. */
185 static const char * const standards
[] =
192 bool matched
= false;
194 for (i
= 0; i
< sizeof (standards
) / sizeof (standards
[0]); ++i
)
195 if (strcmp (identification
->category
[num
], standards
[i
]) == 0)
199 WITH_CUR_LOCALE (error (0, 0, _("\
200 %s: unknown standard `%s' for category `%s'"),
202 identification
->category
[num
],
203 category_name
[num
]));
210 identification_output (struct localedef_t
*locale
,
211 const struct charmap_t
*charmap
,
212 const char *output_path
)
214 struct locale_identification_t
*identification
215 = locale
->categories
[LC_IDENTIFICATION
].identification
;
216 struct locale_file file
;
219 init_locale_data (&file
, _NL_ITEM_INDEX (_NL_NUM_LC_IDENTIFICATION
));
220 add_locale_string (&file
, identification
->title
);
221 add_locale_string (&file
, identification
->source
);
222 add_locale_string (&file
, identification
->address
);
223 add_locale_string (&file
, identification
->contact
);
224 add_locale_string (&file
, identification
->email
);
225 add_locale_string (&file
, identification
->tel
);
226 add_locale_string (&file
, identification
->fax
);
227 add_locale_string (&file
, identification
->language
);
228 add_locale_string (&file
, identification
->territory
);
229 add_locale_string (&file
, identification
->audience
);
230 add_locale_string (&file
, identification
->application
);
231 add_locale_string (&file
, identification
->abbreviation
);
232 add_locale_string (&file
, identification
->revision
);
233 add_locale_string (&file
, identification
->date
);
234 start_locale_structure (&file
);
235 for (num
= 0; num
< __LC_LAST
; ++num
)
237 add_locale_string (&file
, identification
->category
[num
]);
238 end_locale_structure (&file
);
239 add_locale_string (&file
, charmap
->code_set_name
);
240 write_locale_data (output_path
, LC_IDENTIFICATION
, "LC_IDENTIFICATION",
245 /* The parser for the LC_IDENTIFICATION section of the locale definition. */
247 identification_read (struct linereader
*ldfile
, struct localedef_t
*result
,
248 const struct charmap_t
*charmap
, const char *repertoire_name
,
251 struct locale_identification_t
*identification
;
254 struct token
*cattok
;
258 /* The rest of the line containing `LC_IDENTIFICATION' must be free. */
259 lr_ignore_rest (ldfile
, 1);
263 now
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
266 while (nowtok
== tok_eol
);
268 /* If we see `copy' now we are almost done. */
269 if (nowtok
== tok_copy
)
271 handle_copy (ldfile
, charmap
, repertoire_name
, result
,
272 tok_lc_identification
, LC_IDENTIFICATION
,
273 "LC_IDENTIFICATION", ignore_content
);
277 /* Prepare the data structures. */
278 identification_startup (ldfile
, result
, ignore_content
);
279 identification
= result
->categories
[LC_IDENTIFICATION
].identification
;
283 /* Of course we don't proceed beyond the end of file. */
284 if (nowtok
== tok_eof
)
287 /* Ignore empty lines. */
288 if (nowtok
== tok_eol
)
290 now
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
297 #define STR_ELEM(cat) \
299 /* Ignore the rest of the line if we don't need the input of \
301 if (ignore_content) \
303 lr_ignore_rest (ldfile, 0); \
307 arg = lr_token (ldfile, charmap, result, NULL, verbose); \
308 if (arg->tok != tok_string) \
310 if (identification->cat != NULL) \
311 lr_error (ldfile, _("\
312 %s: field `%s' declared more than once"), "LC_IDENTIFICATION", #cat); \
313 else if (!ignore_content && arg->val.str.startmb == NULL) \
315 lr_error (ldfile, _("\
316 %s: unknown character in field `%s'"), "LC_IDENTIFICATION", #cat); \
317 identification->cat = ""; \
319 else if (!ignore_content) \
320 identification->cat = arg->val.str.startmb; \
331 STR_ELEM (territory
);
333 STR_ELEM (application
);
334 STR_ELEM (abbreviation
);
339 /* Ignore the rest of the line if we don't need the input of
343 lr_ignore_rest (ldfile
, 0);
347 /* We expect two operands. */
348 arg
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
349 if (arg
->tok
!= tok_string
&& arg
->tok
!= tok_ident
)
351 /* Next is a semicolon. */
352 cattok
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
353 if (cattok
->tok
!= tok_semicolon
)
355 /* Now a LC_xxx identifier. */
356 cattok
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
359 #define CATEGORY(lname, uname) \
360 case tok_lc_##lname: \
361 category = LC_##uname; \
364 CATEGORY (identification
, IDENTIFICATION
);
365 CATEGORY (ctype
, CTYPE
);
366 CATEGORY (collate
, COLLATE
);
367 CATEGORY (time
, TIME
);
368 CATEGORY (numeric
, NUMERIC
);
369 CATEGORY (monetary
, MONETARY
);
370 CATEGORY (messages
, MESSAGES
);
371 CATEGORY (paper
, PAPER
);
372 CATEGORY (name
, NAME
);
373 CATEGORY (address
, ADDRESS
);
374 CATEGORY (telephone
, TELEPHONE
);
375 CATEGORY (measurement
, MEASUREMENT
);
380 if (identification
->category
[category
] != NULL
)
382 lr_error (ldfile
, _("\
383 %s: duplicate category version definition"), "LC_IDENTIFICATION");
384 free (arg
->val
.str
.startmb
);
387 identification
->category
[category
] = arg
->val
.str
.startmb
;
391 /* Next we assume `LC_IDENTIFICATION'. */
392 arg
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
393 if (arg
->tok
== tok_eof
)
395 if (arg
->tok
== tok_eol
)
396 lr_error (ldfile
, _("%s: incomplete `END' line"),
397 "LC_IDENTIFICATION");
398 else if (arg
->tok
!= tok_lc_identification
)
399 lr_error (ldfile
, _("\
400 %1$s: definition does not end with `END %1$s'"), "LC_IDENTIFICATION");
401 lr_ignore_rest (ldfile
, arg
->tok
== tok_lc_identification
);
406 SYNTAX_ERROR (_("%s: syntax error"), "LC_IDENTIFICATION");
409 /* Prepare for the next round. */
410 now
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
414 /* When we come here we reached the end of the file. */
415 lr_error (ldfile
, _("%s: premature end of file"), "LC_IDENTIFICATION");