gcc-4.6.0/gcc/opts-common.c#decode_cmdline_options_to_array

/* Decode command-line options (ARGC and ARGV being the arguments of
   main) into an array, setting *DECODED_OPTIONS to a pointer to that
   array and *DECODED_OPTIONS_COUNT to the number of entries in the
   array.  The first entry in the array is always one for the program
   name (OPT_SPECIAL_program_name).  LANG_MASK indicates the language
   flags applicable for decoding (including CL_COMMON and CL_TARGET if
   those options should be considered applicable).  Do not produce any

   diagnostics or set state outside of these variables. 将命令行选项‘解码’到一个

数组中,设置 *decoded_options指向这个数组,*decoded_options_count指向

表示这个数组大小的整数。数组的第一个元素往往是程序名(OPT_SPECIAL_

program_name). LANG_MASK指出可以解码的语言标记?。禁止任何对这些

变量的检测,或者设置其状态。 */


void
decode_cmdline_options_to_array (unsigned int argc, const char **argv, 
unsigned int lang_mask,
struct cl_decoded_option **decoded_options,
unsigned int *decoded_options_count)
{
  unsigned int n, i;
  struct cl_decoded_option *opt_array;
  unsigned int num_decoded_options;
  bool argv_copied = false;


  opt_array = XNEWVEC (struct cl_decoded_option, argc);

//设置第一个选项
  opt_array[0].opt_index = OPT_SPECIAL_program_name;//选项的下标
  opt_array[0].warn_message = NULL;//无警告信息
  opt_array[0].arg = argv[0];//字符串参数
  opt_array[0].orig_option_with_args_text = argv[0];//指向在原始命令行命令中的位置
  opt_array[0].canonical_option_num_elements = 1;//规范化后选项内容的大小
  opt_array[0].canonical_option[0] = argv[0];//选项内容第一项
  opt_array[0].canonical_option[1] = NULL;//没有其他项
  opt_array[0].canonical_option[2] = NULL;
  opt_array[0].canonical_option[3] = NULL;
  opt_array[0].value = 1;//布尔真值 ?
  opt_array[0].errors = 0;//没有错误信息?
  num_decoded_options = 1;//记录当前已经‘解码’的选项个数。


  for (i = 1; i < argc; i += n)
    {
      const char *opt = argv[i];


      /* Interpret "-" or a non-switch as a file name.  读取‘-’选项,

         或者不是-选项则作为文件名*/

      if (opt[0] != '-' || opt[1] == '\0')//不是-选项
{
  generate_option_input_file (opt, &opt_array[num_decoded_options]);//
 num_decoded_options++;
 n = 1;
 continue;
}

//‘-’选项
      n = decode_cmdline_option (argv + i, lang_mask,
&opt_array[num_decoded_options]);
      num_decoded_options++;
    }


  if (argv_copied)
    free (argv);
  *decoded_options = opt_array;
  *decoded_options_count = num_decoded_options;
  prune_options (decoded_options, decoded_options_count);
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值