]>
git.ipfire.org Git - thirdparty/glibc.git/blob - locale/programs/ld-telephone.c
1 /* Copyright (C) 1998, 1999, 2000, 2001, 2002 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 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
31 #include "localedef.h"
32 #include "localeinfo.h"
36 /* The real definition of the struct for the LC_TELEPHONE locale. */
37 struct locale_telephone_t
39 const char *tel_int_fmt
;
40 const char *tel_dom_fmt
;
41 const char *int_select
;
42 const char *int_prefix
;
47 telephone_startup (struct linereader
*lr
, struct localedef_t
*locale
,
51 locale
->categories
[LC_TELEPHONE
].telephone
= (struct locale_telephone_t
*)
52 xcalloc (1, sizeof (struct locale_telephone_t
));
56 lr
->translate_strings
= 1;
57 lr
->return_widestr
= 0;
63 telephone_finish (struct localedef_t
*locale
, const struct charmap_t
*charmap
)
65 struct locale_telephone_t
*telephone
=
66 locale
->categories
[LC_TELEPHONE
].telephone
;
69 /* Now resolve copying and also handle completely missing definitions. */
70 if (telephone
== NULL
)
72 /* First see whether we were supposed to copy. If yes, find the
74 if (locale
->copy_name
[LC_TELEPHONE
] != NULL
)
76 /* Find the copying locale. This has to happen transitively since
77 the locale we are copying from might also copying another one. */
78 struct localedef_t
*from
= locale
;
81 from
= find_locale (LC_TELEPHONE
, from
->copy_name
[LC_TELEPHONE
],
82 from
->repertoire_name
, charmap
);
83 while (from
->categories
[LC_TELEPHONE
].telephone
== NULL
84 && from
->copy_name
[LC_TELEPHONE
] != NULL
);
86 telephone
= locale
->categories
[LC_TELEPHONE
].telephone
87 = from
->categories
[LC_TELEPHONE
].telephone
;
90 /* If there is still no definition issue an warning and create an
92 if (telephone
== NULL
)
95 WITH_CUR_LOCALE (error (0, 0, _("\
96 No definition for %s category found"), "LC_TELEPHONE"));
97 telephone_startup (NULL
, locale
, 0);
98 telephone
= locale
->categories
[LC_TELEPHONE
].telephone
;
103 if (telephone
->tel_int_fmt
== NULL
)
106 WITH_CUR_LOCALE (error (0, 0, _("%s: field `%s' not defined"),
107 "LC_TELEPHONE", "tel_int_fmt"));
108 /* Use as the default value the value of the i18n locale. */
109 telephone
->tel_int_fmt
= "+%c %a %l";
113 /* We must check whether the format string contains only the
114 allowed escape sequences. */
115 const char *cp
= telephone
->tel_int_fmt
;
118 WITH_CUR_LOCALE (error (0, 0, _("%s: field `%s' must not be empty"),
119 "LC_TELEPHONE", "tel_int_fmt"));
125 if (strchr ("aAlc", *++cp
) == NULL
)
127 WITH_CUR_LOCALE (error (0, 0, _("\
128 %s: invalid escape sequence in field `%s'"), "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 WITH_CUR_LOCALE (error (0, 0, _("\
151 %s: invalid escape sequence in field `%s'"), "LC_TELEPHONE", "tel_dom_fmt"));
159 #define TEST_ELEM(cat) \
160 if (telephone->cat == NULL) \
162 if (verbose && ! nothing) \
163 WITH_CUR_LOCALE (error (0, 0, _("%s: field `%s' not defined"), \
164 "LC_TELEPHONE", #cat)); \
165 telephone->cat = ""; \
168 TEST_ELEM (int_select
);
169 TEST_ELEM (int_prefix
);
174 telephone_output (struct localedef_t
*locale
, const struct charmap_t
*charmap
,
175 const char *output_path
)
177 struct locale_telephone_t
*telephone
=
178 locale
->categories
[LC_TELEPHONE
].telephone
;
179 struct iovec iov
[2 + _NL_ITEM_INDEX (_NL_NUM_LC_TELEPHONE
)];
180 struct locale_file data
;
181 uint32_t idx
[_NL_ITEM_INDEX (_NL_NUM_LC_TELEPHONE
)];
184 data
.magic
= LIMAGIC (LC_TELEPHONE
);
185 data
.n
= _NL_ITEM_INDEX (_NL_NUM_LC_TELEPHONE
);
186 iov
[cnt
].iov_base
= (void *) &data
;
187 iov
[cnt
].iov_len
= sizeof (data
);
190 iov
[cnt
].iov_base
= (void *) idx
;
191 iov
[cnt
].iov_len
= sizeof (idx
);
194 idx
[cnt
- 2] = iov
[0].iov_len
+ iov
[1].iov_len
;
195 iov
[cnt
].iov_base
= (void *) telephone
->tel_int_fmt
;
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 *) telephone
->tel_dom_fmt
;
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 *) telephone
->int_select
;
206 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
209 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
210 iov
[cnt
].iov_base
= (void *) telephone
->int_prefix
;
211 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
214 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
215 iov
[cnt
].iov_base
= (void *) charmap
->code_set_name
;;
216 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
219 assert (cnt
== 2 + _NL_ITEM_INDEX (_NL_NUM_LC_TELEPHONE
));
221 write_locale_data (output_path
, LC_TELEPHONE
, "LC_TELEPHONE",
222 2 + _NL_ITEM_INDEX (_NL_NUM_LC_TELEPHONE
), iov
);
226 /* The parser for the LC_TELEPHONE section of the locale definition. */
228 telephone_read (struct linereader
*ldfile
, struct localedef_t
*result
,
229 const struct charmap_t
*charmap
, const char *repertoire_name
,
232 struct locale_telephone_t
*telephone
;
237 /* The rest of the line containing `LC_TELEPHONE' must be free. */
238 lr_ignore_rest (ldfile
, 1);
242 now
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
245 while (nowtok
== tok_eol
);
247 /* If we see `copy' now we are almost done. */
248 if (nowtok
== tok_copy
)
250 handle_copy (ldfile
, charmap
, repertoire_name
, result
, tok_lc_telephone
,
251 LC_TELEPHONE
, "LC_TELEPHONE", ignore_content
);
255 /* Prepare the data structures. */
256 telephone_startup (ldfile
, result
, ignore_content
);
257 telephone
= result
->categories
[LC_TELEPHONE
].telephone
;
261 /* Of course we don't proceed beyond the end of file. */
262 if (nowtok
== tok_eof
)
265 /* Ingore empty lines. */
266 if (nowtok
== tok_eol
)
268 now
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
275 #define STR_ELEM(cat) \
277 /* Ignore the rest of the line if we don't need the input of \
279 if (ignore_content) \
281 lr_ignore_rest (ldfile, 0); \
285 arg = lr_token (ldfile, charmap, result, NULL, verbose); \
286 if (arg->tok != tok_string) \
288 if (telephone->cat != NULL) \
289 lr_error (ldfile, _("%s: field `%s' declared more than once"), \
290 "LC_TELEPHONE", #cat); \
291 else if (!ignore_content && arg->val.str.startmb == NULL) \
293 lr_error (ldfile, _("%s: unknown character in field `%s'"), \
294 "LC_TELEPHONE", #cat); \
295 telephone->cat = ""; \
297 else if (!ignore_content) \
298 telephone->cat = arg->val.str.startmb; \
301 STR_ELEM (tel_int_fmt
);
302 STR_ELEM (tel_dom_fmt
);
303 STR_ELEM (int_select
);
304 STR_ELEM (int_prefix
);
307 /* Next we assume `LC_TELEPHONE'. */
308 arg
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
309 if (arg
->tok
== tok_eof
)
311 if (arg
->tok
== tok_eol
)
312 lr_error (ldfile
, _("%s: incomplete `END' line"), "LC_TELEPHONE");
313 else if (arg
->tok
!= tok_lc_telephone
)
314 lr_error (ldfile
, _("\
315 %1$s: definition does not end with `END %1$s'"), "LC_TELEPHONE");
316 lr_ignore_rest (ldfile
, arg
->tok
== tok_lc_telephone
);
321 SYNTAX_ERROR (_("%s: syntax error"), "LC_TELEPHONE");
324 /* Prepare for the next round. */
325 now
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
329 /* When we come here we reached the end of the file. */
330 lr_error (ldfile
, _("%s: premature end of file"), "LC_TELEPHONE");