CVS update: php3/functions

From: Date: Tue, 22 Sep 1998 19:39:35 +0000
Subject: CVS update: php3/functions
Groups: php.dev 
Request: Send a blank email to php-dev+get-1419@lists.php.net to get a copy of this message
Date: Tuesday September 22, 1998 @ 15:39 Author: zeev Update of /repository/php3/functions In directory asf:/u2/tmp/cvs-serv25978/functions Modified Files: basic_functions.c basic_functions.h Log Message: Add uksort() Index: php3/functions/basic_functions.c diff -c php3/functions/basic_functions.c:1.220 php3/functions/basic_functions.c:1.221 *** php3/functions/basic_functions.c:1.220 Mon Sep 21 12:03:36 1998 --- php3/functions/basic_functions.c Tue Sep 22 15:39:33 1998 *************** *** 105,110 **** --- 105,111 ---- {"sort", php3_sort, first_arg_force_ref}, {"rsort", php3_rsort, first_arg_force_ref}, {"usort", php3_user_sort, first_arg_force_ref}, + {"uksort", php3_user_key_sort, first_arg_force_ref}, {"uasort", php3_auser_sort, first_arg_force_ref}, {"array_walk", php3_array_walk, first_arg_force_ref}, {"sizeof", php3_count, first_arg_allow_ref}, *************** *** 854,859 **** --- 855,929 ---- } convert_to_string(user_compare_func_name); if (_php3_hash_sort(array->value.ht, array_user_compare, 0) == FAILURE) { + user_compare_func_name = old_compare_func; + return; + } + user_compare_func_name = old_compare_func; + RETURN_TRUE; + } + + + static int array_user_key_compare(const void *a, const void *b) + { + Bucket *f; + Bucket *s; + pval key1, key2; + pval *args[2] = {&key1, &key2}; + pval retval; + int status; + + f = *((Bucket **) a); + s = *((Bucket **) b); + + if (f->arKey) { + key1.value.str.val = estrndup(f->arKey, f->nKeyLength); + key1.value.str.len = f->nKeyLength; + key1.type = IS_STRING; + } else { + key1.value.lval = f->h; + key1.type = IS_LONG; + } + if (s->arKey) { + key2.value.str.val = estrndup(s->arKey, s->nKeyLength); + key2.value.str.len = s->nKeyLength; + key2.type = IS_STRING; + } else { + key2.value.lval = s->h; + key2.type = IS_LONG; + } + + status = call_user_function(&GLOBAL(function_table), NULL, user_compare_func_name, &retval, 2, args); + + pval_destructor(&key1); + pval_destructor(&key2); + + if (status==SUCCESS) { + convert_to_long(&retval); + return retval.value.lval; + } else { + return 0; + } + } + + + void php3_user_key_sort(INTERNAL_FUNCTION_PARAMETERS) + { + pval *array; + pval *old_compare_func; + TLS_VARS; + + old_compare_func = user_compare_func_name; + if (ARG_COUNT(ht) != 2 || getParameters(ht, 2, &array, &user_compare_func_name) == FAILURE) { + user_compare_func_name = old_compare_func; + WRONG_PARAM_COUNT; + } + if (!(array->type & IS_HASH)) { + php3_error(E_WARNING, "Wrong datatype in uasort() call"); + user_compare_func_name = old_compare_func; + return; + } + convert_to_string(user_compare_func_name); + if (_php3_hash_sort(array->value.ht, array_user_key_compare, 0) == FAILURE) { user_compare_func_name = old_compare_func; return; } Index: php3/functions/basic_functions.h diff -c php3/functions/basic_functions.h:1.33 php3/functions/basic_functions.h:1.34 *** php3/functions/basic_functions.h:1.33 Mon Sep 21 12:03:37 1998 --- php3/functions/basic_functions.h Tue Sep 22 15:39:33 1998 *************** *** 29,35 **** */ ! /* $Id: basic_functions.h,v 1.33 1998/09/21 16:03:37 zeev Exp $ */ #ifndef _BASIC_FUNCTIONS_H #define _BASIC_FUNCTIONS_H --- 29,35 ---- */ ! /* $Id: basic_functions.h,v 1.34 1998/09/22 19:39:33 zeev Exp $ */ #ifndef _BASIC_FUNCTIONS_H #define _BASIC_FUNCTIONS_H *************** *** 53,58 **** --- 53,59 ---- extern void php3_rsort(INTERNAL_FUNCTION_PARAMETERS); extern void php3_user_sort(INTERNAL_FUNCTION_PARAMETERS); extern void php3_auser_sort(INTERNAL_FUNCTION_PARAMETERS); + extern void php3_user_key_sort(INTERNAL_FUNCTION_PARAMETERS); extern void php3_array_walk(INTERNAL_FUNCTION_PARAMETERS); extern void php3_count(INTERNAL_FUNCTION_PARAMETERS); extern void php3_flush(INTERNAL_FUNCTION_PARAMETERS); -- 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 (#1419) next »