예제 #1
0
static int option_begin(const char* str)
{
	if (is_short_option(str))
		return short_option_begin(str);
	else if (is_long_option(str))
		return long_option_begin(str);
	assert(0);
	return 0;
}
예제 #2
0
static int find_short_index(char * const *argv)
{
   for (int index = 0; argv[index]; index++)
   {
      if (is_short_option(argv[index]))
         return index;
   }

   return -1;
}
예제 #3
0
static int find_short_index(char * const *argv)
{
   int idx;
   for (idx = 0; argv[idx]; idx++)
   {
      if (is_short_option(argv[idx]))
         return idx;
   }

   return -1;
}
예제 #4
0
int getopt_long_only(int argc, char * const argv[],
	const char *optstring,
	const struct option *longopts, int *longindex)
{
	if (!argc || !argv)
		return -1;

	getopt_param param = scan_param(optstring ? optstring : "");

	if (optind >= argc) {
		if (!param.posix && !param.process_all)
			swap_values(argc, (char**)argv, optind);
		return -1;
	}

	optarg = 0;

	if (!nextchar) {// we are in begin of argument... no previous iterations on this arg
		int retval;
		if (!detect_next_option(argc, argv, param, retval))
			return retval;

		const char* str = argv[optind];
		if (is_long_option(str)) {
			int _longindex;
			if (!longindex) // if no longindex specified - create own temp...
				longindex = &_longindex;
			return get_long_option(argc, argv, param, longopts, longindex);
		}
		else if (is_short_option(str)) {
			return get_long_short_option(argc, argv, param, longopts, longindex);
		}
	}

	return get_short_option(argc, argv, param);
}
예제 #5
0
static bool is_option(const char* str)
{
	return (is_short_option(str) || is_long_option(str));
}