Annotation of embedaddon/confuse/doc/html/reread_8c-example.html, revision 1.1

1.1     ! misho       1: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
        !             2:         "http://www.w3.org/TR/html4/strict.dtd">
        !             3: <html>
        !             4: <head>
        !             5:  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
        !             6:  <title>confuse: reread.c</title>
        !             7:  <link rel="stylesheet" href="tutorial.css" type="text/css">
        !             8: </head>
        !             9: <body>
        !            10: 
        !            11: <div class="main">
        !            12: 
        !            13: <!-- doxygen-header.html ends here -->
        !            14: <!-- Generated by Doxygen 1.5.8 -->
        !            15: <div class="navigation" id="top">
        !            16:   <div class="tabs">
        !            17:     <ul>
        !            18:       <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
        !            19:       <li><a href="annotated.html"><span>Data&nbsp;Structures</span></a></li>
        !            20:       <li><a href="files.html"><span>Files</span></a></li>
        !            21:       <li><a href="examples.html"><span>Examples</span></a></li>
        !            22:     </ul>
        !            23:   </div>
        !            24: </div>
        !            25: <div class="contents">
        !            26: <h1>reread.c</h1><div class="fragment"><pre class="fragment"><span class="preprocessor">#include "<a class="code" href="confuse_8h.html" title="A configuration file parser library.">confuse.h</a>"</span>
        !            27: <span class="preprocessor">#include &lt;string.h&gt;</span>
        !            28: <span class="preprocessor">#include &lt;signal.h&gt;</span>
        !            29: <span class="preprocessor">#include &lt;unistd.h&gt;</span>
        !            30: 
        !            31: <a name="_a0"></a><a class="code" href="structcfg__t.html" title="Data structure holding information about a &amp;quot;section&amp;quot;.">cfg_t</a> *cfg = 0;
        !            32: <span class="keyword">const</span> <span class="keywordtype">char</span> *config_filename = <span class="stringliteral">"./reread.conf"</span>;
        !            33: 
        !            34: <span class="keywordtype">void</span> read_config(<span class="keywordtype">void</span>)
        !            35: {
        !            36:     <a name="_a1"></a><a class="code" href="structcfg__opt__t.html" title="Data structure holding information about an option.">cfg_opt_t</a> arg_opts[] = {
        !            37:         <a name="a2"></a><a class="code" href="confuse_8h.html#963e2ee16396dcf36f6d1937faa00f0c" title="Initialize a string option.">CFG_STR</a>(<span class="stringliteral">"value"</span>, <span class="stringliteral">"default"</span>, <a name="a3"></a><a class="code" href="confuse_8h.html#65df72d236bcc3e7f22c5b2b5c24bded" title="Flags.">CFGF_NONE</a>),
        !            38:         <a name="a4"></a><a class="code" href="confuse_8h.html#6b29dd8a4c6cd3d392d4ab6b2e535597" title="Terminate list of options.">CFG_END</a>()
        !            39:     };
        !            40:     <a class="code" href="structcfg__opt__t.html" title="Data structure holding information about an option.">cfg_opt_t</a> opts[] = {
        !            41:         <a name="a5"></a><a class="code" href="confuse_8h.html#c2b17561e944264c594ea0802e56d308" title="Initialize an integer option.">CFG_INT</a>(<span class="stringliteral">"delay"</span>, 3, <a class="code" href="confuse_8h.html#65df72d236bcc3e7f22c5b2b5c24bded" title="Flags.">CFGF_NONE</a>),
        !            42:         <a class="code" href="confuse_8h.html#963e2ee16396dcf36f6d1937faa00f0c" title="Initialize a string option.">CFG_STR</a>(<span class="stringliteral">"message"</span>, <span class="stringliteral">"This is a message"</span>, <a class="code" href="confuse_8h.html#65df72d236bcc3e7f22c5b2b5c24bded" title="Flags.">CFGF_NONE</a>),
        !            43:         <a name="a6"></a><a class="code" href="confuse_8h.html#043d5c79624269e5f60f59a698e461a6" title="Initialize a section.">CFG_SEC</a>(<span class="stringliteral">"argument"</span>, arg_opts, <a name="a7"></a><a class="code" href="confuse_8h.html#86b522a5daef5c07066b28f1585d2d77" title="option may be specified multiple times (only applies to sections)">CFGF_MULTI</a> | <a name="a8"></a><a class="code" href="confuse_8h.html#65d20dbd5b778dd1bf3b3895206b4497" title="option has a title (only applies to sections)">CFGF_TITLE</a>),
        !            44:         <a class="code" href="confuse_8h.html#6b29dd8a4c6cd3d392d4ab6b2e535597" title="Terminate list of options.">CFG_END</a>()
        !            45:     };
        !            46:     <span class="keywordtype">int</span> ret;
        !            47: 
        !            48:     <span class="keywordtype">char</span> *buf = <span class="stringliteral">""</span> \
        !            49:         <span class="stringliteral">" delay = 3\n"</span> \
        !            50:         <span class="stringliteral">"# message = \"asdfasfasfd tersf\"\n"</span> \
        !            51:         <span class="stringliteral">" argument one { value = 1 }\n"</span> \
        !            52:         <span class="stringliteral">" argument two { value=foo}\n"</span>;
        !            53: 
        !            54:     <a name="a9"></a>cfg_free(cfg);
        !            55: 
        !            56:     cfg = <a name="a10"></a>cfg_init(opts, 0);
        !            57:     ret = <a name="a11"></a>cfg_parse_buf(cfg, buf);
        !            58:     ret = <a name="a12"></a>cfg_parse(cfg, config_filename);
        !            59: }
        !            60: 
        !            61: <span class="keywordtype">void</span> sighandler(<span class="keywordtype">int</span> sig)
        !            62: {
        !            63:     read_config();
        !            64:     signal(SIGHUP, sighandler);
        !            65: }
        !            66: 
        !            67: <span class="keyword">static</span> <span class="keywordtype">int</span> loop = 1;
        !            68: 
        !            69: <span class="keywordtype">void</span> usr1handler(<span class="keywordtype">int</span> sig)
        !            70: {
        !            71:     loop = 0;
        !            72: }
        !            73: 
        !            74: <span class="keywordtype">int</span> main(<span class="keywordtype">void</span>)
        !            75: {
        !            76:     <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i;
        !            77: 
        !            78:     read_config();
        !            79:     signal(SIGHUP, sighandler);
        !            80:     signal(SIGUSR1, usr1handler);
        !            81: 
        !            82:     <span class="keywordflow">while</span>(loop)
        !            83:     {
        !            84:         printf(<span class="stringliteral">"Message: %s"</span>, <a name="a13"></a>cfg_getstr(cfg, <span class="stringliteral">"message"</span>));
        !            85:         <span class="keywordflow">for</span>(i = 0; i &lt; <a name="a14"></a>cfg_size(cfg, <span class="stringliteral">"argument"</span>); i++)
        !            86:         {
        !            87:             <a class="code" href="structcfg__t.html" title="Data structure holding information about a &amp;quot;section&amp;quot;.">cfg_t</a> *arg = <a name="a15"></a>cfg_getnsec(cfg, <span class="stringliteral">"argument"</span>, i);
        !            88:             printf(<span class="stringliteral">", %s"</span>, cfg_getstr(arg, <span class="stringliteral">"value"</span>));
        !            89:         }
        !            90:         printf(<span class="stringliteral">"\n"</span>);
        !            91: 
        !            92:         sleep(<a name="a16"></a>cfg_getint(cfg, <span class="stringliteral">"delay"</span>));
        !            93:     }
        !            94: 
        !            95:     cfg_free(cfg);
        !            96:     cfg = 0;
        !            97: 
        !            98:     <span class="keywordflow">return</span> 0;
        !            99: }
        !           100: </pre></div> </div>
        !           101: <!-- doxygen-footer.html starts here -->
        !           102:   </div>
        !           103:  </body>
        !           104: </html>

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>