gimp/plug-ins/script-fu/script-fu.c

340 lines
13 KiB
C
Raw Normal View History

/* GIMP - The GNU Image Manipulation Program
1997-11-24 22:05:25 +00:00
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This program is free software: you can redistribute it and/or modify
1997-11-24 22:05:25 +00:00
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
1997-11-24 22:05:25 +00:00
* (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, see <https://www.gnu.org/licenses/>.
1997-11-24 22:05:25 +00:00
*/
New file. * plug-ins/makefile.msc: New file. * plug-ins/*/*.c (Well, not really all files, but many): Portability fixes. Include config.h, and guard inclusion of POSIX and Unix headers like <unistd.h>, <dirent.h> and <sys/time.h>. Include <string.h> if functions from it are used. Use g_ntohl() and g_htonl() insteead of ntohl() and htonl(), thus no need to include <netinet/in.h>. Include <io.h> on Win32 when using open/read/write (which actually are defined as _open/_read/_write by glib.h). Define S_* macros if necessary on Win32. Define rint() and M_PI if necessary (these definitions should be factored out somewhere, no sense repeating them in lots of files). Open files in binary mode when needed. * plug-ins/FractalExplorer/FractalExplorer.c: Use g_malloc()/g_free(). Use g_strdup_printf(). * plug-ins/dbbrowser/dbbrowser.c: No need to include <X11/Xlib.h>. * plug-ins/destripe/destripe.c: Guard use of SIGBUS. * plug-ins/{flame/flame,hrz/hrz,pnm/pnm}.c: No need to check for NULL returns from g_malloc() and g_new() as they abort on failure. Use g_strdup_printf(). * plug-ins/gz/gz.c: Win32 version of running the subprocess. * plug-ins/hrz/hrz.c: Win32 version. Use more generic tests for non-Unix (OS/2 and Win32), for instance HAVE_MMAP. * plug-ins/script-fu/interp_slib.c: Win32 version of myruntime(). * plug-ins/script-fu/interp_sliba.c: Handle \\ (escaped backslahsh). * plug-ins/script-fu/script-fu-console.c: Bypass on Win32. * plug-ins/script-fu/script-fu-scripts.c: Portability fixes. Use g_strdup_printf() instead of separate malloc() and sprintf(). Use g_strescape() for strings being passed to Scheme. Some Win32-only stuff.
1999-05-29 01:28:24 +00:00
#include "config.h"
1997-11-24 22:05:25 +00:00
#include <string.h>
New file. * plug-ins/makefile.msc: New file. * plug-ins/*/*.c (Well, not really all files, but many): Portability fixes. Include config.h, and guard inclusion of POSIX and Unix headers like <unistd.h>, <dirent.h> and <sys/time.h>. Include <string.h> if functions from it are used. Use g_ntohl() and g_htonl() insteead of ntohl() and htonl(), thus no need to include <netinet/in.h>. Include <io.h> on Win32 when using open/read/write (which actually are defined as _open/_read/_write by glib.h). Define S_* macros if necessary on Win32. Define rint() and M_PI if necessary (these definitions should be factored out somewhere, no sense repeating them in lots of files). Open files in binary mode when needed. * plug-ins/FractalExplorer/FractalExplorer.c: Use g_malloc()/g_free(). Use g_strdup_printf(). * plug-ins/dbbrowser/dbbrowser.c: No need to include <X11/Xlib.h>. * plug-ins/destripe/destripe.c: Guard use of SIGBUS. * plug-ins/{flame/flame,hrz/hrz,pnm/pnm}.c: No need to check for NULL returns from g_malloc() and g_new() as they abort on failure. Use g_strdup_printf(). * plug-ins/gz/gz.c: Win32 version of running the subprocess. * plug-ins/hrz/hrz.c: Win32 version. Use more generic tests for non-Unix (OS/2 and Win32), for instance HAVE_MMAP. * plug-ins/script-fu/interp_slib.c: Win32 version of myruntime(). * plug-ins/script-fu/interp_sliba.c: Handle \\ (escaped backslahsh). * plug-ins/script-fu/script-fu-console.c: Bypass on Win32. * plug-ins/script-fu/script-fu-scripts.c: Portability fixes. Use g_strdup_printf() instead of separate malloc() and sprintf(). Use g_strescape() for strings being passed to Scheme. Some Win32-only stuff.
1999-05-29 01:28:24 +00:00
#include <libgimp/gimp.h>
#include "console/script-fu-console.h"
#include "script-fu-eval.h"
#include "script-fu-text-console.h"
1997-11-24 22:05:25 +00:00
#include "libscriptfu/script-fu-lib.h"
#include "libscriptfu/script-fu-intl.h"
1997-11-24 22:05:25 +00:00
#define SCRIPT_FU_TYPE (script_fu_get_type ())
G_DECLARE_FINAL_TYPE (ScriptFu, script_fu, SCRIPT, FU, GimpPlugIn)
struct _ScriptFu
{
GimpPlugIn parent_instance;
};
static GList * script_fu_query_procedures (GimpPlugIn *plug_in);
static GimpProcedure * script_fu_create_procedure (GimpPlugIn *plug_in,
const gchar *name);
static GimpValueArray * script_fu_run (GimpProcedure *procedure,
GimpProcedureConfig *config,
gpointer run_data);
static GimpValueArray * script_fu_batch_run (GimpProcedure *procedure,
GimpRunMode run_mode,
const gchar *code,
GimpProcedureConfig *config,
gpointer run_data);
static void script_fu_run_init (GimpProcedure *procedure,
GimpRunMode run_mode);
static void script_fu_extension_init (GimpPlugIn *plug_in);
G_DEFINE_TYPE (ScriptFu, script_fu, GIMP_TYPE_PLUG_IN)
GIMP_MAIN (SCRIPT_FU_TYPE)
DEFINE_STD_SET_I18N
1997-11-24 22:05:25 +00:00
static void
script_fu_class_init (ScriptFuClass *klass)
1997-11-24 22:05:25 +00:00
{
GimpPlugInClass *plug_in_class = GIMP_PLUG_IN_CLASS (klass);
plug_in_class->query_procedures = script_fu_query_procedures;
plug_in_class->create_procedure = script_fu_create_procedure;
plug_in_class->set_i18n = STD_SET_I18N;
1997-11-24 22:05:25 +00:00
}
static void
script_fu_init (ScriptFu *script_fu)
1997-11-24 22:05:25 +00:00
{
}
static GList *
script_fu_query_procedures (GimpPlugIn *plug_in)
{
GList *list = NULL;
list = g_list_append (list, g_strdup ("extension-script-fu"));
list = g_list_append (list, g_strdup ("plug-in-script-fu-console"));
list = g_list_append (list, g_strdup ("plug-in-script-fu-text-console"));
list = g_list_append (list, g_strdup ("plug-in-script-fu-eval"));
return list;
}
static GimpProcedure *
script_fu_create_procedure (GimpPlugIn *plug_in,
const gchar *name)
{
GimpProcedure *procedure = NULL;
if (! strcmp (name, "extension-script-fu"))
{
procedure = gimp_procedure_new (plug_in, name,
GIMP_PDB_PROC_TYPE_EXTENSION,
script_fu_run, NULL, NULL);
gimp_procedure_set_documentation (procedure,
"A scheme interpreter for scripting "
"GIMP operations",
"More help here later",
NULL);
gimp_procedure_set_attribution (procedure,
"Spencer Kimball & Peter Mattis",
"Spencer Kimball & Peter Mattis",
"1997");
}
else if (! strcmp (name, "plug-in-script-fu-console"))
{
procedure = gimp_procedure_new (plug_in, name,
GIMP_PDB_PROC_TYPE_PLUGIN,
script_fu_run, NULL, NULL);
gimp_procedure_set_menu_label (procedure, _("Script-Fu _Console"));
gimp_procedure_add_menu_path (procedure,
"<Image>/Filters/Development/Script-Fu");
gimp_procedure_set_documentation (procedure,
_("Interactive console for Script-Fu "
"development"),
"Provides an interface which allows "
"interactive scheme development.",
name);
gimp_procedure_set_attribution (procedure,
"Spencer Kimball & Peter Mattis",
"Spencer Kimball & Peter Mattis",
"1997");
gimp_procedure_add_enum_argument (procedure, "run-mode",
"Run mode",
"The run mode",
GIMP_TYPE_RUN_MODE,
GIMP_RUN_INTERACTIVE,
G_PARAM_READWRITE);
gimp_procedure_add_string_array_aux_argument (procedure, "history",
"Command history",
"History",
G_PARAM_READWRITE);
}
else if (! strcmp (name, "plug-in-script-fu-text-console"))
{
procedure = gimp_procedure_new (plug_in, name,
GIMP_PDB_PROC_TYPE_PLUGIN,
script_fu_run, NULL, NULL);
gimp_procedure_set_documentation (procedure,
"Provides a text console mode for "
"script-fu development",
"Provides an interface which allows "
"interactive scheme development.",
name);
gimp_procedure_set_attribution (procedure,
"Spencer Kimball & Peter Mattis",
"Spencer Kimball & Peter Mattis",
"1997");
gimp_procedure_add_enum_argument (procedure, "run-mode",
"Run mode",
"The run mode",
GIMP_TYPE_RUN_MODE,
GIMP_RUN_INTERACTIVE,
G_PARAM_READWRITE);
}
else if (! strcmp (name, "plug-in-script-fu-eval"))
{
procedure = gimp_batch_procedure_new (plug_in, name, "Script-fu (scheme)",
GIMP_PDB_PROC_TYPE_PLUGIN,
script_fu_batch_run, NULL, NULL);
gimp_procedure_set_documentation (procedure,
"Evaluate scheme code",
"Evaluate the code under the scheme "
"interpreter (primarily for batch mode)",
name);
gimp_procedure_set_attribution (procedure,
"Manish Singh",
"Manish Singh",
"1998");
}
return procedure;
}
static GimpValueArray *
script_fu_run (GimpProcedure *procedure,
GimpProcedureConfig *config,
gpointer run_data)
{
GimpPlugIn *plug_in = gimp_procedure_get_plug_in (procedure);
const gchar *name = gimp_procedure_get_name (procedure);
GimpValueArray *return_vals = NULL;
GimpRunMode run_mode = GIMP_RUN_NONINTERACTIVE;
1997-11-24 22:05:25 +00:00
if (g_object_class_find_property (G_OBJECT_GET_CLASS (config), "run-mode") != NULL)
g_object_get (config, "run-mode", &run_mode, NULL);
script_fu_run_init (procedure, run_mode);
if (strcmp (name, "extension-script-fu") == 0)
1997-11-24 22:05:25 +00:00
{
/*
* The main script-fu extension.
*/
1997-11-24 22:05:25 +00:00
/* Acknowledge that the extension is properly initialized */
gimp_procedure_extension_ready (procedure);
1997-11-24 22:05:25 +00:00
/* Go into an endless loop */
while (TRUE)
gimp_plug_in_extension_process (plug_in, 0);
1997-11-24 22:05:25 +00:00
}
else if (strcmp (name, "plug-in-script-fu-text-console") == 0)
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.
2001-07-17 22:53:21 +00:00
{
/*
With this commit we finally say goodbye to SIOD. This large set of changes 2006-10-15 Kevin Cozens <kcozens@cvs.gnome.org> With this commit we finally say goodbye to SIOD. This large set of changes updates the Script-Fu plug-in to use the TinyScheme Scheme interpreter. These changes originated with changes originally made to Script-Fu which created Tiny-Fu (aka. the gimp-tiny-fu module). * plug-ins/script-fu/Makefile.am * plug-ins/script-fu/script-fu-console.c * plug-ins/script-fu/script-fu-interface.c * plug-ins/script-fu/script-fu-scripts.c * plug-ins/script-fu/script-fu-scripts.h * plug-ins/script-fu/script-fu-server.c * plug-ins/script-fu/script-fu-text-console.c * plug-ins/script-fu/script-fu.c: Updated with the changes made to these files as part of the work on the Tiny-Fu project. * plug-ins/script-fu/scheme-wrapper.c * plug-ins/script-fu/scheme-wrapper.h: Renamed from siod-wrapper.[ch] and updated based on differences to ts-wrapper.[ch] from gimp-tiny-fu. * plug-ins/script-fu/ftx/* * plug-ins/script-fu/re/* * plug-ins/script-fu/tinyscheme/* * plug-ins/script-fu/scripts/script-fu.init * plug-ins/script-fu/scripts/script-fu-compat.init * plug-ins/script-fu/scripts/contactsheet.scm * plug-ins/script-fu/scripts/script-fu-set-cmap.scm * plug-ins/script-fu/scripts/script-fu-util-setpt.scm * plug-ins/script-fu/scripts/ts-helloworld.scm: Added all of these files and directories from Tiny-Fu. Updated the Makefile.am files of ftx, re, and tinyscheme now they are in the GIMP source tree. * plug-ins/script-fu/scripts/*.scm: All scripts have been updated as needed to ensure they will work with the TinyScheme interpreter. Most of the files have been reformatted making it easier to see the syntax of Scheme and making them easier to read. * plug-ins/script-fu/scripts/Makefile.am: Updated script file lists. * plug-ins/script-fu/siod-wrapper.c * plug-ins/script-fu/siod-wrapper.h * plug-ins/script-fu/siod/*: Removed obsolete files. * configure.in: Updated list of files in AC_CONFIG_FILES. Changed --disable-script-fu to --without-script-fu which it should have been when originally added. * INSTALL: Updated to show change to --without-script-fu.
2006-10-16 01:08:54 +00:00
* The script-fu text console for interactive Scheme development
*/
return_vals = script_fu_text_console_run (procedure, config);
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.
2001-07-17 22:53:21 +00:00
}
else if (strcmp (name, "plug-in-script-fu-console") == 0)
1997-11-24 22:05:25 +00:00
{
/*
With this commit we finally say goodbye to SIOD. This large set of changes 2006-10-15 Kevin Cozens <kcozens@cvs.gnome.org> With this commit we finally say goodbye to SIOD. This large set of changes updates the Script-Fu plug-in to use the TinyScheme Scheme interpreter. These changes originated with changes originally made to Script-Fu which created Tiny-Fu (aka. the gimp-tiny-fu module). * plug-ins/script-fu/Makefile.am * plug-ins/script-fu/script-fu-console.c * plug-ins/script-fu/script-fu-interface.c * plug-ins/script-fu/script-fu-scripts.c * plug-ins/script-fu/script-fu-scripts.h * plug-ins/script-fu/script-fu-server.c * plug-ins/script-fu/script-fu-text-console.c * plug-ins/script-fu/script-fu.c: Updated with the changes made to these files as part of the work on the Tiny-Fu project. * plug-ins/script-fu/scheme-wrapper.c * plug-ins/script-fu/scheme-wrapper.h: Renamed from siod-wrapper.[ch] and updated based on differences to ts-wrapper.[ch] from gimp-tiny-fu. * plug-ins/script-fu/ftx/* * plug-ins/script-fu/re/* * plug-ins/script-fu/tinyscheme/* * plug-ins/script-fu/scripts/script-fu.init * plug-ins/script-fu/scripts/script-fu-compat.init * plug-ins/script-fu/scripts/contactsheet.scm * plug-ins/script-fu/scripts/script-fu-set-cmap.scm * plug-ins/script-fu/scripts/script-fu-util-setpt.scm * plug-ins/script-fu/scripts/ts-helloworld.scm: Added all of these files and directories from Tiny-Fu. Updated the Makefile.am files of ftx, re, and tinyscheme now they are in the GIMP source tree. * plug-ins/script-fu/scripts/*.scm: All scripts have been updated as needed to ensure they will work with the TinyScheme interpreter. Most of the files have been reformatted making it easier to see the syntax of Scheme and making them easier to read. * plug-ins/script-fu/scripts/Makefile.am: Updated script file lists. * plug-ins/script-fu/siod-wrapper.c * plug-ins/script-fu/siod-wrapper.h * plug-ins/script-fu/siod/*: Removed obsolete files. * configure.in: Updated list of files in AC_CONFIG_FILES. Changed --disable-script-fu to --without-script-fu which it should have been when originally added. * INSTALL: Updated to show change to --without-script-fu.
2006-10-16 01:08:54 +00:00
* The script-fu console for interactive Scheme development
*/
return_vals = script_fu_console_run (procedure, config);
1997-11-24 22:05:25 +00:00
}
if (! return_vals)
return_vals = gimp_procedure_new_return_values (procedure,
GIMP_PDB_SUCCESS,
NULL);
return return_vals;
}
static GimpValueArray *
script_fu_batch_run (GimpProcedure *procedure,
GimpRunMode run_mode,
const gchar *code,
GimpProcedureConfig *config,
gpointer run_data)
{
const gchar *name = gimp_procedure_get_name (procedure);
GimpValueArray *return_vals = NULL;
script_fu_run_init (procedure, run_mode);
if (strcmp (name, "plug-in-script-fu-eval") == 0)
{
/*
* A non-interactive "console" (for batch mode)
*/
if (g_strcmp0 (code, "-") == 0)
/* Redirecting to script-fu text console, for backward compatibility */
return_vals = script_fu_text_console_run (procedure, config);
else
return_vals = script_fu_eval_run (procedure, run_mode, code, config);
}
if (! return_vals)
return_vals = gimp_procedure_new_return_values (procedure,
GIMP_PDB_SUCCESS,
NULL);
return return_vals;
1997-11-24 22:05:25 +00:00
}
static void
script_fu_run_init (GimpProcedure *procedure,
GimpRunMode run_mode)
{
GimpPlugIn *plug_in = gimp_procedure_get_plug_in (procedure);
const gchar *name = gimp_procedure_get_name (procedure);
GList *path;
path = script_fu_search_path ();
/* 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 auxiliary temporary procedures for the base extension */
script_fu_extension_init (plug_in);
/* Init the interpreter, allow register scripts */
script_fu_init_embedded_interpreter (path, TRUE, run_mode);
}
else
{
/* Init the interpreter, not allow register scripts */
script_fu_init_embedded_interpreter (path, FALSE, run_mode);
}
script_fu_find_and_register_scripts (plug_in, path);
g_list_free_full (path, (GDestroyNotify) g_object_unref);
}
1997-11-24 22:05:25 +00:00
static void
script_fu_extension_init (GimpPlugIn *plug_in)
1997-11-24 22:05:25 +00:00
{
gimp_plug_in_add_menu_branch (plug_in, "<Image>/Help", N_("_GIMP Online"));
gimp_plug_in_add_menu_branch (plug_in, "<Image>/Help", N_("_User Manual"));
gimp_plug_in_add_menu_branch (plug_in, "<Image>/Filters/Development",
N_("_Script-Fu"));
gimp_plug_in_add_menu_branch (plug_in, "<Image>/Filters/Development/Script-Fu",
N_("_Test"));
gimp_plug_in_add_menu_branch (plug_in, "<Image>/File/Create",
N_("_Buttons"));
gimp_plug_in_add_menu_branch (plug_in, "<Image>/File/Create",
N_("_Logos"));
gimp_plug_in_add_menu_branch (plug_in, "<Image>/File/Create",
N_("_Patterns"));
gimp_plug_in_add_menu_branch (plug_in, "<Image>/File/Create",
N_("_Web Page Themes"));
gimp_plug_in_add_menu_branch (plug_in, "<Image>/File/Create/Web Page Themes",
N_("_Alien Glow"));
gimp_plug_in_add_menu_branch (plug_in, "<Image>/File/Create/Web Page Themes",
N_("_Beveled Pattern"));
gimp_plug_in_add_menu_branch (plug_in, "<Image>/File/Create/Web Page Themes",
N_("_Classic.Gimp.Org"));
gimp_plug_in_add_menu_branch (plug_in, "<Image>/Filters",
N_("Alpha to _Logo"));
/* Commented out until fixed or replaced.
* script_fu_register_refresh_procedure (plug_in);
*/
1997-11-24 22:05:25 +00:00
}