Make the version_ok() hack a little more...uh, big.
authorRyan C. Gordon <icculus@icculus.org>
Wed, 16 Jun 2004 07:07:13 +0000
changeset 57 26c5e31040e5
parent 50 bbbabb3b038a
child 58 06ca80107923
Make the version_ok() hack a little more...uh, big.
mojopatch.c
platform_unix.c
--- a/mojopatch.c	Sun May 30 17:07:53 2004 +0000
+++ b/mojopatch.c	Wed Jun 16 07:07:13 2004 +0000
@@ -581,9 +581,39 @@
     if (*allowed_ver == '\0')
         return 1;  /* No specified version? Anything is okay, then. */
 
+    if (strcmp(allowed_ver, ver) == 0)
+        return -1;  /* all patched up. */
+
     buf = (char *) alloca(strlen(allowed_ver) + 1);
     strcpy(buf, allowed_ver);
 
+    const char *lessThan = "less than ";
+    const size_t lessThanLen = strlen(lessThan);
+    if (strncmp(buf, lessThan, lessThanLen) == 0)
+    {
+        char *endptr = NULL;
+        double dver;
+        double dallow;
+        ptr = buf + lessThanLen;
+        *ptr = '\0';
+        ptr++;
+
+        dver = strtod(ver, &endptr);
+        if (endptr == ver)
+            return 0;
+
+        dallow = strtod(ptr, &endptr);
+        if (endptr == ptr)
+            return 0;
+
+        if (dver < dallow)
+            return(1);
+        else if (dver == dallow)
+            return(-1);
+
+        return(0);
+    } /* if */
+
     while ((ptr = strstr(buf, " or ")) != NULL)
     {
         *ptr = '\0';
--- a/platform_unix.c	Sun May 30 17:07:53 2004 +0000
+++ b/platform_unix.c	Wed Jun 16 07:07:13 2004 +0000
@@ -329,21 +329,13 @@
     ptr = find_info_plist_version(mem);
     if (ptr != NULL)
     {
-        if (version_ok(ptr, version))
-            retval = 1;
-        else
+        retval = version_ok(ptr, version);
+        if (retval == -1)
+            _fatal("You seem to be all patched up already!");
+        else if (retval == 0)
         {
-            if (strcmp(ptr, newversion) == 0)
-            {
-                _fatal("You seem to be all patched up already!");
-                retval = -1;
-            } /* if */
-            else
-            {
-                _fatal("This patch applies to version '%s', but you have '%s'.",
-                        version, ptr);
-                retval = 0;
-            } /* else */
+            _fatal("This patch applies to version '%s', but you have '%s'.",
+                    version, ptr);
         } /* else */
     } /* if */