1 Allow preprocessor-like directives. These keywords were already
2 defined in locale/programs/locfile-kw.h, an implementation for
3 'define', 'undef', 'ifdef', 'else' and 'endif' is now provided in
4 locale/programs/ld-collate.c. For the moment, 'ifndef' and 'elif'
5 are not implemented because they do not appear in locfile-kw.h.
6 This patch is harmless, it only adds new keywords.
8 # DP: Dpatch author: Denis Barbier
9 # DP: Patch author: Denis Barbier
10 # DP: Upstream status: BZ686
11 # DP: Date: 2006-01-08
14 locale/programs/ld-collate.c | 275 +++++++++++++++++++++++++++++++++++++++++++
15 1 file changed, 275 insertions(+)
17 --- a/locale/programs/ld-collate.c
18 +++ b/locale/programs/ld-collate.c
23 +/* Data type for toggles. */
24 +struct toggle_list_t;
30 + /* Predecessor in the list. */
31 + struct toggle_list_t *last;
33 + /* This flag is set when a keyword is undefined. */
36 + /* Where does the branch come from. */
41 /* Sparse table of struct element_t *. */
42 #define TABLE wchead_table
43 #define ELEMENT struct element_t *
45 /* This value is used when handling ellipsis. */
46 struct element_t ellipsis_weight;
48 + /* This is a stack of . */
49 + struct toggle_list_t *flow_control;
51 /* Known collating elements. */
52 hash_table elem_table;
54 @@ -1467,6 +1488,56 @@
58 +static struct token *
59 +flow_skip (struct linereader *ldfile, const struct charmap_t *charmap,
60 + struct locale_collate_t *collate)
64 + enum token_t nowtok;
67 + lr_ignore_rest (ldfile, 0);
68 + now = lr_token (ldfile, charmap, NULL, NULL, 0);
70 + if (nowtok == tok_eof)
72 + else if (nowtok == tok_ifdef || nowtok == tok_ifndef)
74 + else if (nowtok == tok_else)
76 + if (strcmp (collate->flow_control->name, "else") == 0)
78 + _("%s: `else' statement at `%s:%Zu' cannot be followed by another `else' statement"),
79 + "LC_COLLATE", collate->flow_control->name, collate->flow_control->line);
82 + collate->flow_control->name = "else";
83 + collate->flow_control->file = ldfile->fname;
84 + collate->flow_control->line = ldfile->lineno;
88 + else if (nowtok == tok_endif)
92 + collate->flow_control = collate->flow_control->last;
98 + if (nowtok == tok_eof)
99 + WITH_CUR_LOCALE (error (0, 0, _("\
100 +%s: unterminated `%s' flow control beginning at %s:%Zu"),
101 + "LC_COLLATE", collate->flow_control->name,
102 + collate->flow_control->file,
103 + collate->flow_control->line));
109 collate_startup (struct linereader *ldfile, struct localedef_t *locale,
110 struct localedef_t *copy_locale, int ignore_content)
111 @@ -2514,6 +2585,8 @@
115 + static struct toggle_list_t *defined_keywords = NULL;
117 /* Get the repertoire we have to use. */
118 if (repertoire_name != NULL)
119 repertoire = repertoire_read (repertoire_name);
120 @@ -2528,6 +2601,82 @@
122 while (nowtok == tok_eol);
124 + while (nowtok == tok_define || nowtok == tok_undef)
126 + /* Ignore the rest of the line if we don't need the input of
128 + if (ignore_content)
130 + lr_ignore_rest (ldfile, 0);
131 + now = lr_token (ldfile, charmap, result, NULL, verbose);
136 + arg = lr_token (ldfile, charmap, result, NULL, verbose);
137 + if (arg->tok != tok_ident)
140 + if (nowtok == tok_define)
142 + struct toggle_list_t *runp = defined_keywords;
145 + while (runp != NULL)
146 + if (strncmp (runp->name, arg->val.str.startmb,
147 + arg->val.str.lenmb) == 0
148 + && runp->name[arg->val.str.lenmb] == '\0')
149 + SYNTAX_ERROR (_("%s: syntax error"), "LC_COLLATE");
153 + if (runp != NULL && runp->is_undefined == 0)
155 + lr_ignore_rest (ldfile, 0);
156 + SYNTAX_ERROR (_("%s: syntax error"), "LC_COLLATE");
161 + runp = (struct toggle_list_t *) xcalloc (1, sizeof (*runp));
162 + runp->last = defined_keywords;
163 + defined_keywords = runp;
167 + free ((char *) runp->name);
168 + runp->is_undefined = 0;
171 + name = (char *) xmalloc (arg->val.str.lenmb + 1);
172 + memcpy (name, arg->val.str.startmb, arg->val.str.lenmb);
173 + name[arg->val.str.lenmb] = '\0';
178 + struct toggle_list_t *runp = defined_keywords;
179 + while (runp != NULL)
180 + if (strncmp (runp->name, arg->val.str.startmb,
181 + arg->val.str.lenmb) == 0
182 + && runp->name[arg->val.str.lenmb] == '\0')
184 + runp->is_undefined = 1;
185 + SYNTAX_ERROR (_("%s: syntax error"), "LC_COLLATE");
191 + lr_ignore_rest (ldfile, 1);
194 + now = lr_token (ldfile, charmap, result, NULL, verbose);
197 + while (nowtok == tok_eol);
200 if (nowtok == tok_copy)
202 now = lr_token (ldfile, charmap, result, NULL, verbose);
203 @@ -3682,6 +3831,125 @@
204 repertoire, result, nowtok);
208 + /* Ignore the rest of the line if we don't need the input of
210 + if (ignore_content)
212 + lr_ignore_rest (ldfile, 0);
216 + arg = lr_token (ldfile, charmap, result, NULL, verbose);
217 + if (arg->tok != tok_ident)
221 + struct toggle_list_t *runp = defined_keywords;
222 + struct toggle_list_t *flow = (struct toggle_list_t *) xcalloc (1, sizeof (*runp));
223 + flow->name = "ifdef";
224 + flow->file = ldfile->fname;
225 + flow->line = ldfile->lineno;
226 + flow->last = collate->flow_control;
227 + collate->flow_control = flow;
229 + while (runp != NULL)
230 + if (strncmp (runp->name, arg->val.str.startmb,
231 + arg->val.str.lenmb) == 0
232 + && runp->name[arg->val.str.lenmb] == '\0')
239 + now = flow_skip(ldfile, charmap, collate);
240 + if (now->tok == tok_eof)
241 + WITH_CUR_LOCALE (error (0, 0, _("\
242 +%s: unterminated `%s' flow control"), "LC_COLLATE", collate->flow_control->name));
245 + lr_ignore_rest (ldfile, 1);
249 + /* Ignore the rest of the line if we don't need the input of
251 + if (ignore_content)
253 + lr_ignore_rest (ldfile, 0);
257 + arg = lr_token (ldfile, charmap, result, NULL, verbose);
258 + if (arg->tok != tok_ident)
262 + struct toggle_list_t *runp = defined_keywords;
263 + struct toggle_list_t *flow = (struct toggle_list_t *) xcalloc (1, sizeof (*runp));
264 + flow->name = "ifndef";
265 + flow->file = ldfile->fname;
266 + flow->line = ldfile->lineno;
267 + flow->last = collate->flow_control;
268 + collate->flow_control = flow;
270 + while (runp != NULL)
271 + if (strncmp (runp->name, arg->val.str.startmb,
272 + arg->val.str.lenmb) == 0
273 + && runp->name[arg->val.str.lenmb] == '\0')
280 + now = flow_skip(ldfile, charmap, collate);
281 + if (now->tok == tok_eof)
282 + WITH_CUR_LOCALE (error (0, 0, _("\
283 +%s: unterminated `%s' flow control"), "LC_COLLATE", collate->flow_control->name));
286 + lr_ignore_rest (ldfile, 1);
290 + /* Ignore the rest of the line if we don't need the input of
292 + if (ignore_content)
294 + lr_ignore_rest (ldfile, 0);
298 + if (strcmp (collate->flow_control->name, "else") == 0)
300 + _("%s: `else' statement at `%s:%Zu' cannot be followed by another `else' statement"),
301 + "LC_COLLATE", collate->flow_control->name, collate->flow_control->line);
302 + collate->flow_control->name = "else";
303 + collate->flow_control->file = ldfile->fname;
304 + collate->flow_control->line = ldfile->lineno;
305 + now = flow_skip(ldfile, charmap, collate);
306 + if (now->tok == tok_eof)
307 + WITH_CUR_LOCALE (error (0, 0, _("\
308 +%s: unterminated `%s' flow control"), "LC_COLLATE", collate->flow_control->name));
312 + /* Ignore the rest of the line if we don't need the input of
314 + if (ignore_content)
316 + lr_ignore_rest (ldfile, 0);
320 + if (collate->flow_control == NULL)
323 + collate->flow_control = collate->flow_control->last;
327 /* Next we assume `LC_COLLATE'. */
329 @@ -3711,6 +3979,13 @@
331 WITH_CUR_LOCALE (error (0, 0, _("\
332 %s: missing `reorder-sections-end' keyword"), "LC_COLLATE"));
333 + if (collate->flow_control != NULL
334 + && strcmp(collate->flow_control->file, ldfile->fname) == 0)
335 + WITH_CUR_LOCALE (error (0, 0, _("\
336 +%s: unterminated `%s' flow control beginning at %s:%Zu"),
337 + "LC_COLLATE", collate->flow_control->name,
338 + collate->flow_control->file,
339 + collate->flow_control->line));
341 arg = lr_token (ldfile, charmap, result, NULL, verbose);
342 if (arg->tok == tok_eof)