|
|
1.1 ! root 1: #define ERR(str, chr) if(opterr){fprint(2, "%s%s%c\n", argv[0], str, chr);} ! 2: int opterr = 1; ! 3: int optind = 1; ! 4: int optopt; ! 5: char *optarg; ! 6: char *strchr(); ! 7: ! 8: int ! 9: getopt (argc, argv, opts) ! 10: char **argv, *opts; ! 11: { ! 12: static int sp = 1; ! 13: register c; ! 14: register char *cp; ! 15: ! 16: if (sp == 1) ! 17: if (optind >= argc || ! 18: argv[optind][0] != '-' || argv[optind][1] == '\0') ! 19: return -1; ! 20: else if (strcmp(argv[optind], "--") == 0) { ! 21: optind++; ! 22: return -1; ! 23: } ! 24: optopt = c = argv[optind][sp]; ! 25: if (c == ':' || (cp=strchr(opts, c)) == 0) { ! 26: ERR (": illegal option -- ", c); ! 27: if (argv[optind][++sp] == '\0') { ! 28: optind++; ! 29: sp = 1; ! 30: } ! 31: return '?'; ! 32: } ! 33: if (*++cp == ':') { ! 34: if (argv[optind][sp+1] != '\0') ! 35: optarg = &argv[optind++][sp+1]; ! 36: else if (++optind >= argc) { ! 37: ERR (": option requires an argument -- ", c); ! 38: sp = 1; ! 39: return '?'; ! 40: } else ! 41: optarg = argv[optind++]; ! 42: sp = 1; ! 43: } else { ! 44: if (argv[optind][++sp] == '\0') { ! 45: sp = 1; ! 46: optind++; ! 47: } ! 48: optarg = 0; ! 49: } ! 50: return c; ! 51: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.