1 /* Copyright (C) 1998-2023 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published
6 by the Free Software Foundation; version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, see <https://www.gnu.org/licenses/>. */
28 #include "localedef.h"
29 #include "localeinfo.h"
33 /* The real definition of the struct for the LC_PAPER locale. */
42 paper_startup (struct linereader
*lr
, struct localedef_t
*locale
,
46 locale
->categories
[LC_PAPER
].paper
=
47 (struct locale_paper_t
*) xcalloc (1, sizeof (struct locale_paper_t
));
51 lr
->translate_strings
= 1;
52 lr
->return_widestr
= 0;
58 paper_finish (struct localedef_t
*locale
, const struct charmap_t
*charmap
)
60 struct locale_paper_t
*paper
= locale
->categories
[LC_PAPER
].paper
;
63 /* Now resolve copying and also handle completely missing definitions. */
66 /* First see whether we were supposed to copy. If yes, find the
68 if (locale
->copy_name
[LC_PAPER
] != NULL
)
70 /* Find the copying locale. This has to happen transitively since
71 the locale we are copying from might also copying another one. */
72 struct localedef_t
*from
= locale
;
75 from
= find_locale (LC_PAPER
, from
->copy_name
[LC_PAPER
],
76 from
->repertoire_name
, charmap
);
77 while (from
->categories
[LC_PAPER
].paper
== NULL
78 && from
->copy_name
[LC_PAPER
] != NULL
);
80 paper
= locale
->categories
[LC_PAPER
].paper
81 = from
->categories
[LC_PAPER
].paper
;
84 /* If there is still no definition issue an warning and create an
89 No definition for %s category found"), "LC_PAPER");
90 paper_startup (NULL
, locale
, 0);
91 paper
= locale
->categories
[LC_PAPER
].paper
;
96 if (paper
->height
== 0)
99 record_error (0, 0, _("%s: field `%s' not defined"),
100 "LC_PAPER", "height");
101 /* Use as default values the values from the i18n locale. */
105 if (paper
->width
== 0)
108 record_error (0, 0, _("%s: field `%s' not defined"),
109 "LC_PAPER", "width");
110 /* Use as default values the values from the i18n locale. */
117 paper_output (struct localedef_t
*locale
, const struct charmap_t
*charmap
,
118 const char *output_path
)
120 struct locale_paper_t
*paper
= locale
->categories
[LC_PAPER
].paper
;
121 struct locale_file file
;
123 init_locale_data (&file
, _NL_ITEM_INDEX (_NL_NUM_LC_PAPER
));
124 add_locale_uint32 (&file
, paper
->height
);
125 add_locale_uint32 (&file
, paper
->width
);
126 add_locale_string (&file
, charmap
->code_set_name
);
127 write_locale_data (output_path
, LC_PAPER
, "LC_PAPER", &file
);
131 /* The parser for the LC_PAPER section of the locale definition. */
133 paper_read (struct linereader
*ldfile
, struct localedef_t
*result
,
134 const struct charmap_t
*charmap
, const char *repertoire_name
,
137 struct locale_paper_t
*paper
;
142 /* The rest of the line containing `LC_PAPER' must be empty. */
143 lr_ignore_rest (ldfile
, 1);
147 now
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
150 while (nowtok
== tok_eol
);
152 /* If we see `copy' now we are almost done. */
153 if (nowtok
== tok_copy
)
155 handle_copy (ldfile
, charmap
, repertoire_name
, result
, tok_lc_paper
,
156 LC_PAPER
, "LC_PAPER", ignore_content
);
160 /* Prepare the data structures. */
161 paper_startup (ldfile
, result
, ignore_content
);
162 paper
= result
->categories
[LC_PAPER
].paper
;
166 /* Of course we don't proceed beyond the end of file. */
167 if (nowtok
== tok_eof
)
170 /* Ingore empty lines. */
171 if (nowtok
== tok_eol
)
173 now
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
180 #define INT_ELEM(cat) \
182 /* Ignore the rest of the line if we don't need the input of \
184 if (ignore_content) \
186 lr_ignore_rest (ldfile, 0); \
190 arg = lr_token (ldfile, charmap, result, NULL, verbose); \
191 if (arg->tok != tok_number) \
193 else if (paper->cat != 0) \
194 lr_error (ldfile, _("%s: field `%s' declared more than once"), \
196 else if (!ignore_content) \
197 paper->cat = arg->val.num; \
204 /* Next we assume `LC_PAPER'. */
205 arg
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
206 if (arg
->tok
== tok_eof
)
208 if (arg
->tok
== tok_eol
)
209 lr_error (ldfile
, _("%s: incomplete `END' line"), "LC_PAPER");
210 else if (arg
->tok
!= tok_lc_paper
)
211 lr_error (ldfile
, _("\
212 %1$s: definition does not end with `END %1$s'"), "LC_PAPER");
213 lr_ignore_rest (ldfile
, arg
->tok
== tok_lc_paper
);
218 SYNTAX_ERROR (_("%s: syntax error"), "LC_PAPER");
221 /* Prepare for the next round. */
222 now
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
226 /* When we come here we reached the end of the file. */
227 lr_error (ldfile
, _("%s: premature end of file"), "LC_PAPER");