Artifact [13506d5d97]

Artifact 13506d5d971d176beedec7c8e4d28451accdec5c:

Wiki page [Manual for lc_register_var] by rkeene on 2014-11-24 20:11:50.
D 2014-11-24T20:11:50.528
L Manual\sfor\slc_register_var
P 084900ca0db1f0e051901d70709d0544a0fb50fa
U rkeene
W 7171
<H2>NAME</H2>
lc_register_var - Register a variable for automatic processing.
<P>
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<B>#include &lt;<A HREF="artifact/7c61a9805e664fde7943807af8d5e164e7cebdb6">libconfig.h</A>&gt;</B>
<P>
<B>int lc_register_var(const char *</B><I>var</I><B>, lc_var_type_t </B><I>type</I><B>, void *</B><I>data</I><B>, char </B><I>opt</I><B>);</B>
<P>
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
The
<B><A HREF="wiki/Manual for lc_register_var">lc_register_var</A></B>(3)
function registers a variable for automatic processing.
The
<I>var</I>
parameter specifies the variable name for processing.  This name can exist in a configuration file, an environment variable, or on the command line.
The
<I>opt</I>
parameter specifies the single letter short option that can be specified on the command line to change the value of the variable specified by the
<I>data</I>
parameter.  A value of '&nbsp;' can be specified for no short option.
<P>
The
<I>type</I>
parameter is of type
<I>lc_var_type_t</I>
which specifies the type of the
<I>data</I>
parameter.
Valid values for
<I>type</I>
are:
<DL COMPACT>
<DT>LC_VAR_STRING<DD>
For a string type variable.  The data passed should be of type &quot;char **&quot;.  The data will be set to a region of memory that has been allocated with malloc() and can be released be free()'d.
<DT>LC_VAR_LONG_LONG<DD>
For a &quot;long long&quot; integer type variable.  The data passed should be of type &quot;long long *&quot;.
<DT>LC_VAR_LONG<DD>
For a &quot;long&quot; integer type variable.  The data passed should be of type &quot;long *&quot;.
<DT>LC_VAR_INT<DD>
For a &quot;int&quot; integer type variable.  The data passed should be of type &quot;int *&quot;.
<DT>LC_VAR_SHORT<DD>
For a &quot;short&quot; integer type variable.  The data passed should be of type &quot;short *&quot;.
<DT>LC_VAR_FLOAT<DD>
For a &quot;float&quot; floating point type variable.  The data passed should be of type &quot;float *&quot;.
<DT>LC_VAR_DOUBLE<DD>
For a &quot;double&quot; floating point type variable.  The data passed should be of type &quot;double *&quot;.
<DT>LC_VAR_BOOL<DD>
For a boolean type variable.  The data passed should be of type &quot;int *&quot;.  When a true value is specified the variable is set to 1.  When a false value is specified the variable is set to 0.  Any other value sets the variable to -1.  Valid true values are: enable, true, yes, on, y, and 1.  Valid false values are: disable, false, off, no, n, and 0.
<DT>LC_VAR_FILENAME<DD>
Not implemented.
<DT>LC_VAR_DIRECTORY<DD>
Not implemented.
<DT>LC_VAR_SIZE_LONG_LONG<DD>
For a &quot;long long&quot; integer type that can have size modifiers, such as 'G' or gigabytes, 'M' for megabytes, 'K' for kilobytes.  The data passed should be of type &quot;long long *&quot;.
<DT>LC_VAR_SIZE_LONG<DD>
For a &quot;long&quot; integer type that can have size modifiers, such as 'G' or gigabytes, 'M' for megabytes, 'K' for kilobytes.  The data passed should be of type &quot;long *&quot;.
<DT>LC_VAR_SIZE_INT<DD>
For a &quot;int&quot; integer type that can have size modifiers, such as 'G' or gigabytes, 'M' for megabytes, 'K' for kilobytes.  The data passed should be of type &quot;int *&quot;.
<DT>LC_VAR_SIZE_SHORT<DD>
For a &quot;short&quot; integer type that can have size modifiers, such as 'G' or gigabytes, 'M' for megabytes, 'K' for kilobytes.  The data passed should be of type &quot;short *&quot;.
<DT>LC_VAR_SIZE_SIZE_T<DD>
For a &quot;size_t&quot; data type that can have size modifiers, such as 'G' or gigabytes, 'M' for megabytes, 'K' for kilobytes.  The data passed should be of type &quot;size_t *&quot;.
<DT>LC_VAR_TIME<DD>
Not implemented.
<DT>LC_VAR_DATE<DD>
Not implemented.
<DT>LC_VAR_BOOL_BY_EXISTANCE<DD>
This type of variable takes no arguments, it is set to true (1) by its existance in a configuration file, environment variable, or on the command line.  If it is not specified, the value of the data passed is not changed.  The data passed should be of type &quot;int *&quot;.
<DT>LC_VAR_CIDR<DD>
This type of variable accepts a CIDR format netmask and IP.  This is not yet implemented. (XXX)
<DT>LC_VAR_IP<DD>
This type of variable accepts an IP address in decimal-dot format.  The value is stored in a uint32_t in network byte order.
<DT>LC_VAR_HOSTNAME<DD>
This type of variable accepts an address in hostname format.  The value is stored in a uint32_t in network byte order.
<DT>LC_VAR_ADDR<DD>
This type of variable accepts an address in either hostname or decimal-dot format.  The value is stored in a uint32_t in network byte order.
<P>
</DL>
<A NAME="lbAE">&nbsp;</A>
<H2>RETURN VALUE</H2>
On success 0 is returned, otherwise -1 is returned.
<P>
<A NAME="lbAF">&nbsp;</A>
<H2>EXAMPLE</H2>
<PRE>
#include &lt;<A HREF="artifact/7c61a9805e664fde7943807af8d5e164e7cebdb6">libconfig.h</A>&gt;
#include &lt;<A HREF="file:/usr/include/stdlib.h">stdlib.h</A>&gt;
#include &lt;<A HREF="file:/usr/include/stdio.h">stdio.h</A>&gt;
int main(int argc, char **argv) {
        int lc_p_ret, lc_rv_ret;
        char *filename = NULL;
        long int counter = -1;
        lc_rv_ret = lc_register_var(&quot;Begin&quot;, LC_VAR_LONG,
                                    &amp;counter, 'c');
        if (lc_rv_ret != 0) {
                fprintf(stderr, &quot;Error registering variable: %i.\n&quot;,
                        lc_geterrno());
                return(EXIT_FAILURE);
        }
        lc_rv_ret = lc_register_var(&quot;File&quot;, LC_VAR_STRING,
                                    &amp;filename, 'f');
        if (lc_rv_ret != 0) {
                fprintf(stderr, &quot;Error registering variable: %i.\n&quot;,
                        lc_geterrno());
                return(EXIT_FAILURE);
        }
        lc_p_ret = lc_process(argc, argv, &quot;example&quot;, LC_CONF_APACHE,
                              NULL);
        lc_cleanup();
        if (lc_p_ret != 0) {
                fprintf(stderr, &quot;Error processing configuration: \
                        %s\n&quot;, lc_geterrstr());
                return(EXIT_FAILURE);
        }
        if (filename != NULL) {
                printf(&quot;File specified was: %s\n&quot;, filename);
        } else {
                printf(&quot;No filename specified.\n&quot;);
        }
        if (counter != -1) {
                printf(&quot;Counter was specified as: %ld\n&quot;, counter);
        } else {
                printf(&quot;Counter was not specified.\n&quot;);
        }
        return(EXIT_SUCCESS);
}
</PRE>
<P>
<A NAME="lbAG">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="wiki/Manual">libconfig</A></B>(3),
<B><A HREF="wiki/Manual for lc_register_callback">lc_register_callback</A></B>(3),
<B><A HREF="wiki/Manual for lc_geterrno">lc_geterrno</A></B>(3),
<B><A HREF="wiki/Manual for lc_geterrstr">lc_geterrstr</A></B>(3),
<B><A HREF="wiki/Manual for lc_seterrstr">lc_seterrstr</A></B>(3),
<B><A HREF="wiki/Manual for lc_handle_type">lc_handle_type</A></B>(3),
<B><A HREF="wiki/Manual for lc_process">lc_process</A></B>(3),
<B><A HREF="wiki/Manual for lc_process_file">lc_process_file</A></B>(3),
<B><A HREF="wiki/Manual for lc_cleanup">lc_cleanup</A></B>(3)
<P>

Z 3bc46f4157bbc96dc860edc74d093c22