.
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"> </A>
<H2>SYNOPSIS</H2>
<B>#include <<A HREF="artifact/7c61a9805e664fde7943807af8d5e164e7cebdb6">libconfig.h</A>></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"> </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 ' ' 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 "char **". 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 "long long" integer type variable. The data passed should be of type "long long *".
<DT>LC_VAR_LONG<DD>
For a "long" integer type variable. The data passed should be of type "long *".
<DT>LC_VAR_INT<DD>
For a "int" integer type variable. The data passed should be of type "int *".
<DT>LC_VAR_SHORT<DD>
For a "short" integer type variable. The data passed should be of type "short *".
<DT>LC_VAR_FLOAT<DD>
For a "float" floating point type variable. The data passed should be of type "float *".
<DT>LC_VAR_DOUBLE<DD>
For a "double" floating point type variable. The data passed should be of type "double *".
<DT>LC_VAR_BOOL<DD>
For a boolean type variable. The data passed should be of type "int *". 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 "long long" 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 "long long *".
<DT>LC_VAR_SIZE_LONG<DD>
For a "long" 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 "long *".
<DT>LC_VAR_SIZE_INT<DD>
For a "int" 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 "int *".
<DT>LC_VAR_SIZE_SHORT<DD>
For a "short" 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 "short *".
<DT>LC_VAR_SIZE_SIZE_T<DD>
For a "size_t" 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 "size_t *".
<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 "int *".
<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"> </A>
<H2>RETURN VALUE</H2>
On success 0 is returned, otherwise -1 is returned.
<P>
<A NAME="lbAF"> </A>
<H2>EXAMPLE</H2>
<PRE>
#include <<A HREF="artifact/7c61a9805e664fde7943807af8d5e164e7cebdb6">libconfig.h</A>>
#include <<A HREF="file:/usr/include/stdlib.h">stdlib.h</A>>
#include <<A HREF="file:/usr/include/stdio.h">stdio.h</A>>
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("Begin", LC_VAR_LONG,
&counter, 'c');
if (lc_rv_ret != 0) {
fprintf(stderr, "Error registering variable: %i.\n",
lc_geterrno());
return(EXIT_FAILURE);
}
lc_rv_ret = lc_register_var("File", LC_VAR_STRING,
&filename, 'f');
if (lc_rv_ret != 0) {
fprintf(stderr, "Error registering variable: %i.\n",
lc_geterrno());
return(EXIT_FAILURE);
}
lc_p_ret = lc_process(argc, argv, "example", LC_CONF_APACHE,
NULL);
lc_cleanup();
if (lc_p_ret != 0) {
fprintf(stderr, "Error processing configuration: \
%s\n", lc_geterrstr());
return(EXIT_FAILURE);
}
if (filename != NULL) {
printf("File specified was: %s\n", filename);
} else {
printf("No filename specified.\n");
}
if (counter != -1) {
printf("Counter was specified as: %ld\n", counter);
} else {
printf("Counter was not specified.\n");
}
return(EXIT_SUCCESS);
}
</PRE>
<P>
<A NAME="lbAG"> </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