2001-10-19 01:27:36 +08:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* gimpmodules.c
|
|
|
|
* (C) 1999 Austin Donnelly <austin@gimp.org>
|
|
|
|
*
|
|
|
|
* 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 <stdio.h>
|
|
|
|
#include <string.h>
|
2002-02-18 22:34:50 +08:00
|
|
|
|
2001-10-19 01:27:36 +08:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
#include <glib-object.h>
|
|
|
|
|
|
|
|
#include "libgimpbase/gimpbase.h"
|
2002-10-21 22:15:02 +08:00
|
|
|
#include "libgimpmodule/gimpmodule.h"
|
2001-10-19 01:27:36 +08:00
|
|
|
|
|
|
|
#include "core-types.h"
|
|
|
|
|
2002-12-30 02:58:24 +08:00
|
|
|
#include "config/gimpconfig-path.h"
|
2003-09-02 20:55:38 +08:00
|
|
|
#include "config/gimpconfigwriter.h"
|
|
|
|
#include "config/gimpcoreconfig.h"
|
|
|
|
#include "config/gimpscanner.h"
|
2002-11-19 04:50:31 +08:00
|
|
|
|
2001-11-20 21:53:21 +08:00
|
|
|
#include "gimp.h"
|
|
|
|
#include "gimpmodules.h"
|
2001-10-19 01:27:36 +08:00
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
#include "gimp-intl.h"
|
2001-10-19 01:27:36 +08:00
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_modules_init (Gimp *gimp)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_GIMP (gimp));
|
|
|
|
|
2002-10-23 22:55:07 +08:00
|
|
|
gimp->module_db = gimp_module_db_new (gimp->be_verbose);
|
2001-10-19 01:27:36 +08:00
|
|
|
gimp->write_modulerc = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_modules_exit (Gimp *gimp)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_GIMP (gimp));
|
|
|
|
|
2002-10-23 22:55:07 +08:00
|
|
|
if (gimp->module_db)
|
2001-10-19 01:27:36 +08:00
|
|
|
{
|
2003-01-06 06:07:10 +08:00
|
|
|
g_object_unref (gimp->module_db);
|
2002-10-23 22:55:07 +08:00
|
|
|
gimp->module_db = NULL;
|
2001-10-19 01:27:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_modules_load (Gimp *gimp)
|
|
|
|
{
|
2003-09-02 21:24:43 +08:00
|
|
|
gchar *filename;
|
|
|
|
gchar *path;
|
|
|
|
GScanner *scanner;
|
|
|
|
gchar *module_load_inhibit = NULL;
|
2003-09-02 20:55:38 +08:00
|
|
|
|
2001-10-19 01:27:36 +08:00
|
|
|
g_return_if_fail (GIMP_IS_GIMP (gimp));
|
|
|
|
|
2003-09-02 20:55:38 +08:00
|
|
|
filename = gimp_personal_rc_file ("modulerc");
|
2003-09-02 21:24:43 +08:00
|
|
|
scanner = gimp_scanner_new_file (filename, NULL);
|
2001-10-19 01:27:36 +08:00
|
|
|
g_free (filename);
|
|
|
|
|
2003-09-02 21:24:43 +08:00
|
|
|
if (scanner)
|
|
|
|
{
|
|
|
|
GTokenType token;
|
|
|
|
GError *error = NULL;
|
|
|
|
|
2003-09-02 20:55:38 +08:00
|
|
|
#define MODULE_LOAD_INHIBIT 1
|
|
|
|
|
2003-09-02 21:24:43 +08:00
|
|
|
g_scanner_scope_add_symbol (scanner, 0, "module-load-inhibit",
|
|
|
|
GINT_TO_POINTER (MODULE_LOAD_INHIBIT));
|
2003-09-02 20:55:38 +08:00
|
|
|
|
2003-09-02 21:24:43 +08:00
|
|
|
token = G_TOKEN_LEFT_PAREN;
|
2003-09-02 20:55:38 +08:00
|
|
|
|
2003-09-02 21:24:43 +08:00
|
|
|
while (g_scanner_peek_next_token (scanner) == token)
|
2003-09-02 20:55:38 +08:00
|
|
|
{
|
2003-09-02 21:24:43 +08:00
|
|
|
token = g_scanner_get_next_token (scanner);
|
2003-09-02 20:55:38 +08:00
|
|
|
|
2003-09-02 21:24:43 +08:00
|
|
|
switch (token)
|
2003-09-02 20:55:38 +08:00
|
|
|
{
|
2003-09-02 21:24:43 +08:00
|
|
|
case G_TOKEN_LEFT_PAREN:
|
|
|
|
token = G_TOKEN_SYMBOL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case G_TOKEN_SYMBOL:
|
|
|
|
if (scanner->value.v_symbol == GINT_TO_POINTER (MODULE_LOAD_INHIBIT))
|
|
|
|
{
|
|
|
|
token = G_TOKEN_STRING;
|
|
|
|
|
|
|
|
if (! gimp_scanner_parse_string_no_validate (scanner,
|
|
|
|
&module_load_inhibit))
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
token = G_TOKEN_RIGHT_PAREN;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case G_TOKEN_RIGHT_PAREN:
|
|
|
|
token = G_TOKEN_LEFT_PAREN;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: /* do nothing */
|
|
|
|
break;
|
2003-09-02 20:55:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef MODULE_LOAD_INHIBIT
|
|
|
|
|
2003-09-02 21:24:43 +08:00
|
|
|
if (token != G_TOKEN_LEFT_PAREN)
|
|
|
|
{
|
|
|
|
g_scanner_get_next_token (scanner);
|
|
|
|
g_scanner_unexp_token (scanner, token, NULL, NULL, NULL,
|
|
|
|
_("fatal parse error"), TRUE);
|
|
|
|
}
|
2003-09-02 20:55:38 +08:00
|
|
|
|
2003-09-02 21:24:43 +08:00
|
|
|
error:
|
2003-09-02 20:55:38 +08:00
|
|
|
|
2003-09-02 21:24:43 +08:00
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
g_message (error->message);
|
|
|
|
g_clear_error (&error);
|
|
|
|
}
|
2003-09-02 20:55:38 +08:00
|
|
|
|
2003-09-02 21:24:43 +08:00
|
|
|
gimp_scanner_destroy (scanner);
|
|
|
|
}
|
2003-09-02 20:55:38 +08:00
|
|
|
|
|
|
|
if (module_load_inhibit)
|
|
|
|
{
|
|
|
|
gimp_module_db_set_load_inhibit (gimp->module_db, module_load_inhibit);
|
|
|
|
g_free (module_load_inhibit);
|
|
|
|
}
|
|
|
|
|
|
|
|
path = gimp_config_path_expand (gimp->config->module_path, TRUE, NULL);
|
|
|
|
gimp_module_db_load (gimp->module_db, path);
|
|
|
|
g_free (path);
|
2001-10-19 01:27:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
add_to_inhibit_string (gpointer data,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2002-10-21 22:15:02 +08:00
|
|
|
GimpModule *module = data;
|
|
|
|
GString *str = user_data;
|
2001-10-19 01:27:36 +08:00
|
|
|
|
2002-10-21 22:15:02 +08:00
|
|
|
if (module->load_inhibit)
|
2001-10-19 01:27:36 +08:00
|
|
|
{
|
|
|
|
str = g_string_append_c (str, G_SEARCHPATH_SEPARATOR);
|
2002-10-21 22:15:02 +08:00
|
|
|
str = g_string_append (str, module->filename);
|
2001-10-19 01:27:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-10-23 22:55:07 +08:00
|
|
|
void
|
|
|
|
gimp_modules_unload (Gimp *gimp)
|
2001-10-19 01:27:36 +08:00
|
|
|
{
|
2002-10-23 22:55:07 +08:00
|
|
|
g_return_if_fail (GIMP_IS_GIMP (gimp));
|
2001-10-19 01:27:36 +08:00
|
|
|
|
2002-10-23 22:55:07 +08:00
|
|
|
if (gimp->write_modulerc)
|
2001-10-19 01:27:36 +08:00
|
|
|
{
|
2003-09-02 20:55:38 +08:00
|
|
|
GimpConfigWriter *writer;
|
|
|
|
GString *str;
|
|
|
|
gchar *p;
|
|
|
|
gchar *filename;
|
|
|
|
GError *error = NULL;
|
2002-10-23 22:55:07 +08:00
|
|
|
|
|
|
|
str = g_string_new (NULL);
|
|
|
|
g_list_foreach (gimp->module_db->modules, add_to_inhibit_string, str);
|
|
|
|
if (str->len > 0)
|
|
|
|
p = str->str + 1;
|
|
|
|
else
|
|
|
|
p = "";
|
|
|
|
|
|
|
|
filename = gimp_personal_rc_file ("modulerc");
|
2003-09-02 20:55:38 +08:00
|
|
|
writer = gimp_config_writer_new_file (filename, TRUE,
|
|
|
|
"GIMP modulerc", &error);
|
2002-10-23 22:55:07 +08:00
|
|
|
g_free (filename);
|
|
|
|
|
2003-09-02 20:55:38 +08:00
|
|
|
if (writer)
|
2002-10-23 22:55:07 +08:00
|
|
|
{
|
2003-09-02 20:55:38 +08:00
|
|
|
gimp_config_writer_open (writer, "module-load-inhibit");
|
|
|
|
gimp_config_writer_printf (writer, "\"%s\"", p);
|
|
|
|
gimp_config_writer_close (writer);
|
|
|
|
|
|
|
|
gimp_config_writer_finish (writer, "end of modulerc", &error);
|
2002-10-23 22:55:07 +08:00
|
|
|
|
|
|
|
gimp->write_modulerc = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_string_free (str, TRUE);
|
2003-09-02 20:55:38 +08:00
|
|
|
|
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
g_message (error->message);
|
|
|
|
g_clear_error (&error);
|
|
|
|
}
|
2001-10-19 01:27:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-10-23 22:55:07 +08:00
|
|
|
void
|
|
|
|
gimp_modules_refresh (Gimp *gimp)
|
2001-10-19 01:27:36 +08:00
|
|
|
{
|
2002-12-30 02:58:24 +08:00
|
|
|
gchar *path;
|
|
|
|
|
2002-10-23 22:55:07 +08:00
|
|
|
g_return_if_fail (GIMP_IS_GIMP (gimp));
|
2001-10-19 01:27:36 +08:00
|
|
|
|
2002-12-30 02:58:24 +08:00
|
|
|
path = gimp_config_path_expand (gimp->config->module_path, TRUE, NULL);
|
|
|
|
gimp_module_db_refresh (gimp->module_db, path);
|
|
|
|
g_free (path);
|
2001-10-19 01:27:36 +08:00
|
|
|
}
|