1 /* Copyright (C) 1998,1999,2000,2001,2002,2005 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/>. */
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 WITH_CUR_LOCALE (error (0, 0, _("\
133 No definition for %s category found"), "LC_IDENTIFICATION"));
134 identification_startup (NULL
, locale
, 0);
136 = locale
->categories
[LC_IDENTIFICATION
].identification
;
141 #define TEST_ELEM(cat) \
142 if (identification->cat == NULL) \
144 if (verbose && ! nothing) \
145 WITH_CUR_LOCALE (error (0, 0, _("%s: field `%s' not defined"), \
146 "LC_IDENTIFICATION", #cat)); \
147 identification->cat = ""; \
157 TEST_ELEM (language
);
158 TEST_ELEM (territory
);
159 TEST_ELEM (audience
);
160 TEST_ELEM (application
);
161 TEST_ELEM (abbreviation
);
162 TEST_ELEM (revision
);
165 for (num
= 0; num
< __LC_LAST
; ++num
)
166 if (num
!= LC_ALL
&& identification
->category
[num
] == NULL
)
168 if (verbose
&& ! nothing
)
169 WITH_CUR_LOCALE (error (0, 0, _("\
170 %s: no identification for category `%s'"),
171 "LC_IDENTIFICATION", category_name
[num
]));
172 identification
->category
[num
] = "";
178 identification_output (struct localedef_t
*locale
,
179 const struct charmap_t
*charmap
,
180 const char *output_path
)
182 struct locale_identification_t
*identification
183 = locale
->categories
[LC_IDENTIFICATION
].identification
;
184 struct iovec iov
[2 + _NL_ITEM_INDEX (_NL_NUM_LC_IDENTIFICATION
)
186 struct locale_file data
;
187 uint32_t idx
[_NL_ITEM_INDEX (_NL_NUM_LC_IDENTIFICATION
)];
192 data
.magic
= LIMAGIC (LC_IDENTIFICATION
);
193 data
.n
= _NL_ITEM_INDEX (_NL_NUM_LC_IDENTIFICATION
);
194 iov
[cnt
].iov_base
= (void *) &data
;
195 iov
[cnt
].iov_len
= sizeof (data
);
198 iov
[cnt
].iov_base
= (void *) idx
;
199 iov
[cnt
].iov_len
= sizeof (idx
);
202 idx
[cnt
- 2] = iov
[0].iov_len
+ iov
[1].iov_len
;
203 iov
[cnt
].iov_base
= (void *) identification
->title
;
204 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
207 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
208 iov
[cnt
].iov_base
= (void *) identification
->source
;
209 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
212 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
213 iov
[cnt
].iov_base
= (void *) identification
->address
;
214 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
217 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
218 iov
[cnt
].iov_base
= (void *) identification
->contact
;
219 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
222 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
223 iov
[cnt
].iov_base
= (void *) identification
->email
;
224 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
227 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
228 iov
[cnt
].iov_base
= (void *) identification
->tel
;
229 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
232 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
233 iov
[cnt
].iov_base
= (void *) identification
->fax
;
234 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
237 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
238 iov
[cnt
].iov_base
= (void *) identification
->language
;
239 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
242 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
243 iov
[cnt
].iov_base
= (void *) identification
->territory
;
244 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
247 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
248 iov
[cnt
].iov_base
= (void *) identification
->audience
;
249 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
252 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
253 iov
[cnt
].iov_base
= (void *) identification
->application
;
254 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
257 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
258 iov
[cnt
].iov_base
= (void *) identification
->abbreviation
;
259 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
262 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
263 iov
[cnt
].iov_base
= (void *) identification
->revision
;
264 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
267 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
268 iov
[cnt
].iov_base
= (void *) identification
->date
;
269 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
272 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
274 idx
[last_idx
] = idx
[cnt
- 2];
275 for (num
= 0; num
< __LC_LAST
; ++num
)
278 iov
[cnt
].iov_base
= (void *) identification
->category
[num
];
279 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
280 idx
[last_idx
] += iov
[cnt
].iov_len
;
284 assert (last_idx
== _NL_ITEM_INDEX (_NL_NUM_LC_IDENTIFICATION
) - 1);
285 iov
[cnt
].iov_base
= (void *) charmap
->code_set_name
;
286 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
289 assert (cnt
== (2 + _NL_ITEM_INDEX (_NL_NUM_LC_IDENTIFICATION
)
292 write_locale_data (output_path
, LC_IDENTIFICATION
, "LC_IDENTIFICATION", cnt
,
297 /* The parser for the LC_IDENTIFICATION section of the locale definition. */
299 identification_read (struct linereader
*ldfile
, struct localedef_t
*result
,
300 const struct charmap_t
*charmap
, const char *repertoire_name
,
303 struct locale_identification_t
*identification
;
306 struct token
*cattok
;
310 /* The rest of the line containing `LC_IDENTIFICATION' must be free. */
311 lr_ignore_rest (ldfile
, 1);
315 now
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
318 while (nowtok
== tok_eol
);
320 /* If we see `copy' now we are almost done. */
321 if (nowtok
== tok_copy
)
323 handle_copy (ldfile
, charmap
, repertoire_name
, result
,
324 tok_lc_identification
, LC_IDENTIFICATION
,
325 "LC_IDENTIFICATION", ignore_content
);
329 /* Prepare the data structures. */
330 identification_startup (ldfile
, result
, ignore_content
);
331 identification
= result
->categories
[LC_IDENTIFICATION
].identification
;
335 /* Of course we don't proceed beyond the end of file. */
336 if (nowtok
== tok_eof
)
339 /* Ignore empty lines. */
340 if (nowtok
== tok_eol
)
342 now
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
349 #define STR_ELEM(cat) \
351 /* Ignore the rest of the line if we don't need the input of \
353 if (ignore_content) \
355 lr_ignore_rest (ldfile, 0); \
359 arg = lr_token (ldfile, charmap, result, NULL, verbose); \
360 if (arg->tok != tok_string) \
362 if (identification->cat != NULL) \
363 lr_error (ldfile, _("\
364 %s: field `%s' declared more than once"), "LC_IDENTIFICATION", #cat); \
365 else if (!ignore_content && arg->val.str.startmb == NULL) \
367 lr_error (ldfile, _("\
368 %s: unknown character in field `%s'"), "LC_IDENTIFICATION", #cat); \
369 identification->cat = ""; \
371 else if (!ignore_content) \
372 identification->cat = arg->val.str.startmb; \
383 STR_ELEM (territory
);
385 STR_ELEM (application
);
386 STR_ELEM (abbreviation
);
391 /* Ignore the rest of the line if we don't need the input of
395 lr_ignore_rest (ldfile
, 0);
399 /* We expect two operands. */
400 arg
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
401 if (arg
->tok
!= tok_string
&& arg
->tok
!= tok_ident
)
403 /* Next is a semicolon. */
404 cattok
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
405 if (cattok
->tok
!= tok_semicolon
)
407 /* Now a LC_xxx identifier. */
408 cattok
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
411 #define CATEGORY(lname, uname) \
412 case tok_lc_##lname: \
413 category = LC_##uname; \
416 CATEGORY (identification
, IDENTIFICATION
);
417 CATEGORY (ctype
, CTYPE
);
418 CATEGORY (collate
, COLLATE
);
419 CATEGORY (time
, TIME
);
420 CATEGORY (numeric
, NUMERIC
);
421 CATEGORY (monetary
, MONETARY
);
422 CATEGORY (messages
, MESSAGES
);
423 CATEGORY (paper
, PAPER
);
424 CATEGORY (name
, NAME
);
425 CATEGORY (address
, ADDRESS
);
426 CATEGORY (telephone
, TELEPHONE
);
427 CATEGORY (measurement
, MEASUREMENT
);
432 if (identification
->category
[category
] != NULL
)
434 lr_error (ldfile
, _("\
435 %s: duplicate category version definition"), "LC_IDENTIFICATION");
436 free (arg
->val
.str
.startmb
);
439 identification
->category
[category
] = arg
->val
.str
.startmb
;
443 /* Next we assume `LC_IDENTIFICATION'. */
444 arg
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
445 if (arg
->tok
== tok_eof
)
447 if (arg
->tok
== tok_eol
)
448 lr_error (ldfile
, _("%s: incomplete `END' line"),
449 "LC_IDENTIFICATION");
450 else if (arg
->tok
!= tok_lc_identification
)
451 lr_error (ldfile
, _("\
452 %1$s: definition does not end with `END %1$s'"), "LC_IDENTIFICATION");
453 lr_ignore_rest (ldfile
, arg
->tok
== tok_lc_identification
);
458 SYNTAX_ERROR (_("%s: syntax error"), "LC_IDENTIFICATION");
461 /* Prepare for the next round. */
462 now
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
466 /* When we come here we reached the end of the file. */
467 lr_error (ldfile
, _("%s: premature end of file"), "LC_IDENTIFICATION");