1 /* Copyright (C) 1998-2015 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/>. */
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 locale_file file
;
188 init_locale_data (&file
, _NL_ITEM_INDEX (_NL_NUM_LC_IDENTIFICATION
));
189 add_locale_string (&file
, identification
->title
);
190 add_locale_string (&file
, identification
->source
);
191 add_locale_string (&file
, identification
->address
);
192 add_locale_string (&file
, identification
->contact
);
193 add_locale_string (&file
, identification
->email
);
194 add_locale_string (&file
, identification
->tel
);
195 add_locale_string (&file
, identification
->fax
);
196 add_locale_string (&file
, identification
->language
);
197 add_locale_string (&file
, identification
->territory
);
198 add_locale_string (&file
, identification
->audience
);
199 add_locale_string (&file
, identification
->application
);
200 add_locale_string (&file
, identification
->abbreviation
);
201 add_locale_string (&file
, identification
->revision
);
202 add_locale_string (&file
, identification
->date
);
203 start_locale_structure (&file
);
204 for (num
= 0; num
< __LC_LAST
; ++num
)
206 add_locale_string (&file
, identification
->category
[num
]);
207 end_locale_structure (&file
);
208 add_locale_string (&file
, charmap
->code_set_name
);
209 write_locale_data (output_path
, LC_IDENTIFICATION
, "LC_IDENTIFICATION",
214 /* The parser for the LC_IDENTIFICATION section of the locale definition. */
216 identification_read (struct linereader
*ldfile
, struct localedef_t
*result
,
217 const struct charmap_t
*charmap
, const char *repertoire_name
,
220 struct locale_identification_t
*identification
;
223 struct token
*cattok
;
227 /* The rest of the line containing `LC_IDENTIFICATION' must be free. */
228 lr_ignore_rest (ldfile
, 1);
232 now
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
235 while (nowtok
== tok_eol
);
237 /* If we see `copy' now we are almost done. */
238 if (nowtok
== tok_copy
)
240 handle_copy (ldfile
, charmap
, repertoire_name
, result
,
241 tok_lc_identification
, LC_IDENTIFICATION
,
242 "LC_IDENTIFICATION", ignore_content
);
246 /* Prepare the data structures. */
247 identification_startup (ldfile
, result
, ignore_content
);
248 identification
= result
->categories
[LC_IDENTIFICATION
].identification
;
252 /* Of course we don't proceed beyond the end of file. */
253 if (nowtok
== tok_eof
)
256 /* Ignore empty lines. */
257 if (nowtok
== tok_eol
)
259 now
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
266 #define STR_ELEM(cat) \
268 /* Ignore the rest of the line if we don't need the input of \
270 if (ignore_content) \
272 lr_ignore_rest (ldfile, 0); \
276 arg = lr_token (ldfile, charmap, result, NULL, verbose); \
277 if (arg->tok != tok_string) \
279 if (identification->cat != NULL) \
280 lr_error (ldfile, _("\
281 %s: field `%s' declared more than once"), "LC_IDENTIFICATION", #cat); \
282 else if (!ignore_content && arg->val.str.startmb == NULL) \
284 lr_error (ldfile, _("\
285 %s: unknown character in field `%s'"), "LC_IDENTIFICATION", #cat); \
286 identification->cat = ""; \
288 else if (!ignore_content) \
289 identification->cat = arg->val.str.startmb; \
300 STR_ELEM (territory
);
302 STR_ELEM (application
);
303 STR_ELEM (abbreviation
);
308 /* Ignore the rest of the line if we don't need the input of
312 lr_ignore_rest (ldfile
, 0);
316 /* We expect two operands. */
317 arg
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
318 if (arg
->tok
!= tok_string
&& arg
->tok
!= tok_ident
)
320 /* Next is a semicolon. */
321 cattok
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
322 if (cattok
->tok
!= tok_semicolon
)
324 /* Now a LC_xxx identifier. */
325 cattok
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
328 #define CATEGORY(lname, uname) \
329 case tok_lc_##lname: \
330 category = LC_##uname; \
333 CATEGORY (identification
, IDENTIFICATION
);
334 CATEGORY (ctype
, CTYPE
);
335 CATEGORY (collate
, COLLATE
);
336 CATEGORY (time
, TIME
);
337 CATEGORY (numeric
, NUMERIC
);
338 CATEGORY (monetary
, MONETARY
);
339 CATEGORY (messages
, MESSAGES
);
340 CATEGORY (paper
, PAPER
);
341 CATEGORY (name
, NAME
);
342 CATEGORY (address
, ADDRESS
);
343 CATEGORY (telephone
, TELEPHONE
);
344 CATEGORY (measurement
, MEASUREMENT
);
349 if (identification
->category
[category
] != NULL
)
351 lr_error (ldfile
, _("\
352 %s: duplicate category version definition"), "LC_IDENTIFICATION");
353 free (arg
->val
.str
.startmb
);
356 identification
->category
[category
] = arg
->val
.str
.startmb
;
360 /* Next we assume `LC_IDENTIFICATION'. */
361 arg
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
362 if (arg
->tok
== tok_eof
)
364 if (arg
->tok
== tok_eol
)
365 lr_error (ldfile
, _("%s: incomplete `END' line"),
366 "LC_IDENTIFICATION");
367 else if (arg
->tok
!= tok_lc_identification
)
368 lr_error (ldfile
, _("\
369 %1$s: definition does not end with `END %1$s'"), "LC_IDENTIFICATION");
370 lr_ignore_rest (ldfile
, arg
->tok
== tok_lc_identification
);
375 SYNTAX_ERROR (_("%s: syntax error"), "LC_IDENTIFICATION");
378 /* Prepare for the next round. */
379 now
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
383 /* When we come here we reached the end of the file. */
384 lr_error (ldfile
, _("%s: premature end of file"), "LC_IDENTIFICATION");