Skip ahead in the patchfile if a given product is already patched.
authorRyan C. Gordon <icculus@icculus.org>
Fri, 28 May 2004 12:56:49 +0000
changeset 40 bac807d1f829
parent 39 89ddd0c0e7b9
child 41 7edecb332efb
Skip ahead in the patchfile if a given product is already patched.
mojopatch.c
platform_unix.c
--- a/mojopatch.c	Fri May 28 12:52:11 2004 +0000
+++ b/mojopatch.c	Fri May 28 12:56:49 2004 +0000
@@ -157,6 +157,7 @@
 static int appending = 0;
 static int alwaysadd = 0;
 static int quietonsuccess = 0;
+static int skip_patch = 0;
 static PatchCommands command = COMMAND_NONE;
 
 static const char *patchfile = NULL;
@@ -539,11 +540,16 @@
 static void _current_operation(const char *fmt, ...)
 {
     char buf[512];
-    va_list ap;
-    va_start(ap, fmt);
-    vsnprintf(buf, sizeof (buf), fmt, ap);
-    va_end(ap);
-    buf[sizeof(buf)-1] = '\0';
+    if (skip_patch)
+        strcpy(buf, "Skipping ahead...");
+    else
+    {
+        va_list ap;
+        va_start(ap, fmt);
+        vsnprintf(buf, sizeof (buf), fmt, ap);
+        va_end(ap);
+        buf[sizeof(buf)-1] = '\0';
+    } /* else */
     ui_status(buf);
     ui_pump();
 } /* _current_operation */
@@ -605,7 +611,7 @@
 
 static inline int info_only(void)
 {
-    return(command == COMMAND_INFO);
+    return((command == COMMAND_INFO) || (skip_patch));
 } /* info_only */
 
 
@@ -1860,11 +1866,12 @@
 
     if (!info_only())
     {
-        if (!chdir_by_identifier(h->product, h->identifier,
-                                 h->version, h->newversion))
-        {
+        int rc = chdir_by_identifier(h->product, h->identifier,
+                                     h->version, h->newversion);
+        if (rc == 0)
             return(PATCHERROR);
-        } /* if */
+        else if (rc == -1)
+            skip_patch = 1;
     } /* if */
 
     if (*h->readmefname)
@@ -1932,6 +1939,8 @@
             } /* if */
         } /* if */
 
+        skip_patch = 0;  /* reset for next patch... */
+
         /* !!! FIXME: This loses command line overrides! */
         memset(&header, '\0', sizeof (header));
 
--- a/platform_unix.c	Fri May 28 12:52:11 2004 +0000
+++ b/platform_unix.c	Fri May 28 12:56:49 2004 +0000
@@ -318,15 +318,17 @@
             retval = 1;
         else
         {
-            if (strcmp(version, newversion) == 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 */
-            free(mem);
-            return(0);
         } /* else */
     } /* if */
 
@@ -335,7 +337,7 @@
     if (io != NULL)
         fclose(io);
 
-    if (!retval) _fatal("Can't determine product's installed version.");
+    if (retval == 0) _fatal("Can't determine product's installed version.");
     return(retval);
 } /* parse_info_dot_plist */