From: ewt Date: Sun, 25 Feb 1996 22:10:25 +0000 (+0000) Subject: added vercmp() X-Git-Tag: tznext/4.11.0.1.tizen20130304~11541 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=faa8bd69ac8e17e03d0ed4a6598095850bb69a07;p=tools%2Flibrpm-tizen.git added vercmp() CVS patchset: 419 CVS date: 1996/02/25 22:10:25 --- diff --git a/lib/misc.c b/lib/misc.c index f4472d6..6a0910f 100644 --- a/lib/misc.c +++ b/lib/misc.c @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -117,3 +118,70 @@ static void init_arch_os(void) /* XXX unknown os - how should we handle this? */ } } + +int vercmp(char * one, char * two) { + int num1, num2; + char oldch1, oldch2; + char * str1, * str2; + int rc; + int isnum; + + if (!strcmp(one, two)) return 0; + + str1 = alloca(strlen(one) + 1); + str2 = alloca(strlen(two) + 1); + + strcpy(str1, one); + strcpy(str2, two); + + one = str1; + two = str2; + + while (*one && *two) { + while (*one && !isalnum(*one)) one++; + while (*two && !isalnum(*two)) two++; + + str1 = one; + str2 = two; + + if (isdigit(*str1)) { + while (*str1 && isdigit(*str1)) str1++; + while (*str2 && isdigit(*str2)) str2++; + isnum = 1; + } else { + while (*str1 && isalpha(*str1)) str1++; + while (*str2 && isalpha(*str2)) str2++; + isnum = 0; + } + + oldch1 = *str1; + *str1 = '\0'; + oldch2 = *str2; + *str2 = '\0'; + + if (one == str1) return -1; /* arbitrary */ + if (two == str2) return -1; + + if (isnum) { + num1 = atoi(one); + num2 = atoi(two); + + if (num1 < num2) + return -1; + else if (num1 > num2) + return 1; + } else { + rc = strcmp(one, two); + if (rc) return rc; + } + + *str1 = oldch1; + one = str1; + *str2 = oldch2; + two = str2; + } + + if ((!*one) && (!*two)) return 0; + + if (!*one) return 1; else return -1; +} diff --git a/lib/misc.h b/lib/misc.h index 341dd8f..903f886 100644 --- a/lib/misc.h +++ b/lib/misc.h @@ -11,4 +11,6 @@ int getArchNum(void); char *getOsName(void); char *getArchName(void); +int vercmp(char * one, char * two); + #endif