Gimp/plug-ins/script-fu/script-fu.c
Michael Natterer ecb0b58439 Changed the semantics of GIMP_EXTENSION and (to some extent) of
2003-06-19  Michael Natterer  <mitch@gimp.org>

	Changed the semantics of GIMP_EXTENSION and (to some extent)
	of GIMP_PLUGIN:

	The old meaning of EXTENSION was "I live in the toolbox" and
	PLUGIN meant "I take RUN-MODE,IMAGE,DRAWABLE args (but only if I
	am invoked interactively)". This is completely useless, since
	living in the toolbox means having "<Toolbox>" in the menu_path
	and taking RUN-MODE,IMAGE,DRAWABLE means just that, regardless of
	what type of procedure we are.

	The new meaning of GIMP_PLUGIN is just "I am an ordinary procedure,
	I am invoked, do my job and finish", while GIMP_EXTENSION means
	"I will install temporary procedures and I will keep running to
	keep them available".

	(A GIMP_EXTENSION *must* call gimp_extension_ack() now to tell the
	core that it's ready to run, or the core will block waiting for
	the message !!!).

	* configure.in: bumped version number to 1.3.16.

	* libgimpbase/gimpprotocol.h: increased protocol version number so
	old extensions will refuse to load.

	* app/gui/plug-in-commands.c (plug_in_run_cmd_callback): don't
	blindly pass RUN-MODE,IMAGE,DRAWABLE to GIMP_PLUGIN procedures but
	look at their parameters and pass them either RUN-MODE, or
	RUN-MODE,IMAGE, or RUN-MODE,IMAGE,DRAWABLE.

	* app/pdb/procedural_db.c: cleaned up, better error reporting,
	replaced an impossible error message by g_return_if_fail()

	* app/plug-in/plug-in-message.c (plug_in_handle_proc_install):
	better error messages.

	* app/plug-in/plug-in-params.c: allocate parameter arrays using
	g_new0() so we don't have to worry about uninitialized stuff
	later.

	* app/plug-in/plug-in-run.c (plug_in_run): wait for
	gimp_extension_ack() installation confirmation for ALL extensions,
	not just for automatically started ones.

	* app/plug-in/plug-ins.c: cleanup.

	* libgimp/gimp.[ch]: cleaned up and API-documented massively. Made
	all magic values given in the GPConfig message static and added
	accessor functions for them. Added gimp_tile_width()/height().
	Added new function gimp_extension_enable() which turns on
	asynchronous processing of temp_proc run requests without having
	to enter an endless gimp_extension_process() loop. Moved all
	private functions to the end of the file. Added tons of
	g_return_if_fail() all over the place.  Call gimp_run_procedure2()
	from gimp_run_procedure() instead of duplicating the
	code. Indentation, spacing, stuff...

	* libgimp/gimptile.[ch]: removed gimp_tile_width()/height().

	* libgimp/gimpdrawable.c
	* libgimp/gimppixelrgn.c
	* libgimp/gimptile.c: use the gimp_tile_width()/height() accessor
	functions.

	* libgimp/gimp.def: added gimp_extension_enable.

	* libgimp/gimpmenu.c: removed evil code which connected to
	_readchannel manually and use gimp_extension_enable() for watching
	temp_procs.

	* plug-ins/helpbrowser/helpbrowser.c: removed the same evil code
	here and call gimp_extension_enable(). Call gimp_extension_ack()
	to let the core know that the temp_proc is installed.

	* plug-ins/script-fu/script-fu.c: made all procedures except the
	permanently running "extension_script_fu" ordinary GIMP_PLUGIN
	procedures.

	* plug-ins/common/curve_bend.c
	* plug-ins/common/plugindetails.c
	* plug-ins/common/screenshot.c
	* plug-ins/common/uniteditor.c
	* plug-ins/common/winclipboard.c
	* plug-ins/dbbrowser/dbbrowser.c
	* plug-ins/gfli/gfli.c
	* plug-ins/twain/twain.c
	* plug-ins/webbrowser/webbrowser.c
	* plug-ins/winsnap/winsnap.c: made them all ordinary GIMP_PLUGIN
	procedures and renamed them from "extension_*" to "plug_in_*".
	Random cleanups.

	* app/widgets/gimphelp.c
	* plug-ins/maze/maze_face.c: call "plug_in_web_browser" now.
