You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by tn...@apache.org on 2002/03/01 17:18:39 UTC
cvs commit: xml-xerces/c/tools/NLS/Xlat Xlat.cpp
tng 02/03/01 08:18:38
Modified: c/tools/NLS/Xlat Xlat.cpp
Log:
Nest entire code in an inner block so that reference counting should recover
all document and DOMString storage when this block exits.
Revision Changes Path
1.11 +318 -309 xml-xerces/c/tools/NLS/Xlat/Xlat.cpp
Index: Xlat.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/tools/NLS/Xlat/Xlat.cpp,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- Xlat.cpp 7 Feb 2002 16:19:40 -0000 1.10
+++ Xlat.cpp 1 Mar 2002 16:18:38 -0000 1.11
@@ -1,37 +1,37 @@
/*
* The Apache Software License, Version 1.1
- *
+ *
* Copyright (c) 1999-2000 The Apache Software Foundation. All rights
* reserved.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
+ * notice, this list of conditions and the following disclaimer.
+ *
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
- *
+ *
* 3. The end-user documentation included with the redistribution,
- * if any, must include the following acknowledgment:
+ * if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
- *
+ *
* 4. The names "Xerces" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
- * software without prior written permission. For written
+ * software without prior written permission. For written
* permission, please contact apache\@apache.org.
- *
+ *
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
- *
+ *
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
@@ -45,7 +45,7 @@
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
- *
+ *
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation, and was
* originally based on software copyright (c) 1999, International
@@ -57,6 +57,10 @@
/*
* $Log: Xlat.cpp,v $
+ * Revision 1.11 2002/03/01 16:18:38 tng
+ * Nest entire code in an inner block so that reference counting should recover
+ * all document and DOMString storage when this block exits.
+ *
* Revision 1.10 2002/02/07 16:19:40 knoaman
* sane_include update.
*
@@ -117,7 +121,7 @@
// ---------------------------------------------------------------------------
-// Includes
+// Includes
// ---------------------------------------------------------------------------
#include "Xlat.hpp"
@@ -136,7 +140,7 @@
// ---------------------------------------------------------------------------
// Global data
// ---------------------------------------------------------------------------
-const XMLCh* typePrefixes[MsgTypes_Count] =
+const XMLCh* typePrefixes[MsgTypes_Count] =
{
L"W_"
, L"E_"
@@ -393,360 +397,366 @@
return ErrReturn_BadParameters;
}
- DOM_Document srcDoc;
- const unsigned int bufSize = 4095;
- XMLCh tmpFileBuf[bufSize + 1];
- try
{
+ // Nest entire code in an inner block.
+ // Reference counting should recover all document
+ // storage when this block exits.
+
+ DOM_Document srcDoc;
+ const unsigned int bufSize = 4095;
+ XMLCh tmpFileBuf[bufSize + 1];
try
{
- // Build the input file name
- swprintf
- (
- tmpFileBuf
- , L"%s%s%s/XMLErrList_%s.Xml"
- , gSrcRoot
- , gRelativeInputPath
- , gLocale
- , gLocale
- );
-
- //
- // Ok, lets invoke the DOM parser on the input file and build
- // a DOM tree. Turn on validation when we do this.
- //
- DOMParser parser;
- parser.setDoValidation(true);
- XlatErrHandler errHandler;
- parser.setErrorHandler(&errHandler);
- parser.parse(tmpFileBuf);
- srcDoc = parser.getDocument();
- }
-
- catch(const XMLException& toCatch)
- {
- parseError(toCatch);
- }
-
- //
- // Use the output format parm to create the correct kind of output
- // formatter.
- //
- XlatFormatter* formatter = 0;
- switch(gOutFormat)
- {
- case OutFormat_CppSrc :
- formatter = new CppSrcFormatter;
- break;
-
- case OutFormat_Win32RC :
- formatter = new Win32RCFormatter;
- break;
-
- case OutFormat_MsgCatalog :
- formatter = new MsgCatFormatter;
- break;
-
- default :
- wprintf(L"Uknown formatter type enum\n\n");
- throw ErrReturn_Internal;
- }
-
- //
- // Lets handle the root element stuff first. This one holds any over
- // all information.
- //
- DOM_Element rootElem = srcDoc.getDocumentElement();
- DOMString localeStr = rootElem.getAttribute(L"Locale");
-
- // Make sure that the locale matches what we were given
- if (XMLString::compareString(localeStr.rawBuffer(), gLocale))
- {
- wprintf(L"The file's locale does not match the target locale\n");
- throw ErrReturn_LocaleErr;
- }
-
- //
- // Get a list of all the MsgDomain children. These each hold one of
- // the sets of (potentially separately) loadable messages. More
- // importantly they all have their own error id space.
- //
- DOM_NodeList msgSetList = rootElem.getElementsByTagName(L"MsgDomain");
-
- //
- // Loop through them and look for the domains that we know are
- // supposed to be there.
- //
- const unsigned int count = msgSetList.getLength();
-
- //
- // Ok, its good enough to get started. So lets call the start output
- // method on the formatter.
- //
- formatter->startOutput(localeStr.rawBuffer(), gOutPath);
+ try
+ {
+ // Build the input file name
+ swprintf
+ (
+ tmpFileBuf
+ , L"%s%s%s/XMLErrList_%s.Xml"
+ , gSrcRoot
+ , gRelativeInputPath
+ , gLocale
+ , gLocale
+ );
- //
- // For each message domain element, we call start and end domain
- // events bracketed around the loop that sends out each message
- // in that domain.
- //
- // Within each domain, we check for the Warning, Error, and Validity
- // subelements, and then iterate all the messages in each one.
- //
- for (unsigned int index = 0; index < count; index++)
- {
- // We know its a DOM Element, so go ahead and cast it
- DOM_Node curNode = msgSetList.item(index);
- const DOM_Element& curElem = (const DOM_Element&)curNode;
+ //
+ // Ok, lets invoke the DOM parser on the input file and build
+ // a DOM tree. Turn on validation when we do this.
+ //
+ DOMParser parser;
+ parser.setDoValidation(true);
+ XlatErrHandler errHandler;
+ parser.setErrorHandler(&errHandler);
+ parser.parse(tmpFileBuf);
+ srcDoc = parser.getDocument();
+ }
- //
- // Get some of the attribute strings that we need, and transcode
- // couple that need to be in local format.
- //
- DOMString domainStr = curElem.getAttribute(L"Domain");
+ catch(const XMLException& toCatch)
+ {
+ parseError(toCatch);
+ }
//
- // Look at the domain and set up our application specific info
- // that is on a per-domain basis. We need to indicate what the
- // name of the header is and what the namespace is that they
- // codes will go into
+ // Use the output format parm to create the correct kind of output
+ // formatter.
//
- const XMLCh* headerName = 0;
- const XMLCh* errNameSpace = 0;
- if (!XMLString::compareString(domainStr.rawBuffer(), XMLUni::fgXMLErrDomain))
+ XlatFormatter* formatter = 0;
+ switch(gOutFormat)
{
- headerName = L"XMLErrorCodes.hpp";
- errNameSpace = L"XMLErrs";
- }
- else if (!XMLString::compareString(domainStr.rawBuffer(), XMLUni::fgValidityDomain))
- {
- headerName = L"XMLValidityCodes.hpp";
- errNameSpace = L"XMLValid";
- }
- else if (!XMLString::compareString(domainStr.rawBuffer(), XMLUni::fgExceptDomain))
- {
- headerName = L"XMLExceptMsgs.hpp";
- errNameSpace = L"XMLExcepts";
- }
- else
- {
- // Not one of ours, so skip it
- continue;
+ case OutFormat_CppSrc :
+ formatter = new CppSrcFormatter;
+ break;
+
+ case OutFormat_Win32RC :
+ formatter = new Win32RCFormatter;
+ break;
+
+ case OutFormat_MsgCatalog :
+ formatter = new MsgCatFormatter;
+ break;
+
+ default :
+ wprintf(L"Uknown formatter type enum\n\n");
+ throw ErrReturn_Internal;
}
//
- // Lets try to create the header file that was indicated for
- // this domain.
+ // Lets handle the root element stuff first. This one holds any over
+ // all information.
//
- swprintf
- (
- tmpFileBuf
- , L"%s%s"
- , gOutPath
- , headerName
- );
- FILE* outHeader = _wfopen(tmpFileBuf, L"wt+");
- if (!outHeader)
+ DOM_Element rootElem = srcDoc.getDocumentElement();
+ DOMString localeStr = rootElem.getAttribute(L"Locale");
+
+ // Make sure that the locale matches what we were given
+ if (XMLString::compareString(localeStr.rawBuffer(), gLocale))
{
- wprintf(L"Could not open domain header file: %s\n\n", tmpFileBuf);
- throw ErrReturn_OutFileOpenFailed;
+ wprintf(L"The file's locale does not match the target locale\n");
+ throw ErrReturn_LocaleErr;
}
//
- // Write out the opening of the class they are nested within, and
- // the header protection define.
+ // Get a list of all the MsgDomain children. These each hold one of
+ // the sets of (potentially separately) loadable messages. More
+ // importantly they all have their own error id space.
//
- 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);
-
- // If its not the exception domain, then we need a header included
- if (XMLString::compareString(domainStr.rawBuffer(), XMLUni::fgExceptDomain))
- fwprintf(outHeader, L"#include <xercesc/framework/XMLErrorReporter.hpp>\n\n");
-
- fwprintf(outHeader, L"class %s\n{\npublic :\n enum Codes\n {\n", errNameSpace);
+ DOM_NodeList msgSetList = rootElem.getElementsByTagName(L"MsgDomain");
- // Tell the formatter that a new domain is starting
- formatter->startDomain
- (
- domainStr.rawBuffer()
- , errNameSpace
- );
+ //
+ // Loop through them and look for the domains that we know are
+ // supposed to be there.
+ //
+ const unsigned int count = msgSetList.getLength();
//
- // Force out the first message, which is always implicit and is
- // the 'no error' entry for that domain.
+ // Ok, its good enough to get started. So lets call the start output
+ // method on the formatter.
//
- unsigned int count = 0;
- fwprintf(outHeader, L" %-32s = %d\n", L"NoError", count++);
+ formatter->startOutput(localeStr.rawBuffer(), gOutPath);
//
- // Loop through the children of this node, which should take us
- // through the optional Warning, Error, and Validity subsections.
+ // For each message domain element, we call start and end domain
+ // events bracketed around the loop that sends out each message
+ // in that domain.
//
- DOM_Node typeNode = curElem.getFirstChild();
- bool typeGotten[3] = { false, false, false };
- while (!typeNode.isNull())
+ // Within each domain, we check for the Warning, Error, and Validity
+ // subelements, and then iterate all the messages in each one.
+ //
+ for (unsigned int index = 0; index < count; index++)
{
- // Skip over text nodes or comment nodes ect...
- if (typeNode.getNodeType() != DOM_Node::ELEMENT_NODE)
+ // We know its a DOM Element, so go ahead and cast it
+ DOM_Node curNode = msgSetList.item(index);
+ const DOM_Element& curElem = (const DOM_Element&)curNode;
+
+ //
+ // Get some of the attribute strings that we need, and transcode
+ // couple that need to be in local format.
+ //
+ DOMString domainStr = curElem.getAttribute(L"Domain");
+
+ //
+ // Look at the domain and set up our application specific info
+ // that is on a per-domain basis. We need to indicate what the
+ // name of the header is and what the namespace is that they
+ // codes will go into
+ //
+ const XMLCh* headerName = 0;
+ const XMLCh* errNameSpace = 0;
+ if (!XMLString::compareString(domainStr.rawBuffer(), XMLUni::fgXMLErrDomain))
{
- typeNode = typeNode.getNextSibling();
- continue;
+ headerName = L"XMLErrorCodes.hpp";
+ errNameSpace = L"XMLErrs";
}
-
- // Convert it to an element node
- const DOM_Element& typeElem = (const DOM_Element&)typeNode;
-
- // Now get its tag name and convert that to a message type enum
- DOMString typeName = typeElem.getTagName();
-
- MsgTypes type;
- if (typeName.equals(L"Warning"))
+ else if (!XMLString::compareString(domainStr.rawBuffer(), XMLUni::fgValidityDomain))
{
- type = MsgType_Warning;
- typeGotten[0] = true;
+ headerName = L"XMLValidityCodes.hpp";
+ errNameSpace = L"XMLValid";
}
- else if (typeName.equals(L"Error"))
+ else if (!XMLString::compareString(domainStr.rawBuffer(), XMLUni::fgExceptDomain))
{
- type = MsgType_Error;
- typeGotten[1] = true;
+ headerName = L"XMLExceptMsgs.hpp";
+ errNameSpace = L"XMLExcepts";
}
- else if (typeName.equals(L"FatalError"))
+ else
{
- type = MsgType_FatalError;
- typeGotten[2] = true;
+ // Not one of ours, so skip it
+ continue;
}
- else
+
+ //
+ // 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)
{
- wprintf(L"Expected a Warning, Error, or FatalError node\n\n");
- throw ErrReturn_SrcFmtError;
+ wprintf(L"Could not open domain header file: %s\n\n", tmpFileBuf);
+ throw ErrReturn_OutFileOpenFailed;
}
- // Call the start message type event
- formatter->startMsgType(type);
+ //
+ // 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);
+
+ // If its not the exception domain, then we need a header included
+ if (XMLString::compareString(domainStr.rawBuffer(), XMLUni::fgExceptDomain))
+ fwprintf(outHeader, L"#include <xercesc/framework/XMLErrorReporter.hpp>\n\n");
+
+ fwprintf(outHeader, L"class %s\n{\npublic :\n enum Codes\n {\n", errNameSpace);
- // Enumerate the messages under this subsection
- enumMessages
+ // Tell the formatter that a new domain is starting
+ formatter->startDomain
(
- typeElem
- , formatter
- , outHeader
- , type
- , count
+ domainStr.rawBuffer()
+ , errNameSpace
);
- // Call the end message type event
- formatter->endMsgType(type);
+ //
+ // Force out the first message, which is always implicit and is
+ // the 'no error' entry for that domain.
+ //
+ unsigned int count = 0;
+ fwprintf(outHeader, L" %-32s = %d\n", L"NoError", count++);
+
+ //
+ // Loop through the children of this node, which should take us
+ // through the optional Warning, Error, and Validity subsections.
+ //
+ DOM_Node typeNode = curElem.getFirstChild();
+ bool typeGotten[3] = { false, false, false };
+ while (!typeNode.isNull())
+ {
+ // Skip over text nodes or comment nodes ect...
+ if (typeNode.getNodeType() != DOM_Node::ELEMENT_NODE)
+ {
+ typeNode = typeNode.getNextSibling();
+ continue;
+ }
+
+ // Convert it to an element node
+ const DOM_Element& typeElem = (const DOM_Element&)typeNode;
+
+ // Now get its tag name and convert that to a message type enum
+ DOMString typeName = typeElem.getTagName();
+
+ MsgTypes type;
+ if (typeName.equals(L"Warning"))
+ {
+ type = MsgType_Warning;
+ typeGotten[0] = true;
+ }
+ else if (typeName.equals(L"Error"))
+ {
+ type = MsgType_Error;
+ typeGotten[1] = true;
+ }
+ else if (typeName.equals(L"FatalError"))
+ {
+ type = MsgType_FatalError;
+ typeGotten[2] = true;
+ }
+ else
+ {
+ wprintf(L"Expected a Warning, Error, or FatalError node\n\n");
+ throw ErrReturn_SrcFmtError;
+ }
- // Move to the next child of the source element
- typeNode = typeNode.getNextSibling();
- }
+ // Call the start message type event
+ formatter->startMsgType(type);
- //
- // For any that we did not get, spit out faux boundary
- // values for it.
- //
- for (unsigned int subIndex = 0; subIndex < 3; subIndex++)
- {
- if (!typeGotten[subIndex])
+ // Enumerate the messages under this subsection
+ enumMessages
+ (
+ typeElem
+ , formatter
+ , outHeader
+ , type
+ , count
+ );
+
+ // Call the end message type event
+ formatter->endMsgType(type);
+
+ // Move to the next child of the source element
+ typeNode = typeNode.getNextSibling();
+ }
+
+ //
+ // For any that we did not get, spit out faux boundary
+ // values for it.
+ //
+ for (unsigned int subIndex = 0; subIndex < 3; subIndex++)
+ {
+ if (!typeGotten[subIndex])
+ {
+ fwprintf
+ (
+ outHeader
+ , L" , %s%-30s = %d\n"
+ , typePrefixes[subIndex]
+ , L"LowBounds"
+ , count++
+ );
+ fwprintf
+ (
+ outHeader
+ , L" , %s%-30s = %d\n"
+ , typePrefixes[subIndex]
+ , L"HighBounds"
+ , count++
+ );
+ }
+ }
+
+ // Tell the formatter that this domain is ending
+ formatter->endDomain(domainStr.rawBuffer(), count);
+
+ // Close out the enum declaration
+ fwprintf(outHeader, L" };\n\n");
+
+ //
+ // Generate the code that creates the simple static methods
+ // for testing the error types. We don't do this for the
+ // exceptions header.
+ //
+ if (XMLString::compareString(domainStr.rawBuffer(), XMLUni::fgExceptDomain))
{
fwprintf
(
outHeader
- , L" , %s%-30s = %d\n"
- , typePrefixes[subIndex]
- , L"LowBounds"
- , count++
+ , L" static bool isFatal(const %s::Codes toCheck)\n"
+ L" {\n"
+ L" return ((toCheck >= F_LowBounds) && (toCheck <= F_HighBounds));\n"
+ L" }\n\n"
+ , errNameSpace
);
+
fwprintf
(
outHeader
- , L" , %s%-30s = %d\n"
- , typePrefixes[subIndex]
- , L"HighBounds"
- , count++
+ , L" static bool isWarning(const %s::Codes toCheck)\n"
+ L" {\n"
+ L" return ((toCheck >= W_LowBounds) && (toCheck <= W_HighBounds));\n"
+ L" }\n\n"
+ , errNameSpace
);
- }
- }
-
- // Tell the formatter that this domain is ending
- formatter->endDomain(domainStr.rawBuffer(), count);
- // Close out the enum declaration
- fwprintf(outHeader, L" };\n\n");
-
- //
- // Generate the code that creates the simple static methods
- // for testing the error types. We don't do this for the
- // exceptions header.
- //
- if (XMLString::compareString(domainStr.rawBuffer(), XMLUni::fgExceptDomain))
- {
- fwprintf
- (
- outHeader
- , L" static bool isFatal(const %s::Codes toCheck)\n"
- L" {\n"
- L" return ((toCheck >= F_LowBounds) && (toCheck <= F_HighBounds));\n"
- L" }\n\n"
- , errNameSpace
- );
-
- fwprintf
- (
- outHeader
- , L" static bool isWarning(const %s::Codes toCheck)\n"
- L" {\n"
- L" return ((toCheck >= W_LowBounds) && (toCheck <= W_HighBounds));\n"
- L" }\n\n"
- , errNameSpace
- );
+ fwprintf
+ (
+ outHeader
+ , L" static bool isError(const %s::Codes toCheck)\n"
+ L" {\n"
+ L" return ((toCheck >= E_LowBounds) && (toCheck <= E_HighBounds));\n"
+ L" }\n\n"
+ , errNameSpace
+ );
- fwprintf
- (
- outHeader
- , L" static bool isError(const %s::Codes toCheck)\n"
- L" {\n"
- L" return ((toCheck >= E_LowBounds) && (toCheck <= E_HighBounds));\n"
- L" }\n\n"
- , errNameSpace
- );
+ fwprintf
+ (
+ outHeader
+ , L" static XMLErrorReporter::ErrTypes errorType(const %s::Codes toCheck)\n"
+ L" {\n"
+ L" if ((toCheck >= W_LowBounds) && (toCheck <= W_HighBounds))\n"
+ L" return XMLErrorReporter::ErrType_Warning;\n"
+ L" else if ((toCheck >= F_LowBounds) && (toCheck <= F_HighBounds))\n"
+ L" return XMLErrorReporter::ErrType_Fatal;\n"
+ L" else if ((toCheck >= E_LowBounds) && (toCheck <= E_HighBounds))\n"
+ L" return XMLErrorReporter::ErrType_Error;\n"
+ L" return XMLErrorReporter::ErrTypes_Unknown;\n"
+ L" }\n"
+ , errNameSpace
+ );
+ }
- fwprintf
- (
- outHeader
- , L" static XMLErrorReporter::ErrTypes errorType(const %s::Codes toCheck)\n"
- L" {\n"
- L" if ((toCheck >= W_LowBounds) && (toCheck <= W_HighBounds))\n"
- L" return XMLErrorReporter::ErrType_Warning;\n"
- L" else if ((toCheck >= F_LowBounds) && (toCheck <= F_HighBounds))\n"
- L" return XMLErrorReporter::ErrType_Fatal;\n"
- L" else if ((toCheck >= E_LowBounds) && (toCheck <= E_HighBounds))\n"
- L" return XMLErrorReporter::ErrType_Error;\n"
- L" return XMLErrorReporter::ErrTypes_Unknown;\n"
- L" }\n"
- , errNameSpace
- );
+ // And close out the class declaration and the header file
+ fwprintf(outHeader, L"};\n#endif\n\n");
+ fclose(outHeader);
}
- // And close out the class declaration and the header file
- fwprintf(outHeader, L"};\n#endif\n\n");
- fclose(outHeader);
- }
-
- // Ok, we are done so call the end output method
- formatter->endOutput();
+ // Ok, we are done so call the end output method
+ formatter->endOutput();
- // And clean up the stuff we allocated
- delete formatter;
- }
+ // And clean up the stuff we allocated
+ delete formatter;
+ }
- catch(const ErrReturns retVal)
- {
- // And call the termination method
- XMLPlatformUtils::Terminate();
- return retVal;
+ catch(const ErrReturns retVal)
+ {
+ // And call the termination method
+ XMLPlatformUtils::Terminate();
+ return retVal;
+ }
}
// And call the termination method
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org