You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by ab...@locus.apache.org on 2000/04/03 21:27:19 UTC
cvs commit: xml-xerces/c/src/util/Platforms/IRIX IRIXPlatformUtils.cpp
abagchi 00/04/03 12:27:19
Modified: c/src/util/Platforms/IRIX IRIXPlatformUtils.cpp
Log:
Included changes for SGI IRIX 6.5
Revision Changes Path
1.9 +142 -158 xml-xerces/c/src/util/Platforms/IRIX/IRIXPlatformUtils.cpp
Index: IRIXPlatformUtils.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/util/Platforms/IRIX/IRIXPlatformUtils.cpp,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- IRIXPlatformUtils.cpp 2000/03/02 21:10:36 1.8
+++ IRIXPlatformUtils.cpp 2000/04/03 19:27:19 1.9
@@ -1,37 +1,37 @@
/*
* The Apache Software License, Version 1.1
- *
+ *
* Copyright (c) 1999-2000 The Apache Software Foundation. All rights
* reserved.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
+ * notice, this list of conditions and the following disclaimer.
+ *
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
- *
+ *
* 3. The end-user documentation included with the redistribution,
- * if any, must include the following acknowledgment:
+ * if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
- *
+ *
* 4. The names "Xerces" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
- * software without prior written permission. For written
+ * software without prior written permission. For written
* permission, please contact apache\@apache.org.
- *
+ *
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
- *
+ *
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
@@ -45,7 +45,7 @@
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
- *
+ *
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation, and was
* originally based on software copyright (c) 1999, International
@@ -56,6 +56,9 @@
/*
* $Log: IRIXPlatformUtils.cpp,v $
+ * Revision 1.9 2000/04/03 19:27:19 abagchi
+ * Included changes for SGI IRIX 6.5
+ *
* Revision 1.8 2000/03/02 21:10:36 abagchi
* Added empty function platformTerm()
*
@@ -95,7 +98,7 @@
// Includes
// ---------------------------------------------------------------------------
-#ifndef APP_NO_THREADS
+#if !defined(APP_NO_THREADS)
#include <pthread.h>
#endif
@@ -103,7 +106,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
-#include <libgen.h>
+#include <sys/param.h>
#include <sys/timeb.h>
#include <string.h>
#include <util/PlatformUtils.hpp>
@@ -113,7 +116,6 @@
#include <util/XMLString.hpp>
#include <util/XMLUni.hpp>
-
#if defined(XML_USE_ICU_TRANSCODER)
#include <util/Transcoders/ICU/ICUTransService.hpp>
#else
@@ -124,14 +126,18 @@
#if defined(XML_USE_ICU_MESSAGELOADER)
#include <util/MsgLoaders/ICU/ICUMsgLoader.hpp>
-
#else
// Same as -DXML_USE_INMEM_MESSAGELOADER
#include <util/MsgLoaders/InMemory/InMemMsgLoader.hpp>
#endif
+#if defined (XML_USE_NETACCESSOR_SOCKET)
+ #include <util/NetAccessors/Socket/SocketNetAccessor.hpp>
+#endif
+
+
// ---------------------------------------------------------------------------
// Local Methods
// ---------------------------------------------------------------------------
@@ -169,40 +175,19 @@
XMLNetAccessor* XMLPlatformUtils::makeNetAccessor()
{
+#if defined (XML_USE_NETACCESSOR_SOCKET)
+ return new SocketNetAccessor();
+#else
return 0;
+#endif
}
-
-// -----------------------------------------------------------------------
-// Standard out/error support
-// -----------------------------------------------------------------------
-
-void XMLPlatformUtils::writeToStdErr(const char* const toWrite)
-{
- WriteCharStr(stderr, toWrite);
-}
-void XMLPlatformUtils::writeToStdErr(const XMLCh* const toWrite)
-{
- WriteUStrStdErr(toWrite);
-}
-void XMLPlatformUtils::writeToStdOut(const XMLCh* const toWrite)
-{
- WriteUStrStdOut(toWrite);
-}
-void XMLPlatformUtils::writeToStdOut(const char* const toWrite)
-{
- WriteCharStr(stdout, toWrite);
-}
-
-
// ---------------------------------------------------------------------------
// XMLPlatformUtils: Platform init method
// ---------------------------------------------------------------------------
static XMLMutex atomicOpsMutex;
-
-
void XMLPlatformUtils::platformInit()
{
//
@@ -211,74 +196,113 @@
// circular dependency between compareAndExchange() and
// mutex creation that must be broken.
atomicOpsMutex.fHandle = XMLPlatformUtils::makeMutex();
+}
- // Here you would also set the fgLibLocation global variable
- // XMLPlatformUtils::fgLibLocation is the variable to be set
-
- static const char* sharedLibEnvVar = "LD_LIBRARY_PATH";
- char* libraryPath = 0;
- char libName[256];
-
- // Construct the library name from the global variables
-
- strcpy(libName, Xerces_DLLName);
- strcat(libName, gXercesVersionStr);
- strcat(libName, ".so");
- char* libEnvVar = getenv(sharedLibEnvVar);
- char* libPath = NULL;
+XMLCh* XMLPlatformUtils::weavePaths(const XMLCh* const basePath
+ , const XMLCh* const relativePath)
- if (libEnvVar == NULL)
- {
- panic(XMLPlatformUtils::Panic_CantFindLib);
- }
+{
+ // Create a buffer as large as both parts and empty it
+ XMLCh* tmpBuf = new XMLCh[XMLString::stringLen(basePath)
+ + XMLString::stringLen(relativePath)
+ + 2];
+ *tmpBuf = 0;
//
- // Its necessary to create a copy because strtok() modifies the
- // string as it returns tokens. We don't want to modify the string
- // returned to by getenv().
+ // If we have no base path, then just take the relative path as
+ // is.
//
+ if (!basePath)
+ {
+ XMLString::copyString(tmpBuf, relativePath);
+ return tmpBuf;
+ }
- libPath = new char[strlen(libEnvVar) + 1];
- strcpy(libPath, libEnvVar);
+ if (!*basePath)
+ {
+ XMLString::copyString(tmpBuf, relativePath);
+ return tmpBuf;
+ }
+ const XMLCh* basePtr = basePath + (XMLString::stringLen(basePath) - 1);
+ if ((*basePtr != chForwardSlash)
+ && (*basePtr != chBackSlash))
+ {
+ while ((basePtr >= basePath)
+ && ((*basePtr != chForwardSlash) && (*basePtr != chBackSlash)))
+ {
+ basePtr--;
+ }
+ }
- // First do the searching process for the first directory listing
+ // There is no relevant base path, so just take the relative part
+ if (basePtr < basePath)
+ {
+ XMLString::copyString(tmpBuf, relativePath);
+ return tmpBuf;
+ }
- char* allPaths = libPath;
- char* libPathName;
+ // After this, make sure the buffer gets handled if we exit early
+ ArrayJanitor<XMLCh> janBuf(tmpBuf);
- while ((libPathName = strtok(allPaths, ":")) != NULL)
+ //
+ // We have some path part, so we need to check to see if we ahve to
+ // weave any of the parts together.
+ //
+ const XMLCh* pathPtr = relativePath;
+ while (true)
{
- FILE* dummyFptr = 0;
- allPaths = 0;
+ // If it does not start with some period, then we are done
+ if (*pathPtr != chPeriod)
+ break;
- char* libfile = new char[strlen(libPathName) + strlen(libName) + 2];
- strcpy(libfile, libPathName);
- strcat(libfile, "/");
- strcat(libfile, libName);
+ unsigned int periodCount = 1;
+ pathPtr++;
+ if (*pathPtr == chPeriod)
+ {
+ pathPtr++;
+ periodCount++;
+ }
- dummyFptr = (FILE *) fopen(libfile, "rb");
- delete [] libfile;
- if (dummyFptr != NULL)
+ // Has to be followed by a \ or / or the null to mean anything
+ if ((*pathPtr != chForwardSlash) && (*pathPtr != chBackSlash)
+ && *pathPtr)
{
- fclose(dummyFptr);
- libraryPath = new char[strlen(libPathName)+1];
- strcpy((char *) libraryPath, libPathName);
break;
}
-
- } // while
-
- delete libPath;
+ if (*pathPtr)
+ pathPtr++;
- XMLPlatformUtils::fgLibLocation = libraryPath;
-
- if (XMLPlatformUtils::fgLibLocation == NULL)
- {
- panic(XMLPlatformUtils::Panic_CantFindLib);
+ // If its one period, just eat it, else move backwards in the base
+ if (periodCount == 2)
+ {
+ basePtr--;
+ while ((basePtr >= basePath)
+ && ((*basePtr != chForwardSlash) && (*basePtr != chBackSlash)))
+ {
+ basePtr--;
+ }
+
+ // The base cannot provide enough levels, so its in error/
+ if (basePtr < basePath)
+ ThrowXML(XMLPlatformUtilsException,
+ XMLExcepts::File_BasePathUnderflow);
+ }
}
+ // Copy the base part up to the base pointer
+ XMLCh* bufPtr = tmpBuf;
+ const XMLCh* tmpPtr = basePath;
+ while (tmpPtr <= basePtr)
+ *bufPtr++ = *tmpPtr++;
+
+ // And then copy on the rest of our path
+ XMLString::copyString(bufPtr, pathPtr);
+
+ // Orphan the buffer and return it
+ janBuf.orphan();
+ return tmpBuf;
}
@@ -322,61 +346,16 @@
XMLTransService* XMLPlatformUtils::makeTransService()
{
#if defined (XML_USE_ICU_TRANSCODER)
- //
- // We need to figure out the path to the Intl converter files.
- //
-
- static const char * icuDataEnvVar = "ICU_DATA";
- char * intlPath = 0;
-
- char* envVal = getenv(icuDataEnvVar);
-
- // Check if environment variable is set...
- if (envVal != NULL)
- {
- unsigned int pathLen = strlen(envVal);
- intlPath = new char[pathLen + 2];
-
- strcpy((char *) intlPath, envVal);
- if (envVal[pathLen - 1] != '/')
- {
- strcat((char *) intlPath, "/");
- }
-
- ICUTransService::setICUPath(intlPath);
- delete intlPath;
-
- return new ICUTransService;
- }
-
- //
- // If the environment variable ICU_DATA is not set, assume that the
- // converter files are stored relative to the Xerces-C library.
- //
-
- unsigned int lent = strlen(XMLPlatformUtils::fgLibLocation) +
- strlen("/icu/data/") + 1;
- intlPath = new char[lent];
- strcpy(intlPath, XMLPlatformUtils::fgLibLocation);
- strcat(intlPath, "/icu/data/");
-
- ICUTransService::setICUPath(intlPath);
- delete intlPath;
-
+ // Use ICU transcoding services.
+ // same as -DXML_USE_ICU_MESSAGELOADER
return new ICUTransService;
-
-
#else
-
// Use native transcoding services.
// same as -DXML_USE_INMEM_MESSAGELOADER
return new IconvTransService;
#endif
-
-} // XMLPlatformUtils::makeTransService
-
-
+}
// ---------------------------------------------------------------------------
// XMLPlatformUtils: The panic method
@@ -400,7 +379,7 @@
reasonStr = "Cannot initialize the system or mutex";
fprintf(stderr, "%s\n", reasonStr);
-
+
exit(-1);
}
@@ -408,6 +387,7 @@
// ---------------------------------------------------------------------------
// XMLPlatformUtils: File Methods
// ---------------------------------------------------------------------------
+
unsigned int XMLPlatformUtils::curFilePos(FileHandle theFile)
{
int curPos = ftell( (FILE*)theFile);
@@ -452,7 +432,7 @@
return (unsigned int)retVal;
}
-FileHandle XMLPlatformUtils::openFile(const unsigned short* const fileName)
+FileHandle XMLPlatformUtils::openFile(const XMLCh* const fileName)
{
const char* tmpFileName = XMLString::transcode(fileName);
ArrayJanitor<char> janText((char*)tmpFileName);
@@ -463,14 +443,23 @@
return retVal;
}
+FileHandle XMLPlatformUtils::openFile(const char* const fileName)
+{
+ FileHandle retVal = (FILE*)fopen( fileName , "rb" );
+
+ if (retVal == NULL)
+ return 0;
+ return retVal;
+}
FileHandle XMLPlatformUtils::openStdInHandle()
{
- return (FileHandle) fdopen(dup(0), "rb");
+ return (FileHandle)fdopen(dup(0), "rb");
}
+
unsigned int
XMLPlatformUtils::readFileBuffer( FileHandle theFile
, const unsigned int toRead
@@ -508,9 +497,8 @@
return (unsigned long)(aTime.time*1000 + aTime.millitm);
}
-
-XMLCh* XMLPlatformUtils::getBasePath(const XMLCh* const srcPath)
+XMLCh* XMLPlatformUtils::getFullPath(const XMLCh* const srcPath)
{
//
@@ -522,24 +510,18 @@
ArrayJanitor<char> janText(newSrc);
// Use a local buffer that is big enough for the largest legal path
- // Note #1186: dirName() is not thread safe.
- char* tmpPath = dirname(newSrc);
- if (!tmpPath)
+ char *absPath = new char[1024];
+ // get the absolute path
+ char* retPath = realpath(newSrc, absPath);
+ ArrayJanitor<char> janText2(retPath);
+
+ if (!retPath)
{
- ThrowXML(XMLPlatformUtilsException,
- XMLExcepts::File_CouldNotGetBasePathName);
+ ThrowXML(XMLPlatformUtilsException, XMLExcepts::File_CouldNotGetBasePathName);
}
-
- char* newXMLString = new char [strlen(tmpPath) +2];
- ArrayJanitor<char> newJanitor(newXMLString);
- strcpy(newXMLString, tmpPath);
- strcat(newXMLString , "/");
-
- // Return a copy of the path, in Unicode format
- return XMLString::transcode(newXMLString);
+ return XMLString::transcode(absPath);
}
-
bool XMLPlatformUtils::isRelative(const XMLCh* const toCheck)
{
// Check for pathological case of empty path
@@ -582,7 +564,6 @@
}
-
void XMLPlatformUtils::closeMutex(void* const mtxHandle)
{
if (mtxHandle != NULL)
@@ -656,6 +637,10 @@
#else // #if !defined (APP_NO_THREADS)
+void XMLPlatformUtils::platformInit()
+{
+}
+
void* XMLPlatformUtils::makeMutex()
{
return 0;
@@ -694,7 +679,6 @@
}
#endif // APP_NO_THREADS
-
void XMLPlatformUtils::platformTerm()
{