2001-07-18 08:24:07 +08:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
2001-08-17 22:27:31 +08:00
|
|
|
#include <glib-object.h>
|
2001-07-18 08:24:07 +08:00
|
|
|
|
|
|
|
#include "core/core-types.h"
|
|
|
|
|
2002-12-05 23:49:59 +08:00
|
|
|
#include "core/gimp.h"
|
|
|
|
|
2001-07-18 08:24:07 +08:00
|
|
|
#include "batch.h"
|
|
|
|
|
|
|
|
#include "pdb/procedural_db.h"
|
|
|
|
|
|
|
|
|
2003-11-30 22:44:13 +08:00
|
|
|
static gboolean batch_exit_after_callback (Gimp *gimp,
|
|
|
|
gboolean kill_it);
|
|
|
|
static void batch_run_cmd (Gimp *gimp,
|
2003-12-01 00:05:56 +08:00
|
|
|
ProcRecord *proc,
|
2003-11-30 22:44:13 +08:00
|
|
|
const gchar *cmd);
|
|
|
|
static void batch_perl_server (Gimp *gimp,
|
|
|
|
GimpRunMode run_mode,
|
|
|
|
gint flags,
|
|
|
|
gint extra);
|
2001-07-18 08:24:07 +08:00
|
|
|
|
|
|
|
|
|
|
|
void
|
2003-11-30 22:44:13 +08:00
|
|
|
batch_run (Gimp *gimp,
|
|
|
|
const gchar **batch_cmds)
|
2001-07-18 08:24:07 +08:00
|
|
|
{
|
2003-12-01 00:08:46 +08:00
|
|
|
ProcRecord *eval_proc = NULL;
|
|
|
|
gboolean perl_server_running = FALSE;
|
|
|
|
gulong exit_id;
|
|
|
|
gint i;
|
2001-07-18 08:24:07 +08:00
|
|
|
|
2003-11-30 22:44:13 +08:00
|
|
|
exit_id = g_signal_connect_after (gimp, "exit",
|
|
|
|
G_CALLBACK (batch_exit_after_callback),
|
|
|
|
NULL);
|
|
|
|
|
2003-03-22 00:50:55 +08:00
|
|
|
if (batch_cmds[0] && strcmp (batch_cmds[0], "-") == 0)
|
2001-07-18 08:24:07 +08:00
|
|
|
{
|
2003-09-03 17:30:09 +08:00
|
|
|
batch_cmds[0] = "(plug-in-script-fu-text-console RUN-INTERACTIVE)";
|
2003-03-22 00:50:55 +08:00
|
|
|
batch_cmds[1] = NULL;
|
2001-07-18 08:24:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; batch_cmds[i]; i++)
|
|
|
|
{
|
2003-09-03 17:30:09 +08:00
|
|
|
/* until --batch-interp=xxx or something similar is implemented
|
2001-07-18 08:24:07 +08:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
{
|
2003-03-22 00:50:55 +08:00
|
|
|
gint run_mode, flags, extra;
|
2001-07-18 08:24:07 +08:00
|
|
|
|
2003-03-22 00:50:55 +08:00
|
|
|
if (sscanf (batch_cmds[i],
|
|
|
|
"(extension%*[-_]perl%*[-_]server %i %i %i)",
|
|
|
|
&run_mode, &flags, &extra) == 3)
|
2001-07-18 08:24:07 +08:00
|
|
|
{
|
2003-12-01 00:08:46 +08:00
|
|
|
if (! perl_server_running)
|
2003-03-22 00:50:55 +08:00
|
|
|
{
|
|
|
|
batch_perl_server (gimp, run_mode, flags, extra);
|
2003-12-01 00:08:46 +08:00
|
|
|
perl_server_running = TRUE;
|
2003-03-22 00:50:55 +08:00
|
|
|
}
|
2001-07-18 08:24:07 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2001-07-18 09:11:36 +08:00
|
|
|
|
2003-03-22 00:50:55 +08:00
|
|
|
if (! eval_proc)
|
2003-09-03 17:30:09 +08:00
|
|
|
eval_proc = procedural_db_lookup (gimp, "plug_in_script_fu_eval");
|
2003-03-22 00:50:55 +08:00
|
|
|
|
2001-07-18 09:11:36 +08:00
|
|
|
if (! eval_proc)
|
2001-07-18 08:24:07 +08:00
|
|
|
{
|
2003-11-14 23:33:40 +08:00
|
|
|
g_message ("script-fu not available: batch mode disabled");
|
2001-07-18 08:24:07 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-12-01 00:05:56 +08:00
|
|
|
batch_run_cmd (gimp, eval_proc, batch_cmds[i]);
|
2001-07-18 08:24:07 +08:00
|
|
|
}
|
2003-11-30 22:44:13 +08:00
|
|
|
|
|
|
|
g_signal_handler_disconnect (gimp, exit_id);
|
2001-07-18 08:24:07 +08:00
|
|
|
}
|
|
|
|
|
2003-11-30 22:44:13 +08:00
|
|
|
static gboolean
|
|
|
|
batch_exit_after_callback (Gimp *gimp,
|
|
|
|
gboolean kill_it)
|
|
|
|
{
|
|
|
|
if (gimp->be_verbose)
|
|
|
|
g_print ("EXIT: batch_exit_after_callback\n");
|
|
|
|
|
|
|
|
exit (EXIT_SUCCESS);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2001-07-18 08:24:07 +08:00
|
|
|
|
|
|
|
static void
|
2003-03-22 00:50:55 +08:00
|
|
|
batch_run_cmd (Gimp *gimp,
|
2003-12-01 00:05:56 +08:00
|
|
|
ProcRecord *proc,
|
2003-03-22 00:50:55 +08:00
|
|
|
const gchar *cmd)
|
2001-07-18 08:24:07 +08:00
|
|
|
{
|
|
|
|
Argument *args;
|
|
|
|
Argument *vals;
|
|
|
|
gint i;
|
|
|
|
|
2003-12-01 00:05:56 +08:00
|
|
|
args = g_new0 (Argument, proc->num_args);
|
|
|
|
for (i = 0; i < proc->num_args; i++)
|
|
|
|
args[i].arg_type = proc->args[i].arg_type;
|
2001-07-18 08:24:07 +08:00
|
|
|
|
2003-03-22 00:50:55 +08:00
|
|
|
args[0].value.pdb_int = GIMP_RUN_NONINTERACTIVE;
|
|
|
|
args[1].value.pdb_pointer = (gpointer) cmd;
|
2001-07-18 08:24:07 +08:00
|
|
|
|
2004-04-15 07:37:34 +08:00
|
|
|
vals = procedural_db_execute (gimp, gimp_get_user_context (gimp),
|
|
|
|
"plug_in_script_fu_eval", args);
|
2001-07-18 08:24:07 +08:00
|
|
|
|
|
|
|
switch (vals[0].value.pdb_int)
|
|
|
|
{
|
|
|
|
case GIMP_PDB_EXECUTION_ERROR:
|
|
|
|
g_print ("batch command: experienced an execution error.\n");
|
|
|
|
break;
|
|
|
|
case GIMP_PDB_CALLING_ERROR:
|
|
|
|
g_print ("batch command: experienced a calling error.\n");
|
|
|
|
break;
|
|
|
|
case GIMP_PDB_SUCCESS:
|
|
|
|
g_print ("batch command: executed successfully.\n");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2003-09-03 17:30:09 +08:00
|
|
|
|
2003-12-01 00:05:56 +08:00
|
|
|
procedural_db_destroy_args (vals, proc->num_values);
|
2003-03-22 00:50:55 +08:00
|
|
|
g_free (args);
|
2001-07-18 08:24:07 +08:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-03-22 00:50:55 +08:00
|
|
|
batch_perl_server (Gimp *gimp,
|
|
|
|
GimpRunMode run_mode,
|
|
|
|
gint flags,
|
|
|
|
gint extra)
|
2001-07-18 08:24:07 +08:00
|
|
|
{
|
|
|
|
ProcRecord *pserver_proc;
|
|
|
|
Argument *args;
|
|
|
|
Argument *vals;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
pserver_proc = procedural_db_lookup (gimp, "extension_perl_server");
|
|
|
|
|
|
|
|
if (!pserver_proc)
|
|
|
|
{
|
2003-03-22 00:50:55 +08:00
|
|
|
g_message ("extension_perl_server not available: "
|
|
|
|
"unable to start the perl server");
|
2001-07-18 08:24:07 +08:00
|
|
|
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;
|
|
|
|
|
2004-04-15 07:37:34 +08:00
|
|
|
vals = procedural_db_execute (gimp, gimp_get_user_context (gimp),
|
|
|
|
"extension_perl_server", args);
|
2001-07-18 08:24:07 +08:00
|
|
|
|
|
|
|
switch (vals[0].value.pdb_int)
|
|
|
|
{
|
|
|
|
case GIMP_PDB_EXECUTION_ERROR:
|
2003-03-22 00:50:55 +08:00
|
|
|
g_printerr ("perl server: experienced an execution error.\n");
|
2001-07-18 08:24:07 +08:00
|
|
|
break;
|
|
|
|
case GIMP_PDB_CALLING_ERROR:
|
2003-03-22 00:50:55 +08:00
|
|
|
g_printerr ("perl server: experienced a calling error.\n");
|
2001-07-18 08:24:07 +08:00
|
|
|
break;
|
|
|
|
case GIMP_PDB_SUCCESS:
|
2003-03-22 00:50:55 +08:00
|
|
|
g_printerr ("perl server: executed successfully.\n");
|
2001-07-18 08:24:07 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2003-11-14 23:33:40 +08:00
|
|
|
|
2001-07-18 08:24:07 +08:00
|
|
|
procedural_db_destroy_args (vals, pserver_proc->num_values);
|
|
|
|
g_free(args);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|