| version 1.1, 2002/05/10 00:38:18 |
version 1.2, 2002/05/20 16:10:24 |
|
|
| <title id="usage.parsing.title">Parsing</title> |
<title id="usage.parsing.title">Parsing</title> |
| <para> |
<para> |
| |
|
| |
After &name; context is created and context flags are set, we can start with |
| |
configuration parsing. This chapter contains information about particular |
| |
parsing methods. |
| |
|
| |
<funcsynopsis> |
| |
<funcsynopsisinfo><![CDATA[#include <cfg+.h>]]></funcsynopsisinfo> |
| |
|
| |
<funcprototype> |
| |
<funcdef>int <function>cfg_parse</function></funcdef> |
| |
<paramdef>const CFG_CONTEXT <parameter>con</parameter></paramdef> |
| |
</funcprototype> |
| |
|
| |
<funcprototype> |
| |
<funcdef>int <function>cfg_get_next_opt</function></funcdef> |
| |
<paramdef>const CFG_CONTEXT <parameter>con</parameter></paramdef> |
| |
</funcprototype> |
| |
|
| |
</funcsynopsis> |
| |
|
| |
</para> |
| |
<para> |
| |
|
| |
These functions get created context as its sigle argument. Depending on context |
| |
type they parse next configuration file line or command line argument. If found |
| |
option is in specified options set (see <xref linkend="usage.options-set" |
| |
endterm="usage.options-set.title"> chapter) and if |
| |
<structfield>value</structfield> field in <structname>cfg_option</structname> of |
| |
appropriate option is not <constant>NULL</constant>, that field is filled with |
| |
parsed argument or arguments. |
| |
|
| |
</para> |
| |
<para> |
| |
|
| |
The main and only one difference between these two parsing functions is, that |
| |
after option is found on command line or in config file and |
| |
<structfield>val</structfield> structure field is not <constant>0</constant>, |
| |
<function>cfg_get_next_opt()</function> returns that value. Otherwise function |
| |
continues on next line or argument. This feature is especially usuable for |
| |
applications with need of more sophisticated command line or config file |
| |
parsing. Function <function>cfg_parse()</function> allways ignores |
| |
<structfield>val</structfield> value. |
| |
|
| |
</para> |
| |
<para> |
| |
|
| |
These functions also returns error code if error has occured. Note, that all |
| |
error codes are lower than <constant>0</constant>. That is the reason why it is |
| |
good to keep value of <structfield>val</structfield> structure member equal or |
| |
greater than <constant>0</constant>. More information with error codes description |
| |
are in <xref linkend="usage.error-codes" endterm="usage.error-codes.title"> |
| |
chapter. |
| |
|
| |
</para> |
| |
<para> |
| |
|
| |
On end of parsing <constant>0</constant> is returned. |
| |
|
| |
</para> |
| |
<para> |
| |
|
| |
Following functions are for providing additional information when returned |
| |
options are handled. |
| |
|
| |
<funcsynopsis> |
| |
<funcsynopsisinfo><![CDATA[#include <cfg+.h>]]></funcsynopsisinfo> |
| |
|
| |
<funcprototype> |
| |
<funcdef>char *<function>cfg_get_cur_opt</function></funcdef> |
| |
<paramdef>const CFG_CONTEXT <parameter>con</parameter></paramdef> |
| |
</funcprototype> |
| |
|
| |
<funcprototype> |
| |
<funcdef>int <function>cfg_get_cur_arg</function></funcdef> |
| |
<paramdef>const CFG_CONTEXT <parameter>con</parameter></paramdef> |
| |
</funcprototype> |
| |
|
| |
<funcprototype> |
| |
<funcdef>int <function>cfg_get_cur_idx</function></funcdef> |
| |
<paramdef>const CFG_CONTEXT <parameter>con</parameter></paramdef> |
| |
</funcprototype> |
| |
|
| |
</funcsynopsis> |
| |
|
| |
</para> |
| |
<para> |
| |
|
| |
Functions have following behaviour: <function>cfg_get_cur_opt()</function> |
| |
returns currently processed option name, <function>cfg_get_cur_arg()</function> |
| |
returns currently processed option argument, |
| |
<function>cfg_get_cur_idx()</function> returns argv index in command line |
| |
context and file byte or line position in config file context of currently |
| |
processed option. |
| |
|
| </para> |
</para> |
| </sect1> |
</sect1> |
| |
|