#BEGIN DIFF

#define	FLAG_AUTONAME	0
#define	FLAG_VERBOSE	1
#define	FLAG_INFILE		2
#define	FLAG_OUTFILE	3

struct cmdflag_s
{
	int	short_name;
	char *long_name;
	int idx;
}	cmdflags[] = 
{
	{'a', "--autoname", -1},
	{'v', "--verbose", -1},
	{'i', "--infile", -1},
	{'o', "--outfile", -1},
	{0, NULL, -1}
};

static vboolean
set_short_flags(char *flags,int test_idx)
{
	
	int i = 0;
	for(i = 0;cmdflags[i].short_name;i++)
	{
		if(strchr(flags, cmdflags[i].short_name))
			cmdflags[i].idx = test_idx;
	}
	return true; /* TODO */
}

static vboolean
set_long_flag(char *flag,int test_idx)
{
	int i = 0;
	for(i = 0;cmdflags[i].short_name;i++)
	{
		if(!strcmp(flag, cmdflags[i].long_name))
		{
			cmdflags[i].idx = test_idx;
			return true;
		}
	}
	return false;
}

static vboolean
set_flags(int argc, char *argv[])
{
	for(i = 1;i < argc;i++)
	{
		if(argv[i][0] != '-')
			continue;
		if(argv[i][1] == '-')
			return set_long_flag(argv[i] + 2, i);
		else
			return set_short_flags(argv[i] + 1, i);
	}
}

static void usage() {}

int main(int argc, char *argv[])
{
	CALLER_NAME(main)
	int i;
	char *script = "test.fcic";
	char *dumpdev = "CON", *outfile = dumpdev;
	logStartConsoleLog();
	logUpperLevel(LOG_TRACE);
	if(!set_flags(argc, argv))
	{
		usage();
		return;
	}
	if(cmdflags[FLAG_OUTFILE].idx > 0)
	{ 
		if(cmdflags[FLAG_AUTONAME].idx > 0)
		{
			puts("--outfile is meaningless with --autoname.");
			return -1;
		}
		if(cmdflags[FLAG_OUTFILE].idx + 1 >= argc)
		{
			usage();
			return -1;
		}
		outfile = argv[cmdflags[FLAG_OUTFILE].idx + 1];
	}
	if(cmdflags[FLAG_INFILE].idx > 0)
	{ 
		if(cmdflags[FLAG_INFILE].idx + 1 >= argc)
		{
			usage();
			return -1;
		}
		infile = argv[cmdflags[FLAG_OUTFILE].idx + 1];
	}

#END DIFF
