cvs: php4 /ext/standard basic_functions.c string.c /main main.c php_variables.c php_variables.h
| From: | Stanislav Malyshev | Date: | Mon, 11 Sep 2000 14:50:27 +0000 |
| Subject: | cvs: php4 /ext/standard basic_functions.c string.c /main main.c php_variables.c php_variables.h | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-1698@lists.php.net to get a copy of this message | ||
stas Mon Sep 11 07:50:27 2000 EDT
Modified files:
/php4/ext/standard basic_functions.c string.c
/php4/main main.c php_variables.c php_variables.h
Log:
Add additional parameter to parse_str for saving result (thanks to
John Bafford <dshadow@zort.net>)
@ Added second parameter for parse_str to save result (John Bafford)
Index: php4/ext/standard/basic_functions.c
diff -u php4/ext/standard/basic_functions.c:1.254 php4/ext/standard/basic_functions.c:1.255
--- php4/ext/standard/basic_functions.c:1.254 Sat Sep 9 22:59:16 2000
+++ php4/ext/standard/basic_functions.c Mon Sep 11 07:50:26 2000
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: basic_functions.c,v 1.254 2000/09/10 05:59:16 sterling Exp $ */
+/* $Id: basic_functions.c,v 1.255 2000/09/11 14:50:26 stas Exp $ */
#include "php.h"
#include "php_main.h"
@@ -182,7 +182,7 @@
PHP_FE(levenshtein, NULL)
PHP_FE(chr, NULL)
PHP_FE(ord, NULL)
- PHP_FE(parse_str, NULL)
+ PHP_FE(parse_str, second_arg_force_ref)
PHP_FE(str_pad, NULL)
PHP_FALIAS(rtrim, chop, NULL)
PHP_FALIAS(strchr, strstr, NULL)
Index: php4/ext/standard/string.c
diff -u php4/ext/standard/string.c:1.150 php4/ext/standard/string.c:1.151
--- php4/ext/standard/string.c:1.150 Mon Sep 11 06:54:59 2000
+++ php4/ext/standard/string.c Mon Sep 11 07:50:26 2000
@@ -18,7 +18,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: string.c,v 1.150 2000/09/11 13:54:59 andrei Exp $ */
+/* $Id: string.c,v 1.151 2000/09/11 14:50:26 stas Exp $ */
/* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */
@@ -775,6 +775,11 @@
}
}
+ if (opt == PHP_PATHINFO_DIRNAME || argc < 2) {
+ ret = php_basename(Z_STRVAL_PP(str), len);
+ add_assoc_string(tmp, "dirname", ret, 1);
+ }
+
if (argc == 2) {
zval **element;
zend_hash_get_current_data(Z_ARRVAL_P(tmp), (void **)&element);
@@ -2397,23 +2402,45 @@
}
/* }}} */
-/* {{{ proto void parse_str(string encoded_string)
+/* {{{ proto void parse_str(string encoded_string, [array result])
Parses GET/POST/COOKIE data and sets global variables */
PHP_FUNCTION(parse_str)
{
zval **arg;
+ zval **arrayArg;
+ zval *sarg;
char *res = NULL;
+ int argCount;
+
PLS_FETCH();
SLS_FETCH();
- if (zend_get_parameters_ex(1, &arg) == FAILURE) {
+ argCount = ARG_COUNT(ht);
+ if(argCount < 1 || argCount > 2 || zend_get_parameters_ex(argCount, &arg, &arrayArg)
== FAILURE) {
WRONG_PARAM_COUNT;
}
+
convert_to_string_ex(arg);
- if ((*arg)->value.str.val && *(*arg)->value.str.val) {
- res = estrndup((*arg)->value.str.val,(*arg)->value.str.len);
+ sarg = *arg;
+ if (sarg->value.str.val && *sarg->value.str.val) {
+ res = estrndup(sarg->value.str.val, sarg->value.str.len);
+ }
+
+ if(argCount == 1)
+ php_treat_data(PARSE_STRING, res, NULL ELS_CC PLS_CC SLS_CC);
+ else
+ {
+ if(!ParameterPassedByReference(ht, 2)){
+ php_error(E_WARNING, "Array not passed by reference in call to parse_str()");
+ return;
+ }
+
+ /* Clear out the array that was passed in. */
+ zval_dtor(*arrayArg);
+ array_init(*arrayArg);
+
+ php_treat_data(PARSE_STRING, res, *arrayArg ELS_CC PLS_CC SLS_CC);
}
- php_treat_data(PARSE_STRING, res ELS_CC PLS_CC SLS_CC);
}
/* }}} */
Index: php4/main/main.c
diff -u php4/main/main.c:1.318 php4/main/main.c:1.319
--- php4/main/main.c:1.318 Sat Sep 9 16:21:44 2000
+++ php4/main/main.c Mon Sep 11 07:50:26 2000
@@ -19,7 +19,7 @@
*/
-/* $Id: main.c,v 1.318 2000/09/09 23:21:44 derick Exp $ */
+/* $Id: main.c,v 1.319 2000/09/11 14:50:26 stas Exp $ */
#include <stdio.h>
@@ -1007,21 +1007,21 @@
case 'p':
case 'P':
if (!_gpc_flags[0] && !SG(headers_sent) && SG(request_info).request_method
&& !strcasecmp(SG(request_info).request_method, "POST")) {
- php_treat_data(PARSE_POST, NULL ELS_CC PLS_CC SLS_CC); /* POST Data */
+ php_treat_data(PARSE_POST, NULL, NULL ELS_CC PLS_CC SLS_CC); /* POST Data */
_gpc_flags[0]=1;
}
break;
case 'c':
case 'C':
if (!_gpc_flags[1]) {
- php_treat_data(PARSE_COOKIE, NULL ELS_CC PLS_CC SLS_CC); /* Cookie Data */
+ php_treat_data(PARSE_COOKIE, NULL, NULL ELS_CC PLS_CC SLS_CC); /* Cookie Data */
_gpc_flags[1]=1;
}
break;
case 'g':
case 'G':
if (!_gpc_flags[2]) {
- php_treat_data(PARSE_GET, NULL ELS_CC PLS_CC SLS_CC); /* GET Data */
+ php_treat_data(PARSE_GET, NULL, NULL ELS_CC PLS_CC SLS_CC); /* GET Data */
_gpc_flags[2]=1;
}
break;
Index: php4/main/php_variables.c
diff -u php4/main/php_variables.c:1.16 php4/main/php_variables.c:1.17
--- php4/main/php_variables.c:1.16 Tue Sep 5 12:06:29 2000
+++ php4/main/php_variables.c Mon Sep 11 07:50:26 2000
@@ -209,7 +209,7 @@
}
-void php_treat_data(int arg, char *str ELS_DC PLS_DC SLS_DC)
+void php_treat_data(int arg, char *str, zval* destArray ELS_DC PLS_DC SLS_DC)
{
char *res = NULL, *var, *val;
pval *array_ptr;
@@ -236,7 +236,7 @@
}
break;
default:
- array_ptr=NULL;
+ array_ptr=destArray;
break;
}
Index: php4/main/php_variables.h
diff -u php4/main/php_variables.h:1.6 php4/main/php_variables.h:1.7
--- php4/main/php_variables.h:1.6 Sun Jul 23 18:39:51 2000
+++ php4/main/php_variables.h Mon Sep 11 07:50:26 2000
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_variables.h,v 1.6 2000/07/24 01:39:51 david Exp $ */
+/* $Id: php_variables.h,v 1.7 2000/09/11 14:50:26 stas Exp $ */
#ifndef PHP_VARIABLES_H
#define PHP_VARIABLES_H
@@ -30,7 +30,7 @@
#define PARSE_COOKIE 2
#define PARSE_STRING 3
-void php_treat_data(int arg, char *str ELS_DC PLS_DC SLS_DC);
+void php_treat_data(int arg, char *str, zval* destArray ELS_DC PLS_DC SLS_DC);
void php_import_environment_variables(ELS_D PLS_DC);
PHPAPI void php_register_variable(char *var, char *val, pval *track_vars_array ELS_DC PLS_DC);
PHPAPI void php_register_variable_ex(char *var, zval *val, pval *track_vars_array ELS_DC PLS_DC);