1 /* Copyright (C) 1998-2023 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published
6 by the Free Software Foundation; version 2 of the License, or
7 (at your option) any later version.
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, see <https://www.gnu.org/licenses/>. */
28 #include "localedef.h"
29 #include "localeinfo.h"
33 /* The real definition of the struct for the LC_TELEPHONE locale. */
34 struct locale_telephone_t
36 const char *tel_int_fmt
;
37 const char *tel_dom_fmt
;
38 const char *int_select
;
39 const char *int_prefix
;
44 telephone_startup (struct linereader
*lr
, struct localedef_t
*locale
,
48 locale
->categories
[LC_TELEPHONE
].telephone
= (struct locale_telephone_t
*)
49 xcalloc (1, sizeof (struct locale_telephone_t
));
53 lr
->translate_strings
= 1;
54 lr
->return_widestr
= 0;
60 telephone_finish (struct localedef_t
*locale
, const struct charmap_t
*charmap
)
62 struct locale_telephone_t
*telephone
=
63 locale
->categories
[LC_TELEPHONE
].telephone
;
66 /* Now resolve copying and also handle completely missing definitions. */
67 if (telephone
== NULL
)
69 /* First see whether we were supposed to copy. If yes, find the
71 if (locale
->copy_name
[LC_TELEPHONE
] != NULL
)
73 /* Find the copying locale. This has to happen transitively since
74 the locale we are copying from might also copying another one. */
75 struct localedef_t
*from
= locale
;
78 from
= find_locale (LC_TELEPHONE
, from
->copy_name
[LC_TELEPHONE
],
79 from
->repertoire_name
, charmap
);
80 while (from
->categories
[LC_TELEPHONE
].telephone
== NULL
81 && from
->copy_name
[LC_TELEPHONE
] != NULL
);
83 telephone
= locale
->categories
[LC_TELEPHONE
].telephone
84 = from
->categories
[LC_TELEPHONE
].telephone
;
87 /* If there is still no definition issue an warning and create an
89 if (telephone
== NULL
)
92 No definition for %s category found"), "LC_TELEPHONE");
93 telephone_startup (NULL
, locale
, 0);
94 telephone
= locale
->categories
[LC_TELEPHONE
].telephone
;
99 if (telephone
->tel_int_fmt
== NULL
)
102 record_error (0, 0, _("%s: field `%s' not defined"),
103 "LC_TELEPHONE", "tel_int_fmt");
104 /* Use as the default value the value of the i18n locale. */
105 telephone
->tel_int_fmt
= "+%c %a%t%l";
109 /* We must check whether the format string contains only the
110 allowed escape sequences. */
111 const char *cp
= telephone
->tel_int_fmt
;
114 record_error (0, 0, _("%s: field `%s' must not be empty"),
115 "LC_TELEPHONE", "tel_int_fmt");
121 if (strchr ("aAcCelt", *++cp
) == NULL
)
123 record_error (0, 0, _("\
124 %s: invalid escape sequence in field `%s'"), "LC_TELEPHONE", "tel_int_fmt");
132 if (telephone
->tel_dom_fmt
== NULL
)
133 telephone
->tel_dom_fmt
= "";
134 else if (telephone
->tel_dom_fmt
[0] != '\0')
136 /* We must check whether the format string contains only the
137 allowed escape sequences. */
138 const char *cp
= telephone
->tel_dom_fmt
;
144 if (strchr ("aAcCelt", *++cp
) == NULL
)
146 record_error (0, 0, _("\
147 %s: invalid escape sequence in field `%s'"), "LC_TELEPHONE", "tel_dom_fmt");
155 #define TEST_ELEM(cat) \
156 if (telephone->cat == NULL) \
158 if (verbose && ! nothing) \
159 record_warning (_("%s: field `%s' not defined"), "LC_TELEPHONE", \
161 telephone->cat = ""; \
164 TEST_ELEM (int_select
);
165 TEST_ELEM (int_prefix
);
170 telephone_output (struct localedef_t
*locale
, const struct charmap_t
*charmap
,
171 const char *output_path
)
173 struct locale_telephone_t
*telephone
=
174 locale
->categories
[LC_TELEPHONE
].telephone
;
175 struct locale_file file
;
177 init_locale_data (&file
, _NL_ITEM_INDEX (_NL_NUM_LC_TELEPHONE
));
178 add_locale_string (&file
, telephone
->tel_int_fmt
);
179 add_locale_string (&file
, telephone
->tel_dom_fmt
);
180 add_locale_string (&file
, telephone
->int_select
);
181 add_locale_string (&file
, telephone
->int_prefix
);
182 add_locale_string (&file
, charmap
->code_set_name
);
183 write_locale_data (output_path
, LC_TELEPHONE
, "LC_TELEPHONE", &file
);
187 /* The parser for the LC_TELEPHONE section of the locale definition. */
189 telephone_read (struct linereader
*ldfile
, struct localedef_t
*result
,
190 const struct charmap_t
*charmap
, const char *repertoire_name
,
193 struct locale_telephone_t
*telephone
;
198 /* The rest of the line containing `LC_TELEPHONE' must be free. */
199 lr_ignore_rest (ldfile
, 1);
203 now
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
206 while (nowtok
== tok_eol
);
208 /* If we see `copy' now we are almost done. */
209 if (nowtok
== tok_copy
)
211 handle_copy (ldfile
, charmap
, repertoire_name
, result
, tok_lc_telephone
,
212 LC_TELEPHONE
, "LC_TELEPHONE", ignore_content
);
216 /* Prepare the data structures. */
217 telephone_startup (ldfile
, result
, ignore_content
);
218 telephone
= result
->categories
[LC_TELEPHONE
].telephone
;
222 /* Of course we don't proceed beyond the end of file. */
223 if (nowtok
== tok_eof
)
226 /* Ingore empty lines. */
227 if (nowtok
== tok_eol
)
229 now
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
236 #define STR_ELEM(cat) \
238 /* Ignore the rest of the line if we don't need the input of \
240 if (ignore_content) \
242 lr_ignore_rest (ldfile, 0); \
246 arg = lr_token (ldfile, charmap, result, NULL, verbose); \
247 if (arg->tok != tok_string) \
249 if (telephone->cat != NULL) \
250 lr_error (ldfile, _("%s: field `%s' declared more than once"), \
251 "LC_TELEPHONE", #cat); \
252 else if (!ignore_content && arg->val.str.startmb == NULL) \
254 lr_error (ldfile, _("%s: unknown character in field `%s'"), \
255 "LC_TELEPHONE", #cat); \
256 telephone->cat = ""; \
258 else if (!ignore_content) \
259 telephone->cat = arg->val.str.startmb; \
262 STR_ELEM (tel_int_fmt
);
263 STR_ELEM (tel_dom_fmt
);
264 STR_ELEM (int_select
);
265 STR_ELEM (int_prefix
);
268 /* Next we assume `LC_TELEPHONE'. */
269 arg
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
270 if (arg
->tok
== tok_eof
)
272 if (arg
->tok
== tok_eol
)
273 lr_error (ldfile
, _("%s: incomplete `END' line"), "LC_TELEPHONE");
274 else if (arg
->tok
!= tok_lc_telephone
)
275 lr_error (ldfile
, _("\
276 %1$s: definition does not end with `END %1$s'"), "LC_TELEPHONE");
277 lr_ignore_rest (ldfile
, arg
->tok
== tok_lc_telephone
);
282 SYNTAX_ERROR (_("%s: syntax error"), "LC_TELEPHONE");
285 /* Prepare for the next round. */
286 now
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
290 /* When we come here we reached the end of the file. */
291 lr_error (ldfile
, _("%s: premature end of file"), "LC_TELEPHONE");