RELEASE/1.0RELEASE/1.1RELEASE/1.2debug-cidebug-ci-sanitisersfaster-cavernloglog-selectstereostereo-2025walls-datawalls-data-hanging-as-warningwarn-only-for-hanging-survey
Rev | Line | |
---|
[d1b1380] | 1 | #include <stdio.h> |
---|
| 2 | #include <string.h> |
---|
| 3 | |
---|
| 4 | #define ERR(_s, _c) { if (opterr) fprintf (stderr, "%s%c\n", argv[0], _s, _c);} |
---|
| 5 | |
---|
| 6 | int opterr = 1; |
---|
| 7 | int optind = 1; |
---|
| 8 | int optopt; |
---|
| 9 | char *optarg; |
---|
| 10 | |
---|
| 11 | int getopt(int argc, char **argv, char *opts) |
---|
| 12 | { |
---|
| 13 | static int sp = 1; |
---|
| 14 | int c; |
---|
| 15 | char *cp; |
---|
| 16 | |
---|
| 17 | if(sp == 1) |
---|
| 18 | if(optind >= argc || |
---|
| 19 | argv[optind][0] != '-' || argv[optind][1] == '\0') |
---|
| 20 | return(EOF); |
---|
| 21 | else if(strcmp(argv[optind], "--") == NULL) { |
---|
| 22 | optind++; |
---|
| 23 | return(EOF); |
---|
| 24 | } |
---|
| 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') { |
---|
| 29 | optind++; |
---|
| 30 | sp = 1; |
---|
| 31 | } |
---|
| 32 | return('?'); |
---|
| 33 | } |
---|
| 34 | if(*++cp == ':') { |
---|
| 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); |
---|
| 39 | sp = 1; |
---|
| 40 | return('?'); |
---|
| 41 | } else |
---|
| 42 | optarg = argv[optind++]; |
---|
| 43 | sp = 1; |
---|
| 44 | } else { |
---|
| 45 | if(argv[optind][++sp] == '\0') { |
---|
| 46 | sp = 1; |
---|
| 47 | optind++; |
---|
| 48 | } |
---|
| 49 | optarg = NULL; |
---|
| 50 | } |
---|
| 51 | return(c); |
---|
| 52 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.