Check-in [f953f16a77]
Overview
Comment:Added an lc_seterrstr() function
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:f953f16a77c572d5c5e61ea30ba7d6ffd481ed59
User & Date: rkeene on 2006-12-16 17:06:08
Other Links: manifest | tags
Context
2006-12-17
00:11
Updated libconfig to reset lc_errno at the start of each function check-in: c8032b5a5e user: rkeene tags: trunk
2006-12-16
17:06
Added an lc_seterrstr() function check-in: f953f16a77 user: rkeene tags: trunk
17:06
Subversion to Fossil Copy Commit. Please Ignore. Recording copying lc_geterrstr.3.in to lc_seterrstr.3.in. check-in: 9f254f7f02 user: rkeene tags: trunk
Changes

Modified build/build_web_manpages from [15a48182c3] to [30cc606ea6].

     4      4   fi
     5      5   
     6      6   if [ ! -f libconfig.3 ]; then
     7      7   	echo  'Could not find libconfig.3, aborting.' >&2
     8      8   	exit 1
     9      9   fi
    10     10   
    11         -for file in lc_cleanup lc_geterrno lc_geterrstr lc_process lc_process_file lc_register_callback lc_register_var libconfig; do
           11  +for file in lc_cleanup lc_geterrno lc_geterrstr lc_seterrstr lc_process lc_process_file lc_register_callback lc_register_var libconfig; do
    12     12   	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
    13     13   done
    14     14   

build/prep.sh became executable with contents [3f4d67e154].

whitespace changes only

Modified lc_cleanup.3.in from [1a58c9eea6] to [efcfee978b].

    61     61   	}
    62     62   
    63     63   	return(EXIT_SUCCESS);
    64     64   }
    65     65   .fi
    66     66   
    67     67   .SH "SEE ALSO"
           68  +.BR libconfig (3),
    68     69   .BR lc_register_var (3),
    69     70   .BR lc_register_callback (3),
           71  +.BR lc_seterrstr (3),
    70     72   .BR lc_geterrstr (3),
    71     73   .BR lc_geterrno (3),
    72     74   .BR lc_process_file (3),
    73     75   .BR lc_process (3)

Modified lc_geterrno.3.in from [cd34ea9cd7] to [d8407e858d].

    81     81   	}
    82     82   
    83     83   	return(EXIT_SUCCESS);
    84     84   }
    85     85   .fi
    86     86   
    87     87   .SH "SEE ALSO"
           88  +.BR libconfig (3),
    88     89   .BR lc_register_var (3),
    89     90   .BR lc_register_callback (3),
    90     91   .BR lc_geterrstr (3),
           92  +.BR lc_seterrstr (3),
    91     93   .BR lc_cleanup (3),
    92     94   .BR lc_process_file (3),
    93     95   .BR lc_process (3)

Modified lc_geterrstr.3.in from [72b9664bc6] to [36f9da08c6].

    49     49   	}
    50     50   
    51     51   	return(EXIT_SUCCESS);
    52     52   }
    53     53   .fi
    54     54   
    55     55   .SH "SEE ALSO"
           56  +.BR libconfig (3),
    56     57   .BR lc_register_var (3),
    57     58   .BR lc_register_callback (3),
           59  +.BR lc_seterrstr (3),
    58     60   .BR lc_geterrno (3),
    59     61   .BR lc_cleanup (3),
    60     62   .BR lc_process_file (3),
    61     63   .BR lc_process (3)

Modified lc_process.3.in from [95fe0e123b] to [0f2dddbaaa].

    95     95   	}
    96     96   
    97     97   	return(EXIT_SUCCESS);
    98     98   }
    99     99   .fi
   100    100   
   101    101   .SH "SEE ALSO"
          102  +.BR libconfig (3),
   102    103   .BR lc_register_var (3),
   103    104   .BR lc_register_callback (3),
   104    105   .BR lc_geterrno (3),
          106  +.BR lc_seterrstr (3),
   105    107   .BR lc_geterrstr (3),
   106    108   .BR lc_cleanup (3),
   107    109   .BR lc_process_file (3)

