]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/binutils/ld/ldlex.l
unfinished sblive driver, playback/mixer only for now - not enabled in
[FreeBSD/FreeBSD.git] / contrib / binutils / ld / ldlex.l
1 %{
2
3 /* Copyright (C) 1991, 92, 93, 94, 95, 96, 97, 1998
4    Free Software Foundation, Inc.
5
6 This file is part of GLD, the Gnu Linker.
7
8 GLD is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
12
13 GLD is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GLD; see the file COPYING.  If not, write to the Free
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
21 02111-1307, USA.  */
22
23 /*
24 This was written by steve chamberlain
25                     sac@cygnus.com
26 */
27
28
29 #include <ansidecl.h>
30 #include <stdio.h>
31 #include <ctype.h>
32
33 #ifdef MPW
34 /* Prevent enum redefinition problems. */
35 #define TRUE_FALSE_ALREADY_DEFINED
36 #endif /* MPW */
37
38 #include "bfd.h"
39 #include "sysdep.h"
40 #include "ld.h"
41 #include "ldgram.h"
42 #include "ldmisc.h"
43 #include "ldexp.h"
44 #include "ldlang.h"
45 #include "ldfile.h"
46 #include "ldlex.h"
47 #include "ldmain.h"
48
49 /* The type of top-level parser input.
50    yylex and yyparse (indirectly) both check this.  */
51 input_type parser_input;
52
53 /* Line number in the current input file.
54    (FIXME Actually, it doesn't appear to get reset for each file?)  */
55 unsigned int lineno = 1;
56
57 /* The string we are currently lexing, or NULL if we are reading a
58    file.  */
59 const char *lex_string = NULL;
60
61 /* Support for flex reading from more than one input file (stream).
62    `include_stack' is flex's input state for each open file;
63    `file_name_stack' is the file names.  `lineno_stack' is the current
64    line numbers.
65
66    If `include_stack_ptr' is 0, we haven't started reading anything yet.
67    Otherwise, stack elements 0 through `include_stack_ptr - 1' are valid.  */
68
69 #undef YY_INPUT
70 #define YY_INPUT(buf,result,max_size) yy_input(buf, &result, max_size)
71
72 #define MAX_INCLUDE_DEPTH 10
73 static YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
74 static const char *file_name_stack[MAX_INCLUDE_DEPTH];
75 static unsigned int lineno_stack[MAX_INCLUDE_DEPTH];
76 static unsigned int include_stack_ptr = 0;
77
78 static YY_BUFFER_STATE yy_create_string_buffer PARAMS ((const char *string,
79                                                         size_t size));
80 static void yy_input PARAMS ((char *, int *result, int max_size));
81
82 static void comment PARAMS ((void));
83 static void lex_warn_invalid PARAMS ((char *where, char *what));
84
85 /* STATES 
86         EXPRESSION      definitely in an expression
87         SCRIPT          definitely in a script
88         BOTH            either EXPRESSION or SCRIPT
89         DEFSYMEXP       in an argument to -defsym
90         MRI             in an MRI script
91         VERS_START      starting a Sun style mapfile
92         VERS_SCRIPT     a Sun style mapfile
93         VERS_NODE       a node within a Sun style mapfile
94 */
95 #define RTOKEN(x)  {  yylval.token = x; return x; }
96
97 /* Some versions of flex want this.  */
98 #ifndef yywrap
99 int yywrap () { return 1; }
100 #endif
101 %}
102
103 %a 4000
104 %o 5000
105
106 CMDFILENAMECHAR   [_a-zA-Z0-9\/\.\\_\+\$\:\[\]\\\,\=\&\!\<\>\-\~]
107 CMDFILENAMECHAR1  [_a-zA-Z0-9\/\.\\_\+\$\:\[\]\\\,\=\&\!\<\>\~]
108 FILENAMECHAR1   [_a-zA-Z\/\.\\\$\_\~]
109 SYMBOLCHARN     [_a-zA-Z\/\.\\\$\_\~0-9]
110 FILENAMECHAR    [_a-zA-Z0-9\/\.\-\_\+\=\$\:\[\]\\\,\~]
111 WILDCHAR        [_a-zA-Z0-9\/\.\-\_\+\=\$\:\[\]\\\,\~\?\*]
112 WHITE           [ \t\n\r]+ 
113
114 NOCFILENAMECHAR [_a-zA-Z0-9\/\.\-\_\+\$\:\[\]\\\~]
115
116 V_TAG [.$_a-zA-Z][._a-zA-Z0-9]*
117 V_IDENTIFIER [*?.$_a-zA-Z][*?_a-zA-Z0-9]*
118
119 %s SCRIPT
120 %s EXPRESSION
121 %s BOTH
122 %s DEFSYMEXP
123 %s MRI
124 %s VERS_START
125 %s VERS_SCRIPT
126 %s VERS_NODE
127 %%
128
129   if (parser_input != input_selected)
130     {
131       /* The first token of the input determines the initial parser state.  */
132       input_type t = parser_input;
133       parser_input = input_selected;
134       switch (t)
135         {
136         case input_script: return INPUT_SCRIPT; break;
137         case input_mri_script: return INPUT_MRI_SCRIPT; break;
138         case input_version_script: return INPUT_VERSION_SCRIPT; break;
139         case input_defsym: return INPUT_DEFSYM; break;
140         default: abort ();
141         }
142     }
143
144 <BOTH,SCRIPT,EXPRESSION>"/*"    { comment(); }
145
146
147 <DEFSYMEXP>"-"                  { RTOKEN('-');}
148 <DEFSYMEXP>"+"                  { RTOKEN('+');}
149 <DEFSYMEXP>{FILENAMECHAR1}{SYMBOLCHARN}*   { yylval.name = buystring(yytext); return NAME; }
150 <DEFSYMEXP>"="                  { RTOKEN('='); }
151
152 <MRI,EXPRESSION>"$"([0-9A-Fa-f])+ {
153                                 yylval.integer = bfd_scan_vma (yytext+1, 0,16);
154                                 return INT;
155                         }
156
157 <MRI,EXPRESSION>([0-9A-Fa-f])+(H|h|X|x|B|b|O|o|D|d) {
158                                    int ibase ;
159                                    switch (yytext[yyleng-1]) {
160                                     case 'X': 
161                                     case 'x':
162                                     case 'H':
163                                     case 'h':
164                                      ibase = 16;
165                                      break;
166                                     case 'O':
167                                     case 'o':
168                                      ibase = 8;
169                                      break;
170                                     case 'B':
171                                     case 'b':
172                                      ibase = 2;
173                                      break;
174                                     default:
175                                      ibase = 10;
176                                    }
177                                    yylval.integer = bfd_scan_vma (yytext, 0,
178                                                                   ibase);
179                                    return INT;
180                                  }
181 <SCRIPT,DEFSYMEXP,MRI,BOTH,EXPRESSION>((("$"|"0x")([0-9A-Fa-f])+)|(([0-9])+))(M|K|m|k)? {
182                                   char *s = yytext;
183
184                                   if (*s == '$')
185                                     ++s;
186                                   yylval.integer = bfd_scan_vma (s, 0, 0);
187                                   if (yytext[yyleng-1] == 'M'
188                                       || yytext[yyleng-1] == 'm')
189                                     yylval.integer *= 1024 * 1024;
190                                   if (yytext[yyleng-1] == 'K' 
191                                       || yytext[yyleng-1]=='k')
192                                     yylval.integer *= 1024;
193                                   return INT;
194                                 }
195 <BOTH,SCRIPT,EXPRESSION,MRI>"]"         { RTOKEN(']');}
196 <BOTH,SCRIPT,EXPRESSION,MRI>"["         { RTOKEN('[');}
197 <BOTH,SCRIPT,EXPRESSION,MRI>"<<="       { RTOKEN(LSHIFTEQ);}
198 <BOTH,SCRIPT,EXPRESSION,MRI>">>="       { RTOKEN(RSHIFTEQ);}
199 <BOTH,SCRIPT,EXPRESSION,MRI>"||"        { RTOKEN(OROR);}
200 <BOTH,SCRIPT,EXPRESSION,MRI>"=="        { RTOKEN(EQ);}
201 <BOTH,SCRIPT,EXPRESSION,MRI>"!="        { RTOKEN(NE);}
202 <BOTH,SCRIPT,EXPRESSION,MRI>">="        { RTOKEN(GE);}
203 <BOTH,SCRIPT,EXPRESSION,MRI>"<="        { RTOKEN(LE);}
204 <BOTH,SCRIPT,EXPRESSION,MRI>"<<"        { RTOKEN(LSHIFT);}
205 <BOTH,SCRIPT,EXPRESSION,MRI>">>"        { RTOKEN(RSHIFT);}
206 <BOTH,SCRIPT,EXPRESSION,MRI>"+="        { RTOKEN(PLUSEQ);}
207 <BOTH,SCRIPT,EXPRESSION,MRI>"-="        { RTOKEN(MINUSEQ);}
208 <BOTH,SCRIPT,EXPRESSION,MRI>"*="        { RTOKEN(MULTEQ);}
209 <BOTH,SCRIPT,EXPRESSION,MRI>"/="        { RTOKEN(DIVEQ);}
210 <BOTH,SCRIPT,EXPRESSION,MRI>"&="        { RTOKEN(ANDEQ);}
211 <BOTH,SCRIPT,EXPRESSION,MRI>"|="        { RTOKEN(OREQ);}
212 <BOTH,SCRIPT,EXPRESSION,MRI>"&&"        { RTOKEN(ANDAND);}
213 <BOTH,SCRIPT,EXPRESSION,MRI>">"         { RTOKEN('>');}
214 <BOTH,SCRIPT,EXPRESSION,MRI>","         { RTOKEN(',');}
215 <BOTH,SCRIPT,EXPRESSION,MRI>"&"         { RTOKEN('&');}
216 <BOTH,SCRIPT,EXPRESSION,MRI>"|"         { RTOKEN('|');}
217 <BOTH,SCRIPT,EXPRESSION,MRI>"~"         { RTOKEN('~');}
218 <BOTH,SCRIPT,EXPRESSION,MRI>"!"         { RTOKEN('!');}
219 <BOTH,SCRIPT,EXPRESSION,MRI>"?"         { RTOKEN('?');}
220 <BOTH,SCRIPT,EXPRESSION,MRI>"*"         { RTOKEN('*');}
221 <BOTH,SCRIPT,EXPRESSION,MRI>"+"         { RTOKEN('+');}
222 <BOTH,SCRIPT,EXPRESSION,MRI>"-"         { RTOKEN('-');}
223 <BOTH,SCRIPT,EXPRESSION,MRI>"/"         { RTOKEN('/');}
224 <BOTH,SCRIPT,EXPRESSION,MRI>"%"         { RTOKEN('%');}
225 <BOTH,SCRIPT,EXPRESSION,MRI>"<"         { RTOKEN('<');}
226 <BOTH,SCRIPT,EXPRESSION,MRI>"="          { RTOKEN('=');}
227 <BOTH,SCRIPT,EXPRESSION,MRI>"}"                 { RTOKEN('}') ; }
228 <BOTH,SCRIPT,EXPRESSION,MRI>"{"                 { RTOKEN('{'); }
229 <BOTH,SCRIPT,EXPRESSION,MRI>")"                 { RTOKEN(')');}
230 <BOTH,SCRIPT,EXPRESSION,MRI>"("                 { RTOKEN('(');}
231 <BOTH,SCRIPT,EXPRESSION,MRI>":"         { RTOKEN(':'); }
232 <BOTH,SCRIPT,EXPRESSION,MRI>";"         { RTOKEN(';');}
233 <BOTH,SCRIPT>"MEMORY"           { RTOKEN(MEMORY);}
234 <BOTH,SCRIPT>"ORIGIN"           { RTOKEN(ORIGIN);}
235 <BOTH,SCRIPT>"VERSION"          { RTOKEN(VERSIONK);}
236 <EXPRESSION,BOTH,SCRIPT>"BLOCK"         { RTOKEN(BLOCK);}
237 <EXPRESSION,BOTH,SCRIPT>"BIND"          { RTOKEN(BIND);}
238 <BOTH,SCRIPT>"LENGTH"           { RTOKEN(LENGTH);}
239 <EXPRESSION,BOTH,SCRIPT>"ALIGN"                 { RTOKEN(ALIGN_K);}
240 <EXPRESSION,BOTH,SCRIPT>"ADDR"                  { RTOKEN(ADDR);}
241 <EXPRESSION,BOTH,SCRIPT>"LOADADDR"              { RTOKEN(LOADADDR);}
242 <EXPRESSION,BOTH>"MAX"                  { RTOKEN(MAX); }
243 <EXPRESSION,BOTH>"MIN"                  { RTOKEN(MIN); }
244 <BOTH,SCRIPT>"ENTRY"                    { RTOKEN(ENTRY);}
245 <EXPRESSION,BOTH,SCRIPT>"NEXT"                  { RTOKEN(NEXT);}
246 <EXPRESSION,BOTH,SCRIPT>"sizeof_headers"        { RTOKEN(SIZEOF_HEADERS);}
247 <EXPRESSION,BOTH,SCRIPT>"SIZEOF_HEADERS"        { RTOKEN(SIZEOF_HEADERS);}
248 <BOTH,SCRIPT>"MAP"                      { RTOKEN(MAP);}
249 <EXPRESSION,BOTH,SCRIPT>"SIZEOF"                { RTOKEN(SIZEOF);}
250 <BOTH,SCRIPT>"TARGET"           { RTOKEN(TARGET_K);}
251 <BOTH,SCRIPT>"SEARCH_DIR"               { RTOKEN(SEARCH_DIR);}
252 <BOTH,SCRIPT>"OUTPUT"           { RTOKEN(OUTPUT);}
253 <BOTH,SCRIPT>"INPUT"                    { RTOKEN(INPUT);}
254 <EXPRESSION,BOTH,SCRIPT>"GROUP"         { RTOKEN(GROUP);}
255 <EXPRESSION,BOTH,SCRIPT>"DEFINED"               { RTOKEN(DEFINED);}
256 <BOTH,SCRIPT>"CREATE_OBJECT_SYMBOLS"    { RTOKEN(CREATE_OBJECT_SYMBOLS);}
257 <BOTH,SCRIPT>"CONSTRUCTORS"             { RTOKEN( CONSTRUCTORS);}
258 <BOTH,SCRIPT>"FORCE_COMMON_ALLOCATION" { RTOKEN(FORCE_COMMON_ALLOCATION);}
259 <BOTH,SCRIPT>"SECTIONS"         { RTOKEN(SECTIONS);}
260 <BOTH,SCRIPT>"FILL"                     { RTOKEN(FILL);}
261 <BOTH,SCRIPT>"STARTUP"          { RTOKEN(STARTUP);}
262 <BOTH,SCRIPT>"OUTPUT_FORMAT"            { RTOKEN(OUTPUT_FORMAT);}
263 <BOTH,SCRIPT>"OUTPUT_ARCH"              { RTOKEN( OUTPUT_ARCH);}
264 <BOTH,SCRIPT>"HLL"                      { RTOKEN(HLL);}
265 <BOTH,SCRIPT>"SYSLIB"           { RTOKEN(SYSLIB);}
266 <BOTH,SCRIPT>"FLOAT"                    { RTOKEN(FLOAT);}
267 <BOTH,SCRIPT>"QUAD"                     { RTOKEN( QUAD);}
268 <BOTH,SCRIPT>"SQUAD"                    { RTOKEN( SQUAD);}
269 <BOTH,SCRIPT>"LONG"                     { RTOKEN( LONG);}
270 <BOTH,SCRIPT>"SHORT"                    { RTOKEN( SHORT);}
271 <BOTH,SCRIPT>"BYTE"                     { RTOKEN( BYTE);}
272 <BOTH,SCRIPT>"NOFLOAT"          { RTOKEN(NOFLOAT);}
273 <EXPRESSION,BOTH,SCRIPT>"NOCROSSREFS"   { RTOKEN(NOCROSSREFS);}
274 <BOTH,SCRIPT>"OVERLAY"                  { RTOKEN(OVERLAY); }
275 <EXPRESSION,BOTH,SCRIPT>"NOLOAD"        { RTOKEN(NOLOAD);}
276 <EXPRESSION,BOTH,SCRIPT>"DSECT"         { RTOKEN(DSECT);}
277 <EXPRESSION,BOTH,SCRIPT>"COPY"          { RTOKEN(COPY);}
278 <EXPRESSION,BOTH,SCRIPT>"INFO"          { RTOKEN(INFO);}
279 <EXPRESSION,BOTH,SCRIPT>"OVERLAY"       { RTOKEN(OVERLAY);}
280 <BOTH,SCRIPT>"o"                        { RTOKEN(ORIGIN);}
281 <BOTH,SCRIPT>"org"                      { RTOKEN(ORIGIN);}
282 <BOTH,SCRIPT>"l"                        { RTOKEN( LENGTH);}
283 <BOTH,SCRIPT>"len"                      { RTOKEN( LENGTH);}
284 <BOTH,SCRIPT>"INCLUDE"                  { RTOKEN(INCLUDE);}
285 <BOTH,SCRIPT>"PHDRS"                    { RTOKEN (PHDRS); }
286 <EXPRESSION,BOTH,SCRIPT>"AT"                    { RTOKEN(AT);}
287 <EXPRESSION,BOTH,SCRIPT>"PROVIDE"               { RTOKEN(PROVIDE); }
288 <MRI>"#".*\n?                   { ++ lineno; }
289 <MRI>"\n"                       { ++ lineno;  RTOKEN(NEWLINE); }
290 <MRI>"*".*                      { /* Mri comment line */ }
291 <MRI>";".*                      { /* Mri comment line */ }
292 <MRI>"END"                      { RTOKEN(ENDWORD); }
293 <MRI>"ALIGNMOD"         { RTOKEN(ALIGNMOD);}
294 <MRI>"ALIGN"            { RTOKEN(ALIGN_K);}
295 <MRI>"CHIP"                     { RTOKEN(CHIP); }
296 <MRI>"BASE"                     { RTOKEN(BASE); }
297 <MRI>"ALIAS"                     { RTOKEN(ALIAS); }
298 <MRI>"TRUNCATE"                     { RTOKEN(TRUNCATE); }
299 <MRI>"LOAD"                     { RTOKEN(LOAD); }
300 <MRI>"PUBLIC"                   { RTOKEN(PUBLIC); }
301 <MRI>"ORDER"                    { RTOKEN(ORDER); }
302 <MRI>"NAME"                     { RTOKEN(NAMEWORD); }
303 <MRI>"FORMAT"                   { RTOKEN(FORMAT); }
304 <MRI>"CASE"                     { RTOKEN(CASE); }
305 <MRI>"EXTERN"                   { RTOKEN(EXTERN); }
306 <MRI>"START"                    { RTOKEN(START); }
307 <MRI>"LIST".*                   { RTOKEN(LIST); /* LIST and ignore to end of line */ }
308 <MRI>"SECT"                     { RTOKEN(SECT); }
309 <EXPRESSION,BOTH,SCRIPT,MRI>"ABSOLUTE"                  { RTOKEN(ABSOLUTE); }
310 <MRI>"end"                      { RTOKEN(ENDWORD); }
311 <MRI>"alignmod"         { RTOKEN(ALIGNMOD);}
312 <MRI>"align"            { RTOKEN(ALIGN_K);}
313 <MRI>"chip"                     { RTOKEN(CHIP); }
314 <MRI>"base"                     { RTOKEN(BASE); }
315 <MRI>"alias"                     { RTOKEN(ALIAS); }
316 <MRI>"truncate"                     { RTOKEN(TRUNCATE); }
317 <MRI>"load"                     { RTOKEN(LOAD); }
318 <MRI>"public"                   { RTOKEN(PUBLIC); }
319 <MRI>"order"                    { RTOKEN(ORDER); }
320 <MRI>"name"                     { RTOKEN(NAMEWORD); }
321 <MRI>"format"                   { RTOKEN(FORMAT); }
322 <MRI>"case"                     { RTOKEN(CASE); }
323 <MRI>"extern"                   { RTOKEN(EXTERN); }
324 <MRI>"start"                    { RTOKEN(START); }
325 <MRI>"list".*                   { RTOKEN(LIST); /* LIST and ignore to end of line */ }
326 <MRI>"sect"                     { RTOKEN(SECT); }
327 <EXPRESSION,BOTH,SCRIPT,MRI>"absolute"                  { RTOKEN(ABSOLUTE); }
328
329 <MRI>{FILENAMECHAR1}{NOCFILENAMECHAR}*  {
330 /* Filename without commas, needed to parse mri stuff */
331                                  yylval.name = buystring(yytext); 
332                                   return NAME;
333                                 }
334
335
336 <BOTH,EXPRESSION>{FILENAMECHAR1}{FILENAMECHAR}* {
337                                  yylval.name = buystring(yytext); 
338                                   return NAME;
339                                 }
340 <BOTH,EXPRESSION>"-l"{FILENAMECHAR}+ {
341                                   yylval.name = buystring (yytext + 2);
342                                   return LNAME;
343                                 }
344 <SCRIPT>{WILDCHAR}* {
345                 /* Annoyingly, this pattern can match comments, and we have
346                    longest match issues to consider.  So if the first two
347                    characters are a comment opening, put the input back and
348                    try again.  */
349                 if (yytext[0] == '/' && yytext[1] == '*')
350                   {
351                     yyless(2);
352                     comment ();
353                   }
354                 else
355                   {
356                     yylval.name = buystring(yytext);
357                     return NAME;
358                   }
359         }
360
361 <EXPRESSION,BOTH,SCRIPT>"\""[^\"]*"\"" {
362                                         /* No matter the state, quotes
363                                            give what's inside */
364                                         yylval.name = buystring(yytext+1);
365                                         yylval.name[yyleng-2] = 0;
366                                         return NAME;
367                                 }
368 <BOTH,SCRIPT,EXPRESSION>"\n"            { lineno++;}
369 <MRI,BOTH,SCRIPT,EXPRESSION>[ \t\r]+    { }
370
371 <VERS_NODE,VERS_SCRIPT>[:,;]    { return *yytext; }
372
373 <VERS_NODE>global               { RTOKEN(GLOBAL); }
374
375 <VERS_NODE>local                { RTOKEN(LOCAL); }
376
377 <VERS_NODE>{V_IDENTIFIER}       { yylval.name = buystring (yytext);
378                                   return VERS_IDENTIFIER; }
379
380 <VERS_SCRIPT>{V_TAG}            { yylval.name = buystring (yytext);
381                                   return VERS_TAG; }
382
383 <VERS_START>"{"                 { BEGIN(VERS_SCRIPT); return *yytext; }
384
385 <VERS_SCRIPT>"{"                { BEGIN(VERS_NODE); return *yytext; }
386 <VERS_SCRIPT,VERS_NODE>"}"      { BEGIN(VERS_SCRIPT); return *yytext; }
387
388 <VERS_START,VERS_NODE,VERS_SCRIPT>[\n]          { lineno++; }
389
390 <VERS_START,VERS_NODE,VERS_SCRIPT>#.*           { /* Eat up comments */ }
391
392 <VERS_START,VERS_NODE,VERS_SCRIPT>[ \t\r]+      { /* Eat up whitespace */ }
393
394 <<EOF>> {
395   include_stack_ptr--;
396     
397   if (include_stack_ptr == 0) 
398   {
399     yyterminate();
400   }
401   else 
402   {
403     yy_switch_to_buffer(include_stack[include_stack_ptr]);
404
405   }
406   BEGIN(SCRIPT);
407   ldfile_input_filename = file_name_stack[include_stack_ptr - 1];
408   lineno = lineno_stack[include_stack_ptr - 1];
409
410   return END;
411 }
412
413 <SCRIPT,MRI,VERS_START,VERS_SCRIPT,VERS_NODE>.  lex_warn_invalid(" in script", yytext);
414 <EXPRESSION,DEFSYMEXP,BOTH>.    lex_warn_invalid(" in expression", yytext);
415     
416 %%
417 \f
418
419 /* Switch flex to reading script file NAME, open on FILE,
420    saving the current input info on the include stack.  */
421
422 void
423 lex_push_file (file, name)
424      FILE *file;
425      const char *name;
426 {
427   if (include_stack_ptr >= MAX_INCLUDE_DEPTH) 
428     {
429       einfo("%F:includes nested too deeply\n");
430     }
431   file_name_stack[include_stack_ptr] = name;
432   lineno_stack[include_stack_ptr] = 1;
433   include_stack[include_stack_ptr] = YY_CURRENT_BUFFER;
434
435   include_stack_ptr++;
436   yyin = file;
437   yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
438   BEGIN (SCRIPT);
439 }
440
441 /* Return a newly created flex input buffer containing STRING,
442    which is SIZE bytes long.  */
443
444 static YY_BUFFER_STATE 
445 yy_create_string_buffer (string, size)
446      CONST char *string;
447      size_t size;
448 {
449   YY_BUFFER_STATE b;
450
451   /* Calls to m-alloc get turned by sed into xm-alloc.  */
452   b = (YY_BUFFER_STATE) malloc (sizeof (struct yy_buffer_state));
453   b->yy_input_file = 0;
454   b->yy_buf_size = size;
455
456   /* yy_ch_buf has to be 2 characters longer than the size given because
457      we need to put in 2 end-of-buffer characters.  */
458   b->yy_ch_buf = (char *) malloc ((unsigned) (b->yy_buf_size + 3));
459
460   b->yy_ch_buf[0] = '\n';
461   strcpy (b->yy_ch_buf+1, string);
462   b->yy_ch_buf[size+1] = YY_END_OF_BUFFER_CHAR;
463   b->yy_ch_buf[size+2] = YY_END_OF_BUFFER_CHAR;
464   b->yy_n_chars = size+1;
465   b->yy_buf_pos = &b->yy_ch_buf[1];
466
467   /* flex 2.4.7 changed the interface.  FIXME: We should not be using
468      a flex internal interface in the first place!  */
469 #ifdef YY_BUFFER_NEW
470   b->yy_buffer_status = YY_BUFFER_NEW;
471 #else
472   b->yy_eof_status = EOF_NOT_SEEN;
473 #endif
474
475   return b;
476 }
477
478 /* Switch flex to reading from STRING, saving the current input info
479    on the include stack.  */
480
481 void
482 lex_redirect (string)
483      CONST char *string;
484 {
485   YY_BUFFER_STATE tmp;
486
487   yy_init = 0;
488   if (include_stack_ptr >= MAX_INCLUDE_DEPTH) 
489     {
490       einfo("%F: macros nested too deeply\n");
491     }
492   file_name_stack[include_stack_ptr] = "redirect";
493   lineno_stack[include_stack_ptr] = 0;
494   include_stack[include_stack_ptr] = YY_CURRENT_BUFFER;
495   include_stack_ptr++;
496   tmp = yy_create_string_buffer (string, strlen (string));
497   yy_switch_to_buffer (tmp);
498   BEGIN (SCRIPT);
499 }
500 \f
501 /* Functions to switch to a different flex start condition,
502    saving the current start condition on `state_stack'.  */
503
504 static int state_stack[MAX_INCLUDE_DEPTH * 2];
505 static int *state_stack_p = state_stack;
506
507 void
508 ldlex_script ()
509 {
510   *(state_stack_p)++ = yy_start;
511   BEGIN (SCRIPT);
512 }
513
514 void
515 ldlex_mri_script ()
516 {
517   *(state_stack_p)++ = yy_start;
518   BEGIN (MRI);
519 }
520
521 void
522 ldlex_version_script ()
523 {
524   *(state_stack_p)++ = yy_start;
525   BEGIN (VERS_START);
526 }
527
528 void
529 ldlex_version_file ()
530 {
531   *(state_stack_p)++ = yy_start;
532   BEGIN (VERS_SCRIPT);
533 }
534
535 void
536 ldlex_defsym ()
537 {
538   *(state_stack_p)++ = yy_start;
539   BEGIN (DEFSYMEXP);
540 }
541            
542 void
543 ldlex_expression ()
544 {
545   *(state_stack_p)++ = yy_start;
546   BEGIN (EXPRESSION);
547 }
548
549 void
550 ldlex_both ()
551 {
552   *(state_stack_p)++ = yy_start;
553   BEGIN (BOTH);
554 }
555
556 void
557 ldlex_popstate ()
558 {
559   yy_start = *(--state_stack_p);
560 }
561 \f
562
563 /* Place up to MAX_SIZE characters in BUF and return in *RESULT
564    either the number of characters read, or 0 to indicate EOF.  */
565
566 static void
567 yy_input (buf, result, max_size)
568      char *buf;
569      int *result;
570      int max_size;
571 {
572   *result = 0; 
573   if (yy_current_buffer->yy_input_file)
574     {
575       if (yyin)
576         {
577           *result = read (fileno (yyin), (char *) buf, max_size);
578           if (*result < 0) 
579             einfo ("%F%P: read in flex scanner failed\n");
580         }
581     }
582 }
583
584 /* Eat the rest of a C-style comment.  */
585
586 static void
587 comment ()
588 {
589   int c;
590
591   while (1)
592   {
593     c = input();
594     while (c != '*' && c != EOF) 
595     {
596       if (c == '\n')
597         lineno++;
598       c = input();
599     }
600
601     if (c == '*')
602     {
603       c = input();
604       while (c == '*')
605        c = input();
606       if (c == '/')
607        break;                   /* found the end */
608     }
609
610     if (c == '\n')
611       lineno++;
612
613     if (c == EOF)
614     {
615       einfo( "%F%P: EOF in comment\n");
616       break;
617     }
618   }
619 }
620
621 /* Warn the user about a garbage character WHAT in the input
622    in context WHERE.  */
623
624 static void
625 lex_warn_invalid (where, what)
626      char *where, *what;
627 {
628   char buf[5];
629
630   /* If we have found an input file whose format we do not recognize,
631      and we are therefore treating it as a linker script, and we find
632      an invalid character, then most likely this is a real object file
633      of some different format.  Treat it as such.  */
634   if (ldfile_assumed_script)
635     {
636       bfd_set_error (bfd_error_file_not_recognized);
637       einfo ("%F%s: file not recognized: %E\n", ldfile_input_filename);
638     }
639
640   if (! isprint ((unsigned char) *what))
641     {
642       sprintf (buf, "\\%03o", (unsigned int) *what);
643       what = buf;
644     }
645
646   einfo ("%P:%S: ignoring invalid character `%s'%s\n", what, where);
647 }