1 /* Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 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 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
35 /* Undefine following line in production version. */
36 /* #define NDEBUG 1 */
40 #include "stringtrans.h"
41 #include "localeinfo.h"
44 extern void *xmalloc (size_t __n
);
47 /* The real definition of the struct for the LC_MESSAGES locale. */
48 struct locale_messages_t
58 messages_startup (struct linereader
*lr
, struct localedef_t
*locale
,
59 struct charset_t
*charset
)
61 struct locale_messages_t
*messages
;
63 /* We have a definition for LC_MESSAGES. */
64 copy_posix
.mask
&= ~(1 << LC_MESSAGES
);
66 /* It is important that we always use UCS1 encoding for strings now. */
67 encoding_method
= ENC_UCS1
;
69 locale
->categories
[LC_MESSAGES
].messages
= messages
=
70 (struct locale_messages_t
*) xmalloc (sizeof (struct locale_messages_t
));
72 memset (messages
, '\0', sizeof (struct locale_messages_t
));
77 messages_finish (struct localedef_t
*locale
)
79 struct locale_messages_t
*messages
80 = locale
->categories
[LC_MESSAGES
].messages
;
82 /* The fields YESSTR and NOSTR are optional. */
83 if (messages
->yesexpr
== NULL
)
86 error (0, 0, _("field `%s' in category `%s' undefined"),
87 "yesexpr", "LC_MESSAGES");
94 /* Test whether it are correct regular expressions. */
95 result
= regcomp (&re
, messages
->yesexpr
, REG_EXTENDED
);
96 if (result
!= 0 && !be_quiet
)
100 (void) regerror (result
, &re
, errbuf
, BUFSIZ
);
102 no correct regular expression for field `%s' in category `%s': %s"),
103 "yesexpr", "LC_MESSAGES", errbuf
);
107 if (messages
->noexpr
== NULL
)
110 error (0, 0, _("field `%s' in category `%s' undefined"),
111 "noexpr", "LC_MESSAGES");
118 /* Test whether it are correct regular expressions. */
119 result
= regcomp (&re
, messages
->noexpr
, REG_EXTENDED
);
120 if (result
!= 0 && !be_quiet
)
124 (void) regerror (result
, &re
, errbuf
, BUFSIZ
);
126 no correct regular expression for field `%s' in category `%s': %s"),
127 "noexpr", "LC_MESSAGES", errbuf
);
134 messages_output (struct localedef_t
*locale
, const char *output_path
)
136 struct locale_messages_t
*messages
137 = locale
->categories
[LC_MESSAGES
].messages
;
138 struct iovec iov
[2 + _NL_ITEM_INDEX (_NL_NUM_LC_MESSAGES
)];
139 struct locale_file data
;
140 u_int32_t idx
[_NL_ITEM_INDEX (_NL_NUM_LC_MESSAGES
)];
143 if ((locale
->binary
& (1 << LC_MESSAGES
)) != 0)
145 iov
[0].iov_base
= messages
;
146 iov
[0].iov_len
= locale
->len
[LC_MESSAGES
];
148 write_locale_data (output_path
, "LC_MESSAGES", 1, iov
);
153 data
.magic
= LIMAGIC (LC_MESSAGES
);
154 data
.n
= _NL_ITEM_INDEX (_NL_NUM_LC_MESSAGES
);
155 iov
[cnt
].iov_base
= (void *) &data
;
156 iov
[cnt
].iov_len
= sizeof (data
);
159 iov
[cnt
].iov_base
= (void *) idx
;
160 iov
[cnt
].iov_len
= sizeof (idx
);
163 idx
[cnt
- 2] = iov
[0].iov_len
+ iov
[1].iov_len
;
164 iov
[cnt
].iov_base
= (void *) (messages
->yesexpr
?: "");
165 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
168 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
169 iov
[cnt
].iov_base
= (void *) (messages
->noexpr
?: "");
170 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
173 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
174 iov
[cnt
].iov_base
= (void *) (messages
->yesstr
?: "");
175 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
178 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
179 iov
[cnt
].iov_base
= (void *) (messages
->nostr
?: "");
180 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
182 assert (cnt
+ 1 == 2 + _NL_ITEM_INDEX (_NL_NUM_LC_MESSAGES
));
184 write_locale_data (output_path
, "LC_MESSAGES",
185 2 + _NL_ITEM_INDEX (_NL_NUM_LC_MESSAGES
), iov
);
190 messages_add (struct linereader
*lr
, struct localedef_t
*locale
,
191 enum token_t tok
, struct token
*code
,
192 struct charset_t
*charset
)
194 struct locale_messages_t
*messages
195 = locale
->categories
[LC_MESSAGES
].messages
;
200 if (code
->val
.str
.start
== NULL
)
202 lr_error (lr
, _("unknown character in field `%s' of category `%s'"),
203 "yesexpr", "LC_MESSAGES");
204 messages
->yesexpr
= "";
207 messages
->yesexpr
= code
->val
.str
.start
;
211 if (code
->val
.str
.start
== NULL
)
213 lr_error (lr
, _("unknown character in field `%s' of category `%s'"),
214 "noexpr", "LC_MESSAGES");
215 messages
->noexpr
= "";
218 messages
->noexpr
= code
->val
.str
.start
;
222 if (code
->val
.str
.start
== NULL
)
224 lr_error (lr
, _("unknown character in field `%s' of category `%s'"),
225 "yesstr", "LC_MESSAGES");
226 messages
->yesstr
= "";
229 messages
->yesstr
= code
->val
.str
.start
;
233 if (code
->val
.str
.start
== NULL
)
235 lr_error (lr
, _("unknown character in field `%s' of category `%s'"),
236 "nostr", "LC_MESSAGES");
237 messages
->nostr
= "";
240 messages
->nostr
= code
->val
.str
.start
;
244 assert (! "unknown token in category `LC_MESSAGES': should not happen");