# include <stdio.h>

char *strchr();


int optind = 1;
char *optarg;

getopt(argc, argv, optstring)
char **argv;
char *optstring;
{    static int p = 1;
     char *cp, ch;

again:
    if (optind >= argc || argv[optind][0] != '-')
	return EOF;
    ch = argv[optind][p];
    if (ch == NULL) {
	optind++;
	p = 1;
	goto again;
	}
    cp = strchr(optstring, ch);
    if (cp == NULL) {
	fprintf(stderr, "Unknown switch '%c'\n", ch);
	return '?';
	}
    if (cp[1] != ':')
	return ch;
    optarg = argv[optind+1];
    optind += 2;
    p = 1;
    return ch;
}
