X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/mLib/blobdiff_plain/0683223aa93d14e4b1d0620010392c518a3a6392..e57e2b62e774ced2ee062715c2e3f1d444895b06:/versioncmp.c diff --git a/versioncmp.c b/versioncmp.c index 335098b..7b67dc2 100644 --- a/versioncmp.c +++ b/versioncmp.c @@ -7,7 +7,7 @@ * (c) 2007 Straylight/Edgeware */ -/*----- Licensing notice --------------------------------------------------* +/*----- Licensing notice --------------------------------------------------* * * This file is part of the mLib utilities library. * @@ -15,12 +15,12 @@ * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. - * + * * mLib is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Library General Public License for more details. - * + * * You should have received a copy of the GNU Library General Public * License along with mLib; if not, write to the Free * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, @@ -125,28 +125,26 @@ static int vcmp(const char *va, const char *val, pa = vchr(&va, val); pb = vchr(&vb, vbl); for (;;) { - if (pa == va && pb == vb) - break; - else if (pa == va) - return (-1); - else if (pb == vb) - return (+1); - else if (*pa == *pb) { - pa++; pb++; - continue; - } else if (isalpha((unsigned char)*pa) == isalpha((unsigned char)*pb)) - return (CMP(*pa, *pb)); - else if (isalpha((unsigned char)*pa)) - return (-1); - else - return (+1); + if (pa == va) ia = 1; + else if (isalpha((unsigned char)*pa)) ia = 2; + else if (*pa == '~') ia = 0; + else ia = 3; + + if (pb == vb) ib = 1; + else if (isalpha((unsigned char)*pb)) ib = 2; + else if (*pb == '~') ib = 0; + else ib = 3; + + if (ia != ib) return (CMP(ia, ib)); + else if (pa == va && pb == vb) break; + else if (*pa != *pb) return (CMP(*pa, *pb)); + pa++; pb++; } /* --- Compare digit portions --- */ ia = vint(&va, val); ib = vint(&vb, vbl); - if (ia != ib) - return (CMP(ia, ib)); + if (ia != ib) return (CMP(ia, ib)); } } @@ -166,7 +164,7 @@ static void vsplit(const char *v, struct vinfo *vi) n = strlen(v); if ((p = strrchr(v, '-')) == 0) vi->s = vi->sl = 0; - else { + else { vi->s = p + 1; vi->sl = v + n; n = p - v;