jani            Mon Oct  1 12:32:39 2007 UTC

  Added files:                 
    /php-src/main       getopt.c php_getopt.h 

  Removed files:               
    /php-src/sapi/cgi   getopt.c php_getopt.h 
    /php-src/sapi/cli   getopt.c php_getopt.h 

  Modified files:              
    /php-src    configure.in 
    /php-src/ext/standard       basic_functions.c config.m4 
    /php-src/sapi/cgi   cgi_main.c config.w32 config9.m4 
    /php-src/sapi/cli   config.w32 php_cli.c 
    /php-src/win32/build        config.w32 
  Log:
  - Added common getopt implementation to core.
  - Added long-option feature to getopt().
  - Made getopt() available on win32 systems.
  Patch by: David Soria Parra <[EMAIL PROTECTED]>
  [DOC]: These changes will be available from 5.3+
  
  
http://cvs.php.net/viewvc.cgi/php-src/configure.in?r1=1.640&r2=1.641&diff_format=u
Index: php-src/configure.in
diff -u php-src/configure.in:1.640 php-src/configure.in:1.641
--- php-src/configure.in:1.640  Mon Aug 20 14:28:29 2007
+++ php-src/configure.in        Mon Oct  1 12:32:39 2007
@@ -1,4 +1,4 @@
-## $Id: configure.in,v 1.640 2007/08/20 14:28:29 jani Exp $ -*- autoconf -*-
+## $Id: configure.in,v 1.641 2007/10/01 12:32:39 jani Exp $ -*- autoconf -*-
 dnl ## Process this file with autoconf to produce a configure script.
 
 divert(1)
@@ -1054,7 +1054,7 @@
 if test "$PHP_CLI" != "no"; then
   PHP_CLI_TARGET="\$(SAPI_CLI_PATH)"
   PHP_INSTALL_CLI_TARGET="install-cli"
-  PHP_ADD_SOURCES(sapi/cli, php_cli.c php_cli_readline.c getopt.c,, cli)
+  PHP_ADD_SOURCES(sapi/cli, php_cli.c php_cli_readline.c,, cli)
   PHP_INSTALLED_SAPIS="cli $PHP_SAPI"
 else
   PHP_INSTALLED_SAPIS="$PHP_SAPI"
@@ -1208,7 +1208,7 @@
        php_ini.c SAPI.c rfc1867.c php_content_types.c strlcpy.c \
        strlcat.c mergesort.c reentrancy.c php_variables.c php_ticks.c \
        network.c php_open_temporary_file.c php_logos.c \
