Commit 52475f57 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer
Browse files

seems Mathieu messed up the last commit :) Added these two files back from

2001-07-18  Michael Natterer  <mitch@gimp.org>

	* app/batch.[ch]: seems Mathieu messed up the last commit :) Added
	these two files back from the Attic, removed the old STDIN code
	and added a small hack which calls "extension-script-fu-text-console"

	* app/main.c: reverted to the last version, so old and new batch
	mode are both there now.
parent d48c27fd
2001-07-18 Michael Natterer <mitch@gimp.org>
* app/batch.[ch]: seems Mathieu messed up the last commit :) Added
these two files back from the Attic, removed the old STDIN code
and added a small hack which calls "extension-script-fu-text-console"
* app/main.c: reverted to the last version, so old and new batch
mode are both there now.
2001-07-17 Mathieu Lacage <mathieu@gnome.org>
* app/batch.c: new code to call the script_fuc_text_console pdb function.
......
/* 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_pserver (Gimp *gimp,
gint run_mode,
gint flags,
gint extra);
static ProcRecord *eval_proc;
void
batch_init (Gimp *gimp)
{
gboolean perl_server_already_running = FALSE;
gint i;
eval_proc = procedural_db_lookup (gimp, "extension_script_fu_eval");
if (batch_cmds[0] && ! strcmp (batch_cmds[0], "-"))
{
batch_cmds[0] = "(extension-script-fu-text-console RUN-INTERACTIVE)";
if (batch_cmds[1])
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_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;
}
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;
}
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;
}
/* 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.
*/
#ifndef __BATCH_H__
#define __BATCH_H__
void batch_init (Gimp *gimp);
#endif /* __BATCH_H__ */
......@@ -63,7 +63,6 @@ gboolean no_data = FALSE;
gboolean no_splash = FALSE;
gboolean no_splash_image = FALSE;
gboolean be_verbose = FALSE;
gboolean use_stdin = FALSE;
gboolean use_shm = FALSE;
gboolean use_debug_handler = FALSE;
gboolean console_messages = FALSE;
......@@ -71,6 +70,7 @@ gboolean restore_session = FALSE;
StackTraceMode stack_trace_mode = STACK_TRACE_QUERY;
gchar *alternate_gimprc = NULL;
gchar *alternate_system_gimprc = NULL;
gchar **batch_cmds = NULL;
/* other global variables */
gchar *prog_name = NULL; /* our executable name */
......@@ -93,6 +93,9 @@ gboolean double_speed = FALSE;
* left are assumed to be image files the GIMP should
* display.
*
* The exception is the batch switch. When this is
* encountered, all remaining args are treated as batch
* commands.
*/
int
......@@ -130,6 +133,8 @@ main (int argc,
use_shm = TRUE;
#endif
batch_cmds = g_new (char *, argc);
batch_cmds[0] = NULL;
for (i = 1; i < argc; i++)
{
......@@ -143,7 +148,15 @@ main (int argc,
(strcmp (argv[i], "-b") == 0))
{
argv[i] = NULL;
use_stdin = TRUE;
for (j = 0, i++ ; i < argc; j++, i++)
{
batch_cmds[j] = argv[i];
argv[i] = NULL;
}
batch_cmds[j] = NULL;
if (batch_cmds[0] == NULL) /* We need at least one batch command */
show_help = TRUE;
}
else if (strcmp (argv[i], "--system-gimprc") == 0)
{
......@@ -279,7 +292,7 @@ main (int argc,
{
g_print (_("\nUsage: %s [option ... ] [file ... ]\n\n"), argv[0]);
g_print (_("Options:\n"));
g_print (_(" -b, --batch Read scheme statements from stdin.\n"));
g_print (_(" -b, --batch <commands> Run in batch mode.\n"));
g_print (_(" -c, --console-messages Display warnings to console instead of a dialog box.\n"));
g_print (_(" -d, --no-data Do not load brushes, gradients, palettes, patterns.\n"));
g_print (_(" -i, --no-interface Run without a user interface.\n"));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment