Skip to content
Snippets Groups Projects
MacOSPlatformUtils.cpp 45.9 KiB
Newer Older
PeiYong Zhang's avatar
PeiYong Zhang committed
/*
 * Copyright 1999-2000,2004 The Apache Software Foundation.
 * 
 * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
PeiYong Zhang's avatar
PeiYong Zhang committed
 */

/*
 * $Id$
 */


// ---------------------------------------------------------------------------
//  Includes
// ---------------------------------------------------------------------------
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <cstdio>
#include <memory>
#include <algorithm>
#include <unistd.h>

#if defined(__APPLE__)
    //	Include from Frameworks Headers under ProjectBuilder
    #include <Carbon/Carbon.h>
#else
    //	Classic include styles
    #include <Files.h>
    #include <Gestalt.h>
    #include <TextUtils.h>
    #include <TextEncodingConverter.h>
    #include <Multiprocessing.h>
    #include <DriverSynchronization.h>
    #include <DriverServices.h>
    #include <CFString.h>
    #include <URLAccess.h>
#endif

#include <xercesc/util/XercesDefs.hpp>
PeiYong Zhang's avatar
PeiYong Zhang committed
#include <xercesc/util/Janitor.hpp>
#include <xercesc/util/PlatformUtils.hpp>
#include <xercesc/util/RuntimeException.hpp>
#include <xercesc/util/XMLUniDefs.hpp>
#include <xercesc/util/XMLUni.hpp>
#include <xercesc/util/XMLString.hpp>
#include <xercesc/util/Platforms/MacOS/MacOSPlatformUtils.hpp>
#include <xercesc/util/Platforms/MacOS/MacCarbonFile.hpp>
#include <xercesc/util/Platforms/MacOS/MacPosixFile.hpp>
PeiYong Zhang's avatar
PeiYong Zhang committed
#include <xercesc/util/PanicHandler.hpp>
#include <xercesc/util/OutOfMemoryException.hpp>
PeiYong Zhang's avatar
PeiYong Zhang committed

#if (defined(XML_USE_INMEMORY_MSGLOADER) || defined(XML_USE_INMEM_MESSAGELOADER))
   #include <xercesc/util/MsgLoaders/InMemory/InMemMsgLoader.hpp>
#endif

#if defined(XML_USE_ICU_TRANSCODER)
   #include <xercesc/util/Transcoders/ICU/ICUTransService.hpp>
#elif (defined(XML_USE_MACOS_UNICODECONVERTER) || defined(XML_USE_NATIVE_TRANSCODER))
PeiYong Zhang's avatar
PeiYong Zhang committed
   #include <xercesc/util/Transcoders/MacOSUnicodeConverter/MacOSUnicodeConverter.hpp>
#endif

//	Make up our minds about which netaccessor we'll use
#if (defined(XML_USE_NETACCESSOR_URLACCESSCF) || (defined(XML_USE_NETACCESSOR_NATIVE) && TARGET_API_MAC_CARBON))
    #define USE_URLACCESSCF
#elif (defined(XML_USE_NETACCESSOR_URLACCESS) || (defined(XML_USE_NETACCESSOR_NATIVE) && !TARGET_API_MAC_CARBON))
    #define USE_URLACCESS
#endif

#if defined(USE_URLACCESSCF)
   #include <xercesc/util/NetAccessors/MacOSURLAccessCF/MacOSURLAccessCF.hpp>
#elif defined(USE_URLACCESS)
PeiYong Zhang's avatar
PeiYong Zhang committed
   #include <xercesc/util/NetAccessors/MacOSURLAccess/MacOSURLAccess.hpp>
#elif defined(XML_USE_NETACCESSOR_SOCKET)
   #include <xercesc/util/NetAccessors/Socket/SocketNetAccessor.hpp>
PeiYong Zhang's avatar
PeiYong Zhang committed
#endif

Tinny Ng's avatar
Tinny Ng committed
XERCES_CPP_NAMESPACE_BEGIN
PeiYong Zhang's avatar
PeiYong Zhang committed

//----------------------------------------------------------------------------
// Function Prototypes
//----------------------------------------------------------------------------
XMLCh*	ConvertColonToSlash(XMLCh* p, std::size_t charCount);
XMLCh*	ConvertSlashToColon(XMLCh* p, std::size_t charCount);
char*	ConvertSlashToColon(char* p, std::size_t charCount);

XMLCh*	XMLCreateFullPathFromFSRef_X(const FSRef& startingRef, MemoryManager* const manager);
XMLCh*	XMLCreateFullPathFromFSRef_Classic(const FSRef& startingRef, MemoryManager* const manager);
XMLCh*	XMLCreateFullPathFromFSSpec_Classic(const FSSpec& startingSpec,
                                            MemoryManager* const manager);
