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 */
18 static void init_ver(struct ver *v, const char *s) {
19 strncpy(v->str, s, 1023);
28 static int ver_cmp(struct ver *a, struct ver *b) {
29 if (a->type == 0 && b->type == 0) {
32 if (a->type != b->type) {
33 return a->type < b->type ? -1 : 1;
37 if (a->s && ! b->s) return 1;
38 if (b->s && ! a->s) return -1;
39 if (!b->s && ! a->s) {
42 cmp = strcmp(a->s, b->s);
46 return cmp < 0 ? -1 : 1;
50 return a->nv < b->nv ? -1 : 1;
55 static int next_comp(struct ver *v) {
58 /* restore over-written character */
65 /* skip over anything that isn't alphanumeric */
67 while (*s && !isalnum(*s)) {
73 /* zero return if at end of string */
79 while (isdigit(*s)) s++;
84 } else if (isalpha(*s)) {
86 while (isalpha(*s)) s++;
97 * alphabetic less than numeric
99 int zpm_vercmp(const char *vsa, const char *vsb) {
120 if (an == 0 && a.type == 2 && b.sep == 0 && b.type == 1) {
122 } else if (bn == 0 && b.type == 2 && a.sep == 0 && a.type == 1) {
125 return an < bn ? -1 : 1;
127 if (an == 0 && bn == 0) {
130 cmp = ver_cmp(&a, &b);