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_PAPER locale. */
44 paper_startup (struct linereader
*lr
, struct localedef_t
*locale
,
48 locale
->categories
[LC_PAPER
].paper
=
49 (struct locale_paper_t
*) xcalloc (1, sizeof (struct locale_paper_t
));
53 lr
->translate_strings
= 1;
54 lr
->return_widestr
= 0;
60 paper_finish (struct localedef_t
*locale
, const struct charmap_t
*charmap
)
62 struct locale_paper_t
*paper
= locale
->categories
[LC_PAPER
].paper
;
65 /* Now resolve copying and also handle completely missing definitions. */
68 /* First see whether we were supposed to copy. If yes, find the
70 if (locale
->copy_name
[LC_PAPER
] != NULL
)
72 /* Find the copying locale. This has to happen transitively since
73 the locale we are copying from might also copying another one. */
74 struct localedef_t
*from
= locale
;
77 from
= find_locale (LC_PAPER
, from
->copy_name
[LC_PAPER
],
78 from
->repertoire_name
, charmap
);
79 while (from
->categories
[LC_PAPER
].paper
== NULL
80 && from
->copy_name
[LC_PAPER
] != NULL
);
82 paper
= locale
->categories
[LC_PAPER
].paper
83 = from
->categories
[LC_PAPER
].paper
;
86 /* If there is still no definition issue an warning and create an
91 WITH_CUR_LOCALE (error (0, 0, _("\
92 No definition for %s category found"), "LC_PAPER"));
93 paper_startup (NULL
, locale
, 0);
94 paper
= locale
->categories
[LC_PAPER
].paper
;
99 if (paper
->height
== 0)
102 WITH_CUR_LOCALE (error (0, 0, _("%s: field `%s' not defined"),
103 "LC_PAPER", "height"));
104 /* Use as default values the values from the i18n locale. */
108 if (paper
->width
== 0)
111 WITH_CUR_LOCALE (error (0, 0, _("%s: field `%s' not defined"),
112 "LC_PAPER", "width"));
113 /* Use as default values the values from the i18n locale. */
120 paper_output (struct localedef_t
*locale
, const struct charmap_t
*charmap
,
121 const char *output_path
)
123 struct locale_paper_t
*paper
= locale
->categories
[LC_PAPER
].paper
;
124 struct iovec iov
[2 + _NL_ITEM_INDEX (_NL_NUM_LC_PAPER
)];
125 struct locale_file data
;
126 uint32_t idx
[_NL_ITEM_INDEX (_NL_NUM_LC_PAPER
)];
129 data
.magic
= LIMAGIC (LC_PAPER
);
130 data
.n
= _NL_ITEM_INDEX (_NL_NUM_LC_PAPER
);
131 iov
[cnt
].iov_base
= (void *) &data
;
132 iov
[cnt
].iov_len
= sizeof (data
);
135 iov
[cnt
].iov_base
= (void *) idx
;
136 iov
[cnt
].iov_len
= sizeof (idx
);
139 idx
[cnt
- 2] = iov
[cnt
- 2].iov_len
+ iov
[cnt
- 1].iov_len
;
140 iov
[cnt
].iov_base
= &paper
->height
;
141 iov
[cnt
].iov_len
= 4;
144 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
145 iov
[cnt
].iov_base
= &paper
->width
;
146 iov
[cnt
].iov_len
= 4;
149 idx
[cnt
- 2] = idx
[cnt
- 3] + iov
[cnt
- 1].iov_len
;
150 iov
[cnt
].iov_base
= (void *) charmap
->code_set_name
;
151 iov
[cnt
].iov_len
= strlen (iov
[cnt
].iov_base
) + 1;
154 assert (cnt
== 2 + _NL_ITEM_INDEX (_NL_NUM_LC_PAPER
));
156 write_locale_data (output_path
, LC_PAPER
, "LC_PAPER",
157 2 + _NL_ITEM_INDEX (_NL_NUM_LC_PAPER
), iov
);
161 /* The parser for the LC_PAPER section of the locale definition. */
163 paper_read (struct linereader
*ldfile
, struct localedef_t
*result
,
164 const struct charmap_t
*charmap
, const char *repertoire_name
,
167 struct locale_paper_t
*paper
;
172 /* The rest of the line containing `LC_PAPER' must be empty. */
173 lr_ignore_rest (ldfile
, 1);
177 now
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
180 while (nowtok
== tok_eol
);
182 /* If we see `copy' now we are almost done. */
183 if (nowtok
== tok_copy
)
185 handle_copy (ldfile
, charmap
, repertoire_name
, result
, tok_lc_paper
,
186 LC_PAPER
, "LC_PAPER", ignore_content
);
190 /* Prepare the data structures. */
191 paper_startup (ldfile
, result
, ignore_content
);
192 paper
= result
->categories
[LC_PAPER
].paper
;
196 /* Of course we don't proceed beyond the end of file. */
197 if (nowtok
== tok_eof
)
200 /* Ingore empty lines. */
201 if (nowtok
== tok_eol
)
203 now
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
210 #define INT_ELEM(cat) \
212 /* Ignore the rest of the line if we don't need the input of \
214 if (ignore_content) \
216 lr_ignore_rest (ldfile, 0); \
220 arg = lr_token (ldfile, charmap, result, NULL, verbose); \
221 if (arg->tok != tok_number) \
223 else if (paper->cat != 0) \
224 lr_error (ldfile, _("%s: field `%s' declared more than once"), \
226 else if (!ignore_content) \
227 paper->cat = arg->val.num; \
234 /* Next we assume `LC_PAPER'. */
235 arg
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
236 if (arg
->tok
== tok_eof
)
238 if (arg
->tok
== tok_eol
)
239 lr_error (ldfile
, _("%s: incomplete `END' line"), "LC_PAPER");
240 else if (arg
->tok
!= tok_lc_paper
)
241 lr_error (ldfile
, _("\
242 %1$s: definition does not end with `END %1$s'"), "LC_PAPER");
243 lr_ignore_rest (ldfile
, arg
->tok
== tok_lc_paper
);
248 SYNTAX_ERROR (_("%s: syntax error"), "LC_PAPER");
251 /* Prepare for the next round. */
252 now
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
256 /* When we come here we reached the end of the file. */
257 lr_error (ldfile
, _("%s: premature end of file"), "LC_PAPER");