src/dpdk/lib/librte_eal/windows/getopt.c
static int
parse_long_options(char **nargv, const char *options,
	const struct option *long_options, int *idx, int short_too)
{
	const char *current_argv;
	char *has_equal;
	size_t current_argv_len;
	int i, match;

	current_argv = place;
	match = -1;

	optind++;

	has_equal = strchr(current_argv, '=');
	if (has_equal != NULL) {
		/* argument found (--option=arg) */
		current_argv_len = has_equal - current_argv;
		has_equal++;
	} else
		current_argv_len = strlen(current_argv);

	for (i = 0; long_options[i].name; i++) {
		/* find matching long option */
		if (strncmp(current_argv, long_options[i].name,
		    current_argv_len))
			continue;

		if (strlen(long_options[i].name) == current_argv_len) {
			/* exact match */
			match = i;
			break;
		}
		/*
		 * If this is a known short option, don't allow
		 * a partial match of a single character.
		 */
		if (short_too && current_argv_len == 1)
			continue;

		if (match == -1)	/* partial match */
			match = i;
		else {
			/* ambiguous abbreviation */
			if (PRINT_ERROR)
				warnx(ambig, (int)current_argv_len,
				     current_argv);
			optopt = 0;
			return BADCH;
		}
	}
	if (match != -1) {		/* option found */
		if (long_options[match].has_arg == no_argument
		    && has_equal) {
			if (PRINT_ERROR)
				warnx(noarg, (int)current_argv_len,
				     current_argv);
			/*
			 * XXX: GNU sets optopt to val regardless of flag
			 */
			if (long_options[match].flag == NULL)
				optopt = long_options[match].val;
			else
				optopt = 0;
			return BADARG;
		}
		if (long_options[match].has_arg == required_argument ||
		    long_options[match].has_arg == optional_argument) {
			if (has_equal)
				optarg = has_equal;
			else if (long_options[match].has_arg ==
			    required_argument) {
				/*
				 * optional argument doesn't use next nargv
				 */
				optarg = nargv[optind++];
			}
		}
		if ((long_options[match].has_arg == required_argument)
		    && (optarg == NULL)) {
			/*
			 * Missing argument; leading ':' indicates no error
			 * should be generated.
			 */
			if (PRINT_ERROR)
				warnx(recargstring,
				    current_argv);
			/*
			 * XXX: GNU sets optopt to val regardless of flag
			 */
			if (long_options[match].flag == NULL)
				optopt = long_options[match].val;
			else
				optopt = 0;
			--optind;
			return BADARG;
		}
	} else {			/* unknown option */
		if (short_too) {
			--optind;
			return (-1);
		}
		if (PRINT_ERROR)
			warnx(illoptstring, current_argv);
		optopt = 0;
		return BADCH;
	}
	if (idx)
		*idx = match;
	if (long_options[match].flag) {
		*long_options[match].flag = long_options[match].val;
		return 0;
	} else
		return (long_options[match].val);
}
/*
 * parse_long_options --
 *	Parse long options in argc/argv argument vector.
 * Returns -1 if short_too is set and the option does not match long_options.
 */
