diff --git a/ChangeLog b/ChangeLog index 3db63da981..c697704dca 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2003-09-02 Michael Natterer + + * app/config/gimpcoreconfig.[ch] + * app/config/gimprc-blurbs.h: removed "module-load-inhibit" + property since the GimpModuleDB stores this value. + + * app/config/gimpconfigwriter.[ch] (gimp_config_writer_new): + renamed parameter "gboolean safe" to "gboolean atomic". + + * app/core/gimpmodules.c: ported modulerc parsing/writing to + GimpScanner and GimpConfigWriter (apparently it was forgotten + during gimprc cleanup). Makes keeping modules from being loaded + work again. Reported by Michael Schumacher on #gimp. + 2003-09-02 Simon Budig * app/vectors/gimpstroke.c: duplicate the closed property too. diff --git a/app/config/gimpconfigwriter.c b/app/config/gimpconfigwriter.c index a4cb3bf52b..d1449fb14b 100644 --- a/app/config/gimpconfigwriter.c +++ b/app/config/gimpconfigwriter.c @@ -65,7 +65,7 @@ static gboolean gimp_config_writer_close_file (GimpConfigWriter *writer, GimpConfigWriter * gimp_config_writer_new_file (const gchar *filename, - gboolean safe, + gboolean atomic, const gchar *header, GError **error) { @@ -76,7 +76,7 @@ gimp_config_writer_new_file (const gchar *filename, g_return_val_if_fail (filename != NULL, NULL); g_return_val_if_fail (error == NULL || *error == NULL, NULL); - if (safe) + if (atomic) { tmpname = g_strconcat (filename, "XXXXXX", NULL); diff --git a/app/config/gimpconfigwriter.h b/app/config/gimpconfigwriter.h index a0c6804241..a4c8194624 100644 --- a/app/config/gimpconfigwriter.h +++ b/app/config/gimpconfigwriter.h @@ -24,7 +24,7 @@ GimpConfigWriter * gimp_config_writer_new_file (const gchar *filename, - gboolean safe, + gboolean atomic, const gchar *header, GError **error); GimpConfigWriter * gimp_config_writer_new_fd (gint fd); diff --git a/app/config/gimpcoreconfig.c b/app/config/gimpcoreconfig.c index 52981a881b..5d0b081af5 100644 --- a/app/config/gimpcoreconfig.c +++ b/app/config/gimpcoreconfig.c @@ -84,7 +84,6 @@ enum PROP_UNDO_LEVELS, PROP_UNDO_SIZE, PROP_PLUGINRC_PATH, - PROP_MODULE_LOAD_INHIBIT, PROP_LAYER_PREVIEWS, PROP_LAYER_PREVIEW_SIZE, PROP_THUMBNAIL_SIZE, @@ -257,11 +256,6 @@ gimp_core_config_class_init (GimpCoreConfigClass *klass) GIMP_PARAM_PATH_FILE, "${gimp_dir}" G_DIR_SEPARATOR_S "pluginrc", GIMP_PARAM_RESTART); - GIMP_CONFIG_INSTALL_PROP_STRING (object_class, PROP_MODULE_LOAD_INHIBIT, - "module-load-inhibit", - MODULE_LOAD_INHIBIT_BLURB, - NULL, - 0); GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_LAYER_PREVIEWS, "layer-previews", LAYER_PREVIEWS_BLURB, TRUE, @@ -313,7 +307,6 @@ gimp_core_config_finalize (GObject *object) g_free (core_config->default_font); g_free (core_config->default_comment); g_free (core_config->plug_in_rc_path); - g_free (core_config->module_load_inhibit); G_OBJECT_CLASS (parent_class)->finalize (object); } @@ -420,10 +413,6 @@ gimp_core_config_set_property (GObject *object, g_free (core_config->plug_in_rc_path); core_config->plug_in_rc_path = g_value_dup_string (value); break; - case PROP_MODULE_LOAD_INHIBIT: - g_free (core_config->module_load_inhibit); - core_config->module_load_inhibit = g_value_dup_string (value); - break; case PROP_LAYER_PREVIEWS: core_config->layer_previews = g_value_get_boolean (value); break; @@ -536,9 +525,6 @@ gimp_core_config_get_property (GObject *object, case PROP_PLUGINRC_PATH: g_value_set_string (value, core_config->plug_in_rc_path); break; - case PROP_MODULE_LOAD_INHIBIT: - g_value_set_string (value, core_config->module_load_inhibit); - break; case PROP_LAYER_PREVIEWS: g_value_set_boolean (value, core_config->layer_previews); break; diff --git a/app/config/gimpcoreconfig.h b/app/config/gimpcoreconfig.h index e13460d4d4..d1668106ed 100644 --- a/app/config/gimpcoreconfig.h +++ b/app/config/gimpcoreconfig.h @@ -65,7 +65,6 @@ struct _GimpCoreConfig gint levels_of_undo; gulong undo_size; gchar *plug_in_rc_path; - gchar *module_load_inhibit; gboolean layer_previews; GimpPreviewSize layer_preview_size; GimpThumbnailSize thumbnail_size; diff --git a/app/config/gimprc-blurbs.h b/app/config/gimprc-blurbs.h index 16a3bbdfa4..a60e7977be 100644 --- a/app/config/gimprc-blurbs.h +++ b/app/config/gimprc-blurbs.h @@ -176,9 +176,6 @@ N_("Generally only a concern for 8-bit displays, this sets the minimum " \ #define MODULE_PATH_BLURB \ "Sets the module search path." -#define MODULE_LOAD_INHIBIT_BLURB \ -"To inhibit loading of a module, add its name here." - #define MONITOR_RES_FROM_GDK_BLURB \ "When enabled, the GIMP will use the monitor resolution from the " \ "windowing system." diff --git a/app/core/gimp-modules.c b/app/core/gimp-modules.c index 7d9231889f..6a63cac33f 100644 --- a/app/core/gimp-modules.c +++ b/app/core/gimp-modules.c @@ -36,11 +36,12 @@ #include "core-types.h" -#include "config/gimpcoreconfig.h" #include "config/gimpconfig-path.h" +#include "config/gimpconfigwriter.h" +#include "config/gimpcoreconfig.h" +#include "config/gimpscanner.h" #include "gimp.h" -#include "gimplist.h" #include "gimpmodules.h" #include "gimp-intl.h" @@ -70,15 +71,85 @@ gimp_modules_exit (Gimp *gimp) void gimp_modules_load (Gimp *gimp) { + gchar *filename; + gchar *path; + GScanner *scanner; + GTokenType token; + gchar *module_load_inhibit = NULL; + GError *error = NULL; + g_return_if_fail (GIMP_IS_GIMP (gimp)); -#if 0 - gchar *filename = gimp_personal_rc_file ("modulerc"); - gimprc_parse_file (filename); + filename = gimp_personal_rc_file ("modulerc"); + scanner = gimp_scanner_new_file (filename, &error); g_free (filename); -#endif - gimp_modules_refresh (gimp); +#define MODULE_LOAD_INHIBIT 1 + + g_scanner_scope_add_symbol (scanner, 0, "module-load-inhibit", + GINT_TO_POINTER (MODULE_LOAD_INHIBIT)); + + token = G_TOKEN_LEFT_PAREN; + + while (g_scanner_peek_next_token (scanner) == token) + { + token = g_scanner_get_next_token (scanner); + + switch (token) + { + 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; + } + } + +#undef MODULE_LOAD_INHIBIT + + 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); + } + + error: + + if (error) + { + g_message (error->message); + g_clear_error (&error); + } + + gimp_scanner_destroy (scanner); + + 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); } static void @@ -102,10 +173,11 @@ gimp_modules_unload (Gimp *gimp) if (gimp->write_modulerc) { - GString *str; - gchar *p; - gchar *filename; - FILE *fp; + GimpConfigWriter *writer; + GString *str; + gchar *p; + gchar *filename; + GError *error = NULL; str = g_string_new (NULL); g_list_foreach (gimp->module_db->modules, add_to_inhibit_string, str); @@ -115,18 +187,28 @@ gimp_modules_unload (Gimp *gimp) p = ""; filename = gimp_personal_rc_file ("modulerc"); - fp = fopen (filename, "wt"); + writer = gimp_config_writer_new_file (filename, TRUE, + "GIMP modulerc", &error); g_free (filename); - if (fp) + if (writer) { - fprintf (fp, "(module-load-inhibit \"%s\")\n", p); - fclose (fp); + 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); gimp->write_modulerc = FALSE; } g_string_free (str, TRUE); + + if (error) + { + g_message (error->message); + g_clear_error (&error); + } } } @@ -137,9 +219,6 @@ gimp_modules_refresh (Gimp *gimp) g_return_if_fail (GIMP_IS_GIMP (gimp)); - gimp_module_db_set_load_inhibit (gimp->module_db, - gimp->config->module_load_inhibit); - path = gimp_config_path_expand (gimp->config->module_path, TRUE, NULL); gimp_module_db_refresh (gimp->module_db, path); g_free (path); diff --git a/app/core/gimpmodules.c b/app/core/gimpmodules.c index 7d9231889f..6a63cac33f 100644 --- a/app/core/gimpmodules.c +++ b/app/core/gimpmodules.c @@ -36,11 +36,12 @@ #include "core-types.h" -#include "config/gimpcoreconfig.h" #include "config/gimpconfig-path.h" +#include "config/gimpconfigwriter.h" +#include "config/gimpcoreconfig.h" +#include "config/gimpscanner.h" #include "gimp.h" -#include "gimplist.h" #include "gimpmodules.h" #include "gimp-intl.h" @@ -70,15 +71,85 @@ gimp_modules_exit (Gimp *gimp) void gimp_modules_load (Gimp *gimp) { + gchar *filename; + gchar *path; + GScanner *scanner; + GTokenType token; + gchar *module_load_inhibit = NULL; + GError *error = NULL; + g_return_if_fail (GIMP_IS_GIMP (gimp)); -#if 0 - gchar *filename = gimp_personal_rc_file ("modulerc"); - gimprc_parse_file (filename); + filename = gimp_personal_rc_file ("modulerc"); + scanner = gimp_scanner_new_file (filename, &error); g_free (filename); -#endif - gimp_modules_refresh (gimp); +#define MODULE_LOAD_INHIBIT 1 + + g_scanner_scope_add_symbol (scanner, 0, "module-load-inhibit", + GINT_TO_POINTER (MODULE_LOAD_INHIBIT)); + + token = G_TOKEN_LEFT_PAREN; + + while (g_scanner_peek_next_token (scanner) == token) + { + token = g_scanner_get_next_token (scanner); + + switch (token) + { + 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; + } + } + +#undef MODULE_LOAD_INHIBIT + + 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); + } + + error: + + if (error) + { + g_message (error->message); + g_clear_error (&error); + } + + gimp_scanner_destroy (scanner); + + 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); } static void @@ -102,10 +173,11 @@ gimp_modules_unload (Gimp *gimp) if (gimp->write_modulerc) { - GString *str; - gchar *p; - gchar *filename; - FILE *fp; + GimpConfigWriter *writer; + GString *str; + gchar *p; + gchar *filename; + GError *error = NULL; str = g_string_new (NULL); g_list_foreach (gimp->module_db->modules, add_to_inhibit_string, str); @@ -115,18 +187,28 @@ gimp_modules_unload (Gimp *gimp) p = ""; filename = gimp_personal_rc_file ("modulerc"); - fp = fopen (filename, "wt"); + writer = gimp_config_writer_new_file (filename, TRUE, + "GIMP modulerc", &error); g_free (filename); - if (fp) + if (writer) { - fprintf (fp, "(module-load-inhibit \"%s\")\n", p); - fclose (fp); + 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); gimp->write_modulerc = FALSE; } g_string_free (str, TRUE); + + if (error) + { + g_message (error->message); + g_clear_error (&error); + } } } @@ -137,9 +219,6 @@ gimp_modules_refresh (Gimp *gimp) g_return_if_fail (GIMP_IS_GIMP (gimp)); - gimp_module_db_set_load_inhibit (gimp->module_db, - gimp->config->module_load_inhibit); - path = gimp_config_path_expand (gimp->config->module_path, TRUE, NULL); gimp_module_db_refresh (gimp->module_db, path); g_free (path); diff --git a/libgimpconfig/gimpconfigwriter.c b/libgimpconfig/gimpconfigwriter.c index a4cb3bf52b..d1449fb14b 100644 --- a/libgimpconfig/gimpconfigwriter.c +++ b/libgimpconfig/gimpconfigwriter.c @@ -65,7 +65,7 @@ static gboolean gimp_config_writer_close_file (GimpConfigWriter *writer, GimpConfigWriter * gimp_config_writer_new_file (const gchar *filename, - gboolean safe, + gboolean atomic, const gchar *header, GError **error) { @@ -76,7 +76,7 @@ gimp_config_writer_new_file (const gchar *filename, g_return_val_if_fail (filename != NULL, NULL); g_return_val_if_fail (error == NULL || *error == NULL, NULL); - if (safe) + if (atomic) { tmpname = g_strconcat (filename, "XXXXXX", NULL); diff --git a/libgimpconfig/gimpconfigwriter.h b/libgimpconfig/gimpconfigwriter.h index a0c6804241..a4c8194624 100644 --- a/libgimpconfig/gimpconfigwriter.h +++ b/libgimpconfig/gimpconfigwriter.h @@ -24,7 +24,7 @@ GimpConfigWriter * gimp_config_writer_new_file (const gchar *filename, - gboolean safe, + gboolean atomic, const gchar *header, GError **error); GimpConfigWriter * gimp_config_writer_new_fd (gint fd);