2 * Copyright (c) 2007, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
18 #include "sat_debug.h"
21 vercmp(const char *s1, const char *q1, const char *s2, const char *q2)
26 while (s1 < q1 && s2 < q2)
28 while (s1 < q1 && !(*s1 >= '0' && *s1 <= '9') &&
29 !(*s1 >= 'a' && *s1 <= 'z') && !(*s1 >= 'A' && *s1 <= 'Z'))
31 while (s2 < q2 && !(*s2 >= '0' && *s2 <= '9') &&
32 !(*s2 >= 'a' && *s2 <= 'z') && !(*s2 >= 'A' && *s2 <= 'Z'))
34 if ((*s1 >= '0' && *s1 <= '9') || (*s2 >= '0' && *s2 <= '9'))
36 while (*s1 == '0' && s1[1] >= '0' && s1[1] <= '9')
38 while (*s2 == '0' && s2[1] >= '0' && s2[1] <= '9')
40 for (e1 = s1; *e1 >= '0' && *e1 <= '9'; )
42 for (e2 = s2; *e2 >= '0' && *e2 <= '9'; )
44 r = e1 - s1 - (e2 - s2);
46 r = strncmp(s1, s2, e1 - s1);
48 return r > 0 ? 1 : -1;
52 for (e1 = s1; (*e1 >= 'a' && *e1 <= 'z') || (*e1 >= 'A' && *e1 <= 'Z'); )
54 for (e2 = s2; (*e2 >= 'a' && *e2 <= 'z') || (*e2 >= 'A' && *e2 <= 'Z'); )
56 r = e1 - s1 - (e2 - s2);
59 r = strncmp(s1, s2, e2 - s2);
60 return r >= 0 ? 1 : -1;
64 r = strncmp(s1, s2, e1 - s1);
65 return r <= 0 ? -1 : 1;
67 r = strncmp(s1, s2, e1 - s1);
69 return r > 0 ? 1 : -1;
74 return s1 < q1 ? 1 : s2 < q2 ? -1 : 0;
78 // edition (e:v-r) compare
80 evrcmp(Pool *pool, Id evr1id, Id evr2id)
83 const char *evr1, *evr2;
89 evr1 = id2str(pool, evr1id);
90 evr2 = id2str(pool, evr2id);
93 sat_debug (DEBUG_5,"evrcmp %s %s\n", evr1, evr2);
95 for (s1 = evr1; *s1 >= '0' && *s1 <= '9'; s1++)
97 for (s2 = evr2; *s2 >= '0' && *s2 <= '9'; s2++)
99 if (s1 == evr1 || *s1 != ':')
101 if (s2 == evr2 || *s2 != ':')
105 r = vercmp(evr1, s1, evr2, s2);
113 if (!pool->promoteepoch)
130 for (s1 = evr1, r1 = 0; *s1; s1++)
133 for (s2 = evr2, r2 = 0; *s2; s2++)
136 r = vercmp(evr1, r1 ? r1 : s1, evr2, r2 ? r2 : s2);
141 if (s1 != ++r1 && s2 != ++r2)
142 r = vercmp(r1, s1, r2, s2);