cvs: /php4 ChangeLog /php4/ext/standard basic_functions.c basic_functions.h

From: Date: Mon, 04 Oct 1999 21:10:56 +0000
Subject: cvs: /php4 ChangeLog /php4/ext/standard basic_functions.c basic_functions.h
Groups: php.version4 
Request: Send a blank email to php-version4+get-5160@lists.php.net to get a copy of this message
andrei Mon Oct 4 17:10:56 1999 EDT Modified files: /php4 ChangeLog /php4/ext/standard basic_functions.c basic_functions.h Log: Taken from PHP3 source. Index: php4/ChangeLog diff -u php4/ChangeLog:1.164 php4/ChangeLog:1.165 --- php4/ChangeLog:1.164 Mon Oct 4 14:07:44 1999 +++ php4/ChangeLog Mon Oct 4 17:10:24 1999 @@ -2,6 +2,7 @@ ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ?? ?? 1999, Version 4.0 Beta 3 +- Ported range() and shuffle() from PHP3 to PHP4 (Andrei) - Fixed header("HTTP/..."); behaviour (Sascha) - Improved UNIX build system. Now utilizes libtool (Sascha) - Upgrade some more internal functions to use new Zend function API. (Thies, Index: php4/ext/standard/basic_functions.c diff -u php4/ext/standard/basic_functions.c:1.95 php4/ext/standard/basic_functions.c:1.96 --- php4/ext/standard/basic_functions.c:1.95 Fri Oct 1 13:36:54 1999 +++ php4/ext/standard/basic_functions.c Mon Oct 4 17:10:25 1999 @@ -90,6 +90,7 @@ PHP_FE(usort, first_arg_force_ref) PHP_FE(uasort, first_arg_force_ref) PHP_FE(uksort, first_arg_force_ref) + PHP_FE(shuffle, first_arg_force_ref) PHP_FE(array_walk, first_arg_force_ref) PHP_FALIAS(sizeof, count, first_arg_allow_ref) PHP_FE(count, first_arg_allow_ref) @@ -317,6 +318,7 @@ PHP_FE(in_array, NULL) PHP_FE(extract, NULL) PHP_FE(compact, NULL) + PHP_FE(range, NULL) PHP_FE(array_push, first_arg_force_ref) PHP_FE(array_pop, first_arg_force_ref) PHP_FE(array_shift, first_arg_force_ref) @@ -2468,6 +2470,73 @@ } efree(args); +} +/* }}} */ + +/* {{{ proto array range(int low, int high) + Create an array containing the range of integers from low to high (inclusive) */ +PHP_FUNCTION(range) +{ + zval *zlow, *zhigh; + int low, high; + + if (ARG_COUNT(ht) != 2 || getParameters(ht,2,&zlow,&zhigh) == FAILURE) { + WRONG_PARAM_COUNT; + } + convert_to_long(zlow); + convert_to_long(zhigh); + low = zlow->value.lval; + high = zhigh->value.lval; + + /* allocate an array for return */ + if (array_init(return_value) == FAILURE) { + RETURN_FALSE; + } + + for (; low <= high; low++) { + add_next_index_long(return_value, low); + } +} +/* }}} */ + + +static int array_data_shuffle(const void *a, const void*b) { + return ( + /* This is just a little messy. */ +#ifdef HAVE_LRAND48 + lrand48() +#else +#ifdef HAVE_RANDOM + random() +#else + rand() +#endif +#endif + % 2) ? 1 : -1; +} + + +/* {{{ proto int shuffle(array array_arg) + Randomly shuffle the contents of an array */ +PHP_FUNCTION(shuffle) +{ + zval **array; + + if (ARG_COUNT(ht) != 1 || getParametersEx(1, &array) == FAILURE) { + WRONG_PARAM_COUNT; + } + if ((*array)->type != IS_ARRAY) { + php_error(E_WARNING, "Wrong datatype in shuffle() call"); + return; + } + if (!ParameterPassedByReference(ht,1)) { + php_error(E_WARNING, "Array not passed by reference in call to shuffle()"); + return; + } + if (zend_hash_sort((*array)->value.ht, array_data_shuffle, 1) == FAILURE) { + return; + } + RETURN_TRUE; } /* }}} */ Index: php4/ext/standard/basic_functions.h diff -u php4/ext/standard/basic_functions.h:1.19 php4/ext/standard/basic_functions.h:1.20 --- php4/ext/standard/basic_functions.h:1.19 Fri Oct 1 13:36:54 1999 +++ php4/ext/standard/basic_functions.h Mon Oct 4 17:10:26 1999 @@ -29,7 +29,7 @@ */ -/* $Id: basic_functions.h,v 1.19 1999/10/01 17:36:54 andrei Exp $ */ +/* $Id: basic_functions.h,v 1.20 1999/10/04 21:10:26 andrei Exp $ */ #ifndef _BASIC_FUNCTIONS_H #define _BASIC_FUNCTIONS_H @@ -122,6 +122,8 @@ PHP_FUNCTION(in_array); PHP_FUNCTION(extract); PHP_FUNCTION(compact); +PHP_FUNCTION(range); +PHP_FUNCTION(shuffle); PHP_FUNCTION(array_push); PHP_FUNCTION(array_pop); PHP_FUNCTION(array_shift);

« previous php.version4 (#5160) next »