diff options
author | ewt <devnull@localhost> | 1996-02-25 22:10:25 +0000 |
---|---|---|
committer | ewt <devnull@localhost> | 1996-02-25 22:10:25 +0000 |
commit | faa8bd69ac8e17e03d0ed4a6598095850bb69a07 (patch) | |
tree | 80e9c2bc9e7ced53da9f05bdaa2b08ede5c684ca /lib | |
parent | 8ecf043b19cda5c7c864aeeeb94d37becd7e4cda (diff) | |
download | rpm-faa8bd69ac8e17e03d0ed4a6598095850bb69a07.tar.gz rpm-faa8bd69ac8e17e03d0ed4a6598095850bb69a07.tar.bz2 rpm-faa8bd69ac8e17e03d0ed4a6598095850bb69a07.zip |
added vercmp()
CVS patchset: 419
CVS date: 1996/02/25 22:10:25
Diffstat (limited to 'lib')
-rw-r--r-- | lib/misc.c | 68 | ||||
-rw-r--r-- | lib/misc.h | 2 |
2 files changed, 70 insertions, 0 deletions
diff --git a/lib/misc.c b/lib/misc.c index f4472d6d8..6a0910f03 100644 --- a/lib/misc.c +++ b/lib/misc.c @@ -1,4 +1,5 @@ #include <errno.h> +#include <ctype.h> #include <stdlib.h> #include <sys/stat.h> #include <sys/utsname.h> @@ -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 341dd8fd5..903f886d7 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 |