[gimp] app, plug-ins: redirect plug-in-script-fu-eval to text console in…



commit c1d2f35b7349c6c48076b1544363d36edfa8d461
Author: Jehan <jehan girinstud io>
Date:   Sun Apr 17 14:23:21 2022 +0200

    app, plug-ins: redirect plug-in-script-fu-eval to text console in…
    
    … plug-in code.
    
    In particular, we should not hardcode this in core code anymore. The
    behavior is otherwise exactly the same, except that we made the core
    code generic as it should be.

 app/core/gimp-batch.c          | 71 +++++++++++++++---------------------------
 plug-ins/script-fu/script-fu.c |  6 +++-
 2 files changed, 30 insertions(+), 47 deletions(-)
---
diff --git a/app/core/gimp-batch.c b/app/core/gimp-batch.c
index 2656fa772f..edc0b4cdf8 100644
--- a/app/core/gimp-batch.c
+++ b/app/core/gimp-batch.c
@@ -54,10 +54,11 @@ gimp_batch_run (Gimp         *gimp,
                 const gchar  *batch_interpreter,
                 const gchar **batch_commands)
 {
-  GSList *batch_procedures;
-  GSList *iter;
-  gulong  exit_id;
-  gint    retval = EXIT_SUCCESS;
+  GimpProcedure *eval_proc;
+  GSList        *batch_procedures;
+  GSList        *iter;
+  gulong         exit_id;
+  gint           retval = EXIT_SUCCESS;
 
   if (! batch_commands || ! batch_commands[0])
     return retval;
@@ -155,55 +156,33 @@ gimp_batch_run (Gimp         *gimp,
                                     G_CALLBACK (gimp_batch_exit_after_callback),
                                     NULL);
 
-  /*  script-fu text console, hardcoded for backward compatibility  */
-
-  if (strcmp (batch_interpreter, "plug-in-script-fu-eval") == 0 &&
-      strcmp (batch_commands[0], "-") == 0)
-    {
-      const gchar   *proc_name = "plug-in-script-fu-text-console";
-      GimpProcedure *procedure = gimp_pdb_lookup_procedure (gimp->pdb,
-                                                            proc_name);
-
-      retval = 69; /* EX_UNAVAILABLE - service unavailable (sysexits.h) */
-      if (procedure)
-        retval = gimp_batch_run_cmd (gimp, proc_name, procedure,
-                                     GIMP_RUN_NONINTERACTIVE, NULL);
-      else
-        g_message (_("The batch interpreter '%s' is not available. "
-                     "Batch mode disabled."), proc_name);
-    }
-  else
+  eval_proc = gimp_pdb_lookup_procedure (gimp->pdb, batch_interpreter);
+  if (eval_proc)
     {
-      GimpProcedure *eval_proc = gimp_pdb_lookup_procedure (gimp->pdb,
-                                                            batch_interpreter);
+      gint i;
 
-      retval = 69; /* EX_UNAVAILABLE - service unavailable (sysexits.h) */
-      if (eval_proc)
+      retval = EXIT_SUCCESS;
+      for (i = 0; batch_commands[i]; i++)
         {
-          gint i;
+          retval = gimp_batch_run_cmd (gimp, batch_interpreter, eval_proc,
+                                       GIMP_RUN_NONINTERACTIVE, batch_commands[i]);
 
-          retval = EXIT_SUCCESS;
-          for (i = 0; batch_commands[i]; i++)
+          /* In case of several commands, stop and return last
+           * failed command.
+           */
+          if (retval != EXIT_SUCCESS)
             {
-              retval = gimp_batch_run_cmd (gimp, batch_interpreter, eval_proc,
-                                            GIMP_RUN_NONINTERACTIVE, batch_commands[i]);
-
-              /* In case of several commands, stop and return last
-               * failed command.
-               */
-              if (retval != EXIT_SUCCESS)
-                {
-                  g_printerr ("Stopping at failing batch command [%d]: %s\n",
-                              i, batch_commands[i]);
-                  break;
-                }
+              g_printerr ("Stopping at failing batch command [%d]: %s\n",
+                          i, batch_commands[i]);
+              break;
             }
         }
-      else
-        {
-          g_message (_("The batch interpreter '%s' is not available. "
-                       "Batch mode disabled."), batch_interpreter);
-        }
+    }
+  else
+    {
+      retval = 69; /* EX_UNAVAILABLE - service unavailable (sysexits.h) */
+      g_message (_("The batch interpreter '%s' is not available. "
+                   "Batch mode disabled."), batch_interpreter);
     }
 
   g_signal_handler_disconnect (gimp, exit_id);
diff --git a/plug-ins/script-fu/script-fu.c b/plug-ins/script-fu/script-fu.c
index 87b87b5fb7..2405e5b7d8 100644
--- a/plug-ins/script-fu/script-fu.c
+++ b/plug-ins/script-fu/script-fu.c
@@ -339,7 +339,11 @@ script_fu_batch_run (GimpProcedure        *procedure,
        *  A non-interactive "console" (for batch mode)
        */
 
-      return_vals = script_fu_eval_run (procedure, run_mode, code, args);
+      if (g_strcmp0 (code, "-") == 0)
+        /* Redirecting to script-fu text console, for backward compatibility  */
+        return_vals = script_fu_text_console_run (procedure, args);
+      else
+        return_vals = script_fu_eval_run (procedure, run_mode, code, args);
     }
 
   if (! return_vals)


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