1 /* Copyright (C) 1998,1999,2000,2001,2002,2005 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, write to the Free Software Foundation,
17 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
30 #include "localedef.h"
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
,
61 const struct charmap_t
*charmap
)
63 struct locale_measurement_t
*measurement
=
64 locale
->categories
[LC_MEASUREMENT
].measurement
;
67 /* Now resolve copying and also handle completely missing definitions. */
68 if (measurement
== NULL
)
70 /* First see whether we were supposed to copy. If yes, find the
72 if (locale
->copy_name
[LC_MEASUREMENT
] != NULL
)
74 /* Find the copying locale. This has to happen transitively since
75 the locale we are copying from might also copying another one. */
76 struct localedef_t
*from
= locale
;
79 from
= find_locale (LC_MEASUREMENT
,
80 from
->copy_name
[LC_MEASUREMENT
],
81 from
->repertoire_name
, charmap
);
82 while (from
->categories
[LC_MEASUREMENT
].measurement
== NULL
83 && from
->copy_name
[LC_MEASUREMENT
] != NULL
);
85 measurement
= locale
->categories
[LC_MEASUREMENT
].measurement
86 = from
->categories
[LC_MEASUREMENT
].measurement
;
89 /* If there is still no definition issue an warning and create an
91 if (measurement
== NULL
)
94 WITH_CUR_LOCALE (error (0, 0, _("\
95 No definition for %s category found"), "LC_MEASUREMENT"));
96 measurement_startup (NULL
, locale
, 0);
97 measurement
= locale
->categories
[LC_MEASUREMENT
].measurement
;
102 if (measurement
->measurement
== 0)
105 WITH_CUR_LOCALE (error (0, 0, _("%s: field `%s' not defined"),
106 "LC_MEASUREMENT", "measurement"));
107 /* Use as the default value the value of the i18n locale. */
108 measurement
->measurement
= 1;
112 if (measurement
->measurement
> 3)
113 WITH_CUR_LOCALE (error (0, 0, _("%s: invalid value for field `%s'"),
114 "LC_MEASUREMENT", "measurement"));
120 measurement_output (struct localedef_t
*locale
,
121 const struct charmap_t
*charmap
, const char *output_path
)
123 struct locale_measurement_t
*measurement
=
124 locale
->categories
[LC_MEASUREMENT
].measurement
;
125 struct iovec iov
[2 + _NL_ITEM_INDEX (_NL_NUM_LC_MEASUREMENT
)];
126 struct locale_file data
;
127 uint32_t idx
[_NL_ITEM_INDEX (_NL_NUM_LC_MEASUREMENT
)];
130 data
.magic
= LIMAGIC (LC_MEASUREMENT
);
131 data
.n
= _NL_ITEM_INDEX (_NL_NUM_LC_MEASUREMENT
);
132 iov
[cnt
].iov_base
= (void *) &data
;
133 iov
[cnt
].iov_len
= sizeof (data
);
136 iov
[cnt
].iov_base
= (void *) idx
;
137 iov
[cnt
].iov_len
= sizeof (idx
);
140 idx
[cnt
- 2] = iov
[0].iov_len
+ iov
[1].iov_len
;
141 iov
[cnt
].iov_base
= &measurement
->measurement
;
142 iov
[cnt
].iov_len
= 1;
145 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
146 iov
[cnt
].iov_base
= (void *) charmap
->code_set_name
;
147 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
150 assert (cnt
== 2 + _NL_ITEM_INDEX (_NL_NUM_LC_MEASUREMENT
));
152 write_locale_data (output_path
, LC_MEASUREMENT
, "LC_MEASUREMENT",
153 2 + _NL_ITEM_INDEX (_NL_NUM_LC_MEASUREMENT
), iov
);
157 /* The parser for the LC_MEASUREMENT section of the locale definition. */
159 measurement_read (struct linereader
*ldfile
, struct localedef_t
*result
,
160 const struct charmap_t
*charmap
, const char *repertoire_name
,
163 struct locale_measurement_t
*measurement
;
168 /* The rest of the line containing `LC_MEASUREMENT' must be free. */
169 lr_ignore_rest (ldfile
, 1);
173 now
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
176 while (nowtok
== tok_eol
);
178 /* If we see `copy' now we are almost done. */
179 if (nowtok
== tok_copy
)
181 handle_copy (ldfile
, charmap
, repertoire_name
, result
,
182 tok_lc_measurement
, LC_MEASUREMENT
, "LC_MEASUREMENT",
187 /* Prepare the data structures. */
188 measurement_startup (ldfile
, result
, ignore_content
);
189 measurement
= result
->categories
[LC_MEASUREMENT
].measurement
;
193 /* Of course we don't proceed beyond the end of file. */
194 if (nowtok
== tok_eof
)
197 /* Ingore empty lines. */
198 if (nowtok
== tok_eol
)
200 now
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
207 #define INT_ELEM(cat) \
209 /* Ignore the rest of the line if we don't need the input of \
211 if (ignore_content) \
213 lr_ignore_rest (ldfile, 0); \
217 arg = lr_token (ldfile, charmap, result, NULL, verbose); \
218 if (arg->tok != tok_number) \
220 else if (measurement->cat != 0) \
221 lr_error (ldfile, _("%s: field `%s' declared more than once"), \
222 "LC_MEASUREMENT", #cat); \
223 else if (!ignore_content) \
224 measurement->cat = arg->val.num; \
227 INT_ELEM (measurement
);
230 /* Next we assume `LC_MEASUREMENT'. */
231 arg
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
232 if (arg
->tok
== tok_eof
)
234 if (arg
->tok
== tok_eol
)
235 lr_error (ldfile
, _("%s: incomplete `END' line"),
237 else if (arg
->tok
!= tok_lc_measurement
)
238 lr_error (ldfile
, _("\
239 %1$s: definition does not end with `END %1$s'"), "LC_MEASUREMENT");
240 lr_ignore_rest (ldfile
, arg
->tok
== tok_lc_measurement
);
245 SYNTAX_ERROR (_("%s: syntax error"), "LC_MEASUREMENT");
248 /* Prepare for the next round. */
249 now
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
253 /* When we come here we reached the end of the file. */
254 lr_error (ldfile
, _("%s: premature end of file"),