2013-02-26 01:36:47 -05:00
|
|
|
#define _GNU_SOURCE
|
|
|
|
#include <ctype.h>
|
2011-09-11 22:45:56 -04:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
int strverscmp(const char *l, const char *r)
|
|
|
|
{
|
2013-02-26 01:36:47 -05:00
|
|
|
int haszero=1;
|
|
|
|
while (*l==*r) {
|
|
|
|
if (!*l) return 0;
|
|
|
|
|
|
|
|
if (*l=='0') {
|
|
|
|
if (haszero==1) {
|
|
|
|
haszero=0;
|
|
|
|
}
|
|
|
|
} else if (isdigit(*l)) {
|
|
|
|
if (haszero==1) {
|
|
|
|
haszero=2;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
haszero=1;
|
|
|
|
}
|
|
|
|
l++; r++;
|
|
|
|
}
|
|
|
|
if (haszero==1 && (*l=='0' || *r=='0')) {
|
|
|
|
haszero=0;
|
|
|
|
}
|
|
|
|
if ((isdigit(*l) && isdigit(*r) ) && haszero) {
|
|
|
|
size_t lenl=0, lenr=0;
|
|
|
|
while (isdigit(l[lenl]) ) lenl++;
|
|
|
|
while (isdigit(r[lenr]) ) lenr++;
|
|
|
|
if (lenl==lenr) {
|
|
|
|
return (*l - *r);
|
2013-02-26 01:42:11 -05:00
|
|
|
} else if (lenl>lenr) {
|
|
|
|
return 1;
|
2013-02-26 01:36:47 -05:00
|
|
|
} else {
|
2013-02-26 01:42:11 -05:00
|
|
|
return -1;
|
2013-02-26 01:36:47 -05:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return (*l - *r);
|
|
|
|
}
|
2011-09-11 22:45:56 -04:00
|
|
|
}
|