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