mirror of
https://github.com/MariaDB/server.git
synced 2025-01-22 23:04:20 +01:00
2d037dc6cc
git-svn-id: file:///svn/toku/tokudb@10480 c7de825b-a66e-492c-adef-691d508d4ae1
49 lines
1,007 B
C
49 lines
1,007 B
C
#include <unistd.h>
|
|
|
|
char *optarg;
|
|
int optind;
|
|
|
|
static const char *match(char c, const char *optstring) {
|
|
int i;
|
|
for (i=0;optstring[i]; i++)
|
|
if (c == optstring[i])
|
|
return &optstring[i];
|
|
return 0;
|
|
}
|
|
|
|
int getopt(int argc, char * const argv[], const char *optstring) {
|
|
static int lastargc = 0;
|
|
char *arg;
|
|
const char *theopt;
|
|
if (lastargc == 0) {
|
|
lastargc = 1;
|
|
optind = 1;
|
|
}
|
|
optarg = 0;
|
|
if (lastargc >= argc) {
|
|
lastargc = 0;
|
|
return -1;
|
|
}
|
|
arg = argv[lastargc++];
|
|
if (arg[0] != '-') {
|
|
lastargc = 0;
|
|
return -1;
|
|
}
|
|
theopt = match(arg[1], optstring);
|
|
if (!theopt) {
|
|
lastargc = 0;
|
|
return -1;
|
|
}
|
|
if (theopt[1] == ':') {
|
|
if (arg[2])
|
|
optarg = &arg[2];
|
|
else if (lastargc >= argc) {
|
|
lastargc = 0;
|
|
return -1;
|
|
} else
|
|
optarg = argv[lastargc++];
|
|
}
|
|
optind = lastargc;
|
|
return theopt[0];
|
|
}
|
|
|