diff options
Diffstat (limited to 'ext/standard/versioning.c')
| -rw-r--r-- | ext/standard/versioning.c | 90 | 
1 files changed, 30 insertions, 60 deletions
diff --git a/ext/standard/versioning.c b/ext/standard/versioning.c index 1e3738c6e1..e03c5eaa1b 100644 --- a/ext/standard/versioning.c +++ b/ext/standard/versioning.c @@ -29,18 +29,6 @@  #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 * @@ -182,68 +170,50 @@ php_version_compare(const char *orig_ver1, const char *orig_ver2)  /* }}} */  /* {{{ do_version_compare() */ -void do_version_compare(INTERNAL_FUNCTION_PARAMETERS, int mode) +/* {{{ proto int version_compare(string ver1, string ver2 [, string oper]) +  Compares two "PHP-standardized" version number strings */ + +PHP_FUNCTION(version_compare)  { -    zval **v1, **v2; +    zval **v1, **v2, **oper;  	int compare, argc; +	char *op;  	argc = ZEND_NUM_ARGS(); -	if (argc != 2 || zend_get_parameters_ex(argc, &v1, &v2) == FAILURE) { +	if (argc < 2 || argc > 3 || zend_get_parameters_ex(argc, &v1, &v2, &oper) == FAILURE) {  		WRONG_PARAM_COUNT;  	}  	convert_to_string_ex(v1);  	convert_to_string_ex(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); +	if (argc == 2) { +		RETURN_LONG(compare); +	} +	convert_to_string_ex(oper); +	op = Z_STRVAL_PP(oper); +	if (!strcmp(op, "<") || !strcmp(op, "lt")) { +		RETURN_LONG(compare == -1); +	} +	if (!strcmp(op, "<=") || !strcmp(op, "le")) { +		RETURN_LONG(compare != 1); +	} +	if (!strcmp(op, ">") || !strcmp(op, "gt")) { +		RETURN_LONG(compare == 1); +	} +	if (!strcmp(op, ">=") || !strcmp(op, "ge")) { +		RETURN_LONG(compare != -1);  	} +	if (!strcmp(op, "==") || !strcmp(op, "=") || !strcmp(op, "eq")) { +		RETURN_LONG(compare == 0); +	} +	if (!strcmp(op, "!=") || !strcmp(op, "<>") || !strcmp(op, "ne")) { +		RETURN_LONG(compare != 0); +	} +	RETURN_NULL();  }  /* }}} */ -/* {{{ 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); - -/* }}} */ -  /*   * Local variables:   * tab-width: 4  | 
