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 version 2 as
7 published by the Free Software Foundation.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software Foundation,
16 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
28 #include "localedef.h"
29 #include "localeinfo.h"
33 /* The real definition of the struct for the LC_NAME locale. */
40 const char *name_miss
;
46 name_startup (struct linereader
*lr
, struct localedef_t
*locale
,
50 locale
->categories
[LC_NAME
].name
=
51 (struct locale_name_t
*) xcalloc (1, sizeof (struct locale_name_t
));
55 lr
->translate_strings
= 1;
56 lr
->return_widestr
= 0;
62 name_finish (struct localedef_t
*locale
, const struct charmap_t
*charmap
)
64 struct locale_name_t
*name
= locale
->categories
[LC_NAME
].name
;
67 /* Now resolve copying and also handle completely missing definitions. */
70 /* First see whether we were supposed to copy. If yes, find the
72 if (locale
->copy_name
[LC_NAME
] != NULL
)
74 /* Find the copying locale. This has to happen transitively since
75 the locale we are copying from might also copying another one. */
76 struct localedef_t
*from
= locale
;
79 from
= find_locale (LC_NAME
, from
->copy_name
[LC_NAME
],
80 from
->repertoire_name
, charmap
);
81 while (from
->categories
[LC_NAME
].name
== NULL
82 && from
->copy_name
[LC_NAME
] != NULL
);
84 name
= locale
->categories
[LC_NAME
].name
85 = from
->categories
[LC_NAME
].name
;
88 /* If there is still no definition issue an warning and create an
93 WITH_CUR_LOCALE (error (0, 0, _("\
94 No definition for %s category found"), "LC_NAME"));
95 name_startup (NULL
, locale
, 0);
96 name
= locale
->categories
[LC_NAME
].name
;
101 if (name
->name_fmt
== NULL
)
104 WITH_CUR_LOCALE (error (0, 0, _("%s: field `%s' not defined"),
105 "LC_NAME", "name_fmt"));
106 /* Use as the default value the value of the i18n locale. */
107 name
->name_fmt
= "%p%t%g%t%m%t%f";
111 /* We must check whether the format string contains only the
112 allowed escape sequences. */
113 const char *cp
= name
->name_fmt
;
116 WITH_CUR_LOCALE (error (0, 0, _("%s: field `%s' must not be empty"),
117 "LC_NAME", "name_fmt"));
126 if (strchr ("dfFgGlomMpsSt", *cp
) == NULL
)
128 WITH_CUR_LOCALE (error (0, 0, _("\
129 %s: invalid escape sequence in field `%s'"), "LC_NAME", "name_fmt"));
137 #define TEST_ELEM(cat) \
138 if (name->cat == NULL) \
140 if (verbose && ! nothing) \
141 WITH_CUR_LOCALE (error (0, 0, _("%s: field `%s' not defined"), \
146 TEST_ELEM (name_gen
);
148 TEST_ELEM (name_mrs
);
149 TEST_ELEM (name_miss
);
155 name_output (struct localedef_t
*locale
, const struct charmap_t
*charmap
,
156 const char *output_path
)
158 struct locale_name_t
*name
= locale
->categories
[LC_NAME
].name
;
159 struct iovec iov
[2 + _NL_ITEM_INDEX (_NL_NUM_LC_NAME
)];
160 struct locale_file data
;
161 uint32_t idx
[_NL_ITEM_INDEX (_NL_NUM_LC_NAME
)];
164 data
.magic
= LIMAGIC (LC_NAME
);
165 data
.n
= _NL_ITEM_INDEX (_NL_NUM_LC_NAME
);
166 iov
[cnt
].iov_base
= (void *) &data
;
167 iov
[cnt
].iov_len
= sizeof (data
);
170 iov
[cnt
].iov_base
= (void *) idx
;
171 iov
[cnt
].iov_len
= sizeof (idx
);
174 idx
[cnt
- 2] = iov
[0].iov_len
+ iov
[1].iov_len
;
175 iov
[cnt
].iov_base
= (void *) name
->name_fmt
;
176 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
179 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
180 iov
[cnt
].iov_base
= (void *) name
->name_gen
;
181 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
184 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
185 iov
[cnt
].iov_base
= (void *) name
->name_mr
;
186 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
189 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
190 iov
[cnt
].iov_base
= (void *) name
->name_mrs
;
191 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
194 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
195 iov
[cnt
].iov_base
= (void *) name
->name_miss
;
196 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
199 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
200 iov
[cnt
].iov_base
= (void *) name
->name_ms
;
201 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
204 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
205 iov
[cnt
].iov_base
= (void *) charmap
->code_set_name
;
206 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
209 assert (cnt
== 2 + _NL_ITEM_INDEX (_NL_NUM_LC_NAME
));
211 write_locale_data (output_path
, LC_NAME
, "LC_NAME",
212 2 + _NL_ITEM_INDEX (_NL_NUM_LC_NAME
), iov
);
216 /* The parser for the LC_NAME section of the locale definition. */
218 name_read (struct linereader
*ldfile
, struct localedef_t
*result
,
219 const struct charmap_t
*charmap
, const char *repertoire_name
,
222 struct locale_name_t
*name
;
227 /* The rest of the line containing `LC_NAME' must be empty. */
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
, tok_lc_name
,
241 LC_NAME
, "LC_NAME", ignore_content
);
245 /* Prepare the data structures. */
246 name_startup (ldfile
, result
, ignore_content
);
247 name
= result
->categories
[LC_NAME
].name
;
251 /* Of course we don't proceed beyond the end of file. */
252 if (nowtok
== tok_eof
)
255 /* Ignore empty lines. */
256 if (nowtok
== tok_eol
)
258 now
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
265 #define STR_ELEM(cat) \
267 /* Ignore the rest of the line if we don't need the input of \
269 if (ignore_content) \
271 lr_ignore_rest (ldfile, 0); \
275 arg = lr_token (ldfile, charmap, result, NULL, verbose); \
276 if (arg->tok != tok_string) \
278 if (name->cat != NULL) \
279 lr_error (ldfile, _("%s: field `%s' declared more than once"), \
281 else if (!ignore_content && arg->val.str.startmb == NULL) \
283 lr_error (ldfile, _("%s: unknown character in field `%s'"), \
287 else if (!ignore_content) \
288 name->cat = arg->val.str.startmb; \
295 STR_ELEM (name_miss
);
299 /* Next we assume `LC_NAME'. */
300 arg
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
301 if (arg
->tok
== tok_eof
)
303 if (arg
->tok
== tok_eol
)
304 lr_error (ldfile
, _("%s: incomplete `END' line"), "LC_NAME");
305 else if (arg
->tok
!= tok_lc_name
)
306 lr_error (ldfile
, _("\
307 %1$s: definition does not end with `END %1$s'"), "LC_NAME");
308 lr_ignore_rest (ldfile
, arg
->tok
== tok_lc_name
);
313 SYNTAX_ERROR (_("%s: syntax error"), "LC_NAME");
316 /* Prepare for the next round. */
317 now
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
321 /* When we come here we reached the end of the file. */
322 lr_error (ldfile
, _("%s: premature end of file"), "LC_NAME");