rpm
4.5
|
00001 00004 #include "system.h" 00005 00006 #include <rpmio.h> 00007 00008 #define _RPMEVR_INTERNAL 00009 #include <rpmdpkg.h> 00010 00011 #include "debug.h" 00012 00013 /*@access EVR_t @*/ 00014 00015 /*@unchecked@*/ 00016 int _rpmdpkg_debug = 0; 00017 00018 /* assume ascii */ 00019 static inline int dpkgEVRctype(char x) 00020 /*@*/ 00021 { 00022 return ( 00023 x == '~' ? -1 00024 : xisdigit(x) ? 0 00025 : !x ? 0 \ 00026 : xisalpha(x) ? x 00027 : x + 256 00028 ); 00029 } 00030 00031 int dpkgEVRcmp(const char *a, const char *b) 00032 { 00033 if (!a) a = ""; 00034 if (!b) b = ""; 00035 00036 while (*a || *b) { 00037 int first_diff= 0; 00038 00039 while ( (*a && !xisdigit(*a)) || (*b && !xisdigit(*b)) ) { 00040 int vc = dpkgEVRctype(*a); 00041 int rc = dpkgEVRctype(*b); 00042 if (vc != rc) return vc - rc; 00043 a++; b++; 00044 } 00045 00046 while (*a == '0') a++; 00047 while (*b == '0') b++; 00048 while (xisdigit(*a) && xisdigit(*b)) { 00049 if (!first_diff) first_diff = *a - *b; 00050 a++; b++; 00051 } 00052 if (xisdigit(*a)) return 1; 00053 if (xisdigit(*b)) return -1; 00054 if (first_diff) return first_diff; 00055 } 00056 return 0; 00057 } 00058 00059 int dpkgEVRparse(const char * evrstr, EVR_t evr) 00060 { 00061 return rpmEVRparse(evrstr, evr); 00062 } 00063 00064 int dpkgEVRcompare(const EVR_t a, const EVR_t b) 00065 { 00066 int r; 00067 00068 if (a->Elong > b->Elong) return 1; 00069 if (a->Elong < b->Elong) return -1; 00070 r = dpkgEVRcmp(a->V, b->V); if (r) return r; 00071 return dpkgEVRcmp(a->R, b->R); 00072 }