-       output.c )
+       output.c getopt.c)
 
 PHP_ADD_SOURCES(main/streams, streams.c cast.c memory.c filter.c \
        plain_wrapper.c userspace.c transports.c xp_socket.c mmap.c \
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/basic_functions.c?r1=1.876&r2=1.877&diff_format=u
Index: php-src/ext/standard/basic_functions.c
diff -u php-src/ext/standard/basic_functions.c:1.876 
php-src/ext/standard/basic_functions.c:1.877
--- php-src/ext/standard/basic_functions.c:1.876        Fri Sep 28 13:06:22 2007
+++ php-src/ext/standard/basic_functions.c      Mon Oct  1 12:32:39 2007
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: basic_functions.c,v 1.876 2007/09/28 13:06:22 jani Exp $ */
+/* $Id: basic_functions.c,v 1.877 2007/10/01 12:32:39 jani Exp $ */
 
 #include "php.h"
 #include "php_streams.h"
@@ -28,6 +28,7 @@
 #include "php_math.h"
 #include "php_http.h"
 #include "php_incomplete_class.h"
+#include "php_getopt.h"
 #include "ext/standard/info.h"
 #include "ext/session/php_session.h"
 #include "zend_operators.h"
@@ -83,10 +84,6 @@
 # include <sys/loadavg.h>
 #endif
 
-#ifdef HARTMUT_0
-#include <getopt.h>
-#endif
-
 #ifdef PHP_WIN32
 # include "win32/unistd.h"
 #endif
@@ -100,7 +97,6 @@
 #include "SAPI.h"
 #include "php_ticks.h"
 
-
 #ifdef ZTS
 PHPAPI int basic_globals_id;
 #else
@@ -725,13 +721,11 @@
 ZEND_END_ARG_INFO()
 #endif
 
-#ifdef HAVE_GETOPT
 static
 ZEND_BEGIN_ARG_INFO_EX(arginfo_getopt, 0, 0, 1)
        ZEND_ARG_INFO(0, options)
        ZEND_ARG_INFO(0, opts) /* ARRAY_INFO(0, opts, 1) */
 ZEND_END_ARG_INFO()
-#endif
 
 static
 ZEND_BEGIN_ARG_INFO(arginfo_flush, 0)
@@ -3128,7 +3122,7 @@
        PHP_FE(iptcembed,                                                       
                                                        arginfo_iptcembed)
        PHP_FE(getimagesize,                                                    
                                                arginfo_getimagesize)
        PHP_FE(image_type_to_mime_type,                                         
                                        arginfo_image_type_to_mime_type)
-       PHP_FE(image_type_to_extension,                                         
                                        arginfo_image_type_to_extension)
+       PHP_FE(image_type_to_extension,                                         
                                        arginfo_image_type_to_extension)
 
        PHP_FE(phpinfo,                                                         
                                                        arginfo_phpinfo)
        PHP_FE(phpversion,                                                      
                                                        arginfo_phpversion)
@@ -3178,7 +3172,7 @@
 #endif
 
 #ifdef HAVE_STRFMON
-       PHP_FE(money_format,                                                    
arginfo_money_format)
+       PHP_FE(money_format,                                                    
                                                arginfo_money_format)
 #endif
 
        PHP_FE(substr,                                                          
                                                        arginfo_substr)
@@ -3359,9 +3353,7 @@
        PHP_FE(putenv,                                                          
                                                        arginfo_putenv)
 #endif
 
-#ifdef HAVE_GETOPT
        PHP_FE(getopt,                                                          
                                                        arginfo_getopt)
-#endif
 
 #ifdef HAVE_GETLOADAVG
        PHP_FE(sys_getloadavg,                                                  
                                                arginfo_sys_getloadavg)
@@ -3408,7 +3400,7 @@
        PHP_FE(unregister_tick_function,                                        
                                        arginfo_unregister_tick_function)
 
        PHP_FE(highlight_file,                                                  
                                                arginfo_highlight_file)
-       PHP_FALIAS(show_source,                 highlight_file,                 
                                arginfo_highlight_file)
+       PHP_FALIAS(show_source,                 highlight_file,                 
                                arginfo_highlight_file)
        PHP_FE(highlight_string,                                                
                                                arginfo_highlight_string)
        PHP_FE(php_strip_whitespace,                                            
                                        arginfo_php_strip_whitespace)
 
@@ -3424,7 +3416,7 @@
        PHP_FE(setcookie,                                                       
                                                        arginfo_setcookie)
        PHP_FE(setrawcookie,                                                    
                                                arginfo_setrawcookie)
        PHP_FE(header,                                                          
                                                        arginfo_header)
-       PHP_FE(headers_sent,                                                    
                                                arginfo_headers_sent)
+       PHP_FE(headers_sent,                                                    
                                                arginfo_headers_sent)
        PHP_FE(headers_list,                                                    
                                                arginfo_headers_list)
 
        PHP_FE(connection_aborted,                                              
                                                arginfo_connection_aborted)
@@ -3447,7 +3439,7 @@
        PHP_FALIAS(checkdnsrr,                  dns_check_record,               
                                arginfo_dns_check_record)
 # if HAVE_DN_SKIPNAME && HAVE_DN_EXPAND
        PHP_FE(dns_get_mx,                                                      
                                                        arginfo_dns_get_mx)
-       PHP_FALIAS(getmxrr,                     dns_get_mx,                     
                                arginfo_dns_get_mx)
+       PHP_FALIAS(getmxrr,                             dns_get_mx,             
                                                arginfo_dns_get_mx)
 # endif
 # if HAVE_DNS_FUNCS
        PHP_FE(dns_get_record,                                                  
                                                arginfo_dns_get_record)
@@ -3457,7 +3449,7 @@
        /* functions from type.c */
        PHP_FE(intval,                                                          
                                                        arginfo_intval)
        PHP_FE(floatval,                                                        
                                                        arginfo_floatval)
-       PHP_FALIAS(doubleval,          floatval,                                
                                arginfo_floatval)
+       PHP_FALIAS(doubleval,                   floatval,                       
                                        arginfo_floatval)
        PHP_FE(strval,                                                          
                                                        arginfo_strval)
        PHP_FE(gettype,                                                         
                                                        arginfo_gettype)
        PHP_FE(settype,                                                         
                                                        arginfo_settype)
@@ -3754,7 +3746,7 @@
 
        /* aliases from array.c */
        PHP_FALIAS(pos,                                 current,                
                                                arginfo_current)
-       PHP_FALIAS(sizeof,                              count,                  
                                                arginfo_count)
+       PHP_FALIAS(sizeof,                              count,                  
                                                arginfo_count)
        PHP_FALIAS(key_exists,                  array_key_exists,               
                                arginfo_array_key_exists)
 
        /* functions from assert.c */
@@ -3769,9 +3761,9 @@
        PHP_FE(ftok,                                                            
                                                        arginfo_ftok)
 #endif
 
-       PHP_FE(str_rot13,                                                       
                                                        arginfo_str_rot13)
-       PHP_FE(stream_get_filters,                                              
                                                arginfo_stream_get_filters)
-       PHP_FE(stream_filter_register,                                          
                                        arginfo_stream_filter_register)
+       PHP_FE(str_rot13,                                                       
                                                        arginfo_str_rot13)
+       PHP_FE(stream_get_filters,                                              
                                                arginfo_stream_get_filters)
+       PHP_FE(stream_filter_register,                                          
                                        arginfo_stream_filter_register)
        PHP_FE(stream_bucket_make_writeable,                                    
                                arginfo_stream_bucket_make_writeable)
        PHP_FE(stream_bucket_prepend,                                           
                                        arginfo_stream_bucket_prepend)
        PHP_FE(stream_bucket_append,                                            
                                        arginfo_stream_bucket_append)
@@ -4432,7 +4424,6 @@
 /* }}} */
 #endif
 
-#ifdef HAVE_GETOPT
 /* {{{ free_argv()
    Free the memory allocated to an argv array. */
 static void free_argv(char **argv, int argc)
@@ -4450,23 +4441,54 @@
 }
 /* }}} */
 
