cvs: php4 /ext/standard php_versioning.h versioning.c

From: Date: Wed, 10 Oct 2001 10:14:51 +0000
Subject: cvs: php4 /ext/standard php_versioning.h versioning.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-7738@lists.php.net to get a copy of this message
ssb Wed Oct 10 06:14:51 2001 EDT Modified files: /php4/ext/standard php_versioning.h versioning.c Log: @Added version_{lt,le,gt,ge,eq} functions (Stig) Index: php4/ext/standard/php_versioning.h diff -u php4/ext/standard/php_versioning.h:1.1 php4/ext/standard/php_versioning.h:1.2 --- php4/ext/standard/php_versioning.h:1.1 Fri Oct 5 19:56:19 2001 +++ php4/ext/standard/php_versioning.h Wed Oct 10 06:14:51 2001 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_versioning.h,v 1.1 2001/10/05 23:56:19 ssb Exp $ */ +/* $Id: php_versioning.h,v 1.2 2001/10/10 10:14:51 ssb Exp $ */ #ifndef PHP_VERSIONING_H #define PHP_VERSIONING_H @@ -27,5 +27,10 @@ PHPAPI char *php_canonicalize_version(const char *); PHPAPI int php_version_compare(const char *, const char *); PHP_FUNCTION(version_compare); +PHP_FUNCTION(version_gt); +PHP_FUNCTION(version_ge); +PHP_FUNCTION(version_lt); +PHP_FUNCTION(version_le); +PHP_FUNCTION(version_eq); #endif Index: php4/ext/standard/versioning.c diff -u php4/ext/standard/versioning.c:1.2 php4/ext/standard/versioning.c:1.3 --- php4/ext/standard/versioning.c:1.2 Sat Oct 6 19:22:36 2001 +++ php4/ext/standard/versioning.c Wed Oct 10 06:14:51 2001 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: versioning.c,v 1.2 2001/10/06 23:22:36 ssb Exp $ */ +/* $Id: versioning.c,v 1.3 2001/10/10 10:14:51 ssb Exp $ */ #include <stdio.h> #include <sys/types.h> @@ -29,6 +29,20 @@ #define sign(n) ((n)<0?-1:((n)>0?1:0)) +#define PHP_VC_COMPARE 0 +#define PHP_VC_LT 1 +#define PHP_VC_LE 2 +#define PHP_VC_GT 3 +#define PHP_VC_GE 4 +#define PHP_VC_EQ 5 + +#define PHP_VCFUNC(name,mode) \ + void name(INTERNAL_FUNCTION_PARAMETERS) { \ + do_version_compare(INTERNAL_FUNCTION_PARAM_PASSTHRU, mode); \ + } + +/* {{{ php_canonicalize_version() */ + PHPAPI char * php_canonicalize_version(const char *version) { @@ -65,6 +79,9 @@ return buf; } +/* }}} */ +/* {{{ compare_special_version_forms() */ + static int compare_special_version_forms(const char *form1, const char *form2) { @@ -95,6 +112,9 @@ return sign(found1 - found2); } +/* }}} */ +/* {{{ php_version_compare() */ + PHPAPI int php_version_compare(const char *orig_ver1, const char *orig_ver2) { @@ -159,19 +179,68 @@ return compare; } -/* {{{ proto int version_compare(string ver1, string ver2) */ +/* }}} */ +/* {{{ do_version_compare() */ -PHP_FUNCTION(version_compare) +void do_version_compare(INTERNAL_FUNCTION_PARAMETERS, int mode) { zval **v1, **v2; + int compare, argc; - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &v1, &v2) == FAILURE) { + argc = ZEND_NUM_ARGS(); + if (argc != 2 || zend_get_parameters_ex(argc, &v1, &v2) == FAILURE) { WRONG_PARAM_COUNT; } convert_to_string_ex(v1); convert_to_string_ex(v2); - RETURN_LONG(php_version_compare(Z_STRVAL_PP(v1), Z_STRVAL_PP(v2))); + compare = php_version_compare(Z_STRVAL_PP(v1), Z_STRVAL_PP(v2)); + switch (mode) { + case PHP_VC_LT: + RETURN_LONG(compare == -1); + case PHP_VC_LE: + RETURN_LONG(compare != 1); + case PHP_VC_GT: + RETURN_LONG(compare == 1); + case PHP_VC_GE: + RETURN_LONG(compare != -1); + case PHP_VC_EQ: + RETURN_LONG(compare == 0); + case PHP_VC_COMPARE: + default: + RETURN_LONG(compare); + } } + +/* }}} */ + +/* {{{ proto int version_compare(string ver1, string ver2) */ + +PHP_VCFUNC(PHP_FN(version_compare), PHP_VC_COMPARE); + +/* }}} */ +/* {{{ proto int version_lt(string ver1, string ver2) */ + +PHP_VCFUNC(PHP_FN(version_lt), PHP_VC_LT); + +/* }}} */ +/* {{{ proto int version_lt(string ver1, string ver2) */ + +PHP_VCFUNC(PHP_FN(version_le), PHP_VC_LE); + +/* }}} */ +/* {{{ proto int version_gt(string ver1, string ver2) */ + +PHP_VCFUNC(PHP_FN(version_gt), PHP_VC_GT); + +/* }}} */ +/* {{{ proto int version_ge(string ver1, string ver2) */ + +PHP_VCFUNC(PHP_FN(version_ge), PHP_VC_GE); + +/* }}} */ +/* {{{ proto int version_eq(string ver1, string ver2) */ + +PHP_VCFUNC(PHP_FN(version_eq), PHP_VC_EQ); /* }}} */

« previous php.cvs (#7738) next »