diff --git a/tools/NLS/Xlat/Makefile b/tools/NLS/Xlat/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..1d2f46390ff37164e59210810c18f9c164cc8060 --- /dev/null +++ b/tools/NLS/Xlat/Makefile @@ -0,0 +1,106 @@ +# The Apache Software License, Version 1.1 +# +# Copyright (c) 2003 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. +# +# 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: +# "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 +# 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 +# DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR +# ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF +# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# 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 +# Business Machines, Inc., http://www.ibm.com . For more information +# on the Apache Software Foundation, please see +# <http://www.apache.org/>. +# +# +# +# REVISIT: this should really be generalized to support platforms +# other than Windows/MSVC++ and Linux/gcc. However, the portability of +# wide character I/O is very non-portable; so this is a nontrivial +# prospect. That's why this Makefile is provided only for gcc +# at the moment. + +XLAT_CPP_OBJECTS = \ + Xlat.o \ + Xlat_CppSrc.o \ + Xlat_ICUResourceBundle.o \ + Xlat_MsgCatalog.o \ + Xlat_Win32RC.o + + +PLATFORM = LINUX +COMPILER = g++ +GCC = yes +GXX = yes +CXXFLAGS = -w -O -D_GNU_SOURCE +CFLAGS = -w -O -D_GNU_SOURCE +LDFLAGS = +EXTRA_LIBS = +LIBRARY_SEARCH_PATHS=-L../../../lib/ +LIBRARY_NAMES=-lxerces-c +INCLUDES=-I../../../include +CMP= -c ${CXXFLAGS} +CC= ${COMPILER} -c -D_REENTRANT -fpic +LINK = ${COMPILER} -fpic ${LDFLAGS} +EXTRA_LINK_OPTIONS=-lc ${EXTRA_LIBS} +APP_NAME=NLSXlat + +all:: ${APP_NAME} + +${APP_NAME}:: ${XLAT_CPP_OBJECTS} + ${LINK} ${XLAT_CPP_OBJECTS} -o ${APP_NAME} ${LIBRARY_SEARCH_PATHS} ${LIBRARY_NAMES} ${EXTRA_LINK_OPTIONS} + +Xlat.o:: Xlat.cpp Xlat_ErrHandler.hpp Xlat_Formatter.hpp Xlat_Types.hpp + ${CC} ${INCLUDES} ${CMP} -o Xlat.o Xlat.cpp +Xlat_CppSrc.o:: Xlat_CppSrc.cpp Xlat_CppSrc.hpp + ${CC} ${INCLUDES} ${CMP} -o Xlat_CppSrc.o Xlat_CppSrc.cpp +Xlat_ICUResourceBundle.o:: Xlat_ICUResourceBundle.cpp Xlat_ICUResourceBundle.hpp + ${CC} ${INCLUDES} ${CMP} -o Xlat_ICUResourceBundle.o Xlat_ICUResourceBundle.cpp +Xlat_MsgCatalog.o:: Xlat_MsgCatalog.cpp Xlat_MsgCatalog.hpp + ${CC} ${INCLUDES} ${CMP} -o Xlat_MsgCatalog.o Xlat_MsgCatalog.cpp +Xlat_Win32RC.o:: Xlat_Win32RC.cpp Xlat_Win32RC.hpp + ${CC} ${INCLUDES} ${CMP} -o Xlat_Win32RC.o Xlat_Win32RC.cpp + +clean:: + rm -f ${XLAT_CPP_OBJECTS} ${APP_NAME} + diff --git a/tools/NLS/Xlat/Xlat.cpp b/tools/NLS/Xlat/Xlat.cpp index 1076185c6f5eeee36119aff7ff8a626f08faff47..53ea8c67c5b069b4d961192fe4de1f39875f9389 100644 --- a/tools/NLS/Xlat/Xlat.cpp +++ b/tools/NLS/Xlat/Xlat.cpp @@ -57,6 +57,9 @@ /* * $Log$ + * Revision 1.17 2003/04/14 08:41:00 gareth + * Xlat now works under linux - Big thanks to Neil Graham (I no longer have to find a windows box). Still slight problems working with glibc before 2.2.4 (If you mess up the parameters it seg faults due to handling of wprintf) + * * Revision 1.16 2002/12/12 23:40:39 peiyongz * normlize locale string. * @@ -141,7 +144,6 @@ #include "Xlat.hpp" - // --------------------------------------------------------------------------- // Static data // @@ -149,19 +151,23 @@ // This is the path, relative to the given input source root, to the // input file. The given local suffix must also be added to it. // --------------------------------------------------------------------------- -static XMLCh* const gRelativeInputPath = L"src/xercesc/NLS/"; +XMLCh* gRelativeInputPath = 0; // --------------------------------------------------------------------------- // Global data // --------------------------------------------------------------------------- -const XMLCh* typePrefixes[MsgTypes_Count] = -{ - L"W_" - , L"E_" - , L"F_" -}; +XMLCh* typePrefixes[MsgTypes_Count]; +// --------------------------------------------------------------------------- +// temporary variables/conversion utility functions +// We need different temps depending on treatment of wide characters +// --------------------------------------------------------------------------- +#ifdef longChars + char* fTmpStr = 0; +#else + wchar_t fTmpWStr[256]; +#endif // --------------------------------------------------------------------------- // Local data @@ -194,6 +200,25 @@ const XMLCh* gSrcRoot = 0; // --------------------------------------------------------------------------- // Local utility methods // --------------------------------------------------------------------------- + +// Initialize the global "constants" (that really require use of the transcoder) +void init_Globals(void) +{ + typePrefixes[0] = XMLString::transcode("W_"); + typePrefixes[1] = XMLString::transcode("E_"); + typePrefixes[2] = XMLString::transcode("F_"); + gRelativeInputPath = XMLString::transcode("src/xercesc/NLS/"); +} + +// Release the global "constants" (that really require use of the transcoder) +void release_Globals(void) +{ + for(int i=0; i<3; i++) + { + XMLString::release(&typePrefixes[i]); + } + XMLString::release(&gRelativeInputPath); +} // // This method is called to parse the parameters. They must be in this @@ -201,75 +226,100 @@ const XMLCh* gSrcRoot = 0; // // /SrcRoot=xxx /OutPath=xxx /OutFmt=xxx /Locale=xxx // -static bool parseParms(const int argC, XMLCh** argV) +//static bool parseParms(const int argC, XMLCh** argV) +bool parseParms(const int argC, XMLCh** argV) { if (argC < 5) return false; unsigned int curParm = 1; - - if (XMLString::startsWith(argV[curParm], L"/SrcRoot=")) + XMLCh *tmpXMLStr = XMLString::transcode("/SrcRoot="); + if (XMLString::startsWith(argV[curParm], tmpXMLStr)) { gSrcRoot = &argV[curParm][9]; } else { wprintf(L"\nExpected /SrcRoot=xxx. Got: %s\n", argV[curParm]); + XMLString::release(&tmpXMLStr); return false; } + XMLString::release(&tmpXMLStr); curParm++; - if (XMLString::startsWith(argV[curParm], L"/OutPath=")) + tmpXMLStr = XMLString::transcode("/OutPath="); + if (XMLString::startsWith(argV[curParm], tmpXMLStr )) { gOutPath = &argV[curParm][9]; } else { wprintf(L"\nExpected /OutPath=xxx. Got: %s\n", argV[curParm]); + XMLString::release(&tmpXMLStr); return false; } + XMLString::release(&tmpXMLStr); curParm++; - if (XMLString::startsWith(argV[curParm], L"/OutFmt=")) + tmpXMLStr = XMLString::transcode("/OutFmt="); + if (XMLString::startsWith(argV[curParm], tmpXMLStr )) { + XMLString::release(&tmpXMLStr); const XMLCh* tmpFmt = &argV[curParm][8]; - if (!XMLString::compareIString(tmpFmt, L"ResBundle")) + tmpXMLStr = XMLString::transcode("ResBundle"); + XMLCh *tmpXMLStr2 = XMLString::transcode("Win32RC"); + XMLCh *tmpXMLStr3 = XMLString::transcode("CppSrc"); + XMLCh *tmpXMLStr4 = XMLString::transcode("MsgCat"); + if (!XMLString::compareIString(tmpFmt, tmpXMLStr )) gOutFormat = OutFormat_ResBundle; - else if (!XMLString::compareIString(tmpFmt, L"Win32RC")) + else if (!XMLString::compareIString(tmpFmt, tmpXMLStr2 )) gOutFormat = OutFormat_Win32RC; - else if (!XMLString::compareIString(tmpFmt, L"CppSrc")) + else if (!XMLString::compareIString(tmpFmt, tmpXMLStr3 )) gOutFormat = OutFormat_CppSrc; - else if (!XMLString::compareIString(tmpFmt, L"MsgCat")) + else if (!XMLString::compareIString(tmpFmt, tmpXMLStr4 )) gOutFormat = OutFormat_MsgCatalog; else { wprintf(L"\n'%s' is not a legal output format\n", tmpFmt); + XMLString::release(&tmpXMLStr); + XMLString::release(&tmpXMLStr2); + XMLString::release(&tmpXMLStr3); + XMLString::release(&tmpXMLStr4); return false; } + XMLString::release(&tmpXMLStr); + XMLString::release(&tmpXMLStr2); + XMLString::release(&tmpXMLStr3); + XMLString::release(&tmpXMLStr4); } else { wprintf(L"\nExpected /OutFmt=xxx. Got: %s\n", argV[curParm]); + XMLString::release(&tmpXMLStr); return false; } curParm++; - if (XMLString::startsWith(argV[curParm], L"/Locale=")) + tmpXMLStr = XMLString::transcode("/Locale="); + if (XMLString::startsWith(argV[curParm], tmpXMLStr )) { gLocale = &argV[curParm][8]; } else { wprintf(L"\nExpected /Locale=xxx. Got: %s\n", argV[curParm]); + XMLString::release(&tmpXMLStr); return false; } + XMLString::release(&tmpXMLStr); return true; } -static void parseError(const XMLException& toCatch) +//static void parseError(const XMLException& toCatch) +void parseError(const XMLException& toCatch) { wprintf ( @@ -282,7 +332,8 @@ static void parseError(const XMLException& toCatch) } -static void parseError(const SAXParseException& toCatch) +//static void parseError(const SAXParseException& toCatch) +void parseError(const SAXParseException& toCatch) { wprintf ( @@ -296,7 +347,8 @@ static void parseError(const SAXParseException& toCatch) } -static void +//static void +void enumMessages( const DOMElement* srcElem , XlatFormatter* const toCall , FILE* const headerFl @@ -307,10 +359,11 @@ enumMessages( const DOMElement* srcElem ( headerFl , L" , %s%-30s = %d\n" - , typePrefixes[msgType] - , L"LowBounds" + , xmlStrToPrintable(typePrefixes[msgType]) + , longChars("LowBounds") , count++ ); + releasePrintableStr // // We just run through each of the child elements, each of which is @@ -331,25 +384,33 @@ enumMessages( const DOMElement* srcElem const DOMElement* curElem = (const DOMElement*)curNode; // Ok, this should be a Message node - if (XMLString::compareString(curElem->getTagName(), L"Message")) + XMLCh *tmpXMLStr = XMLString::transcode("Message"); + if (XMLString::compareString(curElem->getTagName(), tmpXMLStr )) { wprintf(L"Expected a Message node\n\n"); + XMLString::release(&tmpXMLStr); throw ErrReturn_SrcFmtError; } + XMLString::release(&tmpXMLStr); // // Ok, lets pull out the id, text value, and message type. These are // to be passed to the formatter. We have to translate the message // type into one of the offical enum values. // - const XMLCh* msgText = curElem->getAttribute(L"Text"); - const XMLCh* msgId = curElem->getAttribute(L"Id"); + tmpXMLStr = XMLString::transcode("Text"); + const XMLCh* msgText = curElem->getAttribute(tmpXMLStr ); + XMLString::release(&tmpXMLStr); + tmpXMLStr = XMLString::transcode("Id"); + const XMLCh* msgId = curElem->getAttribute(tmpXMLStr ); + XMLString::release(&tmpXMLStr); // // Write out an entry to the target header file. These are enums, so // we use the id as the enum name. // - fwprintf(headerFl, L" , %-32s = %d\n", msgId, count); + fwprintf(headerFl, L" , %-32s = %d\n", xmlStrToPrintable(msgId), count); + releasePrintableStr // And tell the formatter about this one toCall->nextMessage @@ -372,10 +433,11 @@ enumMessages( const DOMElement* srcElem ( headerFl , L" , %s%-30s = %d\n" - , typePrefixes[msgType] - , L"HighBounds" + , xmlStrToPrintable(typePrefixes[msgType]) + , longChars("HighBounds") , count++ ); + releasePrintableStr } @@ -389,8 +451,8 @@ enumMessages( const DOMElement* srcElem // file to get a DOM tree, then passes the DOM tree to the appropriate // output method to output the info in a particular format. // -extern "C" int wmain(int argC, XMLCh** argV) -{ +int Xlat_main(int argC, XMLCh** argV); +int main (int argC, char** argV) { try { XMLPlatformUtils::Initialize(); @@ -401,6 +463,24 @@ extern "C" int wmain(int argC, XMLCh** argV) wprintf(L"Parser init error.\n ERROR: %s\n\n", toCatch.getMessage()); return ErrReturn_ParserInit; } + + XMLCh** newArgV = new XMLCh*[argC]; + for(int i=0;i<argC; i++) + { + newArgV[i] = XMLString::transcode(argV[i]); + } + int toReturn = (Xlat_main(argC,newArgV)); + for (int i=0; i<argC; i++) + { + delete [] newArgV[i]; + } + delete [] newArgV; + return toReturn; +} + +int Xlat_main(int argC, XMLCh** argV) +{ + init_Globals(); // // Lets check the parameters and save them away in globals for use by @@ -417,21 +497,23 @@ extern "C" int wmain(int argC, XMLCh** argV) DOMDocument* srcDoc; const unsigned int bufSize = 4095; - XMLCh tmpFileBuf[bufSize + 1]; + XMLCh *tmpFileBuf = new XMLCh [bufSize + 1]; + tmpFileBuf[0] = 0; + XMLCh *tmpXMLStr = XMLString::transcode("/XMLErrList_"); + XMLCh *tmpXMLStr2 = XMLString::transcode(".Xml"); try { try { // Build the input file name - swprintf - ( - tmpFileBuf - , L"%s%s%s/XMLErrList_%s.Xml" - , gSrcRoot - , gRelativeInputPath - , gLocale - , gLocale - ); + XMLString::catString(tmpFileBuf, gSrcRoot); + XMLString::catString(tmpFileBuf, gRelativeInputPath); + XMLString::catString(tmpFileBuf, gLocale); + XMLString::catString(tmpFileBuf, tmpXMLStr ); + XMLString::catString(tmpFileBuf, gLocale); + XMLString::catString(tmpFileBuf, tmpXMLStr2 ); + XMLString::release(&tmpXMLStr); + XMLString::release(&tmpXMLStr2); // // Ok, lets invoke the DOM parser on the input file and build @@ -449,6 +531,7 @@ extern "C" int wmain(int argC, XMLCh** argV) { parseError(toCatch); } + XMLString::release(&tmpFileBuf); // // Use the output format parm to create the correct kind of output @@ -483,7 +566,9 @@ extern "C" int wmain(int argC, XMLCh** argV) // all information. // DOMElement* rootElem = srcDoc->getDocumentElement(); - const XMLCh* localeStr = rootElem->getAttribute(L"Locale"); + tmpXMLStr = XMLString::transcode("Locale"); + const XMLCh* localeStr = rootElem->getAttribute(tmpXMLStr); + XMLString::release(&tmpXMLStr); // Make sure that the locale matches what we were given if (XMLString::compareString(localeStr, gLocale)) @@ -497,7 +582,9 @@ extern "C" int wmain(int argC, XMLCh** argV) // the sets of (potentially separately) loadable messages. More // importantly they all have their own error id space. // - DOMNodeList* msgSetList = rootElem->getElementsByTagName(L"MsgDomain"); + tmpXMLStr = XMLString::transcode("MsgDomain"); + DOMNodeList* msgSetList = rootElem->getElementsByTagName(tmpXMLStr); + XMLString::release(&tmpXMLStr); // // Loop through them and look for the domains that we know are @@ -551,7 +638,9 @@ extern "C" int wmain(int argC, XMLCh** argV) // Get some of the attribute strings that we need, and transcode // couple that need to be in local format. // - const XMLCh* domainStr = curElem->getAttribute(L"Domain"); + tmpXMLStr = XMLString::transcode("Domain"); + const XMLCh* domainStr = curElem->getAttribute(tmpXMLStr ); + XMLString::release(&tmpXMLStr); // // Look at the domain and set up our application specific info @@ -559,27 +648,27 @@ extern "C" int wmain(int argC, XMLCh** argV) // name of the header is and what the namespace is that they // codes will go into // - const XMLCh* headerName = 0; - const XMLCh* errNameSpace = 0; + XMLCh* headerName = 0; + XMLCh* errNameSpace = 0; if (!XMLString::compareString(domainStr, XMLUni::fgXMLErrDomain)) { - headerName = L"XMLErrorCodes.hpp"; - errNameSpace = L"XMLErrs"; + headerName = XMLString::transcode("XMLErrorCodes.hpp"); + errNameSpace = XMLString::transcode("XMLErrs"); } else if (!XMLString::compareString(domainStr, XMLUni::fgValidityDomain)) { - headerName = L"XMLValidityCodes.hpp"; - errNameSpace = L"XMLValid"; + headerName = XMLString::transcode("XMLValidityCodes.hpp"); + errNameSpace = XMLString::transcode("XMLValid"); } else if (!XMLString::compareString(domainStr, XMLUni::fgExceptDomain)) { - headerName = L"XMLExceptMsgs.hpp"; - errNameSpace = L"XMLExcepts"; + headerName = XMLString::transcode("XMLExceptMsgs.hpp"); + errNameSpace = XMLString::transcode("XMLExcepts"); } else if (!XMLString::compareString(domainStr, XMLUni::fgXMLDOMMsgDomain)) { - headerName = L"XMLDOMMsg.hpp"; - errNameSpace = L"XMLDOMMsg"; + headerName = XMLString::transcode("XMLDOMMsg.hpp"); + errNameSpace = XMLString::transcode("XMLDOMMsg"); } else { @@ -591,27 +680,32 @@ extern "C" int wmain(int argC, XMLCh** argV) // Lets try to create the header file that was indicated for // this domain. // - swprintf - ( - tmpFileBuf - , L"%s%s" - , gOutPath - , headerName - ); - FILE* outHeader = _wfopen(tmpFileBuf, L"wt+"); - if (!outHeader) + tmpFileBuf = new XMLCh [bufSize + 1]; + tmpFileBuf[0] = 0; + XMLString::catString(tmpFileBuf, gOutPath); + XMLString::catString(tmpFileBuf, headerName); + char *tmpFileBufCh = XMLString::transcode(tmpFileBuf); + FILE* outHeader = fopen(tmpFileBufCh, "wt+"); + XMLString::release(&tmpFileBufCh); + if ((!outHeader) || (fwide(outHeader, 1) < 0)) { - wprintf(L"Could not open domain header file: %s\n\n", tmpFileBuf); + wprintf(L"Could not open domain header file: %s\n\n", xmlStrToPrintable(tmpFileBuf)); + releasePrintableStr + XMLString::release(&tmpFileBuf); + XMLString::release(&headerName); + XMLString::release(&errNameSpace); throw ErrReturn_OutFileOpenFailed; } + XMLString::release(&tmpFileBuf); // // Write out the opening of the class they are nested within, and // the header protection define. - // + // fwprintf(outHeader, L"// This file is generated, don't edit it!!\n\n"); - fwprintf(outHeader, L"#if !defined(ERRHEADER_%s)\n", errNameSpace); - fwprintf(outHeader, L"#define ERRHEADER_%s\n\n", errNameSpace); + fwprintf(outHeader, L"#if !defined(ERRHEADER_%s)\n", xmlStrToPrintable(errNameSpace) ); + fwprintf(outHeader, L"#define ERRHEADER_%s\n\n", xmlStrToPrintable(errNameSpace) ); + releasePrintableStr // If its not the exception domain, then we need a header included if (XMLString::compareString(domainStr, XMLUni::fgExceptDomain)) @@ -622,7 +716,8 @@ extern "C" int wmain(int argC, XMLCh** argV) fwprintf(outHeader, L"XERCES_CPP_NAMESPACE_BEGIN\n\n"); // Now the message codes - fwprintf(outHeader, L"class %s\n{\npublic :\n enum Codes\n {\n", errNameSpace); + fwprintf(outHeader, L"class %s\n{\npublic :\n enum Codes\n {\n", xmlStrToPrintable(errNameSpace) ); + releasePrintableStr // Tell the formatter that a new domain is starting formatter->startDomain @@ -636,7 +731,7 @@ extern "C" int wmain(int argC, XMLCh** argV) // the 'no error' entry for that domain. // unsigned int count = 0; - fwprintf(outHeader, L" %-32s = %d\n", L"NoError", count++); + fwprintf(outHeader, L" %-32s = %d\n", longChars("NoError"), count++); // // Loop through the children of this node, which should take us @@ -660,17 +755,20 @@ extern "C" int wmain(int argC, XMLCh** argV) const XMLCh* typeName = typeElem->getTagName(); MsgTypes type; - if (!XMLString::compareString(typeName, L"Warning")) + tmpXMLStr = XMLString::transcode("Warning"); + XMLCh* tmpXMLStr2 = XMLString::transcode("Error"); + XMLCh* tmpXMLStr3 =XMLString::transcode("FatalError"); + if (!XMLString::compareString(typeName, tmpXMLStr )) { type = MsgType_Warning; typeGotten[0] = true; } - else if (!XMLString::compareString(typeName, L"Error")) + else if (!XMLString::compareString(typeName, tmpXMLStr2 )) { type = MsgType_Error; typeGotten[1] = true; } - else if (!XMLString::compareString(typeName, L"FatalError")) + else if (!XMLString::compareString(typeName, tmpXMLStr3 )) { type = MsgType_FatalError; typeGotten[2] = true; @@ -678,8 +776,14 @@ extern "C" int wmain(int argC, XMLCh** argV) else { wprintf(L"Expected a Warning, Error, or FatalError node\n\n"); + XMLString::release(&tmpXMLStr); + XMLString::release(&tmpXMLStr2); + XMLString::release(&tmpXMLStr3); throw ErrReturn_SrcFmtError; } + XMLString::release(&tmpXMLStr); + XMLString::release(&tmpXMLStr2); + XMLString::release(&tmpXMLStr3); // Call the start message type event formatter->startMsgType(type); @@ -713,18 +817,20 @@ extern "C" int wmain(int argC, XMLCh** argV) ( outHeader , L" , %s%-30s = %d\n" - , typePrefixes[subIndex] - , L"LowBounds" + , xmlStrToPrintable(typePrefixes[subIndex]) + , longChars("LowBounds") , count++ ); + releasePrintableStr fwprintf ( outHeader , L" , %s%-30s = %d\n" - , typePrefixes[subIndex] - , L"HighBounds" + , xmlStrToPrintable(typePrefixes[subIndex]) + , longChars("HighBounds") , count++ ); + releasePrintableStr } } @@ -748,8 +854,9 @@ extern "C" int wmain(int argC, XMLCh** argV) L" {\n" L" return ((toCheck >= F_LowBounds) && (toCheck <= F_HighBounds));\n" L" }\n\n" - , errNameSpace + , xmlStrToPrintable(errNameSpace) ); + releasePrintableStr fwprintf ( @@ -758,8 +865,9 @@ extern "C" int wmain(int argC, XMLCh** argV) L" {\n" L" return ((toCheck >= W_LowBounds) && (toCheck <= W_HighBounds));\n" L" }\n\n" - , errNameSpace + , xmlStrToPrintable(errNameSpace) ); + releasePrintableStr fwprintf ( @@ -768,8 +876,9 @@ extern "C" int wmain(int argC, XMLCh** argV) L" {\n" L" return ((toCheck >= E_LowBounds) && (toCheck <= E_HighBounds));\n" L" }\n\n" - , errNameSpace + , xmlStrToPrintable(errNameSpace) ); + releasePrintableStr fwprintf ( @@ -784,8 +893,9 @@ extern "C" int wmain(int argC, XMLCh** argV) L" return XMLErrorReporter::ErrType_Error;\n" L" return XMLErrorReporter::ErrTypes_Unknown;\n" L" }\n" - , errNameSpace + , xmlStrToPrintable(errNameSpace) ); + releasePrintableStr } @@ -794,6 +904,8 @@ extern "C" int wmain(int argC, XMLCh** argV) fwprintf(outHeader, L"XERCES_CPP_NAMESPACE_END\n\n"); fwprintf(outHeader, L"#endif\n\n"); fclose(outHeader); + XMLString::release(&headerName); + XMLString::release(&errNameSpace); } // Ok, we are done so call the end output method @@ -806,7 +918,8 @@ extern "C" int wmain(int argC, XMLCh** argV) catch(const ErrReturns retVal) { // And call the termination method - delete srcDoc; + if(srcDoc) + delete srcDoc; XMLPlatformUtils::Terminate(); return retVal; } @@ -815,6 +928,7 @@ extern "C" int wmain(int argC, XMLCh** argV) } // And call the termination method + release_Globals(); XMLPlatformUtils::Terminate(); // Went ok, so return success @@ -844,3 +958,13 @@ void XlatErrHandler::fatalError(const SAXParseException& toCatch) void XlatErrHandler::resetErrors() { } + +// if longChars is a macro, don't bother +#ifndef longChars + wchar_t* longChars(const char *str) + { + mbstowcs(fTmpWStr, str, 255); + return (fTmpWStr); + } +#endif + diff --git a/tools/NLS/Xlat/Xlat.hpp b/tools/NLS/Xlat/Xlat.hpp index 761c42b0f76c16fb3f62426f9ab9ecffdf4bdb24..b9433abe0c88202172ac047fcd8d336a1977d3b7 100644 --- a/tools/NLS/Xlat/Xlat.hpp +++ b/tools/NLS/Xlat/Xlat.hpp @@ -56,6 +56,9 @@ /* * $Log$ + * Revision 1.9 2003/04/14 08:41:00 gareth + * Xlat now works under linux - Big thanks to Neil Graham (I no longer have to find a windows box). Still slight problems working with glibc before 2.2.4 (If you mess up the parameters it seg faults due to handling of wprintf) + * * Revision 1.8 2002/11/05 22:10:06 tng * Explicit code using namespace in application. * @@ -106,6 +109,8 @@ enum MsgTypes // Includes // --------------------------------------------------------------------------- #include <stdio.h> +#include <wchar.h> +#include <stdlib.h> #include <xercesc/util/XercesDefs.hpp> #include <xercesc/util/PlatformUtils.hpp> @@ -127,4 +132,27 @@ XERCES_CPP_NAMESPACE_USE // --------------------------------------------------------------------------- // Some const global data // --------------------------------------------------------------------------- -extern const XMLCh* typePrefixes[MsgTypes_Count]; +extern XMLCh* typePrefixes[MsgTypes_Count]; + + +// this ugly hack is needed because cygwin/linux and Windows (MSVC++) +// have irreconcileable differences about what to do with chars, wchar_t and XMLCh +// in wfprintf. Windows thinks that XMLCh * is fine here whereas +// char * is not; gcc will allow XMLCh to be cast to wchar_t but happily +// prints out gobbledygook in this case; it only seems happy when +// the native transcoder is used to convert the XMLCh to a char * +#if defined(__linux__) || defined(__CYGWIN__) + extern char *fTmpStr; + #define xmlStrToPrintable(xmlStr) \ + (fTmpStr = XMLString::transcode(xmlStr)) + #define releasePrintableStr \ + XMLString::release(&fTmpStr); + #define longChars(str) str +#elif defined(_WIN32) || defined(WIN32) || defined(__WINDOWS__) + extern wchar_t *longChars(const char *str); + #define xmlStrToPrintable(xmlStr) xmlStr + #define releasePrintableStr +#else + #error Code requires port to host OS! +#endif + diff --git a/tools/NLS/Xlat/Xlat_CppSrc.cpp b/tools/NLS/Xlat/Xlat_CppSrc.cpp index dd87733f1664a1b01d67fedc14074baff5b00b91..6ad44fab21a2fd70689c120f40fa4ab72ea13a37 100644 --- a/tools/NLS/Xlat/Xlat_CppSrc.cpp +++ b/tools/NLS/Xlat/Xlat_CppSrc.cpp @@ -56,6 +56,9 @@ /* * $Log$ + * Revision 1.9 2003/04/14 08:41:00 gareth + * Xlat now works under linux - Big thanks to Neil Graham (I no longer have to find a windows box). Still slight problems working with glibc before 2.2.4 (If you mess up the parameters it seg faults due to handling of wprintf) + * * Revision 1.8 2002/12/12 19:30:48 peiyongz * Message file name changed. * @@ -106,7 +109,8 @@ void CppSrcFormatter::endDomain(const XMLCh* const domainName fwprintf(fOutFl, L"\n};\n"); // Output the const size value - fwprintf(fOutFl, L"const unsigned int %s%s = %d;\n\n", fCurDomainName, L"Size", msgCount); + fwprintf(fOutFl, L"const unsigned int %s%s = %d;\n\n", xmlStrToPrintable(fCurDomainName), longChars("Size"), msgCount); + releasePrintableStr } @@ -122,14 +126,14 @@ void CppSrcFormatter::endMsgType(const MsgTypes type) fwprintf(fOutFl, L" , { "); } - const XMLCh* rawData = typePrefixes[type]; + XMLCh* rawData = typePrefixes[type]; while (*rawData) fwprintf(fOutFl, L"0x%04lX,", *rawData++); - rawData = L"End"; + XMLCh* tmpXMLStr = rawData = XMLString::transcode("End"); while (*rawData) fwprintf(fOutFl, L"0x%04lX,", *rawData++); - + XMLString::release(&tmpXMLStr); fwprintf(fOutFl, L"0x00 }\n"); } @@ -188,21 +192,22 @@ void CppSrcFormatter::startDomain( const XMLCh* const domainName // We have a different array name for each domain, so store that for // later use and for use below. // + XMLString::release(&fCurDomainName); if (!XMLString::compareString(XMLUni::fgXMLErrDomain, domainName)) { - fCurDomainName = L"gXMLErrArray"; + fCurDomainName = XMLString::transcode("gXMLErrArray"); } else if (!XMLString::compareString(XMLUni::fgExceptDomain, domainName)) { - fCurDomainName = L"gXMLExceptArray"; + fCurDomainName = XMLString::transcode("gXMLExceptArray"); } else if (!XMLString::compareString(XMLUni::fgValidityDomain, domainName)) { - fCurDomainName = L"gXMLValidityArray"; + fCurDomainName = XMLString::transcode("gXMLValidityArray"); } else if (!XMLString::compareString(XMLUni::fgXMLDOMMsgDomain, domainName)) { - fCurDomainName = L"gXMLDOMMsgArray"; + fCurDomainName = XMLString::transcode("gXMLDOMMsgArray"); } else { @@ -214,7 +219,8 @@ void CppSrcFormatter::startDomain( const XMLCh* const domainName // Output the leading part of the array declaration. Its just an // array of pointers to Unicode chars. // - fwprintf(fOutFl, L"const XMLCh %s[][128] = \n{\n", fCurDomainName); + fwprintf(fOutFl, L"const XMLCh %s[][128] = \n{\n", xmlStrToPrintable(fCurDomainName)); + releasePrintableStr // Reset the first message trigger fFirst = true; @@ -233,13 +239,14 @@ void CppSrcFormatter::startMsgType(const MsgTypes type) fwprintf(fOutFl, L" , { "); } - const XMLCh* rawData = typePrefixes[type]; + XMLCh* rawData = typePrefixes[type]; while (*rawData) fwprintf(fOutFl, L"0x%04lX,", *rawData++); - rawData = L"Start"; + XMLCh *tmpXMLStr = rawData = XMLString::transcode("Start"); while (*rawData) fwprintf(fOutFl, L"0x%04lX,", *rawData++); + XMLString::release(&tmpXMLStr); fwprintf(fOutFl, L"0x00 }\n"); } @@ -259,10 +266,20 @@ void CppSrcFormatter::startOutput( const XMLCh* const locale // const unsigned int bufSize = 4095; XMLCh tmpBuf[bufSize + 1]; + tmpBuf[0] = 0; + XMLCh *tmpXMLStr = XMLString::transcode("XercesMessages_"); + XMLCh *tmpXMLStr2 = XMLString::transcode(".hpp"); - swprintf(tmpBuf, L"%s/%s_%s.hpp", outPath, L"XercesMessages", locale); - fOutFl = _wfopen(tmpBuf, L"wt"); - if (!fOutFl) + XMLString::catString(tmpBuf, outPath); + XMLString::catString(tmpBuf, tmpXMLStr ); + XMLString::catString(tmpBuf, locale); + XMLString::catString(tmpBuf, tmpXMLStr2 ); + XMLString::release(&tmpXMLStr); + XMLString::release(&tmpXMLStr2); + char *tmpStr = XMLString::transcode(tmpBuf); + fOutFl = fopen(tmpStr, "wt"); + XMLString::release(&tmpStr); + if ((!fOutFl) || (fwide(fOutFl, 1) < 0)) { wprintf(L"Could not open the output file: %s\n\n", tmpBuf); throw ErrReturn_OutFileOpenFailed; diff --git a/tools/NLS/Xlat/Xlat_CppSrc.hpp b/tools/NLS/Xlat/Xlat_CppSrc.hpp index ad27df19e89d1af889ad8c5ffc5463493934f30f..3fa9faff56eacbd7526991f0158315cdf7d97741 100644 --- a/tools/NLS/Xlat/Xlat_CppSrc.hpp +++ b/tools/NLS/Xlat/Xlat_CppSrc.hpp @@ -56,6 +56,9 @@ /* * $Log$ + * Revision 1.5 2003/04/14 08:41:00 gareth + * Xlat now works under linux - Big thanks to Neil Graham (I no longer have to find a windows box). Still slight problems working with glibc before 2.2.4 (If you mess up the parameters it seg faults due to handling of wprintf) + * * Revision 1.4 2000/03/02 19:55:53 roddey * This checkin includes many changes done while waiting for the * 1.1.0 code to be finished. I can't list them all here, but a list is @@ -94,6 +97,7 @@ public : virtual ~CppSrcFormatter() { + XMLString::release(&fCurDomainName); } diff --git a/tools/NLS/Xlat/Xlat_ICUResourceBundle.cpp b/tools/NLS/Xlat/Xlat_ICUResourceBundle.cpp index 74337541dd74a4d88a5d17ad2cac75d0ea2107ff..6c7166baee3e4b32054b91b99202e86491e0518e 100644 --- a/tools/NLS/Xlat/Xlat_ICUResourceBundle.cpp +++ b/tools/NLS/Xlat/Xlat_ICUResourceBundle.cpp @@ -57,6 +57,9 @@ /* * $Id$ * $Log$ + * Revision 1.5 2003/04/14 08:41:00 gareth + * Xlat now works under linux - Big thanks to Neil Graham (I no longer have to find a windows box). Still slight problems working with glibc before 2.2.4 (If you mess up the parameters it seg faults due to handling of wprintf) + * * Revision 1.4 2002/12/17 17:39:09 tng * Xlat: generate icu message file with array format as default. * @@ -102,6 +105,7 @@ ICUResBundFormatter::ICUResBundFormatter() ICUResBundFormatter::~ICUResBundFormatter() { + delete fTranscoder; } // --------------------------------------------------------------------------- @@ -117,7 +121,8 @@ void ICUResBundFormatter::endDomain(const XMLCh* const domainName void ICUResBundFormatter::endMsgType(const MsgTypes type) { #ifndef ICU_RESBUNDLE_IN_TABLE_FORM - fwprintf(fOutFl, L"\t\t\"%S End \" ,\n", typePrefixes[type]); + fwprintf(fOutFl, L"\t\t\"%s End \" ,\n", xmlStrToPrintable(typePrefixes[type]) ); + releasePrintableStr #endif } @@ -142,8 +147,6 @@ ICUResBundFormatter::nextMessage(const XMLCh* const msgText // bother checking, just do it simple and stupid. // - char* outData = fTranscoder->transcode(msgText); - // // array_name { // "xxx" , @@ -158,14 +161,15 @@ ICUResBundFormatter::nextMessage(const XMLCh* const msgText // #ifdef ICU_RESBUNDLE_IN_TABLE_FORM - fwprintf(fOutFl, L"\t\t %3d { \"%S \" } \n", curId, outData); + fwprintf(fOutFl, L"\t\t %3d { \"%s \" } \n", curId, xmlStrToPrintable(msgText)); + releasePrintableStr // need to print leading 0 if less than 100, not tested yet #else - fwprintf(fOutFl, L"\t\t\"%S \" ,\n", outData); + fwprintf(fOutFl, L"\t\t\"%s \" ,\n", xmlStrToPrintable(msgText)); + releasePrintableStr // need a space between the last character and the closing " #endif - delete [] outData; } @@ -178,7 +182,6 @@ void ICUResBundFormatter::startDomain(const XMLCh* const domainName // domainName { // int index = XMLString::lastIndexOf(domainName, chForwardSlash); - char *tmpDomainName = fTranscoder->transcode(&(domainName[index+1])); #ifdef ICU_RESBUNDLE_IN_TABLE_FORM fwprintf(fOutFl, L"\n\t // a table \n"); @@ -186,9 +189,8 @@ void ICUResBundFormatter::startDomain(const XMLCh* const domainName fwprintf(fOutFl, L"\n\t // an array \n"); #endif - fwprintf(fOutFl, L"\t%S { \n" , tmpDomainName); - - delete [] tmpDomainName; + fwprintf(fOutFl, L"\t%s { \n" , xmlStrToPrintable(&(domainName[index+1]))); + releasePrintableStr } @@ -196,7 +198,8 @@ void ICUResBundFormatter::startDomain(const XMLCh* const domainName void ICUResBundFormatter::startMsgType(const MsgTypes type) { #ifndef ICU_RESBUNDLE_IN_TABLE_FORM - fwprintf(fOutFl, L"\t\t\"%S Start \" , \n", typePrefixes[type]); + fwprintf(fOutFl, L"\t\t\"%s Start \" , \n", xmlStrToPrintable(typePrefixes[type]) ); + releasePrintableStr #endif } @@ -215,18 +218,27 @@ void ICUResBundFormatter::startOutput(const XMLCh* const locale // const unsigned int bufSize = 4095; XMLCh tmpBuf[bufSize + 1]; - - - - swprintf(tmpBuf, L"%s/%s.txt", outPath, locale); - fOutFl = _wfopen(tmpBuf, L"wt"); - if (!fOutFl) - { - wprintf(L"Could not open the output file: %s\n\n", tmpBuf); + tmpBuf[0] = 0; + XMLCh *tmpXMLStr = XMLString::transcode(".txt"); + + + + XMLString::catString(tmpBuf, outPath); + XMLString::catString(tmpBuf, locale); + XMLString::catString(tmpBuf, tmpXMLStr ); + XMLString::release(&tmpXMLStr); + char *tmpStr = XMLString::transcode(tmpBuf); + fOutFl = fopen(tmpStr, "wt"); + XMLString::release(&tmpStr); + if ((!fOutFl) || (fwide(fOutFl, 1) < 0)) + { + wprintf(L"Could not open the output file: %s\n\n", xmlStrToPrintable(tmpBuf) ); + releasePrintableStr throw ErrReturn_OutFileOpenFailed; } // Set the message delimiter - fwprintf(fOutFl, L"%s { \n", locale); + fwprintf(fOutFl, L"%s { \n", xmlStrToPrintable(locale) ); + releasePrintableStr } diff --git a/tools/NLS/Xlat/Xlat_MsgCatalog.cpp b/tools/NLS/Xlat/Xlat_MsgCatalog.cpp index f25802720a909223f94efa26fb3485da113f69c1..a6bbff92abe61050e9b325ec5993e9915bcd9ec8 100644 --- a/tools/NLS/Xlat/Xlat_MsgCatalog.cpp +++ b/tools/NLS/Xlat/Xlat_MsgCatalog.cpp @@ -56,6 +56,9 @@ /* * $Log$ + * Revision 1.9 2003/04/14 08:41:00 gareth + * Xlat now works under linux - Big thanks to Neil Graham (I no longer have to find a windows box). Still slight problems working with glibc before 2.2.4 (If you mess up the parameters it seg faults due to handling of wprintf) + * * Revision 1.8 2002/12/12 19:30:48 peiyongz * Message file name changed. * @@ -122,6 +125,7 @@ MsgCatFormatter::MsgCatFormatter() : MsgCatFormatter::~MsgCatFormatter() { + delete fTranscoder; } @@ -165,13 +169,12 @@ MsgCatFormatter::nextMessage(const XMLCh* const msgText // If the text is just US-ASCII, this won't have any effect, but don't // bother checking, just do it simple and stupid. // - char* outData = fTranscoder->transcode(msgText); // // on hp, it is required that message line shall start with number // w/o leading space. // - fwprintf(fOutFl, L"%d %S\n", curId, outData); - delete [] outData; + fwprintf(fOutFl, L"%d %s\n", curId, xmlStrToPrintable(msgText)); + releasePrintableStr } @@ -179,7 +182,8 @@ void MsgCatFormatter::startDomain( const XMLCh* const domainName , const XMLCh* const nameSpace) { // Output a constant to the header file - fwprintf(fOutHpp, L"const unsigned int CatId_%s = %d;\n", nameSpace, fSeqId); + fwprintf(fOutHpp, L"const unsigned int CatId_%s = %d;\n", xmlStrToPrintable(nameSpace), fSeqId); + releasePrintableStr // // Output the leading part of the array declaration. Its just an @@ -210,13 +214,25 @@ void MsgCatFormatter::startOutput( const XMLCh* const locale // where xxx is the locale suffix passed in. // const unsigned int bufSize = 4095; - XMLCh tmpBuf[bufSize + 1]; + XMLCh *tmpBuf = new XMLCh[bufSize + 1]; + tmpBuf[0] = 0; + XMLCh *tmpXMLStr = XMLString::transcode("XercesMessages_"); + XMLCh *tmpXMLStr2 = XMLString::transcode(".msg"); - swprintf(tmpBuf, L"%s/%s_%s.Msg", outPath, L"XercesMessages", locale); - fOutFl = _wfopen(tmpBuf, L"wt"); - if (!fOutFl) - { - wprintf(L"Could not open the output file: %s\n\n", tmpBuf); + XMLString::catString(tmpBuf, outPath); + XMLString::catString(tmpBuf, tmpXMLStr ); + XMLString::catString(tmpBuf, locale); + XMLString::catString(tmpBuf, tmpXMLStr2 ); + XMLString::release(&tmpXMLStr); + XMLString::release(&tmpXMLStr2); + char *tmpStr = XMLString::transcode(tmpBuf); + fOutFl = fopen(tmpStr, "wt"); + XMLString::release(&tmpStr); + if ((!fOutFl) ||(fwide(fOutFl, 1) < 0)) + { + wprintf(L"Could not open the output file: %s\n\n", xmlStrToPrintable(tmpBuf) ); + releasePrintableStr + XMLString::release(&tmpBuf); throw ErrReturn_OutFileOpenFailed; } @@ -224,11 +240,21 @@ void MsgCatFormatter::startOutput( const XMLCh* const locale fwprintf(fOutFl, L"$quote \"\n"); - swprintf(tmpBuf, L"%s/%s.hpp", outPath, L"XMLMsgCat_Ids"); - fOutHpp = _wfopen(tmpBuf, L"wt"); - if (!fOutHpp) - { - wprintf(L"Could not open the output file: %s\n\n", tmpBuf); + XMLString::release(&tmpBuf); + tmpBuf = new XMLCh[bufSize + 1]; + tmpBuf[0] = 0; + tmpXMLStr = XMLString::transcode("XMLMsgCat_Ids.hpp"); + XMLString::catString(tmpBuf, outPath); + XMLString::catString(tmpBuf, tmpXMLStr ); + XMLString::release(&tmpXMLStr); + tmpStr = XMLString::transcode(tmpBuf); + fOutHpp = fopen(tmpStr, "wt"); + XMLString::release(&tmpStr); + if ((!fOutHpp) || (fwide(fOutHpp,1) < 0)) + { + wprintf(L"Could not open the output file: %s\n\n", xmlStrToPrintable(tmpBuf) ); + releasePrintableStr + XMLString::release(&tmpBuf); throw ErrReturn_OutFileOpenFailed; } @@ -245,4 +271,5 @@ void MsgCatFormatter::startOutput( const XMLCh* const locale // Reset the sequence id fSeqId = 1; + XMLString::release(&tmpBuf); } diff --git a/tools/NLS/Xlat/Xlat_Win32RC.cpp b/tools/NLS/Xlat/Xlat_Win32RC.cpp index 6c4c8d6dc2827e1a26e858fe03fcd8ff61b62d60..0079d0c77a324bc7a53e37beab4fc08a3428d4af 100644 --- a/tools/NLS/Xlat/Xlat_Win32RC.cpp +++ b/tools/NLS/Xlat/Xlat_Win32RC.cpp @@ -56,6 +56,9 @@ /* * $Log$ + * Revision 1.6 2003/04/14 08:41:00 gareth + * Xlat now works under linux - Big thanks to Neil Graham (I no longer have to find a windows box). Still slight problems working with glibc before 2.2.4 (If you mess up the parameters it seg faults due to handling of wprintf) + * * Revision 1.5 2002/11/12 17:24:58 tng * DOM Message: add new domain for DOM Messages. * @@ -100,6 +103,7 @@ Win32RCFormatter::Win32RCFormatter() : Win32RCFormatter::~Win32RCFormatter() { + XMLString::release(&fCurDomainName); } @@ -155,24 +159,25 @@ void Win32RCFormatter::startDomain( const XMLCh* const domainName // We have a different array name for each domain, so store that for // later use and for use below. // + XMLString::release(&fCurDomainName); if (!XMLString::compareString(XMLUni::fgXMLErrDomain, domainName)) - { - fCurDomainName = L"gXMLErrArray"; + { + fCurDomainName = XMLString::transcode("gXMLErrArray"); fMsgOffset = 0; } else if (!XMLString::compareString(XMLUni::fgExceptDomain, domainName)) { - fCurDomainName = L"gXMLExceptArray"; + fCurDomainName = XMLString::transcode("gXMLExceptArray"); fMsgOffset = 0x2000; } else if (!XMLString::compareString(XMLUni::fgValidityDomain, domainName)) { - fCurDomainName = L"gXMLValidityArray"; + fCurDomainName = XMLString::transcode("gXMLValidityArray"); fMsgOffset = 0x4000; } else if (!XMLString::compareString(XMLUni::fgXMLDOMMsgDomain, domainName)) { - fCurDomainName = L"gXMLDOMMsgArray"; + fCurDomainName = XMLString::transcode("gXMLDOMMsgArray"); fMsgOffset = 0x6000; } else @@ -213,12 +218,25 @@ void Win32RCFormatter::startOutput( const XMLCh* const locale // const unsigned int bufSize = 4095; XMLCh tmpBuf[bufSize + 1]; - - swprintf(tmpBuf, L"%s/%s_%s.RC", outPath, L"CppErrMsgs", locale); - fOutFl = _wfopen(tmpBuf, L"wt"); - if (!fOutFl) + // make sure the append will work + tmpBuf[0] = 0; + XMLCh *tmpXMLStr = XMLString::transcode("CppErrMsgs_"); + XMLCh *tmpXMLStr2 = XMLString::transcode(".RC"); + + XMLString::catString(tmpBuf, outPath); + XMLString::catString(tmpBuf, tmpXMLStr ); + XMLString::catString(tmpBuf, locale); + XMLString::catString(tmpBuf, tmpXMLStr2 ); + XMLString::release(&tmpXMLStr); + XMLString::release(&tmpXMLStr2); + char *tmpStr = XMLString::transcode(tmpBuf); + fOutFl = fopen(tmpStr, "wt"); + XMLString::release(&tmpStr); + if ((!fOutFl) || (fwide(fOutFl,1) < 0)) { - wprintf(L"Could not open the output file: %s\n\n", tmpBuf); + + wprintf(L"Could not open the output file: %s\n\n", xmlStrToPrintable(tmpBuf) ); + releasePrintableStr throw ErrReturn_OutFileOpenFailed; }