]> git.ipfire.org Git - thirdparty/glibc.git/blame - locale/programs/ld-paper.c
Update copyright notices with scripts/update-copyrights
[thirdparty/glibc.git] / locale / programs / ld-paper.c
CommitLineData
d4697bc9 1/* Copyright (C) 1998-2014 Free Software Foundation, Inc.
4b10dd6c
UD
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
4
43bc8ac6 5 This program is free software; you can redistribute it and/or modify
2e2efe65
RM
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.
4b10dd6c 9
43bc8ac6 10 This program is distributed in the hope that it will be useful,
4b10dd6c 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
43bc8ac6
UD
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
4b10dd6c 14
43bc8ac6 15 You should have received a copy of the GNU General Public License
59ba27a6 16 along with this program; if not, see <http://www.gnu.org/licenses/>. */
4b10dd6c
UD
17
18#ifdef HAVE_CONFIG_H
19# include <config.h>
20#endif
21
4b10dd6c
UD
22#include <error.h>
23#include <langinfo.h>
24#include <string.h>
e054f494 25#include <stdint.h>
4b10dd6c
UD
26#include <sys/uio.h>
27
28#include <assert.h>
29
f2b98f97 30#include "localedef.h"
4b10dd6c
UD
31#include "localeinfo.h"
32#include "locfile.h"
33
34
35/* The real definition of the struct for the LC_PAPER locale. */
36struct locale_paper_t
37{
38 uint32_t height;
4b10dd6c 39 uint32_t width;
4b10dd6c
UD
40};
41
42
43static void
44paper_startup (struct linereader *lr, struct localedef_t *locale,
45 int ignore_content)
46{
47 if (!ignore_content)
48 locale->categories[LC_PAPER].paper =
49 (struct locale_paper_t *) xcalloc (1, sizeof (struct locale_paper_t));
50
b9eb05d6
UD
51 if (lr != NULL)
52 {
53 lr->translate_strings = 1;
54 lr->return_widestr = 0;
55 }
4b10dd6c
UD
56}
57
58
59void
47e8b443 60paper_finish (struct localedef_t *locale, const struct charmap_t *charmap)
4b10dd6c
UD
61{
62 struct locale_paper_t *paper = locale->categories[LC_PAPER].paper;
b9eb05d6
UD
63 int nothing = 0;
64
65 /* Now resolve copying and also handle completely missing definitions. */
66 if (paper == NULL)
67 {
68 /* First see whether we were supposed to copy. If yes, find the
69 actual definition. */
70 if (locale->copy_name[LC_PAPER] != NULL)
71 {
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;
75
76 do
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);
81
82 paper = locale->categories[LC_PAPER].paper
83 = from->categories[LC_PAPER].paper;
84 }
85
86 /* If there is still no definition issue an warning and create an
87 empty one. */
88 if (paper == NULL)
89 {
f6ada7ad 90 if (! be_quiet)
f2b98f97
UD
91 WITH_CUR_LOCALE (error (0, 0, _("\
92No definition for %s category found"), "LC_PAPER"));
b9eb05d6
UD
93 paper_startup (NULL, locale, 0);
94 paper = locale->categories[LC_PAPER].paper;
95 nothing = 1;
96 }
97 }
4b10dd6c
UD
98
99 if (paper->height == 0)
100 {
b9eb05d6 101 if (! nothing)
f2b98f97
UD
102 WITH_CUR_LOCALE (error (0, 0, _("%s: field `%s' not defined"),
103 "LC_PAPER", "height"));
4b10dd6c
UD
104 /* Use as default values the values from the i18n locale. */
105 paper->height = 297;
106 }
4b10dd6c
UD
107
108 if (paper->width == 0)
109 {
b9eb05d6 110 if (! nothing)
f2b98f97
UD
111 WITH_CUR_LOCALE (error (0, 0, _("%s: field `%s' not defined"),
112 "LC_PAPER", "width"));
4b10dd6c
UD
113 /* Use as default values the values from the i18n locale. */
114 paper->width = 210;
115 }
4b10dd6c
UD
116}
117
118
119void
47e8b443 120paper_output (struct localedef_t *locale, const struct charmap_t *charmap,
4b10dd6c
UD
121 const char *output_path)
122{
123 struct locale_paper_t *paper = locale->categories[LC_PAPER].paper;
1ecbb381
RS
124 struct locale_file file;
125
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);
4b10dd6c
UD
131}
132
133
134/* The parser for the LC_PAPER section of the locale definition. */
135void
136paper_read (struct linereader *ldfile, struct localedef_t *result,
47e8b443 137 const struct charmap_t *charmap, const char *repertoire_name,
4b10dd6c
UD
138 int ignore_content)
139{
4b10dd6c
UD
140 struct locale_paper_t *paper;
141 struct token *now;
142 struct token *arg;
143 enum token_t nowtok;
144
4b10dd6c
UD
145 /* The rest of the line containing `LC_PAPER' must be empty. */
146 lr_ignore_rest (ldfile, 1);
147
148 do
149 {
47e8b443 150 now = lr_token (ldfile, charmap, result, NULL, verbose);
4b10dd6c
UD
151 nowtok = now->tok;
152 }
153 while (nowtok == tok_eol);
154
155 /* If we see `copy' now we are almost done. */
156 if (nowtok == tok_copy)
157 {
01ff9d0b 158 handle_copy (ldfile, charmap, repertoire_name, result, tok_lc_paper,
b9eb05d6 159 LC_PAPER, "LC_PAPER", ignore_content);
4b10dd6c
UD
160 return;
161 }
162
163 /* Prepare the data structures. */
164 paper_startup (ldfile, result, ignore_content);
165 paper = result->categories[LC_PAPER].paper;
166
167 while (1)
168 {
169 /* Of course we don't proceed beyond the end of file. */
170 if (nowtok == tok_eof)
171 break;
172
173 /* Ingore empty lines. */
174 if (nowtok == tok_eol)
175 {
47e8b443 176 now = lr_token (ldfile, charmap, result, NULL, verbose);
4b10dd6c
UD
177 nowtok = now->tok;
178 continue;
179 }
180
181 switch (nowtok)
182 {
183#define INT_ELEM(cat) \
184 case tok_##cat: \
b9eb05d6
UD
185 /* Ignore the rest of the line if we don't need the input of \
186 this line. */ \
187 if (ignore_content) \
188 { \
189 lr_ignore_rest (ldfile, 0); \
190 break; \
191 } \
192 \
47e8b443 193 arg = lr_token (ldfile, charmap, result, NULL, verbose); \
4b10dd6c
UD
194 if (arg->tok != tok_number) \
195 goto err_label; \
196 else if (paper->cat != 0) \
197 lr_error (ldfile, _("%s: field `%s' declared more than once"), \
198 "LC_PAPER", #cat); \
199 else if (!ignore_content) \
200 paper->cat = arg->val.num; \
201 break
202
203 INT_ELEM (height);
204 INT_ELEM (width);
205
206 case tok_end:
207 /* Next we assume `LC_PAPER'. */
47e8b443 208 arg = lr_token (ldfile, charmap, result, NULL, verbose);
4b10dd6c
UD
209 if (arg->tok == tok_eof)
210 break;
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);
217 return;
218
219 default:
220 err_label:
221 SYNTAX_ERROR (_("%s: syntax error"), "LC_PAPER");
222 }
223
224 /* Prepare for the next round. */
47e8b443 225 now = lr_token (ldfile, charmap, result, NULL, verbose);
4b10dd6c
UD
226 nowtok = now->tok;
227 }
228
229 /* When we come here we reached the end of the file. */
230 lr_error (ldfile, _("%s: premature end of file"), "LC_PAPER");
231}