Index: Docs/USAGE ================================================================== --- Docs/USAGE +++ Docs/USAGE @@ -1,1 +1,2 @@ -The usage goes here... +See the manual pages for details. +Currently there is no supplemental usage information, there will be soon. Index: configure ================================================================== --- configure +++ configure @@ -16321,11 +16321,11 @@ echo "$as_me:$LINENO: result: $SHOBJLDFLAGS $SHOBJFLAGS" >&5 echo "${ECHO_T}$SHOBJLDFLAGS $SHOBJFLAGS" >&6 - ac_config_files="$ac_config_files Makefile lc_geterrno.3 lc_process.3 lc_register_var.3 lc_geterrstr.3 lc_register_callback.3" + ac_config_files="$ac_config_files Makefile lc_geterrno.3 lc_process.3 lc_register_var.3 lc_geterrstr.3 lc_register_callback.3 libconfig.3" cat >confcache <<\_ACEOF # This file is a shell script that caches the results of configure # tests run on this system so they can be shared between configure # scripts and configure runs, see configure's option --config-cache. # It is not useful on other systems. If it contains results you don't @@ -16853,10 +16853,11 @@ "lc_geterrno.3" ) CONFIG_FILES="$CONFIG_FILES lc_geterrno.3" ;; "lc_process.3" ) CONFIG_FILES="$CONFIG_FILES lc_process.3" ;; "lc_register_var.3" ) CONFIG_FILES="$CONFIG_FILES lc_register_var.3" ;; "lc_geterrstr.3" ) CONFIG_FILES="$CONFIG_FILES lc_geterrstr.3" ;; "lc_register_callback.3" ) CONFIG_FILES="$CONFIG_FILES lc_register_callback.3" ;; + "libconfig.3" ) CONFIG_FILES="$CONFIG_FILES libconfig.3" ;; "config.h" ) CONFIG_HEADERS="$CONFIG_HEADERS config.h" ;; *) { { echo "$as_me:$LINENO: error: invalid argument: $ac_config_target" >&5 echo "$as_me: error: invalid argument: $ac_config_target" >&2;} { (exit 1); exit 1; }; };; esac Index: configure.in ================================================================== --- configure.in +++ configure.in @@ -31,6 +31,6 @@ DC_DO_WIN32 dnl This must be last. DC_GET_SHOBJFLAGS -AC_OUTPUT(Makefile lc_geterrno.3 lc_process.3 lc_register_var.3 lc_geterrstr.3 lc_register_callback.3) +AC_OUTPUT(Makefile lc_geterrno.3 lc_process.3 lc_register_var.3 lc_geterrstr.3 lc_register_callback.3 libconfig.3) ADDED libconfig.3.in Index: libconfig.3.in ================================================================== --- /dev/null +++ libconfig.3.in @@ -0,0 +1,63 @@ +.TH LIBCONFIG 3 "25 Oct 04" "@PACKAGE_STRING@" +.SH NAME +libconfig \- Consistent configuration library. + +.SH SYNOPSIS +.B #include +.sp +.BI "int lc_register_callback(const char *" var ", char " opt ", lc_var_type_t " type ", int (*" callback ")(const char *, const char *, const char *, const char *, lc_flags_t, void *), void *" extra ");" + +.BI "int lc_register_var(const char *" var ", lc_var_type_t " type ", void *" data ", char " opt ");" + +.BI "int lc_process(int " argc ", char **" argv ", const char *" appname ", lc_conf_type_t " type ", const char *" extra ");" + +.BI "lc_err_t lc_geterrno(void);" + +.BI "char *lc_geterrstr(void);" + +.SH DESCRIPTION +Libconfig is a library to provide easy access to configuration data in a consistent and logical manner. + +.SH EXAMPLE +.nf +#include +#include +#include + +int main(int argc, char **argv) { + int lc_p_ret, lc_rv_ret; + char *filename = NULL; + + 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"); + } + + return(EXIT_SUCCESS); +} +.fi + +.SH "SEE ALSO" +.BR lc_register_var (3), +.BR lc_register_callback (3), +.BR lc_geterr (3), +.BR lc_geterrstr (3), +.BR lc_process (3) Index: libconfig.c ================================================================== --- libconfig.c +++ libconfig.c @@ -743,23 +743,25 @@ char *configfile = NULL; char *homedir = NULL; int configsetidx = 0, configidx = 0; int chkretval = 0, retval = 0; - snprintf(configfiles[0][0], sizeof(**configfiles) - 1, "/etc/%s.cfg", appname); - snprintf(configfiles[0][1], sizeof(**configfiles) - 1, "/etc/%s.conf", appname); - snprintf(configfiles[0][2], sizeof(**configfiles) - 1, "/etc/%s/%s.cfg", appname, appname); - snprintf(configfiles[0][3], sizeof(**configfiles) - 1, "/etc/%s/%s.conf", appname, appname); - snprintf(configfiles[0][4], sizeof(**configfiles) - 1, "/usr/etc/%s.cfg", appname); - snprintf(configfiles[0][5], sizeof(**configfiles) - 1, "/usr/etc/%s.conf", appname); - snprintf(configfiles[0][6], sizeof(**configfiles) - 1, "/usr/etc/%s/%s.cfg", appname, appname); - snprintf(configfiles[0][7], sizeof(**configfiles) - 1, "/usr/etc/%s/%s.conf", appname, appname); - snprintf(configfiles[0][8], sizeof(**configfiles) - 1, "/usr/local/etc/%s.cfg", appname); - snprintf(configfiles[0][9], sizeof(**configfiles) - 1, "/usr/local/etc/%s.conf", appname); - snprintf(configfiles[0][10], sizeof(**configfiles) - 1, "/usr/local/etc/%s/%s.cfg", appname, appname); - snprintf(configfiles[0][11], sizeof(**configfiles) - 1, "/usr/local/etc/%s/%s.conf", appname, appname); - snprintf(configfiles[1][0], sizeof(**configfiles) - 1, "%s", extraconfig); + if (extraconfig != NULL) { + snprintf(configfiles[0][0], sizeof(**configfiles) - 1, "%s", extraconfig); + } + snprintf(configfiles[1][0], sizeof(**configfiles) - 1, "/etc/%s.cfg", appname); + snprintf(configfiles[1][1], sizeof(**configfiles) - 1, "/etc/%s.conf", appname); + snprintf(configfiles[1][2], sizeof(**configfiles) - 1, "/etc/%s/%s.cfg", appname, appname); + snprintf(configfiles[1][3], sizeof(**configfiles) - 1, "/etc/%s/%s.conf", appname, appname); + snprintf(configfiles[1][4], sizeof(**configfiles) - 1, "/usr/etc/%s.cfg", appname); + snprintf(configfiles[1][5], sizeof(**configfiles) - 1, "/usr/etc/%s.conf", appname); + snprintf(configfiles[1][6], sizeof(**configfiles) - 1, "/usr/etc/%s/%s.cfg", appname, appname); + snprintf(configfiles[1][7], sizeof(**configfiles) - 1, "/usr/etc/%s/%s.conf", appname, appname); + snprintf(configfiles[1][8], sizeof(**configfiles) - 1, "/usr/local/etc/%s.cfg", appname); + snprintf(configfiles[1][9], sizeof(**configfiles) - 1, "/usr/local/etc/%s.conf", appname); + snprintf(configfiles[1][10], sizeof(**configfiles) - 1, "/usr/local/etc/%s/%s.cfg", appname, appname); + snprintf(configfiles[1][11], sizeof(**configfiles) - 1, "/usr/local/etc/%s/%s.conf", appname, appname); if (getuid() != 0) { homedir = getenv("HOME"); if (homedir == NULL) { pwinfo = getpwuid(getuid()); if (pwinfo != NULL) {