1 /* Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
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. */
31 #include "localeinfo.h"
35 /* The real definition of the struct for the LC_TELEPHONE locale. */
36 struct locale_telephone_t
38 const char *tel_int_fmt
;
39 const char *tel_dom_fmt
;
40 const char *int_select
;
41 const char *int_prefix
;
46 telephone_startup (struct linereader
*lr
, struct localedef_t
*locale
,
50 locale
->categories
[LC_TELEPHONE
].telephone
= (struct locale_telephone_t
*)
51 xcalloc (1, sizeof (struct locale_telephone_t
));
55 lr
->translate_strings
= 1;
56 lr
->return_widestr
= 0;
62 telephone_finish (struct localedef_t
*locale
, struct charmap_t
*charmap
)
64 struct locale_telephone_t
*telephone
=
65 locale
->categories
[LC_TELEPHONE
].telephone
;
68 /* Now resolve copying and also handle completely missing definitions. */
69 if (telephone
== NULL
)
71 /* First see whether we were supposed to copy. If yes, find the
73 if (locale
->copy_name
[LC_TELEPHONE
] != NULL
)
75 /* Find the copying locale. This has to happen transitively since
76 the locale we are copying from might also copying another one. */
77 struct localedef_t
*from
= locale
;
80 from
= find_locale (LC_TELEPHONE
, from
->copy_name
[LC_TELEPHONE
],
81 from
->repertoire_name
, charmap
);
82 while (from
->categories
[LC_TELEPHONE
].telephone
== NULL
83 && from
->copy_name
[LC_TELEPHONE
] != NULL
);
85 telephone
= locale
->categories
[LC_TELEPHONE
].telephone
86 = from
->categories
[LC_TELEPHONE
].telephone
;
89 /* If there is still no definition issue an warning and create an
91 if (telephone
== NULL
)
94 error (0, 0, _("No definition for %s category found"),
96 telephone_startup (NULL
, locale
, 0);
97 telephone
= locale
->categories
[LC_TELEPHONE
].telephone
;
102 if (telephone
->tel_int_fmt
== NULL
)
105 error (0, 0, _("%s: field `%s' not defined"),
106 "LC_TELEPHONE", "tel_int_fmt");
107 /* Use as the default value the value of the i18n locale. */
108 telephone
->tel_int_fmt
= "+%c %a %l";
112 /* We must check whether the format string contains only the
113 allowed escape sequences. */
114 const char *cp
= telephone
->tel_int_fmt
;
117 error (0, 0, _("%s: field `%s' must not be empty"),
118 "LC_TELEPHONE", "tel_int_fmt");
124 if (strchr ("aAlc", *++cp
) == NULL
)
127 %s: invalid escape sequence in field `%s'"),
128 "LC_TELEPHONE", "tel_int_fmt");
136 if (telephone
->tel_dom_fmt
== NULL
)
137 telephone
->tel_dom_fmt
= "";
138 else if (telephone
->tel_dom_fmt
[0] != '\0')
140 /* We must check whether the format string contains only the
141 allowed escape sequences. */
142 const char *cp
= telephone
->tel_dom_fmt
;
148 if (strchr ("aAlc", *++cp
) == NULL
)
150 error (0, 0, _("%s: invalid escape sequence in field `%s'"),
151 "LC_TELEPHONE", "tel_dom_fmt");
159 #define TEST_ELEM(cat) \
160 if (telephone->cat == NULL) \
162 if (verbose && ! nothing) \
163 error (0, 0, _("%s: field `%s' not defined"), "LC_TELEPHONE", #cat); \
164 telephone->cat = ""; \
167 TEST_ELEM (int_select
);
168 TEST_ELEM (int_prefix
);
173 telephone_output (struct localedef_t
*locale
, struct charmap_t
*charmap
,
174 const char *output_path
)
176 struct locale_telephone_t
*telephone
=
177 locale
->categories
[LC_TELEPHONE
].telephone
;
178 struct iovec iov
[2 + _NL_ITEM_INDEX (_NL_NUM_LC_TELEPHONE
)];
179 struct locale_file data
;
180 uint32_t idx
[_NL_ITEM_INDEX (_NL_NUM_LC_TELEPHONE
)];
183 data
.magic
= LIMAGIC (LC_TELEPHONE
);
184 data
.n
= _NL_ITEM_INDEX (_NL_NUM_LC_TELEPHONE
);
185 iov
[cnt
].iov_base
= (void *) &data
;
186 iov
[cnt
].iov_len
= sizeof (data
);
189 iov
[cnt
].iov_base
= (void *) idx
;
190 iov
[cnt
].iov_len
= sizeof (idx
);
193 idx
[cnt
- 2] = iov
[0].iov_len
+ iov
[1].iov_len
;
194 iov
[cnt
].iov_base
= (void *) telephone
->tel_int_fmt
;
195 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
198 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
199 iov
[cnt
].iov_base
= (void *) telephone
->tel_dom_fmt
;
200 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
203 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
204 iov
[cnt
].iov_base
= (void *) telephone
->int_select
;
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
= (void *) telephone
->int_prefix
;
210 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
213 assert (cnt
== 2 + _NL_ITEM_INDEX (_NL_NUM_LC_TELEPHONE
));
215 write_locale_data (output_path
, "LC_TELEPHONE",
216 2 + _NL_ITEM_INDEX (_NL_NUM_LC_TELEPHONE
), iov
);
220 /* The parser for the LC_TELEPHONE section of the locale definition. */
222 telephone_read (struct linereader
*ldfile
, struct localedef_t
*result
,
223 struct charmap_t
*charmap
, const char *repertoire_name
,
226 struct locale_telephone_t
*telephone
;
231 /* The rest of the line containing `LC_TELEPHONE' must be free. */
232 lr_ignore_rest (ldfile
, 1);
236 now
= lr_token (ldfile
, charmap
, NULL
);
239 while (nowtok
== tok_eol
);
241 /* If we see `copy' now we are almost done. */
242 if (nowtok
== tok_copy
)
244 handle_copy (ldfile
, charmap
, repertoire_name
, result
, tok_lc_telephone
,
245 LC_TELEPHONE
, "LC_TELEPHONE", ignore_content
);
249 /* Prepare the data structures. */
250 telephone_startup (ldfile
, result
, ignore_content
);
251 telephone
= result
->categories
[LC_TELEPHONE
].telephone
;
255 /* Of course we don't proceed beyond the end of file. */
256 if (nowtok
== tok_eof
)
259 /* Ingore empty lines. */
260 if (nowtok
== tok_eol
)
262 now
= lr_token (ldfile
, charmap
, NULL
);
269 #define STR_ELEM(cat) \
271 /* Ignore the rest of the line if we don't need the input of \
273 if (ignore_content) \
275 lr_ignore_rest (ldfile, 0); \
279 arg = lr_token (ldfile, charmap, NULL); \
280 if (arg->tok != tok_string) \
282 if (telephone->cat != NULL) \
283 lr_error (ldfile, _("%s: field `%s' declared more than once"), \
284 "LC_TELEPHONE", #cat); \
285 else if (!ignore_content && arg->val.str.startmb == NULL) \
287 lr_error (ldfile, _("%s: unknown character in field `%s'"), \
288 "LC_TELEPHONE", #cat); \
289 telephone->cat = ""; \
291 else if (!ignore_content) \
292 telephone->cat = arg->val.str.startmb; \
295 STR_ELEM (tel_int_fmt
);
296 STR_ELEM (tel_dom_fmt
);
297 STR_ELEM (int_select
);
298 STR_ELEM (int_prefix
);
301 /* Next we assume `LC_TELEPHONE'. */
302 arg
= lr_token (ldfile
, charmap
, NULL
);
303 if (arg
->tok
== tok_eof
)
305 if (arg
->tok
== tok_eol
)
306 lr_error (ldfile
, _("%s: incomplete `END' line"), "LC_TELEPHONE");
307 else if (arg
->tok
!= tok_lc_telephone
)
308 lr_error (ldfile
, _("\
309 %1$s: definition does not end with `END %1$s'"), "LC_TELEPHONE");
310 lr_ignore_rest (ldfile
, arg
->tok
== tok_lc_telephone
);
315 SYNTAX_ERROR (_("%s: syntax error"), "LC_TELEPHONE");
318 /* Prepare for the next round. */
319 now
= lr_token (ldfile
, charmap
, NULL
);
323 /* When we come here we reached the end of the file. */
324 lr_error (ldfile
, _("%s: premature end of file"), "LC_TELEPHONE");