Diff

Differences From Artifact [da39a3ee5e]:

To Artifact [33f89d18c6]:











































































































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
.TH LC_REGISTER_VAR 3 "25 Oct 04" "@PACKAGE_STRING@"
.SH NAME
lc_register_var \- Register a variable for automatic processing.

.SH SYNOPSIS
.B #include <libconfig.h>
.sp
.BI "int lc_register_var(const char *" var ", lc_var_type_t " type ", void *" data ", char " opt ");"

.SH DESCRIPTION
The
.BR lc_register_var (3)
function registers a variable for automatic processing.
The
.IR var
parameter specifies the variable name for processing.  This name can exist in a configuration file, an environment variable, or on the command line.
The
.IR opt
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
.IR data
parameter.  A value of '\0' can be specified for no short option.

The
.IR type 
parameter is of type
.IR lc_var_type_t
which specifies the type of the
.IR data
parameter.
Valid values for
.IR type
are:
.TP
LC_VAR_STRING
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.
.TP
LC_VAR_LONG_LONG
For a "long long" integer type variable.  The data passed should be of type "long long *".
.TP
LC_VAR_LONG
For a "long" integer type variable.  The data passed should be of type "long *".
.TP
LC_VAR_INT
For a "int" integer type variable.  The data passed should be of type "int *".
.TP
LC_VAR_SHORT
For a "short" integer type variable.  The data passed should be of type "short *".
.TP
LC_VAR_BOOL
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.
.TP
LC_VAR_FILENAME
Not implemented.
.TP
LC_VAR_DIRECTORY
Not implemented.
.TP
LC_VAR_SIZE_LONG_LONG
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 *".
.TP
LC_VAR_SIZE_LONG
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 *".
.TP
LC_VAR_SIZE_INT
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 *".
.TP
LC_VAR_SIZE_SHORT
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 *".
.TP
LC_VAR_TIME
Not implemented.
.TP
LC_VAR_DATE
Not implemented.
.TP
LC_VAR_BOOL_BY_EXISTANCE
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 *".

.SH "RETURN VALUE"
On success 0 is returned, otherwise -1 is returned.

.SH EXAMPLE
.nf
#include <libconfig.h>
#include <stdlib.h>
#include <stdio.h>

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);
	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);
}
.fi

.SH "SEE ALSO"
.BR lc_register_callback (3),
.BR lc_geterrno (3),
.BR lc_geterrstr (3),
.BR lc_process (3)