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 void init_ver(struct ver *v, 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 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 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 main(int ac, char *av[]) {
117 if (ac < 2) return 1;
125 if (an == 0 && a.type == 2 && b.sep == 0 && b.type == 1) {
127 } else if (bn == 0 && b.type == 2 && a.sep == 0 && a.type == 1) {
130 printf("%s\n", an < bn ? "-1" : "1");
134 cmp = ver_cmp(&a, &b);
141 /* if we've gotten here, and both have releases, check those */
142 if (a.relstr && b.relstr && a.release != b.release) {
143 printf("%s\n", a.release < b.release ? "-1" : "1");