Beispiel #1
0
int
main(int argc, char *argv[])
{
	option *op;
	int i;

	progname = strrchr(argv[0], '/');

	optsetstyle(0);

	if (progname)
		++progname;
	else
		progname = argv[0];

	optsload(options, progname);

	printf("getopts version: %s\n", OPTS_REV);

	printf("options loaded:\n");
	for (op = &options[0]; op->type; ++op) {
		if (!((op->type == OTYPE_NUL) &&
		  (op->flags & OFLAG_ARG))) {
			printf("\t%s\n", optsprint(op));
		}
		op->flags &= ~OFLAG_SET;
	}

	if (optsgets(argc, argv, options)) {
		fprintf(stderr, "optsgets() errored.\nUsage:");
		for (op = &options[0]; op->type; ++op)
			if (!((op->type == OTYPE_NUL) &&
			  (op->flags & OFLAG_ARG)))
				fprintf(stderr, "%s\n", optsusage(op));
	}

	printf("remaining args:\n");
	for (i = optsind; i < argc; ++i) {
		printf("\t'%s'\n", argv[i]);
	}

	printf("options after getopts:\n");
	for (op = &options[0]; op->type; ++op)
		if (!((op->type == OTYPE_NUL) &&
		  (op->flags & OFLAG_ARG)))
		printf("\t%s [%s]\n", optsprint(op),
			op->flags & OFLAG_SET ? "set" : "not set");
	printf("xflag: %d\n", xflag);

	optssave(options, progname);
	return 0;
}
Beispiel #2
0
int ocd_parse(int* argc, char*** argv)
{
	if(!_options)
		_ocd_create_arguments();
	
	int largc = *argc;
	char** largv = *argv;

	//Determine if there are any arguments to parse.
	int i;
	int origargc = largc;
	for(i = 0; i < largc; i++)
	{
		if(strlen(largv[i]) == 2 && strncmp(largv[i], "--", 2) == 0)
		{
			largc = i;
			break;
		}
	}

	if(largc == origargc) // No double dash
	{
		//Assume we failed because they were actually
		//Program specific arguments.
		return 0;
	}

	if (optsgets(largc, largv, _options)) {

		fprintf(stderr, "optsgets() errored.\nUsage:");
		option* op;
		for (op = &_options[0]; op->type; ++op)
			if (!((op->type == OTYPE_NUL) &&
			  (op->flags & OFLAG_ARG)))
				fprintf(stderr, "%s\n", optsusage(op));
	}

	*argv += largc;
	*argc = *argc - largc;
	return largc;
}
Beispiel #3
0
void ocd_usage()
{
	option* op;
	for (op = &_options[0]; op->type; ++op)
		printf("%s\n", optsusage(op));
}