Sophie

Sophie

distrib > Mageia > 4 > x86_64 > by-pkgid > b293cf61b174f6cb974e48c9096dc9b3 > files > 435

lib64commoncpp-devel-1.8.1-7.mga4.x86_64.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"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.5"/>
<title>GNU CommonC++: cmdlineopt.cpp</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td style="padding-left: 0.5em;">
   <div id="projectname">GNU CommonC++
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.5 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;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><a href="files.html"><span>Files</span></a></li>
      <li><a href="examples.html"><span>Examples</span></a></li>
    </ul>
  </div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">cmdlineopt.cpp</div>  </div>
</div><!--header-->
<div class="contents">
<div class="fragment"><div class="line"><span class="comment">// Copyright (C) 2001 Gianni Mariani</span></div>
<div class="line"><span class="comment">//</span></div>
<div class="line"><span class="comment">// This program is free software; you can redistribute it and/or modify</span></div>
<div class="line"><span class="comment">// it under the terms of the GNU General Public License as published by</span></div>
<div class="line"><span class="comment">// the Free Software Foundation; either version 2 of the License, or</span></div>
<div class="line"><span class="comment">// (at your option) any later version.</span></div>
<div class="line"><span class="comment">//</span></div>
<div class="line"><span class="comment">// This program is distributed in the hope that it will be useful,</span></div>
<div class="line"><span class="comment">// but WITHOUT ANY WARRANTY; without even the implied warranty of</span></div>
<div class="line"><span class="comment">// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span></div>
<div class="line"><span class="comment">// GNU General Public License for more details.</span></div>
<div class="line"><span class="comment">//</span></div>
<div class="line"><span class="comment">// You should have received a copy of the GNU General Public License</span></div>
<div class="line"><span class="comment">// along with this program; if not, write to the Free Software</span></div>
<div class="line"><span class="comment">// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.</span></div>
<div class="line"><span class="comment">//</span></div>
<div class="line"><span class="comment">// As a special exception to the GNU General Public License, permission is</span></div>
<div class="line"><span class="comment">// granted for additional uses of the text contained in its release</span></div>
<div class="line"><span class="comment">// of Common C++.</span></div>
<div class="line"><span class="comment">//</span></div>
<div class="line"><span class="comment">// The exception is that, if you link the Common C++ library with other</span></div>
<div class="line"><span class="comment">// files to produce an executable, this does not by itself cause the</span></div>
<div class="line"><span class="comment">// resulting executable to be covered by the GNU General Public License.</span></div>
<div class="line"><span class="comment">// Your use of that executable is in no way restricted on account of</span></div>
<div class="line"><span class="comment">// linking the Common C++ library code into it.</span></div>
<div class="line"><span class="comment">//</span></div>
<div class="line"><span class="comment">// This exception does not however invalidate any other reasons why</span></div>
<div class="line"><span class="comment">// the executable file might be covered by the GNU General Public License.</span></div>
<div class="line"><span class="comment">//</span></div>
<div class="line"><span class="comment">// This exception applies only to the code released under the</span></div>
<div class="line"><span class="comment">// name Common C++.  If you copy code from other releases into a copy of</span></div>
<div class="line"><span class="comment">// Common C++, as the General Public License permits, the exception does</span></div>
<div class="line"><span class="comment">// not apply to the code that you add in this way.  To avoid misleading</span></div>
<div class="line"><span class="comment">// anyone as to the status of such modified files, you must delete</span></div>
<div class="line"><span class="comment">// this exception notice from them.</span></div>
<div class="line"><span class="comment">//</span></div>
<div class="line"><span class="comment">// If you write modifications of your own for Common C++, it is your choice</span></div>
<div class="line"><span class="comment">// whether to permit this exception to apply to your modifications.</span></div>
<div class="line"><span class="comment">// If you do not wish that, delete this exception notice.</span></div>
<div class="line"><span class="comment">//</span></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"><span class="comment">//</span></div>
<div class="line"><span class="comment">// Example for Common C++ the command line parser interface.</span></div>
<div class="line"><span class="comment">//</span></div>
<div class="line"><span class="comment">//</span></div>
<div class="line"><span class="comment">// This exmaple code shows how to use the command line parser provided by</span></div>
<div class="line"><span class="comment">// CommonC++.  The command line parser provides an interface which is</span></div>
<div class="line"><span class="comment">// &quot;object oriented&quot; such that command line parameters are true &quot;objects&quot;.</span></div>
<div class="line"><span class="comment">//</span></div>
<div class="line"><span class="comment">// Each command line option needs to be created.  By defining &quot;CommandOption&quot;s</span></div>
<div class="line"><span class="comment">// statically, the C++ constructor is called when the objects are loaded and</span></div>
<div class="line"><span class="comment">// before the &quot;main&quot; function is called.  The constructor links itself to</span></div>
<div class="line"><span class="comment">// a list of other CommandOptionXXX in the list provided.  If no</span></div>
<div class="line"><span class="comment">// list is specified in the constructor, a default one is used. Because of</span></div>
<div class="line"><span class="comment">// the undefined nature as to the order in which constructors are called,</span></div>
<div class="line"><span class="comment">// no assumption as to the order in which the CommandOptionXXX constructors</span></div>
<div class="line"><span class="comment">// are called should be made.</span></div>
<div class="line"><span class="comment">//</span></div>
<div class="line"><span class="comment">// CommandOptionXXX classes can be used to derive specialized parameter</span></div>
<div class="line"><span class="comment">// classes that are specific to applications.  The second example shows</span></div>
<div class="line"><span class="comment">// just how this can be done.</span></div>
<div class="line"><span class="comment">//</span></div>
<div class="line"></div>
<div class="line"><span class="comment">//</span></div>
<div class="line"><span class="comment">// Include the CommandOption definitions</span></div>
<div class="line"><span class="comment">//</span></div>
<div class="line"><span class="preprocessor">#include &lt;<a class="code" href="common_8h.html">cc++/common.h</a>&gt;</span></div>
<div class="line"></div>
<div class="line"><span class="preprocessor">#include &lt;iostream&gt;</span></div>
<div class="line"><span class="preprocessor">#ifndef WIN32</span></div>
<div class="line"><span class="preprocessor"></span><span class="preprocessor">#include &lt;cstdlib&gt;</span></div>
<div class="line"><span class="preprocessor">#endif</span></div>
<div class="line"><span class="preprocessor"></span></div>
<div class="line"><span class="preprocessor">#ifdef  CCXX_NAMESPACES</span></div>
<div class="line"><span class="preprocessor"></span><span class="keyword">using namespace </span>std;</div>
<div class="line"><span class="keyword">using namespace </span>ost;</div>
<div class="line"><span class="preprocessor">#endif</span></div>
<div class="line"><span class="preprocessor"></span></div>
<div class="line"><span class="comment">//</span></div>
<div class="line"><span class="comment">// The following definition of options all use the list header</span></div>
<div class="line"><span class="comment">// defaultCommandOptionList (which is specified as the value of the</span></div>
<div class="line"><span class="comment">// default parameter in the constructor.  This convention would</span></div>
<div class="line"><span class="comment">// allow other object files to link into the same list and add parameters</span></div>
<div class="line"><span class="comment">// to the command line of this executable.</span></div>
<div class="line"></div>
<div class="line"><a name="_a0"></a><a class="code" href="classost_1_1_command_option_arg.html">CommandOptionArg</a>        test_option1(</div>
<div class="line">        <span class="stringliteral">&quot;test_option1&quot;</span>, <span class="stringliteral">&quot;p&quot;</span>, <span class="stringliteral">&quot;This option takes an argument&quot;</span>, <span class="keyword">true</span></div>
<div class="line">);</div>
<div class="line"></div>
<div class="line"><a name="_a1"></a><a class="code" href="classost_1_1_command_option_no_arg.html">CommandOptionNoArg</a>      test_noarg(</div>
<div class="line">        <span class="stringliteral">&quot;test_noarg&quot;</span>, <span class="stringliteral">&quot;b&quot;</span>, <span class="stringliteral">&quot;This option does not take an argument&quot;</span></div>
<div class="line">);</div>
<div class="line"></div>
<div class="line"><a class="code" href="classost_1_1_command_option_no_arg.html">CommandOptionNoArg</a>      helparg(</div>
<div class="line">        <span class="stringliteral">&quot;help&quot;</span>, <span class="stringliteral">&quot;?&quot;</span>, <span class="stringliteral">&quot;Print help usage&quot;</span></div>
<div class="line">);</div>
<div class="line"></div>
<div class="line"><a name="_a2"></a><a class="code" href="classost_1_1_command_option_collect.html">CommandOptionCollect</a>    restoargs(</div>
<div class="line">        0, 0, <span class="stringliteral">&quot;Collect all the parameters&quot;</span>, <span class="keyword">true</span></div>
<div class="line">);</div>
<div class="line"></div>
<div class="line"></div>
<div class="line"><span class="comment">//</span></div>
<div class="line"><span class="comment">// Normally this would me the regular main().  In this example</span></div>
<div class="line"><span class="comment">// this processes the first command option list.</span></div>
<div class="line"><span class="comment">//</span></div>
<div class="line"><span class="keywordtype">int</span> Example_main( <span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> ** argv )</div>
<div class="line">{</div>
<div class="line"></div>
<div class="line">        <span class="comment">// Create a CommandOptionParse object.  This takes the</span></div>
<div class="line">        <span class="comment">// defaultCommandOptionList and parses the command line arguments.</span></div>
<div class="line">        <span class="comment">//</span></div>
<div class="line">        <a name="_a3"></a><a class="code" href="classost_1_1_command_option_parse.html">CommandOptionParse</a> * args = <a name="a4"></a><a class="code" href="namespaceost.html#a282d97c4c4323467d6e8b82cb93ec89d">makeCommandOptionParse</a>(</div>
<div class="line">                argc, argv,</div>
<div class="line">                <span class="stringliteral">&quot;CommonC++ command like option interface.  This is example\n&quot;</span></div>
<div class="line">                <span class="stringliteral">&quot;       code only.&quot;</span></div>
<div class="line">        );</div>
<div class="line"></div>
<div class="line">        <span class="comment">// If the user requested help then suppress all the usage error</span></div>
<div class="line">        <span class="comment">// messages.</span></div>
<div class="line">        <span class="keywordflow">if</span> ( helparg.numSet ) {</div>
<div class="line">                cerr &lt;&lt; args-&gt;<a name="a5"></a><a class="code" href="classost_1_1_command_option_parse.html#a7dc375ddeff083528d143a1ffdb67e16">printUsage</a>();</div>
<div class="line">                ::exit(0);</div>
<div class="line">        }</div>
<div class="line"></div>
<div class="line">        <span class="comment">// Print usage your way.</span></div>
<div class="line">        <span class="keywordflow">if</span> ( args-&gt;<a name="a6"></a><a class="code" href="classost_1_1_command_option_parse.html#af8f0828a668ba000ea6ecc4de1d2c5b3">argsHaveError</a>() ) {</div>
<div class="line">                cerr &lt;&lt; args-&gt;<a name="a7"></a><a class="code" href="classost_1_1_command_option_parse.html#af2176dfc5ec12e3b4fb9f39334f5173a">printErrors</a>();</div>
<div class="line">                cerr &lt;&lt; args-&gt;<a class="code" href="classost_1_1_command_option_parse.html#a7dc375ddeff083528d143a1ffdb67e16">printUsage</a>();</div>
<div class="line">                ::exit(1);</div>
<div class="line">        }</div>
<div class="line"></div>
<div class="line">        <span class="comment">// Go off and run any option specific task</span></div>
<div class="line">        args-&gt;<a name="a8"></a><a class="code" href="classost_1_1_command_option_parse.html#a060afd8cbb6e8395191cef1cb68520ea">performTask</a>();</div>
<div class="line"></div>
<div class="line">        <span class="comment">// print all the -p options</span></div>
<div class="line">        <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0; i &lt; test_option1.numValue; i ++ ) {</div>
<div class="line">                cerr &lt;&lt; <span class="stringliteral">&quot;test_option1 = &quot;</span> &lt;&lt; test_option1.values[ i ] &lt;&lt; endl;</div>
<div class="line">        }</div>
<div class="line"></div>
<div class="line">        <span class="comment">// print all the other options.</span></div>
<div class="line">        <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0; i &lt; restoargs.numValue; i ++ ) {</div>
<div class="line">                cerr &lt;&lt; <span class="stringliteral">&quot;restoargs &quot;</span> &lt;&lt; i &lt;&lt; <span class="stringliteral">&quot; : &quot;</span> &lt;&lt; restoargs.values[ i ] &lt;&lt; endl;</div>
<div class="line">        }</div>
<div class="line"></div>
<div class="line">        <span class="keyword">delete</span> args;</div>
<div class="line"></div>
<div class="line">        <span class="keywordflow">return</span> 0;</div>
<div class="line">}</div>
<div class="line"></div>
<div class="line"></div>
<div class="line"><span class="comment">//</span></div>
<div class="line"><span class="comment">// This shows how to build a second option list.  The example is similar to</span></div>
<div class="line"><span class="comment">// the first as well as it shows how to derive a new command object.</span></div>
<div class="line"><span class="comment">//</span></div>
<div class="line"></div>
<div class="line"><a name="_a9"></a><a class="code" href="classost_1_1_command_option.html">CommandOption</a> * TestList = 0;</div>
<div class="line"></div>
<div class="line"><span class="keyword">extern</span> <a name="_a10"></a><a class="code" href="classost_1_1_command_option_rest.html">CommandOptionRest</a>        test_restoargs;</div>
<div class="line"></div>
<div class="line"><span class="preprocessor">#include &lt;unistd.h&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;sys/types.h&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;sys/stat.h&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;fcntl.h&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;errno.h&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;<a class="code" href="string_8h.html">string.h</a>&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;stdlib.h&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;sys/wait.h&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;strstream&gt;</span></div>
<div class="line"></div>
<div class="line"><span class="comment">//</span></div>
<div class="line"><span class="comment">// This is a parameter class derived from CommandOptionArg that takes</span></div>
<div class="line"><span class="comment">// a file name parameter and detects wether the file is accessible</span></div>
<div class="line"><span class="comment">// flagging an error if the file is inaccessible to read.</span></div>
<div class="line"><span class="comment">//</span></div>
<div class="line"><span class="keyword">class </span>file_option : <span class="keyword">public</span> <a class="code" href="classost_1_1_command_option_arg.html">CommandOptionArg</a> {</div>
<div class="line"><span class="keyword">public</span>:</div>
<div class="line"></div>
<div class="line">        <span class="comment">// the constructor calls the regular CommandOptionArg constructor</span></div>
<div class="line">        <span class="comment">// and all should be well.</span></div>
<div class="line">        file_option(</div>
<div class="line">                <span class="keyword">const</span> <span class="keywordtype">char</span>      * in_option_name,</div>
<div class="line">                <span class="keyword">const</span> <span class="keywordtype">char</span>      * in_option_letter,</div>
<div class="line">                <span class="keyword">const</span> <span class="keywordtype">char</span>      * in_description,</div>
<div class="line">                <span class="keywordtype">bool</span>              in_required = <span class="keyword">false</span>,</div>
<div class="line">                <a class="code" href="classost_1_1_command_option.html">CommandOption</a>  ** pp_next = &amp; <a name="a11"></a><a class="code" href="namespaceost.html#a3b701311bbf7cf16f954820e316f5766">defaultCommandOptionList</a></div>
<div class="line">        )</div>
<div class="line">                : <a class="code" href="classost_1_1_command_option_arg.html">CommandOptionArg</a>(</div>
<div class="line">                        in_option_name,</div>
<div class="line">                        in_option_letter,</div>
<div class="line">                        in_description,</div>
<div class="line">                        in_required,</div>
<div class="line">                        pp_next</div>
<div class="line">                )</div>
<div class="line">        {</div>
<div class="line">        }</div>
<div class="line"></div>
<div class="line">        <span class="comment">//</span></div>
<div class="line">        <span class="comment">// When parsing is done check if the file is accessible and register</span></div>
<div class="line">        <span class="comment">// an error with the CommandOptionParse object to let it know so.</span></div>
<div class="line">        <span class="keyword">virtual</span> <span class="keywordtype">void</span> parseDone( <a class="code" href="classost_1_1_command_option_parse.html">CommandOptionParse</a> * cop ) {</div>
<div class="line">                <span class="keywordflow">if</span> ( numValue ) {</div>
<div class="line">                        <span class="keywordflow">if</span> ( ::access( values[ numValue - 1 ], R_OK ) ) {</div>
<div class="line">                                <span class="keywordtype">int</span>     errno_s = errno;</div>
<div class="line">                                strstream msg;</div>
<div class="line">                                msg &lt;&lt; <span class="stringliteral">&quot;Error: &quot;</span> &lt;&lt; optionName &lt;&lt; <span class="stringliteral">&quot; &#39;&quot;</span> &lt;&lt; values[ numValue - 1 ];</div>
<div class="line">                                msg &lt;&lt; <span class="stringliteral">&quot;&#39; : &quot;</span> &lt;&lt; ::strerror( errno_s );</div>
<div class="line"></div>
<div class="line">                                cop-&gt;<a name="a12"></a><a class="code" href="classost_1_1_command_option_parse.html#a1ca17c61a4e4c8f40102cfafed61702a">registerError</a>( msg.str() );</div>
<div class="line">                        }</div>
<div class="line">                }</div>
<div class="line">        }</div>
<div class="line"></div>
<div class="line">        <span class="comment">//</span></div>
<div class="line">        <span class="comment">// Open said file.  Do some operations on things - like open the file.</span></div>
<div class="line">        <span class="keywordtype">int</span> OpenFile() {</div>
<div class="line">                <span class="comment">// Should put in way more error handling here ...</span></div>
<div class="line">                return ::open( values[ numValue - 1 ], O_RDONLY );</div>
<div class="line">        }</div>
<div class="line"></div>
<div class="line">        <span class="comment">//</span></div>
<div class="line">        <span class="comment">// The most elaborate way to spit the contents of a file</span></div>
<div class="line">        <span class="comment">// to standard output.</span></div>
<div class="line">        pid_t   pid;</div>
<div class="line">        <span class="keyword">virtual</span> <span class="keywordtype">void</span> performTask( <a class="code" href="classost_1_1_command_option_parse.html">CommandOptionParse</a> * cop ) {</div>
<div class="line">                pid = ::fork();</div>
<div class="line"></div>
<div class="line">                <span class="keywordflow">if</span> ( pid ) {</div>
<div class="line">                        <span class="keywordflow">return</span>;</div>
<div class="line">                }</div>
<div class="line"></div>
<div class="line">                <span class="keywordtype">int</span> fd = OpenFile();</div>
<div class="line">                <span class="keywordflow">if</span> ( fd &lt; 0 ) {</div>
<div class="line">                        <span class="keywordtype">int</span> errno_s = errno;</div>
<div class="line">                        cerr</div>
<div class="line">                                &lt;&lt; <span class="stringliteral">&quot;Error:  &#39;&quot;</span></div>
<div class="line">                                &lt;&lt; values[ numValue - 1 ]</div>
<div class="line">                                &lt;&lt; <span class="stringliteral">&quot;&#39; : &quot;</span></div>
<div class="line">                                &lt;&lt; ::strerror( errno_s )</div>
<div class="line">                        ;</div>
<div class="line"></div>
<div class="line">                        ::exit( 1 );</div>
<div class="line">                }</div>
<div class="line">                dup2(fd, 0);</div>
<div class="line">                ::execvp( test_restoargs.values[0], (<span class="keywordtype">char</span>**) test_restoargs.values );</div>
<div class="line">                ::exit(1);</div>
<div class="line">        }</div>
<div class="line"></div>
<div class="line">        ~file_option() {</div>
<div class="line">                <span class="keywordflow">if</span> ( pid &lt;= 0 ) <span class="keywordflow">return</span>;</div>
<div class="line">                <span class="keywordtype">int</span> status;</div>
<div class="line">                <a name="a13"></a><a class="code" href="namespaceost.html#a24c7774639b3768bdd45b65a296f6369">::wait</a>(&amp;status);</div>
<div class="line">        }</div>
<div class="line">};</div>
<div class="line"></div>
<div class="line"></div>
<div class="line"><span class="comment">//</span></div>
<div class="line"><span class="comment">// This is the linked list head for the options in the second example.</span></div>
<div class="line"><span class="comment">// Note that the first example used the default value defined in the</span></div>
<div class="line"><span class="comment">// method.  Here it is explicitly specified as TestList in all the following</span></div>
<div class="line"><span class="comment">// CommandOption constructors.</span></div>
<div class="line"></div>
<div class="line">file_option     test_file(</div>
<div class="line">        <span class="stringliteral">&quot;test_file&quot;</span>, <span class="stringliteral">&quot;f&quot;</span>, <span class="stringliteral">&quot;Filename to read from&quot;</span>, <span class="keyword">true</span>, &amp;TestList</div>
<div class="line">);</div>
<div class="line"></div>
<div class="line"><a class="code" href="classost_1_1_command_option_no_arg.html">CommandOptionNoArg</a>      test_xnoarg(</div>
<div class="line">        <span class="stringliteral">&quot;test_xnoarg&quot;</span>, <span class="stringliteral">&quot;b&quot;</span>, <span class="stringliteral">&quot;This option does not take an argument&quot;</span>, <span class="keyword">false</span>, &amp;TestList</div>
<div class="line">);</div>
<div class="line"></div>
<div class="line"><a class="code" href="classost_1_1_command_option_no_arg.html">CommandOptionNoArg</a>      test_helparg(</div>
<div class="line">        <span class="stringliteral">&quot;help&quot;</span>, <span class="stringliteral">&quot;?&quot;</span>, <span class="stringliteral">&quot;Print help usage&quot;</span>, <span class="keyword">false</span>, &amp;TestList</div>
<div class="line">);</div>
<div class="line"></div>
<div class="line"><a class="code" href="classost_1_1_command_option_rest.html">CommandOptionRest</a>       test_restoargs(</div>
<div class="line">        0, 0, <span class="stringliteral">&quot;Command to be executed&quot;</span>, <span class="keyword">true</span>, &amp;TestList</div>
<div class="line">);</div>
<div class="line"></div>
<div class="line"><span class="comment">//</span></div>
<div class="line"><span class="comment">// in most apps this would be the regular &quot;main&quot; function.</span></div>
<div class="line"><span class="keywordtype">int</span> Test_main( <span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> ** argv )</div>
<div class="line">{</div>
<div class="line">        <a class="code" href="classost_1_1_command_option_parse.html">CommandOptionParse</a> * args = <a class="code" href="namespaceost.html#a282d97c4c4323467d6e8b82cb93ec89d">makeCommandOptionParse</a>(</div>
<div class="line">                argc, argv,</div>
<div class="line">                <span class="stringliteral">&quot;Command line parser X test.\n&quot;</span></div>
<div class="line">                <span class="stringliteral">&quot;       This example is executed when the command ends in &#39;x&#39;\n&quot;</span></div>
<div class="line">                <span class="stringliteral">&quot;       It shows how the -f parameter can be specialized.\n&quot;</span>,</div>
<div class="line">                TestList</div>
<div class="line">        );</div>
<div class="line"></div>
<div class="line">        <span class="comment">// If the user requested help then suppress all the usage error</span></div>
<div class="line">        <span class="comment">// messages.</span></div>
<div class="line">        <span class="keywordflow">if</span> ( test_helparg.numSet ) {</div>
<div class="line">                cerr &lt;&lt; args-&gt;<a class="code" href="classost_1_1_command_option_parse.html#a7dc375ddeff083528d143a1ffdb67e16">printUsage</a>();</div>
<div class="line">                ::exit(0);</div>
<div class="line">        }</div>
<div class="line"></div>
<div class="line">        <span class="comment">// Print usage your way.</span></div>
<div class="line">        <span class="keywordflow">if</span> ( args-&gt;<a class="code" href="classost_1_1_command_option_parse.html#af8f0828a668ba000ea6ecc4de1d2c5b3">argsHaveError</a>() ) {</div>
<div class="line">                cerr &lt;&lt; args-&gt;<a class="code" href="classost_1_1_command_option_parse.html#af2176dfc5ec12e3b4fb9f39334f5173a">printErrors</a>();</div>
<div class="line">                cerr &lt;&lt; <span class="stringliteral">&quot;Get help by --help\n&quot;</span>;</div>
<div class="line">                ::exit(1);</div>
<div class="line">        }</div>
<div class="line"></div>
<div class="line">        <span class="comment">// Go off and run any option specific task</span></div>
<div class="line">        args-&gt;<a class="code" href="classost_1_1_command_option_parse.html#a060afd8cbb6e8395191cef1cb68520ea">performTask</a>();</div>
<div class="line"></div>
<div class="line">        <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0; i &lt; test_file.numValue; i ++ ) {</div>
<div class="line">                cerr &lt;&lt; <span class="stringliteral">&quot;test_file = &quot;</span> &lt;&lt; test_file.values[ i ] &lt;&lt; endl;</div>
<div class="line">        }</div>
<div class="line"></div>
<div class="line">        <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0; i &lt; test_restoargs.numValue; i ++ ) {</div>
<div class="line">                cerr &lt;&lt; <span class="stringliteral">&quot;test_restoargs &quot;</span> &lt;&lt; i &lt;&lt; <span class="stringliteral">&quot; : &quot;</span> &lt;&lt; test_restoargs.values[ i ] &lt;&lt; endl;</div>
<div class="line">        }</div>
<div class="line"></div>
<div class="line">        <span class="keyword">delete</span> args;</div>
<div class="line"></div>
<div class="line">        <span class="keywordflow">return</span> 0;</div>
<div class="line">}</div>
<div class="line"></div>
<div class="line"></div>
<div class="line"><span class="comment">//</span></div>
<div class="line"><span class="comment">// This switches behaviour of this executable depending of wether it is</span></div>
<div class="line"><span class="comment">// invoked with a command ending in &quot;x&quot;.  This is mimicking for example</span></div>
<div class="line"><span class="comment">// the behaviour of bunzip2 and bzip2.  These executables are THE SAME</span></div>
<div class="line"><span class="comment">// file i.e.</span></div>
<div class="line"><span class="comment">//   0 lrwxrwxrwx    1 root     root    5 Oct 11 14:04 /usr/bin/bunzip2 -&gt; bzip2*</span></div>
<div class="line"><span class="comment">// and the behaviour is determined by the executable name.</span></div>
<div class="line"><span class="comment">//</span></div>
<div class="line"><span class="comment">// This example is way more complex than the way most people will end up</span></div>
<div class="line"><span class="comment">// using feature.</span></div>
<div class="line"></div>
<div class="line"><span class="keywordtype">int</span> main( <span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> ** argv )</div>
<div class="line">{</div>
<div class="line"></div>
<div class="line">        <span class="keywordtype">int</span> i = ::strlen( argv[ 0 ] );</div>
<div class="line"></div>
<div class="line">        <span class="comment">// determine which real &quot;main&quot; function do I call</span></div>
<div class="line">        <span class="keywordflow">if</span> ( argv[ 0 ][ i - 1 ] == <span class="charliteral">&#39;x&#39;</span> ) {</div>
<div class="line">                <span class="keywordflow">return</span> Test_main( argc, argv );</div>
<div class="line">        } <span class="keywordflow">else</span> {</div>
<div class="line">                <span class="keywordflow">return</span> Example_main( argc, argv );</div>
<div class="line">        }</div>
<div class="line"></div>
<div class="line">}</div>
</div><!-- fragment --> </div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Thu Oct 17 2013 23:24:56 for GNU CommonC++ by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.5
</small></address>
</body>
</html>