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