1 /* Copyright (C) 1998, 1999 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_MEASUREMENT locale. */
36 struct locale_measurement_t
38 unsigned char measurement
;
43 measurement_startup (struct linereader
*lr
, struct localedef_t
*locale
,
47 locale
->categories
[LC_MEASUREMENT
].measurement
=
48 (struct locale_measurement_t
*)
49 xcalloc (1, sizeof (struct locale_measurement_t
));
53 lr
->translate_strings
= 1;
54 lr
->return_widestr
= 0;
60 measurement_finish (struct localedef_t
*locale
, 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
)
92 error (0, 0, _("No definition for %s category found"),
94 measurement_startup (NULL
, locale
, 0);
95 measurement
= locale
->categories
[LC_MEASUREMENT
].measurement
;
100 if (measurement
->measurement
== 0)
103 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 error (0, 0, _("%s: invalid value for field `%s'"),
112 "LC_MEASUREMENT", "meassurement");
118 measurement_output (struct localedef_t
*locale
, struct charmap_t
*charmap
,
119 const char *output_path
)
121 struct locale_measurement_t
*measurement
=
122 locale
->categories
[LC_MEASUREMENT
].measurement
;
123 struct iovec iov
[2 + _NL_ITEM_INDEX (_NL_NUM_LC_MEASUREMENT
)];
124 struct locale_file data
;
125 uint32_t idx
[_NL_ITEM_INDEX (_NL_NUM_LC_MEASUREMENT
)];
128 data
.magic
= LIMAGIC (LC_MEASUREMENT
);
129 data
.n
= _NL_ITEM_INDEX (_NL_NUM_LC_MEASUREMENT
);
130 iov
[cnt
].iov_base
= (void *) &data
;
131 iov
[cnt
].iov_len
= sizeof (data
);
134 iov
[cnt
].iov_base
= (void *) idx
;
135 iov
[cnt
].iov_len
= sizeof (idx
);
138 idx
[cnt
- 2] = iov
[0].iov_len
+ iov
[1].iov_len
;
139 iov
[cnt
].iov_base
= &measurement
->measurement
;
140 iov
[cnt
].iov_len
= 1;
143 assert (cnt
== 2 + _NL_ITEM_INDEX (_NL_NUM_LC_MEASUREMENT
));
145 write_locale_data (output_path
, "LC_MEASUREMENT",
146 2 + _NL_ITEM_INDEX (_NL_NUM_LC_MEASUREMENT
), iov
);
150 /* The parser for the LC_MEASUREMENT section of the locale definition. */
152 measurement_read (struct linereader
*ldfile
, struct localedef_t
*result
,
153 struct charmap_t
*charmap
, const char *repertoire_name
,
156 struct repertoire_t
*repertoire
= NULL
;
157 struct locale_measurement_t
*measurement
;
162 /* Get the repertoire we have to use. */
163 if (repertoire_name
!= NULL
)
164 repertoire
= repertoire_read (repertoire_name
);
166 /* The rest of the line containing `LC_MEASUREMENT' must be free. */
167 lr_ignore_rest (ldfile
, 1);
171 now
= lr_token (ldfile
, charmap
, NULL
);
174 while (nowtok
== tok_eol
);
176 /* If we see `copy' now we are almost done. */
177 if (nowtok
== tok_copy
)
179 handle_copy (ldfile
, charmap
, repertoire
, result
, tok_lc_measurement
,
180 LC_MEASUREMENT
, "LC_MEASUREMENT", ignore_content
);
184 /* Prepare the data structures. */
185 measurement_startup (ldfile
, result
, ignore_content
);
186 measurement
= result
->categories
[LC_MEASUREMENT
].measurement
;
190 /* Of course we don't proceed beyond the end of file. */
191 if (nowtok
== tok_eof
)
194 /* Ingore empty lines. */
195 if (nowtok
== tok_eol
)
197 now
= lr_token (ldfile
, charmap
, NULL
);
204 #define INT_ELEM(cat) \
206 /* Ignore the rest of the line if we don't need the input of \
208 if (ignore_content) \
210 lr_ignore_rest (ldfile, 0); \
214 arg = lr_token (ldfile, charmap, NULL); \
215 if (arg->tok != tok_number) \
217 else if (measurement->cat != 0) \
218 lr_error (ldfile, _("%s: field `%s' declared more than once"), \
219 "LC_MEASUREMENT", #cat); \
220 else if (!ignore_content) \
221 measurement->cat = arg->val.num; \
224 INT_ELEM (measurement
);
227 /* Next we assume `LC_MEASUREMENT'. */
228 arg
= lr_token (ldfile
, charmap
, NULL
);
229 if (arg
->tok
== tok_eof
)
231 if (arg
->tok
== tok_eol
)
232 lr_error (ldfile
, _("%s: incomplete `END' line"),
234 else if (arg
->tok
!= tok_lc_measurement
)
235 lr_error (ldfile
, _("\
236 %1$s: definition does not end with `END %1$s'"), "LC_MEASUREMENT");
237 lr_ignore_rest (ldfile
, arg
->tok
== tok_lc_measurement
);
242 SYNTAX_ERROR (_("%s: syntax error"), "LC_MEASUREMENT");
245 /* Prepare for the next round. */
246 now
= lr_token (ldfile
, charmap
, NULL
);
250 /* When we come here we reached the end of the file. */
251 lr_error (ldfile
, _("%s: premature end of file"),