cvs: php4 /ext/standard versioning.c

From: Date: Fri, 05 Jul 2002 00:55:02 +0000
Subject: cvs: php4 /ext/standard versioning.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-12714@lists.php.net to get a copy of this message
ssb Thu Jul 4 20:55:02 2002 EDT Modified files: /php4/ext/standard versioning.c Log: (PHP version_compare) added "alpha" and "beta", make tests pass Index: php4/ext/standard/versioning.c diff -u php4/ext/standard/versioning.c:1.9 php4/ext/standard/versioning.c:1.10 --- php4/ext/standard/versioning.c:1.9 Sun May 26 08:01:30 2002 +++ php4/ext/standard/versioning.c Thu Jul 4 20:55:02 2002 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: versioning.c,v 1.9 2002/05/26 12:01:30 ssb Exp $ */ +/* $Id: versioning.c,v 1.10 2002/07/05 00:55:02 ssb Exp $ */ #include <stdio.h> #include <sys/types.h> @@ -51,16 +51,28 @@ * s/([^\d\.])([^\D\.])/$1.$2/g; * s/([^\D\.])([^\d\.])/$1.$2/g; */ -#define isdigdot(x) (isdigit(x)||(x)=='.') +#define isdig(x) (isdigit(x)&&(x)!='.') +#define isndig(x) (!isdigit(x)&&(x)!='.') #define isspecialver(x) ((x)=='-'||(x)=='_'||(x)=='+') lq = *(q - 1); - if ((isdigdot(*p) != isdigdot(lp) || isspecialver(*p)) && - (lq != '.' && *p != '.')) { - lq = *q; - *q++ = '.'; - } - *q++ = lp = *p++; + if (isspecialver(*p)) { + if (lq != '.') { + lq = *q++ = '.'; + } + } else if ((isndig(lp) && isdig(*p)) || (isdig(lp) && isndig(*p))) { + if (lq != '.') { + *q++ = '.'; + } + lq = *q++ = *p; + } else if (!isalnum(*p)) { + if (lq != '.') { + lq = *q++ = '.'; + } + } else { + lq = *q++ = *p; + } + lp = *p++; } *q++ = '\0'; return buf; @@ -69,30 +81,37 @@ /* }}} */ /* {{{ compare_special_version_forms() */ +typedef struct { + const char *name; + int order; +} special_forms_t; + static int -compare_special_version_forms(const char *form1, const char *form2) +compare_special_version_forms(char *form1, char *form2) { int i, found1 = -1, found2 = -1; - char **pp; - static char *special_forms[] = { - "dev", - "a", - "b", - "RC", - "#N#", - "pl", - NULL + special_forms_t special_forms[9] = { + {"dev", 0}, + {"alpha", 1}, + {"a", 1}, + {"beta", 2}, + {"b", 2}, + {"RC", 3}, + {"#", 4}, + {"pl", 5}, + NULL, }; + special_forms_t *pp; - for (pp = special_forms, i = 0; *pp != NULL; pp++, i++) { - if (strncmp(form1, *pp, strlen(*pp)) == 0) { - found1 = i; + for (pp = special_forms; pp; pp++) { + if (strncmp(form1, pp->name, strlen(pp->name)) == 0) { + found1 = pp->order; break; } } - for (pp = special_forms, i = 0; *pp != NULL; pp++, i++) { - if (strncmp(form2, *pp, strlen(*pp)) == 0) { - found2 = i; + for (pp = special_forms; pp; pp++) { + if (strncmp(form2, pp->name, strlen(pp->name)) == 0) { + found2 = pp->order; break; } } @@ -118,8 +137,16 @@ return *orig_ver1 ? 1 : -1; } } - ver1 = php_canonicalize_version(orig_ver1); - ver2 = php_canonicalize_version(orig_ver2); + if (orig_ver1[0] == '#') { + ver1 = estrdup(orig_ver1); + } else { + ver1 = php_canonicalize_version(orig_ver1); + } + if (orig_ver2[0] == '#') { + ver2 = estrdup(orig_ver2); + } else { + ver2 = php_canonicalize_version(orig_ver2); + } p1 = n1 = ver1; p2 = n2 = ver2; while (*p1 && *p2 && n1 && n2) {

« previous php.cvs (#12714) next »