57 static int optchr = 0;
59 static char **prev_optarg =
NULL;
63 if(prev_optarg && prev_optarg != optarg) {
70 if (*optind >= argc) {
74 if ((argv[*optind][0] !=
'-')) {
77 if (!argv[*optind][1])
87 if ((argv[*optind][0] ==
'-') && (argv[*optind][1] ==
'-')) {
89 size_t arg_end =
strlen(argv[*optind])-1;
92 if (argv[*optind][2] ==
'\0') {
100 if ((
pos = memchr(&argv[*optind][arg_start],
'=', arg_end - arg_start)) !=
NULL) {
101 arg_end =
pos-&argv[*optind][arg_start];
111 return(php_opt_error(argc, argv, *optind-1, optchr,
OPTERRARG, show_err));
126 if (argv[*optind][optchr] ==
':') {
129 return (php_opt_error(argc, argv, *optind-1, optchr,
OPTERRCOLON, show_err));
131 arg_start = 1 + optchr;
137 int errind = *optind;
140 if (!argv[*optind][optchr+1]) {
147 return(php_opt_error(argc, argv, errind, errchr,
OPTERRNF, show_err));
148 }
else if (argv[*optind][optchr] == opts[
php_optidx].opt_char) {
157 if (!argv[*optind][arg_start]) {
159 if (*optind == argc) {
162 return(php_opt_error(argc, argv, *optind-1, optchr,
OPTERRARG, show_err));
165 }
else if (opts[
php_optidx].need_param == 1) {
166 *optarg = argv[(*optind)++];
168 }
else if (argv[*optind][arg_start] ==
'=') {
170 *optarg = &argv[*optind][arg_start];
173 *optarg = &argv[*optind][arg_start];
179 if (arg_start >= 2 && !((argv[*optind][0] ==
'-') && (argv[*optind][1] ==
'-'))) {
180 if (!argv[*optind][optchr+1])
PHPAPI int php_getopt(int argc, char *const *argv, const opt_struct opts[], char **optarg, int *optind, int show_err, int arg_start)