bool	XMLParsePathToFSRef_X(const XMLCh* const pathName, FSRef& ref, MemoryManager* const manager);
bool	XMLParsePathToFSRef_Classic(const XMLCh* const pathName, FSRef& ref, MemoryManager* const manager);
bool	XMLParsePathToFSSpec_Classic(const XMLCh* const pathName, FSSpec& spec, MemoryManager* const manager);
PeiYong Zhang's avatar
PeiYong Zhang committed


//----------------------------------------------------------------------------
//  Local Data
//
//  gFileSystemCompatible
//   This flag indicates whether the file system APIs meet our minimum
//   requirements.
//
//  gMacOSXOrBetter
//   The system version is >= 10.
//
PeiYong Zhang's avatar
PeiYong Zhang committed
// gHasFSSpecAPIs
//   True if the FSSpecAPIs are available. These are required.
//
// gHasF2TBAPIs
//   True if the FS supports 2 terrabyte calls. These are required for
//   use under Carbon.
//
// gHasHFSPlusAPIs
//   True if the FS supports HFSPlus APIs. If this is true, then the
//   new Fork calls are used, and all file name and path handling
//   uses long unicode names. Note that once a file is opened with
//   the fork calls, only fork calls may be used to access it.
//
// gHasFSPathAPIs
//   True if the FS supports path creation APIs FSPathMakeRef and
//	 FSRefMakePath.
//
// gPathAPIsUsePosixPaths
//   True if the path creation APIs FSPathMakeRef and FSRefMakePath
//	 use posix, rather than HFS, style paths. If so, these routines
//	 are used to support path creation and  interpretation.
PeiYong Zhang's avatar
PeiYong Zhang committed
//
// gHasMPAPIs
//	 True if the Multiprocessing APIs are available.
//
// gUsePosixFiles
//   True if we're using XMLMacPosixFile rather than XMLMacCarbonFile.
//
// gUseGETCWD
//   True if we can rely on getcwd to get the current directory path.
PeiYong Zhang's avatar
PeiYong Zhang committed
//----------------------------------------------------------------------------
bool gFileSystemCompatible	= false;
bool gHasFSSpecAPIs			= false;
bool gHasFS2TBAPIs			= false;
bool gHasHFSPlusAPIs		= false;
bool gHasFSPathAPIs			= false;
bool gPathAPIsUsePosixPaths	= false;
bool gHasMPAPIs				= false;
bool gUsePosixFiles			= false;
PeiYong Zhang's avatar
PeiYong Zhang committed


// ---------------------------------------------------------------------------
//  XMLPlatformUtils: The panic method
// ---------------------------------------------------------------------------
PeiYong Zhang's avatar
PeiYong Zhang committed
void 
XMLPlatformUtils::panic(const PanicHandler::PanicReasons reason)
PeiYong Zhang's avatar
PeiYong Zhang committed
{
    if (fgUserPanicHandler)
		fgUserPanicHandler->panic(reason);
	else
		fgDefaultPanicHandler->panic(reason);
PeiYong Zhang's avatar
PeiYong Zhang committed
}


// ---------------------------------------------------------------------------
//  XMLPlatformUtils: File Methods
// ---------------------------------------------------------------------------
unsigned int
XMLPlatformUtils::curFilePos(const FileHandle theFile
                             , MemoryManager* const manager)
PeiYong Zhang's avatar
PeiYong Zhang committed
{
	return reinterpret_cast<XMLMacAbstractFile*>(theFile)->currPos();
PeiYong Zhang's avatar
PeiYong Zhang committed
}

void
XMLPlatformUtils::closeFile(const FileHandle theFile
                            , MemoryManager* const manager)
PeiYong Zhang's avatar
PeiYong Zhang committed
{
    reinterpret_cast<XMLMacAbstractFile*>(theFile)->close();
	delete reinterpret_cast<XMLMacAbstractFile*>(theFile);
PeiYong Zhang's avatar
PeiYong Zhang committed
}

unsigned int
XMLPlatformUtils::fileSize(const FileHandle theFile
                           , MemoryManager* const manager)
PeiYong Zhang's avatar
PeiYong Zhang committed
{
    return reinterpret_cast<XMLMacAbstractFile*>(theFile)->size();
PeiYong Zhang's avatar
PeiYong Zhang committed
}


FileHandle
XMLPlatformUtils::openFile(const char* const fileName
                           , MemoryManager* const manager)
PeiYong Zhang's avatar
PeiYong Zhang committed
{
Loading
Loading full blame...