📄 xlat.cpp
字号:
, XlatFormatter* const toCall , FILE* const headerFl , const MsgTypes msgType , unsigned int& count){ fwprintf ( headerFl , L" , %s%-30s = %d\n" , xmlStrToPrintable(typePrefixes[msgType]) , longChars("LowBounds") , count++ ); releasePrintableStr // // We just run through each of the child elements, each of which is // a Message element. Each one represents a message to output. We keep // a count so that we can output a const value afterwards. // DOMNode* curNode = srcElem->getFirstChild(); while (curNode) { // Skip over text nodes or comment nodes ect... if (curNode->getNodeType() != DOMNode::ELEMENT_NODE) { curNode = curNode->getNextSibling(); continue; } // Convert it to an element node const DOMElement* curElem = (const DOMElement*)curNode; // Ok, this should be a Message node 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. // 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", xmlStrToPrintable(msgId), count); releasePrintableStr // And tell the formatter about this one toCall->nextMessage ( msgText , msgId , count , count ); // Bump the counter, which is also the id assigner count++; // Move to the next child of the source element curNode = curNode->getNextSibling(); } // Write out an upper range bracketing id for this type of error fwprintf ( headerFl , L" , %s%-30s = %d\n" , xmlStrToPrintable(typePrefixes[msgType]) , longChars("HighBounds") , count++ ); releasePrintableStr}// ---------------------------------------------------------------------------// Program entry point// ---------------------------------------------------------------------------//// This is the program entry point. It checks the parms, parses the input// file to get a DOM tree, then passes the DOM tree to the appropriate// output method to output the info in a particular format.//int Xlat_main(int argC, XMLCh** argV);int main (int argC, char** argV) { try { XMLPlatformUtils::Initialize(); } catch(const XMLException& toCatch) { wprintf(L"Parser init error.\n ERROR: %s\n\n", toCatch.getMessage()); return ErrReturn_ParserInit; } int i; XMLCh** newArgV = new XMLCh*[argC]; for(i=0;i<argC; i++) { newArgV[i] = XMLString::transcode(argV[i]); } int toReturn = (Xlat_main(argC,newArgV)); for (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 // the processing code. // if (!parseParms(argC, argV)) { wprintf(L"Usage:\n NLSXlat /SrcRoot=xx /OutPath=xx /OutFmt=xx /Locale=xx\n\n"); return ErrReturn_BadParameters; } { // Nest entire code in an inner block. DOMDocument* srcDoc; const unsigned int bufSize = 4095; 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 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 // a DOM tree. Turn on validation when we do this. // XercesDOMParser parser; parser.setDoValidation(true); XlatErrHandler errHandler; parser.setErrorHandler(&errHandler); parser.parse(tmpFileBuf); srcDoc = parser.adoptDocument(); } catch(const XMLException& toCatch) { parseError(toCatch); } XMLString::release(&tmpFileBuf); // // 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; case OutFormat_ResBundle: formatter = new ICUResBundFormatter; break; default : wprintf(L"Unknown formatter type enum\n\n"); throw ErrReturn_Internal; } // // Lets handle the root element stuff first. This one holds any over // all information. // DOMElement* rootElem = srcDoc->getDocumentElement(); 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)) { 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. // tmpXMLStr = XMLString::transcode("MsgDomain"); DOMNodeList* msgSetList = rootElem->getElementsByTagName(tmpXMLStr); XMLString::release(&tmpXMLStr); // // Loop through them and look for the domains that we know are // supposed to be there. // const unsigned int count = msgSetList->getLength(); // // Normalize locale string // // locale = ll[[_CC][_VARIANT]] // where ll is language code // CC is country code // VARIANT is variant code // XMLCh normalizedLocale[256]; normalizedLocale[0] = localeStr[0]; normalizedLocale[1] = localeStr[1]; normalizedLocale[2] = 0; XMLString::lowerCase(normalizedLocale); if (XMLString::stringLen(localeStr) > 2) { XMLString::catString(&(normalizedLocale[2]), &(localeStr[2])); XMLString::upperCase(&(normalizedLocale[2])); } // // Ok, its good enough to get started. So lets call the start output // method on the formatter. // formatter->startOutput(normalizedLocale, gOutPath); // // 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 DOMNode* curNode = msgSetList->item(index); const DOMElement* curElem = (const DOMElement*)curNode; // // Get some of the attribute strings that we need, and transcode // couple that need to be in local format. // tmpXMLStr = XMLString::transcode("Domain"); const XMLCh* domainStr = curElem->getAttribute(tmpXMLStr ); XMLString::release(&tmpXMLStr); // // 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 // XMLCh* headerName = 0; XMLCh* errNameSpace = 0; if (!XMLString::compareString(domainStr, XMLUni::fgXMLErrDomain)) { headerName = XMLString::transcode("XMLErrorCodes.hpp"); errNameSpace = XMLString::transcode("XMLErrs"); } else if (!XMLString::compareString(domainStr, XMLUni::fgValidityDomain)) { headerName = XMLString::transcode("XMLValidityCodes.hpp"); errNameSpace = XMLString::transcode("XMLValid"); } else if (!XMLString::compareString(domainStr, XMLUni::fgExceptDomain)) { headerName = XMLString::transcode("XMLExceptMsgs.hpp"); errNameSpace = XMLString::transcode("XMLExcepts"); } else if (!XMLString::compareString(domainStr, XMLUni::fgXMLDOMMsgDomain)) { headerName = XMLString::transcode("XMLDOMMsg.hpp"); errNameSpace = XMLString::transcode("XMLDOMMsg"); } else { // Not one of ours, so skip it
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -