bjori Thu Nov 15 13:11:48 2007 UTC
Added files:
/php-src/ext/standard/tests/general_functions getopt_002.phpt
getopt_003.phpt
Modified files:
/php-src/ext/standard basic_functions.c
Log:
- Allow numeric options
- Add tests
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/basic_functions.c?r1=1.882&r2=1.883&diff_format=u
Index: php-src/ext/standard/basic_functions.c
diff -u php-src/ext/standard/basic_functions.c:1.882
php-src/ext/standard/basic_functions.c:1.883
--- php-src/ext/standard/basic_functions.c:1.882 Wed Nov 14 14:55:44 2007
+++ php-src/ext/standard/basic_functions.c Thu Nov 15 13:11:48 2007
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: basic_functions.c,v 1.882 2007/11/14 14:55:44 bjori Exp $ */
+/* $Id: basic_functions.c,v 1.883 2007/11/15 13:11:48 bjori Exp $ */
#include "php.h"
#include "php_streams.h"
@@ -4470,7 +4470,8 @@
int i, count = 0;
for (i = 0; i < strlen(opts); i++) {
- if ((opts[i] >= 65 && opts[i] <= 90) ||
+ if ((opts[i] >= 48 && opts[i] <= 57) ||
+ (opts[i] >= 65 && opts[i] <= 90) ||
(opts[i] >= 97 && opts[i] <= 122)
) {
count++;
@@ -4480,8 +4481,9 @@
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)
+ while ( (*opts >= 48 && *opts <= 57) || /* 0 - 9 */
+ (*opts >= 65 && *opts <= 90) || /* A - Z */
+ (*opts >= 97 && *opts <= 122) /* a - z */
) {
paras->opt_char = *opts;
paras->need_param = (*(++opts) == ':') ? 1 : 0;
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/general_functions/getopt_002.phpt?view=markup&rev=1.1
Index: php-src/ext/standard/tests/general_functions/getopt_002.phpt
+++ php-src/ext/standard/tests/general_functions/getopt_002.phpt
--TEST--
getopt#002
--ARGS--
-vvv -a value -1111 -2 -v
--INI--
register_argc_argv=On
variables_order=GPS
--FILE--
<?php
var_dump(getopt("2a:vcd1"));
?>
--EXPECT--
array(4) {
["v"]=>
array(4) {
[0]=>
bool(false)
[1]=>
bool(false)
[2]=>
bool(false)
[3]=>
bool(false)
}
["a"]=>
string(5) "value"
[1]=>
array(4) {
[0]=>
bool(false)
[1]=>
bool(false)
[2]=>
bool(false)
[3]=>
bool(false)
}
[2]=>
bool(false)
}
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/general_functions/getopt_003.phpt?view=markup&rev=1.1
Index: php-src/ext/standard/tests/general_functions/getopt_003.phpt
+++ php-src/ext/standard/tests/general_functions/getopt_003.phpt
--TEST--
getopt#003
--ARGS--
-vvv --v -a value --another value -1111 -2 --12 --0 --0 --1 -v
--INI--
register_argc_argv=On
variables_order=GPS
--FILE--
<?php
var_dump(getopt("2a:vcd1", array("another:", 12, 0, 1, "v")));
?>
--EXPECT--
array(7) {
["v"]=>
array(5) {
[0]=>
bool(false)
[1]=>
bool(false)
[2]=>
bool(false)
[3]=>
bool(false)
[4]=>
bool(false)
}
["a"]=>
string(5) "value"
["another"]=>
string(5) "value"
[1]=>
array(5) {
[0]=>
bool(false)
[1]=>
bool(false)
[2]=>
bool(false)
[3]=>
bool(false)
[4]=>
bool(false)
}
[2]=>
bool(false)
[12]=>
bool(false)
[0]=>
array(2) {
[0]=>
bool(false)
[1]=>
bool(false)
}
}
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php