diff --git a/src/xercesc/util/Transcoders/Iconv400/Iconv400TransService.cpp b/src/xercesc/util/Transcoders/Iconv400/Iconv400TransService.cpp deleted file mode 100644 index 130f82f8d7737816a2b215e0af50476c4b5c61f0..0000000000000000000000000000000000000000 --- a/src/xercesc/util/Transcoders/Iconv400/Iconv400TransService.cpp +++ /dev/null @@ -1,888 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -/** - * @01A D998714.1 V5R2M0 100301 Swan :Fix error return flags - * @02A V5R2M0 200419 jrhansen : support lowercase function - * @03A D93234.1 V1R1M0 102804 JRHansen :fix transcode overflow - * @04A D93234.3 V1R1M0 022505 JRHansen :fix transcode error check - * $Id$ - */ - -// --------------------------------------------------------------------------- -// Includes -// --------------------------------------------------------------------------- -#include <xercesc/util/XMLUniDefs.hpp> -#include <xercesc/util/TranscodingException.hpp> -#include "Iconv400TransService.hpp" -#include <string.h> -#include <qlgcase.h> -#include "iconv_cnv.hpp" -#include "iconv_util.hpp" -#include <qusec.h> -#include <xercesc/util/XMLString.hpp> -#include <xercesc/util/Janitor.hpp> - -XERCES_CPP_NAMESPACE_BEGIN - -// --------------------------------------------------------------------------- -// Local functions -// --------------------------------------------------------------------------- - -// -// When XMLCh and ICU's UChar are not the same size, we have to do a temp -// conversion of all strings. These local helper methods make that easier. -// -static UChar* convertToUChar( const XMLCh* const toConvert - , const unsigned int srcLen = 0 - , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager) -{ - const unsigned int actualLen = srcLen - ? srcLen : XMLString::stringLen(toConvert); - - UChar* tmpBuf = (UChar*) manager->allocate - ( - (srcLen + 1) * sizeof(UChar) - );//new UChar[srcLen + 1]; - const XMLCh* srcPtr = toConvert; - UChar* outPtr = tmpBuf; - while (*srcPtr) - *outPtr++ = UChar(*srcPtr++); - *outPtr = 0; - - return tmpBuf; -} - -// --------------------------------------------------------------------------- -// Local, const data -// --------------------------------------------------------------------------- -static const XMLCh gMyServiceId[] = -{ - chLatin_I, chLatin_C, chLatin_O, chLatin_V, chDigit_4, chDigit_0, chDigit_0, chNull -}; - -// --------------------------------------------------------------------------- -// IconvTransService: Constructors and Destructor -// --------------------------------------------------------------------------- -Iconv400TransService::Iconv400TransService() -{ - memset((char*)&convertCtlblkUpper,'\0',sizeof(convertCtlblkUpper)); - convertCtlblkUpper.Type_of_Request = 1; - convertCtlblkUpper.Case_Request = 0; // upper case - convertCtlblkUpper.CCSID_of_Input_Data = 13488; - - memset((char*)&convertCtlblkLower,'\0',sizeof(convertCtlblkLower)); - convertCtlblkLower.Type_of_Request = 1; - convertCtlblkLower.Case_Request = 1; - convertCtlblkLower.CCSID_of_Input_Data = 13488; -} - -Iconv400TransService::~Iconv400TransService() -{ -} - - -// --------------------------------------------------------------------------- -// Iconv400TransService: The virtual transcoding service API -// --------------------------------------------------------------------------- -int Iconv400TransService::compareIString(const XMLCh* const comp1 - , const XMLCh* const comp2) -{ - const XMLCh* psz1 = comp1; - const XMLCh* psz2 = comp2; - - while (true) - { - - if (toUnicodeUpper(*psz1) != toUnicodeUpper(*psz2)) - return int(*psz1) - int(*psz2); - - // If either has ended, then they both ended, so equal - if (!*psz1 || !*psz2) - break; - - // Move upwards for the next round - psz1++; - psz2++; - } - return 0; -} - - -int Iconv400TransService::compareNIString(const XMLCh* const comp1 - , const XMLCh* const comp2 - , const XMLSize_t maxChars) -{ - const XMLCh* psz1 = comp1; - const XMLCh* psz2 = comp2; - - - unsigned int curCount = 0; - while (true) - { - // If an inequality, then return the difference - - - // If an inequality, then return difference - if (toUnicodeUpper(*psz1) != toUnicodeUpper(*psz2)) - return int(*psz1) - int(*psz2); - - // If either ended, then both ended, so equal - if (!*psz1 || !*psz2) - break; - - // Move upwards to next chars - psz1++; - psz2++; - - // - // Bump the count of chars done. If it equals the count then we - // are equal for the requested count, so break out and return - // equal. - // - curCount++; - if (maxChars == curCount) - break; - } - return 0; -} - - - -const XMLCh* Iconv400TransService::getId() const -{ - return gMyServiceId; -} - -XMLLCPTranscoder* Iconv400TransService::makeNewLCPTranscoder() -{ - // - // Try to create a default converter. If it fails, return a null pointer - // which will basically cause the system to give up because we really can't - // do anything without one. - // - UErrorCode uerr = U_ZERO_ERROR; - UConverter* converter = ucnv_open(NULL, &uerr); - if (!converter) - return 0; - - // That went ok, so create an Iconv LCP transcoder wrapper and return it - return new Iconv400LCPTranscoder(converter); -} - - -bool Iconv400TransService::supportsSrcOfs() const -{ - // This implementation supports source offset information - return true; -} - -void Iconv400TransService::upperCase(XMLCh* const toUpperCase) -{ - XMLCh* outPtr = toUpperCase; - while (*outPtr) - { - *outPtr = toUnicodeUpper(*outPtr); - outPtr++; - } -} - -void Iconv400TransService::lowerCase(XMLCh* const toLowerCase) -{ - XMLCh* outPtr = toLowerCase; - while (*outPtr) - { - *outPtr = toUnicodeLower(*outPtr); - outPtr++; - } -} - -// --------------------------------------------------------------------------- -// Iconv400TransService: The virtual transcoding service API -// --------------------------------------------------------------------------- -XMLCh Iconv400TransService::toUnicodeUpper(XMLCh comp1) const -{ - XMLCh chRet; - struct { - int bytes_available; - int bytes_used; - char exception_id[7]; - char reserved; - char exception_data[15]; - } error_code; - error_code.bytes_available = sizeof(error_code); - - long charlen =2; - - QlgConvertCase((char*)&convertCtlblkUpper, - (char*)&comp1, - (char*)&chRet, - (long*)&charlen, - (char*)&error_code); - return chRet; -} - -XMLCh Iconv400TransService::toUnicodeLower(XMLCh comp1) const -{ - XMLCh chRet; - struct { - int bytes_available; - int bytes_used; - char exception_id[7]; - char reserved; - char exception_data[15]; - } error_code; - error_code.bytes_available = sizeof(error_code); - - long charlen =2; - - QlgConvertCase((char*)&convertCtlblkLower, - (char*)&comp1, - (char*)&chRet, - (long*)&charlen, - (char*)&error_code); - return chRet; -} - -// --------------------------------------------------------------------------- -// Iconv400TransService: The protected virtual transcoding service API -// --------------------------------------------------------------------------- -XMLTranscoder* -Iconv400TransService::makeNewXMLTranscoder(const XMLCh* const encodingName - , XMLTransService::Codes& resValue - , const XMLSize_t blockSize - , MemoryManager* const manager) -{ - UErrorCode uerr = U_ZERO_ERROR; - UConverter* converter = ucnv_openU(encodingName, &uerr); - if (!converter) - { - resValue = XMLTransService::UnsupportedEncoding; - return 0; - } - return new (manager) Iconv400Transcoder(encodingName, converter, blockSize, manager); -} - - - - -// --------------------------------------------------------------------------- -// IconvTranscoder: Constructors and Destructor -// --------------------------------------------------------------------------- -Iconv400Transcoder::Iconv400Transcoder( const XMLCh* const encodingName - , UConverter* const toAdopt - , const XMLSize_t blockSize - , MemoryManager* const manager) : - - XMLTranscoder(encodingName, blockSize, manager) - , fConverter(toAdopt) - , fFixed(false) - , fSrcOffsets(0) -{ - // If there is a block size, then allocate our source offset array - if (blockSize) - fSrcOffsets = (long*) manager->allocate(blockSize * sizeof(long));//new long[blockSize]; - - // Remember if its a fixed size encoding - fFixed = (ucnv_getMaxCharSize(fConverter) == ucnv_getMinCharSize(fConverter)); -} - -Iconv400Transcoder::~Iconv400Transcoder() -{ - getMemoryManager()->deallocate(fSrcOffsets);//delete [] fSrcOffsets; - - // If there is a converter, ask Iconv400 to clean it up - if (fConverter) - { - // <TBD> Does this actually delete the structure??? - ucnv_close(fConverter); - fConverter = 0; - } -} - - -// --------------------------------------------------------------------------- -// Iconv400Transcoder: The virtual transcoder API -// --------------------------------------------------------------------------- -unsigned int -Iconv400Transcoder::transcodeFrom(const XMLByte* const srcData - , const unsigned int srcCount - , XMLCh* const toFill - , const unsigned int maxChars - , unsigned int& bytesEaten - , unsigned char* const charSizes) -{ - // If debugging, insure the block size is legal - - - // Set up pointers to the start and end of the source buffer - const XMLByte* startSrc = srcData; - const XMLByte* endSrc = srcData + srcCount; - - // - // And now do the target buffer. This works differently according to - // whether XMLCh and UChar are the same size or not. - // - UChar* startTarget; - if (sizeof(XMLCh) == sizeof(UChar)) - startTarget = (UChar*)toFill; - else - startTarget = (UChar*) getMemoryManager()->allocate - ( - maxChars * sizeof(UChar) - );//new UChar[maxChars]; - UChar* orgTarget = startTarget; - - // - // Transoode the buffer. Buffer overflow errors are normal, occuring - // when the raw input buffer holds more characters than will fit in - // the Unicode output buffer. - // - UErrorCode err = U_ZERO_ERROR; - ucnv_toUnicode - ( - fConverter - , &startTarget - , startTarget + maxChars - , (const char**)&startSrc - , (const char*)endSrc - , (fFixed ? 0 : (int32_t*)fSrcOffsets) - , false - , &err - ); - - - if ((err != U_ZERO_ERROR) && (err != U_INDEX_OUTOFBOUNDS_ERROR) && - (err != U_BUFFER_OVERFLOW_ERROR)) // @03c - { - if (orgTarget != (UChar*)toFill) - getMemoryManager()->deallocate(orgTarget);//delete [] orgTarget; - - if (fFixed) - { - XMLCh tmpBuf[17]; - XMLString::binToText((unsigned int)(*startTarget), tmpBuf, 16, 16, getMemoryManager()); - ThrowXMLwithMemMgr2 - ( - TranscodingException - , XMLExcepts::Trans_BadSrcCP - , tmpBuf - , getEncodingName() - , getMemoryManager() - ); - } - else - { - ThrowXMLwithMemMgr(TranscodingException, XMLExcepts::Trans_BadSrcSeq, getMemoryManager()); - } - } - - // Calculate the bytes eaten and store in caller's param - bytesEaten = startSrc - srcData; - - // And the characters decoded - const unsigned int charsDecoded = startTarget - orgTarget; - - // - // Translate the array of char offsets into an array of character - // sizes, which is what the transcoder interface semantics requires. - // If its fixed, then we can optimize it. - // - if (fFixed) - { - const unsigned char fillSize = (unsigned char)ucnv_getMaxCharSize(fConverter); - memset(charSizes, fillSize, maxChars); - } - else - { - // - // We have to convert the series of offsets into a series of - // sizes. If just one char was decoded, then its the total bytes - // eaten. Otherwise, do a loop and subtract out each element from - // its previous element. - // - if (charsDecoded == 1) - { - charSizes[0] = (unsigned char)bytesEaten; - } - else - { - // ICU does not return an extra element to allow us to figure - // out the last char size, so we have to compute it from the - // total bytes used. - unsigned int index; - for (index = 0; index < charsDecoded - 1; index++) - { - charSizes[index] = (unsigned char)(fSrcOffsets[index + 1] - - fSrcOffsets[index]); - } - if( charsDecoded > 0 ) { - charSizes[charsDecoded - 1] = (unsigned char)(bytesEaten - - fSrcOffsets[charsDecoded - 1]); - } - } - } - - // - // If XMLCh and UChar are not the same size, then we need to copy over - // the temp buffer to the new one. - // - if (sizeof(UChar) != sizeof(XMLCh)) - { - XMLCh* outPtr = toFill; - startTarget = orgTarget; - for (unsigned int index = 0; index < charsDecoded; index++) - *outPtr++ = XMLCh(*startTarget++); - - // And delete the temp buffer - getMemoryManager()->deallocate(orgTarget);//delete [] orgTarget; - } - - // Return the chars we put into the target buffer - return charsDecoded; -} - - -unsigned int -Iconv400Transcoder::transcodeTo( const XMLCh* const srcData - , const unsigned int srcCount - , XMLByte* const toFill - , const unsigned int maxBytes - , unsigned int& charsEaten - , const UnRepOpts options) -{ - // - // Get a pointer to the buffer to transcode. If UChar and XMLCh are - // the same size here, then use the original. Else, create a temp - // one and put a janitor on it. - // - const UChar* srcPtr; - UChar* tmpBufPtr = 0; - if (sizeof(XMLCh) == sizeof(UChar)) - { - srcPtr = (const UChar*)srcData; - } - else - { - tmpBufPtr = convertToUChar(srcData, srcCount, getMemoryManager()); - srcPtr = tmpBufPtr; - } - ArrayJanitor<UChar> janTmpBuf(tmpBufPtr, getMemoryManager()); - - // - // Set the appropriate callback so that it will either fail or use - // the rep char. Remember the old one so we can put it back. - // - UErrorCode err = U_ZERO_ERROR; - - - // - // Ok, lets transcode as many chars as we we can in one shot. The - // ICU API gives enough info not to have to do this one char by char. - // - XMLByte* startTarget = toFill; - const UChar* startSrc = srcPtr; - err = U_ZERO_ERROR; - ucnv_fromUnicode - ( - fConverter - , (char**)&startTarget - , (char*)(startTarget + maxBytes) - , &startSrc - , srcPtr + srcCount - , 0 - , false - , &err - ); - - - if (err) /*@01A*/ - { - XMLCh tmpBuf[17]; - XMLString::binToText((unsigned int)*startSrc, tmpBuf, 16, 16, getMemoryManager()); - ThrowXMLwithMemMgr2 - ( - TranscodingException - , XMLExcepts::Trans_Unrepresentable - , tmpBuf - , getEncodingName() - , getMemoryManager() - ); - } - - // Fill in the chars we ate from the input - charsEaten = startSrc - srcPtr; - - // Return the chars we stored - return startTarget - toFill; -} - - -bool Iconv400Transcoder::canTranscodeTo(const unsigned int toCheck) -{ - // - // If the passed value is really a surrogate embedded together, then - // we need to break it out into its two chars. Else just one. While - // we are ate it, convert them to UChar format if required. - // - UChar srcBuf[2]; - unsigned int srcCount = 1; - if (toCheck & 0xFFFF0000) - { - srcBuf[0] = UChar((toCheck >> 10) + 0xD800); - srcBuf[1] = UChar(toCheck & 0x3FF) + 0xDC00; - srcCount++; - } - else - { - srcBuf[0] = UChar(toCheck); - } - - - // Set upa temp buffer to format into. Make it more than big enough - char tmpBuf[64]; - char* startTarget = tmpBuf; - const UChar* startSrc = srcBuf; - UErrorCode err = U_ZERO_ERROR; - - ucnv_fromUnicode - ( - fConverter - , &startTarget - , startTarget + 64 - , &startSrc - , srcBuf + srcCount - , 0 - , false - , &err - ); - - - return (err==U_ZERO_ERROR); /*@01A*/ -} - - - -// --------------------------------------------------------------------------- -// IconvLCPTranscoder: Constructors and Destructor -// --------------------------------------------------------------------------- -Iconv400LCPTranscoder::Iconv400LCPTranscoder(UConverter* const toAdopt) : - - fConverter(toAdopt) -{ -} - -Iconv400LCPTranscoder::~Iconv400LCPTranscoder() -{ - // If there is a converter, ask Iconv to clean it up - if (fConverter) - { - // <TBD> Does this actually delete the structure??? - ucnv_close(fConverter); - fConverter = 0; - } -} - - -// --------------------------------------------------------------------------- -// Iconv400LCPTranscoder: Constructors and Destructor -// --------------------------------------------------------------------------- -XMLSize_t Iconv400LCPTranscoder::calcRequiredSize(const XMLCh* const srcText - , MemoryManager* const manager) -{ - if (!srcText) - return 0; - - // Lock and attempt the calculation - UErrorCode err = U_ZERO_ERROR; - int32_t targetCap; - { - XMLMutexLock lockConverter(&fMutex); - - targetCap = ucnv_fromUChars - ( - fConverter - , 0 - , 0 - , srcText - , &err - ); - } - - if (err != U_BUFFER_OVERFLOW_ERROR) - return 0; - - return (XMLSize_t)targetCap; -} - -XMLSize_t Iconv400LCPTranscoder::calcRequiredSize(const char* const srcText - , MemoryManager* const manager) -{ - if (!srcText) - return 0; - - int32_t targetCap; - UErrorCode err = U_ZERO_ERROR; - { - XMLMutexLock lockConverter(&fMutex); - - targetCap = ucnv_toUChars - ( - fConverter - , 0 - , 0 - , srcText - , strlen(srcText) - , &err - ); - } - - if (err != U_BUFFER_OVERFLOW_ERROR) - return 0; - - // Subtract one since it includes the terminator space - return (XMLSize_t)(targetCap - 1); -} - - -char* Iconv400LCPTranscoder::transcode(const XMLCh* const toTranscode, - MemoryManager* const manager) -{ - char* retBuf = 0; - - // Check for a couple of special cases - if (!toTranscode) - return 0; - - if (!*toTranscode) - { - retBuf = (char*) manager->allocate(sizeof(char));//new char[1]; - retBuf[0] = 0; - return retBuf; - } - - // Caculate a return buffer size not too big, but less likely to overflow - int32_t targetLen = (int32_t)(u_strlen(toTranscode) * 1.25); - - // Allocate the return buffer - retBuf = (char*) manager->allocate((targetLen + 1) * sizeof(char));//new char[targetLen + 1]; - - // Lock now while we call the converter. - UErrorCode err = U_ZERO_ERROR; - int32_t targetCap; - { - XMLMutexLock lockConverter(&fMutex); - - //Convert the Unicode string to char* - targetCap = ucnv_fromUChars - ( - fConverter - , retBuf - , targetLen + 1 - , toTranscode - , &err - ); - } - - // If targetLen is not enough then buffer overflow might occur - if (err == U_BUFFER_OVERFLOW_ERROR) - { - // Reset the error, delete the old buffer, allocate a new one, and try again - err = U_ZERO_ERROR; - manager->deallocate(retBuf);//delete [] retBuf; - retBuf = (char*) manager->allocate(targetCap * sizeof(char));//new char[targetCap]; - - // Lock again before we retry - XMLMutexLock lockConverter(&fMutex); - targetCap = ucnv_fromUChars - ( - fConverter - , retBuf - , targetCap - , toTranscode - , &err - ); - } - - if (U_FAILURE(err)) - { - manager->deallocate(retBuf);//delete [] retBuf; - return 0; - } - - // Cap it off and return - retBuf[targetCap] = 0; - return retBuf; -} - -XMLCh* Iconv400LCPTranscoder::transcode(const char* const toTranscode, - MemoryManager* const manager) -{ - // Watch for a few pyscho corner cases - if (!toTranscode) - return 0; - - XMLCh* retVal = 0; - if (!*toTranscode) - { - retVal = (XMLCh*) manager->allocate(sizeof(XMLCh));//new XMLCh[1]; - retVal[0] = 0; - return retVal; - } - - // - // Get the length of the string to transcode. The Unicode string will - // almost always be no more chars than were in the source, so this is - // the best guess as to the storage needed. - // - const int32_t srcLen = (int32_t)strlen(toTranscode); - // Allocate unicode string of equivalent length in unicode bytes - retVal = (XMLCh*) manager->allocate((srcLen + 1) * sizeof(XMLCh));//new XMLCh[srcLen+1]; - - // Now lock while we do these calculations - UErrorCode err = U_ZERO_ERROR; - { - XMLMutexLock lockConverter(&fMutex); - - // - // Here we don't know what the target length will be so use 0 and - // expect an U_BUFFER_OVERFLOW_ERROR in which case it'd get resolved - // by the correct capacity value. - // - int32_t targetCap; - targetCap = ucnv_toUChars - ( - fConverter - , retVal - , srcLen+1 - , toTranscode - , srcLen - , &err - ); - - if (err == U_BUFFER_OVERFLOW_ERROR) // @04c - { - - err = U_ZERO_ERROR; - manager->deallocate(retVal); //@04a - retVal = (XMLCh*) manager->allocate(targetCap * sizeof(XMLCh));//new XMLCh[targetCap]; - ucnv_toUChars - ( - fConverter - , retVal - , targetCap - , toTranscode - , srcLen - , &err - ); - } - } - - if (U_FAILURE(err)) - { - // Clean up if we got anything allocated - manager->deallocate(retVal);//delete [] retVal; - return 0; - } - - return retVal; -} - - -bool Iconv400LCPTranscoder::transcode(const char* const toTranscode - , XMLCh* const toFill - , const XMLSize_t maxChars - , MemoryManager* const manager) -{ - // Check for a couple of psycho corner cases - if (!toTranscode || !maxChars) - { - toFill[0] = 0; - return true; - } - - if (!*toTranscode) - { - toFill[0] = 0; - return true; - } - - // Lock and do the transcode operation - UErrorCode err = U_ZERO_ERROR; - const int32_t srcLen = (int32_t)strlen(toTranscode); - { - XMLMutexLock lockConverter(&fMutex); - ucnv_toUChars - ( - fConverter - , toFill - , maxChars + 1 - , toTranscode - , srcLen - , &err - ); - } - - if (U_FAILURE(err)) - return false; - - return true; -} - - -bool Iconv400LCPTranscoder::transcode( const XMLCh* const toTranscode - , char* const toFill - , const XMLSize_t maxChars - , MemoryManager* const manager) -{ - // Watch for a few psycho corner cases - if (!toTranscode || !maxChars) - { - toFill[0] = 0; - return true; - } - - if (!*toTranscode) - { - toFill[0] = 0; - return true; - } - - - UErrorCode err = U_ZERO_ERROR; - int32_t targetCap; - { - XMLMutexLock lockConverter(&fMutex); - targetCap = ucnv_fromUChars - ( - fConverter - , toFill - , maxChars + 1 - , toTranscode - , &err - ); - } - - if (U_FAILURE(err)) - return false; - - toFill[targetCap] = 0; - return true; -} - -XERCES_CPP_NAMESPACE_END - diff --git a/src/xercesc/util/Transcoders/Iconv400/Iconv400TransService.hpp b/src/xercesc/util/Transcoders/Iconv400/Iconv400TransService.hpp deleted file mode 100644 index a8737d0f869fb8734882a5791b8ca8ed546654da..0000000000000000000000000000000000000000 --- a/src/xercesc/util/Transcoders/Iconv400/Iconv400TransService.hpp +++ /dev/null @@ -1,263 +0,0 @@ -#if (__OS400_TGTVRM__>=510) /* @01a */ - #pragma datamodel(P128) /* @01a */ -#endif /* @01a */ - -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -/** - * @02A V5R2M0 200419 jrhansen : support lowercase function - * $Id$ - */ - -#if !defined(XERCESC_INCLUDE_GUARD_ICONV400TRANSSERVICE_HPP) -#define XERCESC_INCLUDE_GUARD_ICONV400TRANSSERVICE_HPP - -#include <xercesc/util/Mutexes.hpp> -#include <xercesc/util/TransService.hpp> -#include <qlg.h> - -XERCES_CPP_NAMESPACE_BEGIN - -struct UConverter; - -class XMLUTIL_EXPORT Iconv400TransService : public XMLTransService -{ -public : - // ----------------------------------------------------------------------- - // Public, static methods - // ----------------------------------------------------------------------- - - - // ----------------------------------------------------------------------- - // Constructors and Destructor - // ----------------------------------------------------------------------- - Iconv400TransService(); - ~Iconv400TransService(); - - - // ----------------------------------------------------------------------- - // Implementation of the virtual transcoding service API - // ----------------------------------------------------------------------- - virtual int compareIString - ( - const XMLCh* const comp1 - , const XMLCh* const comp2 - ); - - virtual int compareNIString - ( - const XMLCh* const comp1 - , const XMLCh* const comp2 - , const XMLSize_t maxChars - ); - - virtual const XMLCh* getId() const; - - virtual XMLLCPTranscoder* makeNewLCPTranscoder(); - - virtual bool supportsSrcOfs() const; - - virtual void upperCase(XMLCh* const toUpperCase); - virtual void lowerCase(XMLCh* const toLowerCase); - - -protected : - // ----------------------------------------------------------------------- - // Protected virtual methods - // ----------------------------------------------------------------------- - virtual XMLTranscoder* makeNewXMLTranscoder - ( - const XMLCh* const encodingName - , XMLTransService::Codes& resValue - , const XMLSize_t blockSize - , MemoryManager* const manager - ); - - -private : - // ----------------------------------------------------------------------- - // Unimplemented constructors and operators - // ----------------------------------------------------------------------- - Iconv400TransService(const Iconv400TransService&); - Iconv400TransService& operator=(const Iconv400TransService&); - - XMLCh toUnicodeUpper(XMLCh toupper) const; - XMLCh toUnicodeLower(XMLCh tolower) const; - - Qlg_CCSID_ReqCtlBlk_T convertCtlblkUpper; - Qlg_CCSID_ReqCtlBlk_T convertCtlblkLower; - -}; - - - -class XMLUTIL_EXPORT Iconv400Transcoder : public XMLTranscoder -{ -public : - // ----------------------------------------------------------------------- - // Constructors and Destructor - // ----------------------------------------------------------------------- - Iconv400Transcoder - ( - const XMLCh* const encodingName - , UConverter* const toAdopt - , const XMLSize_t blockSize - , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager - ); - ~Iconv400Transcoder(); - - // ----------------------------------------------------------------------- - // Implementation of the virtual transcoder interface - // ----------------------------------------------------------------------- - virtual unsigned int transcodeFrom - ( - const XMLByte* const srcData - , const unsigned int srcCount - , XMLCh* const toFill - , const unsigned int maxChars - , unsigned int& bytesEaten - , unsigned char* const charSizes - ); - - virtual unsigned int transcodeTo - ( - const XMLCh* const srcData - , const unsigned int srcCount - , XMLByte* const toFill - , const unsigned int maxBytes - , unsigned int& charsEaten - , const UnRepOpts options - ); - - virtual bool canTranscodeTo - ( - const unsigned int toCheck - ); - - - -private : - // ----------------------------------------------------------------------- - // Unimplemented constructors and operators - // ----------------------------------------------------------------------- - Iconv400Transcoder(); - Iconv400Transcoder(const Iconv400Transcoder&); - Iconv400Transcoder& operator=(const Iconv400Transcoder&); - - - // ----------------------------------------------------------------------- - // Private data members - // - // fConverter - // This is a pointer to the Iconv400 converter that this transcoder - // uses. - // - // fFixed - // This is set to true if the encoding is a fixed size one. This - // can be used to optimize some operations. - // - // fSrcOffsets - // This is an array of longs, which are allocated to the size of - // the trancoding block (if any) indicated in the ctor. It is used - // to get the character offsets from Iconv400, which are then translated - // into an array of char sizes for return. - // ----------------------------------------------------------------------- - UConverter* fConverter; - bool fFixed; - long* fSrcOffsets; - -}; - - -class XMLUTIL_EXPORT Iconv400LCPTranscoder : public XMLLCPTranscoder -{ -public : - // ----------------------------------------------------------------------- - // Constructors and Destructor - // ----------------------------------------------------------------------- - Iconv400LCPTranscoder(UConverter* const toAdopt); - ~Iconv400LCPTranscoder(); - - - // ----------------------------------------------------------------------- - // Implementation of the virtual transcoder interface - // ----------------------------------------------------------------------- - virtual char* transcode(const XMLCh* const toTranscode, - MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); - - virtual XMLCh* transcode(const char* const toTranscode, - MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); - - - // ----------------------------------------------------------------------- - // DEPRECATED old transcode interface - // ----------------------------------------------------------------------- - virtual XMLSize_t calcRequiredSize(const char* const srcText - , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); - - virtual XMLSize_t calcRequiredSize(const XMLCh* const srcText - , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); - - virtual bool transcode - ( - const char* const toTranscode - , XMLCh* const toFill - , const XMLSize_t maxChars - , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager - ); - - virtual bool transcode - ( - const XMLCh* const toTranscode - , char* const toFill - , const XMLSize_t maxChars - , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager - ); - - - -private : - // ----------------------------------------------------------------------- - // Unimplemented constructors and operators - // ----------------------------------------------------------------------- - Iconv400LCPTranscoder(); - Iconv400LCPTranscoder(const Iconv400LCPTranscoder&); - Iconv400LCPTranscoder& operator=(const Iconv400LCPTranscoder&); - - - // ----------------------------------------------------------------------- - // Private data members - // - // fConverter - // This is a pointer to the Iconv converter that this transcoder - // uses. - // - // fMutex - // We have to synchronize threaded calls to the converter. - // ----------------------------------------------------------------------- - UConverter* fConverter; - XMLMutex fMutex; -}; - -XERCES_CPP_NAMESPACE_END - -#endif -#if (__OS400_TGTVRM__>=510) /* @01a */ - #pragma datamodel(pop) /* @01a */ -#endif /* @01a */ - diff --git a/src/xercesc/util/Transcoders/Iconv400/iconv_cnv.cpp b/src/xercesc/util/Transcoders/Iconv400/iconv_cnv.cpp deleted file mode 100644 index 0cf4eeb546b07f686a4b6c4f1f5f044e842043a4..0000000000000000000000000000000000000000 --- a/src/xercesc/util/Transcoders/Iconv400/iconv_cnv.cpp +++ /dev/null @@ -1,726 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -/* - * $Id$ - */ - -#include <xercesc/util/XercesDefs.hpp> -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <errno.h> -#include <iconv_util.hpp> -#include <iconv_cnv.hpp> -#include <qmhrtvm.h> -#include <qusec.h> -#include <xercesc/util/Platforms/OS400/OS400PlatformUtils.hpp> -#include <iconv.h> -#include <errno.h> -#define CHUNK_SIZE 5*1024 - -XERCES_CPP_NAMESPACE_BEGIN - -void Convert_toUnicode(UConverter *, - UChar **, - const UChar *, - const char **, - const char *, - int32_t* offsets, - int, - UErrorCode *); - -void Convert_fromUnicode(UConverter *, - char **, - const char *, - const UChar **, - const UChar *, - int32_t* offsets, - int, - UErrorCode *); - -UChar getNextUChar(UConverter* converter, - const char** source, - const char* sourceLimit, - UErrorCode* err); - -void T_UConverter_fromCodepageToCodepage (UConverter * outConverter, - UConverter * inConverter, - char **target, - const char *targetLimit, - const char **source, - const char *sourceLimit, - int32_t* offsets, - int flush, - UErrorCode * err); -void Converter_fromUnicode(UConverter * _this, - char **target, - const char *targetLimit, - const UChar ** source, - const UChar * sourceLimit, - int32_t *offsets, - int flush, - UErrorCode * err); - -/*Calls through createConverter */ -UConverter* ucnv_open (const char *name, - UErrorCode * err) -{ - if (U_FAILURE (*err)) - return NULL; - - /*In case "name" is NULL we want to open the default converter */ - if (name != NULL) - return createConverter (name, err); - else - return createConverter (iconv_getDefaultCodepage(), err); -} - -/*Extracts the UChar* to a char* and calls through createConverter */ -UConverter* ucnv_openU (const UChar * name, - UErrorCode * err) -{ - char asciiName[MAX_CONVERTER_NAME_LENGTH]; - - if (U_FAILURE (*err)) - return NULL; - if (name == NULL) - return ucnv_open (NULL, err); - if (u_strlen (name) > MAX_CONVERTER_NAME_LENGTH) - { - *err = U_ILLEGAL_ARGUMENT_ERROR; - return NULL; - } - return ucnv_open (u_austrcpy (asciiName, name), err); -} - -/*Decreases the reference counter in the shared immutable section of the object - *and frees the mutable part*/ - -void ucnv_close (UConverter * converter) -{ -/* for iconv we will close the handles and free the converter storage*/ - iconv_close(converter->sharedData->toiconv_handle); - iconv_close(converter->sharedData->fromiconv_handle); - if (converter == NULL) - return; - - - free (converter); - - return; -} - -/* currently required for iconv suuport */ -/* XMLReader calls this and uses fact that it is different than min -to go thru a calculation otherwise if max and min same then there is -a calculation speed up - we will keep the two routines but have them -return different sizes - later will ifdef XMLreader for ICONV to remove the calls*/ - int8_t ucnv_getMaxCharSize (const UConverter * converter) -{ - return (4); /* dummy returns just need to be different in XMLParser - need something else for ICU replacement */ -} -/* currently required for iconv support */ -/* see note for ucnv_getMaxCharSize */ -int8_t ucnv_getMinCharSize (const UConverter * converter) -{ - return (1); -} - -void ucnv_fromUnicode (UConverter * _this, - char **target, - const char *targetLimit, - const UChar ** source, - const UChar * sourceLimit, - int32_t* offsets, - int flush, - UErrorCode * err) -{ - /* - * Check parameters in for all conversions - */ - if (U_FAILURE (*err)) return; - if ((_this == NULL) || ((char *) targetLimit < *target) || (sourceLimit < *source)) - { - *err = U_ILLEGAL_ARGUMENT_ERROR; - return; - } - - - /*calls the specific conversion routines */ - Converter_fromUnicode(_this,target,targetLimit,source,sourceLimit, - offsets,flush,err); - - return; -} - -void ucnv_toUnicode (UConverter * _this, - UChar ** target, - const UChar * targetLimit, - const char **source, - const char *sourceLimit, - int32_t* offsets, - int flush, - UErrorCode * err) -{ - /* - * Check parameters in for all conversions - */ - if (U_FAILURE (*err)) return; - if ((_this == NULL) || ((UChar *) targetLimit < *target) || (sourceLimit < *source)) - { - *err = U_ILLEGAL_ARGUMENT_ERROR; - return; - } - - - - /*calls the specific conversion routines */ - Convert_toUnicode(_this,target,targetLimit,source,sourceLimit, - offsets,flush,err); - return; -} - -int32_t ucnv_fromUChars (const UConverter * converter, - char *target, - int32_t targetSize, - const UChar * source, - UErrorCode * err) -{ - const UChar *mySource = source; - const UChar *mySource_limit; - int32_t mySourceLength = 0; - UConverter myConverter; - char *myTarget = target; - int32_t targetCapacity = 0; - - if (U_FAILURE (*err)) - return 0; - - if ((converter == NULL) || (targetSize < 0)) - { - *err = U_ILLEGAL_ARGUMENT_ERROR; - return 0; - } - - /*makes a local copy of the UConverter */ - myConverter = *converter; - - - /*if the source is empty we return immediately */ - mySourceLength = u_strlen (source); - if (mySourceLength == 0) - { - /*for consistency we still need to - *store 0 in the targetCapacity - *if the user requires it - */ - return 0; - } - - mySource_limit = mySource + mySourceLength; - - if (targetSize > 0) - { - ucnv_fromUnicode (&myConverter, - &myTarget, - target + targetSize, - &mySource, - mySource_limit, - NULL, - TRUE, - err); - targetCapacity = myTarget - target; - } - - /*Updates targetCapacity to contain the number of bytes written to target */ - - if (targetSize == 0) - { - *err = U_BUFFER_OVERFLOW_ERROR; - } - - /* If the output buffer is exhausted, we need to stop writing - * to it but continue the conversion in order to store in targetSize - * the number of bytes that was required*/ - if (*err == U_BUFFER_OVERFLOW_ERROR) - { - char target2[CHUNK_SIZE]; - char *target2_alias = target2; - const char *target2_limit = target2 + CHUNK_SIZE; - - /*We use a stack allocated buffer around which we loop - *(in case the output is greater than CHUNK_SIZE) - */ - - while (*err == U_BUFFER_OVERFLOW_ERROR) - { - *err = U_ZERO_ERROR; - target2_alias = target2; - ucnv_fromUnicode (&myConverter, - &target2_alias, - target2_limit, - &mySource, - mySource_limit, - NULL, - TRUE, - err); - - /*updates the output parameter to contain the number of char required */ - targetCapacity += (target2_alias - target2) + 1; - } - /*We will set the erro code to BUFFER_OVERFLOW_ERROR only if - *nothing graver happened in the previous loop*/ - (targetCapacity)--; - if (U_SUCCESS (*err)) - *err = U_BUFFER_OVERFLOW_ERROR; - } - - return targetCapacity; -} - -int32_t ucnv_toUChars (const UConverter * converter, - UChar * target, - int32_t targetSize, - const char *source, - int32_t sourceSize, - UErrorCode * err) -{ - const char *mySource = source; - const char *mySource_limit = source + sourceSize; - UConverter myConverter; - UChar *myTarget = target; - int32_t targetCapacity; - - if (U_FAILURE (*err)) - return 0; - - if ((converter == NULL) || (targetSize < 0) || (sourceSize < 0)) - { - *err = U_ILLEGAL_ARGUMENT_ERROR; - return 0; - } - /*Means there is no work to be done */ - if (sourceSize == 0) - { - /*for consistency we still need to - *store 0 in the targetCapacity - *if the user requires it - */ - if (targetSize >= 1) - { - target[0] = 0x0000; - return 1; - } - else - return 0; - } - - /*makes a local copy of the UConverter */ - myConverter = *converter; - - - /*Not in pure pre-flight mode */ - if (targetSize > 0) - { - /* Changed from (targetSize * 2) to (targetSize) */ - ucnv_toUnicode (&myConverter, - &myTarget, - target + (targetSize-1), /*Save a spot for the Null terminator */ - &mySource, - mySource_limit, - NULL, - TRUE, - err); - - /*Null terminates the string */ - *(myTarget) = 0x0000; - } - - - /*Rigs targetCapacity to have at least one cell for zero termination */ - /*Updates targetCapacity to contain the number of bytes written to target */ - targetCapacity = 1; - targetCapacity += myTarget - target; - if (targetSize == 0) - { - *err = U_BUFFER_OVERFLOW_ERROR; - } - /* If the output buffer is exhausted, we need to stop writing - * to it but if the input buffer is not exhausted, - * we need to continue the conversion in order to store in targetSize - * the number of bytes that was required - */ - if (*err == U_BUFFER_OVERFLOW_ERROR) - { - UChar target2[CHUNK_SIZE]; - UChar *target2_alias = target2; - const UChar *target2_limit = target2 + CHUNK_SIZE; - - /*We use a stack allocated buffer around which we loop - (in case the output is greater than CHUNK_SIZE) */ - - while (*err == U_BUFFER_OVERFLOW_ERROR) - { - *err = U_ZERO_ERROR; - target2_alias = target2; - ucnv_toUnicode (&myConverter, - &target2_alias, - target2_limit, - &mySource, - mySource_limit, - NULL, - TRUE, - err); - - /*updates the output parameter to contain the number of char required */ - targetCapacity += target2_alias - target2 + 1; - } - (targetCapacity)--; /*adjust for last one */ - if (U_SUCCESS (*err)) - *err = U_BUFFER_OVERFLOW_ERROR; - } - - return targetCapacity; -} - -UChar ucnv_getNextUChar (UConverter * converter, - const char **source, - const char *sourceLimit, - UErrorCode * err) -{ - - - /*calls the specific conversion routines */ - /*as dictated in a code review, avoids a switch statement */ - return getNextUChar(converter,source,sourceLimit,err); -} - - - -/************************** -* Will convert a sequence of bytes from one codepage to another. -* @param toConverterName: The name of the converter that will be used to encode the output buffer -* @param fromConverterName: The name of the converter that will be used to decode the input buffer -* @param target: Pointer to the output buffer* written -* @param targetLength: on input contains the capacity of target, on output the number of bytes copied to target -* @param source: Pointer to the input buffer -* @param sourceLength: on input contains the capacity of source, on output the number of bytes processed in "source" -* @param internal: used internally to store store state data across calls -* @param err: fills in an error status -*/ -void -T_UConverter_fromCodepageToCodepage (UConverter * outConverter, - UConverter * inConverter, - char **target, - const char *targetLimit, - const char **source, - const char *sourceLimit, - int32_t* offsets, - int flush, - UErrorCode * err) -{ - - UChar out_chunk[CHUNK_SIZE]; - const UChar *out_chunk_limit = out_chunk + CHUNK_SIZE; - UChar *out_chunk_alias; - UChar const *out_chunk_alias2; - - - if (U_FAILURE (*err)) return; - - - /*loops until the input buffer is completely consumed - *or if an error has be encountered - *first we convert from inConverter codepage to Unicode - *then from Unicode to outConverter codepage - */ - while ((*source != sourceLimit) && U_SUCCESS (*err)) - { - out_chunk_alias = out_chunk; - ucnv_toUnicode (inConverter, - &out_chunk_alias, - out_chunk_limit, - source, - sourceLimit, - NULL, - flush, - err); - - /*BUFFER_OVERFLOW_ERROR means that the output "CHUNK" is full - *we will require at least another loop (it's a recoverable error) - */ - - if (U_SUCCESS (*err) || (*err == U_BUFFER_OVERFLOW_ERROR)) - { - *err = U_ZERO_ERROR; - out_chunk_alias2 = out_chunk; - - while ((out_chunk_alias2 != out_chunk_alias) && U_SUCCESS (*err)) - { - ucnv_fromUnicode (outConverter, - target, - targetLimit, - &out_chunk_alias2, - out_chunk_alias, - NULL, - TRUE, - err); - - } - } - else - break; - } - - return; -} - -int32_t ucnv_convert(const char *toConverterName, - const char *fromConverterName, - char *target, - int32_t targetSize, - const char *source, - int32_t sourceSize, - UErrorCode * err) -{ - const char *mySource = source; - const char *mySource_limit = source + sourceSize; - int32_t mySourceLength = 0; - UConverter *inConverter; - UConverter *outConverter; - char *myTarget = target; - int32_t targetCapacity = 0; - - if (U_FAILURE (*err)) - return 0; - - if ((targetSize < 0) || (sourceSize < 0)) - { - *err = U_ILLEGAL_ARGUMENT_ERROR; - return 0; - } - - /*if there is no input data, we're done */ - if (sourceSize == 0) - { - /*in case the caller passed an output ptr - *we update it - */ - return 0; - } - - /*create the converters */ - inConverter = ucnv_open (fromConverterName, err); - if (U_FAILURE (*err)) return 0; - outConverter = ucnv_open (toConverterName, err); - if (U_FAILURE (*err)) - { - ucnv_close (inConverter); - return 0; - } - - - if (targetSize > 0) - { - T_UConverter_fromCodepageToCodepage (outConverter, - inConverter, - &myTarget, - target + targetSize, - &mySource, - mySource_limit, - NULL, - TRUE, - err); - } - - - /*Updates targetCapacity to contain the number of bytes written to target */ - targetCapacity = myTarget - target; - if (targetSize == 0) - { - *err = U_BUFFER_OVERFLOW_ERROR; - } - - /* If the output buffer is exhausted, we need to stop writing - * to it but continue the conversion in order to store in targetSize - * the number of bytes that was required*/ - if (*err == U_BUFFER_OVERFLOW_ERROR) - { - char target2[CHUNK_SIZE]; - char *target2_alias = target2; - const char *target2_limit = target2 + CHUNK_SIZE; - - /*We use a stack allocated buffer around which we loop - *(in case the output is greater than CHUNK_SIZE) - */ - - while (*err == U_BUFFER_OVERFLOW_ERROR) - { - *err = U_ZERO_ERROR; - target2_alias = target2; - T_UConverter_fromCodepageToCodepage (outConverter, - inConverter, - &target2_alias, - target2_limit, - &mySource, - mySource_limit, - NULL, - TRUE, - err); - - /*updates the output parameter to contain the number of char required */ - targetCapacity += (target2_alias - target2) + 1; - } - /*We will set the erro code to BUFFER_OVERFLOW_ERROR only if - *nothing graver happened in the previous loop*/ - (targetCapacity)--; - if (U_SUCCESS (*err)) - *err = U_BUFFER_OVERFLOW_ERROR; - } - - ucnv_close (inConverter); - ucnv_close (outConverter); - - return targetCapacity; -} - -void Converter_fromUnicode(UConverter * _this, - char **target, - const char *targetLimit, - const UChar ** source, - const UChar * sourceLimit, - int32_t *offsets, - int flush, - UErrorCode * err) -{ - int chardone; - const UChar *mySource = *source; - unsigned char *myTarget = (unsigned char *) *target; - - int32_t targetLength = targetLimit - (char *) myTarget; - int32_t sourceLength = (sourceLimit - mySource) * 2; - unsigned char targetChar = 0x00; - /* pick up the iconv handle and perform the conversion */ - errno = 0; - chardone =iconv(_this->sharedData->fromiconv_handle,(char**)source, (size_t*) &sourceLength,target,(size_t *)&targetLength); - if (errno!=0) - if (errno == E2BIG) - { - *err = U_BUFFER_OVERFLOW_ERROR; - return; - } - else - - if ((errno ==EBADDATA)|| (errno ==ECONVERT)) - - { - char errno_id[7]; - send_message(NULL,ICONV_CONVERT_PROBLEM,'d'); - convert_errno(errno_id,errno); - send_message(NULL,errno_id,'d'); - *err = U_INVALID_CHAR_FOUND; - return; - } - - - return; - } - -void Convert_toUnicode(UConverter * _this, - UChar ** target, - const UChar * targetLimit, - const char **source, - const char *sourceLimit, - int32_t *offsets, - int flush, - UErrorCode * err) -{ - char *mySource = (char *) *source; - UChar *myTarget = *target; - - int32_t targetLength = (targetLimit - myTarget)*2; /* multiply by 2 */ - int32_t sourceLength = (sourceLimit - (char *) mySource); - int chardone; - /* pick up the iconv handle */ - errno = 0; - chardone =iconv(_this->sharedData->toiconv_handle,(char**)source, (size_t*) &sourceLength,(char **)target,(size_t *)&targetLength); - if (errno!=0) - { - if (errno == E2BIG) - { - *err = U_BUFFER_OVERFLOW_ERROR; - return; - } - else - - if ((errno ==EBADDATA)|| (errno ==ECONVERT)) - - { - char errno_id[7]; - send_message(NULL,ICONV_CONVERT_PROBLEM,'d'); - convert_errno(errno_id,errno); - send_message(NULL,errno_id,'d'); - *err = U_INVALID_CHAR_FOUND; - return; - - } - -} - - - return; -} - -UChar getNextUChar(UConverter* converter, - const char** source, - const char* sourceLimit, - UErrorCode* err) -{ - UChar myUChar; - UChar* myUCharptr; - size_t numberibytes=sizeof(UChar); - size_t numberobytes=sizeof(UChar); - int chardone; - if ((*source)+1 > sourceLimit) - { - *err = U_INDEX_OUTOFBOUNDS_ERROR; - return 0xFFFD; - } - - - /*pick up the iconv handle */ - /* convert the requested character - need to cache characters 6 will do - XMLReader is using this function to get header to process*/ - myUCharptr = &myUChar; - chardone =iconv(converter->sharedData->toiconv_handle,(char**)source, (size_t*) &numberibytes,(char **)&myUCharptr,(size_t *)&numberobytes); - if (myUChar != 0xFFFD) return myUChar; - else - { - UChar* myUCharPtr = &myUChar; - const char* sourceFinal = *source; - - *err = U_INVALID_CHAR_FOUND; - - - /*makes the internal caching transparent to the user*/ - if (*err == U_INDEX_OUTOFBOUNDS_ERROR) *err = U_ZERO_ERROR; - - return myUChar; - } -} - -XERCES_CPP_NAMESPACE_END diff --git a/src/xercesc/util/Transcoders/Iconv400/iconv_cnv.hpp b/src/xercesc/util/Transcoders/Iconv400/iconv_cnv.hpp deleted file mode 100644 index 8f93979ad0f0bbf3922faf428f3bc0a88bf2c6b9..0000000000000000000000000000000000000000 --- a/src/xercesc/util/Transcoders/Iconv400/iconv_cnv.hpp +++ /dev/null @@ -1,311 +0,0 @@ -#if (__OS400_TGTVRM__>=510) /* @01a */ - #pragma datamodel(P128) /* @01a */ -#endif /* @01a */ - -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -/* - * $Id$ - */ - -#if !defined(XERCESC_INCLUDE_GUARD_ICONVUCNV_HPP) -#define XERCESC_INCLUDE_GUARD_ICONVUCNV_HPP - -#include "utypes.h" - -XERCES_CPP_NAMESPACE_BEGIN - -/** - * Creates a UConverter object with the names specified as a C string. - * The actual name will be resolved with the alias file. - * if <TT>NULL</TT> is passed for the converter name, it will create one with the - * getDefaultName return value. - * @param converterName : name of the uconv table - * @param err outgoing error status <TT>MEMORY_ALLOCATION_ERROR, TABLE_NOT_FOUND</TT> - * @return the created Unicode converter object, or <TT>NULL</TT> if an error occured - * @see ucnv_openU - * @see ucnv_openCCSID - * @see ucnv_close - */ - -U_CAPI -UConverter* U_EXPORT2 ucnv_open (const char *converterName, - UErrorCode * err); - - -/** - * Creates a Unicode converter with the names specified as unicode string. The name should be limited to - * the ASCII-7 alphanumerics range. The actual name will be resolved with the alias file. - * if <TT>NULL</TT> is passed for the converter name, it will create one with the - * getDefaultName return value. - * @param converterName : name of the uconv table in a zero terminated Unicode string - * @param err outgoing error status <TT>MEMORY_ALLOCATION_ERROR, TABLE_NOT_FOUND</TT> - * @return the created Unicode converter object, or <TT>NULL</TT> if an error occured - * @see ucnv_open - * @see ucnv_openCCSID - * @see ucnv_close - */ -U_CAPI UConverter* U_EXPORT2 ucnv_openU (const UChar * name, - UErrorCode * err); - - - -/** - * Creates a UConverter object using a CCSID number. - * @param codepage : codepage # of the uconv table - * @param platform : codepage's platform (now only <TT>IBM</TT> supported) - * @param err error status <TT>MEMORY_ALLOCATION_ERROR, TABLE_NOT_FOUND</TT> - * @return the created Unicode converter object, or <TT>NULL</TT> if and error occured - * @see ucnv_open - * @see ucnv_openU - * @see ucnv_close - */ - - -U_CAPI void U_EXPORT2 ucnv_close (UConverter * converter); - - - - -/** - * Returns the maximum length of bytes used by a character. This varies between 1 and 4 - * @param converter the Unicode converter - * @return the maximum number of bytes allowed by this particular converter - * @see ucnv_getMinCharSize - */ -U_CAPI int8_t U_EXPORT2 - ucnv_getMaxCharSize (const UConverter * converter); - - -/** - * Returns the minimum byte length for characters in this codepage. This is either - * 1 or 2 for all supported codepages. - * @param converter the Unicode converter - * @return the minimum number of bytes allowed by this particular converter - * @see ucnv_getMaxCharSize - */ -U_CAPI int8_t U_EXPORT2 - ucnv_getMinCharSize (const UConverter * converter); - - -/** - * Transcodes an array of unicode characters to an array of codepage characters. - * The source pointer is an I/O parameter, it starts out pointing where the function is - * to begin transcoding, and ends up pointing after the first sequence of the bytes - * that it encounters that are semantically invalid. - * if ucnv_setToUCallBack is called with an action other than <TT>STOP</TT> - * before a call is made to this API, <TT>consumed</TT> and <TT>source</TT> should point to the same place - * (unless <TT>target</TT> ends with an imcomplete sequence of bytes and <TT>flush</TT> is <TT>FALSE</TT>). - * the <TT>target</TT> buffer buffer needs to be a least the size of the maximum # of bytes per characters - * allowed by the target codepage. - * @param converter the Unicode converter - * @param converter the Unicode converter - * @param target : I/O parameter. Input : Points to the beginning of the buffer to copy - * codepage characters to. Output : points to after the last codepage character copied - * to <TT>target</TT>. - * @param targetLimit the pointer to the end of the <TT>target</TT> array - * @param source the source Unicode character array - * @param sourceLimit the pointer to the end of the source array - * @param offsets if NULL is passed, nothing will happen to it, otherwise it needs to have the same number - * of allocated cells as <TT>target</TT>. Will fill in offsets from target to source pointer - * e.g: <TT>offsets[3]</TT> is equal to 6, it means that the <TT>target[3]</TT> was a result of transcoding <TT>source[6]</TT> - * For output data carried across calls -1 will be placed for offsets. - * @param flush <TT>TRUE</TT> if the buffer is the last buffer of the conversion interation - * and the conversion will finish with this call, FALSE otherwise. - * @param err the error status. <TT>ILLEGAL_ARGUMENT_ERROR</TT> will be returned if the - * converter is <TT>NULL</TT>. - * @see ucnv_fromUChars - * @see ucnv_convert - * @see ucnv_getMinCharSize - * @see ucnv_setToUCallBack - */ - -U_CAPI - void U_EXPORT2 ucnv_fromUnicode (UConverter * converter, - char **target, - const char *targetLimit, - const UChar ** source, - const UChar * sourceLimit, - int32_t* offsets, - int flush, - UErrorCode * err); - - -/** - * Converts an array of codepage characters into an array of unicode characters. - * The source pointer is an I/O parameter, it starts out pointing at the place - * to begin translating, and ends up pointing after the first sequence of the bytes - * that it encounters that are semantically invalid. - * if ucnv_setFromUCallBack is called with an action other than STOP - * before a call is made to this API, consumed and source should point to the same place - * (unless target ends with an imcomplete sequence of bytes and flush is FALSE). - * @param converter the Unicode converter - * @param target : I/O parameter. Input : Points to the beginning of the buffer to copy - * Unicode characters to. Output : points to after the last UChar copied to target. - * @param targetLimit the pointer to the end of the target array - * @param source the source codepage character array - * @param sourceLimit the pointer to the end of the source array - * @param offsets if NULL is passed, nothing will happen to it, otherwise it needs to have the same number - * of allocated cells as <TT>target</TT>. Will fill in offsets from target to source pointer - * e.g: <TT>offsets[3]</TT> is equal to 6, it means that the <TT>target[3]</TT> was a result of transcoding <TT>source[6]</TT> - * For output data carried across calls -1 will be placed for offsets. - * @param flush TRUE if the buffer is the last buffer and the conversion will finish - * in this call, FALSE otherwise. - * @param err the error code status <TT>ILLEGAL_ARGUMENT_ERROR</TT> will be returned if the - * converter is <TT>NULL</TT>, or if <TT>targetLimit</TT> and <TT>sourceLimit</TT> are misaligned. - * @see ucnv_toUChars - * @see ucnv_getNextUChar - * @see ucnv_convert - * @see ucnv_setFromUCallBack - */ - -U_CAPI - void U_EXPORT2 ucnv_toUnicode (UConverter * converter, - UChar ** target, - const UChar * targetLimit, - const char **source, - const char *sourceLimit, - int32_t* offsets, - int flush, - UErrorCode * err); - - -/** - * Transcodes the source Unicode string to the target string in a codepage encoding - * with the specified Unicode converter. For example, if a Unicode to/from JIS - * converter is specified, the source string in Unicode will be transcoded to JIS - * encoding. The result will be stored in JIS encoding. - * if any problems during conversion are encountered it will SUBSTITUTE with the default (initial) - * substitute characters. - * This function is a more convenient but less efficient version of \Ref{ucnv_fromUnicode}. - * @param converter the Unicode converter - * @param source the <TT>source</TT> Unicode string (zero Terminated) - * @param target the <TT>target</TT> string in codepage encoding (<STRONG>not zero-terminated</STRONG> because some - * codepage do not use '\0' as a string terminator - * @param targetCapacity Input the number of bytes available in the <TT>target</TT> buffer - * @param err the error status code. - * <TT>INDEX_OUTOFBOUNDS_ERROR</TT> will be returned if the - * the # of bytes provided are not enough for transcoding. - * <TT>ILLEGAL_ARGUMENT_ERROR</TT> is returned if the converter is <TT>NULL</TT> or the source or target string is empty. - * <TT>BUFFER_OVERFLOW_ERROR</TT> when <TT>targetSize</TT> turns out to be bigger than <TT>targetCapacity</TT> - * @return number of bytes needed in target, regardless of <TT>targetCapacity</TT> - * @see ucnv_fromUnicode - * @see ucnv_convert - */ -U_CAPI - int32_t U_EXPORT2 ucnv_fromUChars (const UConverter * converter, - char *target, - int32_t targetCapacity, - const UChar * source, - UErrorCode * err); - - - - - -/** - * Transcode the source string in codepage encoding to the target string in - * Unicode encoding. For example, if a Unicode to/from JIS - * converter is specified, the source string in JIS encoding will be transcoded - * to Unicode and placed into a provided target buffer. - * if any problems during conversion are encountered it will SUBSTITUTE with the Unicode REPLACEMENT char - * We recomment, the size of the target buffer needs to be at least as long as the maximum # of bytes per char - * in this character set. - * A zero-terminator will be placed at the end of the target buffer - * This function is a more convenient but less efficient version of \Ref{ucnv_toUnicode}. - * @param converter the Unicode converter - * @param source the source string in codepage encoding - * @param target the target string in Unicode encoding - * @param targetCapacity capacity of the target buffer - * @param sourceSize : Number of bytes in <TT>source</TT> to be transcoded - * @param err the error status code - * <TT>MEMORY_ALLOCATION_ERROR</TT> will be returned if the - * the internal process buffer cannot be allocated for transcoding. - * <TT>ILLEGAL_ARGUMENT_ERROR</TT> is returned if the converter is <TT>NULL</TT> or - * if the source or target string is empty. - * <TT>BUFFER_OVERFLOW_ERROR</TT> when the input buffer is prematurely exhausted and targetSize non-<TT>NULL</TT>. - * @return the number of UChar needed in target (including the zero terminator) - * @see ucnv_getNextUChar - * @see ucnv_toUnicode - * @see ucnv_convert - */ -U_CAPI - int32_t U_EXPORT2 ucnv_toUChars (const UConverter * converter, - UChar * target, - int32_t targetCapacity, - const char *source, - int32_t sourceSize, - UErrorCode * err); - -/******************************** - * Will convert a codepage buffer one character at a time. - * This function was written to be efficient when transcoding small amounts of data at a time. - * In that case it will be more efficient than \Ref{ucnv_toUnicode}. - * When converting large buffers use \Ref{ucnv_toUnicode}. - *@param converter an open UConverter - *@param source the address of a pointer to the codepage buffer, will be updated to point after - *the bytes consumed in the conversion call. - *@param points to the end of the input buffer - *@param err fills in error status (see ucnv_toUnicode) - *@return a UChar resulting from the partial conversion of source - *@see ucnv_toUnicode - *@see ucnv_toUChars - *@see ucnv_convert - */ -U_CAPI - UChar U_EXPORT2 ucnv_getNextUChar (UConverter * converter, - const char **source, - const char *sourceLimit, - UErrorCode * err); - - -/************************** -* Will convert a sequence of bytes from one codepage to another. -* This is <STRONG>NOT AN EFFICIENT</STRONG> way to transcode. -* use \Ref{ucnv_toUnicode} and \Ref{ucnv_fromUnicode} for efficiency -* @param toConverterName: The name of the converter that will be used to encode the output buffer -* @param fromConverterName: The name of the converter that will be used to decode the input buffer -* @param target: Pointer to the output buffer to write to -* @param targetCapacity: on input contains the capacity of target -* @param source: Pointer to the input buffer -* @param sourceLength: on input contains the capacity of source -* @param err: fills in an error status -* @return will be filled in with the number of bytes needed in target -* @see ucnv_fromUnicode -* @see ucnv_toUnicode -* @see ucnv_fromUChars -* @see ucnv_toUChars -* @see ucnv_getNextUChar -*/ -U_CAPI - int32_t U_EXPORT2 ucnv_convert (const char *toConverterName, - const char *fromConverterName, - char *target, - int32_t targetCapacity, - const char *source, - int32_t sourceLength, - UErrorCode * err); - -XERCES_CPP_NAMESPACE_END - -#endif - -#if (__OS400_TGTVRM__>=510) /* @01a */ - #pragma datamodel(pop) /* @01a */ -#endif /* @01a */ - diff --git a/src/xercesc/util/Transcoders/Iconv400/iconv_util.cpp b/src/xercesc/util/Transcoders/Iconv400/iconv_util.cpp deleted file mode 100644 index f5c4e8866280a0f9b4a3aee4897bf5b2ea2237ac..0000000000000000000000000000000000000000 --- a/src/xercesc/util/Transcoders/Iconv400/iconv_util.cpp +++ /dev/null @@ -1,248 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -/* - * $Id$ - */ - -#include <xercesc/util/XercesDefs.hpp> -#include <iconv.h> -#include <xercesc/util/Platforms/OS400/OS400PlatformUtils.hpp> -#include <stdlib.h> -#include <unistd.h> -#include <iconv_util.hpp> -#include <iconv_cnv.hpp> -#include <ctype.h> -#include <qlgusr.h> // @15a - - -XERCES_CPP_NAMESPACE_BEGIN - -#define COPYRIGHT_STRING_LENGTH 200 -#define MAX_STRLEN 0x00FFFFF -#define CHARCCSIDSIZE 5 -static UConverter* _defaultConverter = NULL; -static UErrorCode gErr = U_ZERO_ERROR; - -#include "utypes.h" - -// void shareConverterData (UConverterSharedData * data,char *InDescriptor) ; -// UConverterSharedData *getSharedConverterData(char *Descriptor); -#define defaultConverter (_defaultConverter==NULL)?_defaultConverter=ucnv_open(NULL, &gErr):_defaultConverter - - -/* Cleans up the default converter if it has been allocated. - This is a little messy, but I know the code well enough to - do anything neater. - */ -void cleanupDefaultConverter() -{ - if (_defaultConverter != NULL) { - ucnv_close(_defaultConverter); - _defaultConverter = NULL; - } -} - -static char DEFAULT_CONVERTER_NAME[60] = ""; -const char* iconv_getDefaultCodepage() -{ - strcpy(DEFAULT_CONVERTER_NAME, "ibm037"); - return DEFAULT_CONVERTER_NAME; -} -/* placeholder function to be deleted in 3_0 */ - - -/* used by String.c */ - - - - -int32_t -u_strlen(const UChar *s) -{ - int32_t i = 0; - - while(*s++) - i++; - return i; -} - -/* note sure if needed - think that this is needed in cnv.c */ -char* u_austrcpy(char *s1, - const UChar *ucs2 ) -{ - char * anchor = s1; /* save the start of result string */ - UErrorCode err = U_ZERO_ERROR; - int32_t len; - len = ucnv_fromUChars(defaultConverter, - s1, - MAX_STRLEN, - ucs2, - &err); - - s1[len] = '\0'; - return s1; - -} - -/*Logic determines if the converter is Algorithmic AND/OR cached - *depending on that: - * -we either go to get data from disk and cache it (Data=TRUE, Cached=False) - * -Get it from a Hashphkramtable (Data=X, Cached=TRUE) - * -Call dataConverter initializer (Data=TRUE, Cached=TRUE) - * -Call AlgorithmicConverter initializer (Data=FALSE, Cached=TRUE) - */ -// int QlgCvtTextDescToDesc(int,int,char *,int,char *,int,int); @14d - - - -UConverter * - createConverter (const char *converterName, UErrorCode * err) -{ - char realName[MAX_CONVERTER_NAME_LENGTH]; - char uppercased_converterName[MAX_CONVERTER_NAME_LENGTH]; - UConverter *myUConverter = NULL; - UConverterSharedData *mySharedConverterData = NULL; - - /* following parameters are passed to the convert text decscriptor - to descriptor */ - int InType; - int OutType=1; - char *InDescriptor; - int InDescSize; - char OutDescriptor[CHARCCSIDSIZE]; /* 5 = size of a CCSID id on AS/400*/ - int OutDescSize; - int JobCCSID=0; - char *inchar, *outchar; /* input and output conversion pointers*/ - int tempchar; - if (U_FAILURE (*err)) - return NULL; -/******************************************************************/ -/* assume name is in EBCDIC. The convetername is assumed to be -/* either upper/lower case ebcdic and the text converter requires -/* upper case - Since we do not know we will convert to upper case -** just in case -/******************************************************************/ -inchar = (char*)converterName; -outchar = &uppercased_converterName[0]; -while (*inchar) /*except for null terminator uppercase inputs*/ -{ - tempchar = (int)(*inchar); - *outchar=(char)toupper(tempchar); - inchar ++; - outchar ++; -} - if (outchar -&uppercased_converterName[0]<=MAX_CONVERTER_NAME_LENGTH) - *outchar = '\0'; /* replace the terminator */ - if(!strcmp(uppercased_converterName, "IBM-37")) /* We special-case this one */ - { - memcpy(uppercased_converterName, "IBM-037", 7); - memset(uppercased_converterName + 7, '\0',1); - } -/******************************************************************/ -/* convert name to AS/400 CCSID -** if CCSID is returned then we can complete building the converter -** otherwise we will return the same error as ICU converters -*/ -/******************************************************************/ - InType = 11; /*set for IANA initially */ - if (QlgCvtTextDescToDesc(InType, OutType,(char *)uppercased_converterName, strlen(uppercased_converterName),&OutDescriptor[0],sizeof(OutDescriptor),JobCCSID)<0) - { - InType = 3; /* change to AIX 4.1 if we fail above */ - if (QlgCvtTextDescToDesc(InType, OutType,(char *)uppercased_converterName, strlen(uppercased_converterName),&OutDescriptor[0],sizeof(OutDescriptor),JobCCSID)<0) - { - *err = U_INVALID_TABLE_FILE; - send_message((char *)converterName,ICONV_CCSID_PROBLEM,'d'); - return NULL; - } - } -/*****************************************************************/ -/* create a new converter */ -/*****************************************************************/ - myUConverter = createNewConverter(&OutDescriptor[0], err); - - if (U_FAILURE (*err) || (myUConverter == NULL)) - { - return NULL; - } - return myUConverter; - -} - - -UConverter* createNewConverter(const char *name, UErrorCode *err) -{ - char temp[33]; - int32_t i = 0; - const int8_t *myByteArray = NULL; - const uint16_t *myIndexArray = NULL; - int32_t myValuesCount = 0; - int32_t myIndexCount = 0; - UConverter *myConverter = NULL; - int32_t myCheck; - int8_t errorLevel = 0; - char throwAway[COPYRIGHT_STRING_LENGTH]; - char UNICODE_CCSID_ID_O[33]="IBMCCSID134880000000"; - char UNICODE_CCSID_ID_I[33]="IBMCCSID13488"; - char my_CCSID_ID[33]="\0"; - char CONVERT_ID_START[9] ="IBMCCSID"; /* include null terminator for strcat */ - char DEFAULTS[9] = "00000000"; - if (U_FAILURE (*err)) - return NULL; -/* create the base shell for the converter */ - myConverter = (UConverter *) malloc (sizeof (UConverter)); - if (myConverter == NULL) - { - *err = U_MEMORY_ALLOCATION_ERROR; - return NULL; - } -/* create the "shared area' and link into the shell */ - myConverter->sharedData = - (UConverterSharedData *) malloc (sizeof (UConverterSharedData)); - if (myConverter->sharedData == NULL) - { - free (myConverter); - *err = U_MEMORY_ALLOCATION_ERROR; - return NULL; - } - - memset(my_CCSID_ID, '\0', 33); /* sizeof(my_CCSID_ID)); */ - memcpy(my_CCSID_ID,&CONVERT_ID_START[0],strlen(CONVERT_ID_START)+1); - memcpy(&my_CCSID_ID[8],&name[0],5); - memcpy(&my_CCSID_ID[13],&DEFAULTS[0],7); - memset(temp, '\0', 33); - memcpy(temp, my_CCSID_ID, 13); - - myConverter->sharedData->toiconv_handle = iconv_open(UNICODE_CCSID_ID_I,my_CCSID_ID); -/* memset(&my_CCSID_ID[13],'0',19); clear out the non necessary data to reverse */ - my_CCSID_ID[13] = '\0'; - myConverter->sharedData->fromiconv_handle = iconv_open(temp,UNICODE_CCSID_ID_O); - if ((myConverter->sharedData->toiconv_handle.return_value ==-1) ||(myConverter->sharedData->fromiconv_handle.return_value==-1)) - - { - /*If it isn't any of the above, the file is invalid */ - *err = U_INVALID_TABLE_FILE; - free (myConverter->sharedData); - free (myConverter); - } - - return myConverter; - - -} - -XERCES_CPP_NAMESPACE_END diff --git a/src/xercesc/util/Transcoders/Iconv400/iconv_util.hpp b/src/xercesc/util/Transcoders/Iconv400/iconv_util.hpp deleted file mode 100644 index 5c25f53dd2aba47262f028c6c8e5192556096a1f..0000000000000000000000000000000000000000 --- a/src/xercesc/util/Transcoders/Iconv400/iconv_util.hpp +++ /dev/null @@ -1,124 +0,0 @@ -#if (__OS400_TGTVRM__>=510) /* @01a */ - #pragma datamodel(P128) /* @01a */ -#endif /* @01a */ - -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -/* - * $Id$ - */ - - -#include "utypes.h" -#include <iconv.h> - -XERCES_CPP_NAMESPACE_BEGIN - -const char* iconv_getDefaultCodepage(void); - -// extern "C" int QlgCvtTextDescToDesc (int, int, char *, int, char*, int, int); - -#define MAX_CONVERTER_NAME_LENGTH 60 -#define MAX_SUBCHAR_LEN 4 -#define ERROR_BUFFER_LENGTH 20 -typedef enum {UNKNOWN = -1, IBM = 0} -UCNV_PLATFORM; -typedef enum -{ - UNSUPPORTED_CONVERTER = -1, - SBCS = 0, - DBCS = 1, - MBCS = 2, - LATIN_1 = 3, - UTF8 = 4, - UTF16_BigEndian = 5, - UTF16_LittleEndian = 6, - EBCDIC_STATEFUL = 7, - ISO_2022 = 8, - JIS = 9, - EUC = 10, - GB = 11 -} -UCNV_TYPE; -int32_t -u_strlen(const UChar *s); - -/* note sure if needed - think that this is needed in cnv.c */ -char* u_austrcpy(char *s1, - const UChar *ucs2 ); - -/*Defines the struct of a UConverterSharedData the immutable, shared part of - *UConverter - */ -typedef struct - { - uint32_t referenceCounter; /*used to count number of clients */ - char name[MAX_CONVERTER_NAME_LENGTH]; /*internal name of the converter */ - UCNV_PLATFORM platform; /*platform of the converter (only IBM now */ - int32_t codepage; /*codepage # (now IBM-$codepage) */ - UCNV_TYPE conversionType; /*conversion type */ - int8_t minBytesPerChar; /*Minimum # bytes per char in this codepage */ - int8_t maxBytesPerChar; /*Maximum # bytes per char in this codepage */ - - struct - { /*initial values of some members of the mutable part of object */ - - int8_t subCharLen; - unsigned char subChar[MAX_SUBCHAR_LEN]; - } defaultConverterValues ; - - iconv_t toiconv_handle ; /* handle to convert to unicode*/ - iconv_t fromiconv_handle; /* handle to convert from unicode*/ - } -UConverterSharedData; - - -/*Defines a UConverter, the lightweight mutable part the user sees */ -struct UConverter - { - - - - int8_t pad; - int32_t mode; - int8_t subCharLen; /*length of the codepage specific character sequence */ - unsigned char subChar[MAX_SUBCHAR_LEN]; /*codepage specific character sequence */ - - - UConverterSharedData *sharedData; /*Pointer to the shared immutable part of the - *converter object - */ - - - }; - -typedef struct UConverter UConverter; - -UConverter* createNewConverter(const char *name, UErrorCode *err); - -/*Initializes the mutable lightweight portion of the object - *By copying data from UConverter->sharedData->defaultConverter - */ -static void initializeDataConverter (UConverter * myUConverter); -UConverter *createConverter (const char *converterName, UErrorCode * err); - -XERCES_CPP_NAMESPACE_END -#if (__OS400_TGTVRM__>=510) /* @01a */ - #pragma datamodel(pop) /* @01a */ -#endif /* @01a */ - diff --git a/src/xercesc/util/Transcoders/Iconv400/pos400.h b/src/xercesc/util/Transcoders/Iconv400/pos400.h deleted file mode 100644 index 3b6ee7b626029d4dc6390d915e8acd10406fde51..0000000000000000000000000000000000000000 --- a/src/xercesc/util/Transcoders/Iconv400/pos400.h +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -/* - * $Id$ - */ - -/* Define the platform we're on. */ -#ifndef OS400 -#define OS400 -#endif - -/* Define whether inttypes.h is available */ -#define HAVE_INTTYPES_H 0 - -/* Determines whether specific types are available */ -#define HAVE_INT8_T 0 -#define HAVE_UINT8_T 0 -#define HAVE_INT16_T 0 -#define HAVE_UINT16_T 0 -#define HAVE_INT32_T 0 -#define HAVE_UINT32_T 0 -#define HAVE_BOOL_T 0 - -/* Determines the endianness of the platform */ -#define U_IS_BIG_ENDIAN 1 - -/*===========================================================================*/ -/* Generic data types */ -/*===========================================================================*/ - -/* If your platform does not have the <inttypes.h> header, you may - need to edit the typedefs below. */ -#if HAVE_INTTYPES_H -#include <inttypes.h> -#else - -#if ! HAVE_INT8_T -typedef signed char int8_t; -#endif - -#if ! HAVE_UINT8_T -typedef unsigned char uint8_t; -#endif - -#if ! HAVE_INT16_T -typedef signed short int16_t; -#endif - -#if ! HAVE_UINT16_T -typedef unsigned short uint16_t; -#endif - -#if ! HAVE_INT32_T -typedef signed long int32_t; -#endif - -#if ! HAVE_UINT32_T -typedef unsigned long uint32_t; -#endif - -#endif - -#include <limits.h> -#define T_INT32_MAX (LONG_MAX) - -/*===========================================================================*/ -/* Symbol import-export control */ -/*===========================================================================*/ - -#define U_EXPORT -#define U_EXPORT2 -#define U_IMPORT diff --git a/src/xercesc/util/Transcoders/Iconv400/utypes.h b/src/xercesc/util/Transcoders/Iconv400/utypes.h deleted file mode 100644 index 04d16f46fd090c618db03e1921b31d87a878e6d9..0000000000000000000000000000000000000000 --- a/src/xercesc/util/Transcoders/Iconv400/utypes.h +++ /dev/null @@ -1,231 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -/* - * $Id$ - */ - -#ifndef UTYPES_H -#define UTYPES_H -#include <wchar.h> -#include <stdlib.h> - -/*===========================================================================*/ -/* Include platform-dependent definitions */ -/* which are contained in the platform-specific file platform.h */ -/*===========================================================================*/ - -#include "pos400.h" - -XERCES_CPP_NAMESPACE_BEGIN - -/* XP_CPLUSPLUS is a cross-platform symbol which should be defined when - using C++. It should not be defined when compiling under C. */ -#ifdef __cplusplus -# ifndef XP_CPLUSPLUS -# define XP_CPLUSPLUS -# endif -#else -# undef XP_CPLUSPLUS -#endif - -/*===========================================================================*/ -/* Boolean data type */ -/*===========================================================================*/ - -#if ! HAVE_BOOL_T -typedef int8_t bool_t; -#endif - -#ifndef TRUE -# define TRUE 1 -#endif -#ifndef FALSE -# define FALSE 0 -#endif - -/*===========================================================================*/ -/* Unicode string offset */ -/*===========================================================================*/ -typedef int32_t UTextOffset; - -/*===========================================================================*/ -/* Unicode character */ -/*===========================================================================*/ -typedef uint16_t UChar; - - -/*===========================================================================*/ -/* For C wrappers, we use the symbol U_CAPI. */ -/* This works properly if the includer is C or C++. */ -/* Functions are declared U_CAPI return-type U_EXPORT2 function-name() ... */ -/*===========================================================================*/ - -#ifdef XP_CPLUSPLUS -# define U_CFUNC extern "C" -# define U_CDECL_BEGIN extern "C" { -# define U_CDECL_END } -#else -# define U_CFUNC -# define U_CDECL_BEGIN -# define U_CDECL_END -#endif -#define U_CAPI U_CFUNC U_EXPORT - - -/* Define NULL pointer value if it isn't already defined */ - -#ifndef NULL -#ifdef XP_CPLUSPLUS -#define NULL 0 -#else -#define NULL ((void *)0) -#endif -#endif - -/* Maximum value of a (void*) - use to indicate the limit of - an 'infinite' buffer. */ -#define U_MAX_PTR ((void*)-1) - - - -/*===========================================================================*/ -/* UErrorCode */ -/*===========================================================================*/ - -/** Error code to replace exception handling */ -#ifdef __OS400__ -enum UErrorCode1 { -#else -enum UErrorCode { -#endif - U_ERROR_INFO_START = -128, /* Start of information results (semantically successful) */ - U_USING_FALLBACK_ERROR = -128, - U_USING_DEFAULT_ERROR = -127, - U_ERROR_INFO_LIMIT, - - U_ZERO_ERROR = 0, /* success */ - - U_ILLEGAL_ARGUMENT_ERROR = 1, /* Start of codes indicating failure */ - U_MISSING_RESOURCE_ERROR = 2, - U_INVALID_FORMAT_ERROR = 3, - U_FILE_ACCESS_ERROR = 4, - U_INTERNAL_PROGRAM_ERROR = 5, /* Indicates a bug in the library code */ - U_MESSAGE_PARSE_ERROR = 6, - U_MEMORY_ALLOCATION_ERROR = 7, /* Memory allocation error */ - U_INDEX_OUTOFBOUNDS_ERROR = 8, - U_PARSE_ERROR = 9, /* Equivalent to Java ParseException */ - U_INVALID_CHAR_FOUND = 10, /* In the Character conversion routines: Invalid character or sequence was encountered*/ - U_TRUNCATED_CHAR_FOUND = 11, /* In the Character conversion routines: More bytes are required to complete the conversion successfully*/ - U_ILLEGAL_CHAR_FOUND = 12, /* In codeset conversion: a sequence that does NOT belong in the codepage has been encountered*/ - U_INVALID_TABLE_FORMAT = 13, /* Conversion table file found, but corrupted*/ - U_INVALID_TABLE_FILE = 14, /* Conversion table file not found*/ - U_BUFFER_OVERFLOW_ERROR = 15, /* A result would not fit in the supplied buffer */ - U_UNSUPPORTED_ERROR = 16, /* Requested operation not supported in current context */ - U_ERROR_LIMIT -}; -#ifdef __OS400__ -typedef int UErrorCode; -#define U_SUCCESS(x) ((x)<=U_ZERO_ERROR) -#define U_FAILURE(x) ((x)>U_ZERO_ERROR) -#else -#ifndef XP_CPLUSPLUS -typedef enum UErrorCode UErrorCode; -#endif -#endif - - -/* Use the following to determine if an UErrorCode represents */ -/* operational success or failure. */ -#ifndef __OS400__ -#ifdef XP_CPLUSPLUS -inline bool_t U_SUCCESS(UErrorCode code) { return (bool_t)(code<=U_ZERO_ERROR); } -inline bool_t U_FAILURE(UErrorCode code) { return (bool_t)(code>U_ZERO_ERROR); } -#else -#define U_SUCCESS(x) ((x)<=U_ZERO_ERROR) -#define U_FAILURE(x) ((x)>U_ZERO_ERROR) -#endif -#endif - -/* Casting function for int32_t (backward compatibility version, here until - T_INT32 is replaced) */ -#define T_INT32(i) ((int32_t)i) - - -/*===========================================================================*/ -/* Debugging */ -/*===========================================================================*/ - -/* remove this */ - -/* This function is useful for debugging; it returns the text name */ -/* of an UErrorCode result. This is not the most efficient way of */ -/* doing this but it's just for Debug builds anyway. */ - -/* Do not use these arrays directly: they will move to a .c file! */ -static const char * -_uErrorInfoName[U_ERROR_INFO_LIMIT-U_ERROR_INFO_START]={ - "U_USING_FALLBACK_ERROR", - "U_USING_DEFAULT_ERROR" -}; - -static const char * -_uErrorName[U_ERROR_LIMIT]={ - "U_ZERO_ERROR", - - "U_ILLEGAL_ARGUMENT_ERROR", - "U_MISSING_RESOURCE_ERROR", - "U_INVALID_FORMAT_ERROR", - "U_FILE_ACCESS_ERROR", - "U_INTERNAL_PROGRAM_ERROR", - "U_MESSAGE_PARSE_ERROR", - "U_MEMORY_ALLOCATION_ERROR", - "U_INDEX_OUTOFBOUNDS_ERROR", - "U_PARSE_ERROR", - "U_INVALID_CHAR_FOUND", - "U_TRUNCATED_CHAR_FOUND", - "U_ILLEGAL_CHAR_FOUND", - "U_INVALID_TABLE_FORMAT", - "U_INVALID_TABLE_FILE", - "U_BUFFER_OVERFLOW_ERROR", - "U_UNSUPPORTED_ERROR" -}; - -#ifdef XP_CPLUSPLUS -inline const char * -errorName(UErrorCode code) -{ - if(code>=0 && code<U_ERROR_LIMIT) { - return _uErrorName[code]; - } else if(code>=U_ERROR_INFO_START && code<U_ERROR_INFO_LIMIT) { - return _uErrorInfoName[code-U_ERROR_INFO_START]; - } else { - return "[BOGUS UErrorCode]"; - } -} -#else -# define errorName(code) \ - ((code)>=0 && (code)<U_ERROR_LIMIT) ? \ - _uErrorName[code] : \ - ((code)>=U_ERROR_INFO_START && (code)<U_ERROR_INFO_LIMIT) ? \ - _uErrorInfoName[code-U_ERROR_INFO_START] : \ - "[BOGUS UErrorCode]" -#endif - -XERCES_CPP_NAMESPACE_END - -#endif /* _UTYPES */