version 1.1.1.1, 2017/01/24 14:48:55
|
version 1.1.1.2, 2021/03/17 00:49:17
|
Line 1
|
Line 1
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
"http://www.w3.org/TR/html4/strict.dtd"> | <html xmlns="http://www.w3.org/1999/xhtml"> |
<html> | |
<head> |
<head> |
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> | <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> |
<title>confuse: simple.c</title> | <meta http-equiv="X-UA-Compatible" content="IE=9"/> |
<link rel="stylesheet" href="tutorial.css" type="text/css"> | <meta name="generator" content="Doxygen 1.8.17"/> |
| <title>confuse: simple.c</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="search/search.css" rel="stylesheet" type="text/css"/> |
| <script type="text/javascript" src="search/searchdata.js"></script> |
| <script type="text/javascript" src="search/search.js"></script> |
| <link href="doxygen.css" rel="stylesheet" type="text/css" /> |
</head> |
</head> |
<body> |
<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 id="projectalign" style="padding-left: 0.5em;"> |
|
<div id="projectname">confuse |
|
 <span id="projectnumber">3.3</span> |
|
</div> |
|
</td> |
|
</tr> |
|
</tbody> |
|
</table> |
|
</div> |
|
<!-- end header part --> |
|
<!-- Generated by Doxygen 1.8.17 --> |
|
<script type="text/javascript"> |
|
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */ |
|
var searchBox = new SearchBox("searchBox", "search",false,'Search'); |
|
/* @license-end */ |
|
</script> |
|
<script type="text/javascript" src="menudata.js"></script> |
|
<script type="text/javascript" src="menu.js"></script> |
|
<script type="text/javascript"> |
|
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */ |
|
$(function() { |
|
initMenu('',true,false,'search.php','Search'); |
|
$(document).ready(function() { init_search(); }); |
|
}); |
|
/* @license-end */</script> |
|
<div id="main-nav"></div> |
|
</div><!-- top --> |
|
<!-- window showing the filter options --> |
|
<div id="MSearchSelectWindow" |
|
onmouseover="return searchBox.OnSearchSelectShow()" |
|
onmouseout="return searchBox.OnSearchSelectHide()" |
|
onkeydown="return searchBox.OnSearchSelectKey(event)"> |
|
</div> |
|
|
<div class="main"> | <!-- iframe showing the search results (closed by default) --> |
| <div id="MSearchResultsWindow"> |
<!-- doxygen-header.html ends here --> | <iframe src="javascript:void(0)" frameborder="0" |
<!-- Generated by Doxygen 1.5.8 --> | name="MSearchResults" id="MSearchResults"> |
<div class="navigation" id="top"> | </iframe> |
<div class="tabs"> | |
<ul> | |
<li><a href="index.html"><span>Main Page</span></a></li> | |
<li><a href="annotated.html"><span>Data 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> |
<div class="contents"> |
|
<h1>simple.c</h1><div class="fragment"><pre class="fragment"><span class="preprocessor">#include <string.h></span> |
|
<span class="preprocessor">#include <stdlib.h></span> |
|
<span class="preprocessor">#include "<a class="code" href="confuse_8h.html" title="A configuration file parser library.">confuse.h</a>"</span> |
|
|
|
<span class="keywordtype">int</span> main(<span class="keywordtype">void</span>) | <div class="header"> |
{ | <div class="headertitle"> |
<a class="code" href="confuse_8h.html#4bce4b6aed9b07489d6a5c70321907e4" title="Boolean values.">cfg_bool_t</a> verbose = cfg_false; | <div class="title">simple.c</div> </div> |
<span class="keywordtype">char</span> *server = NULL; | </div><!--header--> |
<span class="keywordtype">double</span> delay = 1.356e-32; | <div class="contents"> |
<span class="keywordtype">char</span> *username = NULL; | <div class="fragment"><div class="line"><span class="preprocessor">#define _GNU_SOURCE</span></div> |
| <div class="line"><span class="preprocessor">#include <string.h></span></div> |
<span class="comment">/* Although the macro used to specify an integer option is called</span> | <div class="line"><span class="preprocessor">#include <stdlib.h></span></div> |
<span class="comment"> * CFG_SIMPLE_INT(), it actually expects a long int. On a 64 bit system</span> | <div class="line"><span class="preprocessor">#include <locale.h></span></div> |
<span class="comment"> * where ints are 32 bit and longs 64 bit (such as the x86-64 or amd64</span> | <div class="line"><span class="preprocessor">#include "<a class="code" href="confuse_8h.html">confuse.h</a>"</span></div> |
<span class="comment"> * architectures), you will get weird effects if you use an int here.</span> | <div class="line"> </div> |
<span class="comment"> *</span> | <div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">void</span>)</div> |
<span class="comment"> * If you use the regular (non-"simple") options, ie CFG_INT() and use</span> | <div class="line">{</div> |
<span class="comment"> * cfg_getint(), this is not a problem as the data types are implicitly</span> | <div class="line"> <span class="keyword">static</span> <a class="code" href="confuse_8h.html#a4bce4b6aed9b07489d6a5c70321907e4">cfg_bool_t</a> verbose = cfg_false;</div> |
<span class="comment"> * cast.</span> | <div class="line"> <span class="keyword">static</span> <span class="keywordtype">char</span> *server = NULL;</div> |
<span class="comment"> */</span> | <div class="line"> <span class="keyword">static</span> <span class="keywordtype">double</span> delay = 1.356e-32;</div> |
<span class="keywordtype">long</span> <span class="keywordtype">int</span> debug = 1; | <div class="line"> <span class="keyword">static</span> <span class="keywordtype">char</span> *username = NULL;</div> |
| <div class="line"> </div> |
<a name="_a0"></a><a class="code" href="structcfg__opt__t.html" title="Data structure holding information about an option.">cfg_opt_t</a> opts[] = { | <div class="line"> <span class="comment">/* Although the macro used to specify an integer option is called</span></div> |
<a name="a1"></a><a class="code" href="confuse_8h.html#228dc9c22fbcbeabed4d171774662ce8" title="Initialize a &quot;simple&quot; boolean option (see documentation for CFG_SIMPLE_STR...">CFG_SIMPLE_BOOL</a>(<span class="stringliteral">"verbose"</span>, &verbose), | <div class="line"><span class="comment"> * CFG_SIMPLE_INT(), it actually expects a long int. On a 64 bit system</span></div> |
<a name="a2"></a><a class="code" href="confuse_8h.html#e54fbbc31bd8c7ec8d7f04597a9f749d" title="Initialize a &quot;simple&quot; string option.">CFG_SIMPLE_STR</a>(<span class="stringliteral">"server"</span>, &server), | <div class="line"><span class="comment"> * where ints are 32 bit and longs 64 bit (such as the x86-64 or amd64</span></div> |
<a class="code" href="confuse_8h.html#e54fbbc31bd8c7ec8d7f04597a9f749d" title="Initialize a &quot;simple&quot; string option.">CFG_SIMPLE_STR</a>(<span class="stringliteral">"user"</span>, &username), | <div class="line"><span class="comment"> * architectures), you will get weird effects if you use an int here.</span></div> |
<a name="a3"></a><a class="code" href="confuse_8h.html#88fa2e73a1294c7e8a1f1519b68ce0ff" title="Initialize a &quot;simple&quot; integer option (see documentation for CFG_SIMPLE_STR...">CFG_SIMPLE_INT</a>(<span class="stringliteral">"debug"</span>, &debug), | <div class="line"><span class="comment"> *</span></div> |
<a name="a4"></a><a class="code" href="confuse_8h.html#073b3b12a5ba4648a1f4f1aa40ff3a2a" title="Initialize a &quot;simple&quot; floating point option (see documentation for CFG_SIMPLE_STR...">CFG_SIMPLE_FLOAT</a>(<span class="stringliteral">"delay"</span>, &delay), | <div class="line"><span class="comment"> * If you use the regular (non-"simple") options, ie CFG_INT() and use</span></div> |
<a name="a5"></a><a class="code" href="confuse_8h.html#6b29dd8a4c6cd3d392d4ab6b2e535597" title="Terminate list of options.">CFG_END</a>() | <div class="line"><span class="comment"> * cfg_getint(), this is not a problem as the data types are implicitly</span></div> |
}; | <div class="line"><span class="comment"> * cast.</span></div> |
<a name="_a6"></a><a class="code" href="structcfg__t.html" title="Data structure holding information about a &quot;section&quot;.">cfg_t</a> *cfg; | <div class="line"><span class="comment"> */</span></div> |
| <div class="line"> <span class="keyword">static</span> <span class="keywordtype">long</span> <span class="keywordtype">int</span> debug = 1;</div> |
<span class="comment">/* set default value for the server option */</span> | <div class="line"> </div> |
server = strdup(<span class="stringliteral">"gazonk"</span>); | <div class="line"> <a name="_a0"></a><a class="code" href="structcfg__opt__t.html">cfg_opt_t</a> opts[] = {</div> |
| <div class="line"> <a name="a1"></a><a class="code" href="confuse_8h.html#a228dc9c22fbcbeabed4d171774662ce8">CFG_SIMPLE_BOOL</a>(<span class="stringliteral">"verbose"</span>, &verbose),</div> |
cfg = <a name="a7"></a>cfg_init(opts, 0); | <div class="line"> <a name="a2"></a><a class="code" href="confuse_8h.html#ae54fbbc31bd8c7ec8d7f04597a9f749d">CFG_SIMPLE_STR</a>(<span class="stringliteral">"server"</span>, &server),</div> |
<a name="a8"></a>cfg_parse(cfg, <span class="stringliteral">"simple.conf"</span>); | <div class="line"> <a class="code" href="confuse_8h.html#ae54fbbc31bd8c7ec8d7f04597a9f749d">CFG_SIMPLE_STR</a>(<span class="stringliteral">"user"</span>, &username),</div> |
| <div class="line"> <a name="a3"></a><a class="code" href="confuse_8h.html#a88fa2e73a1294c7e8a1f1519b68ce0ff">CFG_SIMPLE_INT</a>(<span class="stringliteral">"debug"</span>, &debug),</div> |
printf(<span class="stringliteral">"verbose: %s\n"</span>, verbose ? <span class="stringliteral">"true"</span> : <span class="stringliteral">"false"</span>); | <div class="line"> <a name="a4"></a><a class="code" href="confuse_8h.html#a073b3b12a5ba4648a1f4f1aa40ff3a2a">CFG_SIMPLE_FLOAT</a>(<span class="stringliteral">"delay"</span>, &delay),</div> |
printf(<span class="stringliteral">"server: %s\n"</span>, server); | <div class="line"> <a name="a5"></a><a class="code" href="confuse_8h.html#a6b29dd8a4c6cd3d392d4ab6b2e535597">CFG_END</a>()</div> |
printf(<span class="stringliteral">"username: %s\n"</span>, username); | <div class="line"> };</div> |
printf(<span class="stringliteral">"debug: %ld\n"</span>, debug); | <div class="line"> <a name="_a6"></a><a class="code" href="structcfg__t.html">cfg_t</a> *cfg;</div> |
printf(<span class="stringliteral">"delay: %G\n"</span>, delay); | <div class="line"> </div> |
| <div class="line"> <span class="comment">/* Localize messages & types according to environment, since v2.9 */</span></div> |
printf(<span class="stringliteral">"setting username to 'foo'\n"</span>); | <div class="line"><span class="preprocessor">#ifdef LC_MESSAGES</span></div> |
<span class="comment">/* using cfg_setstr here is not necessary at all, the equivalent</span> | <div class="line"> setlocale(LC_MESSAGES, <span class="stringliteral">""</span>);</div> |
<span class="comment"> * code is:</span> | <div class="line"> setlocale(LC_CTYPE, <span class="stringliteral">""</span>);</div> |
<span class="comment"> * free(username);</span> | <div class="line"><span class="preprocessor">#endif</span></div> |
<span class="comment"> * username = strdup("foo");</span> | <div class="line"> </div> |
<span class="comment"> */</span> | <div class="line"> <span class="comment">/* set default value for the server option */</span></div> |
<a name="a9"></a>cfg_setstr(cfg, <span class="stringliteral">"user"</span>, <span class="stringliteral">"foo"</span>); | <div class="line"> server = strdup(<span class="stringliteral">"gazonk"</span>);</div> |
printf(<span class="stringliteral">"username: %s\n"</span>, username); | <div class="line"> </div> |
| <div class="line"> cfg = <a name="a7"></a><a class="code" href="confuse_8h.html#aec07794916564c8ab437e030ac618aa8">cfg_init</a>(opts, 0);</div> |
<span class="comment">/* print the parsed values to another file */</span> | <div class="line"> <a name="a8"></a><a class="code" href="confuse_8h.html#a0fca327466956c5580199e24397d49fe">cfg_parse</a>(cfg, <span class="stringliteral">"simple.conf"</span>);</div> |
{ | <div class="line"> </div> |
FILE *fp = fopen(<span class="stringliteral">"simple.conf.out"</span>, <span class="stringliteral">"w"</span>); | <div class="line"> printf(<span class="stringliteral">"verbose: %s\n"</span>, verbose ? <span class="stringliteral">"true"</span> : <span class="stringliteral">"false"</span>);</div> |
<a name="a10"></a>cfg_print(cfg, fp); | <div class="line"> printf(<span class="stringliteral">"server: %s\n"</span>, server);</div> |
fclose(fp); | <div class="line"> printf(<span class="stringliteral">"username: %s\n"</span>, username);</div> |
} | <div class="line"> printf(<span class="stringliteral">"debug: %ld\n"</span>, debug);</div> |
| <div class="line"> printf(<span class="stringliteral">"delay: %G\n"</span>, delay);</div> |
<a name="a11"></a>cfg_free(cfg); | <div class="line"> </div> |
| <div class="line"> printf(<span class="stringliteral">"setting username to 'foo'\n"</span>);</div> |
<span class="comment">/* You are responsible for freeing string values. */</span> | <div class="line"> <span class="comment">/* using cfg_setstr here is not necessary at all, the equivalent</span></div> |
free(server); | <div class="line"><span class="comment"> * code is:</span></div> |
free(username); | <div class="line"><span class="comment"> * free(username);</span></div> |
| <div class="line"><span class="comment"> * username = strdup("foo");</span></div> |
<span class="keywordflow">return</span> 0; | <div class="line"><span class="comment"> */</span></div> |
} | <div class="line"> <a name="a9"></a><a class="code" href="confuse_8h.html#a523a5eec449362eee5a0d2709645c35b">cfg_setstr</a>(cfg, <span class="stringliteral">"user"</span>, <span class="stringliteral">"foo"</span>);</div> |
</pre></div> </div> | <div class="line"> printf(<span class="stringliteral">"username: %s\n"</span>, username);</div> |
<!-- doxygen-footer.html starts here --> | <div class="line"> </div> |
</div> | <div class="line"> <span class="comment">/* print the parsed values to another file */</span></div> |
</body> | <div class="line"> {</div> |
| <div class="line"> FILE *fp = fopen(<span class="stringliteral">"simple.conf.out"</span>, <span class="stringliteral">"w"</span>);</div> |
| <div class="line"> </div> |
| <div class="line"> <a name="a10"></a><a class="code" href="confuse_8h.html#ac3343e32da22758f76ec50627316c708">cfg_print</a>(cfg, fp);</div> |
| <div class="line"> fclose(fp);</div> |
| <div class="line"> }</div> |
| <div class="line"> </div> |
| <div class="line"> <a name="a11"></a><a class="code" href="confuse_8h.html#aae5e08626bf53514a6ebf250580feba3">cfg_free</a>(cfg);</div> |
| <div class="line"> </div> |
| <div class="line"> <span class="comment">/* You are responsible for freeing string values. */</span></div> |
| <div class="line"> free(server);</div> |
| <div class="line"> free(username);</div> |
| <div class="line"> </div> |
| <div class="line"> <span class="keywordflow">return</span> 0;</div> |
| <div class="line">}</div> |
| </div><!-- fragment --> </div><!-- contents --> |
| <div class="ttc" id="aconfuse_8h_html_aec07794916564c8ab437e030ac618aa8"><div class="ttname"><a href="confuse_8h.html#aec07794916564c8ab437e030ac618aa8">cfg_init</a></div><div class="ttdeci">DLLIMPORT cfg_t *__export cfg_init(cfg_opt_t *opts, cfg_flag_t flags)</div><div class="ttdoc">Create and initialize a cfg_t structure.</div><div class="ttdef"><b>Definition:</b> confuse.c:1816</div></div> |
| <div class="ttc" id="aconfuse_8h_html_a228dc9c22fbcbeabed4d171774662ce8"><div class="ttname"><a href="confuse_8h.html#a228dc9c22fbcbeabed4d171774662ce8">CFG_SIMPLE_BOOL</a></div><div class="ttdeci">#define CFG_SIMPLE_BOOL(name, svalue)</div><div class="ttdoc">Initialize a "simple" boolean option (see documentation for CFG_SIMPLE_STR for more information).</div><div class="ttdef"><b>Definition:</b> confuse.h:511</div></div> |
| <div class="ttc" id="aconfuse_8h_html_a073b3b12a5ba4648a1f4f1aa40ff3a2a"><div class="ttname"><a href="confuse_8h.html#a073b3b12a5ba4648a1f4f1aa40ff3a2a">CFG_SIMPLE_FLOAT</a></div><div class="ttdeci">#define CFG_SIMPLE_FLOAT(name, svalue)</div><div class="ttdoc">Initialize a "simple" floating point option (see documentation for CFG_SIMPLE_STR for more informatio...</div><div class="ttdef"><b>Definition:</b> confuse.h:478</div></div> |
| <div class="ttc" id="aconfuse_8h_html_a523a5eec449362eee5a0d2709645c35b"><div class="ttname"><a href="confuse_8h.html#a523a5eec449362eee5a0d2709645c35b">cfg_setstr</a></div><div class="ttdeci">DLLIMPORT int __export cfg_setstr(cfg_t *cfg, const char *name, const char *value)</div><div class="ttdoc">Set the value of a string option given its name.</div><div class="ttdef"><b>Definition:</b> confuse.c:2211</div></div> |
| <div class="ttc" id="aconfuse_8h_html_a6b29dd8a4c6cd3d392d4ab6b2e535597"><div class="ttname"><a href="confuse_8h.html#a6b29dd8a4c6cd3d392d4ab6b2e535597">CFG_END</a></div><div class="ttdeci">#define CFG_END()</div><div class="ttdoc">Terminate list of options.</div><div class="ttdef"><b>Definition:</b> confuse.h:574</div></div> |
| <div class="ttc" id="aconfuse_8h_html"><div class="ttname"><a href="confuse_8h.html">confuse.h</a></div><div class="ttdoc">A configuration file parser library.</div></div> |
| <div class="ttc" id="aconfuse_8h_html_ae54fbbc31bd8c7ec8d7f04597a9f749d"><div class="ttname"><a href="confuse_8h.html#ae54fbbc31bd8c7ec8d7f04597a9f749d">CFG_SIMPLE_STR</a></div><div class="ttdeci">#define CFG_SIMPLE_STR(name, svalue)</div><div class="ttdoc">Initialize a "simple" string option.</div><div class="ttdef"><b>Definition:</b> confuse.h:410</div></div> |
| <div class="ttc" id="aconfuse_8h_html_ac3343e32da22758f76ec50627316c708"><div class="ttname"><a href="confuse_8h.html#ac3343e32da22758f76ec50627316c708">cfg_print</a></div><div class="ttdeci">DLLIMPORT int __export cfg_print(cfg_t *cfg, FILE *fp)</div><div class="ttdoc">Print the options and values to a file.</div><div class="ttdef"><b>Definition:</b> confuse.c:2548</div></div> |
| <div class="ttc" id="aconfuse_8h_html_a0fca327466956c5580199e24397d49fe"><div class="ttname"><a href="confuse_8h.html#a0fca327466956c5580199e24397d49fe">cfg_parse</a></div><div class="ttdeci">DLLIMPORT int __export cfg_parse(cfg_t *cfg, const char *filename)</div><div class="ttdoc">Parse a configuration file.</div><div class="ttdef"><b>Definition:</b> confuse.c:1746</div></div> |
| <div class="ttc" id="astructcfg__opt__t_html"><div class="ttname"><a href="structcfg__opt__t.html">cfg_opt_t</a></div><div class="ttdoc">Data structure holding information about an option.</div><div class="ttdef"><b>Definition:</b> confuse.h:309</div></div> |
| <div class="ttc" id="astructcfg__t_html"><div class="ttname"><a href="structcfg__t.html">cfg_t</a></div><div class="ttdoc">Data structure holding information about a "section".</div><div class="ttdef"><b>Definition:</b> confuse.h:252</div></div> |
| <div class="ttc" id="aconfuse_8h_html_aae5e08626bf53514a6ebf250580feba3"><div class="ttname"><a href="confuse_8h.html#aae5e08626bf53514a6ebf250580feba3">cfg_free</a></div><div class="ttdeci">DLLIMPORT int __export cfg_free(cfg_t *cfg)</div><div class="ttdoc">Free a cfg_t context.</div><div class="ttdef"><b>Definition:</b> confuse.c:1962</div></div> |
| <div class="ttc" id="aconfuse_8h_html_a88fa2e73a1294c7e8a1f1519b68ce0ff"><div class="ttname"><a href="confuse_8h.html#a88fa2e73a1294c7e8a1f1519b68ce0ff">CFG_SIMPLE_INT</a></div><div class="ttdeci">#define CFG_SIMPLE_INT(name, svalue)</div><div class="ttdoc">Initialize a "simple" integer option (see documentation for CFG_SIMPLE_STR for more information).</div><div class="ttdef"><b>Definition:</b> confuse.h:445</div></div> |
| <div class="ttc" id="aconfuse_8h_html_a4bce4b6aed9b07489d6a5c70321907e4"><div class="ttname"><a href="confuse_8h.html#a4bce4b6aed9b07489d6a5c70321907e4">cfg_bool_t</a></div><div class="ttdeci">cfg_bool_t</div><div class="ttdoc">Boolean values.</div><div class="ttdef"><b>Definition:</b> confuse.h:232</div></div> |
| <!-- start footer part --> |
| <hr class="footer"/><address class="footer"><small> |
| Generated by  <a href="http://www.doxygen.org/index.html"> |
| <img class="footer" src="doxygen.png" alt="doxygen"/> |
| </a> 1.8.17 |
| </small></address> |
| </body> |
</html> |
</html> |