1 /* Copyright (C) 1998-2018 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; version 2 of the License, or
8 (at your option) any later version.
10 This program 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
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, see <http://www.gnu.org/licenses/>. */
29 #include "localedef.h"
30 #include "localeinfo.h"
34 /* The real definition of the struct for the LC_MEASUREMENT locale. */
35 struct locale_measurement_t
37 unsigned char measurement
;
42 measurement_startup (struct linereader
*lr
, struct localedef_t
*locale
,
46 locale
->categories
[LC_MEASUREMENT
].measurement
=
47 (struct locale_measurement_t
*)
48 xcalloc (1, sizeof (struct locale_measurement_t
));
52 lr
->translate_strings
= 1;
53 lr
->return_widestr
= 0;
59 measurement_finish (struct localedef_t
*locale
,
60 const struct charmap_t
*charmap
)
62 struct locale_measurement_t
*measurement
=
63 locale
->categories
[LC_MEASUREMENT
].measurement
;
66 /* Now resolve copying and also handle completely missing definitions. */
67 if (measurement
== NULL
)
69 /* First see whether we were supposed to copy. If yes, find the
71 if (locale
->copy_name
[LC_MEASUREMENT
] != 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_MEASUREMENT
,
79 from
->copy_name
[LC_MEASUREMENT
],
80 from
->repertoire_name
, charmap
);
81 while (from
->categories
[LC_MEASUREMENT
].measurement
== NULL
82 && from
->copy_name
[LC_MEASUREMENT
] != NULL
);
84 measurement
= locale
->categories
[LC_MEASUREMENT
].measurement
85 = from
->categories
[LC_MEASUREMENT
].measurement
;
88 /* If there is still no definition issue an warning and create an
90 if (measurement
== NULL
)
93 No definition for %s category found"), "LC_MEASUREMENT");
94 measurement_startup (NULL
, locale
, 0);
95 measurement
= locale
->categories
[LC_MEASUREMENT
].measurement
;
100 if (measurement
->measurement
== 0)
103 record_error (0, 0, _("%s: field `%s' not defined"),
104 "LC_MEASUREMENT", "measurement");
105 /* Use as the default value the value of the i18n locale. */
106 measurement
->measurement
= 1;
110 if (measurement
->measurement
> 3)
111 record_error (0, 0, _("%s: invalid value for field `%s'"),
112 "LC_MEASUREMENT", "measurement");
118 measurement_output (struct localedef_t
*locale
,
119 const struct charmap_t
*charmap
, const char *output_path
)
121 struct locale_measurement_t
*measurement
=
122 locale
->categories
[LC_MEASUREMENT
].measurement
;
123 struct locale_file file
;
125 init_locale_data (&file
, _NL_ITEM_INDEX (_NL_NUM_LC_MEASUREMENT
));
126 add_locale_char (&file
, measurement
->measurement
);
127 add_locale_string (&file
, charmap
->code_set_name
);
128 write_locale_data (output_path
, LC_MEASUREMENT
, "LC_MEASUREMENT", &file
);
132 /* The parser for the LC_MEASUREMENT section of the locale definition. */
134 measurement_read (struct linereader
*ldfile
, struct localedef_t
*result
,
135 const struct charmap_t
*charmap
, const char *repertoire_name
,
138 struct locale_measurement_t
*measurement
;
143 /* The rest of the line containing `LC_MEASUREMENT' must be free. */
144 lr_ignore_rest (ldfile
, 1);
148 now
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
151 while (nowtok
== tok_eol
);
153 /* If we see `copy' now we are almost done. */
154 if (nowtok
== tok_copy
)
156 handle_copy (ldfile
, charmap
, repertoire_name
, result
,
157 tok_lc_measurement
, LC_MEASUREMENT
, "LC_MEASUREMENT",
162 /* Prepare the data structures. */
163 measurement_startup (ldfile
, result
, ignore_content
);
164 measurement
= result
->categories
[LC_MEASUREMENT
].measurement
;
168 /* Of course we don't proceed beyond the end of file. */
169 if (nowtok
== tok_eof
)
172 /* Ingore empty lines. */
173 if (nowtok
== tok_eol
)
175 now
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
182 #define INT_ELEM(cat) \
184 /* Ignore the rest of the line if we don't need the input of \
186 if (ignore_content) \
188 lr_ignore_rest (ldfile, 0); \
192 arg = lr_token (ldfile, charmap, result, NULL, verbose); \
193 if (arg->tok != tok_number) \
195 else if (measurement->cat != 0) \
196 lr_error (ldfile, _("%s: field `%s' declared more than once"), \
197 "LC_MEASUREMENT", #cat); \
198 else if (!ignore_content) \
199 measurement->cat = arg->val.num; \
202 INT_ELEM (measurement
);
205 /* Next we assume `LC_MEASUREMENT'. */
206 arg
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
207 if (arg
->tok
== tok_eof
)
209 if (arg
->tok
== tok_eol
)
210 lr_error (ldfile
, _("%s: incomplete `END' line"),
212 else if (arg
->tok
!= tok_lc_measurement
)
213 lr_error (ldfile
, _("\
214 %1$s: definition does not end with `END %1$s'"), "LC_MEASUREMENT");
215 lr_ignore_rest (ldfile
, arg
->tok
== tok_lc_measurement
);
220 SYNTAX_ERROR (_("%s: syntax error"), "LC_MEASUREMENT");
223 /* Prepare for the next round. */
224 now
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
228 /* When we come here we reached the end of the file. */
229 lr_error (ldfile
, _("%s: premature end of file"),