2 * Copyright (c) 2007, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
20 vercmp(const char *s1, const char *q1, const char *s2, const char *q2)
25 while (s1 < q1 && s2 < q2)
27 while (s1 < q1 && !(*s1 >= '0' && *s1 <= '9') &&
28 !(*s1 >= 'a' && *s1 <= 'z') && !(*s1 >= 'A' && *s1 <= 'Z'))
30 while (s2 < q2 && !(*s2 >= '0' && *s2 <= '9') &&
31 !(*s2 >= 'a' && *s2 <= 'z') && !(*s2 >= 'A' && *s2 <= 'Z'))
33 if ((*s1 >= '0' && *s1 <= '9') || (*s2 >= '0' && *s2 <= '9'))
35 while (*s1 == '0' && s1[1] >= '0' && s1[1] <= '9')
37 while (*s2 == '0' && s2[1] >= '0' && s2[1] <= '9')
39 for (e1 = s1; *e1 >= '0' && *e1 <= '9'; )
41 for (e2 = s2; *e2 >= '0' && *e2 <= '9'; )
43 r = e1 - s1 - (e2 - s2);
45 r = strncmp(s1, s2, e1 - s1);
47 return r > 0 ? 1 : -1;
51 for (e1 = s1; (*e1 >= 'a' && *e1 <= 'z') || (*e1 >= 'A' && *e1 <= 'Z'); )
53 for (e2 = s2; (*e2 >= 'a' && *e2 <= 'z') || (*e2 >= 'A' && *e2 <= 'Z'); )
55 r = e1 - s1 - (e2 - s2);
58 r = strncmp(s1, s2, e2 - s2);
59 return r >= 0 ? 1 : -1;
63 r = strncmp(s1, s2, e1 - s1);
64 return r <= 0 ? -1 : 1;
66 r = strncmp(s1, s2, e1 - s1);
68 return r > 0 ? 1 : -1;
73 return s1 < q1 ? 1 : s2 < q2 ? -1 : 0;
76 #define EVRCMP_COMPARE 0
77 #define EVRCMP_MATCH_RELEASE 1
78 #define EVRCMP_MATCH 2
80 // edition (e:v-r) compare
82 evrcmp(Pool *pool, Id evr1id, Id evr2id, int mode)
85 const char *evr1, *evr2;
91 evr1 = id2str(pool, evr1id);
92 evr2 = id2str(pool, evr2id);
95 POOL_DEBUG(DEBUG_EVRCMP, "evrcmp %s %s mode=%d\n", evr1, evr2, mode);
97 for (s1 = evr1; *s1 >= '0' && *s1 <= '9'; s1++)
99 for (s2 = evr2; *s2 >= '0' && *s2 <= '9'; s2++)
101 if (mode == EVRCMP_MATCH && (*evr1 == ':' || *evr2 == ':'))
103 /* empty epoch, skip epoch check */
111 if (s1 == evr1 || *s1 != ':')
113 if (s2 == evr2 || *s2 != ':')
117 r = vercmp(evr1, s1, evr2, s2);
125 if (!pool->promoteepoch)
142 for (s1 = evr1, r1 = 0; *s1; s1++)
145 for (s2 = evr2, r2 = 0; *s2; s2++)
150 if (mode != EVRCMP_MATCH || (evr1 != (r1 ? r1 : s1) && evr2 != (r2 ? r2 : s2)))
151 r = vercmp(evr1, r1 ? r1 : s1, evr2, r2 ? r2 : s2);
155 if (mode == EVRCMP_COMPARE)
164 if (s1 != ++r1 && s2 != ++r2)
165 r = vercmp(r1, s1, r2, s2);
171 evrmatch(Pool *pool, Id evrid, const char *epoch, const char *version, const char *release)
178 evr1 = id2str(pool, evrid);
179 for (s1 = evr1; *s1 >= '0' && *s1 <= '9'; s1++)
181 if (s1 != evr1 && *s1 == ':')
185 r = vercmp(evr1, s1, epoch, epoch + strlen(epoch));
193 while (*epoch == '0')
198 for (s1 = evr1, r1 = 0; *s1; s1++)
203 r = vercmp(evr1, r1 ? r1 : s1, version, version + strlen(version));
211 r = vercmp(r1 + 1, s1, release, release + strlen(release));