Sophie

Sophie

distrib > Mandriva > 2010.2 > i586 > by-pkgid > 9601c7beb4ff23e834bfa171795ed560 > files > 896

vidalia-0.2.9-1mdv2010.1.i586.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>Vidalia: po2wxl.cpp Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Generated by Doxygen 1.6.3 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li><a href="dirs.html"><span>Directories</span></a></li>
    </ul>
  </div>
  <div class="tabs">
    <ul>
      <li><a href="files.html"><span>File&nbsp;List</span></a></li>
      <li><a href="globals.html"><span>File&nbsp;Members</span></a></li>
    </ul>
  </div>
  <div class="navpath"><a class="el" href="dir_b47abd1aad201a152869566145babb61.html">src</a>&nbsp;&raquo;&nbsp;<a class="el" href="dir_beeb2bbed11c559150a792aad3aaec87.html">tools</a>&nbsp;&raquo;&nbsp;<a class="el" href="dir_faf706bdf6b1d72f12419fd6dbb823d9.html">po2wxl</a>
  </div>
</div>
<div class="contents">
<h1>po2wxl.cpp</h1><a href="po2wxl_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
<a name="l00002"></a>00002 <span class="comment">**  $Id: po2wxl.cpp 3679 2009-04-08 05:04:15Z edmanm $</span>
<a name="l00003"></a>00003 <span class="comment">**</span>
<a name="l00004"></a>00004 <span class="comment">**  This file is part of Vidalia, and is subject to the license terms in the</span>
<a name="l00005"></a>00005 <span class="comment">**  LICENSE file, found in the top level directory of this distribution. If you</span>
<a name="l00006"></a>00006 <span class="comment">**  did not receive the LICENSE file with this file, you may obtain it from the</span>
<a name="l00007"></a>00007 <span class="comment">**  Vidalia source package distributed by the Vidalia Project at</span>
<a name="l00008"></a>00008 <span class="comment">**  http://www.vidalia-project.net/. No part of Vidalia, including this file,</span>
<a name="l00009"></a>00009 <span class="comment">**  may be copied, modified, propagated, or distributed except according to the</span>
<a name="l00010"></a>00010 <span class="comment">**  terms described in the LICENSE file.</span>
<a name="l00011"></a>00011 <span class="comment">*/</span>
<a name="l00012"></a>00012 
<a name="l00013"></a>00013 <span class="preprocessor">#include &lt;QFile&gt;</span>
<a name="l00014"></a>00014 <span class="preprocessor">#include &lt;QDomDocument&gt;</span>
<a name="l00015"></a>00015 <span class="preprocessor">#include &lt;QTextStream&gt;</span>
<a name="l00016"></a>00016 <span class="preprocessor">#include &lt;QTextCodec&gt;</span>
<a name="l00017"></a>00017 <span class="preprocessor">#include &lt;stdlib.h&gt;</span>
<a name="l00018"></a>00018 
<a name="l00019"></a><a class="code" href="po2wxl_8cpp.html#a6d81e4cde5f0c1ea456162d9a11e0151">00019</a> <span class="preprocessor">#define WXL_NAMESPACE                  &quot;http://schemas.microsoft.com/wix/2006/localization&quot;</span>
<a name="l00020"></a><a class="code" href="po2wxl_8cpp.html#a3f2e7c2760b144e045598550f9b868b2">00020</a> <span class="preprocessor"></span><span class="preprocessor">#define WXL_ELEMENT_ROOT               &quot;WixLocalization&quot;</span>
<a name="l00021"></a><a class="code" href="po2wxl_8cpp.html#ad695fcfa86d461eb8bbdb287d9e3fbfd">00021</a> <span class="preprocessor"></span><span class="preprocessor">#define WXL_ELEMENT_MESSAGE            &quot;String&quot;</span>
<a name="l00022"></a><a class="code" href="po2wxl_8cpp.html#adb2b27351ab6ef23da047119ab202738">00022</a> <span class="preprocessor"></span><span class="preprocessor">#define WXL_ATTR_MESSAGE_ID            &quot;Id&quot;</span>
<a name="l00023"></a><a class="code" href="po2wxl_8cpp.html#a5e0a01f0b82d6c103fb5e54dd2369564">00023</a> <span class="preprocessor"></span><span class="preprocessor">#define WXL_ATTR_LANGUAGE              &quot;LCID&quot;</span>
<a name="l00024"></a><a class="code" href="po2wxl_8cpp.html#adec5e8a2a2413e2a662570db1f52fde9">00024</a> <span class="preprocessor"></span><span class="preprocessor">#define WXL_ATTR_TRANSLATION_TYPE      &quot;Culture&quot;</span>
<a name="l00025"></a><a class="code" href="po2wxl_8cpp.html#ad011989cfe5cf8dddce46aa40143db6c">00025</a> <span class="preprocessor"></span><span class="preprocessor">#define WXL_ATTR_OVERRIDABLE           &quot;Overridable&quot;</span>
<a name="l00026"></a>00026 <span class="preprocessor"></span><span class="comment"></span>
<a name="l00027"></a>00027 <span class="comment">/** We need to provide an element with the LCID for this locale </span>
<a name="l00028"></a>00028 <span class="comment"> * that is used in the WiX Product definition. */</span>
<a name="l00029"></a>00029 QString
<a name="l00030"></a><a class="code" href="po2wxl_8cpp.html#a1da0262fa2311bbe179d6497c6f6ea0f">00030</a> <a class="code" href="po2wxl_8cpp.html#a1da0262fa2311bbe179d6497c6f6ea0f">culture_lcid</a>(<span class="keyword">const</span> QString &amp;culture)
<a name="l00031"></a>00031 {
<a name="l00032"></a>00032   <span class="comment">/* For now character encoding focused, not generally locale / dialect aware. */</span>
<a name="l00033"></a>00033   QString lcid = <span class="stringliteral">&quot;0&quot;</span>;
<a name="l00034"></a>00034   <span class="keywordflow">if</span>(!culture.compare(<span class="stringliteral">&quot;en&quot;</span>, Qt::CaseInsensitive)) 
<a name="l00035"></a>00035     lcid = <span class="stringliteral">&quot;1033&quot;</span>;
<a name="l00036"></a>00036   <span class="keywordflow">else</span> <span class="keywordflow">if</span>(!culture.compare(<span class="stringliteral">&quot;cs&quot;</span>, Qt::CaseInsensitive)) 
<a name="l00037"></a>00037     lcid = <span class="stringliteral">&quot;1029&quot;</span>;
<a name="l00038"></a>00038   <span class="keywordflow">else</span> <span class="keywordflow">if</span>(!culture.compare(<span class="stringliteral">&quot;de&quot;</span>, Qt::CaseInsensitive)) 
<a name="l00039"></a>00039     lcid = <span class="stringliteral">&quot;1031&quot;</span>;
<a name="l00040"></a>00040   <span class="keywordflow">else</span> <span class="keywordflow">if</span>(!culture.compare(<span class="stringliteral">&quot;es&quot;</span>, Qt::CaseInsensitive)) 
<a name="l00041"></a>00041     lcid = <span class="stringliteral">&quot;1034&quot;</span>;
<a name="l00042"></a>00042   <span class="keywordflow">else</span> <span class="keywordflow">if</span>(!culture.compare(<span class="stringliteral">&quot;fa&quot;</span>, Qt::CaseInsensitive)) 
<a name="l00043"></a>00043     lcid = <span class="stringliteral">&quot;1065&quot;</span>;
<a name="l00044"></a>00044   <span class="keywordflow">else</span> <span class="keywordflow">if</span>(!culture.compare(<span class="stringliteral">&quot;fi&quot;</span>, Qt::CaseInsensitive)) 
<a name="l00045"></a>00045     lcid = <span class="stringliteral">&quot;1035&quot;</span>;
<a name="l00046"></a>00046   <span class="keywordflow">else</span> <span class="keywordflow">if</span>(!culture.compare(<span class="stringliteral">&quot;fr&quot;</span>, Qt::CaseInsensitive)) 
<a name="l00047"></a>00047     lcid = <span class="stringliteral">&quot;1036&quot;</span>;
<a name="l00048"></a>00048   <span class="keywordflow">else</span> <span class="keywordflow">if</span>(!culture.compare(<span class="stringliteral">&quot;he&quot;</span>, Qt::CaseInsensitive)) 
<a name="l00049"></a>00049     lcid = <span class="stringliteral">&quot;1037&quot;</span>;
<a name="l00050"></a>00050   <span class="keywordflow">else</span> <span class="keywordflow">if</span>(!culture.compare(<span class="stringliteral">&quot;it&quot;</span>, Qt::CaseInsensitive)) 
<a name="l00051"></a>00051     lcid = <span class="stringliteral">&quot;1040&quot;</span>;
<a name="l00052"></a>00052   <span class="keywordflow">else</span> <span class="keywordflow">if</span>(!culture.compare(<span class="stringliteral">&quot;nl&quot;</span>, Qt::CaseInsensitive)) 
<a name="l00053"></a>00053     lcid = <span class="stringliteral">&quot;1043&quot;</span>;
<a name="l00054"></a>00054   <span class="keywordflow">else</span> <span class="keywordflow">if</span>(!culture.compare(<span class="stringliteral">&quot;pl&quot;</span>, Qt::CaseInsensitive)) 
<a name="l00055"></a>00055     lcid = <span class="stringliteral">&quot;1045&quot;</span>;
<a name="l00056"></a>00056   <span class="keywordflow">else</span> <span class="keywordflow">if</span>(!culture.compare(<span class="stringliteral">&quot;pt&quot;</span>, Qt::CaseInsensitive)) 
<a name="l00057"></a>00057     lcid = <span class="stringliteral">&quot;1046&quot;</span>;
<a name="l00058"></a>00058   <span class="keywordflow">else</span> <span class="keywordflow">if</span>(!culture.compare(<span class="stringliteral">&quot;ro&quot;</span>, Qt::CaseInsensitive)) 
<a name="l00059"></a>00059     lcid = <span class="stringliteral">&quot;1048&quot;</span>;
<a name="l00060"></a>00060   <span class="keywordflow">else</span> <span class="keywordflow">if</span>(!culture.compare(<span class="stringliteral">&quot;ru&quot;</span>, Qt::CaseInsensitive)) 
<a name="l00061"></a>00061     lcid = <span class="stringliteral">&quot;1049&quot;</span>;
<a name="l00062"></a>00062   <span class="keywordflow">else</span> <span class="keywordflow">if</span>(!culture.compare(<span class="stringliteral">&quot;sv&quot;</span>, Qt::CaseInsensitive)) 
<a name="l00063"></a>00063     lcid = <span class="stringliteral">&quot;1053&quot;</span>;
<a name="l00064"></a>00064   <span class="keywordflow">return</span> lcid;
<a name="l00065"></a>00065 }
<a name="l00066"></a>00066 <span class="comment"></span>
<a name="l00067"></a>00067 <span class="comment">/** Create a new message string element using the source string &lt;b&gt;msgid&lt;/b&gt;</span>
<a name="l00068"></a>00068 <span class="comment"> * and the translation &lt;b&gt;msgstr&lt;/b&gt; and assign identifier attribute. */</span>
<a name="l00069"></a>00069 QDomElement
<a name="l00070"></a><a class="code" href="po2wxl_8cpp.html#ab0f613af31d4465d62fabc2f9663a601">00070</a> <a class="code" href="po2ts_8cpp.html#aeb2dfc933358826c475268be76f27ade">new_message_element</a>(QDomDocument *wxl, <span class="keyword">const</span> QString &amp;strid,
<a name="l00071"></a>00071                     <span class="keyword">const</span> QString &amp;msgid, <span class="keyword">const</span> QString &amp;msgstr)
<a name="l00072"></a>00072 {
<a name="l00073"></a>00073   QDomElement message;
<a name="l00074"></a>00074 
<a name="l00075"></a>00075   message = wxl-&gt;createElement(<a class="code" href="po2wxl_8cpp.html#ad695fcfa86d461eb8bbdb287d9e3fbfd">WXL_ELEMENT_MESSAGE</a>);
<a name="l00076"></a>00076   message.setAttribute(<a class="code" href="po2wxl_8cpp.html#adb2b27351ab6ef23da047119ab202738">WXL_ATTR_MESSAGE_ID</a>, strid);
<a name="l00077"></a>00077 
<a name="l00078"></a>00078   <span class="comment">/* Always allow localized string to be dynamic. This is required for</span>
<a name="l00079"></a>00079 <span class="comment">   * multi-language packages to link correctly.</span>
<a name="l00080"></a>00080 <span class="comment">   */</span>
<a name="l00081"></a>00081   message.setAttribute(<a class="code" href="po2wxl_8cpp.html#ad011989cfe5cf8dddce46aa40143db6c">WXL_ATTR_OVERRIDABLE</a>, <span class="stringliteral">&quot;yes&quot;</span>);
<a name="l00082"></a>00082   <span class="keywordflow">if</span> (!msgstr.isEmpty())
<a name="l00083"></a>00083     message.appendChild(wxl-&gt;createTextNode(msgstr));
<a name="l00084"></a>00084   <span class="keywordflow">else</span>
<a name="l00085"></a>00085     message.appendChild(wxl-&gt;createTextNode(msgid));
<a name="l00086"></a>00086 
<a name="l00087"></a>00087   <span class="keywordflow">return</span> message;
<a name="l00088"></a>00088 }
<a name="l00089"></a>00089 <span class="comment"></span>
<a name="l00090"></a>00090 <span class="comment">/** Create a new WXL document of the appropriate doctype and root</span>
<a name="l00091"></a>00091 <span class="comment"> * element with the Microsoft style culture name for locale. */</span>
<a name="l00092"></a>00092 QDomDocument
<a name="l00093"></a><a class="code" href="po2wxl_8cpp.html#a3e9aad339aa53dcaf63f7e61501ff868">00093</a> <a class="code" href="po2wxl_8cpp.html#a3e9aad339aa53dcaf63f7e61501ff868">new_wxl_document</a>(<span class="keyword">const</span> QString &amp;culture)
<a name="l00094"></a>00094 {
<a name="l00095"></a>00095   QDomDocument wxl;
<a name="l00096"></a>00096   
<a name="l00097"></a>00097   QDomElement root = wxl.createElementNS(<a class="code" href="po2wxl_8cpp.html#a6d81e4cde5f0c1ea456162d9a11e0151">WXL_NAMESPACE</a>, <a class="code" href="po2wxl_8cpp.html#a3f2e7c2760b144e045598550f9b868b2">WXL_ELEMENT_ROOT</a>);
<a name="l00098"></a>00098   root.setAttribute(<a class="code" href="po2wxl_8cpp.html#adec5e8a2a2413e2a662570db1f52fde9">WXL_ATTR_TRANSLATION_TYPE</a>, culture);
<a name="l00099"></a>00099   wxl.appendChild(root);
<a name="l00100"></a>00100 
<a name="l00101"></a>00101   <span class="keywordflow">return</span> wxl;
<a name="l00102"></a>00102 }
<a name="l00103"></a>00103 <span class="comment"></span>
<a name="l00104"></a>00104 <span class="comment">/** Parse the context name from &lt;b&gt;str&lt;/b&gt;, where the context name is of the</span>
<a name="l00105"></a>00105 <span class="comment"> * form DQUOTE ContextName DQUOTE. */</span>
<a name="l00106"></a>00106 QString
<a name="l00107"></a><a class="code" href="po2wxl_8cpp.html#a365f06fe0efd30b4822c6b74fb8a8312">00107</a> <a class="code" href="nsh2po_8cpp.html#a365f06fe0efd30b4822c6b74fb8a8312">parse_message_context</a>(<span class="keyword">const</span> QString &amp;str)
<a name="l00108"></a>00108 {
<a name="l00109"></a>00109   QString out = str.trimmed();
<a name="l00110"></a>00110   out = out.replace(<span class="stringliteral">&quot;\&quot;&quot;</span>, <span class="stringliteral">&quot;&quot;</span>);
<a name="l00111"></a>00111   <span class="keywordflow">return</span> out;
<a name="l00112"></a>00112 }
<a name="l00113"></a>00113 <span class="comment"></span>
<a name="l00114"></a>00114 <span class="comment">/** Parse the context name from &lt;b&gt;str&lt;/b&gt;, where &lt;b&gt;str&lt;/b&gt; is of the</span>
<a name="l00115"></a>00115 <span class="comment"> * form ContextName#Number. This is the format used by translate-toolkit. */</span>
<a name="l00116"></a>00116 QString
<a name="l00117"></a><a class="code" href="po2wxl_8cpp.html#a041f6703063a9673d913561962ddbc6c">00117</a> <a class="code" href="nsh2po_8cpp.html#a041f6703063a9673d913561962ddbc6c">parse_message_context_lame</a>(<span class="keyword">const</span> QString &amp;str)
<a name="l00118"></a>00118 {
<a name="l00119"></a>00119   <span class="keywordflow">if</span> (str.contains(<span class="stringliteral">&quot;#&quot;</span>))
<a name="l00120"></a>00120     <span class="keywordflow">return</span> str.section(<span class="stringliteral">&quot;#&quot;</span>, 0, 0);
<a name="l00121"></a>00121   <span class="keywordflow">return</span> QString();
<a name="l00122"></a>00122 }
<a name="l00123"></a>00123 <span class="comment"></span>
<a name="l00124"></a>00124 <span class="comment">/** Parse the PO-formatted message string from &lt;b&gt;msg&lt;/b&gt;. If &lt;b&gt;msg&lt;/b&gt; is a</span>
<a name="l00125"></a>00125 <span class="comment"> * multiline string, the extra double quotes will be replaced with newlines</span>
<a name="l00126"></a>00126 <span class="comment"> * appropriately. */</span>
<a name="l00127"></a>00127 QString
<a name="l00128"></a><a class="code" href="po2wxl_8cpp.html#a2536f50f6d8ff0752b5fd134a7ef7082">00128</a> <a class="code" href="nsh2po_8cpp.html#a2536f50f6d8ff0752b5fd134a7ef7082">parse_message_string</a>(<span class="keyword">const</span> QString &amp;msg)
<a name="l00129"></a>00129 {
<a name="l00130"></a>00130   QString out = msg.trimmed(); 
<a name="l00131"></a>00131   
<a name="l00132"></a>00132   out.replace(<span class="stringliteral">&quot;\&quot;\n\&quot;&quot;</span>, <span class="stringliteral">&quot;\n&quot;</span>);
<a name="l00133"></a>00133   <span class="keywordflow">if</span> (out.startsWith(<span class="stringliteral">&quot;\&quot;&quot;</span>))
<a name="l00134"></a>00134     out = out.remove(0, 1);
<a name="l00135"></a>00135   <span class="keywordflow">if</span> (out.endsWith(<span class="stringliteral">&quot;\&quot;&quot;</span>))
<a name="l00136"></a>00136     out.chop(1);
<a name="l00137"></a>00137   out.replace(<span class="stringliteral">&quot;\\\&quot;&quot;</span>, <span class="stringliteral">&quot;\&quot;&quot;</span>);
<a name="l00138"></a>00138 
<a name="l00139"></a>00139   <span class="comment">/* convert NSIS style vars to Properties; avoid QRegExp if possible. */</span>
<a name="l00140"></a>00140   <span class="keywordtype">int</span> lind, rind;
<a name="l00141"></a>00141   <span class="keywordflow">while</span> ( ((lind = out.indexOf(<span class="stringliteral">&quot;${&quot;</span>)) &gt;= 0) &amp;&amp;
<a name="l00142"></a>00142           ((rind = out.indexOf(<span class="stringliteral">&quot;}&quot;</span>, lind)) &gt; lind) ) {
<a name="l00143"></a>00143     out.replace(lind, 2, <span class="stringliteral">&quot;[&quot;</span>);
<a name="l00144"></a>00144     out.replace(--rind, 1, <span class="stringliteral">&quot;]&quot;</span>);
<a name="l00145"></a>00145   }
<a name="l00146"></a>00146   <span class="keywordflow">return</span> out;
<a name="l00147"></a>00147 }
<a name="l00148"></a>00148 <span class="comment"></span>
<a name="l00149"></a>00149 <span class="comment">/** Read and return the next non-empty line from &lt;b&gt;stream&lt;/b&gt;. */</span>
<a name="l00150"></a>00150 QString
<a name="l00151"></a><a class="code" href="po2wxl_8cpp.html#a30bb52b8ae8ec480fb93b39710da3b45">00151</a> <a class="code" href="nsh2po_8cpp.html#a30bb52b8ae8ec480fb93b39710da3b45">read_next_line</a>(QTextStream *stream)
<a name="l00152"></a>00152 {
<a name="l00153"></a>00153   stream-&gt;skipWhiteSpace();
<a name="l00154"></a>00154   <span class="keywordflow">return</span> stream-&gt;readLine().append(<span class="stringliteral">&quot;\n&quot;</span>);
<a name="l00155"></a>00155 }
<a name="l00156"></a>00156 <span class="comment"></span>
<a name="l00157"></a>00157 <span class="comment">/** Skip past the header portion of the PO file and any leading whitespace. </span>
<a name="l00158"></a>00158 <span class="comment"> * The next line read from &lt;b&gt;po&lt;/b&gt; will be the first non-header line in the</span>
<a name="l00159"></a>00159 <span class="comment"> * document. */</span>
<a name="l00160"></a>00160 <span class="keywordtype">void</span>
<a name="l00161"></a><a class="code" href="po2wxl_8cpp.html#a8c13543b77ece0e6dc9d0fe52b59e57d">00161</a> <a class="code" href="po2nsh_8cpp.html#a8c13543b77ece0e6dc9d0fe52b59e57d">skip_po_header</a>(QTextStream *po)
<a name="l00162"></a>00162 {
<a name="l00163"></a>00163   QString line;
<a name="l00164"></a>00164   <span class="comment">/* Skip any leading whitespace before the header */</span>
<a name="l00165"></a>00165   po-&gt;skipWhiteSpace();
<a name="l00166"></a>00166   <span class="comment">/* Read to the first empty line */</span>
<a name="l00167"></a>00167   line = po-&gt;readLine();
<a name="l00168"></a>00168   <span class="keywordflow">while</span> (!po-&gt;atEnd() &amp;&amp; !line.isEmpty())
<a name="l00169"></a>00169     line = po-&gt;readLine();
<a name="l00170"></a>00170 }
<a name="l00171"></a>00171 <span class="comment"></span>
<a name="l00172"></a>00172 <span class="comment">/** Convert &lt;b&gt;po&lt;/b&gt; from the PO format to a WXL-formatted XML document.</span>
<a name="l00173"></a>00173 <span class="comment"> * &lt;b&gt;wxl&lt;/b&gt; will be set to the resulting WXL document. Return the number of</span>
<a name="l00174"></a>00174 <span class="comment"> * converted strings on success, or -1 on error and &lt;b&gt;errorMessage&lt;/b&gt; will</span>
<a name="l00175"></a>00175 <span class="comment"> * be set. */</span>
<a name="l00176"></a>00176 <span class="keywordtype">int</span>
<a name="l00177"></a><a class="code" href="po2wxl_8cpp.html#ab68a5be2254c170892acf4e56b866219">00177</a> <a class="code" href="po2wxl_8cpp.html#ab68a5be2254c170892acf4e56b866219">po2wxl</a>(<span class="keyword">const</span> QString&amp; culture, QTextStream *po, QDomDocument *wxl,
<a name="l00178"></a>00178   QString *errorMessage)
<a name="l00179"></a>00179 {
<a name="l00180"></a>00180   QString line;
<a name="l00181"></a>00181   QString msgctxt, msgid, msgstr;
<a name="l00182"></a>00182   QDomElement msgElement;
<a name="l00183"></a>00183   <span class="keywordtype">int</span> n_strings = 0;
<a name="l00184"></a>00184 
<a name="l00185"></a>00185   Q_ASSERT(po);
<a name="l00186"></a>00186   Q_ASSERT(wxl);
<a name="l00187"></a>00187   Q_ASSERT(errorMessage);
<a name="l00188"></a>00188 
<a name="l00189"></a>00189   *wxl = <a class="code" href="po2wxl_8cpp.html#a3e9aad339aa53dcaf63f7e61501ff868">new_wxl_document</a>(culture);
<a name="l00190"></a>00190 
<a name="l00191"></a>00191   <span class="comment">/* Set the LCID to Language code for use as !(loc.LCID) in Product. */</span>
<a name="l00192"></a>00192   QString lcid = <a class="code" href="po2wxl_8cpp.html#a1da0262fa2311bbe179d6497c6f6ea0f">culture_lcid</a>(culture); 
<a name="l00193"></a>00193   wxl-&gt;documentElement().appendChild(
<a name="l00194"></a>00194     <a class="code" href="po2ts_8cpp.html#aeb2dfc933358826c475268be76f27ade">new_message_element</a>(wxl, <a class="code" href="po2wxl_8cpp.html#a5e0a01f0b82d6c103fb5e54dd2369564">WXL_ATTR_LANGUAGE</a>, lcid, lcid)); 
<a name="l00195"></a>00195 
<a name="l00196"></a>00196   <a class="code" href="po2nsh_8cpp.html#a8c13543b77ece0e6dc9d0fe52b59e57d">skip_po_header</a>(po);
<a name="l00197"></a>00197   line = <a class="code" href="nsh2po_8cpp.html#a30bb52b8ae8ec480fb93b39710da3b45">read_next_line</a>(po);
<a name="l00198"></a>00198   <span class="keywordflow">while</span> (!po-&gt;atEnd()) {
<a name="l00199"></a>00199     <span class="comment">/* Ignore all &quot;#&quot; lines except &quot;#:&quot; */</span>
<a name="l00200"></a>00200     <span class="keywordflow">while</span> (line.startsWith(<span class="stringliteral">&quot;#&quot;</span>)) {
<a name="l00201"></a>00201       <span class="keywordflow">if</span> (line.startsWith(<span class="stringliteral">&quot;#:&quot;</span>)) {
<a name="l00202"></a>00202         <span class="comment">/* Context was specified with the stupid overloaded &quot;#:&quot; syntax.*/</span>
<a name="l00203"></a>00203         msgctxt = line.section(<span class="stringliteral">&quot; &quot;</span>, 1);
<a name="l00204"></a>00204         msgctxt = <a class="code" href="nsh2po_8cpp.html#a041f6703063a9673d913561962ddbc6c">parse_message_context_lame</a>(msgctxt);
<a name="l00205"></a>00205       }
<a name="l00206"></a>00206       line = <a class="code" href="nsh2po_8cpp.html#a30bb52b8ae8ec480fb93b39710da3b45">read_next_line</a>(po);
<a name="l00207"></a>00207     }
<a name="l00208"></a>00208 
<a name="l00209"></a>00209     <span class="comment">/* A context specified on a &quot;msgctxt&quot; line takes precedence over a context</span>
<a name="l00210"></a>00210 <span class="comment">     * specified using the overload &quot;#:&quot; notation. */</span>
<a name="l00211"></a>00211     <span class="keywordflow">if</span> (line.startsWith(<span class="stringliteral">&quot;msgctxt &quot;</span>)) {    
<a name="l00212"></a>00212       msgctxt = line.section(<span class="stringliteral">&quot; &quot;</span>, 1);
<a name="l00213"></a>00213       msgctxt = <a class="code" href="nsh2po_8cpp.html#a365f06fe0efd30b4822c6b74fb8a8312">parse_message_context</a>(msgctxt);
<a name="l00214"></a>00214       line = <a class="code" href="nsh2po_8cpp.html#a30bb52b8ae8ec480fb93b39710da3b45">read_next_line</a>(po);
<a name="l00215"></a>00215     }
<a name="l00216"></a>00216     
<a name="l00217"></a>00217     <span class="comment">/* Parse the (possibly multiline) message source string */</span>
<a name="l00218"></a>00218     <span class="keywordflow">if</span> (!line.startsWith(<span class="stringliteral">&quot;msgid &quot;</span>)) {
<a name="l00219"></a>00219       *errorMessage = <span class="stringliteral">&quot;expected &#39;msgid&#39; line&quot;</span>;
<a name="l00220"></a>00220       <span class="keywordflow">return</span> -1;
<a name="l00221"></a>00221     }
<a name="l00222"></a>00222     msgid = line.section(<span class="stringliteral">&quot; &quot;</span>, 1);
<a name="l00223"></a>00223     
<a name="l00224"></a>00224     line = <a class="code" href="nsh2po_8cpp.html#a30bb52b8ae8ec480fb93b39710da3b45">read_next_line</a>(po);
<a name="l00225"></a>00225     <span class="keywordflow">while</span> (line.startsWith(<span class="stringliteral">&quot;\&quot;&quot;</span>)) {
<a name="l00226"></a>00226       msgid.append(line);
<a name="l00227"></a>00227       line = <a class="code" href="nsh2po_8cpp.html#a30bb52b8ae8ec480fb93b39710da3b45">read_next_line</a>(po);
<a name="l00228"></a>00228     }
<a name="l00229"></a>00229     msgid = <a class="code" href="nsh2po_8cpp.html#a2536f50f6d8ff0752b5fd134a7ef7082">parse_message_string</a>(msgid);
<a name="l00230"></a>00230 
<a name="l00231"></a>00231     <span class="comment">/* Parse the (possibly multiline) translated string */</span>
<a name="l00232"></a>00232     <span class="keywordflow">if</span> (!line.startsWith(<span class="stringliteral">&quot;msgstr &quot;</span>)) {
<a name="l00233"></a>00233       *errorMessage = <span class="stringliteral">&quot;expected &#39;msgstr&#39; line&quot;</span>;
<a name="l00234"></a>00234       <span class="keywordflow">return</span> -1;
<a name="l00235"></a>00235     }
<a name="l00236"></a>00236     msgstr = line.section(<span class="stringliteral">&quot; &quot;</span>, 1);
<a name="l00237"></a>00237     
<a name="l00238"></a>00238     line = <a class="code" href="nsh2po_8cpp.html#a30bb52b8ae8ec480fb93b39710da3b45">read_next_line</a>(po);
<a name="l00239"></a>00239     <span class="keywordflow">while</span> (line.startsWith(<span class="stringliteral">&quot;\&quot;&quot;</span>)) {
<a name="l00240"></a>00240       msgstr.append(line);
<a name="l00241"></a>00241       line = <a class="code" href="nsh2po_8cpp.html#a30bb52b8ae8ec480fb93b39710da3b45">read_next_line</a>(po);
<a name="l00242"></a>00242     }
<a name="l00243"></a>00243     msgstr = <a class="code" href="nsh2po_8cpp.html#a2536f50f6d8ff0752b5fd134a7ef7082">parse_message_string</a>(msgstr);
<a name="l00244"></a>00244 
<a name="l00245"></a>00245     <span class="comment">/* Add the message and translation to the .wxl document */</span>
<a name="l00246"></a>00246     wxl-&gt;documentElement().appendChild(
<a name="l00247"></a>00247       <a class="code" href="po2ts_8cpp.html#aeb2dfc933358826c475268be76f27ade">new_message_element</a>(wxl, msgctxt, msgid, msgstr)); 
<a name="l00248"></a>00248     
<a name="l00249"></a>00249     n_strings++;
<a name="l00250"></a>00250   }
<a name="l00251"></a>00251   <span class="keywordflow">return</span> n_strings;
<a name="l00252"></a>00252 }
<a name="l00253"></a>00253 <span class="comment"></span>
<a name="l00254"></a>00254 <span class="comment">/** Display application usage and exit. */</span>
<a name="l00255"></a>00255 <span class="keywordtype">void</span>
<a name="l00256"></a><a class="code" href="po2wxl_8cpp.html#a068e9e76bf4a101f996e30fd122df007">00256</a> <a class="code" href="nsh2po_8cpp.html#a068e9e76bf4a101f996e30fd122df007">print_usage_and_exit</a>()
<a name="l00257"></a>00257 {
<a name="l00258"></a>00258   QTextStream <a class="code" href="namespacetc.html#aa7353218fd7baef0876bbb422ce818af">error</a>(stderr);
<a name="l00259"></a>00259   error &lt;&lt; <span class="stringliteral">&quot;usage: po2wxl [-q] -n &lt;culture name&gt; -i &lt;infile.po&gt; -o &lt;outfile.wxl&gt; &quot;</span>
<a name="l00260"></a>00260            <span class="stringliteral">&quot;[-c &lt;encoding&gt;]\n&quot;</span>;
<a name="l00261"></a>00261   error &lt;&lt; <span class="stringliteral">&quot;  -q (optional)    Quiet mode (errors are still displayed)\n&quot;</span>;
<a name="l00262"></a>00262   error &lt;&lt; <span class="stringliteral">&quot;  -n &lt;culture&gt;     Culture name for translation\n&quot;</span>;
<a name="l00263"></a>00263   error &lt;&lt; <span class="stringliteral">&quot;  -i &lt;infile.po&gt;   Input .po file\n&quot;</span>;
<a name="l00264"></a>00264   error &lt;&lt; <span class="stringliteral">&quot;  -o &lt;outfile.wxl&gt; Output .wxl file\n&quot;</span>;
<a name="l00265"></a>00265   error &lt;&lt; <span class="stringliteral">&quot;  -c &lt;encoding&gt;    Text encoding (default: utf-8)\n&quot;</span>;
<a name="l00266"></a>00266   error.flush();
<a name="l00267"></a>00267   exit(1);
<a name="l00268"></a>00268 }
<a name="l00269"></a>00269 
<a name="l00270"></a>00270 <span class="keywordtype">int</span>
<a name="l00271"></a><a class="code" href="po2wxl_8cpp.html#a0ddf1224851353fc92bfbff6f499fa97">00271</a> <a class="code" href="_c_make_c_x_x_compiler_id_8cpp.html#a0ddf1224851353fc92bfbff6f499fa97">main</a>(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> *argv[])
<a name="l00272"></a>00272 {
<a name="l00273"></a>00273   QTextStream <a class="code" href="namespacetc.html#aa7353218fd7baef0876bbb422ce818af">error</a>(stderr);
<a name="l00274"></a>00274   QString culture, errorMessage;
<a name="l00275"></a>00275   <span class="keywordtype">char</span> *infile, *outfile;
<a name="l00276"></a>00276   QTextCodec *codec = QTextCodec::codecForName(<span class="stringliteral">&quot;utf-8&quot;</span>);
<a name="l00277"></a>00277   <span class="keywordtype">bool</span> quiet = <span class="keyword">false</span>;
<a name="l00278"></a>00278 
<a name="l00279"></a>00279   <span class="comment">/* Check for the correct number of input parameters. */</span>
<a name="l00280"></a>00280   <span class="keywordflow">if</span> (argc &lt; 5 || argc &gt; 9)
<a name="l00281"></a>00281     <a class="code" href="nsh2po_8cpp.html#a068e9e76bf4a101f996e30fd122df007">print_usage_and_exit</a>();
<a name="l00282"></a>00282   <span class="keywordflow">for</span> (<span class="keywordtype">int</span> <a class="code" href="html_8cpp.html#a4a5dba6492ea149585950c59c210ff47">i</a> = 1; <a class="code" href="html_8cpp.html#a4a5dba6492ea149585950c59c210ff47">i</a> &lt; argc; <a class="code" href="html_8cpp.html#a4a5dba6492ea149585950c59c210ff47">i</a>++) {
<a name="l00283"></a>00283     QString arg(argv[<a class="code" href="html_8cpp.html#a4a5dba6492ea149585950c59c210ff47">i</a>]);
<a name="l00284"></a>00284     <span class="keywordflow">if</span> (!arg.compare(<span class="stringliteral">&quot;-q&quot;</span>, Qt::CaseInsensitive))
<a name="l00285"></a>00285       quiet = <span class="keyword">true</span>;
<a name="l00286"></a>00286     <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!arg.compare(<span class="stringliteral">&quot;-n&quot;</span>, Qt::CaseInsensitive) &amp;&amp; ++i &lt; argc)
<a name="l00287"></a>00287       culture = argv[i];
<a name="l00288"></a>00288     <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!arg.compare(<span class="stringliteral">&quot;-i&quot;</span>, Qt::CaseInsensitive) &amp;&amp; ++i &lt; argc)
<a name="l00289"></a>00289       infile = argv[i];
<a name="l00290"></a>00290     <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!arg.compare(<span class="stringliteral">&quot;-o&quot;</span>, Qt::CaseInsensitive) &amp;&amp; ++i &lt; argc)
<a name="l00291"></a>00291       outfile = argv[i];
<a name="l00292"></a>00292     <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!arg.compare(<span class="stringliteral">&quot;-c&quot;</span>, Qt::CaseInsensitive) &amp;&amp; ++i &lt; argc) {
<a name="l00293"></a>00293       codec = QTextCodec::codecForName(argv[i]);
<a name="l00294"></a>00294       <span class="keywordflow">if</span> (!codec) {
<a name="l00295"></a>00295         error &lt;&lt; <span class="stringliteral">&quot;Invalid text encoding specified\n&quot;</span>;
<a name="l00296"></a>00296         <span class="keywordflow">return</span> 1;
<a name="l00297"></a>00297       }
<a name="l00298"></a>00298     } <span class="keywordflow">else</span>
<a name="l00299"></a>00299       <a class="code" href="nsh2po_8cpp.html#a068e9e76bf4a101f996e30fd122df007">print_usage_and_exit</a>(); 
<a name="l00300"></a>00300   }
<a name="l00301"></a>00301 
<a name="l00302"></a>00302   <span class="comment">/* Open the input PO file for reading. */</span>
<a name="l00303"></a>00303   QFile poFile(infile);
<a name="l00304"></a>00304   <span class="keywordflow">if</span> (!poFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
<a name="l00305"></a>00305     error &lt;&lt; QString(<span class="stringliteral">&quot;Unable to open &#39;%1&#39; for reading: %2\n&quot;</span>).arg(infile)
<a name="l00306"></a>00306                                                 .arg(poFile.errorString());
<a name="l00307"></a>00307     <span class="keywordflow">return</span> 2;
<a name="l00308"></a>00308   }
<a name="l00309"></a>00309 
<a name="l00310"></a>00310   QDomDocument wxl;
<a name="l00311"></a>00311   QTextStream po(&amp;poFile);
<a name="l00312"></a>00312   po.setCodec(codec);
<a name="l00313"></a>00313   <span class="keywordtype">int</span> n_strings = <a class="code" href="po2wxl_8cpp.html#ab68a5be2254c170892acf4e56b866219">po2wxl</a>(culture, &amp;po, &amp;wxl, &amp;errorMessage);
<a name="l00314"></a>00314   <span class="keywordflow">if</span> (n_strings &lt; 0) {
<a name="l00315"></a>00315     error &lt;&lt; QString(<span class="stringliteral">&quot;Unable to convert &#39;%1&#39;: %2\n&quot;</span>).arg(infile)
<a name="l00316"></a>00316                                                     .arg(errorMessage);
<a name="l00317"></a>00317     <span class="keywordflow">return</span> 3;
<a name="l00318"></a>00318   }
<a name="l00319"></a>00319 
<a name="l00320"></a>00320   <span class="comment">/* Open the WXL file for writing. */</span>
<a name="l00321"></a>00321   QFile wxlFile(outfile);
<a name="l00322"></a>00322   <span class="keywordflow">if</span> (!wxlFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
<a name="l00323"></a>00323     error &lt;&lt; QString(<span class="stringliteral">&quot;Unable to open &#39;%1&#39; for writing: %2\n&quot;</span>).arg(outfile)
<a name="l00324"></a>00324                                                 .arg(wxlFile.errorString());
<a name="l00325"></a>00325     <span class="keywordflow">return</span> 4;
<a name="l00326"></a>00326   }
<a name="l00327"></a>00327 
<a name="l00328"></a>00328   <span class="comment">/* Write the .wxl output. */</span>
<a name="l00329"></a>00329   QTextStream out(&amp;wxlFile);
<a name="l00330"></a>00330   out.setCodec(codec);
<a name="l00331"></a>00331   out &lt;&lt; QString(<span class="stringliteral">&quot;&lt;?xml version=\&quot;1.0\&quot; encoding=\&quot;%1\&quot;?&gt;\n&quot;</span>)
<a name="l00332"></a>00332                                                   .arg(QString(codec-&gt;name()));
<a name="l00333"></a>00333   out &lt;&lt; wxl.toString(4);
<a name="l00334"></a>00334 
<a name="l00335"></a>00335   <span class="keywordflow">if</span> (!quiet) {
<a name="l00336"></a>00336     QTextStream results(stdout);
<a name="l00337"></a>00337     results &lt;&lt; QString(<span class="stringliteral">&quot;Converted %1 strings from %2 to %3.\n&quot;</span>).arg(n_strings)
<a name="l00338"></a>00338                                                                .arg(infile)
<a name="l00339"></a>00339                                                                .arg(outfile);
<a name="l00340"></a>00340   }
<a name="l00341"></a>00341   <span class="keywordflow">return</span> 0;
<a name="l00342"></a>00342 }
<a name="l00343"></a>00343 
</pre></div></div>
<hr class="footer"/><address style="text-align: right;"><small>Generated on Mon Aug 30 22:58:54 2010 for Vidalia by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.3 </small></address>
</body>
</html>