lexsup.c

来自「基于4个mips核的noc设计」· C语言 代码 · 共 1,283 行 · 第 1/3 页

C
1,283
字号
{  unsigned i;  int is, il, irl;  int ingroup = 0;  char *default_dirlist = NULL;  char shortopts[OPTION_COUNT * 3 + 2];  struct option longopts[OPTION_COUNT + 1];  struct option really_longopts[OPTION_COUNT + 1];  int last_optind;  /* Starting the short option string with '-' is for programs that     expect options and other ARGV-elements in any order and that care about     the ordering of the two.  We describe each non-option ARGV-element     as if it were the argument of an option with character code 1.  */  shortopts[0] = '-';  is = 1;  il = 0;  irl = 0;  for (i = 0; i < OPTION_COUNT; i++)    {      if (ld_options[i].shortopt != '\0')	{	  shortopts[is] = ld_options[i].shortopt;	  ++is;	  if (ld_options[i].opt.has_arg == required_argument	      || ld_options[i].opt.has_arg == optional_argument)	    {	      shortopts[is] = ':';	      ++is;	      if (ld_options[i].opt.has_arg == optional_argument)		{		  shortopts[is] = ':';		  ++is;		}	    }	}      if (ld_options[i].opt.name != NULL)	{	  if (ld_options[i].control == EXACTLY_TWO_DASHES)	    {	      really_longopts[irl] = ld_options[i].opt;	      ++irl;	    }	  else	    {	      longopts[il] = ld_options[i].opt;	      ++il;	    }	}    }  shortopts[is] = '\0';  longopts[il].name = NULL;  really_longopts[irl].name = NULL;  /* The -G option is ambiguous on different platforms.  Sometimes it     specifies the largest data size to put into the small data     section.  Sometimes it is equivalent to --shared.  Unfortunately,     the first form takes an argument, while the second does not.     We need to permit the --shared form because on some platforms,     such as Solaris, gcc -shared will pass -G to the linker.     To permit either usage, we look through the argument list.  If we     find -G not followed by a number, we change it into --shared.     This will work for most normal cases.  */  for (i = 1; i < argc; i++)    if (strcmp (argv[i], "-G") == 0	&& (i + 1 >= argc	    || ! isdigit ((unsigned char) argv[i + 1][0])))      argv[i] = (char *) "--shared";  /* Because we permit long options to start with a single dash, and     we have a --library option, and the -l option is conventionally     used with an immediately following argument, we can have bad     results if somebody tries to use -l with a library whose name     happens to start with "ibrary", as in -li.  We avoid problems by     simply turning -l into --library.  This means that users will     have to use two dashes in order to use --library, which is OK     since that's how it is documented.     FIXME: It's possible that this problem can arise for other short     options as well, although the user does always have the recourse     of adding a space between the option and the argument.  */  for (i = 1; i < argc; i++)    {      if (argv[i][0] == '-'	  && argv[i][1] == 'l'	  && argv[i][2] != '\0')	{	  char *n;	  n = (char *) xmalloc (strlen (argv[i]) + 20);	  sprintf (n, "--library=%s", argv[i] + 2);	  argv[i] = n;	}    }  last_optind = -1;  while (1)    {      int longind;      int optc;      /* Using last_optind lets us avoid calling ldemul_parse_args	 multiple times on a single option, which would lead to	 confusion in the internal static variables maintained by	 getopt.  This could otherwise happen for an argument like	 -nx, in which the -n is parsed as a single option, and we	 loop around to pick up the -x.  */      if (optind != last_optind)	{	  if (ldemul_parse_args (argc, argv))	    continue;	  last_optind = optind;	}      /* getopt_long_only is like getopt_long, but '-' as well as '--'	 can indicate a long option.  */      opterr = 0;      optc = getopt_long_only (argc, argv, shortopts, longopts, &longind);      if (optc == '?')	{	  --optind;	  optc = getopt_long (argc, argv, shortopts, really_longopts, &longind);	}      if (optc == -1)	break;      switch (optc)	{	case '?':	  fprintf (stderr, _("%s: unrecognized option '%s'\n"),		   program_name, argv[optind - 1]);	default:	  fprintf (stderr,		   _("%s: use the --help option for usage information\n"),		   program_name);	  xexit (1);	case 1:			/* File name.  */	  lang_add_input_file (optarg, lang_input_file_is_file_enum,			       (char *) NULL);	  break;	case OPTION_IGNORE:	  break;	case 'a':	  /* For HP/UX compatibility.  Actually -a shared should mean             ``use only shared libraries'' but, then, we don't             currently support shared libraries on HP/UX anyhow.  */	  if (strcmp (optarg, "archive") == 0)	    config.dynamic_link = false;	  else if (strcmp (optarg, "shared") == 0		   || strcmp (optarg, "default") == 0)	    config.dynamic_link = true;	  else	    einfo (_("%P%F: unrecognized -a option `%s'\n"), optarg);	  break;	case OPTION_ASSERT:	  /* FIXME: We just ignore these, but we should handle them.  */	  if (strcmp (optarg, "definitions") == 0)	    ;	  else if (strcmp (optarg, "nodefinitions") == 0)	    ;	  else if (strcmp (optarg, "nosymbolic") == 0)	    ;	  else if (strcmp (optarg, "pure-text") == 0)	    ;	  else	    einfo (_("%P%F: unrecognized -assert option `%s'\n"), optarg);	  break;	case 'A':	  ldfile_add_arch (optarg);	  break;	case 'b':	  lang_add_target (optarg);	  break;	case 'c':	  ldfile_open_command_file (optarg);	  parser_input = input_mri_script;	  yyparse ();	  break;	case OPTION_CALL_SHARED:	  config.dynamic_link = true;	  break;	case OPTION_NON_SHARED:	  config.dynamic_link = false;	  break;	case OPTION_CREF:	  command_line.cref = true;	  link_info.notice_all = true;	  break;	case 'd':	  command_line.force_common_definition = true;	  break;	case OPTION_DEFSYM:	  lex_string = optarg;	  lex_redirect (optarg);	  parser_input = input_defsym;	  parsing_defsym = 1;	  yyparse ();	  parsing_defsym = 0;	  lex_string = NULL;	  break;	case OPTION_DEMANGLE:	  demangling = true;	  if (optarg != NULL)	    {	      enum demangling_styles style;	      style = cplus_demangle_name_to_style (optarg);	      if (style == unknown_demangling)		einfo (_("%F%P: unknown demangling style `%s'"),		       optarg);	      cplus_demangle_set_style (style);	    }	  break;	case OPTION_DYNAMIC_LINKER:	  command_line.interpreter = optarg;	  break;	case OPTION_EB:	  command_line.endian = ENDIAN_BIG;	  break;	case OPTION_EL:	  command_line.endian = ENDIAN_LITTLE;	  break;	case OPTION_EMBEDDED_RELOCS:	  command_line.embedded_relocs = true;	  break;	case OPTION_EXPORT_DYNAMIC:	case 'E': /* HP/UX compatibility.  */	  command_line.export_dynamic = true;	  break;	case 'e':	  lang_add_entry (optarg, true);	  break;	case 'f':	  if (command_line.auxiliary_filters == NULL)	    {	      command_line.auxiliary_filters =		(char **) xmalloc (2 * sizeof (char *));	      command_line.auxiliary_filters[0] = optarg;	      command_line.auxiliary_filters[1] = NULL;	    }	  else	    {	      int c;	      char **p;	      c = 0;	      for (p = command_line.auxiliary_filters; *p != NULL; p++)		++c;	      command_line.auxiliary_filters =		(char **) xrealloc (command_line.auxiliary_filters,				    (c + 2) * sizeof (char *));	      command_line.auxiliary_filters[c] = optarg;	      command_line.auxiliary_filters[c + 1] = NULL;	    }	  break;	case 'F':	  command_line.filter_shlib = optarg;	  break;	case OPTION_FORCE_EXE_SUFFIX:	  command_line.force_exe_suffix = true;	  break;	case 'G':	  {	    char *end;	    g_switch_value = strtoul (optarg, &end, 0);	    if (*end)	      einfo (_("%P%F: invalid number `%s'\n"), optarg);	  }	  break;	case 'g':	  /* Ignore.  */	  break;	case OPTION_GC_SECTIONS:	  command_line.gc_sections = true;	  break;	case OPTION_HELP:	  help ();	  xexit (0);	  break;	case 'L':	  ldfile_add_library_path (optarg, true);	  break;	case 'l':	  lang_add_input_file (optarg, lang_input_file_is_l_enum,			       (char *) NULL);	  break;	case 'M':	  config.map_filename = "-";	  break;	case 'm':	  /* Ignore.  Was handled in a pre-parse.   */	  break;	case OPTION_MAP:	  config.map_filename = optarg;	  break;	case 'N':	  config.text_read_only = false;	  config.magic_demand_paged = false;	  config.dynamic_link = false;	  break;	case 'n':	  config.magic_demand_paged = false;	  config.dynamic_link = false;	  break;	case OPTION_NO_DEMANGLE:	  demangling = false;	  break;	case OPTION_NO_GC_SECTIONS:	  command_line.gc_sections = false;	  break;	case OPTION_NO_KEEP_MEMORY:	  link_info.keep_memory = false;	  break;	case OPTION_NO_UNDEFINED:	  link_info.no_undefined = true;	  break;	case OPTION_ALLOW_SHLIB_UNDEFINED:	  link_info.allow_shlib_undefined = true;	  break;	case OPTION_NO_WARN_MISMATCH:	  command_line.warn_mismatch = false;	  break;	case OPTION_NOINHIBIT_EXEC:	  force_make_executable = true;	  break;	case OPTION_NO_WHOLE_ARCHIVE:	  whole_archive = false;	  break;	case 'O':	  /* FIXME "-O<non-digits> <value>" used to set the address of	     section <non-digits>.  Was this for compatibility with	     something, or can we create a new option to do that	     (with a syntax similar to -defsym)?	     getopt can't handle two args to an option without kludges.  */	  /* Enable optimizations of output files.  */	  link_info.optimize = strtoul (optarg, NULL, 0) ? true : false;	  break;	case 'o':	  lang_add_output (optarg, 0);	  break;	case OPTION_OFORMAT:	  lang_add_output_format (optarg, (char *) NULL, (char *) NULL, 0);	  break;	case 'q':	  link_info.emitrelocations = true;	  break;	case 'i':	case 'r':	  link_info.relocateable = true;	  config.build_constructors = false;	  config.magic_demand_paged = false;	  config.text_read_only = false;	  config.dynamic_link = false;	  break;	case 'R':	  /* The GNU linker traditionally uses -R to mean to include	     only the symbols from a file.  The Solaris linker uses -R	     to set the path used by the runtime linker to find	     libraries.  This is the GNU linker -rpath argument.  We	     try to support both simultaneously by checking the file	     named.  If it is a directory, rather than a regular file,	     we assume -rpath was meant.  */	  {	    struct stat s;	    if (stat (optarg, &s) >= 0		&& ! S_ISDIR (s.st_mode))	      {		lang_add_input_file (optarg,				     lang_input_file_is_symbols_only_enum,				     (char *) NULL);		break;	      }	  }	  /* Fall through.  */	case OPTION_RPATH:	  if (command_line.rpath == NULL)	    command_line.rpath = xstrdup (optarg);	  else	    {	      size_t rpath_len = strlen (command_line.rpath);	      size_t optarg_len = strlen (optarg);	      char *buf;	      char *cp = command_line.rpath;	      /* First see whether OPTARG is already in the path.  */	      do		{		  size_t idx = 0;		  while (optarg[idx] != '\0' && optarg[idx] == cp[idx])		    ++idx;		  if (optarg[idx] == '\0'		      && (cp[idx] == '\0' || cp[idx] == ':'))		    /* We found it.  */		    break;		  /* Not yet found.  */		  cp = strchr (cp, ':');		  if (cp != NULL)		    ++cp;		}	      while (cp != NULL);	      if (cp == NULL)		{		  buf = xmalloc (rpath_len + optarg_len + 2);		  sprintf (buf, "%s:%s", command_line.rpath, optarg);		  free (command_line.rpath);		  command_line.rpath = buf;		}	    }	  break;	case OPTION_RPATH_LINK:	  if (command_line.rpath_link == NULL)	    command_line.rpath_link = xstrdup (optarg);	  else	    {	      char *buf;	      buf = xmalloc (strlen (command_line.rpath_link)			     + strlen (optarg)			     + 2);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?