]> granicus.if.org Git - php/commitdiff
@ - Fixed getopt so it accepts arguments in the form -<option><value> not
authorJames Moore <jmoore@php.net>
Thu, 17 May 2001 21:32:05 +0000 (21:32 +0000)
committerJames Moore <jmoore@php.net>
Thu, 17 May 2001 21:32:05 +0000 (21:32 +0000)
@   just -<option> <value> (jmoore)

sapi/cgi/getopt.c

index 4d9187ba8e8c330167e659bf0b9a41ac1a58a991..a20341eef253886756b0eed6311ef160784bb63c 100644 (file)
@@ -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