parse_long_options
Parse long options in argc/argv argument vector.
Returns -1 if short_too is set and the option does not match long_options.
parse_long_options Parse long options in argc / argv argument vector . Returns - 1 if short_too is set and the option does not match long_options .
static int
parse_long_options(char **nargv, const char *options,
	const struct option *long_options, int *idx, int short_too)
{
	const char *current_argv;
	char *has_equal;
	size_t current_argv_len;
	int i, match;
	current_argv = place;
	match = -1;
	optind++;
	has_equal = strchr(current_argv, '=');
	if (has_equal != NULL) {
		current_argv_len = has_equal - current_argv;
		has_equal++;
	} else
		current_argv_len = strlen(current_argv);
	for (i = 0; long_options[i].name; i++) {
		if (strncmp(current_argv, long_options[i].name,
		    current_argv_len))
			continue;
		if (strlen(long_options[i].name) == current_argv_len) {
			match = i;
			break;
		}
		if (short_too && current_argv_len == 1)
			continue;
		if (match == -1)	
			match = i;
		else {
			if (PRINT_ERROR)
				warnx(ambig, (int)current_argv_len,
				     current_argv);
			optopt = 0;
			return BADCH;
		}
	}
	if (match != -1) {		
		if (long_options[match].has_arg == no_argument
		    && has_equal) {
			if (PRINT_ERROR)
				warnx(noarg, (int)current_argv_len,
				     current_argv);
			if (long_options[match].flag == NULL)
				optopt = long_options[match].val;
			else
				optopt = 0;
			return BADARG;
		}
		if (long_options[match].has_arg == required_argument ||
		    long_options[match].has_arg == optional_argument) {
			if (has_equal)
				optarg = has_equal;
			else if (long_options[match].has_arg ==
			    required_argument) {
				optarg = nargv[optind++];
			}
		}
		if ((long_options[match].has_arg == required_argument)
		    && (optarg == NULL)) {
			if (PRINT_ERROR)
				warnx(recargstring,
				    current_argv);
			if (long_options[match].flag == NULL)
				optopt = long_options[match].val;
			else
				optopt = 0;
			--optind;
			return BADARG;
		}
	} else {			
		if (short_too) {
			--optind;
			return (-1);
		}
		if (PRINT_ERROR)
			warnx(illoptstring, current_argv);
		optopt = 0;
		return BADCH;
	}
	if (idx)
		*idx = match;
	if (long_options[match].flag) {
		*long_options[match].flag = long_options[match].val;
		return 0;
	} else
		return (long_options[match].val);
}
static int parse_long_options ( char * * nargv , const char * options , const struct option * long_options , int * idx , int short_too ) { const char * current_argv ; char * has_equal ; size_t current_argv_len ; int i , match ; current_argv = place ; match = -1 ; optind ++ ; has_equal = strchr ( current_argv , ' ' ) ; if ( has_equal != NULL ) { current_argv_len = has_equal - current_argv ; has_equal ++ ; } else current_argv_len = strlen ( current_argv ) ; for ( i = 0 ; long_options [ i ] . name ; i ++ ) { if ( strncmp ( current_argv , long_options [ i ] . name , current_argv_len ) ) continue ; if ( strlen ( long_options [ i ] . name ) == current_argv_len ) { match = i ; break ; } if ( short_too && current_argv_len == 1 ) continue ; if ( match == -1 ) match = i ; else { if ( PRINT_ERROR ) warnx ( ambig , ( int ) current_argv_len , current_argv ) ; optopt = 0 ; return BADCH ; } } if ( match != -1 ) { if ( long_options [ match ] . has_arg == no_argument && has_equal ) { if ( PRINT_ERROR ) warnx ( noarg , ( int ) current_argv_len , current_argv ) ; if ( long_options [ match ] . flag == NULL ) optopt = long_options [ match ] . val ; else optopt = 0 ; return BADARG ; } if ( long_options [ match ] . has_arg == required_argument || long_options [ match ] . has_arg == optional_argument ) { if ( has_equal ) optarg = has_equal ; else if ( long_options [ match ] . has_arg == required_argument ) { optarg = nargv [ optind ++ ] ; } } if ( ( long_options [ match ] . has_arg == required_argument ) && ( optarg == NULL ) ) { if ( PRINT_ERROR ) warnx ( recargstring , current_argv ) ; if ( long_options [ match ] . flag == NULL ) optopt = long_options [ match ] . val ; else optopt = 0 ; -- optind ; return BADARG ; } } else { if ( short_too ) { -- optind ; return ( -1 ) ; } if ( PRINT_ERROR ) warnx ( illoptstring , current_argv ) ; optopt = 0 ; return BADCH ; } if ( idx ) * idx = match ; if ( long_options [ match ] . flag ) { * long_options [ match ] . flag = long_options [ match ] . val ; return 0 ; } else return ( long_options [ match ] . val ) ; }
parse_long_options
      Parse long options in argc/argv argument vector.
parse_long_options Parse long options in argc / argv argument vector .
/* argument found (--option=arg) */ /* find matching long option */ /* exact match */ /*
		 * If this is a known short option, don't allow
		 * a partial match of a single character.
		 */ /* partial match */ /* ambiguous abbreviation */ /* option found */ /*
			 * XXX: GNU sets optopt to val regardless of flag
			 */ /*
				 * optional argument doesn't use next nargv
				 */ /*
			 * Missing argument; leading ':' indicates no error
			 * should be generated.
			 */ /*
			 * XXX: GNU sets optopt to val regardless of flag
			 */ /* unknown option */