Sophie

Sophie

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

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: po2nsh.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_b64bc80a0889c3e4833a47c8f7a3b741.html">po2nsh</a>
  </div>
</div>
<div class="contents">
<h1>po2nsh.cpp</h1><a href="po2nsh_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">**  This file is part of Vidalia, and is subject to the license terms in the</span>
<a name="l00003"></a>00003 <span class="comment">**  LICENSE file, found in the top level directory of this distribution. If you</span>
<a name="l00004"></a>00004 <span class="comment">**  did not receive the LICENSE file with this file, you may obtain it from the</span>
<a name="l00005"></a>00005 <span class="comment">**  Vidalia source package distributed by the Vidalia Project at</span>
<a name="l00006"></a>00006 <span class="comment">**  http://www.vidalia-project.net/. No part of Vidalia, including this file,</span>
<a name="l00007"></a>00007 <span class="comment">**  may be copied, modified, propagated, or distributed except according to the</span>
<a name="l00008"></a>00008 <span class="comment">**  terms described in the LICENSE file.</span>
<a name="l00009"></a>00009 <span class="comment">*/</span>
<a name="l00010"></a>00010 
<a name="l00011"></a>00011 <span class="preprocessor">#include &lt;QHash&gt;</span>
<a name="l00012"></a>00012 <span class="preprocessor">#include &lt;QFile&gt;</span>
<a name="l00013"></a>00013 <span class="preprocessor">#include &lt;QTextStream&gt;</span>
<a name="l00014"></a>00014 <span class="preprocessor">#include &lt;QTextCodec&gt;</span>
<a name="l00015"></a>00015 <span class="preprocessor">#include &lt;stdlib.h&gt;</span>
<a name="l00016"></a>00016 
<a name="l00017"></a>00017 <span class="comment"></span>
<a name="l00018"></a>00018 <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="l00019"></a>00019 <span class="comment"> * form DQUOTE ContextName DQUOTE. */</span>
<a name="l00020"></a>00020 QString
<a name="l00021"></a><a class="code" href="po2nsh_8cpp.html#a365f06fe0efd30b4822c6b74fb8a8312">00021</a> <a class="code" href="nsh2po_8cpp.html#a365f06fe0efd30b4822c6b74fb8a8312">parse_message_context</a>(<span class="keyword">const</span> QString &amp;str)
<a name="l00022"></a>00022 {
<a name="l00023"></a>00023   QString out = str.trimmed();
<a name="l00024"></a>00024   out = out.replace(<span class="stringliteral">&quot;\&quot;&quot;</span>, <span class="stringliteral">&quot;&quot;</span>);
<a name="l00025"></a>00025   <span class="keywordflow">return</span> out;
<a name="l00026"></a>00026 }
<a name="l00027"></a>00027 <span class="comment"></span>
<a name="l00028"></a>00028 <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="l00029"></a>00029 <span class="comment"> * form ContextName#Number. This is the format used by translate-toolkit. */</span>
<a name="l00030"></a>00030 QString
<a name="l00031"></a><a class="code" href="po2nsh_8cpp.html#a041f6703063a9673d913561962ddbc6c">00031</a> <a class="code" href="nsh2po_8cpp.html#a041f6703063a9673d913561962ddbc6c">parse_message_context_lame</a>(<span class="keyword">const</span> QString &amp;str)
<a name="l00032"></a>00032 {
<a name="l00033"></a>00033   <span class="keywordflow">if</span> (str.contains(<span class="stringliteral">&quot;#&quot;</span>))
<a name="l00034"></a>00034     <span class="keywordflow">return</span> str.section(<span class="stringliteral">&quot;#&quot;</span>, 0, 0);
<a name="l00035"></a>00035   <span class="keywordflow">return</span> QString();
<a name="l00036"></a>00036 }
<a name="l00037"></a>00037 <span class="comment"></span>
<a name="l00038"></a>00038 <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="l00039"></a>00039 <span class="comment"> * multiline string, the extra double quotes will be replaced with newlines</span>
<a name="l00040"></a>00040 <span class="comment"> * appropriately. */</span>
<a name="l00041"></a>00041 QString
<a name="l00042"></a><a class="code" href="po2nsh_8cpp.html#a2536f50f6d8ff0752b5fd134a7ef7082">00042</a> <a class="code" href="nsh2po_8cpp.html#a2536f50f6d8ff0752b5fd134a7ef7082">parse_message_string</a>(<span class="keyword">const</span> QString &amp;msg)
<a name="l00043"></a>00043 {
<a name="l00044"></a>00044   QString out = msg.trimmed(); 
<a name="l00045"></a>00045   
<a name="l00046"></a>00046   out.replace(<span class="stringliteral">&quot;\&quot;\n\&quot;&quot;</span>, <span class="stringliteral">&quot;&quot;</span>);
<a name="l00047"></a>00047   <span class="keywordflow">if</span> (out.startsWith(<span class="stringliteral">&quot;\&quot;&quot;</span>))
<a name="l00048"></a>00048     out = out.remove(0, 1);
<a name="l00049"></a>00049   <span class="keywordflow">if</span> (out.endsWith(<span class="stringliteral">&quot;\&quot;&quot;</span>))
<a name="l00050"></a>00050     out.chop(1);
<a name="l00051"></a>00051   out.replace(<span class="stringliteral">&quot;\\\&quot;&quot;</span>, <span class="stringliteral">&quot;\&quot;&quot;</span>);
<a name="l00052"></a>00052   out.replace(<span class="stringliteral">&quot;\\n&quot;</span>, <span class="stringliteral">&quot;\\r\\n&quot;</span>);
<a name="l00053"></a>00053   out.replace(<span class="stringliteral">&quot;$\\r\\n&quot;</span>, <span class="stringliteral">&quot;$\\r$\\n&quot;</span>);
<a name="l00054"></a>00054   <span class="keywordflow">return</span> out;
<a name="l00055"></a>00055 }
<a name="l00056"></a>00056 <span class="comment"></span>
<a name="l00057"></a>00057 <span class="comment">/** Read and return the next non-empty line from &lt;b&gt;stream&lt;/b&gt;. */</span>
<a name="l00058"></a>00058 QString
<a name="l00059"></a><a class="code" href="po2nsh_8cpp.html#a30bb52b8ae8ec480fb93b39710da3b45">00059</a> <a class="code" href="nsh2po_8cpp.html#a30bb52b8ae8ec480fb93b39710da3b45">read_next_line</a>(QTextStream *stream)
<a name="l00060"></a>00060 {
<a name="l00061"></a>00061   stream-&gt;skipWhiteSpace();
<a name="l00062"></a>00062   <span class="keywordflow">return</span> stream-&gt;readLine().append(<span class="stringliteral">&quot;\n&quot;</span>);
<a name="l00063"></a>00063 }
<a name="l00064"></a>00064 <span class="comment"></span>
<a name="l00065"></a>00065 <span class="comment">/** Skip past the header portion of the PO file and any leading whitespace. </span>
<a name="l00066"></a>00066 <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="l00067"></a>00067 <span class="comment"> * document. */</span>
<a name="l00068"></a>00068 <span class="keywordtype">void</span>
<a name="l00069"></a><a class="code" href="po2nsh_8cpp.html#a8c13543b77ece0e6dc9d0fe52b59e57d">00069</a> <a class="code" href="po2nsh_8cpp.html#a8c13543b77ece0e6dc9d0fe52b59e57d">skip_po_header</a>(QTextStream *po)
<a name="l00070"></a>00070 {
<a name="l00071"></a>00071   QString line;
<a name="l00072"></a>00072   <span class="comment">/* Skip any leading whitespace before the header */</span>
<a name="l00073"></a>00073   po-&gt;skipWhiteSpace();
<a name="l00074"></a>00074   <span class="comment">/* Read to the first empty line */</span>
<a name="l00075"></a>00075   line = po-&gt;readLine();
<a name="l00076"></a>00076   <span class="keywordflow">while</span> (!po-&gt;atEnd() &amp;&amp; !line.isEmpty())
<a name="l00077"></a>00077     line = po-&gt;readLine();
<a name="l00078"></a>00078 }
<a name="l00079"></a>00079 <span class="comment"></span>
<a name="l00080"></a>00080 <span class="comment">/** Convert &lt;b&gt;po&lt;/b&gt; from the PO format to a NSIS-formatted .nsh document.</span>
<a name="l00081"></a>00081 <span class="comment"> * &lt;b&gt;nsh&lt;/b&gt; will be set to the resulting .nsh document. Return the number of</span>
<a name="l00082"></a>00082 <span class="comment"> * converted strings on success, or -1 on error and &lt;b&gt;errorMessage&lt;/b&gt; will</span>
<a name="l00083"></a>00083 <span class="comment"> * be set. */</span>
<a name="l00084"></a>00084 <span class="keywordtype">int</span>
<a name="l00085"></a><a class="code" href="po2nsh_8cpp.html#a55320e7c95b3bea6021cd245c677f0ec">00085</a> <a class="code" href="po2nsh_8cpp.html#a55320e7c95b3bea6021cd245c677f0ec">po2nsh</a>(QTextStream *po, QString *nsh, <span class="keyword">const</span> QString &amp;language,
<a name="l00086"></a>00086       QString *errorMessage)
<a name="l00087"></a>00087 {
<a name="l00088"></a>00088   QString line;
<a name="l00089"></a>00089   QString msgctxt, msgid, msgstr;
<a name="l00090"></a>00090   QHash&lt;QString,QString&gt; header;
<a name="l00091"></a>00091   QTextCodec *codec;
<a name="l00092"></a>00092   <span class="keywordtype">int</span> n_strings = 0;
<a name="l00093"></a>00093   
<a name="l00094"></a>00094   Q_ASSERT(po);
<a name="l00095"></a>00095   Q_ASSERT(nsh);
<a name="l00096"></a>00096   Q_ASSERT(errorMessage);
<a name="l00097"></a>00097   
<a name="l00098"></a>00098   <a class="code" href="po2nsh_8cpp.html#a8c13543b77ece0e6dc9d0fe52b59e57d">skip_po_header</a>(po);
<a name="l00099"></a>00099   line = <a class="code" href="nsh2po_8cpp.html#a30bb52b8ae8ec480fb93b39710da3b45">read_next_line</a>(po);
<a name="l00100"></a>00100   <span class="keywordflow">while</span> (!po-&gt;atEnd()) {
<a name="l00101"></a>00101     <span class="comment">/* Ignore all &quot;#&quot; lines except &quot;#:&quot; */</span>
<a name="l00102"></a>00102     <span class="keywordflow">while</span> (line.startsWith(<span class="stringliteral">&quot;#&quot;</span>)) {
<a name="l00103"></a>00103       <span class="keywordflow">if</span> (line.startsWith(<span class="stringliteral">&quot;#:&quot;</span>)) {
<a name="l00104"></a>00104         <span class="comment">/* Context was specified with the stupid overloaded &quot;#:&quot; syntax.*/</span>
<a name="l00105"></a>00105         msgctxt = line.section(<span class="stringliteral">&quot; &quot;</span>, 1);
<a name="l00106"></a>00106         msgctxt = <a class="code" href="nsh2po_8cpp.html#a041f6703063a9673d913561962ddbc6c">parse_message_context_lame</a>(msgctxt);
<a name="l00107"></a>00107       }
<a name="l00108"></a>00108       line = <a class="code" href="nsh2po_8cpp.html#a30bb52b8ae8ec480fb93b39710da3b45">read_next_line</a>(po);
<a name="l00109"></a>00109     }
<a name="l00110"></a>00110 
<a name="l00111"></a>00111     <span class="comment">/* A context specified on a &quot;msgctxt&quot; line takes precedence over a context</span>
<a name="l00112"></a>00112 <span class="comment">     * specified using the overload &quot;#:&quot; notation. */</span>
<a name="l00113"></a>00113     <span class="keywordflow">if</span> (line.startsWith(<span class="stringliteral">&quot;msgctxt &quot;</span>)) {    
<a name="l00114"></a>00114       msgctxt = line.section(<span class="stringliteral">&quot; &quot;</span>, 1);
<a name="l00115"></a>00115       msgctxt = <a class="code" href="nsh2po_8cpp.html#a365f06fe0efd30b4822c6b74fb8a8312">parse_message_context</a>(msgctxt);
<a name="l00116"></a>00116       line = <a class="code" href="nsh2po_8cpp.html#a30bb52b8ae8ec480fb93b39710da3b45">read_next_line</a>(po);
<a name="l00117"></a>00117     }
<a name="l00118"></a>00118     
<a name="l00119"></a>00119     <span class="comment">/* Parse the (possibly multiline) message source string */</span>
<a name="l00120"></a>00120     <span class="keywordflow">if</span> (!line.startsWith(<span class="stringliteral">&quot;msgid &quot;</span>)) {
<a name="l00121"></a>00121       *errorMessage = <span class="stringliteral">&quot;expected &#39;msgid&#39; line&quot;</span>;
<a name="l00122"></a>00122       <span class="keywordflow">return</span> -1;
<a name="l00123"></a>00123     }
<a name="l00124"></a>00124     msgid = line.section(<span class="stringliteral">&quot; &quot;</span>, 1);
<a name="l00125"></a>00125     
<a name="l00126"></a>00126     line = <a class="code" href="nsh2po_8cpp.html#a30bb52b8ae8ec480fb93b39710da3b45">read_next_line</a>(po);
<a name="l00127"></a>00127     <span class="keywordflow">while</span> (line.startsWith(<span class="stringliteral">&quot;\&quot;&quot;</span>)) {
<a name="l00128"></a>00128       msgid.append(line);
<a name="l00129"></a>00129       line = <a class="code" href="nsh2po_8cpp.html#a30bb52b8ae8ec480fb93b39710da3b45">read_next_line</a>(po);
<a name="l00130"></a>00130     }
<a name="l00131"></a>00131     msgid = <a class="code" href="nsh2po_8cpp.html#a2536f50f6d8ff0752b5fd134a7ef7082">parse_message_string</a>(msgid);
<a name="l00132"></a>00132 
<a name="l00133"></a>00133     <span class="comment">/* Parse the (possibly multiline) translated string */</span>
<a name="l00134"></a>00134     <span class="keywordflow">if</span> (!line.startsWith(<span class="stringliteral">&quot;msgstr &quot;</span>)) {
<a name="l00135"></a>00135       *errorMessage = <span class="stringliteral">&quot;expected &#39;msgstr&#39; line&quot;</span>;
<a name="l00136"></a>00136       <span class="keywordflow">return</span> -1;
<a name="l00137"></a>00137     }
<a name="l00138"></a>00138     msgstr = line.section(<span class="stringliteral">&quot; &quot;</span>, 1);
<a name="l00139"></a>00139     
<a name="l00140"></a>00140     line = <a class="code" href="nsh2po_8cpp.html#a30bb52b8ae8ec480fb93b39710da3b45">read_next_line</a>(po);
<a name="l00141"></a>00141     <span class="keywordflow">while</span> (line.startsWith(<span class="stringliteral">&quot;\&quot;&quot;</span>)) {
<a name="l00142"></a>00142       msgstr.append(line);
<a name="l00143"></a>00143       line = <a class="code" href="nsh2po_8cpp.html#a30bb52b8ae8ec480fb93b39710da3b45">read_next_line</a>(po);
<a name="l00144"></a>00144     }
<a name="l00145"></a>00145     msgstr = <a class="code" href="nsh2po_8cpp.html#a2536f50f6d8ff0752b5fd134a7ef7082">parse_message_string</a>(msgstr);
<a name="l00146"></a>00146 
<a name="l00147"></a>00147     <span class="comment">/* Add the message translation to the .nsh document */</span>
<a name="l00148"></a>00148     nsh-&gt;append(QString(<span class="stringliteral">&quot;LangString &quot;</span>));
<a name="l00149"></a>00149     nsh-&gt;append(msgctxt);
<a name="l00150"></a>00150     nsh-&gt;append(QString(<span class="stringliteral">&quot; ${LANG_%1} &quot;</span>).arg(language));
<a name="l00151"></a>00151     <span class="keywordflow">if</span> (msgstr.isEmpty())
<a name="l00152"></a>00152       nsh-&gt;append(<span class="stringliteral">&quot;\&quot;&quot;</span> + msgid + <span class="stringliteral">&quot;\&quot;&quot;</span>);
<a name="l00153"></a>00153     <span class="keywordflow">else</span>
<a name="l00154"></a>00154       nsh-&gt;append(<span class="stringliteral">&quot;\&quot;&quot;</span> + msgstr + <span class="stringliteral">&quot;\&quot;&quot;</span>);
<a name="l00155"></a>00155     nsh-&gt;append(<span class="stringliteral">&quot;\n&quot;</span>);
<a name="l00156"></a>00156 
<a name="l00157"></a>00157     n_strings++;
<a name="l00158"></a>00158   }
<a name="l00159"></a>00159   <span class="keywordflow">return</span> n_strings;
<a name="l00160"></a>00160 }
<a name="l00161"></a>00161 <span class="comment"></span>
<a name="l00162"></a>00162 <span class="comment">/** Display application usage and exit. */</span>
<a name="l00163"></a>00163 <span class="keywordtype">void</span>
<a name="l00164"></a><a class="code" href="po2nsh_8cpp.html#a068e9e76bf4a101f996e30fd122df007">00164</a> <a class="code" href="nsh2po_8cpp.html#a068e9e76bf4a101f996e30fd122df007">print_usage_and_exit</a>()
<a name="l00165"></a>00165 {
<a name="l00166"></a>00166   QTextStream <a class="code" href="namespacetc.html#aa7353218fd7baef0876bbb422ce818af">error</a>(stderr);
<a name="l00167"></a>00167   error &lt;&lt; <span class="stringliteral">&quot;usage: po2nsh [-q] -i &lt;infile.po&gt; -o &lt;outfile.nsh&gt; &quot;</span>
<a name="l00168"></a>00168            <span class="stringliteral">&quot;-l &lt;language&gt; [-f &lt;from-encoding&gt;] [-t &lt;to-encoding&gt;]\n&quot;</span>;
<a name="l00169"></a>00169   error &lt;&lt; <span class="stringliteral">&quot;  -q (optional)      Quiet mode (errors are still displayed)\n&quot;</span>;
<a name="l00170"></a>00170   error &lt;&lt; <span class="stringliteral">&quot;  -i &lt;infile.po&gt;     Input .po file\n&quot;</span>;
<a name="l00171"></a>00171   error &lt;&lt; <span class="stringliteral">&quot;  -o &lt;outfile.nsh&gt;   Output .nsh file\n&quot;</span>;
<a name="l00172"></a>00172   error &lt;&lt; <span class="stringliteral">&quot;  -l &lt;language&gt;      NSIS language table name\n&quot;</span>;
<a name="l00173"></a>00173   error &lt;&lt; <span class="stringliteral">&quot;  -f &lt;from-encoding&gt; .po file encoding (default: utf-8)\n&quot;</span>;
<a name="l00174"></a>00174   error &lt;&lt; <span class="stringliteral">&quot;  -t &lt;to-encoding&gt;   .nsh file encoding (default: iso-8859-1)\n&quot;</span>;
<a name="l00175"></a>00175   error.flush();
<a name="l00176"></a>00176   exit(1);
<a name="l00177"></a>00177 }
<a name="l00178"></a>00178 
<a name="l00179"></a>00179 <span class="keywordtype">int</span>
<a name="l00180"></a><a class="code" href="po2nsh_8cpp.html#a0ddf1224851353fc92bfbff6f499fa97">00180</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="l00181"></a>00181 {
<a name="l00182"></a>00182   QTextStream <a class="code" href="namespacetc.html#aa7353218fd7baef0876bbb422ce818af">error</a>(stderr);
<a name="l00183"></a>00183   QString language, errorMessage;
<a name="l00184"></a>00184   <span class="keywordtype">char</span> *infile, *outfile;
<a name="l00185"></a>00185   <span class="keywordtype">bool</span> quiet = <span class="keyword">false</span>;
<a name="l00186"></a>00186   QTextCodec *from_codec = QTextCodec::codecForName(<span class="stringliteral">&quot;utf-8&quot;</span>);
<a name="l00187"></a>00187   QTextCodec *to_codec   = QTextCodec::codecForName(<span class="stringliteral">&quot;iso-8859-1&quot;</span>);
<a name="l00188"></a>00188   
<a name="l00189"></a>00189   <span class="comment">/* Check for the correct number of input parameters. */</span>
<a name="l00190"></a>00190   <span class="keywordflow">if</span> (argc &lt; 7 || argc &gt; 12)
<a name="l00191"></a>00191     <a class="code" href="nsh2po_8cpp.html#a068e9e76bf4a101f996e30fd122df007">print_usage_and_exit</a>();
<a name="l00192"></a>00192   <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="l00193"></a>00193     QString arg(argv[<a class="code" href="html_8cpp.html#a4a5dba6492ea149585950c59c210ff47">i</a>]);
<a name="l00194"></a>00194     <span class="keywordflow">if</span> (!arg.compare(<span class="stringliteral">&quot;-q&quot;</span>, Qt::CaseInsensitive))
<a name="l00195"></a>00195       quiet = <span class="keyword">true</span>;
<a name="l00196"></a>00196     <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="l00197"></a>00197       infile = argv[i];
<a name="l00198"></a>00198     <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="l00199"></a>00199       outfile = argv[i];
<a name="l00200"></a>00200     <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!arg.compare(<span class="stringliteral">&quot;-l&quot;</span>, Qt::CaseInsensitive) &amp;&amp; ++i &lt; argc)
<a name="l00201"></a>00201       language = QString(argv[i]).toUpper();
<a name="l00202"></a>00202     <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!arg.compare(<span class="stringliteral">&quot;-f&quot;</span>, Qt::CaseInsensitive) &amp;&amp; ++i &lt; argc) {
<a name="l00203"></a>00203       from_codec = QTextCodec::codecForName(argv[i]);
<a name="l00204"></a>00204       <span class="keywordflow">if</span> (!from_codec) {
<a name="l00205"></a>00205         error &lt;&lt; <span class="stringliteral">&quot;Invalid input encoding: &quot;</span> &lt;&lt; argv[i] &lt;&lt; <span class="stringliteral">&quot;\n&quot;</span>;
<a name="l00206"></a>00206         <span class="keywordflow">return</span> 1;
<a name="l00207"></a>00207       }
<a name="l00208"></a>00208     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!arg.compare(<span class="stringliteral">&quot;-t&quot;</span>, Qt::CaseInsensitive) &amp;&amp; ++i &lt; argc) {
<a name="l00209"></a>00209       to_codec = QTextCodec::codecForName(argv[i]);
<a name="l00210"></a>00210       <span class="keywordflow">if</span> (!to_codec) {
<a name="l00211"></a>00211         error &lt;&lt; <span class="stringliteral">&quot;Invalid output encoding: &quot;</span> &lt;&lt; argv[i] &lt;&lt; <span class="stringliteral">&quot;\n&quot;</span>;
<a name="l00212"></a>00212         <span class="keywordflow">return</span> 1;
<a name="l00213"></a>00213       }
<a name="l00214"></a>00214     } <span class="keywordflow">else</span>
<a name="l00215"></a>00215       <a class="code" href="nsh2po_8cpp.html#a068e9e76bf4a101f996e30fd122df007">print_usage_and_exit</a>(); 
<a name="l00216"></a>00216   }
<a name="l00217"></a>00217 
<a name="l00218"></a>00218   <span class="comment">/* Open the input PO file for reading. */</span>
<a name="l00219"></a>00219   QFile poFile(infile);
<a name="l00220"></a>00220   <span class="keywordflow">if</span> (!poFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
<a name="l00221"></a>00221     error &lt;&lt; QString(<span class="stringliteral">&quot;Unable to open &#39;%1&#39; for reading: %2\n&quot;</span>).arg(infile)
<a name="l00222"></a>00222                                                 .arg(poFile.errorString());
<a name="l00223"></a>00223     <span class="keywordflow">return</span> 2;
<a name="l00224"></a>00224   }
<a name="l00225"></a>00225 
<a name="l00226"></a>00226   QString nsh;
<a name="l00227"></a>00227   QTextStream po(&amp;poFile);
<a name="l00228"></a>00228   po.setCodec(from_codec);
<a name="l00229"></a>00229   <span class="keywordtype">int</span> n_strings = <a class="code" href="po2nsh_8cpp.html#a55320e7c95b3bea6021cd245c677f0ec">po2nsh</a>(&amp;po, &amp;nsh, language, &amp;errorMessage);
<a name="l00230"></a>00230   <span class="keywordflow">if</span> (n_strings &lt; 0) {
<a name="l00231"></a>00231     error &lt;&lt; QString(<span class="stringliteral">&quot;Unable to convert &#39;%1&#39;: %2\n&quot;</span>).arg(infile)
<a name="l00232"></a>00232                                                     .arg(errorMessage);
<a name="l00233"></a>00233     <span class="keywordflow">return</span> 3;
<a name="l00234"></a>00234   }
<a name="l00235"></a>00235   
<a name="l00236"></a>00236   <span class="comment">/* Open the NSH file for writing. */</span>
<a name="l00237"></a>00237   QFile nshFile(outfile);
<a name="l00238"></a>00238   <span class="keywordflow">if</span> (!nshFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
<a name="l00239"></a>00239     error &lt;&lt; QString(<span class="stringliteral">&quot;Unable to open &#39;%1&#39; for writing: %2\n&quot;</span>).arg(outfile)
<a name="l00240"></a>00240                                                 .arg(nshFile.errorString());
<a name="l00241"></a>00241     <span class="keywordflow">return</span> 4;
<a name="l00242"></a>00242   }
<a name="l00243"></a>00243 
<a name="l00244"></a>00244   <span class="comment">/* Finally write the .nsh output. */</span>
<a name="l00245"></a>00245   QTextStream out(&amp;nshFile);
<a name="l00246"></a>00246   out.setCodec(to_codec);
<a name="l00247"></a>00247   out &lt;&lt; nsh;
<a name="l00248"></a>00248 
<a name="l00249"></a>00249   <span class="keywordflow">if</span> (!quiet) {
<a name="l00250"></a>00250     QTextStream results(stdout);
<a name="l00251"></a>00251     results &lt;&lt; QString(<span class="stringliteral">&quot;Converted %1 strings from %2 to %3.\n&quot;</span>).arg(n_strings)
<a name="l00252"></a>00252                                                                .arg(infile)
<a name="l00253"></a>00253                                                                .arg(outfile);
<a name="l00254"></a>00254   }
<a name="l00255"></a>00255   <span class="keywordflow">return</span> 0;
<a name="l00256"></a>00256 }
<a name="l00257"></a>00257 
</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>