mirror of https://github.com/GNOME/gimp.git
app/app_procs.[ch] app/batch.[ch] added new command-line option
2004-10-06 Sven Neumann <sven@gimp.org> * app/app_procs.[ch] * app/batch.[ch] * app/main.c: added new command-line option "--batch-interpreter" that allows to specify the procedure to use to process batch commands. Removed the perl-server hack but kept Script-Fu as the default for backward compatibility. * docs/gimp.1.in: documented the new option.
This commit is contained in:
parent
a1ff75dedb
commit
1956f31140
11
ChangeLog
11
ChangeLog
|
@ -1,3 +1,14 @@
|
|||
2004-10-06 Sven Neumann <sven@gimp.org>
|
||||
|
||||
* app/app_procs.[ch]
|
||||
* app/batch.[ch]
|
||||
* app/main.c: added new command-line option "--batch-interpreter"
|
||||
that allows to specify the procedure to use to process batch
|
||||
commands. Removed the perl-server hack but kept Script-Fu as the
|
||||
default for backward compatibility.
|
||||
|
||||
* docs/gimp.1.in: documented the new option.
|
||||
|
||||
2004-10-06 Michael Natterer <mitch@gimp.org>
|
||||
|
||||
* app/actions/file-commands.c (file_revert_confirm_callback):
|
||||
|
|
|
@ -156,7 +156,8 @@ app_run (const gchar *full_prog_name,
|
|||
const gchar *alternate_system_gimprc,
|
||||
const gchar *alternate_gimprc,
|
||||
const gchar *session_name,
|
||||
const gchar **batch_cmds,
|
||||
const gchar *batch_interpreter,
|
||||
const gchar **batch_commands,
|
||||
gboolean no_interface,
|
||||
gboolean no_data,
|
||||
gboolean no_fonts,
|
||||
|
@ -362,7 +363,7 @@ app_run (const gchar *full_prog_name,
|
|||
gui_post_init (gimp);
|
||||
#endif
|
||||
|
||||
batch_run (gimp, batch_cmds);
|
||||
batch_run (gimp, batch_interpreter, batch_commands);
|
||||
|
||||
loop = g_main_loop_new (NULL, FALSE);
|
||||
|
||||
|
|
|
@ -38,7 +38,8 @@ void app_run (const gchar *full_prog_name,
|
|||
const gchar *alternate_system_gimprc,
|
||||
const gchar *alternate_gimprc,
|
||||
const gchar *session_name,
|
||||
const gchar **batch_cmds,
|
||||
const gchar *batch_interpreter,
|
||||
const gchar **batch_commands,
|
||||
gboolean no_interface,
|
||||
gboolean no_data,
|
||||
gboolean no_fonts,
|
||||
|
|
156
app/batch.c
156
app/batch.c
|
@ -18,13 +18,8 @@
|
|||
|
||||
#include "config.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <glib-object.h>
|
||||
|
||||
|
@ -36,80 +31,73 @@
|
|||
|
||||
#include "pdb/procedural_db.h"
|
||||
|
||||
#include "gimp-intl.h"
|
||||
|
||||
|
||||
#define BATCH_DEFAULT_EVAL_PROC "plug_in_script_fu_eval"
|
||||
|
||||
|
||||
static gboolean batch_exit_after_callback (Gimp *gimp,
|
||||
gboolean kill_it);
|
||||
static void batch_run_cmd (Gimp *gimp,
|
||||
const gchar *proc_name,
|
||||
ProcRecord *proc,
|
||||
const gchar *cmd);
|
||||
static void batch_perl_server (Gimp *gimp,
|
||||
GimpRunMode run_mode,
|
||||
gint flags,
|
||||
gint extra);
|
||||
|
||||
|
||||
void
|
||||
batch_run (Gimp *gimp,
|
||||
const gchar **batch_cmds)
|
||||
const gchar *batch_interpreter,
|
||||
const gchar **batch_commands)
|
||||
{
|
||||
ProcRecord *eval_proc = NULL;
|
||||
gboolean perl_server_running = FALSE;
|
||||
ProcRecord *eval_proc;
|
||||
gulong exit_id;
|
||||
gint i;
|
||||
|
||||
if (! batch_commands ||
|
||||
! batch_commands[0])
|
||||
return;
|
||||
|
||||
exit_id = g_signal_connect_after (gimp, "exit",
|
||||
G_CALLBACK (batch_exit_after_callback),
|
||||
NULL);
|
||||
|
||||
if (batch_cmds[0] && strcmp (batch_cmds[0], "-") == 0)
|
||||
if (! batch_interpreter)
|
||||
{
|
||||
batch_cmds[0] = "(plug-in-script-fu-text-console RUN-INTERACTIVE)";
|
||||
batch_cmds[1] = NULL;
|
||||
batch_interpreter = BATCH_DEFAULT_EVAL_PROC;
|
||||
|
||||
g_printerr ("No batch interpreter specified, using the default '%s'.\n",
|
||||
batch_interpreter);
|
||||
}
|
||||
|
||||
for (i = 0; batch_cmds[i]; i++)
|
||||
if (strcmp (batch_interpreter, BATCH_DEFAULT_EVAL_PROC) == 0 &&
|
||||
strcmp (batch_commands[0], "-") == 0)
|
||||
{
|
||||
/* until --batch-interp=xxx or something similar is implemented
|
||||
* and gimp-1.0 is not extinct use a shortcut to speed up starting the
|
||||
* perl-server tremendously. This is also fully compatible with 1.0.
|
||||
*/
|
||||
{
|
||||
gint run_mode, flags, extra;
|
||||
|
||||
if (sscanf (batch_cmds[i],
|
||||
"(extension%*[-_]perl%*[-_]server %i %i %i)",
|
||||
&run_mode, &flags, &extra) == 3)
|
||||
{
|
||||
if (! perl_server_running)
|
||||
{
|
||||
batch_perl_server (gimp, run_mode, flags, extra);
|
||||
perl_server_running = TRUE;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (! eval_proc)
|
||||
eval_proc = procedural_db_lookup (gimp, "plug_in_script_fu_eval");
|
||||
|
||||
if (! eval_proc)
|
||||
{
|
||||
g_message ("script-fu not available: batch mode disabled");
|
||||
return;
|
||||
}
|
||||
|
||||
batch_run_cmd (gimp, eval_proc, batch_cmds[i]);
|
||||
batch_commands[0] = "(plug-in-script-fu-text-console RUN-INTERACTIVE)";
|
||||
batch_commands[1] = NULL;
|
||||
}
|
||||
|
||||
eval_proc = procedural_db_lookup (gimp, batch_interpreter);
|
||||
if (! eval_proc)
|
||||
{
|
||||
g_message (_("The batch interpreter '%s' is not available, "
|
||||
"batch mode disabled."), batch_interpreter);
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; batch_commands[i]; i++)
|
||||
batch_run_cmd (gimp, batch_interpreter, eval_proc, batch_commands[i]);
|
||||
|
||||
g_signal_handler_disconnect (gimp, exit_id);
|
||||
}
|
||||
|
||||
|
||||
static gboolean
|
||||
batch_exit_after_callback (Gimp *gimp,
|
||||
gboolean kill_it)
|
||||
batch_exit_after_callback (Gimp *gimp,
|
||||
gboolean kill_it)
|
||||
{
|
||||
if (gimp->be_verbose)
|
||||
g_print ("EXIT: batch_exit_after_callback\n");
|
||||
g_print ("EXIT: %s\n", G_STRLOC);
|
||||
|
||||
exit (EXIT_SUCCESS);
|
||||
|
||||
|
@ -118,6 +106,7 @@ batch_exit_after_callback (Gimp *gimp,
|
|||
|
||||
static void
|
||||
batch_run_cmd (Gimp *gimp,
|
||||
const gchar *proc_name,
|
||||
ProcRecord *proc,
|
||||
const gchar *cmd)
|
||||
{
|
||||
|
@ -132,21 +121,22 @@ batch_run_cmd (Gimp *gimp,
|
|||
args[0].value.pdb_int = GIMP_RUN_NONINTERACTIVE;
|
||||
args[1].value.pdb_pointer = (gpointer) cmd;
|
||||
|
||||
vals = procedural_db_execute (gimp, gimp_get_user_context (gimp), NULL,
|
||||
"plug_in_script_fu_eval", args);
|
||||
vals = procedural_db_execute (gimp,
|
||||
gimp_get_user_context (gimp), NULL,
|
||||
proc_name, args);
|
||||
|
||||
switch (vals[0].value.pdb_int)
|
||||
{
|
||||
case GIMP_PDB_EXECUTION_ERROR:
|
||||
g_print ("batch command: experienced an execution error.\n");
|
||||
g_printerr ("batch command: experienced an execution error.\n");
|
||||
break;
|
||||
|
||||
case GIMP_PDB_CALLING_ERROR:
|
||||
g_print ("batch command: experienced a calling error.\n");
|
||||
g_printerr ("batch command: experienced a calling error.\n");
|
||||
break;
|
||||
|
||||
case GIMP_PDB_SUCCESS:
|
||||
g_print ("batch command: executed successfully.\n");
|
||||
break;
|
||||
default:
|
||||
g_printerr ("batch command: executed successfully.\n");
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -155,55 +145,3 @@ batch_run_cmd (Gimp *gimp,
|
|||
|
||||
return;
|
||||
}
|
||||
|
||||
static void
|
||||
batch_perl_server (Gimp *gimp,
|
||||
GimpRunMode run_mode,
|
||||
gint flags,
|
||||
gint extra)
|
||||
{
|
||||
ProcRecord *pserver_proc;
|
||||
Argument *args;
|
||||
Argument *vals;
|
||||
gint i;
|
||||
|
||||
pserver_proc = procedural_db_lookup (gimp, "extension_perl_server");
|
||||
|
||||
if (!pserver_proc)
|
||||
{
|
||||
g_message ("extension_perl_server not available: "
|
||||
"unable to start the perl server");
|
||||
return;
|
||||
}
|
||||
|
||||
args = g_new0 (Argument, pserver_proc->num_args);
|
||||
for (i = 0; i < pserver_proc->num_args; i++)
|
||||
args[i].arg_type = pserver_proc->args[i].arg_type;
|
||||
|
||||
args[0].value.pdb_int = run_mode;
|
||||
args[1].value.pdb_int = flags;
|
||||
args[2].value.pdb_int = extra;
|
||||
|
||||
vals = procedural_db_execute (gimp, gimp_get_user_context (gimp), NULL,
|
||||
"extension_perl_server", args);
|
||||
|
||||
switch (vals[0].value.pdb_int)
|
||||
{
|
||||
case GIMP_PDB_EXECUTION_ERROR:
|
||||
g_printerr ("perl server: experienced an execution error.\n");
|
||||
break;
|
||||
case GIMP_PDB_CALLING_ERROR:
|
||||
g_printerr ("perl server: experienced a calling error.\n");
|
||||
break;
|
||||
case GIMP_PDB_SUCCESS:
|
||||
g_printerr ("perl server: executed successfully.\n");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
procedural_db_destroy_args (vals, pserver_proc->num_values);
|
||||
g_free(args);
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -25,7 +25,8 @@
|
|||
|
||||
|
||||
void batch_run (Gimp *gimp,
|
||||
const gchar **batch_cmds);
|
||||
const gchar *batch_interpreter,
|
||||
const gchar **batch_commands);
|
||||
|
||||
|
||||
#endif /* __BATCH_H__ */
|
||||
|
|
42
app/main.c
42
app/main.c
|
@ -95,11 +95,12 @@ main (int argc,
|
|||
char **argv)
|
||||
{
|
||||
const gchar *abort_message = NULL;
|
||||
gchar *full_prog_name = NULL;
|
||||
gchar *alternate_system_gimprc = NULL;
|
||||
gchar *alternate_gimprc = NULL;
|
||||
gchar *session_name = NULL;
|
||||
gchar **batch_cmds = NULL;
|
||||
const gchar *full_prog_name = NULL;
|
||||
const gchar *alternate_system_gimprc = NULL;
|
||||
const gchar *alternate_gimprc = NULL;
|
||||
const gchar *session_name = NULL;
|
||||
const gchar *batch_interpreter = NULL;
|
||||
const gchar **batch_commands = NULL;
|
||||
gboolean show_help = FALSE;
|
||||
gboolean no_interface = FALSE;
|
||||
gboolean no_data = FALSE;
|
||||
|
@ -231,8 +232,8 @@ main (int argc,
|
|||
mallopt (M_MMAP_THRESHOLD, 64 * 64 - 1);
|
||||
#endif
|
||||
|
||||
batch_cmds = g_new (gchar *, argc);
|
||||
batch_cmds[0] = NULL;
|
||||
batch_commands = g_new (const gchar *, argc);
|
||||
batch_commands[0] = NULL;
|
||||
|
||||
for (i = 1; i < argc; i++)
|
||||
{
|
||||
|
@ -251,18 +252,32 @@ main (int argc,
|
|||
no_interface = TRUE;
|
||||
argv[i] = NULL;
|
||||
}
|
||||
else if (strcmp (argv[i], "--batch-interpreter") == 0)
|
||||
{
|
||||
argv[i] = NULL;
|
||||
if (argc <= ++i)
|
||||
{
|
||||
show_help = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
batch_interpreter = argv[i];
|
||||
argv[i] = NULL;
|
||||
}
|
||||
}
|
||||
else if ((strcmp (argv[i], "--batch") == 0) ||
|
||||
(strcmp (argv[i], "-b") == 0))
|
||||
{
|
||||
argv[i] = NULL;
|
||||
for (j = 0, i++ ; i < argc; j++, i++)
|
||||
{
|
||||
batch_cmds[j] = argv[i];
|
||||
batch_commands[j] = argv[i];
|
||||
argv[i] = NULL;
|
||||
}
|
||||
batch_cmds[j] = NULL;
|
||||
batch_commands[j] = NULL;
|
||||
|
||||
if (batch_cmds[0] == NULL) /* We need at least one batch command */
|
||||
/* We need at least one batch command */
|
||||
if (batch_commands[0] == NULL)
|
||||
show_help = TRUE;
|
||||
}
|
||||
else if (strcmp (argv[i], "--system-gimprc") == 0)
|
||||
|
@ -461,7 +476,8 @@ main (int argc,
|
|||
alternate_system_gimprc,
|
||||
alternate_gimprc,
|
||||
session_name,
|
||||
(const gchar **) batch_cmds,
|
||||
batch_interpreter,
|
||||
batch_commands,
|
||||
no_interface,
|
||||
no_data,
|
||||
no_fonts,
|
||||
|
@ -473,7 +489,7 @@ main (int argc,
|
|||
stack_trace_mode,
|
||||
pdb_compat_mode);
|
||||
|
||||
g_free (batch_cmds);
|
||||
g_free (batch_commands);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
@ -513,6 +529,8 @@ gimp_show_help (const gchar *progname)
|
|||
" Debugging mode for fatal signals.\n"));
|
||||
g_print (_(" --pdb-compat-mode <off | on | warn>\n"
|
||||
" Procedural Database compatibility mode.\n"));
|
||||
g_print (_(" --batch-interpreter <procedure>\n"
|
||||
" The procedure to process batch commands with.\n"));
|
||||
g_print (_(" -b, --batch <commands> Process commands in batch mode.\n"));
|
||||
g_print ("\n");
|
||||
};
|
||||
|
|
|
@ -9,7 +9,7 @@ gimp - an image manipulation and paint program.
|
|||
[\-\-session \fI<name>\fP] [\-g] [\-\-gimprc \fI<gimprc>\fP]
|
||||
[\-\-system\-gimprc \fI<gimprc>\fP] [\-\-dump\-gimprc\fP]
|
||||
[\-\-console\-messages] [\-\-debug\-handlers]
|
||||
[\-b] [\-\-batch \fI<commands>\fP]
|
||||
[\-\-batch\-interpreter \fI<procedure>\fP] [\-b] [\-\-batch \fI<commands>\fP]
|
||||
[\fIfilename\fP] ...
|
||||
|
||||
.SH DESCRIPTION
|
||||
|
@ -98,6 +98,10 @@ If a stack-trace should be generated in case of fatal signals.
|
|||
.B \-\-pdb\-compat\-mode \fI{off|on|warn}\fP
|
||||
If the PDB should provide aliases for deprecated functions.
|
||||
.TP 8
|
||||
.B \-\-batch-interpreter \fI<procedure>\fP
|
||||
Speficies the procedure to use to process batch events. The default is
|
||||
to let Script-Fu evaluate the commands.
|
||||
.TP 8
|
||||
.B \-b, \-\-batch \fI<commands>\fP
|
||||
Execute the set of \fI<commands>\fP non-interactively. The set
|
||||
of \fI<commands>\fP is typically in the form of a script that
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
# marked to allow runtime translation of messages
|
||||
|
||||
app/app_procs.c
|
||||
app/batch.c
|
||||
app/main.c
|
||||
app/sanity.c
|
||||
|
||||
|
|
Loading…
Reference in New Issue