add -warn-common option
[external/binutils.git] / ld / ldlex.l
1 %{
2
3 /* Copyright (C) 1991 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, 675 Mass Ave, Cambridge, MA 02139, USA.  */
20
21 /*
22 This was written by steve chamberlain
23                     sac@cygnus.com
24 */
25
26
27 #include <ansidecl.h>
28 #include "bfd.h"
29 #include "ldgram.h"
30
31 int ldgram_in_defsym;
32 extern int ldgram_had_equals;
33 extern int ldgram_in_script;
34
35 int hex_mode;
36 extern int fgetc();
37 extern int yyparse();
38
39
40
41 char *buystring();
42
43 unsigned int lineno = 1;
44 int old;
45
46 static comment();
47
48 #undef YY_INPUT
49 #define YY_INPUT(buf,result,max_size) yy_input(buf, &result, max_size)
50 #undef YY_FATAL_ERROR
51 #define YY_FATAL_ERROR ;
52 #define MAX_INCLUDE_DEPTH 10
53 YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
54 char *file_name_stack[MAX_INCLUDE_DEPTH];
55 unsigned int include_stack_ptr = 0;
56
57
58 /* STATES 
59         COMMAND         on command line
60         COMMENT         in a C comment
61         EXPRESSION      definiatelyt in an expression
62         SCRIPT          definately in a script
63         SOMEWHERE       either EXPRESSION or SCRIPT
64         MRI             in an MRI script
65 */
66 #define RTOKEN(x)  {  yylval.token = x; return x; }
67 %}
68
69 %a 4000
70 %o 5000
71
72 CMDFILENAMECHAR   [_a-zA-Z0-9\/\.\\_\+\$\:\[\]\\\,\=\&\!\<\>\-\~]
73 CMDFILENAMECHAR1  [_a-zA-Z0-9\/\.\\_\+\$\:\[\]\\\,\=\&\!\<\>\~]
74 FILENAMECHAR1   [_a-zA-Z\/\.\\\$\_\~]
75 SYMBOLCHARN     [_a-zA-Z\/\.\\0-9]
76 FILENAMECHAR    [_a-zA-Z0-9\/\.\-\_\+\=\$\:\[\]\\\,\~]
77 FILENAME        {FILENAMECHAR}+
78 WHITE           [ \t\n]+ 
79
80 NOCFILENAMECHAR [_a-zA-Z0-9\/\.\-\_\+\$\:\[\]\\\~]
81
82
83 %s COMMAND
84 %s SCRIPT
85 %s EXPRESSION
86 %s COMMENT
87 %s BOTH
88 %s DEFSYMEXP
89 %s MRI
90 %%
91
92
93 <BOTH,SCRIPT,EXPRESSION,COMMAND>"/*"    { comment(); }
94
95
96 <DEFSYMEXP>"-"                  { RTOKEN('-');}
97 <DEFSYMEXP>"+"                  { RTOKEN('+');}
98 <DEFSYMEXP>{FILENAMECHAR1}{SYMBOLCHARN}*   { yylval.name = buystring(yytext); return NAME; }
99 <DEFSYMEXP>[ \t]                { RTOKEN(DEFSYMEND); }
100 <DEFSYMEXP>"="                  { RTOKEN('='); }
101 <COMMAND>"--help"               { return OPTION_help; }
102 <COMMAND>"--version"            { return OPTION_version; }
103 <COMMAND>"-defsym"{WHITE}*      { return OPTION_defsym; }
104 <COMMAND>"-format"              { return OPTION_format; }
105 <COMMAND>"-noinhibit-exec"      { return OPTION_noinhibit_exec; }
106 <COMMAND>"-noinhibit_exec"      { return OPTION_noinhibit_exec; }
107 <COMMAND>"-oformat"             { return OPTION_oformat; }
108 <COMMAND>"-sort-common"         { return OPTION_sort_common;}
109 <COMMAND>"-sort_common"         { return OPTION_sort_common;}
110 <COMMAND>"-warn-common"         { return OPTION_warn_common;}
111 <COMMAND>"-n"                   { return OPTION_n; }
112 <COMMAND>"-N"                   { return OPTION_N; }
113 <COMMAND>"-r"                   { return OPTION_r; }
114 <COMMAND>"-relax"               { return OPTION_relax; }
115 <COMMAND>"-i"                   { return OPTION_r; }
116 <COMMAND>"-Ur"                  { return OPTION_Ur; }
117 <COMMAND>"-o"                   { return OPTION_o; }
118 <COMMAND>"-g"                   { return OPTION_g; }
119 <COMMAND>"-e"                   { return OPTION_e; }
120 <COMMAND>"-b"                   { return OPTION_b; }
121 <COMMAND>"-dc"                  { return OPTION_dc; }
122 <COMMAND>"-dp"                  { return OPTION_dp; }
123 <COMMAND>"-d"                   { return OPTION_d; }
124 <COMMAND>"-v"                   { return OPTION_v; }
125 <COMMAND>"-V"                   { return OPTION_V; }
126 <COMMAND>"-m"                   { return OPTION_m; }
127 <COMMAND>"-m"{FILENAME}         { return OPTION_memul; }
128 <COMMAND>"-M"                   { return OPTION_M; }
129 <COMMAND>"-Map"                 { return OPTION_Map;}
130 <COMMAND>"-t"                   { return OPTION_t; }
131 <COMMAND>"-X"                   { return OPTION_X; }
132 <COMMAND>"-x"                   { return OPTION_x; }
133 <COMMAND>"-c"                   { return OPTION_c; }
134 <COMMAND>"-R"                   { return OPTION_R; }
135 <COMMAND>"-u"                   { return OPTION_u; }
136 <COMMAND>"-s"                   { return OPTION_s; }
137 <COMMAND>"-S"                   { return OPTION_S; }
138 <COMMAND>"-Bstat"               { return OPTION_Bstatic; }
139 <COMMAND>"-B"{FILENAME}         { /* Ignored */ }
140 <COMMAND>"-l"{FILENAME}         {
141                                         yylval.name = buystring(yytext+2);
142                                         return OPTION_l; 
143                                 }
144
145 <COMMAND>"-L"{FILENAME}         { 
146                                         yylval.name = buystring(yytext+2);
147                                         return OPTION_Lfile;
148                                 }
149 <COMMAND>"-L"                   { return OPTION_L; }
150 <COMMAND>"-Ttext"               {
151                                  yylval.name = ".text";
152                                  return OPTION_Texp;
153                                 }
154 <COMMAND>"-Tdata"               {
155                                  yylval.name = ".data";
156                                  return OPTION_Texp;
157                                }
158 <COMMAND>"-Tbss"                {
159                                  yylval.name = ".bss";
160                                  return OPTION_Texp;
161                                }
162 <COMMAND>"-O"{FILENAME}         {
163                                 yylval.name = buystring(yytext+2);
164                                 return OPTION_Texp;
165                                 }
166
167 <COMMAND>"-T"{FILENAME}         {
168                                  yylval.name = buystring(yytext+2);
169                                  return OPTION_Tfile;
170                                }
171 <COMMAND>"-T"                   {
172                                  return OPTION_T;
173                                }
174
175 <COMMAND>"-F"{FILENAME}         {
176                                  return OPTION_F;
177                                }
178 <COMMAND>"-F"                   {
179                                  return OPTION_F;
180                                }
181
182 <COMMAND>"-y"{FILENAME}         {
183                                         yylval.name = buystring(yytext+2);
184                                         return OPTION_y;
185                                 }
186                                 
187 <COMMAND>"-A"{FILENAME}         {
188                                         yylval.name = buystring(yytext+2);
189                                         return OPTION_Aarch;
190                                 }
191
192 <COMMAND>"-retain-symbols-file" { return OPTION_RETAIN_SYMBOLS_FILE; }
193
194 <COMMAND>"-EB"                  {
195                                         return OPTION_EB;
196                                 }
197 <COMMAND>"-EL"                  {
198                                         return OPTION_EL;
199                                 }
200 <COMMAND>"-G"                   {
201                                         return OPTION_G;
202                                 }
203 <COMMAND>"-G"([0-9])+           {
204                                         yylval.integer = atoi (yytext + 2);
205                                         return OPTION_Gval;
206                                 }
207
208 <COMMAND>"-Qy"                  {       return OPTION_Qy; }
209 <COMMAND>"-dn"                  {       return OPTION_dn; }
210 <COMMAND>"-Y"                   {       return OPTION_Y;  }
211 <COMMAND>"-YP,"{FILENAME}       {
212                                         yylval.name = buystring (yytext+4);
213                                         return OPTION_YP;
214                                 }
215
216 <MRI,EXPRESSION>"$"([0-9A-Fa-f])+ {
217                                 yylval.integer = strtoul(yytext+1, 0,16);
218                                 return INT;
219                         }
220
221 <MRI,EXPRESSION>([0-9A-Fa-f])+(H|X|B|O|D) {
222                                    int base ;
223                                    switch (yytext[yyleng-1]) {
224                                     case 'X': 
225                                     case 'H':
226                                      base = 16;
227                                      break;
228                                     case 'O':
229                                      base = 8;
230                                      break;
231                                     case 'B':
232                                      base = 2;
233                                      break;
234                                     default:
235                                      base = 10;
236                                    }
237                                    yylval.integer = strtoul(yytext+1, 0, base); 
238                                    return INT;
239                                  }
240 <SCRIPT,DEFSYMEXP,MRI,BOTH,EXPRESSION>"$"?"0x"?([0-9A-Fa-f])+(M|K|m|k)? {
241                                   yylval.integer = strtoul(yytext,0,hex_mode);
242                                   if (yytext[yyleng-1]=='M'
243                                         || yytext[yyleng-1] == 'm') {
244                                       yylval.integer *= 1024*1024;
245                                     }   
246                                   if (yytext[yyleng-1]=='K' 
247                                 || yytext[yyleng-1]=='k') {
248                                       yylval.integer *= 1024;
249                                     }           
250                                   return INT;
251                                 }
252 <BOTH,SCRIPT,EXPRESSION>"]"             { RTOKEN(']');}
253 <BOTH,SCRIPT,EXPRESSION>"["             { RTOKEN('[');}
254 <BOTH,SCRIPT,EXPRESSION>"<<="   { RTOKEN(LSHIFTEQ);}
255 <BOTH,SCRIPT,EXPRESSION>">>="   { RTOKEN(RSHIFTEQ);}
256 <BOTH,SCRIPT,EXPRESSION>"||"    { RTOKEN(OROR);}
257 <BOTH,SCRIPT,EXPRESSION>"=="    { RTOKEN(EQ);}
258 <BOTH,SCRIPT,EXPRESSION>"!="    { RTOKEN(NE);}
259 <BOTH,SCRIPT,EXPRESSION>">="    { RTOKEN(GE);}
260 <BOTH,SCRIPT,EXPRESSION>"<="    { RTOKEN(LE);}
261 <BOTH,SCRIPT,EXPRESSION>"<<"    { RTOKEN(LSHIFT);}
262 <BOTH,SCRIPT,EXPRESSION>">>"    { RTOKEN(RSHIFT);}
263 <BOTH,SCRIPT,EXPRESSION>"+="    { RTOKEN(PLUSEQ);}
264 <BOTH,SCRIPT,EXPRESSION>"-="    { RTOKEN(MINUSEQ);}
265 <BOTH,SCRIPT,EXPRESSION>"*="    { RTOKEN(MULTEQ);}
266 <BOTH,SCRIPT,EXPRESSION>"/="    { RTOKEN(DIVEQ);}
267 <BOTH,SCRIPT,EXPRESSION>"&="    { RTOKEN(ANDEQ);}
268 <BOTH,SCRIPT,EXPRESSION>"|="    { RTOKEN(OREQ);}
269 <BOTH,SCRIPT,EXPRESSION>"&&"    { RTOKEN(ANDAND);}
270 <BOTH,SCRIPT,EXPRESSION>">"             { RTOKEN('>');}
271 <MRI,BOTH,SCRIPT,EXPRESSION>","         { RTOKEN(',');}
272 <BOTH,SCRIPT,EXPRESSION>"&"             { RTOKEN('&');}
273 <BOTH,SCRIPT,EXPRESSION>"|"             { RTOKEN('|');}
274 <BOTH,SCRIPT,EXPRESSION>"~"             { RTOKEN('~');}
275 <BOTH,SCRIPT,EXPRESSION>"!"             { RTOKEN('!');}
276 <BOTH,SCRIPT,EXPRESSION>"?"             { RTOKEN('?');}
277 <BOTH,SCRIPT,EXPRESSION>"*"             { RTOKEN('*');}
278 <BOTH,SCRIPT,EXPRESSION>"+"             { RTOKEN('+');}
279 <BOTH,SCRIPT,EXPRESSION>"-"             { RTOKEN('-');}
280 <BOTH,SCRIPT,EXPRESSION>"/"             { RTOKEN('/');}
281 <BOTH,SCRIPT,EXPRESSION>"%"             { RTOKEN('%');}
282 <BOTH,SCRIPT,EXPRESSION>"<"             { RTOKEN('<');}
283 <BOTH,SCRIPT,EXPRESSION>">"             { RTOKEN('>');}
284 <MRI,BOTH,SCRIPT,EXPRESSION>"="          { RTOKEN('=');}
285 <BOTH,SCRIPT,EXPRESSION>"}"                     { RTOKEN('}') ; }
286 <BOTH,SCRIPT,EXPRESSION>"{"                     { RTOKEN('{'); }
287 <BOTH,SCRIPT,EXPRESSION>")"                     { RTOKEN(')');}
288 <BOTH,SCRIPT,EXPRESSION>"("                     { RTOKEN('(');}
289 <BOTH,SCRIPT,EXPRESSION>"]"             { RTOKEN(']');}
290 <BOTH,SCRIPT,EXPRESSION>"["             { RTOKEN('[');}
291 <BOTH,SCRIPT,EXPRESSION>":"             { RTOKEN(':'); }
292 <BOTH,SCRIPT,EXPRESSION>";"             { RTOKEN(';');}
293 <BOTH,SCRIPT,EXPRESSION>"-"             { RTOKEN('-');}
294 <BOTH,SCRIPT,EXPRESSION>"/"             { RTOKEN('/');}
295 <BOTH,SCRIPT>"MEMORY"           { RTOKEN(MEMORY);}
296 <BOTH,SCRIPT>"ORIGIN"           { RTOKEN(ORIGIN);}
297 <BOTH,SCRIPT>"BLOCK"                    { RTOKEN(BLOCK);}
298 <BOTH,SCRIPT>"LENGTH"           { RTOKEN(LENGTH);}
299 <EXPRESSION,BOTH,SCRIPT>"ALIGN"                 { RTOKEN(ALIGN_K);}
300 <EXPRESSION,BOTH,SCRIPT>"ADDR"                  { RTOKEN(ADDR);}
301 <BOTH,SCRIPT>"ENTRY"                    { RTOKEN(ENTRY);}
302 <EXPRESSION,BOTH,SCRIPT>"NEXT"                  { RTOKEN(NEXT);}
303 <EXPRESSION,BOTH,SCRIPT>"sizeof_headers"        { RTOKEN(SIZEOF_HEADERS);}
304 <EXPRESSION,BOTH,SCRIPT>"SIZEOF_HEADERS"        { RTOKEN(SIZEOF_HEADERS);}
305 <BOTH,SCRIPT>"MAP"                      { RTOKEN(MAP);}
306 <EXPRESSION,BOTH,SCRIPT>"SIZEOF"                { RTOKEN(SIZEOF);}
307 <BOTH,SCRIPT>"TARGET"           { RTOKEN(TARGET_K);}
308 <BOTH,SCRIPT>"SEARCH_DIR"               { RTOKEN(SEARCH_DIR);}
309 <BOTH,SCRIPT>"OUTPUT"           { RTOKEN(OUTPUT);}
310 <BOTH,SCRIPT>"INPUT"                    { RTOKEN(INPUT);}
311 <EXPRESSION,BOTH,SCRIPT>"DEFINED"               { RTOKEN(DEFINED);}
312 <BOTH,SCRIPT>"CREATE_OBJECT_SYMBOLS"    { RTOKEN(CREATE_OBJECT_SYMBOLS);}
313 <BOTH,SCRIPT>"CONSTRUCTORS"             { RTOKEN( CONSTRUCTORS);}
314 <BOTH,SCRIPT>"FORCE_COMMON_ALLOCATION" { RTOKEN(FORCE_COMMON_ALLOCATION);}
315 <BOTH,SCRIPT>"SECTIONS"         { RTOKEN(SECTIONS);}
316 <BOTH,SCRIPT>"FILL"                     { RTOKEN(FILL);}
317 <BOTH,SCRIPT>"STARTUP"          { RTOKEN(STARTUP);}
318 <BOTH,SCRIPT>"OUTPUT_FORMAT"            { RTOKEN(OUTPUT_FORMAT);}
319 <BOTH,SCRIPT>"OUTPUT_ARCH"              { RTOKEN( OUTPUT_ARCH);}
320 <BOTH,SCRIPT>"HLL"                      { RTOKEN(HLL);}
321 <BOTH,SCRIPT>"SYSLIB"           { RTOKEN(SYSLIB);}
322 <BOTH,SCRIPT>"FLOAT"                    { RTOKEN(FLOAT);}
323 <BOTH,SCRIPT>"LONG"                     { RTOKEN( LONG);}
324 <BOTH,SCRIPT>"SHORT"                    { RTOKEN( SHORT);}
325 <BOTH,SCRIPT>"BYTE"                     { RTOKEN( BYTE);}
326 <BOTH,SCRIPT>"NOFLOAT"          { RTOKEN(NOFLOAT);}
327 <EXPRESSION,BOTH,SCRIPT>"NOLOAD"                { RTOKEN(NOLOAD);}
328 <BOTH,SCRIPT>"DSECT"                    { RTOKEN(DSECT);}
329 <BOTH,SCRIPT>"COPY"                     { RTOKEN(COPY);}
330 <BOTH,SCRIPT>"INFO"                     { RTOKEN(INFO);}
331 <BOTH,SCRIPT>"OVERLAY"          { RTOKEN(OVERLAY);}
332 <BOTH,SCRIPT>"o"                        { RTOKEN(ORIGIN);}
333 <BOTH,SCRIPT>"org"                      { RTOKEN(ORIGIN);}
334 <BOTH,SCRIPT>"l"                        { RTOKEN( LENGTH);}
335 <BOTH,SCRIPT>"len"                      { RTOKEN( LENGTH);}
336 <BOTH,SCRIPT>"INCLUDE"                  { RTOKEN(INCLUDE);}
337 <EXPRESSION,BOTH,SCRIPT>"AT"                    { RTOKEN(AT);}
338 <MRI>"\n"                       { ++ lineno;  RTOKEN(NEWLINE); }
339 <MRI>"*".*                      { /* Mri comment line */ }
340 <MRI>"END"                      { RTOKEN(ENDWORD); }
341 <MRI>"ALIGNMOD"         { RTOKEN(ALIGNMOD);}
342 <MRI>"ALIGN"            { RTOKEN(ALIGN_K);}
343
344 <MRI>"CHIP"                     { RTOKEN(CHIP); }
345 <MRI>"BASE"                     { RTOKEN(BASE); }
346 <MRI>"ALIAS"                     { RTOKEN(ALIAS); }
347 <MRI>"TRUNCATE"                     { RTOKEN(TRUNCATE); }
348 <MRI>"LOAD"                     { RTOKEN(LOAD); }
349 <MRI>"PUBLIC"                   { RTOKEN(PUBLIC); }
350 <MRI>"ORDER"                    { RTOKEN(ORDER); }
351 <MRI>"NAME"                     { RTOKEN(NAMEWORD); }
352 <MRI>"FORMAT"                   { RTOKEN(FORMAT); }
353 <MRI>"LIST".*                   { RTOKEN(LIST); /* LIST and ignore to end of line */ }
354 <MRI>"SECT"                     { RTOKEN(SECT); }
355 <EXPRESSION,BOTH,SCRIPT,MRI>"ABSOLUTE"                  { RTOKEN(ABSOLUTE); }
356 <MRI>"end"                      { RTOKEN(ENDWORD); }
357 <MRI>"chip"                     { RTOKEN(CHIP); }
358 <MRI>"load"                     { RTOKEN(LOAD); }
359 <MRI>"order"                    { RTOKEN(ORDER); }
360 <MRI>"name"                     { RTOKEN(NAMEWORD); }
361 <MRI>"format"                   { RTOKEN(FORMAT); }
362 <MRI>"list".*                   { RTOKEN(LIST); /* LIST and ignore to end of line */ }
363 <MRI>"sect"                     { RTOKEN(SECT); }
364 <EXPRESSION,BOTH,SCRIPT,MRI>"absolute"                  { RTOKEN(ABSOLUTE); }
365
366 <COMMAND>{CMDFILENAMECHAR1}{CMDFILENAMECHAR}*   {
367                                  yylval.name = buystring(yytext); 
368                                   return NAME;
369                                 }
370
371
372 <MRI>{FILENAMECHAR1}{NOCFILENAMECHAR}*  {
373 /* Filename without commas, needed to parse mri stuff */
374                                  yylval.name = buystring(yytext); 
375                                   return NAME;
376                                 }
377
378
379 <BOTH,EXPRESSION>{FILENAMECHAR1}{FILENAMECHAR}* {
380                                  yylval.name = buystring(yytext); 
381                                   return NAME;
382                                 }
383 <SCRIPT,COMMAND>{FILENAMECHAR}* { yylval.name = buystring(yytext); 
384                                   return NAME;
385                                 }
386
387 <EXPRESSION,BOTH,COMMAND,SCRIPT>"\""[^\"]*"\"" {
388                                         /* No matter the state, quotes
389                                            give what's inside */
390                                         yylval.name = buystring(yytext+1);
391                                         yylval.name[yyleng-2] = 0;
392                                         return NAME;
393                                 }
394 <BOTH,SCRIPT,EXPRESSION>"\n"            { lineno++;}
395 <MRI,COMMAND,BOTH,SCRIPT,EXPRESSION>[ \t]
396
397 <<EOF>> {
398   extern char *ldfile_input_filename;
399   include_stack_ptr--;
400     
401   if (include_stack_ptr == 0) 
402   {
403     yyterminate();
404   }
405   else 
406   {
407     yy_switch_to_buffer(include_stack[include_stack_ptr]);
408
409   }
410   if (include_stack_ptr==1) 
411   {
412     BEGIN(COMMAND);
413   }
414   else 
415   {
416     BEGIN(SCRIPT);
417     ldfile_input_filename = file_name_stack[include_stack_ptr-1];
418   }
419
420   return END;
421 }
422     
423 %%
424
425 void
426 lex_push_file (file, name)
427      FILE *file;
428      char *name;
429 {
430   if (include_stack_ptr >= MAX_INCLUDE_DEPTH) 
431   {
432     einfo("%F:includes nested too deeply");
433   }
434   file_name_stack[include_stack_ptr] = name;
435   include_stack[include_stack_ptr] = YY_CURRENT_BUFFER;
436
437   include_stack_ptr++;
438   yyin = file;
439   yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
440
441   BEGIN(SCRIPT);
442 }
443
444 YY_BUFFER_STATE 
445 yy_create_string_buffer (string,  size)
446      CONST char *string;
447      int size;
448 {
449   YY_BUFFER_STATE b;
450
451   b = (YY_BUFFER_STATE) malloc( sizeof( struct yy_buffer_state ) );
452   b->yy_input_file = 0;
453   
454   if ( ! b )
455    YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
456
457   b->yy_buf_size = size;
458
459   /* yy_ch_buf has to be 2 characters longer than the size given because
460    * we need to put in 2 end-of-buffer characters.
461    */
462   b->yy_ch_buf = (YY_CHAR *) malloc( (unsigned) (b->yy_buf_size + 3) );
463
464   if ( ! b->yy_ch_buf )
465    YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
466
467
468   b->yy_ch_buf[0] = '\n';
469   strcpy(b->yy_ch_buf+1,  string);
470   b->yy_ch_buf[size+1] = YY_END_OF_BUFFER_CHAR;
471   b->yy_ch_buf[size+2] = YY_END_OF_BUFFER_CHAR;
472     b->yy_n_chars = size+1;
473   b->yy_buf_pos = &b->yy_ch_buf[1];
474
475   b->yy_eof_status = EOF_NOT_SEEN;
476
477   return ( b );
478 }
479
480
481
482 void
483 lex_redirect (string)
484      CONST  char *string;
485 {
486   YY_BUFFER_STATE tmp;
487
488   int len = strlen(string);
489   yy_init = 0  ;  
490   if (include_stack_ptr >= MAX_INCLUDE_DEPTH) 
491   {
492     einfo("%F: macros nested too deeply");
493   }
494   file_name_stack[include_stack_ptr] = "redirect";
495   include_stack[include_stack_ptr] = YY_CURRENT_BUFFER;
496   include_stack_ptr++;
497   tmp =   yy_create_string_buffer(string, len);
498   
499   yy_switch_to_buffer(tmp);
500   BEGIN(COMMAND);
501   yyout = stdout;
502 }
503
504 int state_stack[20];
505 int *state_stack_p = state_stack;
506
507 void
508 ldlex_script ()
509 {
510   *(state_stack_p)++ = yy_start;
511
512   BEGIN(SCRIPT);
513 }
514
515
516 void
517 ldlex_mri_script ()
518 {
519   *(state_stack_p)++ = yy_start;
520   BEGIN(MRI);
521 }
522
523 void
524 ldlex_defsym ()
525 {
526   *(state_stack_p)++ = yy_start;
527   BEGIN(DEFSYMEXP);
528 }
529            
530 void
531 ldlex_expression ()
532 {
533   *(state_stack_p)++ = yy_start;
534   BEGIN(EXPRESSION);
535
536 }
537 void
538 ldlex_both ()
539 {
540   *(state_stack_p)++ = yy_start;
541   BEGIN(BOTH);
542 }
543 void
544 ldlex_command ()
545 {
546   *(state_stack_p)++ = yy_start;
547   BEGIN(COMMAND);
548 }
549
550 void
551 ldlex_popstate ()
552 {
553   yy_start = *(--state_stack_p);
554 }
555
556 yy_input(buf, result, max_size)
557 char *buf;
558 int *result;
559 int max_size;
560 {
561   *result = 0; 
562   if (yy_current_buffer->yy_input_file)
563   {
564     if (yyin)
565      if ( (*result = read( fileno(yyin), (char *) buf, max_size )) < 0 ) 
566       YY_FATAL_ERROR( "read() in flex scanner failed" );
567   }
568 }
569
570 static
571 comment()
572 {
573   int c;
574   while (1)
575   {
576     c = input();
577     while (c !='*' && c != EOF) 
578     {
579       if (c == '\n') lineno++;
580       c = input();
581     }
582
583
584     if (c == '*')
585     {
586       c = input();
587       while ( c == '*')
588        c = input();
589       if ( c == '/' )
590        break;                   /* found the end */
591     }
592
593     if ( c == EOF )
594     {
595       einfo( "%F%P :EOF in comment");
596       break;
597     }
598   }
599 }