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