gimp/app/batch.c

194 lines
5.0 KiB
C
Raw Normal View History

/* 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
added app/display/ and app/plug-in/. Empty for now except for the types 2001-08-17 Michael Natterer <mitch@gimp.org> * configure.in: added app/display/ and app/plug-in/. Empty for now except for the types files. * app/Makefile.am * app/appenums.h * app/apptypes.h: removed. * app/display/Makefile.am * app/display/display-types.h * app/plug-in/Makefile.am * app/plug-in/plug-in-types.h * app/gui/Makefile.am * app/gui/gui-types.h * app/pdb/Makefile.am * app/pdb/pdb-types.h: new files for typedefs. * app/appenv.h: added MessageHandlerType and StackTraceMode here. * app/undo_types.h: moved undo struct typedefs here. * app/tools/tools-types.h * app/core/core-types.h: added some enums and Tattoo here (renamed to GimpTattoo). * app/gdisplay.h: temp_hack: #include "display/display-types.h" * app/gimphelp.c: s/gtk_idle_add/g_idle_add/ * app/gimprc.c: don't use "gimprc" in token handlers but the passed "val1p" and "val2p". * app/image_map.[ch]: cleanup in preparation of making a GObject out of it. * app/base/pixel-region.[ch]: no need to pass the PixelRegionIterator around as void pointer. * app/core/gimp.[ch] * app/core/gimpcontext.[ch] * app/core/gimptoolinfo.[ch] * app/tools/tool_manager.c * app/widgets/gimpdnd.c: added the standard_tool_info to the Gimp object. * app/batch.c * app/file-open.c * app/file-save.c * app/file-utils.c * app/interface.c * app/main.c * app/path.[ch] * app/pathP.h * app/plug_in.h * app/core/gimpdrawable.[ch] * app/core/gimpimage-mask.c * app/core/gimpimage.[ch] * app/core/gimplayer.c * app/gui/color-area.c * app/gui/color-notebook.c * app/gui/colormap-dialog.c * app/gui/dialogs-commands.c * app/gui/dialogs-constructors.c * app/gui/error-console-dialog.c * app/gui/gradient-editor.c * app/gui/gradient-select.c * app/gui/indicator-area.c * app/gui/info-dialog.c * app/gui/palette-editor.c * app/gui/palette-select.c * app/gui/pattern-select.c * app/gui/session.c * app/gui/splash.c * app/gui/view-commands.c * app/tools/gimpinktool-blob.c * app/widgets/gimpcolorpanel.c * app/widgets/gimpdockbook.c * app/widgets/gimppreview.c * app/xcf/xcf-load.c * app/xcf/xcf-save.c * app/xcf/xcf.c: changed accordingly: s/Tattoo/GimpTattoo/, include the new types files, include <glib-object.h> instead of >gtk/gtk.h>. Bad hacks to get rid of SELECTION_OFF and friends in core/ (will be replaced ba a signal soon). * tools/pdbgen/Makefile.am: changed list of headers scanned for enums accordingly. * app/pdb/procedural_db.c * tools/pdbgen/app.pl * tools/pdbgen/pdb/channel.pdb * tools/pdbgen/pdb/display.pdb * tools/pdbgen/pdb/gradient_select.pdb * tools/pdbgen/pdb/image.pdb * tools/pdbgen/pdb/layer.pdb * tools/pdbgen/pdb/pattern_select.pdb: same fixes as above, added hacks to ensure that all foo-types.h files are included before all other gimp internal includes, include "pdb-types.h" unconditionally. * tools/pdbgen/enums.pl * app/pdb/*_cmds.c: regenerated.
2001-08-17 22:27:31 +08:00
#include <glib-object.h>
#include "core/core-types.h"
#include "core/gimp.h"
#include "batch.h"
#include "pdb/procedural_db.h"
static void batch_run_cmd (Gimp *gimp,
const gchar *cmd);
static void batch_perl_server (Gimp *gimp,
GimpRunMode run_mode,
gint flags,
gint extra);
static ProcRecord *eval_proc = NULL;
void
batch_init (Gimp *gimp,
const gchar **batch_cmds)
{
gboolean perl_server_already_running = FALSE;
gint i;
if (batch_cmds[0] && strcmp (batch_cmds[0], "-") == 0)
{
batch_cmds[0] = "(plug-in-script-fu-text-console RUN-INTERACTIVE)";
batch_cmds[1] = NULL;
}
for (i = 0; batch_cmds[i]; i++)
{
/* 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_already_running)
{
batch_perl_server (gimp, run_mode, flags, extra);
perl_server_already_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\n");
return;
}
batch_run_cmd (gimp, batch_cmds[i]);
}
}
static void
batch_run_cmd (Gimp *gimp,
const gchar *cmd)
{
Argument *args;
Argument *vals;
gint i;
added -DG_DISABLE_DEPRECATED and -DGDK_DISABLE_COMPAT_H. 2001-08-29 Michael Natterer <mitch@gimp.org> * configure.in: added -DG_DISABLE_DEPRECATED and -DGDK_DISABLE_COMPAT_H. * app/batch.c * app/file-utils.c * app/gdisplay.c * app/gdisplay_ops.c * app/gimprc.[ch] * app/module_db.c * app/nav_window.c * app/undo_history.c * app/core/gimpgradient.c * app/core/gimpimagefile.c * app/core/gimppalette.c * app/gui/color-notebook.c * app/gui/convert-dialog.c * app/gui/error-console-dialog.c * app/gui/file-commands.c * app/gui/file-open-dialog.c * app/gui/file-save-dialog.c * app/gui/gradient-editor.c * app/gui/info-window.c * app/gui/menus.c * app/gui/palette-import-dialog.c * app/tools/gimpbycolorselecttool.c * app/widgets/gimpcontainerview-utils.c * app/widgets/gimpdatafactoryview.c * libgimp/gimpmenu.c * plug-ins/common/bz2.c * plug-ins/common/compose.c * plug-ins/common/csource.c * plug-ins/common/decompose.c * plug-ins/common/gz.c * plug-ins/common/uniteditor.c * plug-ins/common/wmf.c * plug-ins/common/xbm.c * plug-ins/rcm/rcm_dialog.c * plug-ins/script-fu/interp_slib.c * plug-ins/script-fu/script-fu-console.c * plug-ins/script-fu/script-fu-scripts.c * tools/pdbgen/pdb/fileops.pdb * tools/pdbgen/pdb/gimprc.pdb * app/pdb/fileops_cmds.c * app/pdb/gimprc_cmds.c: removed deprecated stuff like g_basename(), g_dirname(), g_strup() and friends. Added some "const gchar *" declarations while I was on it. Added some G_N_ELEMENTS() macros instead of declaring a useless variable for the number of items. * app/widgets/gtkhwrapbox.[ch] * app/widgets/gtkvwrapbox.[ch] * app/widgets/gtkwrapbox.[ch]: replaced with the latest versions from GLE, ported by the master himself. * app/gui/toolbox.c: changed accordingly. * app/plug_in.c * libgimp/gimp.c * libgimpbase/gimpwire.[ch]: use evil hacks to get binary mode from the new GIOChannel implementation (upstream bugreport already posted).
2001-08-30 01:48:28 +08:00
if (g_ascii_strcasecmp (cmd, "(gimp-quit 0)") == 0)
{
gimp_exit (gimp, TRUE);
return;
}
args = g_new0 (Argument, eval_proc->num_args);
for (i = 0; i < eval_proc->num_args; i++)
args[i].arg_type = eval_proc->args[i].arg_type;
args[0].value.pdb_int = GIMP_RUN_NONINTERACTIVE;
args[1].value.pdb_pointer = (gpointer) cmd;
vals = procedural_db_execute (gimp, "plug_in_script_fu_eval", args);
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;
}
procedural_db_destroy_args (vals, eval_proc->num_values);
g_free (args);
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, "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;
}