Beispiel #1
0
//-----------------------------------------------------------------------------
int32_t Args::getopt()
{
	// Always reset optarg
	m_optarg = NULL;

	// End of arguments
	if (m_optind >= m_scope)
	{
		return -1;
	}

	switch (option_type(m_argv[m_optind]))
	{
		case AOT_SHORT:
		{
			return short_option(m_argv[m_optind]);
		}
		case AOT_LONG:
		{
			return long_option(m_argv[m_optind]);
		}
		case AOT_NOT_OPTION:
		{
			not_option();
			return getopt();
		}
		default:
		{
			return '?';
		}
	}
}
Beispiel #2
0
int get_option(char **argvp[], const struct option *options, char **arg)
{
    char **argv = *argvp;
    const char *opt = *argv;
    int i;

    *arg = NULL;
    if (opt == NULL || opt[0] != '-' || opt[1] == 0)
        return -1;

    if (opt[1] == '-') {
        if (opt[2] == 0) {
            /* '--' => no more options */
            *argvp = argv + 1;
            return -1;
        }
        i = long_option(opt + 2, options);
    } else if (opt[2]) {
        return -1;
    } else {
        i = short_option(opt[1], options);
    }
    argv++;
    if (options[i].has_arg) {
        if (*argv == NULL)
            die("option `%s' requires an argument\n", opt);
        *arg = *argv++;
    }
    *argvp = argv;
    return i;
}
Beispiel #3
0
int
parse_options(const struct weston_option *options,
	      int count, int *argc, char *argv[])
{
	int i, j;

	for (i = 1, j = 1; i < *argc; i++) {
		if (argv[i][0] == '-') {
			if (argv[i][1] == '-') {
				/* Long option, e.g. --foo or --foo=bar */
				if (long_option(options, count, argv[i]))
					continue;

			} else {
				/* Short option, e.g -f or -f42 */
				if (short_option(options, count, argv[i]))
					continue;

				/* ...also handle -f 42 */
				if (i+1 < *argc &&
				    short_option_with_arg(options, count, argv[i], argv[i+1])) {
					i++;
					continue;
				}
			}
		}
		argv[j++] = argv[i];
	}
	argv[j] = NULL;
	*argc = j;

	return j;
}