1 /* Copyright (C) 1996-2018 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@gnu.org>, 1996.
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/>. */
27 #include "linereader.h"
28 #include "localedef.h"
30 /* Structure for storing the contents of a category file. */
33 size_t n_elements
, next_element
;
40 /* Macros used in the parser. */
41 #define SYNTAX_ERROR(string, args...) \
44 lr_error (ldfile, string, ## args); \
45 lr_ignore_rest (ldfile, 0); \
50 /* General handling of `copy'. */
51 extern void handle_copy (struct linereader
*ldfile
,
52 const struct charmap_t
*charmap
,
53 const char *repertoire_name
,
54 struct localedef_t
*result
, enum token_t token
,
55 int locale
, const char *locale_name
,
58 /* Found in locfile.c. */
59 extern int locfile_read (struct localedef_t
*result
,
60 const struct charmap_t
*charmap
);
62 /* Check validity of all the locale data. */
63 extern void check_all_categories (struct localedef_t
*definitions
,
64 const struct charmap_t
*charmap
);
66 /* Write out all locale categories. */
67 extern void write_all_categories (struct localedef_t
*definitions
,
68 const struct charmap_t
*charmap
,
70 const char *output_path
);
72 extern bool swap_endianness_p
;
74 /* Change the output to be big-endian if BIG_ENDIAN is true and
75 little-endian otherwise. */
77 set_big_endian (bool big_endian
)
79 swap_endianness_p
= (big_endian
!= (__BYTE_ORDER
== __BIG_ENDIAN
));
82 /* Munge VALUE so that, when stored, it has the correct byte order
83 for the output files. */
85 __attribute__ ((unused
))
86 maybe_swap_uint32 (uint32_t value
)
88 return swap_endianness_p
? bswap_32 (value
) : value
;
91 /* Likewise, but munge an array of N uint32_ts starting at ARRAY. */
93 maybe_swap_uint32_array (uint32_t *array
, size_t n
)
95 if (swap_endianness_p
)
97 array
[n
] = bswap_32 (array
[n
]);
100 /* Like maybe_swap_uint32_array, but the array of N elements is at
101 the end of OBSTACK's current object. */
103 maybe_swap_uint32_obstack (struct obstack
*obstack
, size_t n
)
105 maybe_swap_uint32_array ((uint32_t *) obstack_next_free (obstack
) - n
, n
);
108 /* Write out the data. */
109 extern void init_locale_data (struct locale_file
*file
, size_t n_elements
);
110 extern void align_locale_data (struct locale_file
*file
, size_t boundary
);
111 extern void add_locale_empty (struct locale_file
*file
);
112 extern void add_locale_raw_data (struct locale_file
*file
, const void *data
,
114 extern void add_locale_raw_obstack (struct locale_file
*file
,
115 struct obstack
*obstack
);
116 extern void add_locale_string (struct locale_file
*file
, const char *string
);
117 extern void add_locale_wstring (struct locale_file
*file
,
118 const uint32_t *string
);
119 extern void add_locale_uint32 (struct locale_file
*file
, uint32_t value
);
120 extern void add_locale_uint32_array (struct locale_file
*file
,
121 const uint32_t *data
, size_t n_elems
);
122 extern void add_locale_char (struct locale_file
*file
, char value
);
123 extern void start_locale_structure (struct locale_file
*file
);
124 extern void end_locale_structure (struct locale_file
*file
);
125 extern void start_locale_prelude (struct locale_file
*file
);
126 extern void end_locale_prelude (struct locale_file
*file
);
127 extern void write_locale_data (const char *output_path
, int catidx
,
128 const char *category
, struct locale_file
*file
);
131 /* Entrypoints for the parsers of the individual categories. */
133 /* Handle LC_CTYPE category. */
134 extern void ctype_read (struct linereader
*ldfile
,
135 struct localedef_t
*result
,
136 const struct charmap_t
*charmap
,
137 const char *repertoire_name
,
139 extern void ctype_finish (struct localedef_t
*locale
,
140 const struct charmap_t
*charmap
);
141 extern void ctype_output (struct localedef_t
*locale
,
142 const struct charmap_t
*charmap
,
143 const char *output_path
);
144 extern uint32_t *find_translit (struct localedef_t
*locale
,
145 const struct charmap_t
*charmap
, uint32_t wch
);
147 /* Handle LC_COLLATE category. */
148 extern void collate_read (struct linereader
*ldfile
,
149 struct localedef_t
*result
,
150 const struct charmap_t
*charmap
,
151 const char *repertoire_name
,
153 extern void collate_finish (struct localedef_t
*locale
,
154 const struct charmap_t
*charmap
);
155 extern void collate_output (struct localedef_t
*locale
,
156 const struct charmap_t
*charmap
,
157 const char *output_path
);
159 /* Handle LC_MONETARY category. */
160 extern void monetary_read (struct linereader
*ldfile
,
161 struct localedef_t
*result
,
162 const struct charmap_t
*charmap
,
163 const char *repertoire_name
,
165 extern void monetary_finish (struct localedef_t
*locale
,
166 const struct charmap_t
*charmap
);
167 extern void monetary_output (struct localedef_t
*locale
,
168 const struct charmap_t
*charmap
,
169 const char *output_path
);
171 /* Handle LC_NUMERIC category. */
172 extern void numeric_read (struct linereader
*ldfile
,
173 struct localedef_t
*result
,
174 const struct charmap_t
*charmap
,
175 const char *repertoire_name
,
177 extern void numeric_finish (struct localedef_t
*locale
,
178 const struct charmap_t
*charmap
);
179 extern void numeric_output (struct localedef_t
*locale
,
180 const struct charmap_t
*charmap
,
181 const char *output_path
);
183 /* Handle LC_MESSAGES category. */
184 extern void messages_read (struct linereader
*ldfile
,
185 struct localedef_t
*result
,
186 const struct charmap_t
*charmap
,
187 const char *repertoire_name
,
189 extern void messages_finish (struct localedef_t
*locale
,
190 const struct charmap_t
*charmap
);
191 extern void messages_output (struct localedef_t
*locale
,
192 const struct charmap_t
*charmap
,
193 const char *output_path
);
195 /* Handle LC_TIME category. */
196 extern void time_read (struct linereader
*ldfile
,
197 struct localedef_t
*result
,
198 const struct charmap_t
*charmap
,
199 const char *repertoire_name
,
201 extern void time_finish (struct localedef_t
*locale
,
202 const struct charmap_t
*charmap
);
203 extern void time_output (struct localedef_t
*locale
,
204 const struct charmap_t
*charmap
,
205 const char *output_path
);
207 /* Handle LC_PAPER category. */
208 extern void paper_read (struct linereader
*ldfile
,
209 struct localedef_t
*result
,
210 const struct charmap_t
*charmap
,
211 const char *repertoire_name
,
213 extern void paper_finish (struct localedef_t
*locale
,
214 const struct charmap_t
*charmap
);
215 extern void paper_output (struct localedef_t
*locale
,
216 const struct charmap_t
*charmap
,
217 const char *output_path
);
219 /* Handle LC_NAME category. */
220 extern void name_read (struct linereader
*ldfile
,
221 struct localedef_t
*result
,
222 const struct charmap_t
*charmap
,
223 const char *repertoire_name
,
225 extern void name_finish (struct localedef_t
*locale
,
226 const struct charmap_t
*charmap
);
227 extern void name_output (struct localedef_t
*locale
,
228 const struct charmap_t
*charmap
,
229 const char *output_path
);
231 /* Handle LC_ADDRESS category. */
232 extern void address_read (struct linereader
*ldfile
,
233 struct localedef_t
*result
,
234 const struct charmap_t
*charmap
,
235 const char *repertoire_name
,
237 extern void address_finish (struct localedef_t
*locale
,
238 const struct charmap_t
*charmap
);
239 extern void address_output (struct localedef_t
*locale
,
240 const struct charmap_t
*charmap
,
241 const char *output_path
);
243 /* Handle LC_TELEPHONE category. */
244 extern void telephone_read (struct linereader
*ldfile
,
245 struct localedef_t
*result
,
246 const struct charmap_t
*charmap
,
247 const char *repertoire_name
,
249 extern void telephone_finish (struct localedef_t
*locale
,
250 const struct charmap_t
*charmap
);
251 extern void telephone_output (struct localedef_t
*locale
,
252 const struct charmap_t
*charmap
,
253 const char *output_path
);
255 /* Handle LC_MEASUREMENT category. */
256 extern void measurement_read (struct linereader
*ldfile
,
257 struct localedef_t
*result
,
258 const struct charmap_t
*charmap
,
259 const char *repertoire_name
,
261 extern void measurement_finish (struct localedef_t
*locale
,
262 const struct charmap_t
*charmap
);
263 extern void measurement_output (struct localedef_t
*locale
,
264 const struct charmap_t
*charmap
,
265 const char *output_path
);
267 /* Handle LC_IDENTIFICATION category. */
268 extern void identification_read (struct linereader
*ldfile
,
269 struct localedef_t
*result
,
270 const struct charmap_t
*charmap
,
271 const char *repertoire_name
,
273 extern void identification_finish (struct localedef_t
*locale
,
274 const struct charmap_t
*charmap
);
275 extern void identification_output (struct localedef_t
*locale
,
276 const struct charmap_t
*charmap
,
277 const char *output_path
);
279 #endif /* locfile.h */