Replace FSF snail mail address with URLs.
[glibc.git] / locale / programs / ld-identification.c
blobb0326f99d38accacbd547567154dbedfeb61dbba
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/>. */
18 #ifdef HAVE_CONFIG_H
19 # include <config.h>
20 #endif
22 #include <error.h>
23 #include <langinfo.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <sys/uio.h>
28 #include <assert.h>
30 #include "localedef.h"
31 #include "localeinfo.h"
32 #include "locfile.h"
35 /* The real definition of the struct for the LC_IDENTIFICATION locale. */
36 struct locale_identification_t
38 const char *title;
39 const char *source;
40 const char *address;
41 const char *contact;
42 const char *email;
43 const char *tel;
44 const char *fax;
45 const char *language;
46 const char *territory;
47 const char *audience;
48 const char *application;
49 const char *abbreviation;
50 const char *revision;
51 const char *date;
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",
64 [LC_ALL] = "LC_ALL",
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"
74 static void
75 identification_startup (struct linereader *lr, struct localedef_t *locale,
76 int ignore_content)
78 if (!ignore_content)
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] =
85 "";
88 if (lr != NULL)
90 lr->translate_strings = 1;
91 lr->return_widestr = 0;
96 void
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;
102 int nothing = 0;
103 size_t num;
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
128 empty one. */
129 if (identification == NULL)
131 if (! be_quiet)
132 WITH_CUR_LOCALE (error (0, 0, _("\
133 No definition for %s category found"), "LC_IDENTIFICATION"));
134 identification_startup (NULL, locale, 0);
135 identification
136 = locale->categories[LC_IDENTIFICATION].identification;
137 nothing = 1;
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 = ""; \
150 TEST_ELEM (title);
151 TEST_ELEM (source);
152 TEST_ELEM (address);
153 TEST_ELEM (contact);
154 TEST_ELEM (email);
155 TEST_ELEM (tel);
156 TEST_ELEM (fax);
157 TEST_ELEM (language);
158 TEST_ELEM (territory);
159 TEST_ELEM (audience);
160 TEST_ELEM (application);
161 TEST_ELEM (abbreviation);
162 TEST_ELEM (revision);
163 TEST_ELEM (date);
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] = "";
177 void
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)
185 + (__LC_LAST - 2)];
186 struct locale_file data;
187 uint32_t idx[_NL_ITEM_INDEX (_NL_NUM_LC_IDENTIFICATION)];
188 size_t cnt = 0;
189 size_t num;
190 size_t last_idx;
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);
196 ++cnt;
198 iov[cnt].iov_base = (void *) idx;
199 iov[cnt].iov_len = sizeof (idx);
200 ++cnt;
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;
205 ++cnt;
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;
210 ++cnt;
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;
215 ++cnt;
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;
220 ++cnt;
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;
225 ++cnt;
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;
230 ++cnt;
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;
235 ++cnt;
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;
240 ++cnt;
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;
245 ++cnt;
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;
250 ++cnt;
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;
255 ++cnt;
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;
260 ++cnt;
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;
265 ++cnt;
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;
270 ++cnt;
272 idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len;
273 last_idx = cnt - 1;
274 idx[last_idx] = idx[cnt - 2];
275 for (num = 0; num < __LC_LAST; ++num)
276 if (num != LC_ALL)
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;
281 ++cnt;
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;
287 ++cnt;
289 assert (cnt == (2 + _NL_ITEM_INDEX (_NL_NUM_LC_IDENTIFICATION)
290 + (__LC_LAST - 2)));
292 write_locale_data (output_path, LC_IDENTIFICATION, "LC_IDENTIFICATION", cnt,
293 iov);
297 /* The parser for the LC_IDENTIFICATION section of the locale definition. */
298 void
299 identification_read (struct linereader *ldfile, struct localedef_t *result,
300 const struct charmap_t *charmap, const char *repertoire_name,
301 int ignore_content)
303 struct locale_identification_t *identification;
304 struct token *now;
305 struct token *arg;
306 struct token *cattok;
307 int category;
308 enum token_t nowtok;
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);
316 nowtok = now->tok;
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);
326 return;
329 /* Prepare the data structures. */
330 identification_startup (ldfile, result, ignore_content);
331 identification = result->categories[LC_IDENTIFICATION].identification;
333 while (1)
335 /* Of course we don't proceed beyond the end of file. */
336 if (nowtok == tok_eof)
337 break;
339 /* Ignore empty lines. */
340 if (nowtok == tok_eol)
342 now = lr_token (ldfile, charmap, result, NULL, verbose);
343 nowtok = now->tok;
344 continue;
347 switch (nowtok)
349 #define STR_ELEM(cat) \
350 case tok_##cat: \
351 /* Ignore the rest of the line if we don't need the input of \
352 this line. */ \
353 if (ignore_content) \
355 lr_ignore_rest (ldfile, 0); \
356 break; \
359 arg = lr_token (ldfile, charmap, result, NULL, verbose); \
360 if (arg->tok != tok_string) \
361 goto err_label; \
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; \
373 break
375 STR_ELEM (title);
376 STR_ELEM (source);
377 STR_ELEM (address);
378 STR_ELEM (contact);
379 STR_ELEM (email);
380 STR_ELEM (tel);
381 STR_ELEM (fax);
382 STR_ELEM (language);
383 STR_ELEM (territory);
384 STR_ELEM (audience);
385 STR_ELEM (application);
386 STR_ELEM (abbreviation);
387 STR_ELEM (revision);
388 STR_ELEM (date);
390 case tok_category:
391 /* Ignore the rest of the line if we don't need the input of
392 this line. */
393 if (ignore_content)
395 lr_ignore_rest (ldfile, 0);
396 break;
399 /* We expect two operands. */
400 arg = lr_token (ldfile, charmap, result, NULL, verbose);
401 if (arg->tok != tok_string && arg->tok != tok_ident)
402 goto err_label;
403 /* Next is a semicolon. */
404 cattok = lr_token (ldfile, charmap, result, NULL, verbose);
405 if (cattok->tok != tok_semicolon)
406 goto err_label;
407 /* Now a LC_xxx identifier. */
408 cattok = lr_token (ldfile, charmap, result, NULL, verbose);
409 switch (cattok->tok)
411 #define CATEGORY(lname, uname) \
412 case tok_lc_##lname: \
413 category = LC_##uname; \
414 break
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);
429 default:
430 goto err_label;
432 if (identification->category[category] != NULL)
434 lr_error (ldfile, _("\
435 %s: duplicate category version definition"), "LC_IDENTIFICATION");
436 free (arg->val.str.startmb);
438 else
439 identification->category[category] = arg->val.str.startmb;
440 break;
442 case tok_end:
443 /* Next we assume `LC_IDENTIFICATION'. */
444 arg = lr_token (ldfile, charmap, result, NULL, verbose);
445 if (arg->tok == tok_eof)
446 break;
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);
454 return;
456 default:
457 err_label:
458 SYNTAX_ERROR (_("%s: syntax error"), "LC_IDENTIFICATION");
461 /* Prepare for the next round. */
462 now = lr_token (ldfile, charmap, result, NULL, verbose);
463 nowtok = now->tok;
466 /* When we come here we reached the end of the file. */
467 lr_error (ldfile, _("%s: premature end of file"), "LC_IDENTIFICATION");