diff options
author | James Moore <jmoore@php.net> | 2001-05-17 21:32:05 +0000 |
---|---|---|
committer | James Moore <jmoore@php.net> | 2001-05-17 21:32:05 +0000 |
commit | 873d59a8ea7490acfe4d5c85ff205bde4df4a8d3 (patch) | |
tree | 68a1b1c0678a4e009c7306e136fbd165e59e0b9d | |
parent | 73f04651fad54ab396d6c9edf6597043e8344448 (diff) | |
download | php-git-873d59a8ea7490acfe4d5c85ff205bde4df4a8d3.tar.gz |
@ - Fixed getopt so it accepts arguments in the form -<option><value> not
@ just -<option> <value> (jmoore)
-rw-r--r-- | sapi/cgi/getopt.c | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/sapi/cgi/getopt.c b/sapi/cgi/getopt.c index 4d9187ba8e..a20341eef2 100644 --- a/sapi/cgi/getopt.c +++ b/sapi/cgi/getopt.c @@ -10,6 +10,7 @@ #define OPTERRARG (3) +char buff[81]; /* too hold option value when needed */ char *ap_php_optarg; int ap_php_optind = 1; static int ap_php_opterr = 1; @@ -98,11 +99,25 @@ int ap_php_getopt(int argc, char* const *argv, const char *optstr) } if (cp[1] == ':') { + /* Check for cases where the value of the argument + is in the form -<arg> <val> or in the form -<arg><val> */ dash = 0; - ap_php_optind++; - if (ap_php_optind == argc) - return(ap_php_optiserr(argc, argv, ap_php_optind-1, optstr, optchr, OPTERRARG)); - ap_php_optarg = argv[ap_php_optind++]; + if(!argv[ap_php_optind][2]) { + ap_php_optind++; + if (ap_php_optind == argc) + return(ap_php_optiserr(argc, argv, ap_php_optind-1, optstr, optchr, OPTERRARG)); + ap_php_optarg = argv[ap_php_optind++]; + } + else + { + int offset = 2; + int len = 0; + while(argv[ap_php_optind][offset]) { + buff[len++] = argv[ap_php_optind][offset++]; + } + ap_php_optarg = buff; + ap_php_optind++; + } return(*cp); } else |