int optind = 1;
int optopt;
char *optarg;
int getopt(int argc, char *const argv[], const char *optstring)
{
static int optchr = 1;
char *cp;
if (optchr == 1) {
if (optind >= argc) {
/* all arguments processed */
return EOF;
}
if (argv[optind][0] != '-' || argv[optind][1] == '\0') {
/* no option characters */
return EOF;
}
}
if (os_strcmp(argv[optind], "--") == 0) {
/* no more options */
optind++;
return EOF;
}
optopt = argv[optind][optchr];
cp ......
阅读全文