1 /* Copyright (C) 1998-2015 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, see <http://www.gnu.org/licenses/>. */
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 locale_file file
;
126 init_locale_data (&file
, _NL_ITEM_INDEX (_NL_NUM_LC_PAPER
));
127 add_locale_uint32 (&file
, paper
->height
);
128 add_locale_uint32 (&file
, paper
->width
);
129 add_locale_string (&file
, charmap
->code_set_name
);
130 write_locale_data (output_path
, LC_PAPER
, "LC_PAPER", &file
);
134 /* The parser for the LC_PAPER section of the locale definition. */
136 paper_read (struct linereader
*ldfile
, struct localedef_t
*result
,
137 const struct charmap_t
*charmap
, const char *repertoire_name
,
140 struct locale_paper_t
*paper
;
145 /* The rest of the line containing `LC_PAPER' must be empty. */
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
, tok_lc_paper
,
159 LC_PAPER
, "LC_PAPER", ignore_content
);
163 /* Prepare the data structures. */
164 paper_startup (ldfile
, result
, ignore_content
);
165 paper
= result
->categories
[LC_PAPER
].paper
;
169 /* Of course we don't proceed beyond the end of file. */
170 if (nowtok
== tok_eof
)
173 /* Ingore empty lines. */
174 if (nowtok
== tok_eol
)
176 now
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
183 #define INT_ELEM(cat) \
185 /* Ignore the rest of the line if we don't need the input of \
187 if (ignore_content) \
189 lr_ignore_rest (ldfile, 0); \
193 arg = lr_token (ldfile, charmap, result, NULL, verbose); \
194 if (arg->tok != tok_number) \
196 else if (paper->cat != 0) \
197 lr_error (ldfile, _("%s: field `%s' declared more than once"), \
199 else if (!ignore_content) \
200 paper->cat = arg->val.num; \
207 /* Next we assume `LC_PAPER'. */
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"), "LC_PAPER");
213 else if (arg
->tok
!= tok_lc_paper
)
214 lr_error (ldfile
, _("\
215 %1$s: definition does not end with `END %1$s'"), "LC_PAPER");
216 lr_ignore_rest (ldfile
, arg
->tok
== tok_lc_paper
);
221 SYNTAX_ERROR (_("%s: syntax error"), "LC_PAPER");
224 /* Prepare for the next round. */
225 now
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
229 /* When we come here we reached the end of the file. */
230 lr_error (ldfile
, _("%s: premature end of file"), "LC_PAPER");