[gimp] plug-ins: make Darktable version checking more generic.



commit 1e78d3d249f3a030f0b90747b4d698ffac6acf94
Author: Jehan <jehan girinstud io>
Date:   Sun Nov 26 03:45:45 2017 +0100

    plug-ins: make Darktable version checking more generic.
    
    I realize that on Fedora 27, the output of `darktable --version` is:
    "this is darktable darktable-2.2.5-4.fc27"
    This is different from the expected output in our plug-in ("this is
    darktable 2.2.5"). I assume this version string can be customized and
    distribution packagers will use the capability. So a regular expression,
    in a slightly more flexible fashion would be better. I still assume that
    the version string with start with "this is darktable", but then I
    accept any non-number string until I reach a common major.minor.patch
    version-looking string.

 plug-ins/file-raw/file-darktable.c |   31 ++++++++++++++++++++++++++-----
 1 files changed, 26 insertions(+), 5 deletions(-)
---
diff --git a/plug-ins/file-raw/file-darktable.c b/plug-ins/file-raw/file-darktable.c
index e8ac2a5..f4b10f6 100644
--- a/plug-ins/file-raw/file-darktable.c
+++ b/plug-ins/file-raw/file-darktable.c
@@ -124,12 +124,31 @@ init (void)
                     NULL,
                     &error))
     {
-      gint major, minor, patch;
-
-      if (sscanf (darktable_stdout,
-                  "this is darktable %d.%d.%d",
-                  &major, &minor, &patch) == 3)
+      GRegex     *regex;
+      GMatchInfo *matches;
+      gint        major;
+      gint        minor;
+
+      /* A default darktable would apparently output something like
+       * "this is darktable 2.2.5", but this version string is
+       * customizable. In the official Fedora package for instance, I
+       * encountered a "this is darktable darktable-2.2.5-4.fc27".
+       * Therefore make the version recognition a bit more flexible.
+       */
+      regex = g_regex_new ("this is darktable [^0-9]*([0-9]+)\\.([0-9]+)\\.([0-9]+)",
+                           0, 0, NULL);
+      if (g_regex_match (regex, darktable_stdout, 0, &matches))
         {
+          gchar *match;
+
+          match = g_match_info_fetch (matches, 1);
+          major = g_ascii_strtoll (match, NULL, 10);
+          g_free (match);
+
+          match = g_match_info_fetch (matches, 2);
+          minor = g_ascii_strtoll (match, NULL, 10);
+          g_free (match);
+
           if (((major == 1 && minor >= 7) || major >= 2))
             {
               if (g_strstr_len (darktable_stdout, -1,
@@ -139,6 +158,8 @@ init (void)
                 }
             }
         }
+      g_match_info_free (matches);
+      g_regex_unref (regex);
     }
   else if (debug_prints)
     printf ("[%s] g_spawn_sync failed\n", __FILE__);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]