locate_option函数
返回argv中选项opt的索引,如果没有找到则返回0。
/**
* Return index of option opt in argv or 0 if not found.
*/
int locate_option(int argc, char **argv, const OptionDef *options,
const char *optname)
{
const OptionDef *po;
int i;
for (i = 1; i < argc; i++) {
const char *cur_opt = argv[i];
if (*cur_opt++ != '-')
continue;
po = find_option(options, cur_opt);
if (!po->name && cur_opt[0] == 'n' && cur_opt[1] == 'o')
po = find_option(options, cur_opt + 2);
if ((!po->name && !strcmp(cur_opt, optname)) ||
(po->name && !strcmp(optname, po->name)))
return i;
if (!po->name || po->flags & HAS_ARG)
i++;
}
return 0;
}