2003-06-19 17:12:00 +00:00

302 lines
8 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 <stdlib.h>
#include <stdio.h>
#include <string.h>
#if HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <gtk/gtk.h>
#include <libgimp/gimp.h>
#include "siod-wrapper.h"
#include "script-fu-console.h"
#include "script-fu-constants.h"
#include "script-fu-scripts.h"
#include "script-fu-server.h"
#include "script-fu-text-console.h"
#include "script-fu-intl.h"
/* Declare local functions.
*/
static void script_fu_quit (void);
static void script_fu_query (void);
static void script_fu_run (gchar *name,
gint nparams,
GimpParam *param,
gint *nreturn_vals,
GimpParam **return_vals);
static void script_fu_auxillary_init (void);
static void script_fu_refresh_proc (gchar *name,
gint nparams,
GimpParam *params,
gint *nreturn_vals,
GimpParam **return_vals);
GimpPlugInInfo PLUG_IN_INFO =
{
NULL, /* init_proc */
script_fu_quit, /* quit_proc */
script_fu_query, /* query_proc */
script_fu_run, /* run_proc */
};
MAIN ()
static void
script_fu_quit (void)
{
}
static void
script_fu_query (void)
{
static GimpParamDef console_args[] =
{
{ GIMP_PDB_INT32, "run_mode", "Interactive, [non-interactive]" }
};
static GimpParamDef textconsole_args[] =
{
{ GIMP_PDB_INT32, "run_mode", "Interactive, [non-interactive]" }
};
static GimpParamDef eval_args[] =
{
{ GIMP_PDB_INT32, "run_mode", "[Interactive], non-interactive" },
{ GIMP_PDB_STRING, "code", "The code to evaluate" }
};
static GimpParamDef server_args[] =
{
{ GIMP_PDB_INT32, "run_mode", "[Interactive], non-interactive" },
{ GIMP_PDB_INT32, "port", "The port on which to listen for requests" },
{ GIMP_PDB_STRING, "logfile", "The file to log server activity to" }
};
gimp_plugin_domain_register (GETTEXT_PACKAGE "-script-fu", NULL);
gimp_install_procedure ("extension_script_fu",
"A scheme interpreter for scripting GIMP operations",
"More help here later",
"Spencer Kimball & Peter Mattis",
"Spencer Kimball & Peter Mattis",
"1997",
NULL,
NULL,
GIMP_EXTENSION,
0, 0, NULL, NULL);
gimp_install_procedure ("plug_in_script_fu_console",
"Provides a console mode for script-fu development",
"Provides an interface which allows interactive scheme development.",
"Spencer Kimball & Peter Mattis",
"Spencer Kimball & Peter Mattis",
"1997",
N_("<Toolbox>/Xtns/Script-Fu/Console..."),
NULL,
GIMP_PLUGIN,
G_N_ELEMENTS (console_args), 0,
console_args, NULL);
gimp_install_procedure ("plug_in_script_fu_text_console",
"Provides a text console mode for script-fu development",
"Provides an interface which allows interactive scheme development.",
"Spencer Kimball & Peter Mattis",
"Spencer Kimball & Peter Mattis",
"1997",
NULL,
NULL,
GIMP_PLUGIN,
G_N_ELEMENTS (textconsole_args), 0,
textconsole_args, NULL);
#ifndef G_OS_WIN32
gimp_install_procedure ("plug_in_script_fu_server",
"Provides a server for remote script-fu operation",
"Provides a server for remote script-fu operation",
"Spencer Kimball & Peter Mattis",
"Spencer Kimball & Peter Mattis",
"1997",
N_("<Toolbox>/Xtns/Script-Fu/Server..."),
NULL,
GIMP_PLUGIN,
G_N_ELEMENTS (server_args), 0,
server_args, NULL);
#endif
gimp_install_procedure ("plug_in_script_fu_eval",
"Evaluate scheme code",
"Evaluate the code under the scheme interpeter (primarily for batch mode)",
"Manish Singh",
"Manish Singh",
"1998",
NULL,
NULL,
GIMP_PLUGIN,
G_N_ELEMENTS (eval_args), 0,
eval_args, NULL);
}
static void
script_fu_run (gchar *name,
gint nparams,
GimpParam *param,
gint *nreturn_vals,
GimpParam **return_vals)
{
INIT_I18N();
siod_set_output_file (stdout);
/* Determine before we allow scripts to register themselves
* whether this is the base, automatically installed script-fu extension
*/
if (strcmp (name, "extension_script_fu") == 0)
{
/* Setup auxillary temporary procedures for the base extension */
script_fu_auxillary_init ();
/* Init the interpreter */
siod_init (TRUE);
}
else
{
/* Init the interpreter */
siod_init (FALSE);
}
/* Load all of the available scripts */
script_fu_find_scripts ();
if (strcmp (name, "extension_script_fu") == 0)
{
/*
* The main, automatically installed script fu extension. For
* things like logos and effects that are runnable from GIMP
* menus.
*/
static GimpParam values[1];
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
/* Acknowledge that the extension is properly initialized */
gimp_extension_ack ();
while (TRUE)
gimp_extension_process (0);
*nreturn_vals = 1;
*return_vals = values;
values[0].type = GIMP_PDB_STATUS;
values[0].data.d_status = status;
}
else if (strcmp (name, "plug_in_script_fu_text_console") == 0)
{
/*
* The script-fu text console for interactive SIOD development
*/
script_fu_text_console_run (name, nparams, param,
nreturn_vals, return_vals);
}
else if (strcmp (name, "plug_in_script_fu_console") == 0)
{
/*
* The script-fu console for interactive SIOD development
*/
script_fu_console_run (name, nparams, param,
nreturn_vals, return_vals);
}
#ifndef G_OS_WIN32
else if (strcmp (name, "plug_in_script_fu_server") == 0)
{
/*
* The script-fu server for remote operation
*/
script_fu_server_run (name, nparams, param,
nreturn_vals, return_vals);
}
#endif
else if (strcmp (name, "plug_in_script_fu_eval") == 0)
{
/*
* A non-interactive "console" (for batch mode)
*/
script_fu_eval_run (name, nparams, param,
nreturn_vals, return_vals);
}
}
static void
script_fu_auxillary_init (void)
{
static GimpParamDef args[] =
{
{ GIMP_PDB_INT32, "run_mode", "[Interactive], non-interactive" }
};
gimp_install_temp_proc ("script_fu_refresh",
_("Re-read all available scripts"),
_("Re-read all available scripts"),
"Spencer Kimball & Peter Mattis",
"Spencer Kimball & Peter Mattis",
"1997",
N_("<Toolbox>/Xtns/Script-Fu/Refresh"),
NULL,
GIMP_TEMPORARY,
G_N_ELEMENTS (args), 0,
args, NULL,
script_fu_refresh_proc);
}
static void
script_fu_refresh_proc (gchar *name,
gint nparams,
GimpParam *params,
gint *nreturn_vals,
GimpParam **return_vals)
{
static GimpParam values[1];
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
/* Reload all of the available scripts */
script_fu_find_scripts ();
*nreturn_vals = 1;
*return_vals = values;
values[0].type = GIMP_PDB_STATUS;
values[0].data.d_status = status;
}