-#ifdef HARTMUT_0
 /* {{{ free_longopts()
    Free the memory allocated to an longopt array. */
-static void free_longopts(struct option *longopts)
+static void free_longopts(opt_struct *longopts)
 {
-       struct option *p;
+       opt_struct *p;
 
        if (longopts) {
-               for (p = longopts; p->name; p++) {
-                       efree((char *)(p->name));
+               for (p = longopts; p && p->opt_char != '-'; p++) {
+                       if (p->opt_name != NULL) {
+                               efree((char *)(p->opt_name));
+                       }
+               }
+       }
+}
+/* }}} */
+
+/* {{{ parse_opts()
+   Convert the typical getopt input characters to the php_getopt struct array 
*/
+static int parse_opts(char * opts, opt_struct ** result)
+{
+       opt_struct * paras = NULL;
+       int i, count = 0;
+
+       for (i = 0; i < strlen(opts); i++) {
+               if ((opts[i] >= 65 && opts[i] <= 90) ||
+                       (opts[i] >= 97 && opts[i] <= 122)
+               ) {
+                       count++;
                }
+       }
 
-               efree(longopts);
+       paras = safe_emalloc(sizeof(opt_struct), count, 0);
+       memset(paras, 0, sizeof(opt_struct) * count);
+       *result = paras;
+       while ( (*opts >= 65 && *opts <= 90) ||
+                       (*opts >= 97 && *opts <= 122)
+       ) {
+               paras->opt_char = *opts;
+               paras->need_param = (*(++opts) == ':') ? 1 : 0;
+               paras->opt_name = NULL;
+               if (paras->need_param == 1) {
+                       opts++;
+               }
+               paras++;
        }
+       return count;
 }
 /* }}} */
-#endif
 
 /* {{{ proto array getopt(string options [, array longopts]) U
    Get options from the command line argument list */
@@ -4475,13 +4497,12 @@
        char *options = NULL, **argv = NULL;
        char opt[2] = { '\0' };
        char *optname;
-       int argc = 0, options_len = 0, o;
+       int argc = 0, options_len = 0, len, o;
+       char *php_optarg = NULL;
+       int php_optind = 1;
        zval *val, **args = NULL, *p_longopts = NULL;
        int optname_len = 0;
-#ifdef HARTMUT_0
-       struct option *longopts = NULL;
-       int longindex = 0;
-#endif
+       opt_struct *opts, *orig_opts;
 
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|a", &options, 
&options_len, &p_longopts) == FAILURE) {
                RETURN_FALSE;
@@ -4519,65 +4540,64 @@
                RETURN_FALSE;
        }
 
