Sophie

Sophie

distrib > Mandriva > 2010.2 > i586 > media > contrib-backports > by-pkgid > 4f5f2dc0f55b453456458df885792b0b > files > 9

ucommon-doc-5.0.4-1mdv2010.2.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>ucommon: shell.cpp</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="main.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Data&nbsp;Structures</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li><a href="examples.html"><span>Examples</span></a></li>
    </ul>
  </div>
</div>
<div class="contents">
<h1>shell.cpp</h1><p>Example of shell parsing.</p>
<div class="fragment"><pre class="fragment"><span class="comment">// Copyright (C) 2009-2010 David Sugar, Tycho Softworks.</span>
<span class="comment">//</span>
<span class="comment">// This file is part of GNU uCommon C++.</span>
<span class="comment">//</span>
<span class="comment">// GNU uCommon C++ is free software: you can redistribute it and/or modify</span>
<span class="comment">// it under the terms of the GNU Lesser General Public License as published</span>
<span class="comment">// by the Free Software Foundation, either version 3 of the License, or</span>
<span class="comment">// (at your option) any later version.</span>
<span class="comment">//</span>
<span class="comment">// GNU uCommon C++ is distributed in the hope that it will be useful,</span>
<span class="comment">// but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="comment">// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
<span class="comment">// GNU Lesser General Public License for more details.</span>
<span class="comment">//</span>
<span class="comment">// You should have received a copy of the GNU Lesser General Public License</span>
<span class="comment">// along with GNU uCommon C++.  If not, see &lt;http://www.gnu.org/licenses/&gt;.</span>

<span class="preprocessor">#ifndef DEBUG</span>
<span class="preprocessor"></span><span class="preprocessor">#define DEBUG</span>
<span class="preprocessor"></span><span class="preprocessor">#endif</span>
<span class="preprocessor"></span>
<span class="preprocessor">#include &lt;<a class="code" href="a00204.html" title="Top level include file for the GNU uCommon C++ core library.">ucommon/ucommon.h</a>&gt;</span>

<span class="preprocessor">#include &lt;stdio.h&gt;</span>

<span class="keyword">using namespace </span>UCOMMON_NAMESPACE;

<span class="keyword">extern</span> <span class="stringliteral">&quot;C&quot;</span> <span class="keywordtype">int</span> main()
{
    <span class="keywordtype">int</span> test_argc;
    <span class="keywordtype">char</span> *test_argv[6];

    shell::bind(<span class="stringliteral">&quot;test&quot;</span>);

    test_argc = 5;
    test_argv[0] = (<span class="keywordtype">char</span> *)<span class="stringliteral">&quot;test&quot;</span>;

    test_argv[1] = (<span class="keywordtype">char</span> *)<span class="stringliteral">&quot;--lines=5&quot;</span>;
    test_argv[2] = (<span class="keywordtype">char</span> *)<span class="stringliteral">&quot;-r&quot;</span>;
    test_argv[3] = (<span class="keywordtype">char</span> *)<span class="stringliteral">&quot;a&quot;</span>;
    test_argv[4] = (<span class="keywordtype">char</span> *)<span class="stringliteral">&quot;b&quot;</span>;
    test_argv[5] = NULL;

    shell::flagopt rflag(<span class="charliteral">&#39;r&#39;</span>, <span class="stringliteral">&quot;--reverse&quot;</span>, <span class="stringliteral">&quot;reverse order of arguments&quot;</span>);
    shell::flagopt tflag(<span class="charliteral">&#39;t&#39;</span>, <span class="stringliteral">&quot;--testing&quot;</span>, <span class="stringliteral">&quot;never hit this flag&quot;</span>);
    shell::numericopt lines(<span class="charliteral">&#39;l&#39;</span>, <span class="stringliteral">&quot;--lines&quot;</span>, <span class="stringliteral">&quot;number of lines in output&quot;</span>);
    shell args(test_argc, test_argv);

    assert(!tflag);
    assert(<a name="a0"></a><a class="code" href="a00208.html#acf24ef988438eb342a8a348f19524e37" title="Convenience function to validate object assuming it is castable to bool.">is</a>(rflag));
    assert(*lines == 5);
    assert(args() == 2);            <span class="comment">// two file arguments left</span>
    assert(<a name="a1"></a><a class="code" href="a00208.html#affb4ebc34459cfbe1d2965c178e52ee9" title="Compare two socket addresses to see if equal.">eq</a>(args[0], <span class="stringliteral">&quot;a&quot;</span>));       <span class="comment">// first file argument is &quot;a&quot;</span>

    <a name="a2"></a><a class="code" href="a00208.html#a111b48f4bb3203a18bab710b093ac628" title="A convenience type for string.">string_t</a> prefix, subdir, basedir;

    prefix = shell::path(shell::SYSTEM_PREFIX);
    subdir = shell::path(shell::SYSTEM_PREFIX, <span class="stringliteral">&quot;test&quot;</span>);
    basedir = shell::path(shell::SYSTEM_PREFIX, <span class="stringliteral">&quot;/test&quot;</span>);

    prefix = prefix + <span class="stringliteral">&quot;/test&quot;</span>;

    assert(<a class="code" href="a00208.html#affb4ebc34459cfbe1d2965c178e52ee9" title="Compare two socket addresses to see if equal.">eq</a>(basedir, <span class="stringliteral">&quot;/test&quot;</span>));
    assert(<a class="code" href="a00208.html#affb4ebc34459cfbe1d2965c178e52ee9" title="Compare two socket addresses to see if equal.">eq</a>(subdir, prefix));
}
</pre></div> </div>
<hr class="footer"/><address style="text-align: right;"><small>Generated on Thu Jul 14 16:38:56 2011 for ucommon 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>