From c1d2f35b7349c6c48076b1544363d36edfa8d461 Mon Sep 17 00:00:00 2001 From: Jehan Date: Sun, 17 Apr 2022 14:23:21 +0200 Subject: [PATCH] =?UTF-8?q?app,=20plug-ins:=20redirect=20plug-in-script-fu?= =?UTF-8?q?-eval=20to=20text=20console=20in=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit … 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 | 73 ++++++++++++---------------------- plug-ins/script-fu/script-fu.c | 6 ++- 2 files changed, 31 insertions(+), 48 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) + eval_proc = gimp_pdb_lookup_procedure (gimp->pdb, batch_interpreter); + if (eval_proc) { - const gchar *proc_name = "plug-in-script-fu-text-console"; - GimpProcedure *procedure = gimp_pdb_lookup_procedure (gimp->pdb, - proc_name); + gint i; - 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); + retval = EXIT_SUCCESS; + for (i = 0; batch_commands[i]; i++) + { + 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; + } + } } else { - GimpProcedure *eval_proc = gimp_pdb_lookup_procedure (gimp->pdb, - batch_interpreter); - retval = 69; /* EX_UNAVAILABLE - service unavailable (sysexits.h) */ - if (eval_proc) - { - gint i; - - retval = EXIT_SUCCESS; - for (i = 0; batch_commands[i]; i++) - { - 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; - } - } - } - else - { - g_message (_("The batch interpreter '%s' is not available. " - "Batch mode disabled."), batch_interpreter); - } + 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)