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;
77 // edition (e:v-r) compare
79 evrcmp(Pool *pool, Id evr1id, Id evr2id)
82 const char *evr1, *evr2;
88 evr1 = id2str(pool, evr1id);
89 evr2 = id2str(pool, evr2id);
92 POOL_DEBUG(DEBUG_EVRCMP, "evrcmp %s %s\n", evr1, evr2);
94 for (s1 = evr1; *s1 >= '0' && *s1 <= '9'; s1++)
96 for (s2 = evr2; *s2 >= '0' && *s2 <= '9'; s2++)
98 if (s1 == evr1 || *s1 != ':')
100 if (s2 == evr2 || *s2 != ':')
104 r = vercmp(evr1, s1, evr2, s2);
112 if (!pool->promoteepoch)
129 for (s1 = evr1, r1 = 0; *s1; s1++)
132 for (s2 = evr2, r2 = 0; *s2; s2++)
135 r = vercmp(evr1, r1 ? r1 : s1, evr2, r2 ? r2 : s2);
138 #ifdef DEBIAN_SEMANTICS
146 if (s1 != ++r1 && s2 != ++r2)
147 r = vercmp(r1, s1, r2, s2);