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_MEASUREMENT locale. */
37 struct locale_measurement_t
39 unsigned char measurement;
44 measurement_startup (struct linereader *lr, struct localedef_t *locale,
48 locale->categories[LC_MEASUREMENT].measurement =
49 (struct locale_measurement_t *)
50 xcalloc (1, sizeof (struct locale_measurement_t));
54 lr->translate_strings = 1;
55 lr->return_widestr = 0;
61 measurement_finish (struct localedef_t *locale,
62 const struct charmap_t *charmap)
64 struct locale_measurement_t *measurement =
65 locale->categories[LC_MEASUREMENT].measurement;
68 /* Now resolve copying and also handle completely missing definitions. */
69 if (measurement == NULL)
71 /* First see whether we were supposed to copy. If yes, find the
73 if (locale->copy_name[LC_MEASUREMENT] != 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_MEASUREMENT,
81 from->copy_name[LC_MEASUREMENT],
82 from->repertoire_name, charmap);
83 while (from->categories[LC_MEASUREMENT].measurement == NULL
84 && from->copy_name[LC_MEASUREMENT] != NULL);
86 measurement = locale->categories[LC_MEASUREMENT].measurement
87 = from->categories[LC_MEASUREMENT].measurement;
90 /* If there is still no definition issue an warning and create an
92 if (measurement == NULL)
95 WITH_CUR_LOCALE (error (0, 0, _("\
96 No definition for %s category found"), "LC_MEASUREMENT"));
97 measurement_startup (NULL, locale, 0);
98 measurement = locale->categories[LC_MEASUREMENT].measurement;
103 if (measurement->measurement == 0)
106 WITH_CUR_LOCALE (error (0, 0, _("%s: field `%s' not defined"),
107 "LC_MEASUREMENT", "measurement"));
108 /* Use as the default value the value of the i18n locale. */
109 measurement->measurement = 1;
113 if (measurement->measurement > 3)
114 WITH_CUR_LOCALE (error (0, 0, _("%s: invalid value for field `%s'"),
115 "LC_MEASUREMENT", "measurement"));
121 measurement_output (struct localedef_t *locale,
122 const struct charmap_t *charmap, const char *output_path)
124 struct locale_measurement_t *measurement =
125 locale->categories[LC_MEASUREMENT].measurement;
126 struct iovec iov[2 + _NL_ITEM_INDEX (_NL_NUM_LC_MEASUREMENT)];
127 struct locale_file data;
128 uint32_t idx[_NL_ITEM_INDEX (_NL_NUM_LC_MEASUREMENT)];
131 data.magic = LIMAGIC (LC_MEASUREMENT);
132 data.n = _NL_ITEM_INDEX (_NL_NUM_LC_MEASUREMENT);
133 iov[cnt].iov_base = (void *) &data;
134 iov[cnt].iov_len = sizeof (data);
137 iov[cnt].iov_base = (void *) idx;
138 iov[cnt].iov_len = sizeof (idx);
141 idx[cnt - 2] = iov[0].iov_len + iov[1].iov_len;
142 iov[cnt].iov_base = &measurement->measurement;
143 iov[cnt].iov_len = 1;
146 idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len;
147 iov[cnt].iov_base = (void *) charmap->code_set_name;
148 iov[cnt].iov_len = strlen (iov[cnt].iov_base) + 1;
151 assert (cnt == 2 + _NL_ITEM_INDEX (_NL_NUM_LC_MEASUREMENT));
153 write_locale_data (output_path, LC_MEASUREMENT, "LC_MEASUREMENT",
154 2 + _NL_ITEM_INDEX (_NL_NUM_LC_MEASUREMENT), iov);
158 /* The parser for the LC_MEASUREMENT section of the locale definition. */
160 measurement_read (struct linereader *ldfile, struct localedef_t *result,
161 const struct charmap_t *charmap, const char *repertoire_name,
164 struct locale_measurement_t *measurement;
169 /* The rest of the line containing `LC_MEASUREMENT' must be free. */
170 lr_ignore_rest (ldfile, 1);
174 now = lr_token (ldfile, charmap, result, NULL, verbose);
177 while (nowtok == tok_eol);
179 /* If we see `copy' now we are almost done. */
180 if (nowtok == tok_copy)
182 handle_copy (ldfile, charmap, repertoire_name, result,
183 tok_lc_measurement, LC_MEASUREMENT, "LC_MEASUREMENT",
188 /* Prepare the data structures. */
189 measurement_startup (ldfile, result, ignore_content);
190 measurement = result->categories[LC_MEASUREMENT].measurement;
194 /* Of course we don't proceed beyond the end of file. */
195 if (nowtok == tok_eof)
198 /* Ingore empty lines. */
199 if (nowtok == tok_eol)
201 now = lr_token (ldfile, charmap, result, NULL, verbose);
208 #define INT_ELEM(cat) \
210 /* Ignore the rest of the line if we don't need the input of \
212 if (ignore_content) \
214 lr_ignore_rest (ldfile, 0); \
218 arg = lr_token (ldfile, charmap, result, NULL, verbose); \
219 if (arg->tok != tok_number) \
221 else if (measurement->cat != 0) \
222 lr_error (ldfile, _("%s: field `%s' declared more than once"), \
223 "LC_MEASUREMENT", #cat); \
224 else if (!ignore_content) \
225 measurement->cat = arg->val.num; \
228 INT_ELEM (measurement);
231 /* Next we assume `LC_MEASUREMENT'. */
232 arg = lr_token (ldfile, charmap, result, NULL, verbose);
233 if (arg->tok == tok_eof)
235 if (arg->tok == tok_eol)
236 lr_error (ldfile, _("%s: incomplete `END' line"),
238 else if (arg->tok != tok_lc_measurement)
239 lr_error (ldfile, _("\
240 %1$s: definition does not end with `END %1$s'"), "LC_MEASUREMENT");
241 lr_ignore_rest (ldfile, arg->tok == tok_lc_measurement);
246 SYNTAX_ERROR (_("%s: syntax error"), "LC_MEASUREMENT");
249 /* Prepare for the next round. */
250 now = lr_token (ldfile, charmap, result, NULL, verbose);
254 /* When we come here we reached the end of the file. */
255 lr_error (ldfile, _("%s: premature end of file"),