From fe8d7c0225bd8e782b0a9b281d895bde6bbcc15e Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Tue, 20 Jul 2010 11:38:34 +0000 Subject: [PATCH] * Remove the CatalogStub class and put the Gatcatalog function directly in BLocaleRoster, * Adjust the B_TRANSLATE macros to take this into account * Adjust collectkatkeys to take it into account too Thanks to Ingo for explaining me all the technical details about hiding things in shared objects. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37616 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/os/locale/Catalog.h | 27 +++++---------------------- headers/os/locale/LocaleRoster.h | 4 ++++ src/bin/locale/collectcatkeys.cpp | 19 ++++++++++++------- src/kits/locale/CatalogStub.cpp | 28 +++++++--------------------- src/tools/locale/collectcatkeys.cpp | 19 ++++++++++++------- 5 files changed, 40 insertions(+), 57 deletions(-) diff --git a/headers/os/locale/Catalog.h b/headers/os/locale/Catalog.h index a68e471e85..e54af57774 100644 --- a/headers/os/locale/Catalog.h +++ b/headers/os/locale/Catalog.h @@ -5,6 +5,7 @@ #ifndef _CATALOG_H_ #define _CATALOG_H_ +#include #include #include @@ -53,24 +54,6 @@ class BCatalog { }; -// Proxy class for handling a "shared object local" catalog. -// This must be included (statically linked) into each shared object needing -// a catalog on its own (application, add-on, library, ...). The shared object -// must also have a mimetype so that the catalog can be identified. -class BCatalogStub -{ - private: - static BCatalog sCatalog; - static vint32 sCatalogInitOnce; - - public: - static BCatalog* GetCatalog(); - static void ForceReload(); - // Use this to force re-initialisation of the catalog (when there - // is a locale change for example) -}; - - #ifndef B_AVOID_TRANSLATION_MACROS // macros for easy catalog-access, define B_AVOID_TRANSLATION_MACROS if // you don't want these: @@ -97,19 +80,19 @@ class BCatalogStub // Translation macros which may be used to shorten translation requests: #undef B_TRANSLATE #define B_TRANSLATE(str) \ - BCatalogStub::GetCatalog()->GetString((str), B_TRANSLATE_CONTEXT) + be_locale_roster->GetCatalog()->GetString((str), B_TRANSLATE_CONTEXT) #undef B_TRANSLATE_COMMENT #define B_TRANSLATE_COMMENT(str, cmt) \ - BCatalogStub::GetCatalog()->GetString((str), B_TRANSLATE_CONTEXT, (cmt)) + be_locale_roster->GetCatalog()->GetString((str), B_TRANSLATE_CONTEXT, (cmt)) #undef B_TRANSLATE_ALL #define B_TRANSLATE_ALL(str, ctx, cmt) \ - BCatalogStub::GetCatalog()->GetString((str), (ctx), (cmt)) + be_locale_roster->GetCatalog()->GetString((str), (ctx), (cmt)) #undef B_TRANSLATE_ID #define B_TRANSLATE_ID(id) \ - BCatalogStub::GetCatalog()->GetString((id)) + be_locale_roster->GetCatalog()->GetString((id)) // Translation markers which can be used to mark static strings/IDs which // are used as key for translation requests (at other places in the code): diff --git a/headers/os/locale/LocaleRoster.h b/headers/os/locale/LocaleRoster.h index 33db25e4be..8f71ada3fb 100644 --- a/headers/os/locale/LocaleRoster.h +++ b/headers/os/locale/LocaleRoster.h @@ -57,6 +57,10 @@ class BLocaleRoster { const char* langPattern = NULL, int32 fingerprint = 0) const; // the message contains... + BCatalog* GetCatalog(); + // Get the catalog for the calling image (that needs to link with + // liblocalestub.a) + static const char *kCatLangAttr; static const char *kCatSigAttr; static const char *kCatFingerprintAttr; diff --git a/src/bin/locale/collectcatkeys.cpp b/src/bin/locale/collectcatkeys.cpp index 08c08facb9..145b72d715 100644 --- a/src/bin/locale/collectcatkeys.cpp +++ b/src/bin/locale/collectcatkeys.cpp @@ -29,7 +29,7 @@ const char *inputFile = NULL; BString outputFile; const char *catalogSig = NULL; const char *catalogLang = "English"; -BString rxString("(BCatalogStub::GetCatalog\\(\\)\\s*->\\s*GetString\\s*" +BString rxString("(be_locale_roster->GetCatalog\\(\\)\\s*->\\s*GetString\\s*" "|BCatalogAddOn\\s*::\\s*MarkForTranslation\\s*)"); @@ -45,17 +45,22 @@ void usage() { fprintf(stderr, - "usage: collectcatkeys [-pvw] [-r ] [-o ] [-l ]\n" + "usage: collectcatkeys [-pvw] [-r ] [-o ] " + "[-l ]\n" " -s \n" "options:\n" - " -l \tlanguage of the target-catalog (default is English)\n" + " -l \tlanguage of the target-catalog (default is " + "English)\n" " -o \t\texplicitly specifies the name of the output-file\n" " -p\t\t\tprint keys as they are found\n" - " -r \t\tchanges the regex used by the key-scanner to the one given,\n" - " \t\t\tthe default is: BCatalogStub::GetCatalog\\(\\)\\s*->\\s*GetString\\s*\n" - " -s \tsignature of the target-catalog\n" + " -r \t\tchanges the regex used by the key-scanner to the one " + "given,\n" + " \t\t\tthe default is: "); + fprintf(stderr, rxString.String()); + fprintf(stderr,"\n -s \tsignature of the target-catalog\n" " -v\t\t\tbe verbose, show summary\n" - " -w\t\t\tshow warnings about catalog-accesses that couldn't be resolved completely\n"); + " -w\t\t\tshow warnings about catalog-accesses that couldn't be " + " resolved completely\n"); exit(-1); } diff --git a/src/kits/locale/CatalogStub.cpp b/src/kits/locale/CatalogStub.cpp index e503d09141..f28d53af05 100644 --- a/src/kits/locale/CatalogStub.cpp +++ b/src/kits/locale/CatalogStub.cpp @@ -4,37 +4,23 @@ */ -#ifndef __CATALOG_STUB_H__ -#define __CATALOG_STUB_H__ - - #include -#include #include -BCatalog BCatalogStub::sCatalog; -vint32 BCatalogStub::sCatalogInitOnce = false; +static BCatalog sCatalog; +static vint32 sCatalogInitOnce = false; -/* static */ BCatalog* -BCatalogStub::GetCatalog() +BCatalog* +BLocaleRoster::GetCatalog() { #if (__GNUC__ < 3) - asm volatile(".hidden GetCatalog__12BCatalogStub"); + asm volatile(".hidden GetCatalog__13BLocaleRoster"); #else - asm volatile(".hidden _ZN12BCatalogStub10GetCatalogEv"); + asm volatile(".hidden _ZN13BLocaleRoster10GetCatalogEv"); #endif - return be_locale_roster->GetCatalog(&sCatalog, &sCatalogInitOnce); + return GetCatalog(&sCatalog, &sCatalogInitOnce); } - -/* static */ void -BCatalogStub::ForceReload() -{ - sCatalogInitOnce = false; -} - - -#endif diff --git a/src/tools/locale/collectcatkeys.cpp b/src/tools/locale/collectcatkeys.cpp index 88f61626fd..80e88d3733 100644 --- a/src/tools/locale/collectcatkeys.cpp +++ b/src/tools/locale/collectcatkeys.cpp @@ -28,7 +28,7 @@ const char *inputFile = NULL; BString outputFile; const char *catalogSig = NULL; const char *catalogLang = "English"; -BString rxString("(BCatalogStub::GetCatalog\\(\\)\\s*->\\s*GetString\\s*" +BString rxString("(be_locale_roster->GetCatalog\\(\\)\\s*->\\s*GetString\\s*" "|BCatalogAddOn\\s*::\\s*MarkForTranslation\\s*)"); @@ -44,17 +44,22 @@ void usage() { fprintf(stderr, - "usage: collectcatkeys [-pvw] [-r ] [-o ] [-l ]\n" + "usage: collectcatkeys [-pvw] [-r ] [-o ] " + "[-l ]\n" " -s \n" "options:\n" - " -l \tlanguage of the target-catalog (default is English)\n" + " -l \tlanguage of the target-catalog (default is " + "English)\n" " -o \t\texplicitly specifies the name of the output-file\n" " -p\t\t\tprint keys as they are found\n" - " -r \t\tchanges the regex used by the key-scanner to the one given,\n" - " \t\t\tthe default is: be_catalog\\s*->\\s*GetString\\s*\n" - " -s \tsignature of the target-catalog\n" + " -r \t\tchanges the regex used by the key-scanner to the one " + "given,\n" + " \t\t\tthe default is: "); + fprintf(stderr, rxString.String()); + fprintf(stderr,"\n -s \tsignature of the target-catalog\n" " -v\t\t\tbe verbose, show summary\n" - " -w\t\t\tshow warnings about catalog-accesses that couldn't be resolved completely\n"); + " -w\t\t\tshow warnings about catalog-accesses that couldn't be " + " resolved completely\n"); exit(-1); }