Commit d48c27fd authored by Mathieu Lacage's avatar Mathieu Lacage Committed by Mathieu Lacage
Browse files

new code to call the script_fuc_text_console pdb function. remove batch

2001-07-17  Mathieu Lacage  <mathieu@gnome.org>

	* app/batch.c: new code to call the script_fuc_text_console pdb function.
	* app/main.c: (main): remove batch command code.

	* plug-ins/script-fu/Makefile.am: add siod-wrapper.h/c
	* plug-ins/script-fu/script-fu-console.c:
	(script_fu_cc_key_function),
	(script_fu_open_siod_console),
	(script_fu_close_siod_console):
	* plug-ins/script-fu/script-fu-scripts.h:
	* plug-ins/script-fu/script-fu-server.c:
	(script_fu_server_quit),
	(script_fu_server_get_mode),
	(execute_command):
	Replace all direct calls to the scheme interpreter with calls to the siod-wrapper.
	* plug-ins/script-fu/script-fu-console.h: remove run_eval.
	* plug-ins/script-fu/script-fu-server.h:
	* plug-ins/script-fu/script-fu-text-console.c:
	(script_fu_text_console_run),
	(read_command),
	(script_fu_text_console_interface):
	The actual new text console.
	* plug-ins/script-fu/script-fu-text-console.h: header.
	* plug-ins/script-fu/script-fu.c:
	(script_fu_quit),
	(script_fu_query),
	(script_fu_run): rename to better words.
	move most of the code to siod-wrapper.c/h
	* plug-ins/script-fu/siod-wrapper.c:
	(siod_get_output_file),
	(siod_set_output_file),
	(siod_get_verbose_level),
	(siod_set_verbose_level),
	(siod_print_welcome),
	(siod_interpret_string),
	(siod_get_error_msg),
	(siod_get_success_msg),
	(siod_init),
	(init_procedures),
	(init_constants),
	(convert_string),
	(sputs_fcn),
	(lprin1s),
	(marshall_proc_db_call),
	(script_fu_register_call),
	(script_fu_quit_call):
	All the funcitons dealing with the internals of the scheme interpreter.
	* plug-ins/script-fu/siod-wrapper.h: the header.
