Xlat_Win32RC.cpp
上传用户:huihehuasu
上传日期:2007-01-10
资源大小:6948k
文件大小:8k
源码类别:

xml/soap/webservice

开发平台:

C/C++

  1. /*
  2.  * The Apache Software License, Version 1.1
  3.  * 
  4.  * Copyright (c) 1999-2000 The Apache Software Foundation.  All rights
  5.  * reserved.
  6.  * 
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  * 
  11.  * 1. Redistributions of source code must retain the above copyright
  12.  *    notice, this list of conditions and the following disclaimer. 
  13.  * 
  14.  * 2. Redistributions in binary form must reproduce the above copyright
  15.  *    notice, this list of conditions and the following disclaimer in
  16.  *    the documentation and/or other materials provided with the
  17.  *    distribution.
  18.  * 
  19.  * 3. The end-user documentation included with the redistribution,
  20.  *    if any, must include the following acknowledgment:  
  21.  *       "This product includes software developed by the
  22.  *        Apache Software Foundation (http://www.apache.org/)."
  23.  *    Alternately, this acknowledgment may appear in the software itself,
  24.  *    if and wherever such third-party acknowledgments normally appear.
  25.  * 
  26.  * 4. The names "Xerces" and "Apache Software Foundation" must
  27.  *    not be used to endorse or promote products derived from this
  28.  *    software without prior written permission. For written 
  29.  *    permission, please contact apache@apache.org.
  30.  * 
  31.  * 5. Products derived from this software may not be called "Apache",
  32.  *    nor may "Apache" appear in their name, without prior written
  33.  *    permission of the Apache Software Foundation.
  34.  * 
  35.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  36.  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  37.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  38.  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  39.  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  42.  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  43.  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  44.  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  45.  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  46.  * SUCH DAMAGE.
  47.  * ====================================================================
  48.  * 
  49.  * This software consists of voluntary contributions made by many
  50.  * individuals on behalf of the Apache Software Foundation, and was
  51.  * originally based on software copyright (c) 1999, International
  52.  * Business Machines, Inc., http://www.ibm.com .  For more information
  53.  * on the Apache Software Foundation, please see
  54.  * <http://www.apache.org/>.
  55.  */
  56. /*
  57.  * $Log: Xlat_Win32RC.cpp,v $
  58.  * Revision 1.4  2000/03/02 19:55:54  roddey
  59.  * This checkin includes many changes done while waiting for the
  60.  * 1.1.0 code to be finished. I can't list them all here, but a list is
  61.  * available elsewhere.
  62.  *
  63.  * Revision 1.3  2000/02/06 07:48:42  rahulj
  64.  * Year 2K copyright swat.
  65.  *
  66.  * Revision 1.2  2000/01/05 20:24:58  roddey
  67.  * Some changes to simplify life for the Messge Catalog message loader. The formatter
  68.  * for the message loader now spits out a simple header of ids that allows the loader to
  69.  * be independent of hard coded set numbers.
  70.  *
  71.  * Revision 1.1.1.1  1999/11/09 01:01:30  twl
  72.  * Initial checkin
  73.  *
  74.  * Revision 1.3  1999/11/08 20:42:07  rahul
  75.  * Swat for adding in Product name and CVS comment log variable.
  76.  *
  77.  */
  78. // ---------------------------------------------------------------------------
  79. //  Includes
  80. // ---------------------------------------------------------------------------
  81. #include "Xlat.hpp"
  82. // ---------------------------------------------------------------------------
  83. //  Win32RCFormatter: Public Constructors and Destructor
  84. // ---------------------------------------------------------------------------
  85. Win32RCFormatter::Win32RCFormatter() :
  86.     fCurDomainName(0)
  87.     , fMsgOffset(0)
  88.     , fOutFl(0)
  89. {
  90. }
  91. Win32RCFormatter::~Win32RCFormatter()
  92. {
  93. }
  94. // ---------------------------------------------------------------------------
  95. //  Win32RCFormatter: Implementation of the formatter interface
  96. // ---------------------------------------------------------------------------
  97. void Win32RCFormatter::endDomain(const  XMLCh* const    domainName
  98.                                 , const unsigned int    msgCount)
  99. {
  100.     // And close out the message table declaration
  101.     fwprintf(fOutFl, L"ENDn");
  102. }
  103. void Win32RCFormatter::endMsgType(const MsgTypes type)
  104. {
  105.     // No-op for us
  106. }
  107. void Win32RCFormatter::endOutput()
  108. {
  109.     // Close the output file
  110.     fclose(fOutFl);
  111. }
  112. void
  113. Win32RCFormatter::nextMessage(  const  XMLCh* const             msgText
  114.                                 , const XMLCh* const            msgId
  115.                                 , const unsigned int            messageId
  116.                                 , const unsigned int            curId)
  117. {
  118.     //
  119.     //  We do not transcode to the output format in this case. Instead we
  120.     //  just store the straight Unicode format. Because we cannot assume 'L'
  121.     //  type prefix support, we have to put them out as numeric character
  122.     //  values.
  123.     //
  124.     fwprintf(fOutFl, L"    %-16d  L"", messageId + fMsgOffset);
  125.     const XMLCh* rawData = msgText;
  126.     while (*rawData)
  127.         fwprintf(fOutFl, L"\x%04lX", *rawData++);
  128.     fwprintf(fOutFl, L"\x00"n");
  129. }
  130. void Win32RCFormatter::startDomain( const   XMLCh* const    domainName
  131.                                     , const XMLCh* const)
  132. {
  133.     //
  134.     //  We have a different array name for each domain, so store that for
  135.     //  later use and for use below.
  136.     //
  137.     if (!XMLString::compareString(XMLUni::fgXMLErrDomain, domainName))
  138.     {
  139.         fCurDomainName = L"gXMLErrArray";
  140.         fMsgOffset = 0;
  141.     }
  142.      else if (!XMLString::compareString(XMLUni::fgExceptDomain, domainName))
  143.     {
  144.         fCurDomainName = L"gXMLExceptArray";
  145.         fMsgOffset = 0x2000;
  146.     }
  147.      else if (!XMLString::compareString(XMLUni::fgValidityDomain, domainName))
  148.     {
  149.         fCurDomainName = L"gXMLValidityArray";
  150.         fMsgOffset = 0x4000;
  151.     }
  152.      else
  153.     {
  154.         wprintf(L"Unknown message domain: %sn", domainName);
  155.         throw ErrReturn_SrcFmtError;
  156.     }
  157.     //
  158.     //  Output the leading part of the array declaration. Its just an
  159.     //  array of pointers to Unicode chars.
  160.     //
  161.     fwprintf
  162.     (
  163.         fOutFl
  164.         , L"STRINGTABLE DISCARDABLEnBEGINn"
  165.     );
  166. }
  167. void Win32RCFormatter::startMsgType(const MsgTypes type)
  168. {
  169.     // No-op for us
  170. }
  171. void Win32RCFormatter::startOutput(  const  XMLCh* const locale
  172.                                     , const XMLCh* const outPath)
  173. {
  174.     //
  175.     //  Ok, lets try to open the the output file. All of the messages for all
  176.     //  the domains are put into a single message tabble in a single RC file,
  177.     //  which can be linked into the program.
  178.     //
  179.     //  CppErrMsgs_xxxx.RC
  180.     //
  181.     //  where xxx is the locale suffix passed in.
  182.     //
  183.     const unsigned int bufSize = 4095;
  184.     XMLCh tmpBuf[bufSize + 1];
  185.     swprintf(tmpBuf, L"%s/%s_%s.RC", outPath, L"CppErrMsgs", locale);
  186.     fOutFl = _wfopen(tmpBuf, L"wt");
  187.     if (!fOutFl)
  188.     {
  189.         wprintf(L"Could not open the output file: %snn", tmpBuf);
  190.         throw ErrReturn_OutFileOpenFailed;
  191.     }
  192.     //
  193.     //  Ok, lets output the grunt data at the start of the file. We put out a
  194.     //  comment that indicates its a generated file, and the title string.
  195.     //
  196.     fwprintf
  197.     (
  198.         fOutFl
  199.         , L"// ----------------------------------------------------------------n"
  200.           L"//  This file was generated from the XML error message source.n"
  201.           L"//  so do not edit this file directly!!n"
  202.           L"// ----------------------------------------------------------------nn"
  203.     );
  204. }