4 #define ERR(str, chr) if(opterr){fprintf(stderr, "%s%s%c\n", argv[0], str, chr);}
11 getopt (int argc, char **argv, char *opts)
19 argv[optind][0] != '-' || argv[optind][1] == '\0')
21 else if (strcmp(argv[optind], "--") == 0) {
25 optopt = c = argv[optind][sp];
26 if (c == ':' || (cp=strchr(opts, c)) == NULL) {
27 ERR (": illegal option -- ", c);
28 if (argv[optind][++sp] == '\0') {
35 if (argv[optind][sp+1] != '\0')
36 optarg = &argv[optind++][sp+1];
37 else if (++optind >= argc) {
38 ERR (": option requires an argument -- ", c);
42 optarg = argv[optind++];
45 if (argv[optind][++sp] == '\0') {