From 8f0abc6eb344f07028fa232813014d47e4da7452 Mon Sep 17 00:00:00 2001 From: "Unknown (roddey)" <dev-null@apache.org> Date: Wed, 19 Jan 2000 00:57:26 +0000 Subject: [PATCH] Changes to get rid of dependence on old utils standard streams and to get rid of the fgLibLocation stuff. git-svn-id: https://svn.apache.org/repos/asf/xerces/c/trunk@171595 13f79535-47bb-0310-9956-ffa450edef68 --- src/util/HeaderDummy.cpp | 9 +- src/util/PlatformUtils.cpp | 16 +- src/util/PlatformUtils.hpp | 20 +- .../Platforms/Win32/Win32PlatformUtils.cpp | 267 ++---------------- src/util/TransService.cpp | 155 +--------- src/util/XMLString.cpp | 5 +- src/util/XMLURL.cpp | 10 +- 7 files changed, 46 insertions(+), 436 deletions(-) diff --git a/src/util/HeaderDummy.cpp b/src/util/HeaderDummy.cpp index 6e1fa0321..581e62871 100644 --- a/src/util/HeaderDummy.cpp +++ b/src/util/HeaderDummy.cpp @@ -56,8 +56,12 @@ /** * $Log$ - * Revision 1.1 1999/11/09 01:04:18 twl - * Initial revision + * Revision 1.2 2000/01/19 00:56:59 roddey + * Changes to get rid of dependence on old utils standard streams and to + * get rid of the fgLibLocation stuff. + * + * Revision 1.1.1.1 1999/11/09 01:04:18 twl + * Initial checkin * * Revision 1.2 1999/11/08 20:45:07 rahul * Swat for adding in Product name and CVS comment log variable. @@ -77,7 +81,6 @@ #include <util/NullPointerException.hpp> #include <util/PlatformUtils.hpp> #include <util/RuntimeException.hpp> -#include <util/TextOutputStream.hpp> #include <util/UnexpectedEOFException.hpp> #include <util/UnsupportedEncodingException.hpp> #include <util/UTFDataFormatException.hpp> diff --git a/src/util/PlatformUtils.cpp b/src/util/PlatformUtils.cpp index 735029cb4..c6b58bbff 100644 --- a/src/util/PlatformUtils.cpp +++ b/src/util/PlatformUtils.cpp @@ -56,6 +56,10 @@ /** * $Log$ + * Revision 1.4 2000/01/19 00:56:59 roddey + * Changes to get rid of dependence on old utils standard streams and to + * get rid of the fgLibLocation stuff. + * * Revision 1.3 1999/12/18 00:18:10 roddey * More changes to support the new, completely orthagonal support for * intrinsic encodings. @@ -97,7 +101,6 @@ static XMLMutex* gMsgMutex = 0; // --------------------------------------------------------------------------- // XMLPlatformUtils: Static Data Members // --------------------------------------------------------------------------- -const char* XMLPlatformUtils::fgLibLocation = 0; bool XMLPlatformUtils::fgInitFlag = false; XMLNetAccessor* XMLPlatformUtils::fgNetAccessor = 0; XMLTransService* XMLPlatformUtils::fgTransService = 0; @@ -128,10 +131,6 @@ void XMLPlatformUtils::Initialize() // level per-platform setup. It cannot use any XML util services at all, // i.e. only native services. // - // One important thing it does is to set the fgLibLocation string, which - // can be used by any subsequent init code that needs to find stuff - // relative to the lib/DLL. - // platformInit(); // @@ -164,13 +163,10 @@ void XMLPlatformUtils::Initialize() // // Now lets ask the per-platform code to give us an instance of the type - // of network access implementation he wants to use. + // of network access implementation he wants to use. This can return + // a zero pointer if this platform doesn't want to support this. // fgNetAccessor = makeNetAccessor(); - if (!fgNetAccessor) - { - // <TBD> For now its returning a null, but later this will be required - } } diff --git a/src/util/PlatformUtils.hpp b/src/util/PlatformUtils.hpp index 46be8c764..c46ecadb2 100644 --- a/src/util/PlatformUtils.hpp +++ b/src/util/PlatformUtils.hpp @@ -56,6 +56,10 @@ /** * $Log$ + * Revision 1.3 2000/01/19 00:56:59 roddey + * Changes to get rid of dependence on old utils standard streams and to + * get rid of the fgLibLocation stuff. + * * Revision 1.2 2000/01/12 00:16:22 roddey * Changes to deal with multiply nested, relative pathed, entities and to deal * with the new URL class changes. @@ -125,16 +129,9 @@ public : // This is the transcoding service. This is provided by the per // platform driver, so each platform can choose what implemenation // it wants to use. - // - // fgLibLocation - // This is the location of the shared library or DLL. For some - // platforms, it might be some fixed directory and others will - // discover it dynamically. All other needed stuff is relative to - // this path. // ----------------------------------------------------------------------- static XMLNetAccessor* fgNetAccessor; static XMLTransService* fgTransService; - static const char* fgLibLocation; // ----------------------------------------------------------------------- @@ -177,15 +174,6 @@ public : static void resetFile(FileHandle theFile); - // ----------------------------------------------------------------------- - // Standard out/error support - // ----------------------------------------------------------------------- - static void writeToStdErr(const char* const toWrite); - static void writeToStdErr(const XMLCh* const toWrite); - static void writeToStdOut(const XMLCh* const toWrite); - static void writeToStdOut(const char* const toWrite); - - // ----------------------------------------------------------------------- // File system methods // ----------------------------------------------------------------------- diff --git a/src/util/Platforms/Win32/Win32PlatformUtils.cpp b/src/util/Platforms/Win32/Win32PlatformUtils.cpp index 9fd9f22ad..66927967d 100644 --- a/src/util/Platforms/Win32/Win32PlatformUtils.cpp +++ b/src/util/Platforms/Win32/Win32PlatformUtils.cpp @@ -56,6 +56,10 @@ /** * $Log$ + * Revision 1.7 2000/01/19 00:57:26 roddey + * Changes to get rid of dependence on old utils standard streams and to + * get rid of the fgLibLocation stuff. + * * Revision 1.6 2000/01/15 01:26:18 rahulj * Added support for HTTP to the parser using libWWW 5.2.8. * Renamed URL.[ch]pp to XMLURL.[ch]pp and like wise for the class name. @@ -95,6 +99,11 @@ #include <util/XMLUni.hpp> #include <windows.h> +// +// These control which transcoding service is used by the Win32 version. +// They allow this to be controlled from the build process by just defining +// one of these values. +// #if defined (XML_USE_ICU_TRANSCODER) #include <util/Transcoders/ICU/ICUTransService.hpp> #elif defined (XML_USE_WIN32_TRANSCODER) @@ -103,6 +112,11 @@ #error A transcoding service must be chosen #endif +// +// These control which message loading service is used by the Win32 version. +// They allow this to be controlled from the build process by just defining +// one of these values. +// #if defined (XML_USE_INMEMORY_MSGLOADER) #include <util/MsgLoaders/InMemory/InMemMsgLoader.hpp> #elif defined (XML_USE_WIN32_MSGLOADER) @@ -111,151 +125,25 @@ #error A message loading service must be chosen #endif - +// +// These control which network access service is used by the Win32 version. +// They allow this to be controlled from the build process by just defining +// one of these values. +// #if defined (XML_USE_NETACCESSOR_LIBWWW) #include <util/NetAccessors/LibWWWNetAccessor.hpp> #endif + // --------------------------------------------------------------------------- // Local data // // gOnNT // We figure out during init if we are on NT or not. If we are, then // we can avoid a lot of transcoding in our system services stuff. -// -// gStdErr -// gStdOut -// The file handles for standard error and standard out. We set these -// up during init. Note that they can be zero if there are no std -// handles, -// -// gStdErrRedir -// gStdOutRedir -// These flags are set to indicate whether their respective output -// handles are redirected. If they are not, then we can use console -// APIs on NT to write Unicode straight to the output. Otherwise we have -// to use file APIs, and we transcode it. // --------------------------------------------------------------------------- static bool gOnNT; -static HANDLE gStdErr; -static bool gStdErrRedir; -static HANDLE gStdOut; -static bool gStdOutRedir; - - -// --------------------------------------------------------------------------- -// Local methods -// --------------------------------------------------------------------------- -static void WriteCharStrStdErr(const char* const toWrite) -{ - // We always just use the file APIs for these - DWORD written; - if (!::WriteFile - ( - gStdErr - , toWrite - , strlen(toWrite) - , &written - , 0)) - { - // - // If if fails due to an invalid handle, then just assume that our - // handles were disconnected and zero it out. This will prevent us - // from getting called again. - // - if (::GetLastError() == ERROR_INVALID_HANDLE) - gStdErr = 0; - else - ThrowXML(XMLPlatformUtilsException, XML4CExcepts::Strm_StdErrWriteFailure); - } -} - - -static void WriteCharStrStdOut(const char* const toWrite) -{ - // We always just use the file APIs for these - DWORD written; - if (!::WriteFile - ( - gStdOut - , toWrite - , strlen(toWrite) - , &written - , 0)) - { - // - // If if fails due to an invalid handle, then just assume that our - // handles were disconnected and zero it out. This will prevent us - // from getting called again. - // - if (::GetLastError() == ERROR_INVALID_HANDLE) - gStdOut = 0; - else - ThrowXML(XMLPlatformUtilsException, XML4CExcepts::Strm_StdOutWriteFailure); - } -} - - -static void WriteUStrStdErr(const XMLCh* const toWrite) -{ - // - // If we are on NT and the handle is not redirected, then we can use - // the console API directly to send out Unicode. Otherwise we have to - // use the file APIs and transcode. - // - DWORD written; - if (gOnNT && !gStdErrRedir) - { - if (!::WriteConsoleW - ( - gStdErr - , toWrite - , XMLString::stringLen(toWrite) - , &written - , 0)) - { - ThrowXML(XMLPlatformUtilsException, XML4CExcepts::Strm_ConWriteFailure); - } - return; - } - - // Oh well, got to do it the hard way - char* tmpVal = XMLString::transcode(toWrite); - ArrayJanitor<char> janTmp(tmpVal); - WriteCharStrStdErr(tmpVal); -} - - -static void WriteUStrStdOut(const XMLCh* const toWrite) -{ - // - // If we are on NT and the handle is not redirected, then we can use - // the console API directly to send out Unicode. Otherwise we have to - // use the file APIs and transcode. - // - DWORD written; - if (gOnNT && !gStdOutRedir) - { - if (!::WriteConsoleW - ( - gStdOut - , toWrite - , XMLString::stringLen(toWrite) - , &written - , 0)) - { - ThrowXML(XMLPlatformUtilsException, XML4CExcepts::Strm_ConWriteFailure); - } - return; - } - - // Oh well, got to do it the hard way - char* tmpVal = XMLString::transcode(toWrite); - ArrayJanitor<char> janTmp(tmpVal); - WriteCharStrStdOut(tmpVal); -} - // --------------------------------------------------------------------------- @@ -436,39 +324,6 @@ void XMLPlatformUtils::resetFile(FileHandle theFile) } -// --------------------------------------------------------------------------- -// XMLPlatformUtils: File Methods -// --------------------------------------------------------------------------- -void XMLPlatformUtils::writeToStdErr(const XMLCh* const toWrite) -{ - // If handles never got opened, then eat the output, else output - if (gStdErr) - WriteUStrStdErr(toWrite); -} - -void XMLPlatformUtils::writeToStdErr(const char* const toWrite) -{ - // If handles never got opened, then eat the output, else output - if (gStdErr) - WriteCharStrStdErr(toWrite); -} - -void XMLPlatformUtils::writeToStdOut(const XMLCh* const toWrite) -{ - // If handles never got opened, then eat the output, else output - if (gStdOut) - WriteUStrStdOut(toWrite); -} - -void XMLPlatformUtils::writeToStdOut(const char* const toWrite) -{ - // If handles never got opened, then eat the output, else output - if (gStdOut) - WriteCharStrStdOut(toWrite); -} - - - // --------------------------------------------------------------------------- // XMLPlatformUtils: File system methods // --------------------------------------------------------------------------- @@ -773,9 +628,8 @@ int XMLPlatformUtils::atomicDecrement(int &location) // // This method is called by the platform independent part of this class // during initialization. We have to create the type of net accessor that -// we want to use. +// we want to use. If none, then just return zero. // - XMLNetAccessor* XMLPlatformUtils::makeNetAccessor() { #if defined (XML_USE_NETACCESSOR_LIBWWW) @@ -818,13 +672,6 @@ XMLTransService* XMLPlatformUtils::makeTransService() // to our DLL. // #if defined (XML_USE_ICU_TRANSCODER) - char tmpBuf[4096]; - if (!::GetEnvironmentVariableA("ICU_DATA", tmpBuf, 4096)) - { - strcpy(tmpBuf, fgLibLocation); - strcat(tmpBuf, "icu\\data\\"); - ICUTransService::setICUPath(tmpBuf); - } return new ICUTransService; #elif defined (XML_USE_WIN32_TRANSCODER) return new Win32TransService; @@ -841,48 +688,6 @@ XMLTransService* XMLPlatformUtils::makeTransService() // void XMLPlatformUtils::platformInit() { - // - // Lets get our own DLL path and store it. The fgLibLocation static - // member must be filled in with the path to the shared Lib or DLL - // so that other code can find any files relative to it. - // - HINSTANCE hmod = ::GetModuleHandleA(XML4C_DLLName); - if (!hmod) - { - // - // If we didn't find it, its probably because its a development - // build which is built as separate DLLs, so lets look for the DLL - // that we are part of. - // - static const char* const privDLLName = "IXUTIL"; - hmod = ::GetModuleHandle(privDLLName); - - // If neither exists, then we give up - if (!hmod) - panic(Panic_CantFindLib); - } - - // - // Get the path to our module. We explicitly get the ASCII version here - // since its stored as ASCII (or the local code page to be more specific, - // so it might be EBCDIC on some platforms.) - // - char tmpBuf[MAX_PATH + 1]; - if (!::GetModuleFileNameA(hmod, tmpBuf, MAX_PATH)) - panic(Panic_CantFindLib); - - // Find the last separator in the list and put a null in the next char - char* sepPtr = 0; - sepPtr = strrchr(tmpBuf, '\\'); - if (sepPtr) - *(sepPtr+1)= 0; - const unsigned int pathLen = strlen(tmpBuf); - - // Allocate a buffer and copy the text into it. Then store it in the static - char* actualBuf = new char[pathLen + 1]; - strcpy(actualBuf, tmpBuf); - fgLibLocation = actualBuf; - // // Figure out if we are on NT and save that flag for later use. // @@ -890,34 +695,4 @@ void XMLPlatformUtils::platformInit() OSVer.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); ::GetVersionEx(&OSVer); gOnNT = (OSVer.dwPlatformId == VER_PLATFORM_WIN32_NT); - - // - // Ok, we have to do a little dance here to determine if we have any - // standard output handles. First we open up the potentially redirected - // standard handles. - // - gStdOut = ::GetStdHandle(STD_OUTPUT_HANDLE); - gStdErr = ::GetStdHandle(STD_ERROR_HANDLE); - - // - // If we got the handles, then get the console mode for them. If this - // fails, then assume for the time being that they are just redirected - // files. - // - // Above, when they are actually used, if they fail because of an - // invalid handle error, the gStdOut and gStdErr handles will get zeroed - // out all further output will be eaten. - // - DWORD dummyParm; - if (gStdOut) - { - if (!::GetConsoleMode(gStdOut, &dummyParm)) - gStdOutRedir = true; - } - - if (gStdErr) - { - if (!::GetConsoleMode(gStdErr, &dummyParm)) - gStdErrRedir = true; - } } diff --git a/src/util/TransService.cpp b/src/util/TransService.cpp index 7c7f27a23..e86e793a5 100644 --- a/src/util/TransService.cpp +++ b/src/util/TransService.cpp @@ -68,163 +68,10 @@ #include <util/XMLUTF8Transcoder.hpp> #include <util/XMLUTF16Transcoder.hpp> #include <util/XMLUni.hpp> +#include <util/TransENameMap.hpp> -// --------------------------------------------------------------------------- -// Local types -// -// This class is a very simple class used to hold mappings from encoding -// names to factory methods for our intrinsic transcoders. This allows us -// to quickly find one of these objects, via a hash table, and invoke the -// factory to create the appropriate type of transcoder. -// -// Derived from it is a simple templatized class that lets us provide the -// correct implementation of the virtual factory method. -// --------------------------------------------------------------------------- -class ENameMap -{ -public : - // ----------------------------------------------------------------------- - // Destructor - // ----------------------------------------------------------------------- - ~ENameMap() - { - delete [] fEncodingName; - } - - - // ----------------------------------------------------------------------- - // Virtual factory method - // ----------------------------------------------------------------------- - virtual XMLTranscoder* makeNew - ( - const unsigned int blockSize - ) const = 0; - - - // ----------------------------------------------------------------------- - // Getter methods - // ----------------------------------------------------------------------- - const XMLCh* getKey() const - { - return fEncodingName; - } - - -protected : - // ----------------------------------------------------------------------- - // Hidden constructors - // ----------------------------------------------------------------------- - ENameMap(const XMLCh* const encodingName) : - - fEncodingName(XMLString::replicate(encodingName)) - { - } - - - ENameMap(){}; -private : - // ----------------------------------------------------------------------- - // Unimplemented constructors and operators - // ----------------------------------------------------------------------- - ENameMap(const ENameMap&); - void operator=(const ENameMap&); - - - // ----------------------------------------------------------------------- - // Private data members - // - // fEncodingName - // This is the encoding name for the transcoder that is controlled - // by this map instance. - // ----------------------------------------------------------------------- - XMLCh* fEncodingName; -}; - - -template <class TType> class ENameMapFor : public ENameMap -{ -public : - // ----------------------------------------------------------------------- - // Constructors and Destructor - // ----------------------------------------------------------------------- - ENameMapFor(const XMLCh* const encodingName) : - - ENameMap(encodingName) - { - } - - ~ENameMapFor() - { - } - - - // ----------------------------------------------------------------------- - // Implementation of virtual factory method - // ----------------------------------------------------------------------- - virtual XMLTranscoder* makeNew(const unsigned int blockSize) const - { - return new TType(getKey(), blockSize); - } - - -private : - // ----------------------------------------------------------------------- - // Unimplemented constructors and operators - // ----------------------------------------------------------------------- - ENameMapFor(){}; - ENameMapFor(const ENameMapFor<TType>&){}; - void operator=(const ENameMapFor<TType>&){}; -}; - - -template <class TType> class EEndianNameMapFor : public ENameMap -{ -public : - // ----------------------------------------------------------------------- - // Constructors and Destructor - // ----------------------------------------------------------------------- - EEndianNameMapFor(const XMLCh* const encodingName, const bool swapped) : - - ENameMap(encodingName) - , fSwapped(swapped) - { - } - - ~EEndianNameMapFor() - { - } - - - // ----------------------------------------------------------------------- - // Implementation of virtual factory method - // ----------------------------------------------------------------------- - virtual XMLTranscoder* makeNew(const unsigned int blockSize) const - { - return new TType(getKey(), blockSize, fSwapped); - } - - -private : - // ----------------------------------------------------------------------- - // Unimplemented constructors and operators - // ----------------------------------------------------------------------- - EEndianNameMapFor(const EEndianNameMapFor<TType>&); - void operator=(const EEndianNameMapFor<TType>&); - - - // ----------------------------------------------------------------------- - // Private data members - // - // fSwapped - // Indicates whether the endianess of the encoding is opposite of - // that of the local host. - // ----------------------------------------------------------------------- - bool fSwapped; -}; - - // --------------------------------------------------------------------------- // Local, static data // diff --git a/src/util/XMLString.cpp b/src/util/XMLString.cpp index 3296c7a02..0af6c1d87 100644 --- a/src/util/XMLString.cpp +++ b/src/util/XMLString.cpp @@ -56,6 +56,10 @@ /** * $Log$ + * Revision 1.5 2000/01/19 00:56:59 roddey + * Changes to get rid of dependence on old utils standard streams and to + * get rid of the fgLibLocation stuff. + * * Revision 1.4 2000/01/12 00:16:23 roddey * Changes to deal with multiply nested, relative pathed, entities and to deal * with the new URL class changes. @@ -86,7 +90,6 @@ #include <util/IllegalArgumentException.hpp> #include <util/Janitor.hpp> #include <util/PlatformUtils.hpp> -#include <util/StdOut.hpp> #include <util/RuntimeException.hpp> #include <util/TransService.hpp> #include <util/TranscodingException.hpp> diff --git a/src/util/XMLURL.cpp b/src/util/XMLURL.cpp index b64106b9d..9f740eb8a 100644 --- a/src/util/XMLURL.cpp +++ b/src/util/XMLURL.cpp @@ -56,6 +56,10 @@ /** * $Log$ + * Revision 1.3 2000/01/19 00:56:59 roddey + * Changes to get rid of dependence on old utils standard streams and to + * get rid of the fgLibLocation stuff. + * * Revision 1.2 2000/01/17 23:38:06 abagchi * Changed string "localhost" to XMLUni::fgLocalHostString * @@ -139,12 +143,6 @@ static const XMLCh gHTTPString[] = chLatin_h, chLatin_t, chLatin_t, chLatin_p, chNull }; -static const XMLCh gLocalHostString[] = -{ - chLatin_l, chLatin_o, chLatin_c, chLatin_a, chLatin_l - , chLatin_h, chLatin_o, chLatin_s, chLatin_t, chNull -}; - static TypeEntry gTypeList[XMLURL::Protocols_Count] = { { XMLURL::File , gFileString } -- GitLab