
2001-07-10 Michael Natterer <mitch@gimp.org> * app/app_procs.[ch]: removed the gimp_busy boolean, check whether user_installation is needed here, not in user_install.c, parse gtkrc an friends only if(!no_interface), create the Gimp object before parsing gimp's rc files an pas it to the parse functions, many other cleanups. * app/appenums.h: added MessageHandlerType and StackTraceMode. * app/appenv.h: removed MessageHandlerType, declare all global variables from main.c (no more hidden global stuff please). * app/errors.[ch]: added the fatal message func here (from main.c), removed the StackTraceMode enum. * app/gimprc.[ch]: renamed functions to gimprc_*(), pass a Gimp pointer to some functions. * app/gimpunit.c * app/unitrc.h: ok, this is ugly: renamed all functions to _gimp_unit_*() and made them public. The unit list is part of the Gimp object now, so pass a Gimp* to all functions. * app/libgimp_glue.[ch]: added EEKy wrappers for all gimp_unit_*() functions which are used by widgets. * app/main.c: cleaned up the global variables, removed the fatal message handler, call app_init() directly, not via the user_install stuff, misc. cleanups. * app/user_install.[ch]: removed the check if user_installation is needed (done by app_procs.c now). * app/core/gimp.[ch]: added the user_unit list and the "busy" boolean. Moved gimp_[set|unset]_busy() here. Added gimp_initialize() which is called after unitrc and gimprc are parsed. * app/batch.c * app/colormaps.c * app/devices.c * app/disp_callbacks.c * app/gdisplay_ops.c * app/gimphelp.c * app/module_db.c * app/nav_window.c * app/plug_in.c * app/core/gimpcontext.c * app/core/gimpdatafiles.c * app/core/gimpimage-convert.c * app/core/gimpimage-duplicate.c * app/core/gimpimage.c * app/core/gimpparasite.c * app/core/gimpparasitelist.h * app/gui/file-open-dialog.c * app/gui/gui.[ch] * app/gui/info-dialog.c * app/gui/info-window.c * app/gui/preferences-dialog.c * app/gui/session.c * app/gui/tips-dialog.c * app/gui/toolbox.c * app/tools/gimpblendtool.c * app/tools/gimpbucketfilltool.c * app/tools/gimpcolorpickertool.c * app/tools/gimpfuzzyselecttool.c * app/tools/gimptransformtool.c * app/tools/tool_manager.c * app/widgets/gimpcolorpanel.c * app/widgets/gimpcursor.c * app/xcf/xcf-load.c * app/xcf/xcf-save.c * app/xcf/xcf.c * tools/pdbgen/Makefile.am * tools/pdbgen/app.pl * tools/pdbgen/enums.pl * tools/pdbgen/pdb/image.pdb * tools/pdbgen/pdb/message.pdb * tools/pdbgen/pdb/unit.pdb * app/pdb/image_cmds.c * app/pdb/message_cmds.c * app/pdb/unit_cmds.c: changed accordingly, minor cleanups.
266 lines
6.1 KiB
C
266 lines
6.1 KiB
C
/* 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 <ctype.h>
|
|
#include <errno.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#ifdef HAVE_UNISTD_H
|
|
#include <unistd.h>
|
|
#endif
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include "core/core-types.h"
|
|
|
|
#include "appenv.h"
|
|
#include "app_procs.h"
|
|
#include "batch.h"
|
|
|
|
#include "pdb/procedural_db.h"
|
|
|
|
|
|
static void batch_run_cmd (Gimp *gimp,
|
|
gchar *cmd);
|
|
static void batch_read (gpointer data,
|
|
gint source,
|
|
GdkInputCondition condition);
|
|
static void batch_pserver (Gimp *gimp,
|
|
gint run_mode,
|
|
gint flags,
|
|
gint extra);
|
|
|
|
|
|
static ProcRecord *eval_proc;
|
|
|
|
|
|
void
|
|
batch_init (Gimp *gimp)
|
|
{
|
|
gboolean read_from_stdin;
|
|
gboolean perl_server_already_running = FALSE;
|
|
gint i;
|
|
|
|
eval_proc = procedural_db_lookup (gimp, "extension_script_fu_eval");
|
|
|
|
read_from_stdin = FALSE;
|
|
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_pserver (gimp, run_mode, flags, extra);
|
|
perl_server_already_running = 1;
|
|
}
|
|
continue;
|
|
}
|
|
}
|
|
|
|
if (!eval_proc)
|
|
{
|
|
g_message ("script-fu not available: batch mode disabled\n");
|
|
return;
|
|
}
|
|
|
|
if (strcmp (batch_cmds[i], "-") == 0)
|
|
{
|
|
if (!read_from_stdin)
|
|
{
|
|
#ifndef G_OS_WIN32 /* for now */
|
|
g_print ("reading batch commands from stdin\n");
|
|
gdk_input_add (STDIN_FILENO, GDK_INPUT_READ, batch_read, gimp);
|
|
read_from_stdin = TRUE;
|
|
#else
|
|
g_error ("Batch mode from standard input not implemented on Win32");
|
|
#endif
|
|
}
|
|
}
|
|
else
|
|
{
|
|
batch_run_cmd (gimp, batch_cmds[i]);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
static void
|
|
batch_run_cmd (Gimp *gimp,
|
|
gchar *cmd)
|
|
{
|
|
Argument *args;
|
|
Argument *vals;
|
|
gint i;
|
|
|
|
if (g_strcasecmp (cmd, "(gimp-quit 0)") == 0)
|
|
{
|
|
app_exit (FALSE);
|
|
exit (0);
|
|
}
|
|
|
|
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 = 1;
|
|
args[1].value.pdb_pointer = cmd;
|
|
|
|
vals = procedural_db_execute (gimp, "extension_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;
|
|
}
|
|
|
|
#ifndef G_OS_WIN32
|
|
|
|
static void
|
|
batch_read (gpointer data,
|
|
gint source,
|
|
GdkInputCondition condition)
|
|
{
|
|
static GString *string;
|
|
gchar buf[32];
|
|
gchar *t;
|
|
gint nread;
|
|
gboolean done;
|
|
|
|
if (condition & GDK_INPUT_READ)
|
|
{
|
|
do {
|
|
nread = read (source, &buf, sizeof (char) * 31);
|
|
} while ((nread == -1) && ((errno == EAGAIN) || (errno == EINTR)));
|
|
|
|
if ((nread == 0) && (!string || (string->len == 0)))
|
|
app_exit (FALSE);
|
|
|
|
buf[nread] = '\0';
|
|
|
|
if (!string)
|
|
string = g_string_new ("");
|
|
|
|
t = buf;
|
|
if (string->len == 0)
|
|
{
|
|
while (*t)
|
|
{
|
|
if (isspace (*t))
|
|
t++;
|
|
else
|
|
break;
|
|
}
|
|
}
|
|
|
|
g_string_append (string, t);
|
|
|
|
done = FALSE;
|
|
|
|
while (*t)
|
|
{
|
|
if ((*t == '\n') || (*t == '\r'))
|
|
done = TRUE;
|
|
t++;
|
|
}
|
|
|
|
if (done)
|
|
{
|
|
batch_run_cmd ((Gimp *) data, string->str);
|
|
g_string_truncate (string, 0);
|
|
}
|
|
}
|
|
}
|
|
|
|
#endif /* !G_OS_WIN32 */
|
|
|
|
static void
|
|
batch_pserver (Gimp *gimp,
|
|
gint 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\n");
|
|
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_print ("perl server: experienced an execution error.\n");
|
|
break;
|
|
case GIMP_PDB_CALLING_ERROR:
|
|
g_print ("perl server: experienced a calling error.\n");
|
|
break;
|
|
case GIMP_PDB_SUCCESS:
|
|
g_print ("perl server: executed successfully.\n");
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
procedural_db_destroy_args (vals, pserver_proc->num_values);
|
|
g_free(args);
|
|
|
|
return;
|
|
}
|