parent b844c985
2001-07-17 Mathieu Lacage <mathieu@gnome.org>
* app/batch.c: new code to call the script_fuc_text_console pdb function.
* app/main.c: (main): remove batch command code.
* plug-ins/script-fu/Makefile.am: add siod-wrapper.h/c
* plug-ins/script-fu/script-fu-console.c:
(script_fu_cc_key_function),
(script_fu_open_siod_console),
(script_fu_close_siod_console):
* plug-ins/script-fu/script-fu-scripts.h:
* plug-ins/script-fu/script-fu-server.c:
(script_fu_server_quit),
(script_fu_server_get_mode),
(execute_command):
Replace all direct calls to the scheme interpreter with calls to the siod-wrapper.
* plug-ins/script-fu/script-fu-console.h: remove run_eval.
* plug-ins/script-fu/script-fu-server.h:
* plug-ins/script-fu/script-fu-text-console.c:
(script_fu_text_console_run),
(read_command),
(script_fu_text_console_interface):
The actual new text console.
* plug-ins/script-fu/script-fu-text-console.h: header.
* plug-ins/script-fu/script-fu.c:
(script_fu_quit),
(script_fu_query),
(script_fu_run): rename to better words.
move most of the code to siod-wrapper.c/h
* plug-ins/script-fu/siod-wrapper.c:
(siod_get_output_file),
(siod_set_output_file),
(siod_get_verbose_level),
(siod_set_verbose_level),
(siod_print_welcome),
(siod_interpret_string),
(siod_get_error_msg),
(siod_get_success_msg),
(siod_init),
(init_procedures),
(init_constants),
(convert_string),
(sputs_fcn),
(lprin1s),
(marshall_proc_db_call),
(script_fu_register_call),
(script_fu_quit_call):
All the funcitons dealing with the internals of the scheme interpreter.
* plug-ins/script-fu/siod-wrapper.h: the header.
2001-07-17 Michael Natterer <mitch@gimp.org>
* app/path.[ch]: removed path_to_beziersel() so this file can be
......
/* 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;
}
......@@ -63,6 +63,7 @@ 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;
......@@ -70,7 +71,6 @@ 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,9 +93,6 @@ 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
......@@ -133,8 +130,6 @@ main (int argc,
use_shm = TRUE;
#endif
batch_cmds = g_new (char *, argc);
batch_cmds[0] = NULL;
for (i = 1; i < argc; i++)
{
......@@ -148,15 +143,7 @@ main (int argc,
(strcmp (argv[i], "-b") == 0))
{
argv[i] = NULL;
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;
use_stdin = TRUE;
}
else if (strcmp (argv[i], "--system-gimprc") == 0)
{
......@@ -292,7 +279,7 @@ main (int argc,
{
g_print (_("\nUsage: %s [option ... ] [file ... ]\n\n"), argv[0]);
g_print (_("Options:\n"));
g_print (_(" -b, --batch <commands> Run in batch mode.\n"));
g_print (_(" -b, --batch Read scheme statements from stdin.\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"));
......
......@@ -14,6 +14,8 @@ script_fu_SOURCES = @STRIP_BEGIN@ \
script-fu.c \
script-fu-console.c \
script-fu-console.h \
script-fu-text-console.h \
script-fu-text-console.c \
script-fu-constants.c \
script-fu-constants.h \
script-fu-intl.h \
......@@ -24,6 +26,8 @@ script_fu_SOURCES = @STRIP_BEGIN@ \
script-fu-enums.h \
siod.h \
siodp.h \
siod-wrapper.c \
siod-wrapper.h \
@STRIP_END@
AM_CPPFLAGS = -DLOCALEDIR=\""$(localedir)"\"
......
This diff is collapsed.
#ifndef SIOD_WRAPPER_H
#define SIOD_WRAPPER_H
#include <stdio.h>
#include <glib.h>
void siod_init (gboolean register_scripts);
FILE *siod_get_output_file (void);
void siod_set_output_file (FILE *file);
int siod_get_verbose_level (void);
void siod_set_verbose_level (int verbose_level);
void siod_print_welcome (void);
const char *siod_get_error_msg (void);
const char *siod_get_success_msg (void);
/* if the return value is 0, success. error otherwise. */
int siod_interpret_string (const char *expr);
#endif /* SIOD_WRAPPER_H */
......@@ -38,7 +38,7 @@
#include "script-fu-intl.h"
#include "siod.h"
#include "siod-wrapper.h"
#include "script-fu-console.h"
#include <plug-ins/dbbrowser/dbbrowser_utils.h>
......@@ -85,8 +85,8 @@ static gboolean script_fu_cc_key_function (GtkWidget *widget,
GdkEventKey *event,
gpointer data);
static FILE * script_fu_open_siod_console (void);
static void script_fu_close_siod_console (void);
static void script_fu_open_siod_console (void);
static void script_fu_close_siod_console(void);
/*
* Local variables
......@@ -113,9 +113,6 @@ static gint history_cur = 0;
static gint history_max = 50;
static gint siod_output_pipe[2];
extern gint siod_verbose_level;
extern gchar siod_err_msg[];
extern FILE *siod_output;
#define message(string) printf("(%s): %d ::: %s\n", __PRETTY_FUNCTION__, __LINE__, string)
......@@ -498,7 +495,7 @@ script_fu_cc_key_function (GtkWidget *widget,
gtk_entry_set_text (GTK_ENTRY (cint.cc), "");
gdk_flush ();
repl_c_string ((char *) list->data, 0, 0, 1);
siod_interpret_string ((char *) list->data);
gimp_displays_flush ();
history = g_list_append (history, NULL);
......@@ -575,36 +572,49 @@ script_fu_cc_key_function (GtkWidget *widget,
return FALSE;
}
static FILE *
static void
script_fu_open_siod_console (void)
{
FILE *siod_output;
siod_output = siod_get_output_file ();
if (siod_output == stdout)
{
if (pipe (siod_output_pipe))
{
gimp_message (_("Unable to open SIOD output pipe"));
}
else if ((siod_output = fdopen (siod_output_pipe [1], "w")) == NULL)
{
gimp_message (_("Unable to open a stream on the SIOD output pipe"));
siod_output = stdout;
}
if (pipe (siod_output_pipe) == 0)
{
siod_output = fdopen (siod_output_pipe [1], "w");
if (siod_output != NULL)
{
siod_set_verbose_level (2);
siod_print_welcome ();
}
else
{
gimp_message (_("Unable to open a stream on the SIOD output pipe"));
siod_output = stdout;
}
}
else
{
siod_verbose_level = 2;
print_welcome ();
}
{
gimp_message (_("Unable to open the SIOD output pipe"));
siod_output = stdout;
}
}
return siod_output;
siod_set_output_file (siod_output);
}
static void
script_fu_close_siod_console (void)
{
FILE *siod_output;
siod_output = siod_get_output_file ();
if (siod_output != stdout)
fclose (siod_output);
close (siod_output_pipe[0]);
close (siod_output_pipe[1]);
}
......@@ -645,3 +655,4 @@ script_fu_eval_run (gchar *name,
values[0].type = GIMP_PDB_STATUS;
values[0].data.d_status = status;
}
......@@ -20,6 +20,7 @@
#define __SCRIPT_FU_SCRIPTS_H__
#include "script-fu-enums.h"
#include "siod.h"
void script_fu_find_scripts (void);
LISP script_fu_add_script (LISP a);
......
......@@ -42,7 +42,7 @@
#include "script-fu-intl.h"
#include "gtk/gtk.h"
#include "siod.h"
#include "siod-wrapper.h"
#include "script-fu-server.h"
......@@ -129,11 +129,6 @@ static void ok_callback (GtkWidget *widget,
gpointer data);
/*
* Global variables
*/
gint server_mode = FALSE;
/*
* Local variables
*/
......@@ -145,6 +140,8 @@ static FILE *server_log_file = NULL;
static GHashTable *clientname_ht = NULL;
static SELECT_MASK server_active;
static SELECT_MASK server_read;
static gboolean script_fu_done = FALSE;
static gboolean server_mode = FALSE;
static ServerInterface sint =
{
......@@ -157,14 +154,23 @@ static ServerInterface sint =
FALSE /* run */
};
extern gboolean script_fu_done;
extern gchar siod_err_msg[];
extern LISP repl_return_val;
/*
* Server interface functions
*/
void
script_fu_server_quit (void)
{
script_fu_done = TRUE;
}
gint
script_fu_server_get_mode (void)
{
return server_mode;
}
void
script_fu_server_run (gchar *name,
gint nparams,
......@@ -355,36 +361,32 @@ server_start (gint port,
static gboolean
execute_command (SFCommand *cmd)
{
guchar buffer[RESPONSE_HEADER];
gchar *response;
time_t clock1;
time_t clock2;
gint response_len;
gboolean error;
gint i;
guchar buffer[RESPONSE_HEADER];
const gchar *response;
time_t clock1;
time_t clock2;
gint response_len;
gboolean error;
gint i;
/* Get the client address from the address/socket table */
server_log ("Processing request #%d\n", cmd->request_no);
time (&clock1);
/* run the command */
if (repl_c_string (cmd->command, 0, 0, 1) != 0)
if (siod_interpret_string (cmd->command) != 0)
{
error = TRUE;
response_len = strlen (siod_err_msg);
response = siod_err_msg;
response = siod_get_error_msg ();
response_len = strlen (response);
server_log ("%s\n", siod_err_msg);
server_log ("%s\n", response);
}
else </