chiark / gitweb /
mdup.h: Remove spurious duplicate summary line from comment.
[mLib] / versioncmp.c
index 335098b88f1ea192fa4e1e7c67f90c6213f277fb..7b67dc21446cf6ed916cc1eb6881429172171329 100644 (file)
@@ -7,7 +7,7 @@
  * (c) 2007 Straylight/Edgeware
  */
 
-/*----- Licensing notice --------------------------------------------------* 
+/*----- Licensing notice --------------------------------------------------*
  *
  * This file is part of the mLib utilities library.
  *
  * 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;