Modified lc_process_file.3.in from [ea98de7617] to [aecb56c52b].

    57     57   	}
    58     58   
    59     59   	return(EXIT_SUCCESS);
    60     60   }
    61     61   .fi
    62     62   
    63     63   .SH "SEE ALSO"
           64  +.BR libconfig (3),
    64     65   .BR lc_register_var (3),
    65     66   .BR lc_register_callback (3),
    66     67   .BR lc_geterrno (3),
    67     68   .BR lc_geterrstr (3),
           69  +.BR lc_seterrstr (3),
    68     70   .BR lc_cleanup (3),
    69     71   .BR lc_process (3)

Modified lc_register_callback.3.in from [cea18abe88] to [caede5b68d].

   149    149   .TP
   150    150   LC_CBRET_OKAY
   151    151   Returning LC_CBRET_OKAY from a callback indicates that all went well and further processing may continue.
   152    152   .TP
   153    153   LC_CBRET_ERROR
   154    154   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
   155    155   .BR lc_process (3)
   156         -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.
          156  +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.
   157    157   
   158    158   
   159    159   .SH "RETURN VALUE"
   160    160   On success 0 is returned, otherwise -1 is returned.
   161    161   
   162    162   .SH EXAMPLE
   163    163   .nf
................................................................................
   170    170                         const char *arguments, const char *value,
   171    171                         lc_flags_t flags, void *extra) {
   172    172   	if (flags == LC_FLAGS_SECTIONEND) {
   173    173   		return(LC_CBRET_OKAY);
   174    174   	}
   175    175   
   176    176   	if (flags != LC_FLAGS_SECTIONSTART) {
   177         -		fprintf(stderr, "IfModule can only be used as a \\
   178         -		        section.\\n");
          177  +		lc_seterrstr("IfModule can only be used as a \\
          178  +		              section.");
   179    179   		return(LC_CBRET_ERROR);
   180    180   	}
   181    181   	if (arguments == NULL) {
   182         -		fprintf(stderr, "You must specify an argument to \\
   183         -		        IfModule.\\n");
          182  +		lc_seterrstr("You must specify an argument to \\
          183  +		              IfModule.");
   184    184   		return(LC_CBRET_ERROR);
   185    185   	}
   186    186   
   187    187   	printf("IfModule %s\\n", arguments);
   188    188   
   189    189   	if (strcasecmp(arguments, "MyModule") == 0) {
   190    190   		return(LC_CBRET_IGNORESECTION);
................................................................................
   221    221   
   222    222   .SH ERRORS
   223    223   .TP
   224    224   .B ENOMEM
   225    225   Memory could not be allocated to create the needed internal structures.
   226    226   
   227    227   .SH "SEE ALSO"
          228  +.BR libconfig (3),
   228    229   .BR lc_register_var (3),
   229    230   .BR lc_geterrno (3),
   230    231   .BR lc_geterrstr (3),
          232  +.BR lc_seterrstr (3),
   231    233   .BR lc_cleanup (3),
   232    234   .BR lc_process_file (3),
   233    235   .BR lc_process (3)

Modified lc_register_var.3.in from [6224b99a5a] to [26c717cf6a].

   142    142   	}
   143    143   
   144    144   	return(EXIT_SUCCESS);
   145    145   }
   146    146   .fi
   147    147   
   148    148   .SH "SEE ALSO"
          149  +.BR libconfig (3),
   149    150   .BR lc_register_callback (3),
   150    151   .BR lc_geterrno (3),
   151    152   .BR lc_geterrstr (3),
          153  +.BR lc_seterrstr (3),
   152    154   .BR lc_cleanup (3),
   153    155   .BR lc_process_file (3),
   154    156   .BR lc_process (3)

Modified lc_seterrstr.3.in from [72b9664bc6] to [eb760dc316].

     1      1   .TH LC_GETERRSTR 3 "25 Oct 04" "@PACKAGE_STRING@"
     2      2   .SH NAME
     3         -lc_geterrstr \- Retrieve a human readable error message.
            3  +lc_geterrstr \- Set an error message from a callback.
     4      4   
     5      5   .SH SYNOPSIS
     6      6   .B #include <libconfig.h>
     7      7   .sp
     8         -.BI "char *lc_geterrstr(void);"
            8  +.BI "void lc_seterrstr(const char *" errstr ");"
     9      9   
    10     10   .SH DESCRIPTION
    11     11   The
           12  +.BR lc_seterrstr (3)
           13  +function sets a human readable error message to be returned by
    12     14   .BR lc_geterrstr (3)
    13         -function returns a string describing the last error code set.
    14         -
    15         -.SH EXAMPLE
    16         -.nf
    17         -#include <libconfig.h>
    18         -#include <stdlib.h>
    19         -#include <stdio.h>
    20         -
    21         -int main(int argc, char **argv) {
    22         -	int lc_p_ret, lc_rv_ret;
    23         -	char *filename = NULL;
    24         -
    25         -	lc_rv_ret = lc_register_var("File", LC_VAR_STRING,
    26         -	                            &filename, 'f');
    27         -
    28         -	if (lc_rv_ret != 0) {
    29         -		fprintf(stderr, "Error registering variable: %s.\\n",
    30         -		        lc_geterrstr());
    31         -		return(EXIT_FAILURE);
    32         -	}
    33         -
    34         -	lc_p_ret = lc_process(argc, argv, "example", LC_CONF_APACHE,
    35         -	                      NULL);
    36         -
    37         -	lc_cleanup();
    38         -
    39         -	if (lc_p_ret != 0) {
    40         -		fprintf(stderr, "Error processing configuration: \\
    41         -		        %s\\n", lc_geterrstr());
    42         -		return(EXIT_FAILURE);
    43         -	}
    44         -
    45         -	if (filename != NULL) {
    46         -		printf("File specified was: %s\\n", filename);
    47         -	} else {
    48         -		printf("No filename specified.\\n");
    49         -	}
    50         -
    51         -	return(EXIT_SUCCESS);
    52         -}
    53         -.fi
           15  +function when an error is returned from a callback function.  The value is ignored if the error is not related to a callback.
    54     16   
    55     17   .SH "SEE ALSO"
           18  +.BR libconfig (3),
    56     19   .BR lc_register_var (3),
    57     20   .BR lc_register_callback (3),
    58     21   .BR lc_geterrno (3),
           22  +.BR lc_geterrstr (3),
    59     23   .BR lc_cleanup (3),
    60     24   .BR lc_process_file (3),
    61     25   .BR lc_process (3)

Modified libconfig.3.in from [08444a4029] to [93e1c94d05].

    11     11   
    12     12   .BI "int lc_process(int " argc ", char **" argv ", const char *" appname ", lc_conf_type_t " type ", const char *" extra ");"
    13     13   
    14     14   .BI "lc_err_t lc_geterrno(void);"
    15     15   
    16     16   .BI "char *lc_geterrstr(void);"
    17     17   
           18  +.BI "void lc_geterrstr(const char *" errstr ");"
           19  +
    18     20   .SH DESCRIPTION
    19     21   Libconfig is a library to provide easy access to configuration data in a consistent and logical manner.  Variables (registered through
    20     22   .BR lc_register_var (3)
    21     23   or
    22     24   .BR lc_register_callback (3))
    23     25   are processed with the
    24     26   .BR lc_process (3)
................................................................................
    73     75   .fi
    74     76   
    75     77   .SH "SEE ALSO"
    76     78   .BR lc_register_var (3),
    77     79   .BR lc_register_callback (3),
    78     80   .BR lc_geterr (3),
    79     81   .BR lc_geterrstr (3),
           82  +.BR lc_seterrstr (3),
    80     83   .BR lc_cleanup (3),
    81     84   .BR lc_process (3),
    82     85   .BR lc_process_file (3)

Modified libconfig.c from [341b40c218] to [508cc92a36].

    34     34   
    35     35   #ifdef HAVE_PWD_H
    36     36   #include <pwd.h>
    37     37   #endif
    38     38   
    39     39   struct lc_varhandler_st *varhandlers = NULL;
    40     40   lc_err_t lc_errno = LC_ERR_NONE;
           41  +const char *lc_err_usererrmsg = NULL;
    41     42   const char *lc_errfile = NULL;
    42     43   int lc_optind = 0;
    43     44   int lc_errline = 0;
    44     45   
    45     46   extern char **environ;
    46     47   
    47     48   static int lc_process_var_string(void *data, const char *value, const char **endptr) {
................................................................................
   977    978   
   978    979   		next = handler->_next;
   979    980   
   980    981   		free(handler);
   981    982   
   982    983   		handler = next;
   983    984   	}
          985  +
          986  +	if (lc_err_usererrmsg) {
          987  +		free((char *) lc_err_usererrmsg);
          988  +
          989  +		lc_err_usererrmsg = NULL;
          990  +	}
   984    991   
   985    992   	varhandlers = NULL;
   986    993   
   987    994   	return;
   988    995   }
   989    996   
   990    997   int lc_process(int argc, char **argv, const char *appname, lc_conf_type_t type, const char *extra) {
................................................................................
  1017   1024   
  1018   1025   	retval = lc_errno;
  1019   1026   
  1020   1027   	lc_errno = LC_ERR_NONE;
  1021   1028   
  1022   1029   	return(retval);
  1023   1030   }
         1031  +
         1032  +void lc_seterrstr(const char *usererrmsg) {
         1033  +	lc_err_usererrmsg = strdup(usererrmsg);
         1034  +}
  1024   1035   
  1025   1036   char *lc_geterrstr(void) {
  1026   1037   	static char retval[512];
  1027         -	char *errmsg = NULL;
         1038  +	const char *errmsg = NULL;
  1028   1039   
  1029   1040   	switch (lc_errno) {
  1030   1041   		case LC_ERR_NONE:
  1031   1042   			errmsg = "Success";
  1032   1043   			break;
  1033   1044   		case LC_ERR_INVCMD:
  1034   1045   			errmsg = "Invalid command or option";
................................................................................
  1042   1053   		case LC_ERR_BADFORMAT:
  1043   1054   			errmsg = "Bad data specified or incorrect format.";
  1044   1055   			break;
  1045   1056   		case LC_ERR_CANTOPEN:
  1046   1057   			errmsg = "Can't open file.";
  1047   1058   			break;
  1048   1059   		case LC_ERR_CALLBACK:
         1060  +			if (lc_err_usererrmsg) {
         1061  +				errmsg = lc_err_usererrmsg;
         1062  +			} else {
  1049   1063   			errmsg = "Error return from application handler.";
         1064  +			}
  1050   1065   			break;
  1051   1066   		case LC_ERR_ENOMEM:
  1052   1067   			errmsg = "Insuffcient memory.";
  1053   1068   			break;
  1054   1069   	}
  1055   1070   
  1056   1071   	/*

Modified libconfig.h.in from [6dd0b27349] to [a51c1e0b82].

    76     76   
    77     77   __BLANK_LINE__
    78     78   
    79     79   int lc_process(int argc, char **argv, const char *appname, lc_conf_type_t type, const char *extra);
    80     80   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);
    81     81   int lc_register_var(const char *var, lc_var_type_t type, void *data, char opt);
    82     82   lc_err_t lc_geterrno(void);
           83  +void lc_seterrstr(const char *usererrstr);
    83     84   char *lc_geterrstr(void);
    84     85   int lc_process_file(const char *appname, const char *pathname, lc_conf_type_t type);
    85     86   void lc_cleanup(void);
    86     87   
    87     88   __BLANK_LINE__
    88     89   
    89     90   !define LC_CBRET_IGNORESECTION (255)