1 /* Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library 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 GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
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
, 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 error (0, 0, _("No definition for %s category found"),
133 "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 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 error (0, 0, _("%s: no identification for category `%s'"),
170 "LC_IDENTIFICATION", category_name
[num
]);
171 identification
->category
[num
] = "";
177 identification_output (struct localedef_t
*locale
, struct charmap_t
*charmap
,
178 const char *output_path
)
180 struct locale_identification_t
*identification
181 = locale
->categories
[LC_IDENTIFICATION
].identification
;
182 struct iovec iov
[2 + _NL_ITEM_INDEX (_NL_NUM_LC_IDENTIFICATION
)
184 struct locale_file data
;
185 uint32_t idx
[_NL_ITEM_INDEX (_NL_NUM_LC_IDENTIFICATION
)];
190 data
.magic
= LIMAGIC (LC_IDENTIFICATION
);
191 data
.n
= _NL_ITEM_INDEX (_NL_NUM_LC_IDENTIFICATION
);
192 iov
[cnt
].iov_base
= (void *) &data
;
193 iov
[cnt
].iov_len
= sizeof (data
);
196 iov
[cnt
].iov_base
= (void *) idx
;
197 iov
[cnt
].iov_len
= sizeof (idx
);
200 idx
[cnt
- 2] = iov
[0].iov_len
+ iov
[1].iov_len
;
201 iov
[cnt
].iov_base
= (void *) identification
->title
;
202 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
205 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
206 iov
[cnt
].iov_base
= (void *) identification
->source
;
207 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
210 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
211 iov
[cnt
].iov_base
= (void *) identification
->address
;
212 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
215 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
216 iov
[cnt
].iov_base
= (void *) identification
->contact
;
217 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
220 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
221 iov
[cnt
].iov_base
= (void *) identification
->email
;
222 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
225 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
226 iov
[cnt
].iov_base
= (void *) identification
->tel
;
227 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
230 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
231 iov
[cnt
].iov_base
= (void *) identification
->fax
;
232 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
235 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
236 iov
[cnt
].iov_base
= (void *) identification
->language
;
237 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
240 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
241 iov
[cnt
].iov_base
= (void *) identification
->territory
;
242 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
245 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
246 iov
[cnt
].iov_base
= (void *) identification
->audience
;
247 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
250 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
251 iov
[cnt
].iov_base
= (void *) identification
->application
;
252 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
255 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
256 iov
[cnt
].iov_base
= (void *) identification
->abbreviation
;
257 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
260 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
261 iov
[cnt
].iov_base
= (void *) identification
->revision
;
262 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
265 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
266 iov
[cnt
].iov_base
= (void *) identification
->date
;
267 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
270 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
272 idx
[last_idx
] = idx
[cnt
- 2];
273 for (num
= 0; num
< __LC_LAST
; ++num
)
276 iov
[cnt
].iov_base
= (void *) identification
->category
[num
];
277 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
278 idx
[last_idx
] += iov
[cnt
].iov_len
;
282 assert (last_idx
== _NL_ITEM_INDEX (_NL_NUM_LC_IDENTIFICATION
) - 1);
283 iov
[cnt
].iov_base
= (void *) charmap
->code_set_name
;
284 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
287 assert (cnt
== (2 + _NL_ITEM_INDEX (_NL_NUM_LC_IDENTIFICATION
)
290 write_locale_data (output_path
, "LC_IDENTIFICATION", cnt
, iov
);
294 /* The parser for the LC_IDENTIFICATION section of the locale definition. */
296 identification_read (struct linereader
*ldfile
, struct localedef_t
*result
,
297 struct charmap_t
*charmap
, const char *repertoire_name
,
300 struct locale_identification_t
*identification
;
303 struct token
*cattok
;
307 /* The rest of the line containing `LC_IDENTIFICATION' must be free. */
308 lr_ignore_rest (ldfile
, 1);
312 now
= lr_token (ldfile
, charmap
, NULL
, verbose
);
315 while (nowtok
== tok_eol
);
317 /* If we see `copy' now we are almost done. */
318 if (nowtok
== tok_copy
)
320 handle_copy (ldfile
, charmap
, repertoire_name
, result
,
321 tok_lc_identification
, LC_IDENTIFICATION
,
322 "LC_IDENTIFICATION", ignore_content
);
326 /* Prepare the data structures. */
327 identification_startup (ldfile
, result
, ignore_content
);
328 identification
= result
->categories
[LC_IDENTIFICATION
].identification
;
332 /* Of course we don't proceed beyond the end of file. */
333 if (nowtok
== tok_eof
)
336 /* Ignore empty lines. */
337 if (nowtok
== tok_eol
)
339 now
= lr_token (ldfile
, charmap
, NULL
, verbose
);
346 #define STR_ELEM(cat) \
348 /* Ignore the rest of the line if we don't need the input of \
350 if (ignore_content) \
352 lr_ignore_rest (ldfile, 0); \
356 arg = lr_token (ldfile, charmap, NULL, verbose); \
357 if (arg->tok != tok_string) \
359 if (identification->cat != NULL) \
360 lr_error (ldfile, _("\
361 %s: field `%s' declared more than once"), "LC_IDENTIFICATION", #cat); \
362 else if (!ignore_content && arg->val.str.startmb == NULL) \
364 lr_error (ldfile, _("\
365 %s: unknown character in field `%s'"), "LC_IDENTIFICATION", #cat); \
366 identification->cat = ""; \
368 else if (!ignore_content) \
369 identification->cat = arg->val.str.startmb; \
380 STR_ELEM (territory
);
382 STR_ELEM (application
);
383 STR_ELEM (abbreviation
);
388 /* Ignore the rest of the line if we don't need the input of
392 lr_ignore_rest (ldfile
, 0);
396 /* We expect two operands. */
397 arg
= lr_token (ldfile
, charmap
, NULL
, verbose
);
398 if (arg
->tok
!= tok_string
&& arg
->tok
!= tok_ident
)
400 /* Next is a semicolon. */
401 cattok
= lr_token (ldfile
, charmap
, NULL
, verbose
);
402 if (cattok
->tok
!= tok_semicolon
)
404 /* Now a LC_xxx identifier. */
405 cattok
= lr_token (ldfile
, charmap
, NULL
, verbose
);
408 #define CATEGORY(lname, uname) \
409 case tok_lc_##lname: \
410 category = LC_##uname; \
413 CATEGORY (identification
, IDENTIFICATION
);
414 CATEGORY (ctype
, CTYPE
);
415 CATEGORY (collate
, COLLATE
);
416 CATEGORY (time
, TIME
);
417 CATEGORY (numeric
, NUMERIC
);
418 CATEGORY (monetary
, MONETARY
);
419 CATEGORY (messages
, MESSAGES
);
420 CATEGORY (paper
, PAPER
);
421 CATEGORY (name
, NAME
);
422 CATEGORY (address
, ADDRESS
);
423 CATEGORY (telephone
, TELEPHONE
);
424 CATEGORY (measurement
, MEASUREMENT
);
429 if (identification
->category
[category
] != NULL
)
431 lr_error (ldfile
, _("\
432 %s: duplicate category version definition"), "LC_IDENTIFICATION");
433 free (arg
->val
.str
.startmb
);
436 identification
->category
[category
] = arg
->val
.str
.startmb
;
440 /* Next we assume `LC_IDENTIFICATION'. */
441 arg
= lr_token (ldfile
, charmap
, NULL
, verbose
);
442 if (arg
->tok
== tok_eof
)
444 if (arg
->tok
== tok_eol
)
445 lr_error (ldfile
, _("%s: incomplete `END' line"),
446 "LC_IDENTIFICATION");
447 else if (arg
->tok
!= tok_lc_identification
)
448 lr_error (ldfile
, _("\
449 %1$s: definition does not end with `END %1$s'"), "LC_IDENTIFICATION");
450 lr_ignore_rest (ldfile
, arg
->tok
== tok_lc_identification
);
455 SYNTAX_ERROR (_("%s: syntax error"), "LC_IDENTIFICATION");
458 /* Prepare for the next round. */
459 now
= lr_token (ldfile
, charmap
, NULL
, verbose
);
463 /* When we come here we reached the end of the file. */
464 lr_error (ldfile
, _("%s: premature end of file"), "LC_IDENTIFICATION");