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, write to the Free Software Foundation,
17 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
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
)
167 if (num
!= LC_ALL
&& identification
->category
[num
] == NULL
)
169 if (verbose
&& ! nothing
)
170 WITH_CUR_LOCALE (error (0, 0, _("\
171 %s: no identification for category `%s'"),
172 "LC_IDENTIFICATION", category_name
[num
]));
173 identification
->category
[num
] = "";
179 identification_output (struct localedef_t
*locale
,
180 const struct charmap_t
*charmap
,
181 const char *output_path
)
183 struct locale_identification_t
*identification
184 = locale
->categories
[LC_IDENTIFICATION
].identification
;
185 struct iovec iov
[2 + _NL_ITEM_INDEX (_NL_NUM_LC_IDENTIFICATION
)
187 struct locale_file data
;
188 uint32_t idx
[_NL_ITEM_INDEX (_NL_NUM_LC_IDENTIFICATION
)];
193 data
.magic
= LIMAGIC (LC_IDENTIFICATION
);
194 data
.n
= _NL_ITEM_INDEX (_NL_NUM_LC_IDENTIFICATION
);
195 iov
[cnt
].iov_base
= (void *) &data
;
196 iov
[cnt
].iov_len
= sizeof (data
);
199 iov
[cnt
].iov_base
= (void *) idx
;
200 iov
[cnt
].iov_len
= sizeof (idx
);
203 idx
[cnt
- 2] = iov
[0].iov_len
+ iov
[1].iov_len
;
204 iov
[cnt
].iov_base
= (void *) identification
->title
;
205 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
208 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
209 iov
[cnt
].iov_base
= (void *) identification
->source
;
210 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
213 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
214 iov
[cnt
].iov_base
= (void *) identification
->address
;
215 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
218 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
219 iov
[cnt
].iov_base
= (void *) identification
->contact
;
220 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
223 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
224 iov
[cnt
].iov_base
= (void *) identification
->email
;
225 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
228 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
229 iov
[cnt
].iov_base
= (void *) identification
->tel
;
230 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
233 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
234 iov
[cnt
].iov_base
= (void *) identification
->fax
;
235 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
238 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
239 iov
[cnt
].iov_base
= (void *) identification
->language
;
240 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
243 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
244 iov
[cnt
].iov_base
= (void *) identification
->territory
;
245 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
248 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
249 iov
[cnt
].iov_base
= (void *) identification
->audience
;
250 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
253 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
254 iov
[cnt
].iov_base
= (void *) identification
->application
;
255 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
258 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
259 iov
[cnt
].iov_base
= (void *) identification
->abbreviation
;
260 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
263 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
264 iov
[cnt
].iov_base
= (void *) identification
->revision
;
265 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
268 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
269 iov
[cnt
].iov_base
= (void *) identification
->date
;
270 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
273 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
275 idx
[last_idx
] = idx
[cnt
- 2];
276 for (num
= 0; num
< __LC_LAST
; ++num
)
279 iov
[cnt
].iov_base
= (void *) identification
->category
[num
];
280 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
281 idx
[last_idx
] += iov
[cnt
].iov_len
;
285 assert (last_idx
== _NL_ITEM_INDEX (_NL_NUM_LC_IDENTIFICATION
) - 1);
286 iov
[cnt
].iov_base
= (void *) charmap
->code_set_name
;
287 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
290 assert (cnt
== (2 + _NL_ITEM_INDEX (_NL_NUM_LC_IDENTIFICATION
)
293 write_locale_data (output_path
, LC_IDENTIFICATION
, "LC_IDENTIFICATION", cnt
,
298 /* The parser for the LC_IDENTIFICATION section of the locale definition. */
300 identification_read (struct linereader
*ldfile
, struct localedef_t
*result
,
301 const struct charmap_t
*charmap
, const char *repertoire_name
,
304 struct locale_identification_t
*identification
;
307 struct token
*cattok
;
311 /* The rest of the line containing `LC_IDENTIFICATION' must be free. */
312 lr_ignore_rest (ldfile
, 1);
316 now
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
319 while (nowtok
== tok_eol
);
321 /* If we see `copy' now we are almost done. */
322 if (nowtok
== tok_copy
)
324 handle_copy (ldfile
, charmap
, repertoire_name
, result
,
325 tok_lc_identification
, LC_IDENTIFICATION
,
326 "LC_IDENTIFICATION", ignore_content
);
330 /* Prepare the data structures. */
331 identification_startup (ldfile
, result
, ignore_content
);
332 identification
= result
->categories
[LC_IDENTIFICATION
].identification
;
336 /* Of course we don't proceed beyond the end of file. */
337 if (nowtok
== tok_eof
)
340 /* Ignore empty lines. */
341 if (nowtok
== tok_eol
)
343 now
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
350 #define STR_ELEM(cat) \
352 /* Ignore the rest of the line if we don't need the input of \
354 if (ignore_content) \
356 lr_ignore_rest (ldfile, 0); \
360 arg = lr_token (ldfile, charmap, result, NULL, verbose); \
361 if (arg->tok != tok_string) \
363 if (identification->cat != NULL) \
364 lr_error (ldfile, _("\
365 %s: field `%s' declared more than once"), "LC_IDENTIFICATION", #cat); \
366 else if (!ignore_content && arg->val.str.startmb == NULL) \
368 lr_error (ldfile, _("\
369 %s: unknown character in field `%s'"), "LC_IDENTIFICATION", #cat); \
370 identification->cat = ""; \
372 else if (!ignore_content) \
373 identification->cat = arg->val.str.startmb; \
384 STR_ELEM (territory
);
386 STR_ELEM (application
);
387 STR_ELEM (abbreviation
);
392 /* Ignore the rest of the line if we don't need the input of
396 lr_ignore_rest (ldfile
, 0);
400 /* We expect two operands. */
401 arg
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
402 if (arg
->tok
!= tok_string
&& arg
->tok
!= tok_ident
)
404 /* Next is a semicolon. */
405 cattok
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
406 if (cattok
->tok
!= tok_semicolon
)
408 /* Now a LC_xxx identifier. */
409 cattok
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
412 #define CATEGORY(lname, uname) \
413 case tok_lc_##lname: \
414 category = LC_##uname; \
417 CATEGORY (identification
, IDENTIFICATION
);
418 CATEGORY (ctype
, CTYPE
);
419 CATEGORY (collate
, COLLATE
);
420 CATEGORY (time
, TIME
);
421 CATEGORY (numeric
, NUMERIC
);
422 CATEGORY (monetary
, MONETARY
);
423 CATEGORY (messages
, MESSAGES
);
424 CATEGORY (paper
, PAPER
);
425 CATEGORY (name
, NAME
);
426 CATEGORY (address
, ADDRESS
);
427 CATEGORY (telephone
, TELEPHONE
);
428 CATEGORY (measurement
, MEASUREMENT
);
433 if (identification
->category
[category
] != NULL
)
435 lr_error (ldfile
, _("\
436 %s: duplicate category version definition"), "LC_IDENTIFICATION");
437 free (arg
->val
.str
.startmb
);
440 identification
->category
[category
] = arg
->val
.str
.startmb
;
444 /* Next we assume `LC_IDENTIFICATION'. */
445 arg
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
446 if (arg
->tok
== tok_eof
)
448 if (arg
->tok
== tok_eol
)
449 lr_error (ldfile
, _("%s: incomplete `END' line"),
450 "LC_IDENTIFICATION");
451 else if (arg
->tok
!= tok_lc_identification
)
452 lr_error (ldfile
, _("\
453 %1$s: definition does not end with `END %1$s'"), "LC_IDENTIFICATION");
454 lr_ignore_rest (ldfile
, arg
->tok
== tok_lc_identification
);
459 SYNTAX_ERROR (_("%s: syntax error"), "LC_IDENTIFICATION");
462 /* Prepare for the next round. */
463 now
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
467 /* When we come here we reached the end of the file. */
468 lr_error (ldfile
, _("%s: premature end of file"), "LC_IDENTIFICATION");