]>
Commit | Line | Data |
---|---|---|
2fa0b342 | 1 | %{ |
0d3e45ea | 2 | |
fb55f9b8 | 3 | /* Copyright (C) 1991, 1992, 1993, 1994 Free Software Foundation, Inc. |
2fa0b342 DHW |
4 | |
5 | This file is part of GLD, the Gnu Linker. | |
6 | ||
7 | GLD is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
2e2bf962 | 9 | the Free Software Foundation; either version 2, or (at your option) |
2fa0b342 DHW |
10 | any later version. |
11 | ||
12 | GLD is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with GLD; see the file COPYING. If not, write to | |
19 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
20 | ||
21 | /* | |
9d1fe8a4 SC |
22 | This was written by steve chamberlain |
23 | [email protected] | |
2fa0b342 DHW |
24 | */ |
25 | ||
26 | ||
9d1fe8a4 | 27 | #include <ansidecl.h> |
fcf276c4 | 28 | #include <stdio.h> |
b5b2c886 SS |
29 | /* start-sanitize-mpw */ |
30 | #ifdef MPW | |
31 | /* Prevent enum redefinition problems. */ | |
32 | #define TRUE_FALSE_ALREADY_DEFINED | |
33 | #endif /* MPW */ | |
34 | /* end-sanitize-mpw */ | |
a02945df | 35 | #include "bfd.h" |
c477527c | 36 | #include "sysdep.h" |
fcf276c4 | 37 | #include "ld.h" |
9d1fe8a4 | 38 | #include "ldgram.h" |
fcf276c4 ILT |
39 | #include "ldmisc.h" |
40 | #include "ldexp.h" | |
41 | #include "ldlang.h" | |
42 | #include "ldfile.h" | |
9f629407 | 43 | #include "ldlex.h" |
fb55f9b8 | 44 | #include "ldmain.h" |
2fa0b342 | 45 | |
d4e5e3c3 DM |
46 | /* The type of top-level parser input. |
47 | yylex and yyparse (indirectly) both check this. */ | |
48 | input_type parser_input; | |
2fa0b342 | 49 | |
d4e5e3c3 | 50 | /* Radix to use for bfd_scan_vma -- 0 (default to base 10) or 16. */ |
9d1fe8a4 | 51 | int hex_mode; |
2e2bf962 | 52 | |
d4e5e3c3 DM |
53 | /* Line number in the current input file. |
54 | (FIXME Actually, it doesn't appear to get reset for each file?) */ | |
dc4726c2 | 55 | unsigned int lineno = 1; |
d4e5e3c3 DM |
56 | |
57 | /* Support for flex reading from more than one input file (stream). | |
58 | `include_stack' is flex's input state for each open file; | |
59 | `file_name_stack' is the file names. | |
60 | ||
61 | If `include_stack_ptr' is 0, we haven't started reading anything yet. | |
62 | Otherwise, stack elements 0 through `include_stack_ptr - 1' are valid. */ | |
1d45ccb3 | 63 | |
9d1fe8a4 SC |
64 | #undef YY_INPUT |
65 | #define YY_INPUT(buf,result,max_size) yy_input(buf, &result, max_size) | |
d4e5e3c3 | 66 | |
9d1fe8a4 | 67 | #define MAX_INCLUDE_DEPTH 10 |
d4e5e3c3 DM |
68 | static YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH]; |
69 | static char *file_name_stack[MAX_INCLUDE_DEPTH]; | |
70 | static unsigned int include_stack_ptr = 0; | |
2fa0b342 | 71 | |
fcf276c4 | 72 | static YY_BUFFER_STATE yy_create_string_buffer PARAMS ((const char *string, |
d4e5e3c3 | 73 | size_t size)); |
fcf276c4 | 74 | static void yy_input PARAMS ((char *, int *result, int max_size)); |
d4e5e3c3 | 75 | |
fcf276c4 | 76 | static void comment PARAMS ((void)); |
fb55f9b8 | 77 | static void lex_warn_invalid PARAMS ((char *where, char *what)); |
2fa0b342 | 78 | |
3d2b83ea | 79 | /* STATES |
fb55f9b8 DM |
80 | EXPRESSION definitely in an expression |
81 | SCRIPT definitely in a script | |
82 | BOTH either EXPRESSION or SCRIPT | |
83 | DEFSYMEXP in an argument to -defsym | |
3d2b83ea | 84 | MRI in an MRI script |
9d1fe8a4 | 85 | */ |
2fa0b342 | 86 | #define RTOKEN(x) { yylval.token = x; return x; } |
d4e5e3c3 DM |
87 | |
88 | /* Some versions of flex want this. */ | |
89 | #ifndef yywrap | |
90 | int yywrap () { return 1; } | |
91 | #endif | |
9d1fe8a4 | 92 | %} |
2fa0b342 | 93 | |
9d1fe8a4 SC |
94 | %a 4000 |
95 | %o 5000 | |
ee0c4cf7 | 96 | |
6bf2e3a7 SC |
97 | CMDFILENAMECHAR [_a-zA-Z0-9\/\.\\_\+\$\:\[\]\\\,\=\&\!\<\>\-\~] |
98 | CMDFILENAMECHAR1 [_a-zA-Z0-9\/\.\\_\+\$\:\[\]\\\,\=\&\!\<\>\~] | |
99 | FILENAMECHAR1 [_a-zA-Z\/\.\\\$\_\~] | |
0d3e45ea | 100 | SYMBOLCHARN [_a-zA-Z\/\.\\0-9] |
6bf2e3a7 | 101 | FILENAMECHAR [_a-zA-Z0-9\/\.\-\_\+\=\$\:\[\]\\\,\~] |
9d1fe8a4 SC |
102 | FILENAME {FILENAMECHAR}+ |
103 | WHITE [ \t\n]+ | |
2fa0b342 | 104 | |
85e38cfa SC |
105 | NOCFILENAMECHAR [_a-zA-Z0-9\/\.\-\_\+\$\:\[\]\\\~] |
106 | ||
107 | ||
91e25b4f PB |
108 | %s SCRIPT |
109 | %s EXPRESSION | |
91e25b4f PB |
110 | %s BOTH |
111 | %s DEFSYMEXP | |
112 | %s MRI | |
9d1fe8a4 | 113 | %% |
91e25b4f | 114 | |
d4e5e3c3 DM |
115 | if (parser_input != input_selected) |
116 | { | |
117 | /* The first token of the input determines the initial parser state. */ | |
118 | input_type t = parser_input; | |
119 | parser_input = input_selected; | |
120 | return t; | |
121 | } | |
6bf2e3a7 | 122 | |
d4e5e3c3 | 123 | <BOTH,SCRIPT,EXPRESSION>"/*" { comment(); } |
6bf2e3a7 SC |
124 | |
125 | ||
0d3e45ea SC |
126 | <DEFSYMEXP>"-" { RTOKEN('-');} |
127 | <DEFSYMEXP>"+" { RTOKEN('+');} | |
128 | <DEFSYMEXP>{FILENAMECHAR1}{SYMBOLCHARN}* { yylval.name = buystring(yytext); return NAME; } | |
0d3e45ea | 129 | <DEFSYMEXP>"=" { RTOKEN('='); } |
2a28d8b0 | 130 | |
3d2b83ea | 131 | <MRI,EXPRESSION>"$"([0-9A-Fa-f])+ { |
f651733a | 132 | yylval.integer = bfd_scan_vma (yytext+1, 0,16); |
3d2b83ea SC |
133 | return INT; |
134 | } | |
135 | ||
91e25b4f | 136 | <MRI,EXPRESSION>([0-9A-Fa-f])+(H|X|B|O|D) { |
9f629407 | 137 | int ibase ; |
3d2b83ea SC |
138 | switch (yytext[yyleng-1]) { |
139 | case 'X': | |
140 | case 'H': | |
9f629407 | 141 | ibase = 16; |
3d2b83ea SC |
142 | break; |
143 | case 'O': | |
9f629407 | 144 | ibase = 8; |
3d2b83ea SC |
145 | break; |
146 | case 'B': | |
9f629407 | 147 | ibase = 2; |
3d2b83ea SC |
148 | break; |
149 | default: | |
9f629407 | 150 | ibase = 10; |
3d2b83ea | 151 | } |
f651733a | 152 | yylval.integer = bfd_scan_vma (yytext+1, 0, |
9f629407 | 153 | ibase); |
3d2b83ea SC |
154 | return INT; |
155 | } | |
9fce28ed | 156 | <SCRIPT,DEFSYMEXP,MRI,BOTH,EXPRESSION>"$"?"0x"?([0-9A-Fa-f])+(M|K|m|k)? { |
f651733a ILT |
157 | yylval.integer = bfd_scan_vma (yytext, 0, |
158 | hex_mode); | |
9d1fe8a4 SC |
159 | if (yytext[yyleng-1]=='M' |
160 | || yytext[yyleng-1] == 'm') { | |
161 | yylval.integer *= 1024*1024; | |
162 | } | |
163 | if (yytext[yyleng-1]=='K' | |
164 | || yytext[yyleng-1]=='k') { | |
165 | yylval.integer *= 1024; | |
166 | } | |
167 | return INT; | |
168 | } | |
169 | <BOTH,SCRIPT,EXPRESSION>"]" { RTOKEN(']');} | |
170 | <BOTH,SCRIPT,EXPRESSION>"[" { RTOKEN('[');} | |
171 | <BOTH,SCRIPT,EXPRESSION>"<<=" { RTOKEN(LSHIFTEQ);} | |
172 | <BOTH,SCRIPT,EXPRESSION>">>=" { RTOKEN(RSHIFTEQ);} | |
173 | <BOTH,SCRIPT,EXPRESSION>"||" { RTOKEN(OROR);} | |
174 | <BOTH,SCRIPT,EXPRESSION>"==" { RTOKEN(EQ);} | |
175 | <BOTH,SCRIPT,EXPRESSION>"!=" { RTOKEN(NE);} | |
176 | <BOTH,SCRIPT,EXPRESSION>">=" { RTOKEN(GE);} | |
177 | <BOTH,SCRIPT,EXPRESSION>"<=" { RTOKEN(LE);} | |
178 | <BOTH,SCRIPT,EXPRESSION>"<<" { RTOKEN(LSHIFT);} | |
179 | <BOTH,SCRIPT,EXPRESSION>">>" { RTOKEN(RSHIFT);} | |
180 | <BOTH,SCRIPT,EXPRESSION>"+=" { RTOKEN(PLUSEQ);} | |
181 | <BOTH,SCRIPT,EXPRESSION>"-=" { RTOKEN(MINUSEQ);} | |
182 | <BOTH,SCRIPT,EXPRESSION>"*=" { RTOKEN(MULTEQ);} | |
183 | <BOTH,SCRIPT,EXPRESSION>"/=" { RTOKEN(DIVEQ);} | |
184 | <BOTH,SCRIPT,EXPRESSION>"&=" { RTOKEN(ANDEQ);} | |
185 | <BOTH,SCRIPT,EXPRESSION>"|=" { RTOKEN(OREQ);} | |
186 | <BOTH,SCRIPT,EXPRESSION>"&&" { RTOKEN(ANDAND);} | |
187 | <BOTH,SCRIPT,EXPRESSION>">" { RTOKEN('>');} | |
3d2b83ea | 188 | <MRI,BOTH,SCRIPT,EXPRESSION>"," { RTOKEN(',');} |
9d1fe8a4 SC |
189 | <BOTH,SCRIPT,EXPRESSION>"&" { RTOKEN('&');} |
190 | <BOTH,SCRIPT,EXPRESSION>"|" { RTOKEN('|');} | |
191 | <BOTH,SCRIPT,EXPRESSION>"~" { RTOKEN('~');} | |
192 | <BOTH,SCRIPT,EXPRESSION>"!" { RTOKEN('!');} | |
193 | <BOTH,SCRIPT,EXPRESSION>"?" { RTOKEN('?');} | |
194 | <BOTH,SCRIPT,EXPRESSION>"*" { RTOKEN('*');} | |
195 | <BOTH,SCRIPT,EXPRESSION>"+" { RTOKEN('+');} | |
196 | <BOTH,SCRIPT,EXPRESSION>"-" { RTOKEN('-');} | |
197 | <BOTH,SCRIPT,EXPRESSION>"/" { RTOKEN('/');} | |
198 | <BOTH,SCRIPT,EXPRESSION>"%" { RTOKEN('%');} | |
199 | <BOTH,SCRIPT,EXPRESSION>"<" { RTOKEN('<');} | |
3d2b83ea | 200 | <MRI,BOTH,SCRIPT,EXPRESSION>"=" { RTOKEN('=');} |
9d1fe8a4 SC |
201 | <BOTH,SCRIPT,EXPRESSION>"}" { RTOKEN('}') ; } |
202 | <BOTH,SCRIPT,EXPRESSION>"{" { RTOKEN('{'); } | |
203 | <BOTH,SCRIPT,EXPRESSION>")" { RTOKEN(')');} | |
204 | <BOTH,SCRIPT,EXPRESSION>"(" { RTOKEN('(');} | |
9d1fe8a4 SC |
205 | <BOTH,SCRIPT,EXPRESSION>":" { RTOKEN(':'); } |
206 | <BOTH,SCRIPT,EXPRESSION>";" { RTOKEN(';');} | |
9d1fe8a4 SC |
207 | <BOTH,SCRIPT>"MEMORY" { RTOKEN(MEMORY);} |
208 | <BOTH,SCRIPT>"ORIGIN" { RTOKEN(ORIGIN);} | |
209 | <BOTH,SCRIPT>"BLOCK" { RTOKEN(BLOCK);} | |
210 | <BOTH,SCRIPT>"LENGTH" { RTOKEN(LENGTH);} | |
211 | <EXPRESSION,BOTH,SCRIPT>"ALIGN" { RTOKEN(ALIGN_K);} | |
212 | <EXPRESSION,BOTH,SCRIPT>"ADDR" { RTOKEN(ADDR);} | |
213 | <BOTH,SCRIPT>"ENTRY" { RTOKEN(ENTRY);} | |
214 | <EXPRESSION,BOTH,SCRIPT>"NEXT" { RTOKEN(NEXT);} | |
215 | <EXPRESSION,BOTH,SCRIPT>"sizeof_headers" { RTOKEN(SIZEOF_HEADERS);} | |
216 | <EXPRESSION,BOTH,SCRIPT>"SIZEOF_HEADERS" { RTOKEN(SIZEOF_HEADERS);} | |
217 | <BOTH,SCRIPT>"MAP" { RTOKEN(MAP);} | |
218 | <EXPRESSION,BOTH,SCRIPT>"SIZEOF" { RTOKEN(SIZEOF);} | |
219 | <BOTH,SCRIPT>"TARGET" { RTOKEN(TARGET_K);} | |
220 | <BOTH,SCRIPT>"SEARCH_DIR" { RTOKEN(SEARCH_DIR);} | |
221 | <BOTH,SCRIPT>"OUTPUT" { RTOKEN(OUTPUT);} | |
222 | <BOTH,SCRIPT>"INPUT" { RTOKEN(INPUT);} | |
dadd414a | 223 | <EXPRESSION,BOTH,SCRIPT>"DEFINED" { RTOKEN(DEFINED);} |
9d1fe8a4 SC |
224 | <BOTH,SCRIPT>"CREATE_OBJECT_SYMBOLS" { RTOKEN(CREATE_OBJECT_SYMBOLS);} |
225 | <BOTH,SCRIPT>"CONSTRUCTORS" { RTOKEN( CONSTRUCTORS);} | |
226 | <BOTH,SCRIPT>"FORCE_COMMON_ALLOCATION" { RTOKEN(FORCE_COMMON_ALLOCATION);} | |
227 | <BOTH,SCRIPT>"SECTIONS" { RTOKEN(SECTIONS);} | |
228 | <BOTH,SCRIPT>"FILL" { RTOKEN(FILL);} | |
229 | <BOTH,SCRIPT>"STARTUP" { RTOKEN(STARTUP);} | |
230 | <BOTH,SCRIPT>"OUTPUT_FORMAT" { RTOKEN(OUTPUT_FORMAT);} | |
231 | <BOTH,SCRIPT>"OUTPUT_ARCH" { RTOKEN( OUTPUT_ARCH);} | |
232 | <BOTH,SCRIPT>"HLL" { RTOKEN(HLL);} | |
233 | <BOTH,SCRIPT>"SYSLIB" { RTOKEN(SYSLIB);} | |
234 | <BOTH,SCRIPT>"FLOAT" { RTOKEN(FLOAT);} | |
c477527c | 235 | <BOTH,SCRIPT>"QUAD" { RTOKEN( QUAD);} |
9d1fe8a4 SC |
236 | <BOTH,SCRIPT>"LONG" { RTOKEN( LONG);} |
237 | <BOTH,SCRIPT>"SHORT" { RTOKEN( SHORT);} | |
238 | <BOTH,SCRIPT>"BYTE" { RTOKEN( BYTE);} | |
239 | <BOTH,SCRIPT>"NOFLOAT" { RTOKEN(NOFLOAT);} | |
dadd414a | 240 | <EXPRESSION,BOTH,SCRIPT>"NOLOAD" { RTOKEN(NOLOAD);} |
9d1fe8a4 SC |
241 | <BOTH,SCRIPT>"DSECT" { RTOKEN(DSECT);} |
242 | <BOTH,SCRIPT>"COPY" { RTOKEN(COPY);} | |
243 | <BOTH,SCRIPT>"INFO" { RTOKEN(INFO);} | |
244 | <BOTH,SCRIPT>"OVERLAY" { RTOKEN(OVERLAY);} | |
245 | <BOTH,SCRIPT>"o" { RTOKEN(ORIGIN);} | |
246 | <BOTH,SCRIPT>"org" { RTOKEN(ORIGIN);} | |
247 | <BOTH,SCRIPT>"l" { RTOKEN( LENGTH);} | |
248 | <BOTH,SCRIPT>"len" { RTOKEN( LENGTH);} | |
dadd414a | 249 | <BOTH,SCRIPT>"INCLUDE" { RTOKEN(INCLUDE);} |
9fce28ed | 250 | <EXPRESSION,BOTH,SCRIPT>"AT" { RTOKEN(AT);} |
2e38b71d | 251 | <MRI>"\n" { ++ lineno; RTOKEN(NEWLINE); } |
91e25b4f | 252 | <MRI>"*".* { /* Mri comment line */ } |
2e38b71d | 253 | <MRI>"END" { RTOKEN(ENDWORD); } |
85e38cfa SC |
254 | <MRI>"ALIGNMOD" { RTOKEN(ALIGNMOD);} |
255 | <MRI>"ALIGN" { RTOKEN(ALIGN_K);} | |
256 | ||
3d2b83ea | 257 | <MRI>"CHIP" { RTOKEN(CHIP); } |
91e25b4f PB |
258 | <MRI>"BASE" { RTOKEN(BASE); } |
259 | <MRI>"ALIAS" { RTOKEN(ALIAS); } | |
85e38cfa | 260 | <MRI>"TRUNCATE" { RTOKEN(TRUNCATE); } |
3d2b83ea | 261 | <MRI>"LOAD" { RTOKEN(LOAD); } |
91e25b4f | 262 | <MRI>"PUBLIC" { RTOKEN(PUBLIC); } |
2e38b71d SC |
263 | <MRI>"ORDER" { RTOKEN(ORDER); } |
264 | <MRI>"NAME" { RTOKEN(NAMEWORD); } | |
265 | <MRI>"FORMAT" { RTOKEN(FORMAT); } | |
266 | <MRI>"LIST".* { RTOKEN(LIST); /* LIST and ignore to end of line */ } | |
3d2b83ea | 267 | <MRI>"SECT" { RTOKEN(SECT); } |
6bf2e3a7 | 268 | <EXPRESSION,BOTH,SCRIPT,MRI>"ABSOLUTE" { RTOKEN(ABSOLUTE); } |
1bd1fa2d SC |
269 | <MRI>"end" { RTOKEN(ENDWORD); } |
270 | <MRI>"chip" { RTOKEN(CHIP); } | |
271 | <MRI>"load" { RTOKEN(LOAD); } | |
272 | <MRI>"order" { RTOKEN(ORDER); } | |
273 | <MRI>"name" { RTOKEN(NAMEWORD); } | |
274 | <MRI>"format" { RTOKEN(FORMAT); } | |
275 | <MRI>"list".* { RTOKEN(LIST); /* LIST and ignore to end of line */ } | |
276 | <MRI>"sect" { RTOKEN(SECT); } | |
6bf2e3a7 | 277 | <EXPRESSION,BOTH,SCRIPT,MRI>"absolute" { RTOKEN(ABSOLUTE); } |
3d2b83ea | 278 | |
85e38cfa SC |
279 | <MRI>{FILENAMECHAR1}{NOCFILENAMECHAR}* { |
280 | /* Filename without commas, needed to parse mri stuff */ | |
281 | yylval.name = buystring(yytext); | |
282 | return NAME; | |
283 | } | |
284 | ||
285 | ||
286 | <BOTH,EXPRESSION>{FILENAMECHAR1}{FILENAMECHAR}* { | |
9d1fe8a4 SC |
287 | yylval.name = buystring(yytext); |
288 | return NAME; | |
289 | } | |
d4e5e3c3 | 290 | <SCRIPT>{FILENAMECHAR}* { yylval.name = buystring(yytext); |
9d1fe8a4 SC |
291 | return NAME; |
292 | } | |
293 | ||
d4e5e3c3 | 294 | <EXPRESSION,BOTH,SCRIPT>"\""[^\"]*"\"" { |
9d1fe8a4 SC |
295 | /* No matter the state, quotes |
296 | give what's inside */ | |
297 | yylval.name = buystring(yytext+1); | |
298 | yylval.name[yyleng-2] = 0; | |
299 | return NAME; | |
300 | } | |
301 | <BOTH,SCRIPT,EXPRESSION>"\n" { lineno++;} | |
d4e5e3c3 | 302 | <MRI,BOTH,SCRIPT,EXPRESSION>[ \t] |
9d1fe8a4 | 303 | |
9d1fe8a4 | 304 | <<EOF>> { |
dadd414a | 305 | include_stack_ptr--; |
9d1fe8a4 | 306 | |
dadd414a SC |
307 | if (include_stack_ptr == 0) |
308 | { | |
309 | yyterminate(); | |
310 | } | |
311 | else | |
312 | { | |
313 | yy_switch_to_buffer(include_stack[include_stack_ptr]); | |
314 | ||
315 | } | |
d4e5e3c3 DM |
316 | BEGIN(SCRIPT); |
317 | ldfile_input_filename = file_name_stack[include_stack_ptr-1]; | |
dadd414a SC |
318 | |
319 | return END; | |
320 | } | |
fb55f9b8 | 321 | |
fb55f9b8 DM |
322 | <SCRIPT,MRI>. lex_warn_invalid(" in script", yytext); |
323 | <EXPRESSION,DEFSYMEXP,BOTH>. lex_warn_invalid(" in expression", yytext); | |
9d1fe8a4 | 324 | |
9d1fe8a4 | 325 | %% |
d4e5e3c3 DM |
326 | \f |
327 | ||
328 | /* Switch flex to reading script file NAME, open on FILE, | |
329 | saving the current input info on the include stack. */ | |
2fa0b342 DHW |
330 | |
331 | void | |
8ddef552 DM |
332 | lex_push_file (file, name) |
333 | FILE *file; | |
334 | char *name; | |
2fa0b342 | 335 | { |
9d1fe8a4 | 336 | if (include_stack_ptr >= MAX_INCLUDE_DEPTH) |
d4e5e3c3 DM |
337 | { |
338 | einfo("%F:includes nested too deeply\n"); | |
339 | } | |
dadd414a SC |
340 | file_name_stack[include_stack_ptr] = name; |
341 | include_stack[include_stack_ptr] = YY_CURRENT_BUFFER; | |
342 | ||
343 | include_stack_ptr++; | |
9d1fe8a4 SC |
344 | yyin = file; |
345 | yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE)); | |
d4e5e3c3 | 346 | BEGIN (SCRIPT); |
2fa0b342 DHW |
347 | } |
348 | ||
d4e5e3c3 DM |
349 | /* Return a newly created flex input buffer containing STRING, |
350 | which is SIZE bytes long. */ | |
351 | ||
fcf276c4 | 352 | static YY_BUFFER_STATE |
d4e5e3c3 | 353 | yy_create_string_buffer (string, size) |
8ddef552 | 354 | CONST char *string; |
d4e5e3c3 | 355 | size_t size; |
2fa0b342 | 356 | { |
9d1fe8a4 | 357 | YY_BUFFER_STATE b; |
2fa0b342 | 358 | |
d4e5e3c3 DM |
359 | /* Calls to m-alloc get turned by sed into xm-alloc. */ |
360 | b = (YY_BUFFER_STATE) malloc (sizeof (struct yy_buffer_state)); | |
9d1fe8a4 | 361 | b->yy_input_file = 0; |
9d1fe8a4 | 362 | b->yy_buf_size = size; |
2fa0b342 | 363 | |
9d1fe8a4 | 364 | /* yy_ch_buf has to be 2 characters longer than the size given because |
d4e5e3c3 DM |
365 | we need to put in 2 end-of-buffer characters. */ |
366 | b->yy_ch_buf = (YY_CHAR *) malloc ((unsigned) (b->yy_buf_size + 3)); | |
2fa0b342 | 367 | |
9d1fe8a4 | 368 | b->yy_ch_buf[0] = '\n'; |
d4e5e3c3 | 369 | strcpy (b->yy_ch_buf+1, string); |
9d1fe8a4 SC |
370 | b->yy_ch_buf[size+1] = YY_END_OF_BUFFER_CHAR; |
371 | b->yy_ch_buf[size+2] = YY_END_OF_BUFFER_CHAR; | |
d4e5e3c3 | 372 | b->yy_n_chars = size+1; |
9d1fe8a4 | 373 | b->yy_buf_pos = &b->yy_ch_buf[1]; |
9d1fe8a4 | 374 | b->yy_eof_status = EOF_NOT_SEEN; |
2fa0b342 | 375 | |
d4e5e3c3 | 376 | return b; |
2fa0b342 | 377 | } |
2fa0b342 | 378 | |
d4e5e3c3 DM |
379 | /* Switch flex to reading from STRING, saving the current input info |
380 | on the include stack. */ | |
1418c83b | 381 | |
9d1fe8a4 | 382 | void |
8ddef552 | 383 | lex_redirect (string) |
d4e5e3c3 | 384 | CONST char *string; |
9d1fe8a4 SC |
385 | { |
386 | YY_BUFFER_STATE tmp; | |
1d45ccb3 | 387 | |
d4e5e3c3 | 388 | yy_init = 0; |
9d1fe8a4 | 389 | if (include_stack_ptr >= MAX_INCLUDE_DEPTH) |
d4e5e3c3 DM |
390 | { |
391 | einfo("%F: macros nested too deeply\n"); | |
392 | } | |
dadd414a SC |
393 | file_name_stack[include_stack_ptr] = "redirect"; |
394 | include_stack[include_stack_ptr] = YY_CURRENT_BUFFER; | |
395 | include_stack_ptr++; | |
d4e5e3c3 DM |
396 | tmp = yy_create_string_buffer (string, strlen (string)); |
397 | yy_switch_to_buffer (tmp); | |
398 | BEGIN (SCRIPT); | |
9d1fe8a4 | 399 | } |
d4e5e3c3 DM |
400 | \f |
401 | /* Functions to switch to a different flex start condition, | |
402 | saving the current start condition on `state_stack'. */ | |
1d45ccb3 | 403 | |
d4e5e3c3 DM |
404 | static int state_stack[MAX_INCLUDE_DEPTH * 2]; |
405 | static int *state_stack_p = state_stack; | |
1d45ccb3 | 406 | |
9d1fe8a4 | 407 | void |
8ddef552 | 408 | ldlex_script () |
9d1fe8a4 | 409 | { |
dadd414a | 410 | *(state_stack_p)++ = yy_start; |
d4e5e3c3 | 411 | BEGIN (SCRIPT); |
9d1fe8a4 | 412 | } |
1418c83b | 413 | |
3d2b83ea | 414 | void |
8ddef552 | 415 | ldlex_mri_script () |
3d2b83ea | 416 | { |
dadd414a | 417 | *(state_stack_p)++ = yy_start; |
d4e5e3c3 | 418 | BEGIN (MRI); |
0d3e45ea SC |
419 | } |
420 | ||
421 | void | |
8ddef552 | 422 | ldlex_defsym () |
0d3e45ea | 423 | { |
dadd414a | 424 | *(state_stack_p)++ = yy_start; |
d4e5e3c3 | 425 | BEGIN (DEFSYMEXP); |
3d2b83ea SC |
426 | } |
427 | ||
9d1fe8a4 | 428 | void |
8ddef552 | 429 | ldlex_expression () |
9d1fe8a4 | 430 | { |
dadd414a | 431 | *(state_stack_p)++ = yy_start; |
d4e5e3c3 | 432 | BEGIN (EXPRESSION); |
9d1fe8a4 | 433 | } |
d4e5e3c3 | 434 | |
9d1fe8a4 | 435 | void |
8ddef552 | 436 | ldlex_both () |
9d1fe8a4 | 437 | { |
dadd414a | 438 | *(state_stack_p)++ = yy_start; |
d4e5e3c3 | 439 | BEGIN (BOTH); |
2fa0b342 DHW |
440 | } |
441 | ||
9d1fe8a4 | 442 | void |
8ddef552 | 443 | ldlex_popstate () |
9d1fe8a4 | 444 | { |
dadd414a | 445 | yy_start = *(--state_stack_p); |
9d1fe8a4 | 446 | } |
d4e5e3c3 DM |
447 | \f |
448 | ||
449 | /* Place up to MAX_SIZE characters in BUF and return in *RESULT | |
450 | either the number of characters read, or 0 to indicate EOF. */ | |
2fa0b342 | 451 | |
fcf276c4 | 452 | static void |
d4e5e3c3 DM |
453 | yy_input (buf, result, max_size) |
454 | char *buf; | |
455 | int *result; | |
456 | int max_size; | |
9d1fe8a4 SC |
457 | { |
458 | *result = 0; | |
459 | if (yy_current_buffer->yy_input_file) | |
d4e5e3c3 DM |
460 | { |
461 | if (yyin) | |
462 | { | |
463 | *result = read (fileno (yyin), (char *) buf, max_size); | |
464 | if (*result < 0) | |
465 | einfo ("%F%P: read in flex scanner failed"); | |
466 | } | |
467 | } | |
9d1fe8a4 | 468 | } |
6bf2e3a7 | 469 | |
d4e5e3c3 DM |
470 | /* Eat the rest of a C-style comment. */ |
471 | ||
fcf276c4 ILT |
472 | static void |
473 | comment () | |
85e38cfa SC |
474 | { |
475 | int c; | |
d4e5e3c3 | 476 | |
85e38cfa SC |
477 | while (1) |
478 | { | |
479 | c = input(); | |
d4e5e3c3 | 480 | while (c != '*' && c != EOF) |
85e38cfa | 481 | { |
d4e5e3c3 DM |
482 | if (c == '\n') |
483 | lineno++; | |
85e38cfa SC |
484 | c = input(); |
485 | } | |
486 | ||
85e38cfa SC |
487 | if (c == '*') |
488 | { | |
489 | c = input(); | |
d4e5e3c3 | 490 | while (c == '*') |
85e38cfa | 491 | c = input(); |
d4e5e3c3 | 492 | if (c == '/') |
85e38cfa SC |
493 | break; /* found the end */ |
494 | } | |
495 | ||
d4e5e3c3 DM |
496 | if (c == '\n') |
497 | lineno++; | |
498 | ||
499 | if (c == EOF) | |
85e38cfa | 500 | { |
d4e5e3c3 | 501 | einfo( "%F%P: EOF in comment\n"); |
85e38cfa SC |
502 | break; |
503 | } | |
504 | } | |
505 | } | |
fb55f9b8 | 506 | |
d4e5e3c3 DM |
507 | /* Warn the user about a garbage character WHAT in the input |
508 | in context WHERE. */ | |
509 | ||
fb55f9b8 DM |
510 | static void |
511 | lex_warn_invalid (where, what) | |
512 | char *where, *what; | |
513 | { | |
514 | fprintf(stderr, | |
515 | "%s: ignoring invalid character `%s'%s\n", | |
516 | program_name, what, where); | |
517 | } |