1 | /* Copyright (C) 1996-2021 Free Software Foundation, Inc. |
2 | This file is part of the GNU C Library. |
3 | Contributed by Ulrich Drepper <drepper@gnu.org>, 1996. |
4 | |
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. |
9 | |
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. |
14 | |
15 | You should have received a copy of the GNU General Public License |
16 | along with this program; if not, see <https://www.gnu.org/licenses/>. */ |
17 | |
18 | #ifndef _LOCFILE_H |
19 | #define _LOCFILE_H 1 |
20 | |
21 | #include <byteswap.h> |
22 | #include <stdbool.h> |
23 | #include <stdint.h> |
24 | #include <sys/uio.h> |
25 | |
26 | #include "obstack.h" |
27 | #include "linereader.h" |
28 | #include "localedef.h" |
29 | |
30 | /* Structure for storing the contents of a category file. */ |
31 | struct locale_file |
32 | { |
33 | size_t n_elements, next_element; |
34 | uint32_t *offsets; |
35 | struct obstack data; |
36 | int structure_stage; |
37 | }; |
38 | |
39 | |
40 | /* Macros used in the parser. */ |
41 | #define SYNTAX_ERROR(string, args...) \ |
42 | do \ |
43 | { \ |
44 | lr_error (ldfile, string, ## args); \ |
45 | lr_ignore_rest (ldfile, 0); \ |
46 | } \ |
47 | while (0) |
48 | |
49 | |
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, |
56 | int ignore_content); |
57 | |
58 | /* Found in locfile.c. */ |
59 | extern int locfile_read (struct localedef_t *result, |
60 | const struct charmap_t *charmap); |
61 | |
62 | /* Check validity of all the locale data. */ |
63 | extern void check_all_categories (struct localedef_t *definitions, |
64 | const struct charmap_t *charmap); |
65 | |
66 | /* Write out all locale categories. */ |
67 | extern void write_all_categories (struct localedef_t *definitions, |
68 | const struct charmap_t *charmap, |
69 | const char *locname, |
70 | const char *output_path); |
71 | |
72 | extern bool swap_endianness_p; |
73 | |
74 | /* Change the output to be big-endian if BIG_ENDIAN is true and |
75 | little-endian otherwise. */ |
76 | static inline void |
77 | set_big_endian (bool big_endian) |
78 | { |
79 | swap_endianness_p = (big_endian != (__BYTE_ORDER == __BIG_ENDIAN)); |
80 | } |
81 | |
82 | /* Munge VALUE so that, when stored, it has the correct byte order |
83 | for the output files. */ |
84 | static uint32_t |
85 | __attribute__ ((unused)) |
86 | maybe_swap_uint32 (uint32_t value) |
87 | { |
88 | return swap_endianness_p ? bswap_32 (value) : value; |
89 | } |
90 | |
91 | /* Likewise, but munge an array of N uint32_ts starting at ARRAY. */ |
92 | static inline void |
93 | maybe_swap_uint32_array (uint32_t *array, size_t n) |
94 | { |
95 | if (swap_endianness_p) |
96 | while (n-- > 0) |
97 | array[n] = bswap_32 (array[n]); |
98 | } |
99 | |
100 | /* Like maybe_swap_uint32_array, but the array of N elements is at |
101 | the end of OBSTACK's current object. */ |
102 | static inline void |
103 | maybe_swap_uint32_obstack (struct obstack *obstack, size_t n) |
104 | { |
105 | maybe_swap_uint32_array ((uint32_t *) obstack_next_free (obstack) - n, n); |
106 | } |
107 | |
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, |
113 | size_t size); |
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); |
129 | |
130 | |
131 | /* Entrypoints for the parsers of the individual categories. */ |
132 | |
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, |
138 | int ignore_content); |
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); |
146 | |
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, |
152 | int ignore_content); |
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); |
158 | |
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, |
164 | int ignore_content); |
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); |
170 | |
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, |
176 | int ignore_content); |
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); |
182 | |
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, |
188 | int ignore_content); |
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); |
194 | |
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, |
200 | int ignore_content); |
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); |
206 | |
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, |
212 | int ignore_content); |
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); |
218 | |
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, |
224 | int ignore_content); |
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); |
230 | |
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, |
236 | int ignore_content); |
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); |
242 | |
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, |
248 | int ignore_content); |
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); |
254 | |
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, |
260 | int ignore_content); |
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); |
266 | |
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, |
272 | int ignore_content); |
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); |
278 | |
279 | #endif /* locfile.h */ |
280 | |