1 /* Copyright (C) 1998, 1999, 2000, 2001, 2002 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 "localedef.h"
33 #include "localeinfo.h"
37 /* The real definition of the struct for the LC_IDENTIFICATION locale. */
38 struct locale_identification_t
48 const char *territory
;
50 const char *application
;
51 const char *abbreviation
;
54 const char *category
[__LC_LAST
];
58 static const char *category_name
[__LC_LAST
] =
60 [LC_CTYPE
] = "LC_CTYPE",
61 [LC_NUMERIC
] = "LC_NUMERIC",
62 [LC_TIME
] = "LC_TIME",
63 [LC_COLLATE
] = "LC_COLLATE",
64 [LC_MONETARY
] = "LC_MONETARY",
65 [LC_MESSAGES
] = "LC_MESSAGES",
67 [LC_PAPER
] = "LC_PAPER",
68 [LC_NAME
] = "LC_NAME",
69 [LC_ADDRESS
] = "LC_ADDRESS",
70 [LC_TELEPHONE
] = "LC_TELEPHONE",
71 [LC_MEASUREMENT
] = "LC_MEASUREMENT",
72 [LC_IDENTIFICATION
] = "LC_IDENTIFICATION"
77 identification_startup (struct linereader
*lr
, struct localedef_t
*locale
,
82 locale
->categories
[LC_IDENTIFICATION
].identification
=
83 (struct locale_identification_t
*)
84 xcalloc (1, sizeof (struct locale_identification_t
));
86 locale
->categories
[LC_IDENTIFICATION
].identification
->category
[LC_ALL
] =
92 lr
->translate_strings
= 1;
93 lr
->return_widestr
= 0;
99 identification_finish (struct localedef_t
*locale
,
100 const struct charmap_t
*charmap
)
102 struct locale_identification_t
*identification
103 = locale
->categories
[LC_IDENTIFICATION
].identification
;
107 /* Now resolve copying and also handle completely missing definitions. */
108 if (identification
== NULL
)
110 /* First see whether we were supposed to copy. If yes, find the
111 actual definition. */
112 if (locale
->copy_name
[LC_IDENTIFICATION
] != NULL
)
114 /* Find the copying locale. This has to happen transitively since
115 the locale we are copying from might also copying another one. */
116 struct localedef_t
*from
= locale
;
119 from
= find_locale (LC_IDENTIFICATION
,
120 from
->copy_name
[LC_IDENTIFICATION
],
121 from
->repertoire_name
, charmap
);
122 while (from
->categories
[LC_IDENTIFICATION
].identification
== NULL
123 && from
->copy_name
[LC_IDENTIFICATION
] != NULL
);
125 identification
= locale
->categories
[LC_IDENTIFICATION
].identification
126 = from
->categories
[LC_IDENTIFICATION
].identification
;
129 /* If there is still no definition issue an warning and create an
131 if (identification
== NULL
)
134 WITH_CUR_LOCALE (error (0, 0, _("\
135 No definition for %s category found"), "LC_IDENTIFICATION"));
136 identification_startup (NULL
, locale
, 0);
138 = locale
->categories
[LC_IDENTIFICATION
].identification
;
143 #define TEST_ELEM(cat) \
144 if (identification->cat == NULL) \
146 if (verbose && ! nothing) \
147 WITH_CUR_LOCALE (error (0, 0, _("%s: field `%s' not defined"), \
148 "LC_IDENTIFICATION", #cat)); \
149 identification->cat = ""; \
159 TEST_ELEM (language
);
160 TEST_ELEM (territory
);
161 TEST_ELEM (audience
);
162 TEST_ELEM (application
);
163 TEST_ELEM (abbreviation
);
164 TEST_ELEM (revision
);
167 for (num
= 0; num
< __LC_LAST
; ++num
)
168 if (num
!= LC_ALL
&& identification
->category
[num
] == NULL
)
170 if (verbose
&& ! nothing
)
171 WITH_CUR_LOCALE (error (0, 0, _("\
172 %s: no identification for category `%s'"),
173 "LC_IDENTIFICATION", category_name
[num
]));
174 identification
->category
[num
] = "";
180 identification_output (struct localedef_t
*locale
,
181 const struct charmap_t
*charmap
,
182 const char *output_path
)
184 struct locale_identification_t
*identification
185 = locale
->categories
[LC_IDENTIFICATION
].identification
;
186 struct iovec iov
[2 + _NL_ITEM_INDEX (_NL_NUM_LC_IDENTIFICATION
)
188 struct locale_file data
;
189 uint32_t idx
[_NL_ITEM_INDEX (_NL_NUM_LC_IDENTIFICATION
)];
194 data
.magic
= LIMAGIC (LC_IDENTIFICATION
);
195 data
.n
= _NL_ITEM_INDEX (_NL_NUM_LC_IDENTIFICATION
);
196 iov
[cnt
].iov_base
= (void *) &data
;
197 iov
[cnt
].iov_len
= sizeof (data
);
200 iov
[cnt
].iov_base
= (void *) idx
;
201 iov
[cnt
].iov_len
= sizeof (idx
);
204 idx
[cnt
- 2] = iov
[0].iov_len
+ iov
[1].iov_len
;
205 iov
[cnt
].iov_base
= (void *) identification
->title
;
206 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
209 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
210 iov
[cnt
].iov_base
= (void *) identification
->source
;
211 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
214 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
215 iov
[cnt
].iov_base
= (void *) identification
->address
;
216 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
219 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
220 iov
[cnt
].iov_base
= (void *) identification
->contact
;
221 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
224 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
225 iov
[cnt
].iov_base
= (void *) identification
->email
;
226 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
229 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
230 iov
[cnt
].iov_base
= (void *) identification
->tel
;
231 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
234 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
235 iov
[cnt
].iov_base
= (void *) identification
->fax
;
236 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
239 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
240 iov
[cnt
].iov_base
= (void *) identification
->language
;
241 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
244 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
245 iov
[cnt
].iov_base
= (void *) identification
->territory
;
246 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
249 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
250 iov
[cnt
].iov_base
= (void *) identification
->audience
;
251 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
254 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
255 iov
[cnt
].iov_base
= (void *) identification
->application
;
256 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
259 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
260 iov
[cnt
].iov_base
= (void *) identification
->abbreviation
;
261 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
264 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
265 iov
[cnt
].iov_base
= (void *) identification
->revision
;
266 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
269 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
270 iov
[cnt
].iov_base
= (void *) identification
->date
;
271 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
274 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
276 idx
[last_idx
] = idx
[cnt
- 2];
277 for (num
= 0; num
< __LC_LAST
; ++num
)
280 iov
[cnt
].iov_base
= (void *) identification
->category
[num
];
281 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
282 idx
[last_idx
] += iov
[cnt
].iov_len
;
286 assert (last_idx
== _NL_ITEM_INDEX (_NL_NUM_LC_IDENTIFICATION
) - 1);
287 iov
[cnt
].iov_base
= (void *) charmap
->code_set_name
;
288 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
291 assert (cnt
== (2 + _NL_ITEM_INDEX (_NL_NUM_LC_IDENTIFICATION
)
294 write_locale_data (output_path
, LC_IDENTIFICATION
, "LC_IDENTIFICATION", cnt
,
299 /* The parser for the LC_IDENTIFICATION section of the locale definition. */
301 identification_read (struct linereader
*ldfile
, struct localedef_t
*result
,
302 const struct charmap_t
*charmap
, const char *repertoire_name
,
305 struct locale_identification_t
*identification
;
308 struct token
*cattok
;
312 /* The rest of the line containing `LC_IDENTIFICATION' must be free. */
313 lr_ignore_rest (ldfile
, 1);
317 now
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
320 while (nowtok
== tok_eol
);
322 /* If we see `copy' now we are almost done. */
323 if (nowtok
== tok_copy
)
325 handle_copy (ldfile
, charmap
, repertoire_name
, result
,
326 tok_lc_identification
, LC_IDENTIFICATION
,
327 "LC_IDENTIFICATION", ignore_content
);
331 /* Prepare the data structures. */
332 identification_startup (ldfile
, result
, ignore_content
);
333 identification
= result
->categories
[LC_IDENTIFICATION
].identification
;
337 /* Of course we don't proceed beyond the end of file. */
338 if (nowtok
== tok_eof
)
341 /* Ignore empty lines. */
342 if (nowtok
== tok_eol
)
344 now
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
351 #define STR_ELEM(cat) \
353 /* Ignore the rest of the line if we don't need the input of \
355 if (ignore_content) \
357 lr_ignore_rest (ldfile, 0); \
361 arg = lr_token (ldfile, charmap, result, NULL, verbose); \
362 if (arg->tok != tok_string) \
364 if (identification->cat != NULL) \
365 lr_error (ldfile, _("\
366 %s: field `%s' declared more than once"), "LC_IDENTIFICATION", #cat); \
367 else if (!ignore_content && arg->val.str.startmb == NULL) \
369 lr_error (ldfile, _("\
370 %s: unknown character in field `%s'"), "LC_IDENTIFICATION", #cat); \
371 identification->cat = ""; \
373 else if (!ignore_content) \
374 identification->cat = arg->val.str.startmb; \
385 STR_ELEM (territory
);
387 STR_ELEM (application
);
388 STR_ELEM (abbreviation
);
393 /* Ignore the rest of the line if we don't need the input of
397 lr_ignore_rest (ldfile
, 0);
401 /* We expect two operands. */
402 arg
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
403 if (arg
->tok
!= tok_string
&& arg
->tok
!= tok_ident
)
405 /* Next is a semicolon. */
406 cattok
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
407 if (cattok
->tok
!= tok_semicolon
)
409 /* Now a LC_xxx identifier. */
410 cattok
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
413 #define CATEGORY(lname, uname) \
414 case tok_lc_##lname: \
415 category = LC_##uname; \
418 CATEGORY (identification
, IDENTIFICATION
);
419 CATEGORY (ctype
, CTYPE
);
420 CATEGORY (collate
, COLLATE
);
421 CATEGORY (time
, TIME
);
422 CATEGORY (numeric
, NUMERIC
);
423 CATEGORY (monetary
, MONETARY
);
424 CATEGORY (messages
, MESSAGES
);
425 CATEGORY (paper
, PAPER
);
426 CATEGORY (name
, NAME
);
427 CATEGORY (address
, ADDRESS
);
428 CATEGORY (telephone
, TELEPHONE
);
429 CATEGORY (measurement
, MEASUREMENT
);
434 if (identification
->category
[category
] != NULL
)
436 lr_error (ldfile
, _("\
437 %s: duplicate category version definition"), "LC_IDENTIFICATION");
438 free (arg
->val
.str
.startmb
);
441 identification
->category
[category
] = arg
->val
.str
.startmb
;
445 /* Next we assume `LC_IDENTIFICATION'. */
446 arg
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
447 if (arg
->tok
== tok_eof
)
449 if (arg
->tok
== tok_eol
)
450 lr_error (ldfile
, _("%s: incomplete `END' line"),
451 "LC_IDENTIFICATION");
452 else if (arg
->tok
!= tok_lc_identification
)
453 lr_error (ldfile
, _("\
454 %1$s: definition does not end with `END %1$s'"), "LC_IDENTIFICATION");
455 lr_ignore_rest (ldfile
, arg
->tok
== tok_lc_identification
);
460 SYNTAX_ERROR (_("%s: syntax error"), "LC_IDENTIFICATION");
463 /* Prepare for the next round. */
464 now
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
468 /* When we come here we reached the end of the file. */
469 lr_error (ldfile
, _("%s: premature end of file"), "LC_IDENTIFICATION");