📄 confuse.h.3
字号:
.br.RI "\fIPrint the options and values to a file. \fP".ti -1c.RI "DLLIMPORT \fBcfg_print_func_t\fP __export \fBcfg_opt_set_print_func\fP (\fBcfg_opt_t\fP *opt, \fBcfg_print_func_t\fP pf)".br.RI "\fISet a print callback function for an option. \fP".ti -1c.RI "DLLIMPORT \fBcfg_print_func_t\fP __export \fBcfg_set_print_func\fP (\fBcfg_t\fP *cfg, const char *name, \fBcfg_print_func_t\fP pf)".br.RI "\fISet a print callback function for an option given its name. \fP".ti -1c.RI "DLLIMPORT \fBcfg_validate_callback_t\fP __export \fBcfg_set_validate_func\fP (\fBcfg_t\fP *cfg, const char *name, \fBcfg_validate_callback_t\fP vf)".br.RI "\fIRegister a validating callback function for an option. \fP".in -1c.SH "Detailed Description".PP A configuration file parser library. .SH "Define Documentation".PP .SS "#define CFG_END() {0,CFGT_NONE,0,0,CFGF_NONE,0,{0,0,cfg_false,0,0},0,0,0,0,0,0}".PPTerminate list of options. .PPThis must be the last initializer in the option list. .PP\fBExamples: \fP.in +1c\fBftpconf.c\fP, \fBreread.c\fP, and \fBsimple.c\fP..SS "#define CFG_FUNC(name, func) {name,CFGT_FUNC,0,0,CFGF_NONE,0,{0,0,cfg_false,0,0},func,0,0,0,0,0}".PPInitialize a function. .PP\fBParameters:\fP.RS 4\fIname\fP The name of the option .br\fIfunc\fP The callback function..RE.PP\fBSee also:\fP.RS 4\fBcfg_func_t\fP .RE.PP.PP\fBExamples: \fP.in +1c\fBftpconf.c\fP..SS "#define CFG_PTR_CB(name, def, flags, parsecb, freecb) __CFG_PTR(name, def, flags, 0, parsecb, freecb)".PPInitialize a user-defined option. .PPCFG_PTR options can only be used together with a value parsing callback..PP\fBParameters:\fP.RS 4\fIname\fP The name of the option .br\fIdef\fP Default value .br\fIflags\fP Flags .br\fIparsecb\fP Value parsing callback .br\fIfreecb\fP Memory release function.RE.PP\fBSee also:\fP.RS 4\fBcfg_callback_t\fP, \fBcfg_free_func_t\fP .RE.PP.SS "#define CFG_SEC(name, opts, flags) {name,CFGT_SEC,0,0,flags,opts,{0,0,cfg_false,0,0},0,0,0,0,0,0}".PPInitialize a section. .PP\fBParameters:\fP.RS 4\fIname\fP The name of the option .br\fIopts\fP Array of options that are valid within this section.br\fIflags\fP Flags, specify CFGF_MULTI if it should be possible to have multiples of the same section, and CFGF_TITLE if the section(s) must have a title (which can be used in the \fBcfg_gettsec()\fP function) .RE.PP.PP\fBExamples: \fP.in +1c\fBftpconf.c\fP, and \fBreread.c\fP..SS "#define CFG_SIMPLE_STR(name, svalue) __CFG_STR(name, 0, CFGF_NONE, svalue, 0)".PPInitialize a 'simple' string option. .PP'Simple' options (in lack of a better expression) does not support lists of values or multiple sections. LibConfuse will store the value of a simple option in the user-defined location specified by the value parameter in the initializer. Simple options are not stored in the \fBcfg_t\fP context, only a pointer. Sections can not be initialized as a 'simple' option..PPAs of version 2.2, libConfuse can now return the values of simple options with the cfg_get functions. This allows using the new cfg_print function with simple options..PPlibConfuse doesn't support handling default values for 'simple' options. They are assumed to be set by the calling application before cfg_parse is called..PP\fBParameters:\fP.RS 4\fIname\fP name of the option .br\fIsvalue\fP pointer to a character pointer (a char **). This value must be initalized either to NULL or to a malloc()'ed string. You can't use .PP.nf char *user = 'joe'; ... \fBcfg_opt_t\fP opts[] = { CFG_SIMPLE_STR('user', &user), ... .fi.PP since libConfuse will try to free the static string 'joe' (which is an error) when a 'user' option is found. Rather, use the following code snippet: .PP.nf char *user = strdup('joe'); ... \fBcfg_opt_t\fP opts[] = { CFG_SIMPLE_STR('user', &user), ... .fi.PP Alternatively, the default value can be set after the opts struct is defined, as in: .PP.nf char *user = 0; ... \fBcfg_opt_t\fP opts[] = { CFG_SIMPLE_STR('user', &user), ... user = strdup('joe'); cfg = cfg_init(opts, 0); cfg_parse(cfg, filename); .fi.PP .RE.PP.PP\fBExamples: \fP.in +1c\fBsimple.c\fP..SH "Typedef Documentation".PP .SS "typedef int(*) \fBcfg_callback_t\fP(\fBcfg_t\fP *cfg, \fBcfg_opt_t\fP *opt, const char *value, void *result)".PPValue parsing callback prototype. .PPThis is a callback function (different from the one registered with the CFG_FUNC initializer) used to parse a value. This can be used to override the internal parsing of a value..PPSuppose you want an integer option that only can have certain values, for example 1, 2 and 3, and these should be written in the configuration file as 'yes', 'no' and 'maybe'. The callback function would be called with the found value ('yes', 'no' or 'maybe') as a string, and the result should be stored in the result parameter..PP\fBParameters:\fP.RS 4\fIcfg\fP The configuration file context. .br\fIopt\fP The option. .br\fIvalue\fP The value found in the configuration file. .br\fIresult\fP Pointer to storage for the result, cast to a void pointer..RE.PP\fBReturns:\fP.RS 4On success, 0 should be returned. All other values indicates an error, and the parsing is aborted. The callback function should notify the error itself, for example by calling \fBcfg_error()\fP. .RE.PP.SS "typedef void(*) \fBcfg_free_func_t\fP(void *value)".PPUser-defined memory release function for CFG_PTR values. .PPThis callback is used to free memory allocated in a value parsing callback function. Especially useful for CFG_PTR options, since libConfuse will not itself release such values. If the values are simply allocated with a malloc(3), one can use the standard free(3) function here. .SS "typedef int(*) \fBcfg_func_t\fP(\fBcfg_t\fP *cfg, \fBcfg_opt_t\fP *opt, int argc, const char **argv)".PPFunction prototype used by CFGT_FUNC options. .PPThis is a callback function, registered with the CFG_FUNC initializer. Each time libConfuse finds a function, the registered callback function is called (parameters are passed as strings, any conversion to other types should be made in the callback function). libConfuse does not support any storage of the data found; these are passed as parameters to the callback, and it's the responsibility of the callback function to do whatever it should do with the data..PP\fBParameters:\fP.RS 4\fIcfg\fP The configuration file context. .br\fIopt\fP The option. .br\fIargc\fP Number of arguments passed. The callback function is responsible for checking that the correct number of arguments are passed. .br\fIargv\fP Arguments as an array of character strings..RE.PP\fBReturns:\fP.RS 4On success, 0 should be returned. All other values indicates an error, and the parsing is aborted. The callback function should notify the error itself, for example by calling \fBcfg_error()\fP..RE.PP\fBSee also:\fP.RS 4\fBCFG_FUNC\fP .RE.PP.SS "typedef void(*) \fBcfg_print_func_t\fP(\fBcfg_opt_t\fP *opt, unsigned int index, FILE *fp)".PPFunction prototype used by the cfg_print_ functions. .PPThis callback function is used to print option values. For options with a value parsing callback, this is often required, especially if a string is mapped to an integer by the callback. This print callback must then map the integer back to the appropriate string..PPExcept for functions, the print callback function should only print the value of the option, not the name and the equal sign (that is handled by the cfg_opt_print function). For function options however, the name and the parenthesis must be printed by this function. The value to print can be accessed with the cfg_opt_get functions..PP\fBParameters:\fP.RS 4\fIopt\fP The option structure (eg, as returned from \fBcfg_getopt()\fP) .br\fIindex\fP Index of the value to get. Zero based. .br\fIfp\fP File stream to print to, use stdout to print to the screen..RE.PP\fBSee also:\fP.RS 4\fBcfg_print\fP, \fBcfg_set_print_func\fP .RE.PP.SS "typedef int(*) \fBcfg_validate_callback_t\fP(\fBcfg_t\fP *cfg, \fBcfg_opt_t\fP *opt)".PPValidating callback prototype. .PPThis callback function is called after an option has been parsed and set. The function is called for both fundamental values (strings, integers etc) as well as lists and sections. This can for example be used to validate that all required options in a section has been set to sane values..PP\fBReturns:\fP.RS 4On success, 0 should be returned. All other values indicates an error, and the parsing is aborted. The callback function should notify the error itself, for example by calling \fBcfg_error()\fP..RE.PP\fBSee also:\fP.RS 4\fBcfg_set_validate_func\fP .RE.PP.SH "Enumeration Type Documentation".PP .SS "enum \fBcfg_type_t\fP".PPFundamental option types. .PP\fBEnumerator: \fP.in +1c.TP\fB\fICFGT_INT \fP\fPinteger .TP\fB\fICFGT_FLOAT \fP\fPfloating point number .TP\fB\fICFGT_STR \fP\fPstring .TP\fB\fICFGT_BOOL \fP\fPboolean value .TP\fB\fICFGT_SEC \fP\fPsection .TP\fB\fICFGT_FUNC \fP\fPfunction .TP\fB\fICFGT_PTR \fP\fPpointer to user-defined value .SH "Function Documentation".PP .SS "DLLIMPORT void __export cfg_addlist (\fBcfg_t\fP * cfg, const char * name, unsigned int nvalues, ...)".PPAdd values for a list option. .PPThe new values are appended to any current values in the list..PP\fBParameters:\fP.RS 4\fIcfg\fP The configuration file context. .br\fIname\fP The name of the option. .br\fInvalues\fP Number of values to add. .br\fI...\fP The values to add, the type must match the type of the option and the number of values must be equal to the nvalues parameter. .RE.PP.SS "DLLIMPORT void __export cfg_error (\fBcfg_t\fP * cfg, const char * fmt, ...)".PPShow a parser error. .PPAny user-defined error reporting function is called. .PP\fBSee also:\fP.RS 4\fBcfg_set_error_function\fP .RE.PP.PP\fBExamples: \fP.in +1c\fBftpconf.c\fP..SS "DLLIMPORT void __export cfg_free (\fBcfg_t\fP * cfg)".PPFree a \fBcfg_t\fP context. .PPAll memory allocated by the \fBcfg_t\fP context structure are freed, and can't be used in any further cfg_* calls. .PP\fBExamples: \fP.in +1c\fBftpconf.c\fP, \fBreread.c\fP, and \fBsimple.c\fP..SS "DLLIMPORT void __export cfg_free_value (\fBcfg_opt_t\fP * opt)".PPFree the memory allocated for the values of a given option. .PPOnly the values are freed, not the option itself (it is freed by \fBcfg_free()\fP)..PP\fBSee also:\fP.RS 4\fBcfg_free()\fP .RE.PP.SS "DLLIMPORT \fBcfg_bool_t\fP __export cfg_getbool (\fBcfg_t\fP * cfg, const char * name)".PPReturns the value of a boolean option. .PP\fBParameters:\fP.RS 4\fIcfg\fP The configuration file context. .br\fIname\fP The name of the option. .RE.PP\fBReturns:\fP.RS 4The requested value is returned. If the option was not set in the configuration file, the default value given in the corresponding \fBcfg_opt_t\fP structure is returned. It is an error to try to get an option that isn't declared. .RE.PP.PP\fBExamples: \fP.in +1c\fBftpconf.c\fP..SS "DLLIMPORT double __export cfg_getfloat (\fBcfg_t\fP * cfg, const char * name)".PPReturns the value of a floating point option. .PP\fBParameters:\fP.RS 4\fIcfg\fP The configuration file context. .br\fIname\fP The name of the option. .RE.PP\fBReturns:\fP.RS 4The requested value is returned. If the option was not set in the configuration file, the default value given in the corresponding \fBcfg_opt_t\fP structure is returned. It is an error to try to get an option that isn't declared. .RE.PP.SS "DLLIMPORT long int __export cfg_getint (\fBcfg_t\fP * cfg, const char * name)".PPReturns the value of an integer option. .PPThis is the same as calling cfg_getnint with index 0. .PP\fBParameters:\fP.RS 4\fIcfg\fP The configuration file context. .br\fIname\fP The name of the option. .RE.PP\fBReturns:\fP.RS 4The requested value is returned. If the option was not set in the configuration file, the default value given in the corresponding \fBcfg_opt_t\fP structure is returned. It is an error to try to get an option that isn't declared. .RE.PP.PP\fBExamples: \fP.in +1c\fBftpconf.c\fP, and \fBreread.c\fP..SS "DLLIMPORT \fBcfg_bool_t\fP __export cfg_getnbool (\fBcfg_t\fP * cfg, const char * name, unsigned int index)".PPIndexed version of \fBcfg_getbool()\fP, used for lists. .PP\fBParameters:\fP.RS 4\fIcfg\fP The configuration file context. .br\fIname\fP The name of the option. .br\fIindex\fP Index of the value to get. Zero based. .RE.PP\fBSee also:\fP.RS 4\fBcfg_getbool\fP .RE.PP.SS "DLLIMPORT double __export cfg_getnfloat (\fBcfg_t\fP * cfg, const char * name, unsigned int index)".PPIndexed version of \fBcfg_getfloat()\fP, used for lists. .PP
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -