#include <errno.h>
+#include <ctype.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/utsname.h>
/* XXX unknown os - how should we handle this? */
}
}
+
+int vercmp(char * one, char * two) {
+ int num1, num2;
+ char oldch1, oldch2;
+ char * str1, * str2;
+ int rc;
+ int isnum;
+
+ if (!strcmp(one, two)) return 0;
+
+ str1 = alloca(strlen(one) + 1);
+ str2 = alloca(strlen(two) + 1);
+
+ strcpy(str1, one);
+ strcpy(str2, two);
+
+ one = str1;
+ two = str2;
+
+ while (*one && *two) {
+ while (*one && !isalnum(*one)) one++;
+ while (*two && !isalnum(*two)) two++;
+
+ str1 = one;
+ str2 = two;
+
+ if (isdigit(*str1)) {
+ while (*str1 && isdigit(*str1)) str1++;
+ while (*str2 && isdigit(*str2)) str2++;
+ isnum = 1;
+ } else {
+ while (*str1 && isalpha(*str1)) str1++;
+ while (*str2 && isalpha(*str2)) str2++;
+ isnum = 0;
+ }
+
+ oldch1 = *str1;
+ *str1 = '\0';
+ oldch2 = *str2;
+ *str2 = '\0';
+
+ if (one == str1) return -1; /* arbitrary */
+ if (two == str2) return -1;
+
+ if (isnum) {
+ num1 = atoi(one);
+ num2 = atoi(two);
+
+ if (num1 < num2)
+ return -1;
+ else if (num1 > num2)
+ return 1;
+ } else {
+ rc = strcmp(one, two);
+ if (rc) return rc;
+ }
+
+ *str1 = oldch1;
+ one = str1;
+ *str2 = oldch2;
+ two = str2;
+ }
+
+ if ((!*one) && (!*two)) return 0;
+
+ if (!*one) return 1; else return -1;
+}