diff --git a/mozilla/intl/uconv/ucvja/Makefile.in b/mozilla/intl/uconv/ucvja/Makefile.in index 78ab97899c7..713fb5745d9 100644 --- a/mozilla/intl/uconv/ucvja/Makefile.in +++ b/mozilla/intl/uconv/ucvja/Makefile.in @@ -35,7 +35,7 @@ CPPSRCS = \ nsCP932ToUnicode.cpp \ nsUnicodeToCP932.cpp \ nsUCvJaSupport.cpp \ - nsUCVJADll.cpp \ + nsUCvJaModule.cpp \ nsEUCJPToUnicode.cpp \ nsISO2022JPToUnicode.cpp \ nsUnicodeToEUCJP.cpp \ diff --git a/mozilla/intl/uconv/ucvja/makefile.win b/mozilla/intl/uconv/ucvja/makefile.win index 10afc6cd025..f09453e07b7 100644 --- a/mozilla/intl/uconv/ucvja/makefile.win +++ b/mozilla/intl/uconv/ucvja/makefile.win @@ -33,7 +33,7 @@ CPPSRCS = \ nsCP932ToUnicode.cpp \ nsUnicodeToCP932.cpp \ nsUCvJaSupport.cpp \ - nsUCVJADll.cpp \ + nsUCvJaModule.cpp \ nsEUCJPToUnicode.cpp \ nsISO2022JPToUnicode.cpp \ nsUnicodeToEUCJP.cpp \ @@ -50,7 +50,7 @@ CPP_OBJS= \ .\$(OBJDIR)\nsCP932ToUnicode.obj \ .\$(OBJDIR)\nsUnicodeToCP932.obj \ .\$(OBJDIR)\nsUCvJaSupport.obj \ - .\$(OBJDIR)\nsUCVJADll.obj \ + .\$(OBJDIR)\nsUCvJaModule.obj \ .\$(OBJDIR)\nsEUCJPToUnicode.obj \ .\$(OBJDIR)\nsISO2022JPToUnicode.obj \ .\$(OBJDIR)\nsUnicodeToEUCJP.obj \ diff --git a/mozilla/intl/uconv/ucvja/nsUCvJaModule.cpp b/mozilla/intl/uconv/ucvja/nsUCvJaModule.cpp new file mode 100644 index 00000000000..1685a75934b --- /dev/null +++ b/mozilla/intl/uconv/ucvja/nsUCvJaModule.cpp @@ -0,0 +1,464 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + * the License for the specific language governing rights and limitations + * under the License. + * + * The Original Code is Mozilla Communicator client code. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are Copyright (C) 1998 + * Netscape Communications Corporation. All Rights Reserved. + */ + +#define NS_IMPL_IDS + +#include "pratom.h" +#include "nsCOMPtr.h" +#include "nsIFactory.h" +#include "nsIRegistry.h" +#include "nsIServiceManager.h" +#include "nsIModule.h" +#include "nsUCVJACID.h" +#include "nsUCVJA2CID.h" +#include "nsUCVJADll.h" + +#include "nsJapaneseToUnicode.h" +#include "nsSJIS2Unicode.h" // To Be Obsoleted +#include "nsUnicodeToSJIS.h" +#include "nsEUCJPToUnicode.h" // To Be Obsoleted +#include "nsISO2022JPToUnicode.h" // To Be Obsoleted +#include "nsUnicodeToEUCJP.h" +#include "nsUnicodeToISO2022JP.h" +#include "nsUnicodeToJISx0201.h" +#include "nsUnicodeToJISx0208.h" +#include "nsUnicodeToJISx0212.h" + +//---------------------------------------------------------------------------- +// Global functions and data [declaration] + +static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID); + +#define DECODER_NAME_BASE "Unicode Decoder-" +#define ENCODER_NAME_BASE "Unicode Encoder-" + +PRInt32 g_InstanceCount = 0; +PRInt32 g_LockCount = 0; + +// To Be Obsoleted +PRUint16 g_ut0201Mapping[] = { +#include "jis0201.ut" +}; + +PRUint16 g_ut0208Mapping[] = { +#include "jis0208.ut" +}; + +PRUint16 g_ut0212Mapping[] = { +#include "jis0212.ut" +}; +// End of To Be Obsoleted + +PRUint16 g_uf0201Mapping[] = { +#include "jis0201.uf" +}; + +PRUint16 g_uf0208Mapping[] = { +#include "jis0208.uf" +}; + +PRUint16 g_uf0212Mapping[] = { +#include "jis0212.uf" +}; + +typedef nsresult (* fpCreateInstance) (nsISupports **); + +struct FactoryData +{ + const nsCID * mCID; + fpCreateInstance CreateInstance; + char * mCharsetSrc; + char * mCharsetDest; +}; + +static FactoryData g_FactoryData[] = +{ + { + &kSJIS2UnicodeCID, + NEW_ShiftJISToUnicode, + "Shift_JIS", + "Unicode" + }, + { // To Be Obsoleted + &kObsSJISToUnicodeCID, + nsSJIS2Unicode::CreateInstance, + "x-obsoleted-Shift_JIS", + "Unicode" + },// To Be Obsoleted + { + &kUnicodeToSJISCID, + nsUnicodeToSJIS::CreateInstance, + "Unicode", + "Shift_JIS" + }, + { + &kISO2022JPToUnicodeCID, + NEW_ISO2022JPToUnicode, + "ISO-2022-JP", + "Unicode" + }, + { + &kEUCJPToUnicodeCID, + NEW_EUCJPToUnicode, + "EUC-JP", + "Unicode" + }, + {// To Be Obsoleted + &kObsISO2022JPToUnicodeCID, + nsISO2022JPToUnicode::CreateInstance, + "x-obsoleted-ISO-2022-JP", + "Unicode" + },// To Be Obsoleted + { // To Be Obsoleted + &kObsEUCJPToUnicodeCID, + nsEUCJPToUnicode::CreateInstance, + "x-obsoleted-EUC-JP", + "Unicode" + },// To Be Obsoleted + { + &kUnicodeToEUCJPCID, + nsUnicodeToEUCJP::CreateInstance, + "Unicode", + "EUC-JP" + }, + { + &kUnicodeToJISx0201CID, + nsUnicodeToJISx0201::CreateInstance, + "Unicode", + "jis_0201" + }, + { + &kUnicodeToJISx0208CID, + nsUnicodeToJISx0208::CreateInstance, + "Unicode", + "jis_0208-1983" + }, + { + &kUnicodeToJISx0212CID, + nsUnicodeToJISx0212::CreateInstance, + "Unicode", + "jis_0212-1990" + }, + { + &kUnicodeToISO2022JPCID, + nsUnicodeToISO2022JP::CreateInstance, + "Unicode", + "ISO-2022-JP" + } +}; + +#define ARRAY_SIZE(_array) \ + (sizeof(_array) / sizeof(_array[0])) + +//---------------------------------------------------------------------------- +// Class nsConverterFactory [declaration] + +/** + * General factory class for converter objects. + * + * @created 24/Feb/1998 + * @author Catalin Rotaru [CATA] + */ +class nsConverterFactory : public nsIFactory +{ + NS_DECL_ISUPPORTS + +private: + + FactoryData * mData; + +public: + + /** + * Class constructor. + */ + nsConverterFactory(FactoryData * aData); + + /** + * Class destructor. + */ + virtual ~nsConverterFactory(); + + //-------------------------------------------------------------------------- + // Interface nsIFactory [declaration] + + NS_IMETHOD CreateInstance(nsISupports *aDelegate, const nsIID &aIID, + void **aResult); + NS_IMETHOD LockFactory(PRBool aLock); +}; + +//---------------------------------------------------------------------------- +// Class nsConverterModule [declaration] + +class nsConverterModule : public nsIModule +{ + NS_DECL_ISUPPORTS + NS_DECL_NSIMODULE + +private: + + PRBool mInitialized; + + void Shutdown(); + +public: + + nsConverterModule(); + + virtual ~nsConverterModule(); + + nsresult Initialize(); + +}; + +//---------------------------------------------------------------------------- +// Global functions and data [implementation] + +static nsConverterModule * gModule = NULL; + +extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager * compMgr, + nsIFileSpec* location, + nsIModule** return_cobj) +{ + nsresult rv = NS_OK; + + NS_ENSURE_ARG_POINTER(return_cobj); + NS_ENSURE_NOT(gModule, NS_ERROR_FAILURE); + + // Create an initialize the module instance + nsConverterModule * m = new nsConverterModule(); + if (!m) { + return NS_ERROR_OUT_OF_MEMORY; + } + + // Increase refcnt and store away nsIModule interface to m in return_cobj + rv = m->QueryInterface(nsIModule::GetIID(), (void**)return_cobj); + if (NS_FAILED(rv)) { + delete m; + m = nsnull; + } + gModule = m; // WARNING: Weak Reference + return rv; +} + +//---------------------------------------------------------------------------- +// Class nsConverterFactory [implementation] + +NS_IMPL_ISUPPORTS(nsConverterFactory, nsCOMTypeInfo::GetIID()); + +nsConverterFactory::nsConverterFactory(FactoryData * aData) +{ + mData = aData; + + NS_INIT_REFCNT(); + PR_AtomicIncrement(&g_InstanceCount); +} + +nsConverterFactory::~nsConverterFactory() +{ + PR_AtomicDecrement(&g_InstanceCount); +} + +//---------------------------------------------------------------------------- +// Interface nsIFactory [implementation] + +NS_IMETHODIMP nsConverterFactory::CreateInstance(nsISupports *aDelegate, + const nsIID &aIID, + void **aResult) +{ + if (aResult == NULL) return NS_ERROR_NULL_POINTER; + if (aDelegate != NULL) return NS_ERROR_NO_AGGREGATION; + + nsISupports * t; + mData->CreateInstance(&t); + if (t == NULL) return NS_ERROR_OUT_OF_MEMORY; + + nsresult res = t->QueryInterface(aIID, aResult); + if (NS_FAILED(res)) delete t; + + return res; +} + +NS_IMETHODIMP nsConverterFactory::LockFactory(PRBool aLock) +{ + if (aLock) PR_AtomicIncrement(&g_LockCount); + else PR_AtomicDecrement(&g_LockCount); + + return NS_OK; +} + +//---------------------------------------------------------------------------- +// Class nsConverterModule [implementation] + +NS_IMPL_ISUPPORTS(nsConverterModule, nsIModule::GetIID()) + +nsConverterModule::nsConverterModule() +: mInitialized(PR_FALSE) +{ + NS_INIT_ISUPPORTS(); +} + +nsConverterModule::~nsConverterModule() +{ + Shutdown(); +} + +nsresult nsConverterModule::Initialize() +{ + return NS_OK; +} + +void nsConverterModule::Shutdown() +{ +} + +//---------------------------------------------------------------------------- +// Interface nsIModule [implementation] + +NS_IMETHODIMP nsConverterModule::GetClassObject(nsIComponentManager *aCompMgr, + const nsCID& aClass, + const nsIID& aIID, + void ** r_classObj) +{ + nsresult rv; + + // Defensive programming: Initialize *r_classObj in case of error below + if (!r_classObj) { + return NS_ERROR_INVALID_POINTER; + } + *r_classObj = NULL; + + if (!mInitialized) { + rv = Initialize(); + if (NS_FAILED(rv)) { + return rv; + } + mInitialized = PR_TRUE; + } + + FactoryData * data; + nsConverterFactory * fact; + + // XXX cache these factories + for (PRUint32 i=0; imCID))) { + fact = new nsConverterFactory(data); + if (fact == NULL) { + return NS_ERROR_OUT_OF_MEMORY; + } + rv = fact->QueryInterface(aIID, (void **) r_classObj); + if (NS_FAILED(rv)) delete fact; + + return rv; + } + } + + return NS_ERROR_FACTORY_NOT_REGISTERED; +} + +NS_IMETHODIMP nsConverterModule::RegisterSelf(nsIComponentManager *aCompMgr, + nsIFileSpec* aPath, + const char* registryLocation, + const char* componentType) +{ + nsresult res; + PRUint32 i; + nsIComponentManager * compMgr = NULL; + nsIRegistry * registry = NULL; + nsRegistryKey key; + char buff[1024]; + + // get the registry + res = nsServiceManager::GetService(NS_REGISTRY_PROGID, + nsIRegistry::GetIID(), (nsISupports**)®istry); + if (NS_FAILED(res)) goto done; + + // open the registry + res = registry->OpenWellKnownRegistry( + nsIRegistry::ApplicationComponentRegistry); + if (NS_FAILED(res)) goto done; + + char name[128]; + char progid[128]; + char * cid_string; + for (i=0; iRegisterComponentSpec(*(g_FactoryData[i].mCID), name, + progid, aPath, PR_TRUE, PR_TRUE); + if(NS_FAILED(res) && (NS_ERROR_FACTORY_EXISTS != res)) goto done; + + // register component info + // XXX take these KONSTANTS out of here; refine this code + cid_string = g_FactoryData[i].mCID->ToString(); + sprintf(buff, "%s/%s", "software/netscape/intl/uconv", cid_string); + nsCRT::free(cid_string); + res = registry -> AddSubtree(nsIRegistry::Common, buff, &key); + if (NS_FAILED(res)) goto done; + res = registry -> SetString(key, "source", g_FactoryData[i].mCharsetSrc); + if (NS_FAILED(res)) goto done; + res = registry -> SetString(key, "destination", g_FactoryData[i].mCharsetDest); + if (NS_FAILED(res)) goto done; + } + +done: + if (registry != NULL) { + registry -> Close(); + nsServiceManager::ReleaseService(NS_REGISTRY_PROGID, registry); + } + + return res; +} + +NS_IMETHODIMP nsConverterModule::UnregisterSelf(nsIComponentManager *aCompMgr, + nsIFileSpec* aPath, + const char* registryLocation) +{ + // XXX also delete the stuff I added to the registry + nsresult rv; + + for (PRUint32 i=0; iUnregisterComponentSpec(*(g_FactoryData[i].mCID), aPath); + } + + return NS_OK; +} + +NS_IMETHODIMP nsConverterModule::CanUnload(nsIComponentManager *aCompMgr, + PRBool *okToUnload) +{ + if (!okToUnload) { + return NS_ERROR_INVALID_POINTER; + } + *okToUnload = (g_InstanceCount == 0 && g_LockCount == 0); + return NS_OK; +} + diff --git a/mozilla/intl/uconv/ucvko/Makefile.in b/mozilla/intl/uconv/ucvko/Makefile.in index 57989e0a1d7..8726deb240b 100644 --- a/mozilla/intl/uconv/ucvko/Makefile.in +++ b/mozilla/intl/uconv/ucvko/Makefile.in @@ -38,7 +38,7 @@ CPPSRCS = \ nsUnicodeToCP949.cpp \ nsUnicodeToX11Johab.cpp \ nsUCvKOSupport.cpp \ - nsUCvKODll.cpp \ + nsUCvKoModule.cpp \ $(NULL) EXPORTS = nsUCvKOCID.h diff --git a/mozilla/intl/uconv/ucvko/makefile.win b/mozilla/intl/uconv/ucvko/makefile.win index 7e22a25d9d1..9c1e3541226 100644 --- a/mozilla/intl/uconv/ucvko/makefile.win +++ b/mozilla/intl/uconv/ucvko/makefile.win @@ -36,7 +36,7 @@ CPPSRCS = \ nsUnicodeToCP949.cpp \ nsUnicodeToX11Johab.cpp \ nsUCvKOSupport.cpp \ - nsUCvKODll.cpp \ + nsUCvKoModule.cpp \ $(NULL) CPP_OBJS= \ @@ -49,7 +49,7 @@ CPP_OBJS= \ .\$(OBJDIR)\nsUnicodeToCP949.obj \ .\$(OBJDIR)\nsUnicodeToX11Johab.obj \ .\$(OBJDIR)\nsUCvKOSupport.obj \ - .\$(OBJDIR)\nsUCvKODll.obj \ + .\$(OBJDIR)\nsUCvKoModule.obj \ $(NULL) EXPORTS=nsUCvKOCID.h \ diff --git a/mozilla/intl/uconv/ucvko/nsUCvKoModule.cpp b/mozilla/intl/uconv/ucvko/nsUCvKoModule.cpp new file mode 100644 index 00000000000..e2fb767e3f1 --- /dev/null +++ b/mozilla/intl/uconv/ucvko/nsUCvKoModule.cpp @@ -0,0 +1,398 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + * the License for the specific language governing rights and limitations + * under the License. + * + * The Original Code is Mozilla Communicator client code. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are Copyright (C) 1998 + * Netscape Communications Corporation. All Rights Reserved. + */ + +#define NS_IMPL_IDS + +#include "pratom.h" +#include "nsCOMPtr.h" +#include "nsIFactory.h" +#include "nsIRegistry.h" +#include "nsIServiceManager.h" +#include "nsIModule.h" +#include "nsUCvKOCID.h" +#include "nsUCvKODll.h" + +#include "nsEUCKRToUnicode.h" +#include "nsUnicodeToEUCKR.h" +#include "nsUnicodeToKSC5601.h" +#include "nsUnicodeToX11Johab.h" + +//---------------------------------------------------------------------------- +// Global functions and data [declaration] + +static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID); + +#define DECODER_NAME_BASE "Unicode Decoder-" +#define ENCODER_NAME_BASE "Unicode Encoder-" + +PRInt32 g_InstanceCount = 0; +PRInt32 g_LockCount = 0; + +PRUint16 g_utKSC5601Mapping[] = { +#include "u20kscgl.ut" +}; + +PRUint16 g_ufKSC5601Mapping[] = { +#include "u20kscgl.uf" +}; + +PRUint16 g_AsciiMapping[] = { + 0x0001, 0x0004, 0x0005, 0x0008, 0x0000, 0x0000, 0x007F, 0x0000 +}; +PRUint16 g_HangulNullMapping[] ={ + 0x0001, 0x0004, 0x0005, 0x0008, 0x0000, 0xAC00, 0xD7A3, 0xAC00 +}; + +typedef nsresult (* fpCreateInstance) (nsISupports **); + +struct FactoryData +{ + const nsCID * mCID; + fpCreateInstance CreateInstance; + char * mCharsetSrc; + char * mCharsetDest; +}; + +static FactoryData g_FactoryData[] = +{ + { + &kEUCKRToUnicodeCID, + nsEUCKRToUnicode::CreateInstance, + "EUC-KR", + "Unicode" + }, + { + &kUnicodeToEUCKRCID, + nsUnicodeToEUCKR::CreateInstance, + "Unicode", + "EUC-KR" + }, + { + &kUnicodeToKSC5601CID, + nsUnicodeToKSC5601::CreateInstance, + "Unicode", + "ks_c_5601-1987" + }, + { + &kUnicodeToX11JohabCID, + nsUnicodeToX11Johab::CreateInstance, + "Unicode", + "x-x11johab" + } +}; + +#define ARRAY_SIZE(_array) \ + (sizeof(_array) / sizeof(_array[0])) + +//---------------------------------------------------------------------------- +// Class nsConverterFactory [declaration] + +/** + * General factory class for converter objects. + * + * @created 24/Feb/1998 + * @author Catalin Rotaru [CATA] + */ +class nsConverterFactory : public nsIFactory +{ + NS_DECL_ISUPPORTS + +private: + + FactoryData * mData; + +public: + + /** + * Class constructor. + */ + nsConverterFactory(FactoryData * aData); + + /** + * Class destructor. + */ + virtual ~nsConverterFactory(); + + //-------------------------------------------------------------------------- + // Interface nsIFactory [declaration] + + NS_IMETHOD CreateInstance(nsISupports *aDelegate, const nsIID &aIID, + void **aResult); + NS_IMETHOD LockFactory(PRBool aLock); +}; + +//---------------------------------------------------------------------------- +// Class nsConverterModule [declaration] + +class nsConverterModule : public nsIModule +{ + NS_DECL_ISUPPORTS + NS_DECL_NSIMODULE + +private: + + PRBool mInitialized; + + void Shutdown(); + +public: + + nsConverterModule(); + + virtual ~nsConverterModule(); + + nsresult Initialize(); + +}; + +//---------------------------------------------------------------------------- +// Global functions and data [implementation] + +static nsConverterModule * gModule = NULL; + +extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager * compMgr, + nsIFileSpec* location, + nsIModule** return_cobj) +{ + nsresult rv = NS_OK; + + NS_ENSURE_ARG_POINTER(return_cobj); + NS_ENSURE_NOT(gModule, NS_ERROR_FAILURE); + + // Create an initialize the module instance + nsConverterModule * m = new nsConverterModule(); + if (!m) { + return NS_ERROR_OUT_OF_MEMORY; + } + + // Increase refcnt and store away nsIModule interface to m in return_cobj + rv = m->QueryInterface(nsIModule::GetIID(), (void**)return_cobj); + if (NS_FAILED(rv)) { + delete m; + m = nsnull; + } + gModule = m; // WARNING: Weak Reference + return rv; +} + +//---------------------------------------------------------------------------- +// Class nsConverterFactory [implementation] + +NS_IMPL_ISUPPORTS(nsConverterFactory, nsCOMTypeInfo::GetIID()); + +nsConverterFactory::nsConverterFactory(FactoryData * aData) +{ + mData = aData; + + NS_INIT_REFCNT(); + PR_AtomicIncrement(&g_InstanceCount); +} + +nsConverterFactory::~nsConverterFactory() +{ + PR_AtomicDecrement(&g_InstanceCount); +} + +//---------------------------------------------------------------------------- +// Interface nsIFactory [implementation] + +NS_IMETHODIMP nsConverterFactory::CreateInstance(nsISupports *aDelegate, + const nsIID &aIID, + void **aResult) +{ + if (aResult == NULL) return NS_ERROR_NULL_POINTER; + if (aDelegate != NULL) return NS_ERROR_NO_AGGREGATION; + + nsISupports * t; + mData->CreateInstance(&t); + if (t == NULL) return NS_ERROR_OUT_OF_MEMORY; + + nsresult res = t->QueryInterface(aIID, aResult); + if (NS_FAILED(res)) delete t; + + return res; +} + +NS_IMETHODIMP nsConverterFactory::LockFactory(PRBool aLock) +{ + if (aLock) PR_AtomicIncrement(&g_LockCount); + else PR_AtomicDecrement(&g_LockCount); + + return NS_OK; +} + +//---------------------------------------------------------------------------- +// Class nsConverterModule [implementation] + +NS_IMPL_ISUPPORTS(nsConverterModule, nsIModule::GetIID()) + +nsConverterModule::nsConverterModule() +: mInitialized(PR_FALSE) +{ + NS_INIT_ISUPPORTS(); +} + +nsConverterModule::~nsConverterModule() +{ + Shutdown(); +} + +nsresult nsConverterModule::Initialize() +{ + return NS_OK; +} + +void nsConverterModule::Shutdown() +{ +} + +//---------------------------------------------------------------------------- +// Interface nsIModule [implementation] + +NS_IMETHODIMP nsConverterModule::GetClassObject(nsIComponentManager *aCompMgr, + const nsCID& aClass, + const nsIID& aIID, + void ** r_classObj) +{ + nsresult rv; + + // Defensive programming: Initialize *r_classObj in case of error below + if (!r_classObj) { + return NS_ERROR_INVALID_POINTER; + } + *r_classObj = NULL; + + if (!mInitialized) { + rv = Initialize(); + if (NS_FAILED(rv)) { + return rv; + } + mInitialized = PR_TRUE; + } + + FactoryData * data; + nsConverterFactory * fact; + + // XXX cache these factories + for (PRUint32 i=0; imCID))) { + fact = new nsConverterFactory(data); + if (fact == NULL) { + return NS_ERROR_OUT_OF_MEMORY; + } + rv = fact->QueryInterface(aIID, (void **) r_classObj); + if (NS_FAILED(rv)) delete fact; + + return rv; + } + } + + return NS_ERROR_FACTORY_NOT_REGISTERED; +} + +NS_IMETHODIMP nsConverterModule::RegisterSelf(nsIComponentManager *aCompMgr, + nsIFileSpec* aPath, + const char* registryLocation, + const char* componentType) +{ + nsresult res; + PRUint32 i; + nsIComponentManager * compMgr = NULL; + nsIRegistry * registry = NULL; + nsRegistryKey key; + char buff[1024]; + + // get the registry + res = nsServiceManager::GetService(NS_REGISTRY_PROGID, + nsIRegistry::GetIID(), (nsISupports**)®istry); + if (NS_FAILED(res)) goto done; + + // open the registry + res = registry->OpenWellKnownRegistry( + nsIRegistry::ApplicationComponentRegistry); + if (NS_FAILED(res)) goto done; + + char name[128]; + char progid[128]; + char * cid_string; + for (i=0; iRegisterComponentSpec(*(g_FactoryData[i].mCID), name, + progid, aPath, PR_TRUE, PR_TRUE); + if(NS_FAILED(res) && (NS_ERROR_FACTORY_EXISTS != res)) goto done; + + // register component info + // XXX take these KONSTANTS out of here; refine this code + cid_string = g_FactoryData[i].mCID->ToString(); + sprintf(buff, "%s/%s", "software/netscape/intl/uconv", cid_string); + nsCRT::free(cid_string); + res = registry -> AddSubtree(nsIRegistry::Common, buff, &key); + if (NS_FAILED(res)) goto done; + res = registry -> SetString(key, "source", g_FactoryData[i].mCharsetSrc); + if (NS_FAILED(res)) goto done; + res = registry -> SetString(key, "destination", g_FactoryData[i].mCharsetDest); + if (NS_FAILED(res)) goto done; + } + +done: + if (registry != NULL) { + registry -> Close(); + nsServiceManager::ReleaseService(NS_REGISTRY_PROGID, registry); + } + + return res; +} + +NS_IMETHODIMP nsConverterModule::UnregisterSelf(nsIComponentManager *aCompMgr, + nsIFileSpec* aPath, + const char* registryLocation) +{ + // XXX also delete the stuff I added to the registry + nsresult rv; + + for (PRUint32 i=0; iUnregisterComponentSpec(*(g_FactoryData[i].mCID), aPath); + } + + return NS_OK; +} + +NS_IMETHODIMP nsConverterModule::CanUnload(nsIComponentManager *aCompMgr, + PRBool *okToUnload) +{ + if (!okToUnload) { + return NS_ERROR_INVALID_POINTER; + } + *okToUnload = (g_InstanceCount == 0 && g_LockCount == 0); + return NS_OK; +} + diff --git a/mozilla/intl/uconv/ucvlatin/Makefile.in b/mozilla/intl/uconv/ucvlatin/Makefile.in index ea69a450327..97809984b3f 100644 --- a/mozilla/intl/uconv/ucvlatin/Makefile.in +++ b/mozilla/intl/uconv/ucvlatin/Makefile.in @@ -138,7 +138,7 @@ CPPSRCS = \ nsUnicodeToSymbol.cpp \ nsUnicodeToZapfDingbat.cpp \ nsUCvLatinSupport.cpp \ - nsUCvLatinDll.cpp \ + nsUCvLatinModule.cpp \ $(NULL) EXPORTS = nsUCvLatinCID.h diff --git a/mozilla/intl/uconv/ucvlatin/makefile.win b/mozilla/intl/uconv/ucvlatin/makefile.win index a18f613e963..3a81b924706 100644 --- a/mozilla/intl/uconv/ucvlatin/makefile.win +++ b/mozilla/intl/uconv/ucvlatin/makefile.win @@ -136,7 +136,7 @@ CPPSRCS = \ nsUnicodeToSymbol.cpp \ nsUnicodeToZapfDingbat.cpp \ nsUCvLatinSupport.cpp \ - nsUCvLatinDll.cpp \ + nsUCvLatinModule.cpp \ $(NULL) CPP_OBJS= \ @@ -249,7 +249,7 @@ CPP_OBJS= \ .\$(OBJDIR)\nsUnicodeToSymbol.obj \ .\$(OBJDIR)\nsUnicodeToZapfDingbat.obj \ .\$(OBJDIR)\nsUCvLatinSupport.obj \ - .\$(OBJDIR)\nsUCvLatinDll.obj \ + .\$(OBJDIR)\nsUCvLatinModule.obj \ $(NULL) EXPORTS=nsUCvLatinCID.h \ diff --git a/mozilla/intl/uconv/ucvlatin/nsUCvLatinModule.cpp b/mozilla/intl/uconv/ucvlatin/nsUCvLatinModule.cpp new file mode 100644 index 00000000000..381d2f65286 --- /dev/null +++ b/mozilla/intl/uconv/ucvlatin/nsUCvLatinModule.cpp @@ -0,0 +1,1093 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + * the License for the specific language governing rights and limitations + * under the License. + * + * The Original Code is Mozilla Communicator client code. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are Copyright (C) 1998 + * Netscape Communications Corporation. All Rights Reserved. + */ + +#define NS_IMPL_IDS + +#include "pratom.h" +#include "nsCOMPtr.h" +#include "nsIFactory.h" +#include "nsIRegistry.h" +#include "nsIServiceManager.h" +#include "nsIModule.h" +#include "nsUCvLatinCID.h" +#include "nsUCvLatinDll.h" + +#include "nsUEscapeToUnicode.h" +#include "nsUnicodeToUEscape.h" +#include "nsAsciiToUnicode.h" +#include "nsISO88591ToUnicode.h" +#include "nsISO88592ToUnicode.h" +#include "nsISO88593ToUnicode.h" +#include "nsISO88594ToUnicode.h" +#include "nsISO88595ToUnicode.h" +#include "nsISO88596ToUnicode.h" +#include "nsISO88597ToUnicode.h" +#include "nsISO88598ToUnicode.h" +#include "nsISO88599ToUnicode.h" +#include "nsISO885910ToUnicode.h" +#include "nsISO885913ToUnicode.h" +#include "nsISO885914ToUnicode.h" +#include "nsISO885915ToUnicode.h" +#include "nsISOIR111ToUnicode.h" +#include "nsCP1250ToUnicode.h" +#include "nsCP1251ToUnicode.h" +#include "nsCP1252ToUnicode.h" +#include "nsCP1253ToUnicode.h" +#include "nsCP1254ToUnicode.h" +#include "nsCP1255ToUnicode.h" +#include "nsCP1256ToUnicode.h" +#include "nsCP1257ToUnicode.h" +#include "nsCP1258ToUnicode.h" +#include "nsCP874ToUnicode.h" +#include "nsCP866ToUnicode.h" +#include "nsKOI8RToUnicode.h" +#include "nsKOI8UToUnicode.h" +#include "nsMacRomanToUnicode.h" +#include "nsMacCEToUnicode.h" +#include "nsMacGreekToUnicode.h" +#include "nsMacTurkishToUnicode.h" +#include "nsMacCroatianToUnicode.h" +#include "nsMacRomanianToUnicode.h" +#include "nsMacCyrillicToUnicode.h" +#include "nsMacUkrainianToUnicode.h" +#include "nsMacIcelandicToUnicode.h" +#include "nsARMSCII8ToUnicode.h" +#include "nsTCVN5712ToUnicode.h" +#include "nsVISCIIToUnicode.h" +#include "nsVPSToUnicode.h" +#include "nsUTF8ToUnicode.h" +#include "nsUTF7ToUnicode.h" +#include "nsMUTF7ToUnicode.h" +#include "nsUCS4BEToUnicode.h" +#include "nsUCS4LEToUnicode.h" +#include "nsUCS2BEToUnicode.h" +#include "nsUCS2LEToUnicode.h" +#include "nsT61ToUnicode.h" +#include "nsUserDefinedToUnicode.h" +#include "nsUnicodeToAscii.h" +#include "nsUnicodeToISO88591.h" +#include "nsUnicodeToISO88592.h" +#include "nsUnicodeToISO88593.h" +#include "nsUnicodeToISO88594.h" +#include "nsUnicodeToISO88595.h" +#include "nsUnicodeToISO88596.h" +#include "nsUnicodeToISO88597.h" +#include "nsUnicodeToISO88598.h" +#include "nsUnicodeToISO88599.h" +#include "nsUnicodeToISO885910.h" +#include "nsUnicodeToISO885913.h" +#include "nsUnicodeToISO885914.h" +#include "nsUnicodeToISO885915.h" +#include "nsUnicodeToISOIR111.h" +#include "nsUnicodeToCP1250.h" +#include "nsUnicodeToCP1251.h" +#include "nsUnicodeToCP1252.h" +#include "nsUnicodeToCP1253.h" +#include "nsUnicodeToCP1254.h" +#include "nsUnicodeToCP1255.h" +#include "nsUnicodeToCP1256.h" +#include "nsUnicodeToCP1257.h" +#include "nsUnicodeToCP1258.h" +#include "nsUnicodeToCP874.h" +#include "nsUnicodeToCP866.h" +#include "nsUnicodeToKOI8R.h" +#include "nsUnicodeToKOI8U.h" +#include "nsUnicodeToMacRoman.h" +#include "nsUnicodeToMacCE.h" +#include "nsUnicodeToMacGreek.h" +#include "nsUnicodeToMacTurkish.h" +#include "nsUnicodeToMacCroatian.h" +#include "nsUnicodeToMacRomanian.h" +#include "nsUnicodeToMacCyrillic.h" +#include "nsUnicodeToMacUkrainian.h" +#include "nsUnicodeToMacIcelandic.h" +#include "nsUnicodeToARMSCII8.h" +#include "nsUnicodeToTCVN5712.h" +#include "nsUnicodeToVISCII.h" +#include "nsUnicodeToVPS.h" +#include "nsUnicodeToUTF8.h" +#include "nsUnicodeToUTF7.h" +#include "nsUnicodeToMUTF7.h" +#include "nsUnicodeToUCS2BE.h" +#include "nsUnicodeToUCS2LE.h" +#include "nsUnicodeToUCS4BE.h" +#include "nsUnicodeToUCS4LE.h" +#include "nsUnicodeToT61.h" +#include "nsUnicodeToUserDefined.h" +#include "nsUnicodeToSymbol.h" +#include "nsUnicodeToZapfDingbat.h" + +//---------------------------------------------------------------------------- +// Global functions and data [declaration] + +static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID); + +#define DECODER_NAME_BASE "Unicode Decoder-" +#define ENCODER_NAME_BASE "Unicode Encoder-" + +PRInt32 g_InstanceCount = 0; +PRInt32 g_LockCount = 0; + +typedef nsresult (* fpCreateInstance) (nsISupports **); + +struct FactoryData +{ + const nsCID * mCID; + fpCreateInstance CreateInstance; + char * mCharsetSrc; + char * mCharsetDest; +}; + +static FactoryData g_FactoryData[] = +{ + { + &kAsciiToUnicodeCID, + nsAsciiToUnicode::CreateInstance, + "us-ascii", + "Unicode" + }, + { + &kUEscapeToUnicodeCID, + NEW_UEscapeToUnicode, + "x-u-escaped", + "Unicode" + }, + { + &kISO88591ToUnicodeCID, + nsISO88591ToUnicode::CreateInstance, + "ISO-8859-1", + "Unicode" + }, + { + &kISO88592ToUnicodeCID, + nsISO88592ToUnicode::CreateInstance, + "ISO-8859-2", + "Unicode" + }, + { + &kISO88593ToUnicodeCID, + nsISO88593ToUnicode::CreateInstance, + "ISO-8859-3", + "Unicode" + }, + { + &kISO88594ToUnicodeCID, + nsISO88594ToUnicode::CreateInstance, + "ISO-8859-4", + "Unicode" + }, + { + &kISO88595ToUnicodeCID, + nsISO88595ToUnicode::CreateInstance, + "ISO-8859-5", + "Unicode" + }, + { + &kISO88596ToUnicodeCID, + nsISO88596ToUnicode::CreateInstance, + "ISO-8859-6", + "Unicode" + }, + { + &kISO88597ToUnicodeCID, + nsISO88597ToUnicode::CreateInstance, + "ISO-8859-7", + "Unicode" + }, + { + &kISO88598ToUnicodeCID, + nsISO88598ToUnicode::CreateInstance, + "ISO-8859-8", + "Unicode" + }, + { + &kISO88599ToUnicodeCID, + nsISO88599ToUnicode::CreateInstance, + "ISO-8859-9", + "Unicode" + }, + { + &kISO885910ToUnicodeCID, + nsISO885910ToUnicode::CreateInstance, + "ISO-8859-10", + "Unicode" + }, + { + &kISO885913ToUnicodeCID, + nsISO885913ToUnicode::CreateInstance, + "ISO-8859-13", + "Unicode" + }, + { + &kISO885914ToUnicodeCID, + nsISO885914ToUnicode::CreateInstance, + "ISO-8859-14", + "Unicode" + }, + { + &kISO885915ToUnicodeCID, + nsISO885915ToUnicode::CreateInstance, + "ISO-8859-15", + "Unicode" + }, + { + &kISOIR111ToUnicodeCID, + nsISOIR111ToUnicode::CreateInstance, + "ISO-IR-111", + "Unicode" + }, + { + &kCP1250ToUnicodeCID, + nsCP1250ToUnicode::CreateInstance, + "windows-1250", + "Unicode" + }, + { + &kCP1251ToUnicodeCID, + nsCP1251ToUnicode::CreateInstance, + "windows-1251", + "Unicode" + }, + { + &kCP1252ToUnicodeCID, + nsCP1252ToUnicode::CreateInstance, + "windows-1252", + "Unicode" + }, + { + &kCP1253ToUnicodeCID, + nsCP1253ToUnicode::CreateInstance, + "windows-1253", + "Unicode" + }, + { + &kCP1254ToUnicodeCID, + nsCP1254ToUnicode::CreateInstance, + "windows-1254", + "Unicode" + }, + { + &kCP1255ToUnicodeCID, + nsCP1255ToUnicode::CreateInstance, + "windows-1255", + "Unicode" + }, + { + &kCP1256ToUnicodeCID, + nsCP1256ToUnicode::CreateInstance, + "windows-1256", + "Unicode" + }, + { + &kCP1257ToUnicodeCID, + nsCP1257ToUnicode::CreateInstance, + "windows-1257", + "Unicode" + }, + { + &kCP1258ToUnicodeCID, + nsCP1258ToUnicode::CreateInstance, + "windows-1258", + "Unicode" + }, + { + &kCP874ToUnicodeCID, + nsCP874ToUnicode::CreateInstance, + "TIS-620", + "Unicode" + }, + { + &kCP866ToUnicodeCID, + nsCP866ToUnicode::CreateInstance, + "IBM866", + "Unicode" + }, + { + &kKOI8RToUnicodeCID, + nsKOI8RToUnicode::CreateInstance, + "KOI8-R", + "Unicode" + }, + { + &kKOI8UToUnicodeCID, + nsKOI8UToUnicode::CreateInstance, + "KOI8-U", + "Unicode" + }, + { + &kMacRomanToUnicodeCID, + nsMacRomanToUnicode::CreateInstance, + "x-mac-roman", + "Unicode" + }, + { + &kMacCEToUnicodeCID, + nsMacCEToUnicode::CreateInstance, + "x-mac-ce", + "Unicode" + }, + { + &kMacGreekToUnicodeCID, + nsMacGreekToUnicode::CreateInstance, + "x-mac-greek", + "Unicode" + }, + { + &kMacTurkishToUnicodeCID, + nsMacTurkishToUnicode::CreateInstance, + "x-mac-turkish", + "Unicode" + }, + { + &kMacCroatianToUnicodeCID, + nsMacCroatianToUnicode::CreateInstance, + "x-mac-croatian", + "Unicode" + }, + { + &kMacRomanianToUnicodeCID, + nsMacRomanianToUnicode::CreateInstance, + "x-mac-romanian", + "Unicode" + }, + { + &kMacCyrillicToUnicodeCID, + nsMacCyrillicToUnicode::CreateInstance, + "x-mac-cyrillic", + "Unicode" + }, + { + &kMacUkrainianToUnicodeCID, + nsMacUkrainianToUnicode::CreateInstance, + "x-mac-ukrainian", + "Unicode" + }, + { + &kMacIcelandicToUnicodeCID, + nsMacIcelandicToUnicode::CreateInstance, + "x-mac-icelandic", + "Unicode" + }, + { + &kARMSCII8ToUnicodeCID, + nsARMSCII8ToUnicode::CreateInstance, + "armscii-8", + "Unicode" + }, + { + &kTCVN5712ToUnicodeCID, + nsTCVN5712ToUnicode::CreateInstance, + "x-viet-tcvn", + "Unicode" + }, + { + &kVISCIIToUnicodeCID, + nsVISCIIToUnicode::CreateInstance, + "VISCII", + "Unicode" + }, + { + &kVPSToUnicodeCID, + nsVPSToUnicode::CreateInstance, + "x-viet-vps", + "Unicode" + }, + { + &kUTF8ToUnicodeCID, + nsUTF8ToUnicode::CreateInstance, + "UTF-8", + "Unicode" + }, + { + &kUTF7ToUnicodeCID, + nsUTF7ToUnicode::CreateInstance, + "UTF-7", + "Unicode" + }, + { + &kMUTF7ToUnicodeCID, + nsMUTF7ToUnicode::CreateInstance, + "x-imap4-modified-utf7", + "Unicode" + }, + { + &kUTF16BEToUnicodeCID, + //nsUCS2BEToUnicode::CreateInstance, + NEW_UTF16BEToUnicode, + "UTF-16BE", + "Unicode" + }, + { + &kUTF16LEToUnicodeCID, + //nsUCS2LEToUnicode::CreateInstance, + NEW_UTF16LEToUnicode, + "UTF-16LE", + "Unicode" + }, + { + &kUTF32BEToUnicodeCID, + nsUCS4BEToUnicode::CreateInstance, + "UTF-32BE", + "Unicode" + }, + { + &kUTF32LEToUnicodeCID, + nsUCS4LEToUnicode::CreateInstance, + "UTF-32LE", + "Unicode" + }, + { + &kT61ToUnicodeCID, + nsT61ToUnicode::CreateInstance, + "T.61-8bit", + "Unicode" + }, + { + &kUserDefinedToUnicodeCID, + nsUserDefinedToUnicode::CreateInstance, + "x-user-defined", + "Unicode" + }, + { + &kUnicodeToAsciiCID, + nsUnicodeToAscii::CreateInstance, + "Unicode", + "us-ascii" + }, + { + &kUnicodeToUEscapeCID, + NEW_UnicodeToUEscape, + "Unicode", + "x-u-escaped" + }, + { + &kUnicodeToISO88591CID, + nsUnicodeToISO88591::CreateInstance, + "Unicode", + "ISO-8859-1" + }, + { + &kUnicodeToISO88592CID, + nsUnicodeToISO88592::CreateInstance, + "Unicode", + "ISO-8859-2" + }, + { + &kUnicodeToISO88593CID, + nsUnicodeToISO88593::CreateInstance, + "Unicode", + "ISO-8859-3" + }, + { + &kUnicodeToISO88594CID, + nsUnicodeToISO88594::CreateInstance, + "Unicode", + "ISO-8859-4" + }, + { + &kUnicodeToISO88595CID, + nsUnicodeToISO88595::CreateInstance, + "Unicode", + "ISO-8859-5" + }, + { + &kUnicodeToISO88596CID, + nsUnicodeToISO88596::CreateInstance, + "Unicode", + "ISO-8859-6" + }, + { + &kUnicodeToISO88597CID, + nsUnicodeToISO88597::CreateInstance, + "Unicode", + "ISO-8859-7" + }, + { + &kUnicodeToISO88598CID, + nsUnicodeToISO88598::CreateInstance, + "Unicode", + "ISO-8859-8" + }, + { + &kUnicodeToISO88599CID, + nsUnicodeToISO88599::CreateInstance, + "Unicode", + "ISO-8859-9" + }, + { + &kUnicodeToISO885910CID, + nsUnicodeToISO885910::CreateInstance, + "Unicode", + "ISO-8859-10" + }, + { + &kUnicodeToISO885913CID, + nsUnicodeToISO885913::CreateInstance, + "Unicode", + "ISO-8859-13" + }, + { + &kUnicodeToISO885914CID, + nsUnicodeToISO885914::CreateInstance, + "Unicode", + "ISO-8859-14" + }, + { + &kUnicodeToISO885915CID, + nsUnicodeToISO885915::CreateInstance, + "Unicode", + "ISO-8859-15" + }, + { + &kUnicodeToISOIR111CID, + nsUnicodeToISOIR111::CreateInstance, + "Unicode", + "ISO-IR-111" + }, + { + &kUnicodeToCP1250CID, + nsUnicodeToCP1250::CreateInstance, + "Unicode", + "windows-1250" + }, + { + &kUnicodeToCP1251CID, + nsUnicodeToCP1251::CreateInstance, + "Unicode", + "windows-1251" + }, + { + &kUnicodeToCP1252CID, + nsUnicodeToCP1252::CreateInstance, + "Unicode", + "windows-1252" + }, + { + &kUnicodeToCP1253CID, + nsUnicodeToCP1253::CreateInstance, + "Unicode", + "windows-1253" + }, + { + &kUnicodeToCP1254CID, + nsUnicodeToCP1254::CreateInstance, + "Unicode", + "windows-1254" + }, + { + &kUnicodeToCP1255CID, + nsUnicodeToCP1255::CreateInstance, + "Unicode", + "windows-1255" + }, + { + &kUnicodeToCP1256CID, + nsUnicodeToCP1256::CreateInstance, + "Unicode", + "windows-1256" + }, + { + &kUnicodeToCP1257CID, + nsUnicodeToCP1257::CreateInstance, + "Unicode", + "windows-1257" + }, + { + &kUnicodeToCP1258CID, + nsUnicodeToCP1258::CreateInstance, + "Unicode", + "windows-1258" + }, + { + &kUnicodeToCP874CID, + nsUnicodeToCP874::CreateInstance, + "Unicode", + "TIS-620" + }, + { + &kUnicodeToCP866CID, + nsUnicodeToCP866::CreateInstance, + "Unicode", + "IBM866" + }, + { + &kUnicodeToKOI8RCID, + nsUnicodeToKOI8R::CreateInstance, + "Unicode", + "KOI8-R" + }, + { + &kUnicodeToKOI8UCID, + nsUnicodeToKOI8U::CreateInstance, + "Unicode", + "KOI8-U" + }, + { + &kUnicodeToMacRomanCID, + nsUnicodeToMacRoman::CreateInstance, + "Unicode", + "x-mac-roman" + }, + { + &kUnicodeToMacCECID, + nsUnicodeToMacCE::CreateInstance, + "Unicode", + "x-mac-ce" + }, + { + &kUnicodeToMacGreekCID, + nsUnicodeToMacGreek::CreateInstance, + "Unicode", + "x-mac-greek" + }, + { + &kUnicodeToMacTurkishCID, + nsUnicodeToMacTurkish::CreateInstance, + "Unicode", + "x-mac-turkish" + }, + { + &kUnicodeToMacCroatianCID, + nsUnicodeToMacCroatian::CreateInstance, + "Unicode", + "x-mac-croatian" + }, + { + &kUnicodeToMacRomanianCID, + nsUnicodeToMacRomanian::CreateInstance, + "Unicode", + "x-mac-romanian" + }, + { + &kUnicodeToMacCyrillicCID, + nsUnicodeToMacCyrillic::CreateInstance, + "Unicode", + "x-mac-cyrillic" + }, + { + &kUnicodeToMacUkrainianCID, + nsUnicodeToMacUkrainian::CreateInstance, + "Unicode", + "x-mac-ukrainian" + }, + { + &kUnicodeToMacIcelandicCID, + nsUnicodeToMacIcelandic::CreateInstance, + "Unicode", + "x-mac-icelandic" + }, + { + &kUnicodeToARMSCII8CID, + nsUnicodeToARMSCII8::CreateInstance, + "Unicode", + "armscii-8" + }, + { + &kUnicodeToTCVN5712CID, + nsUnicodeToTCVN5712::CreateInstance, + "Unicode", + "x-viet-tcvn" + }, + { + &kUnicodeToVISCIICID, + nsUnicodeToVISCII::CreateInstance, + "Unicode", + "VISCII" + }, + { + &kUnicodeToVPSCID, + nsUnicodeToVPS::CreateInstance, + "Unicode", + "x-viet-vps" + }, + { + &kUnicodeToUTF8CID, + nsUnicodeToUTF8::CreateInstance, + "Unicode", + "UTF-8" + }, + { + &kUnicodeToUTF7CID, + nsUnicodeToUTF7::CreateInstance, + "Unicode", + "UTF-7" + }, + { + &kUnicodeToMUTF7CID, + nsUnicodeToMUTF7::CreateInstance, + "Unicode", + "x-imap4-modified-utf7" + }, + { + &kUnicodeToUTF16BECID, + // nsUnicodeToUCS2BE::CreateInstance, + NEW_UnicodeToUTF16BE, + "Unicode", + "UTF-16BE" + }, + { + &kUnicodeToUTF16LECID, + // nsUnicodeToUCS2LE::CreateInstance, + NEW_UnicodeToUTF16LE, + "Unicode", + "UTF-16LE" + }, + { + &kUnicodeToUTF16CID, + NEW_UnicodeToUTF16, + "Unicode", + "UTF-16" + }, + { + &kUnicodeToUTF32BECID, + nsUnicodeToUCS4BE::CreateInstance, + "Unicode", + "UTF-32BE" + }, + { + &kUnicodeToUTF32LECID, + nsUnicodeToUCS4LE::CreateInstance, + "Unicode", + "UTF-32LE" + }, + { + &kUnicodeToT61CID, + nsUnicodeToT61::CreateInstance, + "Unicode", + "T.61-8bit" + }, + { + &kUnicodeToUserDefinedCID, + nsUnicodeToUserDefined::CreateInstance, + "Unicode", + "x-user-defined" + }, + { + &kUnicodeToSymbolCID, + nsUnicodeToSymbol::CreateInstance, + "Unicode", + "Adobe-Symbol-Encoding" + }, + { + &kUnicodeToZapfDingbatsCID, + nsUnicodeToZapfDingbat::CreateInstance, + "Unicode", + "x-zapf-dingbats" + } +}; + +#define ARRAY_SIZE(_array) \ + (sizeof(_array) / sizeof(_array[0])) + +//---------------------------------------------------------------------------- +// Class nsConverterFactory [declaration] + +/** + * General factory class for converter objects. + * + * @created 24/Feb/1998 + * @author Catalin Rotaru [CATA] + */ +class nsConverterFactory : public nsIFactory +{ + NS_DECL_ISUPPORTS + +private: + + FactoryData * mData; + +public: + + /** + * Class constructor. + */ + nsConverterFactory(FactoryData * aData); + + /** + * Class destructor. + */ + virtual ~nsConverterFactory(); + + //-------------------------------------------------------------------------- + // Interface nsIFactory [declaration] + + NS_IMETHOD CreateInstance(nsISupports *aDelegate, const nsIID &aIID, + void **aResult); + NS_IMETHOD LockFactory(PRBool aLock); +}; + +//---------------------------------------------------------------------------- +// Class nsConverterModule [declaration] + +class nsConverterModule : public nsIModule +{ + NS_DECL_ISUPPORTS + NS_DECL_NSIMODULE + +private: + + PRBool mInitialized; + + void Shutdown(); + +public: + + nsConverterModule(); + + virtual ~nsConverterModule(); + + nsresult Initialize(); + +}; + +//---------------------------------------------------------------------------- +// Global functions and data [implementation] + +static nsConverterModule * gModule = NULL; + +extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager * compMgr, + nsIFileSpec* location, + nsIModule** return_cobj) +{ + nsresult rv = NS_OK; + + NS_ENSURE_ARG_POINTER(return_cobj); + NS_ENSURE_NOT(gModule, NS_ERROR_FAILURE); + + // Create an initialize the module instance + nsConverterModule * m = new nsConverterModule(); + if (!m) { + return NS_ERROR_OUT_OF_MEMORY; + } + + // Increase refcnt and store away nsIModule interface to m in return_cobj + rv = m->QueryInterface(nsIModule::GetIID(), (void**)return_cobj); + if (NS_FAILED(rv)) { + delete m; + m = nsnull; + } + gModule = m; // WARNING: Weak Reference + return rv; +} + +//---------------------------------------------------------------------------- +// Class nsConverterFactory [implementation] + +NS_IMPL_ISUPPORTS(nsConverterFactory, nsCOMTypeInfo::GetIID()); + +nsConverterFactory::nsConverterFactory(FactoryData * aData) +{ + mData = aData; + + NS_INIT_REFCNT(); + PR_AtomicIncrement(&g_InstanceCount); +} + +nsConverterFactory::~nsConverterFactory() +{ + PR_AtomicDecrement(&g_InstanceCount); +} + +//---------------------------------------------------------------------------- +// Interface nsIFactory [implementation] + +NS_IMETHODIMP nsConverterFactory::CreateInstance(nsISupports *aDelegate, + const nsIID &aIID, + void **aResult) +{ + if (aResult == NULL) return NS_ERROR_NULL_POINTER; + if (aDelegate != NULL) return NS_ERROR_NO_AGGREGATION; + + nsISupports * t; + mData->CreateInstance(&t); + if (t == NULL) return NS_ERROR_OUT_OF_MEMORY; + + nsresult res = t->QueryInterface(aIID, aResult); + if (NS_FAILED(res)) delete t; + + return res; +} + +NS_IMETHODIMP nsConverterFactory::LockFactory(PRBool aLock) +{ + if (aLock) PR_AtomicIncrement(&g_LockCount); + else PR_AtomicDecrement(&g_LockCount); + + return NS_OK; +} + +//---------------------------------------------------------------------------- +// Class nsConverterModule [implementation] + +NS_IMPL_ISUPPORTS(nsConverterModule, nsIModule::GetIID()) + +nsConverterModule::nsConverterModule() +: mInitialized(PR_FALSE) +{ + NS_INIT_ISUPPORTS(); +} + +nsConverterModule::~nsConverterModule() +{ + Shutdown(); +} + +nsresult nsConverterModule::Initialize() +{ + return NS_OK; +} + +void nsConverterModule::Shutdown() +{ +} + +//---------------------------------------------------------------------------- +// Interface nsIModule [implementation] + +NS_IMETHODIMP nsConverterModule::GetClassObject(nsIComponentManager *aCompMgr, + const nsCID& aClass, + const nsIID& aIID, + void ** r_classObj) +{ + nsresult rv; + + // Defensive programming: Initialize *r_classObj in case of error below + if (!r_classObj) { + return NS_ERROR_INVALID_POINTER; + } + *r_classObj = NULL; + + if (!mInitialized) { + rv = Initialize(); + if (NS_FAILED(rv)) { + return rv; + } + mInitialized = PR_TRUE; + } + + FactoryData * data; + nsConverterFactory * fact; + + // XXX cache these factories + for (PRUint32 i=0; imCID))) { + fact = new nsConverterFactory(data); + if (fact == NULL) { + return NS_ERROR_OUT_OF_MEMORY; + } + rv = fact->QueryInterface(aIID, (void **) r_classObj); + if (NS_FAILED(rv)) delete fact; + + return rv; + } + } + + return NS_ERROR_FACTORY_NOT_REGISTERED; +} + +NS_IMETHODIMP nsConverterModule::RegisterSelf(nsIComponentManager *aCompMgr, + nsIFileSpec* aPath, + const char* registryLocation, + const char* componentType) +{ + nsresult res; + PRUint32 i; + nsIComponentManager * compMgr = NULL; + nsIRegistry * registry = NULL; + nsRegistryKey key; + char buff[1024]; + + // get the registry + res = nsServiceManager::GetService(NS_REGISTRY_PROGID, + nsIRegistry::GetIID(), (nsISupports**)®istry); + if (NS_FAILED(res)) goto done; + + // open the registry + res = registry->OpenWellKnownRegistry( + nsIRegistry::ApplicationComponentRegistry); + if (NS_FAILED(res)) goto done; + + char name[128]; + char progid[128]; + char * cid_string; + for (i=0; iRegisterComponentSpec(*(g_FactoryData[i].mCID), name, + progid, aPath, PR_TRUE, PR_TRUE); + if(NS_FAILED(res) && (NS_ERROR_FACTORY_EXISTS != res)) goto done; + + // register component info + // XXX take these KONSTANTS out of here; refine this code + cid_string = g_FactoryData[i].mCID->ToString(); + sprintf(buff, "%s/%s", "software/netscape/intl/uconv", cid_string); + nsCRT::free(cid_string); + res = registry -> AddSubtree(nsIRegistry::Common, buff, &key); + if (NS_FAILED(res)) goto done; + res = registry -> SetString(key, "source", g_FactoryData[i].mCharsetSrc); + if (NS_FAILED(res)) goto done; + res = registry -> SetString(key, "destination", g_FactoryData[i].mCharsetDest); + if (NS_FAILED(res)) goto done; + } + +done: + if (registry != NULL) { + registry -> Close(); + nsServiceManager::ReleaseService(NS_REGISTRY_PROGID, registry); + } + + return res; +} + +NS_IMETHODIMP nsConverterModule::UnregisterSelf(nsIComponentManager *aCompMgr, + nsIFileSpec* aPath, + const char* registryLocation) +{ + // XXX also delete the stuff I added to the registry + nsresult rv; + + for (PRUint32 i=0; iUnregisterComponentSpec(*(g_FactoryData[i].mCID), aPath); + } + + return NS_OK; +} + +NS_IMETHODIMP nsConverterModule::CanUnload(nsIComponentManager *aCompMgr, + PRBool *okToUnload) +{ + if (!okToUnload) { + return NS_ERROR_INVALID_POINTER; + } + *okToUnload = (g_InstanceCount == 0 && g_LockCount == 0); + return NS_OK; +} + diff --git a/mozilla/intl/uconv/ucvtw/Makefile.in b/mozilla/intl/uconv/ucvtw/Makefile.in index f91092a9793..f8277c999cd 100644 --- a/mozilla/intl/uconv/ucvtw/Makefile.in +++ b/mozilla/intl/uconv/ucvtw/Makefile.in @@ -35,7 +35,7 @@ CPPSRCS = \ nsUnicodeToCP950.cpp \ nsUnicodeToBIG5NoAscii.cpp \ nsUCvTWSupport.cpp \ - nsUCvTWDll.cpp \ + nsUCvTwModule.cpp \ $(NULL) EXPORTS = nsUCvTWCID.h diff --git a/mozilla/intl/uconv/ucvtw/makefile.win b/mozilla/intl/uconv/ucvtw/makefile.win index b4115c93d56..d8e7e9a6133 100644 --- a/mozilla/intl/uconv/ucvtw/makefile.win +++ b/mozilla/intl/uconv/ucvtw/makefile.win @@ -33,7 +33,7 @@ CPPSRCS = \ nsUnicodeToCP950.cpp \ nsUnicodeToBIG5NoAscii.cpp \ nsUCvTWSupport.cpp \ - nsUCvTWDll.cpp \ + nsUCvTwModule.cpp \ $(NULL) CPP_OBJS= \ @@ -43,7 +43,7 @@ CPP_OBJS= \ .\$(OBJDIR)\nsUnicodeToCP950.obj \ .\$(OBJDIR)\nsUnicodeToBIG5NoAscii.obj \ .\$(OBJDIR)\nsUCvTWSupport.obj \ - .\$(OBJDIR)\nsUCvTWDll.obj \ + .\$(OBJDIR)\nsUCvTwModule.obj \ $(NULL) EXPORTS=nsUCvTWCID.h \ diff --git a/mozilla/intl/uconv/ucvtw/nsUCvTwModule.cpp b/mozilla/intl/uconv/ucvtw/nsUCvTwModule.cpp new file mode 100644 index 00000000000..1d3ede22ec6 --- /dev/null +++ b/mozilla/intl/uconv/ucvtw/nsUCvTwModule.cpp @@ -0,0 +1,388 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + * the License for the specific language governing rights and limitations + * under the License. + * + * The Original Code is Mozilla Communicator client code. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are Copyright (C) 1998 + * Netscape Communications Corporation. All Rights Reserved. + */ + +#define NS_IMPL_IDS + +#include "pratom.h" +#include "nsCOMPtr.h" +#include "nsIFactory.h" +#include "nsIRegistry.h" +#include "nsIServiceManager.h" +#include "nsIModule.h" +#include "nsUCvTWCID.h" +#include "nsUCvTWDll.h" + +#include "nsBIG5ToUnicode.h" +#include "nsUnicodeToBIG5.h" +#include "nsUnicodeToBIG5NoAscii.h" + +//---------------------------------------------------------------------------- +// Global functions and data [declaration] + +static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID); + +#define DECODER_NAME_BASE "Unicode Decoder-" +#define ENCODER_NAME_BASE "Unicode Encoder-" + +PRInt32 g_InstanceCount = 0; +PRInt32 g_LockCount = 0; + +PRUint16 g_ufBig5Mapping[] = { +#include "big5.uf" +}; + +PRUint16 g_utBIG5Mapping[] = { +#include "big5.ut" +}; + +PRUint16 g_ASCIIMapping[] = { + 0x0001, 0x0004, 0x0005, 0x0008, 0x0000, 0x0000, 0x007F, 0x0000 +}; + +typedef nsresult (* fpCreateInstance) (nsISupports **); + +struct FactoryData +{ + const nsCID * mCID; + fpCreateInstance CreateInstance; + char * mCharsetSrc; + char * mCharsetDest; +}; + +static FactoryData g_FactoryData[] = +{ + { + &kBIG5ToUnicodeCID, + nsBIG5ToUnicode::CreateInstance, + "BIG5", + "Unicode" + }, + { + &kUnicodeToBIG5CID, + nsUnicodeToBIG5::CreateInstance, + "Unicode", + "BIG5" + }, + { + &kUnicodeToBIG5NoAsciiCID, + nsUnicodeToBIG5NoAscii::CreateInstance, + "Unicode", + "x-x-big5" + } +}; + +#define ARRAY_SIZE(_array) \ + (sizeof(_array) / sizeof(_array[0])) + +//---------------------------------------------------------------------------- +// Class nsConverterFactory [declaration] + +/** + * General factory class for converter objects. + * + * @created 24/Feb/1998 + * @author Catalin Rotaru [CATA] + */ +class nsConverterFactory : public nsIFactory +{ + NS_DECL_ISUPPORTS + +private: + + FactoryData * mData; + +public: + + /** + * Class constructor. + */ + nsConverterFactory(FactoryData * aData); + + /** + * Class destructor. + */ + virtual ~nsConverterFactory(); + + //-------------------------------------------------------------------------- + // Interface nsIFactory [declaration] + + NS_IMETHOD CreateInstance(nsISupports *aDelegate, const nsIID &aIID, + void **aResult); + NS_IMETHOD LockFactory(PRBool aLock); +}; + +//---------------------------------------------------------------------------- +// Class nsConverterModule [declaration] + +class nsConverterModule : public nsIModule +{ + NS_DECL_ISUPPORTS + NS_DECL_NSIMODULE + +private: + + PRBool mInitialized; + + void Shutdown(); + +public: + + nsConverterModule(); + + virtual ~nsConverterModule(); + + nsresult Initialize(); + +}; + +//---------------------------------------------------------------------------- +// Global functions and data [implementation] + +static nsConverterModule * gModule = NULL; + +extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager * compMgr, + nsIFileSpec* location, + nsIModule** return_cobj) +{ + nsresult rv = NS_OK; + + NS_ENSURE_ARG_POINTER(return_cobj); + NS_ENSURE_NOT(gModule, NS_ERROR_FAILURE); + + // Create an initialize the module instance + nsConverterModule * m = new nsConverterModule(); + if (!m) { + return NS_ERROR_OUT_OF_MEMORY; + } + + // Increase refcnt and store away nsIModule interface to m in return_cobj + rv = m->QueryInterface(nsIModule::GetIID(), (void**)return_cobj); + if (NS_FAILED(rv)) { + delete m; + m = nsnull; + } + gModule = m; // WARNING: Weak Reference + return rv; +} + +//---------------------------------------------------------------------------- +// Class nsConverterFactory [implementation] + +NS_IMPL_ISUPPORTS(nsConverterFactory, nsCOMTypeInfo::GetIID()); + +nsConverterFactory::nsConverterFactory(FactoryData * aData) +{ + mData = aData; + + NS_INIT_REFCNT(); + PR_AtomicIncrement(&g_InstanceCount); +} + +nsConverterFactory::~nsConverterFactory() +{ + PR_AtomicDecrement(&g_InstanceCount); +} + +//---------------------------------------------------------------------------- +// Interface nsIFactory [implementation] + +NS_IMETHODIMP nsConverterFactory::CreateInstance(nsISupports *aDelegate, + const nsIID &aIID, + void **aResult) +{ + if (aResult == NULL) return NS_ERROR_NULL_POINTER; + if (aDelegate != NULL) return NS_ERROR_NO_AGGREGATION; + + nsISupports * t; + mData->CreateInstance(&t); + if (t == NULL) return NS_ERROR_OUT_OF_MEMORY; + + nsresult res = t->QueryInterface(aIID, aResult); + if (NS_FAILED(res)) delete t; + + return res; +} + +NS_IMETHODIMP nsConverterFactory::LockFactory(PRBool aLock) +{ + if (aLock) PR_AtomicIncrement(&g_LockCount); + else PR_AtomicDecrement(&g_LockCount); + + return NS_OK; +} + +//---------------------------------------------------------------------------- +// Class nsConverterModule [implementation] + +NS_IMPL_ISUPPORTS(nsConverterModule, nsIModule::GetIID()) + +nsConverterModule::nsConverterModule() +: mInitialized(PR_FALSE) +{ + NS_INIT_ISUPPORTS(); +} + +nsConverterModule::~nsConverterModule() +{ + Shutdown(); +} + +nsresult nsConverterModule::Initialize() +{ + return NS_OK; +} + +void nsConverterModule::Shutdown() +{ +} + +//---------------------------------------------------------------------------- +// Interface nsIModule [implementation] + +NS_IMETHODIMP nsConverterModule::GetClassObject(nsIComponentManager *aCompMgr, + const nsCID& aClass, + const nsIID& aIID, + void ** r_classObj) +{ + nsresult rv; + + // Defensive programming: Initialize *r_classObj in case of error below + if (!r_classObj) { + return NS_ERROR_INVALID_POINTER; + } + *r_classObj = NULL; + + if (!mInitialized) { + rv = Initialize(); + if (NS_FAILED(rv)) { + return rv; + } + mInitialized = PR_TRUE; + } + + FactoryData * data; + nsConverterFactory * fact; + + // XXX cache these factories + for (PRUint32 i=0; imCID))) { + fact = new nsConverterFactory(data); + if (fact == NULL) { + return NS_ERROR_OUT_OF_MEMORY; + } + rv = fact->QueryInterface(aIID, (void **) r_classObj); + if (NS_FAILED(rv)) delete fact; + + return rv; + } + } + + return NS_ERROR_FACTORY_NOT_REGISTERED; +} + +NS_IMETHODIMP nsConverterModule::RegisterSelf(nsIComponentManager *aCompMgr, + nsIFileSpec* aPath, + const char* registryLocation, + const char* componentType) +{ + nsresult res; + PRUint32 i; + nsIComponentManager * compMgr = NULL; + nsIRegistry * registry = NULL; + nsRegistryKey key; + char buff[1024]; + + // get the registry + res = nsServiceManager::GetService(NS_REGISTRY_PROGID, + nsIRegistry::GetIID(), (nsISupports**)®istry); + if (NS_FAILED(res)) goto done; + + // open the registry + res = registry->OpenWellKnownRegistry( + nsIRegistry::ApplicationComponentRegistry); + if (NS_FAILED(res)) goto done; + + char name[128]; + char progid[128]; + char * cid_string; + for (i=0; iRegisterComponentSpec(*(g_FactoryData[i].mCID), name, + progid, aPath, PR_TRUE, PR_TRUE); + if(NS_FAILED(res) && (NS_ERROR_FACTORY_EXISTS != res)) goto done; + + // register component info + // XXX take these KONSTANTS out of here; refine this code + cid_string = g_FactoryData[i].mCID->ToString(); + sprintf(buff, "%s/%s", "software/netscape/intl/uconv", cid_string); + nsCRT::free(cid_string); + res = registry -> AddSubtree(nsIRegistry::Common, buff, &key); + if (NS_FAILED(res)) goto done; + res = registry -> SetString(key, "source", g_FactoryData[i].mCharsetSrc); + if (NS_FAILED(res)) goto done; + res = registry -> SetString(key, "destination", g_FactoryData[i].mCharsetDest); + if (NS_FAILED(res)) goto done; + } + +done: + if (registry != NULL) { + registry -> Close(); + nsServiceManager::ReleaseService(NS_REGISTRY_PROGID, registry); + } + + return res; +} + +NS_IMETHODIMP nsConverterModule::UnregisterSelf(nsIComponentManager *aCompMgr, + nsIFileSpec* aPath, + const char* registryLocation) +{ + // XXX also delete the stuff I added to the registry + nsresult rv; + + for (PRUint32 i=0; iUnregisterComponentSpec(*(g_FactoryData[i].mCID), aPath); + } + + return NS_OK; +} + +NS_IMETHODIMP nsConverterModule::CanUnload(nsIComponentManager *aCompMgr, + PRBool *okToUnload) +{ + if (!okToUnload) { + return NS_ERROR_INVALID_POINTER; + } + *okToUnload = (g_InstanceCount == 0 && g_LockCount == 0); + return NS_OK; +} + diff --git a/mozilla/intl/uconv/ucvtw2/Makefile.in b/mozilla/intl/uconv/ucvtw2/Makefile.in index 38ca39f62d7..81ed89b0700 100644 --- a/mozilla/intl/uconv/ucvtw2/Makefile.in +++ b/mozilla/intl/uconv/ucvtw2/Makefile.in @@ -39,7 +39,7 @@ CPPSRCS = \ nsUnicodeToCNS11643p6.cpp \ nsUnicodeToCNS11643p7.cpp \ nsUCvTW2Support.cpp \ - nsUCvTW2Dll.cpp \ + nsUCvTw2Module.cpp \ $(NULL) EXPORTS = nsUCvTW2CID.h diff --git a/mozilla/intl/uconv/ucvtw2/makefile.win b/mozilla/intl/uconv/ucvtw2/makefile.win index e79be357a98..a151d581c22 100644 --- a/mozilla/intl/uconv/ucvtw2/makefile.win +++ b/mozilla/intl/uconv/ucvtw2/makefile.win @@ -37,7 +37,7 @@ CPPSRCS = \ nsUnicodeToCNS11643p6.cpp \ nsUnicodeToCNS11643p7.cpp \ nsUCvTW2Support.cpp \ - nsUCvTW2Dll.cpp \ + nsUCvTw2Module.cpp \ $(NULL) CPP_OBJS= \ @@ -51,7 +51,7 @@ CPP_OBJS= \ .\$(OBJDIR)\nsUnicodeToCNS11643p6.obj \ .\$(OBJDIR)\nsUnicodeToCNS11643p7.obj \ .\$(OBJDIR)\nsUCvTW2Support.obj \ - .\$(OBJDIR)\nsUCvTW2Dll.obj \ + .\$(OBJDIR)\nsUCvTw2Module.obj \ $(NULL) EXPORTS=nsUCvTW2CID.h \ diff --git a/mozilla/intl/uconv/ucvtw2/nsUCvTw2Module.cpp b/mozilla/intl/uconv/ucvtw2/nsUCvTw2Module.cpp new file mode 100644 index 00000000000..3d24f8567ad --- /dev/null +++ b/mozilla/intl/uconv/ucvtw2/nsUCvTw2Module.cpp @@ -0,0 +1,478 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + * the License for the specific language governing rights and limitations + * under the License. + * + * The Original Code is Mozilla Communicator client code. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are Copyright (C) 1998 + * Netscape Communications Corporation. All Rights Reserved. + */ + +#define NS_IMPL_IDS + +#include "pratom.h" +#include "nsCOMPtr.h" +#include "nsIFactory.h" +#include "nsIRegistry.h" +#include "nsIServiceManager.h" +#include "nsIModule.h" +#include "nsUCvTW2CID.h" +#include "nsUCvTW2Dll.h" + +#include "nsEUCTWToUnicode.h" +#include "nsUnicodeToEUCTW.h" +#include "nsUnicodeToCNS11643p1.h" +#include "nsUnicodeToCNS11643p2.h" +#include "nsUnicodeToCNS11643p3.h" +#include "nsUnicodeToCNS11643p4.h" +#include "nsUnicodeToCNS11643p5.h" +#include "nsUnicodeToCNS11643p6.h" +#include "nsUnicodeToCNS11643p7.h" + +//---------------------------------------------------------------------------- +// Global functions and data [declaration] + +static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID); + +#define DECODER_NAME_BASE "Unicode Decoder-" +#define ENCODER_NAME_BASE "Unicode Encoder-" + +PRInt32 g_InstanceCount = 0; +PRInt32 g_LockCount = 0; + +PRUint16 g_ASCIIMappingTable[] = { + 0x0001, 0x0004, 0x0005, 0x0008, 0x0000, 0x0000, 0x007F, 0x0000 +}; + +PRUint16 g_ufCNS1MappingTable[] = { +#include "cns_1.uf" +}; + +PRUint16 g_ufCNS2MappingTable[] = { +#include "cns_2.uf" +}; + +PRUint16 g_ufCNS3MappingTable[] = { +#include "cns3.uf" +}; + +PRUint16 g_ufCNS4MappingTable[] = { +#include "cns4.uf" +}; + +PRUint16 g_ufCNS5MappingTable[] = { +#include "cns5.uf" +}; + +PRUint16 g_ufCNS6MappingTable[] = { +#include "cns6.uf" +}; + +PRUint16 g_ufCNS7MappingTable[] = { +#include "cns7.uf" +}; + +PRUint16 g_utCNS1MappingTable[] = { +#include "cns_1.ut" +}; + +PRUint16 g_utCNS2MappingTable[] = { +#include "cns_2.ut" +}; + +PRUint16 g_utCNS3MappingTable[] = { +#include "cns3.ut" +}; + +PRUint16 g_utCNS4MappingTable[] = { +#include "cns4.ut" +}; + +PRUint16 g_utCNS5MappingTable[] = { +#include "cns5.ut" +}; + +PRUint16 g_utCNS6MappingTable[] = { +#include "cns6.ut" +}; + +PRUint16 g_utCNS7MappingTable[] = { +#include "cns7.ut" +}; + +typedef nsresult (* fpCreateInstance) (nsISupports **); + +struct FactoryData +{ + const nsCID * mCID; + fpCreateInstance CreateInstance; + char * mCharsetSrc; + char * mCharsetDest; +}; + +static FactoryData g_FactoryData[] = +{ + { + &kEUCTWToUnicodeCID, + nsEUCTWToUnicode::CreateInstance, + "X-EUC-TW", + "Unicode" + }, + { + &kUnicodeToEUCTWCID, + nsUnicodeToEUCTW::CreateInstance, + "Unicode", + "X-EUC-TW" + }, + { + &kUnicodeToCNS11643p1CID, + nsUnicodeToCNS11643p1::CreateInstance, + "Unicode", + "x-cns-11643-1" + }, + { + &kUnicodeToCNS11643p2CID, + nsUnicodeToCNS11643p2::CreateInstance, + "Unicode", + "x-cns-11643-2" + }, + { + &kUnicodeToCNS11643p3CID, + nsUnicodeToCNS11643p3::CreateInstance, + "Unicode", + "x-cns-11643-3" + }, + { + &kUnicodeToCNS11643p4CID, + nsUnicodeToCNS11643p4::CreateInstance, + "Unicode", + "x-cns-11643-4" + }, + { + &kUnicodeToCNS11643p5CID, + nsUnicodeToCNS11643p5::CreateInstance, + "Unicode", + "x-cns-11643-5" + }, + { + &kUnicodeToCNS11643p6CID, + nsUnicodeToCNS11643p6::CreateInstance, + "Unicode", + "x-cns-11643-6" + }, + { + &kUnicodeToCNS11643p7CID, + nsUnicodeToCNS11643p7::CreateInstance, + "Unicode", + "x-cns-11643-7" + } +}; + +#define ARRAY_SIZE(_array) \ + (sizeof(_array) / sizeof(_array[0])) + +//---------------------------------------------------------------------------- +// Class nsConverterFactory [declaration] + +/** + * General factory class for converter objects. + * + * @created 24/Feb/1998 + * @author Catalin Rotaru [CATA] + */ +class nsConverterFactory : public nsIFactory +{ + NS_DECL_ISUPPORTS + +private: + + FactoryData * mData; + +public: + + /** + * Class constructor. + */ + nsConverterFactory(FactoryData * aData); + + /** + * Class destructor. + */ + virtual ~nsConverterFactory(); + + //-------------------------------------------------------------------------- + // Interface nsIFactory [declaration] + + NS_IMETHOD CreateInstance(nsISupports *aDelegate, const nsIID &aIID, + void **aResult); + NS_IMETHOD LockFactory(PRBool aLock); +}; + +//---------------------------------------------------------------------------- +// Class nsConverterModule [declaration] + +class nsConverterModule : public nsIModule +{ + NS_DECL_ISUPPORTS + NS_DECL_NSIMODULE + +private: + + PRBool mInitialized; + + void Shutdown(); + +public: + + nsConverterModule(); + + virtual ~nsConverterModule(); + + nsresult Initialize(); + +}; + +//---------------------------------------------------------------------------- +// Global functions and data [implementation] + +static nsConverterModule * gModule = NULL; + +extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager * compMgr, + nsIFileSpec* location, + nsIModule** return_cobj) +{ + nsresult rv = NS_OK; + + NS_ENSURE_ARG_POINTER(return_cobj); + NS_ENSURE_NOT(gModule, NS_ERROR_FAILURE); + + // Create an initialize the module instance + nsConverterModule * m = new nsConverterModule(); + if (!m) { + return NS_ERROR_OUT_OF_MEMORY; + } + + // Increase refcnt and store away nsIModule interface to m in return_cobj + rv = m->QueryInterface(nsIModule::GetIID(), (void**)return_cobj); + if (NS_FAILED(rv)) { + delete m; + m = nsnull; + } + gModule = m; // WARNING: Weak Reference + return rv; +} + +//---------------------------------------------------------------------------- +// Class nsConverterFactory [implementation] + +NS_IMPL_ISUPPORTS(nsConverterFactory, nsCOMTypeInfo::GetIID()); + +nsConverterFactory::nsConverterFactory(FactoryData * aData) +{ + mData = aData; + + NS_INIT_REFCNT(); + PR_AtomicIncrement(&g_InstanceCount); +} + +nsConverterFactory::~nsConverterFactory() +{ + PR_AtomicDecrement(&g_InstanceCount); +} + +//---------------------------------------------------------------------------- +// Interface nsIFactory [implementation] + +NS_IMETHODIMP nsConverterFactory::CreateInstance(nsISupports *aDelegate, + const nsIID &aIID, + void **aResult) +{ + if (aResult == NULL) return NS_ERROR_NULL_POINTER; + if (aDelegate != NULL) return NS_ERROR_NO_AGGREGATION; + + nsISupports * t; + mData->CreateInstance(&t); + if (t == NULL) return NS_ERROR_OUT_OF_MEMORY; + + nsresult res = t->QueryInterface(aIID, aResult); + if (NS_FAILED(res)) delete t; + + return res; +} + +NS_IMETHODIMP nsConverterFactory::LockFactory(PRBool aLock) +{ + if (aLock) PR_AtomicIncrement(&g_LockCount); + else PR_AtomicDecrement(&g_LockCount); + + return NS_OK; +} + +//---------------------------------------------------------------------------- +// Class nsConverterModule [implementation] + +NS_IMPL_ISUPPORTS(nsConverterModule, nsIModule::GetIID()) + +nsConverterModule::nsConverterModule() +: mInitialized(PR_FALSE) +{ + NS_INIT_ISUPPORTS(); +} + +nsConverterModule::~nsConverterModule() +{ + Shutdown(); +} + +nsresult nsConverterModule::Initialize() +{ + return NS_OK; +} + +void nsConverterModule::Shutdown() +{ +} + +//---------------------------------------------------------------------------- +// Interface nsIModule [implementation] + +NS_IMETHODIMP nsConverterModule::GetClassObject(nsIComponentManager *aCompMgr, + const nsCID& aClass, + const nsIID& aIID, + void ** r_classObj) +{ + nsresult rv; + + // Defensive programming: Initialize *r_classObj in case of error below + if (!r_classObj) { + return NS_ERROR_INVALID_POINTER; + } + *r_classObj = NULL; + + if (!mInitialized) { + rv = Initialize(); + if (NS_FAILED(rv)) { + return rv; + } + mInitialized = PR_TRUE; + } + + FactoryData * data; + nsConverterFactory * fact; + + // XXX cache these factories + for (PRUint32 i=0; imCID))) { + fact = new nsConverterFactory(data); + if (fact == NULL) { + return NS_ERROR_OUT_OF_MEMORY; + } + rv = fact->QueryInterface(aIID, (void **) r_classObj); + if (NS_FAILED(rv)) delete fact; + + return rv; + } + } + + return NS_ERROR_FACTORY_NOT_REGISTERED; +} + +NS_IMETHODIMP nsConverterModule::RegisterSelf(nsIComponentManager *aCompMgr, + nsIFileSpec* aPath, + const char* registryLocation, + const char* componentType) +{ + nsresult res; + PRUint32 i; + nsIComponentManager * compMgr = NULL; + nsIRegistry * registry = NULL; + nsRegistryKey key; + char buff[1024]; + + // get the registry + res = nsServiceManager::GetService(NS_REGISTRY_PROGID, + nsIRegistry::GetIID(), (nsISupports**)®istry); + if (NS_FAILED(res)) goto done; + + // open the registry + res = registry->OpenWellKnownRegistry( + nsIRegistry::ApplicationComponentRegistry); + if (NS_FAILED(res)) goto done; + + char name[128]; + char progid[128]; + char * cid_string; + for (i=0; iRegisterComponentSpec(*(g_FactoryData[i].mCID), name, + progid, aPath, PR_TRUE, PR_TRUE); + if(NS_FAILED(res) && (NS_ERROR_FACTORY_EXISTS != res)) goto done; + + // register component info + // XXX take these KONSTANTS out of here; refine this code + cid_string = g_FactoryData[i].mCID->ToString(); + sprintf(buff, "%s/%s", "software/netscape/intl/uconv", cid_string); + nsCRT::free(cid_string); + res = registry -> AddSubtree(nsIRegistry::Common, buff, &key); + if (NS_FAILED(res)) goto done; + res = registry -> SetString(key, "source", g_FactoryData[i].mCharsetSrc); + if (NS_FAILED(res)) goto done; + res = registry -> SetString(key, "destination", g_FactoryData[i].mCharsetDest); + if (NS_FAILED(res)) goto done; + } + +done: + if (registry != NULL) { + registry -> Close(); + nsServiceManager::ReleaseService(NS_REGISTRY_PROGID, registry); + } + + return res; +} + +NS_IMETHODIMP nsConverterModule::UnregisterSelf(nsIComponentManager *aCompMgr, + nsIFileSpec* aPath, + const char* registryLocation) +{ + // XXX also delete the stuff I added to the registry + nsresult rv; + + for (PRUint32 i=0; iUnregisterComponentSpec(*(g_FactoryData[i].mCID), aPath); + } + + return NS_OK; +} + +NS_IMETHODIMP nsConverterModule::CanUnload(nsIComponentManager *aCompMgr, + PRBool *okToUnload) +{ + if (!okToUnload) { + return NS_ERROR_INVALID_POINTER; + } + *okToUnload = (g_InstanceCount == 0 && g_LockCount == 0); + return NS_OK; +} +