diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2011-09-21 16:34:46 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2011-09-21 18:16:43 +0200 |
commit | 9ffee68dc027662fd8e6aa044d7ee01b0ed5df16 (patch) | |
tree | 25f265198a400f9ac4a17c6ccc73e30ddf4187b8 /sal/textenc | |
parent | Simplify code by letting get_app_path always include a final slash. (diff) | |
download | core-9ffee68dc027662fd8e6aa044d7ee01b0ed5df16.tar.gz core-9ffee68dc027662fd8e6aa044d7ee01b0ed5df16.zip |
Cleaned up sal_textenc, making it work on Mac OS X.
Diffstat (limited to 'sal/textenc')
-rw-r--r-- | sal/textenc/makefile.mk | 6 | ||||
-rw-r--r-- | sal/textenc/tables.cxx | 12 | ||||
-rw-r--r-- | sal/textenc/textenc.cxx | 99 |
3 files changed, 74 insertions, 43 deletions
diff --git a/sal/textenc/makefile.mk b/sal/textenc/makefile.mk index 7970ae0526eb..09bf20841e71 100644 --- a/sal/textenc/makefile.mk +++ b/sal/textenc/makefile.mk @@ -105,12 +105,6 @@ LIB1TARGET= $(SLB)$/$(TARGET).lib LIB1OBJFILES= $(SAL_OBJECTS) $(SAL_COMMON_OBJECTS) OBJTARGET=$(LB)$/$(TARGET).lib -# be nicer to avoid DLLPRE -.IF "$(GUI)" == "WNT" -CDEFS+=-DPLUGIN_NAME=$(DLLPRE)sal_textenc$(UDK_MAJOR)$(DLLPOST) -.ELSE -CDEFS+=-DPLUGIN_NAME=$(DLLPRE)sal_textenc$(DLLPOST).$(UDK_MAJOR) -.ENDIF LIB2TARGET= $(SLB)$/textenc_tables.lib LIB2OBJFILES= $(SAL_TABLES_OBJECTS) $(SAL_COMMON_OBJECTS) diff --git a/sal/textenc/tables.cxx b/sal/textenc/tables.cxx index 8197f6810c49..3f96dcb3e7b5 100644 --- a/sal/textenc/tables.cxx +++ b/sal/textenc/tables.cxx @@ -26,13 +26,9 @@ * ************************************************************************/ -#ifdef IOS -#define Impl_getTextEncodingData tables_Impl_getTextEncodingData -#endif +#include "sal/config.h" -#ifndef INCLUDED_RTL_TEXTENC_GETTEXTENCODINGDATA_H -#include "gettextencodingdata.h" -#endif +#include "sal/types.h" #ifndef INCLUDED_RTL_TEXTENC_TENCHELP_H #include "tenchelp.h" @@ -129,8 +125,8 @@ static sal_uInt16 const aImplDoubleByteIdentifierTab[1] = { 0 }; #include "convertiso2022kr.tab" #include "convertadobe.tab" -ImplTextEncodingData const * -Impl_getTextEncodingData(rtl_TextEncoding nEncoding) +extern "C" ImplTextEncodingData const * sal_getFullTextEncodingData( + rtl_TextEncoding nEncoding) { static ImplTextEncodingData const * const aData[] = { NULL, /* DONTKNOW */ diff --git a/sal/textenc/textenc.cxx b/sal/textenc/textenc.cxx index 0b245a078e82..c638cfd3c722 100644 --- a/sal/textenc/textenc.cxx +++ b/sal/textenc/textenc.cxx @@ -28,6 +28,9 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_sal.hxx" +#include "sal/config.h" + +#include <cstdlib> /* TODO! This file should not be called textenc.c, because it is not the implementation of rtl/textenc.h. Rather, it should be called @@ -36,8 +39,13 @@ #include "tenchelp.h" #include "rtl/textenc.h" #include <sal/macros.h> +#include "boost/noncopyable.hpp" +#include "osl/diagnose.h" +#include "osl/module.hxx" +#include "rtl/instance.hxx" +#include "rtl/ustring.h" #include "rtl/ustring.hxx" -#include "osl/module.h" +#include "sal/types.h" #ifndef INCLUDED_STDDEF_H #include <stddef.h> @@ -94,21 +102,71 @@ static sal_uInt16 const aImplDoubleByteIdentifierTab[1] = { 0 }; #include "tcvtlat1.tab" #include "tcvtuni1.tab" -extern "C" { - typedef ImplTextEncodingData const *(*TextEncodingFunction) (rtl_TextEncoding nEncoding); +namespace { + +#if defined IOS + +extern "C" ImplTextEncodingData const * sal_getFullTextEncodingData( + rtl_TextEncoding); // from tables.cxx in sal_textenc library + +class FullTextEnocdingData: private boost::noncopyable { +public: + ImplTextEncodingData const * get(rtl_TextEncoding encoding) { + return sal_getFullTextEncodingData(encoding); + } }; -// Yes - we should use the unpleasant to use templatized -// sal:: doublecheckfoo thing here. -#ifndef IOS -static TextEncodingFunction pTables; #else -extern "C" ImplTextEncodingData *tables_Impl_getTextEncodingData(rtl_TextEncoding); -#define pTables tables_Impl_getTextEncodingData + +extern "C" { + +typedef ImplTextEncodingData const * TextEncodingFunction(rtl_TextEncoding); + +void SAL_CALL thisModule() {} + +}; + +class FullTextEncodingData: private boost::noncopyable { +public: + FullTextEncodingData() { + if (!module_.loadRelative( + &thisModule, + rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM( + SAL_MODULENAME("sal_textenc"))))) + { + OSL_TRACE("Loading sal_textenc library failed"); + std::abort(); + } + function_ = reinterpret_cast< TextEncodingFunction * >( + module_.getFunctionSymbol( + rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM( + "sal_getFullTextEncodingData")))); + if (function_ == 0) { + OSL_TRACE( + "Obtaining sal_getFullTextEncodingData fuction from sal_textenc" + " library failed"); + std::abort(); + } + } + + ImplTextEncodingData const * get(rtl_TextEncoding encoding) { + return (*function_)(encoding); + } + +private: + osl::Module module_; + TextEncodingFunction * function_; +}; + #endif -#define DOSTRING( x ) #x -#define STRING( x ) DOSTRING( x ) +struct FullTextEncodingDataSingleton: + public rtl::Static< FullTextEncodingData, FullTextEncodingDataSingleton > +{}; + +} ImplTextEncodingData const * Impl_getTextEncodingData(rtl_TextEncoding nEncoding) SAL_THROW_EXTERN_C() @@ -142,24 +200,7 @@ Impl_getTextEncodingData(rtl_TextEncoding nEncoding) SAL_THROW_EXTERN_C() // ---------------------------------------------- #endif default: -#ifndef IOS - if (!pTables) - { - static char const pName[] = STRING(PLUGIN_NAME); - oslModule aModule = osl_loadModuleAscii(pName, SAL_LOADMODULE_DEFAULT); - - if(aModule) - { - static char const pSymbol[] = "Impl_getTextEncodingData"; - pTables = (TextEncodingFunction)osl_getAsciiFunctionSymbol(aModule, pSymbol); - } - } -#endif - if (pTables) - return pTables(nEncoding); -// else -// fprintf (stderr, "missing text encoding library for %d\n", nEncoding); - break; + return FullTextEncodingDataSingleton::get().get(nEncoding); } return NULL; } |