From 3b5dd3bc325350edf0d079e5fb81d9176b4f12f0 Mon Sep 17 00:00:00 2001 From: Matthew Wilber Date: Fri, 9 Jan 2004 04:40:52 +0000 Subject: [PATCH] Fixed LoadTranslator so that Translators won't be added to the roster if there is already a Translator loaded that has the same filename. Now Translators in /system/add-ons/Translators will not be loaded if there are Translators with the same names in /home/config/add-ons/Translators. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@5997 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/translation/TranslatorRoster.cpp | 35 +++++++++++++---------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/src/kits/translation/TranslatorRoster.cpp b/src/kits/translation/TranslatorRoster.cpp index c2581bc984..fb36e0052b 100644 --- a/src/kits/translation/TranslatorRoster.cpp +++ b/src/kits/translation/TranslatorRoster.cpp @@ -1291,6 +1291,18 @@ BTranslatorRoster::FindTranslatorNode(translator_id id) return pTranNode; } +const char * +get_file_name(const char *path) +{ + const char *file_name = strrchr(path, '/'); + if (file_name) + file_name++; + else + file_name = path; + + return file_name; +} + // --------------------------------------------------------------- // LoadTranslator // @@ -1315,17 +1327,14 @@ BTranslatorRoster::LoadTranslator(const char *path) return B_BAD_VALUE; // check that this ref is not already loaded - const char *name = strrchr(path, '/'); - if (name) - name++; - else - name = path; + const char *file_name = get_file_name(path); + + // If a translator with the same filename has already + // been loaded, do not load the current translator and + // return no error. This code is not fool proof, however. for (translator_node *i = fpTranslators; i; i = i->next) - if (!strcmp(name, i->translator->TranslatorName())) + if (!strcmp(file_name, get_file_name(i->path))) return B_NO_ERROR; - // we use name for determining whether it's loaded - // that is not entirely foolproof, but making SURE will be - // a very slow process that I don't much care for. image_id image = load_add_on(path); // Load the data and code for the Translator into memory @@ -1339,13 +1348,9 @@ BTranslatorRoster::LoadTranslator(const char *path) B_SYMBOL_TYPE_TEXT, reinterpret_cast (&pMakeNthTranslator)); if (!err) { // If the translator add-on supports the post R4.5 - // translator creation mechanism - + // translator creation mechanism, keep loading translators + // until MakeNthTranslator stops returning them. BTranslator *ptran = NULL; - // WARNING: This code assumes that the ref count on the - // BTranslators from MakeNth... begin at 1!!! - // I NEED TO WRITE CODE TO TEST WHAT THE REF COUNT FOR - // THESE BTRANSLATORS START AS!!!! for (int32 n = 0; (ptran = pMakeNthTranslator(n, image, 0)); n++) AddTranslatorToList(ptran, path, image, false);