]>
git.ipfire.org Git - thirdparty/glibc.git/blob - locale/programs/ld-messages.c
1 /* Copyright (C) 1995-1999, 2000, 2001, 2002 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@gnu.org>, 1995.
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
25 #include <sys/types.h>
32 #include "localedef.h"
33 #include "linereader.h"
34 #include "localeinfo.h"
38 /* The real definition of the struct for the LC_MESSAGES locale. */
39 struct locale_messages_t
49 messages_startup (struct linereader
*lr
, struct localedef_t
*locale
,
53 locale
->categories
[LC_MESSAGES
].messages
=
54 (struct locale_messages_t
*) xcalloc (1,
55 sizeof (struct locale_messages_t
));
59 lr
->translate_strings
= 1;
60 lr
->return_widestr
= 0;
66 messages_finish (struct localedef_t
*locale
, const struct charmap_t
*charmap
)
68 struct locale_messages_t
*messages
69 = locale
->categories
[LC_MESSAGES
].messages
;
72 /* Now resolve copying and also handle completely missing definitions. */
75 /* First see whether we were supposed to copy. If yes, find the
77 if (locale
->copy_name
[LC_MESSAGES
] != NULL
)
79 /* Find the copying locale. This has to happen transitively since
80 the locale we are copying from might also copying another one. */
81 struct localedef_t
*from
= locale
;
84 from
= find_locale (LC_MESSAGES
, from
->copy_name
[LC_MESSAGES
],
85 from
->repertoire_name
, charmap
);
86 while (from
->categories
[LC_MESSAGES
].messages
== NULL
87 && from
->copy_name
[LC_MESSAGES
] != NULL
);
89 messages
= locale
->categories
[LC_MESSAGES
].messages
90 = from
->categories
[LC_MESSAGES
].messages
;
93 /* If there is still no definition issue an warning and create an
98 WITH_CUR_LOCALE (error (0, 0, _("\
99 No definition for %s category found"), "LC_MESSAGES"));
100 messages_startup (NULL
, locale
, 0);
101 messages
= locale
->categories
[LC_MESSAGES
].messages
;
106 /* The fields YESSTR and NOSTR are optional. */
107 if (messages
->yesstr
== NULL
)
108 messages
->yesstr
= "";
109 if (messages
->nostr
== NULL
)
110 messages
->nostr
= "";
112 if (messages
->yesexpr
== NULL
)
114 if (! be_quiet
&& ! nothing
)
115 WITH_CUR_LOCALE (error (0, 0, _("%s: field `%s' undefined"),
116 "LC_MESSAGES", "yesexpr"));
117 messages
->yesexpr
= "^[yY]";
119 else if (messages
->yesexpr
[0] == '\0')
122 WITH_CUR_LOCALE (error (0, 0, _("\
123 %s: value for field `%s' must not be an empty string"),
124 "LC_MESSAGES", "yesexpr"));
131 /* Test whether it are correct regular expressions. */
132 result
= regcomp (&re
, messages
->yesexpr
, REG_EXTENDED
);
133 if (result
!= 0 && !be_quiet
)
137 (void) regerror (result
, &re
, errbuf
, BUFSIZ
);
138 WITH_CUR_LOCALE (error (0, 0, _("\
139 %s: no correct regular expression for field `%s': %s"),
140 "LC_MESSAGES", "yesexpr", errbuf
));
142 else if (result
!= 0)
146 if (messages
->noexpr
== NULL
)
148 if (! be_quiet
&& ! nothing
)
149 WITH_CUR_LOCALE (error (0, 0, _("%s: field `%s' undefined"),
150 "LC_MESSAGES", "noexpr"));
151 messages
->noexpr
= "^[nN]";
153 else if (messages
->noexpr
[0] == '\0')
156 WITH_CUR_LOCALE (error (0, 0, _("\
157 %s: value for field `%s' must not be an empty string"),
158 "LC_MESSAGES", "noexpr"));
165 /* Test whether it are correct regular expressions. */
166 result
= regcomp (&re
, messages
->noexpr
, REG_EXTENDED
);
167 if (result
!= 0 && !be_quiet
)
171 (void) regerror (result
, &re
, errbuf
, BUFSIZ
);
172 WITH_CUR_LOCALE (error (0, 0, _("\
173 %s: no correct regular expression for field `%s': %s"),
174 "LC_MESSAGES", "noexpr", errbuf
));
176 else if (result
!= 0)
183 messages_output (struct localedef_t
*locale
, const struct charmap_t
*charmap
,
184 const char *output_path
)
186 struct locale_messages_t
*messages
187 = locale
->categories
[LC_MESSAGES
].messages
;
188 struct iovec iov
[2 + _NL_ITEM_INDEX (_NL_NUM_LC_MESSAGES
)];
189 struct locale_file data
;
190 uint32_t idx
[_NL_ITEM_INDEX (_NL_NUM_LC_MESSAGES
)];
193 data
.magic
= LIMAGIC (LC_MESSAGES
);
194 data
.n
= _NL_ITEM_INDEX (_NL_NUM_LC_MESSAGES
);
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
= (char *) messages
->yesexpr
;
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
= (char *) messages
->noexpr
;
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
= (char *) messages
->yesstr
;
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
= (char *) messages
->nostr
;
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
= (char *) charmap
->code_set_name
;
225 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
227 assert (cnt
+ 1 == 2 + _NL_ITEM_INDEX (_NL_NUM_LC_MESSAGES
));
229 write_locale_data (output_path
, LC_MESSAGES
, "LC_MESSAGES",
230 2 + _NL_ITEM_INDEX (_NL_NUM_LC_MESSAGES
), iov
);
234 /* The parser for the LC_MESSAGES section of the locale definition. */
236 messages_read (struct linereader
*ldfile
, struct localedef_t
*result
,
237 const struct charmap_t
*charmap
, const char *repertoire_name
,
240 struct repertoire_t
*repertoire
= NULL
;
241 struct locale_messages_t
*messages
;
245 /* Get the repertoire we have to use. */
246 if (repertoire_name
!= NULL
)
247 repertoire
= repertoire_read (repertoire_name
);
249 /* The rest of the line containing `LC_MESSAGES' must be free. */
250 lr_ignore_rest (ldfile
, 1);
255 now
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
258 while (nowtok
== tok_eol
);
260 /* If we see `copy' now we are almost done. */
261 if (nowtok
== tok_copy
)
263 handle_copy (ldfile
, charmap
, repertoire_name
, result
, tok_lc_messages
,
264 LC_MESSAGES
, "LC_MESSAGES", ignore_content
);
268 /* Prepare the data structures. */
269 messages_startup (ldfile
, result
, ignore_content
);
270 messages
= result
->categories
[LC_MESSAGES
].messages
;
276 /* Of course we don't proceed beyond the end of file. */
277 if (nowtok
== tok_eof
)
280 /* Ignore empty lines. */
281 if (nowtok
== tok_eol
)
283 now
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
290 #define STR_ELEM(cat) \
292 /* Ignore the rest of the line if we don't need the input of \
294 if (ignore_content) \
296 lr_ignore_rest (ldfile, 0); \
300 if (messages->cat != NULL) \
302 lr_error (ldfile, _("\
303 %s: field `%s' declared more than once"), "LC_MESSAGES", #cat); \
304 lr_ignore_rest (ldfile, 0); \
307 now = lr_token (ldfile, charmap, result, repertoire, verbose); \
308 if (now->tok != tok_string) \
310 else if (!ignore_content && now->val.str.startmb == NULL) \
312 lr_error (ldfile, _("\
313 %s: unknown character in field `%s'"), "LC_MESSAGES", #cat); \
314 messages->cat = ""; \
316 else if (!ignore_content) \
317 messages->cat = now->val.str.startmb; \
326 /* Next we assume `LC_MESSAGES'. */
327 arg
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
328 if (arg
->tok
== tok_eof
)
330 if (arg
->tok
== tok_eol
)
331 lr_error (ldfile
, _("%s: incomplete `END' line"), "LC_MESSAGES");
332 else if (arg
->tok
!= tok_lc_messages
)
333 lr_error (ldfile
, _("\
334 %1$s: definition does not end with `END %1$s'"), "LC_MESSAGES");
335 lr_ignore_rest (ldfile
, arg
->tok
== tok_lc_messages
);
340 SYNTAX_ERROR (_("%s: syntax error"), "LC_MESSAGES");
343 /* Prepare for the next round. */
344 now
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
348 /* When we come here we reached the end of the file. */
349 lr_error (ldfile
, _("%s: premature end of file"), "LC_MESSAGES");