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 locale_file file;
127
init_locale_data (&file, _NL_ITEM_INDEX (_NL_NUM_LC_MEASUREMENT));
128
add_locale_char (&file, measurement->measurement);
129
add_locale_string (&file, charmap->code_set_name);
130
write_locale_data (output_path, LC_MEASUREMENT, "LC_MEASUREMENT", &file);
134
/* The parser for the LC_MEASUREMENT section of the locale definition. */
136
measurement_read (struct linereader *ldfile, struct localedef_t *result,
137
const struct charmap_t *charmap, const char *repertoire_name,
140
struct locale_measurement_t *measurement;
145
/* The rest of the line containing `LC_MEASUREMENT' must be free. */
146
lr_ignore_rest (ldfile, 1);
150
now = lr_token (ldfile, charmap, result, NULL, verbose);
153
while (nowtok == tok_eol);
155
/* If we see `copy' now we are almost done. */
156
if (nowtok == tok_copy)
158
handle_copy (ldfile, charmap, repertoire_name, result,
159
tok_lc_measurement, LC_MEASUREMENT, "LC_MEASUREMENT",
164
/* Prepare the data structures. */
165
measurement_startup (ldfile, result, ignore_content);
166
measurement = result->categories[LC_MEASUREMENT].measurement;
170
/* Of course we don't proceed beyond the end of file. */
171
if (nowtok == tok_eof)
174
/* Ingore empty lines. */
175
if (nowtok == tok_eol)
177
now = lr_token (ldfile, charmap, result, NULL, verbose);
184
#define INT_ELEM(cat) \
186
/* Ignore the rest of the line if we don't need the input of \
188
if (ignore_content) \
190
lr_ignore_rest (ldfile, 0); \
194
arg = lr_token (ldfile, charmap, result, NULL, verbose); \
195
if (arg->tok != tok_number) \
197
else if (measurement->cat != 0) \
198
lr_error (ldfile, _("%s: field `%s' declared more than once"), \
199
"LC_MEASUREMENT", #cat); \
200
else if (!ignore_content) \
201
measurement->cat = arg->val.num; \
204
INT_ELEM (measurement);
207
/* Next we assume `LC_MEASUREMENT'. */
208
arg = lr_token (ldfile, charmap, result, NULL, verbose);
209
if (arg->tok == tok_eof)
211
if (arg->tok == tok_eol)
212
lr_error (ldfile, _("%s: incomplete `END' line"),
214
else if (arg->tok != tok_lc_measurement)
215
lr_error (ldfile, _("\
216
%1$s: definition does not end with `END %1$s'"), "LC_MEASUREMENT");
217
lr_ignore_rest (ldfile, arg->tok == tok_lc_measurement);
222
SYNTAX_ERROR (_("%s: syntax error"), "LC_MEASUREMENT");
225
/* Prepare for the next round. */
226
now = lr_token (ldfile, charmap, result, NULL, verbose);
230
/* When we come here we reached the end of the file. */
231
lr_error (ldfile, _("%s: premature end of file"),