]> granicus.if.org Git - php/commitdiff
MFB: sync getopt from CLI
authorfoobar <sniper@php.net>
Sun, 15 Apr 2007 22:54:26 +0000 (22:54 +0000)
committerfoobar <sniper@php.net>
Sun, 15 Apr 2007 22:54:26 +0000 (22:54 +0000)
sapi/cgi/getopt.c
sapi/cgi/php_getopt.h

index 82e90ed95f94ca536ba11e4147365b52fe716f9c..963c4554e1ace31908c7e2d3972fe45f87d98ea9 100644 (file)
@@ -16,6 +16,8 @@
    +----------------------------------------------------------------------+
 */
 
+/* $Id$ */
+
 #include <stdio.h>
 #include <string.h>
 #include <assert.h>
@@ -77,29 +79,34 @@ int php_getopt(int argc, char* const *argv, const opt_struct opts[], char **opta
        }
        if ((argv[*optind][0] == '-') && (argv[*optind][1] == '-')) {
                /* '--' indicates end of args if not followed by a known long option name */
+               if (argv[*optind][2] == '\0') {
+                       (*optind)++;
+                       return(EOF);
+               }
+
                while (1) {
                        opts_idx++;
                        if (opts[opts_idx].opt_char == '-') {
                                (*optind)++;
-                               return(EOF);
+                               return(php_opt_error(argc, argv, *optind-1, optchr, OPTERRARG, show_err));
                        } else if (opts[opts_idx].opt_name && !strcmp(&argv[*optind][2], opts[opts_idx].opt_name)) {
                                break;
                        }
                }
                optchr = 0;
-               dash = 1;
-               arg_start = 2 + strlen(opts[opts_idx].opt_name);
-       }
-       if (!dash) {
-               dash = 1;
-               optchr = 1;
-       }
-
-       /* Check if the guy tries to do a -: kind of flag */
-       if (argv[*optind][optchr] == ':') {
                dash = 0;
-               (*optind)++;
-               return (php_opt_error(argc, argv, *optind-1, optchr, OPTERRCOLON, show_err));
+               arg_start = 2 + strlen(opts[opts_idx].opt_name);
+       } else {
+               if (!dash) {
+                       dash = 1;
+                       optchr = 1;
+               }
+               /* Check if the guy tries to do a -: kind of flag */
+               if (argv[*optind][optchr] == ':') {
+                       dash = 0;
+                       (*optind)++;
+                       return (php_opt_error(argc, argv, *optind-1, optchr, OPTERRCOLON, show_err));
+               }
        }
        if (opts_idx < 0) {
                while (1) {
index 4bfa4339770636e70c16b2fd946f82cf26bddeca..fc14c967437b096e8a996932716225c3704d8b93 100644 (file)
    +----------------------------------------------------------------------+
 */
 
+/* $Id$ */
+
 #include "php.h"
 
+#ifdef NETWARE
+/*
+As NetWare LibC has optind and optarg macros defined in unistd.h our local variables were getting mistakenly preprocessed so undeffing optind and optarg
+*/
+#undef optarg
+#undef optind
+#endif
 /* Define structure for one recognized option (both single char and long name).
  * If short_open is '-' this is the last option.
  */