com php-src: Add optind param to getopt: ext/standard/basic_f unctions.c ext/standard/tests/general_functions/getopt_ 006.phpt
ext/standard/tests/general_functions/getop t_007.phpt ext/standard/tests/general_functions/g etopt_008.phpt ext/standard/tests/general_functio
ns/getopt_009.phpt
| From: | JulienPauli | Date: | Fri, 08 Jul 2016 14:53:24 +0000 |
| Subject: | com php-src: Add optind param to getopt: ext/standard/basic_f unctions.c ext/standard/tests/general_functions/getopt_ 006.phpt ext/standard/tests/general_functions/getop t_007.phpt ext/standard/tests/general_functions/g etopt_008.phpt ext/standard/tests/general_functio ns/getopt_009.phpt |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-92892@lists.php.net to get a copy of this message | ||
Commit: e4f7f00a7748b1312f6486639c158be887f23e18
Author: Adam Saponara <saponara@gmail.com> Sun, 29 May 2016 13:44:16 -0400
Committer: Julien Pauli <jpauli@php.net> Fri, 8 Jul 2016 16:53:24 +0200
Parents: 6ab9b848e8b3d3421217fe6e863f1874609ff773
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=e4f7f00a7748b1312f6486639c158be887f23e18
Log:
Add optind param to getopt
Changed paths:
M ext/standard/basic_functions.c
A ext/standard/tests/general_functions/getopt_006.phpt
A ext/standard/tests/general_functions/getopt_007.phpt
A ext/standard/tests/general_functions/getopt_008.phpt
A ext/standard/tests/general_functions/getopt_009.phpt
Diff:
diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c
index 20f03bb..7fa1ad4 100644
--- a/ext/standard/basic_functions.c
+++ b/ext/standard/basic_functions.c
@@ -646,6 +646,7 @@ ZEND_END_ARG_INFO()
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_ARG_INFO(1, optind)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO(arginfo_flush, 0)
@@ -4269,7 +4270,7 @@ static int parse_opts(char * opts, opt_struct ** result)
}
/* }}} */
-/* {{{ proto array getopt(string options [, array longopts])
+/* {{{ proto array getopt(string options [, array longopts [, int &optind]])
Get options from the command line argument list */
PHP_FUNCTION(getopt)
{
@@ -4281,13 +4282,20 @@ PHP_FUNCTION(getopt)
char *php_optarg = NULL;
int php_optind = 1;
zval val, *args = NULL, *p_longopts = NULL;
+ zval *zoptind = NULL;
int optname_len = 0;
opt_struct *opts, *orig_opts;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|a", &options, &options_len,
&p_longopts) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|az/", &options, &options_len,
&p_longopts, &zoptind) == FAILURE) {
RETURN_FALSE;
}
+ /* Init zoptind to 1 */
+ if (zoptind) {
+ zval_dtor(zoptind);
+ ZVAL_LONG(zoptind, 1);
+ }
+
/* Get argv from the global symbol table. We calculate argc ourselves
* in order to be on the safe side, even though it is also available
* from the symbol table. */
@@ -4429,6 +4437,11 @@ PHP_FUNCTION(getopt)
php_optarg = NULL;
}
+ /* Set zoptind to php_optind */
+ if (zoptind) {
+ ZVAL_LONG(zoptind, php_optind);
+ }
+
free_longopts(orig_opts);
efree(orig_opts);
free_argv(argv, argc);
diff --git a/ext/standard/tests/general_functions/getopt_006.phpt
b/ext/standard/tests/general_functions/getopt_006.phpt
new file mode 100644
index 0000000..875c404
--- /dev/null
+++ b/ext/standard/tests/general_functions/getopt_006.phpt
@@ -0,0 +1,15 @@
+--TEST--
+getopt#006 (optind #1)
+--ARGS--
+-a 1 -b 2 test
+--INI--
+register_argc_argv=On
+variables_order=GPS
+--FILE--
+<?php
+ $optind = null;
+ getopt('a:b:', [], $optind);
+ var_dump($optind);
+?>
+--EXPECT--
+int(5)
diff --git a/ext/standard/tests/general_functions/getopt_007.phpt
b/ext/standard/tests/general_functions/getopt_007.phpt
new file mode 100644
index 0000000..157a86e
--- /dev/null
+++ b/ext/standard/tests/general_functions/getopt_007.phpt
@@ -0,0 +1,15 @@
+--TEST--
+getopt#007 (optind #2)
+--ARGS--
+-a 1 -b 2 -- test
+--INI--
+register_argc_argv=On
+variables_order=GPS
+--FILE--
+<?php
+ $optind = null;
+ getopt('a:b:', [], $optind);
+ var_dump($optind);
+?>
+--EXPECT--
+int(6)
diff --git a/ext/standard/tests/general_functions/getopt_008.phpt
b/ext/standard/tests/general_functions/getopt_008.phpt
new file mode 100644
index 0000000..c6bacf4
--- /dev/null
+++ b/ext/standard/tests/general_functions/getopt_008.phpt
@@ -0,0 +1,15 @@
+--TEST--
+getopt#008 (optind #3)
+--ARGS--
+-a 1 -b 2
+--INI--
+register_argc_argv=On
+variables_order=GPS
+--FILE--
+<?php
+ $optind = null;
+ getopt('a:b:', [], $optind);
+ var_dump($optind);
+?>
+--EXPECT--
+int(5)
diff --git a/ext/standard/tests/general_functions/getopt_009.phpt
b/ext/standard/tests/general_functions/getopt_009.phpt
new file mode 100644
index 0000000..26da1cc
--- /dev/null
+++ b/ext/standard/tests/general_functions/getopt_009.phpt
@@ -0,0 +1,15 @@
+--TEST--
+getopt#009 (optind #4)
+--ARGS--
+messup -a 1 -b 2
+--INI--
+register_argc_argv=On
+variables_order=GPS
+--FILE--
+<?php
+ $optind = null;
+ getopt('a:b:', [], $optind);
+ var_dump($optind);
+?>
+--EXPECT--
+int(1)