]>
Commit | Line | Data |
---|---|---|
40675e7c | 1 | /* Token-reader for Bison's input parser, |
62ab6972 | 2 | Copyright 1984, 1986, 1989, 1992, 2000, 2001 Free Software Foundation, Inc. |
40675e7c | 3 | |
a0f6b076 | 4 | This file is part of Bison, the GNU Compiler Compiler. |
40675e7c | 5 | |
a0f6b076 AD |
6 | Bison is free software; you can redistribute it and/or modify |
7 | it under the terms of the GNU General Public License as published by | |
8 | the Free Software Foundation; either version 2, or (at your option) | |
9 | any later version. | |
40675e7c | 10 | |
a0f6b076 AD |
11 | Bison is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
40675e7c | 15 | |
a0f6b076 AD |
16 | You should have received a copy of the GNU General Public License |
17 | along with Bison; see the file COPYING. If not, write to | |
18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
19 | Boston, MA 02111-1307, USA. */ | |
40675e7c | 20 | |
40675e7c | 21 | #include "system.h" |
ceed8467 | 22 | #include "getargs.h" |
40675e7c DM |
23 | #include "files.h" |
24 | #include "symtab.h" | |
82b6d266 | 25 | #include "options.h" |
40675e7c | 26 | #include "lex.h" |
a0f6b076 | 27 | #include "complain.h" |
b2ca4022 | 28 | #include "gram.h" |
ff4a34be | 29 | #include "quote.h" |
40675e7c DM |
30 | |
31 | /* Buffer for storing the current token. */ | |
0846f581 | 32 | static struct obstack token_obstack; |
09b503c8 | 33 | const char *token_buffer = NULL; |
40675e7c | 34 | |
09b503c8 | 35 | bucket *symval = NULL; |
40675e7c DM |
36 | int numval; |
37 | ||
561f9a30 | 38 | /* A token to be reread, see unlex and lex. */ |
342b8b6e | 39 | static token_t unlexed = tok_undef; |
342b8b6e | 40 | static bucket *unlexed_symval = NULL; |
09b503c8 | 41 | static const char *unlexed_token_buffer = NULL; |
40675e7c DM |
42 | |
43 | void | |
342b8b6e | 44 | lex_init (void) |
40675e7c | 45 | { |
f17bcd1f | 46 | obstack_init (&token_obstack); |
342b8b6e AD |
47 | unlexed = tok_undef; |
48 | } | |
49 | ||
50 | ||
51 | void | |
52 | lex_free (void) | |
53 | { | |
54 | obstack_free (&token_obstack, NULL); | |
40675e7c DM |
55 | } |
56 | ||
57 | ||
40675e7c | 58 | int |
d2729d44 | 59 | skip_white_space (void) |
40675e7c | 60 | { |
abadc117 AD |
61 | int c; |
62 | int inside; | |
40675e7c | 63 | |
abadc117 | 64 | c = getc (finput); |
40675e7c DM |
65 | |
66 | for (;;) | |
67 | { | |
68 | int cplus_comment; | |
69 | ||
70 | switch (c) | |
71 | { | |
72 | case '/': | |
79282c5a | 73 | /* FIXME: Should probably be merged with copy_comment. */ |
abadc117 | 74 | c = getc (finput); |
a083fbbf | 75 | if (c != '*' && c != '/') |
a44c2277 | 76 | { |
a0f6b076 | 77 | complain (_("unexpected `/' found and ignored")); |
a44c2277 RS |
78 | break; |
79 | } | |
40675e7c DM |
80 | cplus_comment = (c == '/'); |
81 | ||
abadc117 | 82 | c = getc (finput); |
40675e7c DM |
83 | |
84 | inside = 1; | |
85 | while (inside) | |
86 | { | |
87 | if (!cplus_comment && c == '*') | |
88 | { | |
89 | while (c == '*') | |
abadc117 | 90 | c = getc (finput); |
40675e7c DM |
91 | |
92 | if (c == '/') | |
93 | { | |
94 | inside = 0; | |
abadc117 | 95 | c = getc (finput); |
40675e7c DM |
96 | } |
97 | } | |
98 | else if (c == '\n') | |
99 | { | |
100 | lineno++; | |
101 | if (cplus_comment) | |
102 | inside = 0; | |
abadc117 | 103 | c = getc (finput); |
40675e7c DM |
104 | } |
105 | else if (c == EOF) | |
a0f6b076 | 106 | fatal (_("unterminated comment")); |
40675e7c | 107 | else |
abadc117 | 108 | c = getc (finput); |
40675e7c DM |
109 | } |
110 | ||
111 | break; | |
112 | ||
113 | case '\n': | |
114 | lineno++; | |
115 | ||
116 | case ' ': | |
117 | case '\t': | |
118 | case '\f': | |
abadc117 | 119 | c = getc (finput); |
40675e7c DM |
120 | break; |
121 | ||
122 | default: | |
36281465 | 123 | return c; |
40675e7c DM |
124 | } |
125 | } | |
126 | } | |
127 | ||
79282c5a AD |
128 | |
129 | /*-----------------------------------------------------. | |
130 | | Do a getc, but give error message if EOF encountered | | |
131 | `-----------------------------------------------------*/ | |
132 | ||
428046f8 | 133 | int |
abadc117 | 134 | xgetc (FILE *f) |
a44c2277 | 135 | { |
abadc117 | 136 | int c = getc (f); |
a44c2277 | 137 | if (c == EOF) |
a0f6b076 | 138 | fatal (_("unexpected end of file")); |
a44c2277 RS |
139 | return c; |
140 | } | |
141 | ||
abadc117 | 142 | |
2648a72d AD |
143 | /*---------------------------------------------------------------. |
144 | | Read one literal character from FINPUT, process \-escapes, and | | |
145 | | return the character. | | |
146 | `---------------------------------------------------------------*/ | |
f17bcd1f | 147 | |
2648a72d AD |
148 | char |
149 | literalchar (void) | |
a44c2277 | 150 | { |
abadc117 | 151 | int c; |
2648a72d | 152 | int res; |
a44c2277 | 153 | |
abadc117 | 154 | c = xgetc (finput); |
a083fbbf | 155 | if (c == '\n') |
a44c2277 | 156 | { |
a0f6b076 | 157 | complain (_("unescaped newline in constant")); |
abadc117 | 158 | ungetc (c, finput); |
2648a72d | 159 | res = '?'; |
a44c2277 RS |
160 | } |
161 | else if (c != '\\') | |
162 | { | |
2648a72d | 163 | res = c; |
a44c2277 RS |
164 | } |
165 | else | |
166 | { | |
abadc117 AD |
167 | c = xgetc (finput); |
168 | if (c == 't') | |
2648a72d | 169 | res = '\t'; |
abadc117 | 170 | else if (c == 'n') |
2648a72d | 171 | res = '\n'; |
abadc117 | 172 | else if (c == 'a') |
2648a72d | 173 | res = '\007'; |
abadc117 | 174 | else if (c == 'r') |
2648a72d | 175 | res = '\r'; |
abadc117 | 176 | else if (c == 'f') |
2648a72d | 177 | res = '\f'; |
abadc117 | 178 | else if (c == 'b') |
2648a72d | 179 | res = '\b'; |
abadc117 | 180 | else if (c == 'v') |
2648a72d | 181 | res = '\013'; |
abadc117 | 182 | else if (c == '\\') |
2648a72d | 183 | res = '\\'; |
abadc117 | 184 | else if (c == '\'') |
2648a72d | 185 | res = '\''; |
abadc117 | 186 | else if (c == '\"') |
2648a72d | 187 | res = '\"'; |
a44c2277 RS |
188 | else if (c <= '7' && c >= '0') |
189 | { | |
2648a72d | 190 | res = 0; |
a44c2277 RS |
191 | while (c <= '7' && c >= '0') |
192 | { | |
2648a72d AD |
193 | res = (res * 8) + (c - '0'); |
194 | if (res >= 256 || res < 0) | |
a44c2277 | 195 | { |
a0f6b076 | 196 | complain (_("octal value outside range 0...255: `\\%o'"), |
2648a72d AD |
197 | res); |
198 | res &= 0xFF; | |
a44c2277 RS |
199 | break; |
200 | } | |
abadc117 | 201 | c = xgetc (finput); |
a44c2277 | 202 | } |
abadc117 | 203 | ungetc (c, finput); |
a44c2277 RS |
204 | } |
205 | else if (c == 'x') | |
206 | { | |
abadc117 | 207 | c = xgetc (finput); |
2648a72d | 208 | res = 0; |
a44c2277 RS |
209 | while (1) |
210 | { | |
211 | if (c >= '0' && c <= '9') | |
2648a72d | 212 | res *= 16, res += c - '0'; |
a44c2277 | 213 | else if (c >= 'a' && c <= 'f') |
2648a72d | 214 | res *= 16, res += c - 'a' + 10; |
a44c2277 | 215 | else if (c >= 'A' && c <= 'F') |
2648a72d | 216 | res *= 16, res += c - 'A' + 10; |
a083fbbf | 217 | else |
a44c2277 | 218 | break; |
2648a72d | 219 | if (res >= 256 || res < 0) |
a44c2277 | 220 | { |
2648a72d AD |
221 | complain (_("hexadecimal value above 255: `\\x%x'"), res); |
222 | res &= 0xFF; | |
a44c2277 RS |
223 | break; |
224 | } | |
abadc117 | 225 | c = xgetc (finput); |
a44c2277 | 226 | } |
abadc117 | 227 | ungetc (c, finput); |
a44c2277 RS |
228 | } |
229 | else | |
230 | { | |
b0ce6046 AD |
231 | char badchar [] = "c"; |
232 | badchar[0] = c; | |
a0f6b076 | 233 | complain (_("unknown escape sequence: `\\' followed by `%s'"), |
b0ce6046 | 234 | quote (badchar)); |
2648a72d | 235 | res = '?'; |
a44c2277 | 236 | } |
abadc117 | 237 | } /* has \ */ |
a44c2277 | 238 | |
2648a72d | 239 | return res; |
a44c2277 RS |
240 | } |
241 | ||
40675e7c DM |
242 | |
243 | void | |
342b8b6e | 244 | unlex (token_t token) |
40675e7c DM |
245 | { |
246 | unlexed = token; | |
561f9a30 | 247 | unlexed_token_buffer = token_buffer; |
40675e7c DM |
248 | unlexed_symval = symval; |
249 | } | |
250 | ||
f282676b AD |
251 | /*-----------------------------------------------------------------. |
252 | | We just read `<' from FIN. Store in TOKEN_BUFFER, the type name | | |
253 | | specified between the `<...>'. | | |
254 | `-----------------------------------------------------------------*/ | |
255 | ||
256 | void | |
257 | read_type_name (FILE *fin) | |
258 | { | |
f282676b AD |
259 | int c = getc (fin); |
260 | ||
261 | while (c != '>') | |
262 | { | |
263 | if (c == EOF) | |
264 | fatal (_("unterminated type name at end of file")); | |
265 | if (c == '\n') | |
266 | { | |
267 | complain (_("unterminated type name")); | |
268 | ungetc (c, fin); | |
269 | break; | |
270 | } | |
271 | ||
f17bcd1f | 272 | obstack_1grow (&token_obstack, c); |
f282676b AD |
273 | c = getc (fin); |
274 | } | |
f17bcd1f AD |
275 | obstack_1grow (&token_obstack, '\0'); |
276 | token_buffer = obstack_finish (&token_obstack); | |
f282676b AD |
277 | } |
278 | ||
40675e7c | 279 | |
511e79b3 | 280 | token_t |
d2729d44 | 281 | lex (void) |
40675e7c | 282 | { |
abadc117 | 283 | int c; |
f17bcd1f AD |
284 | |
285 | /* Just to make sure. */ | |
286 | token_buffer = NULL; | |
40675e7c | 287 | |
342b8b6e | 288 | if (unlexed != tok_undef) |
40675e7c | 289 | { |
342b8b6e | 290 | token_t res = unlexed; |
40675e7c | 291 | symval = unlexed_symval; |
561f9a30 | 292 | token_buffer = unlexed_token_buffer; |
342b8b6e AD |
293 | unlexed = tok_undef; |
294 | return res; | |
40675e7c DM |
295 | } |
296 | ||
abadc117 | 297 | c = skip_white_space (); |
40675e7c DM |
298 | |
299 | switch (c) | |
300 | { | |
301 | case EOF: | |
f17bcd1f | 302 | token_buffer = "EOF"; |
511e79b3 | 303 | return tok_eof; |
40675e7c | 304 | |
abadc117 AD |
305 | case 'A': case 'B': case 'C': case 'D': case 'E': |
306 | case 'F': case 'G': case 'H': case 'I': case 'J': | |
307 | case 'K': case 'L': case 'M': case 'N': case 'O': | |
308 | case 'P': case 'Q': case 'R': case 'S': case 'T': | |
309 | case 'U': case 'V': case 'W': case 'X': case 'Y': | |
40675e7c | 310 | case 'Z': |
abadc117 AD |
311 | case 'a': case 'b': case 'c': case 'd': case 'e': |
312 | case 'f': case 'g': case 'h': case 'i': case 'j': | |
313 | case 'k': case 'l': case 'm': case 'n': case 'o': | |
314 | case 'p': case 'q': case 'r': case 's': case 't': | |
315 | case 'u': case 'v': case 'w': case 'x': case 'y': | |
40675e7c | 316 | case 'z': |
abadc117 AD |
317 | case '.': case '_': |
318 | ||
abadc117 | 319 | while (isalnum (c) || c == '_' || c == '.') |
40675e7c | 320 | { |
f17bcd1f | 321 | obstack_1grow (&token_obstack, c); |
abadc117 | 322 | c = getc (finput); |
40675e7c | 323 | } |
f17bcd1f AD |
324 | obstack_1grow (&token_obstack, '\0'); |
325 | token_buffer = obstack_finish (&token_obstack); | |
abadc117 AD |
326 | ungetc (c, finput); |
327 | symval = getsym (token_buffer); | |
511e79b3 | 328 | return tok_identifier; |
40675e7c | 329 | |
abadc117 AD |
330 | case '0': case '1': case '2': case '3': case '4': |
331 | case '5': case '6': case '7': case '8': case '9': | |
40675e7c DM |
332 | { |
333 | numval = 0; | |
334 | ||
abadc117 | 335 | while (isdigit (c)) |
40675e7c | 336 | { |
f17bcd1f | 337 | obstack_1grow (&token_obstack, c); |
abadc117 AD |
338 | numval = numval * 10 + c - '0'; |
339 | c = getc (finput); | |
40675e7c | 340 | } |
f17bcd1f AD |
341 | obstack_1grow (&token_obstack, '\0'); |
342 | token_buffer = obstack_finish (&token_obstack); | |
abadc117 | 343 | ungetc (c, finput); |
511e79b3 | 344 | return tok_number; |
40675e7c DM |
345 | } |
346 | ||
347 | case '\'': | |
40675e7c DM |
348 | /* parse the literal token and compute character code in code */ |
349 | ||
40675e7c | 350 | { |
2648a72d | 351 | int code = literalchar (); |
5ce94c29 | 352 | |
f17bcd1f | 353 | obstack_1grow (&token_obstack, '\''); |
2648a72d | 354 | obstack_1grow (&token_obstack, code); |
40675e7c | 355 | |
abadc117 | 356 | c = getc (finput); |
a44c2277 | 357 | if (c != '\'') |
40675e7c | 358 | { |
a0f6b076 | 359 | complain (_("use \"...\" for multi-character literal tokens")); |
2648a72d AD |
360 | while (literalchar () != '\'') |
361 | /* Skip. */; | |
40675e7c | 362 | } |
f17bcd1f AD |
363 | obstack_1grow (&token_obstack, '\''); |
364 | obstack_1grow (&token_obstack, '\0'); | |
365 | token_buffer = obstack_finish (&token_obstack); | |
abadc117 | 366 | symval = getsym (token_buffer); |
d7020c20 | 367 | symval->class = token_sym; |
6b7e85b9 | 368 | if (symval->user_token_number == SUNDEF) |
a44c2277 | 369 | symval->user_token_number = code; |
511e79b3 | 370 | return tok_identifier; |
a44c2277 | 371 | } |
40675e7c | 372 | |
a44c2277 | 373 | case '\"': |
a44c2277 RS |
374 | /* parse the literal string token and treat as an identifier */ |
375 | ||
a44c2277 | 376 | { |
abadc117 | 377 | int code; /* ignored here */ |
f17bcd1f AD |
378 | |
379 | obstack_1grow (&token_obstack, '\"'); | |
79282c5a | 380 | /* Read up to and including ". */ |
2648a72d AD |
381 | do |
382 | { | |
383 | code = literalchar (); | |
384 | obstack_1grow (&token_obstack, code); | |
385 | } | |
386 | while (code != '\"'); | |
f17bcd1f AD |
387 | obstack_1grow (&token_obstack, '\0'); |
388 | token_buffer = obstack_finish (&token_obstack); | |
a44c2277 | 389 | |
abadc117 | 390 | symval = getsym (token_buffer); |
d7020c20 | 391 | symval->class = token_sym; |
a44c2277 | 392 | |
511e79b3 | 393 | return tok_identifier; |
40675e7c DM |
394 | } |
395 | ||
396 | case ',': | |
342b8b6e | 397 | token_buffer = ","; |
511e79b3 | 398 | return tok_comma; |
40675e7c DM |
399 | |
400 | case ':': | |
342b8b6e | 401 | token_buffer = ":"; |
511e79b3 | 402 | return tok_colon; |
40675e7c DM |
403 | |
404 | case ';': | |
342b8b6e | 405 | token_buffer = ";"; |
511e79b3 | 406 | return tok_semicolon; |
40675e7c DM |
407 | |
408 | case '|': | |
342b8b6e | 409 | token_buffer = "|"; |
511e79b3 | 410 | return tok_bar; |
40675e7c DM |
411 | |
412 | case '{': | |
342b8b6e | 413 | token_buffer = "{"; |
511e79b3 | 414 | return tok_left_curly; |
40675e7c DM |
415 | |
416 | case '=': | |
342b8b6e | 417 | obstack_1grow (&token_obstack, c); |
40675e7c DM |
418 | do |
419 | { | |
abadc117 | 420 | c = getc (finput); |
342b8b6e | 421 | obstack_1grow (&token_obstack, c); |
abadc117 AD |
422 | if (c == '\n') |
423 | lineno++; | |
40675e7c | 424 | } |
abadc117 | 425 | while (c == ' ' || c == '\n' || c == '\t'); |
342b8b6e AD |
426 | obstack_1grow (&token_obstack, '\0'); |
427 | token_buffer = obstack_finish (&token_obstack); | |
40675e7c DM |
428 | |
429 | if (c == '{') | |
a44c2277 | 430 | { |
511e79b3 | 431 | return tok_left_curly; |
a44c2277 | 432 | } |
40675e7c DM |
433 | else |
434 | { | |
abadc117 | 435 | ungetc (c, finput); |
511e79b3 | 436 | return tok_illegal; |
40675e7c DM |
437 | } |
438 | ||
439 | case '<': | |
f282676b | 440 | read_type_name (finput); |
511e79b3 | 441 | return tok_typename; |
a083fbbf | 442 | |
40675e7c | 443 | case '%': |
abadc117 | 444 | return parse_percent_token (); |
40675e7c DM |
445 | |
446 | default: | |
342b8b6e AD |
447 | obstack_1grow (&token_obstack, c); |
448 | obstack_1grow (&token_obstack, '\0'); | |
449 | token_buffer = obstack_finish (&token_obstack); | |
511e79b3 | 450 | return tok_illegal; |
40675e7c DM |
451 | } |
452 | } | |
453 | ||
82b6d266 PB |
454 | /* This function is a strcmp, which doesn't differentiate `-' and `_' |
455 | chars. */ | |
6deb4447 | 456 | |
82b6d266 PB |
457 | static int |
458 | option_strcmp (const char *left, const char *right) | |
abadc117 | 459 | { |
342b8b6e AD |
460 | const unsigned char *l, *r; |
461 | int c; | |
462 | ||
463 | assert (left); | |
464 | assert (right); | |
465 | l = (const unsigned char *)left; | |
466 | r = (const unsigned char *)right; | |
467 | while (((c = *l - *r++) == 0 && *l != '\0') | |
468 | || ((*l == '-' || *l == '_') && (*r == '_' || *r == '-'))) | |
469 | l++; | |
470 | return c; | |
82b6d266 | 471 | } |
a44c2277 RS |
472 | |
473 | /* Parse a token which starts with %. | |
474 | Assumes the % has already been read and discarded. */ | |
40675e7c | 475 | |
342b8b6e | 476 | token_t |
d2729d44 | 477 | parse_percent_token (void) |
40675e7c | 478 | { |
951366c1 | 479 | const struct option_table_struct *tx = NULL; |
09b503c8 AD |
480 | const char *arg = NULL; |
481 | /* Where the ARG was found in token_buffer. */ | |
482 | size_t arg_offset = 0; | |
40675e7c | 483 | |
342b8b6e | 484 | int c = getc (finput); |
29ae55f1 AD |
485 | obstack_1grow (&token_obstack, '%'); |
486 | obstack_1grow (&token_obstack, c); | |
40675e7c | 487 | |
55024580 | 488 | if (!isalpha (c)) |
40675e7c | 489 | { |
55024580 | 490 | obstack_1grow (&token_obstack, '\0'); |
29ae55f1 | 491 | token_buffer = obstack_finish (&token_obstack); |
40675e7c | 492 | |
55024580 AD |
493 | switch (c) |
494 | { | |
495 | case '%': | |
496 | return tok_two_percents; | |
40675e7c | 497 | |
55024580 AD |
498 | case '{': |
499 | return tok_percent_left_curly; | |
40675e7c | 500 | |
55024580 AD |
501 | /* The following guys are here for backward compatibility with |
502 | very ancient Yacc versions. The paper of Johnson mentions | |
503 | them (as ancient :). */ | |
504 | case '<': | |
505 | return tok_left; | |
40675e7c | 506 | |
55024580 AD |
507 | case '>': |
508 | return tok_right; | |
40675e7c | 509 | |
55024580 AD |
510 | case '2': |
511 | return tok_nonassoc; | |
40675e7c | 512 | |
55024580 AD |
513 | case '0': |
514 | return tok_token; | |
f17bcd1f | 515 | |
55024580 AD |
516 | case '=': |
517 | return tok_prec; | |
518 | ||
519 | default: | |
520 | return tok_illegal; | |
521 | } | |
29ae55f1 | 522 | } |
40675e7c | 523 | |
29ae55f1 | 524 | while (c = getc (finput), isalpha (c) || c == '_' || c == '-') |
40675e7c | 525 | { |
6bc35ae5 MA |
526 | if (c == '_') |
527 | c = '-'; | |
f17bcd1f | 528 | obstack_1grow (&token_obstack, c); |
40675e7c DM |
529 | } |
530 | ||
09b503c8 AD |
531 | /* %DIRECTIVE="ARG". Separate into |
532 | TOKEN_BUFFER = `%DIRECTIVE\0ARG\0'. | |
533 | This is a bit hackish, but once we move to a Bison parser, | |
534 | things will be cleaned up. */ | |
951366c1 AD |
535 | if (c == '=') |
536 | { | |
09b503c8 AD |
537 | /* End of the directive. We skip the `='. */ |
538 | obstack_1grow (&token_obstack, '\0'); | |
539 | /* Fetch the ARG if present. */ | |
951366c1 | 540 | c = getc (finput); |
09b503c8 | 541 | if (c == '"') |
951366c1 | 542 | { |
09b503c8 AD |
543 | int code; |
544 | arg_offset = obstack_object_size (&token_obstack); | |
545 | /* Read up to and including `"'. Do not append the closing | |
546 | `"' in the output: it's not part of the ARG. */ | |
2648a72d | 547 | while ((code = literalchar ()) != '"') |
09b503c8 | 548 | obstack_1grow (&token_obstack, code); |
951366c1 | 549 | } |
09b503c8 | 550 | /* else: should be an error. */ |
951366c1 AD |
551 | } |
552 | else | |
553 | ungetc (c, finput); | |
554 | ||
f17bcd1f AD |
555 | obstack_1grow (&token_obstack, '\0'); |
556 | token_buffer = obstack_finish (&token_obstack); | |
09b503c8 AD |
557 | if (arg_offset) |
558 | arg = token_buffer + arg_offset; | |
40675e7c | 559 | |
a44c2277 | 560 | /* table lookup % directive */ |
82b6d266 PB |
561 | for (tx = option_table; tx->name; tx++) |
562 | if ((tx->access == opt_percent || tx->access == opt_both) | |
563 | && option_strcmp (token_buffer + 1, tx->name) == 0) | |
a44c2277 | 564 | break; |
6deb4447 | 565 | |
65be0866 AD |
566 | if (arg && tx->ret_val != tok_stropt) |
567 | fatal (_("`%s' supports no argument: %s"), token_buffer, quote (arg)); | |
951366c1 | 568 | |
62ab6972 | 569 | |
82b6d266 | 570 | switch (tx->ret_val) |
a44c2277 | 571 | { |
951366c1 AD |
572 | case tok_stropt: |
573 | assert (tx->set_flag); | |
574 | if (arg) | |
575 | { | |
576 | /* Keep only the first assignment: command line options have | |
577 | already been processed, and we want them to have | |
578 | precedence. Side effect: if this %-option is used | |
579 | several times, only the first is honored. Bah. */ | |
580 | if (!*((char **) (tx->set_flag))) | |
09b503c8 | 581 | *((char **) (tx->set_flag)) = xstrdup (arg); |
951366c1 AD |
582 | } |
583 | else | |
584 | fatal (_("`%s' requires an argument"), token_buffer); | |
585 | return tok_noop; | |
586 | break; | |
587 | ||
588 | case tok_intopt: | |
589 | assert (tx->set_flag); | |
590 | *((int *) (tx->set_flag)) = 1; | |
511e79b3 | 591 | return tok_noop; |
62ab6972 AD |
592 | break; |
593 | ||
594 | case tok_obsolete: | |
595 | fatal (_("`%s' is no longer supported"), token_buffer); | |
951366c1 | 596 | return tok_noop; |
62ab6972 | 597 | break; |
342b8b6e AD |
598 | |
599 | default: | |
951366c1 | 600 | return tx->ret_val; |
342b8b6e | 601 | break; |
a44c2277 | 602 | } |
951366c1 | 603 | abort (); |
40675e7c | 604 | } |