7 char str[1024]; /* string rep */
8 char *s; /* start component */
9 int cn; /* current component number */
10 char *next; /* start of potential next component */
11 char keep; /* character over-written with null byte */
12 int sep; /* number of characters in separator */
14 int nv; /* numeric value */
15 int type; /* 0 null, 1 text, 2 numeric */
20 static void init_ver(struct ver *v, const char *s) {
21 strncpy(v->str, s, 1023);
30 /* scan for trailing release */
32 n = strlen(v->str) - 1;
33 if (n > 0 && isdigit(v->str[n])) {
34 while (isdigit(v->str[n])) {
38 v->relstr = v->str + n;
39 v->release = atoi(v->str + n + 1);
46 static int ver_cmp(struct ver *a, struct ver *b) {
47 if (a->type == 0 && b->type == 0) {
50 if (a->type != b->type) {
51 return a->type < b->type ? -1 : 1;
55 cmp = strcmp(a->s, b->s);
59 return cmp < 0 ? -1 : 1;
63 return a->nv < b->nv ? -1 : 1;
68 static int next_comp(struct ver *v) {
71 /* restore over-written character */
78 /* skip over anything that isn't alphanumeric */
80 while (*s && !isalnum(*s)) {
86 /* zero return if at end of string */
92 while (isdigit(*s)) s++;
97 } else if (isalpha(*s)) {
99 while (isalpha(*s)) s++;
110 * alphabetic less than numeric
112 int zpm_vercmp(const char *vsa, const char *vsb) {
123 if (an == 0 && a.type == 2 && b.sep == 0 && b.type == 1) {
125 } else if (bn == 0 && b.type == 2 && a.sep == 0 && a.type == 1) {
128 return an < bn ? -1 : 1;
130 cmp = ver_cmp(&a, &b);
136 /* if we've gotten here, and both have releases, check those */
137 if (a.relstr && b.relstr && a.release != b.release) {
138 return a.release < b.release ? -1 : 1;