+       len = parse_opts(options, &opts);
+
        if (p_longopts) {
-#ifdef HARTMUT_0
-               int len, c = zend_hash_num_elements(Z_ARRVAL_P(p_longopts));
-               struct option *p;
+               int count;
                zval **arg;
-               char *name;
 
-               longopts = (struct option *)ecalloc(c+1, sizeof(struct option));
+               count = zend_hash_num_elements(Z_ARRVAL_P(p_longopts));
+               
+               /* the first <len> slots are filled by the one short ops
+                * we now extend our array and jump to the new added structs */
+               opts = (opt_struct *) erealloc(opts, sizeof(opt_struct) * (len 
+ count + 1));
+        orig_opts = opts;
+        opts += len;
 
-               if (!longopts) {
+        memset(opts, 0, count * sizeof(opt_struct));
+
+               if (!opts) {
                        RETURN_FALSE;
                }
 
                /* Reset the array indexes. */
                zend_hash_internal_pointer_reset(Z_ARRVAL_P(p_longopts));
-               p = longopts;
 
                /* Iterate over the hash to construct the argv array. */
                while (zend_hash_get_current_data(Z_ARRVAL_P(p_longopts), (void 
**)&arg) == SUCCESS) {
-
-                       p->has_arg = 0;
-                       name = estrdup(Z_STRVAL_PP(arg));
-                       len = strlen(name);
-                       if ((len > 0) && (name[len-1] == ':')) {
-                               p->has_arg++;
-                               name[len-1] = '\0';
-                               if ((len > 1) && (name[len-2] == ':')) {
-                                       p->has_arg++;
-                                       name[len-2] = '\0';
+                       opts->need_param = 0;
+                       opts->opt_name = estrdup(Z_STRVAL_PP(arg));
+                       len = strlen(opts->opt_name);
+                       if ((len > 0) && (opts->opt_name[len-1] == ':')) {
+                               opts->need_param++;
+                               opts->opt_name[len-1] = '\0';
+                               if ((len > 1) && (opts->opt_name[len-2] == 
':')) {
+                                       opts->need_param++;
+                                       opts->opt_name[len-2] = '\0';
                                }
                        }
-
-                       p->name = name;
-                       p->flag = NULL;
-                       p->val = 0;
-
+                       opts->opt_char = 0;
+                       opts++;
                        zend_hash_move_forward(Z_ARRVAL_P(p_longopts));
-                       p++;
                }
-#else
-               php_error_docref(NULL TSRMLS_CC, E_WARNING, "No support for 
long options in this build");
-#endif
+       } else {
+               opts = (opt_struct*) erealloc(opts, sizeof(opt_struct) * (len + 
1));
+               orig_opts = opts;
+               opts += len;
        }
 
+       /* php_getopt want to identify the last param */
+       opts->opt_char   = '-';
+       opts->need_param = 0;
+       opts->opt_name   = NULL;
+
        /* Initialize the return value as an array. */
        array_init(return_value);
 
-       /* Disable getopt()'s error messages. */
-       opterr = 0;
-
-       /* Force reinitialization of getopt() (via optind reset) on every call. 
*/
-       optind = 1;
+       /* after our pointer arithmetic jump back to the first element */
+       opts = orig_opts;
 
-       /* Invoke getopt(3) on the argument array. */
-#ifdef HARTMUT_0
-       while ((o = getopt_long(argc, argv, options, longopts, &longindex)) != 
-1) {
-#else
-       while ((o = getopt(argc, argv, options)) != -1) {
-#endif
+       while ((o = php_getopt(argc, argv, opts, &php_optarg, &php_optind, 0, 
1)) != -1) {
                /* Skip unknown arguments. */
                if (o == '?') {
                        continue;
@@ -4585,12 +4605,7 @@
 
                /* Prepare the option character and the argument string. */
                if (o == 0) {
-#ifdef HARTMUT_0
-                       optname = (char *)longopts[longindex].name;
-#else
-                       /* o == 0 shall never happen so this only fixes a 
compiler warning */
-                       optname = NULL;
-#endif
+                       optname = opts[php_optidx].opt_name;
                } else {
                        if (o == 1) {
                                o = '-';
@@ -4600,9 +4615,9 @@
                }
 
                MAKE_STD_ZVAL(val);
-               if (optarg != NULL) {
+               if (php_optarg != NULL) {
                        /* keep the arg as binary, since the encoding is not 
known */
-                       ZVAL_STRING(val, optarg, 1);
+                       ZVAL_STRING(val, php_optarg, 1);
                } else {
                        ZVAL_FALSE(val);
                }
@@ -4631,15 +4646,15 @@
                                zend_hash_add(HASH_OF(return_value), optname, 
strlen(optname)+1, (void *)&val, sizeof(zval *), NULL);
                        }
                }
+
+               php_optarg = NULL;
        }
 
+       free_longopts(orig_opts);
+       efree(orig_opts);
        free_argv(argv, argc);
-#ifdef HARTMUT_0
-       free_longopts(longopts);
-#endif
 }
 /* }}} */
-#endif
 
 /* {{{ proto void flush(void) U
    Flush the output buffer */
@@ -5746,9 +5761,9 @@
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") == FAILURE) {
                return;
        }
-       
+
        str = zend_ini_string("include_path", sizeof("include_path"), 0);
-       
+
        if (str == NULL) {
                RETURN_FALSE;
        }
@@ -6294,7 +6309,7 @@
        }
 
        if (hash_key->nKeyLength) {
-               php_prefix_varname(&new_key, prefix, hash_key->arKey, 
hash_key->nKeyLength-1, hash_key->type, 0 TSRMLS_CC);
+               php_prefix_varname(&new_key, prefix, hash_key->arKey, 
hash_key->nKeyLength - 1, hash_key->type, 0 TSRMLS_CC);
        } else {
                zval num;
                ZVAL_LONG(&num, hash_key->h);
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/config.m4?r1=1.87&r2=1.88&diff_format=u
Index: php-src/ext/standard/config.m4
diff -u php-src/ext/standard/config.m4:1.87 php-src/ext/standard/config.m4:1.88
--- php-src/ext/standard/config.m4:1.87 Sun Jul 15 19:50:06 2007
+++ php-src/ext/standard/config.m4      Mon Oct  1 12:32:39 2007
@@ -1,4 +1,4 @@
-dnl $Id: config.m4,v 1.87 2007/07/15 19:50:06 jani Exp $ -*- autoconf -*-
+dnl $Id: config.m4,v 1.88 2007/10/01 12:32:39 jani Exp $ -*- autoconf -*-
 
 divert(3)dnl
 
@@ -251,12 +251,6 @@
   AC_MSG_RESULT(no)
 fi
 
-dnl getopt long options disabled for now
-dnl as we can't be sure that we get the right getopt.h here
-dnl using the standard AC_CHECK macros
-dnl AC_CHECK_HEADERS(getopt.h)
-dnl AC_CHECK_FUNCS(getopt_long getopt_long_only)
-
 if test "$PHP_SAPI" = "cgi" || test "$PHP_SAPI" = "cli" || test "$PHP_SAPI" = 
"embed"; then
   AC_DEFINE(ENABLE_CHROOT_FUNC, 1, [Whether to enable chroot() function])
 fi
http://cvs.php.net/viewvc.cgi/php-src/sapi/cgi/cgi_main.c?r1=1.339&r2=1.340&diff_format=u
Index: php-src/sapi/cgi/cgi_main.c
diff -u php-src/sapi/cgi/cgi_main.c:1.339 php-src/sapi/cgi/cgi_main.c:1.340
--- php-src/sapi/cgi/cgi_main.c:1.339   Fri Sep 28 02:04:28 2007
+++ php-src/sapi/cgi/cgi_main.c Mon Oct  1 12:32:39 2007
@@ -21,7 +21,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: cgi_main.c,v 1.339 2007/09/28 02:04:28 jani Exp $ */
+/* $Id: cgi_main.c,v 1.340 2007/10/01 12:32:39 jani Exp $ */
 
 #include "php.h"
 #include "php_globals.h"
@@ -1319,7 +1319,7 @@
                }
        }
 
-       while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 
0)) != -1) {
+       while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 
0, 2)) != -1) {
                switch (c) {
                        case 'c':
                                if (cgi_sapi_module.php_ini_path_override) {
@@ -1541,7 +1541,7 @@
        }
 
        zend_first_try {
-               while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, 
&php_optind, 1)) != -1) {
+               while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, 
&php_optind, 1, 2)) != -1) {
                        switch (c) {
                                case 'h':
                                case '?':
@@ -1581,7 +1581,7 @@
                                        goto out;
                                }
 
-                               while ((c = php_getopt(argc, argv, OPTIONS, 
&php_optarg, &php_optind, 0)) != -1) {
+                               while ((c = php_getopt(argc, argv, OPTIONS, 
&php_optarg, &php_optind, 0, 2)) != -1) {
                                        switch (c) {
 
                                                case 'a':       /* interactive 
mode */
http://cvs.php.net/viewvc.cgi/php-src/sapi/cgi/config.w32?r1=1.4&r2=1.5&diff_format=u
Index: php-src/sapi/cgi/config.w32
diff -u php-src/sapi/cgi/config.w32:1.4 php-src/sapi/cgi/config.w32:1.5
--- php-src/sapi/cgi/config.w32:1.4     Sun Dec 25 12:45:01 2005
+++ php-src/sapi/cgi/config.w32 Mon Oct  1 12:32:39 2007
@@ -1,9 +1,9 @@
 // vim:ft=javascript
-// $Id: config.w32,v 1.4 2005/12/25 12:45:01 zeev Exp $
+// $Id: config.w32,v 1.5 2007/10/01 12:32:39 jani Exp $
 
 ARG_ENABLE('cgi', 'Build CGI version of PHP', 'yes');
 
 if (PHP_CGI == "yes") {
-       SAPI('cgi', 'cgi_main.c getopt.c fastcgi.c', 'php-cgi.exe');
+       SAPI('cgi', 'cgi_main.c ..\\..\\main\\getopt.c fastcgi.c', 
'php-cgi.exe');
        ADD_FLAG('LIBS_CGI', 'ws2_32.lib kernel32.lib advapi32.lib');
 }
http://cvs.php.net/viewvc.cgi/php-src/sapi/cgi/config9.m4?r1=1.24&r2=1.25&diff_format=u
Index: php-src/sapi/cgi/config9.m4
diff -u php-src/sapi/cgi/config9.m4:1.24 php-src/sapi/cgi/config9.m4:1.25
--- php-src/sapi/cgi/config9.m4:1.24    Wed Jul 11 23:10:14 2007
+++ php-src/sapi/cgi/config9.m4 Mon Oct  1 12:32:39 2007
@@ -1,5 +1,5 @@
 dnl
-dnl $Id: config9.m4,v 1.24 2007/07/11 23:10:14 jani Exp $
+dnl $Id: config9.m4,v 1.25 2007/10/01 12:32:39 jani Exp $
 dnl
 
 PHP_ARG_ENABLE(cgi,,
@@ -50,7 +50,7 @@
     PHP_SUBST(SAPI_CGI_PATH)
 
     INSTALL_IT="@echo \"Installing PHP CGI binary: 
\$(INSTALL_ROOT)\$(bindir)/\"; \$(INSTALL) -m 0755 \$(SAPI_CGI_PATH) 
\$(INSTALL_ROOT)\$(bindir)/\$(program_prefix)php-cgi\$(program_suffix)\$(EXEEXT)"
-    PHP_SELECT_SAPI(cgi, program, fastcgi.c cgi_main.c getopt.c, , 
'$(SAPI_CGI_PATH)')
+    PHP_SELECT_SAPI(cgi, program, fastcgi.c cgi_main.c, , '$(SAPI_CGI_PATH)')
 
     case $host_alias in
       *aix*)
http://cvs.php.net/viewvc.cgi/php-src/sapi/cli/config.w32?r1=1.4&r2=1.5&diff_format=u
Index: php-src/sapi/cli/config.w32
diff -u php-src/sapi/cli/config.w32:1.4 php-src/sapi/cli/config.w32:1.5
--- php-src/sapi/cli/config.w32:1.4     Sat May 14 19:33:18 2005
+++ php-src/sapi/cli/config.w32 Mon Oct  1 12:32:39 2007
@@ -1,18 +1,18 @@
 // vim:ft=javascript
-// $Id: config.w32,v 1.4 2005/05/14 19:33:18 helly Exp $
+// $Id: config.w32,v 1.5 2007/10/01 12:32:39 jani Exp $
 
 ARG_ENABLE('cli', 'Build CLI version of PHP', 'yes');
 ARG_ENABLE('crt-debug', 'Extra CRT debugging', 'no');
 ARG_ENABLE('cli-win32', 'Build console-less CLI version of PHP', 'no');
 
 if (PHP_CLI == "yes") {
-       SAPI('cli', 'getopt.c php_cli.c php_cli_readline.c', 'php.exe');
+       SAPI('cli', '..\\..\\main\\getopt.c php_cli.c php_cli_readline.c', 
'php.exe');
        if (PHP_CRT_DEBUG == "yes") {
                ADD_FLAG("CFLAGS_CLI", "/D PHP_WIN32_DEBUG_HEAP");
        }
 }
 
 if (PHP_CLI_WIN32 == "yes") {
-       SAPI('cli_win32', 'getopt.c cli_win32.c php_cli_readline.c', 
'php-win.exe');
+       SAPI('cli_win32', '..\\..\\main\\getopt.c cli_win32.c 
php_cli_readline.c', 'php-win.exe');
 }
 
http://cvs.php.net/viewvc.cgi/php-src/sapi/cli/php_cli.c?r1=1.181&r2=1.182&diff_format=u
Index: php-src/sapi/cli/php_cli.c
diff -u php-src/sapi/cli/php_cli.c:1.181 php-src/sapi/cli/php_cli.c:1.182
--- php-src/sapi/cli/php_cli.c:1.181    Thu Sep 27 18:28:43 2007
+++ php-src/sapi/cli/php_cli.c  Mon Oct  1 12:32:39 2007
@@ -20,7 +20,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: php_cli.c,v 1.181 2007/09/27 18:28:43 dmitry Exp $ */
+/* $Id: php_cli.c,v 1.182 2007/10/01 12:32:39 jani Exp $ */
 
 #include "php.h"
 #include "php_globals.h"
@@ -666,7 +666,7 @@
        memcpy(cli_sapi_module.ini_entries, HARDCODED_INI, ini_entries_len+1);
        cli_sapi_module.ini_entries[ini_entries_len+1] = 0;
 
-       while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 
0))!=-1) {
+       while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 
0, 2))!=-1) {
                switch (c) {
                        case 'c':
                                if (cli_sapi_module.php_ini_path_override) {
@@ -738,7 +738,7 @@
                        goto err;
                }
 
-               while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, 
&php_optind, 0)) != -1) {
+               while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, 
&php_optind, 0, 2)) != -1) {
                        switch (c) {
 
                        case 'h': /* help & quit */
@@ -809,7 +809,7 @@
 
                php_optind = orig_optind;
                php_optarg = orig_optarg;
-               while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, 
&php_optind, 0)) != -1) {
+               while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, 
&php_optind, 0, 2)) != -1) {
                        switch (c) {
 
                        case 'a':       /* interactive mode */
http://cvs.php.net/viewvc.cgi/php-src/win32/build/config.w32?r1=1.68&r2=1.69&diff_format=u
Index: php-src/win32/build/config.w32
diff -u php-src/win32/build/config.w32:1.68 php-src/win32/build/config.w32:1.69
--- php-src/win32/build/config.w32:1.68 Sun Jul 15 19:50:07 2007
+++ php-src/win32/build/config.w32      Mon Oct  1 12:32:39 2007
@@ -1,5 +1,5 @@
 // vim:ft=javascript
-// $Id: config.w32,v 1.68 2007/07/15 19:50:07 jani Exp $
+// $Id: config.w32,v 1.69 2007/10/01 12:32:39 jani Exp $
 // "Master" config file; think of it as a configure.in
 // equivalent.
 
@@ -324,7 +324,8 @@
 ADD_SOURCES("main", "main.c snprintf.c spprintf.c fopen_wrappers.c \
        php_scandir.c php_ini.c SAPI.c rfc1867.c php_content_types.c strlcpy.c \
        strlcat.c mergesort.c reentrancy.c php_variables.c php_ticks.c 
network.c \
-       php_open_temporary_file.c php_logos.c output.c internal_functions.c 
php_sprintf.c");
+       php_open_temporary_file.c php_logos.c output.c internal_functions.c 
php_sprintf.c \
+       getopt.c");
 
 ADD_SOURCES("main/streams", "streams.c cast.c memory.c filter.c 
plain_wrapper.c \
        userspace.c transports.c xp_socket.c mmap.c unicode_filter.c 
glob_wrapper.c");

http://cvs.php.net/viewvc.cgi/php-src/main/getopt.c?view=markup&rev=1.1
Index: php-src/main/getopt.c
+++ php-src/main/getopt.c
/*
   +----------------------------------------------------------------------+
   | PHP Version 5                                                        |
   +----------------------------------------------------------------------+
   | Copyright (c) 1997-2007 The PHP Group                                |
   +----------------------------------------------------------------------+
   | This source file is subject to version 3.01 of the PHP license,      |
   | that is bundled with this package in the file LICENSE, and is        |
   | available through the world-wide-web at the following url:           |
   | http://www.php.net/license/3_01.txt                                  |
   | If you did not receive a copy of the PHP license and are unable to   |
   | obtain it through the world-wide-web, please send a note to          |
   | [EMAIL PROTECTED] so we can mail you a copy immediately.               |
   +----------------------------------------------------------------------+
   | Author: Marcus Boerger <[EMAIL PROTECTED]>                               |
   +----------------------------------------------------------------------+
*/

/* $Id: getopt.c,v 1.1 2007/10/01 12:32:39 jani Exp $ */

#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <stdlib.h>
#include "php_getopt.h"

#define OPTERRCOLON (1)
#define OPTERRNF (2)
#define OPTERRARG (3)

static int php_opt_error(int argc, char * const *argv, int oint, int optchr, 
int err, int show_err) /* {{{ */
{
        if (show_err)
        {
                fprintf(stderr, "Error in argument %d, char %d: ", oint, 
optchr+1);
                switch(err)
                {
                case OPTERRCOLON:
                        fprintf(stderr, ": in flags\n");
                        break;
                case OPTERRNF:
                        fprintf(stderr, "option not found %c\n", 
argv[oint][optchr]);
                        break;
                case OPTERRARG:
                        fprintf(stderr, "no argument for option %c\n", 
argv[oint][optchr]);
                        break;
                default:
                        fprintf(stderr, "unknown\n");
                        break;
                }
        }
        return('?');
}
/* }}} */

PHPAPI int php_optidx = -1;

PHPAPI int php_getopt(int argc, char* const *argv, const opt_struct opts[], 
char **optarg, int *optind, int show_err, int arg_start) /* {{{ */
{
        static int optchr = 0;
        static int dash = 0; /* have already seen the - */

        php_optidx = -1;

        if (*optind >= argc) {
                return(EOF);
        }
        if (!dash) {
                if ((argv[*optind][0] !=  '-')) {
                        return(EOF);
                } else {
                        if (!argv[*optind][1])
                        {
                                /*
                                * use to specify stdin. Need to let pgm process 
this and
                                * the following args
                                */
                                return(EOF);
                        }
                }
        }
        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) {
                        php_optidx++;
                        if (opts[php_optidx].opt_char == '-') {
                                (*optind)++;
                                return(php_opt_error(argc, argv, *optind-1, 
optchr, OPTERRARG, show_err));
                        } else if (opts[php_optidx].opt_name && 
!strcmp(&argv[*optind][2], opts[php_optidx].opt_name)) {
                                break;
                        }
                }
                optchr = 0;
                dash = 0;
                arg_start = 2 + strlen(opts[php_optidx].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));
                }
                arg_start = 1 + optchr;
        }
        if (php_optidx < 0) {
                while (1) {
                        php_optidx++;
                        if (opts[php_optidx].opt_char == '-') {
                                int errind = *optind;
                                int errchr = optchr;

                                if (!argv[*optind][optchr+1]) {
                                        dash = 0;
                                        (*optind)++;
                                } else {
                                        optchr++;
                                        arg_start++;
                                }
                                return(php_opt_error(argc, argv, errind, 
errchr, OPTERRNF, show_err));
                        } else if (argv[*optind][optchr] == 
opts[php_optidx].opt_char) {
                                break;
                        }
                }
        }
        if (opts[php_optidx].need_param) {
                /* Check for cases where the value of the argument
                is in the form -<arg> <val> or in the form -<arg><val> */
                dash = 0;
                if (!argv[*optind][arg_start]) {
                        (*optind)++;
                        if (*optind == argc) {
                                return(php_opt_error(argc, argv, *optind-1, 
optchr, OPTERRARG, show_err));
                        }
                        *optarg = argv[(*optind)++];
                } else {
                        *optarg = &argv[*optind][arg_start];
                        (*optind)++;
                }
                return opts[php_optidx].opt_char;
        } else {
                /* multiple options specified as one (exclude long opts) */
                if (arg_start >= 2 && !((argv[*optind][0] == '-') && 
(argv[*optind][1] == '-'))) {
                        if (!argv[*optind][optchr+1])
                        {
                                dash = 0;
                                (*optind)++;
                        } else {
                                optchr++;
                        }
                } else {
                        (*optind)++;
                }
                return opts[php_optidx].opt_char;
        }
        assert(0);
        return(0);      /* never reached */
}
/* }}} */

