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 while (*one && *two) {
00037 while (*one && !xisalnum(*one)) one++;
00038 while (*two && !xisalnum(*two)) two++;
00039
00040 str1 = one;
00041 str2 = two;
00042
00043
00044
00045
00046 if (xisdigit(*str1) || xisdigit(*str2)) {
00047 while (*str1 && xisdigit(*str1)) str1++;
00048 while (*str2 && xisdigit(*str2)) str2++;
00049 isnum = 1;
00050 } else {
00051 while (*str1 && xisalpha(*str1)) str1++;
00052 while (*str2 && xisalpha(*str2)) str2++;
00053 isnum = 0;
00054 }
00055
00056
00057
00058 oldch1 = *str1;
00059 *str1 = '\0';
00060 oldch2 = *str2;
00061 *str2 = '\0';
00062
00063 #if 0
00064
00065
00066 if (one == str1) return -1;
00067 if (two == str2) return -1;
00068 #endif
00069
00070 if (isnum) {
00071
00072
00073
00074
00075
00076 while (*one == '0') one++;
00077 while (*two == '0') two++;
00078
00079
00080 if (strlen(one) > strlen(two)) return 1;
00081 if (strlen(two) > strlen(one)) return -1;
00082 }
00083
00084
00085
00086
00087
00088 rc = strcmp(one, two);
00089 if (rc) return rc;
00090
00091
00092 *str1 = oldch1;
00093 one = str1;
00094 *str2 = oldch2;
00095 two = str2;
00096 }
00097
00098
00099
00100
00101 if ((!*one) && (!*two)) return 0;
00102
00103
00104 if (!*one) return -1; else return 1;
00105 }