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_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, 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
90 error (0, 0, _("No definition for %s category found"), "LC_PAPER");
91 paper_startup (NULL, locale, 0);
92 paper = locale->categories[LC_PAPER].paper;
97 if (paper->height == 0)
100 error (0, 0, _("%s: field `%s' not defined"), "LC_PAPER", "height");
101 /* Use as default values the values from the i18n locale. */
105 if (paper->width == 0)
108 error (0, 0, _("%s: field `%s' not defined"), "LC_PAPER", "width");
109 /* Use as default values the values from the i18n locale. */
116 paper_output (struct localedef_t *locale, struct charmap_t *charmap,
117 const char *output_path)
119 struct locale_paper_t *paper = locale->categories[LC_PAPER].paper;
120 struct iovec iov[2 + _NL_ITEM_INDEX (_NL_NUM_LC_PAPER)];
121 struct locale_file data;
122 uint32_t idx[_NL_ITEM_INDEX (_NL_NUM_LC_PAPER)];
125 data.magic = LIMAGIC (LC_PAPER);
126 data.n = _NL_ITEM_INDEX (_NL_NUM_LC_PAPER);
127 iov[cnt].iov_base = (void *) &data;
128 iov[cnt].iov_len = sizeof (data);
131 iov[cnt].iov_base = (void *) idx;
132 iov[cnt].iov_len = sizeof (idx);
135 idx[cnt - 2] = iov[0].iov_len + iov[1].iov_len;
136 iov[cnt].iov_base = &paper->height;
137 iov[cnt].iov_len = 4;
140 idx[cnt - 2] = iov[0].iov_len + iov[1].iov_len;
141 iov[cnt].iov_base = &paper->width;
142 iov[cnt].iov_len = 4;
145 assert (cnt == 2 + _NL_ITEM_INDEX (_NL_NUM_LC_PAPER));
147 write_locale_data (output_path, "LC_PAPER",
148 2 + _NL_ITEM_INDEX (_NL_NUM_LC_PAPER), iov);
152 /* The parser for the LC_PAPER section of the locale definition. */
154 paper_read (struct linereader *ldfile, struct localedef_t *result,
155 struct charmap_t *charmap, const char *repertoire_name,
158 struct repertoire_t *repertoire = NULL;
159 struct locale_paper_t *paper;
164 /* Get the repertoire we have to use. */
165 if (repertoire_name != NULL)
166 repertoire = repertoire_read (repertoire_name);
168 /* The rest of the line containing `LC_PAPER' must be empty. */
169 lr_ignore_rest (ldfile, 1);
173 now = lr_token (ldfile, charmap, NULL);
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, result, tok_lc_paper,
182 LC_PAPER, "LC_PAPER", ignore_content);
186 /* Prepare the data structures. */
187 paper_startup (ldfile, result, ignore_content);
188 paper = result->categories[LC_PAPER].paper;
192 /* Of course we don't proceed beyond the end of file. */
193 if (nowtok == tok_eof)
196 /* Ingore empty lines. */
197 if (nowtok == tok_eol)
199 now = lr_token (ldfile, charmap, NULL);
206 #define INT_ELEM(cat) \
208 /* Ignore the rest of the line if we don't need the input of \
210 if (ignore_content) \
212 lr_ignore_rest (ldfile, 0); \
216 arg = lr_token (ldfile, charmap, NULL); \
217 if (arg->tok != tok_number) \
219 else if (paper->cat != 0) \
220 lr_error (ldfile, _("%s: field `%s' declared more than once"), \
222 else if (!ignore_content) \
223 paper->cat = arg->val.num; \
230 /* Next we assume `LC_PAPER'. */
231 arg = lr_token (ldfile, charmap, NULL);
232 if (arg->tok == tok_eof)
234 if (arg->tok == tok_eol)
235 lr_error (ldfile, _("%s: incomplete `END' line"), "LC_PAPER");
236 else if (arg->tok != tok_lc_paper)
237 lr_error (ldfile, _("\
238 %1$s: definition does not end with `END %1$s'"), "LC_PAPER");
239 lr_ignore_rest (ldfile, arg->tok == tok_lc_paper);
244 SYNTAX_ERROR (_("%s: syntax error"), "LC_PAPER");
247 /* Prepare for the next round. */
248 now = lr_token (ldfile, charmap, NULL);
252 /* When we come here we reached the end of the file. */
253 lr_error (ldfile, _("%s: premature end of file"), "LC_PAPER");