"Fossies" - the Fresh Open Source Software Archive

Member "htmlrecode-1.3.1/argh/README.html" (21 Jul 2009, 13051 Bytes) of package /linux/www/old/htmlrecode-1.3.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) HTML source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

A hint: This file contains one or more very long lines, so maybe it is better readable using the pure text view mode that shows the contents as wrapped lines within the browser window.


    1 <html><head><meta http-equiv="Content-type" content="text/html; charset=iso-8859-1">
    2  <title>Command line argument handling library</title>
    3  <style type="text/css"><!--
    4 TABLE.toc {border:0px}
    5 A:link,A:visited{text-decoration:none;color:#2A3B83}
    6 A:hover{text-decoration:underline;color:#002040}
    7 A:active{text-decoration:underline;color:#004060;background:#CCD8FF}
    8 TD.toc   {font-size:80%; font-family:Tahoma; text-align:left}
    9 H1       {font-size:250%; font-weight:bold} .level1 {text-align:center}
   10 H2       {font-size:200%; font-weight:bold} .level2 {margin-left:1%}
   11 H3       {font-size:160%; font-weight:bold} .level3 {margin-left:2%}
   12 H4       {font-size:145%; font-weight:bold} .level4 {margin-left:3%}
   13 H5       {font-size:130%; font-weight:bold} .level5 {margin-left:4%}
   14 H6       {font-size:110%; font-weight:bold} .level5 {margin-left:5%}
   15 BODY{background:white;color:black}
   16 CODE{font-family:lucida console,courier new,courier;color:#105000}
   17 PRE.smallerpre{font-family:lucida console,courier new,courier;font-size:80%;color:#500010;margin-left:30px}
   18 SMALL    {font-size:70%}
   19 --></style></head>
   20  <body>
   21   <h1>Command line argument handling library</h1>
   22   <h2 class=level2> 0. Contents </h2>
   23   
   24   This is the documentation of libargh-1.0.8.
   25 <div class=toc><table cellspacing=0 cellpadding=0 class=toc><tr><td width="50%" valign=middle align=left nowrap class=toc>&nbsp;&nbsp;&nbsp;1. <a href="#h0">Purpose</a><br>&nbsp;&nbsp;&nbsp;2. <a href="#h1">Supported</a><br>&nbsp;&nbsp;&nbsp;3. <a href="#h2">Headers</a><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;3.1. <a href="#h3">C++ header: argh.hh</a><br></td>
   26 <td width="50%" valign=middle align=left nowrap class=toc>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;3.2. <a href="#h4">C header: argh.h</a><br>&nbsp;&nbsp;&nbsp;4. <a href="#h5">Copying</a><br>&nbsp;&nbsp;&nbsp;5. <a href="#h6">Requirements</a><br>&nbsp;&nbsp;&nbsp;6. <a href="#download">Downloading</a><br></td>
   27 </tr></table></div><H2 id="h0" class="level2"><a name="h0"></a>1. Purpose</H2><div class="level2" id="divh0">
   28 
   29 Handles commandline parameters.
   30 
   31 </div><H2 id="h1" class="level2"><a name="h1"></a>2. Supported</H2><div class="level2" id="divh1">
   32 
   33 C, C++
   34 
   35 </div><H2 id="h2" class="level2"><a name="h2"></a>3. Headers</H2><div class="level2" id="divh2">
   36 
   37 </div><H3 id="h3" class="level3"><a name="h3"></a>3.1. C++ header: argh.hh</H3><div class="level3" id="divh3">
   38 
   39 <pre class=smallerpre>#ifndef optrar_argh_hh
   40 #define optrar_argh_hh
   41 
   42 /* Copyright (C) 1992,2003 Bisqwit (http://iki.fi/bisqwit/) */
   43 
   44 /*
   45  * C++ USAGE EXAMPLE
   46  * 
   47 
   48 #include &lt;argh.hh&gt;
   49 
   50 int main(int argc, const char *const *argv)
   51 {
   52     vector&lt;string&gt; files;
   53     
   54     string buildfn;
   55     bool worst = false;
   56     
   57     ParamHandler Argh;
   58     
   59     Argh.AddLong(&quot;worst&quot;,   'w').SetBool().SetDesc(&quot;Least optimal.&quot;);
   60     Argh.AddLong(&quot;help&quot;,    'h').SetBool().SetDesc(&quot;This help.&quot;);
   61     Argh.AddLong(&quot;version&quot;, 'V').SetBool().SetDesc(&quot;Displays version information.&quot;);
   62     Argh.AddLong(&quot;build&quot;,   'b').SetString().SetDesc(&quot;Builds the archive.&quot;, &quot;&lt;file&gt;&quot;);
   63     Argh.AddLong(&quot;make&quot;,    'b');
   64     
   65     Argh.AddBool('k');
   66     Argh.AddDesc('k', &quot;This option does nothing.&quot;);
   67     Argh.AddLong(&quot;idle&quot;, 500).SetDesc(&quot;This option does nothing.&quot;);
   68     
   69     Argh.StartParse(argc, argv);
   70     for(;;)
   71     {
   72         int c = Argh.GetParam();
   73         if(c == -1)break;
   74         switch(c)
   75         {
   76             case 'w': worst = Argh.GetBool(); break;
   77             case 'V': printf(&quot;%s\n&quot;, VERSION); return 0;
   78             case 'b': buildfn = Argh.GetString(); break;
   79             case 'k': break; // -k
   80             case 500: break; // --idle
   81             case 'h':
   82                 printf(
   83                     &quot;This is software\n&quot;
   84                     &quot;\nUsage: software [&lt;option&gt; [&lt;...&gt;]] &lt;file&gt; [&lt;...&gt;]\n&quot;
   85                     &quot;\nThis software does something for the files.\n&quot;
   86                     &quot;\nOptions:\n&quot;);
   87                 Argh.ListOptions();
   88                 printf(&quot;\nNo warranty whatsoever.\n&quot;);
   89                 return 0;
   90             default:
   91                 files.push_back(Argh.GetString());
   92         }
   93     }
   94     if(!Argh.ok())return -1;
   95     if(!files.size())
   96     {
   97         fprintf(stderr, &quot;Error: At least one file must be specified.\n&quot;);
   98         return -1;
   99     }
  100     
  101     ...
  102 }
  103 
  104 */
  105 
  106 /* The header begins here. */
  107 
  108 #include &lt;string&gt;
  109 class ParamHandler
  110 {
  111 private:
  112     /* No copying */
  113     void operator=(const ParamHandler &amp;);
  114     ParamHandler (const ParamHandler &amp;);
  115     class Reference;
  116 public:
  117     typedef long keytype;
  118     
  119     ParamHandler();
  120     virtual ~ParamHandler();
  121     virtual void PrintOpt(unsigned space, const std::string &amp;opts, const std::string &amp;desc);
  122     
  123     Reference AddLong(const std::string &amp;longname, keytype alias);
  124     Reference AddBool(keytype c);
  125     Reference AddInt(keytype c, int min, int max);
  126     Reference AddFloat(keytype c, double min, double max);
  127     Reference AddString(keytype c, unsigned min=1, unsigned max=std::string::npos);
  128     Reference AddDesc(keytype c, const std::string &amp;s, const std::string &amp;param=&quot;&quot;);
  129 
  130     // Support for many conventions
  131     void StartParse(int ac, const char *const *av, int firstarg=1);
  132     void StartParse(int ac, const char **av, int firstarg=1);
  133     void StartParse(int ac, char **av, int firstarg=1);
  134     void StartParse(int ac, char *const*av, int firstarg=1);
  135     
  136     const std::string ProgName() const { return A0; }
  137 
  138     /* --not-x, --no-x, --without-x and --with-x are recognized.
  139      * Therefore you should use GetBool().
  140      */
  141     inline const bool GetBool() const      { return polarity; }
  142     inline const int GetInt() const        { return intparm; }
  143     inline const double GetFloat() const   { return doubleparm; }
  144     inline const std::string &amp;GetString() const { return param; }
  145     inline const bool ok() const           { return !error; }
  146     
  147     keytype GetParam();
  148     void ListOptions();
  149 
  150 private:
  151     static inline keytype char2opt(char c1, char c2) { return (unsigned char)c1 + (unsigned char)c2 * 256; }
  152     static inline keytype char3opt(char c1, char c2, char c3) { return (unsigned char)c1 + 256 * char2opt(c2, c3); }
  153     
  154     void ErrorIllegalOption(keytype key);
  155     void ErrorNeedsArg(keytype key);
  156     void ErrorNeedsArg(const std::string &amp;longo);
  157     void ErrorNeedNoArg(const std::string &amp;longo);
  158     void InternalError(keytype key, const char *s);
  159     void ErrorOutOfRange(const std::string &amp;param);
  160     void ErrorUnknownOption(const char *s, bool negafail);
  161         
  162 public:
  163     /* argh_atypemap needs this and I don't know how to make it friend. */
  164     class ArgInfo { public: char type; int min,max;unsigned maxl;double fmin,fmax; };
  165 private:
  166     class argh_aliasmap *aliases;
  167     class argh_descsmap *descs;
  168     class argh_atypemap *argtypes;
  169     class Reference
  170     {
  171         ParamHandler *par;
  172         keytype key;
  173     public:
  174         Reference(ParamHandler *p, keytype k) : par(p), key(k) { }
  175         Reference &amp;SetBool();
  176         Reference &amp;SetInt(int min, int max);
  177         Reference &amp;SetFloat(double min, double max);
  178         Reference &amp;SetString(unsigned min=1, unsigned max=std::string::npos);
  179         Reference &amp;SetDesc(const std::string &amp;s, const std::string &amp;param=&quot;&quot;);
  180     };
  181     Reference MakeRef(keytype key);
  182     int ParseError();
  183     int ShortOpt(keytype key, const char *s);
  184 private:
  185     int argc; const char *const *argv;
  186     const char *A0;
  187     /* parser volatile */
  188     int argpos; bool opts; std::string longo, longobuf; std::string param;
  189     const char *shortpointer; bool error, polarity; int intparm; double doubleparm;
  190 };
  191 
  192 #endif
  193 </pre>
  194 
  195 </div><H3 id="h4" class="level3"><a name="h4"></a>3.2. C header: argh.h</H3><div class="level3" id="divh4">
  196 
  197 <pre class=smallerpre>#ifndef optrar_argh_h
  198 #define optrar_argh_h
  199 
  200 /* Copyright (C) 1992,2003 Bisqwit (http://iki.fi/bisqwit/) */
  201 
  202 #ifdef __cplusplus
  203 extern &quot;C&quot; {
  204 #endif
  205 
  206 extern void argh_init(void);
  207 extern void argh_done(void);
  208 extern void argh_add_long(const char *longname, int alias);
  209 extern void argh_add_bool(int alias);
  210 extern void argh_add_int(int c, int min, int max);
  211 extern void argh_add_float(int c, double min, double max);
  212 extern void argh_add_string(int c, unsigned minlen, unsigned maxlen);
  213 extern void argh_add_desc(int c, const char *s, const char *optparam);
  214 extern void argh_start_parse(int argc, const char *const *argv);
  215 extern int argh_get_bool(void);
  216 extern int argh_get_int(void);
  217 extern double argh_get_float(void);
  218 extern int argh_ok(void);
  219 extern int argh_get_param(void);
  220 extern void argh_list_options(void);
  221 /* Note: This pointer is only valid until next argh_get_param() call */
  222 /* Attention: Do not try to free() it. */
  223 extern const char *argh_get_string(void);
  224 
  225 #ifdef __cplusplus
  226 }
  227 #endif
  228 
  229 /* C language usage example: 
  230 
  231 static int stereo=0;
  232 static int Rate  =43200;
  233 static char *host = NULL;
  234 
  235 static void PrintVersionInfo(void)
  236 {
  237     printf(&quot;erec - polydriving recording server v&quot;VERSION&quot; (C) 1992,2000 Bisqwit\n&quot;);
  238 }
  239 
  240 #include &lt;argh.h&gt;
  241 
  242 int main(int argc, const char *const *argv)
  243 {
  244     int Heelp = 0;
  245     
  246     argh_init();
  247     
  248     argh_add_long(&quot;stereo&quot;, '2'); argh_add_bool('2'); argh_add_desc('2', &quot;Specifies stereo sound. Default is mono.&quot;, NULL);
  249     argh_add_long(&quot;mono&quot;,   'm'); argh_add_bool('m'); argh_add_desc('m', &quot;Redundant. It's here for esd compatibility.&quot;, NULL);
  250     argh_add_long(&quot;rate&quot;,   'r'); argh_add_int('r',18,999999); argh_add_desc('r', &quot;Specifies recording rate. 43200 is default.&quot;, &quot;&lt;num&gt;&quot;);
  251     argh_add_long(&quot;device&quot;, 'd'); argh_add_string('d',1,1023); argh_add_desc('d', &quot;Specify device.&quot;, &quot;&lt;file&gt;&quot;);
  252     argh_add_long(&quot;help&quot;,   'h'); argh_add_bool('h'); argh_add_desc('h', &quot;Help&quot;, NULL);
  253     argh_add_long(&quot;version&quot;,'V'); argh_add_bool('V'); argh_add_desc('V', &quot;Version information&quot;, NULL);
  254     
  255     argh_start_parse(argc, argv);
  256     for(;;)
  257     {
  258         int c = argh_get_param();
  259         if(c == -1)break;
  260         switch(c)
  261         {
  262             case 'V':
  263                 PrintVersionInfo();
  264                 return 0;
  265             case 'h':
  266                 Heelp = 1;
  267                 break;
  268             case '2':
  269                 if(argh_get_bool())++stereo;else stereo=0;
  270                 break;
  271             case 'm':
  272                 if(argh_get_bool())stereo = 0;else ++stereo;
  273                 break;
  274             case 'r':
  275                 Rate = argh_get_int();
  276                 break;
  277             case 'd':
  278                 strncpy(Device, argh_get_string(), sizeof Device);
  279                 Device[sizeof(Device)-1] = 0;
  280                 break;
  281             default:
  282             {
  283                 const char *s = argh_get_string();
  284                 host = (char *)malloc(strlen(s)+1);
  285                 strcpy(host, s);
  286             }
  287         }
  288     }
  289     if(!host)host = (char *)&quot;10.104.2.2&quot;;
  290     
  291     if(!argh_ok())return -1;
  292     
  293     if(Heelp)
  294     {
  295         PrintVersionInfo();
  296         printf(
  297             &quot;\nAllows multiple applications request recorded data&quot;
  298             &quot;\nat the same time with different stream attributes.\n&quot;);
  299         printf(
  300             &quot;Usage: erec [&lt;options&gt; [&lt;...&gt;]] [&lt;host&gt; | none]\n&quot;
  301             &quot;Options:\n&quot;);
  302         argh_list_options();
  303         printf(&quot;\n&quot;
  304             &quot;If &lt;host&gt; is other than none, the output will be sent with esdcat.\n&quot;);
  305         return 0;
  306     }
  307     
  308     ...
  309 }
  310 
  311 */
  312 
  313 #endif
  314 </pre>
  315 
  316 </div><H2 id="h5" class="level2"><a name="h5"></a>4. Copying</H2><div class="level2" id="divh5">
  317 
  318 libargh has been written by Joel Yliluoma, a.k.a.
  319 <a href="http://iki.fi/bisqwit/">Bisqwit</a>,<br>
  320 and is distributed under the terms of the
  321 <a href="http://www.gnu.org/licenses/licenses.html#GPL">General Public License</a> (GPL).
  322 
  323 </div><H2 id="h6" class="level2"><a name="h6"></a>5. Requirements</H2><div class="level2" id="divh6">
  324 
  325 argh has been written in C++, utilizing the standard template library.<br>
  326 GNU make is required.<br>
  327 libargh compiles without warnings at least on g++ versions 3.0.1 and 3.0.3.
  328 
  329 </div><H2 id="download" class="level2"><a name="download"></a>6. Downloading</H2><div class="level2" id="divdownload">
  330    The official home page of libargh
  331    is at <a href="http://iki.fi/bisqwit/source/libargh.html">http://iki.fi/bisqwit/source/libargh.html</a>.<br>
  332    Check there for new versions.
  333 </div> <p align=right><small>Generated from
  334        <code>progdesc.php</code> (last updated: Sat, 25 Jan 2003 16:52:14 +0200)<br>
  335   with <code>docmaker.php</code> (last updated: Thu, 13 Feb 2003 15:11:29 +0200)<br>
  336   at Sat, 27 Sep 2003 16:17:09 +0300</small>
  337  </p>
  338 </body>
  339 </html>