Index: build/build_web_manpages ================================================================== --- build/build_web_manpages +++ build/build_web_manpages @@ -6,9 +6,9 @@ if [ ! -f libconfig.3 ]; then echo 'Could not find libconfig.3, aborting.' >&2 exit 1 fi -for file in lc_cleanup lc_geterrno lc_geterrstr lc_process lc_process_file lc_register_callback lc_register_var libconfig; do +for file in lc_cleanup lc_geterrno lc_geterrstr lc_seterrstr lc_process lc_process_file lc_register_callback lc_register_var libconfig; do man2html -H "REPLACE" -M "/ME" < ${file}.3 | grep -iv '^Content-Type:' | sed 's@"http://REPLACE/ME?\([0-9]*\)+\([^"]*\)"@"\2.htm"@;s@http://REPLACE/ME@@g' > /web/rkeene/docs/oss/libconfig/${file}.htm done Index: lc_cleanup.3.in ================================================================== --- lc_cleanup.3.in +++ lc_cleanup.3.in @@ -63,11 +63,13 @@ return(EXIT_SUCCESS); } .fi .SH "SEE ALSO" +.BR libconfig (3), .BR lc_register_var (3), .BR lc_register_callback (3), +.BR lc_seterrstr (3), .BR lc_geterrstr (3), .BR lc_geterrno (3), .BR lc_process_file (3), .BR lc_process (3) Index: lc_geterrno.3.in ================================================================== --- lc_geterrno.3.in +++ lc_geterrno.3.in @@ -83,11 +83,13 @@ return(EXIT_SUCCESS); } .fi .SH "SEE ALSO" +.BR libconfig (3), .BR lc_register_var (3), .BR lc_register_callback (3), .BR lc_geterrstr (3), +.BR lc_seterrstr (3), .BR lc_cleanup (3), .BR lc_process_file (3), .BR lc_process (3) Index: lc_geterrstr.3.in ================================================================== --- lc_geterrstr.3.in +++ lc_geterrstr.3.in @@ -51,11 +51,13 @@ return(EXIT_SUCCESS); } .fi .SH "SEE ALSO" +.BR libconfig (3), .BR lc_register_var (3), .BR lc_register_callback (3), +.BR lc_seterrstr (3), .BR lc_geterrno (3), .BR lc_cleanup (3), .BR lc_process_file (3), .BR lc_process (3) Index: lc_process.3.in ================================================================== --- lc_process.3.in +++ lc_process.3.in @@ -97,11 +97,13 @@ return(EXIT_SUCCESS); } .fi .SH "SEE ALSO" +.BR libconfig (3), .BR lc_register_var (3), .BR lc_register_callback (3), .BR lc_geterrno (3), +.BR lc_seterrstr (3), .BR lc_geterrstr (3), .BR lc_cleanup (3), .BR lc_process_file (3) Index: lc_process_file.3.in ================================================================== --- lc_process_file.3.in +++ lc_process_file.3.in @@ -59,11 +59,13 @@ return(EXIT_SUCCESS); } .fi .SH "SEE ALSO" +.BR libconfig (3), .BR lc_register_var (3), .BR lc_register_callback (3), .BR lc_geterrno (3), .BR lc_geterrstr (3), +.BR lc_seterrstr (3), .BR lc_cleanup (3), .BR lc_process (3) Index: lc_register_callback.3.in ================================================================== --- lc_register_callback.3.in +++ lc_register_callback.3.in @@ -151,11 +151,11 @@ Returning LC_CBRET_OKAY from a callback indicates that all went well and further processing may continue. .TP LC_CBRET_ERROR Returnning LC_CBRET_ERROR from a callback indicates that the command failed for some reason, the error will be passed back down the chain back to the .BR lc_process (3) -call that began processing the configuration data. If LC_CBRET_ERROR is returned from a callback that begins a section, the entire section is ignored. +call that began processing the configuration data. If LC_CBRET_ERROR is returned from a callback that begins a section, the entire section is ignored. If LC_CBRET_ERROR is returned from a callback that ends a section, the error is ignored. .SH "RETURN VALUE" On success 0 is returned, otherwise -1 is returned. @@ -172,17 +172,17 @@ if (flags == LC_FLAGS_SECTIONEND) { return(LC_CBRET_OKAY); } if (flags != LC_FLAGS_SECTIONSTART) { - fprintf(stderr, "IfModule can only be used as a \\ - section.\\n"); + lc_seterrstr("IfModule can only be used as a \\ + section."); return(LC_CBRET_ERROR); } if (arguments == NULL) { - fprintf(stderr, "You must specify an argument to \\ - IfModule.\\n"); + lc_seterrstr("You must specify an argument to \\ + IfModule."); return(LC_CBRET_ERROR); } printf("IfModule %s\\n", arguments); @@ -223,11 +223,13 @@ .TP .B ENOMEM Memory could not be allocated to create the needed internal structures. .SH "SEE ALSO" +.BR libconfig (3), .BR lc_register_var (3), .BR lc_geterrno (3), .BR lc_geterrstr (3), +.BR lc_seterrstr (3), .BR lc_cleanup (3), .BR lc_process_file (3), .BR lc_process (3) Index: lc_register_var.3.in ================================================================== --- lc_register_var.3.in +++ lc_register_var.3.in @@ -144,11 +144,13 @@ return(EXIT_SUCCESS); } .fi .SH "SEE ALSO" +.BR libconfig (3), .BR lc_register_callback (3), .BR lc_geterrno (3), .BR lc_geterrstr (3), +.BR lc_seterrstr (3), .BR lc_cleanup (3), .BR lc_process_file (3), .BR lc_process (3) Index: lc_seterrstr.3.in ================================================================== --- lc_seterrstr.3.in +++ lc_seterrstr.3.in @@ -1,61 +1,25 @@ .TH LC_GETERRSTR 3 "25 Oct 04" "@PACKAGE_STRING@" .SH NAME -lc_geterrstr \- Retrieve a human readable error message. +lc_geterrstr \- Set an error message from a callback. .SH SYNOPSIS .B #include .sp -.BI "char *lc_geterrstr(void);" +.BI "void lc_seterrstr(const char *" errstr ");" .SH DESCRIPTION The +.BR lc_seterrstr (3) +function sets a human readable error message to be returned by .BR lc_geterrstr (3) -function returns a string describing the last error code set. - -.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: %s.\\n", - lc_geterrstr()); - 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"); - } - - return(EXIT_SUCCESS); -} -.fi +function when an error is returned from a callback function. The value is ignored if the error is not related to a callback. .SH "SEE ALSO" +.BR libconfig (3), .BR lc_register_var (3), .BR lc_register_callback (3), .BR lc_geterrno (3), +.BR lc_geterrstr (3), .BR lc_cleanup (3), .BR lc_process_file (3), .BR lc_process (3) Index: libconfig.3.in ================================================================== --- libconfig.3.in +++ libconfig.3.in @@ -13,10 +13,12 @@ .BI "lc_err_t lc_geterrno(void);" .BI "char *lc_geterrstr(void);" +.BI "void lc_geterrstr(const char *" errstr ");" + .SH DESCRIPTION Libconfig is a library to provide easy access to configuration data in a consistent and logical manner. Variables (registered through .BR lc_register_var (3) or .BR lc_register_callback (3)) @@ -75,8 +77,9 @@ .SH "SEE ALSO" .BR lc_register_var (3), .BR lc_register_callback (3), .BR lc_geterr (3), .BR lc_geterrstr (3), +.BR lc_seterrstr (3), .BR lc_cleanup (3), .BR lc_process (3), .BR lc_process_file (3) Index: libconfig.c ================================================================== --- libconfig.c +++ libconfig.c @@ -36,10 +36,11 @@ #include #endif struct lc_varhandler_st *varhandlers = NULL; lc_err_t lc_errno = LC_ERR_NONE; +const char *lc_err_usererrmsg = NULL; const char *lc_errfile = NULL; int lc_optind = 0; int lc_errline = 0; extern char **environ; @@ -979,10 +980,16 @@ free(handler); handler = next; } + + if (lc_err_usererrmsg) { + free((char *) lc_err_usererrmsg); + + lc_err_usererrmsg = NULL; + } varhandlers = NULL; return; } @@ -1019,14 +1026,18 @@ lc_errno = LC_ERR_NONE; return(retval); } + +void lc_seterrstr(const char *usererrmsg) { + lc_err_usererrmsg = strdup(usererrmsg); +} char *lc_geterrstr(void) { static char retval[512]; - char *errmsg = NULL; + const char *errmsg = NULL; switch (lc_errno) { case LC_ERR_NONE: errmsg = "Success"; break; @@ -1044,11 +1055,15 @@ break; case LC_ERR_CANTOPEN: errmsg = "Can't open file."; break; case LC_ERR_CALLBACK: - errmsg = "Error return from application handler."; + if (lc_err_usererrmsg) { + errmsg = lc_err_usererrmsg; + } else { + errmsg = "Error return from application handler."; + } break; case LC_ERR_ENOMEM: errmsg = "Insuffcient memory."; break; } Index: libconfig.h.in ================================================================== --- libconfig.h.in +++ libconfig.h.in @@ -78,10 +78,11 @@ int lc_process(int argc, char **argv, const char *appname, lc_conf_type_t type, const char *extra); 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); int lc_register_var(const char *var, lc_var_type_t type, void *data, char opt); lc_err_t lc_geterrno(void); +void lc_seterrstr(const char *usererrstr); char *lc_geterrstr(void); int lc_process_file(const char *appname, const char *pathname, lc_conf_type_t type); void lc_cleanup(void); __BLANK_LINE__