]>
git.ipfire.org Git - thirdparty/glibc.git/blob - locale/programs/ld-paper.c
ad1b6ed5ee1f1177d37d9e7e0831d875f02ba6f8
1 /* Copyright (C) 1998-2019 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/>. */
29 #include "localedef.h"
30 #include "localeinfo.h"
34 /* The real definition of the struct for the LC_PAPER locale. */
43 paper_startup (struct linereader
*lr
, struct localedef_t
*locale
,
47 locale
->categories
[LC_PAPER
].paper
=
48 (struct locale_paper_t
*) xcalloc (1, sizeof (struct locale_paper_t
));
52 lr
->translate_strings
= 1;
53 lr
->return_widestr
= 0;
59 paper_finish (struct localedef_t
*locale
, const struct charmap_t
*charmap
)
61 struct locale_paper_t
*paper
= locale
->categories
[LC_PAPER
].paper
;
64 /* Now resolve copying and also handle completely missing definitions. */
67 /* First see whether we were supposed to copy. If yes, find the
69 if (locale
->copy_name
[LC_PAPER
] != NULL
)
71 /* Find the copying locale. This has to happen transitively since
72 the locale we are copying from might also copying another one. */
73 struct localedef_t
*from
= locale
;
76 from
= find_locale (LC_PAPER
, from
->copy_name
[LC_PAPER
],
77 from
->repertoire_name
, charmap
);
78 while (from
->categories
[LC_PAPER
].paper
== NULL
79 && from
->copy_name
[LC_PAPER
] != NULL
);
81 paper
= locale
->categories
[LC_PAPER
].paper
82 = from
->categories
[LC_PAPER
].paper
;
85 /* If there is still no definition issue an warning and create an
90 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 record_error (0, 0, _("%s: field `%s' not defined"),
101 "LC_PAPER", "height");
102 /* Use as default values the values from the i18n locale. */
106 if (paper
->width
== 0)
109 record_error (0, 0, _("%s: field `%s' not defined"),
110 "LC_PAPER", "width");
111 /* Use as default values the values from the i18n locale. */
118 paper_output (struct localedef_t
*locale
, const struct charmap_t
*charmap
,
119 const char *output_path
)
121 struct locale_paper_t
*paper
= locale
->categories
[LC_PAPER
].paper
;
122 struct locale_file file
;
124 init_locale_data (&file
, _NL_ITEM_INDEX (_NL_NUM_LC_PAPER
));
125 add_locale_uint32 (&file
, paper
->height
);
126 add_locale_uint32 (&file
, paper
->width
);
127 add_locale_string (&file
, charmap
->code_set_name
);
128 write_locale_data (output_path
, LC_PAPER
, "LC_PAPER", &file
);
132 /* The parser for the LC_PAPER section of the locale definition. */
134 paper_read (struct linereader
*ldfile
, struct localedef_t
*result
,
135 const struct charmap_t
*charmap
, const char *repertoire_name
,
138 struct locale_paper_t
*paper
;
143 /* The rest of the line containing `LC_PAPER' must be empty. */
144 lr_ignore_rest (ldfile
, 1);
148 now
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
151 while (nowtok
== tok_eol
);
153 /* If we see `copy' now we are almost done. */
154 if (nowtok
== tok_copy
)
156 handle_copy (ldfile
, charmap
, repertoire_name
, result
, tok_lc_paper
,
157 LC_PAPER
, "LC_PAPER", ignore_content
);
161 /* Prepare the data structures. */
162 paper_startup (ldfile
, result
, ignore_content
);
163 paper
= result
->categories
[LC_PAPER
].paper
;
167 /* Of course we don't proceed beyond the end of file. */
168 if (nowtok
== tok_eof
)
171 /* Ingore empty lines. */
172 if (nowtok
== tok_eol
)
174 now
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
181 #define INT_ELEM(cat) \
183 /* Ignore the rest of the line if we don't need the input of \
185 if (ignore_content) \
187 lr_ignore_rest (ldfile, 0); \
191 arg = lr_token (ldfile, charmap, result, NULL, verbose); \
192 if (arg->tok != tok_number) \
194 else if (paper->cat != 0) \
195 lr_error (ldfile, _("%s: field `%s' declared more than once"), \
197 else if (!ignore_content) \
198 paper->cat = arg->val.num; \
205 /* Next we assume `LC_PAPER'. */
206 arg
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
207 if (arg
->tok
== tok_eof
)
209 if (arg
->tok
== tok_eol
)
210 lr_error (ldfile
, _("%s: incomplete `END' line"), "LC_PAPER");
211 else if (arg
->tok
!= tok_lc_paper
)
212 lr_error (ldfile
, _("\
213 %1$s: definition does not end with `END %1$s'"), "LC_PAPER");
214 lr_ignore_rest (ldfile
, arg
->tok
== tok_lc_paper
);
219 SYNTAX_ERROR (_("%s: syntax error"), "LC_PAPER");
222 /* Prepare for the next round. */
223 now
= lr_token (ldfile
, charmap
, result
, NULL
, verbose
);
227 /* When we come here we reached the end of the file. */
228 lr_error (ldfile
, _("%s: premature end of file"), "LC_PAPER");