home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / gnu / djgpp / src / binutils.2 / ld / lexsup.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-30  |  5.4 KB  |  331 lines

  1.  
  2. /* Copyright (C) 1992 Free Software Foundation, Inc.
  3.    
  4. This file is part of GLD, the Gnu Linker.
  5.  
  6. GLD is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 1, or (at your option)
  9. any later version.
  10.  
  11. GLD is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GLD; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. /* 
  21.  * Contributed by Steve Chamberlain
  22.  *                sac@cygnus.com
  23.  */
  24.  
  25. #include "bfd.h"
  26. #include "sysdep.h"
  27. #include <ctype.h>
  28. #include <stdio.h>
  29. #include "ldlex.h"
  30. #include "ld.h"
  31. #include "ldexp.h"
  32. #include "ldgram.h"
  33. #include "ldmisc.h"
  34.  
  35. #if 0
  36. static unsigned int have_pushback;
  37. int thischar;
  38. #define NPUSHBACK 10
  39. extern char *ldfile_input_filename;
  40. extern int donehash ;
  41. int pushback[NPUSHBACK];
  42. FILE *ldlex_input_stack;
  43. unsigned int lineno;
  44.  
  45. char *buystring();
  46.  
  47. extern int ldgram_in_defsym;
  48. extern int ldgram_had_equals;
  49. extern int ldgram_in_script;
  50. int debug;
  51.  
  52. extern char yytext[];
  53. extern YYSTYPE yylval;
  54. extern int yyleng;
  55.  
  56. typedef struct {
  57.     char *name;    
  58. int value;
  59. } keyword_type;
  60. #define RTOKEN(x)  {  yylval.token = x; return x; }
  61. keyword_type keywords[] = 
  62. {
  63. "/", '/',
  64. "MEMORY",MEMORY,
  65. "ORIGIN",ORIGIN,
  66. "BLOCK",BLOCK,
  67. "LENGTH",LENGTH,
  68. "ALIGN",ALIGN_K,
  69. "ADDR",ADDR,
  70. "ENTRY",ENTRY,
  71. "NEXT",NEXT,
  72. "sizeof_headers",SIZEOF_HEADERS,
  73. "SIZEOF_HEADERS",SIZEOF_HEADERS,
  74. "MAP",MAP,
  75. "SIZEOF",SIZEOF,
  76. "TARGET",TARGET_K,
  77. "SEARCH_DIR",SEARCH_DIR,
  78. "OUTPUT",OUTPUT,
  79. "INPUT",INPUT,
  80. "DEFINED",DEFINED,
  81. "CREATE_OBJECT_SYMBOLS",CREATE_OBJECT_SYMBOLS,
  82. "CONSTRUCTORS", CONSTRUCTORS,
  83. "FORCE_COMMON_ALLOCATION",FORCE_COMMON_ALLOCATION,
  84. "SECTIONS",SECTIONS,
  85. "FILL",FILL,
  86. "STARTUP",STARTUP,
  87. "OUTPUT_FORMAT",OUTPUT_FORMAT,
  88. "OUTPUT_ARCH", OUTPUT_ARCH,
  89. "HLL",HLL,
  90. "SYSLIB",SYSLIB,
  91. "FLOAT",FLOAT,
  92. "LONG", LONG,
  93. "SHORT", SHORT,
  94. "BYTE", BYTE,
  95. "NOFLOAT",NOFLOAT,
  96.  
  97. "NOLOAD",NOLOAD,
  98. "DSECT",DSECT,
  99. "COPY",COPY,
  100. "INFO",INFO,
  101. "OVERLAY",OVERLAY,
  102.  
  103. "o",ORIGIN,
  104. "org",ORIGIN,
  105. "l", LENGTH,
  106. "len", LENGTH,
  107. 0,0};
  108.  
  109. int
  110. lex_input()
  111. {
  112.   if (have_pushback > 0) 
  113.       {
  114.     have_pushback --;
  115.     return thischar = pushback[have_pushback];
  116.       }
  117.   if (ldlex_input_stack) {
  118.     thischar = getc(ldlex_input_stack);
  119.  
  120.     if (thischar == EOF)  {
  121.       fclose(ldlex_input_stack);
  122.       ldlex_input_stack = (FILE *)NULL;
  123.       ldfile_input_filename = (char *)NULL;
  124.       /* First char after script eof is a @ so that we can tell the grammer
  125.      that we've left */
  126.       thischar = '@';
  127.  
  128.     }
  129.   }
  130.   else if (command_line && *command_line)  {
  131.     thischar = *(command_line++);
  132.   }
  133.   else {
  134.  thischar = 0;
  135.   }
  136.   if(thischar == '\t') thischar = ' ';
  137.   if (thischar == '\n') { lineno++; }
  138.   return thischar ;
  139. }
  140.  
  141. void
  142. lex_unput(c)
  143. int c;
  144. {
  145.   if (have_pushback > NPUSHBACK) {
  146.     info("%F%P Too many pushbacks\n");
  147.   }
  148.  
  149.   pushback[have_pushback] = c;
  150.   have_pushback ++;
  151. }
  152.  
  153.  
  154.     int
  155. yywrap()
  156.      { return 1; }
  157. /*VARARGS*/
  158.  
  159. #if 0
  160. void
  161. allprint(x) 
  162. int x;
  163. {
  164. fprintf(yyout,"%d",x);
  165. }
  166.  
  167. void
  168. sprint(x) 
  169. char *x;
  170. {
  171. fprintf(yyout,"%s",x);
  172. }
  173. #endif
  174. int  thischar;
  175.  
  176.  
  177.  
  178. void
  179. parse_args(ac, av)
  180. int ac;
  181. char **av;
  182. {
  183.   char *p;
  184.   int i;
  185.   size_t size = 0;
  186.   char *dst;
  187.   debug = 1;
  188.   for (i= 1; i < ac; i++) {
  189.     size += strlen(av[i]) + 2; 
  190.   }
  191.   dst = p = (char *)ldmalloc(size + 2);
  192. /* Put a space arount each option */
  193.  
  194.  
  195.   for (i =1; i < ac; i++) {
  196.  
  197.     unsigned int s = strlen(av[i]);
  198.   *dst++ = ' ';
  199.     memcpy(dst, av[i], s);
  200.     dst[s] = ' ';
  201.     dst += s + 1;
  202.   }
  203.   *dst    = 0;
  204.   parse_line(p,0);
  205.  
  206.   free(p);
  207.  
  208.  
  209. }
  210.  
  211. static long 
  212. DEFUN(number,(default_if_zero,base),
  213.       int default_if_zero AND
  214.       int base)
  215. {
  216.   unsigned  long l = 0;
  217.   int ch = yytext[0];
  218.   if (ch == 0) {
  219.       base = default_if_zero;
  220.     }
  221.   while (1) {
  222.       switch (ch) {
  223.     case 'x':
  224.       base = 16;
  225.       break;
  226.     case 'k':
  227.     case 'K':
  228.       l =l * 1024;
  229.       break;
  230.     case 'm':
  231.     case 'M':
  232.       l =l * 1024 * 1024;
  233.       break;
  234.     case '0': case '1': case '2': case '3': case '4':
  235.     case '5': case '6': case '7': case '8': case '9':
  236.       l = l * base + ch - '0';
  237.       break;
  238.     case 'a': case 'b': case 'c' : case 'd' : case 'e': case 'f':
  239.       l =l *base + ch - 'a' + 10;
  240.       break;
  241.     case 'A': case 'B': case 'C' : case 'D' : case 'E': case 'F':
  242.       l =l *base + ch - 'A' + 10;
  243.       break;
  244.     default:
  245.       lex_unput(ch);
  246.       yylval.integer = l;
  247.       return INT;
  248.     }
  249.       ch = lex_input();
  250.     }
  251. }
  252.  
  253. int inquote()
  254. {
  255.   
  256.  
  257.   yylval.name = buystring(yytext+1);
  258.   yylval.name[yyleng-2] = 0; /* Fry final quote */
  259.   return NAME;
  260. }
  261.  
  262. void
  263. incomment()
  264. {
  265.   while (1) 
  266.   {
  267.     int ch;
  268.     ch = lex_input();
  269.     while (ch != '*') 
  270.     {
  271.       ch = lex_input();
  272.     }
  273.  
  274.  
  275.  
  276.     if (lex_input() == '/') {
  277.     break;
  278.       }
  279.     lex_unput(yytext[yyleng-1]);
  280.   }
  281. }
  282. #endif
  283.  
  284. void parse_line(arg, script)
  285. char *arg;
  286. {
  287.  
  288.   lex_redirect(arg);
  289.   if (script)
  290.    ldlex_script();
  291.   
  292.   yyparse();
  293. }
  294.  
  295. int debug;
  296.  
  297. void
  298. parse_args(ac, av)
  299. int ac;
  300. char **av;
  301. {
  302.   char *p;
  303.   int i;
  304.   size_t size = 0;
  305.   char *dst;
  306.   debug = 1;
  307.   for (i= 1; i < ac; i++) {
  308.       size += strlen(av[i]) + 2; 
  309.     }
  310.   dst = p = (char *)ldmalloc(size + 2);
  311.   /* Put a space arount each option */
  312.  
  313.  
  314.   for (i =1; i < ac; i++) {
  315.  
  316.       unsigned int s = strlen(av[i]);
  317.       *dst++ = ' ';
  318.       memcpy(dst, av[i], s);
  319.       dst[s] = ' ';
  320.       dst += s + 1;
  321.     }
  322.   *dst    = 0;
  323.   parse_line(p,0);
  324.  
  325.   free(p);
  326.  
  327.  
  328. }
  329.  
  330.  
  331.