Initial revision
[binutils.git] / ld / ldlex.l
blob2eef80f1fe2b259cc40f56004b41f3c3a48e3fb0
1 %{
3 /* Copyright (C) 1991, 92, 93, 94, 95, 96, 97, 98, 1999
4    Free Software Foundation, Inc.
6 This file is part of GLD, the Gnu Linker.
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.
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.
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.  */
24 This was written by steve chamberlain
25                     sac@cygnus.com
29 #include <ansidecl.h>
30 #include <stdio.h>
31 #include <ctype.h>
33 #ifdef MPW
34 /* Prevent enum redefinition problems. */
35 #define TRUE_FALSE_ALREADY_DEFINED
36 #endif /* MPW */
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"
49 /* The type of top-level parser input.
50    yylex and yyparse (indirectly) both check this.  */
51 input_type parser_input;
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;
57 /* The string we are currently lexing, or NULL if we are reading a
58    file.  */
59 const char *lex_string = NULL;
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.
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.  */
69 #undef YY_INPUT
70 #define YY_INPUT(buf,result,max_size) yy_input(buf, &result, max_size)
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 static int vers_node_nesting = 0;
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));
83 static void comment PARAMS ((void));
84 static void lex_warn_invalid PARAMS ((char *where, char *what));
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         VERS_START      starting a Sun style mapfile
93         VERS_SCRIPT     a Sun style mapfile
94         VERS_NODE       a node within a Sun style mapfile
96 #define RTOKEN(x)  {  yylval.token = x; return x; }
98 /* Some versions of flex want this.  */
99 #ifndef yywrap
100 int yywrap () { return 1; }
101 #endif
104 %a 4000
105 %o 5000
107 CMDFILENAMECHAR   [_a-zA-Z0-9\/\.\\_\+\$\:\[\]\\\,\=\&\!\<\>\-\~]
108 CMDFILENAMECHAR1  [_a-zA-Z0-9\/\.\\_\+\$\:\[\]\\\,\=\&\!\<\>\~]
109 FILENAMECHAR1   [_a-zA-Z\/\.\\\$\_\~]
110 SYMBOLCHARN     [_a-zA-Z\/\.\\\$\_\~0-9]
111 FILENAMECHAR    [_a-zA-Z0-9\/\.\-\_\+\=\$\:\[\]\\\,\~]
112 WILDCHAR        [_a-zA-Z0-9\/\.\-\_\+\=\$\:\[\]\\\,\~\?\*]
113 WHITE           [ \t\n\r]+ 
115 NOCFILENAMECHAR [_a-zA-Z0-9\/\.\-\_\+\$\:\[\]\\\~]
117 V_TAG [.$_a-zA-Z][._a-zA-Z0-9]*
118 V_IDENTIFIER [*?.$_a-zA-Z][*?.$_a-zA-Z0-9]*
120 %s SCRIPT
121 %s EXPRESSION
122 %s BOTH
123 %s DEFSYMEXP
124 %s MRI
125 %s VERS_START
126 %s VERS_SCRIPT
127 %s VERS_NODE
130   if (parser_input != input_selected)
131     {
132       /* The first token of the input determines the initial parser state.  */
133       input_type t = parser_input;
134       parser_input = input_selected;
135       switch (t)
136         {
137         case input_script: return INPUT_SCRIPT; break;
138         case input_mri_script: return INPUT_MRI_SCRIPT; break;
139         case input_version_script: return INPUT_VERSION_SCRIPT; break;
140         case input_defsym: return INPUT_DEFSYM; break;
141         default: abort ();
142         }
143     }
145 <BOTH,SCRIPT,EXPRESSION>"/*"    { comment(); }
148 <DEFSYMEXP>"-"                  { RTOKEN('-');}
149 <DEFSYMEXP>"+"                  { RTOKEN('+');}
150 <DEFSYMEXP>{FILENAMECHAR1}{SYMBOLCHARN}*   { yylval.name = buystring(yytext); return NAME; }
151 <DEFSYMEXP>"="                  { RTOKEN('='); }
153 <MRI,EXPRESSION>"$"([0-9A-Fa-f])+ {
154                                 yylval.integer = bfd_scan_vma (yytext+1, 0,16);
155                                 return INT;
156                         }
158 <MRI,EXPRESSION>([0-9A-Fa-f])+(H|h|X|x|B|b|O|o|D|d) {
159                                    int ibase ;
160                                    switch (yytext[yyleng-1]) {
161                                     case 'X': 
162                                     case 'x':
163                                     case 'H':
164                                     case 'h':
165                                      ibase = 16;
166                                      break;
167                                     case 'O':
168                                     case 'o':
169                                      ibase = 8;
170                                      break;
171                                     case 'B':
172                                     case 'b':
173                                      ibase = 2;
174                                      break;
175                                     default:
176                                      ibase = 10;
177                                    }
178                                    yylval.integer = bfd_scan_vma (yytext, 0,
179                                                                   ibase);
180                                    return INT;
181                                  }
182 <SCRIPT,DEFSYMEXP,MRI,BOTH,EXPRESSION>((("$"|"0x")([0-9A-Fa-f])+)|(([0-9])+))(M|K|m|k)? {
183                                   char *s = yytext;
185                                   if (*s == '$')
186                                     ++s;
187                                   yylval.integer = bfd_scan_vma (s, 0, 0);
188                                   if (yytext[yyleng-1] == 'M'
189                                       || yytext[yyleng-1] == 'm')
190                                     yylval.integer *= 1024 * 1024;
191                                   if (yytext[yyleng-1] == 'K' 
192                                       || yytext[yyleng-1]=='k')
193                                     yylval.integer *= 1024;
194                                   return INT;
195                                 }
196 <BOTH,SCRIPT,EXPRESSION,MRI>"]"         { RTOKEN(']');}
197 <BOTH,SCRIPT,EXPRESSION,MRI>"["         { RTOKEN('[');}
198 <BOTH,SCRIPT,EXPRESSION,MRI>"<<="       { RTOKEN(LSHIFTEQ);}
199 <BOTH,SCRIPT,EXPRESSION,MRI>">>="       { RTOKEN(RSHIFTEQ);}
200 <BOTH,SCRIPT,EXPRESSION,MRI>"||"        { RTOKEN(OROR);}
201 <BOTH,SCRIPT,EXPRESSION,MRI>"=="        { RTOKEN(EQ);}
202 <BOTH,SCRIPT,EXPRESSION,MRI>"!="        { RTOKEN(NE);}
203 <BOTH,SCRIPT,EXPRESSION,MRI>">="        { RTOKEN(GE);}
204 <BOTH,SCRIPT,EXPRESSION,MRI>"<="        { RTOKEN(LE);}
205 <BOTH,SCRIPT,EXPRESSION,MRI>"<<"        { RTOKEN(LSHIFT);}
206 <BOTH,SCRIPT,EXPRESSION,MRI>">>"        { RTOKEN(RSHIFT);}
207 <BOTH,SCRIPT,EXPRESSION,MRI>"+="        { RTOKEN(PLUSEQ);}
208 <BOTH,SCRIPT,EXPRESSION,MRI>"-="        { RTOKEN(MINUSEQ);}
209 <BOTH,SCRIPT,EXPRESSION,MRI>"*="        { RTOKEN(MULTEQ);}
210 <BOTH,SCRIPT,EXPRESSION,MRI>"/="        { RTOKEN(DIVEQ);}
211 <BOTH,SCRIPT,EXPRESSION,MRI>"&="        { RTOKEN(ANDEQ);}
212 <BOTH,SCRIPT,EXPRESSION,MRI>"|="        { RTOKEN(OREQ);}
213 <BOTH,SCRIPT,EXPRESSION,MRI>"&&"        { RTOKEN(ANDAND);}
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,EXPRESSION,MRI>";"         { RTOKEN(';');}
234 <BOTH,SCRIPT>"MEMORY"           { RTOKEN(MEMORY);}
235 <BOTH,SCRIPT>"ORIGIN"           { RTOKEN(ORIGIN);}
236 <BOTH,SCRIPT>"VERSION"          { RTOKEN(VERSIONK);}
237 <EXPRESSION,BOTH,SCRIPT>"BLOCK"         { RTOKEN(BLOCK);}
238 <EXPRESSION,BOTH,SCRIPT>"BIND"          { RTOKEN(BIND);}
239 <BOTH,SCRIPT>"LENGTH"           { RTOKEN(LENGTH);}
240 <EXPRESSION,BOTH,SCRIPT>"ALIGN"                 { RTOKEN(ALIGN_K);}
241 <EXPRESSION,BOTH,SCRIPT>"ADDR"                  { RTOKEN(ADDR);}
242 <EXPRESSION,BOTH,SCRIPT>"LOADADDR"              { RTOKEN(LOADADDR);}
243 <EXPRESSION,BOTH>"MAX"                  { RTOKEN(MAX_K); }
244 <EXPRESSION,BOTH>"MIN"                  { RTOKEN(MIN_K); }
245 <EXPRESSION,BOTH>"ASSERT"               { RTOKEN(ASSERT_K); }
246 <BOTH,SCRIPT>"ENTRY"                    { RTOKEN(ENTRY);}
247 <BOTH,SCRIPT,MRI>"EXTERN"               { RTOKEN(EXTERN);}
248 <EXPRESSION,BOTH,SCRIPT>"NEXT"                  { RTOKEN(NEXT);}
249 <EXPRESSION,BOTH,SCRIPT>"sizeof_headers"        { RTOKEN(SIZEOF_HEADERS);}
250 <EXPRESSION,BOTH,SCRIPT>"SIZEOF_HEADERS"        { RTOKEN(SIZEOF_HEADERS);}
251 <BOTH,SCRIPT>"MAP"                      { RTOKEN(MAP);}
252 <EXPRESSION,BOTH,SCRIPT>"SIZEOF"                { RTOKEN(SIZEOF);}
253 <BOTH,SCRIPT>"TARGET"           { RTOKEN(TARGET_K);}
254 <BOTH,SCRIPT>"SEARCH_DIR"               { RTOKEN(SEARCH_DIR);}
255 <BOTH,SCRIPT>"OUTPUT"           { RTOKEN(OUTPUT);}
256 <BOTH,SCRIPT>"INPUT"                    { RTOKEN(INPUT);}
257 <EXPRESSION,BOTH,SCRIPT>"GROUP"         { RTOKEN(GROUP);}
258 <EXPRESSION,BOTH,SCRIPT>"DEFINED"               { RTOKEN(DEFINED);}
259 <BOTH,SCRIPT>"CREATE_OBJECT_SYMBOLS"    { RTOKEN(CREATE_OBJECT_SYMBOLS);}
260 <BOTH,SCRIPT>"CONSTRUCTORS"             { RTOKEN( CONSTRUCTORS);}
261 <BOTH,SCRIPT>"FORCE_COMMON_ALLOCATION" { RTOKEN(FORCE_COMMON_ALLOCATION);}
262 <BOTH,SCRIPT>"SECTIONS"         { RTOKEN(SECTIONS);}
263 <BOTH,SCRIPT>"FILL"                     { RTOKEN(FILL);}
264 <BOTH,SCRIPT>"STARTUP"          { RTOKEN(STARTUP);}
265 <BOTH,SCRIPT>"OUTPUT_FORMAT"            { RTOKEN(OUTPUT_FORMAT);}
266 <BOTH,SCRIPT>"OUTPUT_ARCH"              { RTOKEN( OUTPUT_ARCH);}
267 <BOTH,SCRIPT>"HLL"                      { RTOKEN(HLL);}
268 <BOTH,SCRIPT>"SYSLIB"           { RTOKEN(SYSLIB);}
269 <BOTH,SCRIPT>"FLOAT"                    { RTOKEN(FLOAT);}
270 <BOTH,SCRIPT>"QUAD"                     { RTOKEN( QUAD);}
271 <BOTH,SCRIPT>"SQUAD"                    { RTOKEN( SQUAD);}
272 <BOTH,SCRIPT>"LONG"                     { RTOKEN( LONG);}
273 <BOTH,SCRIPT>"SHORT"                    { RTOKEN( SHORT);}
274 <BOTH,SCRIPT>"BYTE"                     { RTOKEN( BYTE);}
275 <BOTH,SCRIPT>"NOFLOAT"          { RTOKEN(NOFLOAT);}
276 <EXPRESSION,BOTH,SCRIPT>"NOCROSSREFS"   { RTOKEN(NOCROSSREFS);}
277 <BOTH,SCRIPT>"OVERLAY"                  { RTOKEN(OVERLAY); }
278 <BOTH,SCRIPT>"SORT"                     { RTOKEN(SORT); }
279 <EXPRESSION,BOTH,SCRIPT>"NOLOAD"        { RTOKEN(NOLOAD);}
280 <EXPRESSION,BOTH,SCRIPT>"DSECT"         { RTOKEN(DSECT);}
281 <EXPRESSION,BOTH,SCRIPT>"COPY"          { RTOKEN(COPY);}
282 <EXPRESSION,BOTH,SCRIPT>"INFO"          { RTOKEN(INFO);}
283 <EXPRESSION,BOTH,SCRIPT>"OVERLAY"       { RTOKEN(OVERLAY);}
284 <BOTH,SCRIPT>"o"                        { RTOKEN(ORIGIN);}
285 <BOTH,SCRIPT>"org"                      { RTOKEN(ORIGIN);}
286 <BOTH,SCRIPT>"l"                        { RTOKEN( LENGTH);}
287 <BOTH,SCRIPT>"len"                      { RTOKEN( LENGTH);}
288 <BOTH,SCRIPT>"INCLUDE"                  { RTOKEN(INCLUDE);}
289 <BOTH,SCRIPT>"PHDRS"                    { RTOKEN (PHDRS); }
290 <EXPRESSION,BOTH,SCRIPT>"AT"                    { RTOKEN(AT);}
291 <EXPRESSION,BOTH,SCRIPT>"PROVIDE"               { RTOKEN(PROVIDE); }
292 <EXPRESSION,BOTH,SCRIPT>"KEEP"          { RTOKEN(KEEP); }
293 <EXPRESSION,BOTH,SCRIPT>"EXCLUDE_FILE"        { RTOKEN(EXCLUDE_FILE); }
294 <MRI>"#".*\n?                   { ++ lineno; }
295 <MRI>"\n"                       { ++ lineno;  RTOKEN(NEWLINE); }
296 <MRI>"*".*                      { /* Mri comment line */ }
297 <MRI>";".*                      { /* Mri comment line */ }
298 <MRI>"END"                      { RTOKEN(ENDWORD); }
299 <MRI>"ALIGNMOD"         { RTOKEN(ALIGNMOD);}
300 <MRI>"ALIGN"            { RTOKEN(ALIGN_K);}
301 <MRI>"CHIP"                     { RTOKEN(CHIP); }
302 <MRI>"BASE"                     { RTOKEN(BASE); }
303 <MRI>"ALIAS"                     { RTOKEN(ALIAS); }
304 <MRI>"TRUNCATE"                     { RTOKEN(TRUNCATE); }
305 <MRI>"LOAD"                     { RTOKEN(LOAD); }
306 <MRI>"PUBLIC"                   { RTOKEN(PUBLIC); }
307 <MRI>"ORDER"                    { RTOKEN(ORDER); }
308 <MRI>"NAME"                     { RTOKEN(NAMEWORD); }
309 <MRI>"FORMAT"                   { RTOKEN(FORMAT); }
310 <MRI>"CASE"                     { RTOKEN(CASE); }
311 <MRI>"START"                    { RTOKEN(START); }
312 <MRI>"LIST".*                   { RTOKEN(LIST); /* LIST and ignore to end of line */ }
313 <MRI>"SECT"                     { RTOKEN(SECT); }
314 <EXPRESSION,BOTH,SCRIPT,MRI>"ABSOLUTE"                  { RTOKEN(ABSOLUTE); }
315 <MRI>"end"                      { RTOKEN(ENDWORD); }
316 <MRI>"alignmod"         { RTOKEN(ALIGNMOD);}
317 <MRI>"align"            { RTOKEN(ALIGN_K);}
318 <MRI>"chip"                     { RTOKEN(CHIP); }
319 <MRI>"base"                     { RTOKEN(BASE); }
320 <MRI>"alias"                     { RTOKEN(ALIAS); }
321 <MRI>"truncate"                     { RTOKEN(TRUNCATE); }
322 <MRI>"load"                     { RTOKEN(LOAD); }
323 <MRI>"public"                   { RTOKEN(PUBLIC); }
324 <MRI>"order"                    { RTOKEN(ORDER); }
325 <MRI>"name"                     { RTOKEN(NAMEWORD); }
326 <MRI>"format"                   { RTOKEN(FORMAT); }
327 <MRI>"case"                     { RTOKEN(CASE); }
328 <MRI>"extern"                   { RTOKEN(EXTERN); }
329 <MRI>"start"                    { RTOKEN(START); }
330 <MRI>"list".*                   { RTOKEN(LIST); /* LIST and ignore to end of line */ }
331 <MRI>"sect"                     { RTOKEN(SECT); }
332 <EXPRESSION,BOTH,SCRIPT,MRI>"absolute"                  { RTOKEN(ABSOLUTE); }
334 <MRI>{FILENAMECHAR1}{NOCFILENAMECHAR}*  {
335 /* Filename without commas, needed to parse mri stuff */
336                                  yylval.name = buystring(yytext); 
337                                   return NAME;
338                                 }
341 <BOTH,EXPRESSION>{FILENAMECHAR1}{FILENAMECHAR}* {
342                                  yylval.name = buystring(yytext); 
343                                   return NAME;
344                                 }
345 <BOTH,EXPRESSION>"-l"{FILENAMECHAR}+ {
346                                   yylval.name = buystring (yytext + 2);
347                                   return LNAME;
348                                 }
349 <SCRIPT>{WILDCHAR}* {
350                 /* Annoyingly, this pattern can match comments, and we have
351                    longest match issues to consider.  So if the first two
352                    characters are a comment opening, put the input back and
353                    try again.  */
354                 if (yytext[0] == '/' && yytext[1] == '*')
355                   {
356                     yyless(2);
357                     comment ();
358                   }
359                 else
360                   {
361                     yylval.name = buystring(yytext);
362                     return NAME;
363                   }
364         }
366 <EXPRESSION,BOTH,SCRIPT,VERS_NODE>"\""[^\"]*"\"" {
367                                         /* No matter the state, quotes
368                                            give what's inside */
369                                         yylval.name = buystring(yytext+1);
370                                         yylval.name[yyleng-2] = 0;
371                                         return NAME;
372                                 }
373 <BOTH,SCRIPT,EXPRESSION>"\n"            { lineno++;}
374 <MRI,BOTH,SCRIPT,EXPRESSION>[ \t\r]+    { }
376 <VERS_NODE,VERS_SCRIPT>[:,;]    { return *yytext; }
378 <VERS_NODE>global               { RTOKEN(GLOBAL); }
380 <VERS_NODE>local                { RTOKEN(LOCAL); }
382 <VERS_NODE>extern               { RTOKEN(EXTERN); }
384 <VERS_NODE>{V_IDENTIFIER}       { yylval.name = buystring (yytext);
385                                   return VERS_IDENTIFIER; }
387 <VERS_SCRIPT>{V_TAG}            { yylval.name = buystring (yytext);
388                                   return VERS_TAG; }
390 <VERS_START>"{"                 { BEGIN(VERS_SCRIPT); return *yytext; }
392 <VERS_SCRIPT>"{"                { BEGIN(VERS_NODE); 
393                                   vers_node_nesting = 0;
394                                   return *yytext;
395                                 }
396 <VERS_SCRIPT>"}"                { return *yytext; }
397 <VERS_NODE>"{"                  { vers_node_nesting++; return *yytext; }
398 <VERS_NODE>"}"                  { if (--vers_node_nesting < 0)
399                                     BEGIN(VERS_SCRIPT);
400                                   return *yytext;
401                                 }
403 <VERS_START,VERS_NODE,VERS_SCRIPT>[\n]          { lineno++; }
405 <VERS_START,VERS_NODE,VERS_SCRIPT>#.*           { /* Eat up comments */ }
407 <VERS_START,VERS_NODE,VERS_SCRIPT>[ \t\r]+      { /* Eat up whitespace */ }
409 <<EOF>> {
410   include_stack_ptr--;
411     
412   if (include_stack_ptr == 0) 
413   {
414     yyterminate();
415   }
416   else 
417   {
418     yy_switch_to_buffer(include_stack[include_stack_ptr]);
420   }
421   BEGIN(SCRIPT);
422   ldfile_input_filename = file_name_stack[include_stack_ptr - 1];
423   lineno = lineno_stack[include_stack_ptr - 1];
425   return END;
428 <SCRIPT,MRI,VERS_START,VERS_SCRIPT,VERS_NODE>.  lex_warn_invalid(" in script", yytext);
429 <EXPRESSION,DEFSYMEXP,BOTH>.    lex_warn_invalid(" in expression", yytext);
430     
434 /* Switch flex to reading script file NAME, open on FILE,
435    saving the current input info on the include stack.  */
437 void
438 lex_push_file (file, name)
439      FILE *file;
440      const char *name;
442   if (include_stack_ptr >= MAX_INCLUDE_DEPTH) 
443     {
444       einfo("%F:includes nested too deeply\n");
445     }
446   file_name_stack[include_stack_ptr] = name;
447   lineno_stack[include_stack_ptr] = 1;
448   include_stack[include_stack_ptr] = YY_CURRENT_BUFFER;
450   include_stack_ptr++;
451   yyin = file;
452   yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
453   BEGIN (SCRIPT);
456 /* Return a newly created flex input buffer containing STRING,
457    which is SIZE bytes long.  */
459 static YY_BUFFER_STATE 
460 yy_create_string_buffer (string, size)
461      CONST char *string;
462      size_t size;
464   YY_BUFFER_STATE b;
466   /* Calls to m-alloc get turned by sed into xm-alloc.  */
467   b = (YY_BUFFER_STATE) malloc (sizeof (struct yy_buffer_state));
468   b->yy_input_file = 0;
469   b->yy_buf_size = size;
471   /* yy_ch_buf has to be 2 characters longer than the size given because
472      we need to put in 2 end-of-buffer characters.  */
473   b->yy_ch_buf = (char *) malloc ((unsigned) (b->yy_buf_size + 3));
475   b->yy_ch_buf[0] = '\n';
476   strcpy (b->yy_ch_buf+1, string);
477   b->yy_ch_buf[size+1] = YY_END_OF_BUFFER_CHAR;
478   b->yy_ch_buf[size+2] = YY_END_OF_BUFFER_CHAR;
479   b->yy_n_chars = size+1;
480   b->yy_buf_pos = &b->yy_ch_buf[1];
482   /* flex 2.4.7 changed the interface.  FIXME: We should not be using
483      a flex internal interface in the first place!  */
484 #ifdef YY_BUFFER_NEW
485   b->yy_buffer_status = YY_BUFFER_NEW;
486 #else
487   b->yy_eof_status = EOF_NOT_SEEN;
488 #endif
490   return b;
493 /* Switch flex to reading from STRING, saving the current input info
494    on the include stack.  */
496 void
497 lex_redirect (string)
498      CONST char *string;
500   YY_BUFFER_STATE tmp;
502   yy_init = 0;
503   if (include_stack_ptr >= MAX_INCLUDE_DEPTH) 
504     {
505       einfo("%F: macros nested too deeply\n");
506     }
507   file_name_stack[include_stack_ptr] = "redirect";
508   lineno_stack[include_stack_ptr] = 0;
509   include_stack[include_stack_ptr] = YY_CURRENT_BUFFER;
510   include_stack_ptr++;
511   tmp = yy_create_string_buffer (string, strlen (string));
512   yy_switch_to_buffer (tmp);
513   BEGIN (SCRIPT);
516 /* Functions to switch to a different flex start condition,
517    saving the current start condition on `state_stack'.  */
519 static int state_stack[MAX_INCLUDE_DEPTH * 2];
520 static int *state_stack_p = state_stack;
522 void
523 ldlex_script ()
525   *(state_stack_p)++ = yy_start;
526   BEGIN (SCRIPT);
529 void
530 ldlex_mri_script ()
532   *(state_stack_p)++ = yy_start;
533   BEGIN (MRI);
536 void
537 ldlex_version_script ()
539   *(state_stack_p)++ = yy_start;
540   BEGIN (VERS_START);
543 void
544 ldlex_version_file ()
546   *(state_stack_p)++ = yy_start;
547   BEGIN (VERS_SCRIPT);
550 void
551 ldlex_defsym ()
553   *(state_stack_p)++ = yy_start;
554   BEGIN (DEFSYMEXP);
556            
557 void
558 ldlex_expression ()
560   *(state_stack_p)++ = yy_start;
561   BEGIN (EXPRESSION);
564 void
565 ldlex_both ()
567   *(state_stack_p)++ = yy_start;
568   BEGIN (BOTH);
571 void
572 ldlex_popstate ()
574   yy_start = *(--state_stack_p);
578 /* Place up to MAX_SIZE characters in BUF and return in *RESULT
579    either the number of characters read, or 0 to indicate EOF.  */
581 static void
582 yy_input (buf, result, max_size)
583      char *buf;
584      int *result;
585      int max_size;
587   *result = 0; 
588   if (yy_current_buffer->yy_input_file)
589     {
590       if (yyin)
591         {
592           *result = read (fileno (yyin), (char *) buf, max_size);
593           if (*result < 0) 
594             einfo ("%F%P: read in flex scanner failed\n");
595         }
596     }
599 /* Eat the rest of a C-style comment.  */
601 static void
602 comment ()
604   int c;
606   while (1)
607   {
608     c = input();
609     while (c != '*' && c != EOF) 
610     {
611       if (c == '\n')
612         lineno++;
613       c = input();
614     }
616     if (c == '*')
617     {
618       c = input();
619       while (c == '*')
620        c = input();
621       if (c == '/')
622        break;                   /* found the end */
623     }
625     if (c == '\n')
626       lineno++;
628     if (c == EOF)
629     {
630       einfo( "%F%P: EOF in comment\n");
631       break;
632     }
633   }
636 /* Warn the user about a garbage character WHAT in the input
637    in context WHERE.  */
639 static void
640 lex_warn_invalid (where, what)
641      char *where, *what;
643   char buf[5];
645   /* If we have found an input file whose format we do not recognize,
646      and we are therefore treating it as a linker script, and we find
647      an invalid character, then most likely this is a real object file
648      of some different format.  Treat it as such.  */
649   if (ldfile_assumed_script)
650     {
651       bfd_set_error (bfd_error_file_not_recognized);
652       einfo ("%F%s: file not recognized: %E\n", ldfile_input_filename);
653     }
655   if (! isprint ((unsigned char) *what))
656     {
657       sprintf (buf, "\\%03o", (unsigned int) *what);
658       what = buf;
659     }
661   einfo ("%P:%S: ignoring invalid character `%s'%s\n", what, where);