CVS update: php3/functions

From: Date: Thu, 11 Feb 1999 06:23:41 +0000
Subject: CVS update: php3/functions
Groups: php.dev 
Request: Send a blank email to php-dev+get-4034@lists.php.net to get a copy of this message
Date: Thursday February 11, 1999 @ 1:23 Author: andrey Update of /repository/php3/functions In directory asf:/u/temp/cvs-serv1088/functions Modified Files: basic_functions.c basic_functions.h Log Message: Added extract() fucntion and docs for it. Feel free to suggest a different name for it. Index: php3/functions/basic_functions.c diff -c php3/functions/basic_functions.c:1.257 php3/functions/basic_functions.c:1.258 *** php3/functions/basic_functions.c:1.257 Wed Feb 3 22:34:52 1999 --- php3/functions/basic_functions.c Thu Feb 11 01:23:40 1999 *************** *** 28,34 **** +----------------------------------------------------------------------+ */ ! /* $Id: basic_functions.c,v 1.257 1999/02/04 03:34:52 andrey Exp $ */ #ifdef THREAD_SAFE #include "tls.h" #endif --- 28,34 ---- +----------------------------------------------------------------------+ */ ! /* $Id: basic_functions.c,v 1.258 1999/02/11 06:23:40 andrey Exp $ */ #ifdef THREAD_SAFE #include "tls.h" #endif *************** *** 319,324 **** --- 319,326 ---- PHP_FE(connection_timeout, NULL) PHP_FE(connection_status, NULL) PHP_FE(ignore_user_abort, NULL) + + PHP_FE(extract, NULL) PHP_FE(function_exists, NULL) *************** *** 366,376 **** --- 368,388 ---- #define M_PI 3.14159265358979323846 #endif + #define EXTR_OVERWRITE 0 + #define EXTR_SKIP 1 + #define EXTR_PREFIX_SAME 2 + #define EXTR_PREFIX_ALL 3 + int php3_minit_basic(INIT_FUNC_ARGS) { TLS_VARS; REGISTER_DOUBLE_CONSTANT("M_PI", M_PI, CONST_CS | CONST_PERSISTENT); + + REGISTER_LONG_CONSTANT("EXTR_OVERWRITE", EXTR_OVERWRITE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("EXTR_SKIP", EXTR_SKIP, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("EXTR_PREFIX_SAME", EXTR_PREFIX_SAME, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("EXTR_PREFIX_ALL", EXTR_PREFIX_ALL, CONST_CS | CONST_PERSISTENT); return SUCCESS; } *************** *** 1974,1979 **** --- 1986,2119 ---- RETURN_FALSE; } else { RETURN_TRUE; + } + } + /* }}} */ + + + /* {{{ int _php3_valid_var_name(char *varname) */ + static int _php3_valid_var_name(char *varname) + { + int len, i; + + if (!varname) + return 0; + + len = strlen(varname); + + if (!isalpha((int)varname[0]) && varname[0] != '_') + return 0; + + if (len > 1) { + for(i=1; i<len; i++) { + if (!isalnum((int)varname[i]) && varname[i] != '_') { + return 0; + } + } + } + + return 1; + } + /* }}} */ + + + /* {{{ proto void extract(array var_array, int extract_type [, string prefix]) + Imports variables into symbol table from an array */ + PHP_FUNCTION(extract) + { + pval *var_array, *etype, *prefix; + pval *var, *exist; + pval data; + char *varname, *finalname; + ulong lkey; + int res; + + switch(ARG_COUNT(ht)) { + case 2: + if (getParameters(ht, 2, &var_array, &etype) == FAILURE) { + WRONG_PARAM_COUNT; + } + convert_to_long(etype); + if (etype->value.lval > EXTR_SKIP && etype->value.lval <= EXTR_PREFIX_ALL) { + WRONG_PARAM_COUNT; + } + break; + + case 3: + if (getParameters(ht, 3, &var_array, &etype, &prefix) == FAILURE) { + WRONG_PARAM_COUNT; + } + break; + + default: + WRONG_PARAM_COUNT; + break; + } + + if (etype->value.lval < EXTR_OVERWRITE || etype->value.lval > EXTR_PREFIX_ALL) { + php3_error(E_WARNING, "Wrong argument in call to extract()"); + return; + } + + if (!(var_array->type & IS_HASH)) { + php3_error(E_WARNING, "Wrong datatype in call to extract()"); + return; + } + + _php3_hash_internal_pointer_reset(var_array->value.ht); + while(_php3_hash_get_current_data(var_array->value.ht, (void **)&var) == SUCCESS) { + if (!(var->type == IS_STRING && + var->value.str.val == undefined_variable_string)) { + + if (_php3_hash_get_current_key(var_array->value.ht, &varname, &lkey) == + HASH_KEY_IS_STRING) { + + data = *var; + pval_copy_constructor(&data); + + if (_php3_valid_var_name(varname)) { + finalname = NULL; + + res = _php3_hash_find(GLOBAL(active_symbol_table), + varname, strlen(varname)+1, (void**)&exist); + switch (etype->value.lval) { + case EXTR_OVERWRITE: + finalname = estrdup(varname); + break; + + case EXTR_PREFIX_SAME: + if (res != SUCCESS) + finalname = estrdup(varname); + /* break omitted intentionally */ + + case EXTR_PREFIX_ALL: + if (!finalname) { + finalname = emalloc(strlen(varname) + prefix->value.str.len + 2); + strcpy(finalname, prefix->value.str.val); + strcat(finalname, "_"); + strcat(finalname, varname); + } + break; + + default: + if (res != SUCCESS) + finalname = estrdup(varname); + break; + } + + if (finalname) { + _php3_hash_update(GLOBAL(active_symbol_table), finalname, + strlen(finalname)+1, &data, sizeof(pval), NULL); + efree(finalname); + } + else + pval_destructor(&data); + } + + efree(varname); + } + } + _php3_hash_move_forward(var_array->value.ht); } } /* }}} */ Index: php3/functions/basic_functions.h diff -c php3/functions/basic_functions.h:1.40 php3/functions/basic_functions.h:1.41 *** php3/functions/basic_functions.h:1.40 Wed Feb 3 22:34:52 1999 --- php3/functions/basic_functions.h Thu Feb 11 01:23:40 1999 *************** *** 29,35 **** */ ! /* $Id: basic_functions.h,v 1.40 1999/02/04 03:34:52 andrey Exp $ */ #ifndef _BASIC_FUNCTIONS_H #define _BASIC_FUNCTIONS_H --- 29,35 ---- */ ! /* $Id: basic_functions.h,v 1.41 1999/02/11 06:23:40 andrey Exp $ */ #ifndef _BASIC_FUNCTIONS_H #define _BASIC_FUNCTIONS_H *************** *** 100,107 **** extern void php3_connection_status(INTERNAL_FUNCTION_PARAMETERS); extern void php3_ignore_user_abort(INTERNAL_FUNCTION_PARAMETERS); PHP_FUNCTION(register_shutdown_function); - PHP_FUNCTION(function_exists); #if HAVE_PUTENV typedef struct { --- 100,109 ---- extern void php3_connection_status(INTERNAL_FUNCTION_PARAMETERS); extern void php3_ignore_user_abort(INTERNAL_FUNCTION_PARAMETERS); + extern PHP_FUNCTION(function_exists); + extern PHP_FUNCTION(extract); + PHP_FUNCTION(register_shutdown_function); #if HAVE_PUTENV typedef struct { -- PHP Development Mailing List http://www.php.net/ To unsubscribe send an empty message to php-dev-unsubscribe@lists.php.net For help: php-dev-help@lists.php.net

« previous php.dev (#4034) next »