From 84a9e5ecf876745b6c5bafc56aa168107740a946 Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Sun, 9 Apr 2006 12:33:32 +0000 Subject: [PATCH] return a GSList* of PlugInDefs instead of a boolean. Don't return anything 2006-04-09 Michael Natterer * app/plug-in/plug-in-rc.[ch] (plug_in_rc_parse): return a GSList* of PlugInDefs instead of a boolean. Don't return anything if any parse error occurs (before, we trusted PlugInDefs from partially broken files). Don't call plug_ins_def_add_from_rc() and don't #include "plug-ins.h". * app/plug-in/plug-ins.[ch]: made plug_ins_def_add_from_rc() private and call it on all PlugInDefs returned by plug_in_rc_parse(). Renamed plug_ins_init_file() to plug_ins_add_from_file() (plug_ins_init): remove code that checks for duplicate plug-in procedures... (plug_ins_procedure_insert): ... and add it where it belongs. --- ChangeLog | 17 ++ app/plug-in/gimppluginmanager.c | 279 ++++++++++++++++---------------- app/plug-in/gimppluginmanager.h | 5 - app/plug-in/plug-in-rc.c | 57 ++++--- app/plug-in/plug-in-rc.h | 12 +- app/plug-in/plug-ins.c | 279 ++++++++++++++++---------------- app/plug-in/plug-ins.h | 5 - 7 files changed, 336 insertions(+), 318 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9b313040af..de5eccecad 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +2006-04-09 Michael Natterer + + * app/plug-in/plug-in-rc.[ch] (plug_in_rc_parse): return a GSList* + of PlugInDefs instead of a boolean. Don't return anything if any + parse error occurs (before, we trusted PlugInDefs from partially + broken files). Don't call plug_ins_def_add_from_rc() and don't + #include "plug-ins.h". + + * app/plug-in/plug-ins.[ch]: made plug_ins_def_add_from_rc() + private and call it on all PlugInDefs returned by plug_in_rc_parse(). + Renamed plug_ins_init_file() to plug_ins_add_from_file() + + (plug_ins_init): remove code that checks for duplicate plug-in + procedures... + + (plug_ins_procedure_insert): ... and add it where it belongs. + 2006-04-09 Michael Natterer * app/xcf/xcf.c (xcf_init): don't register the XCF procedures diff --git a/app/plug-in/gimppluginmanager.c b/app/plug-in/gimppluginmanager.c index 5244621a72..a4518df13a 100644 --- a/app/plug-in/gimppluginmanager.c +++ b/app/plug-in/gimppluginmanager.c @@ -73,15 +73,17 @@ struct _PlugInHelpDomain }; -static void plug_ins_init_file (const GimpDatafileData *file_data, - gpointer data); -static void plug_ins_add_to_db (Gimp *gimp, - GimpContext *context); -static GimpPlugInProcedure * plug_ins_procedure_insert (Gimp *gimp, - GimpPlugInProcedure *proc); -static gint plug_ins_file_proc_compare (gconstpointer a, - gconstpointer b, - gpointer data); +static void plug_ins_add_from_file (const GimpDatafileData *file_data, + gpointer data); +static void plug_ins_add_from_rc (Gimp *gimp, + PlugInDef *plug_in_def); +static void plug_ins_add_to_db (Gimp *gimp, + GimpContext *context); +static void plug_ins_procedure_insert (Gimp *gimp, + GimpPlugInProcedure *proc); +static gint plug_ins_file_proc_compare (gconstpointer a, + gconstpointer b, + gpointer data); /* public functions */ @@ -94,6 +96,7 @@ plug_ins_init (Gimp *gimp, gchar *filename; gchar *basename; gchar *path; + GSList *rc_defs; GSList *list; GList *extensions = NULL; gint n_plugins; @@ -108,11 +111,13 @@ plug_ins_init (Gimp *gimp, plug_in_init (gimp); /* search for binaries in the plug-in directory path */ + status_callback (_("Searching Plug-Ins"), "", 0.0); + path = gimp_config_path_expand (gimp->config->plug_in_path, TRUE, NULL); gimp_datafiles_read_directories (path, G_FILE_TEST_IS_EXECUTABLE, - plug_ins_init_file, + plug_ins_add_from_file, &gimp->plug_in_defs); g_free (path); @@ -142,7 +147,16 @@ plug_ins_init (Gimp *gimp, if (gimp->be_verbose) g_print (_("Parsing '%s'\n"), gimp_filename_to_utf8 (filename)); - if (! plug_in_rc_parse (gimp, filename, &error)) + rc_defs = plug_in_rc_parse (gimp, filename, &error); + + if (rc_defs) + { + for (list = rc_defs; list; list = g_slist_next (list)) + plug_ins_add_from_rc (gimp, list->data); /* consumes list->data */ + + g_slist_free (rc_defs); + } + else { if (error->code != GIMP_CONFIG_ERROR_OPEN_ENOENT) g_message (error->message); @@ -229,42 +243,9 @@ plug_ins_init (Gimp *gimp, GSList *list2; for (list2 = plug_in_def->procedures; list2; list2 = list2->next) - { - GimpPlugInProcedure *proc = list2->data; - GimpPlugInProcedure *overridden_proc; - - overridden_proc = plug_ins_procedure_insert (gimp, proc); - - if (overridden_proc) - { - GSList *list3; - - g_printerr ("removing duplicate PDB procedure \"%s\" " - "registered by '%s'\n", - GIMP_OBJECT (overridden_proc)->name, - gimp_filename_to_utf8 (overridden_proc->prog)); - - /* search the plugin list to see if any plugins had references to - * the overridden_proc. - */ - for (list3 = gimp->plug_in_defs; list3; list3 = list3->next) - { - PlugInDef *plug_in_def2 = list3->data; - - if (g_slist_find (plug_in_def2->procedures, overridden_proc)) - plug_in_def_remove_procedure (plug_in_def2, - overridden_proc); - } - - /* also remove it from the lists of load and save procs */ - gimp->load_procs = g_slist_remove (gimp->load_procs, - overridden_proc); - gimp->save_procs = g_slist_remove (gimp->save_procs, - overridden_proc); - - g_object_unref (overridden_proc); - } - } + { + plug_ins_procedure_insert (gimp, list2->data); + } } /* write the pluginrc file if necessary */ @@ -511,91 +492,6 @@ plug_ins_file_register_thumb_loader (Gimp *gimp, return proc; } -void -plug_ins_def_add_from_rc (Gimp *gimp, - PlugInDef *plug_in_def) -{ - GSList *list; - gchar *basename1; - - g_return_if_fail (GIMP_IS_GIMP (gimp)); - g_return_if_fail (plug_in_def != NULL); - g_return_if_fail (plug_in_def->prog != NULL); - - if (! g_path_is_absolute (plug_in_def->prog)) - { - g_warning ("plug_ins_def_add_from_rc: filename not absolute (skipping)"); - plug_in_def_free (plug_in_def); - return; - } - - basename1 = g_path_get_basename (plug_in_def->prog); - - /* If this is a file load or save plugin, make sure we have - * something for one of the extensions, prefixes, or magic number. - * Other bits of code rely on detecting file plugins by the presence - * of one of these things, but Nick Lamb's alien/unknown format - * loader needs to be able to register no extensions, prefixes or - * magics. -- austin 13/Feb/99 - */ - for (list = plug_in_def->procedures; list; list = list->next) - { - GimpPlugInProcedure *proc = list->data; - - if (! proc->extensions && - ! proc->prefixes && - ! proc->magics && - proc->menu_paths && - (! strncmp (proc->menu_paths->data, "", 6) || - ! strncmp (proc->menu_paths->data, "", 6))) - { - proc->extensions = g_strdup (""); - } - } - - /* Check if the entry mentioned in pluginrc matches an executable - * found in the plug_in_path. - */ - for (list = gimp->plug_in_defs; list; list = list->next) - { - PlugInDef *ondisk_plug_in_def = list->data; - gchar *basename2; - - basename2 = g_path_get_basename (ondisk_plug_in_def->prog); - - if (! strcmp (basename1, basename2)) - { - if (! g_ascii_strcasecmp (plug_in_def->prog, - ondisk_plug_in_def->prog) && - (plug_in_def->mtime == ondisk_plug_in_def->mtime)) - { - /* Use pluginrc entry, deleting ondisk entry */ - list->data = plug_in_def; - plug_in_def_free (ondisk_plug_in_def); - } - else - { - /* Use ondisk entry, deleting pluginrc entry */ - plug_in_def_free (plug_in_def); - } - - g_free (basename2); - g_free (basename1); - - return; - } - - g_free (basename2); - } - - g_free (basename1); - - gimp->write_pluginrc = TRUE; - g_printerr ("executable not found: '%s'\n", - gimp_filename_to_utf8 (plug_in_def->prog)); - plug_in_def_free (plug_in_def); -} - void plug_ins_temp_procedure_add (Gimp *gimp, GimpTemporaryProcedure *proc) @@ -830,8 +726,8 @@ plug_ins_help_domains (Gimp *gimp, /* private functions */ static void -plug_ins_init_file (const GimpDatafileData *file_data, - gpointer data) +plug_ins_add_from_file (const GimpDatafileData *file_data, + gpointer data) { PlugInDef *plug_in_def; GSList **plug_in_defs = data; @@ -865,6 +761,91 @@ plug_ins_init_file (const GimpDatafileData *file_data, *plug_in_defs = g_slist_prepend (*plug_in_defs, plug_in_def); } +static void +plug_ins_add_from_rc (Gimp *gimp, + PlugInDef *plug_in_def) +{ + GSList *list; + gchar *basename1; + + g_return_if_fail (GIMP_IS_GIMP (gimp)); + g_return_if_fail (plug_in_def != NULL); + g_return_if_fail (plug_in_def->prog != NULL); + + if (! g_path_is_absolute (plug_in_def->prog)) + { + g_warning ("plug_ins_def_add_from_rc: filename not absolute (skipping)"); + plug_in_def_free (plug_in_def); + return; + } + + basename1 = g_path_get_basename (plug_in_def->prog); + + /* If this is a file load or save plugin, make sure we have + * something for one of the extensions, prefixes, or magic number. + * Other bits of code rely on detecting file plugins by the presence + * of one of these things, but Nick Lamb's alien/unknown format + * loader needs to be able to register no extensions, prefixes or + * magics. -- austin 13/Feb/99 + */ + for (list = plug_in_def->procedures; list; list = list->next) + { + GimpPlugInProcedure *proc = list->data; + + if (! proc->extensions && + ! proc->prefixes && + ! proc->magics && + proc->menu_paths && + (! strncmp (proc->menu_paths->data, "", 6) || + ! strncmp (proc->menu_paths->data, "", 6))) + { + proc->extensions = g_strdup (""); + } + } + + /* Check if the entry mentioned in pluginrc matches an executable + * found in the plug_in_path. + */ + for (list = gimp->plug_in_defs; list; list = list->next) + { + PlugInDef *ondisk_plug_in_def = list->data; + gchar *basename2; + + basename2 = g_path_get_basename (ondisk_plug_in_def->prog); + + if (! strcmp (basename1, basename2)) + { + if (! g_ascii_strcasecmp (plug_in_def->prog, + ondisk_plug_in_def->prog) && + (plug_in_def->mtime == ondisk_plug_in_def->mtime)) + { + /* Use pluginrc entry, deleting ondisk entry */ + list->data = plug_in_def; + plug_in_def_free (ondisk_plug_in_def); + } + else + { + /* Use ondisk entry, deleting pluginrc entry */ + plug_in_def_free (plug_in_def); + } + + g_free (basename2); + g_free (basename1); + + return; + } + + g_free (basename2); + } + + g_free (basename1); + + gimp->write_pluginrc = TRUE; + g_printerr ("executable not found: '%s'\n", + gimp_filename_to_utf8 (plug_in_def->prog)); + plug_in_def_free (plug_in_def); +} + static void plug_ins_add_to_db (Gimp *gimp, GimpContext *context) @@ -908,7 +889,7 @@ plug_ins_add_to_db (Gimp *gimp, } } -static GimpPlugInProcedure * +static void plug_ins_procedure_insert (Gimp *gimp, GimpPlugInProcedure *proc) { @@ -921,16 +902,38 @@ plug_ins_procedure_insert (Gimp *gimp, if (strcmp (GIMP_OBJECT (proc)->name, GIMP_OBJECT (tmp_proc)->name) == 0) { + GSList *list3; + list->data = g_object_ref (proc); - return tmp_proc; + g_printerr ("removing duplicate PDB procedure \"%s\" " + "registered by '%s'\n", + GIMP_OBJECT (tmp_proc)->name, + gimp_filename_to_utf8 (tmp_proc->prog)); + + /* search the plugin list to see if any plugins had references to + * the tmp_proc. + */ + for (list3 = gimp->plug_in_defs; list3; list3 = list3->next) + { + PlugInDef *plug_in_def2 = list3->data; + + if (g_slist_find (plug_in_def2->procedures, tmp_proc)) + plug_in_def_remove_procedure (plug_in_def2, tmp_proc); + } + + /* also remove it from the lists of load and save procs */ + gimp->load_procs = g_slist_remove (gimp->load_procs, tmp_proc); + gimp->save_procs = g_slist_remove (gimp->save_procs, tmp_proc); + + g_object_unref (tmp_proc); + + return; } } gimp->plug_in_procedures = g_slist_prepend (gimp->plug_in_procedures, g_object_ref (proc)); - - return NULL; } static gint diff --git a/app/plug-in/gimppluginmanager.h b/app/plug-in/gimppluginmanager.h index e57ffea22a..1a1c22e68b 100644 --- a/app/plug-in/gimppluginmanager.h +++ b/app/plug-in/gimppluginmanager.h @@ -58,11 +58,6 @@ GimpPlugInProcedure * plug_ins_file_register_thumb_loader const gchar *load_proc, const gchar *thumb_proc); - -/* Add a plug-in definition. */ -void plug_ins_def_add_from_rc (Gimp *gimp, - PlugInDef *plug_in_def); - /* Add/Remove temporary procedures. */ void plug_ins_temp_procedure_add (Gimp *gimp, GimpTemporaryProcedure *proc); diff --git a/app/plug-in/plug-in-rc.c b/app/plug-in/plug-in-rc.c index 57adfea6be..767fe64404 100644 --- a/app/plug-in/plug-in-rc.c +++ b/app/plug-in/plug-in-rc.c @@ -34,7 +34,6 @@ #include "pdb/gimp-pdb-compat.h" #include "pdb/gimppluginprocedure.h" -#include "plug-ins.h" #include "plug-in-def.h" #include "plug-in-rc.h" @@ -47,7 +46,8 @@ */ static GTokenType plug_in_def_deserialize (Gimp *gimp, - GScanner *scanner); + GScanner *scanner, + GSList **plug_in_defs); static GTokenType plug_in_procedure_deserialize (GScanner *scanner, Gimp *gimp, const gchar *prog, @@ -91,16 +91,16 @@ enum }; -gboolean +GSList * plug_in_rc_parse (Gimp *gimp, const gchar *filename, GError **error) { GScanner *scanner; GEnumClass *enum_class; + GSList *plug_in_defs = NULL; + gint version = GIMP_PROTOCOL_VERSION; GTokenType token; - gboolean retval = FALSE; - gint version = GIMP_PROTOCOL_VERSION; g_return_val_if_fail (GIMP_IS_GIMP (gimp), FALSE); g_return_val_if_fail (filename != NULL, FALSE); @@ -109,7 +109,7 @@ plug_in_rc_parse (Gimp *gimp, scanner = gimp_scanner_new_file (filename, error); if (! scanner) - return FALSE; + return NULL; enum_class = g_type_class_ref (GIMP_TYPE_ICON_TYPE); @@ -179,7 +179,7 @@ plug_in_rc_parse (Gimp *gimp, break; case PLUG_IN_DEF: g_scanner_set_scope (scanner, PLUG_IN_DEF); - token = plug_in_def_deserialize (gimp, scanner); + token = plug_in_def_deserialize (gimp, scanner, &plug_in_defs); g_scanner_set_scope (scanner, 0); break; default: @@ -196,34 +196,39 @@ plug_in_rc_parse (Gimp *gimp, } } - if (version != GIMP_PROTOCOL_VERSION) + if (version != GIMP_PROTOCOL_VERSION || + token != G_TOKEN_LEFT_PAREN) { - g_set_error (error, - GIMP_CONFIG_ERROR, GIMP_CONFIG_ERROR_VERSION, - _("Skipping '%s': wrong GIMP protocol version."), - gimp_filename_to_utf8 (filename)); - } - else 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); - } - else - { - retval = TRUE; + if (version != GIMP_PROTOCOL_VERSION) + { + g_set_error (error, + GIMP_CONFIG_ERROR, GIMP_CONFIG_ERROR_VERSION, + _("Skipping '%s': wrong GIMP protocol version."), + gimp_filename_to_utf8 (filename)); + } + else + { + g_scanner_get_next_token (scanner); + g_scanner_unexp_token (scanner, token, NULL, NULL, NULL, + _("fatal parse error"), TRUE); + } + + g_slist_foreach (plug_in_defs, (GFunc) plug_in_def_free, NULL); + g_slist_free (plug_in_defs); + plug_in_defs = NULL; } g_type_class_unref (enum_class); gimp_scanner_destroy (scanner); - return retval; + return g_slist_reverse (plug_in_defs); } static GTokenType -plug_in_def_deserialize (Gimp *gimp, - GScanner *scanner) +plug_in_def_deserialize (Gimp *gimp, + GScanner *scanner, + GSList **plug_in_defs) { PlugInDef *plug_in_def; GimpPlugInProcedure *proc = NULL; @@ -301,7 +306,7 @@ plug_in_def_deserialize (Gimp *gimp, if (gimp_scanner_parse_token (scanner, token)) { - plug_ins_def_add_from_rc (gimp, plug_in_def); + *plug_in_defs = g_slist_prepend (*plug_in_defs, plug_in_def); return G_TOKEN_LEFT_PAREN; } } diff --git a/app/plug-in/plug-in-rc.h b/app/plug-in/plug-in-rc.h index a195efce36..de0738a72a 100644 --- a/app/plug-in/plug-in-rc.h +++ b/app/plug-in/plug-in-rc.h @@ -23,12 +23,12 @@ #define __PLUG_IN_RC_H__ -gboolean plug_in_rc_parse (Gimp *gimp, - const gchar *filename, - GError **error); -gboolean plug_in_rc_write (GSList *plug_in_defs, - const gchar *filename, - GError **error); +GSList * plug_in_rc_parse (Gimp *gimp, + const gchar *filename, + GError **error); +gboolean plug_in_rc_write (GSList *plug_in_defs, + const gchar *filename, + GError **error); #endif /* __PLUG_IN_RC_H__ */ diff --git a/app/plug-in/plug-ins.c b/app/plug-in/plug-ins.c index 5244621a72..a4518df13a 100644 --- a/app/plug-in/plug-ins.c +++ b/app/plug-in/plug-ins.c @@ -73,15 +73,17 @@ struct _PlugInHelpDomain }; -static void plug_ins_init_file (const GimpDatafileData *file_data, - gpointer data); -static void plug_ins_add_to_db (Gimp *gimp, - GimpContext *context); -static GimpPlugInProcedure * plug_ins_procedure_insert (Gimp *gimp, - GimpPlugInProcedure *proc); -static gint plug_ins_file_proc_compare (gconstpointer a, - gconstpointer b, - gpointer data); +static void plug_ins_add_from_file (const GimpDatafileData *file_data, + gpointer data); +static void plug_ins_add_from_rc (Gimp *gimp, + PlugInDef *plug_in_def); +static void plug_ins_add_to_db (Gimp *gimp, + GimpContext *context); +static void plug_ins_procedure_insert (Gimp *gimp, + GimpPlugInProcedure *proc); +static gint plug_ins_file_proc_compare (gconstpointer a, + gconstpointer b, + gpointer data); /* public functions */ @@ -94,6 +96,7 @@ plug_ins_init (Gimp *gimp, gchar *filename; gchar *basename; gchar *path; + GSList *rc_defs; GSList *list; GList *extensions = NULL; gint n_plugins; @@ -108,11 +111,13 @@ plug_ins_init (Gimp *gimp, plug_in_init (gimp); /* search for binaries in the plug-in directory path */ + status_callback (_("Searching Plug-Ins"), "", 0.0); + path = gimp_config_path_expand (gimp->config->plug_in_path, TRUE, NULL); gimp_datafiles_read_directories (path, G_FILE_TEST_IS_EXECUTABLE, - plug_ins_init_file, + plug_ins_add_from_file, &gimp->plug_in_defs); g_free (path); @@ -142,7 +147,16 @@ plug_ins_init (Gimp *gimp, if (gimp->be_verbose) g_print (_("Parsing '%s'\n"), gimp_filename_to_utf8 (filename)); - if (! plug_in_rc_parse (gimp, filename, &error)) + rc_defs = plug_in_rc_parse (gimp, filename, &error); + + if (rc_defs) + { + for (list = rc_defs; list; list = g_slist_next (list)) + plug_ins_add_from_rc (gimp, list->data); /* consumes list->data */ + + g_slist_free (rc_defs); + } + else { if (error->code != GIMP_CONFIG_ERROR_OPEN_ENOENT) g_message (error->message); @@ -229,42 +243,9 @@ plug_ins_init (Gimp *gimp, GSList *list2; for (list2 = plug_in_def->procedures; list2; list2 = list2->next) - { - GimpPlugInProcedure *proc = list2->data; - GimpPlugInProcedure *overridden_proc; - - overridden_proc = plug_ins_procedure_insert (gimp, proc); - - if (overridden_proc) - { - GSList *list3; - - g_printerr ("removing duplicate PDB procedure \"%s\" " - "registered by '%s'\n", - GIMP_OBJECT (overridden_proc)->name, - gimp_filename_to_utf8 (overridden_proc->prog)); - - /* search the plugin list to see if any plugins had references to - * the overridden_proc. - */ - for (list3 = gimp->plug_in_defs; list3; list3 = list3->next) - { - PlugInDef *plug_in_def2 = list3->data; - - if (g_slist_find (plug_in_def2->procedures, overridden_proc)) - plug_in_def_remove_procedure (plug_in_def2, - overridden_proc); - } - - /* also remove it from the lists of load and save procs */ - gimp->load_procs = g_slist_remove (gimp->load_procs, - overridden_proc); - gimp->save_procs = g_slist_remove (gimp->save_procs, - overridden_proc); - - g_object_unref (overridden_proc); - } - } + { + plug_ins_procedure_insert (gimp, list2->data); + } } /* write the pluginrc file if necessary */ @@ -511,91 +492,6 @@ plug_ins_file_register_thumb_loader (Gimp *gimp, return proc; } -void -plug_ins_def_add_from_rc (Gimp *gimp, - PlugInDef *plug_in_def) -{ - GSList *list; - gchar *basename1; - - g_return_if_fail (GIMP_IS_GIMP (gimp)); - g_return_if_fail (plug_in_def != NULL); - g_return_if_fail (plug_in_def->prog != NULL); - - if (! g_path_is_absolute (plug_in_def->prog)) - { - g_warning ("plug_ins_def_add_from_rc: filename not absolute (skipping)"); - plug_in_def_free (plug_in_def); - return; - } - - basename1 = g_path_get_basename (plug_in_def->prog); - - /* If this is a file load or save plugin, make sure we have - * something for one of the extensions, prefixes, or magic number. - * Other bits of code rely on detecting file plugins by the presence - * of one of these things, but Nick Lamb's alien/unknown format - * loader needs to be able to register no extensions, prefixes or - * magics. -- austin 13/Feb/99 - */ - for (list = plug_in_def->procedures; list; list = list->next) - { - GimpPlugInProcedure *proc = list->data; - - if (! proc->extensions && - ! proc->prefixes && - ! proc->magics && - proc->menu_paths && - (! strncmp (proc->menu_paths->data, "", 6) || - ! strncmp (proc->menu_paths->data, "", 6))) - { - proc->extensions = g_strdup (""); - } - } - - /* Check if the entry mentioned in pluginrc matches an executable - * found in the plug_in_path. - */ - for (list = gimp->plug_in_defs; list; list = list->next) - { - PlugInDef *ondisk_plug_in_def = list->data; - gchar *basename2; - - basename2 = g_path_get_basename (ondisk_plug_in_def->prog); - - if (! strcmp (basename1, basename2)) - { - if (! g_ascii_strcasecmp (plug_in_def->prog, - ondisk_plug_in_def->prog) && - (plug_in_def->mtime == ondisk_plug_in_def->mtime)) - { - /* Use pluginrc entry, deleting ondisk entry */ - list->data = plug_in_def; - plug_in_def_free (ondisk_plug_in_def); - } - else - { - /* Use ondisk entry, deleting pluginrc entry */ - plug_in_def_free (plug_in_def); - } - - g_free (basename2); - g_free (basename1); - - return; - } - - g_free (basename2); - } - - g_free (basename1); - - gimp->write_pluginrc = TRUE; - g_printerr ("executable not found: '%s'\n", - gimp_filename_to_utf8 (plug_in_def->prog)); - plug_in_def_free (plug_in_def); -} - void plug_ins_temp_procedure_add (Gimp *gimp, GimpTemporaryProcedure *proc) @@ -830,8 +726,8 @@ plug_ins_help_domains (Gimp *gimp, /* private functions */ static void -plug_ins_init_file (const GimpDatafileData *file_data, - gpointer data) +plug_ins_add_from_file (const GimpDatafileData *file_data, + gpointer data) { PlugInDef *plug_in_def; GSList **plug_in_defs = data; @@ -865,6 +761,91 @@ plug_ins_init_file (const GimpDatafileData *file_data, *plug_in_defs = g_slist_prepend (*plug_in_defs, plug_in_def); } +static void +plug_ins_add_from_rc (Gimp *gimp, + PlugInDef *plug_in_def) +{ + GSList *list; + gchar *basename1; + + g_return_if_fail (GIMP_IS_GIMP (gimp)); + g_return_if_fail (plug_in_def != NULL); + g_return_if_fail (plug_in_def->prog != NULL); + + if (! g_path_is_absolute (plug_in_def->prog)) + { + g_warning ("plug_ins_def_add_from_rc: filename not absolute (skipping)"); + plug_in_def_free (plug_in_def); + return; + } + + basename1 = g_path_get_basename (plug_in_def->prog); + + /* If this is a file load or save plugin, make sure we have + * something for one of the extensions, prefixes, or magic number. + * Other bits of code rely on detecting file plugins by the presence + * of one of these things, but Nick Lamb's alien/unknown format + * loader needs to be able to register no extensions, prefixes or + * magics. -- austin 13/Feb/99 + */ + for (list = plug_in_def->procedures; list; list = list->next) + { + GimpPlugInProcedure *proc = list->data; + + if (! proc->extensions && + ! proc->prefixes && + ! proc->magics && + proc->menu_paths && + (! strncmp (proc->menu_paths->data, "", 6) || + ! strncmp (proc->menu_paths->data, "", 6))) + { + proc->extensions = g_strdup (""); + } + } + + /* Check if the entry mentioned in pluginrc matches an executable + * found in the plug_in_path. + */ + for (list = gimp->plug_in_defs; list; list = list->next) + { + PlugInDef *ondisk_plug_in_def = list->data; + gchar *basename2; + + basename2 = g_path_get_basename (ondisk_plug_in_def->prog); + + if (! strcmp (basename1, basename2)) + { + if (! g_ascii_strcasecmp (plug_in_def->prog, + ondisk_plug_in_def->prog) && + (plug_in_def->mtime == ondisk_plug_in_def->mtime)) + { + /* Use pluginrc entry, deleting ondisk entry */ + list->data = plug_in_def; + plug_in_def_free (ondisk_plug_in_def); + } + else + { + /* Use ondisk entry, deleting pluginrc entry */ + plug_in_def_free (plug_in_def); + } + + g_free (basename2); + g_free (basename1); + + return; + } + + g_free (basename2); + } + + g_free (basename1); + + gimp->write_pluginrc = TRUE; + g_printerr ("executable not found: '%s'\n", + gimp_filename_to_utf8 (plug_in_def->prog)); + plug_in_def_free (plug_in_def); +} + static void plug_ins_add_to_db (Gimp *gimp, GimpContext *context) @@ -908,7 +889,7 @@ plug_ins_add_to_db (Gimp *gimp, } } -static GimpPlugInProcedure * +static void plug_ins_procedure_insert (Gimp *gimp, GimpPlugInProcedure *proc) { @@ -921,16 +902,38 @@ plug_ins_procedure_insert (Gimp *gimp, if (strcmp (GIMP_OBJECT (proc)->name, GIMP_OBJECT (tmp_proc)->name) == 0) { + GSList *list3; + list->data = g_object_ref (proc); - return tmp_proc; + g_printerr ("removing duplicate PDB procedure \"%s\" " + "registered by '%s'\n", + GIMP_OBJECT (tmp_proc)->name, + gimp_filename_to_utf8 (tmp_proc->prog)); + + /* search the plugin list to see if any plugins had references to + * the tmp_proc. + */ + for (list3 = gimp->plug_in_defs; list3; list3 = list3->next) + { + PlugInDef *plug_in_def2 = list3->data; + + if (g_slist_find (plug_in_def2->procedures, tmp_proc)) + plug_in_def_remove_procedure (plug_in_def2, tmp_proc); + } + + /* also remove it from the lists of load and save procs */ + gimp->load_procs = g_slist_remove (gimp->load_procs, tmp_proc); + gimp->save_procs = g_slist_remove (gimp->save_procs, tmp_proc); + + g_object_unref (tmp_proc); + + return; } } gimp->plug_in_procedures = g_slist_prepend (gimp->plug_in_procedures, g_object_ref (proc)); - - return NULL; } static gint diff --git a/app/plug-in/plug-ins.h b/app/plug-in/plug-ins.h index e57ffea22a..1a1c22e68b 100644 --- a/app/plug-in/plug-ins.h +++ b/app/plug-in/plug-ins.h @@ -58,11 +58,6 @@ GimpPlugInProcedure * plug_ins_file_register_thumb_loader const gchar *load_proc, const gchar *thumb_proc); - -/* Add a plug-in definition. */ -void plug_ins_def_add_from_rc (Gimp *gimp, - PlugInDef *plug_in_def); - /* Add/Remove temporary procedures. */ void plug_ins_temp_procedure_add (Gimp *gimp, GimpTemporaryProcedure *proc);