www.pudn.com > ASM86_64.rar > option.c


#include "option.h"
#include "a64-2.h"


static int get_index_opt(struct opt_struct *opts, char *s)
{
	int i = 0;

	while (opts->opt && !str_cmp(s, opts->opt)) {
		i++; opts++;
	}

	return opts->opt ? i : -1;
}


struct parse_opt parse_option(int i, char **argv, struct opt_struct *opts)
{
	struct parse_opt ret = { -1, 0 };

/*
	if (argv[i][0]=='-' && argv[i][1]=='-' && argv[i][2] != '-') {
		ret = get_index_opt(opts, &argv[i][2]);

	} else 
*/
	if (argv[i][0] == '-') {
		char c[2];
		c[0] = argv[i][1]; c[1] = 0;
		if ((ret.index = get_index_opt(opts, &c[0])) != -1) 
			if (argv[i][2])
				ret.ptr = &argv[i][2];
			else 
				ret.ptr = argv[i+1];
		else if ((ret.index = get_index_opt(opts, &argv[i][1])) != -1)
			ret.ptr = argv[i+1];

	} else if (is_c(argv[i][0]) || argv[i][0] == '_') {
		ret.index = IS_FILE;
	} 
	
	return ret;
}