| 1 | #cxx . . $ `<file>/cstool/getopt.c`/include <string.h> |
| 2 | #include <stdio.h> |
| 3 | |
| 4 | #include "getopt.h"cxx . . $ `<file>/cstool/getopt.h`/ |
| 5 | |
| 6 | int opterrcxx . . $ opterr. = 1, /* if error message should be printed */ |
| 7 | optindcxx . . $ optind. = 1, /* index into parent argv vector */ |
| 8 | optoptcxx . . $ optopt., /* character checked for validity */ |
| 9 | optresetcxx . . $ optreset.; /* reset getopt */ |
| 10 | const char *optargcxx . . $ optarg.; /* argument associated with option */ |
| 11 | |
| 12 | #define BADCHcxx . . $ `cstool/getopt.c:12:9`! (int)'?' |
| 13 | #define BADARGcxx . . $ `cstool/getopt.c:13:9`! (int)':' |
| 14 | #define EMSGcxx . . $ `cstool/getopt.c:14:9`! "" |
| 15 | |
| 16 | /* |
| 17 | * getopt -- |
| 18 | * Parse argc/argv argument vector. |
| 19 | */ |
| 20 | int getoptcxx . . $ getopt(2483c31ff9bab884). (int nargc, char * const nargv[], const char *ostr) |
| 21 | { |
| 22 | static const char *place = EMSGcxx . . $ `cstool/getopt.c:14:9`!; /* option letter processing */ |
| 23 | const char *oli; /* option letter list index */ |
| 24 | |
| 25 | if (optresetcxx . . $ optreset. || !*place) { /* update scanning pointer */ |
| 26 | optresetcxx . . $ optreset. = 0; |
| 27 | if (optindcxx . . $ optind. >= nargc || *(place = nargv[optindcxx . . $ optind.]) != '-') { |
| 28 | place = EMSGcxx . . $ `cstool/getopt.c:14:9`!; |
| 29 | return (-1); |
| 30 | } |
| 31 | |
| 32 | if (place[1] && *++place == '-') { /* found "--" */ |
| 33 | ++optindcxx . . $ optind.; |
| 34 | place = EMSGcxx . . $ `cstool/getopt.c:14:9`!; |
| 35 | return (-1); |
| 36 | } |
| 37 | } /* option letter okay? */ |
| 38 | |
| 39 | if ((optoptcxx . . $ optopt. = (int)*place++) == (int)':' || |
| 40 | !(oli = strchrcxx . . $ strchr(2050848944e00d54). (ostr, optoptcxx . . $ optopt.))) { |
| 41 | /* |
| 42 | * if the user didn't specify '-' as an option, |
| 43 | * assume it means -1. |
| 44 | */ |
| 45 | if (optoptcxx . . $ optopt. == (int)'-') |
| 46 | return (-1); |
| 47 | if (!*place) |
| 48 | ++optindcxx . . $ optind.; |
| 49 | if (opterrcxx . . $ opterr. && *ostr != ':') |
| 50 | (void)printfcxx . . $ printf(581fddd72a8db8fc). ("illegal option -- %c\n", optoptcxx . . $ optopt.); |
| 51 | return (BADCHcxx . . $ `cstool/getopt.c:12:9`!); |
| 52 | } |
| 53 | |
| 54 | if (*++oli != ':') { /* don't need argument */ |
| 55 | optargcxx . . $ optarg. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 56 | if (!*place) |
| 57 | ++optindcxx . . $ optind.; |
| 58 | } else { /* need an argument */ |
| 59 | if (*place) /* no white space */ |
| 60 | optargcxx . . $ optarg. = place; |
| 61 | else if (nargc <= ++optindcxx . . $ optind.) { /* no arg */ |
| 62 | place = EMSGcxx . . $ `cstool/getopt.c:14:9`!; |
| 63 | if (*ostr == ':') |
| 64 | return (BADARGcxx . . $ `cstool/getopt.c:13:9`!); |
| 65 | if (opterrcxx . . $ opterr.) |
| 66 | (void)printfcxx . . $ printf(581fddd72a8db8fc). ("option requires an argument -- %c\n", optoptcxx . . $ optopt.); |
| 67 | return (BADCHcxx . . $ `cstool/getopt.c:12:9`!); |
| 68 | } else /* white space */ |
| 69 | optargcxx . . $ optarg. = nargv[optindcxx . . $ optind.]; |
| 70 | place = EMSGcxx . . $ `cstool/getopt.c:14:9`!; |
| 71 | ++optindcxx . . $ optind.; |
| 72 | } |
| 73 | |
| 74 | return optoptcxx . . $ optopt.; /* dump back option letter */ |
| 75 | } |
| 76 |