/*
 * Local variables:
 * tab-width: 4
 * c-basic-offset: 4
 * End:
 * vim600: sw=4 ts=4 fdm=marker
 * vim<600: sw=4 ts=4
 */

http://cvs.php.net/viewvc.cgi/php-src/main/php_getopt.h?view=markup&rev=1.1
Index: php-src/main/php_getopt.h
+++ php-src/main/php_getopt.h
/*
   +----------------------------------------------------------------------+
   | PHP Version 5                                                        |
   +----------------------------------------------------------------------+
   | Copyright (c) 1997-2007 The PHP Group                                |
   +----------------------------------------------------------------------+
   | This source file is subject to version 3.01 of the PHP license,      |
   | that is bundled with this package in the file LICENSE, and is        |
   | available through the world-wide-web at the following url:           |
   | http://www.php.net/license/3_01.txt                                  |
   | If you did not receive a copy of the PHP license and are unable to   |
   | obtain it through the world-wide-web, please send a note to          |
   | [EMAIL PROTECTED] so we can mail you a copy immediately.               |
   +----------------------------------------------------------------------+
   | Author: Marcus Boerger <[EMAIL PROTECTED]>                               |
   +----------------------------------------------------------------------+
*/

/* $Id: php_getopt.h,v 1.1 2007/10/01 12:32:39 jani Exp $ */

#ifndef PHP_GETOPT_H
#define PHP_GETOPT_H

#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. */
typedef struct _opt_struct {
        char opt_char;
        int  need_param;
        char * opt_name;
} opt_struct;

BEGIN_EXTERN_C()
/* holds the index of the latest fetched element from the opts array */
PHPAPI int php_optidx;
PHPAPI int php_getopt(int argc, char* const *argv, const opt_struct opts[], 
char **optarg, int *optind, int show_err, int arg_start);
END_EXTERN_C()

#endif

/*
 * Local variables:
 * tab-width: 4
 * c-basic-offset: 4
 * End:
 * vim600: noet sw=4 ts=4 fdm=marker
 * vim<600: noet sw=4 ts=4
 */

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to