📄 xlat.cpp
字号:
/* * Copyright 1999-2000,2004 The Apache Software Foundation. * * Licensed 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. *//* * $Log: Xlat.cpp,v $ * Revision 1.21 2004/09/08 13:57:07 peiyongz * Apache License Version 2.0 * * Revision 1.20 2004/05/05 10:53:08 amassari * Make it compile again on Windows * * Revision 1.19 2004/04/20 15:30:49 peiyongz * to generate code for private default constructor * * Revision 1.18 2003/05/14 19:11:34 gareth * Added code creation for new method that returns error serverity the DOM way. * * 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. * * Revision 1.15 2002/11/12 17:24:58 tng * DOM Message: add new domain for DOM Messages. * * Revision 1.14 2002/11/04 15:24:50 tng * C++ Namespace Support. * * Revision 1.13 2002/09/30 22:09:58 peiyongz * To generate icu resource file (in text) for error message. * * Revision 1.12 2002/07/04 17:40:07 tng * Use new DOM in Xlat. * * 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. * * Revision 1.9 2002/02/01 23:48:37 peiyongz * sane_include * * Revision 1.8 2001/05/03 19:09:36 knoaman * Support Warning/Error/FatalError messaging. * Validity constraints errors are treated as errors, with the ability by user to set * validity constraints as fatal errors. * * Revision 1.7 2000/03/18 00:00:58 roddey * Improved error reporting * * Revision 1.6 2000/03/03 01:29:36 roddey * Added a scanReset()/parseReset() method to the scanner and * parsers, to allow for reset after early exit from a progressive parse. * Added calls to new Terminate() call to all of the samples. Improved * documentation in SAX and DOM parsers. * * Revision 1.5 2000/03/02 19:55:52 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 * available elsewhere. * * Revision 1.4 2000/02/14 19:25:44 roddey * Fixed some small bugs in how it used strings returned from DOM calls. * * Revision 1.3 2000/02/06 07:48:41 rahulj * Year 2K copyright swat. * * Revision 1.2 2000/01/05 20:24:58 roddey * Some changes to simplify life for the Messge Catalog message loader. The formatter * for the message loader now spits out a simple header of ids that allows the loader to * be independent of hard coded set numbers. * * Revision 1.1.1.1 1999/11/09 01:01:12 twl * Initial checkin * * Revision 1.5 1999/11/08 20:42:04 rahul * Swat for adding in Product name and CVS comment log variable. * */// ---------------------------------------------------------------------------// This program is designed to parse an XML file which holds error text// data. It will build a DOM tree from that source file and can output it// a number of different formats.//// In order to drastically simplify the program, it is designed only to run// on platforms/compilers that understand Unicode. It can output the data// in whatever format is required, so it can handle outputting for other// platforms. This also simplifies bootstrapping new releases up on other// platforms. Once the Win32 version is working, it can generate output for// the other platforms so that they can have loadable text from day one.// ---------------------------------------------------------------------------// ---------------------------------------------------------------------------// Includes// ---------------------------------------------------------------------------#include "Xlat.hpp"// ---------------------------------------------------------------------------// Static data//// gRelativeInputPath// 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.// ---------------------------------------------------------------------------XMLCh* gRelativeInputPath = 0;// ---------------------------------------------------------------------------// Global data// ---------------------------------------------------------------------------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//// gLocale// This is the locale suffix, e.g. US_EN, that is used to find the// correct file and can be used on output files as well. Its set via// the /Locale= parameter.//// gOutFormat// This is the output format, which is given on the command line as// /OutFmt= Its mapped to the internal enum which is stored here.//// gOutPath// This is the path to the output path, which is given on the command// line as /OutPath=. Its just the path, not a name, since the output// might consist of multiple output files. They will all be based on// the base part of the input name.//// gSrcRoot// This the path to the root of the build tree. The input files needed// are found in known places relative to it.// ---------------------------------------------------------------------------const XMLCh* gLocale = 0;OutFormats gOutFormat = OutFormat_Unknown;const XMLCh* gOutPath = 0;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// order and format, for simplicity://// /SrcRoot=xxx /OutPath=xxx /OutFmt=xxx /Locale=xxx////static bool parseParms(const int argC, XMLCh** argV)bool parseParms(const int argC, XMLCh** argV){ if (argC < 5) return false; unsigned int curParm = 1; 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++; 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++; tmpXMLStr = XMLString::transcode("/OutFmt="); if (XMLString::startsWith(argV[curParm], tmpXMLStr )) { XMLString::release(&tmpXMLStr); const XMLCh* tmpFmt = &argV[curParm][8]; 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, tmpXMLStr2 )) gOutFormat = OutFormat_Win32RC; else if (!XMLString::compareIString(tmpFmt, tmpXMLStr3 )) gOutFormat = OutFormat_CppSrc; 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++; 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)void parseError(const XMLException& toCatch){ wprintf ( L"Exception\n (Line.File):%d.%s\n ERROR: %s\n\n" , toCatch.getSrcLine() , toCatch.getSrcFile() , toCatch.getMessage() ); throw ErrReturn_ParseErr;}//static void parseError(const SAXParseException& toCatch)void parseError(const SAXParseException& toCatch){ wprintf ( L"SAX Parse Error:\n (Line.Col.SysId): %d.%d.%s\n ERROR: %s\n\n" , toCatch.getLineNumber() , toCatch.getColumnNumber() , toCatch.getSystemId() , toCatch.getMessage() ); throw ErrReturn_ParseErr;}//static voidvoidenumMessages( const DOMElement* srcElem
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -