00001
00005 #include "system.h"
00006
00007 #include <rpmlib.h>
00008
00009 #include "debug.h"
00010
00011
00012
00013
00014
00015 int rpmvercmp(const char * a, const char * b)
00016 {
00017 char oldch1, oldch2;
00018 char * str1, * str2;
00019 char * one, * two;
00020 int rc;
00021 int isnum;
00022
00023
00024 if (!strcmp(a, b)) return 0;
00025
00026 str1 = alloca(strlen(a) + 1);
00027 str2 = alloca(strlen(b) + 1);
00028
00029 strcpy(str1, a);
00030 strcpy(str2, b);
00031
00032 one = str1;
00033 two = str2;
00034
00035
00036
00037
00038 while (*one && *two) {
00039 while (*one && !xisalnum(*one)) one++;
00040 while (*two && !xisalnum(*two)) two++;
00041
00042 str1 = one;
00043 str2 = two;
00044
00045
00046
00047
00048 if (xisdigit(*str1)) {
00049 while (*str1 && xisdigit(*str1)) str1++;
00050 while (*str2 && xisdigit(*str2)) str2++;
00051 isnum = 1;
00052 } else {
00053 while (*str1 && xisalpha(*str1)) str1++;
00054 while (*str2 && xisalpha(*str2)) str2++;
00055 isnum = 0;
00056 }
00057
00058
00059
00060
00061 oldch1 = *str1;
00062 *str1 = '\0';
00063 oldch2 = *str2;
00064 *str2 = '\0';
00065
00066
00067
00068
00069 if (one == str1) return -1;
00070
00071 if (two == str2) return (isnum ? 1 : -1);
00072
00073 if (isnum) {
00074
00075
00076
00077
00078
00079 while (*one == '0') one++;
00080 while (*two == '0') two++;
00081
00082
00083 if (strlen(one) > strlen(two)) return 1;
00084 if (strlen(two) > strlen(one)) return -1;
00085 }
00086
00087
00088
00089
00090
00091 rc = strcmp(one, two);
00092 if (rc) return rc;
00093
00094
00095
00096 *str1 = oldch1;
00097 one = str1;
00098 *str2 = oldch2;
00099 two = str2;
00100
00101 }
00102
00103
00104
00105
00106
00107
00108
00109 if ((!*one) && (!*two)) return 0;
00110
00111
00112 if (!*one) return -1; else return 1;
00113
00114 }